* Prepare and invoke a build-in validator. * * @private * * @param {*} value Anything. * @param {*} test The test case. * @param {string} validatorType One of known to Sequelize validators. * @param {string} field The field that is being validated * * @returns {object} An
(value, test, validatorType, field)
| 293 | * @returns {object} An object with specific keys to invoke the validator. |
| 294 | */ |
| 295 | async _invokeBuiltinValidator(value, test, validatorType, field) { |
| 296 | // Cast value as string to pass new Validator.js string requirement |
| 297 | const valueString = String(value); |
| 298 | // check if Validator knows that kind of validation test |
| 299 | if (typeof validator[validatorType] !== 'function') { |
| 300 | throw new Error(`Invalid validator function: ${validatorType}`); |
| 301 | } |
| 302 | |
| 303 | const validatorArgs = this._extractValidatorArgs(test, validatorType, field); |
| 304 | |
| 305 | if (!validator[validatorType](valueString, ...validatorArgs)) { |
| 306 | throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), { validatorName: validatorType, validatorArgs }); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Will extract arguments for the validator. |
no test coverage detected