kibana/packages/kbn-config-schema/index.ts
Tiago Costa 1cbf83f73c
chore(NA): remove src folder requirement from packages (part 2) (#138476)
* refact(NA): apply root_input_dir=src to each already created pkg

* refact(NA): update package generator

* fix(NA): correctly use rootDir

* fix(NA): use root input dir on latest introduced pkgs for jsts_transpiler macro

* chore(NA): merge with main

* chore(NA): first attempt to complete removal of src folder on a small group of pkgs

* Revert "chore(NA): first attempt to complete removal of src folder on a small group of pkgs"

This reverts commit b6f34b7530.

* chore(NA): remove src folder requirement from xpack pkgs

* chore(NA): remove src folder from analytics pkgs

* chore(NA): remove src folder from home pkgs

* chore(NA): remove src folder from shared_ux pkgs

* fix(NA): remove missing src folder inputs on sharedux pkg

* chore(NA): remove src folder from kbn-a* pkgs

* chore(NA): remove src folder from kbn-b* pkgs

* chore(NA): remove src folder from kbn-c* pkgs

* chore(NA): correct exclude pattern for each changed pkg

* chore(NA): remove src folder from kbn-y* pkgs

* chore(NA): remove src folder from kbn-e* pkgs

* chore(NA): remove src folder from kbn-f* and kbn-g* pkgs

* chore(NA): remove src folder from kbn-f* and kbn-g* pkgs

* chore(NA): remove src folder from kbn-h** pkgs

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Revert "chore(NA): remove src folder from kbn-h** pkgs"

This reverts commit dcdf72bcc1.

* fix(NA): grammar location

* test(NA): fix tests for kbn/config-schema

* test(NA): fix tests for kbn/config-schema

* chore(NA): multiple errors fixed

* chore(NA): remove kuery grammar fix

* fix(NA): @kbn/ace imports

* fix(NA): grammar location

* fix(NA): add missing files to tsconfigs

* [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs'

* chore(NA): complete tsconfigs

* Revert "chore(NA): complete tsconfigs"

This reverts commit f48c616864.

* chore(NA): remove src folder from kbn-core* pkgs

* chore(NA): remove src folder from kbn-u* pkgs

* chore(NA): remove src folder from kbn-ui-shared-deps* pkgs

* chore(NA): fix problems on core pkgs

* chore(NA): fix problems on core pkgs

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* fix(NA): shared_built_assets correct location'

* test(NA): update @kbn/optimizer integration snapshots

* chore(NA): remove src folder from kbn-t* p1 pkgs

* chore(NA): remove src folder from kbn-t* p2 pkgs

* chore(NA): update rootDir on utility types pkg

* chore(NA): include missing files on @kbn/test

* chore(NA): include missing files on @kbn/test

* fix(NA): new jest preset paths on @kbn/test

* chore(NA): fix eslint

* fix(NA): new jest preset paths on @kbn/test

* chore(NA): remove exclusion for mocks folde on @kbn/test

* fix(NA): several imports from target_node

* fix(NA): @kbn/test mocha and jest types clash

* chore(NA): remove src folder from kbn-storybook pkg

* chore(NA): remove src folder from kbn-stdio-dev-helpers pkg

* chore(NA): remove src folder from kbn-std pkg

* chore(NA): remove src folder from kbn-sort-pkg-json pkg

* chore(NA): remove src folder from kbn-some-dev-log and kbn-shared-ux-utility pkgs

* chore(NA): remove src folder from kbn-ux-storybook pkg

* chore(NA): remove src folder from kbn-shared-ux-services pkg

* chore(NA): remove src folder from kbn-shared-ux-components pkg

* chore(NA): remove src folder from kbn-shared-svg pkg

* chore(NA): remove src folder from kbn-server-http-tools pkg

* chore(NA): remove src folder from kbn-securitysolution-* pkgs

* chore(NA): remove src folder from kbn-r-* pkgs

* chore(NA): remove src folder from kbn-p* pkgs

* chore(NA): remove src folder from kbn-o* pkgs

* chore(NA): remove src folder from kbn-m* pkgs

* chore(NA): remove src folder from kbn-j,k,l* pkgs

* chore(NA): remove src folder from kbn-j,k,l* pkgs

* chore(NA): remove src folder from kbn-io-ts-utils* pkgs

* chore(NA): remove src folder from kbn-* pkgs except a few

* chore(NA): update @kbn/generate

* fix(NA): wrong exclusion on kbn-storybook

* chore(NA): remove src folder from kbn-monaco pkg

* chore(NA): remove src folder from kbn-interpreter pkg

* fix(NA): wrong exclusion on kbn-storybook

* chore(NA): update every require for target_*/src

* chore(NA): remover src folder from @kbn/handlebars

* fix(NA): license for @kbn/handlebars

* chore(NA): copy templates as part of the jsts_transpiler macro for @kbn/storybook

* chore(NA): update handlebars

* fix(NA): @kbn/plugin-generator import paths

* fix(NA): bundle sizes

* fix(NA): web bundle for @kbn/i18n-react

* Revert "fix(NA): bundle sizes"

This reverts commit 8aefe84fbc.

* Revert "Revert "fix(NA): bundle sizes""

This reverts commit e9d87d72a4.

* fix(NA): @kbn/docs-utils index.ts path expectation

* chore(NA): merge and solve conflicts with main

* fix(NA): relative import to index

* chore(NA): merge and solve conflicts with main

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* chore(NA): apply eslint fix

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2022-08-30 15:57:35 +01:00

223 lines
5.9 KiB
TypeScript

/*
* 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<any>) {
return new AnyType(options);
}
function boolean(options?: TypeOptions<boolean>): Type<boolean> {
return new BooleanType(options);
}
function buffer(options?: TypeOptions<Buffer>): Type<Buffer> {
return new BufferType(options);
}
function stream(options?: TypeOptions<Stream>): Type<Stream> {
return new StreamType(options);
}
function string(options?: StringOptions): Type<string> {
return new StringType(options);
}
function uri(options?: URIOptions): Type<string> {
return new URIType(options);
}
function literal<T extends string | number | boolean | null>(value: T): Type<T> {
return new LiteralType(value);
}
function number(options?: NumberOptions): Type<number> {
return new NumberType(options);
}
function byteSize(options?: ByteSizeOptions): Type<ByteSizeValue> {
return new ByteSizeType(options);
}
function duration(options?: DurationOptions): Type<Duration> {
return new DurationType(options);
}
function never(): Type<never> {
return new NeverType();
}
function ip(options?: IpOptions): Type<string> {
return new IpType(options);
}
/**
* Create an optional type
*/
function maybe<V>(type: Type<V>): Type<V | undefined> {
return new MaybeType(type);
}
function nullable<V>(type: Type<V>): Type<V | null> {
return schema.oneOf([type, schema.literal(null)], { defaultValue: null });
}
function object<P extends Props>(props: P, options?: ObjectTypeOptions<P>): ObjectType<P> {
return new ObjectType(props, options);
}
function arrayOf<T>(itemType: Type<T>, options?: ArrayOptions<T>): Type<T[]> {
return new ArrayType(itemType, options);
}
function mapOf<K, V>(
keyType: Type<K>,
valueType: Type<V>,
options?: MapOfOptions<K, V>
): Type<Map<K, V>> {
return new MapOfType(keyType, valueType, options);
}
function recordOf<K extends string, V>(
keyType: Type<K>,
valueType: Type<V>,
options?: RecordOfOptions<K, V>
): Type<Record<K, V>> {
return new RecordOfType(keyType, valueType, options);
}
function oneOf<A, B, C, D, E, F, G, H, I, J>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>, Type<G>, Type<H>, Type<I>, Type<J>],
options?: TypeOptions<A | B | C | D | E | F | G | H | I | J>
): Type<A | B | C | D | E | F | G | H | I | J>;
function oneOf<A, B, C, D, E, F, G, H, I>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>, Type<G>, Type<H>, Type<I>],
options?: TypeOptions<A | B | C | D | E | F | G | H | I>
): Type<A | B | C | D | E | F | G | H | I>;
function oneOf<A, B, C, D, E, F, G, H>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>, Type<G>, Type<H>],
options?: TypeOptions<A | B | C | D | E | F | G | H>
): Type<A | B | C | D | E | F | G | H>;
function oneOf<A, B, C, D, E, F, G>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>, Type<G>],
options?: TypeOptions<A | B | C | D | E | F | G>
): Type<A | B | C | D | E | F | G>;
function oneOf<A, B, C, D, E, F>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>],
options?: TypeOptions<A | B | C | D | E | F>
): Type<A | B | C | D | E | F>;
function oneOf<A, B, C, D, E>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>],
options?: TypeOptions<A | B | C | D | E>
): Type<A | B | C | D | E>;
function oneOf<A, B, C, D>(
types: [Type<A>, Type<B>, Type<C>, Type<D>],
options?: TypeOptions<A | B | C | D>
): Type<A | B | C | D>;
function oneOf<A, B, C>(
types: [Type<A>, Type<B>, Type<C>],
options?: TypeOptions<A | B | C>
): Type<A | B | C>;
function oneOf<A, B>(types: [Type<A>, Type<B>], options?: TypeOptions<A | B>): Type<A | B>;
function oneOf<A>(types: [Type<A>], options?: TypeOptions<A>): Type<A>;
function oneOf<RTS extends Array<Type<any>>>(types: RTS, options?: TypeOptions<any>): Type<any> {
return new UnionType(types, options);
}
function contextRef<T>(key: string): ContextReference<T> {
return new ContextReference(key);
}
function siblingRef<T>(key: string): SiblingReference<T> {
return new SiblingReference(key);
}
function conditional<A extends ConditionalTypeValue, B, C>(
leftOperand: Reference<A>,
rightOperand: Reference<A> | A | Type<unknown>,
equalType: Type<B>,
notEqualType: Type<C>,
options?: TypeOptions<B | C>
) {
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;