UNPKG

indicative-compiler

Version:

Indicative compiler to compile parsed schema into highly optimized functions

38 lines (37 loc) 1.26 kB
/** * @module compiler/validator */ import { ParsedRule, Message } from 'indicative-parser'; import { CollectorContract, ErrorFormatterContract, ErrorCollectorFn } from '../Contracts'; /** * Collector collects all the errors and creates a copy of validated * data (only when `generateTree = true`). */ export declare class Collector implements CollectorContract { formatter: ErrorFormatterContract; private generateTree; private customErrorCollector?; tree: any; hasErrors: boolean; constructor(formatter: ErrorFormatterContract, generateTree: boolean, customErrorCollector?: ErrorCollectorFn | undefined); /** * Set value of a given node. The function results in a noop * when `value === undefined` or the validation chain has * one or more errors. */ setValue(pointer: string, value: any): void; /** * Returns the collected data */ getData(): any; /** * Returns errors from the formatter */ getErrors(): any; /** * Passes error to the error formatter for a given field and rule. * Also when the message is undefined, it will create a generic * message. */ setError(pointer: string, rule: ParsedRule, message?: Message | Error): void; }