@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 +4 -4
- package/package.json +1 -1
- package/readme.md +57 -57
- package/typebox.d.ts +4 -2
- package/typebox.js +13 -5
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 === '
|
|
165
|
-
schema.allOf[0].const ===
|
|
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 === '
|
|
169
|
-
schema.allOf[1].const ===
|
|
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
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: '
|
|
309
|
-
│ │ │ const:
|
|
308
|
+
│ │ │ type: 'boolean', │
|
|
309
|
+
│ │ │ const: false │
|
|
310
310
|
│ │ │ }, { │
|
|
311
|
-
│ │ │ type: '
|
|
312
|
-
│ │ │ const:
|
|
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 │ '
|
|
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 │ '
|
|
1075
|
-
│ Matrix4 │ 2000 │ '
|
|
1076
|
-
│ Literal_String │ 2000 │ '
|
|
1077
|
-
│ Literal_Number │ 2000 │ '
|
|
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 │ '
|
|
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 │ '
|
|
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 │ '
|
|
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 │ '
|
|
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 │ '
|
|
1140
|
-
│ typebox/conditional │ '
|
|
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 │ '
|
|
1143
|
-
│ typebox/value │ '
|
|
1144
|
-
│ typebox │ ' 11 kb' │ '
|
|
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
|
-
|
|
134
|
+
type: 'boolean';
|
|
135
|
+
const: false;
|
|
135
136
|
}, {
|
|
136
|
-
|
|
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: '
|
|
163
|
-
{ type: '
|
|
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
|
-
|
|
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
|
-
|
|
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 = `
|
|
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 });
|