@sinclair/typebox 0.24.42 → 0.24.44

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/guard/guard.js CHANGED
@@ -161,12 +161,12 @@ var TypeGuard;
161
161
  schema.allOf.length === 2 &&
162
162
  IsObject(schema.allOf[0]) &&
163
163
  IsString(schema.allOf[0].type) &&
164
- schema.allOf[0].type === 'number' &&
165
- schema.allOf[0].const === 0 &&
164
+ schema.allOf[0].type === 'boolean' &&
165
+ schema.allOf[0].const === false &&
166
166
  IsObject(schema.allOf[1]) &&
167
167
  IsString(schema.allOf[1].type) &&
168
- schema.allOf[1].type === 'number' &&
169
- schema.allOf[1].const === 1);
168
+ schema.allOf[1].type === 'boolean' &&
169
+ schema.allOf[1].const === true);
170
170
  }
171
171
  TypeGuard.TNever = TNever;
172
172
  /** Returns true if the given schema is TNull */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.24.42",
3
+ "version": "0.24.44",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -305,11 +305,11 @@ The following table lists the standard TypeBox types.
305
305
  ├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
306
306
  │ const T = Type.Never() │ type T = never │ const T = { │
307
307
  │ │ │ allOf: [{ │
308
- │ │ │ type: 'number'
309
- │ │ │ const: 0
308
+ │ │ │ type: 'boolean',
309
+ │ │ │ const: false
310
310
  │ │ │ }, { │
311
- │ │ │ type: 'number'
312
- │ │ │ const: 1
311
+ │ │ │ type: 'boolean',
312
+ │ │ │ const: true
313
313
  │ │ │ }] │
314
314
  │ │ │ } │
315
315
  │ │ │ │
@@ -1062,29 +1062,29 @@ This benchmark measures compilation performance for varying types. You can revie
1062
1062
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
1063
1063
  │ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
1064
1064
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
1065
- │ Number │ 2000 │ ' 410 ms' │ ' 10 ms' │ ' 41.00 x' │
1066
- │ String │ 2000 │ ' 321 ms' │ ' 8 ms' │ ' 40.13 x' │
1067
- │ Boolean │ 2000 │ ' 314 ms' │ ' 6 ms' │ ' 52.33 x' │
1068
- │ Null │ 2000 │ ' 273 ms' │ ' 6 ms' │ ' 45.50 x' │
1069
- │ RegEx │ 2000 │ ' 485 ms' │ ' 11 ms' │ ' 44.09 x' │
1070
- │ ObjectA │ 2000 │ ' 2867 ms' │ ' 41 ms' │ ' 69.93 x' │
1071
- │ ObjectB │ 2000 │ ' 3018 ms' │ ' 30 ms' │ ' 100.60 x' │
1072
- │ Tuple │ 2000 │ ' 1298 ms' │ ' 21 ms' │ ' 61.81 x' │
1073
- │ Union │ 2000 │ ' 1340 ms' │ ' 23 ms' │ ' 58.26 x' │
1074
- │ Vector4 │ 2000 │ ' 1794 ms' │ ' 22 ms' │ ' 81.55 x' │
1075
- │ Matrix4 │ 2000 │ ' 1037 ms' │ ' 12 ms' │ ' 86.42 x' │
1076
- │ Literal_String │ 2000 │ ' 380 ms' │ ' 9 ms' │ ' 42.22 x' │
1077
- │ Literal_Number │ 2000 │ ' 446 ms' │ ' 8 ms' │ ' 55.75 x' │
1078
- │ Literal_Boolean │ 2000 │ ' 400 ms' │ ' 4 ms' │ ' 100.00 x' │
1079
- │ Array_Number │ 2000 │ ' 764 ms' │ ' 6 ms' │ ' 127.33 x' │
1080
- │ Array_String │ 2000 │ ' 785 ms' │ ' 9 ms' │ ' 87.22 x' │
1081
- │ Array_Boolean │ 2000 │ ' 796 ms' │ ' 6 ms' │ ' 132.67 x' │
1082
- │ Array_ObjectA │ 2000 │ ' 3678 ms' │ ' 34 ms' │ ' 108.18 x' │
1083
- │ Array_ObjectB │ 2000 │ ' 3875 ms' │ ' 34 ms' │ ' 113.97 x' │
1084
- │ Array_Tuple │ 2000 │ ' 2231 ms' │ ' 15 ms' │ ' 148.73 x' │
1085
- │ Array_Union │ 2000 │ ' 1713 ms' │ ' 18 ms' │ ' 95.17 x' │
1086
- │ Array_Vector4 │ 2000 │ ' 2381 ms' │ ' 16 ms' │ ' 148.81 x' │
1087
- │ Array_Matrix4 │ 2000 │ ' 1644 ms' │ ' 14 ms' │ ' 117.43 x' │
1065
+ │ Number │ 2000 │ ' 384 ms' │ ' 9 ms' │ ' 42.67 x' │
1066
+ │ String │ 2000 │ ' 322 ms' │ ' 8 ms' │ ' 40.25 x' │
1067
+ │ Boolean │ 2000 │ ' 310 ms' │ ' 6 ms' │ ' 51.67 x' │
1068
+ │ Null │ 2000 │ ' 271 ms' │ ' 6 ms' │ ' 45.17 x' │
1069
+ │ RegEx │ 2000 │ ' 491 ms' │ ' 12 ms' │ ' 40.92 x' │
1070
+ │ ObjectA │ 2000 │ ' 2935 ms' │ ' 44 ms' │ ' 66.70 x' │
1071
+ │ ObjectB │ 2000 │ ' 3076 ms' │ ' 30 ms' │ ' 102.53 x' │
1072
+ │ Tuple │ 2000 │ ' 1274 ms' │ ' 22 ms' │ ' 57.91 x' │
1073
+ │ Union │ 2000 │ ' 1281 ms' │ ' 22 ms' │ ' 58.23 x' │
1074
+ │ Vector4 │ 2000 │ ' 1602 ms' │ ' 17 ms' │ ' 94.24 x' │
1075
+ │ Matrix4 │ 2000 │ ' 959 ms' │ ' 10 ms' │ ' 95.90 x' │
1076
+ │ Literal_String │ 2000 │ ' 337 ms' │ ' 6 ms' │ ' 56.17 x' │
1077
+ │ Literal_Number │ 2000 │ ' 376 ms' │ ' 5 ms' │ ' 75.20 x' │
1078
+ │ Literal_Boolean │ 2000 │ ' 370 ms' │ ' 5 ms' │ ' 74.00 x' │
1079
+ │ Array_Number │ 2000 │ ' 733 ms' │ ' 9 ms' │ ' 81.44 x' │
1080
+ │ Array_String │ 2000 │ ' 764 ms' │ ' 10 ms' │ ' 76.40 x' │
1081
+ │ Array_Boolean │ 2000 │ ' 818 ms' │ ' 6 ms' │ ' 136.33 x' │
1082
+ │ Array_ObjectA │ 2000 │ ' 3744 ms' │ ' 35 ms' │ ' 106.97 x' │
1083
+ │ Array_ObjectB │ 2000 │ ' 3893 ms' │ ' 34 ms' │ ' 114.50 x' │
1084
+ │ Array_Tuple │ 2000 │ ' 2229 ms' │ ' 16 ms' │ ' 139.31 x' │
1085
+ │ Array_Union │ 2000 │ ' 1705 ms' │ ' 18 ms' │ ' 94.72 x' │
1086
+ │ Array_Vector4 │ 2000 │ ' 2261 ms' │ ' 17 ms' │ ' 133.00 x' │
1087
+ │ Array_Matrix4 │ 2000 │ ' 1574 ms' │ ' 14 ms' │ ' 112.43 x' │
1088
1088
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
1089
1089
  ```
1090
1090
 
@@ -1098,31 +1098,31 @@ This benchmark measures validation performance for varying types. You can review
1098
1098
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
1099
1099
  │ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
1100
1100
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
1101
- │ Number │ 1000000 │ ' 29 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
1102
- │ String │ 1000000 │ ' 24 ms' │ ' 23 ms' │ ' 11 ms' │ ' 2.09 x' │
1103
- │ Boolean │ 1000000 │ ' 21 ms' │ ' 22 ms' │ ' 10 ms' │ ' 2.20 x' │
1104
- │ Null │ 1000000 │ ' 29 ms' │ ' 26 ms' │ ' 15 ms' │ ' 1.73 x' │
1105
- │ RegEx │ 1000000 │ ' 180 ms' │ ' 46 ms' │ ' 36 ms' │ ' 1.28 x' │
1106
- │ ObjectA │ 1000000 │ ' 548 ms' │ ' 36 ms' │ ' 24 ms' │ ' 1.50 x' │
1107
- │ ObjectB │ 1000000 │ ' 995 ms' │ ' 52 ms' │ ' 40 ms' │ ' 1.30 x' │
1108
- │ Tuple │ 1000000 │ ' 119 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
1109
- │ Union │ 1000000 │ ' 308 ms' │ ' 25 ms' │ ' 15 ms' │ ' 1.67 x' │
1110
- │ Recursive │ 1000000 │ ' 3405 ms' │ ' 458 ms' │ ' 214 ms' │ ' 2.14 x' │
1111
- │ Vector4 │ 1000000 │ ' 144 ms' │ ' 23 ms' │ ' 12 ms' │ ' 1.92 x' │
1112
- │ Matrix4 │ 1000000 │ ' 608 ms' │ ' 42 ms' │ ' 29 ms' │ ' 1.45 x' │
1113
- │ Literal_String │ 1000000 │ ' 46 ms' │ ' 21 ms' │ ' 10 ms' │ ' 2.10 x' │
1114
- │ Literal_Number │ 1000000 │ ' 48 ms' │ ' 20 ms' │ ' 9 ms' │ ' 2.22 x' │
1115
- │ Literal_Boolean │ 1000000 │ ' 50 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
1116
- │ Array_Number │ 1000000 │ ' 467 ms' │ ' 34 ms' │ ' 19 ms' │ ' 1.79 x' │
1117
- │ Array_String │ 1000000 │ ' 488 ms' │ ' 32 ms' │ ' 20 ms' │ ' 1.60 x' │
1118
- │ Array_Boolean │ 1000000 │ ' 476 ms' │ ' 34 ms' │ ' 24 ms' │ ' 1.42 x' │
1119
- │ Array_ObjectA │ 1000000 │ ' 14220 ms' │ ' 2819 ms' │ ' 1810 ms' │ ' 1.56 x' │
1120
- │ Array_ObjectB │ 1000000 │ ' 16344 ms' │ ' 3067 ms' │ ' 2147 ms' │ ' 1.43 x' │
1121
- │ Array_Tuple │ 1000000 │ ' 1702 ms' │ ' 92 ms' │ ' 71 ms' │ ' 1.30 x' │
1122
- │ Array_Union │ 1000000 │ ' 4754 ms' │ ' 249 ms' │ ' 89 ms' │ ' 2.80 x' │
1123
- │ Array_Recursive │ 1000000 │ ' 56465 ms' │ ' 6921 ms' │ ' 2411 ms' │ ' 2.87 x' │
1124
- │ Array_Vector4 │ 1000000 │ ' 1974 ms' │ ' 109 ms' │ ' 55 ms' │ ' 1.98 x' │
1125
- │ Array_Matrix4 │ 1000000 │ ' 10722 ms' │ ' 400 ms' │ ' 320 ms' │ ' 1.25 x' │
1101
+ │ Number │ 1000000 │ ' 37 ms' │ ' 5 ms' │ ' 5 ms' │ ' 1.00 x' │
1102
+ │ String │ 1000000 │ ' 31 ms' │ ' 24 ms' │ ' 13 ms' │ ' 1.85 x' │
1103
+ │ Boolean │ 1000000 │ ' 25 ms' │ ' 25 ms' │ ' 11 ms' │ ' 2.27 x' │
1104
+ │ Null │ 1000000 │ ' 32 ms' │ ' 26 ms' │ ' 10 ms' │ ' 2.60 x' │
1105
+ │ RegEx │ 1000000 │ ' 170 ms' │ ' 48 ms' │ ' 35 ms' │ ' 1.37 x' │
1106
+ │ ObjectA │ 1000000 │ ' 564 ms' │ ' 36 ms' │ ' 23 ms' │ ' 1.57 x' │
1107
+ │ ObjectB │ 1000000 │ ' 1000 ms' │ ' 56 ms' │ ' 40 ms' │ ' 1.40 x' │
1108
+ │ Tuple │ 1000000 │ ' 125 ms' │ ' 27 ms' │ ' 13 ms' │ ' 2.08 x' │
1109
+ │ Union │ 1000000 │ ' 316 ms' │ ' 27 ms' │ ' 14 ms' │ ' 1.93 x' │
1110
+ │ Recursive │ 1000000 │ ' 3308 ms' │ ' 415 ms' │ ' 183 ms' │ ' 2.27 x' │
1111
+ │ Vector4 │ 1000000 │ ' 135 ms' │ ' 27 ms' │ ' 12 ms' │ ' 2.25 x' │
1112
+ │ Matrix4 │ 1000000 │ ' 658 ms' │ ' 44 ms' │ ' 30 ms' │ ' 1.47 x' │
1113
+ │ Literal_String │ 1000000 │ ' 48 ms' │ ' 26 ms' │ ' 10 ms' │ ' 2.60 x' │
1114
+ │ Literal_Number │ 1000000 │ ' 49 ms' │ ' 31 ms' │ ' 9 ms' │ ' 3.44 x' │
1115
+ │ Literal_Boolean │ 1000000 │ ' 47 ms' │ ' 28 ms' │ ' 10 ms' │ ' 2.80 x' │
1116
+ │ Array_Number │ 1000000 │ ' 418 ms' │ ' 38 ms' │ ' 17 ms' │ ' 2.24 x' │
1117
+ │ Array_String │ 1000000 │ ' 466 ms' │ ' 35 ms' │ ' 22 ms' │ ' 1.59 x' │
1118
+ │ Array_Boolean │ 1000000 │ ' 403 ms' │ ' 41 ms' │ ' 24 ms' │ ' 1.71 x' │
1119
+ │ Array_ObjectA │ 1000000 │ ' 13596 ms' │ ' 2861 ms' │ ' 1759 ms' │ ' 1.63 x' │
1120
+ │ Array_ObjectB │ 1000000 │ ' 15767 ms' │ ' 2798 ms' │ ' 1991 ms' │ ' 1.41 x' │
1121
+ │ Array_Tuple │ 1000000 │ ' 1666 ms' │ ' 103 ms' │ ' 73 ms' │ ' 1.41 x' │
1122
+ │ Array_Union │ 1000000 │ ' 4738 ms' │ ' 229 ms' │ ' 87 ms' │ ' 2.63 x' │
1123
+ │ Array_Recursive │ 1000000 │ ' 56371 ms' │ ' 7315 ms' │ ' 2813 ms' │ ' 2.60 x' │
1124
+ │ Array_Vector4 │ 1000000 │ ' 2180 ms' │ ' 106 ms' │ ' 53 ms' │ ' 2.00 x' │
1125
+ │ Array_Matrix4 │ 1000000 │ ' 11795 ms' │ ' 384 ms' │ ' 313 ms' │ ' 1.23 x' │
1126
1126
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
1127
1127
  ```
