@sinclair/typebox 0.29.6 → 0.30.0-dev-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.d.ts +7 -4
- package/compiler/compiler.js +208 -194
- package/errors/errors.d.ts +65 -60
- package/errors/errors.js +515 -492
- package/package.json +14 -2
- package/readme.md +161 -169
- package/system/system.js +0 -6
- package/typebox.d.ts +99 -52
- package/typebox.js +496 -573
- package/value/cast.d.ts +4 -4
- package/value/cast.js +254 -260
- package/value/check.d.ts +4 -3
- package/value/check.js +412 -397
- package/value/clone.d.ts +2 -3
- package/value/clone.js +62 -42
- package/value/convert.d.ts +4 -4
- package/value/convert.js +304 -318
- package/value/create.d.ts +4 -6
- package/value/create.js +386 -376
- package/value/delta.d.ts +2 -4
- package/value/delta.js +121 -130
- package/value/equal.d.ts +2 -3
- package/value/equal.js +48 -51
- package/value/guard.d.ts +44 -0
- package/value/guard.js +146 -0
- package/value/hash.d.ts +14 -3
- package/value/hash.js +124 -166
- package/value/index.d.ts +3 -4
- package/value/index.js +6 -20
- package/value/mutate.d.ts +2 -4
- package/value/mutate.js +75 -67
- package/value/pointer.js +8 -2
- package/value/value.d.ts +20 -20
- package/value/value.js +27 -27
- package/value/is.d.ts +0 -11
- package/value/is.js +0 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0-dev-2",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -16,6 +16,17 @@
|
|
|
16
16
|
"./compiler": "./compiler/index.js",
|
|
17
17
|
"./errors": "./errors/index.js",
|
|
18
18
|
"./system": "./system/index.js",
|
|
19
|
+
"./value/cast": "./value/cast.js",
|
|
20
|
+
"./value/check": "./value/check.js",
|
|
21
|
+
"./value/clone": "./value/clone.js",
|
|
22
|
+
"./value/convert": "./value/convert.js",
|
|
23
|
+
"./value/create": "./value/create.js",
|
|
24
|
+
"./value/delta": "./value/delta.js",
|
|
25
|
+
"./value/equal": "./value/equal.js",
|
|
26
|
+
"./value/guard": "./value/guard.js",
|
|
27
|
+
"./value/hash": "./value/hash.js",
|
|
28
|
+
"./value/mutate": "./value/mutate.js",
|
|
29
|
+
"./value/pointer": "./value/pointer.js",
|
|
19
30
|
"./value": "./value/index.js",
|
|
20
31
|
".": "./typebox.js"
|
|
21
32
|
},
|
|
@@ -33,7 +44,8 @@
|
|
|
33
44
|
"start": "hammer task start",
|
|
34
45
|
"benchmark": "hammer task benchmark",
|
|
35
46
|
"build": "hammer task build",
|
|
36
|
-
"publish": "hammer task publish"
|
|
47
|
+
"publish": "hammer task publish",
|
|
48
|
+
"publish:dev": "hammer task publish_dev"
|
|
37
49
|
},
|
|
38
50
|
"devDependencies": {
|
|
39
51
|
"@sinclair/hammer": "^0.17.1",
|
package/readme.md
CHANGED
|
@@ -76,15 +76,15 @@ License MIT
|
|
|
76
76
|
- [Types](#types)
|
|
77
77
|
- [Standard](#types-standard)
|
|
78
78
|
- [Extended](#types-extended)
|
|
79
|
-
- [Modifiers](#types-modifiers)
|
|
80
79
|
- [Options](#types-options)
|
|
80
|
+
- [Properties](#types-properties)
|
|
81
81
|
- [Generics](#types-generics)
|
|
82
82
|
- [References](#types-references)
|
|
83
83
|
- [Recursive](#types-recursive)
|
|
84
84
|
- [Conditional](#types-conditional)
|
|
85
85
|
- [Template Literal](#types-template-literal)
|
|
86
86
|
- [Indexed](#types-indexed)
|
|
87
|
-
- [
|
|
87
|
+
- [Negated](#types-negated)
|
|
88
88
|
- [Rest](#types-rest)
|
|
89
89
|
- [Guards](#types-guards)
|
|
90
90
|
- [Unsafe](#types-unsafe)
|
|
@@ -102,6 +102,7 @@ License MIT
|
|
|
102
102
|
- [Errors](#values-errors)
|
|
103
103
|
- [Mutate](#values-mutate)
|
|
104
104
|
- [Pointer](#values-pointer)
|
|
105
|
+
- [Transform](#values-transform)
|
|
105
106
|
- [TypeCheck](#typecheck)
|
|
106
107
|
- [Ajv](#typecheck-ajv)
|
|
107
108
|
- [TypeCompiler](#typecheck-typecompiler)
|
|
@@ -336,10 +337,10 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
336
337
|
│ │ │ │
|
|
337
338
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
338
339
|
│ const T = Type.Composite([ │ type T = { │ const T = { │
|
|
339
|
-
│ Type.Object({ │ x: number
|
|
340
|
-
│ x: Type.Number() │
|
|
341
|
-
│ }), │
|
|
342
|
-
│ Type.Object({ │
|
|
340
|
+
│ Type.Object({ │ x: number, │ type: 'object', │
|
|
341
|
+
│ x: Type.Number() │ y: number │ required: ['x', 'y'], │
|
|
342
|
+
│ }), │ } │ properties: { │
|
|
343
|
+
│ Type.Object({ │ │ x: { │
|
|
343
344
|
│ y: Type.Number() │ │ type: 'number' │
|
|
344
345
|
│ }) │ │ }, │
|
|
345
346
|
│ ]) │ │ y: { │
|
|
@@ -386,6 +387,12 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
386
387
|
│ ) │ │ │
|
|
387
388
|
│ │ │ │
|
|
388
389
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
390
|
+
│ const T = Type.Pattern('^xy$') │ type T = string │ const T = { │
|
|
391
|
+
│ │ │ type: 'string', │
|
|
392
|
+
│ │ │ pattern: '^xy$' │
|
|
393
|
+
│ │ │ } │
|
|
394
|
+
│ │ │ │
|
|
395
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
389
396
|
│ const U = Type.Union([ │ type U = 'open' | 'close' │ const T = { │
|
|
390
397
|
│ Type.Literal('open'), │ │ type: 'string', │
|
|
391
398
|
│ Type.Literal('close') │ type T = `on${U}` │ pattern: '^on(open|close)$' │
|
|
@@ -504,10 +511,9 @@ TypeBox provides several extended types that can be used to produce schematics f
|
|
|
504
511
|
│ │ │ │
|
|
505
512
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
506
513
|
│ const T = Type.Constructor([ │ type T = new ( │ const T = { │
|
|
507
|
-
│ Type.String(), │ arg0: string, │ type: '
|
|
508
|
-
│ Type.Number() │
|
|
509
|
-
│ ], Type.Boolean()) │ ) => boolean │
|
|
510
|
-
│ │ │ type: 'string' │
|
|
514
|
+
│ Type.String(), │ arg0: string, │ type: 'constructor', │
|
|
515
|
+
│ Type.Number() │ arg0: number │ parameters: [{ │
|
|
516
|
+
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
511
517
|
│ │ │ }, { │
|
|
512
518
|
│ │ │ type: 'number' │
|
|
513
519
|
│ │ │ }], │
|
|
@@ -518,10 +524,9 @@ TypeBox provides several extended types that can be used to produce schematics f
|
|
|
518
524
|
│ │ │ │
|
|
519
525
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
520
526
|
│ const T = Type.Function([ │ type T = ( │ const T = { │
|
|
521
|
-
| Type.String(), │ arg0: string, │ type
|
|
522
|
-
│ Type.Number() │ arg1: number │
|
|
523
|
-
│ ], Type.Boolean()) │ ) => boolean │
|
|
524
|
-
│ │ │ type: 'string' │
|
|
527
|
+
| Type.String(), │ arg0: string, │ type: 'function', │
|
|
528
|
+
│ Type.Number() │ arg1: number │ parameters: [{ │
|
|
529
|
+
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
525
530
|
│ │ │ }, { │
|
|
526
531
|
│ │ │ type: 'number' │
|
|
527
532
|
│ │ │ }], │
|
|
@@ -532,64 +537,95 @@ TypeBox provides several extended types that can be used to produce schematics f
|
|
|
532
537
|
│ │ │ │
|
|
533
538
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
534
539
|
│ const T = Type.Promise( │ type T = Promise<string> │ const T = { │
|
|
535
|
-
│ Type.String() │ │ type: '
|
|
536
|
-
│ ) │ │
|
|
537
|
-
│ │ │ item: { │
|
|
540
|
+
│ Type.String() │ │ type: 'Promise', │
|
|
541
|
+
│ ) │ │ item: { │
|
|
538
542
|
│ │ │ type: 'string' │
|
|
539
543
|
│ │ │ } │
|
|
540
544
|
│ │ │ } │
|
|
541
545
|
│ │ │ │
|
|
546
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
547
|
+
│ const T = Type.Iterator( │ type T = │ const T = { │
|
|
548
|
+
│ Type.String() │ IterableIterator<string> │ type: 'Iterator', │
|
|
549
|
+
│ ) │ │ items: { │
|
|
550
|
+
│ │ │ type: 'string' │
|
|
551
|
+
│ │ │ } │
|
|
552
|
+
│ │ │ } │
|
|
542
553
|
│ │ │ │
|
|
543
554
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
544
|
-
│ const T =
|
|
545
|
-
│
|
|
546
|
-
│
|
|
555
|
+
│ const T = │ type T = │ const T = { │
|
|
556
|
+
│ Type.AsyncIterator( │ AsyncIterableIterator< │ type: 'AsyncIterator', │
|
|
557
|
+
│ Type.String() │ string │ items: { │
|
|
558
|
+
│ ) │ > │ type: 'string' │
|
|
559
|
+
│ │ │ } │
|
|
547
560
|
│ │ │ } │
|
|
548
561
|
│ │ │ │
|
|
549
562
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
550
|
-
│ const T = Type.
|
|
551
|
-
│ │ │ type: '
|
|
552
|
-
│ │ │ instanceOf: 'Date' │
|
|
563
|
+
│ const T = Type.Uint8Array() │ type T = Uint8Array │ const T = { │
|
|
564
|
+
│ │ │ type: 'Uint8Array' │
|
|
553
565
|
│ │ │ } │
|
|
554
566
|
│ │ │ │
|
|
555
567
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
556
|
-
│ const T = Type.
|
|
557
|
-
│ │ │ type: '
|
|
558
|
-
│ │ │ typeOf: 'Undefined' │
|
|
568
|
+
│ const T = Type.Date() │ type T = Date │ const T = { │
|
|
569
|
+
│ │ │ type: 'Date' │
|
|
559
570
|
│ │ │ } │
|
|
560
571
|
│ │ │ │
|
|
561
572
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
562
|
-
│ const T = Type.
|
|
563
|
-
│ │ │
|
|
564
|
-
│ │ │ pattern: 'foo' │
|
|
573
|
+
│ const T = Type.Undefined() │ type T = undefined │ const T = { │
|
|
574
|
+
│ │ │ type: 'undefined' │
|
|
565
575
|
│ │ │ } │
|
|
566
576
|
│ │ │ │
|
|
567
577
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
568
578
|
│ const T = Type.Symbol() │ type T = symbol │ const T = { │
|
|
569
|
-
│ │ │ type: '
|
|
570
|
-
│ │ │ typeOf: 'Symbol' │
|
|
579
|
+
│ │ │ type: 'symbol' │
|
|
571
580
|
│ │ │ } │
|
|
572
581
|
│ │ │ │
|
|
573
582
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
574
583
|
│ const T = Type.BigInt() │ type T = bigint │ const T = { │
|
|
575
|
-
│ │ │ type: '
|
|
576
|
-
│ │ │ typeOf: 'BigInt' │
|
|
584
|
+
│ │ │ type: 'bigint' │
|
|
577
585
|
│ │ │ } │
|
|
578
586
|
│ │ │ │
|
|
579
587
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
580
588
|
│ const T = Type.Void() │ type T = void │ const T = { │
|
|
581
|
-
│ │ │ type: '
|
|
582
|
-
│ │ │ typeOf: 'Void' │
|
|
589
|
+
│ │ │ type: 'void' │
|
|
583
590
|
│ │ │ } │
|
|
584
591
|
│ │ │ │
|
|
585
592
|
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
586
593
|
```
|
|
587
594
|
|
|
588
|
-
<a name='types-
|
|
595
|
+
<a name='types-options'></a>
|
|
596
|
+
|
|
597
|
+
### Options
|
|
598
|
+
|
|
599
|
+
You can pass JSON Schema options on the last argument of any type. Option hints specific to each type are provided for convenience.
|
|
600
|
+
|
|
601
|
+
```typescript
|
|
602
|
+
// String must be an email
|
|
603
|
+
const T = Type.String({ // const T = {
|
|
604
|
+
format: 'email' // type: 'string',
|
|
605
|
+
}) // format: 'email'
|
|
606
|
+
// }
|
|
607
|
+
|
|
608
|
+
// Number must be a multiple of 2
|
|
609
|
+
const T = Type.Number({ // const T = {
|
|
610
|
+
multipleOf: 2 // type: 'number',
|
|
611
|
+
}) // multipleOf: 2
|
|
612
|
+
// }
|
|
613
|
+
|
|
614
|
+
// Array must have at least 5 integer values
|
|
615
|
+
const T = Type.Array(Type.Integer(), { // const T = {
|
|
616
|
+
minItems: 5 // type: 'array',
|
|
617
|
+
}) // minItems: 5,
|
|
618
|
+
// items: {
|
|
619
|
+
// type: 'integer'
|
|
620
|
+
// }
|
|
621
|
+
// }
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
<a name='types-properties'></a>
|
|
589
625
|
|
|
590
|
-
###
|
|
626
|
+
### Properties
|
|
591
627
|
|
|
592
|
-
|
|
628
|
+
Object properties can be modified with `readonly` or `optional`. The following table shows how these modifiers map between TypeScript and JSON Schema.
|
|
593
629
|
|
|
594
630
|
```typescript
|
|
595
631
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -597,7 +633,7 @@ TypeBox provides modifiers that allow schema properties to be statically inferre
|
|
|
597
633
|
│ │ │ │
|
|
598
634
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
599
635
|
│ const T = Type.Object({ │ type T = { │ const T = { │
|
|
600
|
-
│ name: Type.
|
|
636
|
+
│ name: Type.ReadonlyOptional( │ readonly name?: string │ type: 'object', │
|
|
601
637
|
│ Type.String() │ } │ properties: { │
|
|
602
638
|
│ ) │ │ name: { │
|
|
603
639
|
│ }) │ │ type: 'string' │
|
|
@@ -618,7 +654,7 @@ TypeBox provides modifiers that allow schema properties to be statically inferre
|
|
|
618
654
|
│ │ │ │
|
|
619
655
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
620
656
|
│ const T = Type.Object({ │ type T = { │ const T = { │
|
|
621
|
-
│ name: Type.
|
|
657
|
+
│ name: Type.Optional( │ name?: string │ type: 'object', │
|
|
622
658
|
│ Type.String() │ } │ properties: { │
|
|
623
659
|
│ ) │ │ name: { │
|
|
624
660
|
│ }) │ │ type: 'string' │
|
|
@@ -628,37 +664,6 @@ TypeBox provides modifiers that allow schema properties to be statically inferre
|
|
|
628
664
|
│ │ │ │
|
|
629
665
|
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
630
666
|
```
|
|
631
|
-
|
|
632
|
-
<a name='types-options'></a>
|
|
633
|
-
|
|
634
|
-
### Options
|
|
635
|
-
|
|
636
|
-
You can pass JSON Schema options on the last argument of any type. Option hints specific to each type are provided for convenience.
|
|
637
|
-
|
|
638
|
-
```typescript
|
|
639
|
-
// String must be an email
|
|
640
|
-
const T = Type.String({ // const T = {
|
|
641
|
-
format: 'email' // type: 'string',
|
|
642
|
-
}) // format: 'email'
|
|
643
|
-
// }
|
|
644
|
-
|
|
645
|
-
// Number must be a multiple of 2
|
|
646
|
-
const T = Type.Number({ // const T = {
|
|
647
|
-
multipleOf: 2 // type: 'number',
|
|
648
|
-
}) // multipleOf: 2
|
|
649
|
-
// }
|
|
650
|
-
|
|
651
|
-
// Array must have at least 5 integer values
|
|
652
|
-
const T = Type.Array(Type.Integer(), { // const T = {
|
|
653
|
-
minItems: 5 // type: 'array',
|
|
654
|
-
}) // minItems: 5,
|
|
655
|
-
// items: {
|
|
656
|
-
// type: 'integer'
|
|
657
|
-
// }
|
|
658
|
-
// }
|
|
659
|
-
|
|
660
|
-
```
|
|
661
|
-
|
|
662
667
|
<a name='types-generics'></a>
|
|
663
668
|
|
|
664
669
|
### Generic Types
|
|
@@ -685,22 +690,6 @@ type NumberVector = Static<typeof NumberVector> // type NumberVector = {
|
|
|
685
690
|
// y: number,
|
|
686
691
|
// z: number
|
|
687
692
|
// }
|
|
688
|
-
|
|
689
|
-
const BooleanVector = Vector(Type.Boolean()) // const BooleanVector = {
|
|
690
|
-
// type: 'object',
|
|
691
|
-
// required: ['x', 'y', 'z'],
|
|
692
|
-
// properties: {
|
|
693
|
-
// x: { type: 'boolean' },
|
|
694
|
-
// y: { type: 'boolean' },
|
|
695
|
-
// z: { type: 'boolean' }
|
|
696
|
-
// }
|
|
697
|
-
// }
|
|
698
|
-
|
|
699
|
-
type BooleanVector = Static<typeof BooleanVector> // type BooleanVector = {
|
|
700
|
-
// x: boolean,
|
|
701
|
-
// y: boolean,
|
|
702
|
-
// z: boolean
|
|
703
|
-
// }
|
|
704
693
|
```
|
|
705
694
|
|
|
706
695
|
The following creates a generic `Nullable<T>` type.
|
|
@@ -896,20 +885,27 @@ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
|
|
|
896
885
|
// }
|
|
897
886
|
```
|
|
898
887
|
|
|
899
|
-
<a name='types-
|
|
888
|
+
<a name='types-negated'></a>
|
|
889
|
+
|
|
890
|
+
### Negated Types
|
|
900
891
|
|
|
901
|
-
|
|
892
|
+
TypeBox has support for type negation with `Type.Not`. This type will always infer as `unknown`.
|
|
902
893
|
|
|
903
|
-
|
|
894
|
+
```typescript
|
|
895
|
+
const T = Type.Not(Type.String()) // const T = {
|
|
896
|
+
// not: { type: 'string' }
|
|
897
|
+
// }
|
|
898
|
+
|
|
899
|
+
type T = Static<typeof T> // type T = unknown
|
|
900
|
+
//
|
|
901
|
+
// where T could be any type other than string
|
|
902
|
+
```
|
|
903
|
+
This type can be useful for certain forms of type narrowing. For example, consider a type that represents a `number` but not the values `1, 2, 3`. The example below shows an imaginary TypeScript syntax to express such a type followed by the TypeBox representation.
|
|
904
904
|
|
|
905
905
|
```typescript
|
|
906
906
|
// TypeScript
|
|
907
907
|
|
|
908
|
-
type T =
|
|
909
|
-
//
|
|
910
|
-
// ideally expressed as:
|
|
911
|
-
//
|
|
912
|
-
// type T = number & not (1 | 2 | 3)
|
|
908
|
+
type T = number & not (1 | 2 | 3) // not actual syntax
|
|
913
909
|
|
|
914
910
|
// TypeBox
|
|
915
911
|
|
|
@@ -928,14 +924,10 @@ const T = Type.Intersect([ // const T = {
|
|
|
928
924
|
// ]
|
|
929
925
|
// }
|
|
930
926
|
|
|
931
|
-
type T = Static<typeof T> //
|
|
932
|
-
//
|
|
933
|
-
// type T = number & not (1 | 2 | 3)
|
|
934
|
-
// type T = number & unknown
|
|
935
|
-
// type T = number
|
|
927
|
+
type T = Static<typeof T> // type T = number
|
|
936
928
|
```
|
|
937
929
|
|
|
938
|
-
|
|
930
|
+
This type can be used with constraints to create schematics that would otherwise be difficult to express.
|
|
939
931
|
```typescript
|
|
940
932
|
const Even = Type.Number({ multipleOf: 2 })
|
|
941
933
|
|
|
@@ -1045,7 +1037,7 @@ if(TypeGuard.TString(T)) {
|
|
|
1045
1037
|
|
|
1046
1038
|
### Strict
|
|
1047
1039
|
|
|
1048
|
-
TypeBox
|
|
1040
|
+
TypeBox types contain various symbol properties that are used for reflection, composition and compilation. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict` function that will omit these properties if necessary.
|
|
1049
1041
|
|
|
1050
1042
|
```typescript
|
|
1051
1043
|
const T = Type.Object({ // const T = {
|
|
@@ -1053,9 +1045,9 @@ const T = Type.Object({ // const T = {
|
|
|
1053
1045
|
}) // type: 'object',
|
|
1054
1046
|
// properties: {
|
|
1055
1047
|
// name: {
|
|
1056
|
-
// [Kind]: 'String',
|
|
1057
1048
|
// type: 'string',
|
|
1058
|
-
// [
|
|
1049
|
+
// [Kind]: 'String',
|
|
1050
|
+
// [Optional]: 'Optional'
|
|
1059
1051
|
// }
|
|
1060
1052
|
// }
|
|
1061
1053
|
// }
|
|
@@ -1508,35 +1500,35 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1508
1500
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1509
1501
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1510
1502
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1511
|
-
│ Literal_String │ 1000 │ '
|
|
1512
|
-
│ Literal_Number │ 1000 │ '
|
|
1513
|
-
│ Literal_Boolean │ 1000 │ '
|
|
1514
|
-
│ Primitive_Number │ 1000 │ '
|
|
1515
|
-
│ Primitive_String │ 1000 │ '
|
|
1516
|
-
│ Primitive_String_Pattern │ 1000 │ '
|
|
1517
|
-
│ Primitive_Boolean │ 1000 │ '
|
|
1518
|
-
│ Primitive_Null │ 1000 │ '
|
|
1519
|
-
│ Object_Unconstrained │ 1000 │ '
|
|
1520
|
-
│ Object_Constrained │ 1000 │ '
|
|
1521
|
-
│ Object_Vector3 │ 1000 │ '
|
|
1522
|
-
│ Object_Box3D │ 1000 │ '
|
|
1523
|
-
│ Tuple_Primitive │ 1000 │ '
|
|
1524
|
-
│ Tuple_Object │ 1000 │ '
|
|
1525
|
-
│ Composite_Intersect │ 1000 │ '
|
|
1526
|
-
│ Composite_Union │ 1000 │ '
|
|
1527
|
-
│ Math_Vector4 │ 1000 │ '
|
|
1528
|
-
│ Math_Matrix4 │ 1000 │ '
|
|
1529
|
-
│ Array_Primitive_Number │ 1000 │ '
|
|
1530
|
-
│ Array_Primitive_String │ 1000 │ '
|
|
1531
|
-
│ Array_Primitive_Boolean │ 1000 │ '
|
|
1532
|
-
│ Array_Object_Unconstrained │ 1000 │ '
|
|
1533
|
-
│ Array_Object_Constrained │ 1000 │ '
|
|
1534
|
-
│ Array_Tuple_Primitive │ 1000 │ '
|
|
1535
|
-
│ Array_Tuple_Object │ 1000 │ '
|
|
1536
|
-
│ Array_Composite_Intersect │ 1000 │ '
|
|
1537
|
-
│ Array_Composite_Union │ 1000 │ '
|
|
1538
|
-
│ Array_Math_Vector4 │ 1000 │ '
|
|
1539
|
-
│ Array_Math_Matrix4 │ 1000 │ '
|
|
1503
|
+
│ Literal_String │ 1000 │ ' 232 ms' │ ' 8 ms' │ ' 29.00 x' │
|
|
1504
|
+
│ Literal_Number │ 1000 │ ' 179 ms' │ ' 6 ms' │ ' 29.83 x' │
|
|
1505
|
+
│ Literal_Boolean │ 1000 │ ' 154 ms' │ ' 3 ms' │ ' 51.33 x' │
|
|
1506
|
+
│ Primitive_Number │ 1000 │ ' 160 ms' │ ' 7 ms' │ ' 22.86 x' │
|
|
1507
|
+
│ Primitive_String │ 1000 │ ' 149 ms' │ ' 6 ms' │ ' 24.83 x' │
|
|
1508
|
+
│ Primitive_String_Pattern │ 1000 │ ' 191 ms' │ ' 9 ms' │ ' 21.22 x' │
|
|
1509
|
+
│ Primitive_Boolean │ 1000 │ ' 135 ms' │ ' 4 ms' │ ' 33.75 x' │
|
|
1510
|
+
│ Primitive_Null │ 1000 │ ' 144 ms' │ ' 6 ms' │ ' 24.00 x' │
|
|
1511
|
+
│ Object_Unconstrained │ 1000 │ ' 1144 ms' │ ' 30 ms' │ ' 38.13 x' │
|
|
1512
|
+
│ Object_Constrained │ 1000 │ ' 1228 ms' │ ' 24 ms' │ ' 51.17 x' │
|
|
1513
|
+
│ Object_Vector3 │ 1000 │ ' 380 ms' │ ' 9 ms' │ ' 42.22 x' │
|
|
1514
|
+
│ Object_Box3D │ 1000 │ ' 1771 ms' │ ' 30 ms' │ ' 59.03 x' │
|
|
1515
|
+
│ Tuple_Primitive │ 1000 │ ' 471 ms' │ ' 11 ms' │ ' 42.82 x' │
|
|
1516
|
+
│ Tuple_Object │ 1000 │ ' 1272 ms' │ ' 15 ms' │ ' 84.80 x' │
|
|
1517
|
+
│ Composite_Intersect │ 1000 │ ' 606 ms' │ ' 17 ms' │ ' 35.65 x' │
|
|
1518
|
+
│ Composite_Union │ 1000 │ ' 560 ms' │ ' 22 ms' │ ' 25.45 x' │
|
|
1519
|
+
│ Math_Vector4 │ 1000 │ ' 824 ms' │ ' 14 ms' │ ' 58.86 x' │
|
|
1520
|
+
│ Math_Matrix4 │ 1000 │ ' 419 ms' │ ' 9 ms' │ ' 46.56 x' │
|
|
1521
|
+
│ Array_Primitive_Number │ 1000 │ ' 382 ms' │ ' 6 ms' │ ' 63.67 x' │
|
|
1522
|
+
│ Array_Primitive_String │ 1000 │ ' 324 ms' │ ' 6 ms' │ ' 54.00 x' │
|
|
1523
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 301 ms' │ ' 4 ms' │ ' 75.25 x' │
|
|
1524
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1734 ms' │ ' 21 ms' │ ' 82.57 x' │
|
|
1525
|
+
│ Array_Object_Constrained │ 1000 │ ' 1509 ms' │ ' 20 ms' │ ' 75.45 x' │
|
|
1526
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 824 ms' │ ' 14 ms' │ ' 58.86 x' │
|
|
1527
|
+
│ Array_Tuple_Object │ 1000 │ ' 1619 ms' │ ' 16 ms' │ ' 101.19 x' │
|
|
1528
|
+
│ Array_Composite_Intersect │ 1000 │ ' 773 ms' │ ' 16 ms' │ ' 48.31 x' │
|
|
1529
|
+
│ Array_Composite_Union │ 1000 │ ' 822 ms' │ ' 17 ms' │ ' 48.35 x' │
|
|
1530
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1131 ms' │ ' 13 ms' │ ' 87.00 x' │
|
|
1531
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 661 ms' │ ' 10 ms' │ ' 66.10 x' │
|
|
1540
1532
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1541
1533
|
```
|
|
1542
1534
|
|
|
@@ -1550,37 +1542,37 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1550
1542
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1551
1543
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1552
1544
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1553
|
-
│ Literal_String │ 1000000 │ '
|
|
1554
|
-
│ Literal_Number │ 1000000 │ '
|
|
1555
|
-
│ Literal_Boolean │ 1000000 │ '
|
|
1556
|
-
│ Primitive_Number │ 1000000 │ '
|
|
1557
|
-
│ Primitive_String │ 1000000 │ '
|
|
1558
|
-
│ Primitive_String_Pattern │ 1000000 │ '
|
|
1559
|
-
│ Primitive_Boolean │ 1000000 │ '
|
|
1560
|
-
│ Primitive_Null │ 1000000 │ '
|
|
1561
|
-
│ Object_Unconstrained │ 1000000 │ '
|
|
1562
|
-
│ Object_Constrained │ 1000000 │ '
|
|
1563
|
-
│ Object_Vector3 │ 1000000 │ '
|
|
1564
|
-
│ Object_Box3D │ 1000000 │ '
|
|
1565
|
-
│ Object_Recursive │ 1000000 │ '
|
|
1566
|
-
│ Tuple_Primitive │ 1000000 │ '
|
|
1567
|
-
│ Tuple_Object │ 1000000 │ '
|
|
1568
|
-
│ Composite_Intersect │ 1000000 │ '
|
|
1569
|
-
│ Composite_Union │ 1000000 │ '
|
|
1570
|
-
│ Math_Vector4 │ 1000000 │ '
|
|
1571
|
-
│ Math_Matrix4 │ 1000000 │ '
|
|
1572
|
-
│ Array_Primitive_Number │ 1000000 │ '
|
|
1573
|
-
│ Array_Primitive_String │ 1000000 │ '
|
|
1574
|
-
│ Array_Primitive_Boolean │ 1000000 │ '
|
|
1575
|
-
│ Array_Object_Unconstrained │ 1000000 │ '
|
|
1576
|
-
│ Array_Object_Constrained │ 1000000 │ '
|
|
1577
|
-
│ Array_Object_Recursive │ 1000000 │ '
|
|
1578
|
-
│ Array_Tuple_Primitive │ 1000000 │ '
|
|
1579
|
-
│ Array_Tuple_Object │ 1000000 │ '
|
|
1580
|
-
│ Array_Composite_Intersect │ 1000000 │ '
|
|
1581
|
-
│ Array_Composite_Union │ 1000000 │ '
|
|
1582
|
-
│ Array_Math_Vector4 │ 1000000 │ '
|
|
1583
|
-
│ Array_Math_Matrix4 │ 1000000 │ '
|
|
1545
|
+
│ Literal_String │ 1000000 │ ' 18 ms' │ ' 5 ms' │ ' 4 ms' │ ' 1.25 x' │
|
|
1546
|
+
│ Literal_Number │ 1000000 │ ' 15 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1547
|
+
│ Literal_Boolean │ 1000000 │ ' 13 ms' │ ' 16 ms' │ ' 9 ms' │ ' 1.78 x' │
|
|
1548
|
+
│ Primitive_Number │ 1000000 │ ' 21 ms' │ ' 16 ms' │ ' 9 ms' │ ' 1.78 x' │
|
|
1549
|
+
│ Primitive_String │ 1000000 │ ' 19 ms' │ ' 16 ms' │ ' 10 ms' │ ' 1.60 x' │
|
|
1550
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 150 ms' │ ' 41 ms' │ ' 35 ms' │ ' 1.17 x' │
|
|
1551
|
+
│ Primitive_Boolean │ 1000000 │ ' 17 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
|
|
1552
|
+
│ Primitive_Null │ 1000000 │ ' 18 ms' │ ' 16 ms' │ ' 9 ms' │ ' 1.78 x' │
|
|
1553
|
+
│ Object_Unconstrained │ 1000000 │ ' 1001 ms' │ ' 31 ms' │ ' 24 ms' │ ' 1.29 x' │
|
|
1554
|
+
│ Object_Constrained │ 1000000 │ ' 1288 ms' │ ' 50 ms' │ ' 36 ms' │ ' 1.39 x' │
|
|
1555
|
+
│ Object_Vector3 │ 1000000 │ ' 439 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
|
|
1556
|
+
│ Object_Box3D │ 1000000 │ ' 2109 ms' │ ' 52 ms' │ ' 45 ms' │ ' 1.16 x' │
|
|
1557
|
+
│ Object_Recursive │ 1000000 │ ' 5337 ms' │ ' 356 ms' │ ' 162 ms' │ ' 2.20 x' │
|
|
1558
|
+
│ Tuple_Primitive │ 1000000 │ ' 164 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
|
|
1559
|
+
│ Tuple_Object │ 1000000 │ ' 744 ms' │ ' 29 ms' │ ' 18 ms' │ ' 1.61 x' │
|
|
1560
|
+
│ Composite_Intersect │ 1000000 │ ' 764 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
|
|
1561
|
+
│ Composite_Union │ 1000000 │ ' 516 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
|
|
1562
|
+
│ Math_Vector4 │ 1000000 │ ' 262 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
|
|
1563
|
+
│ Math_Matrix4 │ 1000000 │ ' 1089 ms' │ ' 37 ms' │ ' 27 ms' │ ' 1.37 x' │
|
|
1564
|
+
│ Array_Primitive_Number │ 1000000 │ ' 276 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
|
|
1565
|
+
│ Array_Primitive_String │ 1000000 │ ' 228 ms' │ ' 21 ms' │ ' 14 ms' │ ' 1.50 x' │
|
|
1566
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 159 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
|
|
1567
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 5695 ms' │ ' 77 ms' │ ' 69 ms' │ ' 1.12 x' │
|
|
1568
|
+
│ Array_Object_Constrained │ 1000000 │ ' 5701 ms' │ ' 127 ms' │ ' 110 ms' │ ' 1.15 x' │
|
|
1569
|
+
│ Array_Object_Recursive │ 1000000 │ ' 21267 ms' │ ' 1664 ms' │ ' 573 ms' │ ' 2.90 x' │
|
|
1570
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 702 ms' │ ' 40 ms' │ ' 32 ms' │ ' 1.25 x' │
|
|
1571
|
+
│ Array_Tuple_Object │ 1000000 │ ' 3141 ms' │ ' 68 ms' │ ' 51 ms' │ ' 1.33 x' │
|
|
1572
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 3145 ms' │ ' 44 ms' │ ' 35 ms' │ ' 1.26 x' │
|
|
1573
|
+
│ Array_Composite_Union │ 1000000 │ ' 2134 ms' │ ' 68 ms' │ ' 31 ms' │ ' 2.19 x' │
|
|
1574
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1197 ms' │ ' 37 ms' │ ' 25 ms' │ ' 1.48 x' │
|
|
1575
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 5323 ms' │ ' 111 ms' │ ' 96 ms' │ ' 1.16 x' │
|
|
1584
1576
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1585
1577
|
```
|
|
1586
1578
|
|
|
@@ -1594,11 +1586,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1594
1586
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1595
1587
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1596
1588
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1597
|
-
│ typebox/compiler │ '
|
|
1598
|
-
│ typebox/errors │ '
|
|
1599
|
-
│ typebox/system │ '
|
|
1600
|
-
│ typebox/value │ '
|
|
1601
|
-
│ typebox │ '
|
|
1589
|
+
│ typebox/compiler │ '128.2 kb' │ ' 58.2 kb' │ '2.20 x' │
|
|
1590
|
+
│ typebox/errors │ '110.4 kb' │ ' 49.5 kb' │ '2.23 x' │
|
|
1591
|
+
│ typebox/system │ ' 75.2 kb' │ ' 31.1 kb' │ '2.42 x' │
|
|
1592
|
+
│ typebox/value │ '179.6 kb' │ ' 78.7 kb' │ '2.28 x' │
|
|
1593
|
+
│ typebox │ ' 74.1 kb' │ ' 30.6 kb' │ '2.42 x' │
|
|
1602
1594
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1603
1595
|
```
|
|
1604
1596
|
|
package/system/system.js
CHANGED
|
@@ -44,9 +44,6 @@ exports.TypeSystemDuplicateFormat = TypeSystemDuplicateFormat;
|
|
|
44
44
|
/** Creates user defined types and formats and provides overrides for value checking behaviours */
|
|
45
45
|
var TypeSystem;
|
|
46
46
|
(function (TypeSystem) {
|
|
47
|
-
// ------------------------------------------------------------------------
|
|
48
|
-
// Assertion Policies
|
|
49
|
-
// ------------------------------------------------------------------------
|
|
50
47
|
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
51
48
|
TypeSystem.ExactOptionalPropertyTypes = false;
|
|
52
49
|
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
@@ -55,9 +52,6 @@ var TypeSystem;
|
|
|
55
52
|
TypeSystem.AllowNaN = false;
|
|
56
53
|
/** Sets whether `null` should validate for void types. The default is `false` */
|
|
57
54
|
TypeSystem.AllowVoidNull = false;
|
|
58
|
-
// ------------------------------------------------------------------------
|
|
59
|
-
// String Formats and Types
|
|
60
|
-
// ------------------------------------------------------------------------
|
|
61
55
|
/** Creates a new type */
|
|
62
56
|
function Type(kind, check) {
|
|
63
57
|
if (Types.TypeRegistry.Has(kind))
|