@sinclair/typebox 0.26.0-dev.1 → 0.26.0-dev.3
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/compiler/compiler.d.ts +33 -33
- package/compiler/compiler.js +536 -536
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/errors/errors.d.ts +84 -77
- package/errors/errors.js +570 -553
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/package.json +2 -2
- package/readme.md +4 -10
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +20 -20
- package/system/system.js +69 -69
- package/typebox.d.ts +648 -648
- package/typebox.js +1881 -1875
- package/value/cast.d.ts +26 -26
- package/value/cast.js +348 -348
- package/value/check.d.ts +8 -8
- package/value/check.js +450 -450
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/convert.d.ts +13 -13
- package/value/convert.js +345 -345
- package/value/create.d.ts +18 -18
- package/value/create.js +430 -430
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/hash.d.ts +8 -8
- package/value/hash.js +208 -208
- package/value/index.d.ts +5 -5
- package/value/index.js +56 -55
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +26 -26
- package/value/value.js +93 -93
package/typebox.js
CHANGED
|
@@ -1,1875 +1,1881 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.StandardTypeBuilder = exports.TypeBuilder = exports.KeyResolver = exports.ObjectMap = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.ReferenceRegistry = exports.TypeRegistry = exports.
|
|
31
|
-
//
|
|
32
|
-
// Symbols
|
|
33
|
-
//
|
|
34
|
-
exports.
|
|
35
|
-
exports.
|
|
36
|
-
exports.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
schema.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
IsOptionalNumber(schema.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
schema.
|
|
226
|
-
schema.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
IsOptionalBigInt(schema.
|
|
230
|
-
IsOptionalBigInt(schema.
|
|
231
|
-
IsOptionalBigInt(schema.
|
|
232
|
-
IsOptionalBigInt(schema.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
schema.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
schema.
|
|
250
|
-
schema.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
schema.
|
|
268
|
-
schema.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
IsOptionalNumber(schema.
|
|
272
|
-
IsOptionalNumber(schema.
|
|
273
|
-
IsOptionalNumber(schema.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
schema.
|
|
282
|
-
schema.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
schema.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
IsOptionalNumber(schema.
|
|
303
|
-
IsOptionalNumber(schema.
|
|
304
|
-
IsOptionalNumber(schema.
|
|
305
|
-
IsOptionalNumber(schema.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
schema.allOf
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
TSchema(schema.allOf[
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
schema.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
schema.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
IsOptionalNumber(schema.
|
|
391
|
-
IsOptionalNumber(schema.
|
|
392
|
-
IsOptionalNumber(schema.
|
|
393
|
-
IsOptionalNumber(schema.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
schema.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
(
|
|
404
|
-
|
|
405
|
-
IsOptionalNumber(schema.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
schema.
|
|
423
|
-
schema.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
schema.
|
|
434
|
-
|
|
435
|
-
schema
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
schema.
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
IsOptionalNumber(schema.
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
schema.
|
|
488
|
-
schema.
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
schema.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
IsNumber(schema.
|
|
501
|
-
schema.
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
schema.
|
|
523
|
-
schema.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
schema.
|
|
567
|
-
schema.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
//
|
|
622
|
-
//
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
//
|
|
639
|
-
//
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
TypeExtendsResult[TypeExtendsResult["
|
|
644
|
-
TypeExtendsResult[TypeExtendsResult["
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
//
|
|
650
|
-
//
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
//
|
|
656
|
-
//
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
//
|
|
675
|
-
//
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
//
|
|
702
|
-
//
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
//
|
|
722
|
-
//
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
//
|
|
747
|
-
//
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
//
|
|
770
|
-
//
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
//
|
|
788
|
-
//
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
//
|
|
811
|
-
//
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
//
|
|
836
|
-
//
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
//
|
|
845
|
-
//
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
//
|
|
882
|
-
//
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
//
|
|
891
|
-
//
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
//
|
|
911
|
-
//
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
//
|
|
936
|
-
//
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
TypeGuard.TUndefined(schema.properties.description.anyOf[
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
//
|
|
981
|
-
//
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
//
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
//
|
|
1058
|
-
//
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
//
|
|
1076
|
-
//
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
//
|
|
1130
|
-
//
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
//
|
|
1155
|
-
//
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
//
|
|
1175
|
-
//
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
//
|
|
1211
|
-
//
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
//
|
|
1229
|
-
//
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
//
|
|
1251
|
-
//
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
//
|
|
1260
|
-
//
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
//
|
|
1289
|
-
//
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
//
|
|
1368
|
-
//
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
return
|
|
1384
|
-
}
|
|
1385
|
-
function
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
function
|
|
1411
|
-
return
|
|
1412
|
-
}
|
|
1413
|
-
function
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
function
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
//
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
ReferenceRegistry.Set(
|
|
1476
|
-
return
|
|
1477
|
-
}
|
|
1478
|
-
/** `[Standard]` Omits compositing symbols from this schema */
|
|
1479
|
-
Strict(schema) {
|
|
1480
|
-
return JSON.parse(JSON.stringify(schema));
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
exports.TypeBuilder = TypeBuilder;
|
|
1484
|
-
//
|
|
1485
|
-
// StandardTypeBuilder
|
|
1486
|
-
//
|
|
1487
|
-
class StandardTypeBuilder extends TypeBuilder {
|
|
1488
|
-
//
|
|
1489
|
-
// Modifiers
|
|
1490
|
-
//
|
|
1491
|
-
/** `[Modifier]` Creates a Optional property */
|
|
1492
|
-
Optional(schema) {
|
|
1493
|
-
return { [exports.Modifier]: 'Optional', ...
|
|
1494
|
-
}
|
|
1495
|
-
/** `[Modifier]` Creates a ReadonlyOptional property */
|
|
1496
|
-
ReadonlyOptional(schema) {
|
|
1497
|
-
return { [exports.Modifier]: 'ReadonlyOptional', ...
|
|
1498
|
-
}
|
|
1499
|
-
/** `[Modifier]` Creates a Readonly object or property */
|
|
1500
|
-
Readonly(schema) {
|
|
1501
|
-
return { [exports.Modifier]: 'Readonly', ...schema };
|
|
1502
|
-
}
|
|
1503
|
-
//
|
|
1504
|
-
// Types
|
|
1505
|
-
//
|
|
1506
|
-
/** `[Standard]` Creates an Any type */
|
|
1507
|
-
Any(options = {}) {
|
|
1508
|
-
return this.Create({ ...options, [exports.Kind]: 'Any' });
|
|
1509
|
-
}
|
|
1510
|
-
/** `[Standard]` Creates an Array type */
|
|
1511
|
-
Array(items, options = {}) {
|
|
1512
|
-
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items });
|
|
1513
|
-
}
|
|
1514
|
-
/** `[Standard]` Creates a Boolean type */
|
|
1515
|
-
Boolean(options = {}) {
|
|
1516
|
-
return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
|
|
1517
|
-
}
|
|
1518
|
-
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
1519
|
-
Composite(schemas, options = {}) {
|
|
1520
|
-
const optional = new Set();
|
|
1521
|
-
for (const schema of schemas) {
|
|
1522
|
-
for (const [key, property] of globalThis.Object.entries(schema.properties)) {
|
|
1523
|
-
if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property))
|
|
1524
|
-
optional.add(key);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
const properties = {};
|
|
1528
|
-
for (const object of schemas) {
|
|
1529
|
-
for (const [key, property] of globalThis.Object.entries(object.properties)) {
|
|
1530
|
-
const mapped = key in properties ? this.Union([properties[key], property]) : property;
|
|
1531
|
-
properties[key] = optional.has(key) ? this.Optional(mapped) : mapped;
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
return this.Object(properties, options);
|
|
1535
|
-
}
|
|
1536
|
-
/** `[Standard]` Dereferences the given TRef to its target type */
|
|
1537
|
-
Deref(schema) {
|
|
1538
|
-
return ReferenceRegistry.Deref(schema);
|
|
1539
|
-
}
|
|
1540
|
-
/** `[Standard]` Creates a Enum type */
|
|
1541
|
-
Enum(item, options = {}) {
|
|
1542
|
-
// prettier-ignore
|
|
1543
|
-
const values = globalThis.Object.keys(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1544
|
-
const anyOf = values.map((value) => (typeof value === 'string' ? { [exports.Kind]: 'Literal', type: 'string', const: value } : { [exports.Kind]: 'Literal', type: 'number', const: value }));
|
|
1545
|
-
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf });
|
|
1546
|
-
}
|
|
1547
|
-
/** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
|
|
1548
|
-
Extends(left, right, trueType, falseType, options = {}) {
|
|
1549
|
-
switch (TypeExtends.Extends(ReferenceRegistry.Deref(left), ReferenceRegistry.Deref(right))) {
|
|
1550
|
-
case TypeExtendsResult.Union:
|
|
1551
|
-
return this.Union([
|
|
1552
|
-
case TypeExtendsResult.True:
|
|
1553
|
-
return
|
|
1554
|
-
case TypeExtendsResult.False:
|
|
1555
|
-
return
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
/** `[Standard]` Excludes from the left type any type that is not assignable to the right */
|
|
1559
|
-
Exclude(left, right, options = {}) {
|
|
1560
|
-
if (TypeGuard.TUnion(left)) {
|
|
1561
|
-
const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) === TypeExtendsResult.False);
|
|
1562
|
-
return (narrowed.length === 1 ?
|
|
1563
|
-
}
|
|
1564
|
-
else {
|
|
1565
|
-
return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? this.Never(options) :
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
/** `[Standard]` Extracts from left left any type that is assignable to the right */
|
|
1569
|
-
Extract(left, right, options = {}) {
|
|
1570
|
-
if (TypeGuard.TUnion(left)) {
|
|
1571
|
-
const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) !== TypeExtendsResult.False);
|
|
1572
|
-
return (narrowed.length === 1 ?
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1575
|
-
return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ?
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
/** `[Standard]` Creates an Integer type */
|
|
1579
|
-
Integer(options = {}) {
|
|
1580
|
-
return this.Create({ ...options, [exports.Kind]: 'Integer', type: 'integer' });
|
|
1581
|
-
}
|
|
1582
|
-
Intersect(allOf, options = {}) {
|
|
1583
|
-
if (allOf.length === 0)
|
|
1584
|
-
return exports.Type.Never();
|
|
1585
|
-
if (allOf.length === 1)
|
|
1586
|
-
return
|
|
1587
|
-
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
1588
|
-
const cloned = allOf.map((schema) =>
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
Never
|
|
1609
|
-
|
|
1610
|
-
return this.Create({ ...options, [exports.Kind]: 'Never',
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
const
|
|
1630
|
-
const
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
const
|
|
1728
|
-
reassign
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
Ref
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
globalThis.Object.keys(schema.properties)
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
String
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
const
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
if (anyOf.length ===
|
|
1780
|
-
return this.
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
//
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'object', instanceOf: 'Constructor', parameters, returns });
|
|
1813
|
-
}
|
|
1814
|
-
else {
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
/**
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.StandardTypeBuilder = exports.TypeBuilder = exports.KeyResolver = exports.ObjectMap = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.ReferenceRegistry = exports.TypeRegistry = exports.Kind = exports.Hint = exports.Modifier = exports.Recursive = void 0;
|
|
31
|
+
// --------------------------------------------------------------------------
|
|
32
|
+
// Compositing Symbols
|
|
33
|
+
// --------------------------------------------------------------------------
|
|
34
|
+
exports.Recursive = Symbol.for('TypeBox.Recursive');
|
|
35
|
+
exports.Modifier = Symbol.for('TypeBox.Modifier');
|
|
36
|
+
exports.Hint = Symbol.for('TypeBox.Hint');
|
|
37
|
+
exports.Kind = Symbol.for('TypeBox.Kind');
|
|
38
|
+
var TypeRegistry;
|
|
39
|
+
(function (TypeRegistry) {
|
|
40
|
+
const types = new Map();
|
|
41
|
+
/** Clears all user defined types */
|
|
42
|
+
function Clear() {
|
|
43
|
+
return types.clear();
|
|
44
|
+
}
|
|
45
|
+
TypeRegistry.Clear = Clear;
|
|
46
|
+
/** Returns true if this registry contains this kind */
|
|
47
|
+
function Has(kind) {
|
|
48
|
+
return types.has(kind);
|
|
49
|
+
}
|
|
50
|
+
TypeRegistry.Has = Has;
|
|
51
|
+
/** Sets a validation function for a user defined type */
|
|
52
|
+
function Set(kind, func) {
|
|
53
|
+
types.set(kind, func);
|
|
54
|
+
}
|
|
55
|
+
TypeRegistry.Set = Set;
|
|
56
|
+
/** Gets a custom validation function for a user defined type */
|
|
57
|
+
function Get(kind) {
|
|
58
|
+
return types.get(kind);
|
|
59
|
+
}
|
|
60
|
+
TypeRegistry.Get = Get;
|
|
61
|
+
})(TypeRegistry = exports.TypeRegistry || (exports.TypeRegistry = {}));
|
|
62
|
+
// --------------------------------------------------------------------------
|
|
63
|
+
// ReferenceRegistry
|
|
64
|
+
// --------------------------------------------------------------------------
|
|
65
|
+
var ReferenceRegistry;
|
|
66
|
+
(function (ReferenceRegistry) {
|
|
67
|
+
const references = new Map();
|
|
68
|
+
/** Clears the reference registry */
|
|
69
|
+
function Clear() {
|
|
70
|
+
return references.clear();
|
|
71
|
+
}
|
|
72
|
+
ReferenceRegistry.Clear = Clear;
|
|
73
|
+
/** Returns true if this registry contains this schema */
|
|
74
|
+
function Has(schema) {
|
|
75
|
+
return references.has(schema.$id);
|
|
76
|
+
}
|
|
77
|
+
ReferenceRegistry.Has = Has;
|
|
78
|
+
/** Sets this schema on this registry if a $id exists */
|
|
79
|
+
function Set(schema) {
|
|
80
|
+
const $id = typeof schema === 'object' && schema !== null && typeof schema['$id'] === 'string' ? schema['$id'] : undefined;
|
|
81
|
+
if ($id !== undefined)
|
|
82
|
+
references.set($id, schema);
|
|
83
|
+
}
|
|
84
|
+
ReferenceRegistry.Set = Set;
|
|
85
|
+
/** Dereferences the schema one level deep */
|
|
86
|
+
function DerefOne(schema) {
|
|
87
|
+
if (TypeGuard.TRef(schema) || TypeGuard.TSelf(schema)) {
|
|
88
|
+
if (!references.has(schema.$ref))
|
|
89
|
+
throw Error(`ReferenceRegistry: Cannot deref schema with $id '${schema.$ref}'`);
|
|
90
|
+
return references.get(schema.$ref);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return schema;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
ReferenceRegistry.DerefOne = DerefOne;
|
|
97
|
+
/** Dereferences the schema recursively */
|
|
98
|
+
function Deref(schema) {
|
|
99
|
+
if (TypeGuard.TRef(schema)) {
|
|
100
|
+
return Deref(DerefOne(schema));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
ReferenceRegistry.Deref = Deref;
|
|
107
|
+
})(ReferenceRegistry = exports.ReferenceRegistry || (exports.ReferenceRegistry = {}));
|
|
108
|
+
/** Provides functions to create user defined string formats */
|
|
109
|
+
var FormatRegistry;
|
|
110
|
+
(function (FormatRegistry) {
|
|
111
|
+
const formats = new Map();
|
|
112
|
+
/** Clears all user defined string formats */
|
|
113
|
+
function Clear() {
|
|
114
|
+
return formats.clear();
|
|
115
|
+
}
|
|
116
|
+
FormatRegistry.Clear = Clear;
|
|
117
|
+
/** Returns true if the user defined string format exists */
|
|
118
|
+
function Has(format) {
|
|
119
|
+
return formats.has(format);
|
|
120
|
+
}
|
|
121
|
+
FormatRegistry.Has = Has;
|
|
122
|
+
/** Sets a validation function for a user defined string format */
|
|
123
|
+
function Set(format, func) {
|
|
124
|
+
formats.set(format, func);
|
|
125
|
+
}
|
|
126
|
+
FormatRegistry.Set = Set;
|
|
127
|
+
/** Gets a validation function for a user defined string format */
|
|
128
|
+
function Get(format) {
|
|
129
|
+
return formats.get(format);
|
|
130
|
+
}
|
|
131
|
+
FormatRegistry.Get = Get;
|
|
132
|
+
})(FormatRegistry = exports.FormatRegistry || (exports.FormatRegistry = {}));
|
|
133
|
+
// --------------------------------------------------------------------------
|
|
134
|
+
// TypeGuard
|
|
135
|
+
// --------------------------------------------------------------------------
|
|
136
|
+
class TypeGuardUnknownTypeError extends Error {
|
|
137
|
+
constructor(schema) {
|
|
138
|
+
super('TypeGuard: Unknown type');
|
|
139
|
+
this.schema = schema;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
143
|
+
var TypeGuard;
|
|
144
|
+
(function (TypeGuard) {
|
|
145
|
+
function IsObject(value) {
|
|
146
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
147
|
+
}
|
|
148
|
+
function IsArray(value) {
|
|
149
|
+
return typeof value === 'object' && value !== null && Array.isArray(value);
|
|
150
|
+
}
|
|
151
|
+
function IsPattern(value) {
|
|
152
|
+
try {
|
|
153
|
+
new RegExp(value);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function IsControlCharacterFree(value) {
|
|
161
|
+
if (typeof value !== 'string')
|
|
162
|
+
return false;
|
|
163
|
+
for (let i = 0; i < value.length; i++) {
|
|
164
|
+
const code = value.charCodeAt(i);
|
|
165
|
+
if ((code >= 7 && code <= 13) || code === 27 || code === 127) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
function IsBigInt(value) {
|
|
172
|
+
return typeof value === 'bigint';
|
|
173
|
+
}
|
|
174
|
+
function IsString(value) {
|
|
175
|
+
return typeof value === 'string';
|
|
176
|
+
}
|
|
177
|
+
function IsNumber(value) {
|
|
178
|
+
return typeof value === 'number' && globalThis.Number.isFinite(value);
|
|
179
|
+
}
|
|
180
|
+
function IsBoolean(value) {
|
|
181
|
+
return typeof value === 'boolean';
|
|
182
|
+
}
|
|
183
|
+
function IsOptionalBigInt(value) {
|
|
184
|
+
return value === undefined || (value !== undefined && IsBigInt(value));
|
|
185
|
+
}
|
|
186
|
+
function IsOptionalNumber(value) {
|
|
187
|
+
return value === undefined || (value !== undefined && IsNumber(value));
|
|
188
|
+
}
|
|
189
|
+
function IsOptionalBoolean(value) {
|
|
190
|
+
return value === undefined || (value !== undefined && IsBoolean(value));
|
|
191
|
+
}
|
|
192
|
+
function IsOptionalString(value) {
|
|
193
|
+
return value === undefined || (value !== undefined && IsString(value));
|
|
194
|
+
}
|
|
195
|
+
function IsOptionalPattern(value) {
|
|
196
|
+
return value === undefined || (value !== undefined && IsString(value) && IsControlCharacterFree(value) && IsPattern(value));
|
|
197
|
+
}
|
|
198
|
+
function IsOptionalFormat(value) {
|
|
199
|
+
return value === undefined || (value !== undefined && IsString(value) && IsControlCharacterFree(value));
|
|
200
|
+
}
|
|
201
|
+
function IsOptionalSchema(value) {
|
|
202
|
+
return value === undefined || TSchema(value);
|
|
203
|
+
}
|
|
204
|
+
/** Returns true if the given schema is TAny */
|
|
205
|
+
function TAny(schema) {
|
|
206
|
+
return TKind(schema) && schema[exports.Kind] === 'Any' && IsOptionalString(schema.$id);
|
|
207
|
+
}
|
|
208
|
+
TypeGuard.TAny = TAny;
|
|
209
|
+
/** Returns true if the given schema is TArray */
|
|
210
|
+
function TArray(schema) {
|
|
211
|
+
return (TKind(schema) &&
|
|
212
|
+
schema[exports.Kind] === 'Array' &&
|
|
213
|
+
schema.type === 'array' &&
|
|
214
|
+
IsOptionalString(schema.$id) &&
|
|
215
|
+
TSchema(schema.items) &&
|
|
216
|
+
IsOptionalNumber(schema.minItems) &&
|
|
217
|
+
IsOptionalNumber(schema.maxItems) &&
|
|
218
|
+
IsOptionalBoolean(schema.uniqueItems));
|
|
219
|
+
}
|
|
220
|
+
TypeGuard.TArray = TArray;
|
|
221
|
+
/** Returns true if the given schema is TSymbol */
|
|
222
|
+
function TBigInt(schema) {
|
|
223
|
+
// prettier-ignore
|
|
224
|
+
return (TKind(schema) &&
|
|
225
|
+
schema[exports.Kind] === 'BigInt' &&
|
|
226
|
+
schema.type === 'null' &&
|
|
227
|
+
schema.typeOf === 'BigInt' &&
|
|
228
|
+
IsOptionalString(schema.$id) &&
|
|
229
|
+
IsOptionalBigInt(schema.multipleOf) &&
|
|
230
|
+
IsOptionalBigInt(schema.minimum) &&
|
|
231
|
+
IsOptionalBigInt(schema.maximum) &&
|
|
232
|
+
IsOptionalBigInt(schema.exclusiveMinimum) &&
|
|
233
|
+
IsOptionalBigInt(schema.exclusiveMaximum));
|
|
234
|
+
}
|
|
235
|
+
TypeGuard.TBigInt = TBigInt;
|
|
236
|
+
/** Returns true if the given schema is TBoolean */
|
|
237
|
+
function TBoolean(schema) {
|
|
238
|
+
// prettier-ignore
|
|
239
|
+
return (TKind(schema) &&
|
|
240
|
+
schema[exports.Kind] === 'Boolean' &&
|
|
241
|
+
schema.type === 'boolean' &&
|
|
242
|
+
IsOptionalString(schema.$id));
|
|
243
|
+
}
|
|
244
|
+
TypeGuard.TBoolean = TBoolean;
|
|
245
|
+
/** Returns true if the given schema is TConstructor */
|
|
246
|
+
function TConstructor(schema) {
|
|
247
|
+
// prettier-ignore
|
|
248
|
+
if (!(TKind(schema) &&
|
|
249
|
+
schema[exports.Kind] === 'Constructor' &&
|
|
250
|
+
schema.type === 'object' &&
|
|
251
|
+
schema.instanceOf === 'Constructor' &&
|
|
252
|
+
IsOptionalString(schema.$id) &&
|
|
253
|
+
IsArray(schema.parameters) &&
|
|
254
|
+
TSchema(schema.returns))) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
for (const parameter of schema.parameters) {
|
|
258
|
+
if (!TSchema(parameter))
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
TypeGuard.TConstructor = TConstructor;
|
|
264
|
+
/** Returns true if the given schema is TDate */
|
|
265
|
+
function TDate(schema) {
|
|
266
|
+
return (TKind(schema) &&
|
|
267
|
+
schema[exports.Kind] === 'Date' &&
|
|
268
|
+
schema.type === 'object' &&
|
|
269
|
+
schema.instanceOf === 'Date' &&
|
|
270
|
+
IsOptionalString(schema.$id) &&
|
|
271
|
+
IsOptionalNumber(schema.minimumTimestamp) &&
|
|
272
|
+
IsOptionalNumber(schema.maximumTimestamp) &&
|
|
273
|
+
IsOptionalNumber(schema.exclusiveMinimumTimestamp) &&
|
|
274
|
+
IsOptionalNumber(schema.exclusiveMaximumTimestamp));
|
|
275
|
+
}
|
|
276
|
+
TypeGuard.TDate = TDate;
|
|
277
|
+
/** Returns true if the given schema is TFunction */
|
|
278
|
+
function TFunction(schema) {
|
|
279
|
+
// prettier-ignore
|
|
280
|
+
if (!(TKind(schema) &&
|
|
281
|
+
schema[exports.Kind] === 'Function' &&
|
|
282
|
+
schema.type === 'object' &&
|
|
283
|
+
schema.instanceOf === 'Function' &&
|
|
284
|
+
IsOptionalString(schema.$id) &&
|
|
285
|
+
IsArray(schema.parameters) &&
|
|
286
|
+
TSchema(schema.returns))) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
for (const parameter of schema.parameters) {
|
|
290
|
+
if (!TSchema(parameter))
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
TypeGuard.TFunction = TFunction;
|
|
296
|
+
/** Returns true if the given schema is TInteger */
|
|
297
|
+
function TInteger(schema) {
|
|
298
|
+
return (TKind(schema) &&
|
|
299
|
+
schema[exports.Kind] === 'Integer' &&
|
|
300
|
+
schema.type === 'integer' &&
|
|
301
|
+
IsOptionalString(schema.$id) &&
|
|
302
|
+
IsOptionalNumber(schema.multipleOf) &&
|
|
303
|
+
IsOptionalNumber(schema.minimum) &&
|
|
304
|
+
IsOptionalNumber(schema.maximum) &&
|
|
305
|
+
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
306
|
+
IsOptionalNumber(schema.exclusiveMaximum));
|
|
307
|
+
}
|
|
308
|
+
TypeGuard.TInteger = TInteger;
|
|
309
|
+
/** Returns true if the given schema is TIntersect */
|
|
310
|
+
function TIntersect(schema) {
|
|
311
|
+
// prettier-ignore
|
|
312
|
+
if (!(TKind(schema) &&
|
|
313
|
+
schema[exports.Kind] === 'Intersect' &&
|
|
314
|
+
IsArray(schema.allOf) &&
|
|
315
|
+
IsOptionalString(schema.type) &&
|
|
316
|
+
(IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) &&
|
|
317
|
+
IsOptionalString(schema.$id))) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
if ('type' in schema && schema.type !== 'object') {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
for (const inner of schema.allOf) {
|
|
324
|
+
if (!TSchema(inner))
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
TypeGuard.TIntersect = TIntersect;
|
|
330
|
+
/** Returns true if the given schema is TKind */
|
|
331
|
+
function TKind(schema) {
|
|
332
|
+
return IsObject(schema) && exports.Kind in schema && typeof schema[exports.Kind] === 'string'; // TS 4.1.5: any required for symbol indexer
|
|
333
|
+
}
|
|
334
|
+
TypeGuard.TKind = TKind;
|
|
335
|
+
/** Returns true if the given schema is TLiteral */
|
|
336
|
+
function TLiteral(schema) {
|
|
337
|
+
// prettier-ignore
|
|
338
|
+
return (TKind(schema) &&
|
|
339
|
+
schema[exports.Kind] === 'Literal' &&
|
|
340
|
+
IsOptionalString(schema.$id) &&
|
|
341
|
+
(IsString(schema.const) ||
|
|
342
|
+
IsNumber(schema.const) ||
|
|
343
|
+
IsBoolean(schema.const) ||
|
|
344
|
+
IsBigInt(schema.const)));
|
|
345
|
+
}
|
|
346
|
+
TypeGuard.TLiteral = TLiteral;
|
|
347
|
+
/** Returns true if the given schema is TNever */
|
|
348
|
+
function TNever(schema) {
|
|
349
|
+
return (TKind(schema) && schema[exports.Kind] === 'Never' && IsObject(schema.not) && globalThis.Object.getOwnPropertyNames(schema.not).length === 0
|
|
350
|
+
// IsArray(schema.allOf) &&
|
|
351
|
+
// schema.allOf.length === 2 &&
|
|
352
|
+
// IsObject(schema.allOf[0]) &&
|
|
353
|
+
// IsString(schema.allOf[0].type) &&
|
|
354
|
+
// schema.allOf[0].type === 'boolean' &&
|
|
355
|
+
// schema.allOf[0].const === false &&
|
|
356
|
+
// IsObject(schema.allOf[1]) &&
|
|
357
|
+
// IsString(schema.allOf[1].type) &&
|
|
358
|
+
// schema.allOf[1].type === 'boolean' &&
|
|
359
|
+
// schema.allOf[1].const === true
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
TypeGuard.TNever = TNever;
|
|
363
|
+
/** Returns true if the given schema is TNot */
|
|
364
|
+
function TNot(schema) {
|
|
365
|
+
// prettier-ignore
|
|
366
|
+
return (TKind(schema) &&
|
|
367
|
+
schema[exports.Kind] === 'Not' &&
|
|
368
|
+
IsArray(schema.allOf) &&
|
|
369
|
+
schema.allOf.length === 2 &&
|
|
370
|
+
IsObject(schema.allOf[0]) &&
|
|
371
|
+
TSchema(schema.allOf[0].not) &&
|
|
372
|
+
TSchema(schema.allOf[1]));
|
|
373
|
+
}
|
|
374
|
+
TypeGuard.TNot = TNot;
|
|
375
|
+
/** Returns true if the given schema is TNull */
|
|
376
|
+
function TNull(schema) {
|
|
377
|
+
// prettier-ignore
|
|
378
|
+
return (TKind(schema) &&
|
|
379
|
+
schema[exports.Kind] === 'Null' &&
|
|
380
|
+
schema.type === 'null' &&
|
|
381
|
+
IsOptionalString(schema.$id));
|
|
382
|
+
}
|
|
383
|
+
TypeGuard.TNull = TNull;
|
|
384
|
+
/** Returns true if the given schema is TNumber */
|
|
385
|
+
function TNumber(schema) {
|
|
386
|
+
return (TKind(schema) &&
|
|
387
|
+
schema[exports.Kind] === 'Number' &&
|
|
388
|
+
schema.type === 'number' &&
|
|
389
|
+
IsOptionalString(schema.$id) &&
|
|
390
|
+
IsOptionalNumber(schema.multipleOf) &&
|
|
391
|
+
IsOptionalNumber(schema.minimum) &&
|
|
392
|
+
IsOptionalNumber(schema.maximum) &&
|
|
393
|
+
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
394
|
+
IsOptionalNumber(schema.exclusiveMaximum));
|
|
395
|
+
}
|
|
396
|
+
TypeGuard.TNumber = TNumber;
|
|
397
|
+
/** Returns true if the given schema is TObject */
|
|
398
|
+
function TObject(schema) {
|
|
399
|
+
if (!(TKind(schema) &&
|
|
400
|
+
schema[exports.Kind] === 'Object' &&
|
|
401
|
+
schema.type === 'object' &&
|
|
402
|
+
IsOptionalString(schema.$id) &&
|
|
403
|
+
IsObject(schema.properties) &&
|
|
404
|
+
(IsOptionalBoolean(schema.additionalProperties) || IsOptionalSchema(schema.additionalProperties)) &&
|
|
405
|
+
IsOptionalNumber(schema.minProperties) &&
|
|
406
|
+
IsOptionalNumber(schema.maxProperties))) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
410
|
+
if (!IsControlCharacterFree(key))
|
|
411
|
+
return false;
|
|
412
|
+
if (!TSchema(value))
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
TypeGuard.TObject = TObject;
|
|
418
|
+
/** Returns true if the given schema is TPromise */
|
|
419
|
+
function TPromise(schema) {
|
|
420
|
+
// prettier-ignore
|
|
421
|
+
return (TKind(schema) &&
|
|
422
|
+
schema[exports.Kind] === 'Promise' &&
|
|
423
|
+
schema.type === 'object' &&
|
|
424
|
+
schema.instanceOf === 'Promise' &&
|
|
425
|
+
IsOptionalString(schema.$id) &&
|
|
426
|
+
TSchema(schema.item));
|
|
427
|
+
}
|
|
428
|
+
TypeGuard.TPromise = TPromise;
|
|
429
|
+
/** Returns true if the given schema is TRecord */
|
|
430
|
+
function TRecord(schema) {
|
|
431
|
+
// prettier-ignore
|
|
432
|
+
if (!(TKind(schema) &&
|
|
433
|
+
schema[exports.Kind] === 'Record' &&
|
|
434
|
+
schema.type === 'object' &&
|
|
435
|
+
IsOptionalString(schema.$id) &&
|
|
436
|
+
schema.additionalProperties === false &&
|
|
437
|
+
IsObject(schema.patternProperties))) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
const keys = Object.keys(schema.patternProperties);
|
|
441
|
+
if (keys.length !== 1) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
if (!IsPattern(keys[0])) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
if (!TSchema(schema.patternProperties[keys[0]])) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
TypeGuard.TRecord = TRecord;
|
|
453
|
+
/** Returns true if the given schema is TSelf */
|
|
454
|
+
function TSelf(schema) {
|
|
455
|
+
// prettier-ignore
|
|
456
|
+
return (TKind(schema) &&
|
|
457
|
+
schema[exports.Kind] === 'Self' &&
|
|
458
|
+
IsOptionalString(schema.$id) &&
|
|
459
|
+
IsString(schema.$ref));
|
|
460
|
+
}
|
|
461
|
+
TypeGuard.TSelf = TSelf;
|
|
462
|
+
/** Returns true if the given schema is TRef */
|
|
463
|
+
function TRef(schema) {
|
|
464
|
+
// prettier-ignore
|
|
465
|
+
return (TKind(schema) &&
|
|
466
|
+
schema[exports.Kind] === 'Ref' &&
|
|
467
|
+
IsOptionalString(schema.$id) &&
|
|
468
|
+
IsString(schema.$ref));
|
|
469
|
+
}
|
|
470
|
+
TypeGuard.TRef = TRef;
|
|
471
|
+
/** Returns true if the given schema is TString */
|
|
472
|
+
function TString(schema) {
|
|
473
|
+
return (TKind(schema) &&
|
|
474
|
+
schema[exports.Kind] === 'String' &&
|
|
475
|
+
schema.type === 'string' &&
|
|
476
|
+
IsOptionalString(schema.$id) &&
|
|
477
|
+
IsOptionalNumber(schema.minLength) &&
|
|
478
|
+
IsOptionalNumber(schema.maxLength) &&
|
|
479
|
+
IsOptionalPattern(schema.pattern) &&
|
|
480
|
+
IsOptionalFormat(schema.format));
|
|
481
|
+
}
|
|
482
|
+
TypeGuard.TString = TString;
|
|
483
|
+
/** Returns true if the given schema is TSymbol */
|
|
484
|
+
function TSymbol(schema) {
|
|
485
|
+
// prettier-ignore
|
|
486
|
+
return (TKind(schema) &&
|
|
487
|
+
schema[exports.Kind] === 'Symbol' &&
|
|
488
|
+
schema.type === 'null' &&
|
|
489
|
+
schema.typeOf === 'Symbol' &&
|
|
490
|
+
IsOptionalString(schema.$id));
|
|
491
|
+
}
|
|
492
|
+
TypeGuard.TSymbol = TSymbol;
|
|
493
|
+
/** Returns true if the given schema is TTuple */
|
|
494
|
+
function TTuple(schema) {
|
|
495
|
+
// prettier-ignore
|
|
496
|
+
if (!(TKind(schema) &&
|
|
497
|
+
schema[exports.Kind] === 'Tuple' &&
|
|
498
|
+
schema.type === 'array' &&
|
|
499
|
+
IsOptionalString(schema.$id) &&
|
|
500
|
+
IsNumber(schema.minItems) &&
|
|
501
|
+
IsNumber(schema.maxItems) &&
|
|
502
|
+
schema.minItems === schema.maxItems)) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
if (schema.items === undefined && schema.additionalItems === undefined && schema.minItems === 0) {
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
if (!IsArray(schema.items)) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
for (const inner of schema.items) {
|
|
512
|
+
if (!TSchema(inner))
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
TypeGuard.TTuple = TTuple;
|
|
518
|
+
/** Returns true if the given schema is TUndefined */
|
|
519
|
+
function TUndefined(schema) {
|
|
520
|
+
// prettier-ignore
|
|
521
|
+
return (TKind(schema) &&
|
|
522
|
+
schema[exports.Kind] === 'Undefined' &&
|
|
523
|
+
schema.type === 'null' &&
|
|
524
|
+
schema.typeOf === 'Undefined' &&
|
|
525
|
+
IsOptionalString(schema.$id));
|
|
526
|
+
}
|
|
527
|
+
TypeGuard.TUndefined = TUndefined;
|
|
528
|
+
/** Returns true if the given schema is TUnion */
|
|
529
|
+
function TUnion(schema) {
|
|
530
|
+
// prettier-ignore
|
|
531
|
+
if (!(TKind(schema) &&
|
|
532
|
+
schema[exports.Kind] === 'Union' &&
|
|
533
|
+
IsArray(schema.anyOf) &&
|
|
534
|
+
IsOptionalString(schema.$id))) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
for (const inner of schema.anyOf) {
|
|
538
|
+
if (!TSchema(inner))
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
TypeGuard.TUnion = TUnion;
|
|
544
|
+
/** Returns true if the given schema is TUnion<Literal<string>[]> */
|
|
545
|
+
function TUnionLiteral(schema) {
|
|
546
|
+
return TUnion(schema) && schema.anyOf.every((schema) => TLiteral(schema) && typeof schema.const === 'string');
|
|
547
|
+
}
|
|
548
|
+
TypeGuard.TUnionLiteral = TUnionLiteral;
|
|
549
|
+
/** Returns true if the given schema is TUint8Array */
|
|
550
|
+
function TUint8Array(schema) {
|
|
551
|
+
return TKind(schema) && schema[exports.Kind] === 'Uint8Array' && schema.type === 'object' && IsOptionalString(schema.$id) && schema.instanceOf === 'Uint8Array' && IsOptionalNumber(schema.minByteLength) && IsOptionalNumber(schema.maxByteLength);
|
|
552
|
+
}
|
|
553
|
+
TypeGuard.TUint8Array = TUint8Array;
|
|
554
|
+
/** Returns true if the given schema is TUnknown */
|
|
555
|
+
function TUnknown(schema) {
|
|
556
|
+
// prettier-ignore
|
|
557
|
+
return (TKind(schema) &&
|
|
558
|
+
schema[exports.Kind] === 'Unknown' &&
|
|
559
|
+
IsOptionalString(schema.$id));
|
|
560
|
+
}
|
|
561
|
+
TypeGuard.TUnknown = TUnknown;
|
|
562
|
+
/** Returns true if the given schema is TVoid */
|
|
563
|
+
function TVoid(schema) {
|
|
564
|
+
// prettier-ignore
|
|
565
|
+
return (TKind(schema) &&
|
|
566
|
+
schema[exports.Kind] === 'Void' &&
|
|
567
|
+
schema.type === 'null' &&
|
|
568
|
+
schema.typeOf === 'Void' &&
|
|
569
|
+
IsOptionalString(schema.$id));
|
|
570
|
+
}
|
|
571
|
+
TypeGuard.TVoid = TVoid;
|
|
572
|
+
/** Returns true if this schema has the ReadonlyOptional modifier */
|
|
573
|
+
function TReadonlyOptional(schema) {
|
|
574
|
+
return IsObject(schema) && schema[exports.Modifier] === 'ReadonlyOptional';
|
|
575
|
+
}
|
|
576
|
+
TypeGuard.TReadonlyOptional = TReadonlyOptional;
|
|
577
|
+
/** Returns true if this schema has the Readonly modifier */
|
|
578
|
+
function TReadonly(schema) {
|
|
579
|
+
return IsObject(schema) && schema[exports.Modifier] === 'Readonly';
|
|
580
|
+
}
|
|
581
|
+
TypeGuard.TReadonly = TReadonly;
|
|
582
|
+
/** Returns true if this schema has the Optional modifier */
|
|
583
|
+
function TOptional(schema) {
|
|
584
|
+
return IsObject(schema) && schema[exports.Modifier] === 'Optional';
|
|
585
|
+
}
|
|
586
|
+
TypeGuard.TOptional = TOptional;
|
|
587
|
+
/** Returns true if the given schema is TSchema */
|
|
588
|
+
function TSchema(schema) {
|
|
589
|
+
return (typeof schema === 'object' &&
|
|
590
|
+
(TAny(schema) ||
|
|
591
|
+
TArray(schema) ||
|
|
592
|
+
TBoolean(schema) ||
|
|
593
|
+
TBigInt(schema) ||
|
|
594
|
+
TConstructor(schema) ||
|
|
595
|
+
TDate(schema) ||
|
|
596
|
+
TFunction(schema) ||
|
|
597
|
+
TInteger(schema) ||
|
|
598
|
+
TIntersect(schema) ||
|
|
599
|
+
TLiteral(schema) ||
|
|
600
|
+
TNever(schema) ||
|
|
601
|
+
TNot(schema) ||
|
|
602
|
+
TNull(schema) ||
|
|
603
|
+
TNumber(schema) ||
|
|
604
|
+
TObject(schema) ||
|
|
605
|
+
TPromise(schema) ||
|
|
606
|
+
TRecord(schema) ||
|
|
607
|
+
TSelf(schema) ||
|
|
608
|
+
TRef(schema) ||
|
|
609
|
+
TString(schema) ||
|
|
610
|
+
TSymbol(schema) ||
|
|
611
|
+
TTuple(schema) ||
|
|
612
|
+
TUndefined(schema) ||
|
|
613
|
+
TUnion(schema) ||
|
|
614
|
+
TUint8Array(schema) ||
|
|
615
|
+
TUnknown(schema) ||
|
|
616
|
+
TVoid(schema) ||
|
|
617
|
+
(TKind(schema) && TypeRegistry.Has(schema[exports.Kind]))));
|
|
618
|
+
}
|
|
619
|
+
TypeGuard.TSchema = TSchema;
|
|
620
|
+
})(TypeGuard = exports.TypeGuard || (exports.TypeGuard = {}));
|
|
621
|
+
// --------------------------------------------------------------------------
|
|
622
|
+
// ExtendsUndefined
|
|
623
|
+
// --------------------------------------------------------------------------
|
|
624
|
+
var ExtendsUndefined;
|
|
625
|
+
(function (ExtendsUndefined) {
|
|
626
|
+
/** Fast undefined check for properties of type undefined */
|
|
627
|
+
function Check(schema) {
|
|
628
|
+
if (schema[exports.Kind] === 'Undefined')
|
|
629
|
+
return true;
|
|
630
|
+
if (schema[exports.Kind] === 'Union') {
|
|
631
|
+
const union = schema;
|
|
632
|
+
return union.anyOf.some((schema) => Check(schema));
|
|
633
|
+
}
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
ExtendsUndefined.Check = Check;
|
|
637
|
+
})(ExtendsUndefined = exports.ExtendsUndefined || (exports.ExtendsUndefined = {}));
|
|
638
|
+
// --------------------------------------------------------------------------
|
|
639
|
+
// TypeExtends
|
|
640
|
+
// --------------------------------------------------------------------------
|
|
641
|
+
var TypeExtendsResult;
|
|
642
|
+
(function (TypeExtendsResult) {
|
|
643
|
+
TypeExtendsResult[TypeExtendsResult["Union"] = 0] = "Union";
|
|
644
|
+
TypeExtendsResult[TypeExtendsResult["True"] = 1] = "True";
|
|
645
|
+
TypeExtendsResult[TypeExtendsResult["False"] = 2] = "False";
|
|
646
|
+
})(TypeExtendsResult = exports.TypeExtendsResult || (exports.TypeExtendsResult = {}));
|
|
647
|
+
var TypeExtends;
|
|
648
|
+
(function (TypeExtends) {
|
|
649
|
+
// --------------------------------------------------------------------------
|
|
650
|
+
// IntoBooleanResult
|
|
651
|
+
// --------------------------------------------------------------------------
|
|
652
|
+
function IntoBooleanResult(result) {
|
|
653
|
+
return result === TypeExtendsResult.False ? TypeExtendsResult.False : TypeExtendsResult.True;
|
|
654
|
+
}
|
|
655
|
+
// --------------------------------------------------------------------------
|
|
656
|
+
// Any
|
|
657
|
+
// --------------------------------------------------------------------------
|
|
658
|
+
function AnyRight(left, right) {
|
|
659
|
+
return TypeExtendsResult.True;
|
|
660
|
+
}
|
|
661
|
+
function Any(left, right) {
|
|
662
|
+
if (TypeGuard.TIntersect(right))
|
|
663
|
+
return IntersectRight(left, right);
|
|
664
|
+
if (TypeGuard.TUnion(right) && right.anyOf.some((schema) => TypeGuard.TAny(schema) || TypeGuard.TUnknown(schema)))
|
|
665
|
+
return TypeExtendsResult.True;
|
|
666
|
+
if (TypeGuard.TUnion(right))
|
|
667
|
+
return TypeExtendsResult.Union;
|
|
668
|
+
if (TypeGuard.TUnknown(right))
|
|
669
|
+
return TypeExtendsResult.True;
|
|
670
|
+
if (TypeGuard.TAny(right))
|
|
671
|
+
return TypeExtendsResult.True;
|
|
672
|
+
return TypeExtendsResult.Union;
|
|
673
|
+
}
|
|
674
|
+
// --------------------------------------------------------------------------
|
|
675
|
+
// Array
|
|
676
|
+
// --------------------------------------------------------------------------
|
|
677
|
+
function ArrayRight(left, right) {
|
|
678
|
+
if (TypeGuard.TUnknown(left))
|
|
679
|
+
return TypeExtendsResult.False;
|
|
680
|
+
if (TypeGuard.TAny(left))
|
|
681
|
+
return TypeExtendsResult.Union;
|
|
682
|
+
if (TypeGuard.TNever(left))
|
|
683
|
+
return TypeExtendsResult.True;
|
|
684
|
+
return TypeExtendsResult.False;
|
|
685
|
+
}
|
|
686
|
+
function Array(left, right) {
|
|
687
|
+
if (TypeGuard.TIntersect(right))
|
|
688
|
+
return IntersectRight(left, right);
|
|
689
|
+
if (TypeGuard.TUnion(right))
|
|
690
|
+
return UnionRight(left, right);
|
|
691
|
+
if (TypeGuard.TUnknown(right))
|
|
692
|
+
return UnknownRight(left, right);
|
|
693
|
+
if (TypeGuard.TAny(right))
|
|
694
|
+
return AnyRight(left, right);
|
|
695
|
+
if (TypeGuard.TObject(right) && IsObjectArrayLike(right))
|
|
696
|
+
return TypeExtendsResult.True;
|
|
697
|
+
if (!TypeGuard.TArray(right))
|
|
698
|
+
return TypeExtendsResult.False;
|
|
699
|
+
return IntoBooleanResult(Visit(left.items, right.items));
|
|
700
|
+
}
|
|
701
|
+
// --------------------------------------------------------------------------
|
|
702
|
+
// BigInt
|
|
703
|
+
// --------------------------------------------------------------------------
|
|
704
|
+
function BigInt(left, right) {
|
|
705
|
+
if (TypeGuard.TIntersect(right))
|
|
706
|
+
return IntersectRight(left, right);
|
|
707
|
+
if (TypeGuard.TUnion(right))
|
|
708
|
+
return UnionRight(left, right);
|
|
709
|
+
if (TypeGuard.TNever(right))
|
|
710
|
+
return NeverRight(left, right);
|
|
711
|
+
if (TypeGuard.TUnknown(right))
|
|
712
|
+
return UnknownRight(left, right);
|
|
713
|
+
if (TypeGuard.TAny(right))
|
|
714
|
+
return AnyRight(left, right);
|
|
715
|
+
if (TypeGuard.TObject(right))
|
|
716
|
+
return ObjectRight(left, right);
|
|
717
|
+
if (TypeGuard.TRecord(right))
|
|
718
|
+
return RecordRight(left, right);
|
|
719
|
+
return TypeGuard.TBigInt(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
720
|
+
}
|
|
721
|
+
// --------------------------------------------------------------------------
|
|
722
|
+
// Boolean
|
|
723
|
+
// --------------------------------------------------------------------------
|
|
724
|
+
function BooleanRight(left, right) {
|
|
725
|
+
if (TypeGuard.TLiteral(left) && typeof left.const === 'boolean')
|
|
726
|
+
return TypeExtendsResult.True;
|
|
727
|
+
return TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
728
|
+
}
|
|
729
|
+
function Boolean(left, right) {
|
|
730
|
+
if (TypeGuard.TIntersect(right))
|
|
731
|
+
return IntersectRight(left, right);
|
|
732
|
+
if (TypeGuard.TUnion(right))
|
|
733
|
+
return UnionRight(left, right);
|
|
734
|
+
if (TypeGuard.TNever(right))
|
|
735
|
+
return NeverRight(left, right);
|
|
736
|
+
if (TypeGuard.TUnknown(right))
|
|
737
|
+
return UnknownRight(left, right);
|
|
738
|
+
if (TypeGuard.TAny(right))
|
|
739
|
+
return AnyRight(left, right);
|
|
740
|
+
if (TypeGuard.TObject(right))
|
|
741
|
+
return ObjectRight(left, right);
|
|
742
|
+
if (TypeGuard.TRecord(right))
|
|
743
|
+
return RecordRight(left, right);
|
|
744
|
+
return TypeGuard.TBoolean(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
745
|
+
}
|
|
746
|
+
// --------------------------------------------------------------------------
|
|
747
|
+
// Constructor
|
|
748
|
+
// --------------------------------------------------------------------------
|
|
749
|
+
function Constructor(left, right) {
|
|
750
|
+
if (TypeGuard.TIntersect(right))
|
|
751
|
+
return IntersectRight(left, right);
|
|
752
|
+
if (TypeGuard.TUnion(right))
|
|
753
|
+
return UnionRight(left, right);
|
|
754
|
+
if (TypeGuard.TUnknown(right))
|
|
755
|
+
return UnknownRight(left, right);
|
|
756
|
+
if (TypeGuard.TAny(right))
|
|
757
|
+
return AnyRight(left, right);
|
|
758
|
+
if (TypeGuard.TObject(right))
|
|
759
|
+
return ObjectRight(left, right);
|
|
760
|
+
if (!TypeGuard.TConstructor(right))
|
|
761
|
+
return TypeExtendsResult.False;
|
|
762
|
+
if (left.parameters.length > right.parameters.length)
|
|
763
|
+
return TypeExtendsResult.False;
|
|
764
|
+
if (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) {
|
|
765
|
+
return TypeExtendsResult.False;
|
|
766
|
+
}
|
|
767
|
+
return IntoBooleanResult(Visit(left.returns, right.returns));
|
|
768
|
+
}
|
|
769
|
+
// --------------------------------------------------------------------------
|
|
770
|
+
// Date
|
|
771
|
+
// --------------------------------------------------------------------------
|
|
772
|
+
function Date(left, right) {
|
|
773
|
+
if (TypeGuard.TIntersect(right))
|
|
774
|
+
return IntersectRight(left, right);
|
|
775
|
+
if (TypeGuard.TUnion(right))
|
|
776
|
+
return UnionRight(left, right);
|
|
777
|
+
if (TypeGuard.TUnknown(right))
|
|
778
|
+
return UnknownRight(left, right);
|
|
779
|
+
if (TypeGuard.TAny(right))
|
|
780
|
+
return AnyRight(left, right);
|
|
781
|
+
if (TypeGuard.TObject(right))
|
|
782
|
+
return ObjectRight(left, right);
|
|
783
|
+
if (TypeGuard.TRecord(right))
|
|
784
|
+
return RecordRight(left, right);
|
|
785
|
+
return TypeGuard.TDate(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
786
|
+
}
|
|
787
|
+
// --------------------------------------------------------------------------
|
|
788
|
+
// Function
|
|
789
|
+
// --------------------------------------------------------------------------
|
|
790
|
+
function Function(left, right) {
|
|
791
|
+
if (TypeGuard.TIntersect(right))
|
|
792
|
+
return IntersectRight(left, right);
|
|
793
|
+
if (TypeGuard.TUnion(right))
|
|
794
|
+
return UnionRight(left, right);
|
|
795
|
+
if (TypeGuard.TUnknown(right))
|
|
796
|
+
return UnknownRight(left, right);
|
|
797
|
+
if (TypeGuard.TAny(right))
|
|
798
|
+
return AnyRight(left, right);
|
|
799
|
+
if (TypeGuard.TObject(right))
|
|
800
|
+
return ObjectRight(left, right);
|
|
801
|
+
if (!TypeGuard.TFunction(right))
|
|
802
|
+
return TypeExtendsResult.False;
|
|
803
|
+
if (left.parameters.length > right.parameters.length)
|
|
804
|
+
return TypeExtendsResult.False;
|
|
805
|
+
if (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) {
|
|
806
|
+
return TypeExtendsResult.False;
|
|
807
|
+
}
|
|
808
|
+
return IntoBooleanResult(Visit(left.returns, right.returns));
|
|
809
|
+
}
|
|
810
|
+
// --------------------------------------------------------------------------
|
|
811
|
+
// Integer
|
|
812
|
+
// --------------------------------------------------------------------------
|
|
813
|
+
function IntegerRight(left, right) {
|
|
814
|
+
if (TypeGuard.TLiteral(left) && typeof left.const === 'number')
|
|
815
|
+
return TypeExtendsResult.True;
|
|
816
|
+
return TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
817
|
+
}
|
|
818
|
+
function Integer(left, right) {
|
|
819
|
+
if (TypeGuard.TIntersect(right))
|
|
820
|
+
return IntersectRight(left, right);
|
|
821
|
+
if (TypeGuard.TUnion(right))
|
|
822
|
+
return UnionRight(left, right);
|
|
823
|
+
if (TypeGuard.TNever(right))
|
|
824
|
+
return NeverRight(left, right);
|
|
825
|
+
if (TypeGuard.TUnknown(right))
|
|
826
|
+
return UnknownRight(left, right);
|
|
827
|
+
if (TypeGuard.TAny(right))
|
|
828
|
+
return AnyRight(left, right);
|
|
829
|
+
if (TypeGuard.TObject(right))
|
|
830
|
+
return ObjectRight(left, right);
|
|
831
|
+
if (TypeGuard.TRecord(right))
|
|
832
|
+
return RecordRight(left, right);
|
|
833
|
+
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
834
|
+
}
|
|
835
|
+
// --------------------------------------------------------------------------
|
|
836
|
+
// Intersect
|
|
837
|
+
// --------------------------------------------------------------------------
|
|
838
|
+
function IntersectRight(left, right) {
|
|
839
|
+
return right.allOf.every((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
840
|
+
}
|
|
841
|
+
function Intersect(left, right) {
|
|
842
|
+
return left.allOf.some((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
843
|
+
}
|
|
844
|
+
// --------------------------------------------------------------------------
|
|
845
|
+
// Literal
|
|
846
|
+
// --------------------------------------------------------------------------
|
|
847
|
+
function IsLiteralString(schema) {
|
|
848
|
+
return typeof schema.const === 'string';
|
|
849
|
+
}
|
|
850
|
+
function IsLiteralNumber(schema) {
|
|
851
|
+
return typeof schema.const === 'number';
|
|
852
|
+
}
|
|
853
|
+
function IsLiteralBoolean(schema) {
|
|
854
|
+
return typeof schema.const === 'boolean';
|
|
855
|
+
}
|
|
856
|
+
function Literal(left, right) {
|
|
857
|
+
if (TypeGuard.TIntersect(right))
|
|
858
|
+
return IntersectRight(left, right);
|
|
859
|
+
if (TypeGuard.TUnion(right))
|
|
860
|
+
return UnionRight(left, right);
|
|
861
|
+
if (TypeGuard.TNever(right))
|
|
862
|
+
return NeverRight(left, right);
|
|
863
|
+
if (TypeGuard.TUnknown(right))
|
|
864
|
+
return UnknownRight(left, right);
|
|
865
|
+
if (TypeGuard.TAny(right))
|
|
866
|
+
return AnyRight(left, right);
|
|
867
|
+
if (TypeGuard.TObject(right))
|
|
868
|
+
return ObjectRight(left, right);
|
|
869
|
+
if (TypeGuard.TRecord(right))
|
|
870
|
+
return RecordRight(left, right);
|
|
871
|
+
if (TypeGuard.TString(right))
|
|
872
|
+
return StringRight(left, right);
|
|
873
|
+
if (TypeGuard.TNumber(right))
|
|
874
|
+
return NumberRight(left, right);
|
|
875
|
+
if (TypeGuard.TInteger(right))
|
|
876
|
+
return IntegerRight(left, right);
|
|
877
|
+
if (TypeGuard.TBoolean(right))
|
|
878
|
+
return BooleanRight(left, right);
|
|
879
|
+
return TypeGuard.TLiteral(right) && right.const === left.const ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
880
|
+
}
|
|
881
|
+
// --------------------------------------------------------------------------
|
|
882
|
+
// Never
|
|
883
|
+
// --------------------------------------------------------------------------
|
|
884
|
+
function NeverRight(left, right) {
|
|
885
|
+
return TypeExtendsResult.False;
|
|
886
|
+
}
|
|
887
|
+
function Never(left, right) {
|
|
888
|
+
return TypeExtendsResult.True;
|
|
889
|
+
}
|
|
890
|
+
// --------------------------------------------------------------------------
|
|
891
|
+
// Null
|
|
892
|
+
// --------------------------------------------------------------------------
|
|
893
|
+
function Null(left, right) {
|
|
894
|
+
if (TypeGuard.TIntersect(right))
|
|
895
|
+
return IntersectRight(left, right);
|
|
896
|
+
if (TypeGuard.TUnion(right))
|
|
897
|
+
return UnionRight(left, right);
|
|
898
|
+
if (TypeGuard.TNever(right))
|
|
899
|
+
return NeverRight(left, right);
|
|
900
|
+
if (TypeGuard.TUnknown(right))
|
|
901
|
+
return UnknownRight(left, right);
|
|
902
|
+
if (TypeGuard.TAny(right))
|
|
903
|
+
return AnyRight(left, right);
|
|
904
|
+
if (TypeGuard.TObject(right))
|
|
905
|
+
return ObjectRight(left, right);
|
|
906
|
+
if (TypeGuard.TRecord(right))
|
|
907
|
+
return RecordRight(left, right);
|
|
908
|
+
return TypeGuard.TNull(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
909
|
+
}
|
|
910
|
+
// --------------------------------------------------------------------------
|
|
911
|
+
// Number
|
|
912
|
+
// --------------------------------------------------------------------------
|
|
913
|
+
function NumberRight(left, right) {
|
|
914
|
+
if (TypeGuard.TLiteral(left) && IsLiteralNumber(left))
|
|
915
|
+
return TypeExtendsResult.True;
|
|
916
|
+
return TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
917
|
+
}
|
|
918
|
+
function Number(left, right) {
|
|
919
|
+
if (TypeGuard.TIntersect(right))
|
|
920
|
+
return IntersectRight(left, right);
|
|
921
|
+
if (TypeGuard.TUnion(right))
|
|
922
|
+
return UnionRight(left, right);
|
|
923
|
+
if (TypeGuard.TNever(right))
|
|
924
|
+
return NeverRight(left, right);
|
|
925
|
+
if (TypeGuard.TUnknown(right))
|
|
926
|
+
return UnknownRight(left, right);
|
|
927
|
+
if (TypeGuard.TAny(right))
|
|
928
|
+
return AnyRight(left, right);
|
|
929
|
+
if (TypeGuard.TObject(right))
|
|
930
|
+
return ObjectRight(left, right);
|
|
931
|
+
if (TypeGuard.TRecord(right))
|
|
932
|
+
return RecordRight(left, right);
|
|
933
|
+
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
934
|
+
}
|
|
935
|
+
// --------------------------------------------------------------------------
|
|
936
|
+
// Object
|
|
937
|
+
// --------------------------------------------------------------------------
|
|
938
|
+
function IsObjectPropertyCount(schema, count) {
|
|
939
|
+
return globalThis.Object.keys(schema.properties).length === count;
|
|
940
|
+
}
|
|
941
|
+
function IsObjectStringLike(schema) {
|
|
942
|
+
return IsObjectArrayLike(schema);
|
|
943
|
+
}
|
|
944
|
+
function IsObjectSymbolLike(schema) {
|
|
945
|
+
// prettier-ignore
|
|
946
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties && TypeGuard.TUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && ((TypeGuard.TString(schema.properties.description.anyOf[0]) &&
|
|
947
|
+
TypeGuard.TUndefined(schema.properties.description.anyOf[1])) || (TypeGuard.TString(schema.properties.description.anyOf[1]) &&
|
|
948
|
+
TypeGuard.TUndefined(schema.properties.description.anyOf[0]))));
|
|
949
|
+
}
|
|
950
|
+
function IsObjectNumberLike(schema) {
|
|
951
|
+
return IsObjectPropertyCount(schema, 0);
|
|
952
|
+
}
|
|
953
|
+
function IsObjectBooleanLike(schema) {
|
|
954
|
+
return IsObjectPropertyCount(schema, 0);
|
|
955
|
+
}
|
|
956
|
+
function IsObjectBigIntLike(schema) {
|
|
957
|
+
return IsObjectPropertyCount(schema, 0);
|
|
958
|
+
}
|
|
959
|
+
function IsObjectDateLike(schema) {
|
|
960
|
+
return IsObjectPropertyCount(schema, 0);
|
|
961
|
+
}
|
|
962
|
+
function IsObjectUint8ArrayLike(schema) {
|
|
963
|
+
return IsObjectArrayLike(schema);
|
|
964
|
+
}
|
|
965
|
+
function IsObjectFunctionLike(schema) {
|
|
966
|
+
const length = exports.Type.Number();
|
|
967
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'length' in schema.properties && IntoBooleanResult(Visit(schema.properties['length'], length)) === TypeExtendsResult.True);
|
|
968
|
+
}
|
|
969
|
+
function IsObjectConstructorLike(schema) {
|
|
970
|
+
return IsObjectPropertyCount(schema, 0);
|
|
971
|
+
}
|
|
972
|
+
function IsObjectArrayLike(schema) {
|
|
973
|
+
const length = exports.Type.Number();
|
|
974
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'length' in schema.properties && IntoBooleanResult(Visit(schema.properties['length'], length)) === TypeExtendsResult.True);
|
|
975
|
+
}
|
|
976
|
+
function IsObjectPromiseLike(schema) {
|
|
977
|
+
const then = exports.Type.Function([exports.Type.Any()], exports.Type.Any());
|
|
978
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'then' in schema.properties && IntoBooleanResult(Visit(schema.properties['then'], then)) === TypeExtendsResult.True);
|
|
979
|
+
}
|
|
980
|
+
// --------------------------------------------------------------------------
|
|
981
|
+
// Property
|
|
982
|
+
// --------------------------------------------------------------------------
|
|
983
|
+
function Property(left, right) {
|
|
984
|
+
if (Visit(left, right) === TypeExtendsResult.False)
|
|
985
|
+
return TypeExtendsResult.False;
|
|
986
|
+
if (TypeGuard.TOptional(left) && !TypeGuard.TOptional(right))
|
|
987
|
+
return TypeExtendsResult.False;
|
|
988
|
+
return TypeExtendsResult.True;
|
|
989
|
+
}
|
|
990
|
+
function ObjectRight(left, right) {
|
|
991
|
+
if (TypeGuard.TUnknown(left))
|
|
992
|
+
return TypeExtendsResult.False;
|
|
993
|
+
if (TypeGuard.TAny(left))
|
|
994
|
+
return TypeExtendsResult.Union;
|
|
995
|
+
if (TypeGuard.TNever(left))
|
|
996
|
+
return TypeExtendsResult.True;
|
|
997
|
+
if (TypeGuard.TLiteral(left) && IsLiteralString(left) && IsObjectStringLike(right))
|
|
998
|
+
return TypeExtendsResult.True;
|
|
999
|
+
if (TypeGuard.TLiteral(left) && IsLiteralNumber(left) && IsObjectNumberLike(right))
|
|
1000
|
+
return TypeExtendsResult.True;
|
|
1001
|
+
if (TypeGuard.TLiteral(left) && IsLiteralBoolean(left) && IsObjectBooleanLike(right))
|
|
1002
|
+
return TypeExtendsResult.True;
|
|
1003
|
+
if (TypeGuard.TSymbol(left) && IsObjectSymbolLike(right))
|
|
1004
|
+
return TypeExtendsResult.True;
|
|
1005
|
+
if (TypeGuard.TBigInt(left) && IsObjectBigIntLike(right))
|
|
1006
|
+
return TypeExtendsResult.True;
|
|
1007
|
+
if (TypeGuard.TString(left) && IsObjectStringLike(right))
|
|
1008
|
+
return TypeExtendsResult.True;
|
|
1009
|
+
if (TypeGuard.TSymbol(left) && IsObjectSymbolLike(right))
|
|
1010
|
+
return TypeExtendsResult.True;
|
|
1011
|
+
if (TypeGuard.TNumber(left) && IsObjectNumberLike(right))
|
|
1012
|
+
return TypeExtendsResult.True;
|
|
1013
|
+
if (TypeGuard.TInteger(left) && IsObjectNumberLike(right))
|
|
1014
|
+
return TypeExtendsResult.True;
|
|
1015
|
+
if (TypeGuard.TBoolean(left) && IsObjectBooleanLike(right))
|
|
1016
|
+
return TypeExtendsResult.True;
|
|
1017
|
+
if (TypeGuard.TUint8Array(left) && IsObjectUint8ArrayLike(right))
|
|
1018
|
+
return TypeExtendsResult.True;
|
|
1019
|
+
if (TypeGuard.TDate(left) && IsObjectDateLike(right))
|
|
1020
|
+
return TypeExtendsResult.True;
|
|
1021
|
+
if (TypeGuard.TConstructor(left) && IsObjectConstructorLike(right))
|
|
1022
|
+
return TypeExtendsResult.True;
|
|
1023
|
+
if (TypeGuard.TFunction(left) && IsObjectFunctionLike(right))
|
|
1024
|
+
return TypeExtendsResult.True;
|
|
1025
|
+
if (TypeGuard.TRecord(left) && TypeGuard.TString(RecordKey(left))) {
|
|
1026
|
+
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
1027
|
+
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
1028
|
+
return right[exports.Hint] === 'Record' ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1029
|
+
}
|
|
1030
|
+
if (TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left))) {
|
|
1031
|
+
return IsObjectPropertyCount(right, 0) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1032
|
+
}
|
|
1033
|
+
return TypeExtendsResult.False;
|
|
1034
|
+
}
|
|
1035
|
+
function Object(left, right) {
|
|
1036
|
+
if (TypeGuard.TIntersect(right))
|
|
1037
|
+
return IntersectRight(left, right);
|
|
1038
|
+
if (TypeGuard.TUnion(right))
|
|
1039
|
+
return UnionRight(left, right);
|
|
1040
|
+
if (TypeGuard.TUnknown(right))
|
|
1041
|
+
return UnknownRight(left, right);
|
|
1042
|
+
if (TypeGuard.TAny(right))
|
|
1043
|
+
return AnyRight(left, right);
|
|
1044
|
+
if (TypeGuard.TRecord(right))
|
|
1045
|
+
return RecordRight(left, right);
|
|
1046
|
+
if (!TypeGuard.TObject(right))
|
|
1047
|
+
return TypeExtendsResult.False;
|
|
1048
|
+
for (const key of globalThis.Object.keys(right.properties)) {
|
|
1049
|
+
if (!(key in left.properties))
|
|
1050
|
+
return TypeExtendsResult.False;
|
|
1051
|
+
if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
|
|
1052
|
+
return TypeExtendsResult.False;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return TypeExtendsResult.True;
|
|
1056
|
+
}
|
|
1057
|
+
// --------------------------------------------------------------------------
|
|
1058
|
+
// Promise
|
|
1059
|
+
// --------------------------------------------------------------------------
|
|
1060
|
+
function Promise(left, right) {
|
|
1061
|
+
if (TypeGuard.TIntersect(right))
|
|
1062
|
+
return IntersectRight(left, right);
|
|
1063
|
+
if (TypeGuard.TUnion(right))
|
|
1064
|
+
return UnionRight(left, right);
|
|
1065
|
+
if (TypeGuard.TUnknown(right))
|
|
1066
|
+
return UnknownRight(left, right);
|
|
1067
|
+
if (TypeGuard.TAny(right))
|
|
1068
|
+
return AnyRight(left, right);
|
|
1069
|
+
if (TypeGuard.TObject(right) && IsObjectPromiseLike(right))
|
|
1070
|
+
return TypeExtendsResult.True;
|
|
1071
|
+
if (!TypeGuard.TPromise(right))
|
|
1072
|
+
return TypeExtendsResult.False;
|
|
1073
|
+
return IntoBooleanResult(Visit(left.item, right.item));
|
|
1074
|
+
}
|
|
1075
|
+
// --------------------------------------------------------------------------
|
|
1076
|
+
// Record
|
|
1077
|
+
// --------------------------------------------------------------------------
|
|
1078
|
+
function RecordKey(schema) {
|
|
1079
|
+
if ('^(0|[1-9][0-9]*)$' in schema.patternProperties)
|
|
1080
|
+
return exports.Type.Number();
|
|
1081
|
+
if ('^.*$' in schema.patternProperties)
|
|
1082
|
+
return exports.Type.String();
|
|
1083
|
+
throw Error('TypeExtends: Cannot get record key');
|
|
1084
|
+
}
|
|
1085
|
+
function RecordValue(schema) {
|
|
1086
|
+
if ('^(0|[1-9][0-9]*)$' in schema.patternProperties)
|
|
1087
|
+
return schema.patternProperties['^(0|[1-9][0-9]*)$'];
|
|
1088
|
+
if ('^.*$' in schema.patternProperties)
|
|
1089
|
+
return schema.patternProperties['^.*$'];
|
|
1090
|
+
throw Error('TypeExtends: Cannot get record value');
|
|
1091
|
+
}
|
|
1092
|
+
function RecordRight(left, right) {
|
|
1093
|
+
const Key = RecordKey(right);
|
|
1094
|
+
const Value = RecordValue(right);
|
|
1095
|
+
if (TypeGuard.TLiteral(left) && IsLiteralString(left) && TypeGuard.TNumber(Key) && IntoBooleanResult(Visit(left, Value)) === TypeExtendsResult.True)
|
|
1096
|
+
return TypeExtendsResult.True;
|
|
1097
|
+
if (TypeGuard.TUint8Array(left) && TypeGuard.TNumber(Key))
|
|
1098
|
+
return Visit(left, Value);
|
|
1099
|
+
if (TypeGuard.TString(left) && TypeGuard.TNumber(Key))
|
|
1100
|
+
return Visit(left, Value);
|
|
1101
|
+
if (TypeGuard.TArray(left) && TypeGuard.TNumber(Key))
|
|
1102
|
+
return Visit(left, Value);
|
|
1103
|
+
if (TypeGuard.TObject(left)) {
|
|
1104
|
+
for (const key of globalThis.Object.keys(left.properties)) {
|
|
1105
|
+
if (Property(Value, left.properties[key]) === TypeExtendsResult.False) {
|
|
1106
|
+
return TypeExtendsResult.False;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return TypeExtendsResult.True;
|
|
1110
|
+
}
|
|
1111
|
+
return TypeExtendsResult.False;
|
|
1112
|
+
}
|
|
1113
|
+
function Record(left, right) {
|
|
1114
|
+
const Value = RecordValue(left);
|
|
1115
|
+
if (TypeGuard.TIntersect(right))
|
|
1116
|
+
return IntersectRight(left, right);
|
|
1117
|
+
if (TypeGuard.TUnion(right))
|
|
1118
|
+
return UnionRight(left, right);
|
|
1119
|
+
if (TypeGuard.TUnknown(right))
|
|
1120
|
+
return UnknownRight(left, right);
|
|
1121
|
+
if (TypeGuard.TAny(right))
|
|
1122
|
+
return AnyRight(left, right);
|
|
1123
|
+
if (TypeGuard.TObject(right))
|
|
1124
|
+
return ObjectRight(left, right);
|
|
1125
|
+
if (!TypeGuard.TRecord(right))
|
|
1126
|
+
return TypeExtendsResult.False;
|
|
1127
|
+
return Visit(Value, RecordValue(right));
|
|
1128
|
+
}
|
|
1129
|
+
// --------------------------------------------------------------------------
|
|
1130
|
+
// String
|
|
1131
|
+
// --------------------------------------------------------------------------
|
|
1132
|
+
function StringRight(left, right) {
|
|
1133
|
+
if (TypeGuard.TLiteral(left) && typeof left.const === 'string')
|
|
1134
|
+
return TypeExtendsResult.True;
|
|
1135
|
+
return TypeGuard.TString(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1136
|
+
}
|
|
1137
|
+
function String(left, right) {
|
|
1138
|
+
if (TypeGuard.TIntersect(right))
|
|
1139
|
+
return IntersectRight(left, right);
|
|
1140
|
+
if (TypeGuard.TUnion(right))
|
|
1141
|
+
return UnionRight(left, right);
|
|
1142
|
+
if (TypeGuard.TNever(right))
|
|
1143
|
+
return NeverRight(left, right);
|
|
1144
|
+
if (TypeGuard.TUnknown(right))
|
|
1145
|
+
return UnknownRight(left, right);
|
|
1146
|
+
if (TypeGuard.TAny(right))
|
|
1147
|
+
return AnyRight(left, right);
|
|
1148
|
+
if (TypeGuard.TObject(right))
|
|
1149
|
+
return ObjectRight(left, right);
|
|
1150
|
+
if (TypeGuard.TRecord(right))
|
|
1151
|
+
return RecordRight(left, right);
|
|
1152
|
+
return TypeGuard.TString(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1153
|
+
}
|
|
1154
|
+
// --------------------------------------------------------------------------
|
|
1155
|
+
// Symbol
|
|
1156
|
+
// --------------------------------------------------------------------------
|
|
1157
|
+
function Symbol(left, right) {
|
|
1158
|
+
if (TypeGuard.TIntersect(right))
|
|
1159
|
+
return IntersectRight(left, right);
|
|
1160
|
+
if (TypeGuard.TUnion(right))
|
|
1161
|
+
return UnionRight(left, right);
|
|
1162
|
+
if (TypeGuard.TNever(right))
|
|
1163
|
+
return NeverRight(left, right);
|
|
1164
|
+
if (TypeGuard.TUnknown(right))
|
|
1165
|
+
return UnknownRight(left, right);
|
|
1166
|
+
if (TypeGuard.TAny(right))
|
|
1167
|
+
return AnyRight(left, right);
|
|
1168
|
+
if (TypeGuard.TObject(right))
|
|
1169
|
+
return ObjectRight(left, right);
|
|
1170
|
+
if (TypeGuard.TRecord(right))
|
|
1171
|
+
return RecordRight(left, right);
|
|
1172
|
+
return TypeGuard.TSymbol(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1173
|
+
}
|
|
1174
|
+
// --------------------------------------------------------------------------
|
|
1175
|
+
// Tuple
|
|
1176
|
+
// --------------------------------------------------------------------------
|
|
1177
|
+
function TupleRight(left, right) {
|
|
1178
|
+
if (TypeGuard.TUnknown(left))
|
|
1179
|
+
return TypeExtendsResult.False;
|
|
1180
|
+
if (TypeGuard.TAny(left))
|
|
1181
|
+
return TypeExtendsResult.Union;
|
|
1182
|
+
if (TypeGuard.TNever(left))
|
|
1183
|
+
return TypeExtendsResult.True;
|
|
1184
|
+
return TypeExtendsResult.False;
|
|
1185
|
+
}
|
|
1186
|
+
function IsArrayOfTuple(left, right) {
|
|
1187
|
+
return TypeGuard.TArray(right) && left.items !== undefined && left.items.every((schema) => Visit(schema, right.items) === TypeExtendsResult.True);
|
|
1188
|
+
}
|
|
1189
|
+
function Tuple(left, right) {
|
|
1190
|
+
if (TypeGuard.TIntersect(right))
|
|
1191
|
+
return IntersectRight(left, right);
|
|
1192
|
+
if (TypeGuard.TUnion(right))
|
|
1193
|
+
return UnionRight(left, right);
|
|
1194
|
+
if (TypeGuard.TUnknown(right))
|
|
1195
|
+
return UnknownRight(left, right);
|
|
1196
|
+
if (TypeGuard.TAny(right))
|
|
1197
|
+
return AnyRight(left, right);
|
|
1198
|
+
if (TypeGuard.TObject(right) && IsObjectArrayLike(right))
|
|
1199
|
+
return TypeExtendsResult.True;
|
|
1200
|
+
if (TypeGuard.TArray(right) && IsArrayOfTuple(left, right))
|
|
1201
|
+
return TypeExtendsResult.True;
|
|
1202
|
+
if (!TypeGuard.TTuple(right))
|
|
1203
|
+
return TypeExtendsResult.False;
|
|
1204
|
+
if ((left.items === undefined && right.items !== undefined) || (left.items !== undefined && right.items === undefined))
|
|
1205
|
+
return TypeExtendsResult.False;
|
|
1206
|
+
if (left.items === undefined && right.items === undefined)
|
|
1207
|
+
return TypeExtendsResult.True;
|
|
1208
|
+
return left.items.every((schema, index) => Visit(schema, right.items[index]) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1209
|
+
}
|
|
1210
|
+
// --------------------------------------------------------------------------
|
|
1211
|
+
// Uint8Array
|
|
1212
|
+
// --------------------------------------------------------------------------
|
|
1213
|
+
function Uint8Array(left, right) {
|
|
1214
|
+
if (TypeGuard.TIntersect(right))
|
|
1215
|
+
return IntersectRight(left, right);
|
|
1216
|
+
if (TypeGuard.TUnion(right))
|
|
1217
|
+
return UnionRight(left, right);
|
|
1218
|
+
if (TypeGuard.TUnknown(right))
|
|
1219
|
+
return UnknownRight(left, right);
|
|
1220
|
+
if (TypeGuard.TAny(right))
|
|
1221
|
+
return AnyRight(left, right);
|
|
1222
|
+
if (TypeGuard.TObject(right))
|
|
1223
|
+
return ObjectRight(left, right);
|
|
1224
|
+
if (TypeGuard.TRecord(right))
|
|
1225
|
+
return RecordRight(left, right);
|
|
1226
|
+
return TypeGuard.TUint8Array(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1227
|
+
}
|
|
1228
|
+
// --------------------------------------------------------------------------
|
|
1229
|
+
// Undefined
|
|
1230
|
+
// --------------------------------------------------------------------------
|
|
1231
|
+
function Undefined(left, right) {
|
|
1232
|
+
if (TypeGuard.TIntersect(right))
|
|
1233
|
+
return IntersectRight(left, right);
|
|
1234
|
+
if (TypeGuard.TUnion(right))
|
|
1235
|
+
return UnionRight(left, right);
|
|
1236
|
+
if (TypeGuard.TNever(right))
|
|
1237
|
+
return NeverRight(left, right);
|
|
1238
|
+
if (TypeGuard.TUnknown(right))
|
|
1239
|
+
return UnknownRight(left, right);
|
|
1240
|
+
if (TypeGuard.TAny(right))
|
|
1241
|
+
return AnyRight(left, right);
|
|
1242
|
+
if (TypeGuard.TObject(right))
|
|
1243
|
+
return ObjectRight(left, right);
|
|
1244
|
+
if (TypeGuard.TRecord(right))
|
|
1245
|
+
return RecordRight(left, right);
|
|
1246
|
+
if (TypeGuard.TVoid(right))
|
|
1247
|
+
return VoidRight(left, right);
|
|
1248
|
+
return TypeGuard.TUndefined(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1249
|
+
}
|
|
1250
|
+
// --------------------------------------------------------------------------
|
|
1251
|
+
// Union
|
|
1252
|
+
// --------------------------------------------------------------------------
|
|
1253
|
+
function UnionRight(left, right) {
|
|
1254
|
+
return right.anyOf.some((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1255
|
+
}
|
|
1256
|
+
function Union(left, right) {
|
|
1257
|
+
return left.anyOf.every((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1258
|
+
}
|
|
1259
|
+
// --------------------------------------------------------------------------
|
|
1260
|
+
// Unknown
|
|
1261
|
+
// --------------------------------------------------------------------------
|
|
1262
|
+
function UnknownRight(left, right) {
|
|
1263
|
+
return TypeExtendsResult.True;
|
|
1264
|
+
}
|
|
1265
|
+
function Unknown(left, right) {
|
|
1266
|
+
if (TypeGuard.TIntersect(right))
|
|
1267
|
+
return IntersectRight(left, right);
|
|
1268
|
+
if (TypeGuard.TUnion(right))
|
|
1269
|
+
return UnionRight(left, right);
|
|
1270
|
+
if (TypeGuard.TAny(right))
|
|
1271
|
+
return AnyRight(left, right);
|
|
1272
|
+
if (TypeGuard.TString(right))
|
|
1273
|
+
return StringRight(left, right);
|
|
1274
|
+
if (TypeGuard.TNumber(right))
|
|
1275
|
+
return NumberRight(left, right);
|
|
1276
|
+
if (TypeGuard.TInteger(right))
|
|
1277
|
+
return IntegerRight(left, right);
|
|
1278
|
+
if (TypeGuard.TBoolean(right))
|
|
1279
|
+
return BooleanRight(left, right);
|
|
1280
|
+
if (TypeGuard.TArray(right))
|
|
1281
|
+
return ArrayRight(left, right);
|
|
1282
|
+
if (TypeGuard.TTuple(right))
|
|
1283
|
+
return TupleRight(left, right);
|
|
1284
|
+
if (TypeGuard.TObject(right))
|
|
1285
|
+
return ObjectRight(left, right);
|
|
1286
|
+
return TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1287
|
+
}
|
|
1288
|
+
// --------------------------------------------------------------------------
|
|
1289
|
+
// Void
|
|
1290
|
+
// --------------------------------------------------------------------------
|
|
1291
|
+
function VoidRight(left, right) {
|
|
1292
|
+
if (TypeGuard.TUndefined(left))
|
|
1293
|
+
return TypeExtendsResult.True;
|
|
1294
|
+
return TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1295
|
+
}
|
|
1296
|
+
function Void(left, right) {
|
|
1297
|
+
if (TypeGuard.TIntersect(right))
|
|
1298
|
+
return IntersectRight(left, right);
|
|
1299
|
+
if (TypeGuard.TUnion(right))
|
|
1300
|
+
return UnionRight(left, right);
|
|
1301
|
+
if (TypeGuard.TUnknown(right))
|
|
1302
|
+
return UnknownRight(left, right);
|
|
1303
|
+
if (TypeGuard.TAny(right))
|
|
1304
|
+
return AnyRight(left, right);
|
|
1305
|
+
if (TypeGuard.TObject(right))
|
|
1306
|
+
return ObjectRight(left, right);
|
|
1307
|
+
return TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1308
|
+
}
|
|
1309
|
+
function Visit(left, right) {
|
|
1310
|
+
const right_ = ReferenceRegistry.Deref(right);
|
|
1311
|
+
const left_ = ReferenceRegistry.Deref(left);
|
|
1312
|
+
if (TypeGuard.TAny(left_))
|
|
1313
|
+
return Any(left_, right_);
|
|
1314
|
+
if (TypeGuard.TArray(left_))
|
|
1315
|
+
return Array(left_, right_);
|
|
1316
|
+
if (TypeGuard.TBigInt(left_))
|
|
1317
|
+
return BigInt(left_, right_);
|
|
1318
|
+
if (TypeGuard.TBoolean(left_))
|
|
1319
|
+
return Boolean(left_, right_);
|
|
1320
|
+
if (TypeGuard.TConstructor(left_))
|
|
1321
|
+
return Constructor(left_, right_);
|
|
1322
|
+
if (TypeGuard.TDate(left_))
|
|
1323
|
+
return Date(left_, right_);
|
|
1324
|
+
if (TypeGuard.TFunction(left_))
|
|
1325
|
+
return Function(left_, right_);
|
|
1326
|
+
if (TypeGuard.TInteger(left_))
|
|
1327
|
+
return Integer(left_, right_);
|
|
1328
|
+
if (TypeGuard.TIntersect(left_))
|
|
1329
|
+
return Intersect(left_, right_);
|
|
1330
|
+
if (TypeGuard.TLiteral(left_))
|
|
1331
|
+
return Literal(left_, right_);
|
|
1332
|
+
if (TypeGuard.TNever(left_))
|
|
1333
|
+
return Never(left_, right_);
|
|
1334
|
+
if (TypeGuard.TNull(left_))
|
|
1335
|
+
return Null(left_, right_);
|
|
1336
|
+
if (TypeGuard.TNumber(left_))
|
|
1337
|
+
return Number(left_, right_);
|
|
1338
|
+
if (TypeGuard.TRecord(left_))
|
|
1339
|
+
return Record(left_, right_);
|
|
1340
|
+
if (TypeGuard.TString(left_))
|
|
1341
|
+
return String(left_, right_);
|
|
1342
|
+
if (TypeGuard.TSymbol(left_))
|
|
1343
|
+
return Symbol(left_, right_);
|
|
1344
|
+
if (TypeGuard.TObject(left_))
|
|
1345
|
+
return Object(left_, right_);
|
|
1346
|
+
if (TypeGuard.TTuple(left_))
|
|
1347
|
+
return Tuple(left_, right_);
|
|
1348
|
+
if (TypeGuard.TPromise(left_))
|
|
1349
|
+
return Promise(left_, right_);
|
|
1350
|
+
if (TypeGuard.TUint8Array(left_))
|
|
1351
|
+
return Uint8Array(left_, right_);
|
|
1352
|
+
if (TypeGuard.TUndefined(left_))
|
|
1353
|
+
return Undefined(left_, right_);
|
|
1354
|
+
if (TypeGuard.TUnion(left_))
|
|
1355
|
+
return Union(left_, right_);
|
|
1356
|
+
if (TypeGuard.TUnknown(left_))
|
|
1357
|
+
return Unknown(left_, right_);
|
|
1358
|
+
if (TypeGuard.TVoid(left_))
|
|
1359
|
+
return Void(left_, right_);
|
|
1360
|
+
throw Error(`TypeExtends: Unknown left type operand '${left[exports.Kind]}'`);
|
|
1361
|
+
}
|
|
1362
|
+
function Extends(left, right) {
|
|
1363
|
+
return Visit(left, right);
|
|
1364
|
+
}
|
|
1365
|
+
TypeExtends.Extends = Extends;
|
|
1366
|
+
})(TypeExtends = exports.TypeExtends || (exports.TypeExtends = {}));
|
|
1367
|
+
// --------------------------------------------------------------------------
|
|
1368
|
+
// TypeClone
|
|
1369
|
+
// --------------------------------------------------------------------------
|
|
1370
|
+
/** Specialized Clone for Types. Clones and removes non self-referential identifiers */
|
|
1371
|
+
var TypeClone;
|
|
1372
|
+
(function (TypeClone) {
|
|
1373
|
+
function IsRecursive(value) {
|
|
1374
|
+
return typeof value[exports.Recursive] === 'string';
|
|
1375
|
+
}
|
|
1376
|
+
function IsObject(value) {
|
|
1377
|
+
return typeof value === 'object' && value !== null && !globalThis.Array.isArray(value);
|
|
1378
|
+
}
|
|
1379
|
+
function IsArray(value) {
|
|
1380
|
+
return globalThis.Array.isArray(value);
|
|
1381
|
+
}
|
|
1382
|
+
function Array(value) {
|
|
1383
|
+
return value.map((value) => Visit(value));
|
|
1384
|
+
}
|
|
1385
|
+
function Object(value) {
|
|
1386
|
+
const clone = globalThis.Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), globalThis.Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {}));
|
|
1387
|
+
return clone;
|
|
1388
|
+
}
|
|
1389
|
+
function Visit(value) {
|
|
1390
|
+
const clone = IsObject(value) ? { ...value } : IsArray(value) ? [...value] : value;
|
|
1391
|
+
if (IsObject(clone) && !IsRecursive(clone))
|
|
1392
|
+
delete clone['$id'];
|
|
1393
|
+
if (IsObject(clone))
|
|
1394
|
+
return Object(clone);
|
|
1395
|
+
if (IsArray(clone))
|
|
1396
|
+
return Array(clone);
|
|
1397
|
+
return clone;
|
|
1398
|
+
}
|
|
1399
|
+
/** Clones a type. This function will omit non-self referential identifiers on the cloned type. */
|
|
1400
|
+
function Clone(schema, options) {
|
|
1401
|
+
return { ...Visit({ ...schema }), ...options };
|
|
1402
|
+
}
|
|
1403
|
+
TypeClone.Clone = Clone;
|
|
1404
|
+
})(TypeClone = exports.TypeClone || (exports.TypeClone = {}));
|
|
1405
|
+
// --------------------------------------------------------------------------
|
|
1406
|
+
// ObjectMap
|
|
1407
|
+
// --------------------------------------------------------------------------
|
|
1408
|
+
var ObjectMap;
|
|
1409
|
+
(function (ObjectMap) {
|
|
1410
|
+
function Intersect(schema, callback) {
|
|
1411
|
+
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(ReferenceRegistry.Deref(inner), callback)), { ...schema });
|
|
1412
|
+
}
|
|
1413
|
+
function Union(schema, callback) {
|
|
1414
|
+
return exports.Type.Union(schema.anyOf.map((inner) => Visit(ReferenceRegistry.Deref(inner), callback)), { ...schema });
|
|
1415
|
+
}
|
|
1416
|
+
function Object(schema, callback) {
|
|
1417
|
+
return callback(schema);
|
|
1418
|
+
}
|
|
1419
|
+
function Visit(schema, callback) {
|
|
1420
|
+
if (TypeGuard.TIntersect(schema))
|
|
1421
|
+
return Intersect(schema, callback);
|
|
1422
|
+
if (TypeGuard.TUnion(schema))
|
|
1423
|
+
return Union(schema, callback);
|
|
1424
|
+
if (TypeGuard.TObject(schema))
|
|
1425
|
+
return Object(schema, callback);
|
|
1426
|
+
return schema;
|
|
1427
|
+
}
|
|
1428
|
+
function Map(schema, callback, options) {
|
|
1429
|
+
return { ...Visit(TypeClone.Clone(schema, {}), callback), ...options };
|
|
1430
|
+
}
|
|
1431
|
+
ObjectMap.Map = Map;
|
|
1432
|
+
})(ObjectMap = exports.ObjectMap || (exports.ObjectMap = {}));
|
|
1433
|
+
// --------------------------------------------------------------------------
|
|
1434
|
+
// KeyResolver
|
|
1435
|
+
// --------------------------------------------------------------------------
|
|
1436
|
+
var KeyResolver;
|
|
1437
|
+
(function (KeyResolver) {
|
|
1438
|
+
function IsKeyable(schema) {
|
|
1439
|
+
return TypeGuard.TIntersect(schema) || TypeGuard.TUnion(schema) || (TypeGuard.TObject(schema) && globalThis.Object.getOwnPropertyNames(schema.properties).length > 0);
|
|
1440
|
+
}
|
|
1441
|
+
function Intersect(schema) {
|
|
1442
|
+
return [...schema.allOf.filter((schema) => IsKeyable(schema)).reduce((set, schema) => Visit(schema).map((key) => set.add(key))[0], new Set())];
|
|
1443
|
+
}
|
|
1444
|
+
function Union(schema) {
|
|
1445
|
+
const sets = schema.anyOf.filter((schema) => IsKeyable(schema)).map((inner) => Visit(inner));
|
|
1446
|
+
return [...sets.reduce((set, outer) => outer.map((key) => (sets.every((inner) => inner.includes(key)) ? set.add(key) : set))[0], new Set())];
|
|
1447
|
+
}
|
|
1448
|
+
function Object(schema) {
|
|
1449
|
+
return globalThis.Object.keys(schema.properties);
|
|
1450
|
+
}
|
|
1451
|
+
function Visit(schema) {
|
|
1452
|
+
if (TypeGuard.TIntersect(schema))
|
|
1453
|
+
return Intersect(schema);
|
|
1454
|
+
if (TypeGuard.TUnion(schema))
|
|
1455
|
+
return Union(schema);
|
|
1456
|
+
if (TypeGuard.TObject(schema))
|
|
1457
|
+
return Object(schema);
|
|
1458
|
+
return [];
|
|
1459
|
+
}
|
|
1460
|
+
function Resolve(schema) {
|
|
1461
|
+
return Visit(schema);
|
|
1462
|
+
}
|
|
1463
|
+
KeyResolver.Resolve = Resolve;
|
|
1464
|
+
})(KeyResolver = exports.KeyResolver || (exports.KeyResolver = {}));
|
|
1465
|
+
// --------------------------------------------------------------------------
|
|
1466
|
+
// TypeOrdinal: Used for auto $id generation
|
|
1467
|
+
// --------------------------------------------------------------------------
|
|
1468
|
+
let TypeOrdinal = 0;
|
|
1469
|
+
// --------------------------------------------------------------------------
|
|
1470
|
+
// TypeBuilder
|
|
1471
|
+
// --------------------------------------------------------------------------
|
|
1472
|
+
class TypeBuilder {
|
|
1473
|
+
/** `[Utility]` Creates a schema without `static` and `params` types */
|
|
1474
|
+
Create(schema) {
|
|
1475
|
+
ReferenceRegistry.Set(schema);
|
|
1476
|
+
return schema;
|
|
1477
|
+
}
|
|
1478
|
+
/** `[Standard]` Omits compositing symbols from this schema */
|
|
1479
|
+
Strict(schema) {
|
|
1480
|
+
return JSON.parse(JSON.stringify(schema));
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
exports.TypeBuilder = TypeBuilder;
|
|
1484
|
+
// --------------------------------------------------------------------------
|
|
1485
|
+
// StandardTypeBuilder
|
|
1486
|
+
// --------------------------------------------------------------------------
|
|
1487
|
+
class StandardTypeBuilder extends TypeBuilder {
|
|
1488
|
+
// ------------------------------------------------------------------------
|
|
1489
|
+
// Modifiers
|
|
1490
|
+
// ------------------------------------------------------------------------
|
|
1491
|
+
/** `[Modifier]` Creates a Optional property */
|
|
1492
|
+
Optional(schema) {
|
|
1493
|
+
return { [exports.Modifier]: 'Optional', ...TypeClone.Clone(schema, {}) };
|
|
1494
|
+
}
|
|
1495
|
+
/** `[Modifier]` Creates a ReadonlyOptional property */
|
|
1496
|
+
ReadonlyOptional(schema) {
|
|
1497
|
+
return { [exports.Modifier]: 'ReadonlyOptional', ...TypeClone.Clone(schema, {}) };
|
|
1498
|
+
}
|
|
1499
|
+
/** `[Modifier]` Creates a Readonly object or property */
|
|
1500
|
+
Readonly(schema) {
|
|
1501
|
+
return { [exports.Modifier]: 'Readonly', ...schema };
|
|
1502
|
+
}
|
|
1503
|
+
// ------------------------------------------------------------------------
|
|
1504
|
+
// Types
|
|
1505
|
+
// ------------------------------------------------------------------------
|
|
1506
|
+
/** `[Standard]` Creates an Any type */
|
|
1507
|
+
Any(options = {}) {
|
|
1508
|
+
return this.Create({ ...options, [exports.Kind]: 'Any' });
|
|
1509
|
+
}
|
|
1510
|
+
/** `[Standard]` Creates an Array type */
|
|
1511
|
+
Array(items, options = {}) {
|
|
1512
|
+
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items, {}) });
|
|
1513
|
+
}
|
|
1514
|
+
/** `[Standard]` Creates a Boolean type */
|
|
1515
|
+
Boolean(options = {}) {
|
|
1516
|
+
return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
|
|
1517
|
+
}
|
|
1518
|
+
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
1519
|
+
Composite(schemas, options = {}) {
|
|
1520
|
+
const optional = new Set();
|
|
1521
|
+
for (const schema of schemas) {
|
|
1522
|
+
for (const [key, property] of globalThis.Object.entries(schema.properties)) {
|
|
1523
|
+
if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property))
|
|
1524
|
+
optional.add(key);
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
const properties = {};
|
|
1528
|
+
for (const object of schemas) {
|
|
1529
|
+
for (const [key, property] of globalThis.Object.entries(object.properties)) {
|
|
1530
|
+
const mapped = key in properties ? this.Union([properties[key], property]) : TypeClone.Clone(property, {});
|
|
1531
|
+
properties[key] = optional.has(key) ? this.Optional(mapped) : mapped;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
return this.Object(properties, options);
|
|
1535
|
+
}
|
|
1536
|
+
/** `[Standard]` Dereferences the given TRef to its target type */
|
|
1537
|
+
Deref(schema) {
|
|
1538
|
+
return ReferenceRegistry.Deref(schema);
|
|
1539
|
+
}
|
|
1540
|
+
/** `[Standard]` Creates a Enum type */
|
|
1541
|
+
Enum(item, options = {}) {
|
|
1542
|
+
// prettier-ignore
|
|
1543
|
+
const values = globalThis.Object.keys(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1544
|
+
const anyOf = values.map((value) => (typeof value === 'string' ? { [exports.Kind]: 'Literal', type: 'string', const: value } : { [exports.Kind]: 'Literal', type: 'number', const: value }));
|
|
1545
|
+
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf });
|
|
1546
|
+
}
|
|
1547
|
+
/** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
|
|
1548
|
+
Extends(left, right, trueType, falseType, options = {}) {
|
|
1549
|
+
switch (TypeExtends.Extends(ReferenceRegistry.Deref(left), ReferenceRegistry.Deref(right))) {
|
|
1550
|
+
case TypeExtendsResult.Union:
|
|
1551
|
+
return this.Union([TypeClone.Clone(trueType, options), TypeClone.Clone(falseType, options)]);
|
|
1552
|
+
case TypeExtendsResult.True:
|
|
1553
|
+
return TypeClone.Clone(trueType, options);
|
|
1554
|
+
case TypeExtendsResult.False:
|
|
1555
|
+
return TypeClone.Clone(falseType, options);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
/** `[Standard]` Excludes from the left type any type that is not assignable to the right */
|
|
1559
|
+
Exclude(left, right, options = {}) {
|
|
1560
|
+
if (TypeGuard.TUnion(left)) {
|
|
1561
|
+
const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) === TypeExtendsResult.False);
|
|
1562
|
+
return (narrowed.length === 1 ? TypeClone.Clone(narrowed[0], options) : this.Union(narrowed, options));
|
|
1563
|
+
}
|
|
1564
|
+
else {
|
|
1565
|
+
return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Clone(left, options));
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
/** `[Standard]` Extracts from left left any type that is assignable to the right */
|
|
1569
|
+
Extract(left, right, options = {}) {
|
|
1570
|
+
if (TypeGuard.TUnion(left)) {
|
|
1571
|
+
const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) !== TypeExtendsResult.False);
|
|
1572
|
+
return (narrowed.length === 1 ? TypeClone.Clone(narrowed[0], options) : this.Union(narrowed, options));
|
|
1573
|
+
}
|
|
1574
|
+
else {
|
|
1575
|
+
return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? TypeClone.Clone(left, options) : this.Never(options));
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
/** `[Standard]` Creates an Integer type */
|
|
1579
|
+
Integer(options = {}) {
|
|
1580
|
+
return this.Create({ ...options, [exports.Kind]: 'Integer', type: 'integer' });
|
|
1581
|
+
}
|
|
1582
|
+
Intersect(allOf, options = {}) {
|
|
1583
|
+
if (allOf.length === 0)
|
|
1584
|
+
return exports.Type.Never();
|
|
1585
|
+
if (allOf.length === 1)
|
|
1586
|
+
return TypeClone.Clone(allOf[0], options);
|
|
1587
|
+
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
1588
|
+
const cloned = allOf.map((schema) => TypeClone.Clone(schema, {}));
|
|
1589
|
+
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Clone(options.unevaluatedProperties, {}) } : {};
|
|
1590
|
+
if (options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects) {
|
|
1591
|
+
return this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', type: 'object', allOf: cloned });
|
|
1592
|
+
}
|
|
1593
|
+
else {
|
|
1594
|
+
return this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', allOf: cloned });
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
/** `[Standard]` Creates a KeyOf type */
|
|
1598
|
+
KeyOf(schema, options = {}) {
|
|
1599
|
+
const keys = KeyResolver.Resolve(ReferenceRegistry.Deref(schema));
|
|
1600
|
+
// prettier-ignore
|
|
1601
|
+
const keyof = keys.length === 0 ? this.Never(options) : this.Union(keys.map((key) => this.Literal(key)), options);
|
|
1602
|
+
return keyof;
|
|
1603
|
+
}
|
|
1604
|
+
/** `[Standard]` Creates a Literal type */
|
|
1605
|
+
Literal(value, options = {}) {
|
|
1606
|
+
return this.Create({ ...options, [exports.Kind]: 'Literal', const: value, type: typeof value });
|
|
1607
|
+
}
|
|
1608
|
+
/** `[Standard]` Creates a Never type */
|
|
1609
|
+
Never(options = {}) {
|
|
1610
|
+
return this.Create({ ...options, [exports.Kind]: 'Never', not: {} });
|
|
1611
|
+
}
|
|
1612
|
+
/** `[Standard]` Creates a Not type. The first argument is the disallowed type, the second is the allowed. */
|
|
1613
|
+
Not(not, schema, options) {
|
|
1614
|
+
return this.Create({ ...options, [exports.Kind]: 'Not', allOf: [{ not: TypeClone.Clone(not, {}) }, TypeClone.Clone(schema, {})] });
|
|
1615
|
+
}
|
|
1616
|
+
/** `[Standard]` Creates a Null type */
|
|
1617
|
+
Null(options = {}) {
|
|
1618
|
+
return this.Create({ ...options, [exports.Kind]: 'Null', type: 'null' });
|
|
1619
|
+
}
|
|
1620
|
+
/** `[Standard]` Creates a Number type */
|
|
1621
|
+
Number(options = {}) {
|
|
1622
|
+
return this.Create({ ...options, [exports.Kind]: 'Number', type: 'number' });
|
|
1623
|
+
}
|
|
1624
|
+
/** `[Standard]` Creates an Object type */
|
|
1625
|
+
Object(properties, options = {}) {
|
|
1626
|
+
const keys = globalThis.Object.keys(properties);
|
|
1627
|
+
const optional = keys.filter((key) => TypeGuard.TOptional(properties[key]) || TypeGuard.TReadonlyOptional(properties[key]));
|
|
1628
|
+
const required = keys.filter((name) => !optional.includes(name));
|
|
1629
|
+
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties, {}) } : {};
|
|
1630
|
+
const clonedProperties = globalThis.Object.getOwnPropertyNames(properties).reduce((acc, key) => {
|
|
1631
|
+
return { ...acc, [key]: TypeClone.Clone(properties[key], {}) };
|
|
1632
|
+
}, {});
|
|
1633
|
+
if (required.length > 0) {
|
|
1634
|
+
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required });
|
|
1635
|
+
}
|
|
1636
|
+
else {
|
|
1637
|
+
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
Omit(schema, unresolved, options = {}) {
|
|
1641
|
+
const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) : unresolved;
|
|
1642
|
+
// prettier-ignore
|
|
1643
|
+
return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
|
|
1644
|
+
if (schema.required) {
|
|
1645
|
+
schema.required = schema.required.filter((key) => !keys.includes(key));
|
|
1646
|
+
if (schema.required.length === 0)
|
|
1647
|
+
delete schema.required;
|
|
1648
|
+
}
|
|
1649
|
+
for (const key of globalThis.Object.keys(schema.properties)) {
|
|
1650
|
+
if (keys.includes(key))
|
|
1651
|
+
delete schema.properties[key];
|
|
1652
|
+
}
|
|
1653
|
+
return this.Create(schema);
|
|
1654
|
+
}, options);
|
|
1655
|
+
}
|
|
1656
|
+
/** `[Standard]` Creates a mapped type where all properties are Optional */
|
|
1657
|
+
Partial(schema, options = {}) {
|
|
1658
|
+
function Apply(schema) {
|
|
1659
|
+
// prettier-ignore
|
|
1660
|
+
switch (schema[exports.Modifier]) {
|
|
1661
|
+
case 'ReadonlyOptional':
|
|
1662
|
+
schema[exports.Modifier] = 'ReadonlyOptional';
|
|
1663
|
+
break;
|
|
1664
|
+
case 'Readonly':
|
|
1665
|
+
schema[exports.Modifier] = 'ReadonlyOptional';
|
|
1666
|
+
break;
|
|
1667
|
+
case 'Optional':
|
|
1668
|
+
schema[exports.Modifier] = 'Optional';
|
|
1669
|
+
break;
|
|
1670
|
+
default:
|
|
1671
|
+
schema[exports.Modifier] = 'Optional';
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
// prettier-ignore
|
|
1676
|
+
return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
|
|
1677
|
+
delete schema.required;
|
|
1678
|
+
globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
|
|
1679
|
+
return schema;
|
|
1680
|
+
}, options);
|
|
1681
|
+
}
|
|
1682
|
+
Pick(schema, unresolved, options = {}) {
|
|
1683
|
+
const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) : unresolved;
|
|
1684
|
+
// prettier-ignore
|
|
1685
|
+
return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
|
|
1686
|
+
if (schema.required) {
|
|
1687
|
+
schema.required = schema.required.filter((key) => keys.includes(key));
|
|
1688
|
+
if (schema.required.length === 0)
|
|
1689
|
+
delete schema.required;
|
|
1690
|
+
}
|
|
1691
|
+
for (const key of globalThis.Object.keys(schema.properties)) {
|
|
1692
|
+
if (!keys.includes(key))
|
|
1693
|
+
delete schema.properties[key];
|
|
1694
|
+
}
|
|
1695
|
+
return this.Create(schema);
|
|
1696
|
+
}, options);
|
|
1697
|
+
}
|
|
1698
|
+
Record(key, schema, options = {}) {
|
|
1699
|
+
if (TypeGuard.TLiteral(key)) {
|
|
1700
|
+
if (typeof key.const === 'string' || typeof key.const === 'number') {
|
|
1701
|
+
return this.Object({ [key.const]: TypeClone.Clone(schema, {}) }, options);
|
|
1702
|
+
}
|
|
1703
|
+
else
|
|
1704
|
+
throw Error('TypeBuilder: Record key can only be derived from literals of number or string');
|
|
1705
|
+
}
|
|
1706
|
+
if (TypeGuard.TUnion(key)) {
|
|
1707
|
+
if (key.anyOf.every((schema) => TypeGuard.TLiteral(schema) && (typeof schema.const === 'string' || typeof schema.const === 'number'))) {
|
|
1708
|
+
const properties = key.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema, {}) }), {});
|
|
1709
|
+
return this.Object(properties, { ...options, [exports.Hint]: 'Record' });
|
|
1710
|
+
}
|
|
1711
|
+
else
|
|
1712
|
+
throw Error('TypeBuilder: Record key can only be derived from union literal of number or string');
|
|
1713
|
+
}
|
|
1714
|
+
const pattern = ['Integer', 'Number'].includes(key[exports.Kind]) ? '^(0|[1-9][0-9]*)$' : key[exports.Kind] === 'String' && key.pattern ? key.pattern : '^.*$';
|
|
1715
|
+
return this.Create({
|
|
1716
|
+
...options,
|
|
1717
|
+
[exports.Kind]: 'Record',
|
|
1718
|
+
type: 'object',
|
|
1719
|
+
patternProperties: { [pattern]: TypeClone.Clone(schema, {}) },
|
|
1720
|
+
additionalProperties: false,
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
/** `[Standard]` Creates a Recursive type */
|
|
1724
|
+
Recursive(callback, options = {}) {
|
|
1725
|
+
if (options.$id === undefined)
|
|
1726
|
+
options.$id = `T${TypeOrdinal++}`;
|
|
1727
|
+
const self = callback({ [exports.Kind]: 'Self', $ref: `${options.$id}` });
|
|
1728
|
+
const reassign = self;
|
|
1729
|
+
reassign.$id = options.$id; // required as $id is readonly
|
|
1730
|
+
return this.Create({ ...options, ...self, [exports.Recursive]: reassign.$id });
|
|
1731
|
+
}
|
|
1732
|
+
/** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
|
|
1733
|
+
Ref(schema, options = {}) {
|
|
1734
|
+
if (schema.$id === undefined)
|
|
1735
|
+
throw Error('StandardTypeBuilder.Ref: Target type must specify an $id');
|
|
1736
|
+
return this.Create({ ...options, [exports.Kind]: 'Ref', $ref: schema.$id });
|
|
1737
|
+
}
|
|
1738
|
+
/** `[Standard]` Creates a mapped type where all properties are Required */
|
|
1739
|
+
Required(schema, options = {}) {
|
|
1740
|
+
function Apply(schema) {
|
|
1741
|
+
// prettier-ignore
|
|
1742
|
+
switch (schema[exports.Modifier]) {
|
|
1743
|
+
case 'ReadonlyOptional':
|
|
1744
|
+
schema[exports.Modifier] = 'Readonly';
|
|
1745
|
+
break;
|
|
1746
|
+
case 'Readonly':
|
|
1747
|
+
schema[exports.Modifier] = 'Readonly';
|
|
1748
|
+
break;
|
|
1749
|
+
case 'Optional':
|
|
1750
|
+
delete schema[exports.Modifier];
|
|
1751
|
+
break;
|
|
1752
|
+
default:
|
|
1753
|
+
delete schema[exports.Modifier];
|
|
1754
|
+
break;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
// prettier-ignore
|
|
1758
|
+
return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
|
|
1759
|
+
schema.required = globalThis.Object.keys(schema.properties);
|
|
1760
|
+
globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
|
|
1761
|
+
return schema;
|
|
1762
|
+
}, options);
|
|
1763
|
+
}
|
|
1764
|
+
/** `[Standard]` Creates a String type */
|
|
1765
|
+
String(options = {}) {
|
|
1766
|
+
return this.Create({ ...options, [exports.Kind]: 'String', type: 'string' });
|
|
1767
|
+
}
|
|
1768
|
+
/** `[Standard]` Creates a Tuple type */
|
|
1769
|
+
Tuple(items, options = {}) {
|
|
1770
|
+
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
1771
|
+
const clonedItems = items.map((item) => TypeClone.Clone(item, {}));
|
|
1772
|
+
// prettier-ignore
|
|
1773
|
+
const schema = (items.length > 0 ?
|
|
1774
|
+
{ ...options, [exports.Kind]: 'Tuple', type: 'array', items: clonedItems, additionalItems, minItems, maxItems } :
|
|
1775
|
+
{ ...options, [exports.Kind]: 'Tuple', type: 'array', minItems, maxItems });
|
|
1776
|
+
return this.Create(schema);
|
|
1777
|
+
}
|
|
1778
|
+
Union(anyOf, options = {}) {
|
|
1779
|
+
if (anyOf.length === 0)
|
|
1780
|
+
return this.Never(options);
|
|
1781
|
+
if (anyOf.length === 1)
|
|
1782
|
+
return TypeClone.Clone(anyOf[0], options);
|
|
1783
|
+
const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema, {}));
|
|
1784
|
+
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf: clonedAnyOf });
|
|
1785
|
+
}
|
|
1786
|
+
/** `[Standard]` Creates an Unknown type */
|
|
1787
|
+
Unknown(options = {}) {
|
|
1788
|
+
return this.Create({ ...options, [exports.Kind]: 'Unknown' });
|
|
1789
|
+
}
|
|
1790
|
+
/** `[Standard]` Creates a Unsafe type that infers for the generic argument */
|
|
1791
|
+
Unsafe(options = {}) {
|
|
1792
|
+
return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || 'Unsafe' });
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
exports.StandardTypeBuilder = StandardTypeBuilder;
|
|
1796
|
+
// --------------------------------------------------------------------------
|
|
1797
|
+
// TypeBuilder
|
|
1798
|
+
// --------------------------------------------------------------------------
|
|
1799
|
+
class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
1800
|
+
/** `[Extended]` Creates a BigInt type */
|
|
1801
|
+
BigInt(options = {}) {
|
|
1802
|
+
return this.Create({ ...options, [exports.Kind]: 'BigInt', type: 'null', typeOf: 'BigInt' });
|
|
1803
|
+
}
|
|
1804
|
+
/** `[Extended]` Extracts the ConstructorParameters from the given Constructor type */
|
|
1805
|
+
ConstructorParameters(schema, options = {}) {
|
|
1806
|
+
return this.Tuple([...schema.parameters], { ...options });
|
|
1807
|
+
}
|
|
1808
|
+
Constructor(parameters, returns, options = {}) {
|
|
1809
|
+
const clonedReturns = TypeClone.Clone(returns, {});
|
|
1810
|
+
if (TypeGuard.TTuple(parameters)) {
|
|
1811
|
+
const clonedParameters = parameters.items === undefined ? [] : parameters.items.map((parameter) => TypeClone.Clone(parameter, {}));
|
|
1812
|
+
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'object', instanceOf: 'Constructor', parameters: clonedParameters, returns: clonedReturns });
|
|
1813
|
+
}
|
|
1814
|
+
else if (globalThis.Array.isArray(parameters)) {
|
|
1815
|
+
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter, {}));
|
|
1816
|
+
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'object', instanceOf: 'Constructor', parameters: clonedParameters, returns: clonedReturns });
|
|
1817
|
+
}
|
|
1818
|
+
else {
|
|
1819
|
+
throw new Error('ExtendedTypeBuilder.Constructor: Invalid parameters');
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
/** `[Extended]` Creates a Date type */
|
|
1823
|
+
Date(options = {}) {
|
|
1824
|
+
return this.Create({ ...options, [exports.Kind]: 'Date', type: 'object', instanceOf: 'Date' });
|
|
1825
|
+
}
|
|
1826
|
+
Function(parameters, returns, options = {}) {
|
|
1827
|
+
const clonedReturns = TypeClone.Clone(returns, {});
|
|
1828
|
+
if (TypeGuard.TTuple(parameters)) {
|
|
1829
|
+
const clonedParameters = parameters.items === undefined ? [] : parameters.items.map((parameter) => TypeClone.Clone(parameter, {}));
|
|
1830
|
+
return this.Create({ ...options, [exports.Kind]: 'Function', type: 'object', instanceOf: 'Function', parameters: clonedParameters, returns: clonedReturns });
|
|
1831
|
+
}
|
|
1832
|
+
else if (globalThis.Array.isArray(parameters)) {
|
|
1833
|
+
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter, {}));
|
|
1834
|
+
return this.Create({ ...options, [exports.Kind]: 'Function', type: 'object', instanceOf: 'Function', parameters: clonedParameters, returns: clonedReturns });
|
|
1835
|
+
}
|
|
1836
|
+
else {
|
|
1837
|
+
throw new Error('ExtendedTypeBuilder.Function: Invalid parameters');
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
/** `[Extended]` Extracts the InstanceType from the given Constructor */
|
|
1841
|
+
InstanceType(schema, options = {}) {
|
|
1842
|
+
return TypeClone.Clone(schema.returns, options);
|
|
1843
|
+
}
|
|
1844
|
+
/** `[Extended]` Extracts the Parameters from the given Function type */
|
|
1845
|
+
Parameters(schema, options = {}) {
|
|
1846
|
+
return this.Tuple(schema.parameters, { ...options });
|
|
1847
|
+
}
|
|
1848
|
+
/** `[Extended]` Creates a Promise type */
|
|
1849
|
+
Promise(item, options = {}) {
|
|
1850
|
+
return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'object', instanceOf: 'Promise', item: TypeClone.Clone(item, {}) });
|
|
1851
|
+
}
|
|
1852
|
+
/** `[Extended]` Creates a regular expression type */
|
|
1853
|
+
RegEx(regex, options = {}) {
|
|
1854
|
+
return this.Create({ ...options, [exports.Kind]: 'String', type: 'string', pattern: regex.source });
|
|
1855
|
+
}
|
|
1856
|
+
/** `[Extended]` Extracts the ReturnType from the given Function */
|
|
1857
|
+
ReturnType(schema, options = {}) {
|
|
1858
|
+
return TypeClone.Clone(schema.returns, options);
|
|
1859
|
+
}
|
|
1860
|
+
/** `[Extended]` Creates a Symbol type */
|
|
1861
|
+
Symbol(options) {
|
|
1862
|
+
return this.Create({ ...options, [exports.Kind]: 'Symbol', type: 'null', typeOf: 'Symbol' });
|
|
1863
|
+
}
|
|
1864
|
+
/** `[Extended]` Creates a Undefined type */
|
|
1865
|
+
Undefined(options = {}) {
|
|
1866
|
+
return this.Create({ ...options, [exports.Kind]: 'Undefined', type: 'null', typeOf: 'Undefined' });
|
|
1867
|
+
}
|
|
1868
|
+
/** `[Extended]` Creates a Uint8Array type */
|
|
1869
|
+
Uint8Array(options = {}) {
|
|
1870
|
+
return this.Create({ ...options, [exports.Kind]: 'Uint8Array', type: 'object', instanceOf: 'Uint8Array' });
|
|
1871
|
+
}
|
|
1872
|
+
/** `[Extended]` Creates a Void type */
|
|
1873
|
+
Void(options = {}) {
|
|
1874
|
+
return this.Create({ ...options, [exports.Kind]: 'Void', type: 'null', typeOf: 'Void' });
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
exports.ExtendedTypeBuilder = ExtendedTypeBuilder;
|
|
1878
|
+
/** JSON Schema TypeBuilder with Static Resolution for TypeScript */
|
|
1879
|
+
exports.StandardType = new StandardTypeBuilder();
|
|
1880
|
+
/** JSON Schema TypeBuilder with Static Resolution for TypeScript */
|
|
1881
|
+
exports.Type = new ExtendedTypeBuilder();
|