@sinclair/typebox 0.34.28 → 0.34.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/syntax/runtime.d.ts +6 -5
- package/build/cjs/syntax/runtime.js +145 -148
- package/build/cjs/syntax/static.d.ts +79 -108
- package/build/esm/syntax/runtime.d.mts +6 -5
- package/build/esm/syntax/runtime.mjs +145 -148
- package/build/esm/syntax/static.d.mts +79 -108
- package/package.json +1 -1
|
@@ -16,60 +16,43 @@ type SemiColon = ';';
|
|
|
16
16
|
type SingleQuote = "'";
|
|
17
17
|
type DoubleQuote = '"';
|
|
18
18
|
type Tilde = '`';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
Static.Tuple<[
|
|
26
|
-
Static.Tuple<[_, T, _, T, _, T, _, T, _, T, _, T, _, T, _, Delimit<T, _>]>,
|
|
27
|
-
Static.Tuple<[_, T, _, T, _, T, _, T, _, T, _, T, _, Delimit<T, _>]>,
|
|
28
|
-
Static.Tuple<[_, T, _, T, _, T, _, T, _, T, _, Delimit<T, _>]>,
|
|
29
|
-
Static.Tuple<[_, T, _, T, _, T, _, T, _, Delimit<T, _>]>,
|
|
30
|
-
Static.Tuple<[_, T, _, T, _, T, _, Delimit<T, _>]>,
|
|
31
|
-
Static.Tuple<[_, T, _, T, _, Delimit<T, _>]>,
|
|
32
|
-
Static.Tuple<[_, T, _, Delimit<T, _>]>,
|
|
33
|
-
Static.Tuple<[_, Delimit<T, _>]>,
|
|
34
|
-
Static.Tuple<[_]>,
|
|
19
|
+
type DelimitHeadReduce<Elements extends unknown[], Result extends unknown[] = []> = (Elements extends [infer Left extends unknown, ...infer Right extends unknown[]] ? Left extends [infer Element, infer _Delimiter] ? DelimitHeadReduce<Right, [...Result, Element]> : DelimitHeadReduce<Right, Result> : Result);
|
|
20
|
+
interface DelimitHeadMapping extends Static.IMapping {
|
|
21
|
+
output: this['input'] extends unknown[] ? DelimitHeadReduce<this['input']> : [];
|
|
22
|
+
}
|
|
23
|
+
type DelimitHead<Element extends Static.IParser, Delimiter extends Static.IParser> = (Static.Array<Static.Tuple<[Element, Delimiter]>, DelimitHeadMapping>);
|
|
24
|
+
type DelimitTail<Element extends Static.IParser> = Static.Union<[
|
|
25
|
+
Static.Tuple<[Element]>,
|
|
35
26
|
Static.Tuple<[]>
|
|
36
|
-
]
|
|
27
|
+
]>;
|
|
37
28
|
interface DelimitMapping extends Static.IMapping {
|
|
38
|
-
output:
|
|
29
|
+
output: this['input'] extends [infer Left extends unknown[], infer Right extends unknown[]] ? [...Left, ...Right] : [];
|
|
39
30
|
}
|
|
40
|
-
type Delimit<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
], DelimitMapping
|
|
31
|
+
type Delimit<Element extends Static.IParser, Delimiter extends Static.IParser> = Static.Tuple<[
|
|
32
|
+
DelimitHead<Element, Delimiter>,
|
|
33
|
+
DelimitTail<Element>
|
|
34
|
+
], DelimitMapping>;
|
|
44
35
|
type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
|
|
45
|
-
interface GenericArgumentListMapping extends Static.IMapping {
|
|
46
|
-
output: (this['input'] extends [infer Ident extends string, Comma, infer Rest extends unknown[]] ? [Ident, ...Rest] : this['input'] extends [infer Ident extends string, Comma] ? [Ident] : this['input'] extends [infer Ident extends string] ? [Ident] : [
|
|
47
|
-
]);
|
|
48
|
-
}
|
|
49
|
-
type GenericArgumentList = Static.Union<[
|
|
50
|
-
Static.Tuple<[Static.Ident, Static.Const<Comma>, GenericArgumentList]>,
|
|
51
|
-
Static.Tuple<[Static.Ident, Static.Const<Comma>]>,
|
|
52
|
-
Static.Tuple<[Static.Ident]>,
|
|
53
|
-
Static.Tuple<[]>
|
|
54
|
-
], GenericArgumentListMapping>;
|
|
55
36
|
type GenericArgumentsContext<Args extends string[], Context extends t.TProperties, Result extends t.TProperties = {}> = (Args extends [...infer Left extends string[], infer Right extends string] ? GenericArgumentsContext<Left, Context, Result & {
|
|
56
37
|
[_ in Right]: t.TArgument<Left['length']>;
|
|
57
38
|
}> : t.Evaluate<Result & Context>);
|
|
58
39
|
interface GenericArgumentsMapping extends Static.IMapping {
|
|
59
40
|
output: this['input'] extends [LAngle, infer Args extends string[], RAngle] ? this['context'] extends infer Context extends t.TProperties ? GenericArgumentsContext<Args, Context> : never : never;
|
|
60
41
|
}
|
|
42
|
+
type GenericArgumentsList = Delimit<Static.Ident, Static.Const<Comma>>;
|
|
61
43
|
type GenericArguments = Static.Tuple<[
|
|
62
44
|
Static.Const<LAngle>,
|
|
63
|
-
|
|
45
|
+
GenericArgumentsList,
|
|
64
46
|
Static.Const<RAngle>
|
|
65
47
|
], GenericArgumentsMapping>;
|
|
66
48
|
interface GenericReferenceMapping extends Static.IMapping {
|
|
67
49
|
output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Args extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, Args> : never : never;
|
|
68
50
|
}
|
|
51
|
+
type GenericReferenceParameters = Delimit<Type, Static.Const<Comma>>;
|
|
69
52
|
type GenericReference = Static.Tuple<[
|
|
70
53
|
Static.Ident,
|
|
71
54
|
Static.Const<LAngle>,
|
|
72
|
-
|
|
55
|
+
GenericReferenceParameters,
|
|
73
56
|
Static.Const<RAngle>
|
|
74
57
|
], GenericReferenceMapping>;
|
|
75
58
|
interface ReferenceMapping extends Static.IMapping {
|
|
@@ -77,13 +60,13 @@ interface ReferenceMapping extends Static.IMapping {
|
|
|
77
60
|
}
|
|
78
61
|
type Reference = Static.Ident<ReferenceMapping>;
|
|
79
62
|
interface LiteralBooleanMapping extends Static.IMapping {
|
|
80
|
-
output: this['input'] extends `${infer
|
|
63
|
+
output: this['input'] extends `${infer Value extends boolean}` ? t.TLiteral<Value> : never;
|
|
81
64
|
}
|
|
82
65
|
interface LiteralNumberMapping extends Static.IMapping {
|
|
83
|
-
output: this['input'] extends `${infer
|
|
66
|
+
output: this['input'] extends `${infer Value extends number}` ? t.TLiteral<Value> : never;
|
|
84
67
|
}
|
|
85
68
|
interface LiteralStringMapping extends Static.IMapping {
|
|
86
|
-
output: this['input'] extends `${infer
|
|
69
|
+
output: this['input'] extends `${infer Value extends string}` ? t.TLiteral<Value> : never;
|
|
87
70
|
}
|
|
88
71
|
type Literal = Static.Union<[
|
|
89
72
|
Static.Union<[Static.Const<'true'>, Static.Const<'false'>], LiteralBooleanMapping>,
|
|
@@ -91,17 +74,17 @@ type Literal = Static.Union<[
|
|
|
91
74
|
Static.String<[DoubleQuote, SingleQuote, Tilde], LiteralStringMapping>
|
|
92
75
|
]>;
|
|
93
76
|
type Keyword = Static.Union<[
|
|
94
|
-
Static.Const<'
|
|
95
|
-
Static.Const<'
|
|
77
|
+
Static.Const<'string', Static.As<t.TString>>,
|
|
78
|
+
Static.Const<'number', Static.As<t.TNumber>>,
|
|
96
79
|
Static.Const<'boolean', Static.As<t.TBoolean>>,
|
|
80
|
+
Static.Const<'undefined', Static.As<t.TUndefined>>,
|
|
81
|
+
Static.Const<'null', Static.As<t.TNull>>,
|
|
97
82
|
Static.Const<'integer', Static.As<t.TInteger>>,
|
|
83
|
+
Static.Const<'bigint', Static.As<t.TBigInt>>,
|
|
84
|
+
Static.Const<'unknown', Static.As<t.TUnknown>>,
|
|
85
|
+
Static.Const<'any', Static.As<t.TAny>>,
|
|
98
86
|
Static.Const<'never', Static.As<t.TNever>>,
|
|
99
|
-
Static.Const<'null', Static.As<t.TNull>>,
|
|
100
|
-
Static.Const<'number', Static.As<t.TNumber>>,
|
|
101
|
-
Static.Const<'string', Static.As<t.TString>>,
|
|
102
87
|
Static.Const<'symbol', Static.As<t.TSymbol>>,
|
|
103
|
-
Static.Const<'undefined', Static.As<t.TUndefined>>,
|
|
104
|
-
Static.Const<'unknown', Static.As<t.TUnknown>>,
|
|
105
88
|
Static.Const<'void', Static.As<t.TVoid>>
|
|
106
89
|
]>;
|
|
107
90
|
interface KeyOfMapping extends Static.IMapping {
|
|
@@ -111,15 +94,14 @@ type KeyOf = Static.Union<[
|
|
|
111
94
|
Static.Tuple<[Static.Const<'keyof'>]>,
|
|
112
95
|
Static.Tuple<[]>
|
|
113
96
|
], KeyOfMapping>;
|
|
97
|
+
type IndexArrayReduce<Values extends unknown[], Result extends unknown[] = []> = (Values extends [infer Left extends unknown, ...infer Right extends unknown[]] ? Left extends [LBracket, infer Type extends t.TSchema, RBracket] ? IndexArrayReduce<Right, [...Result, [Type]]> : IndexArrayReduce<Right, [...Result, []]> : Result);
|
|
114
98
|
interface IndexArrayMapping extends Static.IMapping {
|
|
115
|
-
output:
|
|
116
|
-
]);
|
|
99
|
+
output: this['input'] extends unknown[] ? IndexArrayReduce<this['input']> : [];
|
|
117
100
|
}
|
|
118
|
-
type IndexArray = Static.Union<[
|
|
119
|
-
Static.Tuple<[Static.Const<LBracket>, Type, Static.Const<RBracket
|
|
120
|
-
Static.Tuple<[Static.Const<LBracket>, Static.Const<RBracket
|
|
121
|
-
|
|
122
|
-
], IndexArrayMapping>;
|
|
101
|
+
type IndexArray = Static.Array<Static.Union<[
|
|
102
|
+
Static.Tuple<[Static.Const<LBracket>, Type, Static.Const<RBracket>]>,
|
|
103
|
+
Static.Tuple<[Static.Const<LBracket>, Static.Const<RBracket>]>
|
|
104
|
+
]>, IndexArrayMapping>;
|
|
123
105
|
interface ExtendsMapping extends Static.IMapping {
|
|
124
106
|
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] : [];
|
|
125
107
|
}
|
|
@@ -128,50 +110,42 @@ type Extends = Static.Union<[
|
|
|
128
110
|
Static.Tuple<[]>
|
|
129
111
|
], ExtendsMapping>;
|
|
130
112
|
interface BaseMapping extends Static.IMapping {
|
|
131
|
-
output: (this['input'] extends [LParen, infer Type extends t.TSchema, RParen] ? Type : this['input'] extends
|
|
113
|
+
output: (this['input'] extends [LParen, infer Type extends t.TSchema, RParen] ? Type : this['input'] extends infer Type extends t.TSchema ? Type : never);
|
|
132
114
|
}
|
|
133
115
|
type Base = Static.Union<[
|
|
134
|
-
Static.Tuple<[
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
Capitalize,
|
|
168
|
-
Uncapitalize,
|
|
169
|
-
Date,
|
|
170
|
-
Uint8Array,
|
|
171
|
-
GenericReference,
|
|
172
|
-
Reference
|
|
173
|
-
]>
|
|
174
|
-
]>
|
|
116
|
+
Static.Tuple<[Static.Const<LParen>, Type, Static.Const<RParen>]>,
|
|
117
|
+
Keyword,
|
|
118
|
+
Object,
|
|
119
|
+
Tuple,
|
|
120
|
+
Literal,
|
|
121
|
+
Function,
|
|
122
|
+
Constructor,
|
|
123
|
+
Mapped,
|
|
124
|
+
AsyncIterator,
|
|
125
|
+
Iterator,
|
|
126
|
+
ConstructorParameters,
|
|
127
|
+
FunctionParameters,
|
|
128
|
+
Argument,
|
|
129
|
+
InstanceType,
|
|
130
|
+
ReturnType,
|
|
131
|
+
Awaited,
|
|
132
|
+
Array,
|
|
133
|
+
Record,
|
|
134
|
+
Promise,
|
|
135
|
+
Partial,
|
|
136
|
+
Required,
|
|
137
|
+
Pick,
|
|
138
|
+
Omit,
|
|
139
|
+
Exclude,
|
|
140
|
+
Extract,
|
|
141
|
+
Lowercase,
|
|
142
|
+
Uppercase,
|
|
143
|
+
Capitalize,
|
|
144
|
+
Uncapitalize,
|
|
145
|
+
Date,
|
|
146
|
+
Uint8Array,
|
|
147
|
+
GenericReference,
|
|
148
|
+
Reference
|
|
175
149
|
], BaseMapping>;
|
|
176
150
|
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);
|
|
177
151
|
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);
|
|
@@ -243,26 +217,23 @@ type PropertyDelimiter = Static.Union<[
|
|
|
243
217
|
Static.Tuple<[Static.Const<SemiColon>]>,
|
|
244
218
|
Static.Tuple<[Static.Const<Newline>]>
|
|
245
219
|
]>;
|
|
246
|
-
type
|
|
247
|
-
|
|
248
|
-
output: this['input'] extends t.TProperties[] ? PropertiesReduce<this['input']> : never;
|
|
249
|
-
}
|
|
250
|
-
type Properties = Static.Union<[Delimit<Property, PropertyDelimiter>], PropertiesMapping>;
|
|
220
|
+
type PropertyList = Delimit<Property, PropertyDelimiter>;
|
|
221
|
+
type ObjectReduce<PropertiesList extends t.TProperties[], Result extends t.TProperties = {}> = (PropertiesList extends [infer Left extends t.TProperties, ...infer Right extends t.TProperties[]] ? ObjectReduce<Right, Result & Left> : t.Evaluate<Result>);
|
|
251
222
|
interface ObjectMapping extends Static.IMapping {
|
|
252
|
-
output: this['input'] extends [
|
|
223
|
+
output: this['input'] extends [LBrace, infer PropertyList extends t.TProperties[], RBrace] ? t.TObject<ObjectReduce<PropertyList>> : never;
|
|
253
224
|
}
|
|
254
225
|
type Object = Static.Tuple<[
|
|
255
226
|
Static.Const<LBrace>,
|
|
256
|
-
|
|
227
|
+
PropertyList,
|
|
257
228
|
Static.Const<RBrace>
|
|
258
229
|
], ObjectMapping>;
|
|
259
|
-
type
|
|
230
|
+
type ElementList = Delimit<Type, Static.Const<Comma>>;
|
|
260
231
|
interface TupleMapping extends Static.IMapping {
|
|
261
|
-
output: this['input'] extends [unknown, infer
|
|
232
|
+
output: this['input'] extends [unknown, infer ElementList extends t.TSchema[], unknown] ? t.TTuple<ElementList> : never;
|
|
262
233
|
}
|
|
263
234
|
type Tuple = Static.Tuple<[
|
|
264
235
|
Static.Const<LBracket>,
|
|
265
|
-
|
|
236
|
+
ElementList,
|
|
266
237
|
Static.Const<RBracket>
|
|
267
238
|
], TupleMapping>;
|
|
268
239
|
interface ParameterMapping extends Static.IMapping {
|
|
@@ -273,24 +244,24 @@ type Parameter = Static.Tuple<[
|
|
|
273
244
|
Static.Const<Colon>,
|
|
274
245
|
Type
|
|
275
246
|
], ParameterMapping>;
|
|
276
|
-
type
|
|
247
|
+
type ParameterList = Delimit<Parameter, Static.Const<Comma>>;
|
|
277
248
|
interface FunctionMapping extends Static.IMapping {
|
|
278
|
-
output: this['input'] extends [LParen, infer
|
|
249
|
+
output: this['input'] extends [LParen, infer ParameterList extends t.TSchema[], RParen, '=>', infer ReturnType extends t.TSchema] ? t.TFunction<ParameterList, ReturnType> : never;
|
|
279
250
|
}
|
|
280
251
|
type Function = Static.Tuple<[
|
|
281
252
|
Static.Const<LParen>,
|
|
282
|
-
|
|
253
|
+
ParameterList,
|
|
283
254
|
Static.Const<RParen>,
|
|
284
255
|
Static.Const<'=>'>,
|
|
285
256
|
Type
|
|
286
257
|
], FunctionMapping>;
|
|
287
258
|
interface ConstructorMapping extends Static.IMapping {
|
|
288
|
-
output: this['input'] extends ['new', LParen, infer
|
|
259
|
+
output: this['input'] extends ['new', LParen, infer ParameterList extends t.TSchema[], RParen, '=>', infer InstanceType extends t.TSchema] ? t.TConstructor<ParameterList, InstanceType> : never;
|
|
289
260
|
}
|
|
290
261
|
type Constructor = Static.Tuple<[
|
|
291
262
|
Static.Const<'new'>,
|
|
292
263
|
Static.Const<LParen>,
|
|
293
|
-
|
|
264
|
+
ParameterList,
|
|
294
265
|
Static.Const<RParen>,
|
|
295
266
|
Static.Const<'=>'>,
|
|
296
267
|
Type
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Runtime } from '../parser/index.mjs';
|
|
2
2
|
import * as t from '../type/index.mjs';
|
|
3
3
|
export declare const Module: Runtime.Module<{
|
|
4
|
-
|
|
4
|
+
GenericArgumentsList: Runtime.ITuple<unknown[]>;
|
|
5
5
|
GenericArguments: Runtime.ITuple<t.TProperties>;
|
|
6
6
|
Literal: Runtime.IUnion<t.TLiteral<string> | t.TLiteral<number> | t.TLiteral<boolean>>;
|
|
7
7
|
Keyword: Runtime.IUnion<t.TAny | t.TBoolean | t.TBigInt | t.TNever | t.TString | t.TNumber | t.TInteger | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
|
|
8
8
|
KeyOf: Runtime.IUnion<boolean>;
|
|
9
|
-
IndexArray: Runtime.
|
|
9
|
+
IndexArray: Runtime.IArray<unknown[]>;
|
|
10
10
|
Extends: Runtime.IUnion<unknown[]>;
|
|
11
11
|
Base: Runtime.IUnion<unknown>;
|
|
12
12
|
Factor: Runtime.ITuple<t.TSchema>;
|
|
@@ -22,13 +22,13 @@ export declare const Module: Runtime.Module<{
|
|
|
22
22
|
[x: string]: t.TSchema;
|
|
23
23
|
}>;
|
|
24
24
|
PropertyDelimiter: Runtime.IUnion<[","] | [",", "\n"] | [";"] | [";", "\n"] | ["\n"]>;
|
|
25
|
-
|
|
25
|
+
PropertyList: Runtime.ITuple<unknown[]>;
|
|
26
26
|
Object: Runtime.ITuple<t.TObject<t.TProperties>>;
|
|
27
|
-
|
|
27
|
+
ElementList: Runtime.ITuple<unknown[]>;
|
|
28
28
|
Tuple: Runtime.ITuple<t.TTuple<t.TSchema[]>>;
|
|
29
29
|
Parameter: Runtime.ITuple<t.TSchema>;
|
|
30
|
+
ParameterList: Runtime.ITuple<unknown[]>;
|
|
30
31
|
Function: Runtime.ITuple<t.TFunction<t.TSchema[], t.TSchema>>;
|
|
31
|
-
Parameters: Runtime.IUnion<unknown[]>;
|
|
32
32
|
Constructor: Runtime.ITuple<t.TConstructor<t.TSchema[], t.TSchema>>;
|
|
33
33
|
Mapped: Runtime.ITuple<t.TLiteral<"Mapped types not supported">>;
|
|
34
34
|
AsyncIterator: Runtime.ITuple<t.TAsyncIterator<t.TSchema>>;
|
|
@@ -54,6 +54,7 @@ export declare const Module: Runtime.Module<{
|
|
|
54
54
|
Uncapitalize: Runtime.ITuple<t.TSchema>;
|
|
55
55
|
Date: Runtime.IConst<t.TDate>;
|
|
56
56
|
Uint8Array: Runtime.IConst<t.TUint8Array>;
|
|
57
|
+
GenericReferenceParameters: Runtime.ITuple<unknown[]>;
|
|
57
58
|
GenericReference: Runtime.ITuple<t.TSchema>;
|
|
58
59
|
Reference: Runtime.IIdent<t.TSchema>;
|
|
59
60
|
}>;
|