@sinclair/typebox 0.34.14 → 0.34.16
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/index.d.ts +1 -1
- package/build/cjs/syntax/index.js +1 -1
- package/build/cjs/syntax/runtime.d.ts +38 -54
- package/build/cjs/syntax/runtime.js +60 -202
- package/build/cjs/syntax/static.d.ts +62 -148
- package/build/cjs/syntax/syntax.d.ts +33 -0
- package/build/cjs/syntax/syntax.js +37 -0
- package/build/cjs/type/constructor-parameters/constructor-parameters.d.ts +3 -3
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +3 -1
- package/build/cjs/type/instance-type/instance-type.d.ts +5 -4
- package/build/cjs/type/instance-type/instance-type.js +3 -1
- package/build/cjs/type/parameters/parameters.d.ts +3 -3
- package/build/cjs/type/parameters/parameters.js +3 -1
- package/build/cjs/type/return-type/return-type.d.ts +5 -4
- package/build/cjs/type/return-type/return-type.js +3 -1
- package/build/cjs/type/type/javascript.d.ts +4 -4
- package/build/cjs/value/convert/convert.js +1 -1
- package/build/esm/syntax/index.d.mts +1 -1
- package/build/esm/syntax/index.mjs +1 -1
- package/build/esm/syntax/runtime.d.mts +38 -54
- package/build/esm/syntax/runtime.mjs +60 -202
- package/build/esm/syntax/static.d.mts +62 -148
- package/build/esm/syntax/syntax.d.mts +33 -0
- package/build/esm/syntax/syntax.mjs +30 -0
- package/build/esm/type/constructor-parameters/constructor-parameters.d.mts +3 -3
- package/build/esm/type/constructor-parameters/constructor-parameters.mjs +3 -1
- package/build/esm/type/instance-type/instance-type.d.mts +5 -4
- package/build/esm/type/instance-type/instance-type.mjs +3 -1
- package/build/esm/type/parameters/parameters.d.mts +3 -3
- package/build/esm/type/parameters/parameters.mjs +3 -1
- package/build/esm/type/return-type/return-type.d.mts +5 -4
- package/build/esm/type/return-type/return-type.mjs +3 -1
- package/build/esm/type/type/javascript.d.mts +4 -4
- package/build/esm/value/convert/convert.mjs +1 -1
- package/package.json +11 -1
- package/parser/package.json +4 -0
- package/readme.md +86 -161
- package/build/cjs/syntax/parse.d.ts +0 -15
- package/build/cjs/syntax/parse.js +0 -19
- package/build/esm/syntax/parse.d.mts +0 -15
- package/build/esm/syntax/parse.mjs +0 -14
- /package/build/cjs/{syntax/parsebox → parser}/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/module.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/module.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/token.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/token.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/types.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/runtime/types.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/index.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/index.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/parse.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/parse.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/token.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/token.js +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/types.d.ts +0 -0
- /package/build/cjs/{syntax/parsebox → parser}/static/types.js +0 -0
- /package/build/esm/{syntax/parsebox → parser}/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/guard.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/guard.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/module.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/module.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/parse.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/parse.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/token.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/token.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/types.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/runtime/types.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/index.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/index.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/parse.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/parse.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/token.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/token.mjs +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/types.d.mts +0 -0
- /package/build/esm/{syntax/parsebox → parser}/static/types.mjs +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Static } from '
|
|
2
|
-
import * as
|
|
1
|
+
import { Static } from '../parser/index';
|
|
2
|
+
import * as t from '../type/index';
|
|
3
3
|
type Newline = '\n';
|
|
4
4
|
type LBracket = '[';
|
|
5
5
|
type RBracket = ']';
|
|
@@ -16,7 +16,6 @@ type SemiColon = ';';
|
|
|
16
16
|
type SingleQuote = "'";
|
|
17
17
|
type DoubleQuote = '"';
|
|
18
18
|
type Tilde = '`';
|
|
19
|
-
type Equals = '=';
|
|
20
19
|
interface DelimitTailMapping<_ = unknown> extends Static.IMapping {
|
|
21
20
|
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 [_] ? [] : [
|
|
22
21
|
]);
|
|
@@ -42,98 +41,19 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
|
|
|
42
41
|
Static.Tuple<[Parser, DelimitTail<Parser, Delimiter>]>,
|
|
43
42
|
Static.Tuple<[]>
|
|
44
43
|
], DelimitMapping>);
|
|
45
|
-
type Deref<Context extends
|
|
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
|
+
type Deref<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
|
|
125
45
|
interface ReferenceMapping extends Static.IMapping {
|
|
126
|
-
output: this['context'] extends
|
|
46
|
+
output: this['context'] extends t.TProperties ? this['input'] extends string ? Deref<this['context'], this['input']> : never : never;
|
|
127
47
|
}
|
|
128
48
|
type Reference = Static.Ident<ReferenceMapping>;
|
|
129
49
|
interface LiteralBooleanMapping extends Static.IMapping {
|
|
130
|
-
output: this['input'] extends `${infer S extends boolean}` ?
|
|
50
|
+
output: this['input'] extends `${infer S extends boolean}` ? t.TLiteral<S> : never;
|
|
131
51
|
}
|
|
132
52
|
interface LiteralNumberMapping extends Static.IMapping {
|
|
133
|
-
output: this['input'] extends `${infer S extends number}` ?
|
|
53
|
+
output: this['input'] extends `${infer S extends number}` ? t.TLiteral<S> : never;
|
|
134
54
|
}
|
|
135
55
|
interface LiteralStringMapping extends Static.IMapping {
|
|
136
|
-
output: this['input'] extends `${infer S extends string}` ?
|
|
56
|
+
output: this['input'] extends `${infer S extends string}` ? t.TLiteral<S> : never;
|
|
137
57
|
}
|
|
138
58
|
type Literal = Static.Union<[
|
|
139
59
|
Static.Union<[Static.Const<'true'>, Static.Const<'false'>], LiteralBooleanMapping>,
|
|
@@ -141,18 +61,18 @@ type Literal = Static.Union<[
|
|
|
141
61
|
Static.String<[DoubleQuote, SingleQuote, Tilde], LiteralStringMapping>
|
|
142
62
|
]>;
|
|
143
63
|
type Keyword = Static.Union<[
|
|
144
|
-
Static.Const<'any', Static.As<
|
|
145
|
-
Static.Const<'bigint', Static.As<
|
|
146
|
-
Static.Const<'boolean', Static.As<
|
|
147
|
-
Static.Const<'integer', Static.As<
|
|
148
|
-
Static.Const<'never', Static.As<
|
|
149
|
-
Static.Const<'null', Static.As<
|
|
150
|
-
Static.Const<'number', Static.As<
|
|
151
|
-
Static.Const<'string', Static.As<
|
|
152
|
-
Static.Const<'symbol', Static.As<
|
|
153
|
-
Static.Const<'undefined', Static.As<
|
|
154
|
-
Static.Const<'unknown', Static.As<
|
|
155
|
-
Static.Const<'void', Static.As<
|
|
64
|
+
Static.Const<'any', Static.As<t.TAny>>,
|
|
65
|
+
Static.Const<'bigint', Static.As<t.TBigInt>>,
|
|
66
|
+
Static.Const<'boolean', Static.As<t.TBoolean>>,
|
|
67
|
+
Static.Const<'integer', Static.As<t.TInteger>>,
|
|
68
|
+
Static.Const<'never', Static.As<t.TNever>>,
|
|
69
|
+
Static.Const<'null', Static.As<t.TNull>>,
|
|
70
|
+
Static.Const<'number', Static.As<t.TNumber>>,
|
|
71
|
+
Static.Const<'string', Static.As<t.TString>>,
|
|
72
|
+
Static.Const<'symbol', Static.As<t.TSymbol>>,
|
|
73
|
+
Static.Const<'undefined', Static.As<t.TUndefined>>,
|
|
74
|
+
Static.Const<'unknown', Static.As<t.TUnknown>>,
|
|
75
|
+
Static.Const<'void', Static.As<t.TVoid>>
|
|
156
76
|
]>;
|
|
157
77
|
interface KeyOfMapping extends Static.IMapping {
|
|
158
78
|
output: this['input'] extends [] ? false : true;
|
|
@@ -162,7 +82,7 @@ type KeyOf = Static.Union<[
|
|
|
162
82
|
Static.Tuple<[]>
|
|
163
83
|
], KeyOfMapping>;
|
|
164
84
|
interface IndexArrayMapping extends Static.IMapping {
|
|
165
|
-
output: (this['input'] extends [LBracket, infer Type extends
|
|
85
|
+
output: (this['input'] extends [LBracket, infer Type extends t.TSchema, RBracket, infer Rest extends unknown[]] ? [[Type], ...Rest] : this['input'] extends [LBracket, RBracket, infer Rest extends unknown[]] ? [[], ...Rest] : [
|
|
166
86
|
]);
|
|
167
87
|
}
|
|
168
88
|
type IndexArray = Static.Union<[
|
|
@@ -171,14 +91,14 @@ type IndexArray = Static.Union<[
|
|
|
171
91
|
Static.Tuple<[]>
|
|
172
92
|
], IndexArrayMapping>;
|
|
173
93
|
interface ExtendsMapping extends Static.IMapping {
|
|
174
|
-
output: this['input'] extends ['extends', infer Type extends
|
|
94
|
+
output: this['input'] extends ['extends', infer Type extends t.TSchema, Question, infer True extends t.TSchema, Colon, infer False extends t.TSchema] ? [Type, True, False] : [];
|
|
175
95
|
}
|
|
176
96
|
type Extends = Static.Union<[
|
|
177
97
|
Static.Tuple<[Static.Const<'extends'>, Type, Static.Const<Question>, Type, Static.Const<Colon>, Type]>,
|
|
178
98
|
Static.Tuple<[]>
|
|
179
99
|
], ExtendsMapping>;
|
|
180
100
|
interface BaseMapping extends Static.IMapping {
|
|
181
|
-
output: (this['input'] extends [LParen, infer Type extends
|
|
101
|
+
output: (this['input'] extends [LParen, infer Type extends t.TSchema, RParen] ? Type : this['input'] extends [infer Type extends t.TSchema] ? Type : never);
|
|
182
102
|
}
|
|
183
103
|
type Base = Static.Union<[
|
|
184
104
|
Static.Tuple<[
|
|
@@ -221,10 +141,10 @@ type Base = Static.Union<[
|
|
|
221
141
|
]>
|
|
222
142
|
]>
|
|
223
143
|
], BaseMapping>;
|
|
224
|
-
type FactorExtends<Type extends
|
|
225
|
-
type FactorIndexArray<Type extends
|
|
144
|
+
type FactorExtends<Type extends t.TSchema, Extends extends unknown[]> = (Extends extends [infer Right extends t.TSchema, infer True extends t.TSchema, infer False extends t.TSchema] ? t.TExtends<Type, Right, True, False> : Type);
|
|
145
|
+
type FactorIndexArray<Type extends t.TSchema, IndexArray extends unknown[]> = (IndexArray extends [...infer Left extends unknown[], infer Right extends t.TSchema[]] ? (Right extends [infer Indexer extends t.TSchema] ? t.TIndex<FactorIndexArray<Type, Left>, t.TIndexPropertyKeys<Indexer>> : Right extends [] ? t.TArray<FactorIndexArray<Type, Left>> : t.TNever) : Type);
|
|
226
146
|
interface FactorMapping extends Static.IMapping {
|
|
227
|
-
output: this['input'] extends [infer KeyOf extends boolean, infer Type extends
|
|
147
|
+
output: this['input'] extends [infer KeyOf extends boolean, infer Type extends t.TSchema, infer IndexArray extends unknown[], infer Extends extends unknown[]] ? KeyOf extends true ? FactorExtends<t.TKeyOf<FactorIndexArray<Type, IndexArray>>, Extends> : FactorExtends<FactorIndexArray<Type, IndexArray>, Extends> : never;
|
|
228
148
|
}
|
|
229
149
|
type Factor = Static.Tuple<[
|
|
230
150
|
KeyOf,
|
|
@@ -232,9 +152,9 @@ type Factor = Static.Tuple<[
|
|
|
232
152
|
IndexArray,
|
|
233
153
|
Extends
|
|
234
154
|
], FactorMapping>;
|
|
235
|
-
type ExprBinaryReduce<Left extends
|
|
155
|
+
type ExprBinaryReduce<Left extends t.TSchema, Rest extends unknown[]> = (Rest extends [infer Operator extends unknown, infer Right extends t.TSchema, infer Next extends unknown[]] ? (ExprBinaryReduce<Right, Next> extends infer Schema extends t.TSchema ? (Operator extends '&' ? (Schema extends t.TIntersect<infer Types extends t.TSchema[]> ? t.TIntersect<[Left, ...Types]> : t.TIntersect<[Left, Schema]>) : Operator extends '|' ? (Schema extends t.TUnion<infer Types extends t.TSchema[]> ? t.TUnion<[Left, ...Types]> : t.TUnion<[Left, Schema]>) : never) : never) : Left);
|
|
236
156
|
interface ExprBinaryMapping extends Static.IMapping {
|
|
237
|
-
output: (this['input'] extends [infer Left extends
|
|
157
|
+
output: (this['input'] extends [infer Left extends t.TSchema, infer Rest extends unknown[]] ? ExprBinaryReduce<Left, Rest> : []);
|
|
238
158
|
}
|
|
239
159
|
type ExprTermTail = Static.Union<[
|
|
240
160
|
Static.Tuple<[Static.Const<'&'>, Factor, ExprTermTail]>,
|
|
@@ -252,7 +172,7 @@ type Expr = Static.Tuple<[
|
|
|
252
172
|
ExprTerm,
|
|
253
173
|
ExprTail
|
|
254
174
|
], ExprBinaryMapping>;
|
|
255
|
-
type Type = Expr;
|
|
175
|
+
export type Type = Expr;
|
|
256
176
|
interface PropertyKeyStringMapping extends Static.IMapping {
|
|
257
177
|
output: this['input'];
|
|
258
178
|
}
|
|
@@ -267,17 +187,17 @@ interface OptionalMapping extends Static.IMapping {
|
|
|
267
187
|
}
|
|
268
188
|
type Optional = Static.Union<[Static.Tuple<[Static.Const<Question>]>, Static.Tuple<[]>], OptionalMapping>;
|
|
269
189
|
interface PropertyMapping extends Static.IMapping {
|
|
270
|
-
output: this['input'] extends [infer IsReadonly extends boolean, infer Key extends string, infer IsOptional extends boolean, string, infer Type extends
|
|
190
|
+
output: this['input'] extends [infer IsReadonly extends boolean, infer Key extends string, infer IsOptional extends boolean, string, infer Type extends t.TSchema] ? {
|
|
271
191
|
[_ in Key]: ([
|
|
272
192
|
IsReadonly,
|
|
273
193
|
IsOptional
|
|
274
|
-
] extends [true, true] ?
|
|
194
|
+
] extends [true, true] ? t.TReadonlyOptional<Type> : [
|
|
275
195
|
IsReadonly,
|
|
276
196
|
IsOptional
|
|
277
|
-
] extends [true, false] ?
|
|
197
|
+
] extends [true, false] ? t.TReadonly<Type> : [
|
|
278
198
|
IsReadonly,
|
|
279
199
|
IsOptional
|
|
280
|
-
] extends [false, true] ?
|
|
200
|
+
] extends [false, true] ? t.TOptional<Type> : Type);
|
|
281
201
|
} : never;
|
|
282
202
|
}
|
|
283
203
|
type Property = Static.Tuple<[Readonly, PropertyKey, Optional, Static.Const<Colon>, Type], PropertyMapping>;
|
|
@@ -288,13 +208,13 @@ type PropertyDelimiter = Static.Union<[
|
|
|
288
208
|
Static.Tuple<[Static.Const<SemiColon>]>,
|
|
289
209
|
Static.Tuple<[Static.Const<Newline>]>
|
|
290
210
|
]>;
|
|
291
|
-
type PropertiesReduce<PropertiesArray extends
|
|
211
|
+
type PropertiesReduce<PropertiesArray extends t.TProperties[], Result extends t.TProperties = {}> = (PropertiesArray extends [infer Left extends t.TProperties, ...infer Right extends t.TProperties[]] ? PropertiesReduce<Right, t.Evaluate<Result & Left>> : Result);
|
|
292
212
|
interface PropertiesMapping extends Static.IMapping {
|
|
293
|
-
output: this['input'] extends
|
|
213
|
+
output: this['input'] extends t.TProperties[] ? PropertiesReduce<this['input']> : never;
|
|
294
214
|
}
|
|
295
215
|
type Properties = Static.Union<[Delimit<Property, PropertyDelimiter>], PropertiesMapping>;
|
|
296
216
|
interface ObjectMapping extends Static.IMapping {
|
|
297
|
-
output: this['input'] extends [unknown, infer Properties extends
|
|
217
|
+
output: this['input'] extends [unknown, infer Properties extends t.TProperties, unknown] ? t.TObject<Properties> : never;
|
|
298
218
|
}
|
|
299
219
|
type Object = Static.Tuple<[
|
|
300
220
|
Static.Const<LBrace>,
|
|
@@ -303,7 +223,7 @@ type Object = Static.Tuple<[
|
|
|
303
223
|
], ObjectMapping>;
|
|
304
224
|
type Elements = Delimit<Type, Static.Const<Comma>>;
|
|
305
225
|
interface TupleMapping extends Static.IMapping {
|
|
306
|
-
output: this['input'] extends [unknown, infer Elements extends
|
|
226
|
+
output: this['input'] extends [unknown, infer Elements extends t.TSchema[], unknown] ? t.TTuple<Elements> : never;
|
|
307
227
|
}
|
|
308
228
|
type Tuple = Static.Tuple<[
|
|
309
229
|
Static.Const<LBracket>,
|
|
@@ -311,7 +231,7 @@ type Tuple = Static.Tuple<[
|
|
|
311
231
|
Static.Const<RBracket>
|
|
312
232
|
], TupleMapping>;
|
|
313
233
|
interface ParameterMapping extends Static.IMapping {
|
|
314
|
-
output: this['input'] extends [string, Colon, infer Type extends
|
|
234
|
+
output: this['input'] extends [string, Colon, infer Type extends t.TSchema] ? Type : never;
|
|
315
235
|
}
|
|
316
236
|
type Parameter = Static.Tuple<[
|
|
317
237
|
Static.Ident,
|
|
@@ -320,7 +240,7 @@ type Parameter = Static.Tuple<[
|
|
|
320
240
|
], ParameterMapping>;
|
|
321
241
|
type Parameters = Delimit<Parameter, Static.Const<Comma>>;
|
|
322
242
|
interface FunctionMapping extends Static.IMapping {
|
|
323
|
-
output: this['input'] extends [LParen, infer Parameters extends
|
|
243
|
+
output: this['input'] extends [LParen, infer Parameters extends t.TSchema[], RParen, '=>', infer ReturnType extends t.TSchema] ? t.TFunction<Parameters, ReturnType> : never;
|
|
324
244
|
}
|
|
325
245
|
type Function = Static.Tuple<[
|
|
326
246
|
Static.Const<LParen>,
|
|
@@ -330,7 +250,7 @@ type Function = Static.Tuple<[
|
|
|
330
250
|
Type
|
|
331
251
|
], FunctionMapping>;
|
|
332
252
|
interface ConstructorMapping extends Static.IMapping {
|
|
333
|
-
output: this['input'] extends ['new', LParen, infer Parameters extends
|
|
253
|
+
output: this['input'] extends ['new', LParen, infer Parameters extends t.TSchema[], RParen, '=>', infer InstanceType extends t.TSchema] ? t.TConstructor<Parameters, InstanceType> : never;
|
|
334
254
|
}
|
|
335
255
|
type Constructor = Static.Tuple<[
|
|
336
256
|
Static.Const<'new'>,
|
|
@@ -341,7 +261,7 @@ type Constructor = Static.Tuple<[
|
|
|
341
261
|
Type
|
|
342
262
|
], ConstructorMapping>;
|
|
343
263
|
interface MappedMapping extends Static.IMapping {
|
|
344
|
-
output: this['input'] extends [LBrace, LBracket, infer _Key extends string, 'in', infer _Right extends
|
|
264
|
+
output: this['input'] extends [LBrace, LBracket, infer _Key extends string, 'in', infer _Right extends t.TSchema, RBracket, Colon, infer Type extends t.TSchema, RBrace] ? t.TLiteral<'Mapped types not supported'> : this['input'];
|
|
345
265
|
}
|
|
346
266
|
type Mapped = Static.Tuple<[
|
|
347
267
|
Static.Const<LBrace>,
|
|
@@ -355,7 +275,7 @@ type Mapped = Static.Tuple<[
|
|
|
355
275
|
Static.Const<RBrace>
|
|
356
276
|
], MappedMapping>;
|
|
357
277
|
interface ArrayMapping extends Static.IMapping {
|
|
358
|
-
output: this['input'] extends ['Array', LAngle, infer Type extends
|
|
278
|
+
output: this['input'] extends ['Array', LAngle, infer Type extends t.TSchema, RAngle] ? t.TArray<Type> : never;
|
|
359
279
|
}
|
|
360
280
|
type Array = Static.Tuple<[
|
|
361
281
|
Static.Const<'Array'>,
|
|
@@ -364,7 +284,7 @@ type Array = Static.Tuple<[
|
|
|
364
284
|
Static.Const<RAngle>
|
|
365
285
|
], ArrayMapping>;
|
|
366
286
|
interface AsyncIteratorMapping extends Static.IMapping {
|
|
367
|
-
output: this['input'] extends ['AsyncIterator', LAngle, infer Type extends
|
|
287
|
+
output: this['input'] extends ['AsyncIterator', LAngle, infer Type extends t.TSchema, RAngle] ? t.TAsyncIterator<Type> : never;
|
|
368
288
|
}
|
|
369
289
|
type AsyncIterator = Static.Tuple<[
|
|
370
290
|
Static.Const<'AsyncIterator'>,
|
|
@@ -373,7 +293,7 @@ type AsyncIterator = Static.Tuple<[
|
|
|
373
293
|
Static.Const<RAngle>
|
|
374
294
|
], AsyncIteratorMapping>;
|
|
375
295
|
interface IteratorMapping extends Static.IMapping {
|
|
376
|
-
output: this['input'] extends ['Iterator', LAngle, infer Type extends
|
|
296
|
+
output: this['input'] extends ['Iterator', LAngle, infer Type extends t.TSchema, RAngle] ? t.TIterator<Type> : never;
|
|
377
297
|
}
|
|
378
298
|
type Iterator = Static.Tuple<[
|
|
379
299
|
Static.Const<'Iterator'>,
|
|
@@ -382,7 +302,7 @@ type Iterator = Static.Tuple<[
|
|
|
382
302
|
Static.Const<RAngle>
|
|
383
303
|
], IteratorMapping>;
|
|
384
304
|
interface ConstructorParametersMapping extends Static.IMapping {
|
|
385
|
-
output: this['input'] extends ['ConstructorParameters', LAngle, infer Type extends
|
|
305
|
+
output: this['input'] extends ['ConstructorParameters', LAngle, infer Type extends t.TSchema, RAngle] ? t.TConstructorParameters<Type> : never;
|
|
386
306
|
}
|
|
387
307
|
type ConstructorParameters = Static.Tuple<[
|
|
388
308
|
Static.Const<'ConstructorParameters'>,
|
|
@@ -391,7 +311,7 @@ type ConstructorParameters = Static.Tuple<[
|
|
|
391
311
|
Static.Const<RAngle>
|
|
392
312
|
], ConstructorParametersMapping>;
|
|
393
313
|
interface FunctionParametersMapping extends Static.IMapping {
|
|
394
|
-
output: this['input'] extends ['Parameters', LAngle, infer Type extends
|
|
314
|
+
output: this['input'] extends ['Parameters', LAngle, infer Type extends t.TSchema, RAngle] ? t.TParameters<Type> : never;
|
|
395
315
|
}
|
|
396
316
|
type FunctionParameters = Static.Tuple<[
|
|
397
317
|
Static.Const<'Parameters'>,
|
|
@@ -400,7 +320,7 @@ type FunctionParameters = Static.Tuple<[
|
|
|
400
320
|
Static.Const<RAngle>
|
|
401
321
|
], FunctionParametersMapping>;
|
|
402
322
|
interface InstanceTypeMapping extends Static.IMapping {
|
|
403
|
-
output: this['input'] extends ['InstanceType', LAngle, infer Type extends
|
|
323
|
+
output: this['input'] extends ['InstanceType', LAngle, infer Type extends t.TSchema, RAngle] ? t.TInstanceType<Type> : never;
|
|
404
324
|
}
|
|
405
325
|
type InstanceType = Static.Tuple<[
|
|
406
326
|
Static.Const<'InstanceType'>,
|
|
@@ -409,7 +329,7 @@ type InstanceType = Static.Tuple<[
|
|
|
409
329
|
Static.Const<RAngle>
|
|
410
330
|
], InstanceTypeMapping>;
|
|
411
331
|
interface ReturnTypeMapping extends Static.IMapping {
|
|
412
|
-
output: this['input'] extends ['ReturnType', LAngle, infer Type extends
|
|
332
|
+
output: this['input'] extends ['ReturnType', LAngle, infer Type extends t.TSchema, RAngle] ? t.TReturnType<Type> : never;
|
|
413
333
|
}
|
|
414
334
|
type ReturnType = Static.Tuple<[
|
|
415
335
|
Static.Const<'ReturnType'>,
|
|
@@ -418,7 +338,7 @@ type ReturnType = Static.Tuple<[
|
|
|
418
338
|
Static.Const<RAngle>
|
|
419
339
|
], ReturnTypeMapping>;
|
|
420
340
|
interface AwaitedMapping extends Static.IMapping {
|
|
421
|
-
output: this['input'] extends ['Awaited', LAngle, infer Type extends
|
|
341
|
+
output: this['input'] extends ['Awaited', LAngle, infer Type extends t.TSchema, RAngle] ? t.TAwaited<Type> : never;
|
|
422
342
|
}
|
|
423
343
|
type Awaited = Static.Tuple<[
|
|
424
344
|
Static.Const<'Awaited'>,
|
|
@@ -427,7 +347,7 @@ type Awaited = Static.Tuple<[
|
|
|
427
347
|
Static.Const<RAngle>
|
|
428
348
|
], AwaitedMapping>;
|
|
429
349
|
interface PromiseMapping extends Static.IMapping {
|
|
430
|
-
output: this['input'] extends ['Promise', LAngle, infer Type extends
|
|
350
|
+
output: this['input'] extends ['Promise', LAngle, infer Type extends t.TSchema, RAngle] ? t.TPromise<Type> : never;
|
|
431
351
|
}
|
|
432
352
|
type Promise = Static.Tuple<[
|
|
433
353
|
Static.Const<'Promise'>,
|
|
@@ -436,7 +356,7 @@ type Promise = Static.Tuple<[
|
|
|
436
356
|
Static.Const<RAngle>
|
|
437
357
|
], PromiseMapping>;
|
|
438
358
|
interface RecordMapping extends Static.IMapping {
|
|
439
|
-
output: this['input'] extends ['Record', LAngle, infer Key extends
|
|
359
|
+
output: this['input'] extends ['Record', LAngle, infer Key extends t.TSchema, Comma, infer Type extends t.TSchema, RAngle] ? t.TRecord<Key, Type> : never;
|
|
440
360
|
}
|
|
441
361
|
type Record = Static.Tuple<[
|
|
442
362
|
Static.Const<'Record'>,
|
|
@@ -447,7 +367,7 @@ type Record = Static.Tuple<[
|
|
|
447
367
|
Static.Const<RAngle>
|
|
448
368
|
], RecordMapping>;
|
|
449
369
|
interface PartialMapping extends Static.IMapping {
|
|
450
|
-
output: this['input'] extends ['Partial', LAngle, infer Type extends
|
|
370
|
+
output: this['input'] extends ['Partial', LAngle, infer Type extends t.TSchema, RAngle] ? t.TPartial<Type> : never;
|
|
451
371
|
}
|
|
452
372
|
type Partial = Static.Tuple<[
|
|
453
373
|
Static.Const<'Partial'>,
|
|
@@ -456,7 +376,7 @@ type Partial = Static.Tuple<[
|
|
|
456
376
|
Static.Const<RAngle>
|
|
457
377
|
], PartialMapping>;
|
|
458
378
|
interface RequiredMapping extends Static.IMapping {
|
|
459
|
-
output: this['input'] extends ['Required', LAngle, infer Type extends
|
|
379
|
+
output: this['input'] extends ['Required', LAngle, infer Type extends t.TSchema, RAngle] ? t.TRequired<Type> : never;
|
|
460
380
|
}
|
|
461
381
|
type Required = Static.Tuple<[
|
|
462
382
|
Static.Const<'Required'>,
|
|
@@ -465,7 +385,7 @@ type Required = Static.Tuple<[
|
|
|
465
385
|
Static.Const<RAngle>
|
|
466
386
|
], RequiredMapping>;
|
|
467
387
|
interface PickMapping extends Static.IMapping {
|
|
468
|
-
output: this['input'] extends ['Pick', LAngle, infer Type extends
|
|
388
|
+
output: this['input'] extends ['Pick', LAngle, infer Type extends t.TSchema, Comma, infer Key extends t.TSchema, RAngle] ? t.TPick<Type, Key> : never;
|
|
469
389
|
}
|
|
470
390
|
type Pick = Static.Tuple<[
|
|
471
391
|
Static.Const<'Pick'>,
|
|
@@ -476,7 +396,7 @@ type Pick = Static.Tuple<[
|
|
|
476
396
|
Static.Const<RAngle>
|
|
477
397
|
], PickMapping>;
|
|
478
398
|
interface OmitMapping extends Static.IMapping {
|
|
479
|
-
output: this['input'] extends ['Omit', LAngle, infer Type extends
|
|
399
|
+
output: this['input'] extends ['Omit', LAngle, infer Type extends t.TSchema, Comma, infer Key extends t.TSchema, RAngle] ? t.TOmit<Type, Key> : never;
|
|
480
400
|
}
|
|
481
401
|
type Omit = Static.Tuple<[
|
|
482
402
|
Static.Const<'Omit'>,
|
|
@@ -487,7 +407,7 @@ type Omit = Static.Tuple<[
|
|
|
487
407
|
Static.Const<RAngle>
|
|
488
408
|
], OmitMapping>;
|
|
489
409
|
interface ExcludeMapping extends Static.IMapping {
|
|
490
|
-
output: this['input'] extends ['Exclude', LAngle, infer Type extends
|
|
410
|
+
output: this['input'] extends ['Exclude', LAngle, infer Type extends t.TSchema, Comma, infer PropertyKey extends t.TSchema, RAngle] ? t.TExclude<Type, PropertyKey> : never;
|
|
491
411
|
}
|
|
492
412
|
type Exclude = Static.Tuple<[
|
|
493
413
|
Static.Const<'Exclude'>,
|
|
@@ -498,7 +418,7 @@ type Exclude = Static.Tuple<[
|
|
|
498
418
|
Static.Const<RAngle>
|
|
499
419
|
], ExcludeMapping>;
|
|
500
420
|
interface ExtractMapping extends Static.IMapping {
|
|
501
|
-
output: this['input'] extends ['Extract', LAngle, infer Type extends
|
|
421
|
+
output: this['input'] extends ['Extract', LAngle, infer Type extends t.TSchema, Comma, infer PropertyKey extends t.TSchema, RAngle] ? t.TExtract<Type, PropertyKey> : never;
|
|
502
422
|
}
|
|
503
423
|
type Extract = Static.Tuple<[
|
|
504
424
|
Static.Const<'Extract'>,
|
|
@@ -509,7 +429,7 @@ type Extract = Static.Tuple<[
|
|
|
509
429
|
Static.Const<RAngle>
|
|
510
430
|
], ExtractMapping>;
|
|
511
431
|
interface UppercaseMapping extends Static.IMapping {
|
|
512
|
-
output: this['input'] extends ['Uppercase', LAngle, infer Type extends
|
|
432
|
+
output: this['input'] extends ['Uppercase', LAngle, infer Type extends t.TSchema, RAngle] ? t.TUppercase<Type> : never;
|
|
513
433
|
}
|
|
514
434
|
type Uppercase = Static.Tuple<[
|
|
515
435
|
Static.Const<'Uppercase'>,
|
|
@@ -518,7 +438,7 @@ type Uppercase = Static.Tuple<[
|
|
|
518
438
|
Static.Const<RAngle>
|
|
519
439
|
], UppercaseMapping>;
|
|
520
440
|
interface LowercaseMapping extends Static.IMapping {
|
|
521
|
-
output: this['input'] extends ['Lowercase', LAngle, infer Type extends
|
|
441
|
+
output: this['input'] extends ['Lowercase', LAngle, infer Type extends t.TSchema, RAngle] ? t.TLowercase<Type> : never;
|
|
522
442
|
}
|
|
523
443
|
type Lowercase = Static.Tuple<[
|
|
524
444
|
Static.Const<'Lowercase'>,
|
|
@@ -527,7 +447,7 @@ type Lowercase = Static.Tuple<[
|
|
|
527
447
|
Static.Const<RAngle>
|
|
528
448
|
], LowercaseMapping>;
|
|
529
449
|
interface CapitalizeMapping extends Static.IMapping {
|
|
530
|
-
output: this['input'] extends ['Capitalize', LAngle, infer Type extends
|
|
450
|
+
output: this['input'] extends ['Capitalize', LAngle, infer Type extends t.TSchema, RAngle] ? t.TCapitalize<Type> : never;
|
|
531
451
|
}
|
|
532
452
|
type Capitalize = Static.Tuple<[
|
|
533
453
|
Static.Const<'Capitalize'>,
|
|
@@ -536,7 +456,7 @@ type Capitalize = Static.Tuple<[
|
|
|
536
456
|
Static.Const<RAngle>
|
|
537
457
|
], CapitalizeMapping>;
|
|
538
458
|
interface UncapitalizeMapping extends Static.IMapping {
|
|
539
|
-
output: this['input'] extends ['Uncapitalize', LAngle, infer Type extends
|
|
459
|
+
output: this['input'] extends ['Uncapitalize', LAngle, infer Type extends t.TSchema, RAngle] ? t.TUncapitalize<Type> : never;
|
|
540
460
|
}
|
|
541
461
|
type Uncapitalize = Static.Tuple<[
|
|
542
462
|
Static.Const<'Uncapitalize'>,
|
|
@@ -544,12 +464,6 @@ type Uncapitalize = Static.Tuple<[
|
|
|
544
464
|
Type,
|
|
545
465
|
Static.Const<RAngle>
|
|
546
466
|
], UncapitalizeMapping>;
|
|
547
|
-
type Date = Static.Const<'Date', Static.As<
|
|
548
|
-
type Uint8Array = Static.Const<'Uint8Array', Static.As<
|
|
549
|
-
export type Main = Static.Union<[
|
|
550
|
-
ModuleDeclaration,
|
|
551
|
-
TypeAliasDeclaration,
|
|
552
|
-
InterfaceDeclaration,
|
|
553
|
-
Type
|
|
554
|
-
]>;
|
|
467
|
+
type Date = Static.Const<'Date', Static.As<t.TDate>>;
|
|
468
|
+
type Uint8Array = Static.Const<'Uint8Array', Static.As<t.TUint8Array>>;
|
|
555
469
|
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as Types from '../type/index';
|
|
2
|
+
import { Static } from '../parser/index';
|
|
3
|
+
import { Type } from './static';
|
|
4
|
+
/** Parses a TSchema type from TypeScript syntax but does not infer schematics */
|
|
5
|
+
export declare function NoInfer<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
|
|
6
|
+
/** Parses a TSchema type from TypeScript syntax but does not infer schematics */
|
|
7
|
+
export declare function NoInfer<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
|
|
8
|
+
/** Infers a TSchema type from TypeScript syntax. */
|
|
9
|
+
export type TSyntax<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = (Static.Parse<Type, Code, Context> extends [infer Type extends Types.TSchema, string] ? Type : Types.TNever);
|
|
10
|
+
/** Parses a TSchema type from TypeScript syntax */
|
|
11
|
+
export declare function Syntax<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): TSyntax<Context, Code>;
|
|
12
|
+
/** Parses a TSchema type from TypeScript syntax */
|
|
13
|
+
export declare function Syntax<Code extends string>(code: Code, options?: Types.SchemaOptions): TSyntax<{}, Code>;
|
|
14
|
+
/**
|
|
15
|
+
* Parses a TSchema type from Syntax.
|
|
16
|
+
* @deprecated Use Syntax() function
|
|
17
|
+
*/
|
|
18
|
+
export declare function Parse<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): TSyntax<Context, Code>;
|
|
19
|
+
/**
|
|
20
|
+
* Parses a TSchema type from Syntax.
|
|
21
|
+
* @deprecated Use Syntax() function
|
|
22
|
+
*/
|
|
23
|
+
export declare function Parse<Code extends string>(code: Code, options?: Types.SchemaOptions): TSyntax<{}, Code>;
|
|
24
|
+
/**
|
|
25
|
+
* Parses a TSchema from TypeScript Syntax
|
|
26
|
+
* @deprecated Use NoInfer() function
|
|
27
|
+
*/
|
|
28
|
+
export declare function ParseOnly<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Parses a TSchema from TypeScript Syntax
|
|
31
|
+
* @deprecated Use NoInfer() function
|
|
32
|
+
*/
|
|
33
|
+
export declare function ParseOnly<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NoInfer = NoInfer;
|
|
5
|
+
exports.Syntax = Syntax;
|
|
6
|
+
exports.Parse = Parse;
|
|
7
|
+
exports.ParseOnly = ParseOnly;
|
|
8
|
+
const Types = require("../type/index");
|
|
9
|
+
const runtime_1 = require("./runtime");
|
|
10
|
+
/** Parses a TSchema type from TypeScript syntax but does not infer schematics */
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
function NoInfer(...args) {
|
|
13
|
+
const withContext = typeof args[0] === 'string' ? false : true;
|
|
14
|
+
const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}];
|
|
15
|
+
const type = runtime_1.Module.Parse('Type', code, context)[0];
|
|
16
|
+
return Types.KindGuard.IsSchema(type)
|
|
17
|
+
? Types.CloneType(type, options)
|
|
18
|
+
: Types.Never(options);
|
|
19
|
+
}
|
|
20
|
+
/** Parses a TSchema type from TypeScript syntax */
|
|
21
|
+
function Syntax(...args) {
|
|
22
|
+
return NoInfer.apply(null, args);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses a TSchema type from Syntax.
|
|
26
|
+
* @deprecated Use Syntax() function
|
|
27
|
+
*/
|
|
28
|
+
function Parse(...args) {
|
|
29
|
+
return NoInfer.apply(null, args);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses a TSchema from TypeScript Syntax
|
|
33
|
+
* @deprecated Use NoInfer() function
|
|
34
|
+
*/
|
|
35
|
+
function ParseOnly(...args) {
|
|
36
|
+
return NoInfer.apply(null, args);
|
|
37
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
-
import type { Ensure } from '../helpers/index';
|
|
3
2
|
import type { TConstructor } from '../constructor/index';
|
|
4
3
|
import { type TTuple } from '../tuple/index';
|
|
5
|
-
|
|
4
|
+
import { type TNever } from '../never/index';
|
|
5
|
+
export type TConstructorParameters<Type extends TSchema> = (Type extends TConstructor<infer Parameters extends TSchema[], infer _InstanceType extends TSchema> ? TTuple<Parameters> : TNever);
|
|
6
6
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
7
|
-
export declare function ConstructorParameters<
|
|
7
|
+
export declare function ConstructorParameters<Type extends TSchema>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConstructorParameters = ConstructorParameters;
|
|
5
5
|
const index_1 = require("../tuple/index");
|
|
6
|
+
const index_2 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
7
9
|
function ConstructorParameters(schema, options) {
|
|
8
|
-
return (0, index_1.Tuple)(schema.parameters, options);
|
|
10
|
+
return (KindGuard.IsConstructor(schema) ? (0, index_1.Tuple)(schema.parameters, options) : (0, index_2.Never)(options));
|
|
9
11
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
|
|
1
|
+
import { type TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
+
import { type TConstructor } from '../constructor/index';
|
|
3
|
+
import { type TNever } from '../never/index';
|
|
4
|
+
export type TInstanceType<Type extends TSchema, Result extends TSchema = Type extends TConstructor<infer _Parameters extends TSchema[], infer InstanceType extends TSchema> ? InstanceType : TNever> = Result;
|
|
4
5
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
5
|
-
export declare function InstanceType<
|
|
6
|
+
export declare function InstanceType<Type extends TSchema>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.InstanceType = InstanceType;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
+
const index_1 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
7
9
|
function InstanceType(schema, options) {
|
|
8
|
-
return (0, type_1.CreateType)(schema.returns, options);
|
|
10
|
+
return (KindGuard.IsConstructor(schema) ? (0, type_1.CreateType)(schema.returns, options) : (0, index_1.Never)(options));
|
|
9
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import type { TFunction } from '../function/index';
|
|
3
|
-
import type { Ensure } from '../helpers/index';
|
|
4
3
|
import { type TTuple } from '../tuple/index';
|
|
5
|
-
|
|
4
|
+
import { type TNever } from '../never/index';
|
|
5
|
+
export type TParameters<Type extends TSchema> = (Type extends TFunction<infer Parameters extends TSchema[], infer _ReturnType extends TSchema> ? TTuple<Parameters> : TNever);
|
|
6
6
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
7
|
-
export declare function Parameters<
|
|
7
|
+
export declare function Parameters<Type extends TSchema>(schema: Type, options?: SchemaOptions): TParameters<Type>;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Parameters = Parameters;
|
|
5
5
|
const index_1 = require("../tuple/index");
|
|
6
|
+
const index_2 = require("../never/index");
|
|
7
|
+
const KindGuard = require("../guard/kind");
|
|
6
8
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
7
9
|
function Parameters(schema, options) {
|
|
8
|
-
return (0, index_1.Tuple)(schema.parameters, options);
|
|
10
|
+
return (KindGuard.IsFunction(schema) ? (0, index_1.Tuple)(schema.parameters, options) : (0, index_2.Never)());
|
|
9
11
|
}
|