@sinclair/typebox 0.28.12 → 0.28.14

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.
@@ -166,6 +166,12 @@ var TypeCompiler;
166
166
  function IsString(value) {
167
167
  return typeof value === 'string';
168
168
  }
169
+ // ----------------------------------------------------------------------
170
+ // SchemaGuards
171
+ // ----------------------------------------------------------------------
172
+ function IsAnyOrUnknown(schema) {
173
+ return schema[Types.Kind] === 'Any' || schema[Types.Kind] === 'Unknown';
174
+ }
169
175
  // -------------------------------------------------------------------
170
176
  // Polices
171
177
  // -------------------------------------------------------------------
@@ -194,13 +200,13 @@ var TypeCompiler;
194
200
  }
195
201
  function* Array(schema, references, value) {
196
202
  const expression = CreateExpression(schema.items, references, 'value');
197
- yield `Array.isArray(${value}) && ${value}.every(value => ${expression})`;
198
203
  if (IsNumber(schema.minItems))
199
204
  yield `${value}.length >= ${schema.minItems}`;
200
205
  if (IsNumber(schema.maxItems))
201
206
  yield `${value}.length <= ${schema.maxItems}`;
202
207
  if (schema.uniqueItems === true)
203
208
  yield `((function() { const set = new Set(); for(const element of ${value}) { const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true })())`;
209
+ yield `Array.isArray(${value}) && ${value}.every(value => ${expression})`;
204
210
  }
205
211
  function* BigInt(schema, references, value) {
206
212
  yield `(typeof ${value} === 'bigint')`;
@@ -308,7 +314,7 @@ var TypeCompiler;
308
314
  const property = schema.properties[knownKey];
309
315
  if (schema.required && schema.required.includes(knownKey)) {
310
316
  yield* Visit(property, references, memberExpression);
311
- if (Types.ExtendsUndefined.Check(property))
317
+ if (Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property))
312
318
  yield `('${knownKey}' in ${value})`;
313
319
  }
314
320
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.28.12",
3
+ "version": "0.28.14",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <h1>TypeBox</h1>
4
4
 
5
5
  <p>JSON Schema Type Builder with Static Type Resolution for TypeScript</p>
6
-
6
+
7
7
  <img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
8
8
 
9
9
  <br />
@@ -65,7 +65,7 @@ type T = Static<typeof T> // type T = {
65
65
 
66
66
  TypeBox is a runtime type builder that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
67
67
 
68
- This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
68
+ This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
69
69
 
70
70
  License MIT
71
71
 
@@ -145,23 +145,23 @@ type T = {
145
145
 
146
146
  const T = Type.Object({ // const T = {
147
147
  id: Type.String(), // type: 'object',
148
- name: Type.String(), // properties: {
149
- timestamp: Type.Integer() // id: {
150
- }) // type: 'string'
148
+ name: Type.String(), // properties: {
149
+ timestamp: Type.Integer() // id: {
150
+ }) // type: 'string'
151
151
  // },
152
- // name: {
153
- // type: 'string'
152
+ // name: {
153
+ // type: 'string'
154
154
  // },
155
- // timestamp: {
156
- // type: 'integer'
155
+ // timestamp: {
156
+ // type: 'integer'
157
157
  // }
158
- // },
158
+ // },
159
159
  // required: [
160
160
  // 'id',
161
161
  // 'name',
162
162
  // 'timestamp'
163
163
  // ]
164
- // }
164
+ // }
165
165
 
166
166
  //--------------------------------------------------------------------------------------------
167
167
  //
@@ -186,7 +186,7 @@ import { Value } from '@sinclair/typebox/value'
186
186
  function receive(value: T) { // ... as a Static Type
187
187
 
188
188
  if(Value.Check(T, value)) { // ... as a JSON Schema
189
-
189
+
190
190
  // ok...
191
191
  }
192
192
  }