1128
1128
 
@@ -1136,12 +1136,12 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
1136
1136
  ┌──────────────────────┬────────────┬────────────┬─────────────┐
1137
1137
  │ (index) │ Compiled │ Minified │ Compression │
1138
1138
  ├──────────────────────┼────────────┼────────────┼─────────────┤
1139
- │ typebox/compiler │ ' 48 kb' │ ' 24 kb' │ '2.00 x' │
1140
- │ typebox/conditional │ ' 41 kb' │ ' 16 kb' │ '2.47 x' │
1139
+ │ typebox/compiler │ ' 49 kb' │ ' 24 kb' │ '2.00 x' │
1140
+ │ typebox/conditional │ ' 42 kb' │ ' 17 kb' │ '2.46 x' │
1141
1141
  │ typebox/format │ ' 0 kb' │ ' 0 kb' │ '2.66 x' │
1142
- │ typebox/guard │ ' 20 kb' │ ' 9 kb' │ '2.08 x' │
1143
- │ typebox/value │ ' 68 kb' │ ' 31 kb' │ '2.15 x' │
1144
- │ typebox │ ' 11 kb' │ ' 5 kb' │ '1.91 x' │
1142
+ │ typebox/guard │ ' 21 kb' │ ' 10 kb' │ '2.07 x' │
1143
+ │ typebox/value │ ' 72 kb' │ ' 33 kb' │ '2.16 x' │
1144
+ │ typebox │ ' 11 kb' │ ' 6 kb' │ '1.91 x' │
1145
1145
  └──────────────────────┴────────────┴────────────┴─────────────┘
