import { ClassType } from "@marcj/estdlib"; import { PropertyCompilerSchema, PropertyValidator } from "./decorators"; export declare class PropertyValidatorError { readonly code: string; readonly message: string; constructor(code: string, message: string); } /** * The structure of a validation error. * * Path defines the shallow or deep path (using dots). * Message is an arbitrary message in english. */ export declare class ValidationError { /** * The path to the property. May be a deep path separated by dot. */ readonly path: string; /** * A lower cased error code that can be used to identify this error and translate. */ readonly code: string; /** * Free text of the error. */ readonly message: string; constructor( /** * The path to the property. May be a deep path separated by dot. */ path: string, /** * A lower cased error code that can be used to identify this error and translate. */ code: string, /** * Free text of the error. */ message: string); static createInvalidType(path: string, expectedType: string, actual: any): ValidationError; } /** * */ export declare class ValidationFailed { readonly errors: ValidationError[]; constructor(errors: ValidationError[]); } export declare function handleCustomValidator(propSchema: PropertyCompilerSchema, validator: PropertyValidator, value: any, propertyPath: string, errors: ValidationError[]): void; /** * Validates a set of method arguments and returns the number of errors found. */ export declare function validateMethodArgs(classType: ClassType, methodName: string, args: any[]): ValidationError[]; /** * Validates a object or class instance and returns all errors. * Returns an empty array if not errors found and validation succeeded. * * @example * ``` * validate(SimpleModel, {id: false}); * ``` */ export declare function validate(classType: ClassType, item: { [name: string]: any; } | T, path?: string): ValidationError[]; /** * A type guarded way of using Marshal. * * Note: Methods are not type guarded. * * @example * ``` * if (validates(SimpleMode, data)) { * //data is now typeof SimpleMode * } * ``` */ export declare function validates(classType: ClassType, item: { [name: string]: any; }): item is T; /** * A type guarded way of using Marshal as factory for faster access. * * Note: Methods are not type guarded. * * @example * ``` * const simpleModelValidates = validatesFactory(SimpleMode); * if (simpleModelValidates(data)) { * //data is now typeof SimpleMode * } * ``` */ export declare function validatesFactory(classType: ClassType): (item: { [name: string]: any; }) => item is T;