react-formawesome-core
Version:
React validation form core lib
48 lines (47 loc) • 1.86 kB
TypeScript
export interface UncertainObject<ReturnType = any> {
[key: string]: ReturnType;
}
export interface ErrorInterface {
attribute: string;
details: string;
}
export declare type ValidationModelInterface = UncertainObject;
export interface ModelContainerInterface<ModelI = UncertainObject> {
instance?: ModelI;
defaults?: ModelI;
}
export interface ValidatorPublicInterface<ModelI = UncertainObject> {
modelName: string;
modelValues: ModelI;
modelErrors: UncertainObject<string>;
modelAttributes: Array<string>;
dropToDefaults: () => void;
setDefaults: (defaults: UncertainObject) => void;
validate: (groups?: Array<string>) => Promise<void>;
setModelValue: (attribute: string, value: any) => void;
addErrors: (errors: Array<{
attribute: string;
details: string;
}>) => void;
}
export interface ValidatorConfig {
skipAttributeCheck?: boolean;
}
export declare abstract class AbstractValidator<ModelI = UncertainObject> implements ValidatorPublicInterface<ModelI> {
abstract validate: (groups?: Array<string>) => Promise<void>;
abstract readonly modelName: string;
protected modelErrorsContainer: Map<string, Array<ErrorInterface>>;
protected modelContainer: ModelContainerInterface;
protected config: ValidatorConfig;
readonly modelAttributes: Array<string>;
readonly modelValues: ModelI;
readonly modelErrors: UncertainObject<string>;
setModelValue: <T = any>(attribute: string, value: T) => void;
setDefaults: (defaults: Partial<ModelI>) => void;
dropToDefaults: () => void;
clear: () => void;
addErrors: (errors: ErrorInterface[]) => void;
protected handleErrors: (errors: any, groups: any) => void;
protected protectContainer: () => void;
private convertVendorErrors;
}