1146
1146
  ```
1147
1147
 
package/typebox.d.ts CHANGED
@@ -131,9 +131,11 @@ export interface TNever extends TSchema {
131
131
  [Kind]: 'Never';
132
132
  static: never;
133
133
  allOf: [{
134
- const: 0;
134
+ type: 'boolean';
135
+ const: false;
135
136
  }, {
136
- const: 1;
137
+ type: 'boolean';
138
+ const: true;
137
139
  }];
138
140
  }
139
141
  export interface TNull extends TSchema {
package/typebox.js CHANGED
@@ -159,8 +159,8 @@ class TypeBuilder {
159
159
  ...options,
160
160
  [exports.Kind]: 'Never',
161
161
  allOf: [
162
- { type: 'number', const: 0 },
163
- { type: 'number', const: 1 },
162
+ { type: 'boolean', const: false },
163
+ { type: 'boolean', const: true },
164
164
  ],
165
165
  });
166
166
  }
@@ -192,7 +192,11 @@ class TypeBuilder {
192
192
  Omit(schema, keys, options = {}) {
193
193
  const select = keys[exports.Kind] === 'Union' ? keys.anyOf.map((schema) => schema.const) : keys;
194
194
  const next = { ...this.Clone(schema), ...options, [exports.Hint]: 'Omit' };
195
- next.required = next.required ? next.required.filter((key) => !select.includes(key)) : undefined;
195
+ if (next.required) {
196
+ next.required = next.required.filter((key) => !select.includes(key));
197
+ if (next.required.length === 0)
198
+ delete next.required;
199
+ }
196
200
  for (const key of Object.keys(next.properties)) {
197
201
  if (select.includes(key))
198
202
  delete next.properties[key];
@@ -231,7 +235,11 @@ class TypeBuilder {
231
235
  Pick(schema, keys, options = {}) {
232
236
  const select = keys[exports.Kind] === 'Union' ? keys.anyOf.map((schema) => schema.const) : keys;
233
237
  const next = { ...this.Clone(schema), ...options, [exports.Hint]: 'Pick' };
234
- next.required = next.required ? next.required.filter((key) => select.includes(key)) : undefined;
238
+ if (next.required) {
239
+ next.required = next.required.filter((key) => select.includes(key));
240
+ if (next.required.length === 0)
241
+ delete next.required;
242
+ }
235
243
  for (const key of Object.keys(next.properties)) {
236
244
  if (!select.includes(key))
237
245
  delete next.properties[key];
@@ -263,7 +271,7 @@ class TypeBuilder {
263
271
  /** Creates a recursive object type */
264
272
  Recursive(callback, options = {}) {
265
273
  if (options.$id === undefined)
266
- options.$id = `type-${TypeOrdinal++}`;
274
+ options.$id = `T${TypeOrdinal++}`;
267
275
  const self = callback({ [exports.Kind]: 'Self', $ref: `${options.$id}` });
268
276
  self.$id = options.$id;
269
277
  return this.Create({ ...options, ...self });