@vaadin/hilla-lit-form
Version:
Hilla form utils
34 lines (33 loc) • 1.45 kB
TypeScript
import type { BinderNode } from './BinderNode.js';
import type { BinderRoot } from './BinderRoot.js';
import type { Value } from './Models.js';
import type { ProvisionalModel } from './ProvisionalModel.js';
export interface ValueError<T = unknown> {
property: ProvisionalModel | string;
message: string;
value: T;
validator: Validator<T>;
validatorMessage?: string;
}
export interface ValidationResult {
property: ProvisionalModel | string;
message?: string;
}
export declare class ValidationError extends Error {
errors: readonly ValueError[];
constructor(errors: readonly ValueError[]);
}
export type InterpolateMessageCallback<M extends ProvisionalModel> = (message: string, validator: Validator<Value<M>>, binderNode: BinderNode<M>) => string;
export interface Validator<T = unknown> {
message: string;
impliesRequired?: boolean;
name?: string;
validate(value: T, binder: BinderRoot): Promise<ValidationResult | boolean | readonly ValidationResult[]> | ValidationResult | boolean | readonly ValidationResult[];
}
export declare class ServerValidator implements Validator {
name: string;
message: string;
constructor(message: string);
validate: () => boolean;
}
export declare function runValidator<M extends ProvisionalModel>(model: M, validator: Validator<Value<M>>, interpolateMessageCallback?: InterpolateMessageCallback<M>): Promise<ReadonlyArray<ValueError<Value<M>>>>;