[Security Solutions] (Phase 3, part 1) Removes dependency on security_solution plugin from lists (#99431)

## Summary

Removes the dependency of security_solution from the lists plugin

* Removes some of the deprecated types in favor of the new kbn package
* Adds a workaround in the kbn packages of removing the ?? and `a?.b?.c` typescript since kbn packages cannot transpile it
* Exposes the test_utils from the kbn package 

### Checklist
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
Frank Hassanabad 2021-05-10 10:16:19 -06:00 committed by GitHub
parent 518da5bcc1
commit c092fbfe1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
305 changed files with 1079 additions and 5414 deletions

View file

@ -46,7 +46,7 @@ pageLoadAssetSize:
lens: 96624
licenseManagement: 41817
licensing: 29004
lists: 228500
lists: 280504
logstash: 53548
management: 46112
maps: 80000

View file

@ -21,7 +21,9 @@ export const formatErrors = (errors: t.Errors): string[] => {
.map((entry) => entry.key)
.join(',');
const nameContext = error.context.find((entry) => entry.type?.name?.length > 0);
const nameContext = error.context.find(
(entry) => entry.type != null && entry.type.name != null && entry.type.name.length > 0
);
const suppliedValue =
keyContext !== '' ? keyContext : nameContext != null ? nameContext.type.name : '';
const value = isObject(error.value) ? JSON.stringify(error.value) : error.value;

View file

@ -41,12 +41,14 @@ export * from './from';
export * from './id';
export * from './iso_date_string';
export * from './language';
export * from './list_types';
export * from './max_signals';
export * from './meta';
export * from './name';
export * from './non_empty_array';
export * from './non_empty_or_nullable_string_array';
export * from './non_empty_string';
export * from './non_empty_string_array';
export * from './normalized_ml_job_id';
export * from './only_false_allowed';
export * from './operator';
@ -61,6 +63,7 @@ export * from './severity';
export * from './severity_mapping';
export * from './string_to_positive_number';
export * from './tags';
export * from './test_utils';
export * from './threat';
export * from './threat_mapping';
export * from './threat_subtechnique';

View file

@ -8,7 +8,7 @@
import * as t from 'io-ts';
import { operator } from '../operator';
import { listOperator as operator } from '../list_operator';
import { NonEmptyString } from '../../non_empty_string';
export const entriesExists = t.exact(

View file

@ -10,7 +10,7 @@ import * as t from 'io-ts';
import { NonEmptyString } from '../../non_empty_string';
import { type } from '../type';
import { operator } from '../operator';
import { listOperator as operator } from '../list_operator';
export const entriesList = t.exact(
t.type({

View file

@ -8,7 +8,7 @@
import * as t from 'io-ts';
import { NonEmptyString } from '../../non_empty_string';
import { operator } from '../operator';
import { listOperator as operator } from '../list_operator';
export const entriesMatch = t.exact(
t.type({

View file

@ -8,7 +8,7 @@
import * as t from 'io-ts';
import { operator } from '../operator';
import { listOperator as operator } from '../list_operator';
import { nonEmptyOrNullableStringArray } from '../../non_empty_or_nullable_string_array';
import { NonEmptyString } from '../../non_empty_string';

View file

@ -8,7 +8,7 @@
import * as t from 'io-ts';
import { NonEmptyString } from '../../non_empty_string';
import { operator } from '../operator';
import { listOperator as operator } from '../list_operator';
export const entriesMatchWildcard = t.exact(
t.type({

View file

@ -8,10 +8,11 @@
export * from './comment';
export * from './create_comment';
export * from './default_comments_array';
export * from './default_comments_array';
export * from './default_create_comments_array';
export * from './default_namespace';
export * from './default_namespace_array';
export * from './default_update_comments_array';
export * from './endpoint';
export * from './entries';
export * from './entries_exist';
export * from './entries_list';
@ -26,7 +27,7 @@ export * from './lists';
export * from './lists_default_array';
export * from './non_empty_entries_array';
export * from './non_empty_nested_entries_array';
export * from './operator';
export * from './list_operator';
export * from './os_type';
export * from './type';
export * from './update_comment';

View file

@ -8,14 +8,14 @@
import * as t from 'io-ts';
export const operator = t.keyof({ excluded: null, included: null });
export type Operator = t.TypeOf<typeof operator>;
export enum OperatorEnum {
export const listOperator = t.keyof({ excluded: null, included: null });
export type ListOperator = t.TypeOf<typeof listOperator>;
export enum ListOperatorEnum {
INCLUDED = 'included',
EXCLUDED = 'excluded',
}
export enum OperatorTypeEnum {
export enum ListOperatorTypeEnum {
NESTED = 'nested',
MATCH = 'match',
MATCH_ANY = 'match_any',

View file

@ -37,3 +37,6 @@ export const type = t.keyof({
short: null,
text: null,
});
export const typeOrUndefined = t.union([type, t.undefined]);
export type Type = t.TypeOf<typeof type>;

View file

@ -1,16 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import { foldLeftRight, getPaths } from '../../shared_imports';
import { NonEmptyStringArray } from './non_empty_string_array';
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { NonEmptyStringArray } from '.';
describe('non_empty_string_array', () => {
test('it should FAIL validation when given "null"', () => {

View file

@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import * as t from 'io-ts';
@ -13,7 +14,6 @@ import { Either } from 'fp-ts/lib/Either';
* - A string that is not empty (which will be turned into an array of size 1)
* - A comma separated string that can turn into an array by splitting on it
* - Example input converted to output: "a,b,c" -> ["a", "b", "c"]
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const NonEmptyStringArray = new t.Type<string[], string, unknown>(
'NonEmptyStringArray',
@ -37,12 +37,6 @@ export const NonEmptyStringArray = new t.Type<string[], string, unknown>(
String
);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type NonEmptyStringArray = t.OutputOf<typeof NonEmptyStringArray>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type NonEmptyStringArrayDecoded = t.TypeOf<typeof NonEmptyStringArray>;

View file

@ -22,5 +22,5 @@ export const parseScheduleDates = (time: string): moment.Moment | null => {
? dateMath.parse(time)
: null;
return formattedDate ?? null;
return formattedDate != null ? formattedDate : null;
};

View file

@ -6,10 +6,15 @@
*/
import moment from 'moment';
import {
EndpointEntriesArray,
EntriesArray,
Entry,
EntryMatch,
EntryNested,
OsTypeArray,
} from '@kbn/securitysolution-io-ts-utils';
import { OsTypeArray } from './schemas/common';
import { EntriesArray, Entry, EntryMatch, EntryNested } from './schemas/types';
import { EndpointEntriesArray } from './schemas/types/endpoint';
export const DATE_NOW = '2020-04-20T15:25:31.830Z';
export const OLD_DATE_RELATIVE_TO_DATE_NOW = '2020-04-19T15:25:31.830Z';
export const USER = 'some user';

View file

@ -5,6 +5,8 @@
* 2.0.
*/
import { EntryMatchAny } from '@kbn/securitysolution-io-ts-utils';
import { getEntryMatchExcludeMock, getEntryMatchMock } from '../schemas/types/entry_match.mock';
import {
getEntryMatchAnyExcludeMock,
@ -16,14 +18,10 @@ import {
getEntryNestedMixedEntries,
getEntryNestedMock,
} from '../schemas/types/entry_nested.mock';
import {
getExceptionListItemSchemaMock,
getExceptionListItemSchemaXMock,
} from '../schemas/response/exception_list_item_schema.mock';
import { EntryMatchAny, ExceptionListItemSchema } from '../schemas';
import { getExceptionListItemSchemaMock } from '../schemas/response/exception_list_item_schema.mock';
import { ExceptionListItemSchema } from '../schemas';
import {
ExceptionItemSansLargeValueLists,
buildExceptionFilter,
buildExceptionItemFilter,
buildExclusionClause,
@ -31,10 +29,8 @@ import {
buildMatchAnyClause,
buildMatchClause,
buildNestedClause,
chunkExceptions,
createOrClauses,
} from './build_exceptions_filter';
import { hasLargeValueList } from './utils';
const modifiedGetEntryMatchAnyMock = (): EntryMatchAny => ({
...getEntryMatchAnyMock(),
@ -42,13 +38,6 @@ const modifiedGetEntryMatchAnyMock = (): EntryMatchAny => ({
value: ['some "host" name', 'some other host name'],
});
const getExceptionListItemsWoValueLists = (num: number): ExceptionItemSansLargeValueLists[] => {
const items = getExceptionListItemSchemaXMock(num);
return items.filter(
({ entries }) => !hasLargeValueList(entries)
) as ExceptionItemSansLargeValueLists[];
};
describe('build_exceptions_filter', () => {
describe('buildExceptionFilter', () => {
test('it should return undefined if no exception items', () => {
@ -431,55 +420,6 @@ describe('build_exceptions_filter', () => {
});
});
describe('chunkExceptions', () => {
test('it should NOT split a single should clause as there is nothing to split on with chunkSize 1', () => {
const exceptions = getExceptionListItemsWoValueLists(1);
const chunks = chunkExceptions(exceptions, 1);
expect(chunks).toHaveLength(1);
});
test('it should NOT split a single should clause as there is nothing to split on with chunkSize 2', () => {
const exceptions = getExceptionListItemsWoValueLists(1) as ExceptionItemSansLargeValueLists[];
const chunks = chunkExceptions(exceptions, 2);
expect(chunks).toHaveLength(1);
});
test('it should return an empty array if no exception items passed in', () => {
const chunks = chunkExceptions([], 2);
expect(chunks).toEqual([]);
});
test('it should split an array of size 2 into a length 2 array with chunks on "chunkSize: 1"', () => {
const exceptions = getExceptionListItemsWoValueLists(2);
const chunks = chunkExceptions(exceptions, 1);
expect(chunks).toHaveLength(2);
});
test('it should split an array of size 2 into a length 4 array with chunks on "chunkSize: 1"', () => {
const exceptions = getExceptionListItemsWoValueLists(4);
const chunks = chunkExceptions(exceptions, 1);
expect(chunks).toHaveLength(4);
});
test('it should split an array of size 4 into a length 2 array with chunks on "chunkSize: 2"', () => {
const exceptions = getExceptionListItemsWoValueLists(4);
const chunks = chunkExceptions(exceptions, 2);
expect(chunks).toHaveLength(2);
});
test('it should NOT split an array of size 4 into any groups on "chunkSize: 5"', () => {
const exceptions = getExceptionListItemsWoValueLists(4);
const chunks = chunkExceptions(exceptions, 5);
expect(chunks).toHaveLength(1);
});
test('it should split an array of size 4 into 2 groups on "chunkSize: 3"', () => {
const exceptions = getExceptionListItemsWoValueLists(4);
const chunks = chunkExceptions(exceptions, 3);
expect(chunks).toHaveLength(2);
});
});
describe('createOrClauses', () => {
test('it should create filter with one item if only one exception item exists', () => {
const booleanFilter = createOrClauses([

View file

@ -6,20 +6,19 @@
*/
import { chunk } from 'lodash/fp';
import { Filter } from '../../../../../src/plugins/data/common';
import {
CreateExceptionListItemSchema,
EntryExists,
EntryMatch,
EntryMatchAny,
EntryNested,
ExceptionListItemSchema,
entriesExists,
entriesMatch,
entriesMatchAny,
entriesNested,
} from '../schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { Filter } from '../../../../../src/plugins/data/common';
import { CreateExceptionListItemSchema, ExceptionListItemSchema } from '../schemas';
import { BooleanFilter, NestedFilter } from './types';
import { hasLargeValueList } from './utils';

View file

@ -5,20 +5,9 @@
* 2.0.
*/
import { CreateExceptionListItemSchema, EntriesArray, ExceptionListItemSchema } from '../schemas';
export const hasLargeValueItem = (
exceptionItems: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>
): boolean => {
return exceptionItems.some((exceptionItem) => hasLargeValueList(exceptionItem.entries));
};
import { EntriesArray } from '@kbn/securitysolution-io-ts-utils';
export const hasLargeValueList = (entries: EntriesArray): boolean => {
const found = entries.filter(({ type }) => type === 'list');
return found.length > 0;
};
export const hasNestedEntry = (entries: EntriesArray): boolean => {
const found = entries.filter(({ type }) => type === 'nested');
return found.length > 0;
};

View file

@ -1,189 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { formatErrors } from './format_errors';
describe('utils', () => {
test('returns an empty error message string if there are no errors', () => {
const errors: t.Errors = [];
const output = formatErrors(errors);
expect(output).toEqual([]);
});
test('returns a single error message if given one', () => {
const validationError: t.ValidationError = {
context: [],
message: 'some error',
value: 'Some existing error',
};
const errors: t.Errors = [validationError];
const output = formatErrors(errors);
expect(output).toEqual(['some error']);
});
test('returns a two error messages if given two', () => {
const validationError1: t.ValidationError = {
context: [],
message: 'some error 1',
value: 'Some existing error 1',
};
const validationError2: t.ValidationError = {
context: [],
message: 'some error 2',
value: 'Some existing error 2',
};
const errors: t.Errors = [validationError1, validationError2];
const output = formatErrors(errors);
expect(output).toEqual(['some error 1', 'some error 2']);
});
test('it filters out duplicate error messages', () => {
const validationError1: t.ValidationError = {
context: [],
message: 'some error 1',
value: 'Some existing error 1',
};
const validationError2: t.ValidationError = {
context: [],
message: 'some error 1',
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1, validationError2];
const output = formatErrors(errors);
expect(output).toEqual(['some error 1']);
});
test('will use message before context if it is set', () => {
const context: t.Context = ([{ key: 'some string key' }] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
message: 'I should be used first',
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual(['I should be used first']);
});
test('will use context entry of a single string', () => {
const context: t.Context = ([{ key: 'some string key' }] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual(['Invalid value "Some existing error 1" supplied to "some string key"']);
});
test('will use two context entries of two strings', () => {
const context: t.Context = ([
{ key: 'some string key 1' },
{ key: 'some string key 2' },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual([
'Invalid value "Some existing error 1" supplied to "some string key 1,some string key 2"',
]);
});
test('will filter out and not use any strings of numbers', () => {
const context: t.Context = ([
{ key: '5' },
{ key: 'some string key 2' },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual([
'Invalid value "Some existing error 1" supplied to "some string key 2"',
]);
});
test('will filter out and not use null', () => {
const context: t.Context = ([
{ key: null },
{ key: 'some string key 2' },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual([
'Invalid value "Some existing error 1" supplied to "some string key 2"',
]);
});
test('will filter out and not use empty strings', () => {
const context: t.Context = ([
{ key: '' },
{ key: 'some string key 2' },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual([
'Invalid value "Some existing error 1" supplied to "some string key 2"',
]);
});
test('will use a name context if it cannot find a keyContext', () => {
const context: t.Context = ([
{ key: '' },
{ key: '', type: { name: 'someName' } },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual(['Invalid value "Some existing error 1" supplied to "someName"']);
});
test('will return an empty string if name does not exist but type does', () => {
const context: t.Context = ([{ key: '' }, { key: '', type: {} }] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: 'Some existing error 1',
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual(['Invalid value "Some existing error 1" supplied to ""']);
});
test('will stringify an error value', () => {
const context: t.Context = ([
{ key: '' },
{ key: 'some string key 2' },
] as unknown) as t.Context;
const validationError1: t.ValidationError = {
context,
value: { foo: 'some error' },
};
const errors: t.Errors = [validationError1];
const output = formatErrors(errors);
expect(output).toEqual([
'Invalid value "{"foo":"some error"}" supplied to "some string key 2"',
]);
});
});

View file

@ -1,35 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as t from 'io-ts';
import { isObject } from 'lodash/fp';
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/format_errors/index.ts
*/
export const formatErrors = (errors: t.Errors): string[] => {
const err = errors.map((error) => {
if (error.message != null) {
return error.message;
} else {
const keyContext = error.context
.filter(
(entry) => entry.key != null && !Number.isInteger(+entry.key) && entry.key.trim() !== ''
)
.map((entry) => entry.key)
.join(',');
const nameContext = error.context.find((entry) => entry.type?.name?.length > 0);
const suppliedValue =
keyContext !== '' ? keyContext : nameContext != null ? nameContext.type.name : '';
const value = isObject(error.value) ? JSON.stringify(error.value) : error.value;
return `Invalid value "${value}" supplied to "${suppliedValue}"`;
}
});
return [...new Set(err)];
};

View file

@ -7,31 +7,19 @@
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import {
EsDataTypeGeoPoint,
EsDataTypeGeoPointRange,
EsDataTypeRange,
EsDataTypeRangeTerm,
EsDataTypeSingle,
EsDataTypeUnion,
ExceptionListTypeEnum,
OperatorEnum,
ListOperatorEnum as OperatorEnum,
Type,
esDataTypeGeoPoint,
esDataTypeGeoPointRange,
esDataTypeRange,
esDataTypeRangeTerm,
esDataTypeSingle,
esDataTypeUnion,
exactCheck,
exceptionListType,
operator,
foldLeftRight,
getPaths,
listOperator as operator,
osType,
osTypeArrayOrUndefined,
type,
} from './schemas';
} from '@kbn/securitysolution-io-ts-utils';
describe('Common schemas', () => {
describe('operator', () => {
@ -120,269 +108,6 @@ describe('Common schemas', () => {
});
});
describe('esDataTypeRange', () => {
test('it will work with a given gte, lte range', () => {
const payload: EsDataTypeRange = { gte: '127.0.0.1', lte: '127.0.0.1' };
const decoded = esDataTypeRange.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value', () => {
const payload: EsDataTypeRange & { madeupvalue: string } = {
gte: '127.0.0.1',
lte: '127.0.0.1',
madeupvalue: 'something',
};
const decoded = esDataTypeRange.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
});
describe('esDataTypeRangeTerm', () => {
test('it will work with a date_range', () => {
const payload: EsDataTypeRangeTerm = { date_range: { gte: '2015', lte: '2017' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for date_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
date_range: { gte: '2015', lte: '2017' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
test('it will work with a double_range', () => {
const payload: EsDataTypeRangeTerm = { double_range: { gte: '2015', lte: '2017' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for double_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
double_range: { gte: '2015', lte: '2017' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
test('it will work with a float_range', () => {
const payload: EsDataTypeRangeTerm = { float_range: { gte: '2015', lte: '2017' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for float_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
float_range: { gte: '2015', lte: '2017' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
test('it will work with a integer_range', () => {
const payload: EsDataTypeRangeTerm = { integer_range: { gte: '2015', lte: '2017' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for integer_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
integer_range: { gte: '2015', lte: '2017' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
test('it will work with a ip_range', () => {
const payload: EsDataTypeRangeTerm = { ip_range: { gte: '127.0.0.1', lte: '127.0.0.2' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will work with a ip_range as a CIDR', () => {
const payload: EsDataTypeRangeTerm = { ip_range: '127.0.0.1/16' };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for ip_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
ip_range: { gte: '127.0.0.1', lte: '127.0.0.2' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
test('it will work with a long_range', () => {
const payload: EsDataTypeRangeTerm = { long_range: { gte: '2015', lte: '2017' } };
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value for long_range', () => {
const payload: EsDataTypeRangeTerm & { madeupvalue: string } = {
long_range: { gte: '2015', lte: '2017' },
madeupvalue: 'something',
};
const decoded = esDataTypeRangeTerm.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
});
describe('esDataTypeGeoPointRange', () => {
test('it will work with a given lat, lon range', () => {
const payload: EsDataTypeGeoPointRange = { lat: '20', lon: '30' };
const decoded = esDataTypeGeoPointRange.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value', () => {
const payload: EsDataTypeGeoPointRange & { madeupvalue: string } = {
lat: '20',
lon: '30',
madeupvalue: 'something',
};
const decoded = esDataTypeGeoPointRange.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
});
describe('esDataTypeGeoPoint', () => {
test('it will work with a given lat, lon range', () => {
const payload: EsDataTypeGeoPoint = { geo_point: { lat: '127.0.0.1', lon: '127.0.0.1' } };
const decoded = esDataTypeGeoPoint.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will work with a WKT (Well known text)', () => {
const payload: EsDataTypeGeoPoint = { geo_point: 'POINT (30 10)' };
const decoded = esDataTypeGeoPoint.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will give an error if given an extra madeup value', () => {
const payload: EsDataTypeGeoPoint & { madeupvalue: string } = {
geo_point: 'POINT (30 10)',
madeupvalue: 'something',
};
const decoded = esDataTypeGeoPoint.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupvalue"']);
expect(message.schema).toEqual({});
});
});
describe('esDataTypeSingle', () => {
test('it will work with single type', () => {
const payload: EsDataTypeSingle = { boolean: 'true' };
const decoded = esDataTypeSingle.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will not work with a madeup value', () => {
const payload: EsDataTypeSingle & { madeupValue: 'madeup' } = {
boolean: 'true',
madeupValue: 'madeup',
};
const decoded = esDataTypeSingle.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupValue"']);
expect(message.schema).toEqual({});
});
});
describe('esDataTypeUnion', () => {
test('it will work with a regular union', () => {
const payload: EsDataTypeUnion = { boolean: 'true' };
const decoded = esDataTypeUnion.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it will not work with a madeup value', () => {
const payload: EsDataTypeUnion & { madeupValue: 'madeupValue' } = {
boolean: 'true',
madeupValue: 'madeupValue',
};
const decoded = esDataTypeUnion.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['invalid keys "madeupValue"']);
expect(message.schema).toEqual({});
});
});
describe('osType', () => {
test('it will validate a correct osType', () => {
const payload = 'windows';

View file

@ -8,49 +8,18 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as t from 'io-ts';
import { DefaultNamespace } from '../types/default_namespace';
import { DefaultArray, DefaultStringArray, NonEmptyString } from '../../shared_imports';
import { DefaultNamespace, NonEmptyString } from '@kbn/securitysolution-io-ts-utils';
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
* @deprecated Directly use the type from the package and not from here
*/
export const name = t.string;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Name = t.TypeOf<typeof name>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const nameOrUndefined = t.union([name, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type NameOrUndefined = t.TypeOf<typeof nameOrUndefined>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const description = t.string;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Description = t.TypeOf<typeof description>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const descriptionOrUndefined = t.union([description, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type DescriptionOrUndefined = t.TypeOf<typeof descriptionOrUndefined>;
export {
Type,
OsType,
OsTypeArray,
listOperator as operator,
NonEmptyEntriesArray,
} from '@kbn/securitysolution-io-ts-utils';
export const list_id = NonEmptyString;
export type ListId = t.TypeOf<typeof list_id>;
@ -59,307 +28,7 @@ export type ListIdOrUndefined = t.TypeOf<typeof list_idOrUndefined>;
export const item = t.string;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const created_at = t.string; // TODO: Make this into an ISO Date string check
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const updated_at = t.string; // TODO: Make this into an ISO Date string check
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const updated_by = t.string;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const created_by = t.string;
export const file = t.object;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const id = NonEmptyString;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Id = t.TypeOf<typeof id>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const idOrUndefined = t.union([id, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type IdOrUndefined = t.TypeOf<typeof idOrUndefined>;
export const binary = t.string;
export const binaryOrUndefined = t.union([binary, t.undefined]);
export const boolean = t.string;
export const booleanOrUndefined = t.union([boolean, t.undefined]);
export const byte = t.string;
export const byteOrUndefined = t.union([byte, t.undefined]);
export const date = t.string;
export const dateOrUndefined = t.union([date, t.undefined]);
export const date_nanos = t.string;
export const dateNanosOrUndefined = t.union([date_nanos, t.undefined]);
export const double = t.string;
export const doubleOrUndefined = t.union([double, t.undefined]);
export const float = t.string;
export const floatOrUndefined = t.union([float, t.undefined]);
export const geo_shape = t.string;
export const geoShapeOrUndefined = t.union([geo_shape, t.undefined]);
export const half_float = t.string;
export const halfFloatOrUndefined = t.union([half_float, t.undefined]);
export const integer = t.string;
export const integerOrUndefined = t.union([integer, t.undefined]);
export const ip = t.string;
export const ipOrUndefined = t.union([ip, t.undefined]);
export const keyword = t.string;
export const keywordOrUndefined = t.union([keyword, t.undefined]);
export const text = t.string;
export const textOrUndefined = t.union([text, t.undefined]);
export const long = t.string;
export const longOrUndefined = t.union([long, t.undefined]);
export const shape = t.string;
export const shapeOrUndefined = t.union([shape, t.undefined]);
export const short = t.string;
export const shortOrUndefined = t.union([short, t.undefined]);
export const value = t.string;
export const valueOrUndefined = t.union([value, t.undefined]);
export const tie_breaker_id = t.string; // TODO: Use UUID for this instead of a string for validation
export const _index = t.string;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const type = t.keyof({
binary: null,
boolean: null,
byte: null,
date: null,
date_nanos: null,
date_range: null,
double: null,
double_range: null,
float: null,
float_range: null,
geo_point: null,
geo_shape: null,
half_float: null,
integer: null,
integer_range: null,
ip: null,
ip_range: null,
keyword: null,
long: null,
long_range: null,
shape: null,
short: null,
text: null,
});
export const typeOrUndefined = t.union([type, t.undefined]);
export type Type = t.TypeOf<typeof type>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const meta = t.object;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Meta = t.TypeOf<typeof meta>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const metaOrUndefined = t.union([meta, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type MetaOrUndefined = t.TypeOf<typeof metaOrUndefined>;
export const esDataTypeRange = t.exact(t.type({ gte: t.string, lte: t.string }));
export const date_range = esDataTypeRange;
export const dateRangeOrUndefined = t.union([date_range, t.undefined]);
export const double_range = esDataTypeRange;
export const doubleRangeOrUndefined = t.union([double_range, t.undefined]);
export const float_range = esDataTypeRange;
export const floatRangeOrUndefined = t.union([float_range, t.undefined]);
export const integer_range = esDataTypeRange;
export const integerRangeOrUndefined = t.union([integer_range, t.undefined]);
// ip_range can be just a CIDR value as a range
export const ip_range = t.union([esDataTypeRange, t.string]);
export const ipRangeOrUndefined = t.union([ip_range, t.undefined]);
export const long_range = esDataTypeRange;
export const longRangeOrUndefined = t.union([long_range, t.undefined]);
export type EsDataTypeRange = t.TypeOf<typeof esDataTypeRange>;
export const esDataTypeRangeTerm = t.union([
t.exact(t.type({ date_range })),
t.exact(t.type({ double_range })),
t.exact(t.type({ float_range })),
t.exact(t.type({ integer_range })),
t.exact(t.type({ ip_range })),
t.exact(t.type({ long_range })),
]);
export type EsDataTypeRangeTerm = t.TypeOf<typeof esDataTypeRangeTerm>;
export const esDataTypeGeoPointRange = t.exact(t.type({ lat: t.string, lon: t.string }));
export type EsDataTypeGeoPointRange = t.TypeOf<typeof esDataTypeGeoPointRange>;
export const geo_point = t.union([esDataTypeGeoPointRange, t.string]);
export type GeoPoint = t.TypeOf<typeof geo_point>;
export const geoPointOrUndefined = t.union([geo_point, t.undefined]);
export const esDataTypeGeoPoint = t.exact(t.type({ geo_point }));
export type EsDataTypeGeoPoint = t.TypeOf<typeof esDataTypeGeoPoint>;
export const esDataTypeGeoShape = t.union([
t.exact(t.type({ geo_shape: t.string })),
t.exact(t.type({ shape: t.string })),
]);
export type EsDataTypeGeoShape = t.TypeOf<typeof esDataTypeGeoShape>;
export const esDataTypeSingle = t.union([
t.exact(t.type({ binary })),
t.exact(t.type({ boolean })),
t.exact(t.type({ byte })),
t.exact(t.type({ date })),
t.exact(t.type({ date_nanos })),
t.exact(t.type({ double })),
t.exact(t.type({ float })),
t.exact(t.type({ half_float })),
t.exact(t.type({ integer })),
t.exact(t.type({ ip })),
t.exact(t.type({ keyword })),
t.exact(t.type({ long })),
t.exact(t.type({ short })),
t.exact(t.type({ text })),
]);
export type EsDataTypeSingle = t.TypeOf<typeof esDataTypeSingle>;
export const esDataTypeUnion = t.union([
esDataTypeRangeTerm,
esDataTypeGeoPoint,
esDataTypeGeoShape,
esDataTypeSingle,
]);
export type EsDataTypeUnion = t.TypeOf<typeof esDataTypeUnion>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const tags = DefaultStringArray;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Tags = t.TypeOf<typeof tags>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const tagsOrUndefined = t.union([tags, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type TagsOrUndefined = t.TypeOf<typeof tagsOrUndefined>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const exceptionListType = t.keyof({
detection: null,
endpoint: null,
endpoint_events: null,
});
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const exceptionListTypeOrUndefined = t.union([exceptionListType, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type ExceptionListType = t.TypeOf<typeof exceptionListType>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type ExceptionListTypeOrUndefined = t.TypeOf<typeof exceptionListTypeOrUndefined>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export enum ExceptionListTypeEnum {
DETECTION = 'detection',
ENDPOINT = 'endpoint',
ENDPOINT_EVENTS = 'endpoint_events',
}
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const exceptionListItemType = t.keyof({ simple: null });
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const exceptionListItemTypeOrUndefined = t.union([exceptionListItemType, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type ExceptionListItemType = t.TypeOf<typeof exceptionListItemType>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type ExceptionListItemTypeOrUndefined = t.TypeOf<typeof exceptionListItemTypeOrUndefined>;
export const list_type = t.keyof({ item: null, list: null });
export type ListType = t.TypeOf<typeof list_type>;
@ -404,41 +73,6 @@ export type CursorOrUndefined = t.TypeOf<typeof cursorOrUndefined>;
export const namespace_type = DefaultNamespace;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const operatorIncluded = t.keyof({ included: null });
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const operator = t.keyof({ excluded: null, included: null });
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type Operator = t.TypeOf<typeof operator>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export enum OperatorEnum {
INCLUDED = 'included',
EXCLUDED = 'excluded',
}
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export enum OperatorTypeEnum {
NESTED = 'nested',
MATCH = 'match',
MATCH_ANY = 'match_any',
WILDCARD = 'wildcard',
EXISTS = 'exists',
LIST = 'list',
}
export const serializer = t.string;
export type Serializer = t.TypeOf<typeof serializer>;
@ -467,36 +101,7 @@ export type Immutable = t.TypeOf<typeof immutable>;
export const immutableOrUndefined = t.union([immutable, t.undefined]);
export type ImmutableOrUndefined = t.TypeOf<typeof immutableOrUndefined>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const osType = t.keyof({
linux: null,
macos: null,
windows: null,
});
export const value = t.string;
export const valueOrUndefined = t.union([value, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type OsType = t.TypeOf<typeof osType>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const osTypeArray = DefaultArray(osType);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type OsTypeArray = t.TypeOf<typeof osTypeArray>;
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export const osTypeArrayOrUndefined = t.union([osTypeArray, t.undefined]);
/**
* @deprecated Use packages/kbn-securitysolution-io-ts-utils
*/
export type OsTypeArrayOrUndefined = t.OutputOf<typeof osTypeArray>;
export const tie_breaker_id = t.string; // TODO: Use UUID for this instead of a string for validation

View file

@ -6,9 +6,5 @@
*/
export * from './common';
export * from './elastic_query';
export * from './elastic_response';
export * from './request';
export * from './response';
export * from './saved_objects';
export * from './types';

View file

@ -7,11 +7,15 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import {
CommentsArray,
exactCheck,
foldLeftRight,
getPaths,
} from '@kbn/securitysolution-io-ts-utils';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { getCreateCommentsArrayMock } from '../types/create_comment.mock';
import { getCommentsMock } from '../types/comment.mock';
import { CommentsArray } from '../types';
import {
CreateEndpointListItemSchema,

View file

@ -6,23 +6,24 @@
*/
import * as t from 'io-ts';
import {
ItemId,
CreateCommentsArray,
DefaultCreateCommentsArray,
DefaultUuid,
EntriesArray,
OsTypeArray,
Tags,
description,
exceptionListItemType,
meta,
name,
nonEmptyEndpointEntriesArray,
osTypeArrayOrUndefined,
tags,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { ItemId } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { CreateCommentsArray, DefaultCreateCommentsArray } from '../types';
import { nonEmptyEndpointEntriesArray } from '../types/endpoint';
import { EntriesArray } from '../types/entries';
import { DefaultUuid } from '../../shared_imports';
export const createEndpointListItemSchema = t.intersection([
t.exact(

View file

@ -7,11 +7,15 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import {
CommentsArray,
exactCheck,
foldLeftRight,
getPaths,
} from '@kbn/securitysolution-io-ts-utils';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { getCreateCommentsArrayMock } from '../types/create_comment.mock';
import { getCommentsMock } from '../types/comment.mock';
import { CommentsArray } from '../types';
import {
CreateExceptionListItemSchema,

View file

@ -6,29 +6,25 @@
*/
import * as t from 'io-ts';
import {
ItemId,
CreateCommentsArray,
DefaultCreateCommentsArray,
DefaultUuid,
EntriesArray,
NamespaceType,
OsTypeArray,
Tags,
description,
exceptionListItemType,
list_id,
meta,
name,
namespace_type,
nonEmptyEntriesArray,
osTypeArrayOrUndefined,
tags,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { ItemId, list_id, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import {
CreateCommentsArray,
DefaultCreateCommentsArray,
NamespaceType,
nonEmptyEntriesArray,
} from '../types';
import { EntriesArray } from '../types/entries';
import { DefaultUuid } from '../../shared_imports';
export const createExceptionListItemSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
CreateExceptionListSchema,

View file

@ -6,26 +6,23 @@
*/
import * as t from 'io-ts';
import {
ListId,
DefaultUuid,
DefaultVersionNumber,
DefaultVersionNumberDecoded,
NamespaceType,
OsTypeArray,
Tags,
description,
exceptionListType,
meta,
name,
namespace_type,
osTypeArrayOrUndefined,
tags,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { ListId, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import {
DefaultUuid,
DefaultVersionNumber,
DefaultVersionNumberDecoded,
} from '../../shared_imports';
import { NamespaceType } from '../types';
export const createExceptionListSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getCreateListItemSchemaMock } from './create_list_item_schema.mock';
import { CreateListItemSchema, createListItemSchema } from './create_list_item_schema';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id, meta } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, meta, value } from '../common/schemas';
import { list_id, value } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const createListItemSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { CreateListSchema, createListSchema } from './create_list_schema';
import { getCreateListSchemaMock } from './create_list_schema.mock';

View file

@ -6,10 +6,18 @@
*/
import * as t from 'io-ts';
import {
DefaultVersionNumber,
DefaultVersionNumberDecoded,
description,
id,
meta,
name,
type,
} from '@kbn/securitysolution-io-ts-utils';
import { description, deserializer, id, meta, name, serializer, type } from '../common/schemas';
import { deserializer, serializer } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { DefaultVersionNumber, DefaultVersionNumberDecoded } from '../../shared_imports';
export const createListSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
DeleteEndpointListItemSchema,

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id } from '@kbn/securitysolution-io-ts-utils';
import { id, item_id } from '../common/schemas';
import { item_id } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const deleteEndpointListItemSchema = t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
DeleteExceptionListItemSchema,

View file

@ -6,9 +6,9 @@
*/
import * as t from 'io-ts';
import { NamespaceType, id } from '@kbn/securitysolution-io-ts-utils';
import { id, item_id, namespace_type } from '../common/schemas';
import { NamespaceType } from '../types';
import { item_id, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const deleteExceptionListItemSchema = t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
DeleteExceptionListSchema,

View file

@ -6,9 +6,9 @@
*/
import * as t from 'io-ts';
import { NamespaceType, id } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, namespace_type } from '../common/schemas';
import { NamespaceType } from '../types';
import { list_id, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const deleteExceptionListSchema = t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { DeleteListItemSchema, deleteListItemSchema } from './delete_list_item_schema';
import { getDeleteListItemSchemaMock } from './delete_list_item_schema.mock';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, valueOrUndefined } from '../common/schemas';
import { list_id, valueOrUndefined } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const deleteListItemSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { DeleteListSchema, deleteListSchema } from './delete_list_schema';
import { getDeleteListSchemaMock } from './delete_list_schema.mock';

View file

@ -6,10 +6,9 @@
*/
import * as t from 'io-ts';
import { DefaultStringBooleanFalse, id } from '@kbn/securitysolution-io-ts-utils';
import { id } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { DefaultStringBooleanFalse } from '../types/default_string_boolean_false';
export const deleteListSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
ExportExceptionListQuerySchema,

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, namespace_type } from '../common/schemas';
import { list_id, namespace_type } from '../common/schemas';
export const exportExceptionListQuerySchema = t.exact(
t.type({

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
ExportListItemQuerySchema,

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
getFindEndpointListItemSchemaDecodedMock,

View file

@ -6,10 +6,10 @@
*/
import * as t from 'io-ts';
import { StringToPositiveNumber } from '@kbn/securitysolution-io-ts-utils';
import { filter, sort_field, sort_order } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { StringToPositiveNumber } from '../types/string_to_positive_number';
export const findEndpointListItemSchema = t.exact(
t.partial({

View file

@ -7,8 +7,8 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { LIST_ID } from '../../constants.mock';
import {

View file

@ -6,16 +6,17 @@
*/
import * as t from 'io-ts';
import { sort_field, sort_order } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { StringToPositiveNumber } from '../types/string_to_positive_number';
import {
DefaultNamespaceArray,
DefaultNamespaceArrayTypeDecoded,
} from '../types/default_namespace_array';
import { NonEmptyStringArray } from '../types/non_empty_string_array';
import { EmptyStringArray, EmptyStringArrayDecoded } from '../types/empty_string_array';
EmptyStringArray,
EmptyStringArrayDecoded,
NonEmptyStringArray,
StringToPositiveNumber,
} from '@kbn/securitysolution-io-ts-utils';
import { sort_field, sort_order } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const findExceptionListItemSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
getFindExceptionListSchemaDecodedMock,

View file

@ -6,11 +6,14 @@
*/
import * as t from 'io-ts';
import {
DefaultNamespaceArray,
NamespaceTypeArray,
StringToPositiveNumber,
} from '@kbn/securitysolution-io-ts-utils';
import { filter, sort_field, sort_order } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { StringToPositiveNumber } from '../types/string_to_positive_number';
import { DefaultNamespaceArray, NamespaceTypeArray } from '../types/default_namespace_array';
export const findExceptionListSchema = t.exact(
t.partial({

View file

@ -7,8 +7,8 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { LIST_ID } from '../../constants.mock';
import {

View file

@ -6,10 +6,10 @@
*/
import * as t from 'io-ts';
import { StringToPositiveNumber } from '@kbn/securitysolution-io-ts-utils';
import { cursor, filter, list_id, sort_field, sort_order } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { StringToPositiveNumber } from '../types/string_to_positive_number';
export const findListItemSchema = t.intersection([
t.exact(t.type({ list_id })),

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getFindListSchemaDecodedMock, getFindListSchemaMock } from './find_list_schema.mock';
import { FindListSchemaEncoded, findListSchema } from './find_list_schema';

View file

@ -6,9 +6,9 @@
*/
import * as t from 'io-ts';
import { StringToPositiveNumber } from '@kbn/securitysolution-io-ts-utils';
import { cursor, filter, sort_field, sort_order } from '../common/schemas';
import { StringToPositiveNumber } from '../types/string_to_positive_number';
import { RequiredKeepUndefined } from '../../types';
export const findListSchema = t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
ImportListItemQuerySchema,

View file

@ -6,9 +6,10 @@
*/
import * as t from 'io-ts';
import { type } from '@kbn/securitysolution-io-ts-utils';
import { RequiredKeepUndefined } from '../../types';
import { deserializer, list_id, serializer, type } from '../common/schemas';
import { deserializer, list_id, serializer } from '../common/schemas';
export const importListItemQuerySchema = t.exact(
t.partial({ deserializer, list_id, serializer, type })

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { ImportListItemSchema, importListItemSchema } from './import_list_item_schema';
import { getImportListItemSchemaMock } from './import_list_item_schema.mock';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getPathListItemSchemaMock } from './patch_list_item_schema.mock';
import { PatchListItemSchema, patchListItemSchema } from './patch_list_item_schema';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id, meta } from '@kbn/securitysolution-io-ts-utils';
import { _version, id, meta, value } from '../common/schemas';
import { _version, value } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const patchListItemSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getPathListSchemaMock } from './patch_list_schema.mock';
import { PatchListSchema, patchListSchema } from './patch_list_schema';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { description, id, meta, name } from '@kbn/securitysolution-io-ts-utils';
import { _version, description, id, meta, name, version } from '../common/schemas';
import { _version, version } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const patchListSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getReadEndpointListItemSchemaMock } from './read_endpoint_list_item_schema.mock';
import {

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id } from '@kbn/securitysolution-io-ts-utils';
import { id, item_id } from '../common/schemas';
import { item_id } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const readEndpointListItemSchema = t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getReadExceptionListItemSchemaMock } from './read_exception_list_item_schema.mock';
import {

View file

@ -6,10 +6,10 @@
*/
import * as t from 'io-ts';
import { NamespaceType, id } from '@kbn/securitysolution-io-ts-utils';
import { id, item_id, namespace_type } from '../common/schemas';
import { item_id, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { NamespaceType } from '../types';
export const readExceptionListItemSchema = t.exact(
t.partial({

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getReadExceptionListSchemaMock } from './read_exception_list_schema.mock';
import { ReadExceptionListSchema, readExceptionListSchema } from './read_exception_list_schema';

View file

@ -6,10 +6,10 @@
*/
import * as t from 'io-ts';
import { NamespaceType, id } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, namespace_type } from '../common/schemas';
import { list_id, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { NamespaceType } from '../types';
export const readExceptionListSchema = t.exact(
t.partial({

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getReadListItemSchemaMock } from './read_list_item_schema.mock';
import { ReadListItemSchema, readListItemSchema } from './read_list_item_schema';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id } from '@kbn/securitysolution-io-ts-utils';
import { id, list_id, value } from '../common/schemas';
import { list_id, value } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const readListItemSchema = t.exact(t.partial({ id, list_id, value }));

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getReadListSchemaMock } from './read_list_schema.mock';
import { ReadListSchema, readListSchema } from './read_list_schema';

View file

@ -6,8 +6,7 @@
*/
import * as t from 'io-ts';
import { id } from '../common/schemas';
import { id } from '@kbn/securitysolution-io-ts-utils';
export const readListSchema = t.exact(
t.type({

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
UpdateEndpointListItemSchema,

View file

@ -6,26 +6,24 @@
*/
import * as t from 'io-ts';
import {
DefaultUpdateCommentsArray,
EntriesArray,
OsTypeArray,
Tags,
_version,
UpdateCommentsArray,
description,
exceptionListItemType,
id,
meta,
name,
nonEmptyEntriesArray,
osTypeArrayOrUndefined,
tags,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { _version } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import {
DefaultUpdateCommentsArray,
EntriesArray,
UpdateCommentsArray,
nonEmptyEntriesArray,
} from '../types';
export const updateEndpointListItemSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
UpdateExceptionListItemSchema,

View file

@ -6,28 +6,25 @@
*/
import * as t from 'io-ts';
import {
DefaultUpdateCommentsArray,
EntriesArray,
NamespaceType,
OsTypeArray,
Tags,
_version,
UpdateCommentsArray,
description,
exceptionListItemType,
id,
meta,
name,
namespace_type,
nonEmptyEntriesArray,
osTypeArrayOrUndefined,
tags,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { _version, namespace_type } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import {
DefaultUpdateCommentsArray,
EntriesArray,
NamespaceType,
UpdateCommentsArray,
nonEmptyEntriesArray,
} from '../types';
export const updateExceptionListItemSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import {
UpdateExceptionListSchema,

View file

@ -6,24 +6,21 @@
*/
import * as t from 'io-ts';
import {
NamespaceType,
OsTypeArray,
Tags,
_version,
description,
exceptionListType,
id,
list_id,
meta,
name,
namespace_type,
osTypeArrayOrUndefined,
tags,
version,
} from '../common/schemas';
} from '@kbn/securitysolution-io-ts-utils';
import { _version, list_id, namespace_type, version } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
import { NamespaceType } from '../types';
export const updateExceptionListSchema = t.intersection([
t.exact(

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { UpdateListItemSchema, updateListItemSchema } from './update_list_item_schema';
import { getUpdateListItemSchemaMock } from './update_list_item_schema.mock';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { id, meta } from '@kbn/securitysolution-io-ts-utils';
import { _version, id, meta, value } from '../common/schemas';
import { _version, value } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const updateListItemSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { UpdateListSchema, updateListSchema } from './update_list_schema';
import { getUpdateListSchemaMock } from './update_list_schema.mock';

View file

@ -6,8 +6,9 @@
*/
import * as t from 'io-ts';
import { description, id, meta, name, version } from '@kbn/securitysolution-io-ts-utils';
import { _version, description, id, meta, name, version } from '../common/schemas';
import { _version } from '../common/schemas';
import { RequiredKeepUndefined } from '../../types';
export const updateListSchema = t.intersection([

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getAcknowledgeSchemaResponseMock } from './acknowledge_schema.mock';
import { AcknowledgeSchema, acknowledgeSchema } from './acknowledge_schema';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getExceptionListSchemaMock } from './exception_list_schema.mock';
import { CreateEndpointListSchema, createEndpointListSchema } from './create_endpoint_list_schema';

View file

@ -48,10 +48,6 @@ export const getExceptionListItemSchemaMock = (
...(overrides || {}),
});
export const getExceptionListItemSchemaXMock = (count = 1): ExceptionListItemSchema[] => {
return new Array(count).fill(null).map(() => getExceptionListItemSchemaMock());
};
/**
* This is useful for end to end tests where we remove the auto generated parts for comparisons
* such as created_at, updated_at, and id.

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getExceptionListItemSchemaMock } from './exception_list_item_schema.mock';
import { ExceptionListItemSchema, exceptionListItemSchema } from './exception_list_item_schema';

View file

@ -6,26 +6,29 @@
*/
import * as t from 'io-ts';
import {
_versionOrUndefined,
commentsArray,
created_at,
created_by,
description,
entriesArray,
exceptionListItemType,
id,
item_id,
list_id,
metaOrUndefined,
name,
namespace_type,
osTypeArray,
tags,
tie_breaker_id,
updated_at,
updated_by,
} from '@kbn/securitysolution-io-ts-utils';
import {
_versionOrUndefined,
item_id,
list_id,
namespace_type,
tie_breaker_id,
} from '../common/schemas';
import { commentsArray, entriesArray } from '../types';
export const exceptionListItemSchema = t.exact(
t.type({

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getExceptionListSchemaMock } from './exception_list_schema.mock';
import { ExceptionListSchema, exceptionListSchema } from './exception_list_schema';

View file

@ -6,24 +6,26 @@
*/
import * as t from 'io-ts';
import {
_versionOrUndefined,
created_at,
created_by,
description,
exceptionListType,
id,
immutable,
list_id,
metaOrUndefined,
name,
namespace_type,
osTypeArray,
tags,
tie_breaker_id,
updated_at,
updated_by,
} from '@kbn/securitysolution-io-ts-utils';
import {
_versionOrUndefined,
immutable,
list_id,
namespace_type,
tie_breaker_id,
version,
} from '../common/schemas';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getExceptionListItemSchemaMock } from './exception_list_item_schema.mock';
import { getFoundExceptionListItemSchemaMock } from './found_exception_list_item_schema.mock';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getExceptionListSchemaMock } from './exception_list_schema.mock';
import { getFoundExceptionListSchemaMock } from './found_exception_list_schema.mock';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getListItemIndexExistSchemaResponseMock } from './list_item_index_exist_schema.mock';
import { ListItemIndexExistSchema, listItemIndexExistSchema } from './list_item_index_exist_schema';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getListItemResponseMock } from './list_item_schema.mock';
import { ListItemSchema, listItemSchema } from './list_item_schema';

View file

@ -6,20 +6,22 @@
*/
import * as t from 'io-ts';
import {
_versionOrUndefined,
created_at,
created_by,
deserializerOrUndefined,
id,
list_id,
metaOrUndefined,
serializerOrUndefined,
tie_breaker_id,
type,
updated_at,
updated_by,
} from '@kbn/securitysolution-io-ts-utils';
import {
_versionOrUndefined,
deserializerOrUndefined,
list_id,
serializerOrUndefined,
tie_breaker_id,
value,
} from '../common/schemas';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getListResponseMock } from './list_schema.mock';
import { ListSchema, listSchema } from './list_schema';

View file

@ -6,22 +6,24 @@
*/
import * as t from 'io-ts';
import {
_versionOrUndefined,
created_at,
created_by,
description,
deserializerOrUndefined,
id,
immutable,
metaOrUndefined,
name,
serializerOrUndefined,
tie_breaker_id,
type,
updated_at,
updated_by,
} from '@kbn/securitysolution-io-ts-utils';
import {
_versionOrUndefined,
deserializerOrUndefined,
immutable,
serializerOrUndefined,
tie_breaker_id,
version,
} from '../common/schemas';

View file

@ -7,8 +7,7 @@
import { left } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';
import { getSearchListItemResponseMock } from './search_list_item_schema.mock';
import { SearchListItemSchema, searchListItemSchema } from './search_list_item_schema';

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import { DATE_NOW, ID, USER } from '../../constants.mock';
import { Comment, CommentsArray } from '@kbn/securitysolution-io-ts-utils';
import { Comment, CommentsArray } from './comment';
import { DATE_NOW, ID, USER } from '../../constants.mock';
export const getCommentsMock = (): Comment => ({
comment: 'some old comment',

View file

@ -1,238 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import { DATE_NOW } from '../../constants.mock';
import { foldLeftRight, getPaths } from '../../shared_imports';
import { getCommentsArrayMock, getCommentsMock } from './comment.mock';
import {
Comment,
CommentsArray,
CommentsArrayOrUndefined,
comment,
commentsArray,
commentsArrayOrUndefined,
} from './comment';
describe('Comment', () => {
describe('comment', () => {
test('it fails validation when "id" is undefined', () => {
const payload = { ...getCommentsMock(), id: undefined };
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "id"',
]);
expect(message.schema).toEqual({});
});
test('it passes validation with a typical comment', () => {
const payload = getCommentsMock();
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it passes validation with "updated_at" and "updated_by" fields included', () => {
const payload = getCommentsMock();
payload.updated_at = DATE_NOW;
payload.updated_by = 'someone';
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it fails validation when undefined', () => {
const payload = undefined;
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "({| comment: NonEmptyString, created_at: string, created_by: string, id: NonEmptyString |} & Partial<{| updated_at: string, updated_by: string |}>)"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when "comment" is an empty string', () => {
const payload: Omit<Comment, 'comment'> & { comment: string } = {
...getCommentsMock(),
comment: '',
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual(['Invalid value "" supplied to "comment"']);
expect(message.schema).toEqual({});
});
test('it fails validation when "comment" is not a string', () => {
const payload: Omit<Comment, 'comment'> & { comment: string[] } = {
...getCommentsMock(),
comment: ['some value'],
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "["some value"]" supplied to "comment"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when "created_at" is not a string', () => {
const payload: Omit<Comment, 'created_at'> & { created_at: number } = {
...getCommentsMock(),
created_at: 1,
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "created_at"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when "created_by" is not a string', () => {
const payload: Omit<Comment, 'created_by'> & { created_by: number } = {
...getCommentsMock(),
created_by: 1,
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "created_by"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when "updated_at" is not a string', () => {
const payload: Omit<Comment, 'updated_at'> & { updated_at: number } = {
...getCommentsMock(),
updated_at: 1,
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "updated_at"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when "updated_by" is not a string', () => {
const payload: Omit<Comment, 'updated_by'> & { updated_by: number } = {
...getCommentsMock(),
updated_by: 1,
};
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "updated_by"',
]);
expect(message.schema).toEqual({});
});
test('it should strip out extra keys', () => {
const payload: Comment & {
extraKey?: string;
} = getCommentsMock();
payload.extraKey = 'some value';
const decoded = comment.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(getCommentsMock());
});
});
describe('commentsArray', () => {
test('it passes validation an array of Comment', () => {
const payload = getCommentsArrayMock();
const decoded = commentsArray.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it passes validation when a Comment includes "updated_at" and "updated_by"', () => {
const commentsPayload = getCommentsMock();
commentsPayload.updated_at = DATE_NOW;
commentsPayload.updated_by = 'someone';
const payload = [{ ...commentsPayload }, ...getCommentsArrayMock()];
const decoded = commentsArray.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it fails validation when undefined', () => {
const payload = undefined;
const decoded = commentsArray.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "Array<({| comment: NonEmptyString, created_at: string, created_by: string, id: NonEmptyString |} & Partial<{| updated_at: string, updated_by: string |}>)>"',
]);
expect(message.schema).toEqual({});
});
test('it fails validation when array includes non Comment types', () => {
const payload = ([1] as unknown) as CommentsArray;
const decoded = commentsArray.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "Array<({| comment: NonEmptyString, created_at: string, created_by: string, id: NonEmptyString |} & Partial<{| updated_at: string, updated_by: string |}>)>"',
]);
expect(message.schema).toEqual({});
});
});
describe('commentsArrayOrUndefined', () => {
test('it passes validation an array of Comment', () => {
const payload = getCommentsArrayMock();
const decoded = commentsArrayOrUndefined.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it passes validation when undefined', () => {
const payload = undefined;
const decoded = commentsArrayOrUndefined.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});
test('it fails validation when array includes non Comment types', () => {
const payload = ([1] as unknown) as CommentsArrayOrUndefined;
const decoded = commentsArray.decode(payload);
const message = pipe(decoded, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1" supplied to "Array<({| comment: NonEmptyString, created_at: string, created_by: string, id: NonEmptyString |} & Partial<{| updated_at: string, updated_by: string |}>)>"',
]);
expect(message.schema).toEqual({});
});
});
});

Some files were not shown because too many files have changed in this diff Show more