-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'connector-create-connector-with-api' of github.com:jedr…
…azb/kibana into connector-create-connector-with-api
- Loading branch information
Showing
96 changed files
with
2,968 additions
and
456 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/kbn-io-ts-utils/src/array_to_string_rt/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 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 rt from 'io-ts'; | ||
import { arrayToStringRt } from '.'; | ||
import { isRight, Either, fold } from 'fp-ts/lib/Either'; | ||
import { identity } from 'fp-ts/lib/function'; | ||
|
||
function getValueOrThrow(either: Either<unknown, any>) { | ||
return fold(() => { | ||
throw new Error('Cannot get right value of left'); | ||
}, identity)(either); | ||
} | ||
|
||
describe('arrayToStringRt', () => { | ||
it('should validate strings', () => { | ||
expect(isRight(arrayToStringRt.decode(''))).toBe(true); | ||
expect(isRight(arrayToStringRt.decode('message'))).toBe(true); | ||
expect(isRight(arrayToStringRt.decode('message,event.original'))).toBe(true); | ||
expect(isRight(arrayToStringRt.decode({}))).toBe(false); | ||
expect(isRight(arrayToStringRt.decode(true))).toBe(false); | ||
}); | ||
|
||
it('should return array of strings when decoding', () => { | ||
expect(getValueOrThrow(arrayToStringRt.decode(''))).toEqual(['']); | ||
expect(getValueOrThrow(arrayToStringRt.decode('message'))).toEqual(['message']); | ||
expect(getValueOrThrow(arrayToStringRt.decode('message,event.original'))).toEqual([ | ||
'message', | ||
'event.original', | ||
]); | ||
}); | ||
|
||
it('should be pipable', () => { | ||
const piped = arrayToStringRt.pipe(rt.array(rt.string)); | ||
|
||
const validInput = ['message', 'event.original']; | ||
const invalidInput = {}; | ||
|
||
const valid = piped.decode(validInput.join(',')); | ||
const invalid = piped.decode(invalidInput); | ||
|
||
expect(isRight(valid)).toBe(true); | ||
expect(getValueOrThrow(valid)).toEqual(validInput); | ||
|
||
expect(isRight(invalid)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 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 { either } from 'fp-ts/lib/Either'; | ||
import * as rt from 'io-ts'; | ||
|
||
export const arrayToStringRt = new rt.Type<unknown[], string, unknown>( | ||
'arrayToString', | ||
rt.array(rt.unknown).is, | ||
(input, context) => | ||
either.chain(rt.string.validate(input, context), (str) => { | ||
try { | ||
return rt.success(str.split(',')); | ||
} catch (e) { | ||
return rt.failure(input, context); | ||
} | ||
}), | ||
(arr) => arr.join(',') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.