import Model from "./Model"; import Query from "./Query"; import { Connection } from "mysql"; export default class Validator { private readonly steps; private readonly validationAttributes; private _min?; private _max?; /** * @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: T | undefined, onlyFormat: boolean, connection?: Connection): Promise; defined(): Validator; acceptUndefined(): Validator; equals(other?: T): Validator; regexp(regexp: RegExp): Validator; length(length: 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: Model, querySupplier?: () => Query): Validator; exists(modelClass: Function, foreignKey?: string): Validator; private addStep; getValidationAttributes(): string[]; step(step: number): Validator; } export declare class ValidationBag extends Error { private readonly messages; addMessage(err: ValidationError): void; hasMessages(): boolean; getMessages(): { [p: string]: ValidationError; }; } export declare abstract class ValidationError extends Error { thingName?: string; value?: any; 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 BadValueValidationError extends ValidationError { private readonly expectedValue; constructor(expectedValue: any); 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; }