mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[EBT] Fix schema support to Date (#132051)
This commit is contained in:
parent
4235294f08
commit
327df57c8b
2 changed files with 63 additions and 1 deletions
|
@ -182,6 +182,66 @@ describe('schema types', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Date value', () => {
|
||||
test('it should allow the correct type and enforce the _meta.description', () => {
|
||||
let valueType: SchemaValue<Date> = {
|
||||
type: 'date',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
},
|
||||
};
|
||||
|
||||
valueType = {
|
||||
type: 'keyword',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
optional: false,
|
||||
},
|
||||
};
|
||||
|
||||
valueType = {
|
||||
// @ts-expect-error because the type does not match
|
||||
type: 'long',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
optional: false,
|
||||
},
|
||||
};
|
||||
|
||||
valueType = {
|
||||
type: 'keyword',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
// @ts-expect-error optional can't be true when the types don't set the value as optional
|
||||
optional: true,
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-expect-error because it's missing the _meta.description
|
||||
valueType = { type: 'date' };
|
||||
expect(valueType).not.toBeUndefined(); // <-- Only to stop the var-not-used complain
|
||||
});
|
||||
test('it should enforce `_meta.optional: true`', () => {
|
||||
let valueType: SchemaValue<Date | undefined> = {
|
||||
type: 'date',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
optional: true,
|
||||
},
|
||||
};
|
||||
|
||||
valueType = {
|
||||
type: 'date',
|
||||
_meta: {
|
||||
description: 'Some description',
|
||||
// @ts-expect-error because optional can't be false when the value can be undefined
|
||||
optional: false,
|
||||
},
|
||||
};
|
||||
expect(valueType).not.toBeUndefined(); // <-- Only to stop the var-not-used complain
|
||||
});
|
||||
});
|
||||
|
||||
describe('Object value', () => {
|
||||
test('it should allow "pass_through" and enforce the _meta.description', () => {
|
||||
let valueType: SchemaValue<{ a_value: string }> = {
|
||||
|
|
|
@ -31,7 +31,7 @@ export type AllowedSchemaTypes =
|
|||
/**
|
||||
* Helper to ensure the declared types match the schema types
|
||||
*/
|
||||
export type PossibleSchemaTypes<Value> = Value extends string
|
||||
export type PossibleSchemaTypes<Value> = Value extends string | Date
|
||||
? AllowedSchemaStringTypes
|
||||
: Value extends number
|
||||
? AllowedSchemaNumberTypes
|
||||
|
@ -66,6 +66,8 @@ export type SchemaValue<Value> =
|
|||
: // Otherwise, try to infer the type and enforce the schema
|
||||
NonNullable<Value> extends Array<infer U> | ReadonlyArray<infer U>
|
||||
? SchemaArray<U, Value>
|
||||
: NonNullable<Value> extends Date
|
||||
? SchemaChildValue<Value>
|
||||
: NonNullable<Value> extends object
|
||||
? SchemaObject<Value>
|
||||
: SchemaChildValue<Value>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue