@sinclair/typebox 0.24.51 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.d.ts +1 -1
- package/compiler/compiler.js +15 -2
- package/conditional/structural.js +23 -0
- package/errors/errors.d.ts +43 -38
- package/errors/errors.js +62 -38
- package/guard/guard.d.ts +2 -0
- package/guard/guard.js +96 -14
- package/package.json +1 -1
- package/readme.md +245 -161
- package/typebox.d.ts +66 -47
- package/typebox.js +47 -42
- package/value/cast.js +6 -1
- package/value/check.js +21 -1
- package/value/clone.js +10 -4
- package/value/create.js +13 -0
- package/value/delta.js +8 -0
- package/value/equal.js +6 -0
- package/value/is.d.ts +1 -0
- package/value/is.js +5 -1
package/readme.md
CHANGED
|
@@ -56,10 +56,10 @@ License MIT
|
|
|
56
56
|
- [Overview](#overview)
|
|
57
57
|
- [Usage](#usage)
|
|
58
58
|
- [Types](#types)
|
|
59
|
-
- [Standard](#types-standard)
|
|
59
|
+
- [Standard Types](#types-standard)
|
|
60
|
+
- [Extended Types](#types-extended)
|
|
60
61
|
- [Modifiers](#types-modifiers)
|
|
61
62
|
- [Options](#types-options)
|
|
62
|
-
- [Extended](#types-extended)
|
|
63
63
|
- [Reference](#types-reference)
|
|
64
64
|
- [Recursive](#types-recursive)
|
|
65
65
|
- [Generic](#types-generic)
|
|
@@ -79,7 +79,7 @@ License MIT
|
|
|
79
79
|
- [Pointer](#values-pointer)
|
|
80
80
|
- [TypeCheck](#typecheck)
|
|
81
81
|
- [Ajv](#typecheck-ajv)
|
|
82
|
-
- [
|
|
82
|
+
- [TypeCompiler](#typecheck-typecompiler)
|
|
83
83
|
- [Formats](#typecheck-formats)
|
|
84
84
|
- [Benchmark](#benchmark)
|
|
85
85
|
- [Compile](#benchmark-compile)
|
|
@@ -170,9 +170,9 @@ TypeBox provides a set of functions that allow you to compose JSON Schema simila
|
|
|
170
170
|
|
|
171
171
|
<a name='types-standard'></a>
|
|
172
172
|
|
|
173
|
-
### Standard
|
|
173
|
+
### Standard Types
|
|
174
174
|
|
|
175
|
-
The following table lists the
|
|
175
|
+
The following table lists the Standard TypeBox types.
|
|
176
176
|
|
|
177
177
|
```typescript
|
|
178
178
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -375,6 +375,81 @@ The following table lists the standard TypeBox types.
|
|
|
375
375
|
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
376
376
|
```
|
|
377
377
|
|
|
378
|
+
<a name='types-extended'></a>
|
|
379
|
+
|
|
380
|
+
### Extended Types
|
|
381
|
+
|
|
382
|
+
TypeBox provides a set of extended types that can be used to express schematics for core JavaScript constructs and primitives. Extended types are not valid JSON Schema and will not validate using typical validation. These types however can be used to frame JSON schema and describe callable RPC interfaces that may receive JSON validated data.
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
386
|
+
│ TypeBox │ TypeScript │ Extended Schema │
|
|
387
|
+
│ │ │ │
|
|
388
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
389
|
+
│ const T = Type.Constructor([ │ type T = new ( │ const T = { │
|
|
390
|
+
│ Type.String(), │ arg0: string, │ type: 'object', │
|
|
391
|
+
│ Type.Number() │ arg1: number │ instanceOf: 'Constructor', │
|
|
392
|
+
│ ], Type.Boolean()) │ ) => boolean │ parameters: [{ │
|
|
393
|
+
│ │ │ type: 'string' │
|
|
394
|
+
│ │ │ }, { │
|
|
395
|
+
│ │ │ type: 'number' │
|
|
396
|
+
│ │ │ }], │
|
|
397
|
+
│ │ │ return: { │
|
|
398
|
+
│ │ │ type: 'boolean' │
|
|
399
|
+
│ │ │ } │
|
|
400
|
+
│ │ │ } │
|
|
401
|
+
│ │ │ │
|
|
402
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
403
|
+
│ const T = Type.Function([ │ type T = ( │ const T = { │
|
|
404
|
+
| Type.String(), │ arg0: string, │ type : 'object', │
|
|
405
|
+
│ Type.Number() │ arg1: number │ instanceOf: 'Function', │
|
|
406
|
+
│ ], Type.Boolean()) │ ) => boolean │ parameters: [{ │
|
|
407
|
+
│ │ │ type: 'string' │
|
|
408
|
+
│ │ │ }, { │
|
|
409
|
+
│ │ │ type: 'number' │
|
|
410
|
+
│ │ │ }], │
|
|
411
|
+
│ │ │ return: { │
|
|
412
|
+
│ │ │ type: 'boolean' │
|
|
413
|
+
│ │ │ } │
|
|
414
|
+
│ │ │ } │
|
|
415
|
+
│ │ │ │
|
|
416
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
417
|
+
│ const T = Type.Promise( │ type T = Promise<string> │ const T = { │
|
|
418
|
+
│ Type.String() │ │ type: 'object', │
|
|
419
|
+
│ ) │ │ instanceOf: 'Promise', │
|
|
420
|
+
│ │ │ item: { │
|
|
421
|
+
│ │ │ type: 'string' │
|
|
422
|
+
│ │ │ } │
|
|
423
|
+
│ │ │ } │
|
|
424
|
+
│ │ │ │
|
|
425
|
+
│ │ │ │
|
|
426
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
427
|
+
│ const T = Type.Uint8Array() │ type T = Uint8Array │ const T = { │
|
|
428
|
+
│ │ │ type: 'object', │
|
|
429
|
+
│ │ │ instanceOf: 'Uint8Array' │
|
|
430
|
+
│ │ │ } │
|
|
431
|
+
│ │ │ │
|
|
432
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
433
|
+
│ const T = Type.Date() │ type T = Date │ const T = { │
|
|
434
|
+
│ │ │ type: 'object', │
|
|
435
|
+
│ │ │ instanceOf: 'Date' │
|
|
436
|
+
│ │ │ } │
|
|
437
|
+
│ │ │ │
|
|
438
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
439
|
+
│ const T = Type.Undefined() │ type T = undefined │ const T = { │
|
|
440
|
+
│ │ │ type: 'null', │
|
|
441
|
+
│ │ │ typeOf: 'Undefined' │
|
|
442
|
+
│ │ │ } │
|
|
443
|
+
│ │ │ │
|
|
444
|
+
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
445
|
+
│ const T = Type.Void() │ type T = void │ const T = { │
|
|
446
|
+
│ │ │ type: 'null' │
|
|
447
|
+
│ │ │ typeOf: 'Void' │
|
|
448
|
+
│ │ │ } │
|
|
449
|
+
│ │ │ │
|
|
450
|
+
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
451
|
+
```
|
|
452
|
+
|
|
378
453
|
<a name='types-modifiers'></a>
|
|
379
454
|
|
|
380
455
|
### Modifiers
|
|
@@ -436,70 +511,6 @@ const T = Type.Number({ multipleOf: 2 })
|
|
|
436
511
|
const T = Type.Array(Type.Integer(), { minItems: 5 })
|
|
437
512
|
```
|
|
438
513
|
|
|
439
|
-
<a name='types-extended'></a>
|
|
440
|
-
|
|
441
|
-
### Extended
|
|
442
|
-
|
|
443
|
-
In addition to JSON schema types, TypeBox provides several extended types that allow for the composition of `function` and `constructor` types. These additional types are not valid JSON Schema and will not validate using typical JSON Schema validation. However, these types can be used to frame JSON schema and describe callable interfaces that may receive JSON validated data. These types are as follows.
|
|
444
|
-
|
|
445
|
-
```typescript
|
|
446
|
-
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
447
|
-
│ TypeBox │ TypeScript │ Extended Schema │
|
|
448
|
-
│ │ │ │
|
|
449
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
450
|
-
│ const T = Type.Constructor([ │ type T = new ( │ const T = { │
|
|
451
|
-
│ Type.String(), │ arg0: string, │ type: 'constructor' │
|
|
452
|
-
│ Type.Number() │ arg1: number │ parameters: [{ │
|
|
453
|
-
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
454
|
-
│ │ │ }, { │
|
|
455
|
-
│ │ │ type: 'number' │
|
|
456
|
-
│ │ │ }], │
|
|
457
|
-
│ │ │ return: { │
|
|
458
|
-
│ │ │ type: 'boolean' │
|
|
459
|
-
│ │ │ } │
|
|
460
|
-
│ │ │ } │
|
|
461
|
-
│ │ │ │
|
|
462
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
463
|
-
│ const T = Type.Function([ │ type T = ( │ const T = { │
|
|
464
|
-
| Type.String(), │ arg0: string, │ type : 'function', │
|
|
465
|
-
│ Type.Number() │ arg1: number │ parameters: [{ │
|
|
466
|
-
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
|
467
|
-
│ │ │ }, { │
|
|
468
|
-
│ │ │ type: 'number' │
|
|
469
|
-
│ │ │ }], │
|
|
470
|
-
│ │ │ return: { │
|
|
471
|
-
│ │ │ type: 'boolean' │
|
|
472
|
-
│ │ │ } │
|
|
473
|
-
│ │ │ } │
|
|
474
|
-
│ │ │ │
|
|
475
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
476
|
-
│ const T = Type.Uint8Array() │ type T = Uint8Array │ const T = { │
|
|
477
|
-
│ │ │ type: 'object', │
|
|
478
|
-
│ │ │ specialized: 'Uint8Array' │
|
|
479
|
-
│ │ │ } │
|
|
480
|
-
│ │ │ │
|
|
481
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
482
|
-
│ const T = Type.Promise( │ type T = Promise<string> │ const T = { │
|
|
483
|
-
│ Type.String() │ │ type: 'promise', │
|
|
484
|
-
│ ) │ │ item: { │
|
|
485
|
-
│ │ │ type: 'string' │
|
|
486
|
-
│ │ │ } │
|
|
487
|
-
│ │ │ } │
|
|
488
|
-
│ │ │ │
|
|
489
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
490
|
-
│ const T = Type.Undefined() │ type T = undefined │ const T = { │
|
|
491
|
-
│ │ │ type: 'object', │
|
|
492
|
-
│ │ │ specialized: 'Undefined' │
|
|
493
|
-
│ │ │ } │
|
|
494
|
-
│ │ │ │
|
|
495
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
496
|
-
│ const T = Type.Void() │ type T = void │ const T = { │
|
|
497
|
-
│ │ │ type: 'null' │
|
|
498
|
-
│ │ │ } │
|
|
499
|
-
│ │ │ │
|
|
500
|
-
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
501
|
-
```
|
|
502
|
-
|
|
503
514
|
<a name='types-reference'></a>
|
|
504
515
|
|
|
505
516
|
### Reference
|
|
@@ -890,70 +901,143 @@ ValuePointer.Set(A, '/z', 1) // const A = { x: 1, y: 1,
|
|
|
890
901
|
|
|
891
902
|
## TypeCheck
|
|
892
903
|
|
|
893
|
-
TypeBox
|
|
904
|
+
TypeBox targets JSON Schema Draft 6 and is built and tested against the Ajv JSON Schema validator for standards compliance. TypeBox also includes an optional built-in TypeCompiler that can provide improved compilation and validation performance specifically for TypeBox types only.
|
|
905
|
+
|
|
906
|
+
The following sections detail using these validators.
|
|
894
907
|
|
|
895
908
|
<a name='typecheck-ajv'></a>
|
|
896
909
|
|
|
897
910
|
### Ajv
|
|
898
911
|
|
|
899
|
-
The following
|
|
912
|
+
The following are the recommended configurations to support both the [Standard](#standard) and [Extended](#extended) type sets provided by TypeBox. For schema portability and publishing to remote systems, it is recommended to use the Standard type set only.
|
|
900
913
|
|
|
901
914
|
```bash
|
|
902
915
|
$ npm install ajv ajv-formats --save
|
|
903
916
|
```
|
|
904
917
|
|
|
918
|
+
<details>
|
|
919
|
+
|
|
920
|
+
<summary>
|
|
921
|
+
<strong>Standard Ajv Configuration</strong>
|
|
922
|
+
<p>Expand for Standard Type Set Configuration</p>
|
|
923
|
+
</summary>
|
|
924
|
+
|
|
905
925
|
```typescript
|
|
906
926
|
import { Type } from '@sinclair/typebox'
|
|
907
927
|
import addFormats from 'ajv-formats'
|
|
908
928
|
import Ajv from 'ajv'
|
|
909
929
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
'json-pointer',
|
|
929
|
-
'relative-json-pointer',
|
|
930
|
-
'regex'
|
|
931
|
-
])
|
|
930
|
+
export function createAjv() {
|
|
931
|
+
return addFormats(new Ajv({}), [
|
|
932
|
+
'date-time',
|
|
933
|
+
'time',
|
|
934
|
+
'date',
|
|
935
|
+
'email',
|
|
936
|
+
'hostname',
|
|
937
|
+
'ipv4',
|
|
938
|
+
'ipv6',
|
|
939
|
+
'uri',
|
|
940
|
+
'uri-reference',
|
|
941
|
+
'uuid',
|
|
942
|
+
'uri-template',
|
|
943
|
+
'json-pointer',
|
|
944
|
+
'relative-json-pointer',
|
|
945
|
+
'regex'
|
|
946
|
+
])
|
|
947
|
+
}
|
|
932
948
|
|
|
933
|
-
|
|
934
|
-
//
|
|
935
|
-
// Create a TypeBox type
|
|
936
|
-
//
|
|
937
|
-
//--------------------------------------------------------------------------------------------
|
|
949
|
+
const ajv = createAjv()
|
|
938
950
|
|
|
939
|
-
const
|
|
951
|
+
const R = ajv.validate(Type.Object({ // const R = true
|
|
940
952
|
x: Type.Number(),
|
|
941
953
|
y: Type.Number(),
|
|
942
954
|
z: Type.Number()
|
|
943
|
-
})
|
|
955
|
+
}), { x: 1, y: 2, z: 3 })
|
|
956
|
+
```
|
|
944
957
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
//
|
|
949
|
-
//--------------------------------------------------------------------------------------------
|
|
958
|
+
</details>
|
|
959
|
+
|
|
960
|
+
<details>
|
|
950
961
|
|
|
951
|
-
|
|
962
|
+
<summary>
|
|
963
|
+
<strong>Extended Ajv Configuration</strong>
|
|
964
|
+
<p>Expand for Extended Type Set Configuration</p>
|
|
965
|
+
</summary>
|
|
966
|
+
|
|
967
|
+
```typescript
|
|
968
|
+
import { TypeGuard } from '@sinclair/typebox/guard'
|
|
969
|
+
import { Value } from '@sinclair/typebox/value'
|
|
970
|
+
import { Type } from '@sinclair/typebox'
|
|
971
|
+
import addFormats from 'ajv-formats'
|
|
972
|
+
import Ajv from 'ajv'
|
|
973
|
+
|
|
974
|
+
function schemaOf(schemaOf: string, value: unknown, schema: unknown) {
|
|
975
|
+
switch (schemaOf) {
|
|
976
|
+
case 'Constructor':
|
|
977
|
+
return TypeGuard.TConstructor(schema) && Value.Check(schema, value) // not supported
|
|
978
|
+
case 'Function':
|
|
979
|
+
return TypeGuard.TFunction(schema) && Value.Check(schema, value) // not supported
|
|
980
|
+
case 'Date':
|
|
981
|
+
return TypeGuard.TDate(schema) && Value.Check(schema, value)
|
|
982
|
+
case 'Promise':
|
|
983
|
+
return TypeGuard.TPromise(schema) && Value.Check(schema, value) // not supported
|
|
984
|
+
case 'Uint8Array':
|
|
985
|
+
return TypeGuard.TUint8Array(schema) && Value.Check(schema, value)
|
|
986
|
+
case 'Undefined':
|
|
987
|
+
return TypeGuard.TUndefined(schema) && Value.Check(schema, value) // not supported
|
|
988
|
+
case 'Void':
|
|
989
|
+
return TypeGuard.TVoid(schema) && Value.Check(schema, value)
|
|
990
|
+
default:
|
|
991
|
+
return false
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
export function createAjv() {
|
|
996
|
+
return addFormats(new Ajv({}), [
|
|
997
|
+
'date-time',
|
|
998
|
+
'time',
|
|
999
|
+
'date',
|
|
1000
|
+
'email',
|
|
1001
|
+
'hostname',
|
|
1002
|
+
'ipv4',
|
|
1003
|
+
'ipv6',
|
|
1004
|
+
'uri',
|
|
1005
|
+
'uri-reference',
|
|
1006
|
+
'uuid',
|
|
1007
|
+
'uri-template',
|
|
1008
|
+
'json-pointer',
|
|
1009
|
+
'relative-json-pointer',
|
|
1010
|
+
'regex'
|
|
1011
|
+
])
|
|
1012
|
+
.addKeyword({ type: 'object', keyword: 'instanceOf', validate: schemaOf })
|
|
1013
|
+
.addKeyword({ type: 'null', keyword: 'typeOf', validate: schemaOf })
|
|
1014
|
+
.addKeyword('exclusiveMinimumTimestamp')
|
|
1015
|
+
.addKeyword('exclusiveMaximumTimestamp')
|
|
1016
|
+
.addKeyword('minimumTimestamp')
|
|
1017
|
+
.addKeyword('maximumTimestamp')
|
|
1018
|
+
.addKeyword('minByteLength')
|
|
1019
|
+
.addKeyword('maxByteLength')
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const ajv = createAjv()
|
|
1023
|
+
|
|
1024
|
+
const R = ajv.validate(Type.Object({ // const R = true
|
|
1025
|
+
buffer: Type.Uint8Array(),
|
|
1026
|
+
date: Type.Date(),
|
|
1027
|
+
void: Type.Void()
|
|
1028
|
+
}), {
|
|
1029
|
+
buffer: new Uint8Array(),
|
|
1030
|
+
date: new Date(),
|
|
1031
|
+
void: null
|
|
1032
|
+
})
|
|
952
1033
|
```
|
|
953
1034
|
|
|
954
|
-
|
|
1035
|
+
</details>
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
<a name='typecheck-typecompiler'></a>
|
|
955
1039
|
|
|
956
|
-
###
|
|
1040
|
+
### TypeCompiler
|
|
957
1041
|
|
|
958
1042
|
TypeBox provides an optional high performance just-in-time (JIT) compiler and type checker that can be used in applications that require extremely fast validation. Note that this compiler is optimized for TypeBox types only where the schematics are known in advance. If defining custom types with `Type.Unsafe<T>` please consider Ajv.
|
|
959
1043
|
|
|
@@ -1062,29 +1146,29 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1062
1146
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1063
1147
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1064
1148
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1065
|
-
│ Number │ 2000 │ '
|
|
1066
|
-
│ String │ 2000 │ '
|
|
1067
|
-
│ Boolean │ 2000 │ '
|
|
1068
|
-
│ Null │ 2000 │ '
|
|
1069
|
-
│ RegEx │ 2000 │ '
|
|
1070
|
-
│ ObjectA │ 2000 │ '
|
|
1071
|
-
│ ObjectB │ 2000 │ '
|
|
1072
|
-
│ Tuple │ 2000 │ '
|
|
1073
|
-
│ Union │ 2000 │ '
|
|
1074
|
-
│ Vector4 │ 2000 │ ' 1513 ms' │ '
|
|
1075
|
-
│ Matrix4 │ 2000 │ '
|
|
1076
|
-
│ Literal_String │ 2000 │ '
|
|
1077
|
-
│ Literal_Number │ 2000 │ ' 358 ms' │ '
|
|
1078
|
-
│ Literal_Boolean │ 2000 │ '
|
|
1079
|
-
│ Array_Number │ 2000 │ '
|
|
1080
|
-
│ Array_String │ 2000 │ '
|
|
1081
|
-
│ Array_Boolean │ 2000 │ '
|
|
1082
|
-
│ Array_ObjectA │ 2000 │ '
|
|
1083
|
-
│ Array_ObjectB │ 2000 │ '
|
|
1084
|
-
│ Array_Tuple │ 2000 │ '
|
|
1085
|
-
│ Array_Union │ 2000 │ '
|
|
1086
|
-
│ Array_Vector4 │ 2000 │ '
|
|
1087
|
-
│ Array_Matrix4 │ 2000 │ '
|
|
1149
|
+
│ Number │ 2000 │ ' 421 ms' │ ' 11 ms' │ ' 38.27 x' │
|
|
1150
|
+
│ String │ 2000 │ ' 332 ms' │ ' 11 ms' │ ' 30.18 x' │
|
|
1151
|
+
│ Boolean │ 2000 │ ' 291 ms' │ ' 12 ms' │ ' 24.25 x' │
|
|
1152
|
+
│ Null │ 2000 │ ' 266 ms' │ ' 9 ms' │ ' 29.56 x' │
|
|
1153
|
+
│ RegEx │ 2000 │ ' 486 ms' │ ' 17 ms' │ ' 28.59 x' │
|
|
1154
|
+
│ ObjectA │ 2000 │ ' 2791 ms' │ ' 50 ms' │ ' 55.82 x' │
|
|
1155
|
+
│ ObjectB │ 2000 │ ' 2896 ms' │ ' 37 ms' │ ' 78.27 x' │
|
|
1156
|
+
│ Tuple │ 2000 │ ' 1244 ms' │ ' 21 ms' │ ' 59.24 x' │
|
|
1157
|
+
│ Union │ 2000 │ ' 1258 ms' │ ' 25 ms' │ ' 50.32 x' │
|
|
1158
|
+
│ Vector4 │ 2000 │ ' 1513 ms' │ ' 21 ms' │ ' 72.05 x' │
|
|
1159
|
+
│ Matrix4 │ 2000 │ ' 850 ms' │ ' 11 ms' │ ' 77.27 x' │
|
|
1160
|
+
│ Literal_String │ 2000 │ ' 335 ms' │ ' 7 ms' │ ' 47.86 x' │
|
|
1161
|
+
│ Literal_Number │ 2000 │ ' 358 ms' │ ' 7 ms' │ ' 51.14 x' │
|
|
1162
|
+
│ Literal_Boolean │ 2000 │ ' 356 ms' │ ' 7 ms' │ ' 50.86 x' │
|
|
1163
|
+
│ Array_Number │ 2000 │ ' 689 ms' │ ' 9 ms' │ ' 76.56 x' │
|
|
1164
|
+
│ Array_String │ 2000 │ ' 728 ms' │ ' 12 ms' │ ' 60.67 x' │
|
|
1165
|
+
│ Array_Boolean │ 2000 │ ' 726 ms' │ ' 7 ms' │ ' 103.71 x' │
|
|
1166
|
+
│ Array_ObjectA │ 2000 │ ' 3631 ms' │ ' 35 ms' │ ' 103.74 x' │
|
|
1167
|
+
│ Array_ObjectB │ 2000 │ ' 3636 ms' │ ' 40 ms' │ ' 90.90 x' │
|
|
1168
|
+
│ Array_Tuple │ 2000 │ ' 2119 ms' │ ' 31 ms' │ ' 68.35 x' │
|
|
1169
|
+
│ Array_Union │ 2000 │ ' 1550 ms' │ ' 23 ms' │ ' 67.39 x' │
|
|
1170
|
+
│ Array_Vector4 │ 2000 │ ' 2200 ms' │ ' 18 ms' │ ' 122.22 x' │
|
|
1171
|
+
│ Array_Matrix4 │ 2000 │ ' 1494 ms' │ ' 14 ms' │ ' 106.71 x' │
|
|
1088
1172
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1089
1173
|
```
|
|
1090
1174
|
|
|
@@ -1098,31 +1182,31 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1098
1182
|
┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1099
1183
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1100
1184
|
├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1101
|
-
│ Number │ 1000000 │ '
|
|
1102
|
-
│ String │ 1000000 │ '
|
|
1103
|
-
│ Boolean │ 1000000 │ '
|
|
1104
|
-
│ Null │ 1000000 │ '
|
|
1105
|
-
│ RegEx │ 1000000 │ '
|
|
1106
|
-
│ ObjectA │ 1000000 │ '
|
|
1107
|
-
│ ObjectB │ 1000000 │ '
|
|
1108
|
-
│ Tuple │ 1000000 │ '
|
|
1109
|
-
│ Union │ 1000000 │ '
|
|
1110
|
-
│ Recursive │ 1000000 │ '
|
|
1111
|
-
│ Vector4 │ 1000000 │ '
|
|
1112
|
-
│ Matrix4 │ 1000000 │ '
|
|
1113
|
-
│ Literal_String │ 1000000 │ '
|
|
1114
|
-
│ Literal_Number │ 1000000 │ ' 46 ms' │ '
|
|
1115
|
-
│ Literal_Boolean │ 1000000 │ '
|
|
1116
|
-
│ Array_Number │ 1000000 │ '
|
|
1117
|
-
│ Array_String │ 1000000 │ '
|
|
1118
|
-
│ Array_Boolean │ 1000000 │ '
|
|
1119
|
-
│ Array_ObjectA │ 1000000 │ '
|
|
1120
|
-
│ Array_ObjectB │ 1000000 │ '
|
|
1121
|
-
│ Array_Tuple │ 1000000 │ '
|
|
1122
|
-
│ Array_Union │ 1000000 │ '
|
|
1123
|
-
│ Array_Recursive │ 1000000 │ '
|
|
1124
|
-
│ Array_Vector4 │ 1000000 │ '
|
|
1125
|
-
│ Array_Matrix4 │ 1000000 │ '
|
|
1185
|
+
│ Number │ 1000000 │ ' 28 ms' │ ' 6 ms' │ ' 6 ms' │ ' 1.00 x' │
|
|
1186
|
+
│ String │ 1000000 │ ' 25 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
|
|
1187
|
+
│ Boolean │ 1000000 │ ' 34 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │
|
|
1188
|
+
│ Null │ 1000000 │ ' 37 ms' │ ' 28 ms' │ ' 10 ms' │ ' 2.80 x' │
|
|
1189
|
+
│ RegEx │ 1000000 │ ' 162 ms' │ ' 50 ms' │ ' 37 ms' │ ' 1.35 x' │
|
|
1190
|
+
│ ObjectA │ 1000000 │ ' 550 ms' │ ' 38 ms' │ ' 22 ms' │ ' 1.73 x' │
|
|
1191
|
+
│ ObjectB │ 1000000 │ ' 1033 ms' │ ' 58 ms' │ ' 38 ms' │ ' 1.53 x' │
|
|
1192
|
+
│ Tuple │ 1000000 │ ' 126 ms' │ ' 24 ms' │ ' 14 ms' │ ' 1.71 x' │
|
|
1193
|
+
│ Union │ 1000000 │ ' 326 ms' │ ' 25 ms' │ ' 16 ms' │ ' 1.56 x' │
|
|
1194
|
+
│ Recursive │ 1000000 │ ' 3089 ms' │ ' 436 ms' │ ' 101 ms' │ ' 4.32 x' │
|
|
1195
|
+
│ Vector4 │ 1000000 │ ' 155 ms' │ ' 24 ms' │ ' 12 ms' │ ' 2.00 x' │
|
|
1196
|
+
│ Matrix4 │ 1000000 │ ' 579 ms' │ ' 41 ms' │ ' 28 ms' │ ' 1.46 x' │
|
|
1197
|
+
│ Literal_String │ 1000000 │ ' 50 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
|
|
1198
|
+
│ Literal_Number │ 1000000 │ ' 46 ms' │ ' 22 ms' │ ' 11 ms' │ ' 2.00 x' │
|
|
1199
|
+
│ Literal_Boolean │ 1000000 │ ' 48 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
|
|
1200
|
+
│ Array_Number │ 1000000 │ ' 424 ms' │ ' 32 ms' │ ' 19 ms' │ ' 1.68 x' │
|
|
1201
|
+
│ Array_String │ 1000000 │ ' 483 ms' │ ' 34 ms' │ ' 28 ms' │ ' 1.21 x' │
|
|
1202
|
+
│ Array_Boolean │ 1000000 │ ' 432 ms' │ ' 35 ms' │ ' 26 ms' │ ' 1.35 x' │
|
|
1203
|
+
│ Array_ObjectA │ 1000000 │ ' 13895 ms' │ ' 2440 ms' │ ' 1495 ms' │ ' 1.63 x' │
|
|
1204
|
+
│ Array_ObjectB │ 1000000 │ ' 16261 ms' │ ' 2633 ms' │ ' 2011 ms' │ ' 1.31 x' │
|
|
1205
|
+
│ Array_Tuple │ 1000000 │ ' 1741 ms' │ ' 98 ms' │ ' 66 ms' │ ' 1.48 x' │
|
|
1206
|
+
│ Array_Union │ 1000000 │ ' 4825 ms' │ ' 232 ms' │ ' 87 ms' │ ' 2.67 x' │
|
|
1207
|
+
│ Array_Recursive │ 1000000 │ ' 54158 ms' │ ' 6966 ms' │ ' 1173 ms' │ ' 5.94 x' │
|
|
1208
|
+
│ Array_Vector4 │ 1000000 │ ' 2577 ms' │ ' 99 ms' │ ' 48 ms' │ ' 2.06 x' │
|
|
1209
|
+
│ Array_Matrix4 │ 1000000 │ ' 12648 ms' │ ' 397 ms' │ ' 249 ms' │ ' 1.59 x' │
|
|
1126
1210
|
└──────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1127
1211
|
```
|
|
1128
1212
|
|
|
@@ -1136,12 +1220,12 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1136
1220
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1137
1221
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1138
1222
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1139
|
-
│ typebox/compiler │ '
|
|
1140
|
-
│ typebox/conditional │ '
|
|
1223
|
+
│ typebox/compiler │ ' 54 kb' │ ' 27 kb' │ '1.97 x' │
|
|
1224
|
+
│ typebox/conditional │ ' 44 kb' │ ' 17 kb' │ '2.45 x' │
|
|
1141
1225
|
│ typebox/format │ ' 0 kb' │ ' 0 kb' │ '2.66 x' │
|
|
1142
|
-
│ typebox/guard │ '
|
|
1143
|
-
│ typebox/value │ '
|
|
1144
|
-
│ typebox │ '
|
|
1226
|
+
│ typebox/guard │ ' 22 kb' │ ' 11 kb' │ '2.05 x' │
|
|
1227
|
+
│ typebox/value │ ' 78 kb' │ ' 36 kb' │ '2.13 x' │
|
|
1228
|
+
│ typebox │ ' 12 kb' │ ' 6 kb' │ '1.89 x' │
|
|
1145
1229
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1146
1230
|
```
|
|
1147
1231
|
|