Skip to content

Commit

Permalink
Upgrade io-ts after fix was merged and update use of some types (#55013
Browse files Browse the repository at this point in the history
…) (#55059)

* Upgrade io-ts after fix was merged and update use of some types

* Stricter checking against object keys
  • Loading branch information
jloleysens authored Jan 16, 2020
1 parent 987532f commit 5f45273
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand All @@ -37,6 +37,6 @@ export const failure = (validation: any): ReporterResult => {
const empty: never[] = [];
const success = () => empty;

export const ErrorReporter: Reporter<ReporterResult> = {
report: (validation: Validation<any>) => fold(failure, success)(validation as any),
export const errorReporter: Reporter<ReporterResult> = {
report: fold(failure, success),
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string> = new Set();

let copyOfMappingsConfig = { ...mappingsConfiguration };
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5f45273

Please sign in to comment.