isvalid 4.1.28 → 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 CHANGED
@@ -81,10 +81,13 @@ const formalizeAny = (schema, options = {}) => {
81
81
 
82
82
  // If schema is already formalized we just call back.
83
83
  if (typeof schema._nonFormalizedSchema !== 'undefined') {
84
- if (options.force === true) {
85
- return formalizeAny(schema._nonFormalizedSchema, options);
86
- }
87
- return schema;
84
+
85
+ if (options.force !== true) return schema;
86
+
87
+ schema = merge.strategy({
88
+ objectKeyLookupMethod: 'keys'
89
+ })({}, schema);
90
+
88
91
  }
89
92
 
90
93
  if (!schema.type && !schema.post && !schema.pre && !schema.equal) {
@@ -121,7 +124,8 @@ const formalizeAny = (schema, options = {}) => {
121
124
  'errors': ['object'],
122
125
  'pre': ['function', 'array', 'asyncfunction'],
123
126
  'post': ['function', 'array', 'asyncfunction'],
124
- 'priority': 'number'
127
+ 'priority': 'number',
128
+ '_plugins': 'any'
125
129
  };
126
130
 
127
131
  // Validators specific to type.
@@ -161,7 +165,6 @@ const formalizeAny = (schema, options = {}) => {
161
165
  key = convenienceNames[key] || key;
162
166
 
163
167
  let validator = validators[key];
164
- let test = formalizedSchema[key];
165
168
 
166
169
  if (typeof validator === 'undefined') {
167
170
 
@@ -181,8 +184,13 @@ const formalizeAny = (schema, options = {}) => {
181
184
 
182
185
  if (typeof plugin === 'undefined') throw new SchemaError(schema, `Validator \`${key}\` is unknown in this context.`);
183
186
 
184
- formalizedSchema.plugins = formalizedSchema.plugins || {};
185
- formalizedSchema.plugins[key] = {
187
+ Object.defineProperty(formalizedSchema, '_plugins', {
188
+ value: formalizedSchema._plugins || {},
189
+ enumerable: false,
190
+ writable: true
191
+ });
192
+
193
+ formalizedSchema._plugins[key] = {
186
194
  phase: plugin.phase || 'post',
187
195
  validator: plugin.validate,
188
196
  formalize: plugin.formalize
@@ -190,6 +198,8 @@ const formalizeAny = (schema, options = {}) => {
190
198
 
191
199
  }
192
200
 
201
+ let test = formalizedSchema[key];
202
+
193
203
  // Test for - and transform - errors in validator.
194
204
  if (Array.isArray(test) &&
195
205
 
@@ -215,9 +225,9 @@ const formalizeAny = (schema, options = {}) => {
215
225
  );
216
226
  }
217
227
 
218
- if (typeof (formalizedSchema.plugins || {})[key] !== 'undefined') {
228
+ if (typeof (formalizedSchema._plugins || {})[key] !== 'undefined') {
219
229
  try {
220
- formalizedSchema[key] = formalizedSchema.plugins[key].formalize(formalizedSchema[key], key, type) || formalizedSchema[key];
230
+ formalizedSchema[key] = formalizedSchema._plugins[key].formalize(formalizedSchema[key], key, type) || formalizedSchema[key];
221
231
  } catch (error) {
222
232
  throw new SchemaError(schema, error.message);
223
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.plugins || {})
384
- .filter((key) => schema.plugins[key].phase === phase)
385
- .map((key) => [key, schema.plugins[key].validator]);
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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isvalid",
3
- "version": "4.1.28",
3
+ "version": "4.1.30",
4
4
  "description": "Async JSON validation library for node.js.",
5
5
  "main": "./index.js",
6
6
  "type": "module",