@@ -196,7 +196,7 @@ function receive(value: T) { // ... as a Static Type
196
196
 
197
197
  ## Types
198
198
 
199
- TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
199
+ TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
200
200
 
201
201
  <a name='types-standard'></a>
202
202
 
@@ -645,22 +645,22 @@ You can pass JSON Schema options on the last argument of any type. Option hints
645
645
 
646
646
  ```typescript
647
647
  // String must be an email
648
- const T = Type.String({ // const T = {
648
+ const T = Type.String({ // const T = {
649
649
  format: 'email' // type: 'string',
650
- }) // format: 'email'
650
+ }) // format: 'email'
651
651
  // }
652
652
 
653
653
  // Mumber must be a multiple of 2
654
- const T = Type.Number({ // const T = {
655
- multipleOf: 2 // type: 'number',
656
- }) // multipleOf: 2
654
+ const T = Type.Number({ // const T = {
655
+ multipleOf: 2 // type: 'number',
656
+ }) // multipleOf: 2
657
657
  // }
658
658
 
659
659
  // Array must have at least 5 integer values
660
- const T = Type.Array(Type.Integer(), { // const T = {
660
+ const T = Type.Array(Type.Integer(), { // const T = {
661
661
  minItems: 5 // type: 'array',
662
- }) // minItems: 5,
663
- // items: {
662
+ }) // minItems: 5,
663
+ // items: {
664
664
  // type: 'integer'
665
665
  // }
666
666
  // }
@@ -737,7 +737,7 @@ const T = Type.String({ $id: 'T' }) // const T = {
737
737
  // $id: 'T',
738
738
  // type: 'string'
739
739
  // }
740
-
740
+
741
741
  const R = Type.Ref(T) // const R = {
742
742
  // $ref: 'T'
743
743
  // }
@@ -808,7 +808,7 @@ type T0 = Static<typeof T0> // type T0 = false
808
808
 
809
809
  type T1 = Static<typeof T1> // type T1 = number
810
810
 
811
- type T2 = Static<typeof T2> // type T2 = string
811
+ type T2 = Static<typeof T2> // type T2 = string
812
812
  ```
813
813
 
814
814
  <a name='types-template-literal'></a>
@@ -876,16 +876,16 @@ const T = Type.Object({ // const T = {
876
876
 
877
877
  const A = Type.Index(T, ['x']) // const A = { type: 'number' }
878
878
 
879
- const B = Type.Index(T, ['x', 'y']) // const B = {
879
+ const B = Type.Index(T, ['x', 'y']) // const B = {
880
880
  // anyOf: [
881
- // { type: 'number' },
881
+ // { type: 'number' },
882
882
  // { type: 'string' }
883
883
  // ]
884
884
  // }
885
885
 
886
- const C = Type.Index(T, Type.KeyOf(T)) // const C = {
886
+ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
887
887
  // anyOf: [
888
- // { type: 'number' },
888
+ // { type: 'number' },
889
889
  // { type: 'string' },
890
890
  // { type: 'boolean' }
891
891
  // ]
@@ -987,7 +987,7 @@ import { Type, TypeGuard } from '@sinclair/typebox'
987
987
  const T = Type.String()
988
988
 
989
989
  if(TypeGuard.TString(T)) {
990
-
990
+
991
991
  // T is TString
992
992
  }
993
993
  ```
@@ -1012,12 +1012,12 @@ const T = Type.Object({ // const T = {
1012
1012
  // }
1013
1013
 
1014
1014
  const U = Type.Strict(T) // const U = {
1015
- // type: 'object',
1016
- // properties: {
1017
- // name: {
1018
- // type: 'string'
1019
- // }
1020
- // }
1015
+ // type: 'object',
1016
+ // properties: {
1017
+ // name: {
1018
+ // type: 'string'
1019
+ // }
1020
+ // }
1021
1021
  // }
1022
1022
  ```
1023
1023
 
@@ -1183,21 +1183,21 @@ const R = [...Value.Errors(T, { x: '42' })] // const R = [{
1183
1183
  Use the Mutate function to perform a deep mutable value assignment while retaining internal references.
1184
1184
 
1185
1185
  ```typescript
1186
- const Y = { z: 1 } // const Y = { z: 1 }
1186
+ const Y = { z: 1 } // const Y = { z: 1 }
1187
1187
 
1188
1188
  const X = { y: Y } // const X = { y: { z: 1 } }
1189
1189
 
1190
- const A = { x: X } // const A = { x: { y: { z: 1 } } }
1190
+ const A = { x: X } // const A = { x: { y: { z: 1 } } }
1191
1191
 
1192
1192
 
1193
- Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
1193
+ Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
1194
1194
 
1195
- const R0 = A.x.y.z === 2 // const R0 = 2
1195
+ const R0 = A.x.y.z === 2 // const R0 = true
1196
1196
 
1197
1197
  const R1 = A.x.y === Y // const R1 = true
1198
1198
 
1199
1199
  const R2 = A.x === X // const R2 = true
1200
- ```
1200
+ ```
1201
1201
 
1202
1202
  <a name='values-pointer'></a>
1203
1203
 
@@ -1241,29 +1241,29 @@ import addFormats from 'ajv-formats'
1241
1241
  import Ajv from 'ajv'
1242
1242
 
1243
1243
  const ajv = addFormats(new Ajv({}), [
1244
- 'date-time',
1245
- 'time',
1246
- 'date',
1247
- 'email',
1248
- 'hostname',
1249
- 'ipv4',
1250
- 'ipv6',
1251
- 'uri',
1252
- 'uri-reference',
1244
+ 'date-time',
1245
+ 'time',
1246
+ 'date',
1247
+ 'email',
1248
+ 'hostname',
1249
+ 'ipv4',
1250
+ 'ipv6',
1251
+ 'uri',
1252
+ 'uri-reference',
1253
1253
  'uuid',
1254
- 'uri-template',
1255
- 'json-pointer',
1256
- 'relative-json-pointer',
1254
+ 'uri-template',
1255
+ 'json-pointer',
1256
+ 'relative-json-pointer',
1257
1257
  'regex'
1258
1258
  ])
1259
1259
 
1260
- const C = ajv.compile(Type.Object({
1260
+ const C = ajv.compile(Type.Object({
1261
1261
  x: Type.Number(),
1262
1262
  y: Type.Number(),
1263
1263
  z: Type.Number()
1264
1264
  }))
1265
1265
 
1266
- const R = C({ x: 1, y: 2, z: 3 }) // const R = true
1266
+ const R = C({ x: 1, y: 2, z: 3 }) // const R = true
1267
1267
  ```
1268
1268
 
1269
1269
  <a name='typecheck-typecompiler'></a>
@@ -1350,15 +1350,15 @@ import { TypeSystem } from '@sinclair/typebox/system'
1350
1350
  Use the `Type(...)` function to create custom types. This function lets you specify custom value assertion logic and will return a type factory function which is used to instance the type. This function accepts two generic arguments, the first is the inference type, the second is options used to constrain the type. The following creates a Vector type.
1351
1351
 
1352
1352
  ```typescript
1353
- type VectorOptions = { abs: boolean }
1353
+ type VectorOptions = { abs: boolean }
1354
1354
 
1355
1355
  type Vector = { x: number, y: number }
1356
1356
 
1357
1357
  const Vector = TypeSystem.Type<Vector, VectorOptions>('Vector', (options, value) => {
1358
1358
  return (
1359
1359
  typeof value === 'object' && value !== null &&
1360
- 'x' in value && typeof value.x === 'number' &&
1361
- 'y' in value && typeof value.y === 'number' &&
1360
+ 'x' in value && typeof value.x === 'number' &&
1361
+ 'y' in value && typeof value.y === 'number' &&
1362
1362
  (options.abs ? (value.x === Math.abs(value.x) && value.y === Math.abs(value.y)) : true)
1363
1363
  )
1364
1364
  })
@@ -1383,7 +1383,7 @@ Use the `Format(...)` function to create a custom string format. The following c
1383
1383
  ```typescript
1384
1384
  TypeSystem.Format('lowercase', value => value === value.toLowerCase()) // format should be lowercase
1385
1385
 
1386
- const T = Type.String({ format: 'lowercase' })
1386
+ const T = Type.String({ format: 'lowercase' })
1387
1387
 
1388
1388
  const A = Value.Check(T, 'Hello') // const A = false
1389
1389
 
@@ -1407,13 +1407,13 @@ TypeSystem.ExactOptionalPropertyTypes = true
1407
1407
  //
1408
1408
  // const A: {} = [] - allowed in TS
1409
1409
 
1410
- TypeSystem.AllowArrayObjects = true
1410
+ TypeSystem.AllowArrayObjects = true
1411
1411
 
1412
1412
  // Allow numeric values to be NaN or + or - Infinity (default is false)
1413
1413
  //
1414
1414
  // const A: number = NaN - allowed in TS
1415
1415
 
1416
- TypeSystem.AllowNaN = true
1416
+ TypeSystem.AllowNaN = true
1417
1417
  ```
1418
1418
 
1419
1419
  <a name='workbench'></a>
@@ -1441,7 +1441,8 @@ The following is a list of community packages that provide general tooling and f
1441
1441
  | [elysia](https://github.com/elysiajs/elysia) | Fast and friendly Bun web framework |
1442
1442
  | [fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox) | Fastify TypeBox integration with the Fastify Type Provider |
1443
1443
  | [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
1444
- | [ts2typebox](https://github.com/xddq/ts2typebox) | Cli tool to generate TypeBox JSON schemas based on your Typescript types |
1444
+ | [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from JSON schemas |
1445
+ | [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
1445
1446
 
1446
1447
  <a name='benchmark'></a>
1447
1448
 
@@ -1461,35 +1462,35 @@ This benchmark measures compilation performance for varying types. You can revie
1461
1462
  ┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
1462
1463
  │ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
1463
1464
  ├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
1464
- │ Literal_String │ 1000 │ ' 243 ms' │ ' 8 ms' │ ' 30.38 x' │
1465
- │ Literal_Number │ 1000 │ ' 195 ms' │ ' 5 ms' │ ' 39.00 x' │
1466
- │ Literal_Boolean │ 1000 │ ' 162 ms' │ ' 4 ms' │ ' 40.50 x' │
1467
- │ Primitive_Number │ 1000 │ ' 168 ms' │ ' 6 ms' │ ' 28.00 x' │
1468
- │ Primitive_String │ 1000 │ ' 164 ms' │ ' 5 ms' │ ' 32.80 x' │
1469
- │ Primitive_String_Pattern │ 1000 │ ' 214 ms' │ ' 9 ms' │ ' 23.78 x' │
1470
- │ Primitive_Boolean │ 1000 │ ' 132 ms' │ ' 4 ms' │ ' 33.00 x' │
1471
- │ Primitive_Null │ 1000 │ ' 148 ms' │ ' 4 ms' │ ' 37.00 x' │
1472
- │ Object_Unconstrained │ 1000 │ ' 1158 ms' │ ' 30 ms' │ ' 38.60 x' │
1473
- │ Object_Constrained │ 1000 │ ' 1263 ms' │ ' 25 ms' │ ' 50.52 x' │
1474
- │ Object_Vector3 │ 1000 │ ' 384 ms' │ ' 7 ms' │ ' 54.86 x' │
1475
- │ Object_Box3D │ 1000 │ ' 1932 ms' │ ' 27 ms' │ ' 71.56 x' │
1476
- │ Tuple_Primitive │ 1000 │ ' 478 ms' │ ' 14 ms' │ ' 34.14 x' │
1477
- │ Tuple_Object │ 1000 │ ' 1232 ms' │ ' 14 ms' │ ' 88.00 x' │
1478
- │ Composite_Intersect │ 1000 │ ' 671 ms' │ ' 17 ms' │ ' 39.47 x' │
1479
- │ Composite_Union │ 1000 │ ' 537 ms' │ ' 18 ms' │ ' 29.83 x' │
1480
- │ Math_Vector4 │ 1000 │ ' 816 ms' │ ' 14 ms' │ ' 58.29 x' │
1481
- │ Math_Matrix4 │ 1000 │ ' 417 ms' │ ' 6 ms' │ ' 69.50 x' │
1482
- │ Array_Primitive_Number │ 1000 │ ' 378 ms' │ ' 5 ms' │ ' 75.60 x' │
1483
- │ Array_Primitive_String │ 1000 │ ' 353 ms' │ ' 6 ms' │ ' 58.83 x' │
1484
- │ Array_Primitive_Boolean │ 1000 │ ' 279 ms' │ ' 5 ms' │ ' 55.80 x' │
1485
- │ Array_Object_Unconstrained │ 1000 │ ' 1794 ms' │ ' 20 ms' │ ' 89.70 x' │
1486
- │ Array_Object_Constrained │ 1000 │ ' 1586 ms' │ ' 19 ms' │ ' 83.47 x' │
1487
- │ Array_Tuple_Primitive │ 1000 │ ' 791 ms' │ ' 13 ms' │ ' 60.85 x' │
1488
- │ Array_Tuple_Object │ 1000 │ ' 1638 ms' │ ' 17 ms' │ ' 96.35 x' │
1489
- │ Array_Composite_Intersect │ 1000 │ ' 796 ms' │ ' 17 ms' │ ' 46.82 x' │
1490
- │ Array_Composite_Union │ 1000 │ ' 798 ms' │ ' 15 ms' │ ' 53.20 x' │
1491
- │ Array_Math_Vector4 │ 1000 │ ' 1127 ms' │ ' 14 ms' │ ' 80.50 x' │
1492
- │ Array_Math_Matrix4 │ 1000 │ ' 677 ms' │ ' 9 ms' │ ' 75.22 x' │
1465
+ │ Literal_String │ 1000 │ ' 230 ms' │ ' 7 ms' │ ' 32.86 x' │
1466
+ │ Literal_Number │ 1000 │ ' 171 ms' │ ' 4 ms' │ ' 42.75 x' │
1467
+ │ Literal_Boolean │ 1000 │ ' 148 ms' │ ' 4 ms' │ ' 37.00 x' │
1468
+ │ Primitive_Number │ 1000 │ ' 160 ms' │ ' 6 ms' │ ' 26.67 x' │
1469
+ │ Primitive_String │ 1000 │ ' 149 ms' │ ' 6 ms' │ ' 24.83 x' │
1470
+ │ Primitive_String_Pattern │ 1000 │ ' 199 ms' │ ' 9 ms' │ ' 22.11 x' │
1471
+ │ Primitive_Boolean │ 1000 │ ' 126 ms' │ ' 3 ms' │ ' 42.00 x' │
1472
+ │ Primitive_Null │ 1000 │ ' 141 ms' │ ' 4 ms' │ ' 35.25 x' │
1473
+ │ Object_Unconstrained │ 1000 │ ' 1105 ms' │ ' 27 ms' │ ' 40.93 x' │
1474
+ │ Object_Constrained │ 1000 │ ' 1178 ms' │ ' 22 ms' │ ' 53.55 x' │
1475
+ │ Object_Vector3 │ 1000 │ ' 368 ms' │ ' 8 ms' │ ' 46.00 x' │
1476
+ │ Object_Box3D │ 1000 │ ' 1668 ms' │ ' 28 ms' │ ' 59.57 x' │
1477
+ │ Tuple_Primitive │ 1000 │ ' 446 ms' │ ' 12 ms' │ ' 37.17 x' │
1478
+ │ Tuple_Object │ 1000 │ ' 1146 ms' │ ' 15 ms' │ ' 76.40 x' │
1479
+ │ Composite_Intersect │ 1000 │ ' 661 ms' │ ' 18 ms' │ ' 36.72 x' │
1480
+ │ Composite_Union │ 1000 │ ' 513 ms' │ ' 17 ms' │ ' 30.18 x' │
1481
+ │ Math_Vector4 │ 1000 │ ' 767 ms' │ ' 10 ms' │ ' 76.70 x' │
1482
+ │ Math_Matrix4 │ 1000 │ ' 396 ms' │ ' 10 ms' │ ' 39.60 x' │
1483
+ │ Array_Primitive_Number │ 1000 │ ' 353 ms' │ ' 8 ms' │ ' 44.13 x' │
1484
+ │ Array_Primitive_String │ 1000 │ ' 358 ms' │ ' 5 ms' │ ' 71.60 x' │
1485
+ │ Array_Primitive_Boolean │ 1000 │ ' 265 ms' │ ' 3 ms' │ ' 88.33 x' │
1486
+ │ Array_Object_Unconstrained │ 1000 │ ' 1476 ms' │ ' 19 ms' │ ' 77.68 x' │
1487
+ │ Array_Object_Constrained │ 1000 │ ' 1698 ms' │ ' 20 ms' │ ' 84.90 x' │
1488
+ │ Array_Tuple_Primitive │ 1000 │ ' 654 ms' │ ' 9 ms' │ ' 72.67 x' │
1489
+ │ Array_Tuple_Object │ 1000 │ ' 1492 ms' │ ' 15 ms' │ ' 99.47 x' │
1490
+ │ Array_Composite_Intersect │ 1000 │ ' 1045 ms' │ ' 16 ms' │ ' 65.31 x' │
1491
+ │ Array_Composite_Union │ 1000 │ ' 702 ms' │ ' 14 ms' │ ' 50.14 x' │
1492
+ │ Array_Math_Vector4 │ 1000 │ ' 1016 ms' │ ' 12 ms' │ ' 84.67 x' │
1493
+ │ Array_Math_Matrix4 │ 1000 │ ' 621 ms' │ ' 5 ms' │ ' 124.20 x' │
1493
1494
  └────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
1494
1495
  ```
1495
1496
 
@@ -1503,37 +1504,37 @@ This benchmark measures validation performance for varying types. You can review
1503
1504
  ┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
1504
1505
  │ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
1505
1506
  ├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
1506
- │ Literal_String │ 1000000 │ ' 24 ms' │ ' 5 ms' │ ' 4 ms' │ ' 1.25 x' │
1507
- │ Literal_Number │ 1000000 │ ' 21 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
1508
- │ Literal_Boolean │ 1000000 │ ' 19 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
1509
- │ Primitive_Number │ 1000000 │ ' 24 ms' │ ' 18 ms' │ ' 10 ms' │ ' 1.80 x' │
1510
- │ Primitive_String │ 1000000 │ ' 26 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1511
- │ Primitive_String_Pattern │ 1000000 │ ' 159 ms' │ ' 45 ms' │ ' 36 ms' │ ' 1.25 x' │
1512
- │ Primitive_Boolean │ 1000000 │ ' 22 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
1513
- │ Primitive_Null │ 1000000 │ ' 23 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1514
- │ Object_Unconstrained │ 1000000 │ ' 914 ms' │ ' 34 ms' │ ' 26 ms' │ ' 1.31 x' │
1515
- │ Object_Constrained │ 1000000 │ ' 1095 ms' │ ' 50 ms' │ ' 38 ms' │ ' 1.32 x' │
1516
- │ Object_Vector3 │ 1000000 │ ' 414 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
1517
- │ Object_Box3D │ 1000000 │ ' 1933 ms' │ ' 55 ms' │ ' 53 ms' │ ' 1.04 x' │
1518
- │ Object_Recursive │ 1000000 │ ' 4995 ms' │ ' 378 ms' │ ' 177 ms' │ ' 2.14 x' │
1519
- │ Tuple_Primitive │ 1000000 │ ' 168 ms' │ ' 24 ms' │ ' 13 ms' │ ' 1.85 x' │
1520
- │ Tuple_Object │ 1000000 │ ' 681 ms' │ ' 31 ms' │ ' 19 ms' │ ' 1.63 x' │
1521
- │ Composite_Intersect │ 1000000 │ ' 718 ms' │ ' 25 ms' │ ' 15 ms' │ ' 1.67 x' │
1522
- │ Composite_Union │ 1000000 │ ' 511 ms' │ ' 24 ms' │ ' 14 ms' │ ' 1.71 x' │
1523
- │ Math_Vector4 │ 1000000 │ ' 285 ms' │ ' 23 ms' │ ' 12 ms' │ ' 1.92 x' │
1524
- │ Math_Matrix4 │ 1000000 │ ' 1197 ms' │ ' 39 ms' │ ' 28 ms' │ ' 1.39 x' │
1525
- │ Array_Primitive_Number │ 1000000 │ ' 294 ms' │ ' 22 ms' │ ' 12 ms' │ ' 1.83 x' │
1526
- │ Array_Primitive_String │ 1000000 │ ' 251 ms' │ ' 22 ms' │ ' 14 ms' │ ' 1.57 x' │
1527
- │ Array_Primitive_Boolean │ 1000000 │ ' 131 ms' │ ' 22 ms' │ ' 14 ms' │ ' 1.57 x' │
1528
- │ Array_Object_Unconstrained │ 1000000 │ ' 5249 ms' │ ' 69 ms' │ ' 56 ms' │ ' 1.23 x' │
1529
- │ Array_Object_Constrained │ 1000000 │ ' 5299 ms' │ ' 127 ms' │ ' 123 ms' │ ' 1.03 x' │
1530
- │ Array_Object_Recursive │ 1000000 │ ' 19609 ms' │ ' 1711 ms' │ ' 608 ms' │ ' 2.81 x' │
1531
- │ Array_Tuple_Primitive │ 1000000 │ ' 734 ms' │ ' 38 ms' │ ' 30 ms' │ ' 1.27 x' │
1532
- │ Array_Tuple_Object │ 1000000 │ ' 2843 ms' │ ' 63 ms' │ ' 51 ms' │ ' 1.24 x' │
1533
- │ Array_Composite_Intersect │ 1000000 │ ' 2794 ms' │ ' 43 ms' │ ' 36 ms' │ ' 1.19 x' │
1534
- │ Array_Composite_Union │ 1000000 │ ' 1892 ms' │ ' 66 ms' │ ' 33 ms' │ ' 2.00 x' │
1535
- │ Array_Math_Vector4 │ 1000000 │ ' 1177 ms' │ ' 37 ms' │ ' 23 ms' │ ' 1.61 x' │
1536
- │ Array_Math_Matrix4 │ 1000000 │ ' 5115 ms' │ ' 110 ms' │ ' 85 ms' │ ' 1.29 x' │
1507
+ │ Literal_String │ 1000000 │ ' 22 ms' │ ' 5 ms' │ ' 4 ms' │ ' 1.25 x' │
1508
+ │ Literal_Number │ 1000000 │ ' 19 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1509
+ │ Literal_Boolean │ 1000000 │ ' 18 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1510
+ │ Primitive_Number │ 1000000 │ ' 23 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1511
+ │ Primitive_String │ 1000000 │ ' 23 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
1512
+ │ Primitive_String_Pattern │ 1000000 │ ' 171 ms' │ ' 42 ms' │ ' 36 ms' │ ' 1.17 x' │
1513
+ │ Primitive_Boolean │ 1000000 │ ' 20 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
1514
+ │ Primitive_Null │ 1000000 │ ' 21 ms' │ ' 16 ms' │ ' 8 ms' │ ' 2.00 x' │
1515
+ │ Object_Unconstrained │ 1000000 │ ' 1099 ms' │ ' 31 ms' │ ' 25 ms' │ ' 1.24 x' │
1516
+ │ Object_Constrained │ 1000000 │ ' 1224 ms' │ ' 51 ms' │ ' 36 ms' │ ' 1.42 x' │
1517
+ │ Object_Vector3 │ 1000000 │ ' 420 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │
1518
+ │ Object_Box3D │ 1000000 │ ' 2012 ms' │ ' 53 ms' │ ' 43 ms' │ ' 1.23 x' │
1519
+ │ Object_Recursive │ 1000000 │ ' 5080 ms' │ ' 320 ms' │ ' 150 ms' │ ' 2.13 x' │
1520
+ │ Tuple_Primitive │ 1000000 │ ' 154 ms' │ ' 20 ms' │ ' 12 ms' │ ' 1.67 x' │
1521
+ │ Tuple_Object │ 1000000 │ ' 749 ms' │ ' 27 ms' │ ' 18 ms' │ ' 1.50 x' │
1522
+ │ Composite_Intersect │ 1000000 │ ' 775 ms' │ ' 24 ms' │ ' 14 ms' │ ' 1.71 x' │
1523
+ │ Composite_Union │ 1000000 │ ' 533 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │
1524
+ │ Math_Vector4 │ 1000000 │ ' 275 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1525
+ │ Math_Matrix4 │ 1000000 │ ' 1136 ms' │ ' 37 ms' │ ' 26 ms' │ ' 1.42 x' │
1526
+ │ Array_Primitive_Number │ 1000000 │ ' 316 ms' │ ' 20 ms' │ ' 12 ms' │ ' 1.67 x' │
1527
+ │ Array_Primitive_String │ 1000000 │ ' 239 ms' │ ' 20 ms' │ ' 12 ms' │ ' 1.67 x' │
1528
+ │ Array_Primitive_Boolean │ 1000000 │ ' 151 ms' │ ' 20 ms' │ ' 15 ms' │ ' 1.33 x' │
1529
+ │ Array_Object_Unconstrained │ 1000000 │ ' 5809 ms' │ ' 64 ms' │ ' 56 ms' │ ' 1.14 x' │
1530
+ │ Array_Object_Constrained │ 1000000 │ ' 6210 ms' │ ' 123 ms' │ ' 101 ms' │ ' 1.22 x' │
1531
+ │ Array_Object_Recursive │ 1000000 │ ' 21779 ms' │ ' 1466 ms' │ ' 548 ms' │ ' 2.68 x' │
1532
+ │ Array_Tuple_Primitive │ 1000000 │ ' 730 ms' │ ' 36 ms' │ ' 29 ms' │ ' 1.24 x' │
1533
+ │ Array_Tuple_Object │ 1000000 │ ' 3259 ms' │ ' 63 ms' │ ' 49 ms' │ ' 1.29 x' │
1534
+ │ Array_Composite_Intersect │ 1000000 │ ' 3276 ms' │ ' 44 ms' │ ' 34 ms' │ ' 1.29 x' │
1535
+ │ Array_Composite_Union │ 1000000 │ ' 2279 ms' │ ' 64 ms' │ ' 31 ms' │ ' 2.06 x' │
1536
+ │ Array_Math_Vector4 │ 1000000 │ ' 1139 ms' │ ' 36 ms' │ ' 23 ms' │ ' 1.57 x' │
1537
+ │ Array_Math_Matrix4 │ 1000000 │ ' 4924 ms' │ ' 110 ms' │ ' 92 ms' │ ' 1.20 x' │
1537
1538
  └────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
1538
1539
  ```
1539
1540
 
@@ -1547,11 +1548,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
1547
1548
  ┌──────────────────────┬────────────┬────────────┬─────────────┐
1548
1549
  │ (index) │ Compiled │ Minified │ Compression │
1549
1550
  ├──────────────────────┼────────────┼────────────┼─────────────┤
1550
- │ typebox/compiler │ '127.1 kb' │ ' 56.7 kb' │ '2.24 x' │
1551
- │ typebox/errors │ '110.9 kb' │ ' 48.9 kb' │ '2.27 x' │
1552
- │ typebox/system │ ' 76.3 kb' │ ' 31.2 kb' │ '2.44 x' │
1553
- │ typebox/value │ '176.8 kb' │ ' 76.5 kb' │ '2.31 x' │
1554
- │ typebox │ ' 75.2 kb' │ ' 30.8 kb' │ '2.44 x' │
1551
+ │ typebox/compiler │ '128.0 kb' │ ' 56.9 kb' │ '2.25 x' │
1552
+ │ typebox/errors │ '111.6 kb' │ ' 49.1 kb' │ '2.27 x' │
1553
+ │ typebox/system │ ' 77.0 kb' │ ' 31.5 kb' │ '2.45 x' │
1554
+ │ typebox/value │ '177.7 kb' │ ' 76.8 kb' │ '2.31 x' │
1555
+ │ typebox │ ' 75.9 kb' │ ' 31.0 kb' │ '2.45 x' │
1555
1556
  └──────────────────────┴────────────┴────────────┴─────────────┘
1556
1557
  ```
1557
1558
 
package/value/check.js CHANGED
@@ -66,6 +66,12 @@ var ValueCheck;
66
66
  return value !== undefined;
67
67
  }
68
68
  // ----------------------------------------------------------------------
69
+ // SchemaGuards
70
+ // ----------------------------------------------------------------------
71
+ function IsAnyOrUnknown(schema) {
72
+ return schema[Types.Kind] === 'Any' || schema[Types.Kind] === 'Unknown';
73
+ }
74
+ // ----------------------------------------------------------------------
69
75
  // Policies
70
76
  // ----------------------------------------------------------------------
71
77
  function IsExactOptionalProperty(value, key) {
@@ -254,7 +260,7 @@ var ValueCheck;
254
260
  if (!Visit(property, references, value[knownKey])) {
255
261
  return false;
256
262
  }
257
- if (Types.ExtendsUndefined.Check(property) && !(knownKey in value)) {
263
+ if ((Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property)) && !(knownKey in value)) {
258
264
  return false;
259
265
  }
260
266
  }