indicative-compiler
Version:
Indicative compiler to compile parsed schema into highly optimized functions
68 lines (67 loc) • 2.53 kB
TypeScript
/**
* @module compiler/validator
*/
import { ParsedRule, ParsedRulesMessages } from 'indicative-parser';
import { CollectorContract, ValidationDataRoot, ValidationDefinition } from '../Contracts';
/**
* Runs a series of validations on a given field. This class is feeded with the
* computed nodes generated via [[TreeWalker]].
*/
export declare class ValidationsRunner {
private field;
private type;
private dotPath;
private fieldMessages;
private genericMessages;
/**
* We toggle this flag then creating the `validations` object
*/
async: boolean;
/**
* Collection of validations to be executed on a given field.
*/
private validations;
/**
* Base pointer to this field. When field is inside an
* array, then we need to re-compute the pointer
* based upon the current index in which this
* field is validated.
*
* However, we don't mutate this field.
*/
private pointer;
constructor(field: string, type: 'literal' | 'object' | 'array', dotPath: string[], rules: ParsedRule[], validations: {
[key: string]: ValidationDefinition;
}, fieldMessages: ParsedRulesMessages, genericMessages: ParsedRulesMessages);
/**
* Creating a list of validation functions to be executed as per
* the defined rules.
*/
private computeValidations;
/**
* Returns a fresh data copy by copying some of the values from the actual
* data and then mutating the `tip` and `pointer`. The tip and pointer
* are mutated so that the validation function receives the closest
* object from the pointer, resulting in performant code.
*/
private getDataCopy;
/**
* Reports value to the collector when current field is a literal
* node inside the tree and validation has passed
*/
private reportValueToCollector;
/**
* Reports the validation error to the collector.
*/
private reportErrorToCollector;
/**
* Executes all the validations on a given field synchronously. Run
* [[ValidationsRunner.execAsync]] if want to execute asynchronously.
*/
exec(data: ValidationDataRoot, collector: CollectorContract, config: unknown, bail?: boolean): boolean;
/**
* Executes all the validations on a given field asynchronously. Run
* [[ValidationsRunner.exec]] if want to execute synchronously.
*/
execAsync(data: ValidationDataRoot, collector: CollectorContract, config: unknown, bail?: boolean): Promise<boolean>;
}