import { Connection } from "mysql"; import Model, { ModelType } from "./Model.js"; import ModelQuery from "./ModelQuery.js"; export declare const EMAIL_REGEX: RegExp; export default class Validator { static validate(validationMap: { [p: string]: Validator; }, body: { [p: string]: unknown; }): Promise; private readonly steps; private readonly validationAttributes; private readonly rawValueToHuman?; private _min?; private _max?; constructor(rawValueToHuman?: (val: V) => string); /** * @param thingName The name of the thing to validate. * @param value The value to verify. * @param onlyFormat {@code true} to only validate format properties, {@code false} otherwise. * @param connection A connection to use in case of wrapped transactions. */ execute(thingName: string, value: V | undefined, onlyFormat: boolean, connection?: Connection): Promise; defined(): Validator; acceptUndefined(alsoAcceptEmptyString?: boolean): Validator; equals(other?: V): Validator; sameAs(otherName?: string, other?: V): Validator; regexp(regexp: RegExp): Validator; length(length: number): Validator; /** * @param minLength included */ minLength(minLength: number): Validator; /** * @param maxLength included */ maxLength(maxLength: number): Validator; /** * @param minLength included * @param maxLength included */ between(minLength: number, maxLength: number): Validator; /** * @param min included */ min(min: number): Validator; /** * @param max included */ max(max: number): Validator; unique(model: M | ModelType, foreignKey?: string, querySupplier?: () => ModelQuery): Validator; exists(modelType: ModelType, foreignKey?: string): Validator; private addStep; getValidationAttributes(): string[]; step(step: number): Validator; } export declare class ValidationBag extends Error { private readonly errors; addMessage(err: ValidationError): void; addBag(otherBag: ValidationBag): void; hasMessages(): boolean; getMessages(): { [p: string]: ValidationError; }; getErrors(): ValidationError[]; } export declare class ValidationError extends Error { rawValueToHuman?: (val: V) => string; thingName?: string; value?: V; get name(): string; } export declare class BadLengthValidationError extends ValidationError { private readonly expectedLength; private readonly maxLength?; constructor(expectedLength: number, maxLength?: number); get message(): string; } export declare class TooShortError extends ValidationError { private readonly minLength; constructor(minLength: number); get message(): string; } export declare class TooLongError extends ValidationError { private readonly maxLength; constructor(maxLength: number); get message(): string; } export declare class BadValueValidationError extends ValidationError { private readonly expectedValue; constructor(expectedValue: V); get message(): string; } export declare class DifferentThanError extends ValidationError { private readonly otherName?; constructor(otherName?: string); get message(): string; } export declare class OutOfRangeValidationError extends ValidationError { private readonly min?; private readonly max?; constructor(min?: number, max?: number); get message(): string; } export declare class InvalidFormatValidationError extends ValidationError { get message(): string; } export declare class UndefinedValueValidationError extends ValidationError { get message(): string; } export declare class AlreadyExistsValidationError extends ValidationError { private readonly table; constructor(table: string); get message(): string; } export declare class UnknownRelationValidationError extends ValidationError { private readonly table; private readonly foreignKey?; constructor(table: string, foreignKey?: string); get message(): string; } export declare class FileError extends ValidationError { private readonly _message; constructor(message: string); get message(): string; } export declare type Lengthable = { length: number; }; export declare function isLenghtable(value: unknown): value is Lengthable;