diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/constants/parameters_definition.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/constants/parameters_definition.tsx index 581b1223b7892..1277568b71bbd 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/constants/parameters_definition.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/constants/parameters_definition.tsx @@ -100,14 +100,10 @@ const fielddataFrequencyFilterParam = { }, }, }, - schema: t.intersection([ - t.partial({ - min: t.number, - max: t.number, - min_segment_size: t.number, - }), - t.brand(t.UnknownRecord, (v: any): v is any => !Array.isArray(v), 'Array'), - ]), + schema: t.record( + t.union([t.literal('min'), t.literal('max'), t.literal('min_segment_size')]), + t.number + ), }; const analyzerValidations = [ diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/error_reporter.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/error_reporter.ts index 363ccfc2a5fab..e9beee1071597 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/error_reporter.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/error_reporter.ts @@ -3,14 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { ValidationError, Validation } from 'io-ts'; +import { ValidationError } from 'io-ts'; import { fold } from 'fp-ts/lib/Either'; import { Reporter } from 'io-ts/lib/Reporter'; export type ReporterResult = Array<{ path: string[]; message: string }>; -export const failure = (validation: any): ReporterResult => { - return validation.map((e: ValidationError) => { +const failure = (validation: ValidationError[]): ReporterResult => { + return validation.map(e => { const path: string[] = []; let validationName = ''; @@ -37,6 +37,6 @@ export const failure = (validation: any): ReporterResult => { const empty: never[] = []; const success = () => empty; -export const ErrorReporter: Reporter = { - report: (validation: Validation) => fold(failure, success)(validation as any), +export const errorReporter: Reporter = { + report: fold(failure, success), }; diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts index 990d5ec961a6f..fff735da2e758 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/mappings_validator.ts @@ -8,7 +8,7 @@ import * as t from 'io-ts'; import { ordString } from 'fp-ts/lib/Ord'; import { toArray } from 'fp-ts/lib/Set'; import { isLeft, isRight } from 'fp-ts/lib/Either'; -import { ErrorReporter } from './error_reporter'; +import { errorReporter } from './error_reporter'; import { ALL_DATA_TYPES, PARAMETERS_DEFINITION } from '../constants'; import { FieldMeta } from '../types'; import { getFieldMeta } from '../lib'; @@ -218,7 +218,7 @@ const mappingsConfigurationSchemaKeys = Object.keys(mappingsConfigurationSchema. const validateMappingsConfiguration = ( mappingsConfiguration: any ): { value: any; errors: MappingsValidationError[] } => { - // Array to keep track of invalid configuration parameters. + // Set to keep track of invalid configuration parameters. const configurationRemoved: Set = new Set(); let copyOfMappingsConfig = { ...mappingsConfiguration }; @@ -228,7 +228,7 @@ const validateMappingsConfiguration = ( /** * To keep the logic simple we will strip out the parameters that contain errors */ - const errors = ErrorReporter.report(result); + const errors = errorReporter.report(result); errors.forEach(error => { const configurationName = error.path[0]; configurationRemoved.add(configurationName); diff --git a/x-pack/package.json b/x-pack/package.json index e9238ef6634d0..ff4bd37a7ab1b 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -251,7 +251,7 @@ "immer": "^1.5.0", "inline-style": "^2.0.0", "intl": "^1.2.5", - "io-ts": "^2.0.1", + "io-ts": "^2.0.5", "isbinaryfile": "4.0.2", "joi": "^13.5.2", "jquery": "^3.4.1", diff --git a/yarn.lock b/yarn.lock index 5fc1dba66de0e..9bf5bd1cba136 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16375,10 +16375,10 @@ invert-kv@^2.0.0: resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== -io-ts@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.1.tgz#1261c12f915c2f48d16393a36966636b48a45aa1" - integrity sha512-RezD+WcCfW4VkMkEcQWL/Nmy/nqsWTvTYg7oUmTGzglvSSV2P9h2z1PVeREPFf0GWNzruYleAt1XCMQZSg1xxQ== +io-ts@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.5.tgz#e6e3db9df8b047f9cbd6b69e7d2ad3e6437a0b13" + integrity sha512-pL7uUptryanI5Glv+GUv7xh+aLBjxGEDmLwmEYNSx0yOD3djK0Nw5Bt0N6BAkv9LadOUU7QKpRsLcqnTh3UlLA== ip-regex@^2.1.0: version "2.1.0"