elysia 0.6.19 → 0.6.21
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 +36 -36
- package/dist/bun/index.js +53 -53
- package/dist/bun/index.js.map +22 -24
- package/dist/cjs/index.d.ts +36 -36
- package/dist/cjs/index.js +112 -52
- package/dist/cjs/types.d.ts +1 -1
- package/dist/index.d.ts +36 -36
- package/dist/index.js +4 -4
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -211,7 +211,7 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
211
211
|
}>;
|
|
212
212
|
mount(handle: (request: Request) => MaybePromise<Response>): this;
|
|
213
213
|
mount(path: string, handle: (request: Request) => MaybePromise<Response>): this;
|
|
214
|
-
get<
|
|
214
|
+
get<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
215
215
|
request: Instance['request'];
|
|
216
216
|
store: Instance['store'];
|
|
217
217
|
schema: Instance['schema'];
|
|
@@ -220,12 +220,12 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
220
220
|
defs: Instance['meta']['defs'];
|
|
221
221
|
exposed: Instance['meta']['exposed'];
|
|
222
222
|
schema: Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
223
|
-
[path in `${BasePath}${
|
|
223
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
224
224
|
get: {
|
|
225
225
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
226
226
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
227
227
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
228
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
228
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
229
229
|
response: Typed['response'] extends TSchema | string ? {
|
|
230
230
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
231
231
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -238,18 +238,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
238
238
|
} : {})>;
|
|
239
239
|
};
|
|
240
240
|
}>;
|
|
241
|
-
post<
|
|
241
|
+
post<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
242
242
|
request: Instance['request'];
|
|
243
243
|
store: Instance['store'];
|
|
244
244
|
schema: Instance['schema'];
|
|
245
245
|
error: Instance['error'];
|
|
246
246
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
247
|
-
[path in `${BasePath}${
|
|
247
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
248
248
|
post: {
|
|
249
249
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
250
250
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
251
251
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
252
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
252
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
253
253
|
response: Typed['response'] extends TSchema | string ? {
|
|
254
254
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
255
255
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -261,18 +261,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
261
261
|
};
|
|
262
262
|
} : {})>>;
|
|
263
263
|
}>;
|
|
264
|
-
put<
|
|
264
|
+
put<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
265
265
|
request: Instance['request'];
|
|
266
266
|
store: Instance['store'];
|
|
267
267
|
schema: Instance['schema'];
|
|
268
268
|
error: Instance['error'];
|
|
269
269
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
270
|
-
[path in `${BasePath}${
|
|
270
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
271
271
|
put: {
|
|
272
272
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
273
273
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
274
274
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
275
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
275
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
276
276
|
response: Typed['response'] extends TSchema | string ? {
|
|
277
277
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
278
278
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -284,18 +284,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
284
284
|
};
|
|
285
285
|
} : {})>>;
|
|
286
286
|
}>;
|
|
287
|
-
patch<
|
|
287
|
+
patch<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
288
288
|
request: Instance['request'];
|
|
289
289
|
store: Instance['store'];
|
|
290
290
|
schema: Instance['schema'];
|
|
291
291
|
error: Instance['error'];
|
|
292
292
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
293
|
-
[path in `${BasePath}${
|
|
293
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
294
294
|
patch: {
|
|
295
295
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
296
296
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
297
297
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
298
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
298
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
299
299
|
response: Typed['response'] extends TSchema | string ? {
|
|
300
300
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
301
301
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -307,18 +307,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
307
307
|
};
|
|
308
308
|
} : {})>>;
|
|
309
309
|
}>;
|
|
310
|
-
delete<
|
|
310
|
+
delete<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
311
311
|
request: Instance['request'];
|
|
312
312
|
store: Instance['store'];
|
|
313
313
|
schema: Instance['schema'];
|
|
314
314
|
error: Instance['error'];
|
|
315
315
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
316
|
-
[path in `${BasePath}${
|
|
316
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
317
317
|
delete: {
|
|
318
318
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
319
319
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
320
320
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
321
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
321
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
322
322
|
response: Typed['response'] extends TSchema | string ? {
|
|
323
323
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
324
324
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -330,18 +330,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
330
330
|
};
|
|
331
331
|
} : {})>>;
|
|
332
332
|
}>;
|
|
333
|
-
options<
|
|
333
|
+
options<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
334
334
|
request: Instance['request'];
|
|
335
335
|
store: Instance['store'];
|
|
336
336
|
schema: Instance['schema'];
|
|
337
337
|
error: Instance['error'];
|
|
338
338
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
339
|
-
[path in `${BasePath}${
|
|
339
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
340
340
|
options: {
|
|
341
341
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
342
342
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
343
343
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
344
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
344
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
345
345
|
response: Typed['response'] extends TSchema | string ? {
|
|
346
346
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
347
347
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -353,18 +353,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
353
353
|
};
|
|
354
354
|
} : {})>>;
|
|
355
355
|
}>;
|
|
356
|
-
all<
|
|
356
|
+
all<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
357
357
|
request: Instance['request'];
|
|
358
358
|
store: Instance['store'];
|
|
359
359
|
schema: Instance['schema'];
|
|
360
360
|
error: Instance['error'];
|
|
361
361
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
362
|
-
[path in `${BasePath}${
|
|
362
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
363
363
|
all: {
|
|
364
364
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
365
365
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
366
366
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
367
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
367
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
368
368
|
response: Typed['response'] extends TSchema | string ? {
|
|
369
369
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
370
370
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -376,18 +376,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
376
376
|
};
|
|
377
377
|
} : {})>>;
|
|
378
378
|
}>;
|
|
379
|
-
head<
|
|
379
|
+
head<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
380
380
|
request: Instance['request'];
|
|
381
381
|
store: Instance['store'];
|
|
382
382
|
schema: Instance['schema'];
|
|
383
383
|
error: Instance['error'];
|
|
384
384
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
385
|
-
[path in `${BasePath}${
|
|
385
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
386
386
|
head: {
|
|
387
387
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
388
388
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
389
389
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
390
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
390
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
391
391
|
response: Typed['response'] extends TSchema | string ? {
|
|
392
392
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
393
393
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -399,18 +399,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
399
399
|
};
|
|
400
400
|
} : {})>>;
|
|
401
401
|
}>;
|
|
402
|
-
trace<
|
|
402
|
+
trace<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
403
403
|
request: Instance['request'];
|
|
404
404
|
store: Instance['store'];
|
|
405
405
|
schema: Instance['schema'];
|
|
406
406
|
error: Instance['error'];
|
|
407
407
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
408
|
-
[path in `${BasePath}${
|
|
408
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
409
409
|
trace: {
|
|
410
410
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
411
411
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
412
412
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
413
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
413
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
414
414
|
response: Typed['response'] extends TSchema | string ? {
|
|
415
415
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
416
416
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -422,18 +422,18 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
422
422
|
};
|
|
423
423
|
} : {})>>;
|
|
424
424
|
}>;
|
|
425
|
-
connect<
|
|
425
|
+
connect<Paths extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>, Schema extends TypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, handler: Handler, hook?: LocalHook<Schema, Instance, `${BasePath}${Extract<Paths, string>}`>): Elysia<BasePath, {
|
|
426
426
|
request: Instance['request'];
|
|
427
427
|
store: Instance['store'];
|
|
428
428
|
schema: Instance['schema'];
|
|
429
429
|
error: Instance['error'];
|
|
430
430
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & (MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
431
|
-
[path in `${BasePath}${
|
|
431
|
+
[path in `${BasePath}${Extract<Paths, string>}`]: {
|
|
432
432
|
connect: {
|
|
433
433
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
434
434
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
435
435
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
436
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<
|
|
436
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Paths, string>>, string>;
|
|
437
437
|
response: Typed['response'] extends TSchema | string ? {
|
|
438
438
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
439
439
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
|
@@ -445,16 +445,16 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
445
445
|
};
|
|
446
446
|
} : {})>>;
|
|
447
447
|
}>;
|
|
448
|
-
ws<
|
|
448
|
+
ws<Paths extends string | string[], Schema extends WSTypedSchema<Extract<keyof Instance['meta']['defs'], string>>>(paths: Paths, options: this extends Elysia<any, infer Instance> ? ElysiaWSOptions<`${BasePath}${Extract<Paths, string>}`, Schema, Instance> : never): Elysia<BasePath, {
|
|
449
449
|
request: Instance['request'];
|
|
450
450
|
store: Instance['store'];
|
|
451
451
|
schema: Instance['schema'];
|
|
452
452
|
error: Instance['error'];
|
|
453
|
-
meta: Instance['meta'] & Record<'schema', Record<`${BasePath}${
|
|
454
|
-
subscribe: TypedWSRouteToEden<Typed, Instance['meta']['defs'], `${BasePath}${
|
|
453
|
+
meta: Instance['meta'] & Record<'schema', Record<`${BasePath}${Extract<Paths, string>}`, MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
454
|
+
subscribe: TypedWSRouteToEden<Typed, Instance['meta']['defs'], `${BasePath}${Extract<Paths, string>}`>;
|
|
455
455
|
} : {}>>;
|
|
456
456
|
}>;
|
|
457
|
-
route<Schema extends TypedSchema<Exclude<keyof Instance['meta']['defs'], number | symbol>>, Method extends HTTPMethod, Path extends string, Handler extends LocalHandler<Schema, Instance, `${BasePath}${Path}`>>(method: Method, path: Path, handler: Handler, { config, ...hook }?: LocalHook<Schema, Instance, `${BasePath}${Path}`> & {
|
|
457
|
+
route<Schema extends TypedSchema<Exclude<keyof Instance['meta']['defs'], number | symbol>>, Method extends HTTPMethod, Path extends string | string[], Handler extends LocalHandler<Schema, Instance, `${BasePath}${Extract<Path, string>}`>>(method: Method, path: Path, handler: Handler, { config, ...hook }?: LocalHook<Schema, Instance, `${BasePath}${Extract<Path, string>}`> & {
|
|
458
458
|
config: {
|
|
459
459
|
allowMeta?: boolean;
|
|
460
460
|
};
|
|
@@ -464,12 +464,12 @@ export default class Elysia<BasePath extends string = '', Instance extends Elysi
|
|
|
464
464
|
schema: Instance['schema'];
|
|
465
465
|
error: Instance['error'];
|
|
466
466
|
meta: Record<'defs', Instance['meta']['defs']> & Record<'exposed', Instance['meta']['exposed']> & Record<'schema', Prettify<Instance['meta']['schema'] & MergeSchema<Schema, Instance['schema']> extends infer Typed extends TypedSchema ? {
|
|
467
|
-
[path in `${BasePath}${Path}`]: {
|
|
467
|
+
[path in `${BasePath}${Extract<Path, string>}`]: {
|
|
468
468
|
[method in Method]: {
|
|
469
469
|
body: UnwrapSchema<Typed['body'], Instance['meta']['defs']>;
|
|
470
470
|
headers: UnwrapSchema<Typed['headers'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
471
471
|
query: UnwrapSchema<Typed['query'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
|
|
472
|
-
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path
|
|
472
|
+
params: UnwrapSchema<Typed['params'], Instance['meta']['defs']> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Extract<Path, string>>, string>;
|
|
473
473
|
response: Typed['response'] extends TSchema | string ? {
|
|
474
474
|
'200': UnwrapSchema<Typed['response'], Instance['meta']['defs'], ReturnType<Handler>>;
|
|
475
475
|
} : Typed['response'] extends Record<string, TSchema | string> ? {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{Memoirist as e}from"memoirist";import{mergeHook as t,getSchemaValidator as r,getResponseSchemaValidator as s,mergeDeep as o,checksum as i,mergeLifeCycle as n,filterGlobalHook as a,asGlobal as h}from"./utils";import{composeErrorHandler as d,composeGeneralHandler as u,composeHandler as
|
|
1
|
+
import{Memoirist as e}from"memoirist";import{mergeHook as t,getSchemaValidator as r,getResponseSchemaValidator as s,mergeDeep as o,checksum as i,mergeLifeCycle as n,filterGlobalHook as a,asGlobal as h}from"./utils";import{composeErrorHandler as d,composeGeneralHandler as u,composeHandler as f}from"./compose";import{ws as c}from"./ws";import{isProduction as l,ERROR_CODE as p}from"./error";import{createDynamicErrorHandler as m,createDynamicHandler as y}from"./dynamic-handle";export default class g{config;dependencies={};store={};meta={schema:Object.create(null),defs:Object.create(null),exposed:Object.create(null)};decorators={};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],onResponse:[],error:[],stop:[]};server=null;$schema=null;error={};router=new e;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsRouter;dynamicRouter=new e;lazyLoadModules=[];path="";constructor(e){this.config={forceErrorEncapsulation:!1,prefix:"",aot:!0,strictPath:!1,scoped:!1,...e,seed:e?.seed===void 0?"":e?.seed}}add(e,o,i,n,{allowMeta:a=!1,skipPrefix:h=!1}={allowMeta:!1,skipPrefix:!1}){o=""===o?o:47===o.charCodeAt(0)?o:`/${o}`,this.config.prefix&&!h&&(o=this.config.prefix+o);let d=this.meta.defs;if(n?.type)switch(n.type){case"text":n.type="text/plain";break;case"json":n.type="application/json";break;case"formdata":n.type="multipart/form-data";break;case"urlencoded":n.type="application/x-www-form-urlencoded";break;case"arrayBuffer":n.type="application/octet-stream"}let u={body:r(n?.body??this.$schema?.body,{dynamic:!this.config.aot,models:d}),headers:r(n?.headers??this.$schema?.headers,{dynamic:!this.config.aot,models:d,additionalProperties:!0}),params:r(n?.params??this.$schema?.params,{dynamic:!this.config.aot,models:d}),query:r(n?.query??this.$schema?.query,{dynamic:!this.config.aot,models:d}),response:s(n?.response??this.$schema?.response,{dynamic:!this.config.aot,models:d})},c=t(this.event,n),l=o.endsWith("/")?o.slice(0,o.length-1):o+"/";if(!1===this.config.aot){this.dynamicRouter.add(e,o,{validator:u,hooks:c,content:n?.type,handle:i}),!1===this.config.strictPath&&this.dynamicRouter.add(e,l,{validator:u,hooks:c,content:n?.type,handle:i}),this.routes.push({method:e,path:o,composed:null,handler:i,hooks:c});return}let p=f({path:o,method:e,hooks:c,validator:u,handler:i,handleError:this.handleError,meta:a?this.meta:void 0,onRequest:this.event.request,config:this.config});if(this.routes.push({method:e,path:o,composed:p,handler:i,hooks:c}),-1===o.indexOf(":")&&-1===o.indexOf("*")){let t=this.staticRouter.handlers.length;this.staticRouter.handlers.push(p),this.staticRouter.variables+=`const st${t} = staticRouter.handlers[${t}]
|
|
2
2
|
`,this.staticRouter.map[o]||(this.staticRouter.map[o]={code:""}),"ALL"===e?this.staticRouter.map[o].all=`default: return st${t}(ctx)
|
|
3
3
|
`:this.staticRouter.map[o].code+=`case '${e}': return st${t}(ctx)
|
|
4
|
-
`,this.config.strictPath||(this.staticRouter.map[
|
|
5
|
-
`:this.staticRouter.map[
|
|
6
|
-
`)}else this.router.add(e,o,
|
|
4
|
+
`,this.config.strictPath||(this.staticRouter.map[l]||(this.staticRouter.map[l]={code:""}),"ALL"===e?this.staticRouter.map[l].all=`default: return st${t}(ctx)
|
|
5
|
+
`:this.staticRouter.map[l].code+=`case '${e}': return st${t}(ctx)
|
|
6
|
+
`)}else this.router.add(e,o,p),this.config.strictPath||this.router.add(e,o.endsWith("/")?o.slice(0,o.length-1):o+"/",p)}onStart(e){return this.on("start",e),this}onRequest(e){return this.on("request",e),this}onParse(e){return this.on("parse",e),this}onTransform(e){return this.on("transform",e),this}onBeforeHandle(e){return this.on("beforeHandle",e),this}onAfterHandle(e){return this.on("afterHandle",e),this}onResponse(e){return this.on("response",e),this}addError(e,t){if("string"==typeof e&&t)return t.prototype[p]=e,this;for(let[t,r]of Object.entries(e))r.prototype[p]=t;return this}onError(e){return this.on("error",e),this}onStop(e){return this.on("stop",e),this}on(e,t){switch(t=h(t),e){case"start":this.event.start.push(t);break;case"request":this.event.request.push(t);break;case"response":this.event.onResponse.push(t);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,t);break;case"transform":this.event.transform.push(t);break;case"beforeHandle":this.event.beforeHandle.push(t);break;case"afterHandle":this.event.afterHandle.push(t);break;case"error":this.event.error.push(t);break;case"stop":this.event.stop.push(t)}return this}group(e,r,s){let i=new g({...this.config,prefix:""});i.store=this.store,this.wsRouter&&i.use(c());let n="object"==typeof r,a=(n?s:r)(i);return this.decorators=o(this.decorators,i.decorators),a.event.request.length&&(this.event.request=[...this.event.request,...a.event.request]),a.event.onResponse.length&&(this.event.onResponse=[...this.event.onResponse,...a.event.onResponse]),this.model(a.meta.defs),Object.values(i.routes).forEach(({method:s,path:o,handler:h,hooks:d})=>{if(o=this.config.prefix+e+o,n){let e=i.wsRouter?.find("subscribe",o);if(e){let e=i.wsRouter.history.find(([e,t])=>o===t);if(!e)return;return this.ws(o,e[2])}this.add(s,o,h,t(r,{...d,error:d.error?Array.isArray(d.error)?[...d.error,...a.event.error]:[d.error,...a.event.error]:a.event.error}))}else{let e=i.wsRouter?.find("subscribe",o);if(e){let e=i.wsRouter.history.find(([e,t])=>o===t);if(!e)return;return this.ws(o,e[2])}this.add(s,o,h,t(d,{error:a.event.error}),{skipPrefix:!0})}}),i.wsRouter&&this.wsRouter&&i.wsRouter.history.forEach(([t,r,s])=>{"/"===(r=this.config.prefix+e+r)?this.wsRouter?.add(t,e,s):this.wsRouter?.add(t,`${e}${r}`,s)}),this}guard(e,r){if(!r)return this.event=n(this.event,e),this.$schema={body:e.body,headers:e.headers,params:e.params,query:e.query,response:e.response},this;let s=new g;s.store=this.store,this.wsRouter&&s.use(c());let i=r(s);return this.decorators=o(this.decorators,s.decorators),i.event.request.length&&(this.event.request=[...this.event.request,...i.event.request]),i.event.onResponse.length&&(this.event.onResponse=[...this.event.onResponse,...i.event.onResponse]),this.model(i.meta.defs),Object.values(s.routes).forEach(({method:r,path:o,handler:n,hooks:a})=>{let h=s.wsRouter?.find("subscribe",o);if(h){let e=s.wsRouter.history.find(([e,t])=>o===t);if(!e)return;return this.ws(o,e[2])}this.add(r,o,n,t(e,{...a,error:a.error?Array.isArray(a.error)?[...a.error,...i.event.error]:[a.error,...i.event.error]:i.event.error}))}),s.wsRouter&&this.wsRouter&&s.wsRouter.history.forEach(([e,t,r])=>{this.wsRouter?.add(e,t,r)}),this}use(e){let r=e=>{if("function"==typeof e){let t=e(this);return t instanceof Promise?(this.lazyLoadModules.push(t.then(e=>e.compile())),this):t}let r=e.config.scoped;r||(this.decorators=o(this.decorators,e.decorators),this.state(e.store),this.model(e.meta.defs),this.addError(e.error));let{config:{name:s,seed:h}}=e;if(Object.values(e.routes).forEach(({method:r,path:s,handler:o,hooks:i})=>{let n=e.wsRouter?.find("subscribe",s);if(n){let t=e.wsRouter.history.find(([e,t])=>s===t);if(!t)return;return this.ws(s,t[2])}this.add(r,s,o,t(i,{error:e.event.error}))}),!r){if(s){s in this.dependencies||(this.dependencies[s]=[]);let t=void 0!==h?i(s+JSON.stringify(h)):0;if(this.dependencies[s].some(e=>t===e))return this;this.dependencies[s].push(t),this.event=n(this.event,a(e.event),t)}else this.event=n(this.event,a(e.event))}return this};return e instanceof Promise?(this.lazyLoadModules.push(e.then(e=>"function"==typeof e?e(this):"function"==typeof e.default?e.default(this):r(e.default)).then(e=>e.compile())),this):r(e)}mount(e,t){if("function"==typeof e||0===e.length||"/"===e){let r="function"==typeof e?e:t,s=async({request:e,path:t})=>r(new Request("http://a.cc"+t,e));return this.all("/",s,{type:"none"}),this.all("/*",s,{type:"none"}),this}let r=e.length,s=async({request:e,path:s})=>t(new Request("http://a.cc"+s.slice(r),e));return this.all(e,s,{type:"none"}),this.all(e+(e.endsWith("/")?"*":"/*"),s,{type:"none"}),this}get(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("GET",s,t,r);return this}post(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("POST",s,t,r);return this}put(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("PUT",s,t,r);return this}patch(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("PATCH",s,t,r);return this}delete(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("DELETE",s,t,r);return this}options(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("OPTIONS",s,t,r);return this}all(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("ALL",s,t,r);return this}head(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("HEAD",s,t,r);return this}trace(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("TRACE",s,t,r);return this}connect(e,t,r){for(let s of("string"==typeof e&&(e=[e]),e))this.add("CONNECT",s,t,r);return this}ws(e,t){if(!this.wsRouter)throw Error("Can't find WebSocket. Please register WebSocket plugin first by importing 'elysia/ws'");for(let s of("string"==typeof e&&(e=[e]),e))this.wsRouter.add("subscribe",s,t),this.get(s,e=>{if(!this.server?.upgrade(e.request,{headers:"function"==typeof t.upgrade?t.upgrade(e):t.upgrade,data:{...e,id:Date.now(),headers:e.request.headers.toJSON(),message:r(t?.body,{models:this.meta.defs}),transformMessage:t.transform?Array.isArray(t.transformMessage)?t.transformMessage:[t.transformMessage]:[]}}))return e.set.status=400,"Expected a websocket connection"},{beforeHandle:t.beforeHandle,transform:t.transform,headers:t?.headers,params:t?.params,query:t?.query});return this}route(e,t,r,{config:s,...o}={config:{allowMeta:!1}}){for(let i of("string"==typeof t&&(t=[t]),t))this.add(e,i,r,o,s);return this}state(e,t){return"object"==typeof e?this.store=o(this.store,e):e in this.store||(this.store[e]=t),this}decorate(e,t){return"object"==typeof e?this.decorators=o(this.decorators,e):e in this.decorators||(this.decorators[e]=t),this}derive(e){return e.$elysia="derive",this.onTransform(e)}schema(e){let t=this.meta.defs;return this.$schema={body:r(e.body,{models:t}),headers:r(e?.headers,{models:t,additionalProperties:!0}),params:r(e?.params,{models:t}),query:r(e?.query,{models:t}),response:r(e?.response,{models:t})},this}compile(){return this.fetch=this.config.aot?u(this):y(this),"function"==typeof this.server?.reload&&this.server.reload({...this.server,fetch:this.fetch}),this}handle=async e=>this.fetch(e);fetch=e=>(this.fetch=this.config.aot?u(this):y(this))(e);handleError=async(e,t,r)=>(this.handleError=this.config.aot?d(this):m(this))(e,t,r);outerErrorHandler=e=>new Response(e.message,{status:e?.status??500});listen=(e,t)=>{if(!Bun)throw Error("Bun to run");if(this.compile(),"string"==typeof e&&Number.isNaN(e=+e.trim()))throw Error("Port must be a numeric value");let r=this.fetch,s="object"==typeof e?{development:!l,...this.config.serve,...e,fetch:r,error:this.outerErrorHandler}:{development:!l,...this.config.serve,port:e,fetch:r,error:this.outerErrorHandler};if("undefined"==typeof Bun)throw Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");this.server=Bun?.serve(s);for(let e=0;e<this.event.start.length;e++)this.event.start[e](this);return t&&t(this.server),Promise.all(this.lazyLoadModules).then(()=>{Bun?.gc(!0)}),this};stop=async()=>{if(!this.server)throw Error("Elysia isn't running. Call `app.listen` to start the server.");this.server.stop();for(let e=0;e<this.event.stop.length;e++)await this.event.stop[e](this)};get modules(){return Promise.all(this.lazyLoadModules)}model(e,t){return"object"==typeof e?Object.entries(e).forEach(([e,t])=>{e in this.meta.defs||(this.meta.defs[e]=t)}):this.meta.defs[e]=t,this}}export{mapResponse,mapCompactResponse,mapEarlyResponse}from"./handler";export{t}from"./custom-types";export{ws}from"./ws";export{getSchemaValidator,mergeDeep,mergeHook,mergeObjectArray,getResponseSchemaValidator}from"./utils";export{ParseError,NotFoundError,ValidationError,InternalServerError}from"./error";export{g as Elysia};
|
package/dist/types.d.ts
CHANGED
|
@@ -142,7 +142,7 @@ export type LocalHook<Schema extends TypedSchema, Instance extends ElysiaInstanc
|
|
|
142
142
|
transform?: WithArray<HookHandler<Route, Instance, Path>>;
|
|
143
143
|
beforeHandle?: WithArray<HookHandler<Route, Instance, Path>>;
|
|
144
144
|
afterHandle?: WithArray<AfterRequestHandler<TypedSchemaToRoute<Route, Instance['meta']['schema']>, Instance>>;
|
|
145
|
-
error?: WithArray<ErrorHandler
|
|
145
|
+
error?: WithArray<ErrorHandler<Instance['error']>>;
|
|
146
146
|
parse?: WithArray<BodyParser>;
|
|
147
147
|
onResponse?: WithArray<HookHandler<Route, Instance>>;
|
|
148
148
|
} : never);
|