@bshg/validation
Version:
Validation Library for TypeScript projects
61 lines (60 loc) • 2.47 kB
TypeScript
import { ValidatorFnConfig, ValidatorFnConfigAsync, ValidatorFnConfigCtx, ValidatorFnConfigCtxAsync, ValidatorFnDependConfig, ValidatorFnDependConfigAsync, ValidatorFnDependConfigCtx, ValidatorFnDependConfigCtxAsync } from "../utils";
export declare const messageVars: {
prefix: string;
value: string;
name: string;
};
export type FnConfig = {
message?: string | (() => string);
};
type UseCreateArgs<T> = {
error: (value: T) => boolean;
message: string;
options?: FnConfig;
args?: any[];
};
type UseDependCreateArgs<T, TO extends Record<string, any>> = {
error: (value: T, parent: TO) => boolean;
message: string;
options?: FnConfig;
args?: any[];
};
export declare const messageArgs: (defaultMsg: string, options?: FnConfig, ...args: any[]) => string;
export declare const message: (message: string, options?: FnConfig) => string;
export declare class TypeValidator<T> {
validations: ValidatorFnConfig<T>[];
validationsDepend: ValidatorFnDependConfig<T>[];
validationsAsync: ValidatorFnConfigAsync<T>[];
validationsDependAsync: ValidatorFnDependConfigAsync<T>[];
validationsCtx: ValidatorFnConfigCtx<T>[];
validationsDependCtx: ValidatorFnDependConfigCtx<T>[];
validationsCtxAsync: ValidatorFnConfigCtxAsync<T>[];
validationsDependCtxAsync: ValidatorFnDependConfigCtxAsync<T>[];
/**
* add simple validation errors
*/
onError(config: ValidatorFnConfig<T>): this;
onError<TO>(config: ValidatorFnDependConfig<T, TO>): this;
/**
* add simple validation errors basing on the context
*/
onErrorCtx(config: ValidatorFnConfigCtx<T>): this;
onErrorCtx<TO>(config: ValidatorFnDependConfigCtx<T, TO>): this;
protected useCostume(arg: UseCreateArgs<T>): this;
protected useCostume<TO extends Record<string, any>>(arg: UseDependCreateArgs<T, TO>): this;
/**
* add async validation errors
*/
onErrorAsync(config: ValidatorFnConfigAsync<T>): this;
onErrorAsync<TO>(config: ValidatorFnDependConfigAsync<T, TO>): this;
/**
* add async validation errors basing on the context
*/
onErrorCtxAsync(config: ValidatorFnConfigCtxAsync<T>): this;
onErrorCtxAsync<TO>(config: ValidatorFnDependConfigCtxAsync<T, TO>): this;
}
export type TypeValidatorWithContext<T, TContext extends Record<string, any>> = {
ctx: ((ctx: TContext) => boolean) | Partial<TContext>;
validations: TypeValidator<T>;
};
export {};