import { ConditionOptions, ResolveOptions } from './Condition'; import { TestFunction, Test, TestConfig } from './util/createValidation'; import { ValidateOptions, TransformFunction, Message, Callback, InternalOptions, Maybe, ExtraParams, AnyObject } from './types'; import type { Asserts, Thunk } from './util/types'; import ReferenceSet from './util/ReferenceSet'; import Reference from './Reference'; export declare type SchemaSpec = { nullable: boolean; presence: 'required' | 'defined' | 'optional'; default?: TDefault | (() => TDefault); abortEarly?: boolean; strip?: boolean; strict?: boolean; recursive?: boolean; label?: string | undefined; meta?: any; }; export declare type SchemaOptions = { type?: string; spec?: SchemaSpec; }; export declare type AnySchema = BaseSchema; export interface CastOptions { parent?: any; context?: TContext; assert?: boolean; stripUnknown?: boolean; path?: string; } export interface SchemaRefDescription { type: 'ref'; key: string; } export interface SchemaInnerTypeDescription extends SchemaDescription { innerType?: SchemaFieldDescription; } export interface SchemaObjectDescription extends SchemaDescription { fields: Record; } export declare type SchemaFieldDescription = SchemaDescription | SchemaRefDescription | SchemaObjectDescription | SchemaInnerTypeDescription; export interface SchemaDescription { type: string; label?: string; meta: object; oneOf: unknown[]; notOneOf: unknown[]; tests: Array<{ name?: string; params: ExtraParams | undefined; }>; } export default abstract class BaseSchema { readonly type: string; readonly __inputType: TCast; readonly __outputType: TOutput; readonly __isYupSchema__: boolean; readonly deps: readonly string[]; tests: Test[]; transforms: TransformFunction[]; private conditions; private _mutate?; private _typeError?; private _whitelistError?; private _blacklistError?; protected _whitelist: ReferenceSet; protected _blacklist: ReferenceSet; protected exclusiveTests: Record; spec: SchemaSpec; constructor(options?: SchemaOptions); get _type(): string; protected _typeCheck(_value: any): _value is NonNullable; clone(spec?: Partial>): this; label(label: string): this; meta(): Record | undefined; meta(obj: Record): this; withMutation(fn: (schema: this) => T): T; concat(schema: this): this; concat(schema: AnySchema): AnySchema; isType(v: any): boolean; resolve(options: ResolveOptions): this; /** * * @param {*} value * @param {Object} options * @param {*=} options.parent * @param {*=} options.context */ cast(value: any, options?: CastOptions): TCast; protected _cast(rawValue: any, _options: CastOptions): any; protected _validate(_value: any, options: InternalOptions | undefined, cb: Callback): void; validate(value: any, options?: ValidateOptions): Promise; validateSync(value: any, options?: ValidateOptions): this['__outputType']; isValid(value: any, options?: ValidateOptions): Promise; isValidSync(value: any, options?: ValidateOptions): value is Asserts; protected _getDefault(): any; getDefault(options?: ResolveOptions): TCast; default(def: Thunk): any; strict(isStrict?: boolean): this; protected _isPresent(value: unknown): boolean; defined(message?: Message<{}>): any; required(message?: Message<{}>): any; notRequired(): any; nullable(isNullable?: true): any; nullable(isNullable: false): any; transform(fn: TransformFunction): this; /** * Adds a test function to the schema's queue of tests. * tests can be exclusive or non-exclusive. * * - exclusive tests, will replace any existing tests of the same name. * - non-exclusive: can be stacked * * If a non-exclusive test is added to a schema with an exclusive test of the same name * the exclusive test is removed and further tests of the same name will be stacked. * * If an exclusive test is added to a schema with non-exclusive tests of the same name * the previous tests are removed and further tests of the same name will replace each other. */ test(options: TestConfig): this; test(test: TestFunction): this; test(name: string, test: TestFunction): this; test(name: string, message: Message, test: TestFunction): this; when(options: ConditionOptions): this; when(keys: string | string[], options: ConditionOptions): this; typeError(message: Message): this; oneOf(enums: Array | Reference>, message?: Message<{ values: any; }>): this; notOneOf(enums: Array | Reference>, message?: Message<{ values: any; }>): this; strip(strip?: boolean): this; describe(): SchemaDescription; } export default interface BaseSchema { validateAt(path: string, value: any, options?: ValidateOptions): Promise; validateSyncAt(path: string, value: any, options?: ValidateOptions): TOutput; equals: BaseSchema['oneOf']; is: BaseSchema['oneOf']; not: BaseSchema['notOneOf']; nope: BaseSchema['notOneOf']; optional(): any; }