UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

34 lines 1.35 kB
import { DEFAULT_ERROR_MESSAGES as DecoratorMessages, Validator, } from "@decaf-ts/decorator-validation"; /** * @description Abstract base class for validators that compare new values with old values during updates. * @summary Base class for an Update validator that provides a framework for implementing validation logic that compares a new value with its previous state. * @param {string} [message] - Error message. Defaults to {@link DecoratorMessages#DEFAULT} * @param {string[]} [acceptedTypes] - The accepted value types by the decorator * @class UpdateValidator * @example * // Extending UpdateValidator to create a custom validator * class MyCustomValidator extends UpdateValidator { * constructor() { * super("Custom validation failed"); * } * * public updateHasErrors(value: any, oldValue: any): string | undefined { * // Custom validation logic * if (value === oldValue) { * return this.message; * } * return undefined; * } * * hasErrors(value: any): string | undefined { * return undefined; // Not used for update validators * } * } * @category Validators */ export class UpdateValidator extends Validator { constructor(message = DecoratorMessages.DEFAULT, ...acceptedTypes) { super(message, ...acceptedTypes); } } //# sourceMappingURL=UpdateValidator.js.map