UNPKG

lakutata

Version:

An IoC-based universal application framework.

52 lines (29 loc) 3.18 kB
import { AlternativesSchema, StringSchema, NumberSchema, BooleanSchema, DateSchema, BinarySchema, ArraySchema, ObjectSchema, AnySchema, FunctionSchema, LinkSchema, SymbolSchema, CustomHelpers, ErrorReport, ExternalHelpers } from './TypeDef.internal.121.js'; type Types = 'any' | 'alternatives' | 'array' | 'boolean' | 'binary' | 'date' | 'function' | 'link' | 'number' | 'object' | 'string' | 'symbol'; type PartialSchemaMap<TSchema = any> = { [key in keyof TSchema]?: SchemaLike | SchemaLike[]; }; type PresenceMode = 'optional' | 'required' | 'forbidden'; type IsUnion<T, U extends T = T> = T extends unknown ? [U] extends [T] ? false : true : false; type IsPrimitiveSubset<T> = [ T ] extends [string] ? true : [T] extends [number] ? true : [T] extends [bigint] ? true : [T] extends [boolean] ? true : [T] extends [symbol] ? true : [T] extends [null] ? true : [T] extends [undefined] ? true : false; type IsNonPrimitiveSubsetUnion<T> = true extends IsUnion<T> ? true extends IsPrimitiveSubset<T> ? false : true : false; type NullableType<T> = undefined | null | T; type ObjectPropertiesSchema<T = any> = true extends IsNonPrimitiveSubsetUnion<Exclude<T, undefined | null>> ? AlternativesSchema : T extends NullableType<string> ? StringSchema : T extends NullableType<number> ? NumberSchema : T extends NullableType<bigint> ? NumberSchema : T extends NullableType<boolean> ? BooleanSchema : T extends NullableType<Date> ? DateSchema : T extends NullableType<Buffer> ? BinarySchema : T extends NullableType<Array<any>> ? ArraySchema : T extends NullableType<object> ? (StrictSchemaMap<T> | ObjectSchema<T>) : never; type StrictSchemaMap<TSchema = any> = { [key in keyof TSchema]-?: ObjectPropertiesSchema<TSchema[key]>; }; type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true ? StrictSchemaMap<TSchema> : PartialSchemaMap<TSchema>; type Primitives = string | number | boolean | bigint | symbol | null; type SchemaLikeWithoutArray<TSchema = any> = Exclude<Primitives | Schema<TSchema> | SchemaMap<TSchema>, any[]>; type SchemaLike = SchemaLikeWithoutArray | object; type NoNestedArrays<T extends readonly unknown[]> = Extract<T[number], readonly unknown[]> extends never ? T : never; type UnwrapSchemaLikeWithoutArray<T> = T extends SchemaLikeWithoutArray<infer U> ? U : never; type Schema<P = any> = AnySchema<P> | ArraySchema<P> | AlternativesSchema<P> | BinarySchema<P> | BooleanSchema<P> | DateSchema<P> | FunctionSchema<P> | NumberSchema<P> | ObjectSchema<P> | StringSchema<P> | LinkSchema<P> | SymbolSchema<P>; type SchemaFunction = (schema: Schema) => Schema; type ExtensionBoundSchema = Schema; type LanguageMessages = Record<string, string | Record<string, string>>; type CustomValidator<V = any, R = V> = (value: V, helpers: CustomHelpers<R>) => R | ErrorReport; type ExternalValidationFunction<V = any, R = V> = (value: V, helpers: ExternalHelpers<R>) => R | undefined; export type { CustomValidator, ExtensionBoundSchema, ExternalValidationFunction, LanguageMessages, NoNestedArrays, PresenceMode, Primitives, Schema, SchemaFunction, SchemaLike, SchemaLikeWithoutArray, SchemaMap, Types, UnwrapSchemaLikeWithoutArray };