UNPKG

@decaf-ts/decorator-validation

Version:
61 lines 2.58 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiffValidator = void 0; const Validator_1 = require("./Validator.cjs"); const constants_1 = require("./constants.cjs"); const decorators_1 = require("./decorators.cjs"); const reflection_1 = require("@decaf-ts/reflection"); /** * @summary Diff Validator * * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DiffValidator} * * @class DiffValidator * @extends Validator * * @category Validators */ let DiffValidator = class DiffValidator extends Validator_1.Validator { constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.DIFF) { super(message); } /** * @summary Validates a model * * @param {string} value * @param {DiffValidatorOptions} options * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings. * * @return {string | undefined} * * @override * @see Validator#hasErrors */ hasErrors(value, options, accessor) { let comparisonPropertyValue; try { comparisonPropertyValue = accessor.getValueFromPath(options[constants_1.ValidationKeys.DIFF]); } catch (e) { return this.getMessage(e.message || this.message); } return (0, reflection_1.isEqual)(value, comparisonPropertyValue) ? this.getMessage(options.message || this.message, options.label || options[constants_1.ValidationKeys.DIFF]) : undefined; } }; exports.DiffValidator = DiffValidator; exports.DiffValidator = DiffValidator = __decorate([ (0, decorators_1.validator)(constants_1.ValidationKeys.DIFF), __metadata("design:paramtypes", [String]) ], DiffValidator); //# sourceMappingURL=DiffValidator.js.map