isvalid 4.1.29 → 4.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/formalize.js +13 -6
- package/lib/validate.js +3 -3
- package/package.json +1 -1
package/lib/formalize.js
CHANGED
|
@@ -124,7 +124,8 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
124
124
|
'errors': ['object'],
|
|
125
125
|
'pre': ['function', 'array', 'asyncfunction'],
|
|
126
126
|
'post': ['function', 'array', 'asyncfunction'],
|
|
127
|
-
'priority': 'number'
|
|
127
|
+
'priority': 'number',
|
|
128
|
+
'_plugins': 'any'
|
|
128
129
|
};
|
|
129
130
|
|
|
130
131
|
// Validators specific to type.
|
|
@@ -164,7 +165,6 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
164
165
|
key = convenienceNames[key] || key;
|
|
165
166
|
|
|
166
167
|
let validator = validators[key];
|
|
167
|
-
let test = formalizedSchema[key];
|
|
168
168
|
|
|
169
169
|
if (typeof validator === 'undefined') {
|
|
170
170
|
|
|
@@ -184,8 +184,13 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
184
184
|
|
|
185
185
|
if (typeof plugin === 'undefined') throw new SchemaError(schema, `Validator \`${key}\` is unknown in this context.`);
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
Object.defineProperty(formalizedSchema, '_plugins', {
|
|
188
|
+
value: formalizedSchema._plugins || {},
|
|
189
|
+
enumerable: false,
|
|
190
|
+
writable: true
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
formalizedSchema._plugins[key] = {
|
|
189
194
|
phase: plugin.phase || 'post',
|
|
190
195
|
validator: plugin.validate,
|
|
191
196
|
formalize: plugin.formalize
|
|
@@ -193,6 +198,8 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
193
198
|
|
|
194
199
|
}
|
|
195
200
|
|
|
201
|
+
let test = formalizedSchema[key];
|
|
202
|
+
|
|
196
203
|
// Test for - and transform - errors in validator.
|
|
197
204
|
if (Array.isArray(test) &&
|
|
198
205
|
|
|
@@ -218,9 +225,9 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
218
225
|
);
|
|
219
226
|
}
|
|
220
227
|
|
|
221
|
-
if (typeof (formalizedSchema.
|
|
228
|
+
if (typeof (formalizedSchema._plugins || {})[key] !== 'undefined') {
|
|
222
229
|
try {
|
|
223
|
-
formalizedSchema[key] = formalizedSchema.
|
|
230
|
+
formalizedSchema[key] = formalizedSchema._plugins[key].formalize(formalizedSchema[key], key, type) || formalizedSchema[key];
|
|
224
231
|
} catch (error) {
|
|
225
232
|
throw new SchemaError(schema, error.message);
|
|
226
233
|
}
|
package/lib/validate.js
CHANGED
|
@@ -380,9 +380,9 @@ const validateCustom = async (phase, data, schema, options, keyPath, validatedDa
|
|
|
380
380
|
|
|
381
381
|
const validatePlugins = async (phase, data, schema, options, keyPath) => {
|
|
382
382
|
|
|
383
|
-
const plugins = Object.keys(schema.
|
|
384
|
-
.filter((key) => schema.
|
|
385
|
-
.map((key) => [key, schema.
|
|
383
|
+
const plugins = Object.keys(schema._plugins || {})
|
|
384
|
+
.filter((key) => schema._plugins[key].phase === phase)
|
|
385
|
+
.map((key) => [key, schema._plugins[key].validator]);
|
|
386
386
|
|
|
387
387
|
for (let idx = 0 ; idx < plugins.length ; idx++) {
|
|
388
388
|
const [key, validator] = plugins[idx];
|