elysia-autoload 1.4.0 → 1.5.1

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 CHANGED
@@ -1,6 +1,16 @@
1
1
  # elysia-autoload
2
2
 
3
- 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) support!
3
+ <div align="center">
4
+
5
+ [![npm](https://img.shields.io/npm/v/elysia-autoload?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/elysia-autoload)
6
+ [![npm downloads](https://img.shields.io/npm/dw/elysia-autoload?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/elysia-autoload)
7
+
8
+ <!-- [![JSR](https://jsr.io/badges/elysia-autoload)](https://jsr.io/elysia-autoload)
9
+ [![JSR Score](https://jsr.io/badges/elysia-autoload/score)](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!
4
14
 
5
15
  ## Installation
6
16
 
@@ -42,7 +52,7 @@ export type ElysiaApp = typeof app;
42
52
  // routes/index.ts
43
53
  import type { ElysiaApp } from "app";
44
54
 
45
- export default (app: ElysiaApp) => app.get("/", { hello: "world" });
55
+ export default (app: ElysiaApp) => app.get("", { hello: "world" });
46
56
  ```
47
57
 
48
58
  ### Directory structure
package/dist/index.d.ts CHANGED
@@ -1,5 +1,663 @@
1
1
  import Elysia, { RouteBase, RouteSchema, AnyElysia, LocalHook, InputSchema, SingletonBase, BaseMacro, Elysia as Elysia$1 } from 'elysia';
2
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
+ }
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
  } : {
@@ -16,7 +674,7 @@ type FlattenIndexRoutes<T> = T extends object ? {
16
674
  } & (T extends {
17
675
  index: infer I;
18
676
  } ? I extends ElysiaMatch.RouteEnd ? FlattenIndexRoutes<I> : T : T) : T;
19
- type ElysiaWithBaseUrl<BaseUrl extends string, ElysiaType extends ElysiaMatch.All> = ElysiaMatch.Extract<ElysiaType> extends Elysia<infer BasePath, infer Scoped, infer Singleton, infer Definitions, infer Metadata, infer Routes, infer Ephemeral, infer Volatile> ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, FlattenIndexRoutes<PathToObject<BaseUrl, Routes>>, Ephemeral, Volatile> : never;
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;
20
678
  type SoftString<T extends string> = T | (string & {});
21
679
 
22
680
  type SchemaHandler = ({ path, url, }: {
@@ -54,18 +712,19 @@ interface AutoloadOptions {
54
712
  */
55
713
  skipImportErrors?: boolean;
56
714
  }
57
- declare function autoload(options?: AutoloadOptions): Promise<Elysia$1<string, false, {
715
+ declare function autoload(options?: AutoloadOptions): Promise<Elysia$1<string, {
58
716
  decorator: {};
59
717
  store: {};
60
718
  derive: {};
61
719
  resolve: {};
62
720
  }, {
63
- type: {};
721
+ typebox: TModule<{}>;
64
722
  error: {};
65
723
  }, {
66
724
  schema: {};
67
725
  macro: {};
68
726
  macroFn: {};
727
+ parser: {};
69
728
  }, {}, {
70
729
  derive: {};
71
730
  resolve: {};
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
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) {
@@ -9,36 +10,7 @@ function getPath(dir) {
9
10
  return path.join(process.cwd(), process.argv[1], "..", dir);
10
11
  }
11
12
  function transformToUrl(path2) {
12
- const replacements = [
13
- // Clean the url extensions
14
- { regex: /\.(ts|tsx|js|jsx|mjs|cjs)$/u, replacement: "" },
15
- // Fix windows slashes
16
- { regex: /\\/gu, replacement: "/" },
17
- // Handle wild card based routes - users/[...id]/profile.ts -> users/*/profile
18
- { regex: /\[\.\.\..*\]/gu, replacement: "*" },
19
- // Handle generic square bracket based routes - users/[id]/index.ts -> users/:id
20
- {
21
- regex: /\[(.*?)\]/gu,
22
- replacement: (_, match) => `:${match}`
23
- },
24
- {
25
- regex: /\/?\((.*)\)/,
26
- replacement: ""
27
- },
28
- // Handle the case when multiple parameters are present in one file
29
- // users / [id] - [name].ts to users /: id -:name and users / [id] - [name] / [age].ts to users /: id -: name /: age
30
- { regex: /\]-\[/gu, replacement: "-:" },
31
- { regex: /\]\//gu, replacement: "/" },
32
- { regex: /\[/gu, replacement: "" },
33
- { regex: /\]/gu, replacement: "" },
34
- // remove index from end of path
35
- { regex: /\/?index$/, replacement: "" }
36
- ];
37
- let url = path2;
38
- for (const { regex, replacement } of replacements) {
39
- url = url.replace(regex, replacement);
40
- }
41
- 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$/, "");
42
14
  }
43
15
  function getParamsCount(path2) {
44
16
  return path2.match(/\[(.*?)\]/gu)?.length || 0;
@@ -54,6 +26,10 @@ function addRelativeIfNotDot(path2) {
54
26
  if (path2.at(0) !== ".") return `./${path2}`;
55
27
  return path2;
56
28
  }
29
+ const IS_BUN = typeof Bun !== "undefined";
30
+ function globSync(globPattern, globOptions) {
31
+ return IS_BUN ? Array.from(new Bun.Glob(globPattern).scanSync(globOptions)) : fs.globSync(globPattern, globOptions);
32
+ }
57
33
 
58
34
  const DIR_ROUTES_DEFAULT = "./routes";
59
35
  const TYPES_OUTPUT_DEFAULT = "./routes-types.ts";
@@ -88,32 +64,30 @@ async function autoload(options = {}) {
88
64
  types
89
65
  }
90
66
  });
91
- const glob = new Bun.Glob(pattern || "**/*.{ts,tsx,js,jsx,mjs,cjs}");
92
- const files = await Array.fromAsync(
93
- glob.scan({
94
- cwd: directoryPath
95
- })
96
- );
67
+ const globPattern = pattern || "**/*.{ts,tsx,js,jsx,mjs,cjs}";
68
+ const globOptions = { cwd: directoryPath };
69
+ const files = globSync(globPattern, globOptions);
97
70
  if (failGlob && files.length === 0)
98
71
  throw new Error(
99
72
  `No matches found in ${directoryPath}. You can disable this error by setting the failGlob parameter to false in the options of autoload plugin`
100
73
  );
101
74
  const paths = [];
102
- for await (const filePath of sortByNestedParams(files)) {
75
+ for (const filePath of sortByNestedParams(files)) {
103
76
  const fullPath = path.join(directoryPath, filePath);
104
- const file = await import(fullPath);
77
+ const file = await import(pathToFileURL(fullPath).href);
105
78
  const importName = typeof getImportName === "string" ? getImportName : getImportName(file);
106
- if (!file[importName] && options?.skipImportErrors) continue;
107
- if (!file[importName])
79
+ const importedValue = file[importName];
80
+ if (!importedValue) {
81
+ if (options?.skipImportErrors) continue;
108
82
  throw new Error(`${filePath} don't provide export ${importName}`);
83
+ }
109
84
  const url = transformToUrl(filePath);
110
85
  const groupOptions = schema ? schema({ path: filePath, url }) : {};
111
- const importedValue = file[importName];
112
- if (typeof importedValue === "function" && importedValue.length)
113
- plugin.group(url, groupOptions, importedValue);
114
- if (typeof importedValue === "function" && !importedValue.length)
115
- plugin.group(url, groupOptions, (app) => app.use(importedValue()));
116
- if (importedValue instanceof Elysia)
86
+ if (typeof importedValue === "function")
87
+ if (importedValue.length > 0)
88
+ plugin.group(url, groupOptions, importedValue);
89
+ else plugin.group(url, groupOptions, (app) => app.use(importedValue()));
90
+ else if (importedValue instanceof Elysia)
117
91
  plugin.group(url, groupOptions, (app) => app.use(importedValue));
118
92
  if (types) paths.push([fullPath.replace(directoryPath, ""), importName]);
119
93
  }
@@ -124,23 +98,25 @@ async function autoload(options = {}) {
124
98
  ([x, exportName], index) => `import type ${exportName === "default" ? `Route${index}` : `{ ${exportName} as Route${index} }`} from "${addRelativeIfNotDot(
125
99
  path.relative(
126
100
  path.dirname(outputAbsolutePath),
127
- directoryPath + x.replace(".ts", "").replace(".tsx", "")
128
- ).replace(/\\/gu, "/")
101
+ directoryPath + x.replace(/\.(ts|tsx)$/, "")
102
+ ).replaceAll("\\", "/")
129
103
  )}";`
130
104
  );
131
- await Bun.write(
132
- outputAbsolutePath,
133
- [
134
- `import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
135
- imports.join("\n"),
136
- "",
137
- !types.useExport ? "declare global {" : "",
138
- ` export type ${types.typeName} = ${paths.map(
139
- ([x], index) => `ElysiaWithBaseUrl<"${((prefix?.endsWith("/") ? prefix.slice(0, -1) : prefix) ?? "") + transformToUrl(x) || "/"}", typeof Route${index}>`
140
- ).join("\n & ")}`,
141
- !types.useExport ? "}" : ""
142
- ].join("\n")
143
- );
105
+ const input = [
106
+ `import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
107
+ imports.join("\n"),
108
+ "",
109
+ !types.useExport ? "declare global {" : "",
110
+ ` export type ${types.typeName} = ${paths.map(
111
+ ([x], index) => `ElysiaWithBaseUrl<"${((prefix?.endsWith("/") ? prefix.slice(0, -1) : prefix) ?? "") + transformToUrl(x) || "/"}", typeof Route${index}>`
112
+ ).join("\n & ")}`,
113
+ !types.useExport ? "}" : ""
114
+ ].join("\n");
115
+ if (typeof Bun === "undefined") {
116
+ fs.writeFileSync(outputAbsolutePath, input);
117
+ } else {
118
+ await Bun.write(outputAbsolutePath, input);
119
+ }
144
120
  }
145
121
  }
146
122
  return plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elysia-autoload",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "author": "kravetsone",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -33,15 +33,21 @@
33
33
  },
34
34
  "files": ["dist"],
35
35
  "devDependencies": {
36
- "@biomejs/biome": "1.9.2",
37
- "@elysiajs/eden": "^1.1.3",
38
- "@elysiajs/swagger": "^1.1.1",
39
- "@types/bun": "^1.1.9",
40
- "elysia": "^1.1.13",
41
- "pkgroll": "^2.5.0",
42
- "typescript": "^5.6.2"
36
+ "@biomejs/biome": "^1.9.4",
37
+ "@elysiajs/eden": "^1.2.0",
38
+ "@elysiajs/swagger": "^1.2.0",
39
+ "@types/bun": "^1.1.15",
40
+ "@types/node": "^22.10.5",
41
+ "elysia": "^1.2.10",
42
+ "pkgroll": "^2.6.1",
43
+ "typescript": "^5.7.2",
44
+ "@elysiajs/node": "^1.2.3"
43
45
  },
44
46
  "peerDependencies": {
45
- "elysia": "^1.1.0"
47
+ "elysia": "^1.2.0"
48
+ },
49
+ "engines": {
50
+ "node": ">=22",
51
+ "bun": ">=1.0.0"
46
52
  }
47
53
  }