87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import Model from "./Model";
|
|
import Query from "./Query";
|
|
import { Connection } from "mysql";
|
|
export default class Validator<T> {
|
|
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<void>;
|
|
defined(): Validator<T>;
|
|
acceptUndefined(): Validator<T>;
|
|
equals(other?: T): Validator<T>;
|
|
regexp(regexp: RegExp): Validator<T>;
|
|
length(length: number): Validator<T>;
|
|
/**
|
|
* @param minLength included
|
|
* @param maxLength included
|
|
*/
|
|
between(minLength: number, maxLength: number): Validator<T>;
|
|
/**
|
|
* @param min included
|
|
*/
|
|
min(min: number): Validator<T>;
|
|
/**
|
|
* @param max included
|
|
*/
|
|
max(max: number): Validator<T>;
|
|
unique(model: Model, querySupplier?: () => Query): Validator<T>;
|
|
exists(modelClass: Function, foreignKey?: string): Validator<T>;
|
|
private addStep;
|
|
getValidationAttributes(): string[];
|
|
step(step: number): Validator<T>;
|
|
}
|
|
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;
|
|
}
|