elysia-autoload 1.3.0 → 1.5.0
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/README.md +16 -10
- package/dist/index.d.ts +671 -13
- package/dist/index.js +38 -71
- package/package.json +16 -11
package/README.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# elysia-autoload
|
2
2
|
|
3
|
-
|
3
|
+
<div align="center">
|
4
4
|
|
5
|
-
|
5
|
+
[](https://www.npmjs.org/package/elysia-autoload)
|
6
|
+
[](https://www.npmjs.org/package/elysia-autoload)
|
7
|
+
|
8
|
+
<!-- [](https://jsr.io/elysia-autoload)
|
9
|
+
[](https://jsr.io/elysia-autoload) -->
|
10
|
+
|
11
|
+
</div>
|
12
|
+
|
13
|
+
Plugin for [Elysia](https://elysiajs.com/) which autoload all routes in directory and code-generate types for [Eden](https://elysiajs.com/eden/overview.html) with [`Bun.build`](#bun-build-usage) and **Node adapter** support!
|
6
14
|
|
7
15
|
## Installation
|
8
16
|
|
@@ -44,7 +52,7 @@ export type ElysiaApp = typeof app;
|
|
44
52
|
// routes/index.ts
|
45
53
|
import type { ElysiaApp } from "app";
|
46
54
|
|
47
|
-
export default (app: ElysiaApp) => app.get("
|
55
|
+
export default (app: ElysiaApp) => app.get("", { hello: "world" });
|
48
56
|
```
|
49
57
|
|
50
58
|
### Directory structure
|
@@ -124,14 +132,14 @@ export type ElysiaApp = typeof app;
|
|
124
132
|
```ts
|
125
133
|
// client.ts
|
126
134
|
|
127
|
-
import {
|
135
|
+
import { treaty } from "@elysiajs/eden";
|
128
136
|
|
129
137
|
// Routes are a global type so you don't need to import it.
|
130
138
|
|
131
|
-
const app =
|
139
|
+
const app = treaty<Routes>("http://localhost:3002");
|
132
140
|
|
133
141
|
const { data } = await app.test["some-path-param"].get({
|
134
|
-
|
142
|
+
query: {
|
135
143
|
key: 2,
|
136
144
|
},
|
137
145
|
});
|
@@ -149,15 +157,13 @@ import type Route0 from "./routes/index";
|
|
149
157
|
import type Route1 from "./routes/test/[some]/index";
|
150
158
|
|
151
159
|
declare global {
|
152
|
-
export type Routes = ElysiaWithBaseUrl<"/api",
|
153
|
-
ElysiaWithBaseUrl<"/api/test/:some",
|
160
|
+
export type Routes = ElysiaWithBaseUrl<"/api", typeof Route0> &
|
161
|
+
ElysiaWithBaseUrl<"/api/test/:some", typeof Route1>;
|
154
162
|
}
|
155
163
|
```
|
156
164
|
|
157
165
|
Example of app with types code-generation you can see in [example](https://github.com/kravetsone/elysia-autoload/tree/main/example)
|
158
166
|
|
159
|
-
**Currently, Eden types generation is broken!!**
|
160
|
-
|
161
167
|
### [Bun build](https://bun.sh/docs/bundler) usage
|
162
168
|
|
163
169
|
You can use this plugin with [`Bun.build`](https://bun.sh/docs/bundler), thanks to [esbuild-plugin-autoload](https://github.com/kravetsone/esbuild-plugin-autoload)!
|
package/dist/index.d.ts
CHANGED
@@ -1,23 +1,680 @@
|
|
1
|
-
import Elysia, { RouteBase, LocalHook, InputSchema,
|
1
|
+
import Elysia, { RouteBase, RouteSchema, AnyElysia, LocalHook, InputSchema, SingletonBase, BaseMacro, Elysia as Elysia$1 } from 'elysia';
|
2
|
+
|
3
|
+
/** Symbol key applied to readonly types */
|
4
|
+
declare const ReadonlyKind: unique symbol;
|
5
|
+
/** Symbol key applied to optional types */
|
6
|
+
declare const OptionalKind: unique symbol;
|
7
|
+
/** Symbol key applied to types */
|
8
|
+
declare const Hint: unique symbol;
|
9
|
+
/** Symbol key applied to types */
|
10
|
+
declare const Kind: unique symbol;
|
11
|
+
|
12
|
+
interface TAny extends TSchema {
|
13
|
+
[Kind]: 'Any';
|
14
|
+
static: any;
|
15
|
+
}
|
16
|
+
|
17
|
+
interface TMappedKey<T extends PropertyKey[] = PropertyKey[]> extends TSchema {
|
18
|
+
[Kind]: 'MappedKey';
|
19
|
+
static: T[number];
|
20
|
+
keys: T;
|
21
|
+
}
|
22
|
+
|
23
|
+
interface TMappedResult<T extends TProperties = TProperties> extends TSchema {
|
24
|
+
[Kind]: 'MappedResult';
|
25
|
+
properties: T;
|
26
|
+
static: unknown;
|
27
|
+
}
|
28
|
+
|
29
|
+
interface TAsyncIterator<T extends TSchema = TSchema> extends TSchema {
|
30
|
+
[Kind]: 'AsyncIterator';
|
31
|
+
static: AsyncIterableIterator<Static<T, this['params']>>;
|
32
|
+
type: 'AsyncIterator';
|
33
|
+
items: T;
|
34
|
+
}
|
35
|
+
|
36
|
+
type TReadonly<T extends TSchema> = T & {
|
37
|
+
[ReadonlyKind]: 'Readonly';
|
38
|
+
};
|
39
|
+
|
40
|
+
type TReadonlyOptional<T extends TSchema> = TOptional<T> & TReadonly<T>;
|
41
|
+
|
42
|
+
type StaticReturnType$1<U extends TSchema, P extends unknown[]> = Static<U, P>;
|
43
|
+
type StaticParameter$1<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
|
44
|
+
Static<T, P>
|
45
|
+
];
|
46
|
+
type StaticParameters$1<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters$1<R, P, [...Acc, ...StaticParameter$1<L, P>]> : Acc);
|
47
|
+
type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: StaticParameters$1<T, P>) => StaticReturnType$1<U, P>>;
|
48
|
+
interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
49
|
+
[Kind]: 'Constructor';
|
50
|
+
static: StaticConstructor<T, U, this['params']>;
|
51
|
+
type: 'Constructor';
|
52
|
+
parameters: T;
|
53
|
+
returns: U;
|
54
|
+
}
|
55
|
+
|
56
|
+
type TLiteralValue = boolean | number | string;
|
57
|
+
interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
58
|
+
[Kind]: 'Literal';
|
59
|
+
static: T;
|
60
|
+
const: T;
|
61
|
+
}
|
62
|
+
|
63
|
+
type TEnumRecord = Record<TEnumKey, TEnumValue>;
|
64
|
+
type TEnumValue = string | number;
|
65
|
+
type TEnumKey = string;
|
66
|
+
interface TEnum<T extends Record<string, string | number> = Record<string, string | number>> extends TSchema {
|
67
|
+
[Kind]: 'Union';
|
68
|
+
[Hint]: 'Enum';
|
69
|
+
static: T[keyof T];
|
70
|
+
anyOf: TLiteral<T[keyof T]>[];
|
71
|
+
}
|
72
|
+
|
73
|
+
type StaticReturnType<U extends TSchema, P extends unknown[]> = Static<U, P>;
|
74
|
+
type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadonlyOptional<T> ? [Readonly<Static<T, P>>?] : T extends TReadonly<T> ? [Readonly<Static<T, P>>] : T extends TOptional<T> ? [Static<T, P>?] : [
|
75
|
+
Static<T, P>
|
76
|
+
];
|
77
|
+
type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
|
78
|
+
type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
|
79
|
+
interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
80
|
+
[Kind]: 'Function';
|
81
|
+
static: StaticFunction<T, U, this['params']>;
|
82
|
+
type: 'Function';
|
83
|
+
parameters: T;
|
84
|
+
returns: U;
|
85
|
+
}
|
86
|
+
|
87
|
+
interface TComputed<Target extends string = string, Parameters extends TSchema[] = []> extends TSchema {
|
88
|
+
[Kind]: 'Computed';
|
89
|
+
target: Target;
|
90
|
+
parameters: Parameters;
|
91
|
+
}
|
92
|
+
|
93
|
+
interface TNever extends TSchema {
|
94
|
+
[Kind]: 'Never';
|
95
|
+
static: never;
|
96
|
+
not: {};
|
97
|
+
}
|
98
|
+
|
99
|
+
type TIntersectStatic<T extends TSchema[], P extends unknown[], Acc extends unknown = unknown> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TIntersectStatic<R, P, Acc & Static<L, P>> : Acc;
|
100
|
+
type TUnevaluatedProperties = undefined | TSchema | boolean;
|
101
|
+
interface IntersectOptions extends SchemaOptions {
|
102
|
+
unevaluatedProperties?: TUnevaluatedProperties;
|
103
|
+
}
|
104
|
+
interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
|
105
|
+
[Kind]: 'Intersect';
|
106
|
+
static: TIntersectStatic<T, this['params']>;
|
107
|
+
type?: 'object';
|
108
|
+
allOf: [...T];
|
109
|
+
}
|
110
|
+
|
111
|
+
type TIsIntersectOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? TIsIntersectOptional<Right> : false : true);
|
112
|
+
type TRemoveOptionalFromType$1<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType$1<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType$1<Type> : Type);
|
113
|
+
type TRemoveOptionalFromRest$1<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromRest$1<Right, [...Result, TRemoveOptionalFromType$1<Type>]> : TRemoveOptionalFromRest$1<Right, [...Result, Left]> : Result);
|
114
|
+
type TResolveIntersect<Types extends TSchema[]> = (TIsIntersectOptional<Types> extends true ? TOptional<TIntersect<TRemoveOptionalFromRest$1<Types>>> : TIntersect<TRemoveOptionalFromRest$1<Types>>);
|
115
|
+
type TIntersectEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveIntersect<Types>);
|
116
|
+
|
117
|
+
type UnionStatic<T extends TSchema[], P extends unknown[]> = {
|
118
|
+
[K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
|
119
|
+
}[number];
|
120
|
+
interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
|
121
|
+
[Kind]: 'Union';
|
122
|
+
static: UnionStatic<T, this['params']>;
|
123
|
+
anyOf: T;
|
124
|
+
}
|
125
|
+
|
126
|
+
type TIsUnionOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? true : TIsUnionOptional<Right> : false);
|
127
|
+
type TRemoveOptionalFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<Right, [...Result, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<Right, [...Result, Left]> : Result);
|
128
|
+
type TRemoveOptionalFromType<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType<Type> : Type);
|
129
|
+
type TResolveUnion<Types extends TSchema[], Result extends TSchema[] = TRemoveOptionalFromRest<Types>, IsOptional extends boolean = TIsUnionOptional<Types>> = (IsOptional extends true ? TOptional<TUnion<Result>> : TUnion<Result>);
|
130
|
+
type TUnionEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveUnion<Types>);
|
131
|
+
|
132
|
+
type RecursiveStatic<T extends TSchema> = Static<T, [RecursiveStatic<T>]>;
|
133
|
+
interface TRecursive<T extends TSchema> extends TSchema {
|
134
|
+
[Hint]: 'Recursive';
|
135
|
+
static: RecursiveStatic<T>;
|
136
|
+
}
|
137
|
+
|
138
|
+
interface TRef<Ref extends string = string> extends TSchema {
|
139
|
+
[Kind]: 'Ref';
|
140
|
+
static: unknown;
|
141
|
+
$ref: Ref;
|
142
|
+
}
|
143
|
+
|
144
|
+
type TupleStatic<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TupleStatic<R, P, [...Acc, Static<L, P>]> : Acc;
|
145
|
+
interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
146
|
+
[Kind]: 'Tuple';
|
147
|
+
static: TupleStatic<T, this['params']>;
|
148
|
+
type: 'array';
|
149
|
+
items?: T;
|
150
|
+
additionalItems?: false;
|
151
|
+
minItems: number;
|
152
|
+
maxItems: number;
|
153
|
+
}
|
154
|
+
|
155
|
+
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
156
|
+
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
157
|
+
interface StringOptions extends SchemaOptions {
|
158
|
+
/** The maximum string length */
|
159
|
+
maxLength?: number;
|
160
|
+
/** The minimum string length */
|
161
|
+
minLength?: number;
|
162
|
+
/** A regular expression pattern this string should match */
|
163
|
+
pattern?: string;
|
164
|
+
/** A format this string should match */
|
165
|
+
format?: StringFormatOption;
|
166
|
+
/** The content encoding for this string */
|
167
|
+
contentEncoding?: StringContentEncodingOption;
|
168
|
+
/** The content media type for this string */
|
169
|
+
contentMediaType?: string;
|
170
|
+
}
|
171
|
+
interface TString extends TSchema, StringOptions {
|
172
|
+
[Kind]: 'String';
|
173
|
+
static: string;
|
174
|
+
type: 'string';
|
175
|
+
}
|
176
|
+
|
177
|
+
interface TBoolean extends TSchema {
|
178
|
+
[Kind]: 'Boolean';
|
179
|
+
static: boolean;
|
180
|
+
type: 'boolean';
|
181
|
+
}
|
182
|
+
|
183
|
+
interface NumberOptions extends SchemaOptions {
|
184
|
+
exclusiveMaximum?: number;
|
185
|
+
exclusiveMinimum?: number;
|
186
|
+
maximum?: number;
|
187
|
+
minimum?: number;
|
188
|
+
multipleOf?: number;
|
189
|
+
}
|
190
|
+
interface TNumber extends TSchema, NumberOptions {
|
191
|
+
[Kind]: 'Number';
|
192
|
+
static: number;
|
193
|
+
type: 'number';
|
194
|
+
}
|
195
|
+
|
196
|
+
interface IntegerOptions extends SchemaOptions {
|
197
|
+
exclusiveMaximum?: number;
|
198
|
+
exclusiveMinimum?: number;
|
199
|
+
maximum?: number;
|
200
|
+
minimum?: number;
|
201
|
+
multipleOf?: number;
|
202
|
+
}
|
203
|
+
interface TInteger extends TSchema, IntegerOptions {
|
204
|
+
[Kind]: 'Integer';
|
205
|
+
static: number;
|
206
|
+
type: 'integer';
|
207
|
+
}
|
208
|
+
|
209
|
+
interface BigIntOptions extends SchemaOptions {
|
210
|
+
exclusiveMaximum?: bigint;
|
211
|
+
exclusiveMinimum?: bigint;
|
212
|
+
maximum?: bigint;
|
213
|
+
minimum?: bigint;
|
214
|
+
multipleOf?: bigint;
|
215
|
+
}
|
216
|
+
interface TBigInt extends TSchema, BigIntOptions {
|
217
|
+
[Kind]: 'BigInt';
|
218
|
+
static: bigint;
|
219
|
+
type: 'bigint';
|
220
|
+
}
|
221
|
+
|
222
|
+
type TFromTemplateLiteralKind<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds$1<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds$1<U> : T extends TString ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TBoolean ? true : T extends TLiteral ? true : false;
|
223
|
+
type TFromTemplateLiteralKinds$1<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? TFromTemplateLiteralKind<L> extends false ? false : TFromTemplateLiteralKinds$1<R> : true;
|
224
|
+
type TIsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? TFromTemplateLiteralKinds$1<U> : false;
|
225
|
+
|
226
|
+
type TStringReduceUnary<L extends string, R extends string[], Acc extends string[] = []> = R extends [infer A extends string, ...infer B extends string[]] ? TStringReduceUnary<L, B, [...Acc, `${L}${A}`]> : Acc;
|
227
|
+
type TStringReduceBinary<L extends string[], R extends string[], Acc extends string[] = []> = L extends [infer A extends string, ...infer B extends string[]] ? TStringReduceBinary<B, R, [...Acc, ...TStringReduceUnary<A, R>]> : Acc;
|
228
|
+
type TStringReduceMany<T extends string[][]> = T extends [infer L extends string[], infer R extends string[], ...infer Rest extends string[][]] ? TStringReduceMany<[TStringReduceBinary<L, R>, ...Rest]> : T;
|
229
|
+
type TStringReduce<T extends string[][], O = TStringReduceMany<T>> = 0 extends keyof O ? Assert<O[0], string[]> : [];
|
230
|
+
type TFromTemplateLiteralUnionKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [`${L['const']}`, ...TFromTemplateLiteralUnionKinds<R>] : [];
|
231
|
+
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[], Acc extends TLiteralValue[][] = []> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? (L extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<[...S, ...R], Acc> : L extends TLiteral<infer S extends TLiteralValue> ? TFromTemplateLiteralKinds<R, [...Acc, [S]]> : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<R, [...Acc, TFromTemplateLiteralUnionKinds<S>]> : L extends TBoolean ? TFromTemplateLiteralKinds<R, [...Acc, ['true', 'false']]> : Acc) : Acc;
|
232
|
+
type TTemplateLiteralGenerate<T extends TTemplateLiteral, F = TIsTemplateLiteralFinite<T>> = F extends true ? (T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<S> extends infer R extends string[][] ? TStringReduce<R> : [] : []) : [];
|
233
|
+
|
234
|
+
type TemplateLiteralStaticKind<T, Acc extends string> = T extends TUnion<infer U> ? {
|
235
|
+
[K in keyof U]: TemplateLiteralStatic<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
|
236
|
+
}[number] : T extends TTemplateLiteral ? `${Static<T>}` : T extends TLiteral<infer U> ? `${U}` : T extends TString ? `${string}` : T extends TNumber ? `${number}` : T extends TBigInt ? `${bigint}` : T extends TBoolean ? `${boolean}` : never;
|
237
|
+
type TemplateLiteralStatic<T extends TTemplateLiteralKind[], Acc extends string> = T extends [infer L, ...infer R] ? `${TemplateLiteralStaticKind<L, Acc>}${TemplateLiteralStatic<Assert<R, TTemplateLiteralKind[]>, Acc>}` : Acc;
|
238
|
+
type TTemplateLiteralKind = TTemplateLiteral | TUnion | TLiteral | TInteger | TNumber | TBigInt | TString | TBoolean | TNever;
|
239
|
+
interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
|
240
|
+
[Kind]: 'TemplateLiteral';
|
241
|
+
static: TemplateLiteralStatic<T, EmptyString>;
|
242
|
+
type: 'string';
|
243
|
+
pattern: string;
|
244
|
+
}
|
245
|
+
|
246
|
+
type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Keys extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = (Keys);
|
247
|
+
type TFromUnion$5<Types extends TSchema[], Result extends string[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$5<Right, [...Result, ...TIndexPropertyKeys<Left>]> : Result);
|
248
|
+
type TFromLiteral<LiteralValue extends TLiteralValue> = (LiteralValue extends PropertyKey ? [`${LiteralValue}`] : []);
|
249
|
+
type TIndexPropertyKeys<Type extends TSchema> = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$5<Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral<Value> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
|
250
|
+
]);
|
251
|
+
|
252
|
+
type TFromRest$5<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest$5<Right, Key, [...Result, Assert<TIndexFromPropertyKey<Left, Key>, TSchema>]> : Result);
|
253
|
+
type TFromIntersectRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? TFromIntersectRest<Right, [...Result]> : TFromIntersectRest<Right, [...Result, Left]> : Result);
|
254
|
+
type TFromIntersect$4<Types extends TSchema[], Key extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest$5<Types, Key>>>);
|
255
|
+
type TFromUnionRest<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? [] : TFromUnionRest<Right, [Left, ...Result]> : Result;
|
256
|
+
type TFromUnion$4<Types extends TSchema[], Key extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest$5<Types, Key>>>);
|
257
|
+
type TFromTuple$2<Types extends TSchema[], Key extends PropertyKey> = (Key extends keyof Types ? Types[Key] : Key extends '[number]' ? TUnionEvaluated<Types> : TNever);
|
258
|
+
type TFromArray$2<Type extends TSchema, Key extends PropertyKey> = (Key extends '[number]' ? Type : TNever);
|
259
|
+
type AssertPropertyKey<T> = Assert<T, string | number>;
|
260
|
+
type TFromProperty<Properties extends TProperties, Key extends PropertyKey> = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever);
|
261
|
+
type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer Type extends TSchema> ? TIndexFromPropertyKey<Type, Key> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$4<Types, Key> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$4<Types, Key> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple$2<Types, Key> : Type extends TArray<infer Type extends TSchema> ? TFromArray$2<Type, Key> : Type extends TObject<infer Properties extends TProperties> ? TFromProperty<Properties, Key> : TNever);
|
262
|
+
type TIndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TIndexFromPropertyKeys<Type, Right, [...Result, Assert<TIndexFromPropertyKey<Type, Left>, TSchema>]> : Result);
|
263
|
+
type FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (TUnionEvaluated<TIndexFromPropertyKeys<Type, PropertyKeys>>);
|
264
|
+
declare function FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): FromSchema<Type, PropertyKeys>;
|
265
|
+
type TIndex<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (FromSchema<Type, PropertyKeys>);
|
266
|
+
|
267
|
+
interface TIterator<T extends TSchema = TSchema> extends TSchema {
|
268
|
+
[Kind]: 'Iterator';
|
269
|
+
static: IterableIterator<Static<T, this['params']>>;
|
270
|
+
type: 'Iterator';
|
271
|
+
items: T;
|
272
|
+
}
|
273
|
+
|
274
|
+
interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
275
|
+
[Kind]: 'Promise';
|
276
|
+
static: Promise$1<Static<T, this['params']>>;
|
277
|
+
type: 'Promise';
|
278
|
+
item: TSchema;
|
279
|
+
}
|
280
|
+
/** `[JavaScript]` Creates a Promise type */
|
281
|
+
declare function Promise$1<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
282
|
+
|
283
|
+
type TSetIncludes<T extends PropertyKey[], S extends PropertyKey> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? S extends L ? true : TSetIncludes<R, S> : false);
|
284
|
+
type TSetIntersect<T extends PropertyKey[], S extends PropertyKey[], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TSetIncludes<S, L> extends true ? TSetIntersect<R, S, [...Acc, L]> : TSetIntersect<R, S, [...Acc]> : Acc);
|
285
|
+
type TSetUnion<T extends PropertyKey[], S extends PropertyKey[]> = ([
|
286
|
+
...T,
|
287
|
+
...S
|
288
|
+
]);
|
289
|
+
type TSetIntersectManyResolve<T extends PropertyKey[][], Acc extends PropertyKey[]> = (T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? TSetIntersectManyResolve<R, TSetIntersect<Acc, L>> : Acc);
|
290
|
+
type TSetIntersectMany<T extends PropertyKey[][]> = (T extends [infer L extends PropertyKey[]] ? L : T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? TSetIntersectManyResolve<R, L> : []);
|
291
|
+
type TSetUnionMany<T extends PropertyKey[][], Acc extends PropertyKey[] = []> = (T extends [infer L extends PropertyKey[], ...infer R extends PropertyKey[][]] ? TSetUnionMany<R, TSetUnion<Acc, L>> : Acc);
|
292
|
+
|
293
|
+
type TOptional<T extends TSchema> = T & {
|
294
|
+
[OptionalKind]: 'Optional';
|
295
|
+
};
|
296
|
+
|
297
|
+
interface TRegExp extends TSchema {
|
298
|
+
[Kind]: 'RegExp';
|
299
|
+
static: `${string}`;
|
300
|
+
type: 'RegExp';
|
301
|
+
source: string;
|
302
|
+
flags: string;
|
303
|
+
}
|
304
|
+
|
305
|
+
type TFromTemplateLiteralKeyInfinite<Key extends TTemplateLiteral, Type extends TSchema> = Ensure<TRecord<Key, Type>>;
|
306
|
+
type TFromTemplateLiteralKeyFinite<Key extends TTemplateLiteral, Type extends TSchema, I extends string = Static<Key>> = (Ensure<TObject<Evaluate<{
|
307
|
+
[_ in I]: Type;
|
308
|
+
}>>>);
|
309
|
+
type TFromTemplateLiteralKey<Key extends TTemplateLiteral, Type extends TSchema> = TIsTemplateLiteralFinite<Key> extends false ? TFromTemplateLiteralKeyInfinite<Key, Type> : TFromTemplateLiteralKeyFinite<Key, Type>;
|
310
|
+
type TFromEnumKey<Key extends Record$1<string, string | number>, Type extends TSchema> = Ensure<TObject<{
|
311
|
+
[_ in Key[keyof Key]]: Type;
|
312
|
+
}>>;
|
313
|
+
type TFromUnionKeyLiteralString<Key extends TLiteral<string>, Type extends TSchema> = {
|
314
|
+
[_ in Key['const']]: Type;
|
315
|
+
};
|
316
|
+
type TFromUnionKeyLiteralNumber<Key extends TLiteral<number>, Type extends TSchema> = {
|
317
|
+
[_ in Key['const']]: Type;
|
318
|
+
};
|
319
|
+
type TFromUnionKeyRest<Keys extends TSchema[], Type extends TSchema> = Keys extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TUnion<infer Types extends TSchema[]> ? TFromUnionKeyRest<Types, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<string> ? TFromUnionKeyLiteralString<Left, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<number> ? TFromUnionKeyLiteralNumber<Left, Type> & TFromUnionKeyRest<Right, Type> : {}) : {};
|
320
|
+
type TFromUnionKey<Key extends TSchema[], Type extends TSchema, P extends TProperties = TFromUnionKeyRest<Key, Type>> = (Ensure<TObject<Evaluate<P>>>);
|
321
|
+
type TFromLiteralKey<Key extends TLiteralValue, Type extends TSchema> = (Ensure<TObject<{
|
322
|
+
[_ in Assert<Key, PropertyKey>]: Type;
|
323
|
+
}>>);
|
324
|
+
type TFromRegExpKey<_Key extends TRegExp, Type extends TSchema> = (Ensure<TRecord<TRegExp, Type>>);
|
325
|
+
type TFromStringKey<_Key extends TString, Type extends TSchema> = (Ensure<TRecord<TString, Type>>);
|
326
|
+
type TFromAnyKey<_Key extends TAny, Type extends TSchema> = (Ensure<TRecord<TAny, Type>>);
|
327
|
+
type TFromNeverKey<_Key extends TNever, Type extends TSchema> = (Ensure<TRecord<TNever, Type>>);
|
328
|
+
type TFromIntegerKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
|
329
|
+
type TFromNumberKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
|
330
|
+
type RecordStatic<Key extends TSchema, Type extends TSchema, P extends unknown[]> = (Evaluate<{
|
331
|
+
[_ in Assert<Static<Key>, PropertyKey>]: Static<Type, P>;
|
332
|
+
}>);
|
333
|
+
interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = TSchema> extends TSchema {
|
334
|
+
[Kind]: 'Record';
|
335
|
+
static: RecordStatic<Key, Type, this['params']>;
|
336
|
+
type: 'object';
|
337
|
+
patternProperties: {
|
338
|
+
[pattern: string]: Type;
|
339
|
+
};
|
340
|
+
additionalProperties: TAdditionalProperties;
|
341
|
+
}
|
342
|
+
type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
|
343
|
+
/** `[Json]` Creates a Record type */
|
344
|
+
declare function Record$1<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
|
345
|
+
|
346
|
+
/** Creates a static type from a TypeBox type */
|
347
|
+
type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
348
|
+
params: P;
|
349
|
+
})['static'];
|
350
|
+
|
351
|
+
type ReadonlyOptionalPropertyKeys$1<T extends TProperties> = {
|
352
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
353
|
+
}[keyof T];
|
354
|
+
type ReadonlyPropertyKeys$1<T extends TProperties> = {
|
355
|
+
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
|
356
|
+
}[keyof T];
|
357
|
+
type OptionalPropertyKeys$1<T extends TProperties> = {
|
358
|
+
[K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
359
|
+
}[keyof T];
|
360
|
+
type RequiredPropertyKeys$1<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys$1<T> | ReadonlyPropertyKeys$1<T> | OptionalPropertyKeys$1<T>>;
|
361
|
+
type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys$1<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys$1<T>>> & Partial<Pick<R, OptionalPropertyKeys$1<T>>> & Required<Pick<R, RequiredPropertyKeys$1<T>>>)>;
|
362
|
+
type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
|
363
|
+
[K in keyof T]: Static<T[K], P>;
|
364
|
+
}>;
|
365
|
+
type TPropertyKey = string | number;
|
366
|
+
type TProperties = Record<TPropertyKey, TSchema>;
|
367
|
+
type TAdditionalProperties = undefined | TSchema | boolean;
|
368
|
+
interface ObjectOptions extends SchemaOptions {
|
369
|
+
/** Additional property constraints for this object */
|
370
|
+
additionalProperties?: TAdditionalProperties;
|
371
|
+
/** The minimum number of properties allowed on this object */
|
372
|
+
minProperties?: number;
|
373
|
+
/** The maximum number of properties allowed on this object */
|
374
|
+
maxProperties?: number;
|
375
|
+
}
|
376
|
+
interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
377
|
+
[Kind]: 'Object';
|
378
|
+
static: ObjectStatic<T, this['params']>;
|
379
|
+
additionalProperties?: TAdditionalProperties;
|
380
|
+
type: 'object';
|
381
|
+
properties: T;
|
382
|
+
required?: string[];
|
383
|
+
}
|
384
|
+
|
385
|
+
type TupleToUnion<T extends any[]> = {
|
386
|
+
[K in keyof T]: T[K];
|
387
|
+
}[number];
|
388
|
+
type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
389
|
+
type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
390
|
+
type UnionToTuple<U, Acc extends unknown[] = [], R = UnionLast<U>> = [U] extends [never] ? Acc : UnionToTuple<Exclude<U, R>, [Extract<U, R>, ...Acc]>;
|
391
|
+
type Assert<T, E> = T extends E ? T : never;
|
392
|
+
type Evaluate<T> = T extends infer O ? {
|
393
|
+
[K in keyof O]: O[K];
|
394
|
+
} : never;
|
395
|
+
type Ensure<T> = T extends infer U ? U : never;
|
396
|
+
type EmptyString = '';
|
397
|
+
type ZeroString = '0';
|
398
|
+
type IncrementBase = {
|
399
|
+
m: '9';
|
400
|
+
t: '01';
|
401
|
+
'0': '1';
|
402
|
+
'1': '2';
|
403
|
+
'2': '3';
|
404
|
+
'3': '4';
|
405
|
+
'4': '5';
|
406
|
+
'5': '6';
|
407
|
+
'6': '7';
|
408
|
+
'7': '8';
|
409
|
+
'8': '9';
|
410
|
+
'9': '0';
|
411
|
+
};
|
412
|
+
type IncrementTake<T extends keyof IncrementBase> = IncrementBase[T];
|
413
|
+
type IncrementStep<T extends string> = T extends IncrementBase['m'] ? IncrementBase['t'] : T extends `${infer L extends keyof IncrementBase}${infer R}` ? L extends IncrementBase['m'] ? `${IncrementTake<L>}${IncrementStep<R>}` : `${IncrementTake<L>}${R}` : never;
|
414
|
+
type IncrementReverse<T extends string> = T extends `${infer L}${infer R}` ? `${IncrementReverse<R>}${L}` : T;
|
415
|
+
type TIncrement<T extends string> = IncrementReverse<IncrementStep<IncrementReverse<T>>>;
|
416
|
+
|
417
|
+
interface ArrayOptions extends SchemaOptions {
|
418
|
+
/** The minimum number of items in this array */
|
419
|
+
minItems?: number;
|
420
|
+
/** The maximum number of items in this array */
|
421
|
+
maxItems?: number;
|
422
|
+
/** Should this schema contain unique items */
|
423
|
+
uniqueItems?: boolean;
|
424
|
+
/** A schema for which some elements should match */
|
425
|
+
contains?: TSchema;
|
426
|
+
/** A minimum number of contains schema matches */
|
427
|
+
minContains?: number;
|
428
|
+
/** A maximum number of contains schema matches */
|
429
|
+
maxContains?: number;
|
430
|
+
}
|
431
|
+
type ArrayStatic<T extends TSchema, P extends unknown[]> = Ensure<Static<T, P>[]>;
|
432
|
+
interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
433
|
+
[Kind]: 'Array';
|
434
|
+
static: ArrayStatic<T, this['params']>;
|
435
|
+
type: 'array';
|
436
|
+
items: T;
|
437
|
+
}
|
438
|
+
|
439
|
+
interface SchemaOptions {
|
440
|
+
$schema?: string;
|
441
|
+
/** Id for this schema */
|
442
|
+
$id?: string;
|
443
|
+
/** Title of this schema */
|
444
|
+
title?: string;
|
445
|
+
/** Description of this schema */
|
446
|
+
description?: string;
|
447
|
+
/** Default value for this schema */
|
448
|
+
default?: any;
|
449
|
+
/** Example values matching this schema */
|
450
|
+
examples?: any;
|
451
|
+
/** Optional annotation for readOnly */
|
452
|
+
readOnly?: boolean;
|
453
|
+
/** Optional annotation for writeOnly */
|
454
|
+
writeOnly?: boolean;
|
455
|
+
[prop: string]: any;
|
456
|
+
}
|
457
|
+
interface TKind {
|
458
|
+
[Kind]: string;
|
459
|
+
}
|
460
|
+
interface TSchema extends TKind, SchemaOptions {
|
461
|
+
[ReadonlyKind]?: string;
|
462
|
+
[OptionalKind]?: string;
|
463
|
+
[Hint]?: string;
|
464
|
+
params: unknown[];
|
465
|
+
static: unknown;
|
466
|
+
}
|
467
|
+
|
468
|
+
type TFromComputed$4<Target extends string, Parameters extends TSchema[]> = Ensure<(TComputed<'Awaited', [TComputed<Target, Parameters>]>)>;
|
469
|
+
type TFromRef$3<Ref extends string> = Ensure<TComputed<'Awaited', [TRef<Ref>]>>;
|
470
|
+
type TFromRest$4<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest$4<Right, [...Result, TAwaited<Left>]> : Result);
|
471
|
+
type TAwaited<Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed$4<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef$3<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest$4<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest$4<Types>> : Type extends TPromise<infer Type extends TSchema> ? TAwaited<Type> : Type);
|
472
|
+
|
473
|
+
type TFromRest$3<Types extends TSchema[], Result extends PropertyKey[][] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest$3<R, [...Result, TKeyOfPropertyKeys<L>]> : Result);
|
474
|
+
type TFromIntersect$3<Types extends TSchema[], PropertyKeysArray extends PropertyKey[][] = TFromRest$3<Types>, PropertyKeys extends PropertyKey[] = TSetUnionMany<PropertyKeysArray>> = PropertyKeys;
|
475
|
+
type TFromUnion$3<Types extends TSchema[], PropertyKeysArray extends PropertyKey[][] = TFromRest$3<Types>, PropertyKeys extends PropertyKey[] = TSetIntersectMany<PropertyKeysArray>> = PropertyKeys;
|
476
|
+
type TFromTuple$1<Types extends TSchema[], Indexer extends string = ZeroString, Acc extends PropertyKey[] = []> = Types extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? TFromTuple$1<R, TIncrement<Indexer>, [...Acc, Indexer]> : Acc;
|
477
|
+
type TFromArray$1<_ extends TSchema> = ([
|
478
|
+
'[number]'
|
479
|
+
]);
|
480
|
+
type TFromProperties$7<Properties extends TProperties> = (UnionToTuple<keyof Properties>);
|
481
|
+
type TKeyOfPropertyKeys<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TKeyOfPropertyKeys<Type> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$3<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$3<Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple$1<Types> : Type extends TArray<infer Type extends TSchema> ? TFromArray$1<Type> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties$7<Properties> : [
|
482
|
+
]);
|
483
|
+
|
484
|
+
type TFromComputed$3<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'KeyOf', [TComputed<Target, Parameters>]>>;
|
485
|
+
type TFromRef$2<Ref extends string> = Ensure<TComputed<'KeyOf', [TRef<Ref>]>>;
|
486
|
+
/** `[Internal]` Used by KeyOfFromMappedResult */
|
487
|
+
type TKeyOfFromType<Type extends TSchema, PropertyKeys extends PropertyKey[] = TKeyOfPropertyKeys<Type>, PropertyKeyTypes extends TSchema[] = TKeyOfPropertyKeysToRest<PropertyKeys>, Result = TUnionEvaluated<PropertyKeyTypes>> = Ensure<Result>;
|
488
|
+
type TKeyOfPropertyKeysToRest<PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? L extends '[number]' ? TKeyOfPropertyKeysToRest<R, [...Result, TNumber]> : TKeyOfPropertyKeysToRest<R, [...Result, TLiteral<Assert<L, TLiteralValue>>]> : Result);
|
489
|
+
type TKeyOf<Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed$3<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef$2<Ref> : Type extends TMappedResult ? TKeyOfFromMappedResult<Type> : TKeyOfFromType<Type>);
|
490
|
+
|
491
|
+
type TFromProperties$6<Properties extends TProperties> = ({
|
492
|
+
[K2 in keyof Properties]: TKeyOfFromType<Properties[K2]>;
|
493
|
+
});
|
494
|
+
type TFromMappedResult$2<MappedResult extends TMappedResult> = (Evaluate<TFromProperties$6<MappedResult['properties']>>);
|
495
|
+
type TKeyOfFromMappedResult<MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult$2<MappedResult>> = (Ensure<TMappedResult<Properties>>);
|
496
|
+
|
497
|
+
type TFromProperties$5<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = ({
|
498
|
+
[K2 in keyof Properties]: TOmit<Properties[K2], PropertyKeys>;
|
499
|
+
});
|
500
|
+
type TFromMappedResult$1<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[]> = (Evaluate<TFromProperties$5<MappedResult['properties'], PropertyKeys>>);
|
501
|
+
type TOmitFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult$1<MappedResult, PropertyKeys>> = (Ensure<TMappedResult<Properties>>);
|
502
|
+
|
503
|
+
type TFromIntersect$2<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect$2<R, PropertyKeys, [...Result, TOmit<L, PropertyKeys>]> : Result);
|
504
|
+
type TFromUnion$2<T extends TSchema[], K extends PropertyKey[], Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion$2<R, K, [...Result, TOmit<L, K>]> : Result);
|
505
|
+
type TFromProperties$4<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKey extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Omit$1<Properties, UnionKey>>);
|
506
|
+
type TFromObject$4<Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties$4<Properties, PropertyKeys>)>>;
|
507
|
+
type TUnionFromPropertyKeys$1<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys$1<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys$1<Rest, [...Result]> : TUnion<Result>);
|
508
|
+
type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect$2<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion$2<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject$4<TObject<Types>, PropertyKeys> : TObject<{}>);
|
509
|
+
type TResolvePropertyKeys$1<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
510
|
+
type TResolveTypeKey$1<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys$1<Key> : Key;
|
511
|
+
type TOmit<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TOmitFromMappedResult<Type, TResolvePropertyKeys$1<Key>> : Key extends TMappedKey ? TOmitFromMappedKey<Type, Key> : [
|
512
|
+
IsTypeRef,
|
513
|
+
IsKeyRef
|
514
|
+
] extends [true, true] ? TComputed<'Omit', [Type, TResolveTypeKey$1<Key>]> : [
|
515
|
+
IsTypeRef,
|
516
|
+
IsKeyRef
|
517
|
+
] extends [false, true] ? TComputed<'Omit', [Type, TResolveTypeKey$1<Key>]> : [
|
518
|
+
IsTypeRef,
|
519
|
+
IsKeyRef
|
520
|
+
] extends [true, false] ? TComputed<'Omit', [Type, TResolveTypeKey$1<Key>]> : TOmitResolve<Type, TResolvePropertyKeys$1<Key>>);
|
521
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
522
|
+
declare function Omit$1<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TOmit<Type, Key>;
|
523
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
524
|
+
declare function Omit$1<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
525
|
+
|
526
|
+
type TFromPropertyKey$1<Type extends TSchema, Key extends PropertyKey> = {
|
527
|
+
[_ in Key]: TOmit<Type, [Key]>;
|
528
|
+
};
|
529
|
+
type TFromPropertyKeys$1<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys$1<Type, RK, Result & TFromPropertyKey$1<Type, LK>> : Result);
|
530
|
+
type TFromMappedKey$1<Type extends TSchema, MappedKey extends TMappedKey> = (TFromPropertyKeys$1<Type, MappedKey['keys']>);
|
531
|
+
type TOmitFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey$1<Type, MappedKey>> = (TMappedResult<Properties>);
|
532
|
+
|
533
|
+
type TFromProperties$3<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = ({
|
534
|
+
[K2 in keyof Properties]: TPick<Properties[K2], PropertyKeys>;
|
535
|
+
});
|
536
|
+
type TFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[]> = (Evaluate<TFromProperties$3<MappedResult['properties'], PropertyKeys>>);
|
537
|
+
type TPickFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult<MappedResult, PropertyKeys>> = (Ensure<TMappedResult<Properties>>);
|
538
|
+
|
539
|
+
type TFromIntersect$1<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect$1<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
540
|
+
type TFromUnion$1<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion$1<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
|
541
|
+
type TFromProperties$2<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKeys extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Pick$1<Properties, UnionKeys & keyof Properties>>);
|
542
|
+
type TFromObject$3<Type extends TObject, Key extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties$2<Properties, Key>)>>;
|
543
|
+
type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
|
544
|
+
type TPickResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect$1<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion$1<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject$3<TObject<Types>, PropertyKeys> : TObject<{}>);
|
545
|
+
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
546
|
+
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
547
|
+
type TPick<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TPickFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TPickFromMappedKey<Type, Key> : [
|
548
|
+
IsTypeRef,
|
549
|
+
IsKeyRef
|
550
|
+
] extends [true, true] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : [
|
551
|
+
IsTypeRef,
|
552
|
+
IsKeyRef
|
553
|
+
] extends [false, true] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : [
|
554
|
+
IsTypeRef,
|
555
|
+
IsKeyRef
|
556
|
+
] extends [true, false] ? TComputed<'Pick', [Type, TResolveTypeKey<Key>]> : TPickResolve<Type, TResolvePropertyKeys<Key>>);
|
557
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
558
|
+
declare function Pick$1<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
559
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
560
|
+
declare function Pick$1<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TPick<Type, Key>;
|
561
|
+
|
562
|
+
type TFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
|
563
|
+
[_ in Key]: TPick<Type, [Key]>;
|
564
|
+
};
|
565
|
+
type TFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer LeftKey extends PropertyKey, ...infer RightKeys extends PropertyKey[]] ? TFromPropertyKeys<Type, RightKeys, Result & TFromPropertyKey<Type, LeftKey>> : Result);
|
566
|
+
type TFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey> = (TFromPropertyKeys<Type, MappedKey['keys']>);
|
567
|
+
type TPickFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey<Type, MappedKey>> = (TMappedResult<Properties>);
|
568
|
+
|
569
|
+
type TFromComputed$2<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Partial', [TComputed<Target, Parameters>]>>;
|
570
|
+
type TFromRef$1<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
|
571
|
+
type TFromProperties$1<Properties extends TProperties> = Evaluate<{
|
572
|
+
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<Properties[K]>;
|
573
|
+
}>;
|
574
|
+
type TFromObject$2<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties$1<Properties>)>>;
|
575
|
+
type TFromRest$2<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest$2<R, [...Result, TPartial<L>]> : Result);
|
576
|
+
type TPartial<T extends TSchema> = (T extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : T extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed$2<Target, Parameters> : T extends TRef<infer Ref extends string> ? TFromRef$1<Ref> : T extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest$2<Types>> : T extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest$2<Types>> : T extends TObject<infer Properties extends TProperties> ? TFromObject$2<TObject<Properties>> : TObject<{}>);
|
577
|
+
|
578
|
+
type TFromComputed$1<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
|
579
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
580
|
+
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
581
|
+
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
|
582
|
+
}>;
|
583
|
+
type TFromObject$1<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
584
|
+
type TFromRest$1<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest$1<R, [...Result, TRequired<L>]> : Result);
|
585
|
+
type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed$1<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest$1<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest$1<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$1<TObject<Properties>> : TObject<{}>);
|
586
|
+
|
587
|
+
type TDerefParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDerefParameters<ModuleProperties, Right, [...Result, TDeref<ModuleProperties, Key>]> : TDerefParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
588
|
+
type TDeref<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDeref<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
|
589
|
+
type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
|
590
|
+
type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, TIndexPropertyKeys<T1>> extends infer Result extends TSchema ? Result : never : never);
|
591
|
+
type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
|
592
|
+
type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
|
593
|
+
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
594
|
+
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
595
|
+
type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
|
596
|
+
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
597
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Record' ? TFromRecord<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
598
|
+
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
599
|
+
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
600
|
+
}>>>;
|
601
|
+
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
602
|
+
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
603
|
+
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
|
604
|
+
type TFromIntersect<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TIntersectEvaluated<TFromRest<ModuleProperties, Types>>>);
|
605
|
+
type TFromUnion<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TUnionEvaluated<TFromRest<ModuleProperties, Types>>>);
|
606
|
+
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
607
|
+
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
608
|
+
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
609
|
+
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
610
|
+
type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
611
|
+
type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
612
|
+
type TComputeModuleProperties<ModuleProperties extends TProperties> = Evaluate<{
|
613
|
+
[Key in keyof ModuleProperties]: TComputeType<ModuleProperties, Key>;
|
614
|
+
}>;
|
615
|
+
|
616
|
+
type TInferArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<Array<TInfer<ModuleProperties, Type>>>);
|
617
|
+
type TInferAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<AsyncIterableIterator<TInfer<ModuleProperties, Type>>>);
|
618
|
+
type TInferConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = Ensure<new (...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, InstanceType>>;
|
619
|
+
type TInferFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<(...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, ReturnType>>;
|
620
|
+
type TInferIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<IterableIterator<TInfer<ModuleProperties, Type>>>);
|
621
|
+
type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TInferIntersect<ModuleProperties, Right, Result & TInfer<ModuleProperties, Left>> : Result);
|
622
|
+
type ReadonlyOptionalPropertyKeys<Properties extends TProperties> = {
|
623
|
+
[Key in keyof Properties]: Properties[Key] extends TReadonly<TSchema> ? (Properties[Key] extends TOptional<Properties[Key]> ? Key : never) : never;
|
624
|
+
}[keyof Properties];
|
625
|
+
type ReadonlyPropertyKeys<Source extends TProperties> = {
|
626
|
+
[Key in keyof Source]: Source[Key] extends TReadonly<TSchema> ? (Source[Key] extends TOptional<Source[Key]> ? never : Key) : never;
|
627
|
+
}[keyof Source];
|
628
|
+
type OptionalPropertyKeys<Source extends TProperties> = {
|
629
|
+
[Key in keyof Source]: Source[Key] extends TOptional<TSchema> ? (Source[Key] extends TReadonly<Source[Key]> ? never : Key) : never;
|
630
|
+
}[keyof Source];
|
631
|
+
type RequiredPropertyKeys<Source extends TProperties> = keyof Omit<Source, ReadonlyOptionalPropertyKeys<Source> | ReadonlyPropertyKeys<Source> | OptionalPropertyKeys<Source>>;
|
632
|
+
type InferPropertiesWithModifiers<Properties extends TProperties, Source extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<Source, ReadonlyOptionalPropertyKeys<Properties>>>> & Readonly<Pick<Source, ReadonlyPropertyKeys<Properties>>> & Partial<Pick<Source, OptionalPropertyKeys<Properties>>> & Required<Pick<Source, RequiredPropertyKeys<Properties>>>)>;
|
633
|
+
type InferProperties<ModuleProperties extends TProperties, Properties extends TProperties> = InferPropertiesWithModifiers<Properties, {
|
634
|
+
[K in keyof Properties]: TInfer<ModuleProperties, Properties[K]>;
|
635
|
+
}>;
|
636
|
+
type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
|
637
|
+
type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
|
638
|
+
type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Ensure<{
|
639
|
+
[_ in InferredKey]: InferedType;
|
640
|
+
}>;
|
641
|
+
type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
|
642
|
+
type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
|
643
|
+
type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Type extends TSchema> ? TInferRecord<ModuleProperties, Key, Type> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
|
644
|
+
/** Inference Path for Imports. This type is used to compute TImport `static` */
|
645
|
+
type TInferFromModuleKey<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Key]> : never);
|
646
|
+
|
647
|
+
interface TImport<ModuleProperties extends TProperties = {}, Key extends keyof ModuleProperties = keyof ModuleProperties> extends TSchema {
|
648
|
+
[Kind]: 'Import';
|
649
|
+
static: TInferFromModuleKey<ModuleProperties, Key>;
|
650
|
+
$defs: ModuleProperties;
|
651
|
+
$ref: Key;
|
652
|
+
}
|
653
|
+
declare class TModule<ModuleProperties extends TProperties, ComputedModuleProperties extends TProperties = TComputeModuleProperties<ModuleProperties>> {
|
654
|
+
private readonly $defs;
|
655
|
+
constructor($defs: ModuleProperties);
|
656
|
+
/** `[Json]` Imports a Type by Key. */
|
657
|
+
Import<Key extends keyof ComputedModuleProperties>(key: Key, options?: SchemaOptions): TImport<ComputedModuleProperties, Key>;
|
658
|
+
private WithIdentifiers;
|
659
|
+
}
|
2
660
|
|
3
661
|
type PathToObject<Path extends string, Type extends RouteBase> = Path extends `${infer Head}/${infer Rest}` ? Head extends "" ? PathToObject<Rest, Type> : {
|
4
662
|
[K in Head]: PathToObject<Rest, Type>;
|
5
663
|
} : {
|
6
664
|
[K in Path]: Type;
|
7
665
|
};
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}>;
|
666
|
+
declare namespace ElysiaMatch {
|
667
|
+
type RouteEnd = Record<string, RouteSchema>;
|
668
|
+
type Fx = (...args: any[]) => AnyElysia;
|
669
|
+
type All = AnyElysia | Fx;
|
670
|
+
type Extract<T extends All> = T extends Fx ? ReturnType<T> : T;
|
671
|
+
}
|
15
672
|
type FlattenIndexRoutes<T> = T extends object ? {
|
16
|
-
[K in keyof T as K extends "index" ? T[K] extends
|
673
|
+
[K in keyof T as K extends "index" ? T[K] extends ElysiaMatch.RouteEnd ? never : K : K]: FlattenIndexRoutes<T[K]>;
|
17
674
|
} & (T extends {
|
18
675
|
index: infer I;
|
19
|
-
} ? I extends
|
20
|
-
type ElysiaWithBaseUrl<BaseUrl extends string, ElysiaType extends
|
676
|
+
} ? I extends ElysiaMatch.RouteEnd ? FlattenIndexRoutes<I> : T : T) : T;
|
677
|
+
type ElysiaWithBaseUrl<BaseUrl extends string, ElysiaType extends ElysiaMatch.All> = ElysiaMatch.Extract<ElysiaType> extends Elysia<infer BasePath, infer Singleton, infer Definitions, infer Metadata, infer Routes, infer Ephemeral, infer Volatile> ? Elysia<BasePath, Singleton, Definitions, Metadata, FlattenIndexRoutes<PathToObject<BaseUrl, Routes>>, Ephemeral, Volatile> : never;
|
21
678
|
type SoftString<T extends string> = T | (string & {});
|
22
679
|
|
23
680
|
type SchemaHandler = ({ path, url, }: {
|
@@ -55,18 +712,19 @@ interface AutoloadOptions {
|
|
55
712
|
*/
|
56
713
|
skipImportErrors?: boolean;
|
57
714
|
}
|
58
|
-
declare function autoload(options?: AutoloadOptions): Promise<Elysia$1<string,
|
715
|
+
declare function autoload(options?: AutoloadOptions): Promise<Elysia$1<string, {
|
59
716
|
decorator: {};
|
60
717
|
store: {};
|
61
718
|
derive: {};
|
62
719
|
resolve: {};
|
63
720
|
}, {
|
64
|
-
|
721
|
+
typebox: TModule<{}>;
|
65
722
|
error: {};
|
66
723
|
}, {
|
67
724
|
schema: {};
|
68
725
|
macro: {};
|
69
726
|
macroFn: {};
|
727
|
+
parser: {};
|
70
728
|
}, {}, {
|
71
729
|
derive: {};
|
72
730
|
resolve: {};
|
package/dist/index.js
CHANGED
@@ -1,45 +1,16 @@
|
|
1
1
|
import fs from 'node:fs';
|
2
2
|
import path from 'node:path';
|
3
|
+
import { pathToFileURL } from 'node:url';
|
3
4
|
import { Elysia } from 'elysia';
|
4
5
|
|
5
6
|
function getPath(dir) {
|
6
|
-
if (path.isAbsolute(dir))
|
7
|
-
return dir;
|
7
|
+
if (path.isAbsolute(dir)) return dir;
|
8
8
|
if (path.isAbsolute(process.argv[1]))
|
9
9
|
return path.join(process.argv[1], "..", dir);
|
10
10
|
return path.join(process.cwd(), process.argv[1], "..", dir);
|
11
11
|
}
|
12
12
|
function transformToUrl(path2) {
|
13
|
-
|
14
|
-
// Clean the url extensions
|
15
|
-
{ regex: /\.(ts|tsx|js|jsx|mjs|cjs)$/u, replacement: "" },
|
16
|
-
// Fix windows slashes
|
17
|
-
{ regex: /\\/gu, replacement: "/" },
|
18
|
-
// Handle wild card based routes - users/[...id]/profile.ts -> users/*/profile
|
19
|
-
{ regex: /\[\.\.\..*\]/gu, replacement: "*" },
|
20
|
-
// Handle generic square bracket based routes - users/[id]/index.ts -> users/:id
|
21
|
-
{
|
22
|
-
regex: /\[(.*?)\]/gu,
|
23
|
-
replacement: (_, match) => `:${match}`
|
24
|
-
},
|
25
|
-
{
|
26
|
-
regex: /\/?\((.*)\)/,
|
27
|
-
replacement: ""
|
28
|
-
},
|
29
|
-
// Handle the case when multiple parameters are present in one file
|
30
|
-
// users / [id] - [name].ts to users /: id -:name and users / [id] - [name] / [age].ts to users /: id -: name /: age
|
31
|
-
{ regex: /\]-\[/gu, replacement: "-:" },
|
32
|
-
{ regex: /\]\//gu, replacement: "/" },
|
33
|
-
{ regex: /\[/gu, replacement: "" },
|
34
|
-
{ regex: /\]/gu, replacement: "" },
|
35
|
-
// remove index from end of path
|
36
|
-
{ regex: /\/?index$/, replacement: "" }
|
37
|
-
];
|
38
|
-
let url = path2;
|
39
|
-
for (const { regex, replacement } of replacements) {
|
40
|
-
url = url.replace(regex, replacement);
|
41
|
-
}
|
42
|
-
return url;
|
13
|
+
return path2.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/u, "").replaceAll("\\", "/").replaceAll(/\[\.\.\..*\]/gu, "*").replaceAll(/\[(.*?)\]/gu, (_, match) => `:${match}`).replace(/\/?\((.*)\)/, "").replaceAll("]-[", "-:").replaceAll("]/", "/").replaceAll(/\[|\]/gu, "").replace(/\/?index$/, "");
|
43
14
|
}
|
44
15
|
function getParamsCount(path2) {
|
45
16
|
return path2.match(/\[(.*?)\]/gu)?.length || 0;
|
@@ -48,13 +19,11 @@ function sortByNestedParams(routes) {
|
|
48
19
|
return routes.sort((a, b) => getParamsCount(a) - getParamsCount(b));
|
49
20
|
}
|
50
21
|
function fixSlashes(prefix) {
|
51
|
-
if (!prefix?.endsWith("/"))
|
52
|
-
return prefix;
|
22
|
+
if (!prefix?.endsWith("/")) return prefix;
|
53
23
|
return prefix.slice(0, -1);
|
54
24
|
}
|
55
25
|
function addRelativeIfNotDot(path2) {
|
56
|
-
if (path2.at(0) !== ".")
|
57
|
-
return `./${path2}`;
|
26
|
+
if (path2.at(0) !== ".") return `./${path2}`;
|
58
27
|
return path2;
|
59
28
|
}
|
60
29
|
|
@@ -91,61 +60,59 @@ async function autoload(options = {}) {
|
|
91
60
|
types
|
92
61
|
}
|
93
62
|
});
|
94
|
-
const
|
95
|
-
const
|
96
|
-
|
97
|
-
cwd: directoryPath
|
98
|
-
})
|
99
|
-
);
|
63
|
+
const globPattern = pattern || "**/*.{ts,tsx,js,jsx,mjs,cjs}";
|
64
|
+
const globOptions = { cwd: directoryPath };
|
65
|
+
const files = typeof Bun === "undefined" ? fs.globSync(globPattern, globOptions) : Array.from(new Bun.Glob(globPattern).scanSync(globOptions));
|
100
66
|
if (failGlob && files.length === 0)
|
101
67
|
throw new Error(
|
102
68
|
`No matches found in ${directoryPath}. You can disable this error by setting the failGlob parameter to false in the options of autoload plugin`
|
103
69
|
);
|
104
70
|
const paths = [];
|
105
|
-
for
|
71
|
+
for (const filePath of sortByNestedParams(files)) {
|
106
72
|
const fullPath = path.join(directoryPath, filePath);
|
107
|
-
const file = await import(fullPath);
|
73
|
+
const file = await import(pathToFileURL(fullPath).href);
|
108
74
|
const importName = typeof getImportName === "string" ? getImportName : getImportName(file);
|
109
|
-
|
110
|
-
|
111
|
-
|
75
|
+
const importedValue = file[importName];
|
76
|
+
if (!importedValue) {
|
77
|
+
if (options?.skipImportErrors) continue;
|
112
78
|
throw new Error(`${filePath} don't provide export ${importName}`);
|
79
|
+
}
|
113
80
|
const url = transformToUrl(filePath);
|
114
81
|
const groupOptions = schema ? schema({ path: filePath, url }) : {};
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
if (importedValue instanceof Elysia)
|
82
|
+
if (typeof importedValue === "function")
|
83
|
+
if (importedValue.length > 0)
|
84
|
+
plugin.group(url, groupOptions, importedValue);
|
85
|
+
else plugin.group(url, groupOptions, (app) => app.use(importedValue()));
|
86
|
+
else if (importedValue instanceof Elysia)
|
121
87
|
plugin.group(url, groupOptions, (app) => app.use(importedValue));
|
122
|
-
if (types)
|
123
|
-
paths.push(fullPath.replace(directoryPath, ""));
|
88
|
+
if (types) paths.push([fullPath.replace(directoryPath, ""), importName]);
|
124
89
|
}
|
125
90
|
if (types) {
|
126
91
|
for await (const outputPath of types.output) {
|
127
92
|
const outputAbsolutePath = getPath(outputPath);
|
128
93
|
const imports = paths.map(
|
129
|
-
(x, index) => `import type Route${index} from "${addRelativeIfNotDot(
|
94
|
+
([x, exportName], index) => `import type ${exportName === "default" ? `Route${index}` : `{ ${exportName} as Route${index} }`} from "${addRelativeIfNotDot(
|
130
95
|
path.relative(
|
131
96
|
path.dirname(outputAbsolutePath),
|
132
|
-
directoryPath + x.replace(
|
133
|
-
).
|
97
|
+
directoryPath + x.replace(/\.(ts|tsx)$/, "")
|
98
|
+
).replaceAll("\\", "/")
|
134
99
|
)}";`
|
135
100
|
);
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
101
|
+
const input = [
|
102
|
+
`import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
|
103
|
+
imports.join("\n"),
|
104
|
+
"",
|
105
|
+
!types.useExport ? "declare global {" : "",
|
106
|
+
` export type ${types.typeName} = ${paths.map(
|
107
|
+
([x], index) => `ElysiaWithBaseUrl<"${((prefix?.endsWith("/") ? prefix.slice(0, -1) : prefix) ?? "") + transformToUrl(x) || "/"}", typeof Route${index}>`
|
108
|
+
).join("\n & ")}`,
|
109
|
+
!types.useExport ? "}" : ""
|
110
|
+
].join("\n");
|
111
|
+
if (typeof Bun === "undefined") {
|
112
|
+
fs.writeFileSync(outputAbsolutePath, input);
|
113
|
+
} else {
|
114
|
+
await Bun.write(outputAbsolutePath, input);
|
115
|
+
}
|
149
116
|
}
|
150
117
|
}
|
151
118
|
return plugin;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "elysia-autoload",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.0",
|
4
4
|
"author": "kravetsone",
|
5
5
|
"type": "module",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -29,20 +29,25 @@
|
|
29
29
|
"scripts": {
|
30
30
|
"prepublishOnly": "bun test && bunx pkgroll",
|
31
31
|
"lint": "bunx @biomejs/biome check src",
|
32
|
-
"lint:fix": "bun lint --apply"
|
33
|
-
"prepare": "bunx husky"
|
32
|
+
"lint:fix": "bun lint --apply"
|
34
33
|
},
|
35
34
|
"files": ["dist"],
|
36
35
|
"devDependencies": {
|
37
|
-
"@biomejs/biome": "1.
|
38
|
-
"@elysiajs/eden": "^1.
|
39
|
-
"@elysiajs/swagger": "^1.
|
40
|
-
"@types/bun": "^1.1.
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
36
|
+
"@biomejs/biome": "1.9.4",
|
37
|
+
"@elysiajs/eden": "^1.2.0",
|
38
|
+
"@elysiajs/swagger": "^1.2.0",
|
39
|
+
"@types/bun": "^1.1.14",
|
40
|
+
"@types/node": "^22.10.2",
|
41
|
+
"elysia": "^1.2.9",
|
42
|
+
"pkgroll": "2.5.1",
|
43
|
+
"typescript": "^5.7.2",
|
44
|
+
"@elysiajs/node": "^1.2.3"
|
44
45
|
},
|
45
46
|
"peerDependencies": {
|
46
|
-
"elysia": "^1.
|
47
|
+
"elysia": "^1.2.0"
|
48
|
+
},
|
49
|
+
"engines": {
|
50
|
+
"node": ">=22",
|
51
|
+
"bun": ">=1.0.0"
|
47
52
|
}
|
48
53
|
}
|