elysia 1.0.16 → 1.0.18

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.js CHANGED
@@ -4,7 +4,7 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
4
4
  * Copyright(c) 2012-2014 Roman Shtylman
5
5
  * Copyright(c) 2015 Douglas Christopher Wilson
6
6
  * MIT Licensed
7
- */var Z1=p$,Q1=s$;var c$=Object.prototype.toString,d0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var s1=N0(c0(),1);class r{$;J;w;constructor($,J,w={}){this.name=$;this.jar=J;this.initial=w}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var p1=($,J,w)=>{if(!$.cookie)$.cookie={};return new Proxy(J,{get(B,X){if(X in J)return new r(X,$.cookie,Object.assign({},w??{},J[X]));return new r(X,$.cookie,Object.assign({},w))}})},p0=async($,J,{secrets:w,sign:B,...X}={})=>{if(!J)return p1($,{},X);const W=typeof w==="string";if(B&&B!==!0&&!Array.isArray(B))B=[B];const Z={},Q=Z1(J);for(let[Y,G]of Object.entries(Q)){let K=s1.default(G);if(B===!0||B?.includes(Y)){if(!w)throw new Error("No secret is provided to cookie plugin");if(W){const R=await S1(K,w);if(R===!1)throw new P0(Y);K=R}else{let R=!0;for(let F=0;F<w.length;F++){const C=await S1(K,w[F]);if(C!==!1){R=!0,K=C;break}}if(!R)throw new P0(Y)}}const U=K.charCodeAt(0);if(U===123||U===91)try{Z[Y]={value:JSON.parse(K)};continue}catch{}if(z0(K)){Z[Y]={value:parseInt(K)};continue}if(K==="true"){Z[Y]={value:!0};continue}if(K==="false"){Z[Y]={value:!1};continue}Z[Y]={value:K}}return p1($,Z,X)};var O0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let J in $)return!0;return!1},V0=($,J)=>{const w=$.size;if(!J&&w||w&&J&&J.status!==206&&J.status!==304&&J.status!==412&&J.status!==416){if(J){if(J.headers instanceof Headers){if(O0)J.headers=J.headers.toJSON();else for(let[B,X]of J.headers.entries())if(B in J.headers)J.headers[B]=X}return new Response($,{status:J.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`},J.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`}})}return new Response($)},l1=($,J)=>{if(!$)return $;$.delete("Set-Cookie");for(let w=0;w<J.length;w++){const B=J[w].indexOf("=");$.append("Set-Cookie",`${J[w].slice(0,B)}=${J[w].slice(B+1)||""}`)}return $},i1=($)=>{if(!$||!m($))return;const J=[];for(let[w,B]of Object.entries($)){if(!w||!B)continue;const X=B.value;if(X===void 0||X===null)continue;J.push(Q1(w,typeof X==="object"?JSON.stringify(X):X+"",B))}if(J.length===0)return;if(J.length===1)return J[0];return J},h=($,J,w)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return new Response("",J);return Response.json($,J);case"Response":const B={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(X in J.headers)J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);return $;case"Error":return l($,J);case"Promise":return $.then((X)=>h(X,J));case"Function":return h($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>h(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($,J);case"Promise":return $.then((B)=>{const X=n(B);if(X!==void 0)return X;return new Response("")});case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>h(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},f=($,J,w)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return;return Response.json($,J);case"Response":const B=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(!(X in J.headers))J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);if($.status!==J.status)J.status=$.status;return $;case"Promise":return $.then((X)=>{const W=f(X,J);if(W!==void 0)return W});case"Error":return l($,J);case"Function":return f($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>f(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((B)=>{const X=f(B,J);if(X!==void 0)return X});case"Error":return l($,J);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>f(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},n=($,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return h($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($);case"Promise":return $.then(n);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(n);if($ instanceof Error)return l($);if("charCodeAt"in $){const w=$.charCodeAt(0);if(w===123||w===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},l=($,J)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:J?.status!==200?J?.status??500:500,headers:J?.headers});var ZJ=function($){let J=$;while(J.endsWith("="))J=J.slice(0,-1);return J},U1=($,J)=>{const w=new URL($);return w.pathname=J,w.toString()},e$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),K1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,J,{skipKeys:w}={})=>{if(K1($)&&K1(J))for(let[B,X]of Object.entries(J)){if(w?.includes(B))continue;if(!K1(X)||!(B in $)||e$(X)){$[B]=X;continue}$[B]=p($[B],X)}return $},$J=($,J)=>{const{properties:w,...B}=$??{},{properties:X,...W}=J??{};return p(B,W)},L=($=[],J=[])=>{if(!$)return[];if(!J)return $;const w=[],B=[];if(!Array.isArray($))$=[$];if(!Array.isArray(J))J=[J];for(let X of $)if(w.push(X),X.checksum)B.push(X.checksum);for(let X of J)if(!B.includes(X.checksum))w.push(X);return w},JJ=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],wJ=JJ.reduce(($,J)=>($[J]=!0,$),{}),BJ=($,J)=>{const w=(B)=>typeof B==="object"&&Object.keys(B).every(z0);if(w($)&&w(J))return{...$,...J};return J??$},u=($,J,{allowMacro:w=!1}={})=>{return{...w?{...$,...J}:void 0,body:J?.body??$?.body,headers:J?.headers??$?.headers,params:J?.params??$?.params,query:J?.query??$?.query,response:BJ($?.response,J?.response),type:$?.type||J?.type,detail:p(J?.detail??{},$?.detail??{}),parse:L($?.parse,J?.parse),transform:L($?.transform,J?.transform),beforeHandle:L($?.beforeHandle,J?.beforeHandle),afterHandle:L($?.afterHandle,J?.afterHandle),onResponse:L($?.onResponse,J?.onResponse),mapResponse:L($?.mapResponse,J?.mapResponse),trace:L($?.trace,J?.trace),error:L($?.error,J?.error)}},k=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$;if(W.type==="object"&&"additionalProperties"in W===!1)W.additionalProperties=X;const Z=(Y)=>R0.Clean(W,Y);if(w){const Y={schema:W,references:"",checkFunc:()=>{},code:"",Check:(G)=>R0.Check(W,G),Errors:(G)=>R0.Errors(W,G),Code:()=>""};if(B&&W.additionalProperties===!0)Y.Clean=Z;if(W.config){if(Y.config=W.config,Y?.schema?.config)delete Y.schema.config}return Y}const Q=r1.Compile(W,Object.values(J));if(Q.Clean=Z,W.config){if(Q.config=W.config,Q?.schema?.config)delete Q.schema.config}return Q},s0=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$,Z=(Y,G)=>{const K=(R)=>R0.Clean(Y,R);if(w)return{schema:Y,references:"",checkFunc:()=>{},code:"",Check:(R)=>R0.Check(Y,R),Errors:(R)=>R0.Errors(Y,R),Code:()=>""};const U=r1.Compile(Y,G);if(B&&Y.additionalProperties===!0)U.Clean=K;return U};if(G1 in W){if("additionalProperties"in W===!1)W.additionalProperties=X;return{200:Z(W,Object.values(J))}}const Q={};return Object.keys(W).forEach((Y)=>{const G=W[+Y];if(typeof G==="string"){if(G in J){const K=J[G];K.type==="object"&&"additionalProperties"in K,Q[+Y]=G1 in K?Z(K,Object.values(J)):K}return}if(G.type==="object"&&"additionalProperties"in G===!1)G.additionalProperties=X;Q[+Y]=G1 in G?Z(G,Object.values(J)):G}),Q},XJ=typeof Bun!=="undefined",WJ=XJ&&typeof Bun.hash==="function",q0=($)=>{if(WJ)return Bun.hash($);let J=9;for(let w=0;w<$.length;)J=Math.imul(J^$.charCodeAt(w++),387420489);return J=J^J>>>9},l0=({validator:$,defaultConfig:J={},config:w,dynamic:B,models:X})=>{let W=k($,{dynamic:B,models:X,additionalProperties:!0});if(m(J))if(W)W.config=$J(W.config,w);else W=k(V.Cookie({}),{dynamic:B,models:X,additionalProperties:!0}),W.config=J;return W},i0=($,J,w)=>{const B=(X)=>{if(!X)return;if(!Array.isArray(X)){const Z=X;if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local";return Z}const W=[...X];for(let Z of W){if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local"}return W};return{start:L($.start,B(J?.start)),request:L($.request,B(J?.request)),parse:L($.parse,B(J?.parse)),transform:L($.transform,B(J?.transform)),beforeHandle:L($.beforeHandle,B(J?.beforeHandle)),afterHandle:L($.afterHandle,B(J?.afterHandle)),mapResponse:L($.mapResponse,B(J?.mapResponse)),onResponse:L($.onResponse,B(J?.onResponse)),trace:$.trace,error:L($.error,B(J?.error)),stop:L($.stop,B(J?.stop))}},n1=($,J,{skipIfHasType:w=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(w)$.scope??=J;else $.scope=J;return $}for(let B of $)if(w)B.scope??=J;else B.scope=J;return $},W0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const J=[];for(let w of $)switch(w.scope){case"global":case"scoped":J.push({...w});break}return J},z1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:W0($?.parse),transform:W0($?.transform),beforeHandle:W0($?.beforeHandle),afterHandle:W0($?.afterHandle),onResponse:W0($?.onResponse),error:W0($?.error),mapResponse:W0($?.mapResponse)}},X0={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},t0=Object.fromEntries(Object.entries(X0).map(([$,J])=>[J,$])),t1=new TextEncoder,_0=async($,J)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(J===null)throw new TypeError("Secret key must be provided.");const w=await crypto.subtle.importKey("raw",t1.encode(J),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),B=await crypto.subtle.sign("HMAC",w,t1.encode($));return $+"."+ZJ(Buffer.from(B).toString("base64"))},S1=async($,J)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(J===null)throw new TypeError("Secret key must be provided.");const w=$.slice(0,$.lastIndexOf("."));return await _0(w,J)===$?w:!1},R1=($,J,w=J)=>{if(!$||typeof $!=="object"||!J)return;for(let[B,X]of Object.entries(J)){if(B in wJ||!(B in $))continue;const W=$[B];if(typeof W==="function")W(X);else if(typeof W==="object")R1(W,X,w)}},o1=({globalHook:$,localHook:J})=>(w)=>(B,X)=>{if(typeof B==="function")B={fn:B};if("fn"in B||Array.isArray(B)){if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(Array.isArray(B))J[w]=J[w].concat(B);else J[w].push(B);return}const{insert:W="after",stack:Z="local"}=B;if(typeof X==="function")X={fn:X};if(Z==="global")if(!Array.isArray(X))if(W==="before")$[w].unshift(X);else $[w].push(X);else if(W==="before")$[w]=X.concat($[w]);else $[w]=$[w].concat(X);else{if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(!Array.isArray(X))if(W==="before")J[w].unshift(X);else J[w].push(X);else if(W==="before")J[w]=X.concat(J[w]);else J[w]=J[w].concat(X)}},z0=($)=>{if($.length<16)return $.trim().length!==0&&!Number.isNaN(Number($));if($.length===16){const J=Number($);if(J.toString()===$)return $.trim().length!==0&&!Number.isNaN(J)}return!1};class _1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,J){return(this.root??Promise.resolve()).then($,J)}}var c=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const J=[];for(let w of $)if(typeof w==="function")J.push({fn:w});else if("fn"in w)J.push(w);return J},a1=($)=>{return{...$,start:c($?.start),request:c($?.request),parse:c($?.parse),transform:c($?.transform),beforeHandle:c($?.beforeHandle),afterHandle:c($?.afterHandle),onResponse:c($?.onResponse),mapResponse:c($?.mapResponse),trace:c($?.trace),error:c($?.error),stop:c($?.stop)}},e1=($)=>{return{...$,start:$.start?.map((J)=>J.fn),request:$.request?.map((J)=>J.fn),parse:$.parse?.map((J)=>J.fn),transform:$.transform?.map((J)=>J.fn),beforeHandle:$.beforeHandle?.map((J)=>J.fn),afterHandle:$.afterHandle?.map((J)=>J.fn),onResponse:$.onResponse?.map((J)=>J.fn),mapResponse:$.mapResponse?.map((J)=>J.fn),trace:$.trace?.map((J)=>J.fn),error:$.error?.map((J)=>J.fn),stop:$.stop?.map((J)=>J.fn)}},r0=($)=>({event:{body:$.event.body,cookie:$.event.cookie,headers:$.event.headers,queries:[...$.event.queries],query:$.event.query,set:$.event.set,unknownQueries:$.event.unknownQueries},trace:{request:$.trace.request,parse:$.trace.parse,transform:$.trace.transform,handle:$.trace.handle,beforeHandle:$.trace.beforeHandle,afterHandle:$.trace.afterHandle,error:$.trace.error,context:$.trace.context,store:$.trace.store,set:$.trace.set}}),j1=($,J=301)=>new Response(null,{status:J,headers:{Location:$}});var $$=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,Z0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),I0=($$?.NODE_ENV??$$?.ENV)==="production",F1=($,J)=>({[d]:X0[$]??$,response:J??($ in t0?t0[$]:$),_type:void 0});class o0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class Q0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class a0 extends Error{J;code="PARSE";status=400;constructor($,J){super($??"PARSE");this.body=J}}class P0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,J){super(J??`"${$}" has invalid cookie signature`);this.key=$}}class I extends Error{$;J;w;code="VALIDATION";status=422;constructor($,J,w){if(typeof w==="object"&&d in w)w=w.response;const B=I0?void 0:("Errors"in J)?J.Errors(w).First():n0.Errors(J,w).First(),X=B?.schema.error?typeof B.schema.error==="function"?B.schema.error($,J,w):B.schema.error:void 0,W=B?.path||"root";let Z="";if(X)Z=typeof X==="object"?JSON.stringify(X):X+"";else if(I0)Z=JSON.stringify({type:"validation",on:$,message:B?.message,found:w});else{const Q=J?.schema??J,Y="Errors"in J?[...J.Errors(w)]:[...n0.Errors(J,w)];let G;try{G=n0.Create(Q)}catch(K){G={type:"Could not create expected value",message:K?.message,error:K}}Z=JSON.stringify({type:"validation",on:$,property:W,message:B?.message,expected:G,found:w,errors:Y},null,2)}super(Z);this.type=$;this.validator=J;this.value=w;Object.setPrototypeOf(this,I.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const J="schema"in $?$.schema:$;try{return n0.Create(J)}catch{return J}}get model(){return I.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var C1={open($){$.data.open?.($)},message($,J){$.data.message?.($,J)},drain($){$.data.drain?.($)},close($,J,w){$.data.close?.($,J,w)}};class j0{$;J;validator;constructor($,J){this.raw=$;this.data=J;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else{const w=new Uint32Array(1);crypto.getRandomValues(w),this.id=w[0].toString()}}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,J=void 0,w)=>{if(this.validator?.Check(J)===!1)throw new I("message",this.validator,J);if(typeof J==="object")J=JSON.stringify(J);return this.raw.publish($,J,w),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new I("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var R$=N0(M1(),1),_$=N0(c0(),1);import{Value as T0} from"@sinclair/typebox/value";var KJ=(new Headers()).toJSON,j$={value:0},F$=({hasTrace:$,hasTraceSet:J=!1,addFn:w,condition:B={}})=>{if($)return w("\nconst reporter = getReporter()\n"),(X,{name:W,attribute:Z="",unit:Q=0}={})=>{const Y=X.indexOf("."),G=Y===-1;if(X!=="request"&&X!=="response"&&!B[G?X:X.slice(0,Y)])return()=>{if(J&&X==="afterHandle")w("\nawait traceDone\n")};if(G)W||=X;else W||="anonymous";return w("\n"+`reporter.emit('event', {
7
+ */var Z1=p$,Q1=s$;var c$=Object.prototype.toString,d0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var s1=N0(c0(),1);class r{$;J;w;constructor($,J,w={}){this.name=$;this.jar=J;this.initial=w}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get partitioned(){return this.cookie.partitioned}set partitioned($){this.cookie.partitioned=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var p1=($,J,w)=>{if(!$.cookie)$.cookie={};return new Proxy(J,{get(B,X){if(X in J)return new r(X,$.cookie,Object.assign({},w??{},J[X]));return new r(X,$.cookie,Object.assign({},w))}})},p0=async($,J,{secrets:w,sign:B,...X}={})=>{if(!J)return p1($,{},X);const W=typeof w==="string";if(B&&B!==!0&&!Array.isArray(B))B=[B];const Z={},Q=Z1(J);for(let[Y,G]of Object.entries(Q)){let K=s1.default(G);if(B===!0||B?.includes(Y)){if(!w)throw new Error("No secret is provided to cookie plugin");if(W){const R=await S1(K,w);if(R===!1)throw new P0(Y);K=R}else{let R=!0;for(let F=0;F<w.length;F++){const C=await S1(K,w[F]);if(C!==!1){R=!0,K=C;break}}if(!R)throw new P0(Y)}}const U=K.charCodeAt(0);if(U===123||U===91)try{Z[Y]={value:JSON.parse(K)};continue}catch{}if(z0(K)){Z[Y]={value:parseInt(K)};continue}if(K==="true"){Z[Y]={value:!0};continue}if(K==="false"){Z[Y]={value:!1};continue}Z[Y]={value:K}}return p1($,Z,X)};var O0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let J in $)return!0;return!1},V0=($,J)=>{const w=$.size;if(!J&&w||w&&J&&J.status!==206&&J.status!==304&&J.status!==412&&J.status!==416){if(J){if(J.headers instanceof Headers){if(O0)J.headers=J.headers.toJSON();else for(let[B,X]of J.headers.entries())if(B in J.headers)J.headers[B]=X}return new Response($,{status:J.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`},J.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`}})}return new Response($)},l1=($,J)=>{if(!$)return $;$.delete("Set-Cookie");for(let w=0;w<J.length;w++){const B=J[w].indexOf("=");$.append("Set-Cookie",`${J[w].slice(0,B)}=${J[w].slice(B+1)||""}`)}return $},i1=($)=>{if(!$||!m($))return;const J=[];for(let[w,B]of Object.entries($)){if(!w||!B)continue;const X=B.value;if(X===void 0||X===null)continue;J.push(Q1(w,typeof X==="object"?JSON.stringify(X):X+"",B))}if(J.length===0)return;if(J.length===1)return J[0];return J},h=($,J,w)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return new Response("",J);return Response.json($,J);case"Response":const B={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(X in J.headers)J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);return $;case"Error":return l($,J);case"Promise":return $.then((X)=>h(X,J));case"Function":return h($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>h(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($,J);case"Promise":return $.then((B)=>{const X=n(B);if(X!==void 0)return X;return new Response("")});case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>h(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},f=($,J,w)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return;return Response.json($,J);case"Response":const B=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(!(X in J.headers))J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);if($.status!==J.status)J.status=$.status;return $;case"Promise":return $.then((X)=>{const W=f(X,J);if(W!==void 0)return W});case"Error":return l($,J);case"Function":return f($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>f(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((B)=>{const X=f(B,J);if(X!==void 0)return X});case"Error":return l($,J);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>f(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},n=($,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return h($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($);case"Promise":return $.then(n);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(n);if($ instanceof Error)return l($);if("charCodeAt"in $){const w=$.charCodeAt(0);if(w===123||w===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},l=($,J)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:J?.status!==200?J?.status??500:500,headers:J?.headers});var ZJ=function($){let J=$;while(J.endsWith("="))J=J.slice(0,-1);return J},U1=($,J)=>{const w=new URL($);return w.pathname=J,w.toString()},e$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),K1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,J,{skipKeys:w}={})=>{if(K1($)&&K1(J))for(let[B,X]of Object.entries(J)){if(w?.includes(B))continue;if(!K1(X)||!(B in $)||e$(X)){$[B]=X;continue}$[B]=p($[B],X)}return $},$J=($,J)=>{const{properties:w,...B}=$??{},{properties:X,...W}=J??{};return p(B,W)},L=($=[],J=[])=>{if(!$)return[];if(!J)return $;const w=[],B=[];if(!Array.isArray($))$=[$];if(!Array.isArray(J))J=[J];for(let X of $)if(w.push(X),X.checksum)B.push(X.checksum);for(let X of J)if(!B.includes(X.checksum))w.push(X);return w},JJ=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],wJ=JJ.reduce(($,J)=>($[J]=!0,$),{}),BJ=($,J)=>{const w=(B)=>typeof B==="object"&&Object.keys(B).every(z0);if(w($)&&w(J))return{...$,...J};return J??$},u=($,J,{allowMacro:w=!1}={})=>{return{...w?{...$,...J}:void 0,body:J?.body??$?.body,headers:J?.headers??$?.headers,params:J?.params??$?.params,query:J?.query??$?.query,response:BJ($?.response,J?.response),type:$?.type||J?.type,detail:p(J?.detail??{},$?.detail??{}),parse:L($?.parse,J?.parse),transform:L($?.transform,J?.transform),beforeHandle:L($?.beforeHandle,J?.beforeHandle),afterHandle:L($?.afterHandle,J?.afterHandle),onResponse:L($?.onResponse,J?.onResponse),mapResponse:L($?.mapResponse,J?.mapResponse),trace:L($?.trace,J?.trace),error:L($?.error,J?.error)}},k=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$;if(W.type==="object"&&"additionalProperties"in W===!1)W.additionalProperties=X;const Z=(Y)=>R0.Clean(W,Y);if(w){const Y={schema:W,references:"",checkFunc:()=>{},code:"",Check:(G)=>R0.Check(W,G),Errors:(G)=>R0.Errors(W,G),Code:()=>""};if(B&&W.additionalProperties===!0)Y.Clean=Z;if(W.config){if(Y.config=W.config,Y?.schema?.config)delete Y.schema.config}return Y}const Q=r1.Compile(W,Object.values(J));if(Q.Clean=Z,W.config){if(Q.config=W.config,Q?.schema?.config)delete Q.schema.config}return Q},s0=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$,Z=(Y,G)=>{const K=(R)=>R0.Clean(Y,R);if(w)return{schema:Y,references:"",checkFunc:()=>{},code:"",Check:(R)=>R0.Check(Y,R),Errors:(R)=>R0.Errors(Y,R),Code:()=>""};const U=r1.Compile(Y,G);if(B&&Y.additionalProperties===!0)U.Clean=K;return U};if(G1 in W){if("additionalProperties"in W===!1)W.additionalProperties=X;return{200:Z(W,Object.values(J))}}const Q={};return Object.keys(W).forEach((Y)=>{const G=W[+Y];if(typeof G==="string"){if(G in J){const K=J[G];K.type==="object"&&"additionalProperties"in K,Q[+Y]=G1 in K?Z(K,Object.values(J)):K}return}if(G.type==="object"&&"additionalProperties"in G===!1)G.additionalProperties=X;Q[+Y]=G1 in G?Z(G,Object.values(J)):G}),Q},XJ=typeof Bun!=="undefined",WJ=XJ&&typeof Bun.hash==="function",q0=($)=>{if(WJ)return Bun.hash($);let J=9;for(let w=0;w<$.length;)J=Math.imul(J^$.charCodeAt(w++),387420489);return J=J^J>>>9},l0=({validator:$,defaultConfig:J={},config:w,dynamic:B,models:X})=>{let W=k($,{dynamic:B,models:X,additionalProperties:!0});if(m(J))if(W)W.config=$J(W.config,w);else W=k(V.Cookie({}),{dynamic:B,models:X,additionalProperties:!0}),W.config=J;return W},i0=($,J,w)=>{const B=(X)=>{if(!X)return;if(!Array.isArray(X)){const Z=X;if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local";return Z}const W=[...X];for(let Z of W){if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local"}return W};return{start:L($.start,B(J?.start)),request:L($.request,B(J?.request)),parse:L($.parse,B(J?.parse)),transform:L($.transform,B(J?.transform)),beforeHandle:L($.beforeHandle,B(J?.beforeHandle)),afterHandle:L($.afterHandle,B(J?.afterHandle)),mapResponse:L($.mapResponse,B(J?.mapResponse)),onResponse:L($.onResponse,B(J?.onResponse)),trace:$.trace,error:L($.error,B(J?.error)),stop:L($.stop,B(J?.stop))}},n1=($,J,{skipIfHasType:w=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(w)$.scope??=J;else $.scope=J;return $}for(let B of $)if(w)B.scope??=J;else B.scope=J;return $},W0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const J=[];for(let w of $)switch(w.scope){case"global":case"scoped":J.push({...w});break}return J},z1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:W0($?.parse),transform:W0($?.transform),beforeHandle:W0($?.beforeHandle),afterHandle:W0($?.afterHandle),onResponse:W0($?.onResponse),error:W0($?.error),mapResponse:W0($?.mapResponse)}},X0={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},t0=Object.fromEntries(Object.entries(X0).map(([$,J])=>[J,$])),t1=new TextEncoder,_0=async($,J)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(J===null)throw new TypeError("Secret key must be provided.");const w=await crypto.subtle.importKey("raw",t1.encode(J),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),B=await crypto.subtle.sign("HMAC",w,t1.encode($));return $+"."+ZJ(Buffer.from(B).toString("base64"))},S1=async($,J)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(J===null)throw new TypeError("Secret key must be provided.");const w=$.slice(0,$.lastIndexOf("."));return await _0(w,J)===$?w:!1},R1=($,J,w=J)=>{if(!$||typeof $!=="object"||!J)return;for(let[B,X]of Object.entries(J)){if(B in wJ||!(B in $))continue;const W=$[B];if(typeof W==="function")W(X);else if(typeof W==="object")R1(W,X,w)}},o1=({globalHook:$,localHook:J})=>(w)=>(B,X)=>{if(typeof B==="function")B={fn:B};if("fn"in B||Array.isArray(B)){if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(Array.isArray(B))J[w]=J[w].concat(B);else J[w].push(B);return}const{insert:W="after",stack:Z="local"}=B;if(typeof X==="function")X={fn:X};if(Z==="global")if(!Array.isArray(X))if(W==="before")$[w].unshift(X);else $[w].push(X);else if(W==="before")$[w]=X.concat($[w]);else $[w]=$[w].concat(X);else{if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(!Array.isArray(X))if(W==="before")J[w].unshift(X);else J[w].push(X);else if(W==="before")J[w]=X.concat(J[w]);else J[w]=J[w].concat(X)}},z0=($)=>{if($.length<16)return $.trim().length!==0&&!Number.isNaN(Number($));if($.length===16){const J=Number($);if(J.toString()===$)return $.trim().length!==0&&!Number.isNaN(J)}return!1};class _1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,J){return(this.root??Promise.resolve()).then($,J)}}var c=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const J=[];for(let w of $)if(typeof w==="function")J.push({fn:w});else if("fn"in w)J.push(w);return J},a1=($)=>{return{...$,start:c($?.start),request:c($?.request),parse:c($?.parse),transform:c($?.transform),beforeHandle:c($?.beforeHandle),afterHandle:c($?.afterHandle),onResponse:c($?.onResponse),mapResponse:c($?.mapResponse),trace:c($?.trace),error:c($?.error),stop:c($?.stop)}},e1=($)=>{return{...$,start:$.start?.map((J)=>J.fn),request:$.request?.map((J)=>J.fn),parse:$.parse?.map((J)=>J.fn),transform:$.transform?.map((J)=>J.fn),beforeHandle:$.beforeHandle?.map((J)=>J.fn),afterHandle:$.afterHandle?.map((J)=>J.fn),onResponse:$.onResponse?.map((J)=>J.fn),mapResponse:$.mapResponse?.map((J)=>J.fn),trace:$.trace?.map((J)=>J.fn),error:$.error?.map((J)=>J.fn),stop:$.stop?.map((J)=>J.fn)}},r0=($)=>({event:{body:$.event.body,cookie:$.event.cookie,headers:$.event.headers,queries:[...$.event.queries],query:$.event.query,set:$.event.set,unknownQueries:$.event.unknownQueries},trace:{request:$.trace.request,parse:$.trace.parse,transform:$.trace.transform,handle:$.trace.handle,beforeHandle:$.trace.beforeHandle,afterHandle:$.trace.afterHandle,error:$.trace.error,context:$.trace.context,store:$.trace.store,set:$.trace.set}}),j1=($,J=301)=>new Response(null,{status:J,headers:{Location:$}});var $$=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,Z0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),I0=($$?.NODE_ENV??$$?.ENV)==="production",F1=($,J)=>({[d]:X0[$]??$,response:J??($ in t0?t0[$]:$),_type:void 0});class o0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class Q0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class a0 extends Error{J;code="PARSE";status=400;constructor($,J){super($??"PARSE");this.body=J}}class P0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,J){super(J??`"${$}" has invalid cookie signature`);this.key=$}}class I extends Error{$;J;w;code="VALIDATION";status=422;constructor($,J,w){if(typeof w==="object"&&d in w)w=w.response;const B=I0?void 0:("Errors"in J)?J.Errors(w).First():n0.Errors(J,w).First(),X=B?.schema.error?typeof B.schema.error==="function"?B.schema.error($,J,w):B.schema.error:void 0,W=B?.path||"root";let Z="";if(X)Z=typeof X==="object"?JSON.stringify(X):X+"";else if(I0)Z=JSON.stringify({type:"validation",on:$,message:B?.message,found:w});else{const Q=J?.schema??J,Y="Errors"in J?[...J.Errors(w)]:[...n0.Errors(J,w)];let G;try{G=n0.Create(Q)}catch(K){G={type:"Could not create expected value",message:K?.message,error:K}}Z=JSON.stringify({type:"validation",on:$,property:W,message:B?.message,expected:G,found:w,errors:Y},null,2)}super(Z);this.type=$;this.validator=J;this.value=w;Object.setPrototypeOf(this,I.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const J="schema"in $?$.schema:$;try{return n0.Create(J)}catch{return J}}get model(){return I.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var C1={open($){$.data.open?.($)},message($,J){$.data.message?.($,J)},drain($){$.data.drain?.($)},close($,J,w){$.data.close?.($,J,w)}};class j0{$;J;validator;constructor($,J){this.raw=$;this.data=J;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else{const w=new Uint32Array(1);crypto.getRandomValues(w),this.id=w[0].toString()}}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,J=void 0,w)=>{if(this.validator?.Check(J)===!1)throw new I("message",this.validator,J);if(typeof J==="object")J=JSON.stringify(J);return this.raw.publish($,J,w),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new I("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var R$=N0(M1(),1),_$=N0(c0(),1);import{Value as T0} from"@sinclair/typebox/value";var KJ=(new Headers()).toJSON,j$={value:0},F$=({hasTrace:$,hasTraceSet:J=!1,addFn:w,condition:B={}})=>{if($)return w("\nconst reporter = getReporter()\n"),(X,{name:W,attribute:Z="",unit:Q=0}={})=>{const Y=X.indexOf("."),G=Y===-1;if(X!=="request"&&X!=="response"&&!B[G?X:X.slice(0,Y)])return()=>{if(J&&X==="afterHandle")w("\nawait traceDone\n")};if(G)W||=X;else W||="anonymous";return w("\n"+`reporter.emit('event', {
8
8
  id,
9
9
  event: '${X}',
10
10
  type: 'begin',
@@ -54,19 +54,19 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
54
54
  ${N("sameSite")}
55
55
  ${N("secure")}
56
56
  }`:"undefined";if(e)S+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${_})\n`;else S+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${_})\n`}if(M){let N=[];if(W.query&&W.query.schema.type==="object")N=Object.keys(W.query.schema.properties);else for(let _ of z.queries)if(N.indexOf(_)===-1)N.push(_);if($.config.forceDynamicQuery===!0||z.unknownQueries===!0||!N.length)S+=`if(c.qi !== -1) {
57
- c.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\+/g, ' '))
57
+ c.query = parseQuery(c.url.slice(c.qi + 1).replace(/\\+/g, ' '))
58
58
 
59
- for(const key of Object.keys(c.query))
60
- c.query[key] = decodeURIComponent(c.query[key])
59
+ // decodeURIComponent is already done in parseQuery function
60
+ // for(const key of Object.keys(c.query))
61
+ // c.query[key] = decodeURIComponentc.query[key])
61
62
  } else c.query = {}`;else S+=`if(c.qi !== -1) {
62
- let url = c.request.url.slice(c.qi).replace(/\\+/g, ' ')
63
+ let url = '&' + c.url.slice(c.qi + 1).replace(/\\+/g, ' ')
63
64
 
64
65
  ${N.map((_,j)=>`
65
66
  ${j===0?"let":""} memory = url.indexOf('&${_}=')
66
- if(memory === -1) memory = url.indexOf('?${_}=')
67
67
  let a${j}
68
68
 
69
- if(memory !== -1) {
69
+ if (memory !== -1) {
70
70
  const start = memory + ${_.length+2}
71
71
  memory = url.indexOf('&', start)
72
72
 
@@ -186,9 +186,9 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
186
186
  mr = onMapResponse[${M0}](c)
187
187
  if(mr instanceof Promise) mr = await mr
188
188
  if(mr !== undefined) c.response = mr
189
- }\n`}S+=A,S+="return mapEarlyResponse(be, c.set, c.request)}\n"}}N()}if(X?.afterHandle.length){const N=E("handle",{name:K?Z.name:void 0});if(X.afterHandle.length)S+=G0?`let r = c.response = await ${R};\n`:`let r = c.response = ${R};\n`;else S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`;N();const _=E("afterHandle",{unit:X.afterHandle.length});for(let j=0;j<X.afterHandle.length;j++){const b=X.afterHandle[j],H=E0(b.fn.toString()),v0=E("afterHandle.unit",{name:b.fn.name});if(!H)S+=x(b.fn)?`await afterHandle[${j}](c)\n`:`afterHandle[${j}](c)\n`,v0();else if(S+=x(b.fn)?`af = await afterHandle[${j}](c)\n`:`af = afterHandle[${j}](c)\n`,v0(),W.response)S+="if(af !== undefined) {",_(),S+=x0("af"),S+="c.response = af }";else S+="if(af !== undefined) {",_(),S+="c.response = af}\n"}if(_(),S+="r = c.response\n",W.response)S+=x0();if(S+=A,X.mapResponse.length)for(let j=0;j<X.mapResponse.length;j++)S+=`\nmr = onMapResponse[${j}](c)
189
+ }\n`}S+=A,S+="return mapEarlyResponse(be, c.set)}\n"}}N()}if(X?.afterHandle.length){const N=E("handle",{name:K?Z.name:void 0});if(X.afterHandle.length)S+=G0?`let r = c.response = await ${R};\n`:`let r = c.response = ${R};\n`;else S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`;N();const _=E("afterHandle",{unit:X.afterHandle.length});for(let j=0;j<X.afterHandle.length;j++){const b=X.afterHandle[j],H=E0(b.fn.toString()),v0=E("afterHandle.unit",{name:b.fn.name});if(!H)S+=x(b.fn)?`await afterHandle[${j}](c)\n`:`afterHandle[${j}](c)\n`,v0();else if(S+=x(b.fn)?`af = await afterHandle[${j}](c)\n`:`af = afterHandle[${j}](c)\n`,v0(),W.response)S+="if(af !== undefined) {",_(),S+=x0("af"),S+="c.response = af }";else S+="if(af !== undefined) {",_(),S+="c.response = af}\n"}if(_(),S+="r = c.response\n",W.response)S+=x0();if(S+=A,X.mapResponse.length)for(let j=0;j<X.mapResponse.length;j++)S+=`\nmr = onMapResponse[${j}](c)
190
190
  if(mr instanceof Promise) mr = await mr
191
- if(mr !== undefined) c.response = mr\n`;if(y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else{const N=E("handle",{name:K?Z.name:void 0});if(W.response||X.mapResponse.length){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),W.response)S+=x0();if(E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
191
+ if(mr !== undefined) c.response = mr\n`;if(y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else{const N=E("handle",{name:K?Z.name:void 0});if(W.response||X.mapResponse.length){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),W.response)S+=x0();if(E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
192
192
  mr = onMapResponse[${_}](c)
193
193
  if(mr instanceof Promise) mr = await mr
194
194
  if(mr !== undefined) r = c.response = mr
@@ -198,24 +198,24 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
198
198
  c.set.redirect ||
199
199
  c.set.cookie
200
200
  )
201
- return mapResponse(${R}.clone(), c.set, c.request)
201
+ return mapResponse(${R}.clone(), c.set)
202
202
  else
203
- return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else if(C.handle||v){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
203
+ return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else if(C.handle||v){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
204
204
  mr = onMapResponse[${_}](c)
205
205
  if(mr instanceof Promise) mr = await mr
206
206
  if(mr !== undefined) r = c.response = mr
207
- }\n`}if(S+=A,y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else{N();const _=G0?`await ${R}`:R;if(E("afterHandle")(),Z instanceof Response)S+=z.set?`if(
207
+ }\n`}if(S+=A,y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else{N();const _=G0?`await ${R}`:R;if(E("afterHandle")(),Z instanceof Response)S+=z.set?`if(
208
208
  isNotEmpty(c.set.headers) ||
209
209
  c.set.status !== 200 ||
210
210
  c.set.redirect ||
211
211
  c.set.cookie
212
212
  )
213
- return mapResponse(${R}.clone(), c.set, c.request)
213
+ return mapResponse(${R}.clone(), c.set)
214
214
  else
215
- return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+=`return mapResponse(${_}, c.set, c.request)\n`;else S+=`return mapCompactResponse(${_}, c.request)\n`}}if(U||F){if(S+="\n} catch(error) {",!w1)S+="return (async () => {";S+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const N=E("error",{unit:X.error.length});if(X.error.length){S+=`
215
+ return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+=`return mapResponse(${_}, c.set)\n`;else S+=`return mapCompactResponse(${_})\n`}}if(U||F){if(S+="\n} catch(error) {",!w1)S+="return (async () => {";S+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const N=E("error",{unit:X.error.length});if(X.error.length){S+=`
216
216
  c.error = error
217
217
  c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
218
- `;for(let _=0;_<X.error.length;_++){const j=`er${_}`,b=E("error.unit",{name:X.error[_].fn.name});if(S+=`\nlet ${j} = handleErrors[${_}](c)\n`,x(X.error[_]))S+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;b(),S+=`${j} = mapEarlyResponse(${j}, set, c.request)\n`,S+=`if (${j}) {`,S+=`return ${j} }\n`}}if(N(),S+="return handleError(c, error, true)\n\n",!w1)S+="})()";if(S+="}",F||P){S+=" finally { ";const _=E("response",{unit:X.onResponse.length});S+=F,_(),S+="}"}}return S=`const {
218
+ `;for(let _=0;_<X.error.length;_++){const j=`er${_}`,b=E("error.unit",{name:X.error[_].fn.name});if(S+=`\nlet ${j} = handleErrors[${_}](c)\n`,x(X.error[_]))S+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;b(),S+=`${j} = mapEarlyResponse(${j}, set)\n`,S+=`if (${j}) {`,S+=`return ${j} }\n`}}if(N(),S+="return handleError(c, error, true)\n\n",!w1)S+="})()";if(S+="}",F||P){S+=" finally { ";const _=E("response",{unit:X.onResponse.length});S+=F,_(),S+="}"}}return S=`const {
219
219
  handler,
220
220
  handleError,
221
221
  hooks: {
@@ -337,12 +337,13 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
337
337
  request
338
338
  )\n`,q(),B+="if(re !== undefined) return re\n";else B+=`${T?"await":""} onRequest[${z}](ctx)\n`,q()}B+=`} catch (error) {
339
339
  return app.handleError(ctx, error)
340
- }`,S(),B+=U,B+="\nctx.qi = qi\n ctx.path = path\n"}else B+=U,B+=`${Z?"const id = +requestId.value++":""}
340
+ }`,S(),B+=U,B+="\nctx.qi = qi\n ctx.path = path\nctx.url=url"}else B+=U,B+=`${Z?"const id = +requestId.value++":""}
341
341
  const ctx = {
342
342
  request,
343
343
  store,
344
344
  qi,
345
345
  path,
346
+ url,
346
347
  redirect,
347
348
  set: {
348
349
  headers: ${Object.keys(X??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
@@ -438,4 +439,4 @@ if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
438
439
 
439
440
  return st${$}(ctx)`;var $1=N0(M1(),1);var O1=($)=>async(J)=>{const w=J.url,B=w.indexOf("/",11),X=w.indexOf("?",B+1),W=X===-1?w.substring(B):w.substring(B,X),Z={cookie:{},status:200,headers:{}},Q=Object.assign({},$.singleton.decorator,{set:Z,store:$.singleton.store,request:J,path:W,qi:X});try{for(let z=0;z<$.event.request.length;z++){const M=$.event.request[z].fn;let D=M(Q);if(D instanceof Promise)D=await D;if(D=f(D,Z),D)return D}const Y=$.router.dynamic.find(J.method,W)??$.router.dynamic.find("ALL",W);if(!Y)throw new Q0;const{handle:G,hooks:K,validator:U,content:R}=Y.store;let F;if(J.method!=="GET"&&J.method!=="HEAD")if(R)switch(R){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const z=await J.formData();for(let M of z.keys()){if(F[M])continue;const D=z.getAll(M);if(D.length===1)F[M]=D[0];else F[M]=D}break}else{let z=J.headers.get("content-type");if(z){const M=z.indexOf(";");if(M!==-1)z=z.slice(0,M);Q.contentType=z;for(let D=0;D<K.parse.length;D++){const T=K.parse[D].fn;let q=T(Q,z);if(q instanceof Promise)q=await q;if(q){F=q;break}}if(delete Q.contentType,F===void 0)switch(z){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const D=await J.formData();for(let T of D.keys()){if(F[T])continue;const q=D.getAll(T);if(q.length===1)F[T]=q[0];else F[T]=q}break}}}Q.body=F,Q.params=Y?.params||void 0,Q.query=X===-1?{}:$1.parse(w.substring(X+1)),Q.headers={};for(let[z,M]of J.headers.entries())Q.headers[z]=M;const C=Object.assign({},$.config?.cookie,U?.cookie?.config),P=J.headers.get("cookie");Q.cookie=await p0(Q.set,P,C?{secrets:C.secrets!==void 0?typeof C.secrets==="string"?C.secrets:C.secrets.join(","):void 0,sign:C.sign===!0?!0:C.sign!==void 0?typeof C.sign==="string"?C.sign:C.sign.join(","):void 0}:void 0);for(let z=0;z<K.transform.length;z++){const M=K.transform[z],D=M.fn(Q);if(M.subType==="derive")if(D instanceof Promise)Object.assign(Q,await D);else Object.assign(Q,D);else if(D instanceof Promise)await D}if(U){if(U.headers){const z={};for(let M in J.headers)z[M]=J.headers.get(M);if(U.headers.Check(z)===!1)throw new I("header",U.headers,z)}if(U.params?.Check(Q.params)===!1)throw new I("params",U.params,Q.params);if(U.query?.Check(Q.query)===!1)throw new I("query",U.query,Q.query);if(U.cookie){const z={};for(let[M,D]of Object.entries(Q.cookie))z[M]=D.value;if(U.cookie?.Check(z)===!1)throw new I("cookie",U.cookie,z)}if(U.body?.Check(F)===!1)throw new I("body",U.body,F)}for(let z=0;z<K.beforeHandle.length;z++){let M=K.beforeHandle[z].fn(Q);if(M instanceof Promise)M=await M;if(M!==void 0){Q.response=M;for(let T=0;T<K.afterHandle.length;T++){let q=K.afterHandle[T].fn(Q);if(q instanceof Promise)q=await q;if(q)M=q}const D=f(M,Q.set);if(D)return D}}let S=G(Q);if(S instanceof Promise)S=await S;if(!K.afterHandle.length){const z=U?.response?.[S.status];if(z?.Check(S)===!1)throw new I("response",z,S)}else{Q.response=S;for(let z=0;z<K.afterHandle.length;z++){let M=K.afterHandle[z].fn(Q);if(M instanceof Promise)M=await M;const D=f(M,Q.set);if(D!==void 0){const T=U?.response?.[S.status];if(T?.Check(D)===!1)throw new I("response",T,D);return D}}}if(Q.set.cookie&&C?.sign){const z=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(Q.set.cookie))Q.set.cookie[M].value=await _0(D.value,"${secret}");else{const M=U?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(Q.set.cookie[D]?.value)Q.set.cookie[D].value=await _0(Q.set.cookie[D].value,z)}}}return h(S,Q.set)}catch(Y){if(Y.status)Z.status=Y.status;return $.handleError(Q,Y)}finally{for(let Y of $.event.onResponse)await Y.fn(Q)}},C$=($)=>async(J,w)=>{const B=Object.assign(J,{error:w,code:w.code});B.set=J.set;for(let X=0;X<$.event.error.length;X++){let Z=$.event.error[X].fn(B);if(Z instanceof Promise)Z=await Z;if(Z!==void 0&&Z!==null)return h(Z,J.set)}return new Response(typeof w.cause==="string"?w.cause:w.message,{headers:J.set.headers,status:w.status??500})};import{TypeRegistry as O$} from"@sinclair/typebox";import{TypeSystem as D0} from"@sinclair/typebox/system";import{Type as H0,FormatRegistry as o} from"@sinclair/typebox";import{Value as C0} from"@sinclair/typebox/value";var RJ=function($){return $%4===0&&($%100!==0||$%400===0)},A$=function($){const J=_J.exec($);if(!J)return!1;const w=+J[1],B=+J[2],X=+J[3];return B>=1&&B<=12&&X>=1&&X<=(B===2&&RJ(w)?29:jJ[B])},V1=function($){return function J(w){const B=FJ.exec(w);if(!B)return!1;const X=+B[1],W=+B[2],Z=+B[3],Q=B[4],Y=B[5]==="-"?-1:1,G=+(B[6]||0),K=+(B[7]||0);if(G>23||K>59||$&&!Q)return!1;if(X<=23&&W<=59&&Z<60)return!0;const U=W-K*Y,R=X-G*Y-(U<0?1:0);return(R===23||R===-1)&&(U===59||U===-1)&&Z<61}},D$=function($){const J=V1($);return function w(B){const X=B.split(CJ);return X.length===2&&A$(X[0])&&J(X[1])}},NJ=function($){return DJ.test($)&&MJ.test($)},AJ=function($){return M$.lastIndex=0,M$.test($)},VJ=function($){return Number.isInteger($)&&$<=OJ&&$>=PJ},qJ=function($){return Number.isInteger($)},N$=function(){return!0},bJ=function($){if(IJ.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},J1={date:A$,time:V1(!0),"date-time":D$(!0),"iso-time":V1(!1),"iso-date-time":D$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:NJ,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:bJ,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:AJ,int32:{type:"number",validate:VJ},int64:{type:"number",validate:qJ},float:{type:"number",validate:N$},double:{type:"number",validate:N$},password:!0,binary:!0},_J=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,jJ=[0,31,28,31,30,31,30,31,31,30,31,30,31],FJ=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,CJ=/t|\s/i,DJ=/\/|:/,MJ=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,M$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,PJ=-2147483648,OJ=2147483647,IJ=/[^\\]\\Z/;import{TypeSystemPolicy as rw,TypeSystem as nw,TypeSystemDuplicateFormat as ow,TypeSystemDuplicateTypeKind as aw} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as J8} from"@sinclair/typebox/compiler";var V$=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,q$=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,I$=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,TJ=J1.date,EJ=J1["date-time"];if(!o.Has("date"))D0.Format("date",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||TJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});if(!o.Has("date-time"))D0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||EJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});Object.entries(J1).forEach(($)=>{const[J,w]=$;if(!o.Has(J)){if(w instanceof RegExp)D0.Format(J,(B)=>w.test(B));else if(typeof w==="function")D0.Format(J,w)}});var V=Object.assign({},H0),P$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<P$($.minSize))return!1;if($.maxSize&&J.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!J.type.startsWith($.extension))return!1}else{for(let w=0;w<$.extension.length;w++)if(J.type.startsWith($.extension[w]))return!0;return!1}return!0},LJ=O$.Get("Files")??D0.Type("File",q1),HJ=O$.Get("Files")??D0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let w=0;w<J.length;w++)if(!q1($,J[w]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",($)=>!!$&&!isNaN(+$));if(!o.Has("boolean"))o.Set("boolean",($)=>$==="true"||$==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",($)=>{let J=$.charCodeAt(0);if(J===9||J===10||J===32)J=$.trimStart().charCodeAt(0);if(J!==123&&J!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const J=H0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((w)=>{const B=+w;if(isNaN(B))return w;if($&&!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>w)},Date:($)=>{const J=H0.Date($);return V.Transform(V.Union([H0.Date($),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((w)=>{if(w instanceof Date)return w;const B=new Date(w);if(!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>{if(typeof w==="string")return new Date(w);return w})},BooleanString:($)=>{const J=H0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((w)=>{if(typeof w==="string")return w==="true";if($&&!C0.Check(J,w))throw new I("property",J,w);return w}).Encode((w)=>w)},ObjectString:($={},J)=>{const w=V.Object($,J),B=JSON.stringify(C0.Create(w));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),w])).Decode((X)=>{if(typeof X==="string"){try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return X}return X}).Encode((X)=>{if(typeof X==="string")try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return JSON.stringify(X)})},File:LJ,Files:($={})=>V.Transform(HJ($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>V.Union([V.Null(),$]),MaybeEmpty:($)=>V.Union([V.Null(),V.Undefined(),$]),Cookie:($,{domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K,...U}={})=>{const R=V.Object($,U);return R.config={domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K},R}};V.BooleanString=a.BooleanString;V.ObjectString=a.ObjectString;V.Numeric=a.Numeric;V.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>a.Nullable($);V.MaybeEmpty=a.MaybeEmpty;V.Cookie=a.Cookie;V.Date=a.Date;class s{config;server=null;dependencies={};reporter=new x1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new B0,ws:new B0,dynamic:new B0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new _1;constructor($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const J=o1({globalHook:this.event,localHook:$}),w={events:{global:this.event,local:$},onParse:J("parse"),onTransform:J("transform"),onBeforeHandle:J("beforeHandle"),onAfterHandle:J("afterHandle"),onResponse:J("onResponse"),mapResponse:J("mapResponse"),onError:J("error")};for(let B of this.extender.macros)R1(B.fn(w),$)}}add($,J,w,B,{allowMeta:X=!1,skipPrefix:W=!1}={allowMeta:!1,skipPrefix:!1}){if(B=a1(B),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!W&&!this.config.scoped)J=this.config.prefix+J;if(B?.type)switch(B.type){case"text":B.type="text/plain";break;case"json":B.type="application/json";break;case"formdata":B.type="multipart/form-data";break;case"urlencoded":B.type="application/x-www-form-urlencoded";break;case"arrayBuffer":B.type="application/octet-stream";break;default:break}const Z=this.definitions.type;let Q,Y,G,K,U,R;const F=!this.config.aot,C={body:B?.body??this.validator?.body,headers:B?.headers??this.validator?.headers,params:B?.params??this.validator?.params,query:B?.query??this.validator?.query,cookie:B?.cookie??this.validator?.cookie,response:B?.response??this.validator?.response},P=()=>C.cookie?l0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:F,models:Z}):void 0,S=this.config.normalize,z=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:F,models:Z,normalize:S}),headers:k(C.headers,{dynamic:F,models:Z,additionalProperties:!0}),params:k(C.params,{dynamic:F,models:Z}),query:k(C.query,{dynamic:F,models:Z,normalize:S}),cookie:P(),response:s0(C.response,{dynamic:F,models:Z,normalize:S})}:{get body(){if(Q)return Q;return Q=k(C.body,{dynamic:F,models:Z,normalize:S})},get headers(){if(Y)return Y;return k(C.headers,{dynamic:F,models:Z,additionalProperties:!0})},get params(){if(G)return G;return G=k(C.params,{dynamic:F,models:Z})},get query(){if(K)return K;return K=k(C.query,{dynamic:F,models:Z})},get cookie(){if(U)return U;return U=P()},get response(){if(R)return R;return R=s0(C.response,{dynamic:F,models:Z,normalize:S})}},M=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(B=u(B,{},{allowMacro:!0}),B.tags)if(!B.detail)B.detail={tags:B.tags};else B.detail.tags=B.tags;if(m(this.config.detail))B.detail=p(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const D=u(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:z,hooks:D,content:B?.type,handle:w}),this.config.strictPath===!1)this.router.dynamic.add($,M,{validator:z,hooks:D,content:B?.type,handle:w});this.router.history.push({method:$,path:J,composed:null,handler:w,hooks:D});return}let T=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}):(A)=>{if(T)return T(A);return(T=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}))(A)};if(!q)v.compose=()=>{return v.composed=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e})};let t=this.router.history.length;if(this.routeTree.has($+J)){if(t=this.router.history.findIndex((A)=>A.path===J&&A.method===$),t!==-1){const A=this.router.history.splice(t,1)[0];if(A&&this.routeTree.has(A?.method+A?.path))this.routeTree.delete(A.method+A.path)}}this.routeTree.set($+J,t),this.router.history.push({method:$,path:J,composed:v,handler:w,hooks:D});const O=this.router.static.http;if($==="$INTERNALWS"){const A=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,A)this.router.static.ws[A]=$0}else if(this.router.ws.add("ws",J,v),A)this.router.ws.add("ws",A,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const A=O.handlers.length;if(O.handlers.push(v),O.variables+=q?`const st${A} = staticRouter.handlers[${A}]\n`:`let st${A} = staticRouter.handlers[${A}]\nlet stc${A}\n`,!O.map[J])O.map[J]={code:""};if($==="ALL")O.map[J].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[J].code=q?`case '${$}': return st${A}(ctx)\n${O.map[J].code}`:`case '${$}': ${L0(A)}\n${O.map[J].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if($==="ALL")O.map[M].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[M].code=q?`case '${$}': return st${A}(ctx)\n${O.map[M].code}`:`case '${$}': ${L0(A)}\n${O.map[M].code}`}}else if(this.router.http.add($,J,v),!this.config.strictPath)this.router.http.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,J){if(!J)return this.on("parse",$);return this.on($,"parse",J)}onTransform($,J){if(!J)return this.on("transform",$);return this.on($,"transform",J)}resolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}mapResolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}onBeforeHandle($,J){if(!J)return this.on("beforeHandle",$);return this.on($,"beforeHandle",J)}onAfterHandle($,J){if(!J)return this.on("afterHandle",$);return this.on($,"afterHandle",J)}mapResponse($,J){if(!J)return this.on("mapResponse",$);return this.on($,"mapResponse",J)}onResponse($,J){if(!J)return this.on("response",$);return this.on($,"response",J)}trace($,J){if(!J)J=$,$={as:"local"};if(!Array.isArray(J))J=[J];for(let w of J)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,w));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Z0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[w,B]of Object.entries($))B.prototype[Z0]=w,this.definitions.error[w]=B;return this}onError($,J){if(!J)return this.on("error",$);return this.on($,"error",J)}onStop($){return this.on("stop",$),this}on($,J,w){let B;switch(typeof $){case"string":B=$,w=J;break;case"object":B=J;break}if(B==="response")B="onResponse";if(Array.isArray(w))w=c(w);else if(typeof w==="function")w=[{fn:w}];else w=[w];const X=w;for(let W of X)W.scope=typeof $==="string"?"local":$?.as??"local";if(B==="trace")h1(X.map((W)=>W.fn),this.inference.trace);else m0({[B]:X.map((W)=>W.fn)},this.inference.event);for(let W of X){const Z=n1(W,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(Z);break;case"request":this.event.request.push(Z);break;case"parse":this.event.parse.push(Z);break;case"transform":this.event.transform.push(Z);break;case"beforeHandle":this.event.beforeHandle.push(Z);break;case"afterHandle":this.event.afterHandle.push(Z);break;case"mapResponse":this.event.mapResponse.push(Z);break;case"onResponse":this.event.onResponse.push(Z);break;case"trace":this.event.trace.push(Z);break;case"error":this.event.error.push(Z);break;case"stop":this.event.stop.push(Z);break}}return this}propagate(){const $=(J)=>{for(let w of J)if("scope"in w&&w.scope==="local")w.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,J,w){const B=new s({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=r0(this.inference);const X=typeof J==="object",W=(X?w:J)(B);if(this.singleton=p(this.singleton,B.singleton),this.definitions=p(this.definitions,B.definitions),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(B.router.history).forEach(({method:Z,path:Q,handler:Y,hooks:G})=>{if(Q=(X?"":this.config.prefix)+$+Q,X){const K=J,U=G;this.add(Z,Q,Y,u(K,{...U||{},error:!U.error?W.event.error:Array.isArray(U.error)?[...U.error||{},...W.event.error||{}]:[U.error,...W.event.error||{}]}))}else this.add(Z,Q,Y,u(G,{error:W.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=i0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const w=new s({...this.config,prefix:""});w.singleton={...this.singleton},w.definitions={...this.definitions},w.inference=r0(this.inference);const B=J(w);if(this.singleton=p(this.singleton,w.singleton),this.definitions=p(this.definitions,w.definitions),B.getServer=()=>this.server,B.event.request.length)this.event.request=[...this.event.request||[],...B.event.request||[]];if(B.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...B.event.onResponse||[]];return this.model(B.definitions.type),Object.values(w.router.history).forEach(({method:X,path:W,handler:Z,hooks:Q})=>{this.add(X,W,Z,u($,{...Q||{},error:!Q.error?B.event.error:Array.isArray(Q.error)?[...Q.error||{},...B.event.error||[]]:[Q.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(w)=>w.use($));if(Array.isArray($)){let w=this;for(let B of $)w=this.use(B);return w}if($ instanceof Promise)return this.promisedModules.add($.then((w)=>{if(typeof w==="function")return w(this);if(w instanceof s)return this._use(w);if(typeof w.default==="function")return w.default(this);if(w.default instanceof s)return this._use(w.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((w)=>w.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const X=$(this);if(X instanceof Promise)return this.promisedModules.add(X.then((W)=>{if(W instanceof s){this.compile();for(let{method:Z,path:Q,handler:Y,hooks:G}of Object.values(W.router.history))this.add(Z,Q,Y,u(G,{error:W.event.error}));return W}if(typeof W==="function")return W(this);if(typeof W.default==="function")return W.default(this);return this._use(W)}).then((W)=>W.compile())),this;return X}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((X)=>X.compile())),this;const{name:J,seed:w}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const B=$.config.scoped;if(B){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:Z})=>W===Z))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<$.extender.macros.length;W++){const Z=this.extender.macros[W];if(X.includes(Z.checksum))$.extender.macros.splice(W,1),W--;X.push(Z.checksum)}if($.onRequest((W)=>{Object.assign(W,this.singleton.decorator),Object.assign(W.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(B===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let W of $.event.trace)if(W.scope&&W.scope!=="local")this.trace(W);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(!this.dependencies[J].some(({checksum:Z})=>W===Z))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<this.extender.macros.length;W++){const Z=this.extender.macros[W];if(Z.checksum){if(X.includes(Z.checksum))this.extender.macros.splice(W,1),W--;X.push(Z.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:X,path:W,handler:Z,hooks:Q}of Object.values($.router.history))this.add(X,W,Z,u(Q,{error:$.event.error}));if(!B)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const X=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:W})=>X===W))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((W)=>W?.subType==="derive").map((W)=>({fn:W.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((W)=>W?.subType==="resolve").map((W)=>({fn:W.toString(),stack:new Error().stack??""}))}),this.event=i0(this.event,z1($.event),X)}else this.event=i0(this.event,z1($.event));return this}macro($){const J={checksum:q0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof s||typeof $==="function"||$.length===0||$==="/"){const X=typeof $==="function"?$:$ instanceof s?$.compile().fetch:J instanceof s?J.compile().fetch:J,W=async({request:Z,path:Q})=>X(new Request(U1(Z.url,Q||"/"),Z));return this.all("/*",W,{type:"none"}),this}const w=$.length;if(J instanceof s)J=J.compile().fetch;const B=async({request:X,path:W})=>J(new Request(U1(X.url,W.slice(w)||"/"),X));return this.all($,B,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get($,J,w){return this.add("GET",$,J,w),this}post($,J,w){return this.add("POST",$,J,w),this}put($,J,w){return this.add("PUT",$,J,w),this}patch($,J,w){return this.add("PATCH",$,J,w),this}delete($,J,w){return this.add("DELETE",$,J,w),this}options($,J,w){return this.add("OPTIONS",$,J,w),this}all($,J,w){return this.add("ALL",$,J,w),this}head($,J,w){return this.add("HEAD",$,J,w),this}connect($,J,w){return this.add("CONNECT",$,J,w),this}route($,J,w,B){return this.add($.toUpperCase(),J,w,B,B?.config),this}ws($,J){const w=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let B=null;const X=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),W=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Z=(Q)=>{if(typeof Q==="string"){const Y=Q?.charCodeAt(0);if(Y===47||Y===123)try{Q=JSON.parse(Q)}catch{}else if(z0(Q))Q=+Q}if(w?.length)for(let Y=0;Y<w.length;Y++){const G=w[Y](Q);if(G!==void 0)Q=G}return Q};return this.route("$INTERNALWS",$,(Q)=>{const{set:Y,path:G,qi:K,headers:U,query:R,params:F}=Q;if(B===null)B=this.getServer();if(B?.upgrade(Q.request,{headers:typeof J.upgrade==="function"?J.upgrade(Q):J.upgrade,data:{validator:W,open(C){J.open?.(new j0(C,Q))},message:(C,P)=>{const S=Z(P);if(X?.Check(S)===!1)return void C.send(new I("message",X,S).message);J.message?.(new j0(C,Q),S)},drain(C){J.drain?.(new j0(C,Q))},close(C,P,S){J.close?.(new j0(C,Q),P,S)}}}))return;return Y.status=400,"Expected a websocket connection"},{beforeHandle:J.beforeHandle,transform:J.transform,headers:J.headers,params:J.params,query:J.query}),this}state($,J){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=J;return this}decorate($,J){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=J;return this}derive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}model($,J){switch(typeof $){case"object":return Object.entries($).forEach(([w,B])=>{if(!(w in this.definitions.type))this.definitions.type[w]=B}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=J,this}mapDerive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}affix($,J,w){if(w==="")return this;const B=["_","-"," "],X=(Y)=>Y[0].toUpperCase()+Y.slice(1),W=$==="prefix"?(Y,G)=>B.includes(Y.at(-1)??"")?Y+G:Y+X(G):B.includes(w.at(-1)??"")?(Y,G)=>G+Y:(Y,G)=>G+X(Y),Z=(Y)=>{const G={};switch(Y){case"decorator":for(let K in this.singleton.decorator)G[W(w,K)]=this.singleton.decorator[K];this.singleton.decorator=G;break;case"state":for(let K in this.singleton.store)G[W(w,K)]=this.singleton.store[K];this.singleton.store=G;break;case"model":for(let K in this.definitions.type)G[W(w,K)]=this.definitions.type[K];this.definitions.type=G;break;case"error":for(let K in this.definitions.error)G[W(w,K)]=this.definitions.error[K];this.definitions.error=G;break}},Q=Array.isArray(J)?J:[J];for(let Y of Q.some((G)=>G==="all")?["decorator","state","model","error"]:Q)Z(Y);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?A1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?A1(this):O1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?P1(this):C$(this))($,J);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,J)=>{if(typeof Bun==="undefined")throw new 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");if(this.compile(),typeof $==="string"){if(!z0($))throw new Error("Port must be a numeric value");$=parseInt($)}const w=this.fetch,B=typeof $==="object"?{development:!I0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:w,error:this.outerErrorHandler}:{development:!I0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:$,fetch:w,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let X=0;X<this.event.start.length;X++)this.event.start[X].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let X=0;X<this.event.stop.length;X++)this.event.stop[X].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,j1 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,s0 as getResponseSchemaValidator,F1 as error,s as default,I as ValidationError,X0 as StatusMap,a0 as ParseError,Q0 as NotFoundError,t0 as InvertedStatusMap,P0 as InvalidCookieSignature,o0 as InternalServerError,s as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
440
441
 
441
- //# debugId=66E63B7DC12E370464756e2164756e21
442
+ //# debugId=499EBAD199D9697A64756e2164756e21