UNPKG

@berish/validate

Version:

Validation of complex objects with support for validation maps, rules and decorators

25 lines (24 loc) 1.32 kB
import { IValidateRule, IRuleErrorTextResult } from '../rule/types'; export declare type RuleArrayType = IValidateRule<any>[]; export declare type RuleTupleType<T> = [RuleArrayType, RuleMapType<T>]; export declare type RuleReferenceType = { $$ref: (string | symbol | number)[]; }; export declare type RuleReferenceTupleType = [RuleArrayType, RuleReferenceType]; export declare type RuleMapType<T> = { [Key in keyof T]?: RuleReferenceType | RuleReferenceTupleType | ValidateMap<T[Key]>; }; export declare type ValidateMap<T> = RuleArrayType | RuleMapType<T> | RuleTupleType<T>; export declare type ValidateMapCompactItem = [(string | symbol | number)[], RuleArrayType | RuleReferenceType | RuleReferenceTupleType]; export declare type ValidateMapCompact = ValidateMapCompactItem[]; export interface IValidationRuleResult { name: string; isValid: boolean; errorText: IRuleErrorTextResult; } export interface IValidationResult { key: (string | number | symbol)[]; rules: IValidationRuleResult[]; } export declare function validateMapSync<T>(obj: T, map: ValidateMap<T> | ValidateMapCompact, showOnlyInvalid?: boolean): IValidationResult[]; export declare function validateMapAsync<T>(obj: T, map: ValidateMap<T> | ValidateMapCompact, showOnlyInvalid?: boolean): Promise<IValidationResult[]>;