schematox 0.3.0 → 0.3.1
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/CHANGELOG.md +15 -1
- package/dist/parse.js +47 -80
- package/dist/struct.js +23 -66
- package/dist/utils/fp.js +2 -2
- package/dist/validate.js +33 -80
- package/dist/verify-primitive.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.3.
|
|
3
|
+
## [0.3.1](https://github.com/incerta/schematox/compare/v0.3.0...v0.3.1)
|
|
4
|
+
|
|
5
|
+
### Bugfix
|
|
6
|
+
|
|
7
|
+
- [`e3527df`](https://github.com/incerta/schematox/commit/e3527dfb46b73a4b6579e3d2aea58f3301aded9a) [#24](https://github.com/incerta/schematox/pull/25) Parser should preserve object optional key only if it is specified in source
|
|
8
|
+
|
|
9
|
+
### Chore
|
|
10
|
+
|
|
11
|
+
- [`7d98a81`](https://github.com/incerta/schematox/commit/7d98a81c2bc18280299365da32f8346d5b145560) Use "es2015" tsconfig target instead of outdated "es5"
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- [`8bc2082`](https://github.com/incerta/schematox/commit/8bc208211457901f4f7246f00694f112d56f8d56) [#22](https://github.com/incerta/schematox/issues/22) Ensure optional properties in schemas reflect as optional in object context (@incerta)
|
|
16
|
+
|
|
17
|
+
## [0.3.0](https://github.com/incerta/schematox/compare/v0.2.0...v0.3.0)
|
|
4
18
|
|
|
5
19
|
### Features
|
|
6
20
|
|
package/dist/parse.js
CHANGED
|
@@ -1,48 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.parse = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const fp_1 = require("./utils/fp");
|
|
6
|
+
const verify_primitive_1 = require("./verify-primitive");
|
|
43
7
|
function parse(schema, subject) {
|
|
44
|
-
|
|
45
|
-
var errors = [];
|
|
8
|
+
const errors = [];
|
|
46
9
|
if (schema.optional === true && subject === undefined) {
|
|
47
10
|
return (0, fp_1.right)(undefined);
|
|
48
11
|
}
|
|
@@ -57,18 +20,32 @@ function parse(schema, subject) {
|
|
|
57
20
|
{
|
|
58
21
|
code: error_1.ERROR_CODE.invalidType,
|
|
59
22
|
path: this || [],
|
|
60
|
-
schema
|
|
61
|
-
subject
|
|
23
|
+
schema,
|
|
24
|
+
subject,
|
|
62
25
|
},
|
|
63
26
|
]);
|
|
64
27
|
}
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const key in schema.of) {
|
|
30
|
+
const narrowedSubj = subject;
|
|
31
|
+
const nestedSchema = schema.of[key];
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(narrowedSubj, key) === false) {
|
|
33
|
+
if (nestedSchema.optional !== true) {
|
|
34
|
+
return (0, fp_1.left)([
|
|
35
|
+
{
|
|
36
|
+
code: error_1.ERROR_CODE.invalidType,
|
|
37
|
+
path: [...(this || []), key],
|
|
38
|
+
schema,
|
|
39
|
+
subject,
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const nestedValue = narrowedSubj[key];
|
|
46
|
+
const parsed = parse.bind([...(this || []), key])(nestedSchema, nestedValue);
|
|
70
47
|
if (parsed.left) {
|
|
71
|
-
parsed.left.forEach(
|
|
48
|
+
parsed.left.forEach((err) => errors.push(err));
|
|
72
49
|
continue;
|
|
73
50
|
}
|
|
74
51
|
result[key] = parsed.right;
|
|
@@ -84,18 +61,18 @@ function parse(schema, subject) {
|
|
|
84
61
|
{
|
|
85
62
|
code: error_1.ERROR_CODE.invalidType,
|
|
86
63
|
path: this || [],
|
|
87
|
-
subject
|
|
88
|
-
schema
|
|
64
|
+
subject,
|
|
65
|
+
schema,
|
|
89
66
|
},
|
|
90
67
|
]);
|
|
91
68
|
}
|
|
92
|
-
|
|
93
|
-
for (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
69
|
+
const result = [];
|
|
70
|
+
for (let i = 0; i < subject.length; i++) {
|
|
71
|
+
const nestedSchema = schema.of;
|
|
72
|
+
const nestedValue = subject[i];
|
|
73
|
+
const parsed = parse.bind([...(this || []), i])(nestedSchema, nestedValue);
|
|
97
74
|
if (parsed.left) {
|
|
98
|
-
parsed.left.forEach(
|
|
75
|
+
parsed.left.forEach((err) => errors.push(err));
|
|
99
76
|
continue;
|
|
100
77
|
}
|
|
101
78
|
result.push(parsed.right);
|
|
@@ -109,8 +86,8 @@ function parse(schema, subject) {
|
|
|
109
86
|
{
|
|
110
87
|
code: error_1.ERROR_CODE.invalidRange,
|
|
111
88
|
path: this || [],
|
|
112
|
-
subject
|
|
113
|
-
schema
|
|
89
|
+
subject,
|
|
90
|
+
schema,
|
|
114
91
|
},
|
|
115
92
|
]);
|
|
116
93
|
}
|
|
@@ -120,40 +97,30 @@ function parse(schema, subject) {
|
|
|
120
97
|
{
|
|
121
98
|
code: error_1.ERROR_CODE.invalidRange,
|
|
122
99
|
path: this || [],
|
|
123
|
-
subject
|
|
124
|
-
schema
|
|
100
|
+
subject,
|
|
101
|
+
schema,
|
|
125
102
|
},
|
|
126
103
|
]);
|
|
127
104
|
}
|
|
128
105
|
return (0, fp_1.right)(result);
|
|
129
106
|
}
|
|
130
107
|
if (schema.type === 'union') {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (parsed.left === undefined) {
|
|
136
|
-
return (0, fp_1.right)(parsed.right);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
141
|
-
finally {
|
|
142
|
-
try {
|
|
143
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
108
|
+
for (const subSchema of schema.of) {
|
|
109
|
+
const parsed = parse(subSchema, subject);
|
|
110
|
+
if (parsed.left === undefined) {
|
|
111
|
+
return (0, fp_1.right)(parsed.right);
|
|
144
112
|
}
|
|
145
|
-
finally { if (e_1) throw e_1.error; }
|
|
146
113
|
}
|
|
147
114
|
return (0, fp_1.left)([
|
|
148
115
|
{
|
|
149
116
|
code: error_1.ERROR_CODE.invalidType,
|
|
150
117
|
path: this || [],
|
|
151
|
-
subject
|
|
152
|
-
schema
|
|
118
|
+
subject,
|
|
119
|
+
schema,
|
|
153
120
|
},
|
|
154
121
|
]);
|
|
155
122
|
}
|
|
156
|
-
|
|
123
|
+
const verified = (0, verify_primitive_1.verifyPrimitive)(schema, subject);
|
|
157
124
|
if (verified === true) {
|
|
158
125
|
return (0, fp_1.right)(subject);
|
|
159
126
|
}
|
|
@@ -161,8 +128,8 @@ function parse(schema, subject) {
|
|
|
161
128
|
{
|
|
162
129
|
code: verified,
|
|
163
130
|
path: this || [],
|
|
164
|
-
subject
|
|
165
|
-
schema
|
|
131
|
+
subject,
|
|
132
|
+
schema,
|
|
166
133
|
},
|
|
167
134
|
]);
|
|
168
135
|
}
|
package/dist/struct.js
CHANGED
|
@@ -1,72 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __values = (this && this.__values) || function(o) {
|
|
14
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
-
if (m) return m.call(o);
|
|
16
|
-
if (o && typeof o.length === "number") return {
|
|
17
|
-
next: function () {
|
|
18
|
-
if (o && i >= o.length) o = void 0;
|
|
19
|
-
return { value: o && o[i++], done: !o };
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
-
};
|
|
24
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
3
|
exports.union = exports.array = exports.object = exports.literal = exports.boolean = exports.number = exports.string = exports.makeStruct = void 0;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const validate_1 = require("./validate");
|
|
6
|
+
const parse_1 = require("./parse");
|
|
29
7
|
function makeStruct(schema) {
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
const params = constants_1.PARAMS_BY_SCHEMA_TYPE[schema.type];
|
|
9
|
+
const result = {
|
|
32
10
|
__schema: schema,
|
|
33
|
-
parse:
|
|
34
|
-
validate:
|
|
35
|
-
guard:
|
|
36
|
-
return (0, validate_1.validate)(schema, subj).left === undefined;
|
|
37
|
-
},
|
|
11
|
+
parse: (subj) => (0, parse_1.parse)(schema, subj),
|
|
12
|
+
validate: (subj) => (0, validate_1.validate)(schema, subj),
|
|
13
|
+
guard: (subj) => (0, validate_1.validate)(schema, subj).left === undefined,
|
|
38
14
|
};
|
|
39
15
|
if (params.has('optional')) {
|
|
40
|
-
result.optional =
|
|
16
|
+
result.optional = () => makeStruct(Object.assign(Object.assign({}, schema), { optional: true }));
|
|
41
17
|
}
|
|
42
18
|
if (params.has('nullable')) {
|
|
43
|
-
result.nullable =
|
|
19
|
+
result.nullable = () => makeStruct(Object.assign(Object.assign({}, schema), { nullable: true }));
|
|
44
20
|
}
|
|
45
21
|
if (params.has('description')) {
|
|
46
|
-
result.description =
|
|
47
|
-
return makeStruct(__assign(__assign({}, schema), { description: description }));
|
|
48
|
-
};
|
|
22
|
+
result.description = (description) => makeStruct(Object.assign(Object.assign({}, schema), { description }));
|
|
49
23
|
}
|
|
50
24
|
if (params.has('brand')) {
|
|
51
|
-
result.brand =
|
|
52
|
-
return makeStruct(__assign(__assign({}, schema), { brand: [key, value] }));
|
|
53
|
-
};
|
|
25
|
+
result.brand = (key, value) => makeStruct(Object.assign(Object.assign({}, schema), { brand: [key, value] }));
|
|
54
26
|
}
|
|
55
27
|
if (params.has('min')) {
|
|
56
|
-
result.min =
|
|
28
|
+
result.min = (min) => makeStruct(Object.assign(Object.assign({}, schema), { min }));
|
|
57
29
|
}
|
|
58
30
|
if (params.has('max')) {
|
|
59
|
-
result.max =
|
|
31
|
+
result.max = (max) => makeStruct(Object.assign(Object.assign({}, schema), { max }));
|
|
60
32
|
}
|
|
61
33
|
if (params.has('minLength')) {
|
|
62
|
-
result.minLength =
|
|
63
|
-
return makeStruct(__assign(__assign({}, schema), { minLength: minLength }));
|
|
64
|
-
};
|
|
34
|
+
result.minLength = (minLength) => makeStruct(Object.assign(Object.assign({}, schema), { minLength }));
|
|
65
35
|
}
|
|
66
36
|
if (params.has('maxLength')) {
|
|
67
|
-
result.maxLength =
|
|
68
|
-
return makeStruct(__assign(__assign({}, schema), { maxLength: maxLength }));
|
|
69
|
-
};
|
|
37
|
+
result.maxLength = (maxLength) => makeStruct(Object.assign(Object.assign({}, schema), { maxLength }));
|
|
70
38
|
}
|
|
71
39
|
return result;
|
|
72
40
|
}
|
|
@@ -84,37 +52,26 @@ function boolean() {
|
|
|
84
52
|
}
|
|
85
53
|
exports.boolean = boolean;
|
|
86
54
|
function literal(of) {
|
|
87
|
-
return makeStruct({ type: 'literal', of
|
|
55
|
+
return makeStruct({ type: 'literal', of });
|
|
88
56
|
}
|
|
89
57
|
exports.literal = literal;
|
|
90
58
|
function object(of) {
|
|
91
|
-
|
|
92
|
-
for (
|
|
59
|
+
const schema = { type: 'object', of: {} };
|
|
60
|
+
for (const key in of) {
|
|
93
61
|
schema.of[key] = of[key].__schema;
|
|
94
62
|
}
|
|
95
63
|
return makeStruct(schema);
|
|
96
64
|
}
|
|
97
65
|
exports.object = object;
|
|
98
66
|
function array(of) {
|
|
99
|
-
|
|
67
|
+
const schema = { type: 'array', of: of.__schema };
|
|
100
68
|
return makeStruct(schema);
|
|
101
69
|
}
|
|
102
70
|
exports.array = array;
|
|
103
71
|
function union(of) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for (var of_1 = __values(of), of_1_1 = of_1.next(); !of_1_1.done; of_1_1 = of_1.next()) {
|
|
108
|
-
var subSchema = of_1_1.value;
|
|
109
|
-
schema.of.push(subSchema.__schema);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
113
|
-
finally {
|
|
114
|
-
try {
|
|
115
|
-
if (of_1_1 && !of_1_1.done && (_a = of_1.return)) _a.call(of_1);
|
|
116
|
-
}
|
|
117
|
-
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
const schema = { type: 'union', of: [] };
|
|
73
|
+
for (const subSchema of of) {
|
|
74
|
+
schema.of.push(subSchema.__schema);
|
|
118
75
|
}
|
|
119
76
|
return makeStruct(schema);
|
|
120
77
|
}
|
package/dist/utils/fp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.right = exports.left = void 0;
|
|
4
|
-
|
|
4
|
+
const left = (value) => ({ left: value });
|
|
5
5
|
exports.left = left;
|
|
6
|
-
|
|
6
|
+
const right = (value) => ({ right: value });
|
|
7
7
|
exports.right = right;
|
package/dist/validate.js
CHANGED
|
@@ -1,48 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.guard = exports.validate = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
4
|
+
const fp_1 = require("./utils/fp");
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
const verify_primitive_1 = require("./verify-primitive");
|
|
43
7
|
function validate(schema, subject) {
|
|
44
|
-
|
|
45
|
-
var errors = [];
|
|
8
|
+
const errors = [];
|
|
46
9
|
if (schema.optional === true && subject === undefined) {
|
|
47
10
|
return (0, fp_1.right)(undefined);
|
|
48
11
|
}
|
|
@@ -57,19 +20,19 @@ function validate(schema, subject) {
|
|
|
57
20
|
{
|
|
58
21
|
code: error_1.ERROR_CODE.invalidType,
|
|
59
22
|
path: this || [],
|
|
60
|
-
schema
|
|
61
|
-
subject
|
|
23
|
+
schema,
|
|
24
|
+
subject,
|
|
62
25
|
},
|
|
63
26
|
]);
|
|
64
27
|
}
|
|
65
|
-
|
|
66
|
-
for (
|
|
28
|
+
const subjectKeySet = new Set(Object.keys(subject));
|
|
29
|
+
for (const key in schema.of) {
|
|
67
30
|
subjectKeySet.delete(key);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
31
|
+
const nestedValue = subject[key];
|
|
32
|
+
const nestedSchema = schema.of[key];
|
|
33
|
+
const validated = validate.bind([...(this || []), key])(nestedSchema, nestedValue);
|
|
71
34
|
if (validated.left) {
|
|
72
|
-
validated.left.forEach(
|
|
35
|
+
validated.left.forEach((err) => errors.push(err));
|
|
73
36
|
continue;
|
|
74
37
|
}
|
|
75
38
|
}
|
|
@@ -79,8 +42,8 @@ function validate(schema, subject) {
|
|
|
79
42
|
if (subjectKeySet.size !== 0) {
|
|
80
43
|
errors.push({
|
|
81
44
|
code: error_1.ERROR_CODE.invalidType,
|
|
82
|
-
subject
|
|
83
|
-
schema
|
|
45
|
+
subject,
|
|
46
|
+
schema,
|
|
84
47
|
path: this || [],
|
|
85
48
|
});
|
|
86
49
|
return (0, fp_1.left)(errors);
|
|
@@ -93,17 +56,17 @@ function validate(schema, subject) {
|
|
|
93
56
|
{
|
|
94
57
|
code: error_1.ERROR_CODE.invalidType,
|
|
95
58
|
path: this || [],
|
|
96
|
-
subject
|
|
97
|
-
schema
|
|
59
|
+
subject,
|
|
60
|
+
schema,
|
|
98
61
|
},
|
|
99
62
|
]);
|
|
100
63
|
}
|
|
101
|
-
for (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
for (let i = 0; i < subject.length; i++) {
|
|
65
|
+
const nestedSchema = schema.of;
|
|
66
|
+
const nestedValue = subject[i];
|
|
67
|
+
const validated = validate.bind([...(this || []), i])(nestedSchema, nestedValue);
|
|
105
68
|
if (validated.left) {
|
|
106
|
-
validated.left.forEach(
|
|
69
|
+
validated.left.forEach((err) => errors.push(err));
|
|
107
70
|
continue;
|
|
108
71
|
}
|
|
109
72
|
}
|
|
@@ -116,8 +79,8 @@ function validate(schema, subject) {
|
|
|
116
79
|
{
|
|
117
80
|
code: error_1.ERROR_CODE.invalidRange,
|
|
118
81
|
path: this || [],
|
|
119
|
-
subject
|
|
120
|
-
schema
|
|
82
|
+
subject,
|
|
83
|
+
schema,
|
|
121
84
|
},
|
|
122
85
|
]);
|
|
123
86
|
}
|
|
@@ -127,39 +90,29 @@ function validate(schema, subject) {
|
|
|
127
90
|
{
|
|
128
91
|
code: error_1.ERROR_CODE.invalidRange,
|
|
129
92
|
path: this || [],
|
|
130
|
-
subject
|
|
131
|
-
schema
|
|
93
|
+
subject,
|
|
94
|
+
schema,
|
|
132
95
|
},
|
|
133
96
|
]);
|
|
134
97
|
}
|
|
135
98
|
return (0, fp_1.right)(subject);
|
|
136
99
|
}
|
|
137
100
|
if (schema.type === 'union') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (validate(subSchema, subject).left === undefined) {
|
|
142
|
-
return (0, fp_1.right)(subject);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
147
|
-
finally {
|
|
148
|
-
try {
|
|
149
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
101
|
+
for (const subSchema of schema.of) {
|
|
102
|
+
if (validate(subSchema, subject).left === undefined) {
|
|
103
|
+
return (0, fp_1.right)(subject);
|
|
150
104
|
}
|
|
151
|
-
finally { if (e_1) throw e_1.error; }
|
|
152
105
|
}
|
|
153
106
|
return (0, fp_1.left)([
|
|
154
107
|
{
|
|
155
108
|
code: error_1.ERROR_CODE.invalidType,
|
|
156
109
|
path: this || [],
|
|
157
|
-
subject
|
|
158
|
-
schema
|
|
110
|
+
subject,
|
|
111
|
+
schema,
|
|
159
112
|
},
|
|
160
113
|
]);
|
|
161
114
|
}
|
|
162
|
-
|
|
115
|
+
const verified = (0, verify_primitive_1.verifyPrimitive)(schema, subject);
|
|
163
116
|
if (verified === true) {
|
|
164
117
|
return (0, fp_1.right)(subject);
|
|
165
118
|
}
|
|
@@ -167,8 +120,8 @@ function validate(schema, subject) {
|
|
|
167
120
|
{
|
|
168
121
|
code: verified,
|
|
169
122
|
path: this || [],
|
|
170
|
-
subject
|
|
171
|
-
schema
|
|
123
|
+
subject,
|
|
124
|
+
schema,
|
|
172
125
|
},
|
|
173
126
|
]);
|
|
174
127
|
}
|
package/dist/verify-primitive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.verifyPrimitive = void 0;
|
|
4
|
-
|
|
4
|
+
const error_1 = require("./error");
|
|
5
5
|
function verifyPrimitive(schema, subject) {
|
|
6
6
|
if (schema.optional === true && subject === undefined) {
|
|
7
7
|
return true;
|
package/package.json
CHANGED