UNPKG

@decaf-ts/db-decorators

Version:

Agnostic database decorators and repository

35 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const decorator_validation_1 = require("@decaf-ts/decorator-validation"); const validation_1 = require("./validation.cjs"); /** * @description Validates the model and checks for errors * @summary Validates the current model state and optionally compares with a previous version * @template M - Type extending Model * @param {M|any} [previousVersion] - Optional previous version of the model for comparison * @param {...any[]} exclusions - Properties to exclude from validation * @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise * @function hasErrors * @memberOf module:db-decorators */ decorator_validation_1.Model.prototype.hasErrors = function (previousVersion, ...exclusions) { if (previousVersion && !(previousVersion instanceof decorator_validation_1.Model)) { exclusions.unshift(previousVersion); previousVersion = undefined; } const async = this.isAsync(); const errs = (0, decorator_validation_1.validate)(this, async, ...exclusions); if (async) { return Promise.resolve(errs).then((resolvedErrs) => { if (resolvedErrs || !previousVersion) { return resolvedErrs; } return (0, validation_1.validateCompare)(previousVersion, this, async, ...exclusions); }); } if (errs || !previousVersion) return errs; // @ts-expect-error Overriding Model prototype method with dynamic conditional return type. return (0, validation_1.validateCompare)(previousVersion, this, async, ...exclusions); }; //# sourceMappingURL=overrides.js.map