UNPKG

@kitmi/data

Version:

Jacaranda Framework Data Access Model

64 lines (63 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { _Validators: function() { return _Validators; }, default: function() { return _default; }, skipValidator: function() { return skipValidator; } }); const _allSync = /*#__PURE__*/ _interop_require_default(require("@kitmi/validators/allSync")); const _utils = require("@kitmi/utils"); const _types = require("@kitmi/types"); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const validatorTable = _allSync.default.handlers.validator; const _Validators = _utils._.mapValues(validatorTable, (validator, name)=>(entity, field, context, value, payload)=>{ if (!validator.__metaCheckNull && value == null) return value; if (skipValidator(field, context, name)) return value; const [validated, reason] = validator(value, payload, field, context); if (!validated) { if (context.options.$dryRun) { context.options.$errors || (context.options.$errors = []); context.options.$errors.push({ message: reason, info: { entity: entity.meta.name, field: field.name, value } }); return value; } throw new _types.ValidationError(reason, { entity: entity.meta.name, field: field.name, value, payload }); } return value; }); const skipValidator = (field, context, validatorName)=>{ const validators = context?.options.$skipValidators; if (validators && (validators.has(validatorName) || validators.has(field.name + '.' + validatorName))) return true; return false; }; const _default = validatorTable; //# sourceMappingURL=Validators.js.map