@sinclair/typebox 0.34.29 → 0.34.31
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 +66 -76
- package/build/cjs/type/record/record.d.ts +2 -2
- package/build/esm/syntax/runtime.d.mts +6 -5
- package/build/esm/syntax/runtime.mjs +145 -148
- package/build/esm/syntax/static.d.mts +66 -76
- package/build/esm/type/record/record.d.mts +2 -2
- package/package.json +1 -1
- package/readme.md +1 -0
|
@@ -39,18 +39,20 @@ type GenericArgumentsContext<Args extends string[], Context extends t.TPropertie
|
|
|
39
39
|
interface GenericArgumentsMapping extends Static.IMapping {
|
|
40
40
|
output: this['input'] extends [LAngle, infer Args extends string[], RAngle] ? this['context'] extends infer Context extends t.TProperties ? GenericArgumentsContext<Args, Context> : never : never;
|
|
41
41
|
}
|
|
42
|
+
type GenericArgumentsList = Delimit<Static.Ident, Static.Const<Comma>>;
|
|
42
43
|
type GenericArguments = Static.Tuple<[
|
|
43
44
|
Static.Const<LAngle>,
|
|
44
|
-
|
|
45
|
+
GenericArgumentsList,
|
|
45
46
|
Static.Const<RAngle>
|
|
46
47
|
], GenericArgumentsMapping>;
|
|
47
48
|
interface GenericReferenceMapping extends Static.IMapping {
|
|
48
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;
|
|
49
50
|
}
|
|
51
|
+
type GenericReferenceParameters = Delimit<Type, Static.Const<Comma>>;
|
|
50
52
|
type GenericReference = Static.Tuple<[
|
|
51
53
|
Static.Ident,
|
|
52
54
|
Static.Const<LAngle>,
|
|
53
|
-
|
|
55
|
+
GenericReferenceParameters,
|
|
54
56
|
Static.Const<RAngle>
|
|
55
57
|
], GenericReferenceMapping>;
|
|
56
58
|
interface ReferenceMapping extends Static.IMapping {
|
|
@@ -58,13 +60,13 @@ interface ReferenceMapping extends Static.IMapping {
|
|
|
58
60
|
}
|
|
59
61
|
type Reference = Static.Ident<ReferenceMapping>;
|
|
60
62
|
interface LiteralBooleanMapping extends Static.IMapping {
|
|
61
|
-
output: this['input'] extends `${infer
|
|
63
|
+
output: this['input'] extends `${infer Value extends boolean}` ? t.TLiteral<Value> : never;
|
|
62
64
|
}
|
|
63
65
|
interface LiteralNumberMapping extends Static.IMapping {
|
|
64
|
-
output: this['input'] extends `${infer
|
|
66
|
+
output: this['input'] extends `${infer Value extends number}` ? t.TLiteral<Value> : never;
|
|
65
67
|
}
|
|
66
68
|
interface LiteralStringMapping extends Static.IMapping {
|
|
67
|
-
output: this['input'] extends `${infer
|
|
69
|
+
output: this['input'] extends `${infer Value extends string}` ? t.TLiteral<Value> : never;
|
|
68
70
|
}
|
|
69
71
|
type Literal = Static.Union<[
|
|
70
72
|
Static.Union<[Static.Const<'true'>, Static.Const<'false'>], LiteralBooleanMapping>,
|
|
@@ -72,17 +74,17 @@ type Literal = Static.Union<[
|
|
|
72
74
|
Static.String<[DoubleQuote, SingleQuote, Tilde], LiteralStringMapping>
|
|
73
75
|
]>;
|
|
74
76
|
type Keyword = Static.Union<[
|
|
75
|
-
Static.Const<'
|
|
76
|
-
Static.Const<'
|
|
77
|
+
Static.Const<'string', Static.As<t.TString>>,
|
|
78
|
+
Static.Const<'number', Static.As<t.TNumber>>,
|
|
77
79
|
Static.Const<'boolean', Static.As<t.TBoolean>>,
|
|
80
|
+
Static.Const<'undefined', Static.As<t.TUndefined>>,
|
|
81
|
+
Static.Const<'null', Static.As<t.TNull>>,
|
|
78
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>>,
|
|
79
86
|
Static.Const<'never', Static.As<t.TNever>>,
|
|
80
|
-
Static.Const<'null', Static.As<t.TNull>>,
|
|
81
|
-
Static.Const<'number', Static.As<t.TNumber>>,
|
|
82
|
-
Static.Const<'string', Static.As<t.TString>>,
|
|
83
87
|
Static.Const<'symbol', Static.As<t.TSymbol>>,
|
|
84
|
-
Static.Const<'undefined', Static.As<t.TUndefined>>,
|
|
85
|
-
Static.Const<'unknown', Static.As<t.TUnknown>>,
|
|
86
88
|
Static.Const<'void', Static.As<t.TVoid>>
|
|
87
89
|
]>;
|
|
88
90
|
interface KeyOfMapping extends Static.IMapping {
|
|
@@ -92,15 +94,14 @@ type KeyOf = Static.Union<[
|
|
|
92
94
|
Static.Tuple<[Static.Const<'keyof'>]>,
|
|
93
95
|
Static.Tuple<[]>
|
|
94
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);
|
|
95
98
|
interface IndexArrayMapping extends Static.IMapping {
|
|
96
|
-
output:
|
|
97
|
-
]);
|
|
99
|
+
output: this['input'] extends unknown[] ? IndexArrayReduce<this['input']> : [];
|
|
98
100
|
}
|
|
99
|
-
type IndexArray = Static.Union<[
|
|
100
|
-
Static.Tuple<[Static.Const<LBracket>, Type, Static.Const<RBracket
|
|
101
|
-
Static.Tuple<[Static.Const<LBracket>, Static.Const<RBracket
|
|
102
|
-
|
|
103
|
-
], 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>;
|
|
104
105
|
interface ExtendsMapping extends Static.IMapping {
|
|
105
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] : [];
|
|
106
107
|
}
|
|
@@ -109,50 +110,42 @@ type Extends = Static.Union<[
|
|
|
109
110
|
Static.Tuple<[]>
|
|
110
111
|
], ExtendsMapping>;
|
|
111
112
|
interface BaseMapping extends Static.IMapping {
|
|
112
|
-
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);
|
|
113
114
|
}
|
|
114
115
|
type Base = Static.Union<[
|
|
115
|
-
Static.Tuple<[
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Capitalize,
|
|
149
|
-
Uncapitalize,
|
|
150
|
-
Date,
|
|
151
|
-
Uint8Array,
|
|
152
|
-
GenericReference,
|
|
153
|
-
Reference
|
|
154
|
-
]>
|
|
155
|
-
]>
|
|
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
|
|
156
149
|
], BaseMapping>;
|
|
157
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);
|
|
158
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);
|
|
@@ -224,26 +217,23 @@ type PropertyDelimiter = Static.Union<[
|
|
|
224
217
|
Static.Tuple<[Static.Const<SemiColon>]>,
|
|
225
218
|
Static.Tuple<[Static.Const<Newline>]>
|
|
226
219
|
]>;
|
|
227
|
-
type
|
|
228
|
-
|
|
229
|
-
output: this['input'] extends t.TProperties[] ? PropertiesReduce<this['input']> : never;
|
|
230
|
-
}
|
|
231
|
-
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>);
|
|
232
222
|
interface ObjectMapping extends Static.IMapping {
|
|
233
|
-
output: this['input'] extends [
|
|
223
|
+
output: this['input'] extends [LBrace, infer PropertyList extends t.TProperties[], RBrace] ? t.TObject<ObjectReduce<PropertyList>> : never;
|
|
234
224
|
}
|
|
235
225
|
type Object = Static.Tuple<[
|
|
236
226
|
Static.Const<LBrace>,
|
|
237
|
-
|
|
227
|
+
PropertyList,
|
|
238
228
|
Static.Const<RBrace>
|
|
239
229
|
], ObjectMapping>;
|
|
240
|
-
type
|
|
230
|
+
type ElementList = Delimit<Type, Static.Const<Comma>>;
|
|
241
231
|
interface TupleMapping extends Static.IMapping {
|
|
242
|
-
output: this['input'] extends [unknown, infer
|
|
232
|
+
output: this['input'] extends [unknown, infer ElementList extends t.TSchema[], unknown] ? t.TTuple<ElementList> : never;
|
|
243
233
|
}
|
|
244
234
|
type Tuple = Static.Tuple<[
|
|
245
235
|
Static.Const<LBracket>,
|
|
246
|
-
|
|
236
|
+
ElementList,
|
|
247
237
|
Static.Const<RBracket>
|
|
248
238
|
], TupleMapping>;
|
|
249
239
|
interface ParameterMapping extends Static.IMapping {
|
|
@@ -254,24 +244,24 @@ type Parameter = Static.Tuple<[
|
|
|
254
244
|
Static.Const<Colon>,
|
|
255
245
|
Type
|
|
256
246
|
], ParameterMapping>;
|
|
257
|
-
type
|
|
247
|
+
type ParameterList = Delimit<Parameter, Static.Const<Comma>>;
|
|
258
248
|
interface FunctionMapping extends Static.IMapping {
|
|
259
|
-
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;
|
|
260
250
|
}
|
|
261
251
|
type Function = Static.Tuple<[
|
|
262
252
|
Static.Const<LParen>,
|
|
263
|
-
|
|
253
|
+
ParameterList,
|
|
264
254
|
Static.Const<RParen>,
|
|
265
255
|
Static.Const<'=>'>,
|
|
266
256
|
Type
|
|
267
257
|
], FunctionMapping>;
|
|
268
258
|
interface ConstructorMapping extends Static.IMapping {
|
|
269
|
-
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;
|
|
270
260
|
}
|
|
271
261
|
type Constructor = Static.Tuple<[
|
|
272
262
|
Static.Const<'new'>,
|
|
273
263
|
Static.Const<LParen>,
|
|
274
|
-
|
|
264
|
+
ParameterList,
|
|
275
265
|
Static.Const<RParen>,
|
|
276
266
|
Static.Const<'=>'>,
|
|
277
267
|
Type
|
|
@@ -28,8 +28,8 @@ type TFromUnionKeyLiteralString<Key extends TLiteral<string>, Type extends TSche
|
|
|
28
28
|
type TFromUnionKeyLiteralNumber<Key extends TLiteral<number>, Type extends TSchema> = {
|
|
29
29
|
[_ in Key['const']]: Type;
|
|
30
30
|
};
|
|
31
|
-
type
|
|
32
|
-
type TFromUnionKey<Key extends TSchema[], Type extends TSchema,
|
|
31
|
+
type TFromUnionKeyVariants<Keys extends TSchema[], Type extends TSchema, Result extends TProperties = {}> = Keys extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TUnion<infer Types extends TSchema[]> ? TFromUnionKeyVariants<Right, Type, Result & TFromUnionKeyVariants<Types, Type>> : Left extends TLiteral<string> ? TFromUnionKeyVariants<Right, Type, Result & TFromUnionKeyLiteralString<Left, Type>> : Left extends TLiteral<number> ? TFromUnionKeyVariants<Right, Type, Result & TFromUnionKeyLiteralNumber<Left, Type>> : {}) : Result;
|
|
32
|
+
type TFromUnionKey<Key extends TSchema[], Type extends TSchema, Properties extends TProperties = TFromUnionKeyVariants<Key, Type>> = (Ensure<TObject<Evaluate<Properties>>>);
|
|
33
33
|
type TFromLiteralKey<Key extends TLiteralValue, Type extends TSchema> = (Ensure<TObject<{
|
|
34
34
|
[_ in Assert<Key, PropertyKey>]: Type;
|
|
35
35
|
}>>);
|
|
@@ -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
|
}>;
|