@sinclair/typebox 0.34.31 → 0.34.32
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/mapping.d.ts +167 -0
- package/build/cjs/syntax/mapping.js +458 -0
- package/build/cjs/syntax/parser.d.ts +162 -0
- package/build/cjs/syntax/parser.js +158 -0
- package/build/cjs/syntax/syntax.d.ts +12 -29
- package/build/cjs/syntax/syntax.js +5 -19
- package/build/esm/syntax/mapping.d.mts +167 -0
- package/build/esm/syntax/mapping.mjs +386 -0
- package/build/esm/syntax/parser.d.mts +162 -0
- package/build/esm/syntax/parser.mjs +78 -0
- package/build/esm/syntax/syntax.d.mts +12 -29
- package/build/esm/syntax/syntax.mjs +5 -17
- package/package.json +1 -1
- package/build/cjs/syntax/runtime.d.ts +0 -60
- package/build/cjs/syntax/runtime.js +0 -715
- package/build/cjs/syntax/static.d.ts +0 -484
- package/build/cjs/syntax/static.js +0 -3
- package/build/esm/syntax/runtime.d.mts +0 -60
- package/build/esm/syntax/runtime.mjs +0 -711
- package/build/esm/syntax/static.d.mts +0 -484
- package/build/esm/syntax/static.mjs +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as T from '@sinclair/typebox.mjs';
|
|
2
|
+
type TDereference<Context extends T.TProperties, Key extends string> = (Key extends keyof Context ? Context[Key] : T.TRef<Key>);
|
|
3
|
+
type TDelimitedDecode<Input extends ([unknown, unknown] | unknown)[], Result extends unknown[] = []> = (Input extends [infer Left, ...infer Right] ? Left extends [infer Item, infer _] ? TDelimitedDecode<Right, [...Result, Item]> : TDelimitedDecode<Right, [...Result, Left]> : Result);
|
|
4
|
+
type TDelimited<Input extends [unknown, unknown]> = Input extends [infer Left extends unknown[], infer Right extends unknown[]] ? TDelimitedDecode<[...Left, ...Right]> : [];
|
|
5
|
+
export type TGenericReferenceParameterListMapping<Input extends [unknown, unknown], Context extends T.TProperties> = TDelimited<Input>;
|
|
6
|
+
export declare function GenericReferenceParameterListMapping(input: [unknown, unknown], context: unknown): unknown[];
|
|
7
|
+
export type TGenericReferenceMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties, Result = Context extends T.TProperties ? Input extends [infer Reference extends string, '<', infer Args extends T.TSchema[], '>'] ? T.TInstantiate<TDereference<Context, Reference>, Args> : never : never> = Result;
|
|
8
|
+
export declare function GenericReferenceMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
9
|
+
export type TGenericArgumentsListMapping<Input extends [unknown, unknown], Context extends T.TProperties> = TDelimited<Input>;
|
|
10
|
+
export declare function GenericArgumentsListMapping(input: [unknown, unknown], context: unknown): unknown[];
|
|
11
|
+
type GenericArgumentsContext<Arguments extends string[], Context extends T.TProperties, Result extends T.TProperties = {}> = (Arguments extends [...infer Left extends string[], infer Right extends string] ? GenericArgumentsContext<Left, Context, Result & {
|
|
12
|
+
[_ in Right]: T.TArgument<Left['length']>;
|
|
13
|
+
}> : T.Evaluate<Result & Context>);
|
|
14
|
+
export type TGenericArgumentsMapping<Input extends [unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['<', infer Arguments extends string[], '>'] ? Context extends infer Context extends T.TProperties ? GenericArgumentsContext<Arguments, Context> : never : never;
|
|
15
|
+
declare const GenericArgumentsContext: (_arguments: string[], context: T.TProperties) => T.TProperties;
|
|
16
|
+
export declare function GenericArgumentsMapping(input: [unknown, unknown, unknown], context: unknown): T.TProperties;
|
|
17
|
+
export type TKeywordStringMapping<Input extends 'string', Context extends T.TProperties> = T.TString;
|
|
18
|
+
export declare function KeywordStringMapping(input: 'string', context: unknown): T.TString;
|
|
19
|
+
export type TKeywordNumberMapping<Input extends 'number', Context extends T.TProperties> = T.TNumber;
|
|
20
|
+
export declare function KeywordNumberMapping(input: 'number', context: unknown): T.TNumber;
|
|
21
|
+
export type TKeywordBooleanMapping<Input extends 'boolean', Context extends T.TProperties> = T.TBoolean;
|
|
22
|
+
export declare function KeywordBooleanMapping(input: 'boolean', context: unknown): T.TBoolean;
|
|
23
|
+
export type TKeywordUndefinedMapping<Input extends 'undefined', Context extends T.TProperties> = T.TUndefined;
|
|
24
|
+
export declare function KeywordUndefinedMapping(input: 'undefined', context: unknown): T.TUndefined;
|
|
25
|
+
export type TKeywordNullMapping<Input extends 'null', Context extends T.TProperties> = T.TNull;
|
|
26
|
+
export declare function KeywordNullMapping(input: 'null', context: unknown): T.TNull;
|
|
27
|
+
export type TKeywordIntegerMapping<Input extends 'integer', Context extends T.TProperties> = T.TInteger;
|
|
28
|
+
export declare function KeywordIntegerMapping(input: 'integer', context: unknown): T.TInteger;
|
|
29
|
+
export type TKeywordBigIntMapping<Input extends 'bigint', Context extends T.TProperties> = T.TBigInt;
|
|
30
|
+
export declare function KeywordBigIntMapping(input: 'bigint', context: unknown): T.TBigInt;
|
|
31
|
+
export type TKeywordUnknownMapping<Input extends 'unknown', Context extends T.TProperties> = T.TUnknown;
|
|
32
|
+
export declare function KeywordUnknownMapping(input: 'unknown', context: unknown): T.TUnknown;
|
|
33
|
+
export type TKeywordAnyMapping<Input extends 'any', Context extends T.TProperties> = T.TAny;
|
|
34
|
+
export declare function KeywordAnyMapping(input: 'any', context: unknown): T.TAny;
|
|
35
|
+
export type TKeywordNeverMapping<Input extends 'never', Context extends T.TProperties> = T.TNever;
|
|
36
|
+
export declare function KeywordNeverMapping(input: 'never', context: unknown): T.TNever;
|
|
37
|
+
export type TKeywordSymbolMapping<Input extends 'symbol', Context extends T.TProperties> = T.TSymbol;
|
|
38
|
+
export declare function KeywordSymbolMapping(input: 'symbol', context: unknown): T.TSymbol;
|
|
39
|
+
export type TKeywordVoidMapping<Input extends 'void', Context extends T.TProperties> = T.TVoid;
|
|
40
|
+
export declare function KeywordVoidMapping(input: 'void', context: unknown): T.TVoid;
|
|
41
|
+
export type TKeywordMapping<Input extends unknown, Context extends T.TProperties> = Input;
|
|
42
|
+
export declare function KeywordMapping(input: unknown, context: unknown): unknown;
|
|
43
|
+
export type TLiteralStringMapping<Input extends string, Context extends T.TProperties> = Input extends T.TLiteralValue ? T.TLiteral<Input> : never;
|
|
44
|
+
export declare function LiteralStringMapping(input: string, context: unknown): T.TLiteral<string>;
|
|
45
|
+
export type TLiteralNumberMapping<Input extends string, Context extends T.TProperties> = Input extends `${infer Value extends number}` ? T.TLiteral<Value> : never;
|
|
46
|
+
export declare function LiteralNumberMapping(input: string, context: unknown): T.TLiteral<number>;
|
|
47
|
+
export type TLiteralBooleanMapping<Input extends 'true' | 'false', Context extends T.TProperties> = Input extends 'true' ? T.TLiteral<true> : T.TLiteral<false>;
|
|
48
|
+
export declare function LiteralBooleanMapping(input: 'true' | 'false', context: unknown): T.TLiteral<boolean>;
|
|
49
|
+
export type TLiteralMapping<Input extends unknown, Context extends T.TProperties> = Input;
|
|
50
|
+
export declare function LiteralMapping(input: unknown, context: unknown): unknown;
|
|
51
|
+
export type TKeyOfMapping<Input extends [unknown] | [], Context extends T.TProperties> = Input extends [unknown] ? true : false;
|
|
52
|
+
export declare function KeyOfMapping(input: [unknown] | [], context: unknown): boolean;
|
|
53
|
+
type TIndexArrayMappingReduce<Input extends unknown[], Result extends unknown[] = []> = (Input extends [infer Left extends unknown, ...infer Right extends unknown[]] ? Left extends ['[', infer Type extends T.TSchema, ']'] ? TIndexArrayMappingReduce<Right, [...Result, [Type]]> : TIndexArrayMappingReduce<Right, [...Result, []]> : Result);
|
|
54
|
+
export type TIndexArrayMapping<Input extends ([unknown, unknown, unknown] | [unknown, unknown])[], Context extends T.TProperties> = Input extends unknown[] ? TIndexArrayMappingReduce<Input> : [];
|
|
55
|
+
export declare function IndexArrayMapping(input: ([unknown, unknown, unknown] | [unknown, unknown])[], context: unknown): unknown[];
|
|
56
|
+
export type TExtendsMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown] | [], Context extends T.TProperties> = Input extends ['extends', infer Type extends T.TSchema, '?', infer True extends T.TSchema, ':', infer False extends T.TSchema] ? [Type, True, False] : [];
|
|
57
|
+
export declare function ExtendsMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown] | [], context: unknown): unknown[];
|
|
58
|
+
export type TBaseMapping<Input extends [unknown, unknown, unknown] | unknown, Context extends T.TProperties> = (Input extends ['(', infer Type extends T.TSchema, ')'] ? Type : Input extends infer Type extends T.TSchema ? Type : never);
|
|
59
|
+
export declare function BaseMapping(input: [unknown, unknown, unknown] | unknown, context: unknown): unknown;
|
|
60
|
+
type TFactorIndexArray<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<TFactorIndexArray<Type, Left>, T.TIndexPropertyKeys<Indexer>> : Right extends [] ? T.TArray<TFactorIndexArray<Type, Left>> : T.TNever) : Type);
|
|
61
|
+
type TFactorExtends<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);
|
|
62
|
+
export type TFactorMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends [infer KeyOf extends boolean, infer Type extends T.TSchema, infer IndexArray extends unknown[], infer Extends extends unknown[]] ? KeyOf extends true ? TFactorExtends<T.TKeyOf<TFactorIndexArray<Type, IndexArray>>, Extends> : TFactorExtends<TFactorIndexArray<Type, IndexArray>, Extends> : never;
|
|
63
|
+
export declare function FactorMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
64
|
+
type TExprBinaryMapping<Left extends T.TSchema, Rest extends unknown[]> = (Rest extends [infer Operator extends unknown, infer Right extends T.TSchema, infer Next extends unknown[]] ? (TExprBinaryMapping<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);
|
|
65
|
+
export type TExprTermTailMapping<Input extends [unknown, unknown, unknown] | [], Context extends T.TProperties> = Input;
|
|
66
|
+
export declare function ExprTermTailMapping(input: [unknown, unknown, unknown] | [], context: unknown): [] | [unknown, unknown, unknown];
|
|
67
|
+
export type TExprTermMapping<Input extends [unknown, unknown], Context extends T.TProperties> = (Input extends [infer Left extends T.TSchema, infer Rest extends unknown[]] ? TExprBinaryMapping<Left, Rest> : []);
|
|
68
|
+
export declare function ExprTermMapping(input: [unknown, unknown], context: unknown): T.TSchema;
|
|
69
|
+
export type TExprTailMapping<Input extends [unknown, unknown, unknown] | [], Context extends T.TProperties> = Input;
|
|
70
|
+
export declare function ExprTailMapping(input: [unknown, unknown, unknown] | [], context: unknown): [] | [unknown, unknown, unknown];
|
|
71
|
+
export type TExprMapping<Input extends [unknown, unknown], Context extends T.TProperties> = Input extends [infer Left extends T.TSchema, infer Rest extends unknown[]] ? TExprBinaryMapping<Left, Rest> : [];
|
|
72
|
+
export declare function ExprMapping(input: [unknown, unknown], context: unknown): T.TSchema;
|
|
73
|
+
export type TTypeMapping<Input extends unknown, Context extends T.TProperties> = Input;
|
|
74
|
+
export declare function TypeMapping(input: unknown, context: unknown): unknown;
|
|
75
|
+
export type TPropertyKeyMapping<Input extends string, Context extends T.TProperties> = Input;
|
|
76
|
+
export declare function PropertyKeyMapping(input: string, context: unknown): string;
|
|
77
|
+
export type TReadonlyMapping<Input extends [unknown] | [], Context extends T.TProperties> = Input extends [unknown] ? true : false;
|
|
78
|
+
export declare function ReadonlyMapping(input: [unknown] | [], context: unknown): boolean;
|
|
79
|
+
export type TOptionalMapping<Input extends [unknown] | [], Context extends T.TProperties> = Input extends [unknown] ? true : false;
|
|
80
|
+
export declare function OptionalMapping(input: [unknown] | [], context: unknown): boolean;
|
|
81
|
+
export type TPropertyMapping<Input extends [unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends [infer IsReadonly extends boolean, infer Key extends string, infer IsOptional extends boolean, string, infer Type extends T.TSchema] ? {
|
|
82
|
+
[_ in Key]: ([
|
|
83
|
+
IsReadonly,
|
|
84
|
+
IsOptional
|
|
85
|
+
] extends [true, true] ? T.TReadonlyOptional<Type> : [
|
|
86
|
+
IsReadonly,
|
|
87
|
+
IsOptional
|
|
88
|
+
] extends [true, false] ? T.TReadonly<Type> : [
|
|
89
|
+
IsReadonly,
|
|
90
|
+
IsOptional
|
|
91
|
+
] extends [false, true] ? T.TOptional<Type> : Type);
|
|
92
|
+
} : never;
|
|
93
|
+
export declare function PropertyMapping(input: [unknown, unknown, unknown, unknown, unknown], context: unknown): {
|
|
94
|
+
[x: string]: T.TSchema;
|
|
95
|
+
};
|
|
96
|
+
export type TPropertyDelimiterMapping<Input extends [unknown, unknown] | [unknown], Context extends T.TProperties> = Input;
|
|
97
|
+
export declare function PropertyDelimiterMapping(input: [unknown, unknown] | [unknown], context: unknown): [unknown] | [unknown, unknown];
|
|
98
|
+
export type TPropertyListMapping<Input extends [unknown, unknown], Context extends T.TProperties> = TDelimited<Input>;
|
|
99
|
+
export declare function PropertyListMapping(input: [unknown, unknown], context: unknown): unknown[];
|
|
100
|
+
type TObjectMappingReduce<PropertiesList extends T.TProperties[], Result extends T.TProperties = {}> = (PropertiesList extends [infer Left extends T.TProperties, ...infer Right extends T.TProperties[]] ? TObjectMappingReduce<Right, Result & Left> : {
|
|
101
|
+
[Key in keyof Result]: Result[Key];
|
|
102
|
+
});
|
|
103
|
+
export type TObjectMapping<Input extends [unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['{', infer PropertyList extends T.TProperties[], '}'] ? T.TObject<TObjectMappingReduce<PropertyList>> : never;
|
|
104
|
+
export declare function ObjectMapping(input: [unknown, unknown, unknown], context: unknown): T.TObject<T.TProperties>;
|
|
105
|
+
export type TElementListMapping<Input extends [unknown, unknown], Context extends T.TProperties> = TDelimited<Input>;
|
|
106
|
+
export declare function ElementListMapping(input: [unknown, unknown], context: unknown): unknown[];
|
|
107
|
+
export type TTupleMapping<Input extends [unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['[', infer Types extends T.TSchema[], ']'] ? T.TTuple<Types> : never;
|
|
108
|
+
export declare function TupleMapping(input: [unknown, unknown, unknown], context: unknown): T.TTuple<T.TSchema[]>;
|
|
109
|
+
export type TParameterMapping<Input extends [unknown, unknown, unknown], Context extends T.TProperties> = Input extends [string, ':', infer Type extends T.TSchema] ? Type : never;
|
|
110
|
+
export declare function ParameterMapping(input: [unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
111
|
+
export type TParameterListMapping<Input extends [unknown, unknown], Context extends T.TProperties> = TDelimited<Input>;
|
|
112
|
+
export declare function ParameterListMapping(input: [unknown, unknown], context: unknown): unknown[];
|
|
113
|
+
export type TFunctionMapping<Input extends [unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['(', infer ParameterList extends T.TSchema[], ')', '=>', infer ReturnType extends T.TSchema] ? T.TFunction<ParameterList, ReturnType> : never;
|
|
114
|
+
export declare function FunctionMapping(input: [unknown, unknown, unknown, unknown, unknown], context: unknown): T.TFunction<T.TSchema[], T.TSchema>;
|
|
115
|
+
export type TConstructorMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['new', '(', infer ParameterList extends T.TSchema[], ')', '=>', infer InstanceType extends T.TSchema] ? T.TConstructor<ParameterList, InstanceType> : never;
|
|
116
|
+
export declare function ConstructorMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TConstructor<T.TSchema[], T.TSchema>;
|
|
117
|
+
export type TMappedMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['{', '[', infer _Key extends string, 'in', infer _Right extends T.TSchema, ']', ':', infer _Type extends T.TSchema, '}'] ? T.TLiteral<'Mapped types not supported'> : never;
|
|
118
|
+
export declare function MappedMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TLiteral<"Mapped types not supported">;
|
|
119
|
+
export type TAsyncIteratorMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['AsyncIterator', '<', infer Type extends T.TSchema, '>'] ? T.TAsyncIterator<Type> : never;
|
|
120
|
+
export declare function AsyncIteratorMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TAsyncIterator<T.TSchema>;
|
|
121
|
+
export type TIteratorMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Iterator', '<', infer Type extends T.TSchema, '>'] ? T.TIterator<Type> : never;
|
|
122
|
+
export declare function IteratorMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TIterator<T.TSchema>;
|
|
123
|
+
export type TArgumentMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Argument', '<', infer Type extends T.TSchema, '>'] ? Type extends T.TLiteral<infer Index extends number> ? T.TArgument<Index> : T.TNever : never;
|
|
124
|
+
export declare function ArgumentMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TNever | T.TArgument<number>;
|
|
125
|
+
export type TAwaitedMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Awaited', '<', infer Type extends T.TSchema, '>'] ? T.TAwaited<Type> : never;
|
|
126
|
+
export declare function AwaitedMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
127
|
+
export type TArrayMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Array', '<', infer Type extends T.TSchema, '>'] ? T.TArray<Type> : never;
|
|
128
|
+
export declare function ArrayMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TArray<T.TSchema>;
|
|
129
|
+
export type TRecordMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Record', '<', infer Key extends T.TSchema, ',', infer Type extends T.TSchema, '>'] ? T.TRecordOrObject<Key, Type> : never;
|
|
130
|
+
export declare function RecordMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
131
|
+
export type TPromiseMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Promise', '<', infer Type extends T.TSchema, '>'] ? T.TPromise<Type> : never;
|
|
132
|
+
export declare function PromiseMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TPromise<T.TSchema>;
|
|
133
|
+
export type TConstructorParametersMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['ConstructorParameters', '<', infer Type extends T.TSchema, '>'] ? T.TConstructorParameters<Type> : never;
|
|
134
|
+
export declare function ConstructorParametersMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
135
|
+
export type TFunctionParametersMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Parameters', '<', infer Type extends T.TSchema, '>'] ? T.TParameters<Type> : never;
|
|
136
|
+
export declare function FunctionParametersMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
137
|
+
export type TInstanceTypeMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['InstanceType', '<', infer Type extends T.TSchema, '>'] ? T.TInstanceType<Type> : never;
|
|
138
|
+
export declare function InstanceTypeMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
139
|
+
export type TReturnTypeMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['ReturnType', '<', infer Type extends T.TSchema, '>'] ? T.TReturnType<Type> : never;
|
|
140
|
+
export declare function ReturnTypeMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
141
|
+
export type TPartialMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Partial', '<', infer Type extends T.TSchema, '>'] ? T.TPartial<Type> : never;
|
|
142
|
+
export declare function PartialMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TObject<{}>;
|
|
143
|
+
export type TRequiredMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Required', '<', infer Type extends T.TSchema, '>'] ? T.TRequired<Type> : never;
|
|
144
|
+
export declare function RequiredMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TObject<{}>;
|
|
145
|
+
export type TPickMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Pick', '<', infer Type extends T.TSchema, ',', infer Key extends T.TSchema, '>'] ? T.TPick<Type, Key> : never;
|
|
146
|
+
export declare function PickMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TObject<{}>;
|
|
147
|
+
export type TOmitMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Omit', '<', infer Type extends T.TSchema, ',', infer Key extends T.TSchema, '>'] ? T.TOmit<Type, Key> : never;
|
|
148
|
+
export declare function OmitMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TObject<{}>;
|
|
149
|
+
export type TExcludeMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Exclude', '<', infer Type extends T.TSchema, ',', infer Key extends T.TSchema, '>'] ? T.TExclude<Type, Key> : never;
|
|
150
|
+
export declare function ExcludeMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TNever;
|
|
151
|
+
export type TExtractMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Extract', '<', infer Type extends T.TSchema, ',', infer Key extends T.TSchema, '>'] ? T.TExtract<Type, Key> : never;
|
|
152
|
+
export declare function ExtractMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
153
|
+
export type TUppercaseMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Uppercase', '<', infer Type extends T.TSchema, '>'] ? T.TUppercase<Type> : never;
|
|
154
|
+
export declare function UppercaseMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
155
|
+
export type TLowercaseMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Lowercase', '<', infer Type extends T.TSchema, '>'] ? T.TLowercase<Type> : never;
|
|
156
|
+
export declare function LowercaseMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
157
|
+
export type TCapitalizeMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Capitalize', '<', infer Type extends T.TSchema, '>'] ? T.TCapitalize<Type> : never;
|
|
158
|
+
export declare function CapitalizeMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
159
|
+
export type TUncapitalizeMapping<Input extends [unknown, unknown, unknown, unknown], Context extends T.TProperties> = Input extends ['Uncapitalize', '<', infer Type extends T.TSchema, '>'] ? T.TUncapitalize<Type> : never;
|
|
160
|
+
export declare function UncapitalizeMapping(input: [unknown, unknown, unknown, unknown], context: unknown): T.TSchema;
|
|
161
|
+
export type TDateMapping<Input extends 'Date', Context extends T.TProperties> = T.TDate;
|
|
162
|
+
export declare function DateMapping(input: 'Date', context: unknown): T.TDate;
|
|
163
|
+
export type TUint8ArrayMapping<Input extends 'Uint8Array', Context extends T.TProperties> = T.TUint8Array;
|
|
164
|
+
export declare function Uint8ArrayMapping(input: 'Uint8Array', context: unknown): T.TUint8Array;
|
|
165
|
+
export type TReferenceMapping<Input extends string, Context extends T.TProperties> = Context extends T.TProperties ? Input extends string ? TDereference<Context, Input> : never : never;
|
|
166
|
+
export declare function ReferenceMapping(input: string, context: unknown): T.TSchema;
|
|
167
|
+
export {};
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import * as T from '@sinclair/typebox.mjs';
|
|
2
|
+
// prettier-ignore
|
|
3
|
+
const Dereference = (context, key) => {
|
|
4
|
+
return key in context ? context[key] : T.Ref(key);
|
|
5
|
+
};
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
const DelimitedDecode = (input, result = []) => {
|
|
8
|
+
return input.reduce((result, left) => {
|
|
9
|
+
return T.ValueGuard.IsArray(left) && left.length === 2
|
|
10
|
+
? [...result, left[0]]
|
|
11
|
+
: [...result, left];
|
|
12
|
+
}, []);
|
|
13
|
+
};
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
const Delimited = (input) => {
|
|
16
|
+
const [left, right] = input;
|
|
17
|
+
return DelimitedDecode([...left, ...right]);
|
|
18
|
+
};
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
export function GenericReferenceParameterListMapping(input, context) {
|
|
21
|
+
return Delimited(input);
|
|
22
|
+
}
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
export function GenericReferenceMapping(input, context) {
|
|
25
|
+
const type = Dereference(context, input[0]);
|
|
26
|
+
const args = input[2];
|
|
27
|
+
return T.Instantiate(type, args);
|
|
28
|
+
}
|
|
29
|
+
// prettier-ignore
|
|
30
|
+
export function GenericArgumentsListMapping(input, context) {
|
|
31
|
+
return Delimited(input);
|
|
32
|
+
}
|
|
33
|
+
// ...
|
|
34
|
+
// prettier-ignore
|
|
35
|
+
const GenericArgumentsContext = (_arguments, context) => {
|
|
36
|
+
return _arguments.reduce((result, arg, index) => {
|
|
37
|
+
return { ...result, [arg]: T.Argument(index) };
|
|
38
|
+
}, context);
|
|
39
|
+
};
|
|
40
|
+
// prettier-ignore
|
|
41
|
+
export function GenericArgumentsMapping(input, context) {
|
|
42
|
+
return input.length === 3
|
|
43
|
+
? GenericArgumentsContext(input[1], context)
|
|
44
|
+
: {};
|
|
45
|
+
}
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
export function KeywordStringMapping(input, context) {
|
|
48
|
+
return T.String();
|
|
49
|
+
}
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
export function KeywordNumberMapping(input, context) {
|
|
52
|
+
return T.Number();
|
|
53
|
+
}
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
export function KeywordBooleanMapping(input, context) {
|
|
56
|
+
return T.Boolean();
|
|
57
|
+
}
|
|
58
|
+
// prettier-ignore
|
|
59
|
+
export function KeywordUndefinedMapping(input, context) {
|
|
60
|
+
return T.Undefined();
|
|
61
|
+
}
|
|
62
|
+
// prettier-ignore
|
|
63
|
+
export function KeywordNullMapping(input, context) {
|
|
64
|
+
return T.Null();
|
|
65
|
+
}
|
|
66
|
+
// prettier-ignore
|
|
67
|
+
export function KeywordIntegerMapping(input, context) {
|
|
68
|
+
return T.Integer();
|
|
69
|
+
}
|
|
70
|
+
// prettier-ignore
|
|
71
|
+
export function KeywordBigIntMapping(input, context) {
|
|
72
|
+
return T.BigInt();
|
|
73
|
+
}
|
|
74
|
+
// prettier-ignore
|
|
75
|
+
export function KeywordUnknownMapping(input, context) {
|
|
76
|
+
return T.Unknown();
|
|
77
|
+
}
|
|
78
|
+
// prettier-ignore
|
|
79
|
+
export function KeywordAnyMapping(input, context) {
|
|
80
|
+
return T.Any();
|
|
81
|
+
}
|
|
82
|
+
// prettier-ignore
|
|
83
|
+
export function KeywordNeverMapping(input, context) {
|
|
84
|
+
return T.Never();
|
|
85
|
+
}
|
|
86
|
+
// prettier-ignore
|
|
87
|
+
export function KeywordSymbolMapping(input, context) {
|
|
88
|
+
return T.Symbol();
|
|
89
|
+
}
|
|
90
|
+
// prettier-ignore
|
|
91
|
+
export function KeywordVoidMapping(input, context) {
|
|
92
|
+
return T.Void();
|
|
93
|
+
}
|
|
94
|
+
// prettier-ignore
|
|
95
|
+
export function KeywordMapping(input, context) {
|
|
96
|
+
return input;
|
|
97
|
+
}
|
|
98
|
+
// prettier-ignore
|
|
99
|
+
export function LiteralStringMapping(input, context) {
|
|
100
|
+
return T.Literal(input);
|
|
101
|
+
}
|
|
102
|
+
// prettier-ignore
|
|
103
|
+
export function LiteralNumberMapping(input, context) {
|
|
104
|
+
return T.Literal(parseFloat(input));
|
|
105
|
+
}
|
|
106
|
+
// prettier-ignore
|
|
107
|
+
export function LiteralBooleanMapping(input, context) {
|
|
108
|
+
return T.Literal(input === 'true');
|
|
109
|
+
}
|
|
110
|
+
// prettier-ignore
|
|
111
|
+
export function LiteralMapping(input, context) {
|
|
112
|
+
return input;
|
|
113
|
+
}
|
|
114
|
+
// prettier-ignore
|
|
115
|
+
export function KeyOfMapping(input, context) {
|
|
116
|
+
return input.length > 0;
|
|
117
|
+
}
|
|
118
|
+
// prettier-ignore
|
|
119
|
+
export function IndexArrayMapping(input, context) {
|
|
120
|
+
return input.reduce((result, current) => {
|
|
121
|
+
return current.length === 3
|
|
122
|
+
? [...result, [current[1]]]
|
|
123
|
+
: [...result, []];
|
|
124
|
+
}, []);
|
|
125
|
+
}
|
|
126
|
+
// prettier-ignore
|
|
127
|
+
export function ExtendsMapping(input, context) {
|
|
128
|
+
return input.length === 6
|
|
129
|
+
? [input[1], input[3], input[5]]
|
|
130
|
+
: [];
|
|
131
|
+
}
|
|
132
|
+
// prettier-ignore
|
|
133
|
+
export function BaseMapping(input, context) {
|
|
134
|
+
return T.ValueGuard.IsArray(input) && input.length === 3 ? input[1] : input;
|
|
135
|
+
}
|
|
136
|
+
// ...
|
|
137
|
+
// prettier-ignore
|
|
138
|
+
const FactorIndexArray = (Type, indexArray) => {
|
|
139
|
+
return indexArray.reduceRight((result, right) => {
|
|
140
|
+
const _right = right;
|
|
141
|
+
return (_right.length === 1 ? T.Index(result, _right[0]) :
|
|
142
|
+
_right.length === 0 ? T.Array(result, _right[0]) :
|
|
143
|
+
T.Never());
|
|
144
|
+
}, Type);
|
|
145
|
+
};
|
|
146
|
+
// prettier-ignore
|
|
147
|
+
const FactorExtends = (Type, Extends) => {
|
|
148
|
+
return Extends.length === 3
|
|
149
|
+
? T.Extends(Type, Extends[0], Extends[1], Extends[2])
|
|
150
|
+
: Type;
|
|
151
|
+
};
|
|
152
|
+
// prettier-ignore
|
|
153
|
+
export function FactorMapping(input, context) {
|
|
154
|
+
const [KeyOf, Type, IndexArray, Extends] = input;
|
|
155
|
+
return KeyOf
|
|
156
|
+
? FactorExtends(T.KeyOf(FactorIndexArray(Type, IndexArray)), Extends)
|
|
157
|
+
: FactorExtends(FactorIndexArray(Type, IndexArray), Extends);
|
|
158
|
+
}
|
|
159
|
+
// prettier-ignore
|
|
160
|
+
function ExprBinaryMapping(Left, Rest) {
|
|
161
|
+
return (Rest.length === 3 ? (() => {
|
|
162
|
+
const [Operator, Right, Next] = Rest;
|
|
163
|
+
const Schema = ExprBinaryMapping(Right, Next);
|
|
164
|
+
if (Operator === '&') {
|
|
165
|
+
return T.TypeGuard.IsIntersect(Schema)
|
|
166
|
+
? T.Intersect([Left, ...Schema.allOf])
|
|
167
|
+
: T.Intersect([Left, Schema]);
|
|
168
|
+
}
|
|
169
|
+
if (Operator === '|') {
|
|
170
|
+
return T.TypeGuard.IsUnion(Schema)
|
|
171
|
+
? T.Union([Left, ...Schema.anyOf])
|
|
172
|
+
: T.Union([Left, Schema]);
|
|
173
|
+
}
|
|
174
|
+
throw 1;
|
|
175
|
+
})() : Left);
|
|
176
|
+
}
|
|
177
|
+
// prettier-ignore
|
|
178
|
+
export function ExprTermTailMapping(input, context) {
|
|
179
|
+
return input;
|
|
180
|
+
}
|
|
181
|
+
// prettier-ignore
|
|
182
|
+
export function ExprTermMapping(input, context) {
|
|
183
|
+
const [left, rest] = input;
|
|
184
|
+
return ExprBinaryMapping(left, rest);
|
|
185
|
+
}
|
|
186
|
+
// prettier-ignore
|
|
187
|
+
export function ExprTailMapping(input, context) {
|
|
188
|
+
return input;
|
|
189
|
+
}
|
|
190
|
+
// prettier-ignore
|
|
191
|
+
export function ExprMapping(input, context) {
|
|
192
|
+
const [left, rest] = input;
|
|
193
|
+
return ExprBinaryMapping(left, rest);
|
|
194
|
+
}
|
|
195
|
+
// prettier-ignore
|
|
196
|
+
export function TypeMapping(input, context) {
|
|
197
|
+
return input;
|
|
198
|
+
}
|
|
199
|
+
// prettier-ignore
|
|
200
|
+
export function PropertyKeyMapping(input, context) {
|
|
201
|
+
return input;
|
|
202
|
+
}
|
|
203
|
+
// prettier-ignore
|
|
204
|
+
export function ReadonlyMapping(input, context) {
|
|
205
|
+
return input.length > 0;
|
|
206
|
+
}
|
|
207
|
+
// prettier-ignore
|
|
208
|
+
export function OptionalMapping(input, context) {
|
|
209
|
+
return input.length > 0;
|
|
210
|
+
}
|
|
211
|
+
// prettier-ignore
|
|
212
|
+
export function PropertyMapping(input, context) {
|
|
213
|
+
const [isReadonly, key, isOptional, _colon, type] = input;
|
|
214
|
+
return {
|
|
215
|
+
[key]: (isReadonly && isOptional ? T.ReadonlyOptional(type) :
|
|
216
|
+
isReadonly && !isOptional ? T.Readonly(type) :
|
|
217
|
+
!isReadonly && isOptional ? T.Optional(type) :
|
|
218
|
+
type)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// prettier-ignore
|
|
222
|
+
export function PropertyDelimiterMapping(input, context) {
|
|
223
|
+
return input;
|
|
224
|
+
}
|
|
225
|
+
// prettier-ignore
|
|
226
|
+
export function PropertyListMapping(input, context) {
|
|
227
|
+
return Delimited(input);
|
|
228
|
+
}
|
|
229
|
+
// prettier-ignore
|
|
230
|
+
export function ObjectMapping(input, context) {
|
|
231
|
+
const propertyList = input[1];
|
|
232
|
+
return T.Object(propertyList.reduce((result, property) => {
|
|
233
|
+
return { ...result, ...property };
|
|
234
|
+
}, {}));
|
|
235
|
+
}
|
|
236
|
+
// prettier-ignore
|
|
237
|
+
export function ElementListMapping(input, context) {
|
|
238
|
+
return Delimited(input);
|
|
239
|
+
}
|
|
240
|
+
// prettier-ignore
|
|
241
|
+
export function TupleMapping(input, context) {
|
|
242
|
+
return T.Tuple(input[1]);
|
|
243
|
+
}
|
|
244
|
+
// prettier-ignore
|
|
245
|
+
export function ParameterMapping(input, context) {
|
|
246
|
+
const [_ident, _colon, type] = input;
|
|
247
|
+
return type;
|
|
248
|
+
}
|
|
249
|
+
// prettier-ignore
|
|
250
|
+
export function ParameterListMapping(input, context) {
|
|
251
|
+
return Delimited(input);
|
|
252
|
+
}
|
|
253
|
+
// prettier-ignore
|
|
254
|
+
export function FunctionMapping(input, context) {
|
|
255
|
+
const [_lparan, parameterList, _rparan, _arrow, returnType] = input;
|
|
256
|
+
return T.Function(parameterList, returnType);
|
|
257
|
+
}
|
|
258
|
+
// prettier-ignore
|
|
259
|
+
export function ConstructorMapping(input, context) {
|
|
260
|
+
const [_new, _lparan, parameterList, _rparan, _arrow, instanceType] = input;
|
|
261
|
+
return T.Constructor(parameterList, instanceType);
|
|
262
|
+
}
|
|
263
|
+
// prettier-ignore
|
|
264
|
+
export function MappedMapping(input, context) {
|
|
265
|
+
const [_lbrace, _lbracket, _key, _in, _right, _rbracket, _colon, _type] = input;
|
|
266
|
+
return T.Literal('Mapped types not supported');
|
|
267
|
+
}
|
|
268
|
+
// prettier-ignore
|
|
269
|
+
export function AsyncIteratorMapping(input, context) {
|
|
270
|
+
const [_name, _langle, type, _rangle] = input;
|
|
271
|
+
return T.AsyncIterator(type);
|
|
272
|
+
}
|
|
273
|
+
// prettier-ignore
|
|
274
|
+
export function IteratorMapping(input, context) {
|
|
275
|
+
const [_name, _langle, type, _rangle] = input;
|
|
276
|
+
return T.Iterator(type);
|
|
277
|
+
}
|
|
278
|
+
// prettier-ignore
|
|
279
|
+
export function ArgumentMapping(input, context) {
|
|
280
|
+
return T.KindGuard.IsLiteralNumber(input[2])
|
|
281
|
+
? T.Argument(Math.trunc(input[2].const))
|
|
282
|
+
: T.Never();
|
|
283
|
+
}
|
|
284
|
+
// prettier-ignore
|
|
285
|
+
export function AwaitedMapping(input, context) {
|
|
286
|
+
const [_name, _langle, type, _rangle] = input;
|
|
287
|
+
return T.Awaited(type);
|
|
288
|
+
}
|
|
289
|
+
// prettier-ignore
|
|
290
|
+
export function ArrayMapping(input, context) {
|
|
291
|
+
const [_name, _langle, type, _rangle] = input;
|
|
292
|
+
return T.Array(type);
|
|
293
|
+
}
|
|
294
|
+
// prettier-ignore
|
|
295
|
+
export function RecordMapping(input, context) {
|
|
296
|
+
const [_name, _langle, key, _comma, type, _rangle] = input;
|
|
297
|
+
return T.Record(key, type);
|
|
298
|
+
}
|
|
299
|
+
// prettier-ignore
|
|
300
|
+
export function PromiseMapping(input, context) {
|
|
301
|
+
const [_name, _langle, type, _rangle] = input;
|
|
302
|
+
return T.Promise(type);
|
|
303
|
+
}
|
|
304
|
+
// prettier-ignore
|
|
305
|
+
export function ConstructorParametersMapping(input, context) {
|
|
306
|
+
const [_name, _langle, type, _rangle] = input;
|
|
307
|
+
return T.ConstructorParameters(type);
|
|
308
|
+
}
|
|
309
|
+
// prettier-ignore
|
|
310
|
+
export function FunctionParametersMapping(input, context) {
|
|
311
|
+
const [_name, _langle, type, _rangle] = input;
|
|
312
|
+
return T.Parameters(type);
|
|
313
|
+
}
|
|
314
|
+
// prettier-ignore
|
|
315
|
+
export function InstanceTypeMapping(input, context) {
|
|
316
|
+
const [_name, _langle, type, _rangle] = input;
|
|
317
|
+
return T.InstanceType(type);
|
|
318
|
+
}
|
|
319
|
+
// prettier-ignore
|
|
320
|
+
export function ReturnTypeMapping(input, context) {
|
|
321
|
+
const [_name, _langle, type, _rangle] = input;
|
|
322
|
+
return T.ReturnType(type);
|
|
323
|
+
}
|
|
324
|
+
// prettier-ignore
|
|
325
|
+
export function PartialMapping(input, context) {
|
|
326
|
+
const [_name, _langle, type, _rangle] = input;
|
|
327
|
+
return T.Partial(type);
|
|
328
|
+
}
|
|
329
|
+
// prettier-ignore
|
|
330
|
+
export function RequiredMapping(input, context) {
|
|
331
|
+
const [_name, _langle, type, _rangle] = input;
|
|
332
|
+
return T.Required(type);
|
|
333
|
+
}
|
|
334
|
+
// prettier-ignore
|
|
335
|
+
export function PickMapping(input, context) {
|
|
336
|
+
const [_name, _langle, key, _comma, type, _rangle] = input;
|
|
337
|
+
return T.Pick(key, type);
|
|
338
|
+
}
|
|
339
|
+
// prettier-ignore
|
|
340
|
+
export function OmitMapping(input, context) {
|
|
341
|
+
const [_name, _langle, key, _comma, type, _rangle] = input;
|
|
342
|
+
return T.Omit(key, type);
|
|
343
|
+
}
|
|
344
|
+
// prettier-ignore
|
|
345
|
+
export function ExcludeMapping(input, context) {
|
|
346
|
+
const [_name, _langle, key, _comma, type, _rangle] = input;
|
|
347
|
+
return T.Exclude(key, type);
|
|
348
|
+
}
|
|
349
|
+
// prettier-ignore
|
|
350
|
+
export function ExtractMapping(input, context) {
|
|
351
|
+
const [_name, _langle, key, _comma, type, _rangle] = input;
|
|
352
|
+
return T.Extract(key, type);
|
|
353
|
+
}
|
|
354
|
+
// prettier-ignore
|
|
355
|
+
export function UppercaseMapping(input, context) {
|
|
356
|
+
const [_name, _langle, type, _rangle] = input;
|
|
357
|
+
return T.Uppercase(type);
|
|
358
|
+
}
|
|
359
|
+
// prettier-ignore
|
|
360
|
+
export function LowercaseMapping(input, context) {
|
|
361
|
+
const [_name, _langle, type, _rangle] = input;
|
|
362
|
+
return T.Lowercase(type);
|
|
363
|
+
}
|
|
364
|
+
// prettier-ignore
|
|
365
|
+
export function CapitalizeMapping(input, context) {
|
|
366
|
+
const [_name, _langle, type, _rangle] = input;
|
|
367
|
+
return T.Capitalize(type);
|
|
368
|
+
}
|
|
369
|
+
// prettier-ignore
|
|
370
|
+
export function UncapitalizeMapping(input, context) {
|
|
371
|
+
const [_name, _langle, type, _rangle] = input;
|
|
372
|
+
return T.Uncapitalize(type);
|
|
373
|
+
}
|
|
374
|
+
// prettier-ignore
|
|
375
|
+
export function DateMapping(input, context) {
|
|
376
|
+
return T.Date();
|
|
377
|
+
}
|
|
378
|
+
// prettier-ignore
|
|
379
|
+
export function Uint8ArrayMapping(input, context) {
|
|
380
|
+
return T.Uint8Array();
|
|
381
|
+
}
|
|
382
|
+
// prettier-ignore
|
|
383
|
+
export function ReferenceMapping(input, context) {
|
|
384
|
+
const target = Dereference(context, input);
|
|
385
|
+
return target;
|
|
386
|
+
}
|