import { type IContainer, type IFactory, type Constructable, type Transformer, type Key } from '@aurelia/kernel'; import { BindingBehaviorExpression } from '@aurelia/expression-parser'; import { IConnectable, type Scope } from '@aurelia/runtime'; import { PropertyBinding } from '@aurelia/runtime-html'; import { PropertyAccessor, PropertyRule, ValidationResult, IValidator, ValidateInstruction, type IValidateable } from '@aurelia/validation'; export type BindingWithBehavior = PropertyBinding & { ast: BindingBehaviorExpression; target: Element | object; }; export type ValidateEventKind = 'validate' | 'reset'; /** * The result of a call to the validation controller's validate method. */ export declare class ControllerValidateResult { valid: boolean; results: ValidationResult[]; instruction?: Partial | undefined; /** * @param {boolean} valid - `true` if the validation passed, else `false`. * @param {ValidationResult[]} results - The validation result of every rule that was evaluated. * @param {ValidateInstruction} [instruction] - The instruction passed to the controller's validate method. */ constructor(valid: boolean, results: ValidationResult[], instruction?: Partial | undefined); } /** * Describes the validation result and target elements pair. * Used to notify the subscribers. */ export declare class ValidationResultTarget { result: ValidationResult; targets: Element[]; constructor(result: ValidationResult, targets: Element[]); } /** * Describes the contract of the validation event. * Used to notify the subscribers. */ export declare class ValidationEvent { kind: ValidateEventKind; addedResults: ValidationResultTarget[]; removedResults: ValidationResultTarget[]; /** * @param {ValidateEventKind} kind - 'validate' or 'reset'. * @param {ValidationResultTarget[]} addedResults - new errors added. * @param {ValidationResultTarget[]} removedResults - old errors removed. * @memberof ValidationEvent */ constructor(kind: ValidateEventKind, addedResults: ValidationResultTarget[], removedResults: ValidationResultTarget[]); } /** * Contract of the validation errors subscriber. * The subscriber should implement this interface. */ export interface ValidationResultsSubscriber { handleValidationEvent(event: ValidationEvent): void; } /** * Describes a binding information to the validation controller. * This is provided by the `validate` binding behavior during binding registration. */ export declare class BindingInfo { sourceObserver: IConnectable; target: Element; scope: Scope; rules?: PropertyRule[] | undefined; propertyInfo: PropertyInfo | undefined; /** * @param {IConnectable} sourceObserver - An observer for the binding source. * @param {Element} target - The HTMLElement associated with the binding. * @param {Scope} scope - The binding scope. * @param {PropertyRule[]} [rules] - Rules bound to the binding behavior. * @param {(PropertyInfo | undefined)} [propertyInfo] - Information describing the associated property for the binding. * @memberof BindingInfo */ constructor(sourceObserver: IConnectable, target: Element, scope: Scope, rules?: PropertyRule[] | undefined, propertyInfo?: PropertyInfo | undefined); } declare class PropertyInfo { object: any; propertyName: string; constructor(object: any, propertyName: string); } export declare function getPropertyInfo(binding: BindingWithBehavior, info: BindingInfo): PropertyInfo | undefined; /** * Orchestrates validation. * Manages a set of bindings, subscribers and objects. */ export interface IValidationController { /** * Collection of registered property bindings. * * @type {Map} */ readonly bindings: Map; /** * Objects that have been added to the controller instance (entity-style validation). * * @type {(Map)} */ readonly objects: Map; /** * Collection of registered subscribers. * * @type {Set} */ readonly subscribers: Set; /** * Current set of validation results. * * @type {ValidationResult[]} */ readonly results: ValidationResult[]; /** * The core validator, used to perform all validation. * * @type {IValidator} */ validator: IValidator; /** * Whether the controller is currently validating. * * @type {boolean} */ validating: boolean; /** * Validates and notifies the subscribers with the result. * * @template TObject * @param {ValidateInstruction} [instruction] - If omitted, then all the registered objects and bindings will be validated. */ validate(instruction?: Partial>): Promise; /** * Registers the given `object` with optional `rules` to the controller. * During `validate` without instruction, the object will be validated. * If the instruction consists of only an object tag, and the `object` is tagged also with the similar tag, it will be validated. */ addObject(object: IValidateable, rules?: PropertyRule[]): void; /** * Deregisters the given `object` from the controller; i.e. during `validate` the `object` won't be validated. */ removeObject(object: IValidateable): void; /** * Adds a manual error. This is never removed explicitly by validation controller when re-validating the errors. * The subscribers gets notified. */ addError(message: string, object: TObject, propertyName?: string | PropertyAccessor | null): ValidationResult; /** * Removes an error from the controller. * The subscribers gets notified. */ removeError(result: ValidationResult): void; /** * Registers the `subscriber` to the controller. * The `subscriber` does not get notified of the previous errors. */ addSubscriber(subscriber: ValidationResultsSubscriber): void; /** * Deregisters the `subscriber` from the controller. */ removeSubscriber(subscriber: ValidationResultsSubscriber): void; /** * Resets the results for a property associated with a binding. */ resetBinding(binding: BindingWithBehavior): void; /** * Revalidates the controller's current set of results. */ revalidateErrors(): Promise; /** * Resets any validation results. * * @param {ValidateInstruction} [instruction] - Instructions on what to reset. If omitted all rendered results will be removed. */ reset(instruction?: ValidateInstruction): void; } export declare const IValidationController: import("@aurelia/kernel").InterfaceSymbol; export declare class ValidationController implements IValidationController { readonly bindings: Map; readonly subscribers: Set; readonly results: ValidationResult[]; validating: boolean; /** * Elements related to validation results that have been rendered. * * @private * @type {Map} */ private readonly elements; readonly objects: Map; readonly validator: IValidator; private readonly parser; addObject(object: IValidateable, rules?: PropertyRule[]): void; removeObject(object: IValidateable): void; addError(message: string, object: TObject, propertyName?: string | PropertyAccessor): ValidationResult; removeError(result: ValidationResult): void; addSubscriber(subscriber: ValidationResultsSubscriber): void; removeSubscriber(subscriber: ValidationResultsSubscriber): void; registerBinding(binding: BindingWithBehavior, info: BindingInfo): void; unregisterBinding(binding: BindingWithBehavior): void; validate(instruction?: Partial>): Promise; reset(instruction?: ValidateInstruction): void; validateBinding(binding: BindingWithBehavior): Promise; resetBinding(binding: BindingWithBehavior): void; revalidateErrors(): Promise; /** * Interprets the instruction and returns a predicate that will identify relevant results in the list of rendered validation results. */ private getInstructionPredicate; /** * Gets the elements associated with an object and propertyName (if any). */ private getAssociatedElements; private processResultDelta; } export declare class ValidationControllerFactory implements IFactory> { Type: Constructable; registerTransformer(_transformer: Transformer>): boolean; construct(container: IContainer, _dynamicDependencies?: Key[] | undefined): IValidationController; } export {}; //# sourceMappingURL=validation-controller.d.ts.map