elysia 0.7.21 → 0.8.0-exp.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,6 +47,8 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
47
47
  path: BasePath;
48
48
  constructor(config?: Partial<ElysiaConfig<BasePath, Scoped>>);
49
49
  private add;
50
+ private setHeader?;
51
+ header(header: Context['set']['headers'] | undefined): this;
50
52
  /**
51
53
  * ### start | Life cycle event
52
54
  * Called after server is ready for serving
@@ -419,7 +421,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
419
421
  * })
420
422
  * ```
421
423
  */
422
- get<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
424
+ get<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
423
425
  [path in `${BasePath}${Path}`]: {
424
426
  get: {
425
427
  body: Route['body'];
@@ -427,7 +429,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
427
429
  query: Route['query'];
428
430
  headers: Route['headers'];
429
431
  response: unknown extends Route['response'] ? {
430
- 200: ReturnType<Function>;
432
+ 200: Function extends () => infer Returned ? Returned : Function;
431
433
  } : Route['response'] extends {
432
434
  200: any;
433
435
  } ? Route['response'] : {
@@ -454,7 +456,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
454
456
  * })
455
457
  * ```
456
458
  */
457
- post<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
459
+ post<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
458
460
  [path in `${BasePath}${Path}`]: {
459
461
  post: {
460
462
  body: Route['body'];
@@ -462,7 +464,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
462
464
  query: Route['query'];
463
465
  headers: Route['headers'];
464
466
  response: unknown extends Route['response'] ? {
465
- 200: ReturnType<Function>;
467
+ 200: Function extends () => infer Returned ? Returned : Function;
466
468
  } : Route['response'] extends {
467
469
  200: any;
468
470
  } ? Route['response'] : {
@@ -489,7 +491,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
489
491
  * })
490
492
  * ```
491
493
  */
492
- put<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
494
+ put<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
493
495
  [path in `${BasePath}${Path}`]: {
494
496
  put: {
495
497
  body: Route['body'];
@@ -497,7 +499,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
497
499
  query: Route['query'];
498
500
  headers: Route['headers'];
499
501
  response: unknown extends Route['response'] ? {
500
- 200: ReturnType<Function>;
502
+ 200: Function extends () => infer Returned ? Returned : Function;
501
503
  } : Route['response'] extends {
502
504
  200: any;
503
505
  } ? Route['response'] : {
@@ -524,7 +526,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
524
526
  * })
525
527
  * ```
526
528
  */
527
- patch<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
529
+ patch<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
528
530
  [path in `${BasePath}${Path}`]: {
529
531
  patch: {
530
532
  body: Route['body'];
@@ -532,7 +534,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
532
534
  query: Route['query'];
533
535
  headers: Route['headers'];
534
536
  response: unknown extends Route['response'] ? {
535
- 200: ReturnType<Function>;
537
+ 200: Function extends () => infer Returned ? Returned : Function;
536
538
  } : Route['response'] extends {
537
539
  200: any;
538
540
  } ? Route['response'] : {
@@ -559,7 +561,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
559
561
  * })
560
562
  * ```
561
563
  */
562
- delete<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
564
+ delete<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
563
565
  [path in `${BasePath}${Path}`]: {
564
566
  delete: {
565
567
  body: Route['body'];
@@ -567,7 +569,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
567
569
  query: Route['query'];
568
570
  headers: Route['headers'];
569
571
  response: unknown extends Route['response'] ? {
570
- 200: ReturnType<Function>;
572
+ 200: Function extends () => infer Returned ? Returned : Function;
571
573
  } : Route['response'] extends {
572
574
  200: any;
573
575
  } ? Route['response'] : {
@@ -594,7 +596,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
594
596
  * })
595
597
  * ```
596
598
  */
597
- options<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
599
+ options<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
598
600
  [path in `${BasePath}${Path}`]: {
599
601
  options: {
600
602
  body: Route['body'];
@@ -602,7 +604,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
602
604
  query: Route['query'];
603
605
  headers: Route['headers'];
604
606
  response: unknown extends Route['response'] ? {
605
- 200: ReturnType<Function>;
607
+ 200: Function extends () => infer Returned ? Returned : Function;
606
608
  } : Route['response'] extends {
607
609
  200: any;
608
610
  } ? Route['response'] : {
@@ -624,7 +626,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
624
626
  * .all('/', () => 'hi')
625
627
  * ```
626
628
  */
627
- all<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
629
+ all<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
628
630
  [path in `${BasePath}${Path}`]: {
629
631
  [method in string]: {
630
632
  body: Route['body'];
@@ -632,7 +634,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
632
634
  query: Route['query'];
633
635
  headers: Route['headers'];
634
636
  response: unknown extends Route['response'] ? {
635
- 200: ReturnType<Function>;
637
+ 200: Function extends () => infer Returned ? Returned : Function;
636
638
  } : Route['response'] extends {
637
639
  200: any;
638
640
  } ? Route['response'] : {
@@ -659,7 +661,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
659
661
  * })
660
662
  * ```
661
663
  */
662
- head<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
664
+ head<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
663
665
  [path in `${BasePath}${Path}`]: {
664
666
  head: {
665
667
  body: Route['body'];
@@ -667,7 +669,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
667
669
  query: Route['query'];
668
670
  headers: Route['headers'];
669
671
  response: unknown extends Route['response'] ? {
670
- 200: ReturnType<Function>;
672
+ 200: Function extends () => infer Returned ? Returned : Function;
671
673
  } : Route['response'] extends {
672
674
  200: any;
673
675
  } ? Route['response'] : {
@@ -694,7 +696,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
694
696
  * })
695
697
  * ```
696
698
  */
697
- connect<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
699
+ connect<const Path extends string, const LocalSchema extends InputSchema<keyof Definitions['type'] & string>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>>(path: Path, handler: Function, hook?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`>): Elysia<BasePath, Decorators, Definitions, ParentSchema, Prettify<Routes & {
698
700
  [path in `${BasePath}${Path}`]: {
699
701
  connect: {
700
702
  body: Route['body'];
@@ -702,7 +704,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
702
704
  query: Route['query'];
703
705
  headers: Route['headers'];
704
706
  response: unknown extends Route['response'] ? {
705
- 200: ReturnType<Function>;
707
+ 200: Function extends () => infer Returned ? Returned : Function;
706
708
  } : Route['response'] extends {
707
709
  200: any;
708
710
  } ? Route['response'] : {
@@ -757,7 +759,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
757
759
  * })
758
760
  * ```
759
761
  */
760
- route<const Method extends HTTPMethod, const Path extends string, const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const Function extends Handler<Route, Decorators, `${BasePath}${Path}`>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(method: Method, path: Path, handler: Function, { config, ...hook }?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`> & {
762
+ route<const Method extends HTTPMethod, const Path extends string, const LocalSchema extends InputSchema<Extract<keyof Definitions['type'], string>>, const Function extends Exclude<Route['response'], Function> | Handler<Route, Decorators, `${BasePath}${Path}`>, const Route extends MergeSchema<UnwrapRoute<LocalSchema, Definitions['type']>, ParentSchema>>(method: Method, path: Path, handler: Function, { config, ...hook }?: LocalHook<LocalSchema, Route, Decorators, Definitions['error'], `${BasePath}${Path}`> & {
761
763
  config: {
762
764
  allowMeta?: boolean;
763
765
  };
@@ -775,7 +777,7 @@ export default class Elysia<BasePath extends string = '', Decorators extends Dec
775
777
  query: Query;
776
778
  headers: Headers;
777
779
  response: unknown extends Response ? {
778
- 200: ReturnType<Function>;
780
+ 200: Function extends () => infer Returned ? Returned : Function;
779
781
  } : Route['response'] extends {
780
782
  200: any;
781
783
  } ? Route['response'] : {