* Instance Validator. * * @param {Instance} modelInstance The model instance. * @param {object} options A dictionary with options. * * @private
| 17 | * @private |
| 18 | */ |
| 19 | class InstanceValidator { |
| 20 | constructor(modelInstance, options) { |
| 21 | options = { |
| 22 | class="cm">// assign defined and default options |
| 23 | hooks: true, |
| 24 | ...options |
| 25 | }; |
| 26 | |
| 27 | if (options.fields && !options.skip) { |
| 28 | options.skip = _.difference(Object.keys(modelInstance.constructor.rawAttributes), options.fields); |
| 29 | } else { |
| 30 | options.skip = options.skip || []; |
| 31 | } |
| 32 | |
| 33 | this.options = options; |
| 34 | |
| 35 | this.modelInstance = modelInstance; |
| 36 | |
| 37 | /** |
| 38 | * Exposes a reference to validator.js. This allows you to add custom validations using `validator.extend` |
| 39 | * |
| 40 | * @name validator |
| 41 | * @private |
| 42 | */ |
| 43 | this.validator = validator; |
| 44 | |
| 45 | /** |
| 46 | * All errors will be stored here from the validations. |
| 47 | * |
| 48 | * @type {Array} Will contain keys that correspond to attributes which will |
| 49 | * be Arrays of Errors. |
| 50 | * @private |
| 51 | */ |
| 52 | this.errors = []; |
| 53 | |
| 54 | /** |
| 55 | * @type {boolean} Indicates if validations are in progress |
| 56 | * @private |
| 57 | */ |
| 58 | this.inProgress = false; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * The main entry point for the Validation module, invoke to start the dance. |
| 63 | * |
| 64 | * @returns {Promise} |
| 65 | * @private |
| 66 | */ |
| 67 | async _validate() { |
| 68 | if (this.inProgress) throw new Error(class="st">'Validations already in progress.'); |
| 69 | |
| 70 | this.inProgress = true; |
| 71 | |
| 72 | await Promise.all([ |
| 73 | this._perAttributeValidators(), |
| 74 | this._customValidators() |
| 75 | ]); |
| 76 |
nothing calls this directly
no outgoing calls
no test coverage detected