@sinclair/typebox 0.33.22 → 0.34.1
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/compiler/compiler.d.ts +2 -2
- package/build/cjs/compiler/compiler.js +13 -2
- package/build/cjs/errors/errors.js +7 -0
- package/build/cjs/index.d.ts +1 -2
- package/build/cjs/index.js +1 -2
- package/build/cjs/syntax/parse.d.ts +14 -15
- package/build/cjs/syntax/parse.js +6 -5
- package/build/cjs/syntax/runtime.d.ts +20 -4
- package/build/cjs/syntax/runtime.js +183 -28
- package/build/cjs/syntax/static.d.ts +107 -23
- 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/{deref → computed}/index.js +1 -1
- package/build/cjs/type/guard/kind.d.ts +12 -4
- package/build/cjs/type/guard/kind.js +15 -0
- package/build/cjs/type/guard/type.d.ts +9 -3
- package/build/cjs/type/guard/type.js +19 -0
- package/build/cjs/type/index.d.ts +1 -2
- package/build/cjs/type/index.js +1 -2
- 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/index.d.ts +1 -0
- package/build/cjs/type/{strict → module}/index.js +1 -1
- 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 +27 -0
- package/build/cjs/type/module/module.js +37 -0
- 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/ref/ref.d.ts +4 -7
- package/build/cjs/type/ref/ref.js +3 -11
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/static/static.d.ts +1 -1
- 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 +45 -68
- package/build/cjs/type/type/json.js +82 -98
- package/build/cjs/type/type/type.d.ts +1 -2
- package/build/cjs/type/type/type.js +55 -57
- 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/cast/cast.js +8 -1
- package/build/cjs/value/check/check.js +11 -4
- package/build/cjs/value/clean/clean.js +8 -1
- package/build/cjs/value/convert/convert.js +7 -0
- package/build/cjs/value/create/create.js +7 -0
- package/build/cjs/value/default/default.js +7 -0
- package/build/cjs/value/transform/decode.js +18 -7
- package/build/cjs/value/transform/encode.js +18 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/compiler/compiler.d.mts +2 -2
- package/build/esm/compiler/compiler.mjs +13 -2
- package/build/esm/errors/errors.mjs +7 -0
- package/build/esm/index.d.mts +1 -2
- package/build/esm/index.mjs +1 -2
- package/build/esm/syntax/parse.d.mts +14 -15
- package/build/esm/syntax/parse.mjs +6 -5
- package/build/esm/syntax/runtime.d.mts +20 -4
- package/build/esm/syntax/runtime.mjs +183 -28
- package/build/esm/syntax/static.d.mts +107 -23
- 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 +12 -4
- package/build/esm/type/guard/kind.mjs +12 -0
- package/build/esm/type/guard/type.d.mts +9 -3
- package/build/esm/type/guard/type.mjs +17 -0
- package/build/esm/type/index.d.mts +1 -2
- package/build/esm/type/index.mjs +1 -2
- 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/index.d.mts +1 -0
- package/build/esm/type/module/index.mjs +1 -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 +27 -0
- package/build/esm/type/module/module.mjs +31 -0
- 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/ref/ref.d.mts +4 -7
- package/build/esm/type/ref/ref.mjs +3 -11
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/static/static.d.mts +1 -1
- 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 +45 -68
- package/build/esm/type/type/json.mjs +47 -63
- package/build/esm/type/type/type.d.mts +1 -2
- package/build/esm/type/type/type.mjs +1 -2
- 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/cast/cast.mjs +9 -2
- package/build/esm/value/check/check.mjs +11 -4
- package/build/esm/value/clean/clean.mjs +9 -2
- package/build/esm/value/convert/convert.mjs +7 -0
- package/build/esm/value/create/create.mjs +7 -0
- package/build/esm/value/default/default.mjs +7 -0
- package/build/esm/value/transform/decode.mjs +13 -2
- package/build/esm/value/transform/encode.mjs +13 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +230 -97
- package/build/cjs/type/deref/deref.d.ts +0 -22
- package/build/cjs/type/deref/deref.js +0 -106
- package/build/cjs/type/deref/index.d.ts +0 -1
- package/build/cjs/type/strict/index.d.ts +0 -1
- package/build/cjs/type/strict/strict.d.ts +0 -12
- package/build/cjs/type/strict/strict.js +0 -16
- package/build/esm/type/deref/deref.d.mts +0 -22
- package/build/esm/type/deref/deref.mjs +0 -102
- package/build/esm/type/deref/index.d.mts +0 -1
- package/build/esm/type/deref/index.mjs +0 -1
- package/build/esm/type/strict/index.d.mts +0 -1
- package/build/esm/type/strict/index.mjs +0 -1
- package/build/esm/type/strict/strict.d.mts +0 -12
- package/build/esm/type/strict/strict.mjs +0 -12
|
@@ -16,6 +16,7 @@ type SemiColon = ';';
|
|
|
16
16
|
type SingleQuote = "'";
|
|
17
17
|
type DoubleQuote = '"';
|
|
18
18
|
type Tilde = '`';
|
|
19
|
+
type Equals = '=';
|
|
19
20
|
interface DelimitTailMapping<_ = unknown> extends Static.IMapping {
|
|
20
21
|
output: (this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer H, _, infer I, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, H, I, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer H, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, H, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer G, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, G, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer F, _, infer Rest extends unknown[]] ? [A, B, C, D, E, F, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer E, _, infer Rest extends unknown[]] ? [A, B, C, D, E, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer D, _, infer Rest extends unknown[]] ? [A, B, C, D, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer C, _, infer Rest extends unknown[]] ? [A, B, C, ...Rest] : this['input'] extends [_, infer A, _, infer B, _, infer Rest extends unknown[]] ? [A, B, ...Rest] : this['input'] extends [_, infer A, _, infer Rest extends unknown[]] ? [A, ...Rest] : this['input'] extends [_, infer Rest extends unknown[]] ? [...Rest] : this['input'] extends [_] ? [] : [
|
|
21
22
|
]);
|
|
@@ -41,10 +42,90 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
|
|
|
41
42
|
Static.Tuple<[Parser, DelimitTail<Parser, Delimiter>]>,
|
|
42
43
|
Static.Tuple<[]>
|
|
43
44
|
], DelimitMapping>);
|
|
45
|
+
type Deref<Context extends Types.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : Types.TRef<Ref>);
|
|
46
|
+
interface ExportModifierMapping extends Static.IMapping {
|
|
47
|
+
output: this['input'] extends [string] ? true : false;
|
|
48
|
+
}
|
|
49
|
+
type ExportModifier = Static.Union<[
|
|
50
|
+
Static.Tuple<[Static.Const<'export'>]>,
|
|
51
|
+
Static.Tuple<[]>
|
|
52
|
+
], ExportModifierMapping>;
|
|
53
|
+
interface TypeAliasDeclarationMapping extends Static.IMapping {
|
|
54
|
+
output: this['input'] extends [infer _Export extends boolean, 'type', infer Ident extends string, Equals, infer Type extends Types.TSchema] ? {
|
|
55
|
+
[_ in Ident]: Type;
|
|
56
|
+
} : never;
|
|
57
|
+
}
|
|
58
|
+
type TypeAliasDeclaration = Static.Tuple<[
|
|
59
|
+
ExportModifier,
|
|
60
|
+
Static.Const<'type'>,
|
|
61
|
+
Static.Ident,
|
|
62
|
+
Static.Const<Equals>,
|
|
63
|
+
Type
|
|
64
|
+
], TypeAliasDeclarationMapping>;
|
|
65
|
+
type HeritageListDelimiter = Static.Union<[Static.Tuple<[Static.Const<Comma>, Static.Const<Newline>]>, Static.Tuple<[Static.Const<Comma>]>]>;
|
|
66
|
+
type HeritageListReduce<Values extends string[], Context extends Types.TProperties, Result extends Types.TSchema[] = []> = (Values extends [infer Ref extends string, ...infer Rest extends string[]] ? HeritageListReduce<Rest, Context, [...Result, Deref<Context, Ref>]> : Result);
|
|
67
|
+
interface HeritageListMapping extends Static.IMapping {
|
|
68
|
+
output: (this['context'] extends Types.TProperties ? this['input'] extends string[] ? HeritageListReduce<this['input'], this['context']> : [] : []);
|
|
69
|
+
}
|
|
70
|
+
type HeritageList = Static.Union<[Delimit<Static.Ident, HeritageListDelimiter>], HeritageListMapping>;
|
|
71
|
+
interface HeritageMapping extends Static.IMapping {
|
|
72
|
+
output: this['input'] extends ['extends', infer List extends Types.TSchema[]] ? List : [];
|
|
73
|
+
}
|
|
74
|
+
type Heritage = Static.Union<[
|
|
75
|
+
Static.Tuple<[Static.Const<'extends'>, HeritageList]>,
|
|
76
|
+
Static.Tuple<[]>
|
|
77
|
+
], HeritageMapping>;
|
|
78
|
+
interface InterfaceDeclarationMapping extends Static.IMapping {
|
|
79
|
+
output: this['input'] extends [boolean, 'interface', infer Ident extends string, infer Heritage extends Types.TSchema[], LBrace, infer Properties extends Types.TProperties, RBrace] ? {
|
|
80
|
+
[_ in Ident]: Types.TIntersectEvaluated<[...Heritage, Types.TObject<Properties>]>;
|
|
81
|
+
} : never;
|
|
82
|
+
}
|
|
83
|
+
type InterfaceDeclaration = Static.Tuple<[
|
|
84
|
+
ExportModifier,
|
|
85
|
+
Static.Const<'interface'>,
|
|
86
|
+
Static.Ident,
|
|
87
|
+
Heritage,
|
|
88
|
+
Static.Const<LBrace>,
|
|
89
|
+
Properties,
|
|
90
|
+
Static.Const<RBrace>
|
|
91
|
+
], InterfaceDeclarationMapping>;
|
|
92
|
+
type ModuleType = Static.Union<[
|
|
93
|
+
InterfaceDeclaration,
|
|
94
|
+
TypeAliasDeclaration
|
|
95
|
+
]>;
|
|
96
|
+
type ModulePropertiesDelimiter = Static.Union<[
|
|
97
|
+
Static.Tuple<[Static.Const<SemiColon>, Static.Const<Newline>]>,
|
|
98
|
+
Static.Tuple<[Static.Const<SemiColon>]>,
|
|
99
|
+
Static.Tuple<[Static.Const<Newline>]>
|
|
100
|
+
]>;
|
|
101
|
+
type ModulePropertiesReduce<Value extends unknown[], Result extends Types.TProperties = {}> = (Value extends [infer ModuleType extends Types.TProperties, unknown[], ...infer Rest extends unknown[]] ? ModulePropertiesReduce<Rest, Result & ModuleType> : Value extends [infer ModuleType extends Types.TProperties] ? ModulePropertiesReduce<[], Result & ModuleType> : Types.Evaluate<Result>);
|
|
102
|
+
interface ModulePropertiesMapping extends Static.IMapping {
|
|
103
|
+
output: this['input'] extends unknown[] ? ModulePropertiesReduce<this['input']> : never;
|
|
104
|
+
}
|
|
105
|
+
type ModuleProperties = Static.Union<[
|
|
106
|
+
Static.Tuple<[ModuleType, ModulePropertiesDelimiter, ModuleProperties]>,
|
|
107
|
+
Static.Tuple<[ModuleType]>,
|
|
108
|
+
Static.Tuple<[]>
|
|
109
|
+
], ModulePropertiesMapping>;
|
|
110
|
+
type ModuleIdentifier = Static.Union<[
|
|
111
|
+
Static.Tuple<[Static.Ident]>,
|
|
112
|
+
Static.Tuple<[]>
|
|
113
|
+
]>;
|
|
114
|
+
interface ModuleDeclarationMapping extends Static.IMapping {
|
|
115
|
+
output: this['input'] extends [boolean, 'module', infer _Ident extends string[], LBrace, infer Properties extends Types.TProperties, RBrace] ? Types.TModule<Properties> : never;
|
|
116
|
+
}
|
|
117
|
+
type ModuleDeclaration = Static.Tuple<[
|
|
118
|
+
ExportModifier,
|
|
119
|
+
Static.Const<'module'>,
|
|
120
|
+
ModuleIdentifier,
|
|
121
|
+
Static.Const<LBrace>,
|
|
122
|
+
ModuleProperties,
|
|
123
|
+
Static.Const<RBrace>
|
|
124
|
+
], ModuleDeclarationMapping>;
|
|
44
125
|
interface ReferenceMapping extends Static.IMapping {
|
|
45
|
-
output: this['
|
|
126
|
+
output: this['context'] extends Types.TProperties ? this['input'] extends string ? Deref<this['context'], this['input']> : never : never;
|
|
46
127
|
}
|
|
47
|
-
type Reference = Static.
|
|
128
|
+
type Reference = Static.Ident<ReferenceMapping>;
|
|
48
129
|
interface LiteralBooleanMapping extends Static.IMapping {
|
|
49
130
|
output: this['input'] extends `${infer S extends boolean}` ? Types.TLiteral<S> : never;
|
|
50
131
|
}
|
|
@@ -171,38 +252,35 @@ type Expr = Static.Tuple<[
|
|
|
171
252
|
ExprTerm,
|
|
172
253
|
ExprTail
|
|
173
254
|
], ExprBinaryMapping>;
|
|
174
|
-
|
|
255
|
+
type Type = Expr;
|
|
175
256
|
interface PropertyKeyStringMapping extends Static.IMapping {
|
|
176
257
|
output: this['input'];
|
|
177
258
|
}
|
|
178
259
|
type PropertyKeyString = Static.String<[SingleQuote, DoubleQuote], PropertyKeyStringMapping>;
|
|
179
260
|
type PropertyKey = Static.Union<[Static.Ident, PropertyKeyString]>;
|
|
180
|
-
interface
|
|
261
|
+
interface ReadonlyMapping extends Static.IMapping {
|
|
181
262
|
output: this['input'] extends ['readonly'] ? true : false;
|
|
182
263
|
}
|
|
183
|
-
type
|
|
184
|
-
interface
|
|
264
|
+
type Readonly = Static.Union<[Static.Tuple<[Static.Const<'readonly'>]>, Static.Tuple<[]>], ReadonlyMapping>;
|
|
265
|
+
interface OptionalMapping extends Static.IMapping {
|
|
185
266
|
output: this['input'] extends [Question] ? true : false;
|
|
186
267
|
}
|
|
187
|
-
type
|
|
268
|
+
type Optional = Static.Union<[Static.Tuple<[Static.Const<Question>]>, Static.Tuple<[]>], OptionalMapping>;
|
|
188
269
|
interface PropertyMapping extends Static.IMapping {
|
|
189
|
-
output: this['input'] extends [infer
|
|
270
|
+
output: this['input'] extends [infer IsReadonly extends boolean, infer Key extends string, infer IsOptional extends boolean, string, infer Type extends Types.TSchema] ? {
|
|
190
271
|
[_ in Key]: ([
|
|
191
|
-
|
|
192
|
-
|
|
272
|
+
IsReadonly,
|
|
273
|
+
IsOptional
|
|
193
274
|
] extends [true, true] ? Types.TReadonlyOptional<Type> : [
|
|
194
|
-
|
|
195
|
-
|
|
275
|
+
IsReadonly,
|
|
276
|
+
IsOptional
|
|
196
277
|
] extends [true, false] ? Types.TReadonly<Type> : [
|
|
197
|
-
|
|
198
|
-
|
|
278
|
+
IsReadonly,
|
|
279
|
+
IsOptional
|
|
199
280
|
] extends [false, true] ? Types.TOptional<Type> : Type);
|
|
200
281
|
} : never;
|
|
201
282
|
}
|
|
202
|
-
type Property = Static.Tuple<[
|
|
203
|
-
type PropertiesEvaluate<T> = {
|
|
204
|
-
[K in keyof T]: T[K];
|
|
205
|
-
} & {};
|
|
283
|
+
type Property = Static.Tuple<[Readonly, PropertyKey, Optional, Static.Const<Colon>, Type], PropertyMapping>;
|
|
206
284
|
type PropertyDelimiter = Static.Union<[
|
|
207
285
|
Static.Tuple<[Static.Const<Comma>, Static.Const<Newline>]>,
|
|
208
286
|
Static.Tuple<[Static.Const<SemiColon>, Static.Const<Newline>]>,
|
|
@@ -210,7 +288,7 @@ type PropertyDelimiter = Static.Union<[
|
|
|
210
288
|
Static.Tuple<[Static.Const<SemiColon>]>,
|
|
211
289
|
Static.Tuple<[Static.Const<Newline>]>
|
|
212
290
|
]>;
|
|
213
|
-
type PropertiesReduce<PropertiesArray extends Types.TProperties[], Result extends Types.TProperties = {}> = (PropertiesArray extends [infer Left extends Types.TProperties, ...infer Right extends Types.TProperties[]] ? PropertiesReduce<Right,
|
|
291
|
+
type PropertiesReduce<PropertiesArray extends Types.TProperties[], Result extends Types.TProperties = {}> = (PropertiesArray extends [infer Left extends Types.TProperties, ...infer Right extends Types.TProperties[]] ? PropertiesReduce<Right, Types.Evaluate<Result & Left>> : Result);
|
|
214
292
|
interface PropertiesMapping extends Static.IMapping {
|
|
215
293
|
output: this['input'] extends Types.TProperties[] ? PropertiesReduce<this['input']> : never;
|
|
216
294
|
}
|
|
@@ -263,7 +341,7 @@ type Constructor = Static.Tuple<[
|
|
|
263
341
|
Type
|
|
264
342
|
], ConstructorMapping>;
|
|
265
343
|
interface MappedMapping extends Static.IMapping {
|
|
266
|
-
output: this['input'] extends [LBrace, LBracket, infer
|
|
344
|
+
output: this['input'] extends [LBrace, LBracket, infer _Key extends string, 'in', infer _Right extends Types.TSchema, RBracket, Colon, infer Type extends Types.TSchema, RBrace] ? Types.TLiteral<'Mapped types not supported'> : this['input'];
|
|
267
345
|
}
|
|
268
346
|
type Mapped = Static.Tuple<[
|
|
269
347
|
Static.Const<LBrace>,
|
|
@@ -378,7 +456,7 @@ type Partial = Static.Tuple<[
|
|
|
378
456
|
Static.Const<RAngle>
|
|
379
457
|
], PartialMapping>;
|
|
380
458
|
interface RequiredMapping extends Static.IMapping {
|
|
381
|
-
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;
|
|
382
460
|
}
|
|
383
461
|
type Required = Static.Tuple<[
|
|
384
462
|
Static.Const<'Required'>,
|
|
@@ -387,7 +465,7 @@ type Required = Static.Tuple<[
|
|
|
387
465
|
Static.Const<RAngle>
|
|
388
466
|
], RequiredMapping>;
|
|
389
467
|
interface PickMapping extends Static.IMapping {
|
|
390
|
-
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;
|
|
391
469
|
}
|
|
392
470
|
type Pick = Static.Tuple<[
|
|
393
471
|
Static.Const<'Pick'>,
|
|
@@ -398,7 +476,7 @@ type Pick = Static.Tuple<[
|
|
|
398
476
|
Static.Const<RAngle>
|
|
399
477
|
], PickMapping>;
|
|
400
478
|
interface OmitMapping extends Static.IMapping {
|
|
401
|
-
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;
|
|
402
480
|
}
|
|
403
481
|
type Omit = Static.Tuple<[
|
|
404
482
|
Static.Const<'Omit'>,
|
|
@@ -468,4 +546,10 @@ type Uncapitalize = Static.Tuple<[
|
|
|
468
546
|
], UncapitalizeMapping>;
|
|
469
547
|
type Date = Static.Const<'Date', Static.As<Types.TDate>>;
|
|
470
548
|
type Uint8Array = Static.Const<'Uint8Array', Static.As<Types.TUint8Array>>;
|
|
549
|
+
export type Main = Static.Union<[
|
|
550
|
+
ModuleDeclaration,
|
|
551
|
+
TypeAliasDeclaration,
|
|
552
|
+
InterfaceDeclaration,
|
|
553
|
+
Type
|
|
554
|
+
]>;
|
|
471
555
|
export {};
|
|
@@ -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';
|
|
1
2
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
3
|
+
import { type TComputed } from '../computed/index';
|
|
2
4
|
import { type TIntersect } from '../intersect/index';
|
|
3
5
|
import { type TUnion } from '../union/index';
|
|
4
6
|
import { type TPromise } from '../promise/index';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
import { type TRef } from '../ref/index';
|
|
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 {};
|
|
@@ -2,40 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Awaited = Awaited;
|
|
5
|
-
const index_1 = require("../intersect/index");
|
|
6
|
-
const index_2 = require("../union/index");
|
|
7
5
|
const type_1 = require("../create/type");
|
|
6
|
+
const index_1 = require("../computed/index");
|
|
7
|
+
const index_2 = require("../intersect/index");
|
|
8
|
+
const index_3 = require("../union/index");
|
|
9
|
+
const index_4 = require("../ref/index");
|
|
8
10
|
// ------------------------------------------------------------------
|
|
9
11
|
// TypeGuard
|
|
10
12
|
// ------------------------------------------------------------------
|
|
11
13
|
const kind_1 = require("../guard/kind");
|
|
12
14
|
// prettier-ignore
|
|
13
|
-
function
|
|
14
|
-
return
|
|
15
|
+
function FromComputed(target, parameters) {
|
|
16
|
+
return (0, index_1.Computed)('Awaited', [(0, index_1.Computed)(target, parameters)]);
|
|
15
17
|
}
|
|
16
18
|
// prettier-ignore
|
|
17
|
-
function
|
|
18
|
-
return (0, index_1.
|
|
19
|
+
function FromRef($ref) {
|
|
20
|
+
return (0, index_1.Computed)('Awaited', [(0, index_4.Ref)($ref)]);
|
|
19
21
|
}
|
|
20
22
|
// prettier-ignore
|
|
21
|
-
function
|
|
22
|
-
return (0, index_2.
|
|
23
|
+
function FromIntersect(types) {
|
|
24
|
+
return (0, index_2.Intersect)(FromRest(types));
|
|
23
25
|
}
|
|
24
26
|
// prettier-ignore
|
|
25
|
-
function
|
|
26
|
-
return
|
|
27
|
+
function FromUnion(types) {
|
|
28
|
+
return (0, index_3.Union)(FromRest(types));
|
|
27
29
|
}
|
|
28
|
-
// ----------------------------------------------------------------
|
|
29
|
-
// AwaitedResolve
|
|
30
|
-
// ----------------------------------------------------------------
|
|
31
30
|
// prettier-ignore
|
|
32
|
-
function
|
|
33
|
-
return (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
function FromPromise(type) {
|
|
32
|
+
return Awaited(type);
|
|
33
|
+
}
|
|
34
|
+
// prettier-ignore
|
|
35
|
+
function FromRest(types) {
|
|
36
|
+
return types.map(type => Awaited(type));
|
|
37
37
|
}
|
|
38
38
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
39
|
-
function Awaited(
|
|
40
|
-
return (0, type_1.CreateType)(
|
|
39
|
+
function Awaited(type, options) {
|
|
40
|
+
return (0, type_1.CreateType)((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) : (0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf) : (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) : (0, kind_1.IsPromise)(type) ? FromPromise(type.item) : (0, kind_1.IsRef)(type) ? FromRef(type.$ref) : type, options);
|
|
41
41
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
+
import { Kind } from '../symbols/symbols';
|
|
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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Computed = Computed;
|
|
5
|
+
const index_1 = require("../create/index");
|
|
6
|
+
const symbols_1 = require("../symbols/symbols");
|
|
7
|
+
/** `[Internal]` Creates a deferred computed type. This type is used exclusively in modules to defer resolution of computable types that contain interior references */
|
|
8
|
+
function Computed(target, parameters, options) {
|
|
9
|
+
return (0, index_1.CreateType)({ [symbols_1.Kind]: 'Computed', target, parameters }, options);
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './computed';
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./computed"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index';
|
|
2
2
|
import { TransformOptions } from '../transform/index';
|
|
3
|
-
import { TTemplateLiteral } from '../template-literal/index';
|
|
4
|
-
import { TArray } from '../array/index';
|
|
5
|
-
import { TBoolean } from '../boolean/index';
|
|
3
|
+
import type { TTemplateLiteral } from '../template-literal/index';
|
|
4
|
+
import type { TArray } from '../array/index';
|
|
5
|
+
import type { TBoolean } from '../boolean/index';
|
|
6
|
+
import type { TComputed } from '../computed/index';
|
|
6
7
|
import type { TRecord } from '../record/index';
|
|
7
8
|
import type { TString } from '../string/index';
|
|
8
9
|
import type { TUnion } from '../union/index';
|
|
@@ -11,10 +12,11 @@ import type { TAsyncIterator } from '../async-iterator/index';
|
|
|
11
12
|
import type { TBigInt } from '../bigint/index';
|
|
12
13
|
import type { TConstructor } from '../constructor/index';
|
|
13
14
|
import type { TFunction } from '../function/index';
|
|
15
|
+
import type { TImport } from '../module/index';
|
|
14
16
|
import type { TInteger } from '../integer/index';
|
|
15
17
|
import type { TIntersect } from '../intersect/index';
|
|
16
18
|
import type { TIterator } from '../iterator/index';
|
|
17
|
-
import type { TLiteral } from '../literal/index';
|
|
19
|
+
import type { TLiteral, TLiteralValue } from '../literal/index';
|
|
18
20
|
import type { TMappedKey, TMappedResult } from '../mapped/index';
|
|
19
21
|
import type { TNever } from '../never/index';
|
|
20
22
|
import type { TNot } from '../not/index';
|
|
@@ -50,6 +52,8 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
|
|
|
50
52
|
export declare function IsBigInt(value: unknown): value is TBigInt;
|
|
51
53
|
/** `[Kind-Only]` Returns true if the given value is TBoolean */
|
|
52
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;
|
|
53
57
|
/** `[Kind-Only]` Returns true if the given value is TConstructor */
|
|
54
58
|
export declare function IsConstructor(value: unknown): value is TConstructor;
|
|
55
59
|
/** `[Kind-Only]` Returns true if the given value is TDate */
|
|
@@ -57,6 +61,8 @@ export declare function IsDate(value: unknown): value is TDate;
|
|
|
57
61
|
/** `[Kind-Only]` Returns true if the given value is TFunction */
|
|
58
62
|
export declare function IsFunction(value: unknown): value is TFunction;
|
|
59
63
|
/** `[Kind-Only]` Returns true if the given value is TInteger */
|
|
64
|
+
export declare function IsImport(value: unknown): value is TImport;
|
|
65
|
+
/** `[Kind-Only]` Returns true if the given value is TInteger */
|
|
60
66
|
export declare function IsInteger(value: unknown): value is TInteger;
|
|
61
67
|
/** `[Kind-Only]` Returns true if the given schema is TProperties */
|
|
62
68
|
export declare function IsProperties(value: unknown): value is TProperties;
|
|
@@ -74,6 +80,8 @@ export declare function IsLiteralString(value: unknown): value is TLiteral<strin
|
|
|
74
80
|
export declare function IsLiteralNumber(value: unknown): value is TLiteral<number>;
|
|
75
81
|
/** `[Kind-Only]` Returns true if the given value is TLiteral<boolean> */
|
|
76
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;
|
|
77
85
|
/** `[Kind-Only]` Returns true if the given value is TLiteral */
|
|
78
86
|
export declare function IsLiteral(value: unknown): value is TLiteral;
|
|
79
87
|
/** `[Kind-Only]` Returns true if the given value is a TMappedKey */
|
|
@@ -8,9 +8,11 @@ exports.IsArray = IsArray;
|
|
|
8
8
|
exports.IsAsyncIterator = IsAsyncIterator;
|
|
9
9
|
exports.IsBigInt = IsBigInt;
|
|
10
10
|
exports.IsBoolean = IsBoolean;
|
|
11
|
+
exports.IsComputed = IsComputed;
|
|
11
12
|
exports.IsConstructor = IsConstructor;
|
|
12
13
|
exports.IsDate = IsDate;
|
|
13
14
|
exports.IsFunction = IsFunction;
|
|
15
|
+
exports.IsImport = IsImport;
|
|
14
16
|
exports.IsInteger = IsInteger;
|
|
15
17
|
exports.IsProperties = IsProperties;
|
|
16
18
|
exports.IsIntersect = IsIntersect;
|
|
@@ -19,6 +21,7 @@ exports.IsKindOf = IsKindOf;
|
|
|
19
21
|
exports.IsLiteralString = IsLiteralString;
|
|
20
22
|
exports.IsLiteralNumber = IsLiteralNumber;
|
|
21
23
|
exports.IsLiteralBoolean = IsLiteralBoolean;
|
|
24
|
+
exports.IsLiteralValue = IsLiteralValue;
|
|
22
25
|
exports.IsLiteral = IsLiteral;
|
|
23
26
|
exports.IsMappedKey = IsMappedKey;
|
|
24
27
|
exports.IsMappedResult = IsMappedResult;
|
|
@@ -76,6 +79,10 @@ function IsBigInt(value) {
|
|
|
76
79
|
function IsBoolean(value) {
|
|
77
80
|
return IsKindOf(value, 'Boolean');
|
|
78
81
|
}
|
|
82
|
+
/** `[Kind-Only]` Returns true if the given value is TComputed */
|
|
83
|
+
function IsComputed(value) {
|
|
84
|
+
return IsKindOf(value, 'Computed');
|
|
85
|
+
}
|
|
79
86
|
/** `[Kind-Only]` Returns true if the given value is TConstructor */
|
|
80
87
|
function IsConstructor(value) {
|
|
81
88
|
return IsKindOf(value, 'Constructor');
|
|
@@ -89,6 +96,10 @@ function IsFunction(value) {
|
|
|
89
96
|
return IsKindOf(value, 'Function');
|
|
90
97
|
}
|
|
91
98
|
/** `[Kind-Only]` Returns true if the given value is TInteger */
|
|
99
|
+
function IsImport(value) {
|
|
100
|
+
return IsKindOf(value, 'Import');
|
|
101
|
+
}
|
|
102
|
+
/** `[Kind-Only]` Returns true if the given value is TInteger */
|
|
92
103
|
function IsInteger(value) {
|
|
93
104
|
return IsKindOf(value, 'Integer');
|
|
94
105
|
}
|
|
@@ -120,6 +131,10 @@ function IsLiteralNumber(value) {
|
|
|
120
131
|
function IsLiteralBoolean(value) {
|
|
121
132
|
return IsLiteral(value) && ValueGuard.IsBoolean(value.const);
|
|
122
133
|
}
|
|
134
|
+
/** `[Kind-Only]` Returns true if the given value is TLiteralValue */
|
|
135
|
+
function IsLiteralValue(value) {
|
|
136
|
+
return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
|
|
137
|
+
}
|
|
123
138
|
/** `[Kind-Only]` Returns true if the given value is TLiteral */
|
|
124
139
|
function IsLiteral(value) {
|
|
125
140
|
return IsKindOf(value, 'Literal');
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Kind, Hint, TransformKind } from '../symbols/index';
|
|
2
2
|
import { TypeBoxError } from '../error/index';
|
|
3
3
|
import { TransformOptions } from '../transform/index';
|
|
4
|
-
import { TTemplateLiteral } from '../template-literal/index';
|
|
5
|
-
import { TArray } from '../array/index';
|
|
6
|
-
import { TBoolean } from '../boolean/index';
|
|
4
|
+
import type { TTemplateLiteral } from '../template-literal/index';
|
|
5
|
+
import type { TArray } from '../array/index';
|
|
6
|
+
import type { TBoolean } from '../boolean/index';
|
|
7
|
+
import type { TComputed } from '../computed/index';
|
|
7
8
|
import type { TRecord } from '../record/index';
|
|
8
9
|
import type { TString } from '../string/index';
|
|
9
10
|
import type { TUnion } from '../union/index';
|
|
@@ -12,6 +13,7 @@ import type { TAsyncIterator } from '../async-iterator/index';
|
|
|
12
13
|
import type { TBigInt } from '../bigint/index';
|
|
13
14
|
import type { TConstructor } from '../constructor/index';
|
|
14
15
|
import type { TFunction } from '../function/index';
|
|
16
|
+
import type { TImport } from '../module/index';
|
|
15
17
|
import type { TInteger } from '../integer/index';
|
|
16
18
|
import type { TIntersect } from '../intersect/index';
|
|
17
19
|
import type { TIterator } from '../iterator/index';
|
|
@@ -53,12 +55,16 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
|
|
|
53
55
|
export declare function IsBigInt(value: unknown): value is TBigInt;
|
|
54
56
|
/** Returns true if the given value is TBoolean */
|
|
55
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;
|
|
56
60
|
/** Returns true if the given value is TConstructor */
|
|
57
61
|
export declare function IsConstructor(value: unknown): value is TConstructor;
|
|
58
62
|
/** Returns true if the given value is TDate */
|
|
59
63
|
export declare function IsDate(value: unknown): value is TDate;
|
|
60
64
|
/** Returns true if the given value is TFunction */
|
|
61
65
|
export declare function IsFunction(value: unknown): value is TFunction;
|
|
66
|
+
/** Returns true if the given value is TImport */
|
|
67
|
+
export declare function IsImport(value: unknown): value is TImport;
|
|
62
68
|
/** Returns true if the given value is TInteger */
|
|
63
69
|
export declare function IsInteger(value: unknown): value is TInteger;
|
|
64
70
|
/** Returns true if the given schema is TProperties */
|
|
@@ -9,9 +9,11 @@ exports.IsArray = IsArray;
|
|
|
9
9
|
exports.IsAsyncIterator = IsAsyncIterator;
|
|
10
10
|
exports.IsBigInt = IsBigInt;
|
|
11
11
|
exports.IsBoolean = IsBoolean;
|
|
12
|
+
exports.IsComputed = IsComputed;
|
|
12
13
|
exports.IsConstructor = IsConstructor;
|
|
13
14
|
exports.IsDate = IsDate;
|
|
14
15
|
exports.IsFunction = IsFunction;
|
|
16
|
+
exports.IsImport = IsImport;
|
|
15
17
|
exports.IsInteger = IsInteger;
|
|
16
18
|
exports.IsProperties = IsProperties;
|
|
17
19
|
exports.IsIntersect = IsIntersect;
|
|
@@ -61,6 +63,7 @@ const KnownTypes = [
|
|
|
61
63
|
'AsyncIterator',
|
|
62
64
|
'BigInt',
|
|
63
65
|
'Boolean',
|
|
66
|
+
'Computed',
|
|
64
67
|
'Constructor',
|
|
65
68
|
'Date',
|
|
66
69
|
'Enum',
|
|
@@ -194,6 +197,10 @@ function IsBoolean(value) {
|
|
|
194
197
|
value.type === 'boolean' &&
|
|
195
198
|
IsOptionalString(value.$id));
|
|
196
199
|
}
|
|
200
|
+
/** Returns true if the given value is TComputed */
|
|
201
|
+
function IsComputed(value) {
|
|
202
|
+
return IsKindOf(value, 'Computed') && IsString(value.target) && ValueGuard.IsArray(value.parameters) && value.parameters.every((schema) => IsSchema(schema));
|
|
203
|
+
}
|
|
197
204
|
/** Returns true if the given value is TConstructor */
|
|
198
205
|
function IsConstructor(value) {
|
|
199
206
|
// prettier-ignore
|
|
@@ -225,6 +232,18 @@ function IsFunction(value) {
|
|
|
225
232
|
value.parameters.every(schema => IsSchema(schema)) &&
|
|
226
233
|
IsSchema(value.returns));
|
|
227
234
|
}
|
|
235
|
+
/** Returns true if the given value is TImport */
|
|
236
|
+
function IsImport(value) {
|
|
237
|
+
// prettier-ignore
|
|
238
|
+
return (IsKindOf(value, 'Import') &&
|
|
239
|
+
ValueGuard.HasPropertyKey(value, '$defs') &&
|
|
240
|
+
ValueGuard.IsObject(value.$defs) &&
|
|
241
|
+
IsProperties(value.$defs) &&
|
|
242
|
+
ValueGuard.HasPropertyKey(value, '$ref') &&
|
|
243
|
+
ValueGuard.IsString(value.$ref) &&
|
|
244
|
+
value.$ref in value.$defs // required
|
|
245
|
+
);
|
|
246
|
+
}
|
|
228
247
|
/** Returns true if the given value is TInteger */
|
|
229
248
|
function IsInteger(value) {
|
|
230
249
|
return (IsKindOf(value, 'Integer') &&
|
|
@@ -10,7 +10,6 @@ export * from './const/index';
|
|
|
10
10
|
export * from './constructor/index';
|
|
11
11
|
export * from './constructor-parameters/index';
|
|
12
12
|
export * from './date/index';
|
|
13
|
-
export * from './deref/index';
|
|
14
13
|
export * from './discard/index';
|
|
15
14
|
export * from './enum/index';
|
|
16
15
|
export * from './error/index';
|
|
@@ -29,6 +28,7 @@ export * from './iterator/index';
|
|
|
29
28
|
export * from './keyof/index';
|
|
30
29
|
export * from './literal/index';
|
|
31
30
|
export * from './mapped/index';
|
|
31
|
+
export * from './module/index';
|
|
32
32
|
export * from './never/index';
|
|
33
33
|
export * from './not/index';
|
|
34
34
|
export * from './null/index';
|
|
@@ -54,7 +54,6 @@ export * from './return-type/index';
|
|
|
54
54
|
export * from './schema/index';
|
|
55
55
|
export * from './sets/index';
|
|
56
56
|
export * from './static/index';
|
|
57
|
-
export * from './strict/index';
|
|
58
57
|
export * from './string/index';
|
|
59
58
|
export * from './symbol/index';
|
|
60
59
|
export * from './symbols/index';
|
package/build/cjs/type/index.js
CHANGED
|
@@ -27,7 +27,6 @@ __exportStar(require("./const/index"), exports);
|
|
|
27
27
|
__exportStar(require("./constructor/index"), exports);
|
|
28
28
|
__exportStar(require("./constructor-parameters/index"), exports);
|
|
29
29
|
__exportStar(require("./date/index"), exports);
|
|
30
|
-
__exportStar(require("./deref/index"), exports);
|
|
31
30
|
__exportStar(require("./discard/index"), exports);
|
|
32
31
|
__exportStar(require("./enum/index"), exports);
|
|
33
32
|
__exportStar(require("./error/index"), exports);
|
|
@@ -46,6 +45,7 @@ __exportStar(require("./iterator/index"), exports);
|
|
|
46
45
|
__exportStar(require("./keyof/index"), exports);
|
|
47
46
|
__exportStar(require("./literal/index"), exports);
|
|
48
47
|
__exportStar(require("./mapped/index"), exports);
|
|
48
|
+
__exportStar(require("./module/index"), exports);
|
|
49
49
|
__exportStar(require("./never/index"), exports);
|
|
50
50
|
__exportStar(require("./not/index"), exports);
|
|
51
51
|
__exportStar(require("./null/index"), exports);
|
|
@@ -71,7 +71,6 @@ __exportStar(require("./return-type/index"), exports);
|
|
|
71
71
|
__exportStar(require("./schema/index"), exports);
|
|
72
72
|
__exportStar(require("./sets/index"), exports);
|
|
73
73
|
__exportStar(require("./static/index"), exports);
|
|
74
|
-
__exportStar(require("./strict/index"), exports);
|
|
75
74
|
__exportStar(require("./string/index"), exports);
|
|
76
75
|
__exportStar(require("./symbol/index"), exports);
|
|
77
76
|
__exportStar(require("./symbols/index"), exports);
|
|
@@ -3,11 +3,11 @@ import type { Ensure, Evaluate } from '../helpers/index';
|
|
|
3
3
|
import type { TProperties } from '../object/index';
|
|
4
4
|
import { type TIndex } from './indexed';
|
|
5
5
|
import { type TMappedResult, type TMappedKey } from '../mapped/index';
|
|
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 {};
|
|
@@ -6,21 +6,21 @@ const indexed_1 = require("./indexed");
|
|
|
6
6
|
const index_1 = require("../mapped/index");
|
|
7
7
|
const value_1 = require("../clone/value");
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function MappedIndexPropertyKey(
|
|
10
|
-
return { [
|
|
9
|
+
function MappedIndexPropertyKey(type, key, options) {
|
|
10
|
+
return { [key]: (0, indexed_1.Index)(type, [key], (0, value_1.Clone)(options)) };
|
|
11
11
|
}
|
|
12
12
|
// prettier-ignore
|
|
13
|
-
function MappedIndexPropertyKeys(
|
|
14
|
-
return
|
|
15
|
-
return { ...
|
|
13
|
+
function MappedIndexPropertyKeys(type, propertyKeys, options) {
|
|
14
|
+
return propertyKeys.reduce((result, left) => {
|
|
15
|
+
return { ...result, ...MappedIndexPropertyKey(type, left, options) };
|
|
16
16
|
}, {});
|
|
17
17
|
}
|
|
18
18
|
// prettier-ignore
|
|
19
|
-
function MappedIndexProperties(
|
|
20
|
-
return MappedIndexPropertyKeys(
|
|
19
|
+
function MappedIndexProperties(type, mappedKey, options) {
|
|
20
|
+
return MappedIndexPropertyKeys(type, mappedKey.keys, options);
|
|
21
21
|
}
|
|
22
22
|
// prettier-ignore
|
|
23
|
-
function IndexFromMappedKey(
|
|
24
|
-
const
|
|
25
|
-
return (0, index_1.MappedResult)(
|
|
23
|
+
function IndexFromMappedKey(type, mappedKey, options) {
|
|
24
|
+
const properties = MappedIndexProperties(type, mappedKey, options);
|
|
25
|
+
return (0, index_1.MappedResult)(properties);
|
|
26
26
|
}
|