-
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 'main' into osquery-flaky-6
- Loading branch information
Showing
189 changed files
with
2,924 additions
and
2,754 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 { ArrayFromString } from './array_from_string'; | ||
import * as z from 'zod'; | ||
|
||
describe('ArrayFromString', () => { | ||
const itemsSchema = z.string(); | ||
|
||
it('should return an array when input is a string', () => { | ||
const result = ArrayFromString(itemsSchema).parse('a,b,c'); | ||
expect(result).toEqual(['a', 'b', 'c']); | ||
}); | ||
|
||
it('should return an empty array when input is an empty string', () => { | ||
const result = ArrayFromString(itemsSchema).parse(''); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return the input as is when it is not a string', () => { | ||
const input = ['a', 'b', 'c']; | ||
const result = ArrayFromString(itemsSchema).parse(input); | ||
expect(result).toEqual(input); | ||
}); | ||
|
||
it('should throw an error when input is not a string or an array', () => { | ||
expect(() => ArrayFromString(itemsSchema).parse(123)).toThrow(); | ||
}); | ||
}); |
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 * as z from 'zod'; | ||
|
||
/** | ||
* This is a helper schema to convert comma separated strings to arrays. Useful | ||
* for processing query params. | ||
* | ||
* @param schema Array items schema | ||
* @returns Array schema that accepts a comma-separated string as input | ||
*/ | ||
export function ArrayFromString<T extends z.ZodTypeAny>(schema: T) { | ||
return z.preprocess( | ||
(value: unknown) => | ||
typeof value === 'string' ? (value === '' ? [] : value.split(',')) : value, | ||
z.array(schema) | ||
); | ||
} |
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,32 @@ | ||
/* | ||
* 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 { BooleanFromString } from './boolean_from_string'; | ||
|
||
describe('BooleanFromString', () => { | ||
it('should return true when input is "true"', () => { | ||
expect(BooleanFromString.parse('true')).toBe(true); | ||
}); | ||
|
||
it('should return false when input is "false"', () => { | ||
expect(BooleanFromString.parse('false')).toBe(false); | ||
}); | ||
|
||
it('should return true when input is true', () => { | ||
expect(BooleanFromString.parse(true)).toBe(true); | ||
}); | ||
|
||
it('should return false when input is false', () => { | ||
expect(BooleanFromString.parse(false)).toBe(false); | ||
}); | ||
|
||
it('should throw an error when input is not a boolean or "true" or "false"', () => { | ||
expect(() => BooleanFromString.parse('not a boolean')).toThrow(); | ||
expect(() => BooleanFromString.parse(42)).toThrow(); | ||
}); | ||
}); |
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 * as z from 'zod'; | ||
|
||
/** | ||
* This is a helper schema to convert a boolean string ("true" or "false") to a | ||
* boolean. Useful for processing query params. | ||
* | ||
* Accepts "true" or "false" as strings, or a boolean. | ||
*/ | ||
export const BooleanFromString = z | ||
.enum(['true', 'false']) | ||
.or(z.boolean()) | ||
.transform((value) => { | ||
if (typeof value === 'boolean') { | ||
return value; | ||
} | ||
return value === 'true'; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 z from 'zod'; | ||
|
||
/** | ||
* Safely parse a payload against a schema, returning the output or undefined. | ||
* This method does not throw validation errors and is useful for validating | ||
* optional objects when we don't care about errors. | ||
* | ||
* @param payload Schema payload | ||
* @param schema Validation schema | ||
* @returns Schema output or undefined | ||
*/ | ||
export function safeParseResult<T extends z.ZodTypeAny>( | ||
payload: unknown, | ||
schema: T | ||
): T['_output'] | undefined { | ||
const result = schema.safeParse(payload); | ||
if (result.success) { | ||
return result.data; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/log_explorer/public/components/log_explorer/types.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,25 @@ | ||
/* | ||
* 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 { DataTableRecord } from '@kbn/discover-utils/types'; | ||
|
||
export type RenderPreviousContent = () => React.ReactNode; | ||
|
||
export interface LogExplorerFlyoutContentProps { | ||
doc: DataTableRecord; | ||
} | ||
|
||
export type FlyoutRenderContent = ( | ||
renderPreviousContent: RenderPreviousContent, | ||
props: LogExplorerFlyoutContentProps | ||
) => React.ReactNode; | ||
|
||
export interface LogExplorerCustomizations { | ||
flyout?: { | ||
renderContent?: FlyoutRenderContent; | ||
}; | ||
} |
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.