schematox 0.3.0-beta.0 → 0.3.1-beta.0
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 +7 -0
- package/dist/parse.js +33 -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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.3.0](https://github.com/incerta/schematox/compare/v0.2.0...v0.3.0) (2024-05-04)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [`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)
|
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,18 @@ 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 nestedSchema = schema.of[key];
|
|
31
|
+
const nestedValue = subject[key];
|
|
32
|
+
const parsed = parse.bind([...(this || []), key])(nestedSchema, nestedValue);
|
|
70
33
|
if (parsed.left) {
|
|
71
|
-
parsed.left.forEach(
|
|
34
|
+
parsed.left.forEach((err) => errors.push(err));
|
|
72
35
|
continue;
|
|
73
36
|
}
|
|
74
37
|
result[key] = parsed.right;
|
|
@@ -84,18 +47,18 @@ function parse(schema, subject) {
|
|
|
84
47
|
{
|
|
85
48
|
code: error_1.ERROR_CODE.invalidType,
|
|
86
49
|
path: this || [],
|
|
87
|
-
subject
|
|
88
|
-
schema
|
|
50
|
+
subject,
|
|
51
|
+
schema,
|
|
89
52
|
},
|
|
90
53
|
]);
|
|
91
54
|
}
|
|
92
|
-
|
|
93
|
-
for (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
55
|
+
const result = [];
|
|
56
|
+
for (let i = 0; i < subject.length; i++) {
|
|
57
|
+
const nestedSchema = schema.of;
|
|
58
|
+
const nestedValue = subject[i];
|
|
59
|
+
const parsed = parse.bind([...(this || []), i])(nestedSchema, nestedValue);
|
|
97
60
|
if (parsed.left) {
|
|
98
|
-
parsed.left.forEach(
|
|
61
|
+
parsed.left.forEach((err) => errors.push(err));
|
|
99
62
|
continue;
|
|
100
63
|
}
|
|
101
64
|
result.push(parsed.right);
|
|
@@ -109,8 +72,8 @@ function parse(schema, subject) {
|
|
|
109
72
|
{
|
|
110
73
|
code: error_1.ERROR_CODE.invalidRange,
|
|
111
74
|
path: this || [],
|
|
112
|
-
subject
|
|
113
|
-
schema
|
|
75
|
+
subject,
|
|
76
|
+
schema,
|
|
114
77
|
},
|
|
115
78
|
]);
|
|
116
79
|
}
|
|
@@ -120,40 +83,30 @@ function parse(schema, subject) {
|
|
|
120
83
|
{
|
|
121
84
|
code: error_1.ERROR_CODE.invalidRange,
|
|
122
85
|
path: this || [],
|
|
123
|
-
subject
|
|
124
|
-
schema
|
|
86
|
+
subject,
|
|
87
|
+
schema,
|
|
125
88
|
},
|
|
126
89
|
]);
|
|
127
90
|
}
|
|
128
91
|
return (0, fp_1.right)(result);
|
|
129
92
|
}
|
|
130
93
|
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);
|
|
94
|
+
for (const subSchema of schema.of) {
|
|
95
|
+
const parsed = parse(subSchema, subject);
|
|
96
|
+
if (parsed.left === undefined) {
|
|
97
|
+
return (0, fp_1.right)(parsed.right);
|
|
144
98
|
}
|
|
145
|
-
finally { if (e_1) throw e_1.error; }
|
|
146
99
|
}
|
|
147
100
|
return (0, fp_1.left)([
|
|
148
101
|
{
|
|
149
102
|
code: error_1.ERROR_CODE.invalidType,
|
|
150
103
|
path: this || [],
|
|
151
|
-
subject
|
|
152
|
-
schema
|
|
104
|
+
subject,
|
|
105
|
+
schema,
|
|
153
106
|
},
|
|
154
107
|
]);
|
|
155
108
|
}
|
|
156
|
-
|
|
109
|
+
const verified = (0, verify_primitive_1.verifyPrimitive)(schema, subject);
|
|
157
110
|
if (verified === true) {
|
|
158
111
|
return (0, fp_1.right)(subject);
|
|
159
112
|
}
|
|
@@ -161,8 +114,8 @@ function parse(schema, subject) {
|
|
|
161
114
|
{
|
|
162
115
|
code: verified,
|
|
163
116
|
path: this || [],
|
|
164
|
-
subject
|
|
165
|
-
schema
|
|
117
|
+
subject,
|
|
118
|
+
schema,
|
|
166
119
|
},
|
|
167
120
|
]);
|
|
168
121
|
}
|
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