OCA_Backend/api/node_modules/sequelize/dist/lib/instance-validator.js.map

8 lines
18 KiB
Plaintext
Raw Permalink Normal View History

2022-01-22 13:36:44 +00:00
{
"version": 3,
"sources": ["../../lib/instance-validator.js"],
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('./utils');\nconst sequelizeError = require('./errors');\nconst DataTypes = require('./data-types');\nconst BelongsTo = require('./associations/belongs-to');\nconst validator = require('./utils/validator-extras').validator;\nconst { promisify } = require('util');\n\n/**\n * Instance Validator.\n *\n * @param {Instance} modelInstance The model instance.\n * @param {object} options A dictionary with options.\n *\n * @private\n */\nclass InstanceValidator {\n constructor(modelInstance, options) {\n options = {\n // assign defined and default options\n hooks: true,\n ...options\n };\n\n if (options.fields && !options.skip) {\n options.skip = _.difference(Object.keys(modelInstance.constructor.rawAttributes), options.fields);\n } else {\n options.skip = options.skip || [];\n }\n\n this.options = options;\n\n this.modelInstance = modelInstance;\n\n /**\n * Exposes a reference to validator.js. This allows you to add custom validations using `validator.extend`\n *\n * @name validator\n * @private\n */\n this.validator = validator;\n\n /**\n * All errors will be stored here from the validations.\n *\n * @type {Array} Will contain keys that correspond to attributes which will\n * be Arrays of Errors.\n * @private\n */\n this.errors = [];\n\n /**\n * @type {boolean} Indicates if validations are in progress\n * @private\n */\n this.inProgress = false;\n }\n\n /**\n * The main entry point for the Validation module, invoke to start the dance.\n *\n * @returns {Promise}\n * @private\n */\n async _validate() {\n if (this.inProgress) throw new Error('Validations already in progress.');\n\n this.inProgress = true;\n\n await Promise.all([\n this._perAttributeValidators(),\n this._customValidators()\n ]);\n\n if (this.errors.length) {\n throw new sequelizeError.ValidationError(null, this.errors);\n }\n }\n\n /**\n * Invoke the Validation sequence and run validation hooks if defined\n * - Before Validation Model Hooks\n * - Validation\n * - On validation success: After Validation Model Hooks\n * - On validation failure: Validation Failed Model Hooks\n *\n * @returns {Promise}\n * @private\n */\n async validate() {\n return await (this.options.hooks ? this._validateAndRunHooks() : this._validate());\n }\n\n /**\n * Invoke the Validation sequence and run hooks\n * - Before Validation Model Hooks\n * - Validation\n * - On validation success: After Validation Model Hooks\n * - On validation failure: Validation Failed Model Hooks\n *\n * @returns {Promise}\n * @private\n */\n async _validateAndRunHooks() {\n const runHooks = this.modelInstance.constructor.runHooks.bind(this.modelInstance.constructor);\n await runHooks('beforeValidate', this.modelInstance, this.options);\n\n try {\n await this._validate();\n } catch (error) {\n const newError = await runHooks('validationFailed', this.modelInstance, this.options, error);\n throw newError || error;\n }\n\n await runHooks('afterValidate', this.modelInstance, this.options);\n return this.modelInstance;\n }\n\n /**\n * Will run all the validators defined per attribute (built-in validators and custom validators)\n *\n * @returns {Promise<Array>}\n * @private\n */\n async _perAttributeValidators() {\n // promisify all attribute invocations\n const validators = [];\n\n _.forIn(this.modelInstance.rawAttributes, (rawAttribute, field) => {\n if (this.options.skip.includes(field)) {\n return;\n }\n\n const value = this.modelInstance.dataValues[field];\n\n if (value instanceof Utils.SequelizeMethod) {\n return;\n }\n\n if (!rawAttribute._autoGenerated && !rawAttribute.autoIncrement) {\n // perform validations based on schema\n this._validateSchema(rawAttribute, field, value);\n
"mappings": ";;;;;;;;;;;;;;;;;AAEA,MAAM,IAAI,QAAQ;AAClB,MAAM,QAAQ,QAAQ;AACtB,MAAM,iBAAiB,QAAQ;AAC/B,MAAM,YAAY,QAAQ;AAC1B,MAAM,YAAY,QAAQ;AAC1B,MAAM,YAAY,QAAQ,4BAA4B;AACtD,MAAM,EAAE,cAAc,QAAQ;AAU9B,wBAAwB;AAAA,EACtB,YAAY,eAAe,SAAS;AAClC,cAAU;AAAA,MAER,OAAO;AAAA,OACJ;AAGL,QAAI,QAAQ,UAAU,CAAC,QAAQ,MAAM;AACnC,cAAQ,OAAO,EAAE,WAAW,OAAO,KAAK,cAAc,YAAY,gBAAgB,QAAQ;AAAA,WACrF;AACL,cAAQ,OAAO,QAAQ,QAAQ;AAAA;AAGjC,SAAK,UAAU;AAEf,SAAK,gBAAgB;AAQrB,SAAK,Y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