@sinclair/typebox 0.29.1 → 0.29.2
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/package.json +1 -1
- package/readme.md +74 -72
- package/typebox.d.ts +8 -2
- package/typebox.js +33 -6
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -888,14 +888,16 @@ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
|
|
|
888
888
|
|
|
889
889
|
### Not Types
|
|
890
890
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
For example, consider a type which is `number` but not `1 | 2 | 3` and where the static type would still technically be a `number`. The following shows a pseudo TypeScript example using `not` followed by the TypeBox implementation.
|
|
891
|
+
TypeBox has partial support for the JSON schema `not` keyword with `Type.Not`. This type is synonymous with the concept of a [negated types](https://github.com/microsoft/TypeScript/issues/4196) which are not supported in the TypeScript language. TypeBox does provide partial inference support via the intersection of `T & not U` (where all negated types infer as `unknown`). This can be used in the following context.
|
|
894
892
|
|
|
895
893
|
```typescript
|
|
896
|
-
//
|
|
894
|
+
// TypeScript
|
|
897
895
|
|
|
898
|
-
type T = number
|
|
896
|
+
type T = Exclude<number, 1 | 2 | 3> // all numbers except 1, 2, 3
|
|
897
|
+
//
|
|
898
|
+
// ideally expressed as:
|
|
899
|
+
//
|
|
900
|
+
// type T = number & not (1 | 2 | 3)
|
|
899
901
|
|
|
900
902
|
// TypeBox
|
|
901
903
|
|
|
@@ -914,11 +916,11 @@ const T = Type.Intersect([ // const T = {
|
|
|
914
916
|
// ]
|
|
915
917
|
// }
|
|
916
918
|
|
|
917
|
-
type T = Static<typeof T> //
|
|
919
|
+
type T = Static<typeof T> // inferred:
|
|
918
920
|
//
|
|
919
|
-
// type T =
|
|
920
|
-
// type T =
|
|
921
|
-
// type T =
|
|
921
|
+
// type T = number & not (1 | 2 | 3)
|
|
922
|
+
// type T = number & unknown
|
|
923
|
+
// type T = number
|
|
922
924
|
```
|
|
923
925
|
|
|
924
926
|
The Not type can be used with constraints to define schematics for types that would otherwise be difficult to express.
|
|
@@ -1494,35 +1496,35 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1494
1496
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1495
1497
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1496
1498
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1497
|
-
│ Literal_String │ 1000 │ '
|
|
1498
|
-
│ Literal_Number │ 1000 │ '
|
|
1499
|
-
│ Literal_Boolean │ 1000 │ '
|
|
1499
|
+
│ Literal_String │ 1000 │ ' 227 ms' │ ' 7 ms' │ ' 32.43 x' │
|
|
1500
|
+
│ Literal_Number │ 1000 │ ' 180 ms' │ ' 6 ms' │ ' 30.00 x' │
|
|
1501
|
+
│ Literal_Boolean │ 1000 │ ' 152 ms' │ ' 5 ms' │ ' 30.40 x' │
|
|
1500
1502
|
│ Primitive_Number │ 1000 │ ' 161 ms' │ ' 6 ms' │ ' 26.83 x' │
|
|
1501
|
-
│ Primitive_String │ 1000 │ '
|
|
1502
|
-
│ Primitive_String_Pattern │ 1000 │ '
|
|
1503
|
-
│ Primitive_Boolean │ 1000 │ '
|
|
1504
|
-
│ Primitive_Null │ 1000 │ '
|
|
1505
|
-
│ Object_Unconstrained │ 1000 │ '
|
|
1506
|
-
│ Object_Constrained │ 1000 │ '
|
|
1507
|
-
│ Object_Vector3 │ 1000 │ '
|
|
1508
|
-
│ Object_Box3D │ 1000 │ '
|
|
1509
|
-
│ Tuple_Primitive │ 1000 │ '
|
|
1510
|
-
│ Tuple_Object │ 1000 │ '
|
|
1511
|
-
│ Composite_Intersect │ 1000 │ '
|
|
1512
|
-
│ Composite_Union │ 1000 │ '
|
|
1513
|
-
│ Math_Vector4 │ 1000 │ '
|
|
1514
|
-
│ Math_Matrix4 │ 1000 │ '
|
|
1515
|
-
│ Array_Primitive_Number │ 1000 │ '
|
|
1516
|
-
│ Array_Primitive_String │ 1000 │ '
|
|
1517
|
-
│ Array_Primitive_Boolean │ 1000 │ '
|
|
1518
|
-
│ Array_Object_Unconstrained │ 1000 │ '
|
|
1519
|
-
│ Array_Object_Constrained │ 1000 │ '
|
|
1520
|
-
│ Array_Tuple_Primitive │ 1000 │ '
|
|
1521
|
-
│ Array_Tuple_Object │ 1000 │ '
|
|
1522
|
-
│ Array_Composite_Intersect │ 1000 │ '
|
|
1523
|
-
│ Array_Composite_Union │ 1000 │ '
|
|
1524
|
-
│ Array_Math_Vector4 │ 1000 │ '
|
|
1525
|
-
│ Array_Math_Matrix4 │ 1000 │ '
|
|
1503
|
+
│ Primitive_String │ 1000 │ ' 150 ms' │ ' 8 ms' │ ' 18.75 x' │
|
|
1504
|
+
│ Primitive_String_Pattern │ 1000 │ ' 202 ms' │ ' 9 ms' │ ' 22.44 x' │
|
|
1505
|
+
│ Primitive_Boolean │ 1000 │ ' 133 ms' │ ' 3 ms' │ ' 44.33 x' │
|
|
1506
|
+
│ Primitive_Null │ 1000 │ ' 147 ms' │ ' 3 ms' │ ' 49.00 x' │
|
|
1507
|
+
│ Object_Unconstrained │ 1000 │ ' 1145 ms' │ ' 31 ms' │ ' 36.94 x' │
|
|
1508
|
+
│ Object_Constrained │ 1000 │ ' 1241 ms' │ ' 26 ms' │ ' 47.73 x' │
|
|
1509
|
+
│ Object_Vector3 │ 1000 │ ' 407 ms' │ ' 7 ms' │ ' 58.14 x' │
|
|
1510
|
+
│ Object_Box3D │ 1000 │ ' 1781 ms' │ ' 27 ms' │ ' 65.96 x' │
|
|
1511
|
+
│ Tuple_Primitive │ 1000 │ ' 489 ms' │ ' 13 ms' │ ' 37.62 x' │
|
|
1512
|
+
│ Tuple_Object │ 1000 │ ' 1278 ms' │ ' 34 ms' │ ' 37.59 x' │
|
|
1513
|
+
│ Composite_Intersect │ 1000 │ ' 613 ms' │ ' 16 ms' │ ' 38.31 x' │
|
|
1514
|
+
│ Composite_Union │ 1000 │ ' 543 ms' │ ' 18 ms' │ ' 30.17 x' │
|
|
1515
|
+
│ Math_Vector4 │ 1000 │ ' 819 ms' │ ' 13 ms' │ ' 63.00 x' │
|
|
1516
|
+
│ Math_Matrix4 │ 1000 │ ' 407 ms' │ ' 7 ms' │ ' 58.14 x' │
|
|
1517
|
+
│ Array_Primitive_Number │ 1000 │ ' 372 ms' │ ' 6 ms' │ ' 62.00 x' │
|
|
1518
|
+
│ Array_Primitive_String │ 1000 │ ' 329 ms' │ ' 6 ms' │ ' 54.83 x' │
|
|
1519
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 313 ms' │ ' 3 ms' │ ' 104.33 x' │
|
|
1520
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1780 ms' │ ' 20 ms' │ ' 89.00 x' │
|
|
1521
|
+
│ Array_Object_Constrained │ 1000 │ ' 1494 ms' │ ' 21 ms' │ ' 71.14 x' │
|
|
1522
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 917 ms' │ ' 10 ms' │ ' 91.70 x' │
|
|
1523
|
+
│ Array_Tuple_Object │ 1000 │ ' 1666 ms' │ ' 13 ms' │ ' 128.15 x' │
|
|
1524
|
+
│ Array_Composite_Intersect │ 1000 │ ' 791 ms' │ ' 18 ms' │ ' 43.94 x' │
|
|
1525
|
+
│ Array_Composite_Union │ 1000 │ ' 833 ms' │ ' 17 ms' │ ' 49.00 x' │
|
|
1526
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1161 ms' │ ' 15 ms' │ ' 77.40 x' │
|
|
1527
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 697 ms' │ ' 10 ms' │ ' 69.70 x' │
|
|
1526
1528
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1527
1529
|
```
|
|
1528
1530
|
|
|
@@ -1536,37 +1538,37 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1536
1538
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1537
1539
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1538
1540
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1539
|
-
│ Literal_String │ 1000000 │ '
|
|
1540
|
-
│ Literal_Number │ 1000000 │ '
|
|
1541
|
+
│ Literal_String │ 1000000 │ ' 25 ms' │ ' 5 ms' │ ' 4 ms' │ ' 1.25 x' │
|
|
1542
|
+
│ Literal_Number │ 1000000 │ ' 19 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1541
1543
|
│ Literal_Boolean │ 1000000 │ ' 18 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1542
|
-
│ Primitive_Number │ 1000000 │ '
|
|
1543
|
-
│ Primitive_String │ 1000000 │ ' 25 ms' │ '
|
|
1544
|
-
│ Primitive_String_Pattern │ 1000000 │ '
|
|
1545
|
-
│ Primitive_Boolean │ 1000000 │ '
|
|
1546
|
-
│ Primitive_Null │ 1000000 │ '
|
|
1547
|
-
│ Object_Unconstrained │ 1000000 │ '
|
|
1548
|
-
│ Object_Constrained │ 1000000 │ '
|
|
1549
|
-
│ Object_Vector3 │ 1000000 │ '
|
|
1550
|
-
│ Object_Box3D │ 1000000 │ '
|
|
1551
|
-
│ Object_Recursive │ 1000000 │ '
|
|
1552
|
-
│ Tuple_Primitive │ 1000000 │ '
|
|
1553
|
-
│ Tuple_Object │ 1000000 │ '
|
|
1554
|
-
│ Composite_Intersect │ 1000000 │ '
|
|
1555
|
-
│ Composite_Union │ 1000000 │ '
|
|
1556
|
-
│ Math_Vector4 │ 1000000 │ '
|
|
1557
|
-
│ Math_Matrix4 │ 1000000 │ '
|
|
1558
|
-
│ Array_Primitive_Number │ 1000000 │ '
|
|
1559
|
-
│ Array_Primitive_String │ 1000000 │ '
|
|
1560
|
-
│ Array_Primitive_Boolean │ 1000000 │ '
|
|
1561
|
-
│ Array_Object_Unconstrained │ 1000000 │ '
|
|
1562
|
-
│ Array_Object_Constrained │ 1000000 │ '
|
|
1563
|
-
│ Array_Object_Recursive │ 1000000 │ '
|
|
1564
|
-
│ Array_Tuple_Primitive │ 1000000 │ '
|
|
1565
|
-
│ Array_Tuple_Object │ 1000000 │ '
|
|
1566
|
-
│ Array_Composite_Intersect │ 1000000 │ '
|
|
1567
|
-
│ Array_Composite_Union │ 1000000 │ '
|
|
1568
|
-
│ Array_Math_Vector4 │ 1000000 │ '
|
|
1569
|
-
│ Array_Math_Matrix4 │ 1000000 │ '
|
|
1544
|
+
│ Primitive_Number │ 1000000 │ ' 26 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1545
|
+
│ Primitive_String │ 1000000 │ ' 25 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
|
|
1546
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 160 ms' │ ' 42 ms' │ ' 36 ms' │ ' 1.17 x' │
|
|
1547
|
+
│ Primitive_Boolean │ 1000000 │ ' 24 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1548
|
+
│ Primitive_Null │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 9 ms' │ ' 2.11 x' │
|
|
1549
|
+
│ Object_Unconstrained │ 1000000 │ ' 1111 ms' │ ' 34 ms' │ ' 24 ms' │ ' 1.42 x' │
|
|
1550
|
+
│ Object_Constrained │ 1000000 │ ' 1262 ms' │ ' 51 ms' │ ' 37 ms' │ ' 1.38 x' │
|
|
1551
|
+
│ Object_Vector3 │ 1000000 │ ' 445 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
|
|
1552
|
+
│ Object_Box3D │ 1000000 │ ' 2029 ms' │ ' 66 ms' │ ' 48 ms' │ ' 1.38 x' │
|
|
1553
|
+
│ Object_Recursive │ 1000000 │ ' 5121 ms' │ ' 464 ms' │ ' 156 ms' │ ' 2.97 x' │
|
|
1554
|
+
│ Tuple_Primitive │ 1000000 │ ' 158 ms' │ ' 22 ms' │ ' 12 ms' │ ' 1.83 x' │
|
|
1555
|
+
│ Tuple_Object │ 1000000 │ ' 761 ms' │ ' 30 ms' │ ' 18 ms' │ ' 1.67 x' │
|
|
1556
|
+
│ Composite_Intersect │ 1000000 │ ' 828 ms' │ ' 24 ms' │ ' 13 ms' │ ' 1.85 x' │
|
|
1557
|
+
│ Composite_Union │ 1000000 │ ' 529 ms' │ ' 22 ms' │ ' 13 ms' │ ' 1.69 x' │
|
|
1558
|
+
│ Math_Vector4 │ 1000000 │ ' 252 ms' │ ' 22 ms' │ ' 11 ms' │ ' 2.00 x' │
|
|
1559
|
+
│ Math_Matrix4 │ 1000000 │ ' 1024 ms' │ ' 38 ms' │ ' 27 ms' │ ' 1.41 x' │
|
|
1560
|
+
│ Array_Primitive_Number │ 1000000 │ ' 264 ms' │ ' 22 ms' │ ' 11 ms' │ ' 2.00 x' │
|
|
1561
|
+
│ Array_Primitive_String │ 1000000 │ ' 240 ms' │ ' 20 ms' │ ' 13 ms' │ ' 1.54 x' │
|
|
1562
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 137 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
|
|
1563
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 6050 ms' │ ' 66 ms' │ ' 55 ms' │ ' 1.20 x' │
|
|
1564
|
+
│ Array_Object_Constrained │ 1000000 │ ' 5954 ms' │ ' 124 ms' │ ' 116 ms' │ ' 1.07 x' │
|
|
1565
|
+
│ Array_Object_Recursive │ 1000000 │ ' 21074 ms' │ ' 1611 ms' │ ' 626 ms' │ ' 2.57 x' │
|
|
1566
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 683 ms' │ ' 37 ms' │ ' 30 ms' │ ' 1.23 x' │
|
|
1567
|
+
│ Array_Tuple_Object │ 1000000 │ ' 3366 ms' │ ' 69 ms' │ ' 54 ms' │ ' 1.28 x' │
|
|
1568
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 3285 ms' │ ' 45 ms' │ ' 36 ms' │ ' 1.25 x' │
|
|
1569
|
+
│ Array_Composite_Union │ 1000000 │ ' 2229 ms' │ ' 69 ms' │ ' 34 ms' │ ' 2.03 x' │
|
|
1570
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1192 ms' │ ' 38 ms' │ ' 25 ms' │ ' 1.52 x' │
|
|
1571
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4916 ms' │ ' 111 ms' │ ' 88 ms' │ ' 1.26 x' │
|
|
1570
1572
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1571
1573
|
```
|
|
1572
1574
|
|
|
@@ -1580,11 +1582,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1580
1582
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1581
1583
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1582
1584
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1583
|
-
│ typebox/compiler │ '
|
|
1584
|
-
│ typebox/errors │ '
|
|
1585
|
-
│ typebox/system │ '
|
|
1586
|
-
│ typebox/value │ '
|
|
1587
|
-
│ typebox │ '
|
|
1585
|
+
│ typebox/compiler │ '130.3 kb' │ ' 58.2 kb' │ '2.24 x' │
|
|
1586
|
+
│ typebox/errors │ '113.3 kb' │ ' 49.8 kb' │ '2.27 x' │
|
|
1587
|
+
│ typebox/system │ ' 78.8 kb' │ ' 32.2 kb' │ '2.45 x' │
|
|
1588
|
+
│ typebox/value │ '180.0 kb' │ ' 77.7 kb' │ '2.32 x' │
|
|
1589
|
+
│ typebox │ ' 77.7 kb' │ ' 31.7 kb' │ '2.45 x' │
|
|
1588
1590
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1589
1591
|
```
|
|
1590
1592
|
|
package/typebox.d.ts
CHANGED
|
@@ -25,8 +25,6 @@ export type Ensure<T> = T extends infer U ? U : never;
|
|
|
25
25
|
export type AssertProperties<T> = T extends TProperties ? T : TProperties;
|
|
26
26
|
export type AssertRest<T, E extends TSchema[] = TSchema[]> = T extends E ? T : [];
|
|
27
27
|
export type AssertType<T, E extends TSchema = TSchema> = T extends E ? T : TNever;
|
|
28
|
-
export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : TIntersect<T>;
|
|
29
|
-
export type UnionType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : TUnion<T>;
|
|
30
28
|
export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
|
|
31
29
|
export type TReadonly<T extends TSchema> = T & {
|
|
32
30
|
[Modifier]: 'Readonly';
|
|
@@ -37,6 +35,14 @@ export type TOptional<T extends TSchema> = T & {
|
|
|
37
35
|
export type TReadonlyOptional<T extends TSchema> = T & {
|
|
38
36
|
[Modifier]: 'ReadonlyOptional';
|
|
39
37
|
};
|
|
38
|
+
export type OptionalUnwrapType<T extends TSchema> = T extends (TOptional<infer S> | TReadonlyOptional<infer S>) ? OptionalUnwrapType<S> : T;
|
|
39
|
+
export type OptionalUnwrapRest<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends (TOptional<infer S> | TReadonlyOptional<infer S>) ? [OptionalUnwrapType<AssertType<S>>, ...OptionalUnwrapRest<AssertRest<R>>] : [L, ...OptionalUnwrapRest<AssertRest<R>>] : [];
|
|
40
|
+
export type IntersectOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends TOptional<AssertType<L>> | TReadonlyOptional<AssertType<L>> ? IntersectOptional<AssertRest<R>> : false : true;
|
|
41
|
+
export type IntersectResolve<T extends TSchema[], U = OptionalUnwrapRest<AssertRest<T>>> = IntersectOptional<AssertRest<T>> extends true ? TOptional<TIntersect<AssertRest<U>>> : TIntersect<AssertRest<U>>;
|
|
42
|
+
export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : IntersectResolve<T>;
|
|
43
|
+
export type UnionOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends (TOptional<AssertType<L>> | TReadonlyOptional<AssertType<L>>) ? true : UnionOptional<AssertRest<R>> : false;
|
|
44
|
+
export type UnionResolve<T extends TSchema[], U = OptionalUnwrapRest<AssertRest<T>>> = UnionOptional<AssertRest<T>> extends true ? TOptional<TUnion<AssertRest<U>>> : TUnion<AssertRest<U>>;
|
|
45
|
+
export type UnionType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : UnionResolve<T>;
|
|
40
46
|
export type Key = string | number;
|
|
41
47
|
export interface SchemaOptions {
|
|
42
48
|
$schema?: string;
|
package/typebox.js
CHANGED
|
@@ -1443,16 +1443,43 @@ var TypeClone;
|
|
|
1443
1443
|
// --------------------------------------------------------------------------
|
|
1444
1444
|
var IndexedAccessor;
|
|
1445
1445
|
(function (IndexedAccessor) {
|
|
1446
|
+
function OptionalUnwrap(schema) {
|
|
1447
|
+
return schema.map((schema) => {
|
|
1448
|
+
const { [exports.Modifier]: _, ...clone } = TypeClone.Clone(schema, {});
|
|
1449
|
+
return clone;
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
function IsIntersectOptional(schema) {
|
|
1453
|
+
return schema.every((schema) => TypeGuard.TOptional(schema));
|
|
1454
|
+
}
|
|
1455
|
+
function IsUnionOptional(schema) {
|
|
1456
|
+
return schema.some((schema) => TypeGuard.TOptional(schema));
|
|
1457
|
+
}
|
|
1458
|
+
function ResolveIntersect(schema) {
|
|
1459
|
+
const optional = IsIntersectOptional(schema.allOf);
|
|
1460
|
+
return optional ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
|
|
1461
|
+
}
|
|
1462
|
+
function ResolveUnion(schema) {
|
|
1463
|
+
const optional = IsUnionOptional(schema.anyOf);
|
|
1464
|
+
return optional ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
|
|
1465
|
+
}
|
|
1466
|
+
function ResolveOptional(schema) {
|
|
1467
|
+
if (schema[exports.Kind] === 'Intersect')
|
|
1468
|
+
return ResolveIntersect(schema);
|
|
1469
|
+
if (schema[exports.Kind] === 'Union')
|
|
1470
|
+
return ResolveUnion(schema);
|
|
1471
|
+
return schema;
|
|
1472
|
+
}
|
|
1446
1473
|
function Intersect(schema, key) {
|
|
1447
|
-
const
|
|
1474
|
+
const resolved = schema.allOf.reduce((acc, schema) => {
|
|
1448
1475
|
const indexed = Visit(schema, key);
|
|
1449
1476
|
return indexed[exports.Kind] === 'Never' ? acc : [...acc, indexed];
|
|
1450
1477
|
}, []);
|
|
1451
|
-
return exports.Type.Intersect(
|
|
1478
|
+
return ResolveOptional(exports.Type.Intersect(resolved));
|
|
1452
1479
|
}
|
|
1453
1480
|
function Union(schema, key) {
|
|
1454
|
-
const
|
|
1455
|
-
return exports.Type.Union(
|
|
1481
|
+
const resolved = schema.anyOf.map((schema) => Visit(schema, key));
|
|
1482
|
+
return ResolveOptional(exports.Type.Union(resolved));
|
|
1456
1483
|
}
|
|
1457
1484
|
function Object(schema, key) {
|
|
1458
1485
|
const property = schema.properties[key];
|
|
@@ -1479,8 +1506,8 @@ var IndexedAccessor;
|
|
|
1479
1506
|
return exports.Type.Never();
|
|
1480
1507
|
}
|
|
1481
1508
|
function Resolve(schema, keys, options = {}) {
|
|
1482
|
-
|
|
1483
|
-
return exports.Type.Union(
|
|
1509
|
+
const resolved = keys.map((key) => Visit(schema, key.toString()));
|
|
1510
|
+
return ResolveOptional(exports.Type.Union(resolved, options));
|
|
1484
1511
|
}
|
|
1485
1512
|
IndexedAccessor.Resolve = Resolve;
|
|
1486
1513
|
})(IndexedAccessor || (exports.IndexedAccessor = IndexedAccessor = {}));
|