diff --git a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/core.ts b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/core.ts index 1da12cde4c9af..b77ed58d4c4d1 100644 --- a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/core.ts +++ b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/core.ts @@ -18,31 +18,3 @@ export const streamDefinitionSchema: z.Schema = z.union([ ]); export const isStreamDefinition = createIsNarrowSchema(z.unknown(), streamDefinitionSchema); - -export type Primitive = string | number | boolean | null | undefined; - -export const primitive: z.ZodType = z.union([ - z.string(), - z.number(), - z.boolean(), - z.null(), - z.undefined(), -]); - -export interface RecursiveRecord { - [key: PropertyKey]: Primitive | Primitive[] | RecursiveRecord; -} - -export const recursiveRecord: z.ZodType = z.lazy(() => - z.record(z.union([primitive, z.array(primitive), recursiveRecord])) -); - -export type FlattenRecord = Record; - -export const flattenRecord: z.ZodType = z.record( - z.union([primitive, z.array(primitive)]) -); - -export const sampleDocument = recursiveRecord; - -export type SampleDocument = RecursiveRecord; diff --git a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/index.ts b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/index.ts index be9dafc266b3a..06f5be3ffc383 100644 --- a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/index.ts +++ b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/index.ts @@ -11,3 +11,4 @@ export * from './api'; export * from './core'; export * from './helpers'; export * from './group'; +export * from './record_types'; diff --git a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/ingest/fields/index.ts b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/ingest/fields/index.ts index 7f9f7121d52f5..482e956f8ef95 100644 --- a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/ingest/fields/index.ts +++ b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/ingest/fields/index.ts @@ -8,6 +8,7 @@ import { MappingProperty } from '@elastic/elasticsearch/lib/api/types'; import { z } from '@kbn/zod'; import { NonEmptyString } from '@kbn/zod-helpers'; +import { recursiveRecord } from '../../record_types'; export const FIELD_DEFINITION_TYPES = [ 'keyword', @@ -34,7 +35,7 @@ export type FieldDefinitionConfigAdvancedParameters = Omit< >; export const fieldDefinitionConfigSchema: z.Schema = z.intersection( - z.record(z.string(), z.unknown()), + recursiveRecord, z.object({ type: z.enum(FIELD_DEFINITION_TYPES), format: z.optional(NonEmptyString), diff --git a/x-pack/platform/packages/shared/kbn-streams-schema/src/models/record_types.ts b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/record_types.ts new file mode 100644 index 0000000000000..58a409b370c4b --- /dev/null +++ b/x-pack/platform/packages/shared/kbn-streams-schema/src/models/record_types.ts @@ -0,0 +1,36 @@ +/* + * 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 { z } from '@kbn/zod'; + +export type Primitive = string | number | boolean | null | undefined; + +export const primitive: z.ZodType = z.union([ + z.string(), + z.number(), + z.boolean(), + z.null(), + z.undefined(), +]); + +export interface RecursiveRecord { + [key: PropertyKey]: Primitive | Primitive[] | RecursiveRecord; +} + +export const recursiveRecord: z.ZodType = z.lazy(() => + z.record(z.union([primitive, z.array(primitive), recursiveRecord])) +); + +export type FlattenRecord = Record; + +export const flattenRecord: z.ZodType = z.record( + z.union([primitive, z.array(primitive)]) +); + +export const sampleDocument = recursiveRecord; + +export type SampleDocument = RecursiveRecord;