import { ReceiveType } from './reflection/reflection.js'; import { CustomError, TypeAnnotation } from '@deepkit/core'; import { Type } from './reflection/type.js'; import { Serializer } from './serializer.js'; export type ValidatorMeta = TypeAnnotation<'validator', [Name, Args]>; export type ValidateFunction = (value: any, type: Type, options: any) => ValidatorError | void; export type Validate[2] = unknown> = ValidatorMeta<'function', [T, Options]>; export type Pattern = ValidatorMeta<'pattern', [T]>; export type Alpha = ValidatorMeta<'alpha'>; export type Alphanumeric = ValidatorMeta<'alphanumeric'>; export type Ascii = ValidatorMeta<'ascii'>; export type Decimal = ValidatorMeta<'decimal', [MinDigits, MaxDigits]>; export type MultipleOf = ValidatorMeta<'multipleOf', [Num]>; export type MinLength = ValidatorMeta<'minLength', [Length]>; export type MaxLength = ValidatorMeta<'maxLength', [Length]>; export type Includes = ValidatorMeta<'includes', [T]>; export type Excludes = ValidatorMeta<'excludes', [T]>; export type Minimum = ValidatorMeta<'minimum', [T]>; export type Maximum = ValidatorMeta<'maximum', [T]>; /** Includes 0. Use PositiveNoZero to exclude 0. */ export type Positive = ValidatorMeta<'positive', unknown & [true]>; /** * Includes 0. Use NegativeNoZero to exclude 0. */ export type Negative = ValidatorMeta<'negative', [true]>; export type PositiveNoZero = ValidatorMeta<'positive', [false]>; export type NegativeNoZero = ValidatorMeta<'negative', [false]>; export type ExclusiveMinimum = ValidatorMeta<'exclusiveMinimum', [T]>; export type ExclusiveMaximum = ValidatorMeta<'exclusiveMaximum', [T]>; export type BeforeDate = ValidatorMeta<'beforeDate', [T]>; export type AfterDate = ValidatorMeta<'afterDate', [T]>; export type BeforeNow = ValidatorMeta<'beforeNow'>; export type AfterNow = ValidatorMeta<'afterNow'>; export declare const EMAIL_REGEX: RegExp; export type Email = string & Pattern; /** * Used in validator functions. */ export declare class ValidatorError { readonly code: string; readonly message: string; readonly path?: string | undefined; constructor(code: string, message: string, path?: string | undefined); } /** * The structure of a validation error. * * Path defines the shallow or deep path (using dots). * Message is an arbitrary message in english. * * In validators please use and return `new ValidatorError('code', 'message')` instead. */ export declare class ValidationErrorItem { /** * The path to the property. Might be a deep path separated by dot. */ readonly path: string; /** * A lower cased error code that can be used to identify this error and translate. */ readonly code: string; /** * Free text of the error. */ readonly message: string; /** * Optional value that caused the error. */ readonly value?: any | undefined; constructor( /** * The path to the property. Might be a deep path separated by dot. */ path: string, /** * A lower cased error code that can be used to identify this error and translate. */ code: string, /** * Free text of the error. */ message: string, /** * Optional value that caused the error. */ value?: any | undefined); toString(prefix?: string): string; } export declare class ValidationError extends CustomError { readonly errors: ValidationErrorItem[]; constructor(errors: ValidationErrorItem[], type?: Type); static from(errors: { path: string; message: string; code?: string; value?: any; }[]): ValidationError; } /** * Returns empty array when valid, or ValidationErrorItem[] with detailed error messages if not valid. * * Returns validation error items when failed. If successful returns an empty array. */ export declare function validate(data: any, type?: ReceiveType): ValidationErrorItem[]; export declare function validateFunction(serializerToUse?: Serializer, type?: ReceiveType): (data: T) => ValidationErrorItem[]; /** * Returns true when valid, and false if not. */ export declare function validates(data: any, type?: ReceiveType): boolean; export declare type __ΩValidatorMeta = any[]; export declare type __ΩValidateFunction = any[]; export declare type __ΩValidate = any[]; export declare type __ΩPattern = any[]; export declare type __ΩAlpha = any[]; export declare type __ΩAlphanumeric = any[]; export declare type __ΩAscii = any[]; export declare type __ΩDecimal = any[]; export declare type __ΩMultipleOf = any[]; export declare type __ΩMinLength = any[]; export declare type __ΩMaxLength = any[]; export declare type __ΩIncludes = any[]; export declare type __ΩExcludes = any[]; export declare type __ΩMinimum = any[]; export declare type __ΩMaximum = any[]; export declare type __ΩPositive = any[]; export declare type __ΩNegative = any[]; export declare type __ΩPositiveNoZero = any[]; export declare type __ΩNegativeNoZero = any[]; export declare type __ΩExclusiveMinimum = any[]; export declare type __ΩExclusiveMaximum = any[]; export declare type __ΩBeforeDate = any[]; export declare type __ΩAfterDate = any[]; export declare type __ΩBeforeNow = any[]; export declare type __ΩAfterNow = any[]; export declare type __ΩEmail = any[];