/* * 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 { Duration } from 'moment'; import { Stream } from 'stream'; import { ByteSizeValue } from './src/byte_size_value'; import { ContextReference, Reference, SiblingReference } from './src/references'; import { AnyType, ArrayOptions, ArrayType, BooleanType, BufferType, ByteSizeOptions, ByteSizeType, ConditionalType, ConditionalTypeValue, DurationOptions, DurationType, IpOptions, IpType, LiteralType, MapOfOptions, MapOfType, MaybeType, NeverType, NumberOptions, NumberType, ObjectType, ObjectTypeOptions, Props, NullableProps, RecordOfOptions, RecordOfType, SchemaStructureEntry, StringOptions, StringType, Type, TypeOf, TypeOptions, UnionType, URIOptions, URIType, StreamType, } from './src/types'; export type { AnyType, ConditionalType, TypeOf, Props, SchemaStructureEntry, NullableProps }; export { ObjectType, Type }; export { ByteSizeValue } from './src/byte_size_value'; export { SchemaTypeError, ValidationError } from './src/errors'; export { isConfigSchema } from './src/typeguards'; function any(options?: TypeOptions) { return new AnyType(options); } function boolean(options?: TypeOptions): Type { return new BooleanType(options); } function buffer(options?: TypeOptions): Type { return new BufferType(options); } function stream(options?: TypeOptions): Type { return new StreamType(options); } function string(options?: StringOptions): Type { return new StringType(options); } function uri(options?: URIOptions): Type { return new URIType(options); } function literal(value: T): Type { return new LiteralType(value); } function number(options?: NumberOptions): Type { return new NumberType(options); } function byteSize(options?: ByteSizeOptions): Type { return new ByteSizeType(options); } function duration(options?: DurationOptions): Type { return new DurationType(options); } function never(): Type { return new NeverType(); } function ip(options?: IpOptions): Type { return new IpType(options); } /** * Create an optional type */ function maybe(type: Type): Type { return new MaybeType(type); } function nullable(type: Type): Type { return schema.oneOf([type, schema.literal(null)], { defaultValue: null }); } function object

(props: P, options?: ObjectTypeOptions

): ObjectType

{ return new ObjectType(props, options); } function arrayOf(itemType: Type, options?: ArrayOptions): Type { return new ArrayType(itemType, options); } function mapOf( keyType: Type, valueType: Type, options?: MapOfOptions ): Type> { return new MapOfType(keyType, valueType, options); } function recordOf( keyType: Type, valueType: Type, options?: RecordOfOptions ): Type> { return new RecordOfType(keyType, valueType, options); } function oneOf( types: [Type, Type, Type, Type, Type, Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type, Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type, Type], options?: TypeOptions ): Type; function oneOf( types: [Type, Type, Type], options?: TypeOptions ): Type; function oneOf(types: [Type, Type], options?: TypeOptions): Type; function oneOf(types: [Type], options?: TypeOptions): Type; function oneOf>>(types: RTS, options?: TypeOptions): Type { return new UnionType(types, options); } function contextRef(key: string): ContextReference { return new ContextReference(key); } function siblingRef(key: string): SiblingReference { return new SiblingReference(key); } function conditional( leftOperand: Reference, rightOperand: Reference | A | Type, equalType: Type, notEqualType: Type, options?: TypeOptions ) { return new ConditionalType(leftOperand, rightOperand, equalType, notEqualType, options); } export const schema = { any, arrayOf, boolean, buffer, byteSize, conditional, contextRef, duration, ip, literal, mapOf, maybe, nullable, never, number, object, oneOf, recordOf, stream, siblingRef, string, uri, }; export type Schema = typeof schema;