Skip to content

Commit 7d37821

Browse files
kibanamachineSpencerspalger
authored
[7.16] [kbn/io-ts] export and require importing individual functions (#117958) (#118075)
* [kbn/io-ts] export and require importing individual functions (#117958) * fix import Co-authored-by: Spencer <email@spalger.com> Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent 5def2c8 commit 7d37821

File tree

33 files changed

+85
-28
lines changed

33 files changed

+85
-28
lines changed

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ const RESTRICTED_IMPORTS = [
226226
name: 'react-use',
227227
message: 'Please use react-use/lib/{method} instead.',
228228
},
229+
{
230+
name: '@kbn/io-ts-utils',
231+
message: `Import directly from @kbn/io-ts-utils/{method} submodules`,
232+
},
229233
];
230234

231235
module.exports = {

packages/kbn-io-ts-utils/BUILD.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ filegroup(
2323

2424
NPM_MODULE_EXTRA_FILES = [
2525
"package.json",
26+
"deep_exact_rt/package.json",
27+
"iso_to_epoch_rt/package.json",
28+
"json_rt/package.json",
29+
"merge_rt/package.json",
30+
"non_empty_string_rt/package.json",
31+
"parseable_types/package.json",
32+
"props_to_schema/package.json",
33+
"strict_keys_rt/package.json",
34+
"to_boolean_rt/package.json",
35+
"to_json_schema/package.json",
36+
"to_number_rt/package.json",
2637
]
2738

2839
RUNTIME_DEPS = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/deep_exact_rt",
3+
"types": "../target_types/deep_exact_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/iso_to_epoch_rt",
3+
"types": "../target_types/iso_to_epoch_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/json_rt",
3+
"types": "../target_types/json_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/merge_rt",
3+
"types": "../target_types/merge_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/non_empty_string_rt",
3+
"types": "../target_types/non_empty_string_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/parseable_types",
3+
"types": "../target_types/parseable_types"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/props_to_schema",
3+
"types": "../target_types/props_to_schema"
4+
}

packages/kbn-io-ts-utils/src/strict_keys_rt/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function strictKeysRt<T extends t.Any>(type: T) {
113113
const excessKeys = difference([...keys.all], [...keys.handled]);
114114

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

119119
return t.success(i);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/strict_keys_rt",
3+
"types": "../target_types/strict_keys_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/to_boolean_rt",
3+
"types": "../target_types/to_boolean_rt"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/to_json_schema",
3+
"types": "../target_types/to_json_schema"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../target_node/to_number_rt",
3+
"types": "../target_types/to_number_rt"
4+
}

packages/kbn-server-route-repository/src/decode_request_params.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* in compliance with, at your election, the Elastic License 2.0 or the Server
66
* Side Public License, v 1.
77
*/
8-
import { jsonRt } from '@kbn/io-ts-utils';
8+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
99
import * as t from 'io-ts';
1010
import { decodeRequestParams } from './decode_request_params';
1111

@@ -69,7 +69,7 @@ describe('decodeRequestParams', () => {
6969
};
7070

7171
expect(decode).toThrowErrorMatchingInlineSnapshot(`
72-
"Excess keys are not allowed:
72+
"Excess keys are not allowed:
7373
path.extraKey"
7474
`);
7575
});

packages/kbn-server-route-repository/src/decode_request_params.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { omitBy, isPlainObject, isEmpty } from 'lodash';
1010
import { isLeft } from 'fp-ts/lib/Either';
1111
import { PathReporter } from 'io-ts/lib/PathReporter';
1212
import Boom from '@hapi/boom';
13-
import { strictKeysRt } from '@kbn/io-ts-utils';
13+
import { strictKeysRt } from '@kbn/io-ts-utils/strict_keys_rt';
1414
import { RouteParamsRT } from './typings';
1515

1616
interface KibanaRequestParams {

packages/kbn-typed-react-router-config/src/create_router.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import React from 'react';
99
import * as t from 'io-ts';
10-
import { toNumberRt } from '@kbn/io-ts-utils';
10+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
1111
import { createRouter } from './create_router';
1212
import { createMemoryHistory } from 'history';
1313
import { route } from './route';

packages/kbn-typed-react-router-config/src/create_router.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@ import {
1515
} from 'react-router-config';
1616
import qs from 'query-string';
1717
import { findLastIndex, merge, compact } from 'lodash';
18-
import type { deepExactRt as deepExactRtTyped, mergeRt as mergeRtTyped } from '@kbn/io-ts-utils';
19-
// @ts-expect-error
20-
import { deepExactRt as deepExactRtNonTyped } from '@kbn/io-ts-utils/target_node/deep_exact_rt';
21-
// @ts-expect-error
22-
import { mergeRt as mergeRtNonTyped } from '@kbn/io-ts-utils/target_node/merge_rt';
18+
import { mergeRt } from '@kbn/io-ts-utils/merge_rt';
19+
import { deepExactRt } from '@kbn/io-ts-utils/deep_exact_rt';
2320
import { FlattenRoutesOf, Route, Router } from './types';
2421

25-
const deepExactRt: typeof deepExactRtTyped = deepExactRtNonTyped;
26-
const mergeRt: typeof mergeRtTyped = mergeRtNonTyped;
27-
2822
function toReactRouterPath(path: string) {
2923
return path.replace(/(?:{([^\/]+)})/g, ':$1');
3024
}

x-pack/plugins/apm/common/environment_rt.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77
import * as t from 'io-ts';
8-
import { nonEmptyStringRt } from '@kbn/io-ts-utils';
8+
import { nonEmptyStringRt } from '@kbn/io-ts-utils/non_empty_string_rt';
99
import {
1010
ENVIRONMENT_ALL,
1111
ENVIRONMENT_NOT_DEFINED,

x-pack/plugins/apm/public/components/routing/home/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
88
import { Outlet } from '@kbn/typed-react-router-config';
99
import * as t from 'io-ts';
1010
import React from 'react';
11-
import { toBooleanRt } from '@kbn/io-ts-utils';
11+
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
1212
import { RedirectTo } from '../redirect_to';
1313
import { comparisonTypeRt } from '../../../../common/runtime_types/comparison_type_rt';
1414
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';

x-pack/plugins/apm/public/components/routing/service_detail/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as t from 'io-ts';
88
import { i18n } from '@kbn/i18n';
99
import React from 'react';
1010
import { Outlet } from '@kbn/typed-react-router-config';
11-
import { toBooleanRt } from '@kbn/io-ts-utils';
11+
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
1212
import { comparisonTypeRt } from '../../../../common/runtime_types/comparison_type_rt';
1313
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
1414
import { environmentRt } from '../../../../common/environment_rt';

x-pack/plugins/apm/server/routes/backends.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as t from 'io-ts';
9-
import { toNumberRt } from '@kbn/io-ts-utils';
9+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
1010
import { setupRequest } from '../lib/helpers/setup_request';
1111
import { environmentRt, kueryRt, offsetRt, rangeRt } from './default_api_types';
1212
import { createApmServerRoute } from './create_apm_server_route';

x-pack/plugins/apm/server/routes/correlations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as t from 'io-ts';
99
import Boom from '@hapi/boom';
1010

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

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

x-pack/plugins/apm/server/routes/default_api_types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

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

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

x-pack/plugins/apm/server/routes/latency_distribution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as t from 'io-ts';
9-
import { toNumberRt } from '@kbn/io-ts-utils';
9+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
1010
import { getOverallLatencyDistribution } from '../lib/latency/get_overall_latency_distribution';
1111
import { setupRequest } from '../lib/helpers/setup_request';
1212
import { createApmServerRoute } from './create_apm_server_route';

x-pack/plugins/apm/server/routes/observability_overview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as t from 'io-ts';
9-
import { toNumberRt } from '@kbn/io-ts-utils';
9+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
1010
import { setupRequest } from '../lib/helpers/setup_request';
1111
import { getServiceCount } from '../lib/observability_overview/get_service_count';
1212
import { getTransactionsPerMinute } from '../lib/observability_overview/get_transactions_per_minute';

x-pack/plugins/apm/server/routes/register_routes/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { jsonRt } from '@kbn/io-ts-utils';
8+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
99
import { createServerRouteRepository } from '@kbn/server-route-repository';
1010
import { ServerRoute } from '@kbn/server-route-repository';
1111
import * as t from 'io-ts';

x-pack/plugins/apm/server/routes/register_routes/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
parseEndpoint,
1818
routeValidationObject,
1919
} from '@kbn/server-route-repository';
20-
import { mergeRt, jsonRt } from '@kbn/io-ts-utils';
20+
import { mergeRt } from '@kbn/io-ts-utils/merge_rt';
21+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
2122
import { pickKeys } from '../../../common/utils/pick_keys';
2223
import { APMRouteHandlerResources, TelemetryUsageCounter } from '../typings';
2324
import type { ApmPluginRequestHandlerContext } from '../typings';

x-pack/plugins/apm/server/routes/rum_client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as t from 'io-ts';
88
import { Logger } from 'kibana/server';
9-
import { isoToEpochRt } from '@kbn/io-ts-utils';
9+
import { isoToEpochRt } from '@kbn/io-ts-utils/iso_to_epoch_rt';
1010
import { setupRequest, Setup } from '../lib/helpers/setup_request';
1111
import { getClientMetrics } from '../lib/rum_client/get_client_metrics';
1212
import { getJSErrors } from '../lib/rum_client/get_js_errors';

x-pack/plugins/apm/server/routes/services.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
import Boom from '@hapi/boom';
9-
import { jsonRt, isoToEpochRt, toNumberRt } from '@kbn/io-ts-utils';
9+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
10+
import { isoToEpochRt } from '@kbn/io-ts-utils/iso_to_epoch_rt';
11+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
1012
import * as t from 'io-ts';
1113
import { uniq } from 'lodash';
1214
import { latencyAggregationTypeRt } from '../../common/latency_aggregation_types';

x-pack/plugins/apm/server/routes/settings/agent_configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as t from 'io-ts';
99
import Boom from '@hapi/boom';
10-
import { toBooleanRt } from '@kbn/io-ts-utils';
10+
import { toBooleanRt } from '@kbn/io-ts-utils/to_boolean_rt';
1111
import { maxSuggestions } from '../../../../observability/common';
1212
import { setupRequest } from '../../lib/helpers/setup_request';
1313
import { getServiceNames } from '../../lib/settings/agent_configuration/get_service_names';

x-pack/plugins/apm/server/routes/source_maps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Boom from '@hapi/boom';
88
import * as t from 'io-ts';
99
import { SavedObjectsClientContract } from 'kibana/server';
10-
import { jsonRt } from '@kbn/io-ts-utils';
10+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
1111
import {
1212
createApmArtifact,
1313
deleteApmArtifact,

x-pack/plugins/apm/server/routes/transactions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* 2.0.
66
*/
77

8-
import { jsonRt, toNumberRt } from '@kbn/io-ts-utils';
8+
import { jsonRt } from '@kbn/io-ts-utils/json_rt';
9+
import { toNumberRt } from '@kbn/io-ts-utils/to_number_rt';
910
import * as t from 'io-ts';
1011
import {
1112
LatencyAggregationType,

0 commit comments

Comments
 (0)