isvalid 3.1.1 → 3.1.2
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 +11 -9
- package/package.json +1 -1
package/lib/formalize.js
CHANGED
|
@@ -27,7 +27,9 @@ const formalizeObject = (formalizedSchema, nonFormalizedSchema, options) => {
|
|
|
27
27
|
|
|
28
28
|
formalizedSchema.schema = formalizedSchema.schema || {};
|
|
29
29
|
|
|
30
|
-
if (utils.instanceTypeName(formalizedSchema.schema) !== 'object')
|
|
30
|
+
if (utils.instanceTypeName(formalizedSchema.schema) !== 'object') {
|
|
31
|
+
throw new SchemaError(formalizedSchema.schema, 'Object schemas must be an object.');
|
|
32
|
+
}
|
|
31
33
|
|
|
32
34
|
// Build new formalized schema into this.
|
|
33
35
|
let formalizedSubSchema = {};
|
|
@@ -38,7 +40,7 @@ const formalizeObject = (formalizedSchema, nonFormalizedSchema, options) => {
|
|
|
38
40
|
formalizedSubSchema[key] = formalizeAny(formalizedSchema.schema[key], options);
|
|
39
41
|
});
|
|
40
42
|
|
|
41
|
-
formalizedSchema.schema = formalizedSubSchema;
|
|
43
|
+
formalizedSchema.schema = finalize(formalizedSubSchema, nonFormalizedSchema.schema);
|
|
42
44
|
|
|
43
45
|
if (typeof formalizedSchema.required === 'undefined') {
|
|
44
46
|
if (Object.keys(formalizedSubSchema).some((key) => formalizedSubSchema[key].required === true || formalizedSubSchema[key].required === 'implicit')) {
|
|
@@ -50,13 +52,13 @@ const formalizeObject = (formalizedSchema, nonFormalizedSchema, options) => {
|
|
|
50
52
|
|
|
51
53
|
};
|
|
52
54
|
|
|
53
|
-
const formalizeArray = (formalizedSchema,
|
|
55
|
+
const formalizeArray = (formalizedSchema, options) => {
|
|
54
56
|
|
|
55
57
|
// formalizedSchema has been pre-processed by formalizeAny, so
|
|
56
58
|
// we only need to formalize the sub-schema.
|
|
57
59
|
|
|
58
60
|
// If no sub-schema is provided we consider the schema final.
|
|
59
|
-
if (typeof formalizedSchema.schema === 'undefined') return
|
|
61
|
+
if (typeof formalizedSchema.schema === 'undefined') return formalizedSchema;
|
|
60
62
|
|
|
61
63
|
formalizedSchema.schema = formalizeAny(formalizedSchema.schema, options);
|
|
62
64
|
|
|
@@ -76,14 +78,14 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
76
78
|
|
|
77
79
|
if (!schema.type && !schema.post && !schema.pre && !schema.equal) {
|
|
78
80
|
if ('object' == utils.instanceTypeName(schema)) {
|
|
79
|
-
return formalizeAny({ type: Object, schema: schema },
|
|
81
|
+
return formalizeAny({ type: Object, schema: schema }, options);
|
|
80
82
|
}
|
|
81
83
|
if ('array' == utils.instanceTypeName(schema)) {
|
|
82
|
-
if (schema.length === 0) return formalizeAny({ type: Array },
|
|
83
|
-
return formalizeAny({ type: Array, schema: schema[0] },
|
|
84
|
+
if (schema.length === 0) return formalizeAny({ type: Array }, options);
|
|
85
|
+
return formalizeAny({ type: Array, schema: schema[0] }, options);
|
|
84
86
|
}
|
|
85
87
|
if ((typeof schema === 'string' && schema.length) || (typeof schema === 'function' && utils.typeName(schema) !== undefined)) {
|
|
86
|
-
return formalizeAny({ type: schema },
|
|
88
|
+
return formalizeAny({ type: schema }, options);
|
|
87
89
|
}
|
|
88
90
|
throw new SchemaError(schema, 'Schemas must have at least on validator of `type`, `post`/`pre` and/or `equal`.');
|
|
89
91
|
}
|
|
@@ -269,7 +271,7 @@ const formalizeAny = (schema, options = {}) => {
|
|
|
269
271
|
formalizedSchema = formalizeObject(formalizedSchema, schema, options);
|
|
270
272
|
}
|
|
271
273
|
else if (utils.isSameType('array', utils.typeName(formalizedSchema.type))) {
|
|
272
|
-
formalizedSchema = formalizeArray(formalizedSchema,
|
|
274
|
+
formalizedSchema = formalizeArray(formalizedSchema, options);
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
|