@sinclair/typebox 0.34.0 → 0.34.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/build/cjs/syntax/runtime.d.ts +4 -1
- package/build/cjs/syntax/runtime.js +3 -1
- package/build/cjs/syntax/static.d.ts +3 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/computed/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -4
- package/build/cjs/type/guard/kind.js +10 -0
- package/build/cjs/type/guard/type.d.ts +6 -3
- package/build/cjs/type/guard/type.js +6 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +8 -52
- package/build/cjs/type/module/module.js +14 -11
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +41 -51
- package/build/cjs/type/type/json.js +40 -40
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/check/check.js +3 -3
- package/build/cjs/value/transform/decode.js +7 -7
- package/build/cjs/value/transform/encode.js +7 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/syntax/runtime.d.mts +4 -1
- package/build/esm/syntax/runtime.mjs +3 -1
- package/build/esm/syntax/static.d.mts +3 -3
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +9 -4
- package/build/esm/type/guard/kind.mjs +8 -0
- package/build/esm/type/guard/type.d.mts +6 -3
- package/build/esm/type/guard/type.mjs +5 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +8 -52
- package/build/esm/type/module/module.mjs +14 -11
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +41 -51
- package/build/esm/type/type/json.mjs +40 -40
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/check/check.mjs +2 -2
- package/build/esm/value/transform/decode.mjs +2 -2
- package/build/esm/value/transform/encode.mjs +2 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +30 -19
|
@@ -17,9 +17,9 @@ const index_9 = require("../../type/never/index");
|
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
const index_10 = require("../guard/index");
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
|
-
//
|
|
20
|
+
// KindGuard
|
|
21
21
|
// ------------------------------------------------------------------
|
|
22
|
-
const
|
|
22
|
+
const kind_1 = require("../../type/guard/kind");
|
|
23
23
|
// ------------------------------------------------------------------
|
|
24
24
|
// Errors
|
|
25
25
|
// ------------------------------------------------------------------
|
|
@@ -174,7 +174,7 @@ function FromIntersect(schema, references, value) {
|
|
|
174
174
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
|
|
175
175
|
return check1 && check2;
|
|
176
176
|
}
|
|
177
|
-
else if ((0,
|
|
177
|
+
else if ((0, kind_1.IsSchema)(schema.unevaluatedProperties)) {
|
|
178
178
|
const keyCheck = new RegExp((0, index_5.KeyOfPattern)(schema));
|
|
179
179
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
|
|
180
180
|
return check1 && check2;
|
|
@@ -14,9 +14,9 @@ const index_5 = require("../check/index");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
const index_6 = require("../guard/index");
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
-
//
|
|
17
|
+
// KindGuard
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
|
-
const
|
|
19
|
+
const kind_1 = require("../../type/guard/kind");
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
21
|
// Errors
|
|
22
22
|
// ------------------------------------------------------------------
|
|
@@ -48,7 +48,7 @@ exports.TransformDecodeError = TransformDecodeError;
|
|
|
48
48
|
// prettier-ignore
|
|
49
49
|
function Default(schema, path, value) {
|
|
50
50
|
try {
|
|
51
|
-
return (0,
|
|
51
|
+
return (0, kind_1.IsTransform)(schema) ? schema[index_1.TransformKind].Decode(value) : value;
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
54
54
|
throw new TransformDecodeError(schema, path, value, error);
|
|
@@ -71,7 +71,7 @@ function FromIntersect(schema, references, path, value) {
|
|
|
71
71
|
if (knownKey in knownProperties) {
|
|
72
72
|
knownProperties[knownKey] = Visit(knownSchema, references, `${path}/${knownKey}`, knownProperties[knownKey]);
|
|
73
73
|
}
|
|
74
|
-
if (!(0,
|
|
74
|
+
if (!(0, kind_1.IsTransform)(schema.unevaluatedProperties)) {
|
|
75
75
|
return Default(schema, path, knownProperties);
|
|
76
76
|
}
|
|
77
77
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -107,13 +107,13 @@ function FromObject(schema, references, path, value) {
|
|
|
107
107
|
// if the property value is undefined, but the target is not, nor does it satisfy exact optional
|
|
108
108
|
// property policy, then we need to continue. This is a special case for optional property handling
|
|
109
109
|
// where a transforms wrapped in a optional modifiers should not run.
|
|
110
|
-
if ((0, index_6.IsUndefined)(knownProperties[key]) && (!(0,
|
|
110
|
+
if ((0, index_6.IsUndefined)(knownProperties[key]) && (!(0, kind_1.IsUndefined)(schema.properties[key]) ||
|
|
111
111
|
policy_1.TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
|
|
112
112
|
continue;
|
|
113
113
|
// decode property
|
|
114
114
|
knownProperties[key] = Visit(schema.properties[key], references, `${path}/${key}`, knownProperties[key]);
|
|
115
115
|
}
|
|
116
|
-
if (!(0,
|
|
116
|
+
if (!(0, kind_1.IsSchema)(schema.additionalProperties)) {
|
|
117
117
|
return Default(schema, path, knownProperties);
|
|
118
118
|
}
|
|
119
119
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -136,7 +136,7 @@ function FromRecord(schema, references, path, value) {
|
|
|
136
136
|
if (knownKeys.test(key)) {
|
|
137
137
|
knownProperties[key] = Visit(schema.patternProperties[pattern], references, `${path}/${key}`, knownProperties[key]);
|
|
138
138
|
}
|
|
139
|
-
if (!(0,
|
|
139
|
+
if (!(0, kind_1.IsSchema)(schema.additionalProperties)) {
|
|
140
140
|
return Default(schema, path, knownProperties);
|
|
141
141
|
}
|
|
142
142
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -14,9 +14,9 @@ const index_5 = require("../check/index");
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
const index_6 = require("../guard/index");
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
|
-
//
|
|
17
|
+
// KindGuard
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
|
-
const
|
|
19
|
+
const kind_1 = require("../../type/guard/kind");
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
21
|
// Errors
|
|
22
22
|
// ------------------------------------------------------------------
|
|
@@ -47,7 +47,7 @@ exports.TransformEncodeError = TransformEncodeError;
|
|
|
47
47
|
// prettier-ignore
|
|
48
48
|
function Default(schema, path, value) {
|
|
49
49
|
try {
|
|
50
|
-
return (0,
|
|
50
|
+
return (0, kind_1.IsTransform)(schema) ? schema[index_1.TransformKind].Encode(value) : value;
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
53
53
|
throw new TransformEncodeError(schema, path, value, error);
|
|
@@ -81,7 +81,7 @@ function FromIntersect(schema, references, path, value) {
|
|
|
81
81
|
if (knownKey in knownProperties) {
|
|
82
82
|
knownProperties[knownKey] = Visit(knownSchema, references, `${path}/${knownKey}`, knownProperties[knownKey]);
|
|
83
83
|
}
|
|
84
|
-
if (!(0,
|
|
84
|
+
if (!(0, kind_1.IsTransform)(schema.unevaluatedProperties)) {
|
|
85
85
|
return knownProperties;
|
|
86
86
|
}
|
|
87
87
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -110,13 +110,13 @@ function FromObject(schema, references, path, value) {
|
|
|
110
110
|
// if the property value is undefined, but the target is not, nor does it satisfy exact optional
|
|
111
111
|
// property policy, then we need to continue. This is a special case for optional property handling
|
|
112
112
|
// where a transforms wrapped in a optional modifiers should not run.
|
|
113
|
-
if ((0, index_6.IsUndefined)(knownProperties[key]) && (!(0,
|
|
113
|
+
if ((0, index_6.IsUndefined)(knownProperties[key]) && (!(0, kind_1.IsUndefined)(schema.properties[key]) ||
|
|
114
114
|
policy_1.TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
|
|
115
115
|
continue;
|
|
116
116
|
// encode property
|
|
117
117
|
knownProperties[key] = Visit(schema.properties[key], references, `${path}/${key}`, knownProperties[key]);
|
|
118
118
|
}
|
|
119
|
-
if (!(0,
|
|
119
|
+
if (!(0, kind_1.IsSchema)(schema.additionalProperties)) {
|
|
120
120
|
return knownProperties;
|
|
121
121
|
}
|
|
122
122
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -140,7 +140,7 @@ function FromRecord(schema, references, path, value) {
|
|
|
140
140
|
if (knownKeys.test(key)) {
|
|
141
141
|
knownProperties[key] = Visit(schema.patternProperties[pattern], references, `${path}/${key}`, knownProperties[key]);
|
|
142
142
|
}
|
|
143
|
-
if (!(0,
|
|
143
|
+
if (!(0, kind_1.IsSchema)(schema.additionalProperties)) {
|
|
144
144
|
return knownProperties;
|
|
145
145
|
}
|
|
146
146
|
const unknownKeys = Object.getOwnPropertyNames(knownProperties);
|
|
@@ -5,76 +5,76 @@ exports.HasTransform = HasTransform;
|
|
|
5
5
|
const index_1 = require("../deref/index");
|
|
6
6
|
const index_2 = require("../../type/symbols/index");
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
//
|
|
8
|
+
// KindGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
const
|
|
10
|
+
const kind_1 = require("../../type/guard/kind");
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// ValueGuard
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const index_3 = require("../guard/index");
|
|
15
15
|
// prettier-ignore
|
|
16
16
|
function FromArray(schema, references) {
|
|
17
|
-
return (0,
|
|
17
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.items, references);
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
20
|
function FromAsyncIterator(schema, references) {
|
|
21
|
-
return (0,
|
|
21
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.items, references);
|
|
22
22
|
}
|
|
23
23
|
// prettier-ignore
|
|
24
24
|
function FromConstructor(schema, references) {
|
|
25
|
-
return (0,
|
|
25
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
26
26
|
}
|
|
27
27
|
// prettier-ignore
|
|
28
28
|
function FromFunction(schema, references) {
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
30
30
|
}
|
|
31
31
|
// prettier-ignore
|
|
32
32
|
function FromIntersect(schema, references) {
|
|
33
|
-
return (0,
|
|
33
|
+
return (0, kind_1.IsTransform)(schema) || (0, kind_1.IsTransform)(schema.unevaluatedProperties) || schema.allOf.some((schema) => Visit(schema, references));
|
|
34
34
|
}
|
|
35
35
|
// prettier-ignore
|
|
36
36
|
function FromIterator(schema, references) {
|
|
37
|
-
return (0,
|
|
37
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.items, references);
|
|
38
38
|
}
|
|
39
39
|
// prettier-ignore
|
|
40
40
|
function FromNot(schema, references) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.not, references);
|
|
42
42
|
}
|
|
43
43
|
// prettier-ignore
|
|
44
44
|
function FromObject(schema, references) {
|
|
45
|
-
return ((0,
|
|
45
|
+
return ((0, kind_1.IsTransform)(schema) ||
|
|
46
46
|
Object.values(schema.properties).some((schema) => Visit(schema, references)) ||
|
|
47
|
-
((0,
|
|
47
|
+
((0, kind_1.IsSchema)(schema.additionalProperties) && Visit(schema.additionalProperties, references)));
|
|
48
48
|
}
|
|
49
49
|
// prettier-ignore
|
|
50
50
|
function FromPromise(schema, references) {
|
|
51
|
-
return (0,
|
|
51
|
+
return (0, kind_1.IsTransform)(schema) || Visit(schema.item, references);
|
|
52
52
|
}
|
|
53
53
|
// prettier-ignore
|
|
54
54
|
function FromRecord(schema, references) {
|
|
55
55
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
56
56
|
const property = schema.patternProperties[pattern];
|
|
57
|
-
return (0,
|
|
57
|
+
return (0, kind_1.IsTransform)(schema) || Visit(property, references) || ((0, kind_1.IsSchema)(schema.additionalProperties) && (0, kind_1.IsTransform)(schema.additionalProperties));
|
|
58
58
|
}
|
|
59
59
|
// prettier-ignore
|
|
60
60
|
function FromRef(schema, references) {
|
|
61
|
-
if ((0,
|
|
61
|
+
if ((0, kind_1.IsTransform)(schema))
|
|
62
62
|
return true;
|
|
63
63
|
return Visit((0, index_1.Deref)(schema, references), references);
|
|
64
64
|
}
|
|
65
65
|
// prettier-ignore
|
|
66
66
|
function FromThis(schema, references) {
|
|
67
|
-
if ((0,
|
|
67
|
+
if ((0, kind_1.IsTransform)(schema))
|
|
68
68
|
return true;
|
|
69
69
|
return Visit((0, index_1.Deref)(schema, references), references);
|
|
70
70
|
}
|
|
71
71
|
// prettier-ignore
|
|
72
72
|
function FromTuple(schema, references) {
|
|
73
|
-
return (0,
|
|
73
|
+
return (0, kind_1.IsTransform)(schema) || (!(0, index_3.IsUndefined)(schema.items) && schema.items.some((schema) => Visit(schema, references)));
|
|
74
74
|
}
|
|
75
75
|
// prettier-ignore
|
|
76
76
|
function FromUnion(schema, references) {
|
|
77
|
-
return (0,
|
|
77
|
+
return (0, kind_1.IsTransform)(schema) || schema.anyOf.some((schema) => Visit(schema, references));
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
80
|
function Visit(schema, references) {
|
|
@@ -114,7 +114,7 @@ function Visit(schema, references) {
|
|
|
114
114
|
case 'Union':
|
|
115
115
|
return FromUnion(schema_, references_);
|
|
116
116
|
default:
|
|
117
|
-
return (0,
|
|
117
|
+
return (0, kind_1.IsTransform)(schema);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
const visited = new Set();
|
|
@@ -12,7 +12,10 @@ export declare const Module: Runtime.Module<{
|
|
|
12
12
|
}>;
|
|
13
13
|
ModuleType: Runtime.IUnion<unknown>;
|
|
14
14
|
ModuleProperties: Runtime.IUnion<Types.TProperties>;
|
|
15
|
-
ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties
|
|
15
|
+
ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties, {
|
|
16
|
+
[x: string]: Types.TSchema;
|
|
17
|
+
[x: number]: Types.TSchema;
|
|
18
|
+
}>>;
|
|
16
19
|
Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>;
|
|
17
20
|
Keyword: Runtime.IUnion<Types.TAny | Types.TNever | Types.TString | Types.TBoolean | Types.TNumber | Types.TInteger | Types.TBigInt | Types.TNull | Types.TSymbol | Types.TUndefined | Types.TUnknown | Types.TVoid>;
|
|
18
21
|
KeyOf: Runtime.IUnion<boolean>;
|
|
@@ -279,7 +279,9 @@ const FactorExtends = (Type, Extends) => {
|
|
|
279
279
|
// prettier-ignore
|
|
280
280
|
const FactorIndexArray = (Type, IndexArray) => {
|
|
281
281
|
const [Left, Right] = DestructureRight(IndexArray);
|
|
282
|
-
return (!Types.ValueGuard.IsUndefined(Right) ? (
|
|
282
|
+
return (!Types.ValueGuard.IsUndefined(Right) ? (
|
|
283
|
+
// note: Indexed types require reimplementation to replace `[number]` indexers
|
|
284
|
+
Right.length === 1 ? Types.Index(FactorIndexArray(Type, Left), Right[0]) :
|
|
283
285
|
Right.length === 0 ? Types.Array(FactorIndexArray(Type, Left)) :
|
|
284
286
|
Types.Never()) : Type);
|
|
285
287
|
};
|
|
@@ -456,7 +456,7 @@ type Partial = Static.Tuple<[
|
|
|
456
456
|
Static.Const<RAngle>
|
|
457
457
|
], PartialMapping>;
|
|
458
458
|
interface RequiredMapping extends Static.IMapping {
|
|
459
|
-
output: this['input'] extends ['Required', LAngle, infer Type extends Types.TSchema, RAngle] ? Types.
|
|
459
|
+
output: this['input'] extends ['Required', LAngle, infer Type extends Types.TSchema, RAngle] ? Types.TRequired<Type> : never;
|
|
460
460
|
}
|
|
461
461
|
type Required = Static.Tuple<[
|
|
462
462
|
Static.Const<'Required'>,
|
|
@@ -465,7 +465,7 @@ type Required = Static.Tuple<[
|
|
|
465
465
|
Static.Const<RAngle>
|
|
466
466
|
], RequiredMapping>;
|
|
467
467
|
interface PickMapping extends Static.IMapping {
|
|
468
|
-
output: this['input'] extends ['Pick', LAngle, infer Type extends Types.TSchema, Comma, infer
|
|
468
|
+
output: this['input'] extends ['Pick', LAngle, infer Type extends Types.TSchema, Comma, infer Key extends Types.TSchema, RAngle] ? Types.TPick<Type, Key> : never;
|
|
469
469
|
}
|
|
470
470
|
type Pick = Static.Tuple<[
|
|
471
471
|
Static.Const<'Pick'>,
|
|
@@ -476,7 +476,7 @@ type Pick = Static.Tuple<[
|
|
|
476
476
|
Static.Const<RAngle>
|
|
477
477
|
], PickMapping>;
|
|
478
478
|
interface OmitMapping extends Static.IMapping {
|
|
479
|
-
output: this['input'] extends ['Omit', LAngle, infer Type extends Types.TSchema, Comma, infer
|
|
479
|
+
output: this['input'] extends ['Omit', LAngle, infer Type extends Types.TSchema, Comma, infer Key extends Types.TSchema, RAngle] ? Types.TOmit<Type, Key> : never;
|
|
480
480
|
}
|
|
481
481
|
type Omit = Static.Tuple<[
|
|
482
482
|
Static.Const<'Omit'>,
|
|
@@ -24,5 +24,5 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
24
24
|
items: T;
|
|
25
25
|
}
|
|
26
26
|
/** `[Json]` Creates an Array type */
|
|
27
|
-
export declare function Array<
|
|
27
|
+
export declare function Array<Type extends TSchema>(items: Type, options?: ArrayOptions): TArray<Type>;
|
|
28
28
|
export {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { Ensure } from '../helpers/index.mjs';
|
|
1
2
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
3
|
+
import { type TComputed } from '../computed/index.mjs';
|
|
2
4
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
3
5
|
import { type TUnion } from '../union/index.mjs';
|
|
4
6
|
import { type TPromise } from '../promise/index.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
import { type TRef } from '../ref/index.mjs';
|
|
8
|
+
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<(TComputed<'Awaited', [TComputed<Target, Parameters>]>)>;
|
|
9
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'Awaited', [TRef<Ref>]>>;
|
|
10
|
+
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<Right, [...Result, TAwaited<Left>]> : Result);
|
|
11
|
+
export type TAwaited<Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TPromise<infer Type extends TSchema> ? TAwaited<Type> : Type);
|
|
7
12
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
8
|
-
export declare function Awaited<T extends TSchema>(
|
|
13
|
+
export declare function Awaited<T extends TSchema>(type: T, options?: SchemaOptions): TAwaited<T>;
|
|
9
14
|
export {};
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
|
+
import { Computed } from '../computed/index.mjs';
|
|
1
3
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
4
|
import { Union } from '../union/index.mjs';
|
|
3
|
-
import {
|
|
5
|
+
import { Ref } from '../ref/index.mjs';
|
|
4
6
|
// ------------------------------------------------------------------
|
|
5
7
|
// TypeGuard
|
|
6
8
|
// ------------------------------------------------------------------
|
|
7
|
-
import { IsIntersect, IsUnion, IsPromise } from '../guard/kind.mjs';
|
|
9
|
+
import { IsIntersect, IsUnion, IsPromise, IsRef, IsComputed } from '../guard/kind.mjs';
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
function FromComputed(target, parameters) {
|
|
12
|
+
return Computed('Awaited', [Computed(target, parameters)]);
|
|
13
|
+
}
|
|
8
14
|
// prettier-ignore
|
|
9
|
-
function
|
|
10
|
-
return
|
|
15
|
+
function FromRef($ref) {
|
|
16
|
+
return Computed('Awaited', [Ref($ref)]);
|
|
11
17
|
}
|
|
12
18
|
// prettier-ignore
|
|
13
|
-
function FromIntersect(
|
|
14
|
-
return Intersect(FromRest(
|
|
19
|
+
function FromIntersect(types) {
|
|
20
|
+
return Intersect(FromRest(types));
|
|
15
21
|
}
|
|
16
22
|
// prettier-ignore
|
|
17
|
-
function FromUnion(
|
|
18
|
-
return Union(FromRest(
|
|
23
|
+
function FromUnion(types) {
|
|
24
|
+
return Union(FromRest(types));
|
|
19
25
|
}
|
|
20
26
|
// prettier-ignore
|
|
21
|
-
function FromPromise(
|
|
22
|
-
return
|
|
27
|
+
function FromPromise(type) {
|
|
28
|
+
return Awaited(type);
|
|
23
29
|
}
|
|
24
|
-
// ----------------------------------------------------------------
|
|
25
|
-
// AwaitedResolve
|
|
26
|
-
// ----------------------------------------------------------------
|
|
27
30
|
// prettier-ignore
|
|
28
|
-
function
|
|
29
|
-
return (
|
|
30
|
-
IsUnion(T) ? FromUnion(T.anyOf) :
|
|
31
|
-
IsPromise(T) ? FromPromise(T.item) :
|
|
32
|
-
T);
|
|
31
|
+
function FromRest(types) {
|
|
32
|
+
return types.map(type => Awaited(type));
|
|
33
33
|
}
|
|
34
34
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
35
|
-
export function Awaited(
|
|
36
|
-
return CreateType(
|
|
35
|
+
export function Awaited(type, options) {
|
|
36
|
+
return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect(type.allOf) : IsUnion(type) ? FromUnion(type.anyOf) : IsPromise(type) ? FromPromise(type.item) : IsRef(type) ? FromRef(type.$ref) : type, options);
|
|
37
37
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { Kind } from '../symbols/symbols.mjs';
|
|
3
|
+
export interface TComputed<Target extends string = string, Parameters extends TSchema[] = []> extends TSchema {
|
|
4
|
+
[Kind]: 'Computed';
|
|
5
|
+
target: Target;
|
|
6
|
+
parameters: Parameters;
|
|
7
|
+
}
|
|
8
|
+
/** `[Internal]` Creates a deferred computed type. This type is used exclusively in modules to defer resolution of computable types that contain interior references */
|
|
9
|
+
export declare function Computed<Target extends string, Parameters extends TSchema[]>(target: Target, parameters: [...Parameters], options?: SchemaOptions): TComputed<Target, Parameters>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/index.mjs';
|
|
2
|
+
import { Kind } from '../symbols/symbols.mjs';
|
|
3
|
+
/** `[Internal]` Creates a deferred computed type. This type is used exclusively in modules to defer resolution of computable types that contain interior references */
|
|
4
|
+
export function Computed(target, parameters, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Computed', target, parameters }, options);
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './computed.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './computed.mjs';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index.mjs';
|
|
2
2
|
import { TransformOptions } from '../transform/index.mjs';
|
|
3
|
-
import { TTemplateLiteral } from '../template-literal/index.mjs';
|
|
4
|
-
import { TArray } from '../array/index.mjs';
|
|
5
|
-
import { TBoolean } from '../boolean/index.mjs';
|
|
3
|
+
import type { TTemplateLiteral } from '../template-literal/index.mjs';
|
|
4
|
+
import type { TArray } from '../array/index.mjs';
|
|
5
|
+
import type { TBoolean } from '../boolean/index.mjs';
|
|
6
|
+
import type { TComputed } from '../computed/index.mjs';
|
|
6
7
|
import type { TRecord } from '../record/index.mjs';
|
|
7
8
|
import type { TString } from '../string/index.mjs';
|
|
8
9
|
import type { TUnion } from '../union/index.mjs';
|
|
@@ -15,7 +16,7 @@ import type { TImport } from '../module/index.mjs';
|
|
|
15
16
|
import type { TInteger } from '../integer/index.mjs';
|
|
16
17
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
17
18
|
import type { TIterator } from '../iterator/index.mjs';
|
|
18
|
-
import type { TLiteral } from '../literal/index.mjs';
|
|
19
|
+
import type { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
19
20
|
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
20
21
|
import type { TNever } from '../never/index.mjs';
|
|
21
22
|
import type { TNot } from '../not/index.mjs';
|
|
@@ -51,6 +52,8 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
|
|
|
51
52
|
export declare function IsBigInt(value: unknown): value is TBigInt;
|
|
52
53
|
/** `[Kind-Only]` Returns true if the given value is TBoolean */
|
|
53
54
|
export declare function IsBoolean(value: unknown): value is TBoolean;
|
|
55
|
+
/** `[Kind-Only]` Returns true if the given value is TComputed */
|
|
56
|
+
export declare function IsComputed(value: unknown): value is TComputed;
|
|
54
57
|
/** `[Kind-Only]` Returns true if the given value is TConstructor */
|
|
55
58
|
export declare function IsConstructor(value: unknown): value is TConstructor;
|
|
56
59
|
/** `[Kind-Only]` Returns true if the given value is TDate */
|
|
@@ -77,6 +80,8 @@ export declare function IsLiteralString(value: unknown): value is TLiteral<strin
|
|
|
77
80
|
export declare function IsLiteralNumber(value: unknown): value is TLiteral<number>;
|
|
78
81
|
/** `[Kind-Only]` Returns true if the given value is TLiteral<boolean> */
|
|
79
82
|
export declare function IsLiteralBoolean(value: unknown): value is TLiteral<boolean>;
|
|
83
|
+
/** `[Kind-Only]` Returns true if the given value is TLiteralValue */
|
|
84
|
+
export declare function IsLiteralValue(value: unknown): value is TLiteralValue;
|
|
80
85
|
/** `[Kind-Only]` Returns true if the given value is TLiteral */
|
|
81
86
|
export declare function IsLiteral(value: unknown): value is TLiteral;
|
|
82
87
|
/** `[Kind-Only]` Returns true if the given value is a TMappedKey */
|
|
@@ -28,6 +28,10 @@ export function IsBigInt(value) {
|
|
|
28
28
|
export function IsBoolean(value) {
|
|
29
29
|
return IsKindOf(value, 'Boolean');
|
|
30
30
|
}
|
|
31
|
+
/** `[Kind-Only]` Returns true if the given value is TComputed */
|
|
32
|
+
export function IsComputed(value) {
|
|
33
|
+
return IsKindOf(value, 'Computed');
|
|
34
|
+
}
|
|
31
35
|
/** `[Kind-Only]` Returns true if the given value is TConstructor */
|
|
32
36
|
export function IsConstructor(value) {
|
|
33
37
|
return IsKindOf(value, 'Constructor');
|
|
@@ -76,6 +80,10 @@ export function IsLiteralNumber(value) {
|
|
|
76
80
|
export function IsLiteralBoolean(value) {
|
|
77
81
|
return IsLiteral(value) && ValueGuard.IsBoolean(value.const);
|
|
78
82
|
}
|
|
83
|
+
/** `[Kind-Only]` Returns true if the given value is TLiteralValue */
|
|
84
|
+
export function IsLiteralValue(value) {
|
|
85
|
+
return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
|
|
86
|
+
}
|
|
79
87
|
/** `[Kind-Only]` Returns true if the given value is TLiteral */
|
|
80
88
|
export function IsLiteral(value) {
|
|
81
89
|
return IsKindOf(value, 'Literal');
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../error/index.mjs';
|
|
3
3
|
import { TransformOptions } from '../transform/index.mjs';
|
|
4
|
-
import { TTemplateLiteral } from '../template-literal/index.mjs';
|
|
5
|
-
import { TArray } from '../array/index.mjs';
|
|
6
|
-
import { TBoolean } from '../boolean/index.mjs';
|
|
4
|
+
import type { TTemplateLiteral } from '../template-literal/index.mjs';
|
|
5
|
+
import type { TArray } from '../array/index.mjs';
|
|
6
|
+
import type { TBoolean } from '../boolean/index.mjs';
|
|
7
|
+
import type { TComputed } from '../computed/index.mjs';
|
|
7
8
|
import type { TRecord } from '../record/index.mjs';
|
|
8
9
|
import type { TString } from '../string/index.mjs';
|
|
9
10
|
import type { TUnion } from '../union/index.mjs';
|
|
@@ -54,6 +55,8 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
|
|
|
54
55
|
export declare function IsBigInt(value: unknown): value is TBigInt;
|
|
55
56
|
/** Returns true if the given value is TBoolean */
|
|
56
57
|
export declare function IsBoolean(value: unknown): value is TBoolean;
|
|
58
|
+
/** Returns true if the given value is TComputed */
|
|
59
|
+
export declare function IsComputed(value: unknown): value is TComputed;
|
|
57
60
|
/** Returns true if the given value is TConstructor */
|
|
58
61
|
export declare function IsConstructor(value: unknown): value is TConstructor;
|
|
59
62
|
/** Returns true if the given value is TDate */
|
|
@@ -9,6 +9,7 @@ const KnownTypes = [
|
|
|
9
9
|
'AsyncIterator',
|
|
10
10
|
'BigInt',
|
|
11
11
|
'Boolean',
|
|
12
|
+
'Computed',
|
|
12
13
|
'Constructor',
|
|
13
14
|
'Date',
|
|
14
15
|
'Enum',
|
|
@@ -142,6 +143,10 @@ export function IsBoolean(value) {
|
|
|
142
143
|
value.type === 'boolean' &&
|
|
143
144
|
IsOptionalString(value.$id));
|
|
144
145
|
}
|
|
146
|
+
/** Returns true if the given value is TComputed */
|
|
147
|
+
export function IsComputed(value) {
|
|
148
|
+
return IsKindOf(value, 'Computed') && IsString(value.target) && ValueGuard.IsArray(value.parameters) && value.parameters.every((schema) => IsSchema(schema));
|
|
149
|
+
}
|
|
145
150
|
/** Returns true if the given value is TConstructor */
|
|
146
151
|
export function IsConstructor(value) {
|
|
147
152
|
// prettier-ignore
|
|
@@ -3,11 +3,11 @@ import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
|
3
3
|
import type { TProperties } from '../object/index.mjs';
|
|
4
4
|
import { type TIndex } from './indexed.mjs';
|
|
5
5
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
6
|
-
type TMappedIndexPropertyKey<
|
|
7
|
-
[_ in
|
|
6
|
+
type TMappedIndexPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
|
|
7
|
+
[_ in Key]: TIndex<Type, [Key]>;
|
|
8
8
|
};
|
|
9
|
-
type TMappedIndexPropertyKeys<
|
|
10
|
-
type TMappedIndexProperties<
|
|
11
|
-
export type TIndexFromMappedKey<
|
|
12
|
-
export declare function IndexFromMappedKey<
|
|
9
|
+
type TMappedIndexPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TMappedIndexPropertyKeys<Type, Right, Result & TMappedIndexPropertyKey<Type, Left>> : Result);
|
|
10
|
+
type TMappedIndexProperties<Type extends TSchema, MappedKey extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<Type, MappedKey['keys']>>;
|
|
11
|
+
export type TIndexFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TMappedIndexProperties<Type, MappedKey>> = (Ensure<TMappedResult<Properties>>);
|
|
12
|
+
export declare function IndexFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TMappedIndexProperties<Type, MappedKey>>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedResult<Properties>;
|
|
13
13
|
export {};
|
|
@@ -2,21 +2,21 @@ import { Index } from './indexed.mjs';
|
|
|
2
2
|
import { MappedResult } from '../mapped/index.mjs';
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function MappedIndexPropertyKey(
|
|
6
|
-
return { [
|
|
5
|
+
function MappedIndexPropertyKey(type, key, options) {
|
|
6
|
+
return { [key]: Index(type, [key], Clone(options)) };
|
|
7
7
|
}
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function MappedIndexPropertyKeys(
|
|
10
|
-
return
|
|
11
|
-
return { ...
|
|
9
|
+
function MappedIndexPropertyKeys(type, propertyKeys, options) {
|
|
10
|
+
return propertyKeys.reduce((result, left) => {
|
|
11
|
+
return { ...result, ...MappedIndexPropertyKey(type, left, options) };
|
|
12
12
|
}, {});
|
|
13
13
|
}
|
|
14
14
|
// prettier-ignore
|
|
15
|
-
function MappedIndexProperties(
|
|
16
|
-
return MappedIndexPropertyKeys(
|
|
15
|
+
function MappedIndexProperties(type, mappedKey, options) {
|
|
16
|
+
return MappedIndexPropertyKeys(type, mappedKey.keys, options);
|
|
17
17
|
}
|
|
18
18
|
// prettier-ignore
|
|
19
|
-
export function IndexFromMappedKey(
|
|
20
|
-
const
|
|
21
|
-
return MappedResult(
|
|
19
|
+
export function IndexFromMappedKey(type, mappedKey, options) {
|
|
20
|
+
const properties = MappedIndexProperties(type, mappedKey, options);
|
|
21
|
+
return MappedResult(properties);
|
|
22
22
|
}
|
|
@@ -3,10 +3,10 @@ import type { TProperties } from '../object/index.mjs';
|
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
5
5
|
import { type TIndex } from './index.mjs';
|
|
6
|
-
type TFromProperties<
|
|
7
|
-
[K2 in keyof
|
|
6
|
+
type TFromProperties<Type extends TSchema, Properties extends TProperties> = ({
|
|
7
|
+
[K2 in keyof Properties]: TIndex<Type, TIndexPropertyKeys<Properties[K2]>>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<
|
|
10
|
-
export type TIndexFromMappedResult<
|
|
11
|
-
export declare function IndexFromMappedResult<
|
|
9
|
+
type TFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult> = (TFromProperties<Type, MappedResult['properties']>);
|
|
10
|
+
export type TIndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>> = (TMappedResult<Properties>);
|
|
11
|
+
export declare function IndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -2,19 +2,20 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
3
3
|
import { Index } from './index.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function FromProperties(
|
|
6
|
-
const
|
|
7
|
-
for (const K2 of Object.getOwnPropertyNames(
|
|
8
|
-
|
|
5
|
+
function FromProperties(type, properties, options) {
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const K2 of Object.getOwnPropertyNames(properties)) {
|
|
8
|
+
const keys = IndexPropertyKeys(properties[K2]);
|
|
9
|
+
result[K2] = Index(type, keys, options);
|
|
9
10
|
}
|
|
10
|
-
return
|
|
11
|
+
return result;
|
|
11
12
|
}
|
|
12
13
|
// prettier-ignore
|
|
13
|
-
function FromMappedResult(
|
|
14
|
-
return FromProperties(
|
|
14
|
+
function FromMappedResult(type, mappedResult, options) {
|
|
15
|
+
return FromProperties(type, mappedResult.properties, options);
|
|
15
16
|
}
|
|
16
17
|
// prettier-ignore
|
|
17
|
-
export function IndexFromMappedResult(
|
|
18
|
-
const
|
|
19
|
-
return MappedResult(
|
|
18
|
+
export function IndexFromMappedResult(type, mappedResult, options) {
|
|
19
|
+
const properties = FromMappedResult(type, mappedResult, options);
|
|
20
|
+
return MappedResult(properties);
|
|
20
21
|
}
|