elysia 0.8.10 → 0.8.11

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.
Files changed (74) hide show
  1. package/dist/bun/index-NDG7Wihu.d.ts +2090 -0
  2. package/dist/bun/index.d.ts +7 -1125
  3. package/dist/bun/index.js +107 -107
  4. package/dist/bun/index.js.map +16 -150
  5. package/dist/cjs/compose.d.ts +19 -12
  6. package/dist/cjs/compose.js +2074 -1104
  7. package/dist/cjs/context.d.ts +7 -58
  8. package/dist/cjs/context.js +17 -2
  9. package/dist/cjs/cookie.d.ts +7 -136
  10. package/dist/cjs/cookie.js +321 -262
  11. package/dist/cjs/dynamic-handle.d.ts +13 -8
  12. package/dist/cjs/dynamic-handle.js +1232 -261
  13. package/dist/cjs/error.d.ts +7 -106
  14. package/dist/cjs/error.js +221 -120
  15. package/dist/cjs/handler.d.ts +7 -9
  16. package/dist/cjs/handler.js +758 -492
  17. package/dist/cjs/index-NDG7Wihu.d.ts +2090 -0
  18. package/dist/cjs/index.d.ts +7 -1125
  19. package/dist/cjs/index.js +5178 -1645
  20. package/dist/cjs/trace.d.ts +11 -2
  21. package/dist/cjs/trace.js +220 -197
  22. package/dist/cjs/type-system.d.ts +6 -64
  23. package/dist/cjs/type-system.js +270 -225
  24. package/dist/cjs/types.d.ts +7 -451
  25. package/dist/cjs/types.js +17 -10
  26. package/dist/cjs/utils.d.ts +7 -93
  27. package/dist/cjs/utils.js +481 -393
  28. package/dist/cjs/ws/index.d.ts +7 -32
  29. package/dist/cjs/ws/index.js +205 -87
  30. package/dist/cjs/ws/types.d.ts +7 -60
  31. package/dist/cjs/ws/types.js +17 -2
  32. package/dist/compose.d.ts +19 -12
  33. package/dist/compose.js +2111 -197
  34. package/dist/context.d.ts +7 -58
  35. package/dist/context.js +0 -1
  36. package/dist/cookie.d.ts +7 -136
  37. package/dist/cookie.js +301 -1
  38. package/dist/dynamic-handle.d.ts +13 -8
  39. package/dist/dynamic-handle.js +1227 -1
  40. package/dist/error.d.ts +7 -106
  41. package/dist/error.js +192 -1
  42. package/dist/handler.d.ts +7 -9
  43. package/dist/handler.js +756 -1
  44. package/dist/index-NDG7Wihu.d.ts +2090 -0
  45. package/dist/index.d.ts +7 -1125
  46. package/dist/index.js +5240 -11
  47. package/dist/trace.d.ts +11 -2
  48. package/dist/trace.js +203 -1
  49. package/dist/type-system.d.ts +6 -64
  50. package/dist/type-system.js +266 -1
  51. package/dist/types.d.ts +7 -451
  52. package/dist/types.js +0 -1
  53. package/dist/utils.d.ts +7 -93
  54. package/dist/utils.js +464 -1
  55. package/dist/ws/index.d.ts +7 -32
  56. package/dist/ws/index.js +182 -1
  57. package/dist/ws/types.d.ts +7 -60
  58. package/dist/ws/types.js +0 -1
  59. package/package.json +28 -31
  60. package/trace/trace.json +2671 -0
  61. package/trace/types.json +42825 -0
  62. package/dist/cjs/compose.js.map +0 -1
  63. package/dist/cjs/context.js.map +0 -1
  64. package/dist/cjs/cookie.js.map +0 -1
  65. package/dist/cjs/dynamic-handle.js.map +0 -1
  66. package/dist/cjs/error.js.map +0 -1
  67. package/dist/cjs/handler.js.map +0 -1
  68. package/dist/cjs/index.js.map +0 -1
  69. package/dist/cjs/trace.js.map +0 -1
  70. package/dist/cjs/type-system.js.map +0 -1
  71. package/dist/cjs/types.js.map +0 -1
  72. package/dist/cjs/utils.js.map +0 -1
  73. package/dist/cjs/ws/index.js.map +0 -1
  74. package/dist/cjs/ws/types.js.map +0 -1
