type Cleaner = (value: V, context?: Record) => T | PromiseLike; interface AnySchema { /** `required: false` - allow undefined values */ required?: boolean; /** `null: true` - allow null values */ null?: boolean; /** Replace `undefined` with this value (sets `required: false` automatically) */ default?: any; /** Override flat collector field label, or `null` to omit field label altogether. */ label?: string | null; /** Nested cleaner (called if the validation passes) */ clean?: Cleaner; } type WithSchema, S> = C & { schema: S; }; declare function setSchema, S>(fn: C, schema: S): WithSchema, any> ? OC : C, S>; declare function cleanAny(schema?: AnySchema): WithSchema, AnySchema>; interface ArraySchema extends AnySchema { /** Individual element cleaner. */ element?: Cleaner; /** Minimum allowed number of elements. */ min?: number; /** Maximum allowed number of elements. */ max?: number; } declare function cleanArray(schema?: ArraySchema): WithSchema, ArraySchema>; interface BooleanSchema extends AnySchema { /** No strict type check, convert value with `!!value` */ cast?: boolean; /** Return `undefined` for `false` */ omit?: boolean; } declare function cleanBoolean(schema?: BooleanSchema): WithSchema, BooleanSchema>; interface StringSchema extends AnySchema { /** * `blank: true` - allow blank values (empty strings). * * `blank: null` - convert blank values (empty strings) to `null` (sets `null: true` automatically). */ blank?: boolean | null; /** `cast: true` - no strict type check, convert value with `String(value)` */ cast?: boolean; /** Test non-blank strings to match against regexp */ regexp?: RegExp; } declare function cleanString(schema?: StringSchema): WithSchema, StringSchema>; interface DateSchema extends Omit, "cast" | "regexp"> { /** * `format: undefined` (default) - return Date object * * `format: null` - return valid value as is * * `format: "iso"` - return ISO-formatted date-time */ format?: null | "iso"; } declare function cleanDate(schema?: DateSchema & { format?: undefined; }): Cleaner; declare function cleanDate(schema?: DateSchema & { format: "iso" | null; }): Cleaner; type EmailSchema = StringSchema; declare function cleanEmail(schema?: EmailSchema): WithSchema, EmailSchema>; interface NumberSchema extends AnySchema { /** No strict type check, convert value with `parseInt(value)` */ cast?: boolean; /** Minimum allowed value */ min?: number; /** Maximum allowed value */ max?: number; parseNumber: (value: any) => number; } type FloatSchema = Omit, "parseNumber">; declare function cleanFloat(schema?: FloatSchema): WithSchema, FloatSchema>; type IntegerSchema = Omit, "parseNumber">; declare function cleanInteger(schema?: IntegerSchema): WithSchema, IntegerSchema>; type ParseKeysOptions = boolean | ((key: string) => string[]); interface ObjectSchema extends AnySchema { /** Create nested objects from keys like `job.position` * * `true`: split by dots * * `(string) => string[]`: custom key path parser function */ parseKeys?: ParseKeysOptions; /** Map of field names to their respective cleaners */ fields: { [F in keyof M]?: Cleaner; }; /** Non-field errors will be grouped under this pseudo field key */ nonFieldErrorsKey?: string; /** `groupErrors: true` (default) - group field errors by field name */ groupErrors?: boolean; } declare function cleanObject, T = M, V = any>(schema: ObjectSchema): WithSchema, ObjectSchema>; declare namespace cleanObject { var fields: >(fields: { [F in keyof T]?: Cleaner | undefined; }) => WithSchema, ObjectSchema>; } type UuidSchema = Omit, "regexp">; declare function cleanUuid(schema?: UuidSchema): WithSchema, UuidSchema>; type indexNs_AnySchema = AnySchema; type indexNs_ArraySchema = ArraySchema; type indexNs_BooleanSchema = BooleanSchema; type indexNs_DateSchema = DateSchema; type indexNs_EmailSchema = EmailSchema; type indexNs_FloatSchema = FloatSchema; type indexNs_IntegerSchema = IntegerSchema; type indexNs_ObjectSchema = ObjectSchema; type indexNs_StringSchema = StringSchema; type indexNs_UuidSchema = UuidSchema; declare namespace indexNs { export { cleanAny as any, indexNs_AnySchema as AnySchema, cleanArray as array, indexNs_ArraySchema as ArraySchema, cleanBoolean as boolean, indexNs_BooleanSchema as BooleanSchema, cleanDate as date, indexNs_DateSchema as DateSchema, cleanEmail as email, indexNs_EmailSchema as EmailSchema, cleanFloat as float, indexNs_FloatSchema as FloatSchema, cleanInteger as integer, indexNs_IntegerSchema as IntegerSchema, cleanObject as object, indexNs_ObjectSchema as ObjectSchema, cleanString as string, indexNs_StringSchema as StringSchema, cleanUuid as uuid, indexNs_UuidSchema as UuidSchema, }; } declare class SchemaError extends Error { } type ErrorMessage = string; type ErrorMessages = ErrorMessage[]; type FieldErrorMessages = { [field: string]: ErrorMessages; }; type SimpleFieldErrorMessages = { [field: string]: ErrorMessage | ErrorMessages; }; interface ErrorOptions { label?: string | null; } declare class ValidationError extends Error { messages?: ErrorMessages; errors?: FieldErrorMessages; opts: ErrorOptions; constructor(arg: ErrorMessage | ErrorMessages | SimpleFieldErrorMessages, opts?: Partial); } export { AnySchema, ArraySchema, BooleanSchema, Cleaner, DateSchema, EmailSchema, ErrorMessage, ErrorMessages, ErrorOptions, FieldErrorMessages, FloatSchema, IntegerSchema, ObjectSchema, SchemaError, SimpleFieldErrorMessages, StringSchema, UuidSchema, ValidationError, WithSchema, cleanAny as any, cleanArray as array, cleanBoolean as boolean, indexNs as clean, cleanAny, cleanArray, cleanBoolean, cleanDate, cleanEmail, cleanFloat, cleanInteger, cleanObject, cleanString, cleanUuid, cleanDate as date, cleanEmail as email, cleanFloat as float, cleanInteger as integer, cleanObject as object, setSchema, cleanString as string, cleanUuid as uuid };