elysia 1.0.22 → 1.0.23

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
@@ -1,59 +1,59 @@
1
1
  // @bun
2
- var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames:gw}=Object;var yw=Object.prototype.hasOwnProperty;var N0=(w,$,J)=>{J=w!=null?Hw(xw(w)):{};const B=$||!w||!w.__esModule?q1(J,"default",{value:w,enumerable:!0}):J;for(let S of gw(w))if(!yw.call(B,S))q1(B,S,{get:()=>w[S],enumerable:!0});return B};var F0=(w,$)=>()=>($||w(($={exports:{}}).exports,$),$.exports);var L1=F0((u$,X1)=>{var P0=function(){},kw=function(w,$,J){this.fn=w,this.context=$,this.once=J||!1},E1=function(w,$,J,B,S){if(typeof J!=="function")throw new TypeError("The listener must be a function");var X=new kw(J,B||w,S),W=y?y+$:$;if(!w._events[W])w._events[W]=X,w._eventsCount++;else if(!w._events[W].fn)w._events[W].push(X);else w._events[W]=[w._events[W],X];return w},f0=function(w,$){if(--w._eventsCount===0)w._events=new P0;else delete w._events[$]},g=function(){this._events=new P0,this._eventsCount=0},vw=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(P0.prototype=Object.create(null),!new P0().__proto__)y=!1}g.prototype.eventNames=function w(){var $=[],J,B;if(this._eventsCount===0)return $;for(B in J=this._events)if(vw.call(J,B))$.push(y?B.slice(1):B);if(Object.getOwnPropertySymbols)return $.concat(Object.getOwnPropertySymbols(J));return $};g.prototype.listeners=function w($){var J=y?y+$:$,B=this._events[J];if(!B)return[];if(B.fn)return[B.fn];for(var S=0,X=B.length,W=new Array(X);S<X;S++)W[S]=B[S].fn;return W};g.prototype.listenerCount=function w($){var J=y?y+$:$,B=this._events[J];if(!B)return 0;if(B.fn)return 1;return B.length};g.prototype.emit=function w($,J,B,S,X,W){var Z=y?y+$:$;if(!this._events[Z])return!1;var R=this._events[Z],Y=arguments.length,G,F;if(R.fn){if(R.once)this.removeListener($,R.fn,void 0,!0);switch(Y){case 1:return R.fn.call(R.context),!0;case 2:return R.fn.call(R.context,J),!0;case 3:return R.fn.call(R.context,J,B),!0;case 4:return R.fn.call(R.context,J,B,S),!0;case 5:return R.fn.call(R.context,J,B,S,X),!0;case 6:return R.fn.call(R.context,J,B,S,X,W),!0}for(F=1,G=new Array(Y-1);F<Y;F++)G[F-1]=arguments[F];R.fn.apply(R.context,G)}else{var j=R.length,_;for(F=0;F<j;F++){if(R[F].once)this.removeListener($,R[F].fn,void 0,!0);switch(Y){case 1:R[F].fn.call(R[F].context);break;case 2:R[F].fn.call(R[F].context,J);break;case 3:R[F].fn.call(R[F].context,J,B);break;case 4:R[F].fn.call(R[F].context,J,B,S);break;default:if(!G)for(_=1,G=new Array(Y-1);_<Y;_++)G[_-1]=arguments[_];R[F].fn.apply(R[F].context,G)}}}return!0};g.prototype.on=function w($,J,B){return E1(this,$,J,B,!1)};g.prototype.once=function w($,J,B){return E1(this,$,J,B,!0)};g.prototype.removeListener=function w($,J,B,S){var X=y?y+$:$;if(!this._events[X])return this;if(!J)return f0(this,X),this;var W=this._events[X];if(W.fn){if(W.fn===J&&(!S||W.once)&&(!B||W.context===B))f0(this,X)}else{for(var Z=0,R=[],Y=W.length;Z<Y;Z++)if(W[Z].fn!==J||S&&!W[Z].once||B&&W[Z].context!==B)R.push(W[Z]);if(R.length)this._events[X]=R.length===1?R[0]:R;else f0(this,X)}return this};g.prototype.removeAllListeners=function w($){var J;if($){if(J=y?y+$:$,this._events[J])f0(this,J)}else this._events=new P0,this._eventsCount=0;return this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=y;g.EventEmitter=g;if(typeof X1!=="undefined")X1.exports=g});var s0=F0((c$,c1)=>{var ow=function(w){var $=w.indexOf("%");if($===-1)return w;var J=w.length,B="",S=0,X=0,W=$,Z=m1;while($>-1&&$<J){var R=d1(w[$+1],4),Y=d1(w[$+2],0),G=R|Y,F=Q1[G];if(Z=Q1[256+Z+F],X=X<<6|G&Q1[364+F],Z===m1)B+=w.slice(S,W),B+=X<=65535?String.fromCharCode(X):String.fromCharCode(55232+(X>>10),56320+(X&1023)),X=0,S=$+3,$=W=w.indexOf("%",S);else if(Z===aw)return null;else{if($+=3,$<J&&w.charCodeAt($)===37)continue;return null}}return B+w.slice(S)},d1=function(w,$){var J=ew[w];return J===void 0?255:J<<$},m1=12,aw=0,Q1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,10,9,9,9,11,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,24,36,48,60,72,84,96,0,12,12,12,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,24,24,24,0,0,0,0,0,0,0,0,0,24,24,0,0,0,0,0,0,0,0,0,0,48,48,48,0,0,0,0,0,0,0,0,0,0,48,48,0,0,0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,127,63,63,63,0,31,15,15,15,7,7,7],ew={"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};c1.exports=ow});var Ww=F0((KJ,Xw)=>{var R$=function(w){const $=new Sw;if(typeof w!=="string")return $;let J=w.length,B="",S="",X=-1,W=-1,Z=!1,R=!1,Y=!1,G=!1,F=!1,j=0;for(let _=0;_<J+1;_++)if(j=_!==J?w.charCodeAt(_):38,j===38){if(F=W>X,!F)W=_;if(B=w.slice(X+1,W),F||B.length>0){if(Y)B=B.replace(Bw," ");if(Z)B=Jw(B)||B;if(F){if(S=w.slice(W+1,_),G)S=S.replace(Bw," ");if(R)S=Jw(S)||S}const C=$[B];if(C===void 0)$[B]=S;else if(C.pop)C.push(S);else $[B]=[C,S]}S="",X=_,W=_,Z=!1,R=!1,Y=!1,G=!1}else if(j===61)if(W<=X)W=_;else R=!0;else if(j===43)if(W>X)G=!0;else Y=!0;else if(j===37)if(W>X)R=!0;else Z=!0;return $},Jw=s0(),Bw=/\+/g,Sw=function(){};Sw.prototype=Object.create(null);Xw.exports=R$});var Rw=F0((jJ,Zw)=>{var Y$=function(w){const $=w.length;if($===0)return"";let J="",B=0,S=0;w:for(;S<$;S++){let X=w.charCodeAt(S);while(X<128){if(Q$[X]!==1){if(B<S)J+=w.slice(B,S);B=S+1,J+=t[X]}if(++S===$)break w;X=w.charCodeAt(S)}if(B<S)J+=w.slice(B,S);if(X<2048){B=S+1,J+=t[192|X>>6]+t[128|X&63];continue}if(X<55296||X>=57344){B=S+1,J+=t[224|X>>12]+t[128|X>>6&63]+t[128|X&63];continue}if(++S,S>=$)throw new Error("URI malformed");const W=w.charCodeAt(S)&1023;B=S+1,X=65536+((X&1023)<<10|W),J+=t[240|X>>18]+t[128|X>>12&63]+t[128|X>>6&63]+t[128|X&63]}if(B===0)return w;if(B<$)return J+w.slice(B);return J},t=Array.from({length:256},(w,$)=>"%"+(($<16?"0":"")+$.toString(16)).toUpperCase()),Q$=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0]);Zw.exports={encodeString:Y$}});var Gw=F0((UJ,Yw)=>{var Qw=function(w){const $=typeof w;if($==="string")return D1(w);else if($==="bigint")return w.toString();else if($==="boolean")return w?"true":"false";else if($==="number"&&Number.isFinite(w))return w<1000000000000000000000?""+w:D1(""+w);return""},G$=function(w){let $="";if(w===null||typeof w!=="object")return $;const J="&",B=Object.keys(w),S=B.length;let X=0;for(let W=0;W<S;W++){const Z=B[W],R=w[Z],Y=D1(Z)+"=";if(W)$+=J;if(Array.isArray(R)){X=R.length;for(let G=0;G<X;G++){if(G)$+=J;$+=Y,$+=Qw(R[G])}}else $+=Y,$+=Qw(R)}return $},{encodeString:D1}=Rw();Yw.exports=G$});var M1=F0((zJ,T0)=>{var Fw=Ww(),Kw=Gw(),jw={parse:Fw,stringify:Kw};T0.exports=jw;T0.exports.default=jw;T0.exports.parse=Fw;T0.exports.stringify=Kw});var K0=(w,$)=>({part:w,store:null,inert:$!==void 0?new Map($.map((J)=>[J.part.charCodeAt(0),J])):null,params:null,wildcardStore:null}),I1=(w,$)=>({...w,part:$}),T1=(w)=>({paramName:w,store:null,inert:null});class B0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add(w,$,J){let B;if(typeof $!="string")throw TypeError("Route path must be a string");$===""?$="/":$[0]!=="/"&&($=`/${$}`),this.history.push([w,$,J]);let S=$[$.length-1]==="*";S&&($=$.slice(0,-1));let X=$.split(B0.regex.static),W=$.match(B0.regex.params)||[];X[X.length-1]===""&&X.pop(),B=this.root[w]?this.root[w]:this.root[w]=K0("/");let Z=0;for(let R=0;R<X.length;++R){let Y=X[R];if(R>0){let G=W[Z++].slice(1);if(B.params===null)B.params=T1(G);else if(B.params.paramName!==G)throw Error(`Cannot create route "${$}" with parameter "${G}" because a route already exists with a different parameter name ("${B.params.paramName}") in the same location`);let F=B.params;if(F.inert===null){B=F.inert=K0(Y);continue}B=F.inert}for(let G=0;;){if(G===Y.length){if(G<B.part.length){let F=I1(B,B.part.slice(G));Object.assign(B,K0(Y,[F]))}break}if(G===B.part.length){if(B.inert===null)B.inert=new Map;else if(B.inert.has(Y.charCodeAt(G))){B=B.inert.get(Y.charCodeAt(G)),Y=Y.slice(G),G=0;continue}let F=K0(Y.slice(G));B.inert.set(Y.charCodeAt(G),F),B=F;break}if(Y[G]!==B.part[G]){let F=I1(B,B.part.slice(G)),j=K0(Y.slice(G));Object.assign(B,K0(B.part.slice(0,G),[F,j])),B=j;break}++G}}if(Z<W.length){let R=W[Z],Y=R.slice(1);if(B.params===null)B.params=T1(Y);else if(B.params.paramName!==Y)throw Error(`Cannot create route "${$}" with parameter "${Y}" because a route already exists with a different parameter name ("${B.params.paramName}") in the same location`);return B.params.store===null&&(B.params.store=J),B.params.store}return S?(B.wildcardStore===null&&(B.wildcardStore=J),B.wildcardStore):(B.store===null&&(B.store=J),B.store)}find(w,$){let J=this.root[w];return J?S1($,$.length,J,0):null}}var S1=(w,$,J,B)=>{let S=J?.part,X=B+S.length;if(S.length>1){if(X>$)return null;if(S.length<15){for(let W=1,Z=B+1;W<S.length;++W,++Z)if(S.charCodeAt(W)!==w.charCodeAt(Z))return null}else if(w.substring(B,X)!==S)return null}if(X===$)return J.store!==null?{store:J.store,params:{}}:J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":""}}:null;if(J.inert!==null){let W=J.inert.get(w.charCodeAt(X));if(W!==void 0){let Z=S1(w,$,W,X);if(Z!==null)return Z}}if(J.params!==null){let W=J.params,Z=w.indexOf("/",X);if(Z!==X){if(Z===-1||Z>=$){if(W.store!==null){let R={};return R[W.paramName]=w.substring(X,$),{store:W.store,params:R}}}else if(W.inert!==null){let R=S1(w,$,W.inert,Z);if(R!==null)return R.params[W.paramName]=w.substring(X,Z),R}}}return J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":w.substring(X,$)}}:null};var H1=N0(L1(),1);var x1=H1.default;var h0=()=>{let w;return[new Promise((J)=>{w=J}),w]},$0=()=>{const[w,$]=h0(),[J,B]=h0(),S=[],X=[];return{signal:w,consume:(W)=>{switch(W.type){case"begin":if(W.unit&&S.length===0)for(let Z=0;Z<W.unit;Z++){const[R,Y]=h0(),[G,F]=h0();S.push(R),X.push([(j)=>{Y({children:[],end:G,name:j.name??"",skip:!1,time:j.time})},(j)=>{F(j)}])}$({children:S,end:J,name:W.name??"",skip:!1,time:W.time});break;case"end":B(W.time);break}},consumeChild(W){switch(W.type){case"begin":if(!X[0])return;const[Z]=X[0];Z({children:[],end:J,name:W.name??"",skip:!1,time:W.time});break;case"end":const R=X.shift();if(!R)return;R[1](W.time)}},resolve(){$({children:[],end:new Promise((W)=>W(0)),name:"",skip:!0,time:0});for(let[W,Z]of X)W({children:[],end:new Promise((R)=>R(0)),name:"",skip:!0,time:0}),Z(0);B(0)}}},g1=(w,$,J)=>{if(typeof J==="object")J=J.fn;return async function B(B){if(B.event!=="request"||B.type!=="begin")return;const S=B.id,X=w(),W=$0(),Z=$0(),R=$0(),Y=$0(),G=$0(),F=$0(),j=$0(),_=$0();W.consume(B);const C=(P)=>{if(P.id===S)switch(P.event){case"request":W.consume(P);break;case"request.unit":W.consumeChild(P);break;case"parse":Z.consume(P);break;case"parse.unit":Z.consumeChild(P);break;case"transform":R.consume(P);break;case"transform.unit":R.consumeChild(P);break;case"beforeHandle":Y.consume(P);break;case"beforeHandle.unit":Y.consumeChild(P);break;case"handle":G.consume(P);break;case"afterHandle":F.consume(P);break;case"afterHandle.unit":F.consumeChild(P);break;case"error":j.consume(P);break;case"error.unit":j.consumeChild(P);break;case"response":if(P.type==="begin")W.resolve(),Z.resolve(),R.resolve(),Y.resolve(),G.resolve(),F.resolve(),j.resolve();else X.off("event",C);_.consume(P);break;case"response.unit":_.consumeChild(P);break;case"exit":W.resolve(),Z.resolve(),R.resolve(),Y.resolve(),G.resolve(),F.resolve(),j.resolve();break}};X.on("event",C),await J({id:S,context:B.ctx,set:B.ctx?.set,store:B.ctx?.store,time:B.time,request:W.signal,parse:Z.signal,transform:R.signal,beforeHandle:Y.signal,handle:G.signal,afterHandle:F.signal,error:j.signal,response:_.signal}),X.emit(`res${S}.${$}`,void 0)}};var v1=(w)=>{if(w.startsWith("async"))w=w.slice(6);let $=-1;if(w.charCodeAt(0)===40){if($=w.indexOf(") => {\n"),$!==-1)return[w.slice(1,$),w.slice($+5),{isArrowReturn:!1}];if($=w.indexOf(") => "),$!==-1)return[w.slice(1,$),w.slice($+5),{isArrowReturn:!0}]}if(w.startsWith("function")){$=w.indexOf("(");const S=w.indexOf(")");return[w.slice($+1,S),w.slice(S+2),{isArrowReturn:!1}]}const J=w.indexOf("(");if(J!==-1){const[S,X]=w.split("\n",2),W=S.lastIndexOf(")")+1;return[S.slice(J,W),"{"+X,{isArrowReturn:!1}]}const B=w.split("\n",2);return[B[0],B[1],{isArrowReturn:!1}]},k1=(w)=>{const $=w.indexOf("{");if($===-1)return[-1,0];let J=$+1,B=1;for(;J<w.length;J++){const S=w.charCodeAt(J);if(S===123)B++;else if(S===125)B--;if(B===0)break}if(B!==0)return[0,w.length];return[$,J+1]},uw=(w)=>{const $=w.lastIndexOf("}");if($===-1)return[-1,0];let J=$-1,B=1;for(;J>=0;J--){const S=w.charCodeAt(J);if(S===125)B++;else if(S===123)B--;if(B===0)break}if(B!==0)return[-1,0];return[J,$+1]},m0=(w)=>{if(w.charCodeAt(0)===40)w=w.slice(1,-1);if(w.charCodeAt(0)===123)w=w.slice(2,-2);while(!0){const[$,J]=k1(w);if($===-1)break;w=w.slice(0,$-2)+w.slice(J+1)}return w.replace(/:/g,"").trim()},fw=(w,$)=>{const J=m0(w);if(!$.query&&J.includes("query"))$.query=!0;if(!$.headers&&J.includes("headers"))$.headers=!0;if(!$.body&&J.includes("body"))$.body=!0;if(!$.cookie&&J.includes("cookie"))$.cookie=!0;if(!$.set&&J.includes("set"))$.set=!0;return J},hw=(w,$)=>{const J=m0(w);if(!$.request&&J.includes("request"))$.request=!0;if(!$.parse&&J.includes("parse"))$.parse=!0;if(!$.transform&&J.includes("transform"))$.transform=!0;if(!$.handle&&J.includes("handle"))$.handle=!0;if(!$.beforeHandle&&J.includes("beforeHandle"))$.beforeHandle=!0;if(!$.afterHandle&&J.includes("afterHandle"))$.afterHandle=!0;if(!$.error&&J.includes("error"))$.error=!0;if(!$.context&&J.includes("context"))$.context=!0;if(!$.store&&J.includes("store"))$.store=!0;if(!$.set&&J.includes("set"))$.set=!0;return J},u1=(w,$,J)=>{const B=$.indexOf(w+"\n",J),S=$.indexOf(w+"\t",J),X=$.indexOf(w+",",J),W=$.indexOf(w+";",J),Z=$.indexOf(w+" ",J);return[B,S,X,W,Z].filter((R)=>R>0).sort((R,Y)=>R-Y)[0]||-1};var W1=(w,$,J=0)=>{if(J>5)return[];const B=[];let S=$;while(!0){let X=u1(" = "+w,S);if(X===-1){const R=S.indexOf(" = "+w);if(R+3+w.length!==S.length)break;X=R}const W=S.slice(0,X);let Z=W.slice(W.lastIndexOf(" ")+1);if(Z==="}"){const[R,Y]=uw(W);B.push(S.slice(R,Y)),S=S.slice(X+3+w.length);continue}while(Z.charCodeAt(0)===44)Z=Z.slice(1);while(Z.charCodeAt(0)===9)Z=Z.slice(1);B.push(Z),S=S.slice(X+3+w.length)}for(let X of B){if(X.charCodeAt(0)===123)continue;const W=W1(X,$);if(W.length>0)B.push(...W)}return B},f1=(w)=>{if(!w)return;if(!w.includes(",")){if(w.includes("..."))return w.slice(w.indexOf("...")+3);return w}const J=w.indexOf("...");if(J===-1)return;return w.slice(J+3).trimEnd()},y1=(w,$,J)=>{const B=(S,X)=>w.includes(X+"."+S)||w.includes(X+'["'+S+'"]')||w.includes(X+"['"+S+"']");for(let S of $){if(!S)continue;if(S.charCodeAt(0)===123){if(S=m0(S),!J.query&&S.includes("query"))J.query=!0;if(!J.headers&&S.includes("headers"))J.headers=!0;if(!J.body&&S.includes("body"))J.body=!0;if(!J.cookie&&S.includes("cookie"))J.cookie=!0;if(!J.set&&S.includes("set"))J.set=!0;continue}if(w.includes("("+S+")")){J.query=!0,J.headers=!0,J.body=!0,J.cookie=!0,J.set=!0,J.queries=[],J.unknownQueries=!0;break}if(!J.query&&B("query",S))J.query=!0;if(w.includes("return "+S)||w.includes("return "+S+".query"))J.query=!0,J.unknownQueries=!0,J.queries=[];if(!J.unknownQueries&&J.query){let X=S+".";if(w.includes(X+"query"))X=S+".query";while(!0){let W=w.indexOf(X);if(W===-1&&w.indexOf(S+"[")!==-1){J.queries=[],J.unknownQueries=!0;break}if(W!==-1){let Z=u1("",w,W+X.length+1);if(Z===-1)Z=void 0;const R=W+S.length+1;w=w.slice(W+S.length+1);let Y=w.slice(0,Z?Z-R:Z).trimEnd();while(W!==-1)if(W=Y.indexOf("."),W!==-1)Y=Y.slice(W+1);if(Y.charCodeAt(Y.length-1)===59)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===44)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===93)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===41)Y=Y.slice(0,-1);if(Y&&!J.queries.includes(Y)){J.queries.push(Y);continue}}break}}if(!J.headers&&B("headers",S))J.headers=!0;if(!J.body&&B("body",S))J.body=!0;if(!J.cookie&&B("cookie",S))J.cookie=!0;if(!J.set&&B("set",S))J.set=!0;if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}return $},mw=(w)=>{while(!0){const $=w.indexOf("=");if($===-1)break;const J=w.indexOf(",",$),B=w.indexOf("}",$),S=[J,B].filter((X)=>X>0).sort((X,W)=>X-W)[0]||-1;if(S===-1){w=w.slice(0,$);break}w=w.slice(0,$)+w.slice(S)}return w.split(",").map(($)=>$.trim()).join(", ")},dw=(w)=>{for(let $ of w){if($.charCodeAt(0)===123)return!1;if($.indexOf("'")!==-1)return!1;if($.indexOf('"')!==-1)return!1;if($.indexOf("\n")!==-1)return!1;if($.indexOf("\t")!==-1)return!1}return!0},cw=(w,$,J)=>{const B=(S,X)=>w.includes(S+"."+X)||w.includes(S+'["'+X+'"]')||w.includes(S+"['"+X+"']");for(let S of $){if(S.charCodeAt(0)===123){if(S=m0(S),!J.request&&S.includes("request"))J.request=!0;if(!J.parse&&S.includes("parse"))J.parse=!0;if(!J.transform&&S.includes("transform"))J.transform=!0;if(!J.handle&&S.includes("handle"))J.handle=!0;if(!J.beforeHandle&&S.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&S.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&S.includes("error"))J.error=!0;if(!J.context&&S.includes("context"))J.context=!0;if(!J.store&&S.includes("store"))J.store=!0;if(!J.set&&S.includes("set"))J.set=!0;continue}if(w.includes("("+S+")")){J.request=!0,J.parse=!0,J.transform=!0,J.handle=!0,J.beforeHandle=!0,J.afterHandle=!0,J.error=!0,J.context=!0,J.store=!0,J.set=!0;break}if(!J.request&&B("request",S))J.request=!0;if(!J.parse&&B("parse",S))J.parse=!0;if(!J.transform&&B("transform",S))J.transform=!0;if(!J.handle&&B("handle",S))J.handle=!0;if(!J.beforeHandle&&B("beforeHandle",S))J.beforeHandle=!0;if(!J.afterHandle&&B("afterHandle",S))J.afterHandle=!0;if(!J.error&&B("error",S))J.error=!0;if(!J.context&&B("context",S))J.context=!0;if(!J.store&&B("store",S))J.store=!0;if(!J.set&&B("set",S))J.set=!0;if(J.request&&J.parse&&J.transform&&J.handle&&J.beforeHandle&&J.afterHandle&&J.error&&J.context&&J.store&&J.set)break}return $},d0=(w,$={queries:[],query:!1,headers:!1,body:!1,cookie:!1,set:!1,unknownQueries:!1})=>{const J=[];if(w.handler&&typeof w.handler==="function")J.push(w.handler);if(w.beforeHandle?.length)J.push(...w.beforeHandle);if(w.parse?.length)J.push(...w.parse);if(w.error?.length)J.push(...w.error);if(w.transform?.length)J.push(...w.transform);if(w.afterHandle?.length)J.push(...w.afterHandle);if(w.mapResponse?.length)J.push(...w.mapResponse);if(w.request?.length)J.push(...w.request);if(w.onResponse?.length)J.push(...w.onResponse);for(let B of J){if(!B)continue;const S="fn"in B?B.fn:B,[X,W,{isArrowReturn:Z}]=v1(S.toString()),R=fw(X,$),Y=f1(R);if(Z&&(W==="query"||R&&W.startsWith(R+".query")))$.query=!0,$.unknownQueries=!0,$.queries=[];if(Y){const F=W1(Y,W);F.splice(0,-1,Y),y1(W,F,$)}const G=R||Y;if(G&&W.includes("return "+G+".query"))$.query=!0,$.unknownQueries=!0,$.queries=[];if($.query){y1(W,["query"],$);const F=X.indexOf("query: {");if(F!==-1){const j=X.slice(F+7),[_,C]=k1(j),P=mw(j.slice(_,C));for(let Q of P.slice(1,-1).split(",")){const K=Q.indexOf(":");if(K!==-1)Q=Q.slice(0,K);if(Q=Q.trim(),Q&&!$.queries.includes(Q))$.queries.push(Q.trim())}}}if($.query&&$.headers&&$.body&&$.cookie&&$.set)break}if(!dw($.queries))$.unknownQueries=!0,$.queries=[];return $},h1=(w,$={request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1})=>{for(let J of w){const[B,S]=v1(J.toString()),X=hw(B,$),W=f1(X);if(W){const Z=W1(W,S);Z.splice(0,-1,W),cw(S,Z,$);continue}if($.request&&$.parse&&$.transform&&$.handle&&$.beforeHandle&&$.afterHandle&&$.error&&$.context&&$.store&&$.set)break}return $};import{Value as a0} from"@sinclair/typebox/value";import{Kind as G1} from"@sinclair/typebox";import{Value as U0} from"@sinclair/typebox/value";import{TypeCompiler as n1} from"@sinclair/typebox/compiler";var pw=function(w,$){if(typeof w!=="string")throw new TypeError("argument str must be a string");var J={},B=$||{},S=B.decode||iw,X=0;while(X<w.length){var W=w.indexOf("=",X);if(W===-1)break;var Z=w.indexOf(";",X);if(Z===-1)Z=w.length;else if(Z<W){X=w.lastIndexOf(";",W-1)+1;continue}var R=w.slice(X,W).trim();if(J[R]===void 0){var Y=w.slice(W+1,Z).trim();if(Y.charCodeAt(0)===34)Y=Y.slice(1,-1);J[R]=nw(Y,S)}X=Z+1}return J},lw=function(w,$,J){var B=J||{},S=B.encode||tw;if(typeof S!=="function")throw new TypeError("option encode is invalid");if(!c0.test(w))throw new TypeError("argument name is invalid");var X=S($);if(X&&!c0.test(X))throw new TypeError("argument val is invalid");var W=w+"="+X;if(B.maxAge!=null){var Z=B.maxAge-0;if(isNaN(Z)||!isFinite(Z))throw new TypeError("option maxAge is invalid");W+="; Max-Age="+Math.floor(Z)}if(B.domain){if(!c0.test(B.domain))throw new TypeError("option domain is invalid");W+="; Domain="+B.domain}if(B.path){if(!c0.test(B.path))throw new TypeError("option path is invalid");W+="; Path="+B.path}if(B.expires){var R=B.expires;if(!rw(R)||isNaN(R.valueOf()))throw new TypeError("option expires is invalid");W+="; Expires="+R.toUTCString()}if(B.httpOnly)W+="; HttpOnly";if(B.secure)W+="; Secure";if(B.partitioned)W+="; Partitioned";if(B.priority){var Y=typeof B.priority==="string"?B.priority.toLowerCase():B.priority;switch(Y){case"low":W+="; Priority=Low";break;case"medium":W+="; Priority=Medium";break;case"high":W+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(B.sameSite){var G=typeof B.sameSite==="string"?B.sameSite.toLowerCase():B.sameSite;switch(G){case!0:W+="; SameSite=Strict";break;case"lax":W+="; SameSite=Lax";break;case"strict":W+="; SameSite=Strict";break;case"none":W+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return W},iw=function(w){return w.indexOf("%")!==-1?decodeURIComponent(w):w},tw=function(w){return encodeURIComponent(w)},rw=function(w){return sw.call(w)==="[object Date]"||w instanceof Date},nw=function(w,$){try{return $(w)}catch(J){return w}};/*!
2
+ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames:gw}=Object;var yw=Object.prototype.hasOwnProperty;var P0=(w,$,J)=>{J=w!=null?Hw(xw(w)):{};const B=$||!w||!w.__esModule?q1(J,"default",{value:w,enumerable:!0}):J;for(let R of gw(w))if(!yw.call(B,R))q1(B,R,{get:()=>w[R],enumerable:!0});return B};var F0=(w,$)=>()=>($||w(($={exports:{}}).exports,$),$.exports);var L1=F0((u$,S1)=>{var O0=function(){},vw=function(w,$,J){this.fn=w,this.context=$,this.once=J||!1},E1=function(w,$,J,B,R){if(typeof J!=="function")throw new TypeError("The listener must be a function");var S=new vw(J,B||w,R),X=y?y+$:$;if(!w._events[X])w._events[X]=S,w._eventsCount++;else if(!w._events[X].fn)w._events[X].push(S);else w._events[X]=[w._events[X],S];return w},f0=function(w,$){if(--w._eventsCount===0)w._events=new O0;else delete w._events[$]},g=function(){this._events=new O0,this._eventsCount=0},kw=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(O0.prototype=Object.create(null),!new O0().__proto__)y=!1}g.prototype.eventNames=function w(){var $=[],J,B;if(this._eventsCount===0)return $;for(B in J=this._events)if(kw.call(J,B))$.push(y?B.slice(1):B);if(Object.getOwnPropertySymbols)return $.concat(Object.getOwnPropertySymbols(J));return $};g.prototype.listeners=function w($){var J=y?y+$:$,B=this._events[J];if(!B)return[];if(B.fn)return[B.fn];for(var R=0,S=B.length,X=new Array(S);R<S;R++)X[R]=B[R].fn;return X};g.prototype.listenerCount=function w($){var J=y?y+$:$,B=this._events[J];if(!B)return 0;if(B.fn)return 1;return B.length};g.prototype.emit=function w($,J,B,R,S,X){var W=y?y+$:$;if(!this._events[W])return!1;var Z=this._events[W],Y=arguments.length,G,F;if(Z.fn){if(Z.once)this.removeListener($,Z.fn,void 0,!0);switch(Y){case 1:return Z.fn.call(Z.context),!0;case 2:return Z.fn.call(Z.context,J),!0;case 3:return Z.fn.call(Z.context,J,B),!0;case 4:return Z.fn.call(Z.context,J,B,R),!0;case 5:return Z.fn.call(Z.context,J,B,R,S),!0;case 6:return Z.fn.call(Z.context,J,B,R,S,X),!0}for(F=1,G=new Array(Y-1);F<Y;F++)G[F-1]=arguments[F];Z.fn.apply(Z.context,G)}else{var U=Z.length,_;for(F=0;F<U;F++){if(Z[F].once)this.removeListener($,Z[F].fn,void 0,!0);switch(Y){case 1:Z[F].fn.call(Z[F].context);break;case 2:Z[F].fn.call(Z[F].context,J);break;case 3:Z[F].fn.call(Z[F].context,J,B);break;case 4:Z[F].fn.call(Z[F].context,J,B,R);break;default:if(!G)for(_=1,G=new Array(Y-1);_<Y;_++)G[_-1]=arguments[_];Z[F].fn.apply(Z[F].context,G)}}}return!0};g.prototype.on=function w($,J,B){return E1(this,$,J,B,!1)};g.prototype.once=function w($,J,B){return E1(this,$,J,B,!0)};g.prototype.removeListener=function w($,J,B,R){var S=y?y+$:$;if(!this._events[S])return this;if(!J)return f0(this,S),this;var X=this._events[S];if(X.fn){if(X.fn===J&&(!R||X.once)&&(!B||X.context===B))f0(this,S)}else{for(var W=0,Z=[],Y=X.length;W<Y;W++)if(X[W].fn!==J||R&&!X[W].once||B&&X[W].context!==B)Z.push(X[W]);if(Z.length)this._events[S]=Z.length===1?Z[0]:Z;else f0(this,S)}return this};g.prototype.removeAllListeners=function w($){var J;if($){if(J=y?y+$:$,this._events[J])f0(this,J)}else this._events=new O0,this._eventsCount=0;return this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=y;g.EventEmitter=g;if(typeof S1!=="undefined")S1.exports=g});var s0=F0((c$,c1)=>{var aw=function(w){var $=w.indexOf("%");if($===-1)return w;var J=w.length,B="",R=0,S=0,X=$,W=m1;while($>-1&&$<J){var Z=d1(w[$+1],4),Y=d1(w[$+2],0),G=Z|Y,F=Q1[G];if(W=Q1[256+W+F],S=S<<6|G&Q1[364+F],W===m1)B+=w.slice(R,X),B+=S<=65535?String.fromCharCode(S):String.fromCharCode(55232+(S>>10),56320+(S&1023)),S=0,R=$+3,$=X=w.indexOf("%",R);else if(W===ow)return null;else{if($+=3,$<J&&w.charCodeAt($)===37)continue;return null}}return B+w.slice(R)},d1=function(w,$){var J=ew[w];return J===void 0?255:J<<$},m1=12,ow=0,Q1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,10,9,9,9,11,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,24,36,48,60,72,84,96,0,12,12,12,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,24,24,24,0,0,0,0,0,0,0,0,0,24,24,0,0,0,0,0,0,0,0,0,0,48,48,48,0,0,0,0,0,0,0,0,0,0,48,48,0,0,0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,127,63,63,63,0,31,15,15,15,7,7,7],ew={"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};c1.exports=aw});var Xw=F0((KJ,Sw)=>{var Z$=function(w){const $=new Rw;if(typeof w!=="string")return $;let J=w.length,B="",R="",S=-1,X=-1,W=!1,Z=!1,Y=!1,G=!1,F=!1,U=0;for(let _=0;_<J+1;_++)if(U=_!==J?w.charCodeAt(_):38,U===38){if(F=X>S,!F)X=_;if(B=w.slice(S+1,X),F||B.length>0){if(Y)B=B.replace(Bw," ");if(W)B=Jw(B)||B;if(F){if(R=w.slice(X+1,_),G)R=R.replace(Bw," ");if(Z)R=Jw(R)||R}const D=$[B];if(D===void 0)$[B]=R;else if(D.pop)D.push(R);else $[B]=[D,R]}R="",S=_,X=_,W=!1,Z=!1,Y=!1,G=!1}else if(U===61)if(X<=S)X=_;else Z=!0;else if(U===43)if(X>S)G=!0;else Y=!0;else if(U===37)if(X>S)Z=!0;else W=!0;return $},Jw=s0(),Bw=/\+/g,Rw=function(){};Rw.prototype=Object.create(null);Sw.exports=Z$});var Zw=F0((jJ,Ww)=>{var Y$=function(w){const $=w.length;if($===0)return"";let J="",B=0,R=0;w:for(;R<$;R++){let S=w.charCodeAt(R);while(S<128){if(Q$[S]!==1){if(B<R)J+=w.slice(B,R);B=R+1,J+=r[S]}if(++R===$)break w;S=w.charCodeAt(R)}if(B<R)J+=w.slice(B,R);if(S<2048){B=R+1,J+=r[192|S>>6]+r[128|S&63];continue}if(S<55296||S>=57344){B=R+1,J+=r[224|S>>12]+r[128|S>>6&63]+r[128|S&63];continue}if(++R,R>=$)throw new Error("URI malformed");const X=w.charCodeAt(R)&1023;B=R+1,S=65536+((S&1023)<<10|X),J+=r[240|S>>18]+r[128|S>>12&63]+r[128|S>>6&63]+r[128|S&63]}if(B===0)return w;if(B<$)return J+w.slice(B);return J},r=Array.from({length:256},(w,$)=>"%"+(($<16?"0":"")+$.toString(16)).toUpperCase()),Q$=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0]);Ww.exports={encodeString:Y$}});var Gw=F0((UJ,Yw)=>{var Qw=function(w){const $=typeof w;if($==="string")return D1(w);else if($==="bigint")return w.toString();else if($==="boolean")return w?"true":"false";else if($==="number"&&Number.isFinite(w))return w<1000000000000000000000?""+w:D1(""+w);return""},G$=function(w){let $="";if(w===null||typeof w!=="object")return $;const J="&",B=Object.keys(w),R=B.length;let S=0;for(let X=0;X<R;X++){const W=B[X],Z=w[W],Y=D1(W)+"=";if(X)$+=J;if(Array.isArray(Z)){S=Z.length;for(let G=0;G<S;G++){if(G)$+=J;$+=Y,$+=Qw(Z[G])}}else $+=Y,$+=Qw(Z)}return $},{encodeString:D1}=Zw();Yw.exports=G$});var M1=F0((zJ,E0)=>{var Fw=Xw(),Kw=Gw(),jw={parse:Fw,stringify:Kw};E0.exports=jw;E0.exports.default=jw;E0.exports.parse=Fw;E0.exports.stringify=Kw});var K0=(w,$)=>({part:w,store:null,inert:$!==void 0?new Map($.map((J)=>[J.part.charCodeAt(0),J])):null,params:null,wildcardStore:null}),I1=(w,$)=>({...w,part:$}),T1=(w)=>({paramName:w,store:null,inert:null});class B0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add(w,$,J){let B;if(typeof $!="string")throw TypeError("Route path must be a string");$===""?$="/":$[0]!=="/"&&($=`/${$}`),this.history.push([w,$,J]);let R=$[$.length-1]==="*";R&&($=$.slice(0,-1));let S=$.split(B0.regex.static),X=$.match(B0.regex.params)||[];S[S.length-1]===""&&S.pop(),B=this.root[w]?this.root[w]:this.root[w]=K0("/");let W=0;for(let Z=0;Z<S.length;++Z){let Y=S[Z];if(Z>0){let G=X[W++].slice(1);if(B.params===null)B.params=T1(G);else if(B.params.paramName!==G)throw Error(`Cannot create route "${$}" with parameter "${G}" because a route already exists with a different parameter name ("${B.params.paramName}") in the same location`);let F=B.params;if(F.inert===null){B=F.inert=K0(Y);continue}B=F.inert}for(let G=0;;){if(G===Y.length){if(G<B.part.length){let F=I1(B,B.part.slice(G));Object.assign(B,K0(Y,[F]))}break}if(G===B.part.length){if(B.inert===null)B.inert=new Map;else if(B.inert.has(Y.charCodeAt(G))){B=B.inert.get(Y.charCodeAt(G)),Y=Y.slice(G),G=0;continue}let F=K0(Y.slice(G));B.inert.set(Y.charCodeAt(G),F),B=F;break}if(Y[G]!==B.part[G]){let F=I1(B,B.part.slice(G)),U=K0(Y.slice(G));Object.assign(B,K0(B.part.slice(0,G),[F,U])),B=U;break}++G}}if(W<X.length){let Z=X[W],Y=Z.slice(1);if(B.params===null)B.params=T1(Y);else if(B.params.paramName!==Y)throw Error(`Cannot create route "${$}" with parameter "${Y}" because a route already exists with a different parameter name ("${B.params.paramName}") in the same location`);return B.params.store===null&&(B.params.store=J),B.params.store}return R?(B.wildcardStore===null&&(B.wildcardStore=J),B.wildcardStore):(B.store===null&&(B.store=J),B.store)}find(w,$){let J=this.root[w];return J?R1($,$.length,J,0):null}}var R1=(w,$,J,B)=>{let R=J?.part,S=B+R.length;if(R.length>1){if(S>$)return null;if(R.length<15){for(let X=1,W=B+1;X<R.length;++X,++W)if(R.charCodeAt(X)!==w.charCodeAt(W))return null}else if(w.substring(B,S)!==R)return null}if(S===$)return J.store!==null?{store:J.store,params:{}}:J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":""}}:null;if(J.inert!==null){let X=J.inert.get(w.charCodeAt(S));if(X!==void 0){let W=R1(w,$,X,S);if(W!==null)return W}}if(J.params!==null){let X=J.params,W=w.indexOf("/",S);if(W!==S){if(W===-1||W>=$){if(X.store!==null){let Z={};return Z[X.paramName]=w.substring(S,$),{store:X.store,params:Z}}}else if(X.inert!==null){let Z=R1(w,$,X.inert,W);if(Z!==null)return Z.params[X.paramName]=w.substring(S,W),Z}}}return J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":w.substring(S,$)}}:null};var H1=P0(L1(),1);var x1=H1.default;var h0=()=>{let w;return[new Promise((J)=>{w=J}),w]},$0=()=>{const[w,$]=h0(),[J,B]=h0(),R=[],S=[];return{signal:w,consume:(X)=>{switch(X.type){case"begin":if(X.unit&&R.length===0)for(let W=0;W<X.unit;W++){const[Z,Y]=h0(),[G,F]=h0();R.push(Z),S.push([(U)=>{Y({children:[],end:G,name:U.name??"",skip:!1,time:U.time})},(U)=>{F(U)}])}$({children:R,end:J,name:X.name??"",skip:!1,time:X.time});break;case"end":B(X.time);break}},consumeChild(X){switch(X.type){case"begin":if(!S[0])return;const[W]=S[0];W({children:[],end:J,name:X.name??"",skip:!1,time:X.time});break;case"end":const Z=S.shift();if(!Z)return;Z[1](X.time)}},resolve(){$({children:[],end:new Promise((X)=>X(0)),name:"",skip:!0,time:0});for(let[X,W]of S)X({children:[],end:new Promise((Z)=>Z(0)),name:"",skip:!0,time:0}),W(0);B(0)}}},g1=(w,$,J)=>{if(typeof J==="object")J=J.fn;return async function B(B){if(B.event!=="request"||B.type!=="begin")return;const R=B.id,S=w(),X=$0(),W=$0(),Z=$0(),Y=$0(),G=$0(),F=$0(),U=$0(),_=$0();X.consume(B);const D=(P)=>{if(P.id===R)switch(P.event){case"request":X.consume(P);break;case"request.unit":X.consumeChild(P);break;case"parse":W.consume(P);break;case"parse.unit":W.consumeChild(P);break;case"transform":Z.consume(P);break;case"transform.unit":Z.consumeChild(P);break;case"beforeHandle":Y.consume(P);break;case"beforeHandle.unit":Y.consumeChild(P);break;case"handle":G.consume(P);break;case"afterHandle":F.consume(P);break;case"afterHandle.unit":F.consumeChild(P);break;case"error":U.consume(P);break;case"error.unit":U.consumeChild(P);break;case"response":if(P.type==="begin")X.resolve(),W.resolve(),Z.resolve(),Y.resolve(),G.resolve(),F.resolve(),U.resolve();else S.off("event",D);_.consume(P);break;case"response.unit":_.consumeChild(P);break;case"exit":X.resolve(),W.resolve(),Z.resolve(),Y.resolve(),G.resolve(),F.resolve(),U.resolve();break}};S.on("event",D),await J({id:R,context:B.ctx,set:B.ctx?.set,store:B.ctx?.store,time:B.time,request:X.signal,parse:W.signal,transform:Z.signal,beforeHandle:Y.signal,handle:G.signal,afterHandle:F.signal,error:U.signal,response:_.signal}),S.emit(`res${R}.${$}`,void 0)}};var k1=(w)=>{if(w.startsWith("async"))w=w.slice(6);let $=-1;if(w.charCodeAt(0)===40){if($=w.indexOf(") => {\n"),$!==-1)return[w.slice(1,$),w.slice($+5),{isArrowReturn:!1}];if($=w.indexOf(") => "),$!==-1)return[w.slice(1,$),w.slice($+5),{isArrowReturn:!0}]}if(w.startsWith("function")){$=w.indexOf("(");const R=w.indexOf(")");return[w.slice($+1,R),w.slice(R+2),{isArrowReturn:!1}]}const J=w.indexOf("(");if(J!==-1){const R=w.indexOf("\n",2),S=w.slice(0,R),X=S.lastIndexOf(")")+1,W=w.slice(R+1);return[S.slice(J,X),"{"+W,{isArrowReturn:!1}]}const B=w.split("\n",2);return[B[0],B[1],{isArrowReturn:!1}]},v1=(w)=>{const $=w.indexOf("{");if($===-1)return[-1,0];let J=$+1,B=1;for(;J<w.length;J++){const R=w.charCodeAt(J);if(R===123)B++;else if(R===125)B--;if(B===0)break}if(B!==0)return[0,w.length];return[$,J+1]},uw=(w)=>{const $=w.lastIndexOf("}");if($===-1)return[-1,0];let J=$-1,B=1;for(;J>=0;J--){const R=w.charCodeAt(J);if(R===125)B++;else if(R===123)B--;if(B===0)break}if(B!==0)return[-1,0];return[J,$+1]},m0=(w)=>{if(w.charCodeAt(0)===40)w=w.slice(1,-1);if(w.charCodeAt(0)===123)w=w.slice(2,-2);while(!0){const[$,J]=v1(w);if($===-1)break;w=w.slice(0,$-2)+w.slice(J+1)}return w.replace(/:/g,"").trim()},fw=(w,$)=>{const J=m0(w);if(!$.query&&J.includes("query"))$.query=!0;if(!$.headers&&J.includes("headers"))$.headers=!0;if(!$.body&&J.includes("body"))$.body=!0;if(!$.cookie&&J.includes("cookie"))$.cookie=!0;if(!$.set&&J.includes("set"))$.set=!0;return J},hw=(w,$)=>{const J=m0(w);if(!$.request&&J.includes("request"))$.request=!0;if(!$.parse&&J.includes("parse"))$.parse=!0;if(!$.transform&&J.includes("transform"))$.transform=!0;if(!$.handle&&J.includes("handle"))$.handle=!0;if(!$.beforeHandle&&J.includes("beforeHandle"))$.beforeHandle=!0;if(!$.afterHandle&&J.includes("afterHandle"))$.afterHandle=!0;if(!$.error&&J.includes("error"))$.error=!0;if(!$.context&&J.includes("context"))$.context=!0;if(!$.store&&J.includes("store"))$.store=!0;if(!$.set&&J.includes("set"))$.set=!0;return J},u1=(w,$,J)=>{const B=$.indexOf(w+"\n",J),R=$.indexOf(w+"\t",J),S=$.indexOf(w+",",J),X=$.indexOf(w+";",J),W=$.indexOf(w+" ",J);return[B,R,S,X,W].filter((Z)=>Z>0).sort((Z,Y)=>Z-Y)[0]||-1};var X1=(w,$,J=0)=>{if(J>5)return[];const B=[];let R=$;while(!0){let S=u1(" = "+w,R);if(S===-1){const Z=R.indexOf(" = "+w);if(Z+3+w.length!==R.length)break;S=Z}const X=R.slice(0,S);let W=X.slice(X.lastIndexOf(" ")+1);if(W==="}"){const[Z,Y]=uw(X);B.push(R.slice(Z,Y)),R=R.slice(S+3+w.length);continue}while(W.charCodeAt(0)===44)W=W.slice(1);while(W.charCodeAt(0)===9)W=W.slice(1);B.push(W),R=R.slice(S+3+w.length)}for(let S of B){if(S.charCodeAt(0)===123)continue;const X=X1(S,$);if(X.length>0)B.push(...X)}return B},f1=(w)=>{if(!w)return;if(!w.includes(",")){if(w.includes("..."))return w.slice(w.indexOf("...")+3);return w}const J=w.indexOf("...");if(J===-1)return;return w.slice(J+3).trimEnd()},y1=(w,$,J)=>{const B=(R,S)=>w.includes(S+"."+R)||w.includes(S+'["'+R+'"]')||w.includes(S+"['"+R+"']");for(let R of $){if(!R)continue;if(R.charCodeAt(0)===123){if(R=m0(R),!J.query&&R.includes("query"))J.query=!0;if(!J.headers&&R.includes("headers"))J.headers=!0;if(!J.body&&R.includes("body"))J.body=!0;if(!J.cookie&&R.includes("cookie"))J.cookie=!0;if(!J.set&&R.includes("set"))J.set=!0;continue}if(w.includes("("+R+")")){J.query=!0,J.headers=!0,J.body=!0,J.cookie=!0,J.set=!0,J.queries=[],J.unknownQueries=!0;break}if(!J.query&&B("query",R))J.query=!0;if(w.includes("return "+R)||w.includes("return "+R+".query"))J.query=!0,J.unknownQueries=!0,J.queries=[];if(!J.unknownQueries&&J.query){let S=R+".";if(w.includes(S+"query"))S=R+".query";while(!0){let X=w.indexOf(S);if(X===-1&&w.indexOf(R+"[")!==-1){J.queries=[],J.unknownQueries=!0;break}if(X!==-1){let W=u1("",w,X+S.length+1);if(W===-1)W=void 0;const Z=X+R.length+1;w=w.slice(X+R.length+1);let Y=w.slice(0,W?W-Z:W).trimEnd();while(X!==-1)if(X=Y.indexOf("."),X!==-1)Y=Y.slice(X+1);if(Y.charCodeAt(Y.length-1)===59)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===44)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===93)Y=Y.slice(0,-1);if(Y.charCodeAt(Y.length-1)===41)Y=Y.slice(0,-1);if(Y&&!J.queries.includes(Y)){J.queries.push(Y);continue}}break}}if(!J.headers&&B("headers",R))J.headers=!0;if(!J.body&&B("body",R))J.body=!0;if(!J.cookie&&B("cookie",R))J.cookie=!0;if(!J.set&&B("set",R))J.set=!0;if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}return $},mw=(w)=>{while(!0){const $=w.indexOf("=");if($===-1)break;const J=w.indexOf(",",$),B=w.indexOf("}",$),R=[J,B].filter((S)=>S>0).sort((S,X)=>S-X)[0]||-1;if(R===-1){w=w.slice(0,$);break}w=w.slice(0,$)+w.slice(R)}return w.split(",").map(($)=>$.trim()).join(", ")},dw=(w)=>{for(let $ of w){if($.charCodeAt(0)===123)return!1;if($.indexOf("'")!==-1)return!1;if($.indexOf('"')!==-1)return!1;if($.indexOf("\n")!==-1)return!1;if($.indexOf("\t")!==-1)return!1;if($.indexOf("(")!==-1)return!1}return!0},cw=(w,$,J)=>{const B=(R,S)=>w.includes(R+"."+S)||w.includes(R+'["'+S+'"]')||w.includes(R+"['"+S+"']");for(let R of $){if(R.charCodeAt(0)===123){if(R=m0(R),!J.request&&R.includes("request"))J.request=!0;if(!J.parse&&R.includes("parse"))J.parse=!0;if(!J.transform&&R.includes("transform"))J.transform=!0;if(!J.handle&&R.includes("handle"))J.handle=!0;if(!J.beforeHandle&&R.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&R.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&R.includes("error"))J.error=!0;if(!J.context&&R.includes("context"))J.context=!0;if(!J.store&&R.includes("store"))J.store=!0;if(!J.set&&R.includes("set"))J.set=!0;continue}if(w.includes("("+R+")")){J.request=!0,J.parse=!0,J.transform=!0,J.handle=!0,J.beforeHandle=!0,J.afterHandle=!0,J.error=!0,J.context=!0,J.store=!0,J.set=!0;break}if(!J.request&&B("request",R))J.request=!0;if(!J.parse&&B("parse",R))J.parse=!0;if(!J.transform&&B("transform",R))J.transform=!0;if(!J.handle&&B("handle",R))J.handle=!0;if(!J.beforeHandle&&B("beforeHandle",R))J.beforeHandle=!0;if(!J.afterHandle&&B("afterHandle",R))J.afterHandle=!0;if(!J.error&&B("error",R))J.error=!0;if(!J.context&&B("context",R))J.context=!0;if(!J.store&&B("store",R))J.store=!0;if(!J.set&&B("set",R))J.set=!0;if(J.request&&J.parse&&J.transform&&J.handle&&J.beforeHandle&&J.afterHandle&&J.error&&J.context&&J.store&&J.set)break}return $},d0=(w,$={queries:[],query:!1,headers:!1,body:!1,cookie:!1,set:!1,unknownQueries:!1})=>{const J=[];if(w.handler&&typeof w.handler==="function")J.push(w.handler);if(w.beforeHandle?.length)J.push(...w.beforeHandle);if(w.parse?.length)J.push(...w.parse);if(w.error?.length)J.push(...w.error);if(w.transform?.length)J.push(...w.transform);if(w.afterHandle?.length)J.push(...w.afterHandle);if(w.mapResponse?.length)J.push(...w.mapResponse);if(w.request?.length)J.push(...w.request);if(w.onResponse?.length)J.push(...w.onResponse);for(let B of J){if(!B)continue;const R="fn"in B?B.fn:B,[S,X,{isArrowReturn:W}]=k1(R.toString()),Z=fw(S,$),Y=f1(Z);if(W&&(X==="query"||Z&&X.startsWith(Z+".query")))$.query=!0,$.unknownQueries=!0,$.queries=[];if(Y){const F=X1(Y,X);F.splice(0,-1,Y),y1(X,F,$)}const G=Z||Y;if(G&&X.includes("return "+G+".query"))$.query=!0,$.unknownQueries=!0,$.queries=[];if($.query){y1(X,["query"],$);const F=S.indexOf("query: {");if(F!==-1){const U=S.slice(F+7),[_,D]=v1(U),P=mw(U.slice(_,D));for(let Q of P.slice(1,-1).split(",")){const j=Q.indexOf(":");if(j!==-1)Q=Q.slice(0,j);if(Q=Q.trim(),Q&&!$.queries.includes(Q))$.queries.push(Q.trim())}}}if($.query&&$.headers&&$.body&&$.cookie&&$.set)break}if(!dw($.queries))$.unknownQueries=!0,$.queries=[];return $},h1=(w,$={request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1})=>{for(let J of w){const[B,R]=k1(J.toString()),S=hw(B,$),X=f1(S);if(X){const W=X1(X,R);W.splice(0,-1,X),cw(R,W,$);continue}if($.request&&$.parse&&$.transform&&$.handle&&$.beforeHandle&&$.afterHandle&&$.error&&$.context&&$.store&&$.set)break}return $};import{Value as o0} from"@sinclair/typebox/value";import{Kind as G1} from"@sinclair/typebox";import{Value as U0} from"@sinclair/typebox/value";import{TypeCompiler as n1} from"@sinclair/typebox/compiler";var pw=function(w,$){if(typeof w!=="string")throw new TypeError("argument str must be a string");var J={},B=$||{},R=B.decode||iw,S=0;while(S<w.length){var X=w.indexOf("=",S);if(X===-1)break;var W=w.indexOf(";",S);if(W===-1)W=w.length;else if(W<X){S=w.lastIndexOf(";",X-1)+1;continue}var Z=w.slice(S,X).trim();if(J[Z]===void 0){var Y=w.slice(X+1,W).trim();if(Y.charCodeAt(0)===34)Y=Y.slice(1,-1);J[Z]=nw(Y,R)}S=W+1}return J},lw=function(w,$,J){var B=J||{},R=B.encode||tw;if(typeof R!=="function")throw new TypeError("option encode is invalid");if(!c0.test(w))throw new TypeError("argument name is invalid");var S=R($);if(S&&!c0.test(S))throw new TypeError("argument val is invalid");var X=w+"="+S;if(B.maxAge!=null){var W=B.maxAge-0;if(isNaN(W)||!isFinite(W))throw new TypeError("option maxAge is invalid");X+="; Max-Age="+Math.floor(W)}if(B.domain){if(!c0.test(B.domain))throw new TypeError("option domain is invalid");X+="; Domain="+B.domain}if(B.path){if(!c0.test(B.path))throw new TypeError("option path is invalid");X+="; Path="+B.path}if(B.expires){var Z=B.expires;if(!rw(Z)||isNaN(Z.valueOf()))throw new TypeError("option expires is invalid");X+="; Expires="+Z.toUTCString()}if(B.httpOnly)X+="; HttpOnly";if(B.secure)X+="; Secure";if(B.partitioned)X+="; Partitioned";if(B.priority){var Y=typeof B.priority==="string"?B.priority.toLowerCase():B.priority;switch(Y){case"low":X+="; Priority=Low";break;case"medium":X+="; Priority=Medium";break;case"high":X+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(B.sameSite){var G=typeof B.sameSite==="string"?B.sameSite.toLowerCase():B.sameSite;switch(G){case!0:X+="; SameSite=Strict";break;case"lax":X+="; SameSite=Lax";break;case"strict":X+="; SameSite=Strict";break;case"none":X+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return X},iw=function(w){return w.indexOf("%")!==-1?decodeURIComponent(w):w},tw=function(w){return encodeURIComponent(w)},rw=function(w){return sw.call(w)==="[object Date]"||w instanceof Date},nw=function(w,$){try{return $(w)}catch(J){return w}};/*!
3
3
  * cookie
4
4
  * Copyright(c) 2012-2014 Roman Shtylman
5
5
  * Copyright(c) 2015 Douglas Christopher Wilson
6
6
  * MIT Licensed
7
- */var Z1=pw,R1=lw;var sw=Object.prototype.toString,c0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var p1=N0(s0(),1);class r{w;$;J;constructor(w,$,J={}){this.name=w;this.jar=$;this.initial=J}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie(w){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=w}get value(){return this.cookie.value}set value(w){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=w}get expires(){return this.cookie.expires}set expires(w){this.cookie.expires=w}get maxAge(){return this.cookie.maxAge}set maxAge(w){this.cookie.maxAge=w}get domain(){return this.cookie.domain}set domain(w){this.cookie.domain=w}get path(){return this.cookie.path}set path(w){this.cookie.path=w}get secure(){return this.cookie.secure}set secure(w){this.cookie.secure=w}get httpOnly(){return this.cookie.httpOnly}set httpOnly(w){this.cookie.httpOnly=w}get sameSite(){return this.cookie.sameSite}set sameSite(w){this.cookie.sameSite=w}get priority(){return this.cookie.priority}set priority(w){this.cookie.priority=w}get partitioned(){return this.cookie.partitioned}set partitioned(w){this.cookie.partitioned=w}get secrets(){return this.cookie.secrets}set secrets(w){this.cookie.secrets=w}update(w){return this.cookie=Object.assign(this.cookie,typeof w==="function"?w(this.cookie):w),this}set(w){return this.cookie=Object.assign({...this.initial,value:this.value},typeof w==="function"?w(this.cookie):w),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 s1=(w,$,J)=>{if(!w.cookie)w.cookie={};return new Proxy($,{get(B,S){if(S in $)return new r(S,w.cookie,Object.assign({},J??{},$[S]));return new r(S,w.cookie,Object.assign({},J))}})},p0=async(w,$,{secrets:J,sign:B,...S}={})=>{if(!$)return s1(w,{},S);const X=typeof J==="string";if(B&&B!==!0&&!Array.isArray(B))B=[B];const W={},Z=Z1($);for(let[R,Y]of Object.entries(Z)){let G=p1.default(Y);if(B===!0||B?.includes(R)){if(!J)throw new Error("No secret is provided to cookie plugin");if(X){const j=await Y1(G,J);if(j===!1)throw new O0(R);G=j}else{let j=!0;for(let _=0;_<J.length;_++){const C=await Y1(G,J[_]);if(C!==!1){j=!0,G=C;break}}if(!j)throw new O0(R)}}const F=G.charCodeAt(0);if(F===123||F===91)try{W[R]={value:JSON.parse(G)};continue}catch{}if(j0(G)){W[R]={value:parseInt(G)};continue}if(G==="true"){W[R]={value:!0};continue}if(G==="false"){W[R]={value:!1};continue}W[R]={value:G}}return s1(w,W,S)};var l1="toJSON"in new Headers,m=(w)=>{if(!w)return!1;for(let $ in w)return!0;return!1},V0=(w,$)=>{const J=w.size;if(!$&&J||J&&$&&$.status!==206&&$.status!==304&&$.status!==412&&$.status!==416){if($){if($.headers instanceof Headers){if(l1)$.headers=$.headers.toJSON();else for(let[B,S]of $.headers.entries())if(B in $.headers)$.headers[B]=S}return new Response(w,{status:$.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`},$.headers)})}return new Response(w,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`}})}return new Response(w)},i1=(w,$)=>{if(!w)return w;w.delete("Set-Cookie");for(let J=0;J<$.length;J++){const B=$[J].indexOf("=");w.append("Set-Cookie",`${$[J].slice(0,B)}=${$[J].slice(B+1)||""}`)}return w},t1=(w)=>{if(!w||!m(w))return;const $=[];for(let[J,B]of Object.entries(w)){if(!J||!B)continue;const S=B.value;if(S===void 0||S===null)continue;$.push(R1(J,typeof S==="object"?JSON.stringify(S):S+"",B))}if($.length===0)return;if($.length===1)return $[0];return $},h=(w,$,J)=>{if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])$.status=w[d],w=w.response;if(m($.headers)||$.status!==200||$.redirect||$.cookie){if(typeof $.status==="string")$.status=X0[$.status];if($.redirect){if($.headers.Location=$.redirect,!$.status||$.status<300||$.status>=400)$.status=302}if($.cookie&&m($.cookie))$.headers["Set-Cookie"]=t1($.cookie);if($.headers["Set-Cookie"]&&Array.isArray($.headers["Set-Cookie"]))$.headers=i1(new Headers($.headers),$.headers["Set-Cookie"]);switch(w?.constructor?.name){case"String":return new Response(w,$);case"Blob":return V0(w,$);case"Array":return Response.json(w,$);case"Object":for(let S in Object.values(w))switch(S?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(S0(w));default:break}return Response.json(w,$);case"ReadableStream":if(!$.headers["content-type"]?.startsWith("text/event-stream"))$.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,$);case void 0:if(!w)return new Response("",$);return Response.json(w,$);case"Response":let B=!1;if($.headers instanceof Headers)for(let S of $.headers.keys())if(S==="set-cookie"){if(B)continue;B=!0;for(let X of $.headers.getSetCookie())w.headers.append("set-cookie",X)}else w.headers.append(S,$.headers?.get(S)??"");else for(let S in $.headers)w.headers.append(S,$.headers[S]);if(w.status!==$.status)$.status=w.status;return w;case"Error":return i(w,$);case"Promise":return w.then((S)=>h(S,$));case"Function":return h(w(),$);case"Number":case"Boolean":return new Response(w.toString(),$);case"Cookie":if(w instanceof r)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w,$);default:if(w instanceof Response){let S=!1;if($.headers instanceof Headers)for(let X of $.headers.keys())if(X==="set-cookie"){if(S)continue;S=!0;for(let W of $.headers.getSetCookie())w.headers.append("set-cookie",W)}else w.headers.append(X,$.headers?.get(X)??"");else for(let X in $.headers)w.headers.append(X,$.headers[X]);if(l1)$.headers=w.headers.toJSON();else for(let[X,W]of w.headers.entries())if(X in $.headers)$.headers[X]=W;return w}if(w instanceof Promise)return w.then((S)=>h(S,$));if(w instanceof Error)return i(w,$);if("charCodeAt"in w){const S=w.charCodeAt(0);if(S===123||S===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w,$)}}else switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w,$);case"Array":return Response.json(w);case"Object":for(let B in Object.values(w))switch(B?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(S0(w),$);default:break}return Response.json(w,$);case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Error":return i(w,$);case"Promise":return w.then((B)=>{const S=n(B);if(S!==void 0)return S;return new Response("")});case"Function":return n(w());case"Number":case"Boolean":return new Response(w.toString());case"Cookie":if(w instanceof r)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w,$);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then((B)=>h(B,$));if(w instanceof Error)return i(w,$);if("charCodeAt"in w){const B=w.charCodeAt(0);if(B===123||B===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w)}},f=(w,$,J)=>{if(w===void 0||w===null)return;if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])$.status=w[d],w=w.response;if(m($.headers)||$.status!==200||$.redirect||$.cookie){if(typeof $.status==="string")$.status=X0[$.status];if($.redirect){if($.headers.Location=$.redirect,!$.status||$.status<300||$.status>=400)$.status=302}if($.cookie&&m($.cookie))$.headers["Set-Cookie"]=t1($.cookie);if($.headers["Set-Cookie"]&&Array.isArray($.headers["Set-Cookie"]))$.headers=i1(new Headers($.headers),$.headers["Set-Cookie"]);switch(w?.constructor?.name){case"String":return new Response(w,$);case"Blob":return V0(w,$);case"Array":return Response.json(w,$);case"Object":for(let S in Object.values(w))switch(S?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(S0(w),$);default:break}return Response.json(w,$);case"ReadableStream":if(!$.headers["content-type"]?.startsWith("text/event-stream"))$.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,$);case void 0:if(!w)return;return Response.json(w,$);case"Response":let B=!1;if($.headers instanceof Headers)for(let S of $.headers.keys())if(S==="set-cookie"){if(B)continue;B=!0;for(let X of $.headers.getSetCookie())w.headers.append("set-cookie",X)}else w.headers.append(S,$.headers?.get(S)??"");else for(let S in $.headers)w.headers.append(S,$.headers[S]);if(w.status!==$.status)$.status=w.status;return w;case"Promise":return w.then((S)=>{const X=f(S,$);if(X!==void 0)return X});case"Error":return i(w,$);case"Function":return f(w(),$);case"Number":case"Boolean":return new Response(w.toString(),$);case"FormData":return new Response(w);case"Cookie":if(w instanceof r)return new Response(w.value,$);return new Response(w?.toString(),$);default:if(w instanceof Response){let S=!1;if($.headers instanceof Headers)for(let X of $.headers.keys())if(X==="set-cookie"){if(S)continue;S=!0;for(let W of $.headers.getSetCookie())w.headers.append("set-cookie",W)}else w.headers.append(X,$.headers?.get(X)??"");else for(let X in $.headers)w.headers.append(X,$.headers[X]);if(w.status!==$.status)$.status=w.status;return w}if(w instanceof Promise)return w.then((S)=>f(S,$));if(w instanceof Error)return i(w,$);if("charCodeAt"in w){const S=w.charCodeAt(0);if(S===123||S===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w,$)}}else switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w,$);case"Array":return Response.json(w);case"Object":for(let B in Object.values(w))switch(B?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(S0(w),$);default:break}return Response.json(w,$);case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Promise":return w.then((B)=>{const S=f(B,$);if(S!==void 0)return S});case"Error":return i(w,$);case"Function":return n(w());case"Number":case"Boolean":return new Response(w.toString());case"Cookie":if(w instanceof r)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then((B)=>f(B,$));if(w instanceof Error)return i(w,$);if("charCodeAt"in w){const B=w.charCodeAt(0);if(B===123||B===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w)}},n=(w,$)=>{if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])return h(w.response,{status:w[d],headers:{}});switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w);case"Array":return Response.json(w);case"Object":w:for(let J of Object.values(w))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(S0(w));case"Object":break w;default:break}return Response.json(w);case"ReadableStream":return $?.signal.addEventListener("abort",{handleEvent(){if(!$?.signal.aborted)w.cancel($)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Error":return i(w);case"Promise":return w.then(n);case"Function":return n(w());case"Number":case"Boolean":return new Response(w.toString());case"FormData":return new Response(w);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then(n);if(w instanceof Error)return i(w);if("charCodeAt"in w){const J=w.charCodeAt(0);if(J===123||J===91)return new Response(JSON.stringify(w),{headers:{"Content-Type":"application/json"}})}return new Response(w)}},i=(w,$)=>new Response(JSON.stringify({name:w?.name,message:w?.message,cause:w?.cause}),{status:$?.status!==200?$?.status??500:500,headers:$?.headers});var Z$=function(w){let $=w;while($.endsWith("="))$=$.slice(0,-1);return $},K1=(w,$)=>{const J=new URL(w);return J.pathname=$,J.toString()},w$=(w)=>typeof w==="function"&&/^\s*class\s+/.test(w.toString())||w.toString().startsWith("[object ")||m(Object.getPrototypeOf(w)),F1=(w)=>w&&typeof w==="object"&&!Array.isArray(w),s=(w,$,{skipKeys:J}={})=>{if(F1(w)&&F1($))for(let[B,S]of Object.entries($)){if(J?.includes(B))continue;if(!F1(S)||!(B in w)||w$(S)){w[B]=S;continue}w[B]=s(w[B],S)}return w},$$=(w,$)=>{const{properties:J,...B}=w??{},{properties:S,...X}=$??{};return s(B,X)},L=(w=[],$=[])=>{if(!w)return[];if(!$)return w;const J=[],B=[];if(!Array.isArray(w))w=[w];if(!Array.isArray($))$=[$];for(let S of w)if(J.push(S),S.checksum)B.push(S.checksum);for(let S of $)if(!B.includes(S.checksum))J.push(S);return J},J$=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],B$=J$.reduce((w,$)=>(w[$]=!0,w),{}),S$=(w,$)=>{const J=(B)=>typeof B==="object"&&Object.keys(B).every(j0);if(J(w)&&J($))return{...w,...$};return $??w},u=(w,$,{allowMacro:J=!1}={})=>{return{...J?{...w,...$}:void 0,body:$?.body??w?.body,headers:$?.headers??w?.headers,params:$?.params??w?.params,query:$?.query??w?.query,response:S$(w?.response,$?.response),type:w?.type||$?.type,detail:s($?.detail??{},w?.detail??{}),parse:L(w?.parse,$?.parse),transform:L(w?.transform,$?.transform),beforeHandle:L(w?.beforeHandle,$?.beforeHandle),afterHandle:L(w?.afterHandle,$?.afterHandle),onResponse:L(w?.onResponse,$?.onResponse),mapResponse:L(w?.mapResponse,$?.mapResponse),trace:L(w?.trace,$?.trace),error:L(w?.error,$?.error)}},k=(w,{models:$={},dynamic:J=!1,normalize:B=!1,additionalProperties:S=B}={})=>{if(!w)return;if(typeof w==="string"&&!(w in $))return;const X=typeof w==="string"?$[w]:w;if(X.type==="object"&&"additionalProperties"in X===!1)X.additionalProperties=S;const W=(R)=>U0.Clean(X,R);if(J){const R={schema:X,references:"",checkFunc:()=>{},code:"",Check:(Y)=>U0.Check(X,Y),Errors:(Y)=>U0.Errors(X,Y),Code:()=>""};if(B&&X.additionalProperties===!0)R.Clean=W;if(X.config){if(R.config=X.config,R?.schema?.config)delete R.schema.config}return R}const Z=n1.Compile(X,Object.values($));if(Z.Clean=W,X.config){if(Z.config=X.config,Z?.schema?.config)delete Z.schema.config}return Z},l0=(w,{models:$={},dynamic:J=!1,normalize:B=!1,additionalProperties:S=B})=>{if(!w)return;if(typeof w==="string"&&!(w in $))return;const X=typeof w==="string"?$[w]:w,W=(R,Y)=>{const G=(j)=>U0.Clean(R,j);if(J)return{schema:R,references:"",checkFunc:()=>{},code:"",Check:(j)=>U0.Check(R,j),Errors:(j)=>U0.Errors(R,j),Code:()=>""};const F=n1.Compile(R,Y);if(B&&R.additionalProperties===!0)F.Clean=G;return F};if(G1 in X){if("additionalProperties"in X===!1)X.additionalProperties=S;return{200:W(X,Object.values($))}}const Z={};return Object.keys(X).forEach((R)=>{const Y=X[+R];if(typeof Y==="string"){if(Y in $){const G=$[Y];G.type==="object"&&"additionalProperties"in G,Z[+R]=G1 in G?W(G,Object.values($)):G}return}if(Y.type==="object"&&"additionalProperties"in Y===!1)Y.additionalProperties=S;Z[+R]=G1 in Y?W(Y,Object.values($)):Y}),Z},X$=typeof Bun!=="undefined",W$=X$&&typeof Bun.hash==="function",b0=(w)=>{if(W$)return Bun.hash(w);let $=9;for(let J=0;J<w.length;)$=Math.imul($^w.charCodeAt(J++),387420489);return $=$^$>>>9},i0=({validator:w,defaultConfig:$={},config:J,dynamic:B,models:S})=>{let X=k(w,{dynamic:B,models:S,additionalProperties:!0});if(m($))if(X)X.config=$$(X.config,J);else X=k(V.Cookie({}),{dynamic:B,models:S,additionalProperties:!0}),X.config=$;return X},t0=(w,$,J)=>{const B=(S)=>{if(!S)return;if(!Array.isArray(S)){const W=S;if(J&&!W.checksum)W.checksum=J;if(W.scope==="scoped")W.scope="local";return W}const X=[...S];for(let W of X){if(J&&!W.checksum)W.checksum=J;if(W.scope==="scoped")W.scope="local"}return X};return{start:L(w.start,B($?.start)),request:L(w.request,B($?.request)),parse:L(w.parse,B($?.parse)),transform:L(w.transform,B($?.transform)),beforeHandle:L(w.beforeHandle,B($?.beforeHandle)),afterHandle:L(w.afterHandle,B($?.afterHandle)),mapResponse:L(w.mapResponse,B($?.mapResponse)),onResponse:L(w.onResponse,B($?.onResponse)),trace:w.trace,error:L(w.error,B($?.error)),stop:L(w.stop,B($?.stop))}},a1=(w,$,{skipIfHasType:J=!1}={})=>{if(!w)return w;if(!Array.isArray(w)){if(J)w.scope??=$;else w.scope=$;return w}for(let B of w)if(J)B.scope??=$;else B.scope=$;return w},W0=(w)=>{if(!w)return w;if(!Array.isArray(w))switch(w.scope){case"global":case"scoped":return{...w};default:return{fn:w}}const $=[];for(let J of w)switch(J.scope){case"global":case"scoped":$.push({...J});break}return $},j1=(w)=>{return{...w,type:w?.type,detail:w?.detail,parse:W0(w?.parse),transform:W0(w?.transform),beforeHandle:W0(w?.beforeHandle),afterHandle:W0(w?.afterHandle),onResponse:W0(w?.onResponse),error:W0(w?.error),mapResponse:W0(w?.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},r0=Object.fromEntries(Object.entries(X0).map(([w,$])=>[$,w])),r1=new TextEncoder,z0=async(w,$)=>{if(typeof w!=="string")throw new TypeError("Cookie value must be provided as a string.");if($===null)throw new TypeError("Secret key must be provided.");const J=await crypto.subtle.importKey("raw",r1.encode($),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),B=await crypto.subtle.sign("HMAC",J,r1.encode(w));return w+"."+Z$(Buffer.from(B).toString("base64"))},Y1=async(w,$)=>{if(typeof w!=="string")throw new TypeError("Signed cookie string must be provided.");if($===null)throw new TypeError("Secret key must be provided.");const J=w.slice(0,w.lastIndexOf("."));return await z0(J,$)===w?J:!1},U1=(w,$,J=$)=>{if(!w||typeof w!=="object"||!$)return;for(let[B,S]of Object.entries($)){if(B in B$||!(B in w))continue;const X=w[B];if(typeof X==="function")X(S);else if(typeof X==="object")U1(X,S,J)}},o1=({globalHook:w,localHook:$})=>(J)=>(B,S)=>{if(typeof B==="function")B={fn:B};if("fn"in B||Array.isArray(B)){if(!$[J])$[J]=[];if(typeof $[J]==="function")$[J]=[$[J]];if(Array.isArray(B))$[J]=$[J].concat(B);else $[J].push(B);return}const{insert:X="after",stack:W="local"}=B;if(typeof S==="function")S={fn:S};if(W==="global")if(!Array.isArray(S))if(X==="before")w[J].unshift(S);else w[J].push(S);else if(X==="before")w[J]=S.concat(w[J]);else w[J]=w[J].concat(S);else{if(!$[J])$[J]=[];if(typeof $[J]==="function")$[J]=[$[J]];if(!Array.isArray(S))if(X==="before")$[J].unshift(S);else $[J].push(S);else if(X==="before")$[J]=S.concat($[J]);else $[J]=$[J].concat(S)}},j0=(w)=>{if(w.length<16)return w.trim().length!==0&&!Number.isNaN(Number(w));if(w.length===16){const $=Number(w);if($.toString()===w)return w.trim().length!==0&&!Number.isNaN($)}return!1};class z1{w;root=null;promises=[];constructor(w=console.error){this.onError=w}get size(){return this.promises.length}add(w){return this.promises.push(w),this.root||=this.drain(),w}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch(w){this.onError(w)}this.promises.shift()}this.root=null}then(w,$){return(this.root??Promise.resolve()).then(w,$)}}var c=(w)=>{if(!w)return w;if(!Array.isArray(w)){if(typeof w==="function")return{fn:w};else if("fn"in w)return w}const $=[];for(let J of w)if(typeof J==="function")$.push({fn:J});else if("fn"in J)$.push(J);return $},e1=(w)=>{return{...w,start:c(w?.start),request:c(w?.request),parse:c(w?.parse),transform:c(w?.transform),beforeHandle:c(w?.beforeHandle),afterHandle:c(w?.afterHandle),onResponse:c(w?.onResponse),mapResponse:c(w?.mapResponse),trace:c(w?.trace),error:c(w?.error),stop:c(w?.stop)}},ww=(w)=>{return{...w,start:w.start?.map(($)=>$.fn),request:w.request?.map(($)=>$.fn),parse:w.parse?.map(($)=>$.fn),transform:w.transform?.map(($)=>$.fn),beforeHandle:w.beforeHandle?.map(($)=>$.fn),afterHandle:w.afterHandle?.map(($)=>$.fn),onResponse:w.onResponse?.map(($)=>$.fn),mapResponse:w.mapResponse?.map(($)=>$.fn),trace:w.trace?.map(($)=>$.fn),error:w.error?.map(($)=>$.fn),stop:w.stop?.map(($)=>$.fn)}},n0=(w)=>({event:{body:w.event.body,cookie:w.event.cookie,headers:w.event.headers,queries:[...w.event.queries],query:w.event.query,set:w.event.set,unknownQueries:w.event.unknownQueries},trace:{request:w.trace.request,parse:w.trace.parse,transform:w.trace.transform,handle:w.trace.handle,beforeHandle:w.trace.beforeHandle,afterHandle:w.trace.afterHandle,error:w.trace.error,context:w.trace.context,store:w.trace.store,set:w.trace.set}}),q0=(w,$=301)=>Response.redirect(w,$),WJ=Symbol("ElysiaFormData"),S0=(w)=>{const $=new FormData;for(let[J,B]of Object.entries(w)){if(Array.isArray(B)){for(let S of B){if(B instanceof File)$.append(J,B,B.name);$.append(J,S)}continue}if(B instanceof File)$.append(J,B,B.name);$.append(J,B)}return $};var $w=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,Z0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),I0=($w?.NODE_ENV??$w?.ENV)==="production",_1=(w,$)=>({[d]:X0[w]??w,response:$??(w in r0?r0[w]:w),_type:void 0});class o0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor(w){super(w??"INTERNAL_SERVER_ERROR")}}class R0 extends Error{code="NOT_FOUND";status=404;constructor(w){super(w??"NOT_FOUND")}}class e0 extends Error{$;code="PARSE";status=400;constructor(w,$){super(w??"PARSE");this.body=$}}class O0 extends Error{w;code="INVALID_COOKIE_SIGNATURE";status=400;constructor(w,$){super($??`"${w}" has invalid cookie signature`);this.key=w}}class q extends Error{w;$;J;code="VALIDATION";status=422;constructor(w,$,J){if(typeof J==="object"&&d in J)J=J.response;const B=I0?void 0:("Errors"in $)?$.Errors(J).First():a0.Errors($,J).First(),S=B?.schema.error!==void 0?typeof B.schema.error==="function"?B.schema.error({type:w,validator:$,value:J,get errors(){return[...$.Errors(J)]}}):B.schema.error:void 0,X=B?.path||"root";let W="";if(S!==void 0)W=typeof S==="object"?JSON.stringify(S):S+"";else if(I0)W=JSON.stringify({type:"validation",on:w,message:B?.message,found:J});else{const Z=$?.schema??$,R="Errors"in $?[...$.Errors(J)]:[...a0.Errors($,J)];let Y;try{Y=a0.Create(Z)}catch(G){Y={type:"Could not create expected value",message:G?.message,error:G}}W=JSON.stringify({type:"validation",on:w,property:X,message:B?.message,expected:Y,found:J,errors:R},null,2)}super(W);this.type=w;this.validator=$;this.value=J;Object.setPrototypeOf(this,q.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel(w){const $="schema"in w?w.schema:w;try{return a0.Create($)}catch{return $}}get model(){return q.simplifyModel(this.validator)}toResponse(w){return new Response(this.message,{status:400,headers:{...w,"content-type":"application/json"}})}}var C1={open(w){w.data.open?.(w)},message(w,$){w.data.message?.(w,$)},drain(w){w.data.drain?.(w)},close(w,$,J){w.data.close?.(w,$,J)}};class _0{w;$;validator;constructor(w,$){this.raw=w;this.data=$;if(this.validator=w.data.validator,w.data.id)this.id=w.data.id;else{const J=new Uint32Array(1);crypto.getRandomValues(J),this.id=J[0].toString()}}get id(){return this.raw.data.id}set id(w){this.raw.data.id=w}get publish(){return(w,$=void 0,J)=>{if(this.validator?.Check($)===!1)throw new q("message",this.validator,$);if(typeof $==="object")$=JSON.stringify($);return this.raw.publish(w,$,J),this}}get send(){return(w)=>{if(this.validator?.Check(w)===!1)throw new q("message",this.validator,w);if(Buffer.isBuffer(w))return this.raw.send(w),this;if(typeof w==="object")w=JSON.stringify(w);return this.raw.send(w),this}}get subscribe(){return(w)=>{return this.raw.subscribe(w),this}}get unsubscribe(){return(w)=>{return this.raw.unsubscribe(w),this}}get cork(){return(w)=>{return this.raw.cork(w),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 Uw=N0(M1(),1),zw=N0(s0(),1);import{Value as E0} from"@sinclair/typebox/value";var F$=(new Headers()).toJSON,_w={value:0},Cw=({hasTrace:w,hasTraceSet:$=!1,addFn:J,condition:B={}})=>{if(w)return J("\nconst reporter = getReporter()\n"),(S,{name:X,attribute:W="",unit:Z=0}={})=>{const R=S.indexOf("."),Y=R===-1;if(S!=="request"&&S!=="response"&&!B[Y?S:S.slice(0,R)])return()=>{if($&&S==="afterHandle")J("\nawait traceDone\n")};if(Y)X||=S;else X||="anonymous";return J("\n"+`reporter.emit('event', {
7
+ */var W1=pw,Z1=lw;var sw=Object.prototype.toString,c0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var p1=P0(s0(),1);class n{w;$;J;constructor(w,$,J={}){this.name=w;this.jar=$;this.initial=J}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie(w){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=w}get value(){return this.cookie.value}set value(w){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=w}get expires(){return this.cookie.expires}set expires(w){this.cookie.expires=w}get maxAge(){return this.cookie.maxAge}set maxAge(w){this.cookie.maxAge=w}get domain(){return this.cookie.domain}set domain(w){this.cookie.domain=w}get path(){return this.cookie.path}set path(w){this.cookie.path=w}get secure(){return this.cookie.secure}set secure(w){this.cookie.secure=w}get httpOnly(){return this.cookie.httpOnly}set httpOnly(w){this.cookie.httpOnly=w}get sameSite(){return this.cookie.sameSite}set sameSite(w){this.cookie.sameSite=w}get priority(){return this.cookie.priority}set priority(w){this.cookie.priority=w}get partitioned(){return this.cookie.partitioned}set partitioned(w){this.cookie.partitioned=w}get secrets(){return this.cookie.secrets}set secrets(w){this.cookie.secrets=w}update(w){return this.cookie=Object.assign(this.cookie,typeof w==="function"?w(this.cookie):w),this}set(w){return this.cookie=Object.assign({...this.initial,value:this.value},typeof w==="function"?w(this.cookie):w),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 s1=(w,$,J)=>{if(!w.cookie)w.cookie={};return new Proxy($,{get(B,R){if(R in $)return new n(R,w.cookie,Object.assign({},J??{},$[R]));return new n(R,w.cookie,Object.assign({},J))}})},p0=async(w,$,{secrets:J,sign:B,...R}={})=>{if(!$)return s1(w,{},R);const S=typeof J==="string";if(B&&B!==!0&&!Array.isArray(B))B=[B];const X={},W=W1($);for(let[Z,Y]of Object.entries(W)){let G=p1.default(Y);if(B===!0||B?.includes(Z)){if(!J)throw new Error("No secret is provided to cookie plugin");if(S){const U=await Y1(G,J);if(U===!1)throw new b0(Z);G=U}else{let U=!0;for(let _=0;_<J.length;_++){const D=await Y1(G,J[_]);if(D!==!1){U=!0,G=D;break}}if(!U)throw new b0(Z)}}if(G==null){X[Z]={value:Y};continue}const F=G.charCodeAt(0);if(F===123||F===91)try{X[Z]={value:JSON.parse(G)};continue}catch{}if(j0(G)){X[Z]={value:parseInt(G)};continue}if(G==="true"){X[Z]={value:!0};continue}if(G==="false"){X[Z]={value:!1};continue}X[Z]={value:G}}return s1(w,X,R)};var l1="toJSON"in new Headers,m=(w)=>{if(!w)return!1;for(let $ in w)return!0;return!1},V0=(w,$)=>{const J=w.size;if(!$&&J||J&&$&&$.status!==206&&$.status!==304&&$.status!==412&&$.status!==416){if($){if($.headers instanceof Headers){if(l1)$.headers=$.headers.toJSON();else for(let[B,R]of $.headers.entries())if(B in $.headers)$.headers[B]=R}return new Response(w,{status:$.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`},$.headers)})}return new Response(w,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`}})}return new Response(w)},i1=(w,$)=>{if(!w)return w;w.delete("Set-Cookie");for(let J=0;J<$.length;J++){const B=$[J].indexOf("=");w.append("Set-Cookie",`${$[J].slice(0,B)}=${$[J].slice(B+1)||""}`)}return w},t1=(w)=>{if(!w||!m(w))return;const $=[];for(let[J,B]of Object.entries(w)){if(!J||!B)continue;const R=B.value;if(R===void 0||R===null)continue;$.push(Z1(J,typeof R==="object"?JSON.stringify(R):R+"",B))}if($.length===0)return;if($.length===1)return $[0];return $},v=(w,$,J)=>{if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])$.status=w[d],w=w.response;if(m($.headers)||$.status!==200||$.redirect||$.cookie){if(typeof $.status==="string")$.status=S0[$.status];if($.redirect){if($.headers.Location=$.redirect,!$.status||$.status<300||$.status>=400)$.status=302}if($.cookie&&m($.cookie))$.headers["Set-Cookie"]=t1($.cookie);if($.headers["Set-Cookie"]&&Array.isArray($.headers["Set-Cookie"]))$.headers=i1(new Headers($.headers),$.headers["Set-Cookie"]);switch(w?.constructor?.name){case"String":return new Response(w,$);case"Blob":return V0(w,$);case"Array":return Response.json(w,$);case"Object":for(let R in Object.values(w))switch(R?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(R0(w));default:break}return Response.json(w,$);case"ReadableStream":if(!$.headers["content-type"]?.startsWith("text/event-stream"))$.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,$);case void 0:if(!w)return new Response("",$);return Response.json(w,$);case"Response":let B=!1;if($.headers instanceof Headers)for(let R of $.headers.keys())if(R==="set-cookie"){if(B)continue;B=!0;for(let S of $.headers.getSetCookie())w.headers.append("set-cookie",S)}else w.headers.append(R,$.headers?.get(R)??"");else for(let R in $.headers)w.headers.append(R,$.headers[R]);if(w.status!==$.status)$.status=w.status;return w;case"Error":return t(w,$);case"Promise":return w.then((R)=>v(R,$));case"Function":return v(w(),$);case"Number":case"Boolean":return new Response(w.toString(),$);case"Cookie":if(w instanceof n)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w,$);default:if(w instanceof Response){let R=!1;if($.headers instanceof Headers)for(let S of $.headers.keys())if(S==="set-cookie"){if(R)continue;R=!0;for(let X of $.headers.getSetCookie())w.headers.append("set-cookie",X)}else w.headers.append(S,$.headers?.get(S)??"");else for(let S in $.headers)w.headers.append(S,$.headers[S]);if(l1)$.headers=w.headers.toJSON();else for(let[S,X]of w.headers.entries())if(S in $.headers)$.headers[S]=X;return w}if(w instanceof Promise)return w.then((R)=>v(R,$));if(w instanceof Error)return t(w,$);if("toResponse"in w)return v(w.toResponse(),$);if("charCodeAt"in w){const R=w.charCodeAt(0);if(R===123||R===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w,$)}}else switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w,$);case"Array":return Response.json(w);case"Object":for(let B in Object.values(w))switch(B?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(R0(w),$);default:break}return Response.json(w,$);case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Error":return t(w,$);case"Promise":return w.then((B)=>{const R=i(B);if(R!==void 0)return R;return new Response("")});case"Function":return i(w());case"Number":case"Boolean":return new Response(w.toString());case"Cookie":if(w instanceof n)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w,$);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then((B)=>v(B,$));if(w instanceof Error)return t(w,$);if("toResponse"in w)return v(w.toResponse(),$);if("charCodeAt"in w){const B=w.charCodeAt(0);if(B===123||B===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w)}},k=(w,$,J)=>{if(w===void 0||w===null)return;if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])$.status=w[d],w=w.response;if(m($.headers)||$.status!==200||$.redirect||$.cookie){if(typeof $.status==="string")$.status=S0[$.status];if($.redirect){if($.headers.Location=$.redirect,!$.status||$.status<300||$.status>=400)$.status=302}if($.cookie&&m($.cookie))$.headers["Set-Cookie"]=t1($.cookie);if($.headers["Set-Cookie"]&&Array.isArray($.headers["Set-Cookie"]))$.headers=i1(new Headers($.headers),$.headers["Set-Cookie"]);switch(w?.constructor?.name){case"String":return new Response(w,$);case"Blob":return V0(w,$);case"Array":return Response.json(w,$);case"Object":for(let R in Object.values(w))switch(R?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(R0(w),$);default:break}return Response.json(w,$);case"ReadableStream":if(!$.headers["content-type"]?.startsWith("text/event-stream"))$.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,$);case void 0:if(!w)return;return Response.json(w,$);case"Response":let B=!1;if($.headers instanceof Headers)for(let R of $.headers.keys())if(R==="set-cookie"){if(B)continue;B=!0;for(let S of $.headers.getSetCookie())w.headers.append("set-cookie",S)}else w.headers.append(R,$.headers?.get(R)??"");else for(let R in $.headers)w.headers.append(R,$.headers[R]);if(w.status!==$.status)$.status=w.status;return w;case"Promise":return w.then((R)=>{const S=k(R,$);if(S!==void 0)return S});case"Error":return t(w,$);case"Function":return k(w(),$);case"Number":case"Boolean":return new Response(w.toString(),$);case"FormData":return new Response(w);case"Cookie":if(w instanceof n)return new Response(w.value,$);return new Response(w?.toString(),$);default:if(w instanceof Response){let R=!1;if($.headers instanceof Headers)for(let S of $.headers.keys())if(S==="set-cookie"){if(R)continue;R=!0;for(let X of $.headers.getSetCookie())w.headers.append("set-cookie",X)}else w.headers.append(S,$.headers?.get(S)??"");else for(let S in $.headers)w.headers.append(S,$.headers[S]);if(w.status!==$.status)$.status=w.status;return w}if(w instanceof Promise)return w.then((R)=>k(R,$));if(w instanceof Error)return t(w,$);if("toResponse"in w)return k(w.toResponse(),$);if("charCodeAt"in w){const R=w.charCodeAt(0);if(R===123||R===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w,$)}}else switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w,$);case"Array":return Response.json(w);case"Object":for(let B in Object.values(w))switch(B?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(R0(w),$);default:break}return Response.json(w,$);case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)w.cancel(J)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Promise":return w.then((B)=>{const R=k(B,$);if(R!==void 0)return R});case"Error":return t(w,$);case"Function":return i(w());case"Number":case"Boolean":return new Response(w.toString());case"Cookie":if(w instanceof n)return new Response(w.value,$);return new Response(w?.toString(),$);case"FormData":return new Response(w);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then((B)=>k(B,$));if(w instanceof Error)return t(w,$);if("toResponse"in w)return k(w.toResponse(),$);if("charCodeAt"in w){const B=w.charCodeAt(0);if(B===123||B===91){if(!$.headers["Content-Type"])$.headers["Content-Type"]="application/json";return new Response(JSON.stringify(w),$)}}return new Response(w)}},i=(w,$)=>{if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])return v(w.response,{status:w[d],headers:{}});switch(w?.constructor?.name){case"String":return new Response(w);case"Blob":return V0(w);case"Array":return Response.json(w);case"Object":w:for(let J of Object.values(w))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(R0(w));case"Object":break w;default:break}return Response.json(w);case"ReadableStream":return $?.signal.addEventListener("abort",{handleEvent(){if(!$?.signal.aborted)w.cancel($)}},{once:!0}),new Response(w,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!w)return new Response("");return new Response(JSON.stringify(w),{headers:{"content-type":"application/json"}});case"Response":return w;case"Error":return t(w);case"Promise":return w.then(i);case"Function":return i(w());case"Number":case"Boolean":return new Response(w.toString());case"FormData":return new Response(w);default:if(w instanceof Response)return new Response(w.body,{headers:{"Content-Type":"application/json"}});if(w instanceof Promise)return w.then(i);if(w instanceof Error)return t(w);if("toResponse"in w)return i(w.toResponse());if("charCodeAt"in w){const J=w.charCodeAt(0);if(J===123||J===91)return new Response(JSON.stringify(w),{headers:{"Content-Type":"application/json"}})}return new Response(w)}},t=(w,$)=>new Response(JSON.stringify({name:w?.name,message:w?.message,cause:w?.cause}),{status:$?.status!==200?$?.status??500:500,headers:$?.headers});var W$=function(w){let $=w;while($.endsWith("="))$=$.slice(0,-1);return $},K1=(w,$)=>{const J=new URL(w);return J.pathname=$,J.toString()},w$=(w)=>typeof w==="function"&&/^\s*class\s+/.test(w.toString())||w.toString().startsWith("[object ")||m(Object.getPrototypeOf(w)),F1=(w)=>w&&typeof w==="object"&&!Array.isArray(w),s=(w,$,{skipKeys:J}={})=>{if(F1(w)&&F1($))for(let[B,R]of Object.entries($)){if(J?.includes(B))continue;if(!F1(R)||!(B in w)||w$(R)){w[B]=R;continue}w[B]=s(w[B],R)}return w},$$=(w,$)=>{const{properties:J,...B}=w??{},{properties:R,...S}=$??{};return s(B,S)},L=(w=[],$=[])=>{if(!w)return[];if(!$)return w;const J=[],B=[];if(!Array.isArray(w))w=[w];if(!Array.isArray($))$=[$];for(let R of w)if(J.push(R),R.checksum)B.push(R.checksum);for(let R of $)if(!B.includes(R.checksum))J.push(R);return J},J$=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],B$=J$.reduce((w,$)=>(w[$]=!0,w),{}),R$=(w,$)=>{const J=(B)=>typeof B==="object"&&Object.keys(B).every(j0);if(J(w)&&J($))return{...w,...$};return $??w},h=(w,$,{allowMacro:J=!1}={})=>{return{...J?{...w,...$}:void 0,body:$?.body??w?.body,headers:$?.headers??w?.headers,params:$?.params??w?.params,query:$?.query??w?.query,response:R$(w?.response,$?.response),type:w?.type||$?.type,detail:s($?.detail??{},w?.detail??{}),parse:L(w?.parse,$?.parse),transform:L(w?.transform,$?.transform),beforeHandle:L(w?.beforeHandle,$?.beforeHandle),afterHandle:L(w?.afterHandle,$?.afterHandle),onResponse:L(w?.onResponse,$?.onResponse),mapResponse:L(w?.mapResponse,$?.mapResponse),trace:L(w?.trace,$?.trace),error:L(w?.error,$?.error)}},f=(w,{models:$={},dynamic:J=!1,normalize:B=!1,additionalProperties:R=!1}={})=>{if(!w)return;if(typeof w==="string"&&!(w in $))return;const S=typeof w==="string"?$[w]:w;if(S.type==="object"&&"additionalProperties"in S===!1)S.additionalProperties=R;const X=(Z)=>U0.Clean(S,Z);if(J){const Z={schema:S,references:"",checkFunc:()=>{},code:"",Check:(Y)=>U0.Check(S,Y),Errors:(Y)=>U0.Errors(S,Y),Code:()=>""};if(B&&S.additionalProperties===!1)Z.Clean=X;if(S.config){if(Z.config=S.config,Z?.schema?.config)delete Z.schema.config}return Z}const W=n1.Compile(S,Object.values($));if(W.Clean=X,S.config){if(W.config=S.config,W?.schema?.config)delete W.schema.config}return W},l0=(w,{models:$={},dynamic:J=!1,normalize:B=!1,additionalProperties:R=!1})=>{if(!w)return;if(typeof w==="string"&&!(w in $))return;const S=typeof w==="string"?$[w]:w,X=(Z,Y)=>{const G=(U)=>U0.Clean(Z,U);if(J)return{schema:Z,references:"",checkFunc:()=>{},code:"",Check:(U)=>U0.Check(Z,U),Errors:(U)=>U0.Errors(Z,U),Code:()=>""};const F=n1.Compile(Z,Y);if(B&&Z.additionalProperties===!1)F.Clean=G;return F};if(G1 in S){if("additionalProperties"in S===!1)S.additionalProperties=R;return{200:X(S,Object.values($))}}const W={};return Object.keys(S).forEach((Z)=>{const Y=S[+Z];if(typeof Y==="string"){if(Y in $){const G=$[Y];G.type==="object"&&"additionalProperties"in G,W[+Z]=G1 in G?X(G,Object.values($)):G}return}if(Y.type==="object"&&"additionalProperties"in Y===!1)Y.additionalProperties=R;W[+Z]=G1 in Y?X(Y,Object.values($)):Y}),W},S$=typeof Bun!=="undefined",X$=S$&&typeof Bun.hash==="function",q0=(w)=>{if(X$)return Bun.hash(w);let $=9;for(let J=0;J<w.length;)$=Math.imul($^w.charCodeAt(J++),387420489);return $=$^$>>>9},i0=({validator:w,defaultConfig:$={},config:J,dynamic:B,models:R})=>{let S=f(w,{dynamic:B,models:R,additionalProperties:!0});if(m($))if(S)S.config=$$(S.config,J);else S=f(b.Cookie({}),{dynamic:B,models:R,additionalProperties:!0}),S.config=$;return S},t0=(w,$,J)=>{const B=(R)=>{if(!R)return;if(!Array.isArray(R)){const X=R;if(J&&!X.checksum)X.checksum=J;if(X.scope==="scoped")X.scope="local";return X}const S=[...R];for(let X of S){if(J&&!X.checksum)X.checksum=J;if(X.scope==="scoped")X.scope="local"}return S};return{start:L(w.start,B($?.start)),request:L(w.request,B($?.request)),parse:L(w.parse,B($?.parse)),transform:L(w.transform,B($?.transform)),beforeHandle:L(w.beforeHandle,B($?.beforeHandle)),afterHandle:L(w.afterHandle,B($?.afterHandle)),mapResponse:L(w.mapResponse,B($?.mapResponse)),onResponse:L(w.onResponse,B($?.onResponse)),trace:w.trace,error:L(w.error,B($?.error)),stop:L(w.stop,B($?.stop))}},o1=(w,$,{skipIfHasType:J=!1}={})=>{if(!w)return w;if(!Array.isArray(w)){if(J)w.scope??=$;else w.scope=$;return w}for(let B of w)if(J)B.scope??=$;else B.scope=$;return w},X0=(w)=>{if(!w)return w;if(!Array.isArray(w))switch(w.scope){case"global":case"scoped":return{...w};default:return{fn:w}}const $=[];for(let J of w)switch(J.scope){case"global":case"scoped":$.push({...J});break}return $},j1=(w)=>{return{...w,type:w?.type,detail:w?.detail,parse:X0(w?.parse),transform:X0(w?.transform),beforeHandle:X0(w?.beforeHandle),afterHandle:X0(w?.afterHandle),onResponse:X0(w?.onResponse),error:X0(w?.error),mapResponse:X0(w?.mapResponse)}},S0={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},r0=Object.fromEntries(Object.entries(S0).map(([w,$])=>[$,w])),r1=new TextEncoder,z0=async(w,$)=>{if(typeof w!=="string")throw new TypeError("Cookie value must be provided as a string.");if($===null)throw new TypeError("Secret key must be provided.");const J=await crypto.subtle.importKey("raw",r1.encode($),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),B=await crypto.subtle.sign("HMAC",J,r1.encode(w));return w+"."+W$(Buffer.from(B).toString("base64"))},Y1=async(w,$)=>{if(typeof w!=="string")throw new TypeError("Signed cookie string must be provided.");if($===null)throw new TypeError("Secret key must be provided.");const J=w.slice(0,w.lastIndexOf("."));return await z0(J,$)===w?J:!1},U1=(w,$,J=$)=>{if(!w||typeof w!=="object"||!$)return;for(let[B,R]of Object.entries($)){if(B in B$||!(B in w))continue;const S=w[B];if(typeof S==="function")S(R);else if(typeof S==="object")U1(S,R,J)}},a1=({globalHook:w,localHook:$})=>(J)=>(B,R)=>{if(typeof B==="function")B={fn:B};if("fn"in B||Array.isArray(B)){if(!$[J])$[J]=[];if(typeof $[J]==="function")$[J]=[$[J]];if(Array.isArray(B))$[J]=$[J].concat(B);else $[J].push(B);return}const{insert:S="after",stack:X="local"}=B;if(typeof R==="function")R={fn:R};if(X==="global")if(!Array.isArray(R))if(S==="before")w[J].unshift(R);else w[J].push(R);else if(S==="before")w[J]=R.concat(w[J]);else w[J]=w[J].concat(R);else{if(!$[J])$[J]=[];if(typeof $[J]==="function")$[J]=[$[J]];if(!Array.isArray(R))if(S==="before")$[J].unshift(R);else $[J].push(R);else if(S==="before")$[J]=R.concat($[J]);else $[J]=$[J].concat(R)}},j0=(w)=>{if(w.length<16)return w.trim().length!==0&&!Number.isNaN(Number(w));if(w.length===16){const $=Number(w);if($.toString()===w)return w.trim().length!==0&&!Number.isNaN($)}return!1};class z1{w;root=null;promises=[];constructor(w=console.error){this.onError=w}get size(){return this.promises.length}add(w){return this.promises.push(w),this.root||=this.drain(),w}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch(w){this.onError(w)}this.promises.shift()}this.root=null}then(w,$){return(this.root??Promise.resolve()).then(w,$)}}var c=(w)=>{if(!w)return w;if(!Array.isArray(w)){if(typeof w==="function")return{fn:w};else if("fn"in w)return w}const $=[];for(let J of w)if(typeof J==="function")$.push({fn:J});else if("fn"in J)$.push(J);return $},e1=(w)=>{return{...w,start:c(w?.start),request:c(w?.request),parse:c(w?.parse),transform:c(w?.transform),beforeHandle:c(w?.beforeHandle),afterHandle:c(w?.afterHandle),onResponse:c(w?.onResponse),mapResponse:c(w?.mapResponse),trace:c(w?.trace),error:c(w?.error),stop:c(w?.stop)}},ww=(w)=>{return{...w,start:w.start?.map(($)=>$.fn),request:w.request?.map(($)=>$.fn),parse:w.parse?.map(($)=>$.fn),transform:w.transform?.map(($)=>$.fn),beforeHandle:w.beforeHandle?.map(($)=>$.fn),afterHandle:w.afterHandle?.map(($)=>$.fn),onResponse:w.onResponse?.map(($)=>$.fn),mapResponse:w.mapResponse?.map(($)=>$.fn),trace:w.trace?.map(($)=>$.fn),error:w.error?.map(($)=>$.fn),stop:w.stop?.map(($)=>$.fn)}},n0=(w)=>({event:{body:w.event.body,cookie:w.event.cookie,headers:w.event.headers,queries:[...w.event.queries],query:w.event.query,set:w.event.set,unknownQueries:w.event.unknownQueries},trace:{request:w.trace.request,parse:w.trace.parse,transform:w.trace.transform,handle:w.trace.handle,beforeHandle:w.trace.beforeHandle,afterHandle:w.trace.afterHandle,error:w.trace.error,context:w.trace.context,store:w.trace.store,set:w.trace.set}}),I0=(w,$=301)=>Response.redirect(w,$),XJ=Symbol("ElysiaFormData"),R0=(w)=>{const $=new FormData;for(let[J,B]of Object.entries(w)){if(Array.isArray(B)){for(let R of B){if(B instanceof File)$.append(J,B,B.name);$.append(J,R)}continue}if(B instanceof File)$.append(J,B,B.name);$.append(J,B)}return $};var $w=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,W0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),T0=($w?.NODE_ENV??$w?.ENV)==="production",_1=(w,$)=>({[d]:S0[w]??w,response:$??(w in r0?r0[w]:w),_type:void 0});class a0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor(w){super(w??"INTERNAL_SERVER_ERROR")}}class Z0 extends Error{code="NOT_FOUND";status=404;constructor(w){super(w??"NOT_FOUND")}}class e0 extends Error{$;code="PARSE";status=400;constructor(w,$){super(w??"PARSE");this.body=$}}class b0 extends Error{w;code="INVALID_COOKIE_SIGNATURE";status=400;constructor(w,$){super($??`"${w}" has invalid cookie signature`);this.key=w}}class I extends Error{w;$;J;code="VALIDATION";status=422;constructor(w,$,J){if(typeof J==="object"&&d in J)J=J.response;const B=T0?void 0:("Errors"in $)?$.Errors(J).First():o0.Errors($,J).First(),R=B?.schema.error!==void 0?typeof B.schema.error==="function"?B.schema.error({type:w,validator:$,value:J,get errors(){return[...$.Errors(J)]}}):B.schema.error:void 0,S=B?.path||"root";let X="";if(R!==void 0)X=typeof R==="object"?JSON.stringify(R):R+"";else if(T0)X=JSON.stringify({type:"validation",on:w,message:B?.message,found:J});else{const W=$?.schema??$,Z="Errors"in $?[...$.Errors(J)]:[...o0.Errors($,J)];let Y;try{Y=o0.Create(W)}catch(G){Y={type:"Could not create expected value",message:G?.message,error:G}}X=JSON.stringify({type:"validation",on:w,property:S,message:B?.message,expected:Y,found:J,errors:Z},null,2)}super(X);this.type=w;this.validator=$;this.value=J;Object.setPrototypeOf(this,I.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel(w){const $="schema"in w?w.schema:w;try{return o0.Create($)}catch{return $}}get model(){return I.simplifyModel(this.validator)}toResponse(w){return new Response(this.message,{status:400,headers:{...w,"content-type":"application/json"}})}}var C1={open(w){w.data.open?.(w)},message(w,$){w.data.message?.(w,$)},drain(w){w.data.drain?.(w)},close(w,$,J){w.data.close?.(w,$,J)}};class _0{w;$;validator;constructor(w,$){this.raw=w;this.data=$;if(this.validator=w.data.validator,w.data.id)this.id=w.data.id;else{const J=new Uint32Array(1);crypto.getRandomValues(J),this.id=J[0].toString()}}get id(){return this.raw.data.id}set id(w){this.raw.data.id=w}get publish(){return(w,$=void 0,J)=>{if(this.validator?.Check($)===!1)throw new I("message",this.validator,$);if(typeof $==="object")$=JSON.stringify($);return this.raw.publish(w,$,J),this}}get send(){return(w)=>{if(this.validator?.Check(w)===!1)throw new I("message",this.validator,w);if(Buffer.isBuffer(w))return this.raw.send(w),this;if(typeof w==="object")w=JSON.stringify(w);return this.raw.send(w),this}}get subscribe(){return(w)=>{return this.raw.subscribe(w),this}}get unsubscribe(){return(w)=>{return this.raw.unsubscribe(w),this}}get cork(){return(w)=>{return this.raw.cork(w),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 Uw=P0(M1(),1),zw=P0(s0(),1);import{Value as C0} from"@sinclair/typebox/value";var F$=(new Headers()).toJSON,_w={value:0},Cw=({hasTrace:w,hasTraceSet:$=!1,addFn:J,condition:B={}})=>{if(w)return J("\nconst reporter = getReporter()\n"),(R,{name:S,attribute:X="",unit:W=0}={})=>{const Z=R.indexOf("."),Y=Z===-1;if(R!=="request"&&R!=="response"&&!B[Y?R:R.slice(0,Z)])return()=>{if($&&R==="afterHandle")J("\nawait traceDone\n")};if(Y)S||=R;else S||="anonymous";return J("\n"+`reporter.emit('event', {
8
8
  id,
9
- event: '${S}',
9
+ event: '${R}',
10
10
  type: 'begin',
11
- name: '${X}',
11
+ name: '${S}',
12
12
  time: performance.now(),
13
- ${Y?`unit: ${Z},`:""}
14
- ${W}
13
+ ${Y?`unit: ${W},`:""}
14
+ ${X}
15
15
  })`.replace(/(\t| |\n)/g,"")+"\n"),()=>{if(J("\n"+`reporter.emit('event', {
16
16
  id,
17
- event: '${S}',
17
+ event: '${R}',
18
18
  type: 'end',
19
19
  time: performance.now()
20
- })`.replace(/(\t| |\n)/g,"")+"\n"),$&&S==="afterHandle")J("\nawait traceDone\n")}};else return()=>()=>{}},L0=(w)=>{const $=w.indexOf(")");if(w.charCodeAt($+2)===61&&w.charCodeAt($+5)!==123)return!0;return w.includes("return")},K$=(w,{injectResponse:$="",normalize:J=!1}={})=>({composeValidation:(B,S=`c.${B}`)=>w?`c.set.status = 422; throw new ValidationError('${B}', ${B}, ${S})`:`c.set.status = 422; return new ValidationError('${B}', ${B}, ${S}).toResponse(c.set.headers)`,composeResponseValidation:(B="r")=>{const S=w?`throw new ValidationError('response', response[c.set.status], ${B})`:`return new ValidationError('response', response[c.set.status], ${B}).toResponse(c.set.headers)`;let X="\n"+$+"\n";if(X+=`let er
20
+ })`.replace(/(\t| |\n)/g,"")+"\n"),$&&R==="afterHandle")J("\nawait traceDone\n")}};else return()=>()=>{}},L0=(w)=>{const $=w.indexOf(")");if(w.charCodeAt($+2)===61&&w.charCodeAt($+5)!==123)return!0;return w.includes("return")},K$=(w,{injectResponse:$="",normalize:J=!1}={})=>({composeValidation:(B,R=`c.${B}`)=>w?`c.set.status = 422; throw new ValidationError('${B}', ${B}, ${R})`:`c.set.status = 422; return new ValidationError('${B}', ${B}, ${R}).toResponse(c.set.headers)`,composeResponseValidation:(B="r")=>{const R=w?`throw new ValidationError('response', response[c.set.status], ${B})`:`return new ValidationError('response', response[c.set.status], ${B}).toResponse(c.set.headers)`;let S="\n"+$+"\n";if(S+=`let er
21
21
 
22
22
  if(${B} && typeof ${B} === "object" && ELYSIA_RESPONSE in ${B})
23
- er = ${B}[ELYSIA_RESPONSE]\n`,J)X+=`
23
+ er = ${B}[ELYSIA_RESPONSE]\n`,J)S+=`
24
24
  if(!er && response[c.set.status]?.Clean)
25
25
  ${B} = response[c.set.status]?.Clean(${B})
26
26
  else if(response[er]?.Clean)
27
- ${B}.response = response[er]?.Clean(${B}.response)`;return X+=`
27
+ ${B}.response = response[er]?.Clean(${B}.response)`;return S+=`
28
28
  if(er) {
29
29
  if(!(${B} instanceof Response) && response[er]?.Check(${B}.response) === false) {
30
30
  if(!(response instanceof Error)) {
31
31
  c.set.status = ${B}[ELYSIA_RESPONSE]
32
32
 
33
- ${S}
33
+ ${R}
34
34
  }
35
35
  }
36
36
  } else if(!(${B} instanceof Response) && response[c.set.status]?.Check(${B}) === false) {
37
37
  if(!(response instanceof Error))
38
- ${S}
39
- }\n`,X}}),VJ=Symbol.for("TypeBox.Kind");var Q0=(w,$)=>{if(!$)return;if($.type==="object"){const J=$.properties;if(!J)return!1;for(let B of Object.keys(J)){const S=J[B];if(w in S)return!0;if(S.type==="object"){if(Q0(w,S))return!0}else if(S.anyOf){for(let X=0;X<S.anyOf.length;X++)if(Q0(w,S.anyOf[X]))return!0}}return!1}return w in $},A1=Symbol.for("TypeBox.Transform"),C0=(w)=>{if(!w)return;if(w.type==="object"&&w.properties){const $=w.properties;for(let J of Object.keys($)){const B=$[J];if(B.type==="object"){if(C0(B))return!0}else if(B.anyOf){for(let X=0;X<B.anyOf.length;X++)if(C0(B.anyOf[X]))return!0}if(A1 in B)return!0}return!1}return A1 in w||w.properties&&A1 in w.properties},j$=/(?:return|=>) \S+\(/g,x=(w)=>{const $="fn"in w?w.fn:w;if($.constructor.name==="AsyncFunction")return!0;const J=$.toString();if(J.includes("=> response.clone("))return!1;if(J.includes("await"))return!0;if(J.includes("async"))return!0;return!!J.match(j$)},w1=({app:w,path:$,method:J,localHook:B,hooks:S,validator:X,handler:W,allowMeta:Z=!1,appInference:{event:R,trace:Y}})=>{const G=typeof W==="function";if(!G)W=h(W,{headers:w.setHeaders??{}});const F=w.config.forceErrorEncapsulation&&(G||S.afterHandle.length>0||S.beforeHandle.length>0||S.transform.length>0)||S.error.length>0||w.event.error.length>0||typeof Bun==="undefined"||S.onResponse.length>0||!!S.trace.length,j=G?"handler(c)":"handler",_=S.onResponse.length?`\n;(async () => {${S.onResponse.map((A,U)=>`await res${U}(c)`).join(";")}})();\n`:"",C=Y,P=S.trace.length>0;let Q="";const K=d0(Object.assign(B,{handler:W}),R),M=K.query||!!X.query,D=J!=="$INTERNALWS"&&J!=="GET"&&J!=="HEAD"&&S.type!=="none"&&(K.body||!!X.body),T=w.setHeaders,b=T&&!!Object.keys(T).length,e=K.headers||X.headers,v=K.cookie||!!X.cookie,l=v?i0({validator:X.cookie,defaultConfig:w.config.cookie,dynamic:!!w.config.aot,config:X.cookie?.config??{},models:w.definitions.type}):void 0,O=l?.config;let N="";if(O?.sign){if(!O.secrets)throw new Error(`t.Cookie required secret which is not set in (${J}) ${$}.`);const A=!O.secrets?void 0:typeof O.secrets==="string"?O.secrets:O.secrets[0];if(N+=`const _setCookie = c.set.cookie
38
+ ${R}
39
+ }\n`,S}}),bJ=Symbol.for("TypeBox.Kind");var Q0=(w,$)=>{if(!$)return;if($.type==="object"){const J=$.properties;if(!J)return!1;for(let B of Object.keys(J)){const R=J[B];if(w in R)return!0;if(R.type==="object"){if(Q0(w,R))return!0}else if(R.anyOf){for(let S=0;S<R.anyOf.length;S++)if(Q0(w,R.anyOf[S]))return!0}}return!1}return w in $},A1=Symbol.for("TypeBox.Transform"),D0=(w)=>{if(!w)return;if(w.type==="object"&&w.properties){const $=w.properties;for(let J of Object.keys($)){const B=$[J];if(B.type==="object"){if(D0(B))return!0}else if(B.anyOf){for(let S=0;S<B.anyOf.length;S++)if(D0(B.anyOf[S]))return!0}if(A1 in B)return!0}return!1}return A1 in w||w.properties&&A1 in w.properties},j$=/(?:return|=>) \S+\(/g,x=(w)=>{const $="fn"in w?w.fn:w;if($.constructor.name==="AsyncFunction")return!0;const J=$.toString();if(J.includes("=> response.clone("))return!1;if(J.includes("await"))return!0;if(J.includes("async"))return!0;return!!J.match(j$)},w1=({app:w,path:$,method:J,localHook:B,hooks:R,validator:S,handler:X,allowMeta:W=!1,appInference:{event:Z,trace:Y}})=>{const G=typeof X==="function";if(!G)X=v(X,{headers:w.setHeaders??{}});const F=w.config.forceErrorEncapsulation&&(G||R.afterHandle.length>0||R.beforeHandle.length>0||R.transform.length>0)||R.error.length>0||w.event.error.length>0||typeof Bun==="undefined"||R.onResponse.length>0||!!R.trace.length,U=G?"handler(c)":"handler",_=R.onResponse.length?`\n;(async () => {${R.onResponse.map((C,K)=>`await res${K}(c)`).join(";")}})();\n`:"",D=Y,P=R.trace.length>0;let Q="";const j=d0(Object.assign(B,{handler:X}),Z),A=j.query||!!S.query,M=J!=="$INTERNALWS"&&J!=="GET"&&J!=="HEAD"&&R.type!=="none"&&(j.body||!!S.body),T=w.setHeaders,V=T&&!!Object.keys(T).length,e=j.headers||S.headers,u=j.cookie||!!S.cookie,l=u?i0({validator:S.cookie,defaultConfig:w.config.cookie,dynamic:!!w.config.aot,config:S.cookie?.config??{},models:w.definitions.type}):void 0,O=l?.config;let N="";if(O?.sign){if(!O.secrets)throw new Error(`t.Cookie required secret which is not set in (${J}) ${$}.`);const C=!O.secrets?void 0:typeof O.secrets==="string"?O.secrets:O.secrets[0];if(N+=`const _setCookie = c.set.cookie
40
40
  if(_setCookie) {`,O.sign===!0)N+=`for(const [key, cookie] of Object.entries(_setCookie)) {
41
- c.set.cookie[key].value = await signCookie(cookie.value, '${A}')
42
- }`;else for(let U of O.sign)N+=`if(_setCookie['${U}']?.value) { c.set.cookie['${U}'].value = await signCookie(_setCookie['${U}'].value, '${A}') }\n`;N+="}\n"}const w0=w.config.normalize,{composeValidation:Y0,composeResponseValidation:g0}=K$(F,{normalize:w0});if(e)Q+=F$?"c.headers = c.request.headers.toJSON()\n":`c.headers = {}
41
+ c.set.cookie[key].value = await signCookie(cookie.value, '${C}')
42
+ }`;else for(let K of O.sign)N+=`if(_setCookie['${K}']?.value) { c.set.cookie['${K}'].value = await signCookie(_setCookie['${K}'].value, '${C}') }\n`;N+="}\n"}const w0=w.config.normalize,{composeValidation:Y0,composeResponseValidation:g0}=K$(F,{normalize:w0});if(e)Q+=F$?"c.headers = c.request.headers.toJSON()\n":`c.headers = {}
43
43
  for (const [key, value] of c.request.headers.entries())
44
44
  c.headers[key] = value
45
- `;if(v){const A=(z,I)=>{const H=O?.[z]??I;if(!H)return typeof I==="string"?`${z}: "${I}",`:`${z}: ${I},`;if(typeof H==="string")return`${z}: '${H}',`;if(H instanceof Date)return`${z}: new Date(${H.getTime()}),`;return`${z}: ${H},`},U=O?`{
46
- secrets: ${O.secrets!==void 0?typeof O.secrets==="string"?`'${O.secrets}'`:"["+O.secrets.reduce((z,I)=>z+`'${I}',`,"")+"]":"undefined"},
47
- sign: ${O.sign===!0?!0:O.sign!==void 0?"["+O.sign.reduce((z,I)=>z+`'${I}',`,"")+"]":"undefined"},
48
- ${A("domain")}
49
- ${A("expires")}
50
- ${A("httpOnly")}
51
- ${A("maxAge")}
52
- ${A("path","/")}
53
- ${A("priority")}
54
- ${A("sameSite")}
55
- ${A("secure")}
56
- }`:"undefined";if(e)Q+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${U})\n`;else Q+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${U})\n`}if(M){let A=[];if(X.query&&X.query.schema.type==="object")A=Object.keys(X.query.schema.properties);else for(let U of K.queries)if(A.indexOf(U)===-1)A.push(U);if(w.config.forceDynamicQuery===!0||K.unknownQueries===!0||!A.length)Q+=`if(c.qi !== -1) {
45
+ `;if(u){const C=(z,q)=>{const H=O?.[z]??q;if(!H)return typeof q==="string"?`${z}: "${q}",`:`${z}: ${q},`;if(typeof H==="string")return`${z}: '${H}',`;if(H instanceof Date)return`${z}: new Date(${H.getTime()}),`;return`${z}: ${H},`},K=O?`{
46
+ secrets: ${O.secrets!==void 0?typeof O.secrets==="string"?`'${O.secrets}'`:"["+O.secrets.reduce((z,q)=>z+`'${q}',`,"")+"]":"undefined"},
47
+ sign: ${O.sign===!0?!0:O.sign!==void 0?"["+O.sign.reduce((z,q)=>z+`'${q}',`,"")+"]":"undefined"},
48
+ ${C("domain")}
49
+ ${C("expires")}
50
+ ${C("httpOnly")}
51
+ ${C("maxAge")}
52
+ ${C("path","/")}
53
+ ${C("priority")}
54
+ ${C("sameSite")}
55
+ ${C("secure")}
56
+ }`:"undefined";if(e)Q+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${K})\n`;else Q+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${K})\n`}if(A){let C=[];if(S.query&&S.query.schema.type==="object")C=Object.keys(S.query.schema.properties);else for(let K of j.queries)if(C.indexOf(K)===-1)C.push(K);if(w.config.forceDynamicQuery===!0||j.unknownQueries===!0||!C.length)Q+=`if(c.qi !== -1) {
57
57
  c.query = parseQuery(c.url.slice(c.qi + 1).replace(/\\+/g, ' '))
58
58
 
59
59
  // decodeURIComponent is already done in parseQuery function
@@ -62,12 +62,12 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
62
62
  } else c.query = {}`;else Q+=`if(c.qi !== -1) {
63
63
  let url = '&' + c.url.slice(c.qi + 1).replace(/\\+/g, ' ')
64
64
 
65
- ${A.map((U,z)=>`
66
- ${z===0?"let":""} memory = url.indexOf('&${U}=')
65
+ ${C.map((K,z)=>`
66
+ ${z===0?"let":""} memory = url.indexOf('&${K}=')
67
67
  let a${z}
68
68
 
69
69
  if (memory !== -1) {
70
- const start = memory + ${U.length+2}
70
+ const start = memory + ${K.length+2}
71
71
  memory = url.indexOf('&', start)
72
72
 
73
73
  if(memory === -1) a${z} = decodeURIComponent(url.slice(start))
@@ -75,11 +75,11 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
75
75
  }`).join("\n")}
76
76
 
77
77
  c.query = {
78
- ${A.map((U,z)=>`'${U}': a${z}`).join(", ")}
78
+ ${C.map((K,z)=>`'${K}': a${z}`).join(", ")}
79
79
  }
80
80
  } else {
81
81
  c.query = {}
82
- }`}const y0=Y.set,v0=K.cookie||K.set||y0||e||G&&b;if(P)Q+="\nconst id = c.$$requestId\n";const E=Cw({hasTrace:P,hasTraceSet:y0,condition:C,addFn:(A)=>{Q+=A}});if(Q+=F?"\n try {\n":"",y0){Q+="\nconst traceDone = Promise.all([";for(let A=0;A<S.trace.length;A++)Q+=`new Promise(r => { reporter.once(\`res\${id}.${A}\`, r) }),`;Q+="])\n"}const G0=typeof W==="function"&&x(W),B1=v||D||y0||G0||!!S.mapResponse.length||S.parse.length>0||S.afterHandle.some(x)||S.beforeHandle.some(x)||S.transform.some(x),Tw=E("parse",{unit:S.parse.length});if(D){const A=S.parse.length||K.body||X.body;if(S.type&&!S.parse.length)switch(S.type){case"json":case"application/json":if(F)Q+=`const tempBody = await c.request.text()
82
+ }`}const y0=Y.set,k0=j.cookie||j.set||y0||e||G&&V;if(P)Q+="\nconst id = c.$$requestId\n";const E=Cw({hasTrace:P,hasTraceSet:y0,condition:D,addFn:(C)=>{Q+=C}});if(Q+=F?"\n try {\n":"",y0){Q+="\nconst traceDone = Promise.all([";for(let C=0;C<R.trace.length;C++)Q+=`new Promise(r => { reporter.once(\`res\${id}.${C}\`, r) }),`;Q+="])\n"}const G0=typeof X==="function"&&x(X),B1=u||M||y0||G0||!!R.mapResponse.length||R.parse.length>0||R.afterHandle.some(x)||R.beforeHandle.some(x)||R.transform.some(x),Tw=E("parse",{unit:R.parse.length});if(M){const C=R.parse.length||j.body||S.body;if(R.type&&!R.parse.length)switch(R.type){case"json":case"application/json":if(F)Q+=`const tempBody = await c.request.text()
83
83
 
84
84
  try {
85
85
  c.body = JSON.parse(tempBody)
@@ -96,11 +96,11 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
96
96
  if (value.length === 1)
97
97
  c.body[key] = value[0]
98
98
  else c.body[key] = value
99
- }\n`;break}else if(A){if(Q+="\n",Q+=e?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')",Q+=`
99
+ }\n`;break}else if(C){if(Q+="\n",Q+=e?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')",Q+=`
100
100
  if (contentType) {
101
101
  const index = contentType.indexOf(';')
102
102
  if (index !== -1) contentType = contentType.substring(0, index)\n
103
- c.contentType = contentType\n`,S.parse.length){Q+="let used = false\n";const U=E("parse",{unit:S.parse.length});for(let z=0;z<S.parse.length;z++){const I=E("parse.unit",{name:S.parse[z].fn.name}),H=`bo${z}`;if(z!==0)Q+="if(!used) {\n";if(Q+=`let ${H} = parse[${z}](c, contentType)\n`,Q+=`if(${H} instanceof Promise) ${H} = await ${H}\n`,Q+=`if(${H} !== undefined) { c.body = ${H}; used = true }\n`,I(),z!==0)Q+="}"}U()}if(Q+="\ndelete c.contentType\n",S.parse.length)Q+="if (!used) {";if(S.type&&!Array.isArray(S.type))switch(S.type){case"json":case"application/json":if(F)Q+=`const tempBody = await c.request.text()
103
+ c.contentType = contentType\n`,R.parse.length){Q+="let used = false\n";const K=E("parse",{unit:R.parse.length});for(let z=0;z<R.parse.length;z++){const q=E("parse.unit",{name:R.parse[z].fn.name}),H=`bo${z}`;if(z!==0)Q+="if(!used) {\n";if(Q+=`let ${H} = parse[${z}](c, contentType)\n`,Q+=`if(${H} instanceof Promise) ${H} = await ${H}\n`,Q+=`if(${H} !== undefined) { c.body = ${H}; used = true }\n`,q(),z!==0)Q+="}"}K()}if(Q+="\ndelete c.contentType\n",R.parse.length)Q+="if (!used) {";if(R.type&&!Array.isArray(R.type))switch(R.type){case"json":case"application/json":if(F)Q+=`const tempBody = await c.request.text()
104
104
 
105
105
  try {
106
106
  c.body = JSON.parse(tempBody)
@@ -158,64 +158,65 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
158
158
  }
159
159
 
160
160
  break
161
- }`;if(S.parse.length)Q+="}";Q+="}\n"}Q+="\n"}if(Tw(),S?.transform){const A=E("transform",{unit:S.transform.length});if(S.transform.length)Q+="\nlet transformed\n";for(let U=0;U<S.transform.length;U++){const z=S.transform[U],I=E("transform.unit",{name:z.fn.name});Q+=x(z)?`transformed = await transform[${U}](c)\n`:`transformed = transform[${U}](c)\n`,Q+=`if(transformed?.[ELYSIA_RESPONSE])
161
+ }`;if(R.parse.length)Q+="}";Q+="}\n"}Q+="\n"}if(Tw(),R?.transform){const C=E("transform",{unit:R.transform.length});if(R.transform.length)Q+="\nlet transformed\n";for(let K=0;K<R.transform.length;K++){const z=R.transform[K],q=E("transform.unit",{name:z.fn.name});Q+=x(z)?`transformed = await transform[${K}](c)\n`:`transformed = transform[${K}](c)\n`,Q+=`if(transformed?.[ELYSIA_RESPONSE])
162
162
  throw transformed
163
163
  else
164
- Object.assign(c, transformed)\n`,I()}A()}if(X){if(Q+="\n",X.headers){if(Q0("default",X.headers.params))for(let[A,U]of Object.entries(E0.Default(X.headers.schema,{}))){const z=typeof U==="object"?JSON.stringify(U):`'${U}'`;if(z)Q+=`c.headers['${A}'] ??= ${z}\n`}if(Q+=`if(headers.Check(c.headers) === false) {
164
+ Object.assign(c, transformed)\n`,q()}C()}if(S){if(Q+="\n",S.headers){if(Q0("default",S.headers.schema))for(let[C,K]of Object.entries(C0.Default(S.headers.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.headers['${C}'] ??= ${z}\n`}if(Q+=`if(headers.Check(c.headers) === false) {
165
165
  ${Y0("headers")}
166
- }`,C0(X.headers.schema))Q+="\nc.headers = headers.Decode(c.headers)\n"}if(X.params){if(Q0("default",X.params.schema))for(let[A,U]of Object.entries(E0.Default(X.params.schema,{}))){const z=typeof U==="object"?JSON.stringify(U):`'${U}'`;if(z)Q+=`c.params['${A}'] ??= ${z}\n`}if(Q+=`if(params.Check(c.params) === false) {
166
+ }`,D0(S.headers.schema))Q+="\nc.headers = headers.Decode(c.headers)\n"}if(S.params){if(Q0("default",S.params.schema))for(let[C,K]of Object.entries(C0.Default(S.params.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.params['${C}'] ??= ${z}\n`}if(Q+=`if(params.Check(c.params) === false) {
167
167
  ${Y0("params")}
168
- }`,C0(X.params.schema))Q+="\nc.params = params.Decode(c.params)\n"}if(X.query){if(w0)Q+="c.query = query.Clean(c.query);\n";if(Q0("default",X.query.schema))for(let[A,U]of Object.entries(E0.Default(X.query.schema,{}))){const z=typeof U==="object"?JSON.stringify(U):`'${U}'`;if(z)Q+=`c.query['${A}'] ??= ${z}\n`}if(Q+=`if(query.Check(c.query) === false) {
168
+ }`,D0(S.params.schema))Q+="\nc.params = params.Decode(c.params)\n"}if(S.query){if(w0)Q+="c.query = query.Clean(c.query);\n";if(Q0("default",S.query.schema))for(let[C,K]of Object.entries(C0.Default(S.query.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.query['${C}'] ??= ${z}\n`}for(let[C,K]of Object.entries(S.query.schema?.properties)){const{type:z,anyOf:q}=K;if(z==="object"||z==="array"){Q+=`c.query['${C}'] = JSON.parse(c.query['${C}'])\n`;continue}if(q)Q+=`if(typeof c.query['${C}'] === "object") c.query['${C}'] = JSON.parse(c.query['${C}'])\n`}if(Q+=`if(query.Check(c.query) === false) {
169
169
  ${Y0("query")}
170
- }`,C0(X.query.schema))Q+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(X.body){if(w0)Q+="c.body = body.Clean(c.body);\n";if(Q0("default",X.body.schema))Q+=`if(body.Check(c.body) === false) {
171
- c.body = Object.assign(${JSON.stringify(E0.Default(X.body.schema,null)??{})}, c.body)
172
-
173
- if(body.Check(c.query) === false) {
170
+ }`,D0(S.query.schema))Q+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(S.body){if(w0)Q+="c.body = body.Clean(c.body);\n";if(Q0("default",S.body.schema)){Q+=`if(body.Check(c.body) === false) {
171
+ if (typeof c.body === 'object') {
172
+ c.body = Object.assign(${JSON.stringify(C0.Default(S.body.schema,{})??{})}, c.body)
173
+ } else {`;const C=C0.Default(S.body.schema,void 0);if(typeof C==="string")Q+=`c.body = '${C}'`;else Q+=`c.body = ${C}`;Q+=`}
174
+ if(body.Check(c.body) === false) {
174
175
  ${Y0("body")}
175
176
  }
176
- }`;else Q+=`if(body.Check(c.body) === false) {
177
+ }`}else Q+=`if(body.Check(c.body) === false) {
177
178
  ${Y0("body")}
178
- }`;if(C0(X.body.schema))Q+="\nc.body = body.Decode(c.body)\n"}if(m(l?.schema?.properties??l?.schema?.schema??{})){if(Q+=`const cookieValue = {}
179
+ }`;if(D0(S.body.schema))Q+="\nc.body = body.Decode(c.body)\n"}if(m(l?.schema?.properties??l?.schema?.schema??{})){if(Q+=`const cookieValue = {}
179
180
  for(const [key, value] of Object.entries(c.cookie))
180
- cookieValue[key] = value.value\n`,Q0("default",l.schema))for(let[A,U]of Object.entries(E0.Default(l.schema,{})))Q+=`cookieValue['${A}'] = ${typeof U==="object"?JSON.stringify(U):U}\n`;Q+=`if(cookie.Check(cookieValue) === false) {
181
+ cookieValue[key] = value.value\n`,Q0("default",l.schema))for(let[C,K]of Object.entries(C0.Default(l.schema,{})))Q+=`cookieValue['${C}'] = ${typeof K==="object"?JSON.stringify(K):K}\n`;Q+=`if(cookie.Check(cookieValue) === false) {
181
182
  ${Y0("cookie","cookieValue")}
182
- }`}}if(S?.beforeHandle){const A=E("beforeHandle",{unit:S.beforeHandle.length});let U=!1;for(let z=0;z<S.beforeHandle.length;z++){const I=S.beforeHandle[z],H=E("beforeHandle.unit",{name:I.fn.name}),k0=L0(I.fn.toString());if(I.subType==="resolve"){if(!U)U=!0,Q+="\nlet resolved\n";Q+=x(I)?`resolved = await beforeHandle[${z}](c);\n`:`resolved = beforeHandle[${z}](c);\n`,Q+=`if(resolved[ELYSIA_RESPONSE])
183
+ }`}}if(R?.beforeHandle){const C=E("beforeHandle",{unit:R.beforeHandle.length});let K=!1;for(let z=0;z<R.beforeHandle.length;z++){const q=R.beforeHandle[z],H=E("beforeHandle.unit",{name:q.fn.name}),v0=L0(q.fn.toString());if(q.subType==="resolve"){if(!K)K=!0,Q+="\nlet resolved\n";Q+=x(q)?`resolved = await beforeHandle[${z}](c);\n`:`resolved = beforeHandle[${z}](c);\n`,Q+=`if(resolved[ELYSIA_RESPONSE])
183
184
  throw resolved
184
185
  else
185
- Object.assign(c, resolved)\n`}else if(!k0)Q+=x(I)?`await beforeHandle[${z}](c);\n`:`beforeHandle[${z}](c);\n`,H();else{if(Q+="Object.assign(c, be);",Q+=x(I)?`be = await beforeHandle[${z}](c);\n`:`be = beforeHandle[${z}](c);\n`,H(),Q+="if(be !== undefined) {\n",A(),S.afterHandle?.length){const A0=E("afterHandle",{unit:S.transform.length});E("handle",{name:G?W.name:void 0})();for(let J0=0;J0<S.afterHandle.length;J0++){const u0=S.afterHandle[J0],Ew=L0(u0.fn.toString()),Lw=E("afterHandle.unit",{name:u0.fn.name});if(Q+="c.response = be\n",!Ew)Q+=x(u0.fn)?`await afterHandle[${J0}](c, be)\n`:`afterHandle[${J0}](c, be)\n`;else Q+=x(u0.fn)?`af = await afterHandle[${J0}](c)\n`:`af = afterHandle[${J0}](c)\n`,Q+="if(af !== undefined) { c.response = be = af }\n";Lw()}A0()}if(X.response)Q+=g0("be");if(S.mapResponse.length){Q+="c.response = be";for(let A0=0;A0<S.mapResponse.length;A0++)Q+=`\nif(mr === undefined) {
186
- mr = onMapResponse[${A0}](c)
186
+ Object.assign(c, resolved)\n`}else if(!v0)Q+=x(q)?`await beforeHandle[${z}](c);\n`:`beforeHandle[${z}](c);\n`,H();else{if(Q+="Object.assign(c, be);",Q+=x(q)?`be = await beforeHandle[${z}](c);\n`:`be = beforeHandle[${z}](c);\n`,H(),Q+="if(be !== undefined) {\n",C(),R.afterHandle?.length){const N0=E("afterHandle",{unit:R.transform.length});E("handle",{name:G?X.name:void 0})();for(let J0=0;J0<R.afterHandle.length;J0++){const u0=R.afterHandle[J0],Ew=L0(u0.fn.toString()),Lw=E("afterHandle.unit",{name:u0.fn.name});if(Q+="c.response = be\n",!Ew)Q+=x(u0.fn)?`await afterHandle[${J0}](c, be)\n`:`afterHandle[${J0}](c, be)\n`;else Q+=x(u0.fn)?`af = await afterHandle[${J0}](c)\n`:`af = afterHandle[${J0}](c)\n`,Q+="if(af !== undefined) { c.response = be = af }\n";Lw()}N0()}if(S.response)Q+=g0("be");if(R.mapResponse.length){Q+="c.response = be";for(let N0=0;N0<R.mapResponse.length;N0++)Q+=`\nif(mr === undefined) {
187
+ mr = onMapResponse[${N0}](c)
187
188
  if(mr instanceof Promise) mr = await mr
188
189
  if(mr !== undefined) c.response = mr
189
- }\n`}Q+=N,Q+="return mapEarlyResponse(be, c.set)}\n"}}A()}if(S?.afterHandle.length){const A=E("handle",{name:G?W.name:void 0});if(S.afterHandle.length)Q+=G0?`let r = c.response = await ${j};\n`:`let r = c.response = ${j};\n`;else Q+=G0?`let r = await ${j};\n`:`let r = ${j};\n`;A();const U=E("afterHandle",{unit:S.afterHandle.length});for(let z=0;z<S.afterHandle.length;z++){const I=S.afterHandle[z],H=L0(I.fn.toString()),k0=E("afterHandle.unit",{name:I.fn.name});if(!H)Q+=x(I.fn)?`await afterHandle[${z}](c)\n`:`afterHandle[${z}](c)\n`,k0();else if(Q+=x(I.fn)?`af = await afterHandle[${z}](c)\n`:`af = afterHandle[${z}](c)\n`,k0(),X.response)Q+="if(af !== undefined) {",U(),Q+=g0("af"),Q+="c.response = af }";else Q+="if(af !== undefined) {",U(),Q+="c.response = af}\n"}if(U(),Q+="r = c.response\n",X.response)Q+=g0();if(Q+=N,S.mapResponse.length)for(let z=0;z<S.mapResponse.length;z++)Q+=`\nmr = onMapResponse[${z}](c)
190
+ }\n`}Q+=N,Q+="return mapEarlyResponse(be, c.set)}\n"}}C()}if(R?.afterHandle.length){const C=E("handle",{name:G?X.name:void 0});if(R.afterHandle.length)Q+=G0?`let r = c.response = await ${U};\n`:`let r = c.response = ${U};\n`;else Q+=G0?`let r = await ${U};\n`:`let r = ${U};\n`;C();const K=E("afterHandle",{unit:R.afterHandle.length});for(let z=0;z<R.afterHandle.length;z++){const q=R.afterHandle[z],H=L0(q.fn.toString()),v0=E("afterHandle.unit",{name:q.fn.name});if(!H)Q+=x(q.fn)?`await afterHandle[${z}](c)\n`:`afterHandle[${z}](c)\n`,v0();else if(Q+=x(q.fn)?`af = await afterHandle[${z}](c)\n`:`af = afterHandle[${z}](c)\n`,v0(),S.response)Q+="if(af !== undefined) {",K(),Q+=g0("af"),Q+="c.response = af }";else Q+="if(af !== undefined) {",K(),Q+="c.response = af}\n"}if(K(),Q+="r = c.response\n",S.response)Q+=g0();if(Q+=N,R.mapResponse.length)for(let z=0;z<R.mapResponse.length;z++)Q+=`\nmr = onMapResponse[${z}](c)
190
191
  if(mr instanceof Promise) mr = await mr
191
- if(mr !== undefined) c.response = mr\n`;if(v0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else{const A=E("handle",{name:G?W.name:void 0});if(X.response||S.mapResponse.length){if(Q+=G0?`let r = await ${j};\n`:`let r = ${j};\n`,A(),X.response)Q+=g0();if(E("afterHandle")(),S.mapResponse.length){Q+="c.response = r";for(let U=0;U<S.mapResponse.length;U++)Q+=`\nif(mr === undefined) {
192
- mr = onMapResponse[${U}](c)
192
+ if(mr !== undefined) c.response = mr\n`;if(k0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else{const C=E("handle",{name:G?X.name:void 0});if(S.response||R.mapResponse.length){if(Q+=G0?`let r = await ${U};\n`:`let r = ${U};\n`,C(),S.response)Q+=g0();if(E("afterHandle")(),R.mapResponse.length){Q+="c.response = r";for(let K=0;K<R.mapResponse.length;K++)Q+=`\nif(mr === undefined) {
193
+ mr = onMapResponse[${K}](c)
193
194
  if(mr instanceof Promise) mr = await mr
194
195
  if(mr !== undefined) r = c.response = mr
195
- }\n`}if(Q+=N,W instanceof Response)Q+=K.set?`if(
196
+ }\n`}if(Q+=N,X instanceof Response)Q+=j.set?`if(
196
197
  isNotEmpty(c.set.headers) ||
197
198
  c.set.status !== 200 ||
198
199
  c.set.redirect ||
199
200
  c.set.cookie
200
201
  )
201
- return mapResponse(${j}.clone(), c.set)
202
+ return mapResponse(${U}.clone(), c.set)
202
203
  else
203
- return ${j}.clone()`:`return ${j}.clone()`,Q+="\n";else if(v0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else if(C.handle||v){if(Q+=G0?`let r = await ${j};\n`:`let r = ${j};\n`,A(),E("afterHandle")(),S.mapResponse.length){Q+="c.response = r";for(let U=0;U<S.mapResponse.length;U++)Q+=`\nif(mr === undefined) {
204
- mr = onMapResponse[${U}](c)
204
+ return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(k0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else if(D.handle||u){if(Q+=G0?`let r = await ${U};\n`:`let r = ${U};\n`,C(),E("afterHandle")(),R.mapResponse.length){Q+="c.response = r";for(let K=0;K<R.mapResponse.length;K++)Q+=`\nif(mr === undefined) {
205
+ mr = onMapResponse[${K}](c)
205
206
  if(mr instanceof Promise) mr = await mr
206
207
  if(mr !== undefined) r = c.response = mr
207
- }\n`}if(Q+=N,v0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else{A();const U=G0?`await ${j}`:j;if(E("afterHandle")(),W instanceof Response)Q+=K.set?`if(
208
+ }\n`}if(Q+=N,k0)Q+="return mapResponse(r, c.set)\n";else Q+="return mapCompactResponse(r)\n"}else{C();const K=G0?`await ${U}`:U;if(E("afterHandle")(),X instanceof Response)Q+=j.set?`if(
208
209
  isNotEmpty(c.set.headers) ||
209
210
  c.set.status !== 200 ||
210
211
  c.set.redirect ||
211
212
  c.set.cookie
212
213
  )
213
- return mapResponse(${j}.clone(), c.set)
214
+ return mapResponse(${U}.clone(), c.set)
214
215
  else
215
- return ${j}.clone()`:`return ${j}.clone()`,Q+="\n";else if(v0)Q+=`return mapResponse(${U}, c.set)\n`;else Q+=`return mapCompactResponse(${U})\n`}}if(F||_){if(Q+="\n} catch(error) {",!B1)Q+="return (async () => {";Q+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const A=E("error",{unit:S.error.length});if(S.error.length){Q+=`
216
+ return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(k0)Q+=`return mapResponse(${K}, c.set)\n`;else Q+=`return mapCompactResponse(${K})\n`}}if(F||_){if(Q+="\n} catch(error) {",!B1)Q+="return (async () => {";Q+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const C=E("error",{unit:R.error.length});if(R.error.length){Q+=`
216
217
  c.error = error
217
218
  c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
218
- `;for(let U=0;U<S.error.length;U++){const z=`er${U}`,I=E("error.unit",{name:S.error[U].fn.name});if(Q+=`\nlet ${z} = handleErrors[${U}](c)\n`,x(S.error[U]))Q+=`if (${z} instanceof Promise) ${z} = await ${z}\n`;I(),Q+=`${z} = mapEarlyResponse(${z}, set)\n`,Q+=`if (${z}) {`,Q+=`return ${z} }\n`}}if(A(),Q+="return handleError(c, error, true)\n\n",!B1)Q+="})()";if(Q+="}",_||P){Q+=" finally { ";const U=E("response",{unit:S.onResponse.length});Q+=_,U(),Q+="}"}}return Q=`const {
219
+ `;for(let K=0;K<R.error.length;K++){const z=`er${K}`,q=E("error.unit",{name:R.error[K].fn.name});if(Q+=`\nlet ${z} = handleErrors[${K}](c)\n`,x(R.error[K]))Q+=`if (${z} instanceof Promise) ${z} = await ${z}\n`;q(),Q+=`${z} = mapEarlyResponse(${z}, set)\n`,Q+=`if (${z}) {`,Q+=`return ${z} }\n`}}if(C(),Q+="return handleError(c, error, true)\n\n",!B1)Q+="})()";if(Q+="}",_||P){Q+=" finally { ";const K=E("response",{unit:R.onResponse.length});Q+=_,K(),Q+="}"}}return Q=`const {
219
220
  handler,
220
221
  handleError,
221
222
  hooks: {
@@ -260,17 +261,17 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
260
261
  ELYSIA_RESPONSE
261
262
  } = hooks
262
263
 
263
- ${S.onResponse.length?`const ${S.onResponse.map((A,U)=>`res${U} = onResponse[${U}]`).join(",")}`:""}
264
+ ${R.onResponse.length?`const ${R.onResponse.map((C,K)=>`res${K} = onResponse[${K}]`).join(",")}`:""}
264
265
 
265
266
  return ${B1?"async":""} function handle(c) {
266
- ${S.beforeHandle.length?"let be":""}
267
- ${S.afterHandle.length?"let af":""}
268
- ${S.mapResponse.length?"let mr":""}
267
+ ${R.beforeHandle.length?"let be":""}
268
+ ${R.afterHandle.length?"let af":""}
269
+ ${R.mapResponse.length?"let mr":""}
269
270
 
270
- ${Z?"c.schema = schema; c.defs = definitions":""}
271
+ ${W?"c.schema = schema; c.defs = definitions":""}
271
272
  ${Q}
272
- }`,Function("hooks",Q)({handler:W,hooks:ww(S),validator:X,handleError:w.handleError,utils:{mapResponse:h,mapCompactResponse:n,mapEarlyResponse:f,parseQuery:Uw.parse,isNotEmpty:m},error:{NotFoundError:R0,ValidationError:q,InternalServerError:o0,ParseError:e0},schema:w.router.history,definitions:w.definitions.type,ERROR_CODE:Z0,getReporter:()=>w.reporter,requestId:_w,parseCookie:p0,signCookie:z0,decodeURIComponent:zw.default,ELYSIA_RESPONSE:d})},N1=(w)=>{const $={event:{...w.inference.event,queries:[...w.inference.event.queries]},trace:{...w.inference.trace}};let J="",B="";const S=w.setHeaders;for(let Q of Object.keys(w.singleton.decorator))J+=`,${Q}: app.singleton.decorator.${Q}`;const X=w.router,W=w.event.trace.length>0;let Z=`
273
- const route = router.find(request.method, path) ${X.http.root.ALL?'?? router.find("ALL", path)':""}
273
+ }`,Function("hooks",Q)({handler:X,hooks:ww(R),validator:S,handleError:w.handleError,utils:{mapResponse:v,mapCompactResponse:i,mapEarlyResponse:k,parseQuery:Uw.parse,isNotEmpty:m},error:{NotFoundError:Z0,ValidationError:I,InternalServerError:a0,ParseError:e0},schema:w.router.history,definitions:w.definitions.type,ERROR_CODE:W0,getReporter:()=>w.reporter,requestId:_w,parseCookie:p0,signCookie:z0,decodeURIComponent:zw.default,ELYSIA_RESPONSE:d})},N1=(w)=>{const $={event:{...w.inference.event,queries:[...w.inference.event.queries]},trace:{...w.inference.trace}};let J="",B="";const R=w.setHeaders;for(let Q of Object.keys(w.singleton.decorator))J+=`,${Q}: app.singleton.decorator.${Q}`;const S=w.router,X=w.event.trace.length>0;let W=`
274
+ const route = router.find(request.method, path) ${S.http.root.ALL?'?? router.find("ALL", path)':""}
274
275
 
275
276
  if (route === null)
276
277
  return ${w.event.error.length?"app.handleError(ctx, notFound)":w.event.request.length?`new Response(error404Message, {
@@ -278,12 +279,12 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
278
279
  headers: ctx.set.headers
279
280
  })`:"error404.clone()"}
280
281
 
281
- ctx.params = route.params\n`;if(!(w.config.precompile===!0||typeof w.config.precompile==="object"&&w.config.precompile.compose===!0))Z+=`
282
+ ctx.params = route.params\n`;if(!(w.config.precompile===!0||typeof w.config.precompile==="object"&&w.config.precompile.compose===!0))W+=`
282
283
  if(route.store.composed)
283
284
  return route.store.composed(ctx)
284
285
 
285
286
  if(route.store.compose)
286
- return (route.store.compose())(ctx)`;else Z+="return route.store(ctx)";Z+="\n";let Y="";for(let[Q,{code:K,all:M}]of Object.entries(X.static.http.map))Y+=`case '${Q}':\nswitch(request.method) {\n${K}\n${M??"default: break map"}}\n\n`;const G=w.event.request.some(x),F=`\n
287
+ return (route.store.compose())(ctx)`;else W+="return route.store(ctx)";W+="\n";let Y="";for(let[Q,{code:j,all:A}]of Object.entries(S.static.http.map))Y+=`case '${Q}':\nswitch(request.method) {\n${j}\n${A??"default: break map"}}\n\n`;const G=w.event.request.some(x),F=`\n
287
288
  const url = request.url
288
289
  const s = url.indexOf('/', 11)
289
290
  const qi = url.indexOf('?', s + 1)
@@ -310,34 +311,34 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
310
311
  const notFound = new NotFoundError()
311
312
 
312
313
  ${w.event.request.length?"const onRequest = app.event.request.map(x => x.fn)":""}
313
- ${X.static.http.variables}
314
+ ${S.static.http.variables}
314
315
  ${w.event.error.length?"":`
315
316
  const error404Message = notFound.message.toString()
316
317
  const error404 = new Response(error404Message, { status: 404 });
317
318
  `}
318
319
 
319
- return ${G?"async":""} function map(request) {\n`,w.event.request.length)B+="let re";const j=Cw({hasTrace:W,hasTraceSet:$.trace.set,condition:{request:$.trace.request},addFn:(Q)=>{B+=Q}});if(w.event.request.length){B+=`
320
- ${W?"const id = +requestId.value++":""}
320
+ return ${G?"async":""} function map(request) {\n`,w.event.request.length)B+="let re";const U=Cw({hasTrace:X,hasTraceSet:$.trace.set,condition:{request:$.trace.request},addFn:(Q)=>{B+=Q}});if(w.event.request.length){B+=`
321
+ ${X?"const id = +requestId.value++":""}
321
322
 
322
323
  const ctx = {
323
324
  request,
324
325
  store,
325
326
  redirect,
326
327
  set: {
327
- headers: ${Object.keys(S??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
328
+ headers: ${Object.keys(R??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
328
329
  status: 200
329
330
  },
330
331
  error
331
- ${W?",$$requestId: +id":""}
332
+ ${X?",$$requestId: +id":""}
332
333
  ${J}
333
334
  }
334
- `;const Q=j("request",{attribute:"ctx",unit:w.event.request.length});B+="\n try {\n";for(let K=0;K<w.event.request.length;K++){const M=w.event.request[K],D=L0(M.fn.toString()),T=x(M),b=j("request.unit",{name:w.event.request[K].fn.name});if(D)B+=`re = mapEarlyResponse(
335
- ${T?"await":""} onRequest[${K}](ctx),
335
+ `;const Q=U("request",{attribute:"ctx",unit:w.event.request.length});B+="\n try {\n";for(let j=0;j<w.event.request.length;j++){const A=w.event.request[j],M=L0(A.fn.toString()),T=x(A),V=U("request.unit",{name:w.event.request[j].fn.name});if(M)B+=`re = mapEarlyResponse(
336
+ ${T?"await":""} onRequest[${j}](ctx),
336
337
  ctx.set,
337
338
  request
338
- )\n`,b(),B+="if(re !== undefined) return re\n";else B+=`${T?"await":""} onRequest[${K}](ctx)\n`,b()}B+=`} catch (error) {
339
+ )\n`,V(),B+="if(re !== undefined) return re\n";else B+=`${T?"await":""} onRequest[${j}](ctx)\n`,V()}B+=`} catch (error) {
339
340
  return app.handleError(ctx, error)
340
- }`,Q(),B+=F,B+="\nctx.qi = qi\n ctx.path = path\nctx.url=url"}else B+=F,B+=`${W?"const id = +requestId.value++":""}
341
+ }`,Q(),B+=F,B+="\nctx.qi = qi\n ctx.path = path\nctx.url=url"}else B+=F,B+=`${X?"const id = +requestId.value++":""}
341
342
  const ctx = {
342
343
  request,
343
344
  store,
@@ -346,18 +347,18 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
346
347
  url,
347
348
  redirect,
348
349
  set: {
349
- headers: ${Object.keys(S??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
350
+ headers: ${Object.keys(R??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
350
351
  status: 200
351
352
  },
352
353
  error
353
- ${W?",$$requestId: id":""}
354
+ ${X?",$$requestId: id":""}
354
355
  ${J}
355
- }`,j("request",{unit:w.event.request.length,attribute:$.trace.context||$.trace.store||$.trace.set?"ctx":""})();const _=w.router.static.ws,C=w.router.ws;if(Object.keys(_).length||C.history.length){B+=`
356
+ }`,U("request",{unit:w.event.request.length,attribute:$.trace.context||$.trace.store||$.trace.set?"ctx":""})();const _=w.router.static.ws,D=w.router.ws;if(Object.keys(_).length||D.history.length){B+=`
356
357
  if(request.method === 'GET') {
357
- switch(path) {`;for(let[Q,K]of Object.entries(_))B+=`
358
+ switch(path) {`;for(let[Q,j]of Object.entries(_))B+=`
358
359
  case '${Q}':
359
360
  if(request.headers.get('upgrade') === 'websocket')
360
- return st${K}(ctx)
361
+ return st${j}(ctx)
361
362
 
362
363
  break`;B+=`
363
364
  default:
@@ -381,8 +382,8 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
381
382
  break
382
383
  }
383
384
 
384
- ${Z}
385
- }`;const P=P1(w);return w.handleError=P,Function("data",B)({app:w,mapEarlyResponse:f,NotFoundError:R0,getReporter:()=>w.reporter,requestId:_w,handleError:P,error:_1,redirect:q0})},P1=(w)=>{let $=`const {
385
+ ${W}
386
+ }`;const P=P1(w);return w.handleError=P,Function("data",B)({app:w,mapEarlyResponse:k,NotFoundError:Z0,getReporter:()=>w.reporter,requestId:_w,handleError:P,error:_1,redirect:I0})},P1=(w)=>{let $=`const {
386
387
  app: { event: { error: onErrorContainer, onResponse: resContainer } },
387
388
  mapResponse,
388
389
  ERROR_CODE,
@@ -403,7 +404,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
403
404
  if(typeof error === "object" && ELYSIA_RESPONSE in error) {
404
405
  error.status = error[ELYSIA_RESPONSE]
405
406
  error.message = error.response
406
- }\n`;for(let J=0;J<w.event.error.length;J++){const B=w.event.error[J],S=`${x(B)?"await ":""}onError[${J}](context)`;if($+="\nif(skipGlobal !== true) {\n",L0(B.fn.toString()))$+=`r = ${S}; if(r !== undefined) {
407
+ }\n`;for(let J=0;J<w.event.error.length;J++){const B=w.event.error[J],R=`${x(B)?"await ":""}onError[${J}](context)`;if($+="\nif(skipGlobal !== true) {\n",L0(B.fn.toString()))$+=`r = ${R}; if(r !== undefined) {
407
408
  if(r instanceof Response) return r
408
409
 
409
410
  if(r[ELYSIA_RESPONSE]) {
@@ -413,7 +414,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
413
414
 
414
415
  if(set.status === 200) set.status = error.status
415
416
  return mapResponse(r, set, context.request)
416
- }\n`;else $+=S+"\n";$+="\n}\n"}return $+=`if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") {
417
+ }\n`;else $+=R+"\n";$+="\n}\n"}return $+=`if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") {
417
418
  set.status = error.status ?? 422
418
419
  return new Response(
419
420
  error.message,
@@ -434,9 +435,9 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
434
435
 
435
436
  return mapResponse(error, set, context.request)
436
437
  }
437
- }`,Function("inject",$)({app:w,mapResponse:h,ERROR_CODE:Z0,ELYSIA_RESPONSE:d})},H0=(w)=>`if(stc${w}) return stc${w}(ctx)
438
+ }`,Function("inject",$)({app:w,mapResponse:v,ERROR_CODE:W0,ELYSIA_RESPONSE:d})},H0=(w)=>`if(stc${w}) return stc${w}(ctx)
438
439
  if(st${w}.compose) return (stc${w} = st${w}.compose())(ctx)
439
440
 
440
- return st${w}(ctx)`;var $1=N0(M1(),1);var O1=(w)=>async($)=>{const J=$.url,B=J.indexOf("/",11),S=J.indexOf("?",B+1),X=S===-1?J.substring(B):J.substring(B,S),W={cookie:{},status:200,headers:{}},Z=Object.assign({},w.singleton.decorator,{set:W,store:w.singleton.store,request:$,path:X,qi:S,redirect:q0});try{for(let K=0;K<w.event.request.length;K++){const M=w.event.request[K].fn;let D=M(Z);if(D instanceof Promise)D=await D;if(D=f(D,W),D)return D}const R=w.router.dynamic.find($.method,X)??w.router.dynamic.find("ALL",X);if(!R)throw new R0;const{handle:Y,hooks:G,validator:F,content:j}=R.store;let _;if($.method!=="GET"&&$.method!=="HEAD")if(j)switch(j){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const K=await $.formData();for(let M of K.keys()){if(_[M])continue;const D=K.getAll(M);if(D.length===1)_[M]=D[0];else _[M]=D}break}else{let K=$.headers.get("content-type");if(K){const M=K.indexOf(";");if(M!==-1)K=K.slice(0,M);Z.contentType=K;for(let D=0;D<G.parse.length;D++){const T=G.parse[D].fn;let b=T(Z,K);if(b instanceof Promise)b=await b;if(b){_=b;break}}if(delete Z.contentType,_===void 0)switch(K){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const D=await $.formData();for(let T of D.keys()){if(_[T])continue;const b=D.getAll(T);if(b.length===1)_[T]=b[0];else _[T]=b}break}}}Z.body=_,Z.params=R?.params||void 0,Z.query=S===-1?{}:$1.parse(J.substring(S+1)),Z.headers={};for(let[K,M]of $.headers.entries())Z.headers[K]=M;const C=Object.assign({},w.config?.cookie,F?.cookie?.config),P=$.headers.get("cookie");Z.cookie=await p0(Z.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 K=0;K<G.transform.length;K++){const M=G.transform[K],D=M.fn(Z);if(M.subType==="derive")if(D instanceof Promise)Object.assign(Z,await D);else Object.assign(Z,D);else if(D instanceof Promise)await D}if(F){if(F.headers){const K={};for(let M in $.headers)K[M]=$.headers.get(M);if(F.headers.Check(K)===!1)throw new q("header",F.headers,K)}if(F.params?.Check(Z.params)===!1)throw new q("params",F.params,Z.params);if(F.query?.Check(Z.query)===!1)throw new q("query",F.query,Z.query);if(F.cookie){const K={};for(let[M,D]of Object.entries(Z.cookie))K[M]=D.value;if(F.cookie?.Check(K)===!1)throw new q("cookie",F.cookie,K)}if(F.body?.Check(_)===!1)throw new q("body",F.body,_)}for(let K=0;K<G.beforeHandle.length;K++){let M=G.beforeHandle[K].fn(Z);if(M instanceof Promise)M=await M;if(M!==void 0){Z.response=M;for(let T=0;T<G.afterHandle.length;T++){let b=G.afterHandle[T].fn(Z);if(b instanceof Promise)b=await b;if(b)M=b}const D=f(M,Z.set);if(D)return D}}let Q=Y(Z);if(Q instanceof Promise)Q=await Q;if(!G.afterHandle.length){const K=F?.response?.[Q.status];if(K?.Check(Q)===!1)throw new q("response",K,Q)}else{Z.response=Q;for(let K=0;K<G.afterHandle.length;K++){let M=G.afterHandle[K].fn(Z);if(M instanceof Promise)M=await M;const D=f(M,Z.set);if(D!==void 0){const T=F?.response?.[Q.status];if(T?.Check(D)===!1)throw new q("response",T,D);return D}}}if(Z.set.cookie&&C?.sign){const K=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(Z.set.cookie))Z.set.cookie[M].value=await z0(D.value,"${secret}");else{const M=F?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(Z.set.cookie[D]?.value)Z.set.cookie[D].value=await z0(Z.set.cookie[D].value,K)}}}return h(Q,Z.set)}catch(R){if(R.status)W.status=R.status;return w.handleError(Z,R)}finally{for(let R of w.event.onResponse)await R.fn(Z)}},Dw=(w)=>async($,J)=>{const B=Object.assign($,{error:J,code:J.code});B.set=$.set;for(let S=0;S<w.event.error.length;S++){let W=w.event.error[S].fn(B);if(W instanceof Promise)W=await W;if(W!==void 0&&W!==null)return h(W,$.set)}return new Response(typeof J.cause==="string"?J.cause:J.message,{headers:$.set.headers,status:J.status??500})};import{TypeRegistry as Vw} from"@sinclair/typebox";import{TypeSystem as M0} from"@sinclair/typebox/system";import{Type as x0,FormatRegistry as a} from"@sinclair/typebox";import{Value as D0} from"@sinclair/typebox/value";var U$=function(w){return w%4===0&&(w%100!==0||w%400===0)},Pw=function(w){const $=z$.exec(w);if(!$)return!1;const J=+$[1],B=+$[2],S=+$[3];return B>=1&&B<=12&&S>=1&&S<=(B===2&&U$(J)?29:_$[B])},V1=function(w){return function $(J){const B=C$.exec(J);if(!B)return!1;const S=+B[1],X=+B[2],W=+B[3],Z=B[4],R=B[5]==="-"?-1:1,Y=+(B[6]||0),G=+(B[7]||0);if(Y>23||G>59||w&&!Z)return!1;if(S<=23&&X<=59&&W<60)return!0;const F=X-G*R,j=S-Y*R-(F<0?1:0);return(j===23||j===-1)&&(F===59||F===-1)&&W<61}},Mw=function(w){const $=V1(w);return function J(B){const S=B.split(D$);return S.length===2&&Pw(S[0])&&$(S[1])}},N$=function(w){return M$.test(w)&&A$.test(w)},P$=function(w){return Aw.lastIndex=0,Aw.test(w)},b$=function(w){return Number.isInteger(w)&&w<=V$&&w>=O$},q$=function(w){return Number.isInteger(w)},Nw=function(){return!0},T$=function(w){if(I$.test(w))return!1;try{return new RegExp(w),!0}catch($){return!1}},J1={date:Pw,time:V1(!0),"date-time":Mw(!0),"iso-time":V1(!1),"iso-date-time":Mw(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:N$,"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:T$,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:P$,int32:{type:"number",validate:b$},int64:{type:"number",validate:q$},float:{type:"number",validate:Nw},double:{type:"number",validate:Nw},password:!0,binary:!0},z$=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,_$=[0,31,28,31,30,31,30,31,31,30,31,30,31],C$=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,D$=/t|\s/i,M$=/\/|:/,A$=/^(?:[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,Aw=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,O$=-2147483648,V$=2147483647,I$=/[^\\]\\Z/;import{TypeSystemPolicy as aJ,TypeSystem as oJ,TypeSystemDuplicateFormat as eJ,TypeSystemDuplicateTypeKind as wB} from"@sinclair/typebox/system";import{TypeCompiler as JB,TypeCheck as BB} from"@sinclair/typebox/compiler";var bw=/(\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))/,qw=/(?: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\([^)]+\)/,Iw=/^(?:(?:(?:(?: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)?)?$/,E$=J1.date,L$=J1["date-time"];if(!a.Has("date"))M0.Format("date",(w)=>{const $=w.replace(/"/g,"");if(bw.test($)||qw.test($)||Iw.test($)||E$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});if(!a.Has("date-time"))M0.Format("date-time",(w)=>{const $=w.replace(/"/g,"");if(bw.test($)||qw.test($)||Iw.test($)||L$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});Object.entries(J1).forEach((w)=>{const[$,J]=w;if(!a.Has($)){if(J instanceof RegExp)M0.Format($,(B)=>J.test(B));else if(typeof J==="function")M0.Format($,J)}});var V=Object.assign({},x0),Ow=(w)=>{if(typeof w==="string")switch(w.slice(-1)){case"k":return+w.slice(0,w.length-1)*1024;case"m":return+w.slice(0,w.length-1)*1048576;default:return+w}return w},b1=(w,$)=>{if(!($ instanceof Blob))return!1;if(w.minSize&&$.size<Ow(w.minSize))return!1;if(w.maxSize&&$.size>Ow(w.maxSize))return!1;if(w.extension)if(typeof w.extension==="string"){if(!$.type.startsWith(w.extension))return!1}else{for(let J=0;J<w.extension.length;J++)if($.type.startsWith(w.extension[J]))return!0;return!1}return!0},H$=Vw.Get("Files")??M0.Type("File",b1),x$=Vw.Get("Files")??M0.Type("Files",(w,$)=>{if(!Array.isArray($))return b1(w,$);if(w.minItems&&$.length<w.minItems)return!1;if(w.maxItems&&$.length>w.maxItems)return!1;for(let J=0;J<$.length;J++)if(!b1(w,$[J]))return!1;return!0});if(!a.Has("numeric"))a.Set("numeric",(w)=>!!w&&!isNaN(+w));if(!a.Has("boolean"))a.Set("boolean",(w)=>w==="true"||w==="false");if(!a.Has("ObjectString"))a.Set("ObjectString",(w)=>{let $=w.charCodeAt(0);if($===9||$===10||$===32)$=w.trimStart().charCodeAt(0);if($!==123&&$!==91)return!1;try{return JSON.parse(w),!0}catch{return!1}});var o={Numeric:(w)=>{const $=x0.Number(w);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number(w)],w)).Decode((J)=>{const B=+J;if(isNaN(B))return J;if(w&&!D0.Check($,B))throw new q("property",$,B);return B}).Encode((J)=>J)},Date:(w)=>{const $=x0.Date(w);return V.Transform(V.Union([x0.Date(w),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],w)).Decode((J)=>{if(J instanceof Date)return J;const B=new Date(J);if(!D0.Check($,B))throw new q("property",$,B);return B}).Encode((J)=>{if(typeof J==="string")return new Date(J);return J})},BooleanString:(w)=>{const $=x0.Boolean(w);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean(w)],w)).Decode((J)=>{if(typeof J==="string")return J==="true";if(w&&!D0.Check($,J))throw new q("property",$,J);return J}).Encode((J)=>J)},ObjectString:(w={},$)=>{const J=V.Object(w,$),B=JSON.stringify(D0.Create(J));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),J])).Decode((S)=>{if(typeof S==="string"){try{S=JSON.parse(S)}catch{throw new q("property",J,S)}if(!D0.Check(J,S))throw new q("property",J,S);return S}return S}).Encode((S)=>{if(typeof S==="string")try{S=JSON.parse(S)}catch{throw new q("property",J,S)}if(!D0.Check(J,S))throw new q("property",J,S);return JSON.stringify(S)})},File:H$,Files:(w={})=>V.Transform(x$(w)).Decode(($)=>{if(Array.isArray($))return $;return[$]}).Encode(($)=>$),Nullable:(w)=>V.Union([V.Null(),w]),MaybeEmpty:(w)=>V.Union([V.Null(),V.Undefined(),w]),Cookie:(w,{domain:$,expires:J,httpOnly:B,maxAge:S,path:X,priority:W,sameSite:Z,secure:R,secrets:Y,sign:G,...F}={})=>{const j=V.Object(w,F);return j.config={domain:$,expires:J,httpOnly:B,maxAge:S,path:X,priority:W,sameSite:Z,secure:R,secrets:Y,sign:G},j}};V.BooleanString=o.BooleanString;V.ObjectString=o.ObjectString;V.Numeric=o.Numeric;V.File=(w={})=>o.File({default:"File",...w,extension:w?.type,type:"string",format:"binary"});V.Files=(w={})=>o.Files({...w,elysiaMeta:"Files",default:"Files",extension:w?.type,type:"array",items:{...w,default:"Files",type:"string",format:"binary"}});V.Nullable=(w)=>o.Nullable(w);V.MaybeEmpty=o.MaybeEmpty;V.Cookie=o.Cookie;V.Date=o.Date;class p{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 z1;constructor(w){if(w?.tags)if(!w.detail)w.detail={tags:w.tags};else w.detail.tags=w.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{path:"/"},analytic:!1,...w,experimental:w?.experimental??{},seed:w?.seed===void 0?"":w?.seed},w?.analytic&&(w?.name||w?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro(w){if(this.extender.macros.length){const $=o1({globalHook:this.event,localHook:w}),J={events:{global:this.event,local:w},onParse:$("parse"),onTransform:$("transform"),onBeforeHandle:$("beforeHandle"),onAfterHandle:$("afterHandle"),onResponse:$("onResponse"),mapResponse:$("mapResponse"),onError:$("error")};for(let B of this.extender.macros)U1(B.fn(J),w)}}add(w,$,J,B,{allowMeta:S=!1,skipPrefix:X=!1}={allowMeta:!1,skipPrefix:!1}){if(B=e1(B),$!==""&&$.charCodeAt(0)!==47)$="/"+$;if(this.config.prefix&&!X&&!this.config.scoped)$=this.config.prefix+$;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 W=this.definitions.type;let Z,R,Y,G,F,j;const _=!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?i0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:_,models:W}):void 0,Q=this.config.normalize,K=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:_,models:W,normalize:Q}),headers:k(C.headers,{dynamic:_,models:W,additionalProperties:!0}),params:k(C.params,{dynamic:_,models:W}),query:k(C.query,{dynamic:_,models:W,normalize:Q}),cookie:P(),response:l0(C.response,{dynamic:_,models:W,normalize:Q})}:{get body(){if(Z)return Z;return Z=k(C.body,{dynamic:_,models:W,normalize:Q})},get headers(){if(R)return R;return k(C.headers,{dynamic:_,models:W,additionalProperties:!0})},get params(){if(Y)return Y;return Y=k(C.params,{dynamic:_,models:W})},get query(){if(G)return G;return G=k(C.query,{dynamic:_,models:W})},get cookie(){if(F)return F;return F=P()},get response(){if(j)return j;return j=l0(C.response,{dynamic:_,models:W,normalize:Q})}},M=$.endsWith("/")?$.slice(0,$.length-1):$+"/";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=s(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(w,$,{validator:K,hooks:D,content:B?.type,handle:J}),this.config.strictPath===!1)this.router.dynamic.add(w,M,{validator:K,hooks:D,content:B?.type,handle:J});this.router.history.push({method:w,path:$,composed:null,handler:J,hooks:D});return}let T=void 0;const b=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=n0(this.inference),v=b?w1({app:this,path:$,method:w,localHook:u(B),hooks:D,validator:K,handler:J,allowMeta:S,appInference:e}):(N)=>{if(T)return T(N);return(T=w1({app:this,path:$,method:w,localHook:u(B),hooks:D,validator:K,handler:J,allowMeta:S,appInference:e}))(N)};if(!b)v.compose=()=>{return v.composed=w1({app:this,path:$,method:w,localHook:u(B),hooks:D,validator:K,handler:J,allowMeta:S,appInference:e})};let l=this.router.history.length;if(this.routeTree.has(w+$)){if(l=this.router.history.findIndex((N)=>N.path===$&&N.method===w),l!==-1){const N=this.router.history.splice(l,1)[0];if(N&&this.routeTree.has(N?.method+N?.path))this.routeTree.delete(N.method+N.path)}}this.routeTree.set(w+$,l),this.router.history.push({method:w,path:$,composed:v,handler:J,hooks:D});const O=this.router.static.http;if(w==="$INTERNALWS"){const N=this.config.strictPath?void 0:$.endsWith("/")?$.slice(0,$.length-1):$+"/";if($.indexOf(":")===-1&&$.indexOf("*")===-1){const w0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${w0} = staticRouter.handlers[${w0}]\n`,this.router.static.ws[$]=w0,N)this.router.static.ws[N]=w0}else if(this.router.ws.add("ws",$,v),N)this.router.ws.add("ws",N,v);return}if($.indexOf(":")===-1&&$.indexOf("*")===-1){const N=O.handlers.length;if(O.handlers.push(v),O.variables+=b?`const st${N} = staticRouter.handlers[${N}]\n`:`let st${N} = staticRouter.handlers[${N}]\nlet stc${N}\n`,!O.map[$])O.map[$]={code:""};if(w==="ALL")O.map[$].all=b?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[$].code=b?`case '${w}': return st${N}(ctx)\n${O.map[$].code}`:`case '${w}': ${H0(N)}\n${O.map[$].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if(w==="ALL")O.map[M].all=b?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[M].code=b?`case '${w}': return st${N}(ctx)\n${O.map[M].code}`:`case '${w}': ${H0(N)}\n${O.map[M].code}`}}else if(this.router.http.add(w,$,v),!this.config.strictPath)this.router.http.add(w,$.endsWith("/")?$.slice(0,$.length-1):$+"/",v)}setHeaders;headers(w){if(!w)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=s(this.setHeaders,w),this}onStart(w){return this.on("start",w),this}onRequest(w){return this.on("request",w),this}onParse(w,$){if(!$)return this.on("parse",w);return this.on(w,"parse",$)}onTransform(w,$){if(!$)return this.on("transform",w);return this.on(w,"transform",$)}resolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}mapResolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}onBeforeHandle(w,$){if(!$)return this.on("beforeHandle",w);return this.on(w,"beforeHandle",$)}onAfterHandle(w,$){if(!$)return this.on("afterHandle",w);return this.on(w,"afterHandle",$)}mapResponse(w,$){if(!$)return this.on("mapResponse",w);return this.on(w,"mapResponse",$)}onResponse(w,$){if(!$)return this.on("response",w);return this.on(w,"response",$)}trace(w,$){if(!$)$=w,w={as:"local"};if(!Array.isArray($))$=[$];for(let J of $)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,J));return this.on(w,"trace",$),this}error(w,$){switch(typeof w){case"string":return $.prototype[Z0]=w,this.definitions.error[w]=$,this;case"function":return this.definitions.error=w(this.definitions.error),this}for(let[J,B]of Object.entries(w))B.prototype[Z0]=J,this.definitions.error[J]=B;return this}onError(w,$){if(!$)return this.on("error",w);return this.on(w,"error",$)}onStop(w){return this.on("stop",w),this}on(w,$,J){let B;switch(typeof w){case"string":B=w,J=$;break;case"object":B=$;break}if(B==="response")B="onResponse";if(Array.isArray(J))J=c(J);else if(typeof J==="function")J=[{fn:J}];else J=[J];const S=J;for(let X of S)X.scope=typeof w==="string"?"local":w?.as??"local";if(B==="trace")h1(S.map((X)=>X.fn),this.inference.trace);else d0({[B]:S.map((X)=>X.fn)},this.inference.event);for(let X of S){const W=a1(X,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(W);break;case"request":this.event.request.push(W);break;case"parse":this.event.parse.push(W);break;case"transform":this.event.transform.push(W);break;case"beforeHandle":this.event.beforeHandle.push(W);break;case"afterHandle":this.event.afterHandle.push(W);break;case"mapResponse":this.event.mapResponse.push(W);break;case"onResponse":this.event.onResponse.push(W);break;case"trace":this.event.trace.push(W);break;case"error":this.event.error.push(W);break;case"stop":this.event.stop.push(W);break}}return this}propagate(){const w=($)=>{for(let J of $)if("scope"in J&&J.scope==="local")J.scope="scoped"};return w(this.event.parse),w(this.event.transform),w(this.event.beforeHandle),w(this.event.afterHandle),w(this.event.mapResponse),w(this.event.onResponse),w(this.event.trace),w(this.event.error),this}group(w,$,J){const B=new p({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=n0(this.inference),B.extender={...this.extender};const S=typeof $==="object",X=(S?J:$)(B);if(this.singleton=s(this.singleton,B.singleton),this.definitions=s(this.definitions,B.definitions),X.event.request.length)this.event.request=[...this.event.request||[],...X.event.request||[]];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...X.event.onResponse||[]];return this.model(X.definitions.type),Object.values(B.router.history).forEach(({method:W,path:Z,handler:R,hooks:Y})=>{if(Z=(S?"":this.config.prefix)+w+Z,S){const G=$,F=Y;this.add(W,Z,R,u(G,{...F||{},error:!F.error?X.event.error:Array.isArray(F.error)?[...F.error||{},...X.event.error||{}]:[F.error,...X.event.error||{}]}))}else this.add(W,Z,R,u(Y,{error:X.event.error}),{skipPrefix:!0})}),this}guard(w,$){if(!$){if(typeof w==="object"){if(this.applyMacro(w),this.event=t0(this.event,w),this.validator={body:w.body??this.validator?.body,headers:w.headers??this.validator?.headers,params:w.params??this.validator?.params,query:w.query??this.validator?.query,response:w.response??this.validator?.response,cookie:w.cookie??this.validator?.cookie},w.detail)if(this.config.detail)this.config.detail=s(Object.assign({},this.config.detail),w.detail);else this.config.detail=w.detail;if(w?.tags)if(!this.config.detail)this.config.detail={tags:w.tags};else this.config.detail.tags=w.tags;return this}return this.guard({},w)}const J=new p({...this.config,prefix:""});J.singleton={...this.singleton},J.definitions={...this.definitions},J.inference=n0(this.inference),J.extender={...this.extender};const B=$(J);if(this.singleton=s(this.singleton,J.singleton),this.definitions=s(this.definitions,J.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(J.router.history).forEach(({method:S,path:X,handler:W,hooks:Z})=>{this.add(S,X,W,u(w,{...Z||{},error:!Z.error?B.event.error:Array.isArray(Z.error)?[...Z.error||{},...B.event.error||[]]:[Z.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use(w,$){if($?.scoped)return this.guard({},(J)=>J.use(w));if(Array.isArray(w)){let J=this;for(let B of w)J=this.use(B);return J}if(w instanceof Promise)return this.promisedModules.add(w.then((J)=>{if(typeof J==="function")return J(this);if(J instanceof p)return this._use(J);if(typeof J.default==="function")return J.default(this);if(J.default instanceof p)return this._use(J.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((J)=>J.compile())),this;return this._use(w)}_use(w){if(typeof w==="function"){const S=w(this);if(S instanceof Promise)return this.promisedModules.add(S.then((X)=>{if(X instanceof p){this.compile();for(let{method:W,path:Z,handler:R,hooks:Y}of Object.values(X.router.history))this.add(W,Z,R,u(Y,{error:X.event.error}));return X}if(typeof X==="function")return X(this);if(typeof X.default==="function")return X.default(this);return this._use(X)}).then((X)=>X.compile())),this;return S}if(w.promisedModules.size)return this.promisedModules.add(w.modules.then(()=>this._use(w)).then((S)=>S.compile())),this;const{name:$,seed:J}=w.config;w.getServer=()=>this.getServer(),w.model(this.definitions.type),w.error(this.definitions.error);const B=w.config.scoped;if(B){if($){if(!($ in this.dependencies))this.dependencies[$]=[];const X=J!==void 0?b0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:W})=>X===W))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:X,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:X,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton.decorator,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((W)=>W.subType==="derive").map((W)=>({fn:W.fn.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((W)=>W.subType==="derive").map((W)=>({fn:W.fn.toString(),stack:new Error().stack??""}))})}w.extender.macros=this.extender.macros.concat(w.extender.macros);const S=[];for(let X=0;X<w.extender.macros.length;X++){const W=this.extender.macros[X];if(S.includes(W.checksum))w.extender.macros.splice(X,1),X--;S.push(W.checksum)}if(w.onRequest((X)=>{Object.assign(X,this.singleton.decorator),Object.assign(X.store,this.singleton.store)}),w.event.trace.length)w.event.trace.push(...w.event.trace);if(!w.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if(w.event.error.length)w.event.error.push(...this.event.error);if(w.config.aot)w.compile();if(B===!0&&w.config.prefix){this.mount(w.config.prefix+"/",w.fetch);for(let X of w.router.history)this.routeTree.set(X.method+`${w.config.prefix}${X.path}`,this.router.history.length),this.router.history.push({...X,path:`${w.config.prefix}${X.path}`,hooks:u(X.hooks,{error:this.event.error})})}else{this.mount(w.fetch);for(let X of w.router.history)this.routeTree.set(X.method+`${w.config.prefix}${X.path}`,this.router.history.length),this.router.history.push({...X,path:`${w.config.prefix}${X.path}`,hooks:u(X.hooks,{error:this.event.error})})}return this}else{this.headers(w.setHeaders),w.reporter=this.reporter;for(let X of w.event.trace)if(X.scope&&X.scope!=="local")this.trace(X);if($){if(!($ in this.dependencies))this.dependencies[$]=[];const X=J!==void 0?b0($+JSON.stringify(J)):0;if(!this.dependencies[$].some(({checksum:W})=>X===W))this.extender.macros=this.extender.macros.concat(w.extender.macros)}else this.extender.macros=this.extender.macros.concat(w.extender.macros);const S=[];for(let X=0;X<this.extender.macros.length;X++){const W=this.extender.macros[X];if(W.checksum){if(S.includes(W.checksum))this.extender.macros.splice(X,1),X--;S.push(W.checksum)}}this.inference={event:{body:this.inference.event.body||w.inference.event.body,cookie:this.inference.event.cookie||w.inference.event.cookie,headers:this.inference.event.headers||w.inference.event.headers,queries:[...this.inference.event.queries,...w.inference.event.queries],query:this.inference.event.query||w.inference.event.query,set:this.inference.event.set||w.inference.event.set,unknownQueries:this.inference.event.unknownQueries||w.inference.event.unknownQueries},trace:{request:this.inference.trace.request||w.inference.trace.request,parse:this.inference.trace.parse||w.inference.trace.parse,transform:this.inference.trace.transform||w.inference.trace.transform,handle:this.inference.trace.handle||w.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||w.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||w.inference.trace.afterHandle,error:this.inference.trace.error||w.inference.trace.error,context:this.inference.trace.context||w.inference.trace.context,store:this.inference.trace.store||w.inference.trace.store,set:this.inference.trace.set||w.inference.trace.set}}}this.decorate(w.singleton.decorator),this.state(w.singleton.store),this.model(w.definitions.type),this.error(w.definitions.error);for(let{method:S,path:X,handler:W,hooks:Z}of Object.values(w.router.history))this.add(S,X,W,u(Z,{error:w.event.error}));if(!B)if($){if(!($ in this.dependencies))this.dependencies[$]=[];const S=J!==void 0?b0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:X})=>S===X))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((X)=>X?.subType==="derive").map((X)=>({fn:X.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((X)=>X?.subType==="resolve").map((X)=>({fn:X.toString(),stack:new Error().stack??""}))}),this.event=t0(this.event,j1(w.event),S)}else this.event=t0(this.event,j1(w.event));return this}macro(w){const $={checksum:b0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:w.toString()})),fn:w};return this.extender.macros.push($),this}mount(w,$){if(w instanceof p||typeof w==="function"||w.length===0||w==="/"){const S=typeof w==="function"?w:w instanceof p?w.compile().fetch:$ instanceof p?$.compile().fetch:$,X=async({request:W,path:Z})=>S(new Request(K1(W.url,Z||"/"),W));return this.all("/*",X,{type:"none"}),this}const J=w.length;if($ instanceof p)$=$.compile().fetch;const B=async({request:S,path:X})=>$(new Request(K1(S.url,X.slice(J)||"/"),S));return this.all(w,B,{type:"none"}),this.all(w+(w.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get(w,$,J){return this.add("GET",w,$,J),this}post(w,$,J){return this.add("POST",w,$,J),this}put(w,$,J){return this.add("PUT",w,$,J),this}patch(w,$,J){return this.add("PATCH",w,$,J),this}delete(w,$,J){return this.add("DELETE",w,$,J),this}options(w,$,J){return this.add("OPTIONS",w,$,J),this}all(w,$,J){return this.add("ALL",w,$,J),this}head(w,$,J){return this.add("HEAD",w,$,J),this}connect(w,$,J){return this.add("CONNECT",w,$,J),this}route(w,$,J,B){return this.add(w.toUpperCase(),$,J,B,B?.config),this}ws(w,$){const J=$.transformMessage?Array.isArray($.transformMessage)?$.transformMessage:[$.transformMessage]:void 0;let B=null;const S=k($?.body,{models:this.definitions.type,normalize:this.config.normalize}),X=k($?.response,{models:this.definitions.type,normalize:this.config.normalize}),W=(Z)=>{if(typeof Z==="string"){const R=Z?.charCodeAt(0);if(R===47||R===123)try{Z=JSON.parse(Z)}catch{}else if(j0(Z))Z=+Z}if(J?.length)for(let R=0;R<J.length;R++){const Y=J[R](Z);if(Y!==void 0)Z=Y}return Z};return this.route("$INTERNALWS",w,(Z)=>{const{set:R,path:Y,qi:G,headers:F,query:j,params:_}=Z;if(B===null)B=this.getServer();if(B?.upgrade(Z.request,{headers:typeof $.upgrade==="function"?$.upgrade(Z):$.upgrade,data:{validator:X,open(C){$.open?.(new _0(C,Z))},message:(C,P)=>{const Q=W(P);if(S?.Check(Q)===!1)return void C.send(new q("message",S,Q).message);$.message?.(new _0(C,Z),Q)},drain(C){$.drain?.(new _0(C,Z))},close(C,P,Q){$.close?.(new _0(C,Z),P,Q)}}}))return;return R.status=400,"Expected a websocket connection"},{beforeHandle:$.beforeHandle,transform:$.transform,headers:$.headers,params:$.params,query:$.query}),this}state(w,$){switch(typeof w){case"object":return this.singleton.store=s(this.singleton.store,w),this;case"function":return this.singleton.store=w(this.singleton.store),this}if(!(w in this.singleton.store))this.singleton.store[w]=$;return this}decorate(w,$){switch(typeof w){case"object":return this.singleton.decorator=s(this.singleton.decorator,w),this;case"function":return this.singleton.decorator=w(this.singleton.decorator),this}if(!(w in this.singleton.decorator))this.singleton.decorator[w]=$;return this}derive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}model(w,$){switch(typeof w){case"object":return Object.entries(w).forEach(([J,B])=>{if(!(J in this.definitions.type))this.definitions.type[J]=B}),this;case"function":return this.definitions.type=w(this.definitions.type),this}return this.definitions.type[w]=$,this}mapDerive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}affix(w,$,J){if(J==="")return this;const B=["_","-"," "],S=(R)=>R[0].toUpperCase()+R.slice(1),X=w==="prefix"?(R,Y)=>B.includes(R.at(-1)??"")?R+Y:R+S(Y):B.includes(J.at(-1)??"")?(R,Y)=>Y+R:(R,Y)=>Y+S(R),W=(R)=>{const Y={};switch(R){case"decorator":for(let G in this.singleton.decorator)Y[X(J,G)]=this.singleton.decorator[G];this.singleton.decorator=Y;break;case"state":for(let G in this.singleton.store)Y[X(J,G)]=this.singleton.store[G];this.singleton.store=Y;break;case"model":for(let G in this.definitions.type)Y[X(J,G)]=this.definitions.type[G];this.definitions.type=Y;break;case"error":for(let G in this.definitions.error)Y[X(J,G)]=this.definitions.error[G];this.definitions.error=Y;break}},Z=Array.isArray($)?$:[$];for(let R of Z.some((Y)=>Y==="all")?["decorator","state","model","error"]:Z)W(R);return this}prefix(w,$){return this.affix("prefix",w,$)}suffix(w,$){return this.affix("suffix",w,$)}compile(){if(this.fetch=this.config.aot?N1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async(w)=>this.fetch(w);fetch=(w)=>{return(this.fetch=this.config.aot?N1(this):O1(this))(w)};handleError=async(w,$)=>(this.handleError=this.config.aot?P1(this):Dw(this))(w,$);outerErrorHandler=(w)=>new Response(w.message||w.name||"Error",{status:w?.status??500});listen=(w,$)=>{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 w==="string"){if(!j0(w))throw new Error("Port must be a numeric value");w=parseInt(w)}const J=this.fetch,B=typeof w==="object"?{development:!I0,reusePort:!0,...this.config.serve||{},...w||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:J,error:this.outerErrorHandler}:{development:!I0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:w,fetch:J,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let S=0;S<this.event.start.length;S++)this.event.start[S].fn(this);if($)$(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let S=0;S<this.event.stop.length;S++)this.event.stop[S].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 w=0;w<this.event.stop.length;w++)this.event.stop[w].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,q0 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,l0 as getResponseSchemaValidator,S0 as form,_1 as error,p as default,q as ValidationError,X0 as StatusMap,e0 as ParseError,R0 as NotFoundError,r0 as InvertedStatusMap,O0 as InvalidCookieSignature,o0 as InternalServerError,p as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
441
+ return st${w}(ctx)`;var $1=P0(M1(),1);var O1=(w)=>async($)=>{const J=$.url,B=J.indexOf("/",11),R=J.indexOf("?",B+1),S=R===-1?J.substring(B):J.substring(B,R),X={cookie:{},status:200,headers:{}},W=Object.assign({},w.singleton.decorator,{set:X,store:w.singleton.store,request:$,path:S,qi:R,redirect:I0});try{for(let j=0;j<w.event.request.length;j++){const A=w.event.request[j].fn;let M=A(W);if(M instanceof Promise)M=await M;if(M=k(M,X),M)return M}const Z=w.router.dynamic.find($.method,S)??w.router.dynamic.find("ALL",S);if(!Z)throw new Z0;const{handle:Y,hooks:G,validator:F,content:U}=Z.store;let _;if($.method!=="GET"&&$.method!=="HEAD")if(U)switch(U){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const j=await $.formData();for(let A of j.keys()){if(_[A])continue;const M=j.getAll(A);if(M.length===1)_[A]=M[0];else _[A]=M}break}else{let j=$.headers.get("content-type");if(j){const A=j.indexOf(";");if(A!==-1)j=j.slice(0,A);W.contentType=j;for(let M=0;M<G.parse.length;M++){const T=G.parse[M].fn;let V=T(W,j);if(V instanceof Promise)V=await V;if(V){_=V;break}}if(delete W.contentType,_===void 0)switch(j){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const M=await $.formData();for(let T of M.keys()){if(_[T])continue;const V=M.getAll(T);if(V.length===1)_[T]=V[0];else _[T]=V}break}}}W.body=_,W.params=Z?.params||void 0,W.query=R===-1?{}:$1.parse(J.substring(R+1)),W.headers={};for(let[j,A]of $.headers.entries())W.headers[j]=A;const D=Object.assign({},w.config?.cookie,F?.cookie?.config),P=$.headers.get("cookie");W.cookie=await p0(W.set,P,D?{secrets:D.secrets!==void 0?typeof D.secrets==="string"?D.secrets:D.secrets.join(","):void 0,sign:D.sign===!0?!0:D.sign!==void 0?typeof D.sign==="string"?D.sign:D.sign.join(","):void 0}:void 0);for(let j=0;j<G.transform.length;j++){const A=G.transform[j],M=A.fn(W);if(A.subType==="derive")if(M instanceof Promise)Object.assign(W,await M);else Object.assign(W,M);else if(M instanceof Promise)await M}if(F){if(F.headers){const j={};for(let A in $.headers)j[A]=$.headers.get(A);if(F.headers.Check(j)===!1)throw new I("header",F.headers,j)}if(F.params?.Check(W.params)===!1)throw new I("params",F.params,W.params);if(F.query?.Check(W.query)===!1)throw new I("query",F.query,W.query);if(F.cookie){const j={};for(let[A,M]of Object.entries(W.cookie))j[A]=M.value;if(F.cookie?.Check(j)===!1)throw new I("cookie",F.cookie,j)}if(F.body?.Check(_)===!1)throw new I("body",F.body,_)}for(let j=0;j<G.beforeHandle.length;j++){let A=G.beforeHandle[j].fn(W);if(A instanceof Promise)A=await A;if(A!==void 0){W.response=A;for(let T=0;T<G.afterHandle.length;T++){let V=G.afterHandle[T].fn(W);if(V instanceof Promise)V=await V;if(V)A=V}const M=k(A,W.set);if(M)return M}}let Q=Y(W);if(Q instanceof Promise)Q=await Q;if(!G.afterHandle.length){const j=F?.response?.[Q.status];if(j?.Check(Q)===!1)throw new I("response",j,Q)}else{W.response=Q;for(let j=0;j<G.afterHandle.length;j++){let A=G.afterHandle[j].fn(W);if(A instanceof Promise)A=await A;const M=k(A,W.set);if(M!==void 0){const T=F?.response?.[Q.status];if(T?.Check(M)===!1)throw new I("response",T,M);return M}}}if(W.set.cookie&&D?.sign){const j=!D.secrets?void 0:typeof D.secrets==="string"?D.secrets:D.secrets[0];if(D.sign===!0)for(let[A,M]of Object.entries(W.set.cookie))W.set.cookie[A].value=await z0(M.value,"${secret}");else{const A=F?.cookie?.schema?.properties;for(let M of D.sign){if(!(M in A))continue;if(W.set.cookie[M]?.value)W.set.cookie[M].value=await z0(W.set.cookie[M].value,j)}}}return v(Q,W.set)}catch(Z){if(Z.status)X.status=Z.status;return w.handleError(W,Z)}finally{for(let Z of w.event.onResponse)await Z.fn(W)}},Dw=(w)=>async($,J)=>{const B=Object.assign($,{error:J,code:J.code});B.set=$.set;for(let R=0;R<w.event.error.length;R++){let X=w.event.error[R].fn(B);if(X instanceof Promise)X=await X;if(X!==void 0&&X!==null)return v(X,$.set)}return new Response(typeof J.cause==="string"?J.cause:J.message,{headers:$.set.headers,status:J.status??500})};import{TypeRegistry as bw} from"@sinclair/typebox";import{TypeSystem as A0} from"@sinclair/typebox/system";import{Type as x0,FormatRegistry as o} from"@sinclair/typebox";import{Value as M0} from"@sinclair/typebox/value";var U$=function(w){return w%4===0&&(w%100!==0||w%400===0)},Pw=function(w){const $=z$.exec(w);if(!$)return!1;const J=+$[1],B=+$[2],R=+$[3];return B>=1&&B<=12&&R>=1&&R<=(B===2&&U$(J)?29:_$[B])},b1=function(w){return function $(J){const B=C$.exec(J);if(!B)return!1;const R=+B[1],S=+B[2],X=+B[3],W=B[4],Z=B[5]==="-"?-1:1,Y=+(B[6]||0),G=+(B[7]||0);if(Y>23||G>59||w&&!W)return!1;if(R<=23&&S<=59&&X<60)return!0;const F=S-G*Z,U=R-Y*Z-(F<0?1:0);return(U===23||U===-1)&&(F===59||F===-1)&&X<61}},Mw=function(w){const $=b1(w);return function J(B){const R=B.split(D$);return R.length===2&&Pw(R[0])&&$(R[1])}},N$=function(w){return M$.test(w)&&A$.test(w)},P$=function(w){return Aw.lastIndex=0,Aw.test(w)},V$=function(w){return Number.isInteger(w)&&w<=b$&&w>=O$},q$=function(w){return Number.isInteger(w)},Nw=function(){return!0},T$=function(w){if(I$.test(w))return!1;try{return new RegExp(w),!0}catch($){return!1}},J1={date:Pw,time:b1(!0),"date-time":Mw(!0),"iso-time":b1(!1),"iso-date-time":Mw(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:N$,"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:T$,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:P$,int32:{type:"number",validate:V$},int64:{type:"number",validate:q$},float:{type:"number",validate:Nw},double:{type:"number",validate:Nw},password:!0,binary:!0},z$=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,_$=[0,31,28,31,30,31,30,31,31,30,31,30,31],C$=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,D$=/t|\s/i,M$=/\/|:/,A$=/^(?:[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,Aw=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,O$=-2147483648,b$=2147483647,I$=/[^\\]\\Z/;import{TypeSystemPolicy as oJ,TypeSystem as aJ,TypeSystemDuplicateFormat as eJ,TypeSystemDuplicateTypeKind as wB} from"@sinclair/typebox/system";import{TypeCompiler as JB,TypeCheck as BB} from"@sinclair/typebox/compiler";var Vw=/(\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))/,qw=/(?: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\([^)]+\)/,Iw=/^(?:(?:(?:(?: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)?)?$/,E$=J1.date,L$=J1["date-time"];if(!o.Has("date"))A0.Format("date",(w)=>{const $=w.replace(/"/g,"");if(Vw.test($)||qw.test($)||Iw.test($)||E$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});if(!o.Has("date-time"))A0.Format("date-time",(w)=>{const $=w.replace(/"/g,"");if(Vw.test($)||qw.test($)||Iw.test($)||L$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});Object.entries(J1).forEach((w)=>{const[$,J]=w;if(!o.Has($)){if(J instanceof RegExp)A0.Format($,(B)=>J.test(B));else if(typeof J==="function")A0.Format($,J)}});var b=Object.assign({},x0),Ow=(w)=>{if(typeof w==="string")switch(w.slice(-1)){case"k":return+w.slice(0,w.length-1)*1024;case"m":return+w.slice(0,w.length-1)*1048576;default:return+w}return w},V1=(w,$)=>{if(!($ instanceof Blob))return!1;if(w.minSize&&$.size<Ow(w.minSize))return!1;if(w.maxSize&&$.size>Ow(w.maxSize))return!1;if(w.extension)if(typeof w.extension==="string"){if(!$.type.startsWith(w.extension))return!1}else{for(let J=0;J<w.extension.length;J++)if($.type.startsWith(w.extension[J]))return!0;return!1}return!0},H$=bw.Get("Files")??A0.Type("File",V1),x$=bw.Get("Files")??A0.Type("Files",(w,$)=>{if(!Array.isArray($))return V1(w,$);if(w.minItems&&$.length<w.minItems)return!1;if(w.maxItems&&$.length>w.maxItems)return!1;for(let J=0;J<$.length;J++)if(!V1(w,$[J]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",(w)=>!!w&&!isNaN(+w));if(!o.Has("boolean"))o.Set("boolean",(w)=>w==="true"||w==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",(w)=>{let $=w.charCodeAt(0);if($===9||$===10||$===32)$=w.trimStart().charCodeAt(0);if($!==123&&$!==91)return!1;try{return JSON.parse(w),!0}catch{return!1}});var a={Numeric:(w)=>{const $=x0.Number(w);return b.Transform(b.Union([b.String({format:"numeric",default:0}),b.Number(w)],w)).Decode((J)=>{const B=+J;if(isNaN(B))return J;if(w&&!M0.Check($,B))throw new I("property",$,B);return B}).Encode((J)=>J)},Date:(w)=>{const $=x0.Date(w);return b.Transform(b.Union([x0.Date(w),b.String({format:"date",default:(new Date()).toISOString()}),b.String({format:"date-time",default:(new Date()).toISOString()})],w)).Decode((J)=>{if(J instanceof Date)return J;const B=new Date(J);if(!M0.Check($,B))throw new I("property",$,B);return B}).Encode((J)=>{if(typeof J==="string")return new Date(J);return J})},BooleanString:(w)=>{const $=x0.Boolean(w);return b.Transform(b.Union([b.String({format:"boolean",default:!1}),b.Boolean(w)],w)).Decode((J)=>{if(typeof J==="string")return J==="true";if(w&&!M0.Check($,J))throw new I("property",$,J);return J}).Encode((J)=>J)},ObjectString:(w={},$)=>{const J=b.Object(w,$),B=JSON.stringify(M0.Create(J));return b.Transform(b.Union([b.String({format:"ObjectString",default:B}),J])).Decode((R)=>{if(typeof R==="string"){try{R=JSON.parse(R)}catch{throw new I("property",J,R)}if(!M0.Check(J,R))throw new I("property",J,R);return R}return R}).Encode((R)=>{if(typeof R==="string")try{R=JSON.parse(R)}catch{throw new I("property",J,R)}if(!M0.Check(J,R))throw new I("property",J,R);return JSON.stringify(R)})},File:H$,Files:(w={})=>b.Transform(x$(w)).Decode(($)=>{if(Array.isArray($))return $;return[$]}).Encode(($)=>$),Nullable:(w)=>b.Union([b.Null(),w]),MaybeEmpty:(w)=>b.Union([b.Null(),b.Undefined(),w]),Cookie:(w,{domain:$,expires:J,httpOnly:B,maxAge:R,path:S,priority:X,sameSite:W,secure:Z,secrets:Y,sign:G,...F}={})=>{const U=b.Object(w,F);return U.config={domain:$,expires:J,httpOnly:B,maxAge:R,path:S,priority:X,sameSite:W,secure:Z,secrets:Y,sign:G},U}};b.BooleanString=a.BooleanString;b.ObjectString=a.ObjectString;b.Numeric=a.Numeric;b.File=(w={})=>a.File({default:"File",...w,extension:w?.type,type:"string",format:"binary"});b.Files=(w={})=>a.Files({...w,elysiaMeta:"Files",default:"Files",extension:w?.type,type:"array",items:{...w,default:"Files",type:"string",format:"binary"}});b.Nullable=(w)=>a.Nullable(w);b.MaybeEmpty=a.MaybeEmpty;b.Cookie=a.Cookie;b.Date=a.Date;class p{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 z1;constructor(w){if(w?.tags)if(!w.detail)w.detail={tags:w.tags};else w.detail.tags=w.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{path:"/"},analytic:!1,forceDynamicQuery:!0,...w,experimental:w?.experimental??{},seed:w?.seed===void 0?"":w?.seed},w?.analytic&&(w?.name||w?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro(w){if(this.extender.macros.length){const $=a1({globalHook:this.event,localHook:w}),J={events:{global:this.event,local:w},onParse:$("parse"),onTransform:$("transform"),onBeforeHandle:$("beforeHandle"),onAfterHandle:$("afterHandle"),onResponse:$("onResponse"),mapResponse:$("mapResponse"),onError:$("error")};for(let B of this.extender.macros)U1(B.fn(J),w)}}add(w,$,J,B,{allowMeta:R=!1,skipPrefix:S=!1}={allowMeta:!1,skipPrefix:!1}){if(B=e1(B),$!==""&&$.charCodeAt(0)!==47)$="/"+$;if(this.config.prefix&&!S&&!this.config.scoped)$=this.config.prefix+$;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 X=this.definitions.type;let W,Z,Y,G,F,U;const _=!this.config.aot,D={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=()=>D.cookie?i0({validator:D.cookie,defaultConfig:this.config.cookie,config:D.cookie?.config??{},dynamic:_,models:X}):void 0,Q=this.config.normalize,j=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:f(D.body,{dynamic:_,models:X,normalize:Q}),headers:f(D.headers,{dynamic:_,models:X,additionalProperties:!0}),params:f(D.params,{dynamic:_,models:X}),query:f(D.query,{dynamic:_,models:X,normalize:Q}),cookie:P(),response:l0(D.response,{dynamic:_,models:X,normalize:Q})}:{get body(){if(W)return W;return W=f(D.body,{dynamic:_,models:X,normalize:Q})},get headers(){if(Z)return Z;return f(D.headers,{dynamic:_,models:X,additionalProperties:!0})},get params(){if(Y)return Y;return Y=f(D.params,{dynamic:_,models:X})},get query(){if(G)return G;return G=f(D.query,{dynamic:_,models:X})},get cookie(){if(F)return F;return F=P()},get response(){if(U)return U;return U=l0(D.response,{dynamic:_,models:X,normalize:Q})}},A=$.endsWith("/")?$.slice(0,$.length-1):$+"/";if(B=h(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=s(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const M=h(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add(w,$,{validator:j,hooks:M,content:B?.type,handle:J}),this.config.strictPath===!1)this.router.dynamic.add(w,A,{validator:j,hooks:M,content:B?.type,handle:J});this.router.history.push({method:w,path:$,composed:null,handler:J,hooks:M});return}let T=void 0;const V=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=n0(this.inference),u=V?w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e}):(N)=>{if(T)return T(N);return(T=w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e}))(N)};if(!V)u.compose=()=>{return u.composed=w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e})};let l=this.router.history.length;if(this.routeTree.has(w+$)){if(l=this.router.history.findIndex((N)=>N.path===$&&N.method===w),l!==-1){const N=this.router.history.splice(l,1)[0];if(N&&this.routeTree.has(N?.method+N?.path))this.routeTree.delete(N.method+N.path)}}this.routeTree.set(w+$,l),this.router.history.push({method:w,path:$,composed:u,handler:J,hooks:M});const O=this.router.static.http;if(w==="$INTERNALWS"){const N=this.config.strictPath?void 0:$.endsWith("/")?$.slice(0,$.length-1):$+"/";if($.indexOf(":")===-1&&$.indexOf("*")===-1){const w0=O.handlers.length;if(O.handlers.push(u),O.variables+=`const st${w0} = staticRouter.handlers[${w0}]\n`,this.router.static.ws[$]=w0,N)this.router.static.ws[N]=w0}else if(this.router.ws.add("ws",$,u),N)this.router.ws.add("ws",N,u);return}if($.indexOf(":")===-1&&$.indexOf("*")===-1){const N=O.handlers.length;if(O.handlers.push(u),O.variables+=V?`const st${N} = staticRouter.handlers[${N}]\n`:`let st${N} = staticRouter.handlers[${N}]\nlet stc${N}\n`,!O.map[$])O.map[$]={code:""};if(w==="ALL")O.map[$].all=V?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[$].code=V?`case '${w}': return st${N}(ctx)\n${O.map[$].code}`:`case '${w}': ${H0(N)}\n${O.map[$].code}`;if(!this.config.strictPath){if(!O.map[A])O.map[A]={code:""};if(w==="ALL")O.map[A].all=V?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[A].code=V?`case '${w}': return st${N}(ctx)\n${O.map[A].code}`:`case '${w}': ${H0(N)}\n${O.map[A].code}`}}else if(this.router.http.add(w,$,u),!this.config.strictPath)this.router.http.add(w,$.endsWith("/")?$.slice(0,$.length-1):$+"/",u)}setHeaders;headers(w){if(!w)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=s(this.setHeaders,w),this}onStart(w){return this.on("start",w),this}onRequest(w){return this.on("request",w),this}onParse(w,$){if(!$)return this.on("parse",w);return this.on(w,"parse",$)}onTransform(w,$){if(!$)return this.on("transform",w);return this.on(w,"transform",$)}resolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}mapResolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}onBeforeHandle(w,$){if(!$)return this.on("beforeHandle",w);return this.on(w,"beforeHandle",$)}onAfterHandle(w,$){if(!$)return this.on("afterHandle",w);return this.on(w,"afterHandle",$)}mapResponse(w,$){if(!$)return this.on("mapResponse",w);return this.on(w,"mapResponse",$)}onResponse(w,$){if(!$)return this.on("response",w);return this.on(w,"response",$)}trace(w,$){if(!$)$=w,w={as:"local"};if(!Array.isArray($))$=[$];for(let J of $)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,J));return this.on(w,"trace",$),this}error(w,$){switch(typeof w){case"string":return $.prototype[W0]=w,this.definitions.error[w]=$,this;case"function":return this.definitions.error=w(this.definitions.error),this}for(let[J,B]of Object.entries(w))B.prototype[W0]=J,this.definitions.error[J]=B;return this}onError(w,$){if(!$)return this.on("error",w);return this.on(w,"error",$)}onStop(w){return this.on("stop",w),this}on(w,$,J){let B;switch(typeof w){case"string":B=w,J=$;break;case"object":B=$;break}if(B==="response")B="onResponse";if(Array.isArray(J))J=c(J);else if(typeof J==="function")J=[{fn:J}];else J=[J];const R=J;for(let S of R)S.scope=typeof w==="string"?"local":w?.as??"local";if(B==="trace")h1(R.map((S)=>S.fn),this.inference.trace);else d0({[B]:R.map((S)=>S.fn)},this.inference.event);for(let S of R){const X=o1(S,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.push(X);break;case"transform":this.event.transform.push(X);break;case"beforeHandle":this.event.beforeHandle.push(X);break;case"afterHandle":this.event.afterHandle.push(X);break;case"mapResponse":this.event.mapResponse.push(X);break;case"onResponse":this.event.onResponse.push(X);break;case"trace":this.event.trace.push(X);break;case"error":this.event.error.push(X);break;case"stop":this.event.stop.push(X);break}}return this}propagate(){const w=($)=>{for(let J of $)if("scope"in J&&J.scope==="local")J.scope="scoped"};return w(this.event.parse),w(this.event.transform),w(this.event.beforeHandle),w(this.event.afterHandle),w(this.event.mapResponse),w(this.event.onResponse),w(this.event.trace),w(this.event.error),this}group(w,$,J){const B=new p({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=n0(this.inference),B.extender={...this.extender};const R=typeof $==="object",S=(R?J:$)(B);if(this.singleton=s(this.singleton,B.singleton),this.definitions=s(this.definitions,B.definitions),S.event.request.length)this.event.request=[...this.event.request||[],...S.event.request||[]];if(S.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...S.event.onResponse||[]];return this.model(S.definitions.type),Object.values(B.router.history).forEach(({method:X,path:W,handler:Z,hooks:Y})=>{if(W=(R?"":this.config.prefix)+w+W,R){const G=$,F=Y;this.add(X,W,Z,h(G,{...F||{},error:!F.error?S.event.error:Array.isArray(F.error)?[...F.error||{},...S.event.error||{}]:[F.error,...S.event.error||{}]}))}else this.add(X,W,Z,h(Y,{error:S.event.error}),{skipPrefix:!0})}),this}guard(w,$){if(!$){if(typeof w==="object"){if(this.applyMacro(w),this.event=t0(this.event,w),this.validator={body:w.body??this.validator?.body,headers:w.headers??this.validator?.headers,params:w.params??this.validator?.params,query:w.query??this.validator?.query,response:w.response??this.validator?.response,cookie:w.cookie??this.validator?.cookie},w.detail)if(this.config.detail)this.config.detail=s(Object.assign({},this.config.detail),w.detail);else this.config.detail=w.detail;if(w?.tags)if(!this.config.detail)this.config.detail={tags:w.tags};else this.config.detail.tags=w.tags;return this}return this.guard({},w)}const J=new p({...this.config,prefix:""});J.singleton={...this.singleton},J.definitions={...this.definitions},J.inference=n0(this.inference),J.extender={...this.extender};const B=$(J);if(this.singleton=s(this.singleton,J.singleton),this.definitions=s(this.definitions,J.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(J.router.history).forEach(({method:R,path:S,handler:X,hooks:W})=>{this.add(R,S,X,h(w,{...W||{},error:!W.error?B.event.error:Array.isArray(W.error)?[...W.error||{},...B.event.error||[]]:[W.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use(w,$){if($?.scoped)return this.guard({},(J)=>J.use(w));if(Array.isArray(w)){let J=this;for(let B of w)J=this.use(B);return J}if(w instanceof Promise)return this.promisedModules.add(w.then((J)=>{if(typeof J==="function")return J(this);if(J instanceof p)return this._use(J);if(typeof J.default==="function")return J.default(this);if(J.default instanceof p)return this._use(J.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((J)=>J.compile())),this;return this._use(w)}_use(w){if(typeof w==="function"){const R=w(this);if(R instanceof Promise)return this.promisedModules.add(R.then((S)=>{if(S instanceof p){this.compile();for(let{method:X,path:W,handler:Z,hooks:Y}of Object.values(S.router.history))this.add(X,W,Z,h(Y,{error:S.event.error}));return S}if(typeof S==="function")return S(this);if(typeof S.default==="function")return S.default(this);return this._use(S)}).then((S)=>S.compile())),this;return R}if(w.promisedModules.size)return this.promisedModules.add(w.modules.then(()=>this._use(w)).then((R)=>R.compile())),this;const{name:$,seed:J}=w.config;w.getServer=()=>this.getServer(),w.model(this.definitions.type),w.error(this.definitions.error);const B=w.config.scoped;if(B){if($){if(!($ in this.dependencies))this.dependencies[$]=[];const S=J!==void 0?q0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:X})=>S===X))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton.decorator,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((X)=>X.subType==="derive").map((X)=>({fn:X.fn.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((X)=>X.subType==="derive").map((X)=>({fn:X.fn.toString(),stack:new Error().stack??""}))})}w.extender.macros=this.extender.macros.concat(w.extender.macros);const R=[];for(let S=0;S<w.extender.macros.length;S++){const X=this.extender.macros[S];if(R.includes(X.checksum))w.extender.macros.splice(S,1),S--;R.push(X.checksum)}if(w.onRequest((S)=>{Object.assign(S,this.singleton.decorator),Object.assign(S.store,this.singleton.store)}),w.event.trace.length)w.event.trace.push(...w.event.trace);if(!w.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if(w.event.error.length)w.event.error.push(...this.event.error);if(w.config.aot)w.compile();if(B===!0&&w.config.prefix){this.mount(w.config.prefix+"/",w.fetch);for(let S of w.router.history)this.routeTree.set(S.method+`${w.config.prefix}${S.path}`,this.router.history.length),this.router.history.push({...S,path:`${w.config.prefix}${S.path}`,hooks:h(S.hooks,{error:this.event.error})})}else{this.mount(w.fetch);for(let S of w.router.history)this.routeTree.set(S.method+`${w.config.prefix}${S.path}`,this.router.history.length),this.router.history.push({...S,path:`${w.config.prefix}${S.path}`,hooks:h(S.hooks,{error:this.event.error})})}return this}else{this.headers(w.setHeaders),w.reporter=this.reporter;for(let S of w.event.trace)if(S.scope&&S.scope!=="local")this.trace(S);if($){if(!($ in this.dependencies))this.dependencies[$]=[];const S=J!==void 0?q0($+JSON.stringify(J)):0;if(!this.dependencies[$].some(({checksum:X})=>S===X))this.extender.macros=this.extender.macros.concat(w.extender.macros)}else this.extender.macros=this.extender.macros.concat(w.extender.macros);const R=[];for(let S=0;S<this.extender.macros.length;S++){const X=this.extender.macros[S];if(X.checksum){if(R.includes(X.checksum))this.extender.macros.splice(S,1),S--;R.push(X.checksum)}}this.inference={event:{body:this.inference.event.body||w.inference.event.body,cookie:this.inference.event.cookie||w.inference.event.cookie,headers:this.inference.event.headers||w.inference.event.headers,queries:[...this.inference.event.queries,...w.inference.event.queries],query:this.inference.event.query||w.inference.event.query,set:this.inference.event.set||w.inference.event.set,unknownQueries:this.inference.event.unknownQueries||w.inference.event.unknownQueries},trace:{request:this.inference.trace.request||w.inference.trace.request,parse:this.inference.trace.parse||w.inference.trace.parse,transform:this.inference.trace.transform||w.inference.trace.transform,handle:this.inference.trace.handle||w.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||w.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||w.inference.trace.afterHandle,error:this.inference.trace.error||w.inference.trace.error,context:this.inference.trace.context||w.inference.trace.context,store:this.inference.trace.store||w.inference.trace.store,set:this.inference.trace.set||w.inference.trace.set}}}this.decorate(w.singleton.decorator),this.state(w.singleton.store),this.model(w.definitions.type),this.error(w.definitions.error);for(let{method:R,path:S,handler:X,hooks:W}of Object.values(w.router.history))this.add(R,S,X,h(W,{error:w.event.error}));if(!B)if($){if(!($ in this.dependencies))this.dependencies[$]=[];const R=J!==void 0?q0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:S})=>R===S))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:R,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:R,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((S)=>S?.subType==="derive").map((S)=>({fn:S.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((S)=>S?.subType==="resolve").map((S)=>({fn:S.toString(),stack:new Error().stack??""}))}),this.event=t0(this.event,j1(w.event),R)}else this.event=t0(this.event,j1(w.event));return this}macro(w){const $={checksum:q0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:w.toString()})),fn:w};return this.extender.macros.push($),this}mount(w,$){if(w instanceof p||typeof w==="function"||w.length===0||w==="/"){const R=typeof w==="function"?w:w instanceof p?w.compile().fetch:$ instanceof p?$.compile().fetch:$,S=async({request:X,path:W})=>R(new Request(K1(X.url,W||"/"),X));return this.all("/*",S,{type:"none"}),this}const J=w.length;if($ instanceof p)$=$.compile().fetch;const B=async({request:R,path:S})=>$(new Request(K1(R.url,S.slice(J)||"/"),R));return this.all(w,B,{type:"none"}),this.all(w+(w.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get(w,$,J){return this.add("GET",w,$,J),this}post(w,$,J){return this.add("POST",w,$,J),this}put(w,$,J){return this.add("PUT",w,$,J),this}patch(w,$,J){return this.add("PATCH",w,$,J),this}delete(w,$,J){return this.add("DELETE",w,$,J),this}options(w,$,J){return this.add("OPTIONS",w,$,J),this}all(w,$,J){return this.add("ALL",w,$,J),this}head(w,$,J){return this.add("HEAD",w,$,J),this}connect(w,$,J){return this.add("CONNECT",w,$,J),this}route(w,$,J,B){return this.add(w.toUpperCase(),$,J,B,B?.config),this}ws(w,$){const J=$.transformMessage?Array.isArray($.transformMessage)?$.transformMessage:[$.transformMessage]:void 0;let B=null;const R=f($?.body,{models:this.definitions.type,normalize:this.config.normalize}),S=f($?.response,{models:this.definitions.type,normalize:this.config.normalize}),X=(W)=>{if(typeof W==="string"){const Z=W?.charCodeAt(0);if(Z===47||Z===123)try{W=JSON.parse(W)}catch{}else if(j0(W))W=+W}if(J?.length)for(let Z=0;Z<J.length;Z++){const Y=J[Z](W);if(Y!==void 0)W=Y}return W};return this.route("$INTERNALWS",w,(W)=>{const{set:Z,path:Y,qi:G,headers:F,query:U,params:_}=W;if(B===null)B=this.getServer();if(B?.upgrade(W.request,{headers:typeof $.upgrade==="function"?$.upgrade(W):$.upgrade,data:{validator:S,open(D){$.open?.(new _0(D,W))},message:(D,P)=>{const Q=X(P);if(R?.Check(Q)===!1)return void D.send(new I("message",R,Q).message);$.message?.(new _0(D,W),Q)},drain(D){$.drain?.(new _0(D,W))},close(D,P,Q){$.close?.(new _0(D,W),P,Q)}}}))return;return Z.status=400,"Expected a websocket connection"},{beforeHandle:$.beforeHandle,transform:$.transform,headers:$.headers,params:$.params,query:$.query}),this}state(w,$){switch(typeof w){case"object":return this.singleton.store=s(this.singleton.store,w),this;case"function":return this.singleton.store=w(this.singleton.store),this}if(!(w in this.singleton.store))this.singleton.store[w]=$;return this}decorate(w,$){switch(typeof w){case"object":return this.singleton.decorator=s(this.singleton.decorator,w),this;case"function":return this.singleton.decorator=w(this.singleton.decorator),this}if(!(w in this.singleton.decorator))this.singleton.decorator[w]=$;return this}derive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}model(w,$){switch(typeof w){case"object":return Object.entries(w).forEach(([J,B])=>{if(!(J in this.definitions.type))this.definitions.type[J]=B}),this;case"function":return this.definitions.type=w(this.definitions.type),this}return this.definitions.type[w]=$,this}mapDerive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}affix(w,$,J){if(J==="")return this;const B=["_","-"," "],R=(Z)=>Z[0].toUpperCase()+Z.slice(1),S=w==="prefix"?(Z,Y)=>B.includes(Z.at(-1)??"")?Z+Y:Z+R(Y):B.includes(J.at(-1)??"")?(Z,Y)=>Y+Z:(Z,Y)=>Y+R(Z),X=(Z)=>{const Y={};switch(Z){case"decorator":for(let G in this.singleton.decorator)Y[S(J,G)]=this.singleton.decorator[G];this.singleton.decorator=Y;break;case"state":for(let G in this.singleton.store)Y[S(J,G)]=this.singleton.store[G];this.singleton.store=Y;break;case"model":for(let G in this.definitions.type)Y[S(J,G)]=this.definitions.type[G];this.definitions.type=Y;break;case"error":for(let G in this.definitions.error)Y[S(J,G)]=this.definitions.error[G];this.definitions.error=Y;break}},W=Array.isArray($)?$:[$];for(let Z of W.some((Y)=>Y==="all")?["decorator","state","model","error"]:W)X(Z);return this}prefix(w,$){return this.affix("prefix",w,$)}suffix(w,$){return this.affix("suffix",w,$)}compile(){if(this.fetch=this.config.aot?N1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async(w)=>this.fetch(w);fetch=(w)=>{return(this.fetch=this.config.aot?N1(this):O1(this))(w)};handleError=async(w,$)=>(this.handleError=this.config.aot?P1(this):Dw(this))(w,$);outerErrorHandler=(w)=>new Response(w.message||w.name||"Error",{status:w?.status??500});listen=(w,$)=>{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 w==="string"){if(!j0(w))throw new Error("Port must be a numeric value");w=parseInt(w)}const J=this.fetch,B=typeof w==="object"?{development:!T0,reusePort:!0,...this.config.serve||{},...w||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:J,error:this.outerErrorHandler}:{development:!T0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:w,fetch:J,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let R=0;R<this.event.start.length;R++)this.event.start[R].fn(this);if($)$(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let R=0;R<this.event.stop.length;R++)this.event.stop[R].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 w=0;w<this.event.stop.length;w++)this.event.stop[w].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{b as t,I0 as redirect,L as mergeObjectArray,h as mergeHook,v as mapResponse,k as mapEarlyResponse,i as mapCompactResponse,f as getSchemaValidator,l0 as getResponseSchemaValidator,R0 as form,_1 as error,p as default,I as ValidationError,S0 as StatusMap,e0 as ParseError,Z0 as NotFoundError,r0 as InvertedStatusMap,b0 as InvalidCookieSignature,a0 as InternalServerError,p as Elysia,W0 as ERROR_CODE,d as ELYSIA_RESPONSE,n as Cookie};
441
442
 
442
- //# debugId=33217D8EE94CE77E64756e2164756e21
443
+ //# debugId=12D0A25E55A7CBE264756e2164756e21