@sinclair/typebox 0.26.8 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.js +13 -6
- package/errors/errors.d.ts +2 -2
- package/errors/errors.js +21 -10
- package/package.json +2 -2
- package/readme.md +205 -109
- package/typebox.d.ts +113 -39
- package/typebox.js +391 -51
- package/value/cast.d.ts +4 -4
- package/value/cast.js +14 -9
- package/value/check.d.ts +2 -2
- package/value/check.js +17 -9
- package/value/convert.d.ts +2 -2
- package/value/convert.js +14 -9
- package/value/create.d.ts +6 -2
- package/value/create.js +35 -16
- package/value/index.d.ts +1 -0
- package/value/mutate.d.ts +13 -0
- package/value/mutate.js +121 -0
- package/value/value.d.ts +3 -0
- package/value/value.js +6 -0
package/readme.md
CHANGED
|
@@ -81,6 +81,7 @@ License MIT
|
|
|
81
81
|
- [References](#types-references)
|
|
82
82
|
- [Recursive](#types-recursive)
|
|
83
83
|
- [Conditional](#types-conditional)
|
|
84
|
+
- [Template Literal](#types-template-literal)
|
|
84
85
|
- [Guards](#types-guards)
|
|
85
86
|
- [Unsafe](#types-unsafe)
|
|
86
87
|
- [Strict](#types-strict)
|
|
@@ -95,6 +96,7 @@ License MIT
|
|
|
95
96
|
- [Diff](#values-diff)
|
|
96
97
|
- [Patch](#values-patch)
|
|
97
98
|
- [Errors](#values-errors)
|
|
99
|
+
- [Mutate](#values-mutate)
|
|
98
100
|
- [Pointer](#values-pointer)
|
|
99
101
|
- [TypeCheck](#typecheck)
|
|
100
102
|
- [Ajv](#typecheck-ajv)
|
|
@@ -264,12 +266,12 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
264
266
|
│ Type.Number(), │ │ type: 'array', │
|
|
265
267
|
│ Type.Number() │ │ items: [{ │
|
|
266
268
|
│ ]) │ │ type: 'number' │
|
|
267
|
-
│ │ │
|
|
268
|
-
│ │ │
|
|
269
|
-
│ │ │
|
|
270
|
-
│ │ │
|
|
271
|
-
│ │ │
|
|
272
|
-
│ │ │
|
|
269
|
+
│ │ │ }, { │
|
|
270
|
+
│ │ │ type: 'number' │
|
|
271
|
+
│ │ │ }], │
|
|
272
|
+
│ │ │ additionalItems: false, │
|
|
273
|
+
│ │ │ minItems: 2, │
|
|
274
|
+
│ │ │ maxItems: 2 │
|
|
273
275
|
│ │ │ } │
|
|
274
276
|
│ │ │ │
|
|
275
277
|
│ │ │ │
|
|
@@ -321,6 +323,7 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
321
323
|
│ │ │ y: { │
|
|
322
324
|
│ │ │ type: 'number' │
|
|
323
325
|
│ │ │ } │
|
|
326
|
+
│ │ │ } │
|
|
324
327
|
│ │ │ }] │
|
|
325
328
|
│ │ │ } │
|
|
326
329
|
│ │ │ │
|
|
@@ -385,6 +388,18 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
385
388
|
│ ) │ │ │
|
|
386
389
|
│ │ │ │
|
|
387
390
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
391
|
+
│ const U = Type.Union([ │ type U = 'open' | 'close' │ const T = { │
|
|
392
|
+
│ Type.Literal('open'), │ │ type: 'string', │
|
|
393
|
+
│ Type.Literal('close') │ type T = `on${U}` │ pattern: '^on(open|close)$' │
|
|
394
|
+
│ ]) │ │ } │
|
|
395
|
+
│ │ │ │
|
|
396
|
+
│ const T = Type │ │ │
|
|
397
|
+
│ .TemplateLiteral([ │ │ │
|
|
398
|
+
│ Type.Literal('on'), │ │ │
|
|
399
|
+
│ U │ │ │
|
|
400
|
+
│ ]) │ │ │
|
|
401
|
+
│ │ │ │
|
|
402
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
388
403
|
│ const T = Type.Record( │ type T = Record< │ const T = { │
|
|
389
404
|
│ Type.String(), │ string, │ type: 'object', │
|
|
390
405
|
│ Type.Number() │ number, │ patternProperties: { │
|
|
@@ -424,23 +439,23 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
424
439
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
425
440
|
│ const T = Type.Pick( │ type T = Pick<{ │ const T = { │
|
|
426
441
|
│ Type.Object({ │ x: number, │ type: 'object', │
|
|
427
|
-
│ x: Type.Number(), │ y: number │
|
|
428
|
-
│ y: Type.Number()
|
|
429
|
-
│ }), ['x']
|
|
430
|
-
│ ) │ │
|
|
431
|
-
│ │ │
|
|
432
|
-
│ │ │
|
|
442
|
+
│ x: Type.Number(), │ y: number │ required: ['x'], │
|
|
443
|
+
│ y: Type.Number() │ }, 'x'> │ properties: { │
|
|
444
|
+
│ }), ['x'] | │ x: { │
|
|
445
|
+
│ ) │ │ type: 'number' │
|
|
446
|
+
│ │ │ } │
|
|
447
|
+
│ │ │ } │
|
|
433
448
|
│ │ │ } │
|
|
434
449
|
│ │ │ │
|
|
435
450
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
436
451
|
│ const T = Type.Omit( │ type T = Omit<{ │ const T = { │
|
|
437
452
|
│ Type.Object({ │ x: number, │ type: 'object', │
|
|
438
|
-
│ x: Type.Number(), │ y: number │
|
|
439
|
-
│ y: Type.Number()
|
|
440
|
-
│ }), ['x']
|
|
441
|
-
│ ) │ │
|
|
442
|
-
│ │ │
|
|
443
|
-
│ │ │
|
|
453
|
+
│ x: Type.Number(), │ y: number │ required: ['y'], │
|
|
454
|
+
│ y: Type.Number() │ }, 'x'> │ properties: { │
|
|
455
|
+
│ }), ['x'] | │ y: { │
|
|
456
|
+
│ ) │ │ type: 'number' │
|
|
457
|
+
│ │ │ } │
|
|
458
|
+
│ │ │ } │
|
|
444
459
|
│ │ │ } │
|
|
445
460
|
│ │ │ │
|
|
446
461
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
@@ -687,7 +702,7 @@ type T = Static<typeof T> // type T = string | null
|
|
|
687
702
|
|
|
688
703
|
### Reference Types
|
|
689
704
|
|
|
690
|
-
Reference types are supported with `Type.Ref
|
|
705
|
+
Reference types are supported with `Type.Ref`. The target type must specify a valid `$id`.
|
|
691
706
|
|
|
692
707
|
```typescript
|
|
693
708
|
const T = Type.String({ $id: 'T' }) // const T = {
|
|
@@ -704,7 +719,7 @@ const R = Type.Ref(T) // const R = {
|
|
|
704
719
|
|
|
705
720
|
### Recursive Types
|
|
706
721
|
|
|
707
|
-
Recursive types are supported with `Type.Recursive
|
|
722
|
+
Recursive types are supported with `Type.Recursive`
|
|
708
723
|
|
|
709
724
|
```typescript
|
|
710
725
|
const Node = Type.Recursive(Node => Type.Object({ // const Node = {
|
|
@@ -741,33 +756,85 @@ function test(node: Node) {
|
|
|
741
756
|
|
|
742
757
|
### Conditional Types
|
|
743
758
|
|
|
744
|
-
Conditional types are supported with `Extends`, `Exclude` and `Extract
|
|
745
|
-
|
|
746
|
-
**TypeScript**
|
|
759
|
+
Conditional types are supported with `Type.Extends`, `Type.Exclude` and `Type.Extract`
|
|
747
760
|
|
|
748
761
|
```typescript
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
type
|
|
752
|
-
|
|
753
|
-
type
|
|
754
|
-
|
|
762
|
+
// TypeScript
|
|
763
|
+
|
|
764
|
+
type T0 = string extends number ? true : false // type T0 = false
|
|
765
|
+
|
|
766
|
+
type T1 = Extract<string | number, number> // type T1 = number
|
|
767
|
+
|
|
768
|
+
type T2 = Exclude<string | number, number> // type T2 = string
|
|
769
|
+
|
|
770
|
+
// TypeBox
|
|
771
|
+
|
|
772
|
+
const T0 = Type.Extends(Type.String(), Type.Number(), Type.Literal(true), Type.Literal(false))
|
|
773
|
+
|
|
774
|
+
const T1 = Type.Extract(Type.Union([Type.String(), Type.Number()]), Type.Number())
|
|
775
|
+
|
|
776
|
+
const T2 = Type.Exclude(Type.Union([Type.String(), Type.Number()]), Type.Number())
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
type T0 = Static<typeof T0> // type T0 = false
|
|
780
|
+
|
|
781
|
+
type T1 = Static<typeof T1> // type T1 = number
|
|
782
|
+
|
|
783
|
+
type T2 = Static<typeof T2> // type T2 = string
|
|
755
784
|
```
|
|
756
|
-
|
|
785
|
+
|
|
786
|
+
<a name='types-template-literal'></a>
|
|
787
|
+
|
|
788
|
+
### Template Literal Types
|
|
789
|
+
|
|
790
|
+
Template Literal types are supported with `Type.TemplateLiteral`
|
|
791
|
+
|
|
757
792
|
```typescript
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
//
|
|
793
|
+
// TypeScript
|
|
794
|
+
|
|
795
|
+
type T = `option${'A'|'B'}` // type T = 'optionA' | 'optionB'
|
|
796
|
+
|
|
797
|
+
type R = Record<T, string> // type R = {
|
|
798
|
+
// optionA: string
|
|
799
|
+
// optionB: string
|
|
800
|
+
// }
|
|
801
|
+
|
|
802
|
+
// TypeBox
|
|
803
|
+
|
|
804
|
+
const T = Type.TemplateLiteral([ // const T = {
|
|
805
|
+
Type.Literal('option'), // pattern: '^option(A|B)$',
|
|
806
|
+
Type.Union([ // type: 'string'
|
|
807
|
+
Type.Literal('A'), // }
|
|
808
|
+
Type.Literal('B')
|
|
809
|
+
])
|
|
810
|
+
])
|
|
811
|
+
|
|
812
|
+
const R = Type.Record(T, Type.String()) // const R = {
|
|
813
|
+
// type: 'object',
|
|
814
|
+
// required: ['optionA', 'optionB'],
|
|
815
|
+
// properties: {
|
|
816
|
+
// optionA: {
|
|
817
|
+
// type: 'string'
|
|
818
|
+
// },
|
|
819
|
+
// optionB: {
|
|
820
|
+
// type: 'string'
|
|
821
|
+
// }
|
|
822
|
+
// }
|
|
823
|
+
// }
|
|
824
|
+
|
|
825
|
+
type T = Static<typeof T> // type T = 'optionA' | 'optionB'
|
|
826
|
+
|
|
827
|
+
type R = Static<typeof R> // type R = {
|
|
828
|
+
// optionA: string
|
|
829
|
+
// optionB: string
|
|
830
|
+
// }
|
|
764
831
|
```
|
|
765
832
|
|
|
766
833
|
<a name='types-unsafe'></a>
|
|
767
834
|
|
|
768
835
|
### Unsafe
|
|
769
836
|
|
|
770
|
-
Use `Type.Unsafe
|
|
837
|
+
Use `Type.Unsafe` to create custom schematics with user defined inference rules.
|
|
771
838
|
|
|
772
839
|
```typescript
|
|
773
840
|
const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
@@ -777,7 +844,7 @@ const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
|
777
844
|
type T = Static<typeof T> // type T = string
|
|
778
845
|
```
|
|
779
846
|
|
|
780
|
-
The `Type.Unsafe
|
|
847
|
+
The `Type.Unsafe` type can be useful to express specific OpenAPI schema representations.
|
|
781
848
|
|
|
782
849
|
```typescript
|
|
783
850
|
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
@@ -829,7 +896,7 @@ if(TypeGuard.TString(T)) {
|
|
|
829
896
|
|
|
830
897
|
### Strict
|
|
831
898
|
|
|
832
|
-
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are used for type composition and reflection. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict
|
|
899
|
+
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are used for type composition and reflection. 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.
|
|
833
900
|
|
|
834
901
|
```typescript
|
|
835
902
|
const T = Type.Object({ // const T = {
|
|
@@ -905,7 +972,7 @@ const R = Value.Check(T, { x: 1 }) // const R = true
|
|
|
905
972
|
Use the Convert function to convert a value into its target type if a reasonable conversion is possible.
|
|
906
973
|
|
|
907
974
|
```typescript
|
|
908
|
-
const T = Type.Object({ x: Type.Number()
|
|
975
|
+
const T = Type.Object({ x: Type.Number() })
|
|
909
976
|
|
|
910
977
|
const R1 = Value.Convert(T, { x: '3.14' }) // const R1 = { x: 3.14 }
|
|
911
978
|
|
|
@@ -987,7 +1054,6 @@ const E = Value.Diff(A, B) // const E = [
|
|
|
987
1054
|
const C = Value.Patch<typeof B>(A, E) // const C = { x: 3 }
|
|
988
1055
|
```
|
|
989
1056
|
|
|
990
|
-
|
|
991
1057
|
<a name='values-errors'></a>
|
|
992
1058
|
|
|
993
1059
|
### Errors
|
|
@@ -1010,6 +1076,29 @@ const R = [...Value.Errors(T, { x: '42' })] // const R = [{
|
|
|
1010
1076
|
// }]
|
|
1011
1077
|
```
|
|
1012
1078
|
|
|
1079
|
+
<a name='values-mutate'></a>
|
|
1080
|
+
|
|
1081
|
+
### Mutate
|
|
1082
|
+
|
|
1083
|
+
Use the Mutate function to perform a deep mutable value assignment while retaining internal references.
|
|
1084
|
+
|
|
1085
|
+
```typescript
|
|
1086
|
+
const Y = { z: 1 } // const Y = { z: 1 }
|
|
1087
|
+
|
|
1088
|
+
const X = { y: Y } // const X = { y: { z: 1 } }
|
|
1089
|
+
|
|
1090
|
+
const A = { x: X } // const A = { x: { y: { z: 1 } } }
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
|
|
1094
|
+
|
|
1095
|
+
const R0 = A.x.y.z === 2 // const R0 = 2
|
|
1096
|
+
|
|
1097
|
+
const R1 = A.x.y === Y // const R1 = true
|
|
1098
|
+
|
|
1099
|
+
const R2 = A.x === X // const R2 = true
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1013
1102
|
<a name='values-pointer'></a>
|
|
1014
1103
|
|
|
1015
1104
|
### Pointer
|
|
@@ -1021,10 +1110,13 @@ import { ValuePointer } from '@sinclair/typebox/value'
|
|
|
1021
1110
|
|
|
1022
1111
|
const A = { x: 0, y: 0, z: 0 }
|
|
1023
1112
|
|
|
1024
|
-
ValuePointer.Set(A, '/x', 1) // const A = { x: 1, y: 0, z: 0 }
|
|
1025
|
-
|
|
1026
|
-
ValuePointer.Set(A, '/
|
|
1113
|
+
ValuePointer.Set(A, '/x', 1) // const A' = { x: 1, y: 0, z: 0 }
|
|
1114
|
+
|
|
1115
|
+
ValuePointer.Set(A, '/y', 1) // const A' = { x: 1, y: 1, z: 0 }
|
|
1116
|
+
|
|
1117
|
+
ValuePointer.Set(A, '/z', 1) // const A' = { x: 1, y: 1, z: 1 }
|
|
1027
1118
|
```
|
|
1119
|
+
|
|
1028
1120
|
<a name='typecheck'></a>
|
|
1029
1121
|
|
|
1030
1122
|
## TypeCheck
|
|
@@ -1181,16 +1273,16 @@ const R = Value.Check(T, { x: 1, y: 2 }) // const R = true
|
|
|
1181
1273
|
|
|
1182
1274
|
### Formats
|
|
1183
1275
|
|
|
1184
|
-
Use the `Format(...)` function to create a custom string format. The following creates a
|
|
1276
|
+
Use the `Format(...)` function to create a custom string format. The following creates a format that checks for lowercase strings.
|
|
1185
1277
|
|
|
1186
1278
|
```typescript
|
|
1187
1279
|
TypeSystem.Format('lowercase', value => value === value.toLowerCase()) // format should be lowercase
|
|
1188
1280
|
|
|
1189
1281
|
const T = Type.String({ format: 'lowercase' })
|
|
1190
1282
|
|
|
1191
|
-
const A = Value.Check(T, '
|
|
1283
|
+
const A = Value.Check(T, 'Hello') // const A = false
|
|
1192
1284
|
|
|
1193
|
-
const B = Value.Check(T, '
|
|
1285
|
+
const B = Value.Check(T, 'hello') // const B = true
|
|
1194
1286
|
```
|
|
1195
1287
|
|
|
1196
1288
|
<a name='typesystem-policies'></a>
|
|
@@ -1217,7 +1309,7 @@ TypeSystem.AllowNaN = true
|
|
|
1217
1309
|
|
|
1218
1310
|
## Benchmark
|
|
1219
1311
|
|
|
1220
|
-
This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.
|
|
1312
|
+
This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.12.0.
|
|
1221
1313
|
|
|
1222
1314
|
For additional comparative benchmarks, please refer to [typescript-runtime-type-benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/).
|
|
1223
1315
|
|
|
@@ -1231,33 +1323,35 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1231
1323
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1232
1324
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1233
1325
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1234
|
-
│ Literal_String │ 1000 │ '
|
|
1235
|
-
│ Literal_Number │ 1000 │ '
|
|
1236
|
-
│ Literal_Boolean │ 1000 │ '
|
|
1237
|
-
│ Primitive_Number │ 1000 │ '
|
|
1238
|
-
│ Primitive_String │ 1000 │ '
|
|
1239
|
-
│ Primitive_String_Pattern │ 1000 │ '
|
|
1240
|
-
│ Primitive_Boolean │ 1000 │ '
|
|
1241
|
-
│ Primitive_Null │ 1000 │ '
|
|
1242
|
-
│ Object_Unconstrained │ 1000 │ '
|
|
1243
|
-
│ Object_Constrained │ 1000 │ '
|
|
1244
|
-
│
|
|
1245
|
-
│
|
|
1246
|
-
│
|
|
1247
|
-
│
|
|
1248
|
-
│
|
|
1249
|
-
│
|
|
1250
|
-
│
|
|
1251
|
-
│
|
|
1252
|
-
│
|
|
1253
|
-
│
|
|
1254
|
-
│
|
|
1255
|
-
│
|
|
1256
|
-
│
|
|
1257
|
-
│
|
|
1258
|
-
│
|
|
1259
|
-
│
|
|
1260
|
-
│
|
|
1326
|
+
│ Literal_String │ 1000 │ ' 257 ms' │ ' 8 ms' │ ' 32.13 x' │
|
|
1327
|
+
│ Literal_Number │ 1000 │ ' 203 ms' │ ' 4 ms' │ ' 50.75 x' │
|
|
1328
|
+
│ Literal_Boolean │ 1000 │ ' 183 ms' │ ' 4 ms' │ ' 45.75 x' │
|
|
1329
|
+
│ Primitive_Number │ 1000 │ ' 174 ms' │ ' 8 ms' │ ' 21.75 x' │
|
|
1330
|
+
│ Primitive_String │ 1000 │ ' 158 ms' │ ' 9 ms' │ ' 17.56 x' │
|
|
1331
|
+
│ Primitive_String_Pattern │ 1000 │ ' 213 ms' │ ' 13 ms' │ ' 16.38 x' │
|
|
1332
|
+
│ Primitive_Boolean │ 1000 │ ' 136 ms' │ ' 6 ms' │ ' 22.67 x' │
|
|
1333
|
+
│ Primitive_Null │ 1000 │ ' 144 ms' │ ' 6 ms' │ ' 24.00 x' │
|
|
1334
|
+
│ Object_Unconstrained │ 1000 │ ' 1176 ms' │ ' 38 ms' │ ' 30.95 x' │
|
|
1335
|
+
│ Object_Constrained │ 1000 │ ' 1181 ms' │ ' 31 ms' │ ' 38.10 x' │
|
|
1336
|
+
│ Object_Vector3 │ 1000 │ ' 387 ms' │ ' 8 ms' │ ' 48.38 x' │
|
|
1337
|
+
│ Object_Box3D │ 1000 │ ' 1693 ms' │ ' 25 ms' │ ' 67.72 x' │
|
|
1338
|
+
│ Tuple_Primitive │ 1000 │ ' 470 ms' │ ' 15 ms' │ ' 31.33 x' │
|
|
1339
|
+
│ Tuple_Object │ 1000 │ ' 1206 ms' │ ' 17 ms' │ ' 70.94 x' │
|
|
1340
|
+
│ Composite_Intersect │ 1000 │ ' 567 ms' │ ' 20 ms' │ ' 28.35 x' │
|
|
1341
|
+
│ Composite_Union │ 1000 │ ' 515 ms' │ ' 21 ms' │ ' 24.52 x' │
|
|
1342
|
+
│ Math_Vector4 │ 1000 │ ' 787 ms' │ ' 10 ms' │ ' 78.70 x' │
|
|
1343
|
+
│ Math_Matrix4 │ 1000 │ ' 386 ms' │ ' 8 ms' │ ' 48.25 x' │
|
|
1344
|
+
│ Array_Primitive_Number │ 1000 │ ' 349 ms' │ ' 7 ms' │ ' 49.86 x' │
|
|
1345
|
+
│ Array_Primitive_String │ 1000 │ ' 336 ms' │ ' 4 ms' │ ' 84.00 x' │
|
|
1346
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 284 ms' │ ' 3 ms' │ ' 94.67 x' │
|
|
1347
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1704 ms' │ ' 19 ms' │ ' 89.68 x' │
|
|
1348
|
+
│ Array_Object_Constrained │ 1000 │ ' 1456 ms' │ ' 18 ms' │ ' 80.89 x' │
|
|
1349
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 792 ms' │ ' 15 ms' │ ' 52.80 x' │
|
|
1350
|
+
│ Array_Tuple_Object │ 1000 │ ' 1552 ms' │ ' 17 ms' │ ' 91.29 x' │
|
|
1351
|
+
│ Array_Composite_Intersect │ 1000 │ ' 744 ms' │ ' 18 ms' │ ' 41.33 x' │
|
|
1352
|
+
│ Array_Composite_Union │ 1000 │ ' 783 ms' │ ' 15 ms' │ ' 52.20 x' │
|
|
1353
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1093 ms' │ ' 14 ms' │ ' 78.07 x' │
|
|
1354
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 684 ms' │ ' 6 ms' │ ' 114.00 x' │
|
|
1261
1355
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1262
1356
|
```
|
|
1263
1357
|
|
|
@@ -1271,35 +1365,37 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1271
1365
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1272
1366
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1273
1367
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1274
|
-
│ Literal_String │ 1000000 │ '
|
|
1275
|
-
│ Literal_Number │ 1000000 │ '
|
|
1276
|
-
│ Literal_Boolean │ 1000000 │ '
|
|
1277
|
-
│ Primitive_Number │ 1000000 │ '
|
|
1278
|
-
│ Primitive_String │ 1000000 │ '
|
|
1279
|
-
│ Primitive_String_Pattern │ 1000000 │ '
|
|
1280
|
-
│ Primitive_Boolean │ 1000000 │ ' 23 ms' │ '
|
|
1281
|
-
│ Primitive_Null │ 1000000 │ '
|
|
1282
|
-
│ Object_Unconstrained │ 1000000 │ '
|
|
1283
|
-
│ Object_Constrained │ 1000000 │ '
|
|
1284
|
-
│
|
|
1285
|
-
│
|
|
1286
|
-
│
|
|
1287
|
-
│
|
|
1288
|
-
│
|
|
1289
|
-
│
|
|
1290
|
-
│
|
|
1291
|
-
│
|
|
1292
|
-
│
|
|
1293
|
-
│
|
|
1294
|
-
│
|
|
1295
|
-
│
|
|
1296
|
-
│
|
|
1297
|
-
│
|
|
1298
|
-
│
|
|
1299
|
-
│
|
|
1300
|
-
│
|
|
1301
|
-
│
|
|
1302
|
-
│
|
|
1368
|
+
│ Literal_String │ 1000000 │ ' 27 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
|
|
1369
|
+
│ Literal_Number │ 1000000 │ ' 23 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
|
|
1370
|
+
│ Literal_Boolean │ 1000000 │ ' 21 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
|
|
1371
|
+
│ Primitive_Number │ 1000000 │ ' 26 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
|
|
1372
|
+
│ Primitive_String │ 1000000 │ ' 25 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1373
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 155 ms' │ ' 49 ms' │ ' 43 ms' │ ' 1.14 x' │
|
|
1374
|
+
│ Primitive_Boolean │ 1000000 │ ' 23 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1375
|
+
│ Primitive_Null │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1376
|
+
│ Object_Unconstrained │ 1000000 │ ' 804 ms' │ ' 35 ms' │ ' 28 ms' │ ' 1.25 x' │
|
|
1377
|
+
│ Object_Constrained │ 1000000 │ ' 1041 ms' │ ' 55 ms' │ ' 41 ms' │ ' 1.34 x' │
|
|
1378
|
+
│ Object_Vector3 │ 1000000 │ ' 380 ms' │ ' 26 ms' │ ' 20 ms' │ ' 1.30 x' │
|
|
1379
|
+
│ Object_Box3D │ 1000000 │ ' 1785 ms' │ ' 65 ms' │ ' 52 ms' │ ' 1.25 x' │
|
|
1380
|
+
│ Object_Recursive │ 1000000 │ ' 4984 ms' │ ' 396 ms' │ ' 114 ms' │ ' 3.47 x' │
|
|
1381
|
+
│ Tuple_Primitive │ 1000000 │ ' 168 ms' │ ' 24 ms' │ ' 16 ms' │ ' 1.50 x' │
|
|
1382
|
+
│ Tuple_Object │ 1000000 │ ' 673 ms' │ ' 30 ms' │ ' 26 ms' │ ' 1.15 x' │
|
|
1383
|
+
│ Composite_Intersect │ 1000000 │ ' 751 ms' │ ' 28 ms' │ ' 20 ms' │ ' 1.40 x' │
|
|
1384
|
+
│ Composite_Union │ 1000000 │ ' 489 ms' │ ' 24 ms' │ ' 16 ms' │ ' 1.50 x' │
|
|
1385
|
+
│ Math_Vector4 │ 1000000 │ ' 259 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
|
|
1386
|
+
│ Math_Matrix4 │ 1000000 │ ' 1002 ms' │ ' 40 ms' │ ' 30 ms' │ ' 1.33 x' │
|
|
1387
|
+
│ Array_Primitive_Number │ 1000000 │ ' 252 ms' │ ' 22 ms' │ ' 15 ms' │ ' 1.47 x' │
|
|
1388
|
+
│ Array_Primitive_String │ 1000000 │ ' 227 ms' │ ' 22 ms' │ ' 18 ms' │ ' 1.22 x' │
|
|
1389
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 150 ms' │ ' 23 ms' │ ' 22 ms' │ ' 1.05 x' │
|
|
1390
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 4754 ms' │ ' 71 ms' │ ' 64 ms' │ ' 1.11 x' │
|
|
1391
|
+
│ Array_Object_Constrained │ 1000000 │ ' 4787 ms' │ ' 142 ms' │ ' 123 ms' │ ' 1.15 x' │
|
|
1392
|
+
│ Array_Object_Recursive │ 1000000 │ ' 19088 ms' │ ' 1735 ms' │ ' 314 ms' │ ' 5.53 x' │
|
|
1393
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 650 ms' │ ' 41 ms' │ ' 31 ms' │ ' 1.32 x' │
|
|
1394
|
+
│ Array_Tuple_Object │ 1000000 │ ' 2770 ms' │ ' 67 ms' │ ' 55 ms' │ ' 1.22 x' │
|
|
1395
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 2693 ms' │ ' 50 ms' │ ' 39 ms' │ ' 1.28 x' │
|
|
1396
|
+
│ Array_Composite_Union │ 1000000 │ ' 1982 ms' │ ' 72 ms' │ ' 33 ms' │ ' 2.18 x' │
|
|
1397
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1068 ms' │ ' 40 ms' │ ' 26 ms' │ ' 1.54 x' │
|
|
1398
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4609 ms' │ ' 115 ms' │ ' 88 ms' │ ' 1.31 x' │
|
|
1303
1399
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1304
1400
|
```
|
|
1305
1401
|
|
|
@@ -1313,11 +1409,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1313
1409
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1314
1410
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1315
1411
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1316
|
-
│ typebox/compiler │ '
|
|
1317
|
-
│ typebox/errors │ '
|
|
1318
|
-
│ typebox/system │ '
|
|
1319
|
-
│ typebox/value │ '
|
|
1320
|
-
│ typebox │ '
|
|
1412
|
+
│ typebox/compiler │ '124.3 kb' │ ' 55.7 kb' │ '2.23 x' │
|
|
1413
|
+
│ typebox/errors │ '107.8 kb' │ ' 47.9 kb' │ '2.25 x' │
|
|
1414
|
+
│ typebox/system │ ' 73.3 kb' │ ' 30.2 kb' │ '2.43 x' │
|
|
1415
|
+
│ typebox/value │ '170.7 kb' │ ' 74.2 kb' │ '2.30 x' │
|
|
1416
|
+
│ typebox │ ' 72.0 kb' │ ' 29.7 kb' │ '2.43 x' │
|
|
1321
1417
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1322
1418
|
```
|
|
1323
1419
|
|