@sinclair/typebox 0.26.0-dev.3 → 0.26.0-dev.5
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 +9 -4
- package/compiler/compiler.js +121 -97
- package/errors/errors.d.ts +5 -1
- package/errors/errors.js +173 -157
- package/package.json +1 -1
- package/readme.md +70 -71
- package/typebox.d.ts +24 -27
- package/typebox.js +115 -166
- package/value/cast.d.ts +6 -2
- package/value/cast.js +130 -111
- package/value/check.d.ts +5 -1
- package/value/check.js +168 -154
- package/value/convert.d.ts +6 -6
- package/value/convert.js +83 -74
- package/value/create.d.ts +6 -2
- package/value/create.js +102 -77
- package/value/value.d.ts +13 -3
- package/value/value.js +15 -15
package/readme.md
CHANGED
|
@@ -676,7 +676,7 @@ const BooleanVector = Vector(Type.Boolean()) // const BooleanVector = {
|
|
|
676
676
|
|
|
677
677
|
### Reference Types
|
|
678
678
|
|
|
679
|
-
Reference types are supported with `Type.Ref(...)`.
|
|
679
|
+
Reference types are supported with `Type.Ref(...)`.
|
|
680
680
|
|
|
681
681
|
```typescript
|
|
682
682
|
const T = Type.String({ $id: 'T' }) // const T = {
|
|
@@ -687,11 +687,6 @@ const T = Type.String({ $id: 'T' }) // const T = {
|
|
|
687
687
|
const R = Type.Ref(T) // const R = {
|
|
688
688
|
// $ref: 'T'
|
|
689
689
|
// }
|
|
690
|
-
|
|
691
|
-
const U = Type.Deref(R) // const U = {
|
|
692
|
-
// $id: 'T',
|
|
693
|
-
// type: 'string'
|
|
694
|
-
// }
|
|
695
690
|
```
|
|
696
691
|
|
|
697
692
|
<a name='types-recursive'></a>
|
|
@@ -1222,33 +1217,37 @@ For additional comparative benchmarks, please refer to [typescript-runtime-type-
|
|
|
1222
1217
|
This benchmark measures compilation performance for varying types. You can review this benchmark [here](https://github.com/sinclairzx81/typebox/blob/master/benchmark/measurement/module/compile.ts).
|
|
1223
1218
|
|
|
1224
1219
|
```typescript
|
|
1225
|
-
|
|
1226
|
-
│
|
|
1227
|
-
|
|
1228
|
-
│
|
|
1229
|
-
│
|
|
1230
|
-
│
|
|
1231
|
-
│
|
|
1232
|
-
│
|
|
1233
|
-
│
|
|
1234
|
-
│
|
|
1235
|
-
│
|
|
1236
|
-
│
|
|
1237
|
-
│
|
|
1238
|
-
│
|
|
1239
|
-
│
|
|
1240
|
-
│
|
|
1241
|
-
│
|
|
1242
|
-
│
|
|
1243
|
-
│
|
|
1244
|
-
│
|
|
1245
|
-
│
|
|
1246
|
-
│
|
|
1247
|
-
│
|
|
1248
|
-
│
|
|
1249
|
-
│
|
|
1250
|
-
│
|
|
1251
|
-
|
|
1220
|
+
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1221
|
+
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1222
|
+
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1223
|
+
│ Literal_String │ 1000 │ ' 252 ms' │ ' 8 ms' │ ' 31.50 x' │
|
|
1224
|
+
│ Literal_Number │ 1000 │ ' 198 ms' │ ' 5 ms' │ ' 39.60 x' │
|
|
1225
|
+
│ Literal_Boolean │ 1000 │ ' 183 ms' │ ' 6 ms' │ ' 30.50 x' │
|
|
1226
|
+
│ Primitive_Number │ 1000 │ ' 172 ms' │ ' 12 ms' │ ' 14.33 x' │
|
|
1227
|
+
│ Primitive_String │ 1000 │ ' 156 ms' │ ' 10 ms' │ ' 15.60 x' │
|
|
1228
|
+
│ Primitive_Boolean │ 1000 │ ' 137 ms' │ ' 10 ms' │ ' 13.70 x' │
|
|
1229
|
+
│ Primitive_Null │ 1000 │ ' 118 ms' │ ' 7 ms' │ ' 16.86 x' │
|
|
1230
|
+
│ Primitive_RegEx │ 1000 │ ' 235 ms' │ ' 11 ms' │ ' 21.36 x' │
|
|
1231
|
+
│ Object_Unconstrained │ 1000 │ ' 1183 ms' │ ' 39 ms' │ ' 30.33 x' │
|
|
1232
|
+
│ Object_Constrained │ 1000 │ ' 1164 ms' │ ' 35 ms' │ ' 33.26 x' │
|
|
1233
|
+
│ Tuple_Primitive │ 1000 │ ' 470 ms' │ ' 16 ms' │ ' 29.38 x' │
|
|
1234
|
+
│ Tuple_Object │ 1000 │ ' 1096 ms' │ ' 17 ms' │ ' 64.47 x' │
|
|
1235
|
+
│ Composite_Intersect │ 1000 │ ' 570 ms' │ ' 21 ms' │ ' 27.14 x' │
|
|
1236
|
+
│ Composite_Union │ 1000 │ ' 523 ms' │ ' 21 ms' │ ' 24.90 x' │
|
|
1237
|
+
│ Math_Vector4 │ 1000 │ ' 788 ms' │ ' 12 ms' │ ' 65.67 x' │
|
|
1238
|
+
│ Math_Matrix4 │ 1000 │ ' 389 ms' │ ' 12 ms' │ ' 32.42 x' │
|
|
1239
|
+
│ Array_Primitive_Number │ 1000 │ ' 291 ms' │ ' 6 ms' │ ' 48.50 x' │
|
|
1240
|
+
│ Array_Primitive_String │ 1000 │ ' 313 ms' │ ' 4 ms' │ ' 78.25 x' │
|
|
1241
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 357 ms' │ ' 3 ms' │ ' 119.00 x' │
|
|
1242
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1551 ms' │ ' 19 ms' │ ' 81.63 x' │
|
|
1243
|
+
│ Array_Object_Constrained │ 1000 │ ' 1258 ms' │ ' 20 ms' │ ' 62.90 x' │
|
|
1244
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 951 ms' │ ' 15 ms' │ ' 63.40 x' │
|
|
1245
|
+
│ Array_Tuple_Object │ 1000 │ ' 1157 ms' │ ' 14 ms' │ ' 82.64 x' │
|
|
1246
|
+
│ Array_Composite_Intersect │ 1000 │ ' 856 ms' │ ' 19 ms' │ ' 45.05 x' │
|
|
1247
|
+
│ Array_Composite_Union │ 1000 │ ' 1073 ms' │ ' 16 ms' │ ' 67.06 x' │
|
|
1248
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1062 ms' │ ' 11 ms' │ ' 96.55 x' │
|
|
1249
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 478 ms' │ ' 6 ms' │ ' 79.67 x' │
|
|
1250
|
+
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1252
1251
|
```
|
|
1253
1252
|
|
|
1254
1253
|
<a name='benchmark-validate'></a>
|
|
@@ -1258,35 +1257,39 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1258
1257
|
This benchmark measures validation performance for varying types. You can review this benchmark [here](https://github.com/sinclairzx81/typebox/blob/master/benchmark/measurement/module/check.ts).
|
|
1259
1258
|
|
|
1260
1259
|
```typescript
|
|
1261
|
-
|
|
1262
|
-
│
|
|
1263
|
-
|
|
1264
|
-
│
|
|
1265
|
-
│
|
|
1266
|
-
│
|
|
1267
|
-
│
|
|
1268
|
-
│
|
|
1269
|
-
│
|
|
1270
|
-
│
|
|
1271
|
-
│
|
|
1272
|
-
│
|
|
1273
|
-
│
|
|
1274
|
-
│
|
|
1275
|
-
│
|
|
1276
|
-
│
|
|
1277
|
-
│
|
|
1278
|
-
│
|
|
1279
|
-
│
|
|
1280
|
-
│
|
|
1281
|
-
│
|
|
1282
|
-
│
|
|
1283
|
-
│
|
|
1284
|
-
│
|
|
1285
|
-
│
|
|
1286
|
-
│
|
|
1287
|
-
│
|
|
1288
|
-
│
|
|
1289
|
-
|
|
1260
|
+
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1261
|
+
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1262
|
+
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1263
|
+
│ Literal_String │ 1000000 │ ' 24 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
|
|
1264
|
+
│ Literal_Number │ 1000000 │ ' 19 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
|
|
1265
|
+
│ Literal_Boolean │ 1000000 │ ' 19 ms' │ ' 18 ms' │ ' 10 ms' │ ' 1.80 x' │
|
|
1266
|
+
│ Primitive_Number │ 1000000 │ ' 25 ms' │ ' 17 ms' │ ' 11 ms' │ ' 1.55 x' │
|
|
1267
|
+
│ Primitive_String │ 1000000 │ ' 23 ms' │ ' 16 ms' │ ' 10 ms' │ ' 1.60 x' │
|
|
1268
|
+
│ Primitive_Boolean │ 1000000 │ ' 19 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
|
|
1269
|
+
│ Primitive_Null │ 1000000 │ ' 21 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
|
|
1270
|
+
│ Primitive_RegEx │ 1000000 │ ' 154 ms' │ ' 45 ms' │ ' 38 ms' │ ' 1.18 x' │
|
|
1271
|
+
│ Object_Unconstrained │ 1000000 │ ' 837 ms' │ ' 34 ms' │ ' 29 ms' │ ' 1.17 x' │
|
|
1272
|
+
│ Object_Constrained │ 1000000 │ ' 1045 ms' │ ' 52 ms' │ ' 45 ms' │ ' 1.16 x' │
|
|
1273
|
+
│ Object_Recursive │ 1000000 │ ' 4711 ms' │ ' 355 ms' │ ' 100 ms' │ ' 3.55 x' │
|
|
1274
|
+
│ Tuple_Primitive │ 1000000 │ ' 163 ms' │ ' 21 ms' │ ' 16 ms' │ ' 1.31 x' │
|
|
1275
|
+
│ Tuple_Object │ 1000000 │ ' 668 ms' │ ' 30 ms' │ ' 26 ms' │ ' 1.15 x' │
|
|
1276
|
+
│ Composite_Intersect │ 1000000 │ ' 682 ms' │ ' 28 ms' │ ' 21 ms' │ ' 1.33 x' │
|
|
1277
|
+
│ Composite_Union │ 1000000 │ ' 463 ms' │ ' 22 ms' │ ' 19 ms' │ ' 1.16 x' │
|
|
1278
|
+
│ Math_Vector4 │ 1000000 │ ' 255 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │
|
|
1279
|
+
│ Math_Matrix4 │ 1000000 │ ' 988 ms' │ ' 38 ms' │ ' 29 ms' │ ' 1.31 x' │
|
|
1280
|
+
│ Array_Primitive_Number │ 1000000 │ ' 270 ms' │ ' 26 ms' │ ' 15 ms' │ ' 1.73 x' │
|
|
1281
|
+
│ Array_Primitive_String │ 1000000 │ ' 207 ms' │ ' 22 ms' │ ' 16 ms' │ ' 1.38 x' │
|
|
1282
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 137 ms' │ ' 21 ms' │ ' 19 ms' │ ' 1.11 x' │
|
|
1283
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 4698 ms' │ ' 68 ms' │ ' 61 ms' │ ' 1.11 x' │
|
|
1284
|
+
│ Array_Object_Constrained │ 1000000 │ ' 4863 ms' │ ' 139 ms' │ ' 117 ms' │ ' 1.19 x' │
|
|
1285
|
+
│ Array_Object_Recursive │ 1000000 │ ' 19170 ms' │ ' 1606 ms' │ ' 332 ms' │ ' 4.84 x' │
|
|
1286
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 724 ms' │ ' 38 ms' │ ' 31 ms' │ ' 1.23 x' │
|
|
1287
|
+
│ Array_Tuple_Object │ 1000000 │ ' 2843 ms' │ ' 71 ms' │ ' 63 ms' │ ' 1.13 x' │
|
|
1288
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 2816 ms' │ ' 49 ms' │ ' 40 ms' │ ' 1.23 x' │
|
|
1289
|
+
│ Array_Composite_Union │ 1000000 │ ' 2021 ms' │ ' 69 ms' │ ' 39 ms' │ ' 1.77 x' │
|
|
1290
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1080 ms' │ ' 39 ms' │ ' 25 ms' │ ' 1.56 x' │
|
|
1291
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4561 ms' │ ' 112 ms' │ ' 96 ms' │ ' 1.17 x' │
|
|
1292
|
+
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1290
1293
|
```
|
|
1291
1294
|
|
|
1292
1295
|
<a name='benchmark-compression'></a>
|
|
@@ -1299,15 +1302,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1299
1302
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1300
1303
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1301
1304
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1302
|
-
│ typebox/compiler │ '
|
|
1303
|
-
│ typebox/
|
|
1304
|
-
│ typebox/
|
|
1305
|
-
│ typebox/
|
|
1306
|
-
│ typebox
|
|
1307
|
-
│ typebox/hash │ ' 4.2 kb' │ ' 1.8 kb' │ '2.30 x' │
|
|
1308
|
-
│ typebox/system │ ' 14.0 kb' │ ' 7.1 kb' │ '1.96 x' │
|
|
1309
|
-
│ typebox/value │ ' 90.0 kb' │ ' 41.8 kb' │ '2.15 x' │
|
|
1310
|
-
│ typebox │ ' 12.0 kb' │ ' 6.4 kb' │ '1.89 x' │
|
|
1305
|
+
│ typebox/compiler │ '108.2 kb' │ ' 48.5 kb' │ '2.23 x' │
|
|
1306
|
+
│ typebox/errors │ ' 92.9 kb' │ ' 41.4 kb' │ '2.24 x' │
|
|
1307
|
+
│ typebox/system │ ' 59.7 kb' │ ' 24.5 kb' │ '2.43 x' │
|
|
1308
|
+
│ typebox/value │ '153.3 kb' │ ' 66.6 kb' │ '2.30 x' │
|
|
1309
|
+
│ typebox │ ' 58.7 kb' │ ' 24.1 kb' │ '2.43 x' │
|
|
1311
1310
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1312
1311
|
```
|
|
1313
1312
|
|
package/typebox.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const Recursive: unique symbol;
|
|
2
1
|
export declare const Modifier: unique symbol;
|
|
3
2
|
export declare const Hint: unique symbol;
|
|
4
3
|
export declare const Kind: unique symbol;
|
|
@@ -27,7 +26,7 @@ export type TReadonlyOptional<T extends TSchema> = T & {
|
|
|
27
26
|
export interface SchemaOptions {
|
|
28
27
|
$schema?: string;
|
|
29
28
|
/** Id for this schema */
|
|
30
|
-
|
|
29
|
+
$id?: string;
|
|
31
30
|
/** Title of this schema */
|
|
32
31
|
title?: string;
|
|
33
32
|
/** Description of this schema */
|
|
@@ -43,7 +42,6 @@ export interface TKind {
|
|
|
43
42
|
}
|
|
44
43
|
export interface TSchema extends SchemaOptions, TKind {
|
|
45
44
|
[Modifier]?: string;
|
|
46
|
-
[Recursive]?: string;
|
|
47
45
|
[Hint]?: string;
|
|
48
46
|
params: unknown[];
|
|
49
47
|
static: unknown;
|
|
@@ -84,7 +82,6 @@ export interface TBoolean extends TSchema {
|
|
|
84
82
|
type: 'boolean';
|
|
85
83
|
}
|
|
86
84
|
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
87
|
-
export type TDeref<T> = T extends TRef<infer U> ? TDeref<U> : T;
|
|
88
85
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
89
86
|
export type TCompositeUnion<Left extends TSchema, Right extends TSchema> = Ensure<TUnion<[Left, Right]>>;
|
|
90
87
|
export type TCompositeMerge<T extends TObject, Output extends Record<any, TSchema>> = Evaluate<{
|
|
@@ -93,7 +90,7 @@ export type TCompositeMerge<T extends TObject, Output extends Record<any, TSchem
|
|
|
93
90
|
[Key in keyof Output]: Key extends keyof T['properties'] ? TCompositeUnion<T['properties'][Key], Output[Key]> : Output[Key];
|
|
94
91
|
}>;
|
|
95
92
|
export type TCompositeReduce<T extends TObject[], Output extends {}> = T extends [infer L, ...infer R] ? TCompositeReduce<[...Assert<R, TObject[]>], TCompositeMerge<Assert<L, TObject>, Output>> : T extends [] ? Output : never;
|
|
96
|
-
export type TComposite<T extends TObject[]> = Ensure<TObject<TCompositeReduce<T, {}>>>;
|
|
93
|
+
export type TComposite<T extends TObject[] = TObject[]> = Ensure<TObject<TCompositeReduce<T, {}>>>;
|
|
97
94
|
export type TConstructorParameterArray<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
98
95
|
[K in keyof T]: Static<Assert<T[K], TSchema>, P>;
|
|
99
96
|
}];
|
|
@@ -170,9 +167,9 @@ export type TKeyOfTuple<T extends TSchema> = {
|
|
|
170
167
|
} extends infer U ? UnionToTuple<Exclude<{
|
|
171
168
|
[K in keyof U]: U[K];
|
|
172
169
|
}[keyof U], undefined>> : never;
|
|
173
|
-
export type TKeyOf<T extends TSchema = TSchema
|
|
170
|
+
export type TKeyOf<T extends TSchema = TSchema> = (T extends TIntersect ? TKeyOfTuple<T> : T extends TUnion ? TKeyOfTuple<T> : T extends TObject ? TKeyOfTuple<T> : [
|
|
174
171
|
]) extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
|
|
175
|
-
export type TLiteralValue = string | number | boolean
|
|
172
|
+
export type TLiteralValue = string | number | boolean;
|
|
176
173
|
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
177
174
|
[Kind]: 'Literal';
|
|
178
175
|
static: T;
|
|
@@ -242,7 +239,7 @@ export type TOmitArray<T extends TSchema[], K extends keyof any> = Assert<{
|
|
|
242
239
|
[K2 in keyof T]: TOmit<Assert<T[K2], TSchema>, K>;
|
|
243
240
|
}, TSchema[]>;
|
|
244
241
|
export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<Assert<Omit<T, K>, TProperties>>;
|
|
245
|
-
export type TOmit<T extends TSchema, K extends keyof any
|
|
242
|
+
export type TOmit<T extends TSchema, K extends keyof any> = T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
246
243
|
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
247
244
|
export type TPartialArray<T extends TSchema[]> = Assert<{
|
|
248
245
|
[K in keyof T]: TPartial<Assert<T[K], TSchema>>;
|
|
@@ -250,14 +247,14 @@ export type TPartialArray<T extends TSchema[]> = Assert<{
|
|
|
250
247
|
export type TPartialProperties<T extends TProperties> = Evaluate<Assert<{
|
|
251
248
|
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T[K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T[K] extends TOptional<infer U> ? TOptional<U> : TOptional<T[K]>;
|
|
252
249
|
}, TProperties>>;
|
|
253
|
-
export type TPartial<T extends TSchema
|
|
250
|
+
export type TPartial<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TPartialArray<S>> : T extends TUnion<infer S> ? TUnion<TPartialArray<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
|
|
254
251
|
export type TPickArray<T extends TSchema[], K extends keyof any> = {
|
|
255
252
|
[K2 in keyof T]: TPick<Assert<T[K2], TSchema>, K>;
|
|
256
253
|
};
|
|
257
254
|
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
258
255
|
[K in keyof R]: Assert<R[K], TSchema> extends TSchema ? R[K] : never;
|
|
259
256
|
}) : never;
|
|
260
|
-
export type TPick<T extends TSchema, K extends keyof any
|
|
257
|
+
export type TPick<T extends TSchema, K extends keyof any> = T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
261
258
|
export type TPromiseStatic<T extends TSchema, P extends unknown[]> = Promise<Static<T, P>>;
|
|
262
259
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
263
260
|
[Kind]: 'Promise';
|
|
@@ -305,7 +302,7 @@ export type TRequiredArray<T extends TSchema[]> = Assert<{
|
|
|
305
302
|
export type TRequiredProperties<T extends TProperties> = Evaluate<Assert<{
|
|
306
303
|
[K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T[K] extends TReadonly<infer U> ? TReadonly<U> : T[K] extends TOptional<infer U> ? U : T[K];
|
|
307
304
|
}, TProperties>>;
|
|
308
|
-
export type TRequired<T extends TSchema
|
|
305
|
+
export type TRequired<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TRequiredArray<S>> : T extends TUnion<infer S> ? TUnion<TRequiredArray<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
|
|
309
306
|
export type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex';
|
|
310
307
|
export interface StringOptions<Format extends string> extends SchemaOptions {
|
|
311
308
|
minLength?: number;
|
|
@@ -391,6 +388,8 @@ export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
|
391
388
|
})['static'];
|
|
392
389
|
export type TypeRegistryValidationFunction<TSchema> = (schema: TSchema, value: unknown) => boolean;
|
|
393
390
|
export declare namespace TypeRegistry {
|
|
391
|
+
/** Returns the entries in this registry */
|
|
392
|
+
function Entries(): Map<string, TypeRegistryValidationFunction<any>>;
|
|
394
393
|
/** Clears all user defined types */
|
|
395
394
|
function Clear(): void;
|
|
396
395
|
/** Returns true if this registry contains this kind */
|
|
@@ -400,21 +399,11 @@ export declare namespace TypeRegistry {
|
|
|
400
399
|
/** Gets a custom validation function for a user defined type */
|
|
401
400
|
function Get(kind: string): TypeRegistryValidationFunction<any> | undefined;
|
|
402
401
|
}
|
|
403
|
-
export declare namespace ReferenceRegistry {
|
|
404
|
-
/** Clears the reference registry */
|
|
405
|
-
function Clear(): void;
|
|
406
|
-
/** Returns true if this registry contains this schema */
|
|
407
|
-
function Has(schema: TSchema): boolean;
|
|
408
|
-
/** Sets this schema on this registry if a $id exists */
|
|
409
|
-
function Set(schema: TSchema): void;
|
|
410
|
-
/** Dereferences the schema one level deep */
|
|
411
|
-
function DerefOne(schema: TSchema): TSchema;
|
|
412
|
-
/** Dereferences the schema recursively */
|
|
413
|
-
function Deref(schema: TSchema): TSchema;
|
|
414
|
-
}
|
|
415
402
|
export type FormatRegistryValidationFunction = (value: string) => boolean;
|
|
416
403
|
/** Provides functions to create user defined string formats */
|
|
417
404
|
export declare namespace FormatRegistry {
|
|
405
|
+
/** Returns the entries in this registry */
|
|
406
|
+
function Entries(): Map<string, FormatRegistryValidationFunction>;
|
|
418
407
|
/** Clears all user defined string formats */
|
|
419
408
|
function Clear(): void;
|
|
420
409
|
/** Returns true if the user defined string format exists */
|
|
@@ -496,8 +485,8 @@ export declare namespace TypeGuard {
|
|
|
496
485
|
/** Returns true if the given schema is TSchema */
|
|
497
486
|
function TSchema(schema: unknown): schema is TSchema;
|
|
498
487
|
}
|
|
488
|
+
/** Fast undefined check used for properties of type undefined */
|
|
499
489
|
export declare namespace ExtendsUndefined {
|
|
500
|
-
/** Fast undefined check for properties of type undefined */
|
|
501
490
|
function Check(schema: TSchema): boolean;
|
|
502
491
|
}
|
|
503
492
|
export declare enum TypeExtendsResult {
|
|
@@ -508,7 +497,7 @@ export declare enum TypeExtendsResult {
|
|
|
508
497
|
export declare namespace TypeExtends {
|
|
509
498
|
function Extends(left: TSchema, right: TSchema): TypeExtendsResult;
|
|
510
499
|
}
|
|
511
|
-
/** Specialized Clone for Types
|
|
500
|
+
/** Specialized Clone for Types */
|
|
512
501
|
export declare namespace TypeClone {
|
|
513
502
|
/** Clones a type. This function will omit non-self referential identifiers on the cloned type. */
|
|
514
503
|
function Clone<T extends TSchema>(schema: T, options: SchemaOptions): T;
|
|
@@ -539,9 +528,9 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
539
528
|
/** `[Standard]` Creates a Boolean type */
|
|
540
529
|
Boolean(options?: SchemaOptions): TBoolean;
|
|
541
530
|
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
531
|
+
Composite<T extends TIntersect<TObject[]>>(schema: T, options?: ObjectOptions): TComposite<T['allOf']>;
|
|
532
|
+
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
542
533
|
Composite<T extends TObject[]>(schemas: [...T], options?: ObjectOptions): TComposite<T>;
|
|
543
|
-
/** `[Standard]` Dereferences the given TRef to its target type */
|
|
544
|
-
Deref<T extends TRef>(schema: T): TDeref<T>;
|
|
545
534
|
/** `[Standard]` Creates a Enum type */
|
|
546
535
|
Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
|
|
547
536
|
/** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
|
|
@@ -575,12 +564,20 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
575
564
|
Omit<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TOmit<T, K[number]>;
|
|
576
565
|
/** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
|
|
577
566
|
Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TUnionOfLiteral<K>>;
|
|
567
|
+
/** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
|
|
568
|
+
Omit<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TOmit<T, K['const']>;
|
|
569
|
+
/** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
|
|
570
|
+
Omit<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TOmit<T, never>;
|
|
578
571
|
/** `[Standard]` Creates a mapped type where all properties are Optional */
|
|
579
572
|
Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
580
573
|
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
581
574
|
Pick<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TPick<T, K[number]>;
|
|
582
575
|
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
583
576
|
Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TUnionOfLiteral<K>>;
|
|
577
|
+
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
578
|
+
Pick<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TPick<T, K['const']>;
|
|
579
|
+
/** `[Standard]` Creates a mapped type whose keys are picked from the given type */
|
|
580
|
+
Pick<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TPick<T, never>;
|
|
584
581
|
/** `[Standard]` Creates an Object type from the given Literal Union */
|
|
585
582
|
Record<K extends TUnion<TLiteral<string | number>[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordPropertiesFromUnionLiteral<K, T>>;
|
|
586
583
|
/** `[Standard]` Creates an Object type from the given Literal Union */
|