@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19
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/build/import/compiler/compiler.mjs +14 -8
- package/build/import/errors/errors.mjs +15 -11
- package/build/import/type/awaited/awaited.mjs +4 -4
- package/build/import/type/deref/deref.mjs +12 -12
- package/build/import/type/exclude/exclude.mjs +8 -5
- package/build/import/type/extends/extends-check.mjs +167 -167
- package/build/import/type/extends/extends.mjs +3 -3
- package/build/import/type/extract/extract.mjs +5 -5
- package/build/import/type/guard/type.d.mts +50 -50
- package/build/import/type/guard/type.mjs +136 -136
- package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +9 -9
- package/build/import/type/intersect/intersect-create.mjs +4 -4
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
- package/build/import/type/intersect/intersect.mjs +2 -2
- package/build/import/type/intrinsic/intrinsic.mjs +5 -5
- package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +16 -16
- package/build/import/type/modifiers/modifiers.mjs +3 -3
- package/build/import/type/object/object.mjs +3 -3
- package/build/import/type/omit/omit.mjs +6 -6
- package/build/import/type/partial/partial.mjs +5 -5
- package/build/import/type/pick/pick.mjs +6 -6
- package/build/import/type/record/record.mjs +7 -7
- package/build/import/type/required/required.mjs +5 -5
- package/build/import/type/rest/rest.mjs +6 -2
- package/build/import/type/template-literal/pattern.mjs +9 -9
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +2 -2
- package/build/import/value/check/check.mjs +18 -11
- package/build/import/value/clean/clean.mjs +9 -7
- package/build/import/value/clone/clone.mjs +7 -4
- package/build/import/value/convert/convert.mjs +6 -2
- package/build/import/value/default/default.mjs +12 -4
- package/build/import/value/transform/decode.mjs +12 -6
- package/build/import/value/transform/encode.mjs +12 -6
- package/build/import/value/transform/has.mjs +24 -18
- package/build/require/compiler/compiler.js +77 -71
- package/build/require/errors/errors.js +58 -54
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/deref/deref.js +11 -11
- package/build/require/type/exclude/exclude.js +7 -4
- package/build/require/type/extends/extends-check.js +167 -167
- package/build/require/type/extends/extends.js +2 -2
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/type.d.ts +50 -50
- package/build/require/type/guard/type.js +184 -184
- package/build/require/type/indexed/indexed-property-keys.js +6 -6
- package/build/require/type/indexed/indexed.js +9 -9
- package/build/require/type/intersect/intersect-create.js +3 -3
- package/build/require/type/intersect/intersect-evaluated.js +2 -2
- package/build/require/type/intersect/intersect.js +1 -1
- package/build/require/type/intrinsic/intrinsic.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.js +6 -6
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +15 -15
- package/build/require/type/modifiers/modifiers.js +2 -2
- package/build/require/type/object/object.js +2 -2
- package/build/require/type/omit/omit.js +5 -5
- package/build/require/type/partial/partial.js +4 -4
- package/build/require/type/pick/pick.js +5 -5
- package/build/require/type/record/record.js +6 -6
- package/build/require/type/required/required.js +4 -4
- package/build/require/type/rest/rest.js +5 -1
- package/build/require/type/template-literal/pattern.js +8 -8
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/union/union-evaluated.js +1 -1
- package/build/require/value/check/check.js +63 -56
- package/build/require/value/clean/clean.js +31 -29
- package/build/require/value/clone/clone.js +7 -4
- package/build/require/value/convert/convert.js +42 -38
- package/build/require/value/default/default.js +24 -16
- package/build/require/value/transform/decode.js +27 -21
- package/build/require/value/transform/encode.js +28 -22
- package/build/require/value/transform/has.js +29 -23
- package/package.json +1 -1
- package/readme.md +5 -5
|
@@ -2,19 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Check = exports.ValueCheckUnknownTypeError = void 0;
|
|
5
|
-
const index_1 = require("
|
|
6
|
-
const index_2 = require("
|
|
7
|
-
const index_3 = require("../
|
|
8
|
-
const index_4 = require("
|
|
9
|
-
const index_5 = require("../../type/
|
|
10
|
-
const index_6 = require("../../type/
|
|
11
|
-
const index_7 = require("../../type/
|
|
5
|
+
const index_1 = require("../../system/index");
|
|
6
|
+
const index_2 = require("../deref/index");
|
|
7
|
+
const index_3 = require("../hash/index");
|
|
8
|
+
const index_4 = require("../../type/symbols/index");
|
|
9
|
+
const index_5 = require("../../type/keyof/index");
|
|
10
|
+
const index_6 = require("../../type/extends/index");
|
|
11
|
+
const index_7 = require("../../type/registry/index");
|
|
12
|
+
const index_8 = require("../../type/never/index");
|
|
13
|
+
// ------------------------------------------------------------------
|
|
14
|
+
// ValueGuard
|
|
15
|
+
// ------------------------------------------------------------------
|
|
16
|
+
// prettier-ignore
|
|
17
|
+
const index_9 = require("../guard/index");
|
|
18
|
+
// ------------------------------------------------------------------
|
|
19
|
+
// TypeGuard
|
|
20
|
+
// ------------------------------------------------------------------
|
|
12
21
|
const type_1 = require("../../type/guard/type");
|
|
13
|
-
|
|
14
|
-
const index_9 = require("../../type/never/index");
|
|
15
|
-
// --------------------------------------------------------------------------
|
|
22
|
+
// ------------------------------------------------------------------
|
|
16
23
|
// Errors
|
|
17
|
-
//
|
|
24
|
+
// ------------------------------------------------------------------
|
|
18
25
|
class ValueCheckUnknownTypeError extends Error {
|
|
19
26
|
constructor(schema) {
|
|
20
27
|
super(`Unknown type`);
|
|
@@ -22,26 +29,26 @@ class ValueCheckUnknownTypeError extends Error {
|
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
|
|
25
|
-
//
|
|
32
|
+
// ------------------------------------------------------------------
|
|
26
33
|
// TypeGuards
|
|
27
|
-
//
|
|
34
|
+
// ------------------------------------------------------------------
|
|
28
35
|
function IsAnyOrUnknown(schema) {
|
|
29
|
-
return schema[
|
|
36
|
+
return schema[index_4.Kind] === 'Any' || schema[index_4.Kind] === 'Unknown';
|
|
30
37
|
}
|
|
31
|
-
//
|
|
38
|
+
// ------------------------------------------------------------------
|
|
32
39
|
// Guards
|
|
33
|
-
//
|
|
40
|
+
// ------------------------------------------------------------------
|
|
34
41
|
function IsDefined(value) {
|
|
35
42
|
return value !== undefined;
|
|
36
43
|
}
|
|
37
|
-
//
|
|
44
|
+
// ------------------------------------------------------------------
|
|
38
45
|
// Types
|
|
39
|
-
//
|
|
46
|
+
// ------------------------------------------------------------------
|
|
40
47
|
function TAny(schema, references, value) {
|
|
41
48
|
return true;
|
|
42
49
|
}
|
|
43
50
|
function TArray(schema, references, value) {
|
|
44
|
-
if (!(0,
|
|
51
|
+
if (!(0, index_9.IsArray)(value))
|
|
45
52
|
return false;
|
|
46
53
|
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
47
54
|
return false;
|
|
@@ -54,7 +61,7 @@ function TArray(schema, references, value) {
|
|
|
54
61
|
}
|
|
55
62
|
// prettier-ignore
|
|
56
63
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
57
|
-
const hashed = (0,
|
|
64
|
+
const hashed = (0, index_3.Hash)(element);
|
|
58
65
|
if (set.has(hashed)) {
|
|
59
66
|
return false;
|
|
60
67
|
}
|
|
@@ -65,27 +72,27 @@ function TArray(schema, references, value) {
|
|
|
65
72
|
return false;
|
|
66
73
|
}
|
|
67
74
|
// contains
|
|
68
|
-
if (!(IsDefined(schema.contains) || (0,
|
|
75
|
+
if (!(IsDefined(schema.contains) || (0, index_9.IsNumber)(schema.minContains) || (0, index_9.IsNumber)(schema.maxContains))) {
|
|
69
76
|
return true; // exit
|
|
70
77
|
}
|
|
71
|
-
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0,
|
|
78
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0, index_8.Never)();
|
|
72
79
|
const containsCount = value.reduce((acc, value) => (Visit(containsSchema, references, value) ? acc + 1 : acc), 0);
|
|
73
80
|
if (containsCount === 0) {
|
|
74
81
|
return false;
|
|
75
82
|
}
|
|
76
|
-
if ((0,
|
|
83
|
+
if ((0, index_9.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
77
84
|
return false;
|
|
78
85
|
}
|
|
79
|
-
if ((0,
|
|
86
|
+
if ((0, index_9.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
80
87
|
return false;
|
|
81
88
|
}
|
|
82
89
|
return true;
|
|
83
90
|
}
|
|
84
91
|
function TAsyncIterator(schema, references, value) {
|
|
85
|
-
return (0,
|
|
92
|
+
return (0, index_9.IsAsyncIterator)(value);
|
|
86
93
|
}
|
|
87
94
|
function TBigInt(schema, references, value) {
|
|
88
|
-
if (!(0,
|
|
95
|
+
if (!(0, index_9.IsBigInt)(value))
|
|
89
96
|
return false;
|
|
90
97
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
91
98
|
return false;
|
|
@@ -105,13 +112,13 @@ function TBigInt(schema, references, value) {
|
|
|
105
112
|
return true;
|
|
106
113
|
}
|
|
107
114
|
function TBoolean(schema, references, value) {
|
|
108
|
-
return (0,
|
|
115
|
+
return (0, index_9.IsBoolean)(value);
|
|
109
116
|
}
|
|
110
117
|
function TConstructor(schema, references, value) {
|
|
111
118
|
return Visit(schema.returns, references, value.prototype);
|
|
112
119
|
}
|
|
113
120
|
function TDate(schema, references, value) {
|
|
114
|
-
if (!(0,
|
|
121
|
+
if (!(0, index_9.IsDate)(value))
|
|
115
122
|
return false;
|
|
116
123
|
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
117
124
|
return false;
|
|
@@ -131,10 +138,10 @@ function TDate(schema, references, value) {
|
|
|
131
138
|
return true;
|
|
132
139
|
}
|
|
133
140
|
function TFunction(schema, references, value) {
|
|
134
|
-
return (0,
|
|
141
|
+
return (0, index_9.IsFunction)(value);
|
|
135
142
|
}
|
|
136
143
|
function TInteger(schema, references, value) {
|
|
137
|
-
if (!(0,
|
|
144
|
+
if (!(0, index_9.IsInteger)(value)) {
|
|
138
145
|
return false;
|
|
139
146
|
}
|
|
140
147
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
@@ -157,12 +164,12 @@ function TInteger(schema, references, value) {
|
|
|
157
164
|
function TIntersect(schema, references, value) {
|
|
158
165
|
const check1 = schema.allOf.every((schema) => Visit(schema, references, value));
|
|
159
166
|
if (schema.unevaluatedProperties === false) {
|
|
160
|
-
const keyPattern = new RegExp((0,
|
|
167
|
+
const keyPattern = new RegExp((0, index_5.KeyOfPattern)(schema));
|
|
161
168
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
|
|
162
169
|
return check1 && check2;
|
|
163
170
|
}
|
|
164
|
-
else if ((0, type_1.
|
|
165
|
-
const keyCheck = new RegExp((0,
|
|
171
|
+
else if ((0, type_1.IsSchema)(schema.unevaluatedProperties)) {
|
|
172
|
+
const keyCheck = new RegExp((0, index_5.KeyOfPattern)(schema));
|
|
166
173
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
|
|
167
174
|
return check1 && check2;
|
|
168
175
|
}
|
|
@@ -171,7 +178,7 @@ function TIntersect(schema, references, value) {
|
|
|
171
178
|
}
|
|
172
179
|
}
|
|
173
180
|
function TIterator(schema, references, value) {
|
|
174
|
-
return (0,
|
|
181
|
+
return (0, index_9.IsIterator)(value);
|
|
175
182
|
}
|
|
176
183
|
function TLiteral(schema, references, value) {
|
|
177
184
|
return value === schema.const;
|
|
@@ -183,10 +190,10 @@ function TNot(schema, references, value) {
|
|
|
183
190
|
return !Visit(schema.not, references, value);
|
|
184
191
|
}
|
|
185
192
|
function TNull(schema, references, value) {
|
|
186
|
-
return (0,
|
|
193
|
+
return (0, index_9.IsNull)(value);
|
|
187
194
|
}
|
|
188
195
|
function TNumber(schema, references, value) {
|
|
189
|
-
if (!
|
|
196
|
+
if (!index_1.TypeSystemPolicy.IsNumberLike(value))
|
|
190
197
|
return false;
|
|
191
198
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
192
199
|
return false;
|
|
@@ -206,7 +213,7 @@ function TNumber(schema, references, value) {
|
|
|
206
213
|
return true;
|
|
207
214
|
}
|
|
208
215
|
function TObject(schema, references, value) {
|
|
209
|
-
if (!
|
|
216
|
+
if (!index_1.TypeSystemPolicy.IsObjectLike(value))
|
|
210
217
|
return false;
|
|
211
218
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
212
219
|
return false;
|
|
@@ -221,12 +228,12 @@ function TObject(schema, references, value) {
|
|
|
221
228
|
if (!Visit(property, references, value[knownKey])) {
|
|
222
229
|
return false;
|
|
223
230
|
}
|
|
224
|
-
if (((0,
|
|
231
|
+
if (((0, index_6.ExtendsUndefinedCheck)(property) || IsAnyOrUnknown(property)) && !(knownKey in value)) {
|
|
225
232
|
return false;
|
|
226
233
|
}
|
|
227
234
|
}
|
|
228
235
|
else {
|
|
229
|
-
if (
|
|
236
|
+
if (index_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey) && !Visit(property, references, value[knownKey])) {
|
|
230
237
|
return false;
|
|
231
238
|
}
|
|
232
239
|
}
|
|
@@ -250,10 +257,10 @@ function TObject(schema, references, value) {
|
|
|
250
257
|
}
|
|
251
258
|
}
|
|
252
259
|
function TPromise(schema, references, value) {
|
|
253
|
-
return (0,
|
|
260
|
+
return (0, index_9.IsPromise)(value);
|
|
254
261
|
}
|
|
255
262
|
function TRecord(schema, references, value) {
|
|
256
|
-
if (!
|
|
263
|
+
if (!index_1.TypeSystemPolicy.IsRecordLike(value)) {
|
|
257
264
|
return false;
|
|
258
265
|
}
|
|
259
266
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
@@ -280,10 +287,10 @@ function TRecord(schema, references, value) {
|
|
|
280
287
|
return check1 && check2 && check3;
|
|
281
288
|
}
|
|
282
289
|
function TRef(schema, references, value) {
|
|
283
|
-
return Visit((0,
|
|
290
|
+
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
284
291
|
}
|
|
285
292
|
function TString(schema, references, value) {
|
|
286
|
-
if (!(0,
|
|
293
|
+
if (!(0, index_9.IsString)(value)) {
|
|
287
294
|
return false;
|
|
288
295
|
}
|
|
289
296
|
if (IsDefined(schema.minLength)) {
|
|
@@ -300,24 +307,24 @@ function TString(schema, references, value) {
|
|
|
300
307
|
return false;
|
|
301
308
|
}
|
|
302
309
|
if (IsDefined(schema.format)) {
|
|
303
|
-
if (!
|
|
310
|
+
if (!index_7.FormatRegistry.Has(schema.format))
|
|
304
311
|
return false;
|
|
305
|
-
const func =
|
|
312
|
+
const func = index_7.FormatRegistry.Get(schema.format);
|
|
306
313
|
return func(value);
|
|
307
314
|
}
|
|
308
315
|
return true;
|
|
309
316
|
}
|
|
310
317
|
function TSymbol(schema, references, value) {
|
|
311
|
-
return (0,
|
|
318
|
+
return (0, index_9.IsSymbol)(value);
|
|
312
319
|
}
|
|
313
320
|
function TTemplateLiteral(schema, references, value) {
|
|
314
|
-
return (0,
|
|
321
|
+
return (0, index_9.IsString)(value) && new RegExp(schema.pattern).test(value);
|
|
315
322
|
}
|
|
316
323
|
function TThis(schema, references, value) {
|
|
317
|
-
return Visit((0,
|
|
324
|
+
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
318
325
|
}
|
|
319
326
|
function TTuple(schema, references, value) {
|
|
320
|
-
if (!(0,
|
|
327
|
+
if (!(0, index_9.IsArray)(value)) {
|
|
321
328
|
return false;
|
|
322
329
|
}
|
|
323
330
|
if (schema.items === undefined && !(value.length === 0)) {
|
|
@@ -336,13 +343,13 @@ function TTuple(schema, references, value) {
|
|
|
336
343
|
return true;
|
|
337
344
|
}
|
|
338
345
|
function TUndefined(schema, references, value) {
|
|
339
|
-
return (0,
|
|
346
|
+
return (0, index_9.IsUndefined)(value);
|
|
340
347
|
}
|
|
341
348
|
function TUnion(schema, references, value) {
|
|
342
349
|
return schema.anyOf.some((inner) => Visit(inner, references, value));
|
|
343
350
|
}
|
|
344
351
|
function TUint8Array(schema, references, value) {
|
|
345
|
-
if (!(0,
|
|
352
|
+
if (!(0, index_9.IsUint8Array)(value)) {
|
|
346
353
|
return false;
|
|
347
354
|
}
|
|
348
355
|
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
@@ -357,18 +364,18 @@ function TUnknown(schema, references, value) {
|
|
|
357
364
|
return true;
|
|
358
365
|
}
|
|
359
366
|
function TVoid(schema, references, value) {
|
|
360
|
-
return
|
|
367
|
+
return index_1.TypeSystemPolicy.IsVoidLike(value);
|
|
361
368
|
}
|
|
362
369
|
function TKind(schema, references, value) {
|
|
363
|
-
if (!
|
|
370
|
+
if (!index_7.TypeRegistry.Has(schema[index_4.Kind]))
|
|
364
371
|
return false;
|
|
365
|
-
const func =
|
|
372
|
+
const func = index_7.TypeRegistry.Get(schema[index_4.Kind]);
|
|
366
373
|
return func(schema, value);
|
|
367
374
|
}
|
|
368
375
|
function Visit(schema, references, value) {
|
|
369
376
|
const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
|
|
370
377
|
const schema_ = schema;
|
|
371
|
-
switch (schema_[
|
|
378
|
+
switch (schema_[index_4.Kind]) {
|
|
372
379
|
case 'Any':
|
|
373
380
|
return TAny(schema_, references_, value);
|
|
374
381
|
case 'Array':
|
|
@@ -430,7 +437,7 @@ function Visit(schema, references, value) {
|
|
|
430
437
|
case 'Void':
|
|
431
438
|
return TVoid(schema_, references_, value);
|
|
432
439
|
default:
|
|
433
|
-
if (!
|
|
440
|
+
if (!index_7.TypeRegistry.Has(schema_[index_4.Kind]))
|
|
434
441
|
throw new ValueCheckUnknownTypeError(schema_);
|
|
435
442
|
return TKind(schema_, references_, value);
|
|
436
443
|
}
|
|
@@ -2,51 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Clean = void 0;
|
|
5
|
-
const index_1 = require("
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const index_5 = require("../deref/index");
|
|
11
|
-
const index_6 = require("../../type/symbols/index");
|
|
5
|
+
const index_1 = require("../../type/keyof/index");
|
|
6
|
+
const index_2 = require("../check/index");
|
|
7
|
+
const index_3 = require("../clone/index");
|
|
8
|
+
const index_4 = require("../deref/index");
|
|
9
|
+
const index_5 = require("../../type/symbols/index");
|
|
12
10
|
// ------------------------------------------------------------------
|
|
13
|
-
//
|
|
11
|
+
// ValueGuard
|
|
14
12
|
// ------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
// prettier-ignore
|
|
14
|
+
const index_6 = require("../guard/index");
|
|
15
|
+
// ------------------------------------------------------------------
|
|
16
|
+
// TypeGuard
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
const type_1 = require("../../type/guard/type");
|
|
18
20
|
// ------------------------------------------------------------------
|
|
19
21
|
// IsCheckable
|
|
20
22
|
// ------------------------------------------------------------------
|
|
21
23
|
function IsCheckable(schema) {
|
|
22
|
-
return (0, type_1.
|
|
24
|
+
return (0, type_1.IsSchema)(schema) && schema[index_5.Kind] !== 'Unsafe';
|
|
23
25
|
}
|
|
24
26
|
// ------------------------------------------------------------------
|
|
25
27
|
// Types
|
|
26
28
|
// ------------------------------------------------------------------
|
|
27
29
|
function TArray(schema, references, value) {
|
|
28
|
-
if (!(0,
|
|
30
|
+
if (!(0, index_6.IsArray)(value))
|
|
29
31
|
return value;
|
|
30
32
|
return value.map((value) => Visit(schema.items, references, value));
|
|
31
33
|
}
|
|
32
34
|
function TIntersect(schema, references, value) {
|
|
33
35
|
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
34
|
-
const intersections = schema.allOf.map((schema) => Visit(schema, references, (0,
|
|
35
|
-
const composite = intersections.reduce((acc, value) => ((0,
|
|
36
|
-
if (!(0,
|
|
36
|
+
const intersections = schema.allOf.map((schema) => Visit(schema, references, (0, index_3.Clone)(value)));
|
|
37
|
+
const composite = intersections.reduce((acc, value) => ((0, index_6.IsObject)(value) ? { ...acc, ...value } : value), {});
|
|
38
|
+
if (!(0, index_6.IsObject)(value) || !(0, index_6.IsObject)(composite) || !(0, type_1.IsSchema)(unevaluatedProperties))
|
|
37
39
|
return composite;
|
|
38
|
-
const knownkeys = (0,
|
|
40
|
+
const knownkeys = (0, index_1.KeyOfPropertyKeys)(schema);
|
|
39
41
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
40
42
|
if (knownkeys.includes(key))
|
|
41
43
|
continue;
|
|
42
|
-
if ((0,
|
|
44
|
+
if ((0, index_2.Check)(unevaluatedProperties, references, value[key])) {
|
|
43
45
|
composite[key] = Visit(unevaluatedProperties, references, value[key]);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
return composite;
|
|
47
49
|
}
|
|
48
50
|
function TObject(schema, references, value) {
|
|
49
|
-
if (!(0,
|
|
51
|
+
if (!(0, index_6.IsObject)(value) || (0, index_6.IsArray)(value))
|
|
50
52
|
return value; // Check IsArray for AllowArrayObject configuration
|
|
51
53
|
const additionalProperties = schema.additionalProperties;
|
|
52
54
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
@@ -54,7 +56,7 @@ function TObject(schema, references, value) {
|
|
|
54
56
|
value[key] = Visit(schema.properties[key], references, value[key]);
|
|
55
57
|
continue;
|
|
56
58
|
}
|
|
57
|
-
if (IsSchema(additionalProperties) && (0,
|
|
59
|
+
if ((0, type_1.IsSchema)(additionalProperties) && (0, index_2.Check)(additionalProperties, references, value[key])) {
|
|
58
60
|
value[key] = Visit(additionalProperties, references, value[key]);
|
|
59
61
|
continue;
|
|
60
62
|
}
|
|
@@ -63,7 +65,7 @@ function TObject(schema, references, value) {
|
|
|
63
65
|
return value;
|
|
64
66
|
}
|
|
65
67
|
function TRecord(schema, references, value) {
|
|
66
|
-
if (!(0,
|
|
68
|
+
if (!(0, index_6.IsObject)(value))
|
|
67
69
|
return value;
|
|
68
70
|
const additionalProperties = schema.additionalProperties;
|
|
69
71
|
const propertyKeys = Object.keys(value);
|
|
@@ -74,7 +76,7 @@ function TRecord(schema, references, value) {
|
|
|
74
76
|
value[key] = Visit(propertySchema, references, value[key]);
|
|
75
77
|
continue;
|
|
76
78
|
}
|
|
77
|
-
if (IsSchema(additionalProperties) && (0,
|
|
79
|
+
if ((0, type_1.IsSchema)(additionalProperties) && (0, index_2.Check)(additionalProperties, references, value[key])) {
|
|
78
80
|
value[key] = Visit(additionalProperties, references, value[key]);
|
|
79
81
|
continue;
|
|
80
82
|
}
|
|
@@ -83,15 +85,15 @@ function TRecord(schema, references, value) {
|
|
|
83
85
|
return value;
|
|
84
86
|
}
|
|
85
87
|
function TRef(schema, references, value) {
|
|
86
|
-
return Visit((0,
|
|
88
|
+
return Visit((0, index_4.Deref)(schema, references), references, value);
|
|
87
89
|
}
|
|
88
90
|
function TThis(schema, references, value) {
|
|
89
|
-
return Visit((0,
|
|
91
|
+
return Visit((0, index_4.Deref)(schema, references), references, value);
|
|
90
92
|
}
|
|
91
93
|
function TTuple(schema, references, value) {
|
|
92
|
-
if (!(0,
|
|
94
|
+
if (!(0, index_6.IsArray)(value))
|
|
93
95
|
return value;
|
|
94
|
-
if ((0,
|
|
96
|
+
if ((0, index_6.IsUndefined)(schema.items))
|
|
95
97
|
return [];
|
|
96
98
|
const length = Math.min(value.length, schema.items.length);
|
|
97
99
|
for (let i = 0; i < length; i++) {
|
|
@@ -104,16 +106,16 @@ function TTuple(schema, references, value) {
|
|
|
104
106
|
}
|
|
105
107
|
function TUnion(schema, references, value) {
|
|
106
108
|
for (const inner of schema.anyOf) {
|
|
107
|
-
if (IsCheckable(inner) && (0,
|
|
109
|
+
if (IsCheckable(inner) && (0, index_2.Check)(inner, value)) {
|
|
108
110
|
return Visit(inner, references, value);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
return value;
|
|
112
114
|
}
|
|
113
115
|
function Visit(schema, references, value) {
|
|
114
|
-
const references_ = (0,
|
|
116
|
+
const references_ = (0, index_6.IsString)(schema.$id) ? [...references, schema] : references;
|
|
115
117
|
const schema_ = schema;
|
|
116
|
-
switch (schema_[
|
|
118
|
+
switch (schema_[index_5.Kind]) {
|
|
117
119
|
case 'Array':
|
|
118
120
|
return TArray(schema_, references_, value);
|
|
119
121
|
case 'Intersect':
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Clone = void 0;
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
// ValueGuard
|
|
7
|
+
// ------------------------------------------------------------------
|
|
5
8
|
const index_1 = require("../guard/index");
|
|
6
|
-
//
|
|
9
|
+
// ------------------------------------------------------------------
|
|
7
10
|
// Clonable
|
|
8
|
-
//
|
|
11
|
+
// ------------------------------------------------------------------
|
|
9
12
|
function ObjectType(value) {
|
|
10
13
|
const keys = [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertySymbols(value)];
|
|
11
14
|
return keys.reduce((acc, key) => ({ ...acc, [key]: Clone(value[key]) }), {});
|
|
@@ -22,9 +25,9 @@ function DateType(value) {
|
|
|
22
25
|
function ValueType(value) {
|
|
23
26
|
return value;
|
|
24
27
|
}
|
|
25
|
-
//
|
|
28
|
+
// ------------------------------------------------------------------
|
|
26
29
|
// Clone
|
|
27
|
-
//
|
|
30
|
+
// ------------------------------------------------------------------
|
|
28
31
|
/** Returns a clone of the given value */
|
|
29
32
|
function Clone(value) {
|
|
30
33
|
if ((0, index_1.IsArray)(value))
|