@@ -0,0 +1,2090 @@
1
+ import { Serve, WebSocketHandler, Server, ServerWebSocket } from 'bun';
2
+ import * as _sinclair_typebox from '@sinclair/typebox';
3
+ import { TSchema, Static, TAnySchema, TObject, NumberOptions, SchemaOptions, TNumber, TProperties, ObjectOptions, TUnion, TNull, TUndefined } from '@sinclair/typebox';
4
+ import { TypeCheck } from '@sinclair/typebox/compiler';
5
+ import '@sinclair/typebox/system';
6
+ import { OpenAPIV3 } from 'openapi-types';
7
+ import { EventEmitter } from 'eventemitter3';
8
+
9
+ interface CookieOptions {
10
+ /**
11
+ * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
12
+ * domain is set, and most clients will consider the cookie to apply to only
13
+ * the current domain.
14
+ */
15
+ domain?: string | undefined;
16
+ /**
17
+ * Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
18
+ * no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
19
+ * it on a condition like exiting a web browser application.
20
+ *
21
+ * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
22
+ * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
23
+ * possible not all clients by obey this, so if both are set, they should
24
+ * point to the same date and time.
25
+ */
26
+ expires?: Date | undefined;
27
+ /**
28
+ * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
29
+ * When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
30
+ * default, the `HttpOnly` attribute is not set.
31
+ *
32
+ * *Note* be careful when setting this to true, as compliant clients will
33
+ * not allow client-side JavaScript to see the cookie in `document.cookie`.
34
+ */
35
+ httpOnly?: boolean | undefined;
36
+ /**
37
+ * Specifies the number (in seconds) to be the value for the `Max-Age`
38
+ * `Set-Cookie` attribute. The given number will be converted to an integer
39
+ * by rounding down. By default, no maximum age is set.
40
+ *
41
+ * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
42
+ * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
43
+ * possible not all clients by obey this, so if both are set, they should
44
+ * point to the same date and time.
45
+ */
46
+ maxAge?: number | undefined;
47
+ /**
48
+ * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
49
+ * By default, the path is considered the "default path".
50
+ */
51
+ path?: string | undefined;
52
+ /**
53
+ * Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
54
+ *
55
+ * - `'low'` will set the `Priority` attribute to `Low`.
56
+ * - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
57
+ * - `'high'` will set the `Priority` attribute to `High`.
58
+ *
59
+ * More information about the different priority levels can be found in
60
+ * [the specification][rfc-west-cookie-priority-00-4.1].
61
+ *
62
+ * **note** This is an attribute that has not yet been fully standardized, and may change in the future.
63
+ * This also means many clients may ignore this attribute until they understand it.
64
+ */
65
+ priority?: 'low' | 'medium' | 'high' | undefined;
66
+ /**
67
+ * Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
68
+ *
69
+ * - `true` will set the `SameSite` attribute to `Strict` for strict same
70
+ * site enforcement.
71
+ * - `false` will not set the `SameSite` attribute.
72
+ * - `'lax'` will set the `SameSite` attribute to Lax for lax same site
73
+ * enforcement.
74
+ * - `'strict'` will set the `SameSite` attribute to Strict for strict same
75
+ * site enforcement.
76
+ * - `'none'` will set the SameSite attribute to None for an explicit
77
+ * cross-site cookie.
78
+ *
79
+ * More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
80
+ *
81
+ * *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
82
+ */
83
+ sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined;
84
+ /**
85
+ * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
86
+ * `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
87
+ *
88
+ * *Note* be careful when setting this to `true`, as compliant clients will
89
+ * not send the cookie back to the server in the future if the browser does
90
+ * not have an HTTPS connection.
91
+ */
92
+ secure?: boolean | undefined;
93
+ /**
94
+ * Secret key for signing cookie
95
+ *
96
+ * If array is passed, will use Key Rotation.
97
+ *
98
+ * Key rotation is when an encryption key is retired
99
+ * and replaced by generating a new cryptographic key.
100
+ */
101
+ secrets?: string | string[];
102
+ }
103
+ type MutateCookie<T = unknown> = CookieOptions & {
104
+ value?: T;
105
+ } extends infer A ? A | ((previous: A) => A) : never;
106
+ type CookieJar = Record<string, Cookie>;
107
+ declare class Cookie<T = unknown> implements CookieOptions {
108
+ private _value;
109
+ property: Readonly<CookieOptions>;
110
+ name: string | undefined;
111
+ private setter;
112
+ constructor(_value: T, property?: Readonly<CookieOptions>);
113
+ get(): T;
114
+ get value(): T;
115
+ set value(value: T);
116
+ add<T>(config: MutateCookie<T>): Cookie<T>;
117
+ set<T>(config: MutateCookie): Cookie<T>;
118
+ remove(options?: Pick<CookieOptions, 'domain' | 'path' | 'sameSite' | 'secure'>): void;
119
+ get domain(): string | undefined;
120
+ set domain(value: string | undefined);
121
+ get expires(): Date | undefined;
122
+ set expires(value: Date | undefined);
123
+ get httpOnly(): boolean | undefined;
124
+ set httpOnly(value: boolean | undefined);
125
+ get maxAge(): number | undefined;
126
+ set maxAge(value: number | undefined);
127
+ get path(): string | undefined;
128
+ set path(value: string | undefined);
129
+ get priority(): "low" | "medium" | "high" | undefined;
130
+ set priority(value: "low" | "medium" | "high" | undefined);
131
+ get sameSite(): boolean | "lax" | "strict" | "none" | undefined;
132
+ set sameSite(value: boolean | "lax" | "strict" | "none" | undefined);
133
+ get secure(): boolean | undefined;
134
+ set secure(value: boolean | undefined);
135
+ toString(): string;
136
+ private sync;
137
+ }
138
+ declare const createCookieJar: (initial: CookieJar, set: Context['set'], properties?: CookieOptions) => CookieJar;
139
+ declare const parseCookie: (set: Context['set'], cookieString?: string | null, { secret, sign, ...properties }?: CookieOptions & {
140
+ secret?: string | string[] | undefined;
141
+ sign?: string | true | string[] | undefined;
142
+ }) => Promise<CookieJar>;
143
+
144
+ declare const ERROR_CODE: unique symbol;
145
+ declare const ELYSIA_RESPONSE: unique symbol;
146
+ declare const isProduction: boolean;
147
+ type ElysiaErrors = InternalServerError | NotFoundError | ParseError | ValidationError | InvalidCookieSignature;
148
+ declare const error: <const Code extends number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", const T>(code: Code, response: T) => {
149
+ response: T;
150
+ [ELYSIA_RESPONSE]: Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
151
+ readonly Continue: 100;
152
+ readonly 'Switching Protocols': 101;
153
+ readonly Processing: 102;
154
+ readonly 'Early Hints': 103;
155
+ readonly OK: 200;
156
+ readonly Created: 201;
157
+ readonly Accepted: 202;
158
+ readonly 'Non-Authoritative Information': 203;
159
+ readonly 'No Content': 204;
160
+ readonly 'Reset Content': 205;
161
+ readonly 'Partial Content': 206;
162
+ readonly 'Multi-Status': 207;
163
+ readonly 'Already Reported': 208;
164
+ readonly 'Multiple Choices': 300;
165
+ readonly 'Moved Permanently': 301;
166
+ readonly Found: 302;
167
+ readonly 'See Other': 303;
168
+ readonly 'Not Modified': 304;
169
+ readonly 'Temporary Redirect': 307;
170
+ readonly 'Permanent Redirect': 308;
171
+ readonly 'Bad Request': 400;
172
+ readonly Unauthorized: 401;
173
+ readonly 'Payment Required': 402;
174
+ readonly Forbidden: 403;
175
+ readonly 'Not Found': 404;
176
+ readonly 'Method Not Allowed': 405;
177
+ readonly 'Not Acceptable': 406;
178
+ readonly 'Proxy Authentication Required': 407;
179
+ readonly 'Request Timeout': 408;
180
+ readonly Conflict: 409;
181
+ readonly Gone: 410;
182
+ readonly 'Length Required': 411;
183
+ readonly 'Precondition Failed': 412;
184
+ readonly 'Payload Too Large': 413;
185
+ readonly 'URI Too Long': 414;
186
+ readonly 'Unsupported Media Type': 415;
187
+ readonly 'Range Not Satisfiable': 416;
188
+ readonly 'Expectation Failed': 417;
189
+ readonly "I'm a teapot": 418;
190
+ readonly 'Misdirected Request': 421;
191
+ readonly 'Unprocessable Content': 422;
192
+ readonly Locked: 423;
193
+ readonly 'Failed Dependency': 424;
194
+ readonly 'Too Early': 425;
195
+ readonly 'Upgrade Required': 426;
196
+ readonly 'Precondition Required': 428;
197
+ readonly 'Too Many Requests': 429;
198
+ readonly 'Request Header Fields Too Large': 431;
199
+ readonly 'Unavailable For Legal Reasons': 451;
200
+ readonly 'Internal Server Error': 500;
201
+ readonly 'Not Implemented': 501;
202
+ readonly 'Bad Gateway': 502;
203
+ readonly 'Service Unavailable': 503;
204
+ readonly 'Gateway Timeout': 504;
205
+ readonly 'HTTP Version Not Supported': 505;
206
+ readonly 'Variant Also Negotiates': 506;
207
+ readonly 'Insufficient Storage': 507;
208
+ readonly 'Loop Detected': 508;
209
+ readonly 'Not Extended': 510;
210
+ readonly 'Network Authentication Required': 511;
211
+ }[Code] : Code;
212
+ };
213
+ declare class InternalServerError extends Error {
214
+ code: string;
215
+ status: number;
216
+ constructor(message?: string);
217
+ }
218
+ declare class NotFoundError extends Error {
219
+ code: string;
220
+ status: number;
221
+ constructor(message?: string);
222
+ }
223
+ declare class ParseError extends Error {
224
+ code: string;
225
+ status: number;
226
+ constructor(message?: string);
227
+ }
228
+ declare class InvalidCookieSignature extends Error {
229
+ key: string;
230
+ code: string;
231
+ status: number;
232
+ constructor(key: string, message?: string);
233
+ }
234
+ declare class ValidationError extends Error {
235
+ type: string;
236
+ validator: TSchema | TypeCheck<any>;
237
+ value: unknown;
238
+ code: string;
239
+ status: number;
240
+ constructor(type: string, validator: TSchema | TypeCheck<any>, value: unknown);
241
+ get all(): any[];
242
+ static simplifyModel(validator: TSchema | TypeCheck<any>): any;
243
+ get model(): any;
244
+ toResponse(headers?: Record<string, any>): Response;
245
+ }
246
+
247
+ type HeadersInit = string[][] | Record<string, string | ReadonlyArray<string>> | Headers;
248
+ type ElysiaConfig<T extends string = '', Scoped extends boolean = false> = {
249
+ name?: string;
250
+ seed?: unknown;
251
+ serve?: Partial<Serve>;
252
+ prefix?: T;
253
+ /**
254
+ * Disable `new Error` thrown marked as Error on Bun 0.6
255
+ */
256
+ forceErrorEncapsulation?: boolean;
257
+ /**
258
+ * Disable Ahead of Time compliation
259
+ *
260
+ * Reduced performance but faster startup time
261
+ */
262
+ aot?: boolean;
263
+ /**
264
+ * Whether should Elysia tolerate suffix '/' or vice-versa
265
+ *
266
+ * @default false
267
+ */
268
+ strictPath?: boolean;
269
+ /**
270
+ * If set to true, other Elysia handler will not inherits global life-cycle, store, decorators from the current instance
271
+ *
272
+ * @default false
273
+ */
274
+ scoped?: Scoped;
275
+ websocket?: Omit<WebSocketHandler<any>, 'open' | 'close' | 'message' | 'drain'>;
276
+ cookie?: CookieOptions & {
277
+ /**
278
+ * Specified cookie name to be signed globally
279
+ */
280
+ sign?: true | string | string[];
281
+ };
282
+ /**
283
+ * Capture more detail information for each dependencies
284
+ */
285
+ analytic?: boolean;
286
+ };
287
+ type MaybeArray$1<T> = T | T[];
288
+ type MaybePromise<T> = T | Promise<T>;
289
+ type ObjectValues<T extends object> = T[keyof T];
290
+ /**
291
+ * @link https://stackoverflow.com/a/49928360/1490091
292
+ */
293
+ type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}` ? Parameter : Part extends `*` ? '*' : never;
294
+ type GetPathParameter<Path extends string> = Path extends `${infer A}/${infer B}` ? IsPathParameter<A> | GetPathParameter<B> : IsPathParameter<Path>;
295
+ type Prettify<T> = {
296
+ [K in keyof T]: T[K];
297
+ } & {};
298
+ type Reconcile<A extends Object, B extends Object> = {
299
+ [key in keyof A as key extends keyof B ? never : key]: A[key];
300
+ } extends infer Collision ? {} extends Collision ? {
301
+ [key in keyof B]: B[key];
302
+ } : Prettify<Collision & {
303
+ [key in keyof B]: B[key];
304
+ }> : never;
305
+ type DecoratorBase = {
306
+ request: {
307
+ [x: string]: unknown;
308
+ };
309
+ store: {
310
+ [x: string]: unknown;
311
+ };
312
+ derive: {
313
+ [x: string]: unknown;
314
+ };
315
+ resolve: {
316
+ [x: string]: unknown;
317
+ };
318
+ };
319
+ type DefinitionBase = {
320
+ type: {
321
+ [x: string]: unknown;
322
+ };
323
+ error: {
324
+ [x: string]: Error;
325
+ };
326
+ };
327
+ type RouteBase = {
328
+ [path: string]: {
329
+ [method: string]: RouteSchema;
330
+ };
331
+ };
332
+ interface RouteSchema {
333
+ body?: unknown;
334
+ headers?: unknown;
335
+ query?: unknown;
336
+ params?: unknown;
337
+ cookie?: unknown;
338
+ response?: unknown;
339
+ }
340
+ type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends DefinitionBase['type'] = {}> = Schema extends undefined ? unknown : Schema extends TSchema ? Static<NonNullable<Schema>> : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Definitions : unknown;
341
+ type UnwrapRoute<Schema extends InputSchema<any>, Definitions extends DefinitionBase['type'] = {}> = {
342
+ body: UnwrapSchema<Schema['body'], Definitions>;
343
+ headers: UnwrapSchema<Schema['headers'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
344
+ query: UnwrapSchema<Schema['query'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
345
+ params: UnwrapSchema<Schema['params'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
346
+ cookie: UnwrapSchema<Schema['cookie'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
347
+ response: Schema['response'] extends TSchema | string ? UnwrapSchema<Schema['response'], Definitions> : Schema['response'] extends {
348
+ 200: TAnySchema | string;
349
+ } ? {
350
+ [k in keyof Schema['response']]: UnwrapSchema<Schema['response'][k], Definitions>;
351
+ } : unknown | void;
352
+ };
353
+ type UnwrapGroupGuardRoute<Schema extends InputSchema<any>, Definitions extends DefinitionBase['type'] = {}, Path extends string = ''> = {
354
+ body: UnwrapSchema<Schema['body'], Definitions>;
355
+ headers: UnwrapSchema<Schema['headers'], Definitions> extends infer A extends Record<string, unknown> ? A : undefined;
356
+ query: UnwrapSchema<Schema['query'], Definitions> extends infer A extends Record<string, unknown> ? A : undefined;
357
+ params: UnwrapSchema<Schema['params'], Definitions> extends infer A extends Record<string, unknown> ? A : Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never;
358
+ cookie: UnwrapSchema<Schema['cookie'], Definitions> extends infer A extends Record<string, unknown> ? A : undefined;
359
+ response: Schema['response'] extends TSchema | string ? UnwrapSchema<Schema['response'], Definitions> : Schema['response'] extends {
360
+ [k in string]: TSchema | string;
361
+ } ? UnwrapSchema<ObjectValues<Schema['response']>, Definitions> : unknown | void;
362
+ };
363
+ interface LifeCycleStore {
364
+ type?: ContentType;
365
+ start: GracefulHandler<any>[];
366
+ request: PreHandler<any, any>[];
367
+ parse: BodyHandler<any, any>[];
368
+ transform: TransformHandler<any, any>[];
369
+ beforeHandle: OptionalHandler<any, any>[];
370
+ afterHandle: AfterHandler<any, any>[];
371
+ mapResponse: MapResponse<any, any>[];
372
+ onResponse: VoidHandler<any, any>[];
373
+ trace: TraceHandler<any, any>[];
374
+ error: ErrorHandler<any, any, any>[];
375
+ stop: GracefulHandler<any>[];
376
+ }
377
+ type LifeCycleEvent = 'start' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'response' | 'error' | 'stop';
378
+ type ContentType = MaybeArray$1<(string & {}) | 'none' | 'text' | 'json' | 'formdata' | 'urlencoded' | 'arrayBuffer' | 'text/plain' | 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'>;
379
+ type HTTPMethod = (string & {}) | 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE' | 'ALL';
380
+ interface InputSchema<Name extends string = string> {
381
+ body?: TSchema | Name;
382
+ headers?: TObject | Name;
383
+ query?: TObject | Name;
384
+ params?: TObject | Name;
385
+ cookie?: TObject | Name;
386
+ response?: TSchema | Record<number, TSchema> | Name | Record<number, Name | TSchema>;
387
+ }
388
+ type MergeSchema<A extends RouteSchema, B extends RouteSchema> = {
389
+ body: undefined extends A['body'] ? B['body'] : A['body'];
390
+ headers: undefined extends A['headers'] ? B['headers'] : A['headers'];
391
+ query: undefined extends A['query'] ? B['query'] : A['query'];
392
+ params: undefined extends A['params'] ? B['params'] : A['params'];
393
+ cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie'];
394
+ response: undefined extends A['response'] ? B['response'] : A['response'];
395
+ };
396
+ type Handler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
397
+ request: {};
398
+ store: {};
399
+ derive: {};
400
+ resolve: {};
401
+ }, Path extends string = ''> = (context: Prettify<Context<Route, Decorators, Path>>) => Route['response'] extends {
402
+ 200: unknown;
403
+ } ? Response | MaybePromise<Route['response'][keyof Route['response']]> : Response | MaybePromise<Route['response']>;
404
+ type OptionalHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
405
+ request: {};
406
+ store: {};
407
+ derive: {};
408
+ resolve: {};
409
+ }> = Handler<Route, Decorators> extends (context: infer Context) => infer Returned ? (context: Context) => Returned | MaybePromise<void> : never;
410
+ type AfterHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
411
+ request: {};
412
+ store: {};
413
+ derive: {};
414
+ resolve: {};
415
+ }> = Handler<Route, Decorators> extends (context: infer Context) => infer Returned ? (context: Prettify<{
416
+ response: Route['response'];
417
+ } & Context>) => Returned | MaybePromise<void> : never;
418
+ type MapResponse<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
419
+ request: {};
420
+ store: {};
421
+ derive: {};
422
+ resolve: {};
423
+ }> = Handler<Omit<Route, 'response'> & {
424
+ response: MaybePromise<Response | undefined | void>;
425
+ }, Decorators & {
426
+ derive: {
427
+ response: Route['response'];
428
+ };
429
+ }>;
430
+ type VoidHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
431
+ request: {};
432
+ store: {};
433
+ derive: {};
434
+ resolve: {};
435
+ }> = (context: Prettify<Context<Route, Decorators>>) => MaybePromise<void>;
436
+ type TransformHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
437
+ request: {};
438
+ store: {};
439
+ derive: {};
440
+ resolve: {};
441
+ }> = (context: Prettify<Context<Route, Omit<Decorators, 'resolve'> & {
442
+ resolve: {};
443
+ }>>) => MaybePromise<void>;
444
+ type TraceEvent = 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'error' | 'response' extends infer Events extends string ? Events | `${Events}.unit` | 'handle' | 'exit' : never;
445
+ type TraceStream = {
446
+ id: number;
447
+ event: TraceEvent;
448
+ type: 'begin' | 'end';
449
+ time: number;
450
+ name?: string;
451
+ unit?: number;
452
+ };
453
+ type TraceReporter = EventEmitter<{
454
+ [res in `res${number}.${number}`]: undefined;
455
+ } & {
456
+ event(stream: TraceStream): MaybePromise<void>;
457
+ }>;
458
+ type TraceProcess<Type extends 'begin' | 'end' = 'begin' | 'end'> = Type extends 'begin' ? Prettify<{
459
+ name: string;
460
+ time: number;
461
+ skip: boolean;
462
+ end: Promise<TraceProcess<'end'>>;
463
+ children: Promise<TraceProcess<'begin'>>[];
464
+ }> : number;
465
+ type TraceHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
466
+ request: {};
467
+ store: {};
468
+ derive: {};
469
+ resolve: {};
470
+ }> = (lifecycle: Prettify<{
471
+ context: Context<Route, Decorators>;
472
+ set: Context['set'];
473
+ id: number;
474
+ time: number;
475
+ } & {
476
+ [x in 'request' | 'parse' | 'transform' | 'beforeHandle' | 'handle' | 'afterHandle' | 'error' | 'response']: Promise<TraceProcess<'begin'>>;
477
+ } & {
478
+ store: Decorators['store'];
479
+ }>) => MaybePromise<void>;
480
+ type TraceListener = EventEmitter<{
481
+ [event in TraceEvent | 'all']: (trace: TraceProcess) => MaybePromise<void>;
482
+ }>;
483
+ type BodyHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
484
+ request: {};
485
+ store: {};
486
+ derive: {};
487
+ resolve: {};
488
+ }> = (context: Prettify<Context<Route, Decorators>>, contentType: string) => MaybePromise<any>;
489
+ type PreHandler<Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
490
+ request: {};
491
+ store: {};
492
+ derive: {};
493
+ resolve: {};
494
+ }> = (context: Prettify<PreContext<Decorators>>) => MaybePromise<Route['response'] | void>;
495
+ type GracefulHandler<Instance extends Elysia<any, any, any, any, any, any, any>> = (data: Instance) => any;
496
+ type ErrorHandler<T extends Record<string, Error> = {}, Route extends RouteSchema = {}, Decorators extends DecoratorBase = {
497
+ request: {};
498
+ store: {};
499
+ derive: {};
500
+ resolve: {};
501
+ }> = (context: Prettify<Context<Route, Decorators> & ({
502
+ request: Request;
503
+ code: 'UNKNOWN';
504
+ error: Readonly<Error>;
505
+ set: Context['set'];
506
+ } | {
507
+ request: Request;
508
+ code: 'VALIDATION';
509
+ error: Readonly<ValidationError>;
510
+ set: Context['set'];
511
+ } | {
512
+ request: Request;
513
+ code: 'NOT_FOUND';
514
+ error: Readonly<NotFoundError>;
515
+ set: Context['set'];
516
+ } | {
517
+ request: Request;
518
+ code: 'PARSE';
519
+ error: Readonly<ParseError>;
520
+ set: Context['set'];
521
+ } | {
522
+ request: Request;
523
+ code: 'INTERNAL_SERVER_ERROR';
524
+ error: Readonly<InternalServerError>;
525
+ set: Context['set'];
526
+ } | {
527
+ request: Request;
528
+ code: 'INVALID_COOKIE_SIGNATURE';
529
+ error: Readonly<InvalidCookieSignature>;
530
+ set: Context['set'];
531
+ } | {
532
+ [K in keyof T]: {
533
+ request: Request;
534
+ code: K;
535
+ error: Readonly<T[K]>;
536
+ set: Context['set'];
537
+ };
538
+ }[keyof T])>) => any | Promise<any>;
539
+ type Isolate<T> = {
540
+ [P in keyof T]: T[P];
541
+ };
542
+ type LocalHook<LocalSchema extends InputSchema = {}, Route extends RouteSchema = RouteSchema, Decorators extends DecoratorBase = {
543
+ request: {};
544
+ store: {};
545
+ derive: {};
546
+ resolve: {};
547
+ }, Errors extends Record<string, Error> = {}, Extension extends BaseMacro = {}, Path extends string = '', TypedRoute extends RouteSchema = Route extends {
548
+ params: Record<string, unknown>;
549
+ } ? Route : Route & {
550
+ params: Record<GetPathParameter<Path>, string>;
551
+ }> = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) & Extension & {
552
+ /**
553
+ * Short for 'Content-Type'
554
+ *
555
+ * Available:
556
+ * - 'none': do not parse body
557
+ * - 'text' / 'text/plain': parse body as string
558
+ * - 'json' / 'application/json': parse body as json
559
+ * - 'formdata' / 'multipart/form-data': parse body as form-data
560
+ * - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
561
+ * - 'arraybuffer': parse body as readable stream
562
+ */
563
+ type?: ContentType;
564
+ detail?: Partial<OpenAPIV3.OperationObject>;
565
+ /**
566
+ * Custom body parser
567
+ */
568
+ parse?: MaybeArray$1<BodyHandler<TypedRoute, Decorators>>;
569
+ /**
570
+ * Transform context's value
571
+ */
572
+ transform?: MaybeArray$1<TransformHandler<TypedRoute, Decorators>>;
573
+ /**
574
+ * Execute before main handler
575
+ */
576
+ beforeHandle?: MaybeArray$1<OptionalHandler<TypedRoute, Decorators>>;
577
+ /**
578
+ * Execute after main handler
579
+ */
580
+ afterHandle?: MaybeArray$1<AfterHandler<TypedRoute, Decorators>>;
581
+ /**
582
+ * Execute after main handler
583
+ */
584
+ mapResponse?: MaybeArray$1<MapResponse<TypedRoute, Decorators>>;
585
+ /**
586
+ * Catch error
587
+ */
588
+ error?: MaybeArray$1<ErrorHandler<Errors, TypedRoute, Decorators>>;
589
+ /**
590
+ * Custom body parser
591
+ */
592
+ onResponse?: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>;
593
+ };
594
+ type ComposedHandler = (context: Context) => MaybePromise<Response>;
595
+ interface InternalRoute {
596
+ method: HTTPMethod;
597
+ path: string;
598
+ composed: ComposedHandler | Response | null;
599
+ handler: Handler;
600
+ hooks: LocalHook;
601
+ }
602
+ type SchemaValidator = {
603
+ body?: TypeCheck<any>;
604
+ headers?: TypeCheck<any>;
605
+ query?: TypeCheck<any>;
606
+ params?: TypeCheck<any>;
607
+ cookie?: TypeCheck<any>;
608
+ response?: Record<number, TypeCheck<any>>;
609
+ };
610
+ type ListenCallback = (server: Server) => MaybePromise<void>;
611
+ type AddPrefix<Prefix extends string, T> = {
612
+ [K in keyof T as `${Prefix}${K & string}`]: T[K];
613
+ };
614
+ type AddPrefixCapitalize<Prefix extends string, T> = {
615
+ [K in keyof T as `${Prefix}${Capitalize<K & string>}`]: T[K];
616
+ };
617
+ type AddSuffix<Suffix extends string, T> = {
618
+ [K in keyof T as `${K & string}${Suffix}`]: T[K];
619
+ };
620
+ type AddSuffixCapitalize<Suffix extends string, T> = {
621
+ [K in keyof T as `${K & string}${Capitalize<Suffix>}`]: T[K];
622
+ };
623
+ type Checksum = {
624
+ name?: string;
625
+ seed?: unknown;
626
+ checksum: number;
627
+ stack?: string;
628
+ routes?: InternalRoute[];
629
+ decorators?: DecoratorBase['request'];
630
+ store?: DecoratorBase['store'];
631
+ type?: DefinitionBase['type'];
632
+ error?: DefinitionBase['error'];
633
+ dependencies?: Record<string, Checksum[]>;
634
+ derive?: {
635
+ fn: string;
636
+ stack: string;
637
+ }[];
638
+ resolve?: {
639
+ fn: string;
640
+ stack: string;
641
+ }[];
642
+ };
643
+ type BaseMacro = Record<string, BaseMacro | ((a: any) => unknown)>;
644
+ type MacroToProperty<T extends BaseMacro> = Prettify<{
645
+ [K in keyof T]: T[K] extends Function ? T[K] extends (a: infer Params) => any ? Params | undefined : T[K] : MacroToProperty<T[K]>;
646
+ }>;
647
+ interface MacroManager<TypedRoute extends RouteSchema = {}, Decorators extends DecoratorBase = {
648
+ request: {};
649
+ store: {};
650
+ derive: {};
651
+ resolve: {};
652
+ }, Errors extends Record<string, Error> = {}> {
653
+ onParse(fn: MaybeArray$1<BodyHandler<TypedRoute, Decorators>>): unknown;
654
+ onParse(options: {
655
+ insert?: 'before' | 'after';
656
+ stack?: 'global' | 'local';
657
+ }, fn: MaybeArray$1<BodyHandler<TypedRoute, Decorators>>): unknown;
658
+ onTransform(fn: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>): unknown;
659
+ onTransform(options: {
660
+ insert?: 'before' | 'after';
661
+ stack?: 'global' | 'local';
662
+ }, fn: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>): unknown;
663
+ onBeforeHandle(fn: MaybeArray$1<OptionalHandler<TypedRoute, Decorators>>): unknown;
664
+ onBeforeHandle(options: {
665
+ insert?: 'before' | 'after';
666
+ stack?: 'global' | 'local';
667
+ }, fn: MaybeArray$1<OptionalHandler<TypedRoute, Decorators>>): unknown;
668
+ onAfterHandle(fn: MaybeArray$1<AfterHandler<TypedRoute, Decorators>>): unknown;
669
+ onAfterHandle(options: {
670
+ insert?: 'before' | 'after';
671
+ stack?: 'global' | 'local';
672
+ }, fn: MaybeArray$1<AfterHandler<TypedRoute, Decorators>>): unknown;
673
+ onError(fn: MaybeArray$1<ErrorHandler<Errors, TypedRoute, Decorators>>): unknown;
674
+ onError(options: {
675
+ insert?: 'before' | 'after';
676
+ stack?: 'global' | 'local';
677
+ }, fn: MaybeArray$1<ErrorHandler<Errors, TypedRoute, Decorators>>): unknown;
678
+ onResponse(fn: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>): unknown;
679
+ onResponse(options: {
680
+ insert?: 'before' | 'after';
681
+ stack?: 'global' | 'local';
682
+ }, fn: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>): unknown;
683
+ events: {
684
+ global: Prettify<LifeCycleStore & RouteSchema>;
685
+ local: Prettify<LifeCycleStore & RouteSchema>;
686
+ };
687
+ }
688
+
689
+ declare const replaceUrlPath: (url: string, pathname: string) => string;
690
+ declare const mergeDeep: <const A extends Record<string, any>, const B extends Record<string, any>>(target: A, source: B, { skipKeys }?: {
691
+ skipKeys?: string[] | undefined;
692
+ }) => A & B;
693
+ declare const mergeCookie: <const A extends Object, const B extends Object>(target: A, source: B) => A & B;
694
+ declare const mergeObjectArray: <T>(a: T | T[], b: T | T[]) => T[];
695
+ declare const primitiveHooks: readonly ["start", "request", "parse", "transform", "resolve", "beforeHandle", "afterHandle", "onResponse", "mapResponse", "trace", "error", "stop", "body", "headers", "params", "query", "response", "type", "detail"];
696
+ declare const mergeHook: (a?: LocalHook<any, any, any, any> | LifeCycleStore, b?: LocalHook<any, any, any, any>) => LifeCycleStore;
697
+ declare const getSchemaValidator: (s: TSchema | string | undefined, { models, additionalProperties, dynamic }: {
698
+ models?: Record<string, TSchema> | undefined;
699
+ additionalProperties?: boolean | undefined;
700
+ dynamic?: boolean | undefined;
701
+ }) => TypeCheck<TSchema> | undefined;
702
+ declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, additionalProperties, dynamic }: {
703
+ models?: Record<string, TSchema> | undefined;
704
+ additionalProperties?: boolean | undefined;
705
+ dynamic?: boolean | undefined;
706
+ }) => Record<number, TypeCheck<any>> | undefined;
707
+ declare const checksum: (s: string) => number;
708
+ declare const mergeLifeCycle: (a: LifeCycleStore, b: LifeCycleStore | LocalHook, checksum?: number) => LifeCycleStore;
709
+ declare const asGlobalHook: (hook: LocalHook<any, any>, inject?: boolean) => LocalHook<any, any>;
710
+ declare const asGlobal: <T extends MaybeArray$1<Function> | undefined>(fn: T, inject?: boolean) => T;
711
+ declare const filterGlobalHook: (hook: LocalHook<any, any>) => LocalHook<any, any>;
712
+ declare const StatusMap: {
713
+ readonly Continue: 100;
714
+ readonly 'Switching Protocols': 101;
715
+ readonly Processing: 102;
716
+ readonly 'Early Hints': 103;
717
+ readonly OK: 200;
718
+ readonly Created: 201;
719
+ readonly Accepted: 202;
720
+ readonly 'Non-Authoritative Information': 203;
721
+ readonly 'No Content': 204;
722
+ readonly 'Reset Content': 205;
723
+ readonly 'Partial Content': 206;
724
+ readonly 'Multi-Status': 207;
725
+ readonly 'Already Reported': 208;
726
+ readonly 'Multiple Choices': 300;
727
+ readonly 'Moved Permanently': 301;
728
+ readonly Found: 302;
729
+ readonly 'See Other': 303;
730
+ readonly 'Not Modified': 304;
731
+ readonly 'Temporary Redirect': 307;
732
+ readonly 'Permanent Redirect': 308;
733
+ readonly 'Bad Request': 400;
734
+ readonly Unauthorized: 401;
735
+ readonly 'Payment Required': 402;
736
+ readonly Forbidden: 403;
737
+ readonly 'Not Found': 404;
738
+ readonly 'Method Not Allowed': 405;
739
+ readonly 'Not Acceptable': 406;
740
+ readonly 'Proxy Authentication Required': 407;
741
+ readonly 'Request Timeout': 408;
742
+ readonly Conflict: 409;
743
+ readonly Gone: 410;
744
+ readonly 'Length Required': 411;
745
+ readonly 'Precondition Failed': 412;
746
+ readonly 'Payload Too Large': 413;
747
+ readonly 'URI Too Long': 414;
748
+ readonly 'Unsupported Media Type': 415;
749
+ readonly 'Range Not Satisfiable': 416;
750
+ readonly 'Expectation Failed': 417;
751
+ readonly "I'm a teapot": 418;
752
+ readonly 'Misdirected Request': 421;
753
+ readonly 'Unprocessable Content': 422;
754
+ readonly Locked: 423;
755
+ readonly 'Failed Dependency': 424;
756
+ readonly 'Too Early': 425;
757
+ readonly 'Upgrade Required': 426;
758
+ readonly 'Precondition Required': 428;
759
+ readonly 'Too Many Requests': 429;
760
+ readonly 'Request Header Fields Too Large': 431;
761
+ readonly 'Unavailable For Legal Reasons': 451;
762
+ readonly 'Internal Server Error': 500;
763
+ readonly 'Not Implemented': 501;
764
+ readonly 'Bad Gateway': 502;
765
+ readonly 'Service Unavailable': 503;
766
+ readonly 'Gateway Timeout': 504;
767
+ readonly 'HTTP Version Not Supported': 505;
768
+ readonly 'Variant Also Negotiates': 506;
769
+ readonly 'Insufficient Storage': 507;
770
+ readonly 'Loop Detected': 508;
771
+ readonly 'Not Extended': 510;
772
+ readonly 'Network Authentication Required': 511;
773
+ };
774
+ type HTTPStatusName = keyof typeof StatusMap;
775
+ declare const signCookie: (val: string, secret: string | null) => Promise<string>;
776
+ declare const unsignCookie: (input: string, secret: string | null) => Promise<string | false>;
777
+ declare const traceBackMacro: (extension: any, property: Record<string, unknown>, hooks?: Record<string, unknown>) => void;
778
+ declare const isNumericString: (message: string) => boolean;
779
+
780
+ type WithoutNullableKeys<Type> = {
781
+ [Key in keyof Type]-?: NonNullable<Type[Key]>;
782
+ };
783
+
784
+ type Context<Route extends RouteSchema = RouteSchema, Decorators extends DecoratorBase = {
785
+ request: {};
786
+ store: {};
787
+ derive: {};
788
+ resolve: {};
789
+ }, Path extends string = ''> = Prettify<{
790
+ body: Route['body'];
791
+ query: undefined extends Route['query'] ? Record<string, string | undefined> : Route['query'];
792
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
793
+ headers: undefined extends Route['headers'] ? Record<string, string | undefined> : Route['headers'];
794
+ cookie: undefined extends Route['cookie'] ? Record<string, Cookie<any>> : Record<string, Cookie<any>> & WithoutNullableKeys<{
795
+ [key in keyof Route['cookie']]: Cookie<Route['cookie'][key]>;
796
+ }>;
797
+ set: {
798
+ headers: Record<string, string> & {
799
+ 'Set-Cookie'?: string | string[];
800
+ };
801
+ status?: number | HTTPStatusName;
802
+ redirect?: string;
803
+ /**
804
+ * ! Internal Property
805
+ *
806
+ * Use `Context.cookie` instead
807
+ */
808
+ cookie?: Record<string, Prettify<{
809
+ value: string;
810
+ } & CookieOptions>>;
811
+ };
812
+ path: string;
813
+ request: Request;
814
+ store: Decorators['store'];
815
+ } & Decorators['request'] & Decorators['derive'] & Decorators['resolve']>;
816
+ type PreContext<Decorators extends DecoratorBase = {
817
+ request: {};
818
+ store: {};
819
+ derive: {};
820
+ resolve: {};
821
+ }> = Prettify<{
822
+ store: Decorators['store'];
823
+ request: Request;
824
+ set: {
825
+ headers: {
826
+ [header: string]: string;
827
+ } & {
828
+ ['Set-Cookie']?: string | string[];
829
+ };
830
+ status?: number;
831
+ redirect?: string;
832
+ };
833
+ } & Decorators['request']>;
834
+
835
+ declare const websocket: WebSocketHandler<any>;
836
+ declare class ElysiaWS<WS extends ServerWebSocket<{
837
+ id?: string;
838
+ validator?: TypeCheck<TSchema>;
839
+ }>, Route extends RouteSchema = RouteSchema, Decorators extends DecoratorBase = {
840
+ request: {};
841
+ store: {};
842
+ derive: {};
843
+ resolve: {};
844
+ }> {
845
+ raw: WS;
846
+ data: Context<Route, Decorators>;
847
+ validator?: TypeCheck<TSchema>;
848
+ constructor(raw: WS, data: Context<Route, Decorators>);
849
+ get id(): string;
850
+ set id(newID: string);
851
+ get publish(): (topic: string, data?: Route['response'], compress?: boolean) => this;
852
+ get send(): (data: Route['response']) => this;
853
+ get subscribe(): (room: string) => this;
854
+ get unsubscribe(): (room: string) => this;
855
+ get cork(): (callback: (ws: WS) => this) => this;
856
+ get close(): () => this;
857
+ get terminate(): () => void;
858
+ get isSubscribed(): (topic: string) => boolean;
859
+ get remoteAddress(): string;
860
+ }
861
+
862
+ declare namespace WS {
863
+ type Config = Omit<WebSocketHandler, 'open' | 'message' | 'close' | 'drain'>;
864
+ type LocalHook<LocalSchema extends InputSchema = {}, Route extends RouteSchema = RouteSchema, Decorators extends DecoratorBase = {
865
+ request: {};
866
+ store: {};
867
+ derive: {};
868
+ resolve: {};
869
+ }, Errors extends Record<string, Error> = {}, Path extends string = '', TypedRoute extends RouteSchema = keyof Route['params'] extends never ? Route & {
870
+ params: Record<GetPathParameter<Path>, string>;
871
+ } : Route> = (LocalSchema extends {} ? LocalSchema : Isolate<LocalSchema>) & Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain' | 'publish' | 'publishToSelf'> & (ElysiaWS<ServerWebSocket<{
872
+ validator?: TypeCheck<TSchema>;
873
+ }>, TypedRoute, Decorators> extends infer WS ? {
874
+ transform?: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>;
875
+ transformMessage?: MaybeArray$1<VoidHandler<TypedRoute, Decorators>>;
876
+ beforeHandle?: MaybeArray$1<Handler<TypedRoute, Decorators>>;
877
+ /**
878
+ * Catch error
879
+ */
880
+ error?: MaybeArray$1<ErrorHandler<Errors>>;
881
+ /**
882
+ * Headers to register to websocket before `upgrade`
883
+ */
884
+ upgrade?: HeadersInit | ((context: Context) => HeadersInit);
885
+ /**
886
+ * The {@link ServerWebSocket} has been opened
887
+ *
888
+ * @param ws The {@link ServerWebSocket} that was opened
889
+ */
890
+ open?: (ws: WS) => void | Promise<void>;
891
+ /**
892
+ * Handle an incoming message to a {@link ServerWebSocket}
893
+ *
894
+ * @param ws The {@link ServerWebSocket} that received the message
895
+ * @param message The message received
896
+ *
897
+ * To change `message` to be an `ArrayBuffer` instead of a `Uint8Array`, set `ws.binaryType = "arraybuffer"`
898
+ */
899
+ message?: (ws: WS, message: Route['body']) => any;
900
+ /**
901
+ * The {@link ServerWebSocket} is being closed
902
+ * @param ws The {@link ServerWebSocket} that was closed
903
+ * @param code The close code
904
+ * @param message The close message
905
+ */
906
+ close?: (ws: WS, code: number, message: string) => void | Promise<void>;
907
+ /**
908
+ * The {@link ServerWebSocket} is ready for more data
909
+ *
910
+ * @param ws The {@link ServerWebSocket} that is ready
911
+ */
912
+ drain?: (ws: WS) => void | Promise<void>;
913
+ } : {});
914
+ }
915
+
916
+ declare const t: _sinclair_typebox.JavaScriptTypeBuilder;
917
+ type MaybeArray<T> = T | T[];
918
+ declare namespace ElysiaTypeOptions {
919
+ type Numeric = NumberOptions;
920
+ type FileUnit = number | `${number}${'k' | 'm'}`;
921
+ interface File extends SchemaOptions {
922
+ type?: MaybeArray<(string & {}) | 'image' | 'image/jpeg' | 'image/png' | 'image/gif' | 'image/tiff' | 'image/x-icon' | 'image/svg' | 'image/webp' | 'image/avif' | 'audio' | 'audio/mpeg' | 'audio/x-ms-wma' | 'audio/vnd.rn-realaudio' | 'audio/x-wav' | 'video' | 'video/mpeg' | 'video/mp4' | 'video/quicktime' | 'video/x-ms-wmv' | 'video/x-msvideo' | 'video/x-flv' | 'video/webm' | 'text' | 'text/css' | 'text/csv' | 'text/html' | 'text/javascript' | 'text/plain' | 'text/xml' | 'application' | 'application/ogg' | 'application/pdf' | 'application/xhtml' | 'application/html' | 'application/json' | 'application/ld+json' | 'application/xml' | 'application/zip' | 'font' | 'font/woff2' | 'font/woff' | 'font/ttf' | 'font/otf'>;
923
+ minSize?: FileUnit;
924
+ maxSize?: FileUnit;
925
+ }
926
+ interface Files extends File {
927
+ minItems?: number;
928
+ maxItems?: number;
929
+ }
930
+ }
931
+ declare const ElysiaType: {
932
+ readonly Numeric: (property?: NumberOptions) => TNumber;
933
+ readonly ObjectString: <T extends TProperties>(properties: T, options?: ObjectOptions) => TObject<T>;
934
+ readonly File: (options?: Partial<ElysiaTypeOptions.File> | undefined) => _sinclair_typebox.TUnsafe<File>;
935
+ readonly Files: (options?: ElysiaTypeOptions.Files) => _sinclair_typebox.TTransform<_sinclair_typebox.TUnsafe<File[]>, File[]>;
936
+ readonly Nullable: <T extends TSchema>(schema: T) => TUnion<[T, TNull]>;
937
+ /**
938
+ * Allow Optional, Nullable and Undefined
939
+ */
940
+ readonly MaybeEmpty: <T_1 extends TSchema>(schema: T_1) => TUnion<[T_1, TUndefined]>;
941
+ readonly Cookie: <T_2 extends TProperties>(properties: T_2, options?: (ObjectOptions & CookieOptions & {
942
+ /**
943
+ * Secret key for signing cookie
944
+ *
945
+ * If array is passed, will use Key Rotation.
946
+ *
947
+ * Key rotation is when an encryption key is retired
948
+ * and replaced by generating a new cryptographic key.
949
+ */
950
+ secrets?: string | string[] | undefined;
951
+ /**
952
+ * Specified cookie name to be signed globally
953
+ */
954
+ sign?: readonly ((string & {}) | keyof T_2)[] | undefined;
955
+ }) | undefined) => TObject<T_2>;
956
+ };
957
+ type TCookie = (typeof ElysiaType)['Cookie'];
958
+ declare module '@sinclair/typebox' {
959
+ interface JavaScriptTypeBuilder {
960
+ ObjectString: typeof ElysiaType.ObjectString;
961
+ Numeric: typeof ElysiaType.Numeric;
962
+ File: typeof ElysiaType.File;
963
+ Files: typeof ElysiaType.Files;
964
+ Nullable: typeof ElysiaType.Nullable;
965
+ MaybeEmpty: typeof ElysiaType.MaybeEmpty;
966
+ Cookie: typeof ElysiaType.Cookie;
967
+ }
968
+ interface SchemaOptions {
969
+ error?: string | ((type: string, validator: TypeCheck<any>, value: unknown) => string | void);
970
+ }
971
+ }
972
+
973
+ declare const isNotEmpty: (obj: Object) => boolean;
974
+ declare const parseSetCookies: (headers: Headers, setCookie: string[]) => Headers;
975
+ declare const cookieToHeader: (cookies: Context['set']['cookie']) => string | string[] | undefined;
976
+ declare const mapResponse: (response: unknown, set: Context['set']) => Response;
977
+ declare const mapEarlyResponse: (response: unknown, set: Context['set']) => Response | undefined;
978
+ declare const mapCompactResponse: (response: unknown) => Response;
979
+ declare const errorToResponse: (error: Error, set?: Context['set']) => Response;
980
+
981
+ /**
982
+ * ### Elysia Server
983
+ * Main instance to create web server using Elysia
984
+ *
985
+ * ---
986
+ * @example
987
+ * ```typescript
988
+ * import { Elysia } from 'elysia'
989
+ *
990
+ * new Elysia()
991
+ * .get("/", () => "Hello")
992
+ * .listen(8080)
993
+ * ```
994
+ */
995
+ declare class Elysia<BasePath extends string = '', Decorators extends DecoratorBase = {
996
+ request: {};
997
+ store: {};
998
+ derive: {};
999
+ resolve: {};
1000
+ }, Definitions extends DefinitionBase = {
1001
+ type: {};
1002
+ error: {};
1003
+ }, ParentSchema extends RouteSchema = {}, Macro extends Record<string, unknown> = {}, Routes extends RouteBase = {}, Scoped extends boolean = false> {
1004
+ config: ElysiaConfig<BasePath>;
1005
+ private dependencies;
1006
+ store: Decorators['store'];
1007
+ private decorators;
1008
+ private definitions;
1009
+ schema: Routes;
1010
+ private macros;
1011
+ event: LifeCycleStore;
1012
+ reporter: TraceReporter;
1013
+ server: Server | null;
1014
+ private getServer;
1015
+ private validator;
1016
+ private router;
1017
+ private wsRouter;
1018
+ routes: InternalRoute[];
1019
+ private staticRouter;
1020
+ private wsPaths;
1021
+ private dynamicRouter;
1022
+ private lazyLoadModules;
1023
+ path: BasePath;
1024
+ stack: string | undefined;
1025
+ constructor(config?: Partial<ElysiaConfig<BasePath, Scoped>>);
1026
+ private add;
1027
+ private setHeaders?;
1028
+ headers(header: Context['set']['headers'] | undefined): this;
1029
+ /**
1030
+ * ### start | Life cycle event
1031
+ * Called after server is ready for serving
1032
+ *
1033
+ * ---
1034
+ * @example
1035
+ * ```typescript
1036
+ * new Elysia()
1037
+ * .onStart(({ url, port }) => {
1038
+ * console.log("Running at ${url}:${port}")
1039
+ * })
1040
+ * .listen(8080)
1041
+ * ```
1042
+ */
1043
+ onStart(handler: MaybeArray$1<GracefulHandler<this>>): this;
1044
+ /**
1045
+ * ### request | Life cycle event
1046
+ * Called on every new request is accepted
1047
+ *
1048
+ * ---
1049
+ * @example
1050
+ * ```typescript
1051
+ * new Elysia()
1052
+ * .onRequest(({ method, url }) => {
1053
+ * saveToAnalytic({ method, url })
1054
+ * })
1055
+ * ```
1056
+ */
1057
+ onRequest<Schema extends RouteSchema = {}>(handler: MaybeArray$1<PreHandler<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1058
+ /**
1059
+ * ### parse | Life cycle event
1060
+ * Callback function to handle body parsing
1061
+ *
1062
+ * If truthy value is returned, will be assigned to `context.body`
1063
+ * Otherwise will skip the callback and look for the next one.
1064
+ *
1065
+ * Equivalent to Express's body parser
1066
+ *
1067
+ * ---
1068
+ * @example
1069
+ * ```typescript
1070
+ * new Elysia()
1071
+ * .onParse((request, contentType) => {
1072
+ * if(contentType === "application/json")
1073
+ * return request.json()
1074
+ * })
1075
+ * ```
1076
+ */
1077
+ onParse(parser: MaybeArray$1<BodyHandler<ParentSchema, Decorators>>): this;
1078
+ /**
1079
+ * ### transform | Life cycle event
1080
+ * Assign or transform anything related to context before validation.
1081
+ *
1082
+ * ---
1083
+ * @example
1084
+ * ```typescript
1085
+ * new Elysia()
1086
+ * .onTransform(({ params }) => {
1087
+ * if(params.id)
1088
+ * params.id = +params.id
1089
+ * })
1090
+ * ```
1091
+ */
1092
+ onTransform<Schema extends RouteSchema = {}>(handler: MaybeArray$1<TransformHandler<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1093
+ /**
1094
+ * ### After Handle | Life cycle event
1095
+ * Intercept request **after** main handler is called.
1096
+ *
1097
+ * If truthy value is returned, will be assigned as `Response`
1098
+ *
1099
+ * ---
1100
+ * @example
1101
+ * ```typescript
1102
+ * new Elysia()
1103
+ * .onAfterHandle((context, response) => {
1104
+ * if(typeof response === "object")
1105
+ * return JSON.stringify(response)
1106
+ * })
1107
+ * ```
1108
+ */
1109
+ /**
1110
+ * Derive new property for each request with access to `Context`.
1111
+ *
1112
+ * If error is thrown, the scope will skip to handling error instead.
1113
+ *
1114
+ * ---
1115
+ * @example
1116
+ * new Elysia()
1117
+ * .state('counter', 1)
1118
+ * .derive(({ store }) => ({
1119
+ * increase() {
1120
+ * store.counter++
1121
+ * }
1122
+ * }))
1123
+ */
1124
+ resolve<Resolver extends Object>(resolver: (context: Prettify<Context<ParentSchema, Decorators>>) => MaybePromise<Resolver> extends {
1125
+ store: any;
1126
+ } ? never : Resolver): Elysia<BasePath, {
1127
+ request: Decorators['request'];
1128
+ store: Decorators['store'];
1129
+ derive: Decorators['resolve'];
1130
+ resolve: Prettify<Decorators['resolve'] & Awaited<Resolver>>;
1131
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1132
+ /**
1133
+ * ### Before Handle | Life cycle event
1134
+ * Intercept request **before(()) main handler is called.
1135
+ *
1136
+ * If truthy value is returned, will be assigned as `Response` and skip the main handler
1137
+ *
1138
+ * ---
1139
+ * @example
1140
+ * ```typescript
1141
+ * new Elysia()
1142
+ * .onBeforeHandle(({ params: { id }, status }) => {
1143
+ * if(id && !isExisted(id)) {
1144
+ * status(401)
1145
+ *
1146
+ * return "Unauthorized"
1147
+ * }
1148
+ * })
1149
+ * ```
1150
+ */
1151
+ onBeforeHandle<Schema extends RouteSchema = {}>(handler: MaybeArray$1<OptionalHandler<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1152
+ /**
1153
+ * ### After Handle | Life cycle event
1154
+ * Intercept request **after** main handler is called.
1155
+ *
1156
+ * If truthy value is returned, will be assigned as `Response`
1157
+ *
1158
+ * ---
1159
+ * @example
1160
+ * ```typescript
1161
+ * new Elysia()
1162
+ * .onAfterHandle((context, response) => {
1163
+ * if(typeof response === "object")
1164
+ * return JSON.stringify(response)
1165
+ * })
1166
+ * ```
1167
+ */
1168
+ onAfterHandle<Schema extends RouteSchema = {}>(handler: MaybeArray$1<AfterHandler<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1169
+ /**
1170
+ * ### After Handle | Life cycle event
1171
+ * Intercept request **after** main handler is called.
1172
+ *
1173
+ * If truthy value is returned, will be assigned as `Response`
1174
+ *
1175
+ * ---
1176
+ * @example
1177
+ * ```typescript
1178
+ * new Elysia()
1179
+ * .mapResponse((context, response) => {
1180
+ * if(typeof response === "object")
1181
+ * return JSON.stringify(response)
1182
+ * })
1183
+ * ```
1184
+ */
1185
+ mapResponse<Schema extends RouteSchema = {}>(handler: MaybeArray$1<MapResponse<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1186
+ /**
1187
+ * ### response | Life cycle event
1188
+ * Called when handler is executed
1189
+ * Good for analytic metrics
1190
+ *
1191
+ * ---
1192
+ * @example
1193
+ * ```typescript
1194
+ * new Elysia()
1195
+ * .onError(({ code }) => {
1196
+ * if(code === "NOT_FOUND")
1197
+ * return "Path not found :("
1198
+ * })
1199
+ * ```
1200
+ */
1201
+ onResponse<Schema extends RouteSchema = {}>(handler: MaybeArray$1<VoidHandler<MergeSchema<Schema, ParentSchema>, Decorators>>): this;
1202
+ /**
1203
+ * ### After Handle | Life cycle event
1204
+ * Intercept request **after** main handler is called.
1205
+ *
1206
+ * If truthy value is returned, will be assigned as `Response`
1207
+ *
1208
+ * ---
1209
+ * @example
1210
+ * ```typescript
1211
+ * new Elysia()
1212
+ * .onAfterHandle((context, response) => {
1213
+ * if(typeof response === "object")
1214
+ * return JSON.stringify(response)
1215
+ * })
1216
+ * ```
1217
+ */
1218
+ trace<Route extends RouteSchema = {}>(handler: TraceHandler<Route, Decorators>): this;
1219
+ /**
1220
+ * Register errors
1221
+ *
1222
+ * ---
1223
+ * @example
1224
+ * ```typescript
1225
+ * class CustomError extends Error {
1226
+ * constructor() {
1227
+ * super()
1228
+ * }
1229
+ * }
1230
+ *
1231
+ * new Elysia()
1232
+ * .error('CUSTOM_ERROR', CustomError)
1233
+ * ```
1234
+ */
1235
+ error<const Errors extends Record<string, {
1236
+ prototype: Error;
1237
+ }>>(errors: Errors): Elysia<BasePath, Decorators, {
1238
+ type: Definitions['type'];
1239
+ error: Definitions['error'] & {
1240
+ [K in keyof Errors]: Errors[K] extends {
1241
+ prototype: infer LiteralError extends Error;
1242
+ } ? LiteralError : Errors[K];
1243
+ };
1244
+ }, ParentSchema, Macro, Routes, Scoped>;
1245
+ /**
1246
+ * Register errors
1247
+ *
1248
+ * ---
1249
+ * @example
1250
+ * ```typescript
1251
+ * class CustomError extends Error {
1252
+ * constructor() {
1253
+ * super()
1254
+ * }
1255
+ * }
1256
+ *
1257
+ * new Elysia()
1258
+ * .error({
1259
+ * CUSTOM_ERROR: CustomError
1260
+ * })
1261
+ * ```
1262
+ */
1263
+ error<Name extends string, const CustomError extends {
1264
+ prototype: Error;
1265
+ }>(name: Name, errors: CustomError): Elysia<BasePath, Decorators, {
1266
+ type: Definitions['type'];
1267
+ error: Definitions['error'] & {
1268
+ [name in Name]: CustomError extends {
1269
+ prototype: infer LiteralError extends Error;
1270
+ } ? LiteralError : CustomError;
1271
+ };
1272
+ }, ParentSchema, Macro, Routes, Scoped>;
1273
+ /**
1274
+ * Register errors
1275
+ *
1276
+ * ---
1277
+ * @example
1278
+ * ```typescript
1279
+ * class CustomError extends Error {
1280
+ * constructor() {
1281
+ * super()
1282
+ * }
1283
+ * }
1284
+ *
1285
+ * new Elysia()
1286
+ * .error('CUSTOM_ERROR', CustomError)
1287
+ * ```
1288
+ */
1289
+ error<const NewErrors extends Record<string, Error>>(mapper: (decorators: Definitions['error']) => NewErrors): Elysia<BasePath, Decorators, {
1290
+ type: Definitions['type'];
1291
+ error: {
1292
+ [K in keyof NewErrors]: NewErrors[K] extends {
1293
+ prototype: infer LiteralError extends Error;
1294
+ } ? LiteralError : never;
1295
+ };
1296
+ }, ParentSchema, Macro, Routes, Scoped>;
1297
+ /**
1298
+ * ### Error | Life cycle event
1299
+ * Called when error is thrown during processing request
1300
+ *
1301
+ * ---
1302
+ * @example
1303
+ * ```typescript
1304
+ * new Elysia()
1305
+ * .onError(({ code }) => {
1306
+ * if(code === "NOT_FOUND")
1307
+ * return "Path not found :("
1308
+ * })
1309
+ * ```
1310
+ */
1311
+ onError<Schema extends RouteSchema = {}>(handler: ErrorHandler<Definitions['error'], MergeSchema<Schema, ParentSchema>, Decorators>): this;
1312
+ /**
1313
+ * ### stop | Life cycle event
1314
+ * Called after server stop serving request
1315
+ *
1316
+ * ---
1317
+ * @example
1318
+ * ```typescript
1319
+ * new Elysia()
1320
+ * .onStop((app) => {
1321
+ * cleanup()
1322
+ * })
1323
+ * ```
1324
+ */
1325
+ onStop(handler: MaybeArray$1<GracefulHandler<this>>): this;
1326
+ /**
1327
+ * ### on
1328
+ * Syntax sugar for attaching life cycle event by name
1329
+ *
1330
+ * Does the exact same thing as `.on[Event]()`
1331
+ *
1332
+ * ---
1333
+ * @example
1334
+ * ```typescript
1335
+ * new Elysia()
1336
+ * .on('error', ({ code }) => {
1337
+ * if(code === "NOT_FOUND")
1338
+ * return "Path not found :("
1339
+ * })
1340
+ * ```
1341
+ */
1342
+ on<Event extends keyof LifeCycleStore>(type: Exclude<Event, 'onResponse'> | 'response', handlers: MaybeArray$1<Extract<LifeCycleStore[Event], Function[]>[0]>): this;
1343
+ group<const NewElysia extends Elysia<any, any, any, any, any, any, any>, const Prefix extends string>(prefix: Prefix, run: (group: Elysia<`${BasePath}${Prefix}`, Decorators, Definitions, ParentSchema, Macro, {}>) => NewElysia): NewElysia extends Elysia<any, infer PluginDecorators, infer PluginDefinitions, infer PluginSchema, any, any> ? Elysia<BasePath, PluginDecorators, PluginDefinitions, PluginSchema, Macro, Prettify<Routes & NewElysia['schema']>> : this;
1344
+ group<const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const NewElysia extends Elysia<any, any, any, any, any, any, any>, const Prefix extends string, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(prefix: Prefix, schema: LocalHook<LocalSchema, Schema, Decorators, Definitions['error'], Macro, `${BasePath}${Prefix}`>, run: (group: Elysia<`${BasePath}${Prefix}`, Decorators, Definitions, Schema, Macro, {}>) => NewElysia): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & NewElysia['schema']>>;
1345
+ guard<const LocalSchema extends InputSchema, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(hook: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, BasePath>): Elysia<BasePath, Decorators, Definitions, Route, Macro, Routes, Scoped>;
1346
+ guard<const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const NewElysia extends Elysia<any, any, any, any, any, any, any>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(schema: LocalHook<LocalSchema, Schema, Decorators, Definitions['error'], Macro>, run: (group: Elysia<BasePath, Decorators, Definitions, Schema, Macro, {}, Scoped>) => NewElysia): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & NewElysia['schema']>>;
1347
+ use<NewElysia extends Elysia<any, any, any, any, any, any, any> = this>(plugin: MaybePromise<(app: NewElysia) => MaybePromise<NewElysia>>): NewElysia extends Elysia<any, infer PluginDecorators, infer PluginDefinitions, infer PluginSchema, infer PluginMacro, any> ? Elysia<BasePath, {
1348
+ request: Prettify<Decorators['request'] & PluginDecorators['request']>;
1349
+ store: Prettify<Decorators['store'] & PluginDecorators['store']>;
1350
+ derive: Prettify<Decorators['derive'] & PluginDecorators['derive']>;
1351
+ resolve: Prettify<Decorators['resolve'] & PluginDecorators['resolve']>;
1352
+ }, {
1353
+ type: Prettify<Definitions['type'] & PluginDefinitions['type']>;
1354
+ error: Prettify<Definitions['error'] & PluginDefinitions['error']>;
1355
+ }, Prettify<MergeSchema<ParentSchema, PluginSchema>>, Prettify<Macro & PluginMacro>, Routes & NewElysia['schema'], Scoped> : this;
1356
+ use<NewElysia extends Elysia<any, any, any, any, any, any, any>>(instance: MaybePromise<NewElysia>): NewElysia extends Elysia<any, infer PluginDecorators, infer PluginDefinitions, infer PluginSchema, infer PluginMacro, any, infer IsScoped> ? IsScoped extends true ? Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, BasePath extends `` ? Routes & NewElysia['schema'] : Routes & AddPrefix<BasePath, NewElysia['schema']>, Scoped> : Elysia<BasePath, {
1357
+ request: Prettify<Decorators['request'] & PluginDecorators['request']>;
1358
+ store: Prettify<Decorators['store'] & PluginDecorators['store']>;
1359
+ derive: Prettify<Decorators['derive'] & PluginDecorators['derive']>;
1360
+ resolve: Prettify<Decorators['resolve'] & PluginDecorators['resolve']>;
1361
+ }, {
1362
+ type: Prettify<Definitions['type'] & PluginDefinitions['type']>;
1363
+ error: Prettify<Definitions['error'] & PluginDefinitions['error']>;
1364
+ }, Prettify<MergeSchema<ParentSchema, PluginSchema>>, Prettify<Macro & PluginMacro>, BasePath extends `` ? Routes & NewElysia['schema'] : Routes & AddPrefix<BasePath, NewElysia['schema']>, Scoped> : this;
1365
+ use<NewElysia extends Elysia<any, any, any, any, any, any, any>>(plugin: Promise<{
1366
+ default: (elysia: Elysia<any, any, any, any, any, any, any>) => MaybePromise<NewElysia>;
1367
+ }>): NewElysia extends Elysia<any, infer PluginDecorators, infer PluginDefinitions, infer PluginSchema, infer PluginMacro, any> ? Elysia<BasePath, {
1368
+ request: Decorators['request'] & PluginDecorators['request'];
1369
+ store: Decorators['store'] & PluginDecorators['store'];
1370
+ derive: Decorators['derive'] & PluginDecorators['derive'];
1371
+ resolve: Decorators['resolve'] & PluginDecorators['resolve'];
1372
+ }, {
1373
+ type: Definitions['type'] & PluginDefinitions['type'];
1374
+ error: Definitions['error'] & PluginDefinitions['error'];
1375
+ }, MergeSchema<ParentSchema, PluginSchema>, Prettify<Macro & PluginMacro>, BasePath extends `` ? Routes & NewElysia['schema'] : Routes & AddPrefix<BasePath, NewElysia['schema']>, Scoped> : this;
1376
+ use<LazyLoadElysia extends Elysia<any, any, any, any, any, any, any>>(plugin: Promise<{
1377
+ default: LazyLoadElysia;
1378
+ }>): LazyLoadElysia extends Elysia<any, infer PluginDecorators, infer PluginDefinitions, infer PluginSchema, infer PluginMacro, any> ? Elysia<BasePath, {
1379
+ request: PluginDecorators['request'] & Decorators['request'];
1380
+ store: PluginDecorators['store'] & Decorators['store'];
1381
+ derive: Decorators['derive'] & PluginDecorators['derive'];
1382
+ resolve: Decorators['resolve'] & PluginDecorators['resolve'];
1383
+ }, {
1384
+ type: PluginDefinitions['type'] & Definitions['type'];
1385
+ error: PluginDefinitions['error'] & Definitions['error'];
1386
+ }, MergeSchema<PluginSchema, ParentSchema>, Prettify<Macro & PluginMacro>, BasePath extends `` ? Routes & LazyLoadElysia['schema'] : Routes & AddPrefix<BasePath, LazyLoadElysia['schema']>> : this;
1387
+ private _use;
1388
+ macro<const NewMacro extends BaseMacro>(macro: (route: MacroManager<Routes, Decorators, Definitions['error']>) => NewMacro): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro & Partial<MacroToProperty<NewMacro>>, Routes, Scoped>;
1389
+ mount(handle: ((request: Request) => MaybePromise<Response>) | Elysia<any, any, any, any, any, any, any>): this;
1390
+ mount(path: string, handle: ((request: Request) => MaybePromise<Response>) | Elysia<any, any, any, any, any, any, any>): this;
1391
+ /**
1392
+ * ### get
1393
+ * Register handler for path with method [GET]
1394
+ *
1395
+ * ---
1396
+ * @example
1397
+ * ```typescript
1398
+ * import { Elysia, t } from 'elysia'
1399
+ *
1400
+ * new Elysia()
1401
+ * .get('/', () => 'hi')
1402
+ * .get('/with-hook', () => 'hi', {
1403
+ * schema: {
1404
+ * response: t.String()
1405
+ * }
1406
+ * })
1407
+ * ```
1408
+ */
1409
+ get<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1410
+ [path in `${BasePath}${Path}`]: {
1411
+ get: {
1412
+ body: Route['body'];
1413
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1414
+ query: Route['query'];
1415
+ headers: Route['headers'];
1416
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1417
+ 200: Exclude<Res, {
1418
+ [ELYSIA_RESPONSE]: number;
1419
+ }>;
1420
+ } & (Extract<Res, {
1421
+ [ELYSIA_RESPONSE]: number;
1422
+ }> extends infer ErrorResponse extends {
1423
+ [ELYSIA_RESPONSE]: number;
1424
+ response: any;
1425
+ } ? {
1426
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1427
+ } : {})> : {
1428
+ 200: Res;
1429
+ } : never : Route['response'] extends {
1430
+ 200: any;
1431
+ } ? Route['response'] : {
1432
+ 200: Route['response'];
1433
+ };
1434
+ };
1435
+ };
1436
+ }>, Scoped>;
1437
+ /**
1438
+ * ### post
1439
+ * Register handler for path with method [POST]
1440
+ *
1441
+ * ---
1442
+ * @example
1443
+ * ```typescript
1444
+ * import { Elysia, t } from 'elysia'
1445
+ *
1446
+ * new Elysia()
1447
+ * .post('/', () => 'hi')
1448
+ * .post('/with-hook', () => 'hi', {
1449
+ * schema: {
1450
+ * response: t.String()
1451
+ * }
1452
+ * })
1453
+ * ```
1454
+ */
1455
+ post<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1456
+ [path in `${BasePath}${Path}`]: {
1457
+ post: {
1458
+ body: Route['body'];
1459
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1460
+ query: Route['query'];
1461
+ headers: Route['headers'];
1462
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1463
+ 200: Exclude<Res, {
1464
+ [ELYSIA_RESPONSE]: number;
1465
+ }>;
1466
+ } & (Extract<Res, {
1467
+ [ELYSIA_RESPONSE]: number;
1468
+ }> extends infer ErrorResponse extends {
1469
+ [ELYSIA_RESPONSE]: number;
1470
+ response: any;
1471
+ } ? {
1472
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1473
+ } : {})> : {
1474
+ 200: Res;
1475
+ } : never : Route['response'] extends {
1476
+ 200: any;
1477
+ } ? Route['response'] : {
1478
+ 200: Route['response'];
1479
+ };
1480
+ };
1481
+ };
1482
+ }>, Scoped>;
1483
+ /**
1484
+ * ### put
1485
+ * Register handler for path with method [PUT]
1486
+ *
1487
+ * ---
1488
+ * @example
1489
+ * ```typescript
1490
+ * import { Elysia, t } from 'elysia'
1491
+ *
1492
+ * new Elysia()
1493
+ * .put('/', () => 'hi')
1494
+ * .put('/with-hook', () => 'hi', {
1495
+ * schema: {
1496
+ * response: t.String()
1497
+ * }
1498
+ * })
1499
+ * ```
1500
+ */
1501
+ put<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1502
+ [path in `${BasePath}${Path}`]: {
1503
+ put: {
1504
+ body: Route['body'];
1505
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1506
+ query: Route['query'];
1507
+ headers: Route['headers'];
1508
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1509
+ 200: Exclude<Res, {
1510
+ [ELYSIA_RESPONSE]: number;
1511
+ }>;
1512
+ } & (Extract<Res, {
1513
+ [ELYSIA_RESPONSE]: number;
1514
+ }> extends infer ErrorResponse extends {
1515
+ [ELYSIA_RESPONSE]: number;
1516
+ response: any;
1517
+ } ? {
1518
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1519
+ } : {})> : {
1520
+ 200: Res;
1521
+ } : never : Route['response'] extends {
1522
+ 200: any;
1523
+ } ? Route['response'] : {
1524
+ 200: Route['response'];
1525
+ };
1526
+ };
1527
+ };
1528
+ }>, Scoped>;
1529
+ /**
1530
+ * ### patch
1531
+ * Register handler for path with method [PATCH]
1532
+ *
1533
+ * ---
1534
+ * @example
1535
+ * ```typescript
1536
+ * import { Elysia, t } from 'elysia'
1537
+ *
1538
+ * new Elysia()
1539
+ * .patch('/', () => 'hi')
1540
+ * .patch('/with-hook', () => 'hi', {
1541
+ * schema: {
1542
+ * response: t.String()
1543
+ * }
1544
+ * })
1545
+ * ```
1546
+ */
1547
+ patch<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1548
+ [path in `${BasePath}${Path}`]: {
1549
+ patch: {
1550
+ body: Route['body'];
1551
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1552
+ query: Route['query'];
1553
+ headers: Route['headers'];
1554
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1555
+ 200: Exclude<Res, {
1556
+ [ELYSIA_RESPONSE]: number;
1557
+ }>;
1558
+ } & (Extract<Res, {
1559
+ [ELYSIA_RESPONSE]: number;
1560
+ }> extends infer ErrorResponse extends {
1561
+ [ELYSIA_RESPONSE]: number;
1562
+ response: any;
1563
+ } ? {
1564
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1565
+ } : {})> : {
1566
+ 200: Res;
1567
+ } : never : Route['response'] extends {
1568
+ 200: any;
1569
+ } ? Route['response'] : {
1570
+ 200: Route['response'];
1571
+ };
1572
+ };
1573
+ };
1574
+ }>, Scoped>;
1575
+ /**
1576
+ * ### delete
1577
+ * Register handler for path with method [DELETE]
1578
+ *
1579
+ * ---
1580
+ * @example
1581
+ * ```typescript
1582
+ * import { Elysia, t } from 'elysia'
1583
+ *
1584
+ * new Elysia()
1585
+ * .delete('/', () => 'hi')
1586
+ * .delete('/with-hook', () => 'hi', {
1587
+ * schema: {
1588
+ * response: t.String()
1589
+ * }
1590
+ * })
1591
+ * ```
1592
+ */
1593
+ delete<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1594
+ [path in `${BasePath}${Path}`]: {
1595
+ delete: {
1596
+ body: Route['body'];
1597
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1598
+ query: Route['query'];
1599
+ headers: Route['headers'];
1600
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1601
+ 200: Exclude<Res, {
1602
+ [ELYSIA_RESPONSE]: number;
1603
+ }>;
1604
+ } & (Extract<Res, {
1605
+ [ELYSIA_RESPONSE]: number;
1606
+ }> extends infer ErrorResponse extends {
1607
+ [ELYSIA_RESPONSE]: number;
1608
+ response: any;
1609
+ } ? {
1610
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1611
+ } : {})> : {
1612
+ 200: Res;
1613
+ } : never : Route['response'] extends {
1614
+ 200: any;
1615
+ } ? Route['response'] : {
1616
+ 200: Route['response'];
1617
+ };
1618
+ };
1619
+ };
1620
+ }>, Scoped>;
1621
+ /**
1622
+ * ### options
1623
+ * Register handler for path with method [OPTIONS]
1624
+ *
1625
+ * ---
1626
+ * @example
1627
+ * ```typescript
1628
+ * import { Elysia, t } from 'elysia'
1629
+ *
1630
+ * new Elysia()
1631
+ * .options('/', () => 'hi')
1632
+ * .options('/with-hook', () => 'hi', {
1633
+ * schema: {
1634
+ * response: t.String()
1635
+ * }
1636
+ * })
1637
+ * ```
1638
+ */
1639
+ options<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1640
+ [path in `${BasePath}${Path}`]: {
1641
+ get: {
1642
+ body: Route['body'];
1643
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1644
+ query: Route['query'];
1645
+ headers: Route['headers'];
1646
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1647
+ 200: Exclude<Res, {
1648
+ [ELYSIA_RESPONSE]: number;
1649
+ }>;
1650
+ } & (Extract<Res, {
1651
+ [ELYSIA_RESPONSE]: number;
1652
+ }> extends infer ErrorResponse extends {
1653
+ [ELYSIA_RESPONSE]: number;
1654
+ response: any;
1655
+ } ? {
1656
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1657
+ } : {})> : {
1658
+ 200: Res;
1659
+ } : never : Route['response'] extends {
1660
+ 200: any;
1661
+ } ? Route['response'] : {
1662
+ 200: Route['response'];
1663
+ };
1664
+ };
1665
+ };
1666
+ }>, Scoped>;
1667
+ /**
1668
+ * ### all
1669
+ * Register handler for path with any method
1670
+ *
1671
+ * ---
1672
+ * @example
1673
+ * ```typescript
1674
+ * import { Elysia, t } from 'elysia'
1675
+ *
1676
+ * new Elysia()
1677
+ * .all('/', () => 'hi')
1678
+ * ```
1679
+ */
1680
+ all<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1681
+ [path in `${BasePath}${Path}`]: {
1682
+ [method in string]: {
1683
+ body: Route['body'];
1684
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1685
+ query: Route['query'];
1686
+ headers: Route['headers'];
1687
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1688
+ 200: Exclude<Res, {
1689
+ [ELYSIA_RESPONSE]: number;
1690
+ }>;
1691
+ } & (Extract<Res, {
1692
+ [ELYSIA_RESPONSE]: number;
1693
+ }> extends infer ErrorResponse extends {
1694
+ [ELYSIA_RESPONSE]: number;
1695
+ response: any;
1696
+ } ? {
1697
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1698
+ } : {})> : {
1699
+ 200: Res;
1700
+ } : never : Route['response'] extends {
1701
+ 200: any;
1702
+ } ? Route['response'] : {
1703
+ 200: Route['response'];
1704
+ };
1705
+ };
1706
+ };
1707
+ }>, Scoped>;
1708
+ /**
1709
+ * ### head
1710
+ * Register handler for path with method [HEAD]
1711
+ *
1712
+ * ---
1713
+ * @example
1714
+ * ```typescript
1715
+ * import { Elysia, t } from 'elysia'
1716
+ *
1717
+ * new Elysia()
1718
+ * .head('/', () => 'hi')
1719
+ * .head('/with-hook', () => 'hi', {
1720
+ * schema: {
1721
+ * response: t.String()
1722
+ * }
1723
+ * })
1724
+ * ```
1725
+ */
1726
+ head<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1727
+ [path in `${BasePath}${Path}`]: {
1728
+ head: {
1729
+ body: Route['body'];
1730
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1731
+ query: Route['query'];
1732
+ headers: Route['headers'];
1733
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1734
+ 200: Exclude<Res, {
1735
+ [ELYSIA_RESPONSE]: number;
1736
+ }>;
1737
+ } & (Extract<Res, {
1738
+ [ELYSIA_RESPONSE]: number;
1739
+ }> extends infer ErrorResponse extends {
1740
+ [ELYSIA_RESPONSE]: number;
1741
+ response: any;
1742
+ } ? {
1743
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1744
+ } : {})> : {
1745
+ 200: Res;
1746
+ } : never : Route['response'] extends {
1747
+ 200: any;
1748
+ } ? Route['response'] : {
1749
+ 200: Route['response'];
1750
+ };
1751
+ };
1752
+ };
1753
+ }>, Scoped>;
1754
+ /**
1755
+ * ### connect
1756
+ * Register handler for path with method [CONNECT]
1757
+ *
1758
+ * ---
1759
+ * @example
1760
+ * ```typescript
1761
+ * import { Elysia, t } from 'elysia'
1762
+ *
1763
+ * new Elysia()
1764
+ * .connect('/', () => 'hi')
1765
+ * .connect('/with-hook', () => 'hi', {
1766
+ * schema: {
1767
+ * response: t.String()
1768
+ * }
1769
+ * })
1770
+ * ```
1771
+ */
1772
+ connect<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1773
+ [path in `${BasePath}${Path}`]: {
1774
+ connect: {
1775
+ body: Route['body'];
1776
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1777
+ query: Route['query'];
1778
+ headers: Route['headers'];
1779
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1780
+ 200: Exclude<Res, {
1781
+ [ELYSIA_RESPONSE]: number;
1782
+ }>;
1783
+ } & (Extract<Res, {
1784
+ [ELYSIA_RESPONSE]: number;
1785
+ }> extends infer ErrorResponse extends {
1786
+ [ELYSIA_RESPONSE]: number;
1787
+ response: any;
1788
+ } ? {
1789
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1790
+ } : {})> : {
1791
+ 200: Res;
1792
+ } : never : Route['response'] extends {
1793
+ 200: any;
1794
+ } ? Route['response'] : {
1795
+ 200: Route['response'];
1796
+ };
1797
+ };
1798
+ };
1799
+ }>, Scoped>;
1800
+ /**
1801
+ * ### ws
1802
+ * Register handler for path with method [ws]
1803
+ *
1804
+ * ---
1805
+ * @example
1806
+ * ```typescript
1807
+ * import { Elysia, t } from 'elysia'
1808
+ *
1809
+ * new Elysia()
1810
+ * .ws('/', {
1811
+ * message(ws, message) {
1812
+ * ws.send(message)
1813
+ * }
1814
+ * })
1815
+ * ```
1816
+ */
1817
+ ws<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(path: Path, options: WS.LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1818
+ [path in `${BasePath}${Path}`]: {
1819
+ subscribe: {
1820
+ body: Route['body'];
1821
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1822
+ query: Route['query'];
1823
+ headers: Route['headers'];
1824
+ response: Route['response'];
1825
+ };
1826
+ };
1827
+ }>, Scoped>;
1828
+ /**
1829
+ * ### route
1830
+ * Register handler for path with custom method
1831
+ *
1832
+ * ---
1833
+ * @example
1834
+ * ```typescript
1835
+ * import { Elysia, t } from 'elysia'
1836
+ *
1837
+ * new Elysia()
1838
+ * .route('CUSTOM', '/', () => 'hi')
1839
+ * .route('CUSTOM', '/with-hook', () => 'hi', {
1840
+ * schema: {
1841
+ * response: t.String()
1842
+ * }
1843
+ * })
1844
+ * ```
1845
+ */
1846
+ route<const Method extends HTTPMethod, const Path extends string, const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const Handle extends Exclude<Route['response'], Handle> | Handler<Route, Decorators, `${BasePath}${Path}`>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(method: Method, path: Path, handler: Handle, { config, ...hook }?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], Macro, `${BasePath}${Path}`> & {
1847
+ config: {
1848
+ allowMeta?: boolean;
1849
+ };
1850
+ }): Elysia<BasePath, Decorators, Definitions, ParentSchema, Macro, Prettify<Routes & {
1851
+ [path in `${BasePath}${Path}`]: {
1852
+ [method in Lowercase<Method>]: {
1853
+ body: Route['body'];
1854
+ params: undefined extends Route['params'] ? Path extends `${string}/${':' | '*'}${string}` ? Record<GetPathParameter<Path>, string> : never : Route['params'];
1855
+ query: Route['query'];
1856
+ headers: Route['headers'];
1857
+ response: unknown extends Route['response'] ? (Handle extends (...a: any) => infer Returned ? Returned : Handle) extends infer Res ? keyof Res extends typeof ELYSIA_RESPONSE ? Prettify<{
1858
+ 200: Exclude<Res, {
1859
+ [ELYSIA_RESPONSE]: number;
1860
+ }>;
1861
+ } & (Extract<Res, {
1862
+ [ELYSIA_RESPONSE]: number;
1863
+ }> extends infer ErrorResponse extends {
1864
+ [ELYSIA_RESPONSE]: number;
1865
+ response: any;
1866
+ } ? {
1867
+ [status in ErrorResponse[typeof ELYSIA_RESPONSE]]: ErrorResponse['response'];
1868
+ } : {})> : {
1869
+ 200: Res;
1870
+ } : never : Route['response'] extends {
1871
+ 200: any;
1872
+ } ? Route['response'] : {
1873
+ 200: Route['response'];
1874
+ };
1875
+ };
1876
+ };
1877
+ }>, Scoped>;
1878
+ /**
1879
+ * ### state
1880
+ * Assign global mutatable state accessible for all handler
1881
+ *
1882
+ * ---
1883
+ * @example
1884
+ * ```typescript
1885
+ * new Elysia()
1886
+ * .state({ counter: 0 })
1887
+ * .get('/', (({ counter }) => ++counter)
1888
+ * ```
1889
+ */
1890
+ state<Name extends string | number | symbol, Value>(name: Name, value: Value): Elysia<BasePath, {
1891
+ request: Decorators['request'];
1892
+ store: Prettify<Decorators['store'] & {
1893
+ [name in Name]: Value;
1894
+ }>;
1895
+ derive: Decorators['derive'];
1896
+ resolve: Decorators['resolve'];
1897
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1898
+ /**
1899
+ * ### state
1900
+ * Assign global mutatable state accessible for all handler
1901
+ *
1902
+ * ---
1903
+ * @example
1904
+ * ```typescript
1905
+ * new Elysia()
1906
+ * .state('counter', 0)
1907
+ * .get('/', (({ counter }) => ++counter)
1908
+ * ```
1909
+ */
1910
+ state<Store extends Record<string, unknown>>(store: Store): Elysia<BasePath, {
1911
+ request: Decorators['request'];
1912
+ store: Prettify<Decorators['store'] & Store>;
1913
+ derive: Decorators['derive'];
1914
+ resolve: Decorators['resolve'];
1915
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1916
+ state<const NewStore extends Record<string, unknown>>(mapper: (decorators: Decorators['store']) => NewStore): Elysia<BasePath, {
1917
+ request: Decorators['request'];
1918
+ store: NewStore;
1919
+ derive: Decorators['derive'];
1920
+ resolve: Decorators['resolve'];
1921
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1922
+ /**
1923
+ * ### decorate
1924
+ * Define custom method to `Context` accessible for all handler
1925
+ *
1926
+ * ---
1927
+ * @example
1928
+ * ```typescript
1929
+ * new Elysia()
1930
+ * .decorate('getDate', () => Date.now())
1931
+ * .get('/', (({ getDate }) => getDate())
1932
+ * ```
1933
+ */
1934
+ decorate<const Name extends string, const Value>(name: Name, value: Value): Elysia<BasePath, {
1935
+ request: Prettify<Decorators['request'] & {
1936
+ [name in Name]: Value;
1937
+ }>;
1938
+ store: Decorators['store'];
1939
+ derive: Decorators['derive'];
1940
+ resolve: Decorators['resolve'];
1941
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1942
+ /**
1943
+ * ### decorate
1944
+ * Define custom method to `Context` accessible for all handler
1945
+ *
1946
+ * ---
1947
+ * @example
1948
+ * ```typescript
1949
+ * new Elysia()
1950
+ * .decorate('getDate', () => Date.now())
1951
+ * .get('/', (({ getDate }) => getDate())
1952
+ * ```
1953
+ */
1954
+ decorate<const NewDecorators extends Record<string, unknown>>(decorators: NewDecorators): Elysia<BasePath, {
1955
+ request: Prettify<Decorators['request'] & NewDecorators>;
1956
+ store: Decorators['store'];
1957
+ derive: Decorators['derive'];
1958
+ resolve: Decorators['resolve'];
1959
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1960
+ decorate<const NewDecorators extends Record<string, unknown>>(mapper: (decorators: Decorators['request']) => NewDecorators): Elysia<BasePath, {
1961
+ request: NewDecorators;
1962
+ store: Decorators['store'];
1963
+ derive: Decorators['derive'];
1964
+ resolve: Decorators['resolve'];
1965
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1966
+ /**
1967
+ * Derive new property for each request with access to `Context`.
1968
+ *
1969
+ * If error is thrown, the scope will skip to handling error instead.
1970
+ *
1971
+ * ---
1972
+ * @example
1973
+ * new Elysia()
1974
+ * .state('counter', 1)
1975
+ * .derive(({ store }) => ({
1976
+ * increase() {
1977
+ * store.counter++
1978
+ * }
1979
+ * }))
1980
+ */
1981
+ derive<Derivative extends Object>(transform: (context: Prettify<Context<ParentSchema, Decorators>>) => MaybePromise<Derivative> extends {
1982
+ store: any;
1983
+ } ? never : Derivative): Elysia<BasePath, {
1984
+ request: Decorators['request'];
1985
+ store: Decorators['store'];
1986
+ derive: Prettify<Decorators['derive'] & Awaited<Derivative>>;
1987
+ resolve: Decorators['resolve'];
1988
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
1989
+ model<Name extends string, Model extends TSchema>(name: Name, model: Model): Elysia<BasePath, Decorators, {
1990
+ type: Prettify<Definitions['type'] & {
1991
+ [name in Name]: Static<Model>;
1992
+ }>;
1993
+ error: Definitions['error'];
1994
+ }, ParentSchema, Macro, Routes, Scoped>;
1995
+ model<Recorder extends Record<string, TSchema>>(record: Recorder): Elysia<BasePath, Decorators, {
1996
+ type: Prettify<Definitions['type'] & {
1997
+ [key in keyof Recorder]: Static<Recorder[key]>;
1998
+ }>;
1999
+ error: Definitions['error'];
2000
+ }, ParentSchema, Macro, Routes, Scoped>;
2001
+ model<const NewType extends Record<string, TSchema>>(mapper: (decorators: {
2002
+ [type in keyof Definitions['type']]: ReturnType<typeof t.Unsafe<Definitions['type'][type]>>;
2003
+ }) => NewType): Elysia<BasePath, Decorators, {
2004
+ type: {
2005
+ [x in keyof NewType]: Static<NewType[x]>;
2006
+ };
2007
+ error: Definitions['error'];
2008
+ }, ParentSchema, Macro, Routes, Scoped>;
2009
+ mapDerive<const NewStore extends Record<string, unknown>>(mapper: (decorators: Decorators['request']) => MaybePromise<NewStore>): Elysia<BasePath, {
2010
+ request: Decorators['request'];
2011
+ store: NewStore;
2012
+ derive: Decorators['derive'];
2013
+ resolve: Decorators['resolve'];
2014
+ }, Definitions, ParentSchema, Macro, Routes, Scoped>;
2015
+ affix<const Base extends 'prefix' | 'suffix', const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(base: Base, type: Type, word: Word): Elysia<BasePath, {
2016
+ request: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Decorators['request']> : AddPrefixCapitalize<Word, Decorators['request']> : AddSuffixCapitalize<Word, Decorators['request']> : Decorators['request'];
2017
+ store: Type extends 'state' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Decorators['store']> : AddPrefixCapitalize<Word, Decorators['store']> : AddSuffix<Word, Decorators['store']> : Decorators['store'];
2018
+ derive: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Decorators['derive']> : AddPrefixCapitalize<Word, Decorators['derive']> : AddSuffixCapitalize<Word, Decorators['derive']> : Decorators['derive'];
2019
+ resolve: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Decorators['resolve']> : AddPrefixCapitalize<Word, Decorators['resolve']> : AddSuffixCapitalize<Word, Decorators['resolve']> : Decorators['resolve'];
2020
+ }, {
2021
+ type: Type extends 'model' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Definitions['type']> : AddPrefixCapitalize<Word, Definitions['type']> : AddSuffixCapitalize<Word, Definitions['type']> : Definitions['type'];
2022
+ error: Type extends 'error' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Definitions['error']> : AddPrefixCapitalize<Word, Definitions['error']> : AddSuffixCapitalize<Word, Definitions['error']> : Definitions['error'];
2023
+ }, ParentSchema, Macro, Routes, Scoped>;
2024
+ prefix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, {
2025
+ request: Type extends "all" | "decorator" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Decorators["request"]> : AddPrefixCapitalize<Word, Decorators["request"]> : Decorators["request"];
2026
+ store: Type extends "all" | "state" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Decorators["store"]> : AddPrefixCapitalize<Word, Decorators["store"]> : Decorators["store"];
2027
+ derive: Type extends "all" | "decorator" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Decorators["derive"]> : AddPrefixCapitalize<Word, Decorators["derive"]> : Decorators["derive"];
2028
+ resolve: Type extends "all" | "decorator" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Decorators["resolve"]> : AddPrefixCapitalize<Word, Decorators["resolve"]> : Decorators["resolve"];
2029
+ }, {
2030
+ type: Type extends "all" | "model" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Definitions["type"]> : AddPrefixCapitalize<Word, Definitions["type"]> : Definitions["type"];
2031
+ error: Type extends "all" | "error" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Definitions["error"]> : AddPrefixCapitalize<Word, Definitions["error"]> : Definitions["error"];
2032
+ }, ParentSchema, Macro, Routes, Scoped>;
2033
+ suffix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, {
2034
+ request: Type extends "all" | "decorator" ? AddSuffixCapitalize<Word, Decorators["request"]> : Decorators["request"];
2035
+ store: Type extends "all" | "state" ? AddSuffix<Word, Decorators["store"]> : Decorators["store"];
2036
+ derive: Type extends "all" | "decorator" ? AddSuffixCapitalize<Word, Decorators["derive"]> : Decorators["derive"];
2037
+ resolve: Type extends "all" | "decorator" ? AddSuffixCapitalize<Word, Decorators["resolve"]> : Decorators["resolve"];
2038
+ }, {
2039
+ type: Type extends "all" | "model" ? AddSuffixCapitalize<Word, Definitions["type"]> : Definitions["type"];
2040
+ error: Type extends "all" | "error" ? AddSuffixCapitalize<Word, Definitions["error"]> : Definitions["error"];
2041
+ }, ParentSchema, Macro, Routes, Scoped>;
2042
+ compile(): this;
2043
+ handle: (request: Request) => Promise<Response>;
2044
+ /**
2045
+ * Use handle can be either sync or async to save performance.
2046
+ *
2047
+ * Beside benchmark purpose, please use 'handle' instead.
2048
+ */
2049
+ fetch: (request: Request) => MaybePromise<Response>;
2050
+ private handleError;
2051
+ private outerErrorHandler;
2052
+ /**
2053
+ * ### listen
2054
+ * Assign current instance to port and start serving
2055
+ *
2056
+ * ---
2057
+ * @example
2058
+ * ```typescript
2059
+ * new Elysia()
2060
+ * .get("/", () => 'hi')
2061
+ * .listen(8080)
2062
+ * ```
2063
+ */
2064
+ listen: (options: string | number | Partial<Serve>, callback?: ListenCallback) => this;
2065
+ /**
2066
+ * ### stop
2067
+ * Stop server from serving
2068
+ *
2069
+ * ---
2070
+ * @example
2071
+ * ```typescript
2072
+ * const app = new Elysia()
2073
+ * .get("/", () => 'hi')
2074
+ * .listen(8080)
2075
+ *
2076
+ * // Sometime later
2077
+ * app.stop()
2078
+ * ```
2079
+ */
2080
+ stop: () => Promise<void>;
2081
+ /**
2082
+ * Wait until all lazy loaded modules all load is fully
2083
+ */
2084
+ get modules(): Promise<Elysia<any, any, {
2085
+ type: {};
2086
+ error: {};
2087
+ }, {}, {}, {}, false>[]>;
2088
+ }
2089
+
2090
+ export { type GracefulHandler as $, type InputSchema as A, type MergeSchema as B, type Context as C, type DecoratorBase as D, Elysia as E, type OptionalHandler as F, type GetPathParameter as G, type Handler as H, InternalServerError as I, type AfterHandler as J, type MapResponse as K, type LifeCycleStore as L, type MaybeArray$1 as M, NotFoundError as N, type ObjectValues as O, type PreHandler as P, type VoidHandler as Q, type Reconcile as R, type SchemaValidator as S, type TraceReporter as T, type UnwrapSchema as U, ValidationError as V, type TransformHandler as W, type TraceEvent as X, type TraceProcess as Y, type TraceListener as Z, type BodyHandler as _, type ElysiaErrors as a, type ErrorHandler as a0, type Isolate as a1, type LocalHook as a2, type InternalRoute as a3, type ListenCallback as a4, type AddPrefix as a5, type AddPrefixCapitalize as a6, type AddSuffix as a7, type AddSuffixCapitalize as a8, type Checksum as a9, t as aA, ElysiaTypeOptions as aB, ElysiaType as aC, type TCookie as aD, isNotEmpty as aE, parseSetCookies as aF, cookieToHeader as aG, mapResponse as aH, mapEarlyResponse as aI, mapCompactResponse as aJ, errorToResponse as aK, type BaseMacro as aa, type MacroToProperty as ab, type MacroManager as ac, replaceUrlPath as ad, mergeDeep as ae, mergeCookie as af, mergeObjectArray as ag, primitiveHooks as ah, mergeHook as ai, getSchemaValidator as aj, getResponseSchemaValidator as ak, checksum as al, mergeLifeCycle as am, asGlobalHook as an, asGlobal as ao, filterGlobalHook as ap, StatusMap as aq, type HTTPStatusName as ar, signCookie as as, unsignCookie as at, traceBackMacro as au, isNumericString as av, type PreContext as aw, websocket as ax, ElysiaWS as ay, WS as az, type ElysiaConfig as b, type ComposedHandler as c, type TraceHandler as d, type TraceStream as e, type CookieOptions as f, Cookie as g, createCookieJar as h, ERROR_CODE as i, ELYSIA_RESPONSE as j, isProduction as k, error as l, ParseError as m, InvalidCookieSignature as n, type HeadersInit as o, parseCookie as p, type MaybePromise as q, type Prettify as r, type DefinitionBase as s, type RouteBase as t, type RouteSchema as u, type UnwrapRoute as v, type UnwrapGroupGuardRoute as w, type LifeCycleEvent as x, type ContentType as y, type HTTPMethod as z };