Skip to content

Commit

Permalink
[8.0] [kbn/io-ts] export and require importing individual functions (#…
Browse files Browse the repository at this point in the history
…117958) (#118074)

* [kbn/io-ts] export and require importing individual functions (#117958)

* [kbn/io-ts] fix direct import

Conflict between #117958 and #115145

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
4 people committed Nov 9, 2021
1 parent 069964c commit 4dc230c
Show file tree
Hide file tree
Showing 33 changed files with 85 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ const RESTRICTED_IMPORTS = [
name: 'react-use',
message: 'Please use react-use/lib/{method} instead.',
},
{
name: '@kbn/io-ts-utils',
message: `Import directly from @kbn/io-ts-utils/{method} submodules`,
},
];

module.exports = {
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-io-ts-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ filegroup(

NPM_MODULE_EXTRA_FILES = [
"package.json",
"deep_exact_rt/package.json",
"iso_to_epoch_rt/package.json",
"json_rt/package.json",
"merge_rt/package.json",
"non_empty_string_rt/package.json",
"parseable_types/package.json",
"props_to_schema/package.json",
"strict_keys_rt/package.json",
"to_boolean_rt/package.json",
"to_json_schema/package.json",
"to_number_rt/package.json",
]

RUNTIME_DEPS = [
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/deep_exact_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/deep_exact_rt",
"types": "../target_types/deep_exact_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/iso_to_epoch_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/iso_to_epoch_rt",
"types": "../target_types/iso_to_epoch_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/json_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/json_rt",
"types": "../target_types/json_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/merge_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/merge_rt",
"types": "../target_types/merge_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/non_empty_string_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/non_empty_string_rt",
"types": "../target_types/non_empty_string_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/parseable_types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/parseable_types",
"types": "../target_types/parseable_types"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/props_to_schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/props_to_schema",
"types": "../target_types/props_to_schema"
}
2 changes: 1 addition & 1 deletion packages/kbn-io-ts-utils/src/strict_keys_rt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function strictKeysRt<T extends t.Any>(type: T) {
const excessKeys = difference([...keys.all], [...keys.handled]);

if (excessKeys.length) {
return t.failure(i, context, `Excess keys are not allowed: \n${excessKeys.join('\n')}`);
return t.failure(i, context, `Excess keys are not allowed:\n${excessKeys.join('\n')}`);
}

return t.success(i);
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/strict_keys_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/strict_keys_rt",
"types": "../target_types/strict_keys_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/to_boolean_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/to_boolean_rt",
"types": "../target_types/to_boolean_rt"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/to_json_schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/to_json_schema",
"types": "../target_types/to_json_schema"
}
4 changes: 4 additions & 0 deletions packages/kbn-io-ts-utils/to_number_rt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../target_node/to_number_rt",
"types": "../target_types/to_number_rt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { jsonRt } from '@kbn/io-ts-utils';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import * as t from 'io-ts';
import { decodeRequestParams } from './decode_request_params';

Expand Down Expand Up @@ -69,7 +69,7 @@ describe('decodeRequestParams', () => {
};

expect(decode).toThrowErrorMatchingInlineSnapshot(`
"Excess keys are not allowed:
"Excess keys are not allowed:
path.extraKey"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { omitBy, isPlainObject, isEmpty } from 'lodash';
import { isLeft } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
import Boom from '@hapi/boom';
import { strictKeysRt } from '@kbn/io-ts-utils';
import { strictKeysRt } from '@kbn/io-ts-utils/strict_keys_rt';
import { RouteParamsRT } from './typings';

interface KibanaRequestParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import React from 'react';
import * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import { createRouter } from './create_router';
import { createMemoryHistory } from 'history';
import { route } from './route';
Expand Down
10 changes: 2 additions & 8 deletions packages/kbn-typed-react-router-config/src/create_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ import {
} from 'react-router-config';
import qs from 'query-string';
import { findLastIndex, merge, compact } from 'lodash';
import type { deepExactRt as deepExactRtTyped, mergeRt as mergeRtTyped } from '@kbn/io-ts-utils';
// @ts-expect-error
import { deepExactRt as deepExactRtNonTyped } from '@kbn/io-ts-utils/target_node/deep_exact_rt';
// @ts-expect-error
import { mergeRt as mergeRtNonTyped } from '@kbn/io-ts-utils/target_node/merge_rt';
import { mergeRt } from '@kbn/io-ts-utils/merge_rt';
import { deepExactRt } from '@kbn/io-ts-utils/deep_exact_rt';
import { FlattenRoutesOf, Route, Router } from './types';

const deepExactRt: typeof deepExactRtTyped = deepExactRtNonTyped;
const mergeRt: typeof mergeRtTyped = mergeRtNonTyped;

function toReactRouterPath(path: string) {
return path.replace(/(?:{([^\/]+)})/g, ':$1');
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/common/environment_rt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import * as t from 'io-ts';
import { nonEmptyStringRt } from '@kbn/io-ts-utils';
import { nonEmptyStringRt } from '@kbn/io-ts-utils/non_empty_string_rt';
import {
ENVIRONMENT_ALL,
ENVIRONMENT_NOT_DEFINED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
import { Outlet } from '@kbn/typed-react-router-config';
import * as t from 'io-ts';
import React from 'react';
import { toBooleanRt } from '@kbn/io-ts-utils';
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
import { RedirectTo } from '../redirect_to';
import { comparisonTypeRt } from '../../../../common/runtime_types/comparison_type_rt';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as t from 'io-ts';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { Outlet } from '@kbn/typed-react-router-config';
import { toBooleanRt } from '@kbn/io-ts-utils';
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
import { comparisonTypeRt } from '../../../../common/runtime_types/comparison_type_rt';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import { environmentRt } from '../../../../common/environment_rt';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/backends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import { setupRequest } from '../lib/helpers/setup_request';
import { environmentRt, kueryRt, offsetRt, rangeRt } from './default_api_types';
import { createApmServerRoute } from './create_apm_server_route';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as t from 'io-ts';
import Boom from '@hapi/boom';

import { i18n } from '@kbn/i18n';
import { toNumberRt } from '@kbn/io-ts-utils';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';

import { isActivePlatinumLicense } from '../../common/license_check';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/default_api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as t from 'io-ts';
import { isoToEpochRt } from '@kbn/io-ts-utils';
import { isoToEpochRt } from '@kbn/io-ts-utils/iso_to_epoch_rt';

export { environmentRt } from '../../common/environment_rt';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/latency_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import { getOverallLatencyDistribution } from '../lib/latency/get_overall_latency_distribution';
import { setupRequest } from '../lib/helpers/setup_request';
import { createApmServerRoute } from './create_apm_server_route';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/observability_overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as t from 'io-ts';
import { toNumberRt } from '@kbn/io-ts-utils';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import { setupRequest } from '../lib/helpers/setup_request';
import { getServiceCount } from '../lib/observability_overview/get_service_count';
import { getTransactionsPerMinute } from '../lib/observability_overview/get_transactions_per_minute';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { jsonRt } from '@kbn/io-ts-utils';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import { createServerRouteRepository } from '@kbn/server-route-repository';
import { ServerRoute } from '@kbn/server-route-repository';
import * as t from 'io-ts';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/routes/register_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
parseEndpoint,
routeValidationObject,
} from '@kbn/server-route-repository';
import { mergeRt, jsonRt } from '@kbn/io-ts-utils';
import { mergeRt } from '@kbn/io-ts-utils/merge_rt';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import { pickKeys } from '../../../common/utils/pick_keys';
import { APMRouteHandlerResources, TelemetryUsageCounter } from '../typings';
import type { ApmPluginRequestHandlerContext } from '../typings';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as t from 'io-ts';
import { Logger } from 'kibana/server';
import { isoToEpochRt } from '@kbn/io-ts-utils';
import { isoToEpochRt } from '@kbn/io-ts-utils/iso_to_epoch_rt';
import { setupRequest, Setup } from '../lib/helpers/setup_request';
import { getClientMetrics } from '../lib/rum_client/get_client_metrics';
import { getJSErrors } from '../lib/rum_client/get_js_errors';
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import Boom from '@hapi/boom';
import { jsonRt, isoToEpochRt, toNumberRt } from '@kbn/io-ts-utils';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import { isoToEpochRt } from '@kbn/io-ts-utils/iso_to_epoch_rt';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import * as t from 'io-ts';
import { uniq } from 'lodash';
import { latencyAggregationTypeRt } from '../../common/latency_aggregation_types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as t from 'io-ts';
import Boom from '@hapi/boom';
import { toBooleanRt } from '@kbn/io-ts-utils';
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
import { maxSuggestions } from '../../../../observability/common';
import { setupRequest } from '../../lib/helpers/setup_request';
import { getServiceNames } from '../../lib/settings/agent_configuration/get_service_names';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Boom from '@hapi/boom';
import * as t from 'io-ts';
import { SavedObjectsClientContract } from 'kibana/server';
import { jsonRt } from '@kbn/io-ts-utils';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import {
createApmArtifact,
deleteApmArtifact,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/routes/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { jsonRt, toNumberRt } from '@kbn/io-ts-utils';
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
import * as t from 'io-ts';
import {
LatencyAggregationType,
Expand Down

0 comments on commit 4dc230c

Please sign in to comment.