elysia 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bun/index.d.ts +1427 -10
- package/dist/bun/index.js +86 -86
- package/dist/bun/index.js.map +5 -5
- package/dist/cjs/compose.d.ts +13 -23
- package/dist/cjs/compose.js +21 -8
- package/dist/cjs/context.d.ts +71 -10
- package/dist/cjs/cookies.d.ts +138 -10
- package/dist/cjs/cookies.js +21 -8
- package/dist/cjs/dynamic-handle.d.ts +14 -10
- package/dist/cjs/dynamic-handle.js +21 -8
- package/dist/cjs/error.d.ts +14 -18
- package/dist/cjs/error.js +21 -8
- package/dist/cjs/handler.d.ts +10 -10
- package/dist/cjs/handler.js +21 -8
- package/dist/cjs/index.d.ts +1427 -10
- package/dist/cjs/index.js +32 -9
- package/dist/cjs/sucrose.d.ts +16 -28
- package/dist/cjs/trace.d.ts +2 -14
- package/dist/cjs/type-system.d.ts +69 -10
- package/dist/cjs/type-system.js +21 -8
- package/dist/cjs/types.d.ts +575 -10
- package/dist/cjs/utils.d.ts +192 -10
- package/dist/cjs/utils.js +21 -8
- package/dist/cjs/ws/index.d.ts +33 -10
- package/dist/cjs/ws/index.js +21 -8
- package/dist/cjs/ws/types.d.ts +57 -10
- package/dist/compose.d.ts +13 -23
- package/dist/compose.mjs +21 -8
- package/dist/context.d.ts +71 -10
- package/dist/cookies.d.ts +138 -10
- package/dist/cookies.mjs +21 -8
- package/dist/dynamic-handle.d.ts +14 -10
- package/dist/dynamic-handle.mjs +21 -8
- package/dist/error.d.ts +14 -18
- package/dist/error.mjs +21 -8
- package/dist/handler.d.ts +10 -10
- package/dist/handler.mjs +21 -8
- package/dist/index.d.ts +1427 -10
- package/dist/index.mjs +28 -9
- package/dist/sucrose.d.ts +16 -28
- package/dist/trace.d.ts +2 -14
- package/dist/type-system.d.ts +69 -10
- package/dist/type-system.mjs +21 -8
- package/dist/types.d.ts +575 -10
- package/dist/utils.d.ts +192 -10
- package/dist/utils.mjs +21 -8
- package/dist/ws/index.d.ts +33 -10
- package/dist/ws/index.mjs +21 -8
- package/dist/ws/types.d.ts +57 -10
- package/package.json +25 -39
- package/tsconfig.dts.json +106 -0
- package/dist/cjs/dynamic-handle-DrPvRYu3.d.ts +0 -2540
- package/dist/dynamic-handle-DrPvRYu3.d.ts +0 -2540
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,10 +1,1427 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
8
|
-
import '
|
|
9
|
-
import '
|
|
10
|
-
import '
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="bun-types" />
|
|
4
|
+
/// <reference types="bun-types" />
|
|
5
|
+
import type { Serve, Server } from 'bun';
|
|
6
|
+
import { Memoirist } from 'memoirist';
|
|
7
|
+
import { type Static, type TSchema } from '@sinclair/typebox';
|
|
8
|
+
import type { Context } from './context';
|
|
9
|
+
import { t } from './type-system';
|
|
10
|
+
import type { WS } from './ws/types';
|
|
11
|
+
import { type DynamicHandler } from './dynamic-handle';
|
|
12
|
+
import type { ElysiaConfig, SingletonBase, DefinitionBase, ComposedHandler, InputSchema, LocalHook, MergeSchema, RouteSchema, UnwrapRoute, InternalRoute, HTTPMethod, SchemaValidator, VoidHandler, PreHandler, BodyHandler, OptionalHandler, AfterHandler, ErrorHandler, LifeCycleStore, MaybePromise, Prettify, Prettify2, ListenCallback, AddPrefix, AddSuffix, AddPrefixCapitalize, AddSuffixCapitalize, TraceHandler, MaybeArray, GracefulHandler, GetPathParameter, MapResponse, MacroManager, BaseMacro, MacroToProperty, TransformHandler, MetadataBase, RouteBase, CreateEden, ComposeElysiaResponse, InlineHandler, LifeCycleType, MacroQueue, EphemeralType, ExcludeElysiaResponse } from './types';
|
|
13
|
+
/**
|
|
14
|
+
* ### Elysia Server
|
|
15
|
+
* Main instance to create web server using Elysia
|
|
16
|
+
*
|
|
17
|
+
* ---
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Elysia } from 'elysia'
|
|
21
|
+
*
|
|
22
|
+
* new Elysia()
|
|
23
|
+
* .get("/", () => "Hello")
|
|
24
|
+
* .listen(8080)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export default class Elysia<const in out BasePath extends string = '', const in out Scoped extends boolean = false, const in out Singleton extends SingletonBase = {
|
|
28
|
+
decorator: {};
|
|
29
|
+
store: {};
|
|
30
|
+
derive: {};
|
|
31
|
+
resolve: {};
|
|
32
|
+
}, const in out Definitions extends DefinitionBase = {
|
|
33
|
+
type: {};
|
|
34
|
+
error: {};
|
|
35
|
+
}, const in out Metadata extends MetadataBase = {
|
|
36
|
+
schema: {};
|
|
37
|
+
macro: {};
|
|
38
|
+
}, const out Routes extends RouteBase = {}, const in out Ephemeral extends EphemeralType = {
|
|
39
|
+
derive: {};
|
|
40
|
+
resolve: {};
|
|
41
|
+
schema: {};
|
|
42
|
+
}, const in out Volatile extends EphemeralType = {
|
|
43
|
+
derive: {};
|
|
44
|
+
resolve: {};
|
|
45
|
+
schema: {};
|
|
46
|
+
}> {
|
|
47
|
+
config: ElysiaConfig<BasePath, Scoped>;
|
|
48
|
+
server: Server | null;
|
|
49
|
+
private dependencies;
|
|
50
|
+
private reporter;
|
|
51
|
+
_routes: Routes;
|
|
52
|
+
_types: {
|
|
53
|
+
Prefix: BasePath;
|
|
54
|
+
Scoped: Scoped;
|
|
55
|
+
Singleton: Singleton;
|
|
56
|
+
Definitions: Definitions;
|
|
57
|
+
Metadata: Metadata;
|
|
58
|
+
};
|
|
59
|
+
_ephemeral: Ephemeral;
|
|
60
|
+
_volatile: Volatile;
|
|
61
|
+
protected singleton: Singleton;
|
|
62
|
+
get store(): Singleton['store'];
|
|
63
|
+
get decorator(): Singleton['decorator'];
|
|
64
|
+
get _scoped(): Scoped;
|
|
65
|
+
protected definitions: {
|
|
66
|
+
type: Record<string, TSchema>;
|
|
67
|
+
error: Record<string, Error>;
|
|
68
|
+
};
|
|
69
|
+
protected extender: {
|
|
70
|
+
macros: MacroQueue;
|
|
71
|
+
};
|
|
72
|
+
protected validator: SchemaValidator | null;
|
|
73
|
+
event: LifeCycleStore;
|
|
74
|
+
telemetry: {
|
|
75
|
+
stack: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
router: {
|
|
78
|
+
http: Memoirist<ComposedHandler>;
|
|
79
|
+
ws: Memoirist<ComposedHandler>;
|
|
80
|
+
dynamic: Memoirist<DynamicHandler>;
|
|
81
|
+
static: {
|
|
82
|
+
http: {
|
|
83
|
+
handlers: ComposedHandler[];
|
|
84
|
+
variables: string;
|
|
85
|
+
map: Record<string, {
|
|
86
|
+
code: string;
|
|
87
|
+
all?: string | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
all: string;
|
|
90
|
+
};
|
|
91
|
+
ws: Record<string, number>;
|
|
92
|
+
};
|
|
93
|
+
history: InternalRoute[];
|
|
94
|
+
};
|
|
95
|
+
protected inference: {
|
|
96
|
+
readonly event: {
|
|
97
|
+
readonly body: false;
|
|
98
|
+
readonly cookie: false;
|
|
99
|
+
readonly headers: false;
|
|
100
|
+
readonly queries: [];
|
|
101
|
+
readonly query: false;
|
|
102
|
+
readonly set: false;
|
|
103
|
+
readonly unknownQueries: false;
|
|
104
|
+
};
|
|
105
|
+
readonly trace: {
|
|
106
|
+
readonly request: false;
|
|
107
|
+
readonly parse: false;
|
|
108
|
+
readonly transform: false;
|
|
109
|
+
readonly handle: false;
|
|
110
|
+
readonly beforeHandle: false;
|
|
111
|
+
readonly afterHandle: false;
|
|
112
|
+
readonly error: false;
|
|
113
|
+
readonly context: false;
|
|
114
|
+
readonly store: false;
|
|
115
|
+
readonly set: false;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
private promisedModules;
|
|
119
|
+
constructor(config?: ElysiaConfig<BasePath, Scoped>);
|
|
120
|
+
private getServer;
|
|
121
|
+
get routes(): InternalRoute[];
|
|
122
|
+
protected routeTree: Map<string, number>;
|
|
123
|
+
private add;
|
|
124
|
+
private setHeaders?;
|
|
125
|
+
headers(header: Context['set']['headers'] | undefined): this;
|
|
126
|
+
/**
|
|
127
|
+
* ### start | Life cycle event
|
|
128
|
+
* Called after server is ready for serving
|
|
129
|
+
*
|
|
130
|
+
* ---
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* new Elysia()
|
|
134
|
+
* .onStart(({ url, port }) => {
|
|
135
|
+
* console.log("Running at ${url}:${port}")
|
|
136
|
+
* })
|
|
137
|
+
* .listen(8080)
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
onStart(handler: MaybeArray<GracefulHandler<this>>): this;
|
|
141
|
+
/**
|
|
142
|
+
* ### request | Life cycle event
|
|
143
|
+
* Called on every new request is accepted
|
|
144
|
+
*
|
|
145
|
+
* ---
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* new Elysia()
|
|
149
|
+
* .onRequest(({ method, url }) => {
|
|
150
|
+
* saveToAnalytic({ method, url })
|
|
151
|
+
* })
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
onRequest<const Schema extends RouteSchema>(handler: MaybeArray<PreHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
155
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
156
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
157
|
+
}>>): this;
|
|
158
|
+
/**
|
|
159
|
+
* ### parse | Life cycle event
|
|
160
|
+
* Callback function to handle body parsing
|
|
161
|
+
*
|
|
162
|
+
* If truthy value is returned, will be assigned to `context.body`
|
|
163
|
+
* Otherwise will skip the callback and look for the next one.
|
|
164
|
+
*
|
|
165
|
+
* Equivalent to Express's body parser
|
|
166
|
+
*
|
|
167
|
+
* ---
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* new Elysia()
|
|
171
|
+
* .onParse((request, contentType) => {
|
|
172
|
+
* if(contentType === "application/json")
|
|
173
|
+
* return request.json()
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
onParse<const Schema extends RouteSchema>(parser: MaybeArray<BodyHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
178
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
179
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
180
|
+
}, BasePath>>): this;
|
|
181
|
+
/**
|
|
182
|
+
* ### parse | Life cycle event
|
|
183
|
+
* Callback function to handle body parsing
|
|
184
|
+
*
|
|
185
|
+
* If truthy value is returned, will be assigned to `context.body`
|
|
186
|
+
* Otherwise will skip the callback and look for the next one.
|
|
187
|
+
*
|
|
188
|
+
* Equivalent to Express's body parser
|
|
189
|
+
*
|
|
190
|
+
* ---
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* new Elysia()
|
|
194
|
+
* .onParse((request, contentType) => {
|
|
195
|
+
* if(contentType === "application/json")
|
|
196
|
+
* return request.json()
|
|
197
|
+
* })
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
onParse<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
|
|
201
|
+
as?: Type;
|
|
202
|
+
}, parser: MaybeArray<BodyHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
203
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
204
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
205
|
+
} : 'scoped' extends Type ? {
|
|
206
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
207
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
208
|
+
} : {
|
|
209
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
210
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
211
|
+
})>>): this;
|
|
212
|
+
/**
|
|
213
|
+
* ### transform | Life cycle event
|
|
214
|
+
* Assign or transform anything related to context before validation.
|
|
215
|
+
*
|
|
216
|
+
* ---
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* new Elysia()
|
|
220
|
+
* .onTransform(({ params }) => {
|
|
221
|
+
* if(params.id)
|
|
222
|
+
* params.id = +params.id
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
onTransform<const Schema extends RouteSchema>(handler: MaybeArray<TransformHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
227
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
228
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
229
|
+
}, BasePath>>): this;
|
|
230
|
+
/**
|
|
231
|
+
* ### transform | Life cycle event
|
|
232
|
+
* Assign or transform anything related to context before validation.
|
|
233
|
+
*
|
|
234
|
+
* ---
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* new Elysia()
|
|
238
|
+
* .onTransform(({ params }) => {
|
|
239
|
+
* if(params.id)
|
|
240
|
+
* params.id = +params.id
|
|
241
|
+
* })
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
onTransform<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
|
|
245
|
+
as?: Type;
|
|
246
|
+
}, handler: MaybeArray<TransformHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
247
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
248
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
249
|
+
} : 'scoped' extends Type ? {
|
|
250
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
251
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
252
|
+
} : {
|
|
253
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
254
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
255
|
+
})>>): this;
|
|
256
|
+
/**
|
|
257
|
+
* Derive new property for each request with access to `Context`.
|
|
258
|
+
*
|
|
259
|
+
* If error is thrown, the scope will skip to handling error instead.
|
|
260
|
+
*
|
|
261
|
+
* ---
|
|
262
|
+
* @example
|
|
263
|
+
* new Elysia()
|
|
264
|
+
* .state('counter', 1)
|
|
265
|
+
* .derive(({ store }) => ({
|
|
266
|
+
* increase() {
|
|
267
|
+
* store.counter++
|
|
268
|
+
* }
|
|
269
|
+
* }))
|
|
270
|
+
*/
|
|
271
|
+
resolve<const Resolver extends Record<string, unknown>, const Type extends LifeCycleType>(options: {
|
|
272
|
+
as?: Type;
|
|
273
|
+
}, resolver: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & ('global' extends Type ? {
|
|
274
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
275
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
276
|
+
} : 'scoped' extends Type ? {
|
|
277
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
278
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
279
|
+
} : {
|
|
280
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
281
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
282
|
+
})>>) => MaybePromise<Resolver>): Type extends 'global' ? Elysia<BasePath, Scoped, {
|
|
283
|
+
decorator: Singleton['decorator'];
|
|
284
|
+
store: Singleton['store'];
|
|
285
|
+
derive: Singleton['resolve'];
|
|
286
|
+
resolve: Prettify<Singleton['resolve'] & ExcludeElysiaResponse<Resolver>>;
|
|
287
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile> : Type extends 'scoped' ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, {
|
|
288
|
+
derive: Ephemeral['resolve'];
|
|
289
|
+
resolve: Prettify<Ephemeral['resolve'] & ExcludeElysiaResponse<Resolver>>;
|
|
290
|
+
schema: Ephemeral['schema'];
|
|
291
|
+
}, Volatile> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
292
|
+
derive: Volatile['resolve'];
|
|
293
|
+
resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<Resolver>>;
|
|
294
|
+
schema: Volatile['schema'];
|
|
295
|
+
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Derive new property for each request with access to `Context`.
|
|
298
|
+
*
|
|
299
|
+
* If error is thrown, the scope will skip to handling error instead.
|
|
300
|
+
*
|
|
301
|
+
* ---
|
|
302
|
+
* @example
|
|
303
|
+
* new Elysia()
|
|
304
|
+
* .state('counter', 1)
|
|
305
|
+
* .derive(({ store }) => ({
|
|
306
|
+
* increase() {
|
|
307
|
+
* store.counter++
|
|
308
|
+
* }
|
|
309
|
+
* }))
|
|
310
|
+
*/
|
|
311
|
+
resolve<const Resolver extends Record<string, unknown>>(resolver: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
|
|
312
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
313
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
314
|
+
}, BasePath>>) => MaybePromise<Resolver>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
315
|
+
derive: Volatile['resolve'];
|
|
316
|
+
resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<Resolver>>;
|
|
317
|
+
schema: Volatile['schema'];
|
|
318
|
+
}>;
|
|
319
|
+
mapResolve<const NewResolver extends Record<string, unknown>>(mapper: (context: Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
|
|
320
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
321
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
322
|
+
}, BasePath>) => MaybePromise<NewResolver>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
323
|
+
derive: Volatile['derive'];
|
|
324
|
+
resolve: NewResolver;
|
|
325
|
+
schema: Volatile['schema'];
|
|
326
|
+
}>;
|
|
327
|
+
mapResolve<const NewResolver extends Record<string, unknown>, const Type extends LifeCycleType>(options: {
|
|
328
|
+
as?: Type;
|
|
329
|
+
}, mapper: (context: Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & ('global' extends Type ? {
|
|
330
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
331
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
332
|
+
} : 'scoped' extends Type ? {
|
|
333
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
334
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
335
|
+
} : {
|
|
336
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
337
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
338
|
+
})>) => MaybePromise<NewResolver>): Type extends 'global' ? Elysia<BasePath, Scoped, {
|
|
339
|
+
decorator: Singleton['decorator'];
|
|
340
|
+
store: Singleton['store'];
|
|
341
|
+
derive: Singleton['resolve'];
|
|
342
|
+
resolve: Awaited<NewResolver>;
|
|
343
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile> : Type extends 'scoped' ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, {
|
|
344
|
+
derive: Ephemeral['resolve'];
|
|
345
|
+
resolve: Prettify<Ephemeral['resolve'] & ExcludeElysiaResponse<NewResolver>>;
|
|
346
|
+
schema: Ephemeral['schema'];
|
|
347
|
+
}, Volatile> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
348
|
+
derive: Volatile['resolve'];
|
|
349
|
+
resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<NewResolver>>;
|
|
350
|
+
schema: Volatile['schema'];
|
|
351
|
+
}>;
|
|
352
|
+
/**
|
|
353
|
+
* ### Before Handle | Life cycle event
|
|
354
|
+
* Execute after validation and before the main route handler.
|
|
355
|
+
*
|
|
356
|
+
* If truthy value is returned, will be assigned as `Response` and skip the main handler
|
|
357
|
+
*
|
|
358
|
+
* ---
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* new Elysia()
|
|
362
|
+
* .onBeforeHandle(({ params: { id }, status }) => {
|
|
363
|
+
* if(id && !isExisted(id)) {
|
|
364
|
+
* status(401)
|
|
365
|
+
*
|
|
366
|
+
* return "Unauthorized"
|
|
367
|
+
* }
|
|
368
|
+
* })
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
onBeforeHandle<const Schema extends RouteSchema>(handler: MaybeArray<OptionalHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
372
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
373
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
374
|
+
}>>): this;
|
|
375
|
+
/**
|
|
376
|
+
* ### Before Handle | Life cycle event
|
|
377
|
+
* Execute after validation and before the main route handler.
|
|
378
|
+
*
|
|
379
|
+
* If truthy value is returned, will be assigned as `Response` and skip the main handler
|
|
380
|
+
*
|
|
381
|
+
* ---
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* new Elysia()
|
|
385
|
+
* .onBeforeHandle(({ params: { id }, status }) => {
|
|
386
|
+
* if(id && !isExisted(id)) {
|
|
387
|
+
* status(401)
|
|
388
|
+
*
|
|
389
|
+
* return "Unauthorized"
|
|
390
|
+
* }
|
|
391
|
+
* })
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
onBeforeHandle<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
|
|
395
|
+
as?: Type;
|
|
396
|
+
}, handler: MaybeArray<OptionalHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
397
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
398
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
399
|
+
} : 'scoped' extends Type ? {
|
|
400
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
401
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
402
|
+
} : {
|
|
403
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
404
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
405
|
+
}), BasePath>>): this;
|
|
406
|
+
/**
|
|
407
|
+
* ### After Handle | Life cycle event
|
|
408
|
+
* Intercept request **after** main handler is called.
|
|
409
|
+
*
|
|
410
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
411
|
+
*
|
|
412
|
+
* ---
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* new Elysia()
|
|
416
|
+
* .onAfterHandle((context, response) => {
|
|
417
|
+
* if(typeof response === "object")
|
|
418
|
+
* return JSON.stringify(response)
|
|
419
|
+
* })
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
onAfterHandle<const Schema extends RouteSchema>(handler: MaybeArray<AfterHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
423
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
424
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
425
|
+
}, BasePath>>): this;
|
|
426
|
+
/**
|
|
427
|
+
* ### After Handle | Life cycle event
|
|
428
|
+
* Intercept request **after** main handler is called.
|
|
429
|
+
*
|
|
430
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
431
|
+
*
|
|
432
|
+
* ---
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* new Elysia()
|
|
436
|
+
* .onAfterHandle((context, response) => {
|
|
437
|
+
* if(typeof response === "object")
|
|
438
|
+
* return JSON.stringify(response)
|
|
439
|
+
* })
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
onAfterHandle<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
|
|
443
|
+
as?: LifeCycleType;
|
|
444
|
+
}, handler: MaybeArray<AfterHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
445
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
446
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
447
|
+
} : 'scoped' extends Type ? {
|
|
448
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
449
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
450
|
+
} : {
|
|
451
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
452
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
453
|
+
})>>): this;
|
|
454
|
+
/**
|
|
455
|
+
* ### After Handle | Life cycle event
|
|
456
|
+
* Intercept request **after** main handler is called.
|
|
457
|
+
*
|
|
458
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
459
|
+
*
|
|
460
|
+
* ---
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* new Elysia()
|
|
464
|
+
* .mapResponse((context, response) => {
|
|
465
|
+
* if(typeof response === "object")
|
|
466
|
+
* return JSON.stringify(response)
|
|
467
|
+
* })
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
mapResponse<const Schema extends RouteSchema>(handler: MaybeArray<MapResponse<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
471
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
472
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
473
|
+
}, BasePath>>): this;
|
|
474
|
+
/**
|
|
475
|
+
* ### After Handle | Life cycle event
|
|
476
|
+
* Intercept request **after** main handler is called.
|
|
477
|
+
*
|
|
478
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
479
|
+
*
|
|
480
|
+
* ---
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* new Elysia()
|
|
484
|
+
* .mapResponse((context, response) => {
|
|
485
|
+
* if(typeof response === "object")
|
|
486
|
+
* return JSON.stringify(response)
|
|
487
|
+
* })
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
mapResponse<const Schema extends RouteSchema, Type extends LifeCycleType>(options: {
|
|
491
|
+
as?: Type;
|
|
492
|
+
}, handler: MaybeArray<MapResponse<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
493
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
494
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
495
|
+
} : 'scoped' extends Type ? {
|
|
496
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
497
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
498
|
+
} : {
|
|
499
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
500
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
501
|
+
})>>): this;
|
|
502
|
+
/**
|
|
503
|
+
* ### response | Life cycle event
|
|
504
|
+
* Called when handler is executed
|
|
505
|
+
* Good for analytic metrics
|
|
506
|
+
*
|
|
507
|
+
* ---
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* new Elysia()
|
|
511
|
+
* .onError(({ code }) => {
|
|
512
|
+
* if(code === "NOT_FOUND")
|
|
513
|
+
* return "Path not found :("
|
|
514
|
+
* })
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
onResponse<const Schema extends RouteSchema>(handler: MaybeArray<VoidHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & {
|
|
518
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
519
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
520
|
+
}>>): this;
|
|
521
|
+
/**
|
|
522
|
+
* ### response | Life cycle event
|
|
523
|
+
* Called when handler is executed
|
|
524
|
+
* Good for analytic metrics
|
|
525
|
+
*
|
|
526
|
+
* ---
|
|
527
|
+
* @example
|
|
528
|
+
* ```typescript
|
|
529
|
+
* new Elysia()
|
|
530
|
+
* .onError(({ code }) => {
|
|
531
|
+
* if(code === "NOT_FOUND")
|
|
532
|
+
* return "Path not found :("
|
|
533
|
+
* })
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
onResponse<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
|
|
537
|
+
as?: Type;
|
|
538
|
+
}, handler: MaybeArray<VoidHandler<MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton & ('global' extends Type ? {
|
|
539
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
540
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
541
|
+
} : 'scoped' extends Type ? {
|
|
542
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
543
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
544
|
+
} : {
|
|
545
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
546
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
547
|
+
})>>): this;
|
|
548
|
+
/**
|
|
549
|
+
* ### After Handle | Life cycle event
|
|
550
|
+
* Intercept request **after** main handler is called.
|
|
551
|
+
*
|
|
552
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
553
|
+
*
|
|
554
|
+
* ---
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* new Elysia()
|
|
558
|
+
* .onAfterHandle((context, response) => {
|
|
559
|
+
* if(typeof response === "object")
|
|
560
|
+
* return JSON.stringify(response)
|
|
561
|
+
* })
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
trace<const Schema extends RouteSchema>(handler: MaybeArray<TraceHandler<Schema, Singleton>>): this;
|
|
565
|
+
/**
|
|
566
|
+
* ### After Handle | Life cycle event
|
|
567
|
+
* Intercept request **after** main handler is called.
|
|
568
|
+
*
|
|
569
|
+
* If truthy value is returned, will be assigned as `Response`
|
|
570
|
+
*
|
|
571
|
+
* ---
|
|
572
|
+
* @example
|
|
573
|
+
* ```typescript
|
|
574
|
+
* new Elysia()
|
|
575
|
+
* .onAfterHandle((context, response) => {
|
|
576
|
+
* if(typeof response === "object")
|
|
577
|
+
* return JSON.stringify(response)
|
|
578
|
+
* })
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
trace<const Schema extends RouteSchema>(options: {
|
|
582
|
+
as?: LifeCycleType;
|
|
583
|
+
}, handler: MaybeArray<TraceHandler<Schema, Singleton>>): this;
|
|
584
|
+
/**
|
|
585
|
+
* Register errors
|
|
586
|
+
*
|
|
587
|
+
* ---
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* class CustomError extends Error {
|
|
591
|
+
* constructor() {
|
|
592
|
+
* super()
|
|
593
|
+
* }
|
|
594
|
+
* }
|
|
595
|
+
*
|
|
596
|
+
* new Elysia()
|
|
597
|
+
* .error('CUSTOM_ERROR', CustomError)
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
error<const Errors extends Record<string, {
|
|
601
|
+
prototype: Error;
|
|
602
|
+
}>>(errors: Errors): Elysia<BasePath, Scoped, Singleton, {
|
|
603
|
+
type: Definitions['type'];
|
|
604
|
+
error: Definitions['error'] & {
|
|
605
|
+
[K in keyof Errors]: Errors[K] extends {
|
|
606
|
+
prototype: infer LiteralError extends Error;
|
|
607
|
+
} ? LiteralError : Errors[K];
|
|
608
|
+
};
|
|
609
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
610
|
+
/**
|
|
611
|
+
* Register errors
|
|
612
|
+
*
|
|
613
|
+
* ---
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* class CustomError extends Error {
|
|
617
|
+
* constructor() {
|
|
618
|
+
* super()
|
|
619
|
+
* }
|
|
620
|
+
* }
|
|
621
|
+
*
|
|
622
|
+
* new Elysia()
|
|
623
|
+
* .error({
|
|
624
|
+
* CUSTOM_ERROR: CustomError
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
error<Name extends string, const CustomError extends {
|
|
629
|
+
prototype: Error;
|
|
630
|
+
}>(name: Name, errors: CustomError): Elysia<BasePath, Scoped, Singleton, {
|
|
631
|
+
type: Definitions['type'];
|
|
632
|
+
error: Definitions['error'] & {
|
|
633
|
+
[name in Name]: CustomError extends {
|
|
634
|
+
prototype: infer LiteralError extends Error;
|
|
635
|
+
} ? LiteralError : CustomError;
|
|
636
|
+
};
|
|
637
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
638
|
+
/**
|
|
639
|
+
* Register errors
|
|
640
|
+
*
|
|
641
|
+
* ---
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* class CustomError extends Error {
|
|
645
|
+
* constructor() {
|
|
646
|
+
* super()
|
|
647
|
+
* }
|
|
648
|
+
* }
|
|
649
|
+
*
|
|
650
|
+
* new Elysia()
|
|
651
|
+
* .error('CUSTOM_ERROR', CustomError)
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
error<const NewErrors extends Record<string, Error>>(mapper: (decorators: Definitions['error']) => NewErrors): Elysia<BasePath, Scoped, Singleton, {
|
|
655
|
+
type: Definitions['type'];
|
|
656
|
+
error: {
|
|
657
|
+
[K in keyof NewErrors]: NewErrors[K] extends {
|
|
658
|
+
prototype: infer LiteralError extends Error;
|
|
659
|
+
} ? LiteralError : never;
|
|
660
|
+
};
|
|
661
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
662
|
+
/**
|
|
663
|
+
* ### Error | Life cycle event
|
|
664
|
+
* Called when error is thrown during processing request
|
|
665
|
+
*
|
|
666
|
+
* ---
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* new Elysia()
|
|
670
|
+
* .onError(({ code }) => {
|
|
671
|
+
* if(code === "NOT_FOUND")
|
|
672
|
+
* return "Path not found :("
|
|
673
|
+
* })
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
onError<const Schema extends RouteSchema>(handler: ErrorHandler<Definitions['error'], MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton>): this;
|
|
677
|
+
/**
|
|
678
|
+
* ### Error | Life cycle event
|
|
679
|
+
* Called when error is thrown during processing request
|
|
680
|
+
*
|
|
681
|
+
* ---
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* new Elysia()
|
|
685
|
+
* .onError(({ code }) => {
|
|
686
|
+
* if(code === "NOT_FOUND")
|
|
687
|
+
* return "Path not found :("
|
|
688
|
+
* })
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
onError<const Schema extends RouteSchema>(options: {
|
|
692
|
+
as?: LifeCycleType;
|
|
693
|
+
}, handler: ErrorHandler<Definitions['error'], MergeSchema<Schema, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, Singleton>): this;
|
|
694
|
+
/**
|
|
695
|
+
* ### stop | Life cycle event
|
|
696
|
+
* Called after server stop serving request
|
|
697
|
+
*
|
|
698
|
+
* ---
|
|
699
|
+
* @example
|
|
700
|
+
* ```typescript
|
|
701
|
+
* new Elysia()
|
|
702
|
+
* .onStop((app) => {
|
|
703
|
+
* cleanup()
|
|
704
|
+
* })
|
|
705
|
+
* ```
|
|
706
|
+
*/
|
|
707
|
+
onStop(handler: MaybeArray<GracefulHandler<this>>): this;
|
|
708
|
+
/**
|
|
709
|
+
* ### on
|
|
710
|
+
* Syntax sugar for attaching life cycle event by name
|
|
711
|
+
*
|
|
712
|
+
* Does the exact same thing as `.on[Event]()`
|
|
713
|
+
*
|
|
714
|
+
* ---
|
|
715
|
+
* @example
|
|
716
|
+
* ```typescript
|
|
717
|
+
* new Elysia()
|
|
718
|
+
* .on('error', ({ code }) => {
|
|
719
|
+
* if(code === "NOT_FOUND")
|
|
720
|
+
* return "Path not found :("
|
|
721
|
+
* })
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
on<Event extends keyof LifeCycleStore>(type: Exclude<Event, 'onResponse'> | 'response', handlers: MaybeArray<Extract<LifeCycleStore[Event], Function[]>[0]>): this;
|
|
725
|
+
/**
|
|
726
|
+
* ### on
|
|
727
|
+
* Syntax sugar for attaching life cycle event by name
|
|
728
|
+
*
|
|
729
|
+
* Does the exact same thing as `.on[Event]()`
|
|
730
|
+
*
|
|
731
|
+
* ---
|
|
732
|
+
* @example
|
|
733
|
+
* ```typescript
|
|
734
|
+
* new Elysia()
|
|
735
|
+
* .on('error', ({ code }) => {
|
|
736
|
+
* if(code === "NOT_FOUND")
|
|
737
|
+
* return "Path not found :("
|
|
738
|
+
* })
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
on<const Event extends keyof LifeCycleStore>(options: {
|
|
742
|
+
as?: LifeCycleType;
|
|
743
|
+
}, type: Exclude<Event, 'onResponse'> | 'response', handlers: MaybeArray<Extract<LifeCycleStore[Event], Function[]>[0]>): this;
|
|
744
|
+
group<const Prefix extends string, const NewElysia extends Elysia<any, any, any, any, any, any, any, any>>(prefix: Prefix, run: (group: Elysia<`${BasePath}${Prefix}`, Scoped, Singleton, Definitions, Metadata, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
745
|
+
group<const Prefix extends string, const NewElysia extends Elysia<any, any, any, any, any, any, any, any>, const Input extends InputSchema<Extract<keyof Definitions['type'], string>>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['type']>, Metadata['schema']>>(prefix: Prefix, schema: LocalHook<Input, Schema, Singleton & {
|
|
746
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
747
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
748
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Prefix}`>, run: (group: Elysia<`${BasePath}${Prefix}`, false, Singleton, Definitions, {
|
|
749
|
+
schema: Schema;
|
|
750
|
+
macro: Metadata['macro'];
|
|
751
|
+
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & NewElysia['_routes'], Ephemeral, Volatile>;
|
|
752
|
+
guard<const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema']>>(hook: LocalHook<LocalSchema, Schema, Singleton & {
|
|
753
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
754
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
755
|
+
}, Definitions['error'], Metadata['macro'], BasePath>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
756
|
+
derive: Volatile['resolve'];
|
|
757
|
+
resolve: Volatile['resolve'];
|
|
758
|
+
schema: MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>;
|
|
759
|
+
}>;
|
|
760
|
+
guard<const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const NewElysia extends Elysia<any, any, any, any, any, any, any, any>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema']>>(run: (group: Elysia<BasePath, Scoped, Singleton, Definitions, {
|
|
761
|
+
schema: Prettify<Schema>;
|
|
762
|
+
macro: Metadata['macro'];
|
|
763
|
+
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
764
|
+
guard<const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const NewElysia extends Elysia<any, any, any, any, any, any, any, any>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema']>>(schema: LocalHook<LocalSchema, Schema, Singleton & {
|
|
765
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
766
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
767
|
+
}, Definitions['error'], Metadata['macro'], ''>, run: (group: Elysia<BasePath, Scoped, Singleton, Definitions, {
|
|
768
|
+
schema: Prettify<Schema>;
|
|
769
|
+
macro: Metadata['macro'];
|
|
770
|
+
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
771
|
+
/**
|
|
772
|
+
* Inline fn
|
|
773
|
+
*/
|
|
774
|
+
use<const NewElysia extends Elysia<any, any, any, any, any, any, any, any>, const Param extends Elysia<any, any, any, any, any, any, any, any> = this>(plugin: MaybePromise<(app: Param) => MaybePromise<NewElysia>>): NewElysia['_scoped'] extends false ? Elysia<BasePath, Scoped, Prettify2<Singleton & NewElysia['_types']['Singleton']>, Prettify2<Definitions & NewElysia['_types']['Definitions']>, Prettify2<Metadata & NewElysia['_types']['Metadata']>, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Prettify<Ephemeral & NewElysia['_ephemeral']>, Prettify2<Volatile & NewElysia['_volatile']>> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
775
|
+
/**
|
|
776
|
+
* Entire Instance
|
|
777
|
+
**/
|
|
778
|
+
use<const NewElysia extends Elysia<any, any, any, any, any, any, any, any>>(instance: MaybePromise<NewElysia>): NewElysia['_scoped'] extends false ? Elysia<BasePath, Scoped, Prettify2<Singleton & NewElysia['_types']['Singleton']>, Prettify2<Definitions & NewElysia['_types']['Definitions']>, Prettify2<Metadata & NewElysia['_types']['Metadata']>, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Ephemeral, Prettify2<Volatile & NewElysia['_ephemeral']>> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
779
|
+
/**
|
|
780
|
+
* Import fn
|
|
781
|
+
*/
|
|
782
|
+
use<const NewElysia extends Elysia<any, any, any, any, any, any, any, any>>(plugin: Promise<{
|
|
783
|
+
default: (elysia: Elysia<any, any, any, any, any, any, any, any>) => MaybePromise<NewElysia>;
|
|
784
|
+
}>): NewElysia['_scoped'] extends false ? Elysia<BasePath, Scoped, Prettify2<Singleton & NewElysia['_types']['Singleton']>, Prettify2<Definitions & NewElysia['_types']['Definitions']>, Prettify2<Metadata & NewElysia['_types']['Metadata']>, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Prettify2<Ephemeral & NewElysia['_ephemeral']>, Prettify2<Volatile & NewElysia['_volatile']>> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, BasePath extends `` ? Routes & NewElysia['_routes'] : Routes & CreateEden<BasePath, NewElysia['_routes']>, Ephemeral, Volatile>;
|
|
785
|
+
/**
|
|
786
|
+
* Import entire instance
|
|
787
|
+
*/
|
|
788
|
+
use<const LazyLoadElysia extends Elysia<any, any, any, any, any, any, any, any>>(plugin: Promise<{
|
|
789
|
+
default: LazyLoadElysia;
|
|
790
|
+
}>): LazyLoadElysia['_scoped'] extends false ? Elysia<BasePath, Scoped, Prettify2<Singleton & LazyLoadElysia['_types']['Singleton']>, Prettify2<Definitions & LazyLoadElysia['_types']['Definitions']>, Prettify2<Metadata & LazyLoadElysia['_types']['Metadata']>, BasePath extends `` ? Routes & LazyLoadElysia['_routes'] : Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>, Ephemeral, Prettify2<Volatile & LazyLoadElysia['_ephemeral']>> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, BasePath extends `` ? Routes & LazyLoadElysia['_routes'] : Routes & CreateEden<BasePath, LazyLoadElysia['_routes']>, Ephemeral, Volatile>;
|
|
791
|
+
private _use;
|
|
792
|
+
macro<const NewMacro extends BaseMacro>(macro: (route: MacroManager<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
|
|
793
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
794
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
795
|
+
}, Definitions['error']>) => NewMacro): Elysia<BasePath, Scoped, Singleton, Definitions, {
|
|
796
|
+
schema: Metadata['schema'];
|
|
797
|
+
macro: Metadata['macro'] & Partial<MacroToProperty<NewMacro>>;
|
|
798
|
+
}, Routes, Ephemeral, Volatile>;
|
|
799
|
+
mount(handle: ((request: Request) => MaybePromise<Response>) | Elysia<any, any, any, any, any, any, any, any>): this;
|
|
800
|
+
mount(path: string, handle: ((request: Request) => MaybePromise<Response>) | Elysia<any, any, any, any, any, any, any, any>): this;
|
|
801
|
+
/**
|
|
802
|
+
* ### get
|
|
803
|
+
* Register handler for path with method [GET]
|
|
804
|
+
*
|
|
805
|
+
* ---
|
|
806
|
+
* @example
|
|
807
|
+
* ```typescript
|
|
808
|
+
* import { Elysia, t } from 'elysia'
|
|
809
|
+
*
|
|
810
|
+
* new Elysia()
|
|
811
|
+
* .get('/', () => 'hi')
|
|
812
|
+
* .get('/with-hook', () => 'hi', {
|
|
813
|
+
* response: t.String()
|
|
814
|
+
* })
|
|
815
|
+
* ```
|
|
816
|
+
*/
|
|
817
|
+
get<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
818
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
819
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
820
|
+
}, `${BasePath}${Path extends '/' ? '' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
821
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
822
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
823
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
824
|
+
get: {
|
|
825
|
+
body: Schema['body'];
|
|
826
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
827
|
+
query: Schema['query'];
|
|
828
|
+
headers: Schema['headers'];
|
|
829
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
830
|
+
};
|
|
831
|
+
}>, Ephemeral, Volatile>;
|
|
832
|
+
/**
|
|
833
|
+
* ### post
|
|
834
|
+
* Register handler for path with method [POST]
|
|
835
|
+
*
|
|
836
|
+
* ---
|
|
837
|
+
* @example
|
|
838
|
+
* ```typescript
|
|
839
|
+
* import { Elysia, t } from 'elysia'
|
|
840
|
+
*
|
|
841
|
+
* new Elysia()
|
|
842
|
+
* .post('/', () => 'hi')
|
|
843
|
+
* .post('/with-hook', () => 'hi', {
|
|
844
|
+
* response: t.String()
|
|
845
|
+
* })
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
post<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
849
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
850
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
851
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
852
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
853
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
854
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
855
|
+
post: {
|
|
856
|
+
body: Schema['body'];
|
|
857
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
858
|
+
query: Schema['query'];
|
|
859
|
+
headers: Schema['headers'];
|
|
860
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
861
|
+
};
|
|
862
|
+
}>, Ephemeral, Volatile>;
|
|
863
|
+
/**
|
|
864
|
+
* ### put
|
|
865
|
+
* Register handler for path with method [PUT]
|
|
866
|
+
*
|
|
867
|
+
* ---
|
|
868
|
+
* @example
|
|
869
|
+
* ```typescript
|
|
870
|
+
* import { Elysia, t } from 'elysia'
|
|
871
|
+
*
|
|
872
|
+
* new Elysia()
|
|
873
|
+
* .put('/', () => 'hi')
|
|
874
|
+
* .put('/with-hook', () => 'hi', {
|
|
875
|
+
* response: t.String()
|
|
876
|
+
* })
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
put<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
880
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
881
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
882
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
883
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
884
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
885
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
886
|
+
put: {
|
|
887
|
+
body: Schema['body'];
|
|
888
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
889
|
+
query: Schema['query'];
|
|
890
|
+
headers: Schema['headers'];
|
|
891
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
892
|
+
};
|
|
893
|
+
}>, Ephemeral, Volatile>;
|
|
894
|
+
/**
|
|
895
|
+
* ### patch
|
|
896
|
+
* Register handler for path with method [PATCH]
|
|
897
|
+
*
|
|
898
|
+
* ---
|
|
899
|
+
* @example
|
|
900
|
+
* ```typescript
|
|
901
|
+
* import { Elysia, t } from 'elysia'
|
|
902
|
+
*
|
|
903
|
+
* new Elysia()
|
|
904
|
+
* .patch('/', () => 'hi')
|
|
905
|
+
* .patch('/with-hook', () => 'hi', {
|
|
906
|
+
* response: t.String()
|
|
907
|
+
* })
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
patch<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
911
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
912
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
913
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
914
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
915
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
916
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
917
|
+
patch: {
|
|
918
|
+
body: Schema['body'];
|
|
919
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
920
|
+
query: Schema['query'];
|
|
921
|
+
headers: Schema['headers'];
|
|
922
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
923
|
+
};
|
|
924
|
+
}>, Ephemeral, Volatile>;
|
|
925
|
+
/**
|
|
926
|
+
* ### delete
|
|
927
|
+
* Register handler for path with method [DELETE]
|
|
928
|
+
*
|
|
929
|
+
* ---
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* import { Elysia, t } from 'elysia'
|
|
933
|
+
*
|
|
934
|
+
* new Elysia()
|
|
935
|
+
* .delete('/', () => 'hi')
|
|
936
|
+
* .delete('/with-hook', () => 'hi', {
|
|
937
|
+
* response: t.String()
|
|
938
|
+
* })
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
delete<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
942
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
943
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
944
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
945
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
946
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
947
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
948
|
+
delete: {
|
|
949
|
+
body: Schema['body'];
|
|
950
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
951
|
+
query: Schema['query'];
|
|
952
|
+
headers: Schema['headers'];
|
|
953
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
954
|
+
};
|
|
955
|
+
}>, Ephemeral, Volatile>;
|
|
956
|
+
/**
|
|
957
|
+
* ### options
|
|
958
|
+
* Register handler for path with method [POST]
|
|
959
|
+
*
|
|
960
|
+
* ---
|
|
961
|
+
* @example
|
|
962
|
+
* ```typescript
|
|
963
|
+
* import { Elysia, t } from 'elysia'
|
|
964
|
+
*
|
|
965
|
+
* new Elysia()
|
|
966
|
+
* .options('/', () => 'hi')
|
|
967
|
+
* .options('/with-hook', () => 'hi', {
|
|
968
|
+
* response: t.String()
|
|
969
|
+
* })
|
|
970
|
+
* ```
|
|
971
|
+
*/
|
|
972
|
+
options<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
973
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
974
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
975
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
976
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
977
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
978
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
979
|
+
options: {
|
|
980
|
+
body: Schema['body'];
|
|
981
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
982
|
+
query: Schema['query'];
|
|
983
|
+
headers: Schema['headers'];
|
|
984
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
985
|
+
};
|
|
986
|
+
}>, Ephemeral, Volatile>;
|
|
987
|
+
/**
|
|
988
|
+
* ### all
|
|
989
|
+
* Register handler for path with method [ALL]
|
|
990
|
+
*
|
|
991
|
+
* ---
|
|
992
|
+
* @example
|
|
993
|
+
* ```typescript
|
|
994
|
+
* import { Elysia, t } from 'elysia'
|
|
995
|
+
*
|
|
996
|
+
* new Elysia()
|
|
997
|
+
* .all('/', () => 'hi')
|
|
998
|
+
* .all('/with-hook', () => 'hi', {
|
|
999
|
+
* response: t.String()
|
|
1000
|
+
* })
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
all<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
1004
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1005
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1006
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
1007
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1008
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1009
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
1010
|
+
[method in string]: {
|
|
1011
|
+
body: Schema['body'];
|
|
1012
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
1013
|
+
query: Schema['query'];
|
|
1014
|
+
headers: Schema['headers'];
|
|
1015
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
1016
|
+
};
|
|
1017
|
+
}>, Ephemeral, Volatile>;
|
|
1018
|
+
/**
|
|
1019
|
+
* ### head
|
|
1020
|
+
* Register handler for path with method [HEAD]
|
|
1021
|
+
*
|
|
1022
|
+
* ---
|
|
1023
|
+
* @example
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* import { Elysia, t } from 'elysia'
|
|
1026
|
+
*
|
|
1027
|
+
* new Elysia()
|
|
1028
|
+
* .head('/', () => 'hi')
|
|
1029
|
+
* .head('/with-hook', () => 'hi', {
|
|
1030
|
+
* response: t.String()
|
|
1031
|
+
* })
|
|
1032
|
+
* ```
|
|
1033
|
+
*/
|
|
1034
|
+
head<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
1035
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1036
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1037
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
1038
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1039
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1040
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
1041
|
+
head: {
|
|
1042
|
+
body: Schema['body'];
|
|
1043
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
1044
|
+
query: Schema['query'];
|
|
1045
|
+
headers: Schema['headers'];
|
|
1046
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
1047
|
+
};
|
|
1048
|
+
}>, Ephemeral, Volatile>;
|
|
1049
|
+
/**
|
|
1050
|
+
* ### connect
|
|
1051
|
+
* Register handler for path with method [CONNECT]
|
|
1052
|
+
*
|
|
1053
|
+
* ---
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* import { Elysia, t } from 'elysia'
|
|
1057
|
+
*
|
|
1058
|
+
* new Elysia()
|
|
1059
|
+
* .connect('/', () => 'hi')
|
|
1060
|
+
* .connect('/with-hook', () => 'hi', {
|
|
1061
|
+
* response: t.String()
|
|
1062
|
+
* })
|
|
1063
|
+
* ```
|
|
1064
|
+
*/
|
|
1065
|
+
connect<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
1066
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1067
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1068
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
1069
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1070
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1071
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
1072
|
+
connect: {
|
|
1073
|
+
body: Schema['body'];
|
|
1074
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
1075
|
+
query: Schema['query'];
|
|
1076
|
+
headers: Schema['headers'];
|
|
1077
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
1078
|
+
};
|
|
1079
|
+
}>, Ephemeral, Volatile>;
|
|
1080
|
+
/**
|
|
1081
|
+
* ### route
|
|
1082
|
+
* Register handler for path with method [ROUTE]
|
|
1083
|
+
*
|
|
1084
|
+
* ---
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```typescript
|
|
1087
|
+
* import { Elysia, t } from 'elysia'
|
|
1088
|
+
*
|
|
1089
|
+
* new Elysia()
|
|
1090
|
+
* .route('/', () => 'hi')
|
|
1091
|
+
* .route('/with-hook', () => 'hi', {
|
|
1092
|
+
* response: t.String()
|
|
1093
|
+
* })
|
|
1094
|
+
* ```
|
|
1095
|
+
*/
|
|
1096
|
+
route<const Method extends HTTPMethod, const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema'] & Ephemeral['schema'] & Volatile['schema']>, const Handle extends InlineHandler<Schema, Singleton & {
|
|
1097
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1098
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1099
|
+
}, `${BasePath}${Path extends '/' ? '/index' : Path}`>>(method: Method, path: Path, handler: Handle, hook?: LocalHook<LocalSchema, Schema, Singleton & {
|
|
1100
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1101
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1102
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`> & {
|
|
1103
|
+
config: {
|
|
1104
|
+
allowMeta?: boolean;
|
|
1105
|
+
};
|
|
1106
|
+
}): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath & string}${Path extends '/' ? '/index' : Path}`, {
|
|
1107
|
+
[method in Method]: {
|
|
1108
|
+
body: Schema['body'];
|
|
1109
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
1110
|
+
query: Schema['query'];
|
|
1111
|
+
headers: Schema['headers'];
|
|
1112
|
+
response: ComposeElysiaResponse<Schema['response'], Handle>;
|
|
1113
|
+
};
|
|
1114
|
+
}>, Ephemeral, Volatile>;
|
|
1115
|
+
/**
|
|
1116
|
+
* ### ws
|
|
1117
|
+
* Register handler for path with method [ws]
|
|
1118
|
+
*
|
|
1119
|
+
* ---
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* import { Elysia, t } from 'elysia'
|
|
1123
|
+
*
|
|
1124
|
+
* new Elysia()
|
|
1125
|
+
* .ws('/', {
|
|
1126
|
+
* message(ws, message) {
|
|
1127
|
+
* ws.send(message)
|
|
1128
|
+
* }
|
|
1129
|
+
* })
|
|
1130
|
+
* ```
|
|
1131
|
+
*/
|
|
1132
|
+
ws<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Schema extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, Metadata['schema']>>(path: Path, options: WS.LocalHook<LocalSchema, Schema, Singleton & {
|
|
1133
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1134
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1135
|
+
}, Definitions['error'], Metadata['macro'], `${BasePath}${Path extends '/' ? '/index' : Path}`>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes & CreateEden<`${BasePath}${Path extends '/' ? '/index' : Path}`, {
|
|
1136
|
+
subscribe: {
|
|
1137
|
+
body: Schema['body'];
|
|
1138
|
+
params: undefined extends Schema['params'] ? Record<GetPathParameter<Path>, string> : Schema['params'];
|
|
1139
|
+
query: Schema['query'];
|
|
1140
|
+
headers: Schema['headers'];
|
|
1141
|
+
response: Schema['response'];
|
|
1142
|
+
};
|
|
1143
|
+
}>, Ephemeral, Volatile>;
|
|
1144
|
+
/**
|
|
1145
|
+
* ### state
|
|
1146
|
+
* Assign global mutatable state accessible for all handler
|
|
1147
|
+
*
|
|
1148
|
+
* ---
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```typescript
|
|
1151
|
+
* new Elysia()
|
|
1152
|
+
* .state({ counter: 0 })
|
|
1153
|
+
* .get('/', (({ counter }) => ++counter)
|
|
1154
|
+
* ```
|
|
1155
|
+
*/
|
|
1156
|
+
state<const Name extends string | number | symbol, Value>(name: Name, value: Value): Elysia<BasePath, Scoped, {
|
|
1157
|
+
decorator: Singleton['decorator'];
|
|
1158
|
+
store: Prettify<Singleton['store'] & {
|
|
1159
|
+
[name in Name]: Value;
|
|
1160
|
+
}>;
|
|
1161
|
+
derive: Singleton['derive'];
|
|
1162
|
+
resolve: Singleton['resolve'];
|
|
1163
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1164
|
+
/**
|
|
1165
|
+
* ### state
|
|
1166
|
+
* Assign global mutatable state accessible for all handler
|
|
1167
|
+
*
|
|
1168
|
+
* ---
|
|
1169
|
+
* @example
|
|
1170
|
+
* ```typescript
|
|
1171
|
+
* new Elysia()
|
|
1172
|
+
* .state('counter', 0)
|
|
1173
|
+
* .get('/', (({ counter }) => ++counter)
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
state<Store extends Record<string, unknown>>(store: Store): Elysia<BasePath, Scoped, {
|
|
1177
|
+
decorator: Singleton['decorator'];
|
|
1178
|
+
store: Prettify<Singleton['store'] & Store>;
|
|
1179
|
+
derive: Singleton['derive'];
|
|
1180
|
+
resolve: Singleton['resolve'];
|
|
1181
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1182
|
+
state<NewStore extends Record<string, unknown>>(mapper: (decorators: Singleton['store']) => NewStore): Elysia<BasePath, Scoped, {
|
|
1183
|
+
decorator: Singleton['decorator'];
|
|
1184
|
+
store: NewStore;
|
|
1185
|
+
derive: Singleton['derive'];
|
|
1186
|
+
resolve: Singleton['resolve'];
|
|
1187
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1188
|
+
/**
|
|
1189
|
+
* ### decorate
|
|
1190
|
+
* Define custom method to `Context` accessible for all handler
|
|
1191
|
+
*
|
|
1192
|
+
* ---
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```typescript
|
|
1195
|
+
* new Elysia()
|
|
1196
|
+
* .decorate('getDate', () => Date.now())
|
|
1197
|
+
* .get('/', (({ getDate }) => getDate())
|
|
1198
|
+
* ```
|
|
1199
|
+
*/
|
|
1200
|
+
decorate<const Name extends string, const Value>(name: Name, value: Value): Elysia<BasePath, Scoped, {
|
|
1201
|
+
decorator: Prettify<Singleton['decorator'] & {
|
|
1202
|
+
[name in Name]: Value;
|
|
1203
|
+
}>;
|
|
1204
|
+
store: Singleton['store'];
|
|
1205
|
+
derive: Singleton['derive'];
|
|
1206
|
+
resolve: Singleton['resolve'];
|
|
1207
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1208
|
+
/**
|
|
1209
|
+
* ### decorate
|
|
1210
|
+
* Define custom method to `Context` accessible for all handler
|
|
1211
|
+
*
|
|
1212
|
+
* ---
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```typescript
|
|
1215
|
+
* new Elysia()
|
|
1216
|
+
* .decorate('getDate', () => Date.now())
|
|
1217
|
+
* .get('/', (({ getDate }) => getDate())
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
1220
|
+
decorate<const NewDecorators extends Record<string, unknown>>(decorators: NewDecorators): Elysia<BasePath, Scoped, {
|
|
1221
|
+
decorator: Prettify<Singleton['decorator'] & NewDecorators>;
|
|
1222
|
+
store: Singleton['store'];
|
|
1223
|
+
derive: Singleton['derive'];
|
|
1224
|
+
resolve: Singleton['resolve'];
|
|
1225
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1226
|
+
decorate<const NewDecorators extends Record<string, unknown>>(mapper: (decorators: Singleton['decorator']) => NewDecorators): Elysia<BasePath, Scoped, {
|
|
1227
|
+
decorator: NewDecorators;
|
|
1228
|
+
store: Singleton['store'];
|
|
1229
|
+
derive: Singleton['derive'];
|
|
1230
|
+
resolve: Singleton['resolve'];
|
|
1231
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Derive new property for each request with access to `Context`.
|
|
1234
|
+
*
|
|
1235
|
+
* If error is thrown, the scope will skip to handling error instead.
|
|
1236
|
+
*
|
|
1237
|
+
* ---
|
|
1238
|
+
* @example
|
|
1239
|
+
* new Elysia()
|
|
1240
|
+
* .state('counter', 1)
|
|
1241
|
+
* .derive(({ store }) => ({
|
|
1242
|
+
* increase() {
|
|
1243
|
+
* store.counter++
|
|
1244
|
+
* }
|
|
1245
|
+
* }))
|
|
1246
|
+
*/
|
|
1247
|
+
derive<const Derivative extends Record<string, unknown>>(transform: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
|
|
1248
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1249
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1250
|
+
}>>) => MaybePromise<Derivative>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
1251
|
+
derive: Prettify<Volatile['derive'] & ExcludeElysiaResponse<Derivative>>;
|
|
1252
|
+
resolve: Volatile['resolve'];
|
|
1253
|
+
schema: Volatile['schema'];
|
|
1254
|
+
}>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Derive new property for each request with access to `Context`.
|
|
1257
|
+
*
|
|
1258
|
+
* If error is thrown, the scope will skip to handling error instead.
|
|
1259
|
+
*
|
|
1260
|
+
* ---
|
|
1261
|
+
* @example
|
|
1262
|
+
* new Elysia()
|
|
1263
|
+
* .state('counter', 1)
|
|
1264
|
+
* .derive(({ store }) => ({
|
|
1265
|
+
* increase() {
|
|
1266
|
+
* store.counter++
|
|
1267
|
+
* }
|
|
1268
|
+
* }))
|
|
1269
|
+
*/
|
|
1270
|
+
derive<const Derivative extends Record<string, unknown>, const Type extends LifeCycleType>(options: {
|
|
1271
|
+
as?: Type;
|
|
1272
|
+
}, transform: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & ('global' extends Type ? {
|
|
1273
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
1274
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
1275
|
+
} : 'scoped' extends Type ? {
|
|
1276
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
1277
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
1278
|
+
} : {
|
|
1279
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1280
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1281
|
+
}), BasePath>>) => MaybePromise<Derivative>): Type extends 'global' ? Elysia<BasePath, Scoped, {
|
|
1282
|
+
decorator: Singleton['decorator'];
|
|
1283
|
+
store: Singleton['store'];
|
|
1284
|
+
derive: Singleton['resolve'];
|
|
1285
|
+
resolve: Prettify<Singleton['resolve'] & ExcludeElysiaResponse<Derivative>>;
|
|
1286
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile> : Type extends 'scoped' ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, {
|
|
1287
|
+
derive: Ephemeral['resolve'];
|
|
1288
|
+
resolve: Prettify<Ephemeral['resolve'] & ExcludeElysiaResponse<Derivative>>;
|
|
1289
|
+
schema: Ephemeral['schema'];
|
|
1290
|
+
}, Volatile> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
1291
|
+
derive: Volatile['resolve'];
|
|
1292
|
+
resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<Derivative>>;
|
|
1293
|
+
schema: Volatile['schema'];
|
|
1294
|
+
}>;
|
|
1295
|
+
model<const Name extends string, const Model extends TSchema>(name: Name, model: Model): Elysia<BasePath, Scoped, Singleton, {
|
|
1296
|
+
type: Prettify<Definitions['type'] & {
|
|
1297
|
+
[name in Name]: Static<Model>;
|
|
1298
|
+
}>;
|
|
1299
|
+
error: Definitions['error'];
|
|
1300
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1301
|
+
model<const Recorder extends Record<string, TSchema>>(record: Recorder): Elysia<BasePath, Scoped, Singleton, {
|
|
1302
|
+
type: Prettify<Definitions['type'] & {
|
|
1303
|
+
[key in keyof Recorder]: Static<Recorder[key]>;
|
|
1304
|
+
}>;
|
|
1305
|
+
error: Definitions['error'];
|
|
1306
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1307
|
+
model<const NewType extends Record<string, TSchema>>(mapper: (decorators: {
|
|
1308
|
+
[type in keyof Definitions['type']]: ReturnType<typeof t.Unsafe<Definitions['type'][type]>>;
|
|
1309
|
+
}) => NewType): Elysia<BasePath, Scoped, Singleton, {
|
|
1310
|
+
type: {
|
|
1311
|
+
[x in keyof NewType]: Static<NewType[x]>;
|
|
1312
|
+
};
|
|
1313
|
+
error: Definitions['error'];
|
|
1314
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1315
|
+
mapDerive<const NewDerivative extends Record<string, unknown>>(mapper: (context: Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
|
|
1316
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1317
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1318
|
+
}, BasePath>) => MaybePromise<NewDerivative>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
1319
|
+
derive: NewDerivative;
|
|
1320
|
+
resolve: Volatile['resolve'];
|
|
1321
|
+
schema: Volatile['schema'];
|
|
1322
|
+
}>;
|
|
1323
|
+
mapDerive<const NewDerivative extends Record<string, unknown>, const Type extends LifeCycleType>(options: {
|
|
1324
|
+
as?: Type;
|
|
1325
|
+
}, mapper: (context: Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & ('global' extends Type ? {
|
|
1326
|
+
derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
|
|
1327
|
+
resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
|
|
1328
|
+
} : 'scoped' extends Type ? {
|
|
1329
|
+
derive: Ephemeral['derive'] & Partial<Volatile['derive']>;
|
|
1330
|
+
resolve: Ephemeral['resolve'] & Partial<Volatile['resolve']>;
|
|
1331
|
+
} : {
|
|
1332
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1333
|
+
resolve: Ephemeral['resolve'] & Volatile['resolve'];
|
|
1334
|
+
}), BasePath>) => MaybePromise<NewDerivative>): Type extends 'global' ? Elysia<BasePath, Scoped, {
|
|
1335
|
+
decorator: Singleton['decorator'];
|
|
1336
|
+
store: Singleton['store'];
|
|
1337
|
+
derive: Singleton['resolve'];
|
|
1338
|
+
resolve: Prettify<Singleton['resolve'] & ExcludeElysiaResponse<NewDerivative>>;
|
|
1339
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile> : Type extends 'scoped' ? Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, {
|
|
1340
|
+
derive: Ephemeral['resolve'];
|
|
1341
|
+
resolve: Prettify<Ephemeral['resolve'] & ExcludeElysiaResponse<NewDerivative>>;
|
|
1342
|
+
schema: Ephemeral['schema'];
|
|
1343
|
+
}, Volatile> : Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
1344
|
+
derive: Volatile['resolve'];
|
|
1345
|
+
resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<NewDerivative>>;
|
|
1346
|
+
schema: Volatile['schema'];
|
|
1347
|
+
}>;
|
|
1348
|
+
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, Scoped, {
|
|
1349
|
+
decorator: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Singleton['decorator']> : AddPrefixCapitalize<Word, Singleton['decorator']> : AddSuffixCapitalize<Word, Singleton['decorator']> : Singleton['decorator'];
|
|
1350
|
+
store: Type extends 'state' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Singleton['store']> : AddPrefixCapitalize<Word, Singleton['store']> : AddSuffix<Word, Singleton['store']> : Singleton['store'];
|
|
1351
|
+
derive: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Singleton['derive']> : AddPrefixCapitalize<Word, Singleton['derive']> : AddSuffixCapitalize<Word, Singleton['derive']> : Singleton['derive'];
|
|
1352
|
+
resolve: Type extends 'decorator' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Singleton['resolve']> : AddPrefixCapitalize<Word, Singleton['resolve']> : AddSuffixCapitalize<Word, Singleton['resolve']> : Singleton['resolve'];
|
|
1353
|
+
}, {
|
|
1354
|
+
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'];
|
|
1355
|
+
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'];
|
|
1356
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1357
|
+
prefix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, Scoped, {
|
|
1358
|
+
decorator: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Singleton["decorator"]> : AddPrefixCapitalize<Word, Singleton["decorator"]> : Singleton["decorator"];
|
|
1359
|
+
store: Type extends "all" | "state" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Singleton["store"]> : AddPrefixCapitalize<Word, Singleton["store"]> : Singleton["store"];
|
|
1360
|
+
derive: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Singleton["derive"]> : AddPrefixCapitalize<Word, Singleton["derive"]> : Singleton["derive"];
|
|
1361
|
+
resolve: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Singleton["resolve"]> : AddPrefixCapitalize<Word, Singleton["resolve"]> : Singleton["resolve"];
|
|
1362
|
+
}, {
|
|
1363
|
+
type: Type extends "all" | "model" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Definitions["type"]> : AddPrefixCapitalize<Word, Definitions["type"]> : Definitions["type"];
|
|
1364
|
+
error: Type extends "error" | "all" ? Word extends `${string} ` | `${string}_` | `${string}-` ? AddPrefix<Word, Definitions["error"]> : AddPrefixCapitalize<Word, Definitions["error"]> : Definitions["error"];
|
|
1365
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1366
|
+
suffix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, Scoped, {
|
|
1367
|
+
decorator: Type extends "decorator" | "all" ? AddSuffixCapitalize<Word, Singleton["decorator"]> : Singleton["decorator"];
|
|
1368
|
+
store: Type extends "all" | "state" ? AddSuffix<Word, Singleton["store"]> : Singleton["store"];
|
|
1369
|
+
derive: Type extends "decorator" | "all" ? AddSuffixCapitalize<Word, Singleton["derive"]> : Singleton["derive"];
|
|
1370
|
+
resolve: Type extends "decorator" | "all" ? AddSuffixCapitalize<Word, Singleton["resolve"]> : Singleton["resolve"];
|
|
1371
|
+
}, {
|
|
1372
|
+
type: Type extends "all" | "model" ? AddSuffixCapitalize<Word, Definitions["type"]> : Definitions["type"];
|
|
1373
|
+
error: Type extends "error" | "all" ? AddSuffixCapitalize<Word, Definitions["error"]> : Definitions["error"];
|
|
1374
|
+
}, Metadata, Routes, Ephemeral, Volatile>;
|
|
1375
|
+
compile(): this;
|
|
1376
|
+
handle: (request: Request) => Promise<Response>;
|
|
1377
|
+
/**
|
|
1378
|
+
* Use handle can be either sync or async to save performance.
|
|
1379
|
+
*
|
|
1380
|
+
* Beside benchmark purpose, please use 'handle' instead.
|
|
1381
|
+
*/
|
|
1382
|
+
fetch: (request: Request) => MaybePromise<Response>;
|
|
1383
|
+
private handleError;
|
|
1384
|
+
private outerErrorHandler;
|
|
1385
|
+
/**
|
|
1386
|
+
* ### listen
|
|
1387
|
+
* Assign current instance to port and start serving
|
|
1388
|
+
*
|
|
1389
|
+
* ---
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```typescript
|
|
1392
|
+
* new Elysia()
|
|
1393
|
+
* .get("/", () => 'hi')
|
|
1394
|
+
* .listen(8080)
|
|
1395
|
+
* ```
|
|
1396
|
+
*/
|
|
1397
|
+
listen: (options: string | number | Partial<Serve>, callback?: ListenCallback) => this;
|
|
1398
|
+
/**
|
|
1399
|
+
* ### stop
|
|
1400
|
+
* Stop server from serving
|
|
1401
|
+
*
|
|
1402
|
+
* ---
|
|
1403
|
+
* @example
|
|
1404
|
+
* ```typescript
|
|
1405
|
+
* const app = new Elysia()
|
|
1406
|
+
* .get("/", () => 'hi')
|
|
1407
|
+
* .listen(8080)
|
|
1408
|
+
*
|
|
1409
|
+
* // Sometime later
|
|
1410
|
+
* app.stop()
|
|
1411
|
+
* ```
|
|
1412
|
+
*/
|
|
1413
|
+
stop: () => Promise<void>;
|
|
1414
|
+
/**
|
|
1415
|
+
* Wait until all lazy loaded modules all load is fully
|
|
1416
|
+
*/
|
|
1417
|
+
get modules(): Promise<any[]>;
|
|
1418
|
+
}
|
|
1419
|
+
export { Elysia };
|
|
1420
|
+
export { mapResponse, mapCompactResponse, mapEarlyResponse } from './handler';
|
|
1421
|
+
export { t } from './type-system';
|
|
1422
|
+
export { Cookie, type CookieOptions } from './cookies';
|
|
1423
|
+
export { getSchemaValidator, mergeHook, mergeObjectArray, getResponseSchemaValidator, StatusMap, InvertedStatusMap } from './utils';
|
|
1424
|
+
export { error, ParseError, NotFoundError, ValidationError, InternalServerError, InvalidCookieSignature, ERROR_CODE, ELYSIA_RESPONSE } from './error';
|
|
1425
|
+
export type { Context, PreContext } from './context';
|
|
1426
|
+
export type { ElysiaFn, EphemeralType, CreateEden, ComposeElysiaResponse, ElysiaConfig, SingletonBase, DefinitionBase, RouteBase, Handler, ComposedHandler, InputSchema, LocalHook, MergeSchema, RouteSchema, UnwrapRoute, InternalRoute, HTTPMethod, SchemaValidator, VoidHandler, PreHandler, BodyHandler, OptionalHandler, ErrorHandler, AfterHandler, LifeCycleEvent, TraceEvent, LifeCycleStore, LifeCycleType, MaybePromise, ListenCallback, UnwrapSchema, TraceHandler, TraceProcess, TraceReporter, TraceStream, Checksum } from './types';
|
|
1427
|
+
export type { Static, TSchema } from '@sinclair/typebox';
|