UNPKG

lakmus

Version:
35 lines (34 loc) 1.47 kB
import { Validator } from "./validator"; import { ValidationError } from "./results/validation-error"; import { PropertyValidator } from "./validators/property-validator"; /** Defines a rule associated with a property which can have multiple validators. */ export declare class ValidationRule<TInstance, TProperty> { /** Collection validators to apply. */ collectionValidators: Validator<any>[]; /** Property name. */ propertyName: string; /** Property name to display in error message. */ propertyDisplayName: string; /** Property validators to apply. */ propertyValidators: PropertyValidator[]; /** Custom validators to apply. */ validators: Validator<TProperty>[]; /** Conditions that control when the rule should execute. */ when: { (instance: TInstance): boolean; }[]; /** * Initializes a new instance of the ValidationRule class. * @param name Property name. */ constructor(name: string); /** * Performs validation using an object instance and returns a collection of validation errors. * @param instance The object to validate. */ validate(instance: TInstance): ValidationError[]; private validateWithCollectionValidator(context, validator, errors); private validateWithValidator(value, validator, errors); private validateWithPropertyValidator(context, validator, errors); private getValue(instance); }