@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19
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/build/import/compiler/compiler.mjs +14 -8
- package/build/import/errors/errors.mjs +15 -11
- package/build/import/type/awaited/awaited.mjs +4 -4
- package/build/import/type/deref/deref.mjs +12 -12
- package/build/import/type/exclude/exclude.mjs +8 -5
- package/build/import/type/extends/extends-check.mjs +167 -167
- package/build/import/type/extends/extends.mjs +3 -3
- package/build/import/type/extract/extract.mjs +5 -5
- package/build/import/type/guard/type.d.mts +50 -50
- package/build/import/type/guard/type.mjs +136 -136
- package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +9 -9
- package/build/import/type/intersect/intersect-create.mjs +4 -4
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
- package/build/import/type/intersect/intersect.mjs +2 -2
- package/build/import/type/intrinsic/intrinsic.mjs +5 -5
- package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +16 -16
- package/build/import/type/modifiers/modifiers.mjs +3 -3
- package/build/import/type/object/object.mjs +3 -3
- package/build/import/type/omit/omit.mjs +6 -6
- package/build/import/type/partial/partial.mjs +5 -5
- package/build/import/type/pick/pick.mjs +6 -6
- package/build/import/type/record/record.mjs +7 -7
- package/build/import/type/required/required.mjs +5 -5
- package/build/import/type/rest/rest.mjs +6 -2
- package/build/import/type/template-literal/pattern.mjs +9 -9
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +2 -2
- package/build/import/value/check/check.mjs +18 -11
- package/build/import/value/clean/clean.mjs +9 -7
- package/build/import/value/clone/clone.mjs +7 -4
- package/build/import/value/convert/convert.mjs +6 -2
- package/build/import/value/default/default.mjs +12 -4
- package/build/import/value/transform/decode.mjs +12 -6
- package/build/import/value/transform/encode.mjs +12 -6
- package/build/import/value/transform/has.mjs +24 -18
- package/build/require/compiler/compiler.js +77 -71
- package/build/require/errors/errors.js +58 -54
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/deref/deref.js +11 -11
- package/build/require/type/exclude/exclude.js +7 -4
- package/build/require/type/extends/extends-check.js +167 -167
- package/build/require/type/extends/extends.js +2 -2
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/type.d.ts +50 -50
- package/build/require/type/guard/type.js +184 -184
- package/build/require/type/indexed/indexed-property-keys.js +6 -6
- package/build/require/type/indexed/indexed.js +9 -9
- package/build/require/type/intersect/intersect-create.js +3 -3
- package/build/require/type/intersect/intersect-evaluated.js +2 -2
- package/build/require/type/intersect/intersect.js +1 -1
- package/build/require/type/intrinsic/intrinsic.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.js +6 -6
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +15 -15
- package/build/require/type/modifiers/modifiers.js +2 -2
- package/build/require/type/object/object.js +2 -2
- package/build/require/type/omit/omit.js +5 -5
- package/build/require/type/partial/partial.js +4 -4
- package/build/require/type/pick/pick.js +5 -5
- package/build/require/type/record/record.js +6 -6
- package/build/require/type/required/required.js +4 -4
- package/build/require/type/rest/rest.js +5 -1
- package/build/require/type/template-literal/pattern.js +8 -8
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/union/union-evaluated.js +1 -1
- package/build/require/value/check/check.js +63 -56
- package/build/require/value/clean/clean.js +31 -29
- package/build/require/value/clone/clone.js +7 -4
- package/build/require/value/convert/convert.js +42 -38
- package/build/require/value/default/default.js +24 -16
- package/build/require/value/transform/decode.js +27 -21
- package/build/require/value/transform/encode.js +28 -22
- package/build/require/value/transform/has.js +29 -23
- package/package.json +1 -1
- package/readme.md +5 -5
|
@@ -24,7 +24,7 @@ function FromRest(T, K) {
|
|
|
24
24
|
function FromIntersectRest(T) {
|
|
25
25
|
const [L, ...R] = T;
|
|
26
26
|
return (T.length > 0
|
|
27
|
-
? (0, type_2.
|
|
27
|
+
? (0, type_2.IsNever)(L)
|
|
28
28
|
? [...FromIntersectRest(R)]
|
|
29
29
|
: [L, ...FromIntersectRest(R)]
|
|
30
30
|
: []);
|
|
@@ -37,7 +37,7 @@ function FromIntersect(T, K) {
|
|
|
37
37
|
function FromUnionRest(T, S = T) {
|
|
38
38
|
const [L, ...R] = T;
|
|
39
39
|
return (T.length > 0
|
|
40
|
-
? (0, type_2.
|
|
40
|
+
? (0, type_2.IsNever)(L)
|
|
41
41
|
? []
|
|
42
42
|
: FromUnionRest(R, S)
|
|
43
43
|
: S);
|
|
@@ -66,11 +66,11 @@ function FromProperty(T, K) {
|
|
|
66
66
|
}
|
|
67
67
|
// prettier-ignore
|
|
68
68
|
function FromKey(T, K) {
|
|
69
|
-
return ((0, type_2.
|
|
70
|
-
(0, type_2.
|
|
71
|
-
(0, type_2.
|
|
72
|
-
(0, type_2.
|
|
73
|
-
(0, type_2.
|
|
69
|
+
return ((0, type_2.IsIntersect)(T) ? FromIntersect(T.allOf, K) :
|
|
70
|
+
(0, type_2.IsUnion)(T) ? FromUnion(T.anyOf, K) :
|
|
71
|
+
(0, type_2.IsTuple)(T) ? FromTuple(T.items ?? [], K) :
|
|
72
|
+
(0, type_2.IsArray)(T) ? FromArray(T.items, K) :
|
|
73
|
+
(0, type_2.IsObject)(T) ? FromProperty(T.properties, K) :
|
|
74
74
|
(0, index_1.Never)());
|
|
75
75
|
}
|
|
76
76
|
// prettier-ignore
|
|
@@ -87,8 +87,8 @@ function FromSchema(T, K) {
|
|
|
87
87
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
88
88
|
function Index(T, K, options = {}) {
|
|
89
89
|
// prettier-ignore
|
|
90
|
-
return ((0, type_2.
|
|
91
|
-
(0, type_2.
|
|
90
|
+
return ((0, type_2.IsMappedKey)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_key_1.IndexFromMappedKey)(T, K, options)) :
|
|
91
|
+
(0, type_2.IsSchema)(K) ? (0, type_1.CloneType)(FromSchema(T, (0, indexed_property_keys_1.IndexPropertyKeys)(K)), options) :
|
|
92
92
|
(0, type_1.CloneType)(FromSchema(T, K), options));
|
|
93
93
|
}
|
|
94
94
|
exports.Index = Index;
|
|
@@ -14,11 +14,11 @@ const type_2 = require("../guard/type");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
// prettier-ignore
|
|
16
16
|
function IntersectCreate(T, options) {
|
|
17
|
-
const allObjects = T.every((schema) => (0, type_2.
|
|
18
|
-
const clonedUnevaluatedProperties = (0, type_2.
|
|
17
|
+
const allObjects = T.every((schema) => (0, type_2.IsObject)(schema));
|
|
18
|
+
const clonedUnevaluatedProperties = (0, type_2.IsSchema)(options.unevaluatedProperties)
|
|
19
19
|
? { unevaluatedProperties: (0, type_1.CloneType)(options.unevaluatedProperties) }
|
|
20
20
|
: {};
|
|
21
|
-
return ((options.unevaluatedProperties === false || (0, type_2.
|
|
21
|
+
return ((options.unevaluatedProperties === false || (0, type_2.IsSchema)(options.unevaluatedProperties) || allObjects
|
|
22
22
|
? { ...options, ...clonedUnevaluatedProperties, [index_1.Kind]: 'Intersect', type: 'object', allOf: (0, type_1.CloneRest)(T) }
|
|
23
23
|
: { ...options, ...clonedUnevaluatedProperties, [index_1.Kind]: 'Intersect', allOf: (0, type_1.CloneRest)(T) }));
|
|
24
24
|
}
|
|
@@ -17,7 +17,7 @@ const type_2 = require("../guard/type");
|
|
|
17
17
|
function IsIntersectOptional(T) {
|
|
18
18
|
const [L, ...R] = T;
|
|
19
19
|
return (T.length > 0
|
|
20
|
-
? (0, type_2.
|
|
20
|
+
? (0, type_2.IsOptional)(L)
|
|
21
21
|
? IsIntersectOptional(R)
|
|
22
22
|
: false
|
|
23
23
|
: true);
|
|
@@ -42,7 +42,7 @@ function IntersectEvaluated(T, options = {}) {
|
|
|
42
42
|
return (0, index_3.Never)(options);
|
|
43
43
|
if (T.length === 1)
|
|
44
44
|
return (0, type_1.CloneType)(T[0], options);
|
|
45
|
-
if (T.some((schema) => (0, type_2.
|
|
45
|
+
if (T.some((schema) => (0, type_2.IsTransform)(schema)))
|
|
46
46
|
throw new Error('Cannot intersect transform types');
|
|
47
47
|
return ResolveIntersect(T, options);
|
|
48
48
|
}
|
|
@@ -16,7 +16,7 @@ function Intersect(T, options = {}) {
|
|
|
16
16
|
return (0, index_1.Never)(options);
|
|
17
17
|
if (T.length === 1)
|
|
18
18
|
return (0, type_1.CloneType)(T[0], options);
|
|
19
|
-
if (T.some((schema) => (0, type_2.
|
|
19
|
+
if (T.some((schema) => (0, type_2.IsTransform)(schema)))
|
|
20
20
|
throw new Error('Cannot intersect transform types');
|
|
21
21
|
return (0, intersect_create_1.IntersectCreate)(T, options);
|
|
22
22
|
}
|
|
@@ -58,11 +58,11 @@ function Intrinsic(schema, mode, options = {}) {
|
|
|
58
58
|
// prettier-ignore
|
|
59
59
|
return (
|
|
60
60
|
// Intrinsic-Mapped-Inference
|
|
61
|
-
(0, type_1.
|
|
61
|
+
(0, type_1.IsMappedKey)(schema) ? (0, intrinsic_from_mapped_key_1.IntrinsicFromMappedKey)(schema, mode, options) :
|
|
62
62
|
// Standard-Inference
|
|
63
|
-
(0, type_1.
|
|
64
|
-
(0, type_1.
|
|
65
|
-
(0, type_1.
|
|
63
|
+
(0, type_1.IsTemplateLiteral)(schema) ? FromTemplateLiteral(schema, mode, schema) :
|
|
64
|
+
(0, type_1.IsUnion)(schema) ? (0, index_3.Union)(FromRest(schema.anyOf, mode), options) :
|
|
65
|
+
(0, type_1.IsLiteral)(schema) ? (0, index_2.Literal)(FromLiteralValue(schema.const, mode), options) :
|
|
66
66
|
schema);
|
|
67
67
|
}
|
|
68
68
|
exports.Intrinsic = Intrinsic;
|
|
@@ -57,12 +57,12 @@ function FromPatternProperties(patternProperties) {
|
|
|
57
57
|
/** Returns a tuple of PropertyKeys derived from the given TSchema. */
|
|
58
58
|
// prettier-ignore
|
|
59
59
|
function KeyOfPropertyKeys(T) {
|
|
60
|
-
return ((0, type_1.
|
|
61
|
-
(0, type_1.
|
|
62
|
-
(0, type_1.
|
|
63
|
-
(0, type_1.
|
|
64
|
-
(0, type_1.
|
|
65
|
-
(0, type_1.
|
|
60
|
+
return ((0, type_1.IsIntersect)(T) ? FromIntersect(T.allOf) :
|
|
61
|
+
(0, type_1.IsUnion)(T) ? FromUnion(T.anyOf) :
|
|
62
|
+
(0, type_1.IsTuple)(T) ? FromTuple(T.items ?? []) :
|
|
63
|
+
(0, type_1.IsArray)(T) ? FromArray(T.items) :
|
|
64
|
+
(0, type_1.IsObject)(T) ? FromProperties(T.properties) :
|
|
65
|
+
(0, type_1.IsRecord)(T) ? FromPatternProperties(T.patternProperties) :
|
|
66
66
|
[]);
|
|
67
67
|
}
|
|
68
68
|
exports.KeyOfPropertyKeys = KeyOfPropertyKeys;
|
|
@@ -24,7 +24,7 @@ function FromLiterals(T) {
|
|
|
24
24
|
}
|
|
25
25
|
/** `[Json]` Creates a KeyOf type */
|
|
26
26
|
function KeyOf(T, options = {}) {
|
|
27
|
-
if ((0, type_2.
|
|
27
|
+
if ((0, type_2.IsMappedResult)(T)) {
|
|
28
28
|
return (0, keyof_from_mapped_result_1.KeyOfFromMappedResult)(T, options);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -62,22 +62,22 @@ function FromProperties(K, T) {
|
|
|
62
62
|
function FromSchemaType(K, T) {
|
|
63
63
|
return (
|
|
64
64
|
// unevaluated modifier types
|
|
65
|
-
(0, type_2.
|
|
66
|
-
(0, type_2.
|
|
65
|
+
(0, type_2.IsOptional)(T) ? (0, index_12.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
|
|
66
|
+
(0, type_2.IsReadonly)(T) ? (0, index_14.Readonly)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.ReadonlyKind]))) :
|
|
67
67
|
// unevaluated mapped types
|
|
68
|
-
(0, type_2.
|
|
69
|
-
(0, type_2.
|
|
68
|
+
(0, type_2.IsMappedResult)(T) ? FromMappedResult(K, T.properties) :
|
|
69
|
+
(0, type_2.IsMappedKey)(T) ? FromMappedKey(K, T.keys) :
|
|
70
70
|
// unevaluated types
|
|
71
|
-
(0, type_2.
|
|
72
|
-
(0, type_2.
|
|
73
|
-
(0, type_2.
|
|
74
|
-
(0, type_2.
|
|
75
|
-
(0, type_2.
|
|
76
|
-
(0, type_2.
|
|
77
|
-
(0, type_2.
|
|
78
|
-
(0, type_2.
|
|
79
|
-
(0, type_2.
|
|
80
|
-
(0, type_2.
|
|
71
|
+
(0, type_2.IsConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
72
|
+
(0, type_2.IsFunction)(T) ? (0, index_6.Function)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
73
|
+
(0, type_2.IsAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items)) :
|
|
74
|
+
(0, type_2.IsIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items)) :
|
|
75
|
+
(0, type_2.IsIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf)) :
|
|
76
|
+
(0, type_2.IsUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf)) :
|
|
77
|
+
(0, type_2.IsTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? [])) :
|
|
78
|
+
(0, type_2.IsObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties)) :
|
|
79
|
+
(0, type_2.IsArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items)) :
|
|
80
|
+
(0, type_2.IsPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item)) :
|
|
81
81
|
T);
|
|
82
82
|
}
|
|
83
83
|
// prettier-ignore
|
|
@@ -89,7 +89,7 @@ function FromMappedFunctionReturnType(K, T) {
|
|
|
89
89
|
}
|
|
90
90
|
/** `[Json]` Creates a Mapped object type */
|
|
91
91
|
function Mapped(key, map, options = {}) {
|
|
92
|
-
const K = (0, type_2.
|
|
92
|
+
const K = (0, type_2.IsSchema)(key) ? (0, index_7.IndexPropertyKeys)(key) : key;
|
|
93
93
|
const RT = map({ [index_1.Kind]: 'MappedKey', keys: K });
|
|
94
94
|
const R = FromMappedFunctionReturnType(K, RT);
|
|
95
95
|
return (0, type_1.CloneType)((0, index_11.Object)(R), options);
|
|
@@ -16,7 +16,7 @@ const type_1 = require("../guard/type");
|
|
|
16
16
|
function IsOptionalFromIntersect(T) {
|
|
17
17
|
const [L, ...R] = T;
|
|
18
18
|
return (T.length > 0
|
|
19
|
-
? (0, type_1.
|
|
19
|
+
? (0, type_1.IsOptional)(L)
|
|
20
20
|
? IsOptionalFromIntersect(R)
|
|
21
21
|
: false
|
|
22
22
|
: true);
|
|
@@ -25,7 +25,7 @@ function IsOptionalFromIntersect(T) {
|
|
|
25
25
|
function IsOptionalFromUnion(T) {
|
|
26
26
|
const [L, ...R] = T;
|
|
27
27
|
return (T.length > 0
|
|
28
|
-
? (0, type_1.
|
|
28
|
+
? (0, type_1.IsOptional)(L)
|
|
29
29
|
? true
|
|
30
30
|
: IsOptionalFromUnion(R)
|
|
31
31
|
: false);
|
|
@@ -12,9 +12,9 @@ const type_2 = require("../guard/type");
|
|
|
12
12
|
/** `[Json]` Creates an Object type */
|
|
13
13
|
function _Object(properties, options = {}) {
|
|
14
14
|
const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
|
|
15
|
-
const optionalKeys = propertyKeys.filter((key) => (0, type_2.
|
|
15
|
+
const optionalKeys = propertyKeys.filter((key) => (0, type_2.IsOptional)(properties[key]));
|
|
16
16
|
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
17
|
-
const clonedAdditionalProperties = (0, type_2.
|
|
17
|
+
const clonedAdditionalProperties = (0, type_2.IsSchema)(options.additionalProperties) ? { additionalProperties: (0, type_1.CloneType)(options.additionalProperties) } : {};
|
|
18
18
|
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: (0, type_1.CloneType)(properties[key]) }), {});
|
|
19
19
|
return (requiredKeys.length > 0
|
|
20
20
|
? { ...options, ...clonedAdditionalProperties, [index_1.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
|
|
@@ -39,18 +39,18 @@ function FromProperties(T, K) {
|
|
|
39
39
|
}
|
|
40
40
|
// prettier-ignore
|
|
41
41
|
function OmitResolve(T, K) {
|
|
42
|
-
return ((0, type_2.
|
|
43
|
-
(0, type_2.
|
|
44
|
-
(0, type_2.
|
|
42
|
+
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
43
|
+
(0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
|
|
44
|
+
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
45
45
|
(0, index_3.Object)({}));
|
|
46
46
|
}
|
|
47
47
|
exports.OmitResolve = OmitResolve;
|
|
48
48
|
function Omit(T, K, options = {}) {
|
|
49
|
-
if ((0, type_2.
|
|
49
|
+
if ((0, type_2.IsMappedKey)(K)) {
|
|
50
50
|
return (0, omit_from_mapped_key_1.OmitFromMappedKey)(T, K, options);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
const I = (0, type_2.
|
|
53
|
+
const I = (0, type_2.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
|
|
54
54
|
const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
|
|
55
55
|
const R = (0, type_1.CloneType)(OmitResolve(T, I), options);
|
|
56
56
|
return { ...D, ...R };
|
|
@@ -37,14 +37,14 @@ function FromProperties(T) {
|
|
|
37
37
|
}
|
|
38
38
|
// prettier-ignore
|
|
39
39
|
function PartialResolve(T) {
|
|
40
|
-
return ((0, type_2.
|
|
41
|
-
(0, type_2.
|
|
42
|
-
(0, type_2.
|
|
40
|
+
return ((0, type_2.IsIntersect)(T) ? (0, index_3.Intersect)(FromIntersect(T.allOf)) :
|
|
41
|
+
(0, type_2.IsUnion)(T) ? (0, index_4.Union)(FromUnion(T.anyOf)) :
|
|
42
|
+
(0, type_2.IsObject)(T) ? (0, index_2.Object)(FromProperties(T.properties)) :
|
|
43
43
|
(0, index_2.Object)({}));
|
|
44
44
|
}
|
|
45
45
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
46
46
|
function Partial(T, options = {}) {
|
|
47
|
-
if ((0, type_2.
|
|
47
|
+
if ((0, type_2.IsMappedResult)(T)) {
|
|
48
48
|
return (0, partial_from_mapped_result_1.PartialFromMappedResult)(T, options);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
@@ -30,18 +30,18 @@ function FromProperties(T, K) {
|
|
|
30
30
|
}
|
|
31
31
|
// prettier-ignore
|
|
32
32
|
function PickResolve(T, K) {
|
|
33
|
-
return ((0, type_2.
|
|
34
|
-
(0, type_2.
|
|
35
|
-
(0, type_2.
|
|
33
|
+
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
34
|
+
(0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
|
|
35
|
+
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
36
36
|
(0, index_3.Object)({}));
|
|
37
37
|
}
|
|
38
38
|
exports.PickResolve = PickResolve;
|
|
39
39
|
function Pick(T, K, options = {}) {
|
|
40
|
-
if ((0, type_2.
|
|
40
|
+
if ((0, type_2.IsMappedKey)(K)) {
|
|
41
41
|
return (0, pick_from_mapped_key_1.PickFromMappedKey)(T, K, options);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
const I = (0, type_2.
|
|
44
|
+
const I = (0, type_2.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
|
|
45
45
|
const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
|
|
46
46
|
const R = (0, type_1.CloneType)(PickResolve(T, I), options);
|
|
47
47
|
return { ...D, ...R };
|
|
@@ -70,12 +70,12 @@ function FromNumberKey(_, T, options) {
|
|
|
70
70
|
/** `[Json]` Creates a Record type */
|
|
71
71
|
function Record(K, T, options = {}) {
|
|
72
72
|
// prettier-ignore
|
|
73
|
-
return ((0, type_2.
|
|
74
|
-
(0, type_2.
|
|
75
|
-
(0, type_2.
|
|
76
|
-
(0, type_2.
|
|
77
|
-
(0, type_2.
|
|
78
|
-
(0, type_2.
|
|
73
|
+
return ((0, type_2.IsUnion)(K) ? FromUnionKey(K.anyOf, T, options) :
|
|
74
|
+
(0, type_2.IsTemplateLiteral)(K) ? FromTemplateLiteralKey(K, T, options) :
|
|
75
|
+
(0, type_2.IsLiteral)(K) ? FromLiteralKey(K.const, T, options) :
|
|
76
|
+
(0, type_2.IsString)(K) ? FromStringKey(K, T, options) :
|
|
77
|
+
(0, type_2.IsInteger)(K) ? FromIntegerKey(K, T, options) :
|
|
78
|
+
(0, type_2.IsNumber)(K) ? FromNumberKey(K, T, options) :
|
|
79
79
|
(0, index_2.Never)(options));
|
|
80
80
|
}
|
|
81
81
|
exports.Record = Record;
|
|
@@ -36,14 +36,14 @@ function FromProperties(T) {
|
|
|
36
36
|
}
|
|
37
37
|
// prettier-ignore
|
|
38
38
|
function RequiredResolve(T) {
|
|
39
|
-
return ((0, type_2.
|
|
40
|
-
(0, type_2.
|
|
41
|
-
(0, type_2.
|
|
39
|
+
return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf)) :
|
|
40
|
+
(0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf)) :
|
|
41
|
+
(0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties)) :
|
|
42
42
|
(0, index_3.Object)({}));
|
|
43
43
|
}
|
|
44
44
|
/** `[Json]` Constructs a type where all properties are required */
|
|
45
45
|
function Required(T, options = {}) {
|
|
46
|
-
if ((0, type_2.
|
|
46
|
+
if ((0, type_2.IsMappedResult)(T)) {
|
|
47
47
|
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(T, options);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
@@ -8,8 +8,12 @@ const type_1 = require("../clone/type");
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// prettier-ignore
|
|
10
10
|
const type_2 = require("../guard/type");
|
|
11
|
+
// prettier-ignore
|
|
11
12
|
function RestResolve(T) {
|
|
12
|
-
return ((0, type_2.
|
|
13
|
+
return ((0, type_2.IsIntersect)(T) ? [...T.allOf] :
|
|
14
|
+
(0, type_2.IsUnion)(T) ? [...T.anyOf] :
|
|
15
|
+
(0, type_2.IsTuple)(T) ? [...(T.items ?? [])] :
|
|
16
|
+
[]);
|
|
13
17
|
}
|
|
14
18
|
exports.RestResolve = RestResolve;
|
|
15
19
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
@@ -23,14 +23,14 @@ function Escape(value) {
|
|
|
23
23
|
}
|
|
24
24
|
// prettier-ignore
|
|
25
25
|
function Visit(schema, acc) {
|
|
26
|
-
return ((0, type_1.
|
|
27
|
-
(0, type_1.
|
|
28
|
-
(0, type_1.
|
|
29
|
-
(0, type_1.
|
|
30
|
-
(0, type_1.
|
|
31
|
-
(0, type_1.
|
|
32
|
-
(0, type_1.
|
|
33
|
-
(0, type_1.
|
|
26
|
+
return ((0, type_1.IsTemplateLiteral)(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
|
|
27
|
+
(0, type_1.IsUnion)(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
|
|
28
|
+
(0, type_1.IsNumber)(schema) ? `${acc}${index_1.PatternNumber}` :
|
|
29
|
+
(0, type_1.IsInteger)(schema) ? `${acc}${index_1.PatternNumber}` :
|
|
30
|
+
(0, type_1.IsBigInt)(schema) ? `${acc}${index_1.PatternNumber}` :
|
|
31
|
+
(0, type_1.IsString)(schema) ? `${acc}${index_1.PatternString}` :
|
|
32
|
+
(0, type_1.IsLiteral)(schema) ? `${acc}${Escape(schema.const.toString())}` :
|
|
33
|
+
(0, type_1.IsBoolean)(schema) ? `${acc}${index_1.PatternBoolean}` :
|
|
34
34
|
(() => { throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[index_2.Kind]}'`); })());
|
|
35
35
|
}
|
|
36
36
|
function TemplateLiteralPattern(kinds) {
|
|
@@ -39,7 +39,7 @@ class TransformEncodeBuilder {
|
|
|
39
39
|
}
|
|
40
40
|
Encode(encode) {
|
|
41
41
|
const schema = (0, type_1.CloneType)(this.schema);
|
|
42
|
-
return ((0, type_2.
|
|
42
|
+
return ((0, type_2.IsTransform)(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.TransformEncodeBuilder = TransformEncodeBuilder;
|