@@ -109,6 +109,15 @@ export type CloudflareModuleAdapter = (
109
109
request : Request ,
110
110
) => ReqResHandler < Response > ;
111
111
112
+ export type ElysiaAdapter = ( ctx : {
113
+ body : Update ;
114
+ headers : Record < string , string | undefined > ;
115
+ set : {
116
+ headers : Record < string , string > ;
117
+ status : number ;
118
+ } ;
119
+ } ) => ReqResHandler < string > ;
120
+
112
121
export type ExpressAdapter = ( req : {
113
122
body : Update ;
114
123
header : ( header : string ) => string | undefined ;
@@ -539,6 +548,33 @@ const worktop: WorktopAdapter = (req, res) => ({
539
548
unauthorized : ( ) => res . send ( 401 , WRONG_TOKEN_ERROR ) ,
540
549
} ) ;
541
550
551
+ const elysia : ElysiaAdapter = ( ctx ) => {
552
+ // @note upgrade target to use modern code?
553
+ // const { promise, resolve } = Promise.withResolvers<string>();
554
+
555
+ let resolve : ( result : string ) => void ;
556
+ const handlerReturn = new Promise < string > ( ( res ) => resolve = res ) ;
557
+
558
+ return {
559
+ // @note technically the type shouldn't be limited to Promise, because it's fine to await plain values as well
560
+ update : Promise . resolve ( ctx . body as Update ) ,
561
+ header : ctx . headers [ SECRET_HEADER_LOWERCASE ] ,
562
+ end ( ) {
563
+ resolve ( "" ) ;
564
+ } ,
565
+ respond ( json ) {
566
+ // @note since json is passed as string here, we gotta define proper content-type
567
+ ctx . set . headers [ "content-type" ] = "application/json" ;
568
+ resolve ( json ) ;
569
+ } ,
570
+ unauthorized ( ) {
571
+ ctx . set . status = 401 ;
572
+ resolve ( "" ) ;
573
+ } ,
574
+ handlerReturn,
575
+ } ;
576
+ } ;
577
+
542
578
// Please open a pull request if you want to add another adapter
543
579
export const adapters = {
544
580
"aws-lambda" : awsLambda ,
@@ -547,6 +583,7 @@ export const adapters = {
547
583
bun,
548
584
cloudflare,
549
585
"cloudflare-mod" : cloudflareModule ,
586
+ elysia,
550
587
express,
551
588
fastify,
552
589
hono,
0 commit comments