elysia 1.0.26 → 1.0.27
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 +30 -20
- package/dist/bun/index.js.map +5 -5
- package/dist/cjs/compose.js +15 -4
- package/dist/cjs/index.js +19 -5
- package/dist/cjs/utils.js +1 -1
- package/dist/compose.mjs +15 -4
- package/dist/index.mjs +19 -5
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
- package/tsconfig.dts.json +0 -106
- package/tsconfig.test.tsbuildinfo +0 -1
package/dist/bun/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
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}};/*!
|
|
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(){},kw=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 kw(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},vw=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(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 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 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 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}]},k1=(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]=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),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}]=v1(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]=k1(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]=v1(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 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', {
|
|
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 $},k=(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)=>k(R,$));case"Function":return k(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)=>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"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)=>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)}},v=(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=v(R,$);if(S!==void 0)return S});case"Error":return t(w,$);case"Function":return v(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)=>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"Promise":return w.then((B)=>{const R=v(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)=>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)}},i=(w,$)=>{if(w?.$passthrough)w=w?.[w.$passthrough];if(w?.[d])return k(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=!0}={})=>{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
9
|
event: '${R}',
|
|
10
10
|
type: 'begin',
|
|
@@ -36,7 +36,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
36
36
|
} else if(!(${B} instanceof Response) && response[c.set.status]?.Check(${B}) === false) {
|
|
37
37
|
if(!(response instanceof Error))
|
|
38
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=
|
|
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=k(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
41
|
c.set.cookie[key].value = await signCookie(cookie.value, '${C}')
|
|
42
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 = {}
|
|
@@ -56,9 +56,6 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
56
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
|
-
// decodeURIComponent is already done in parseQuery function
|
|
60
|
-
// for(const key of Object.keys(c.query))
|
|
61
|
-
// c.query[key] = decodeURIComponentc.query[key])
|
|
62
59
|
} else c.query = {}`;else Q+=`if(c.qi !== -1) {
|
|
63
60
|
let url = '&' + c.url.slice(c.qi + 1).replace(/\\+/g, ' ')
|
|
64
61
|
|
|
@@ -79,7 +76,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
79
76
|
}
|
|
80
77
|
} else {
|
|
81
78
|
c.query = {}
|
|
82
|
-
}`}const y0=Y.set,
|
|
79
|
+
}`}const y0=Y.set,v0=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
80
|
|
|
84
81
|
try {
|
|
85
82
|
c.body = JSON.parse(tempBody)
|
|
@@ -168,7 +165,20 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
168
165
|
}`,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+=`\nif(typeof c.query['${C}'] === "string")
|
|
169
166
|
try {
|
|
170
167
|
c.query['${C}'] = JSON.parse(c.query['${C}'])
|
|
171
|
-
} catch {}\n`;continue}if(q)Q
|
|
168
|
+
} catch {}\n`;continue}if(q)Q+=`\nif(Array.isArray(c.query['${C}'])) {
|
|
169
|
+
for(let i = 0; i < c.query['${C}'].length; i++) {
|
|
170
|
+
if(
|
|
171
|
+
typeof c.query['${C}'][i] === "string" &&
|
|
172
|
+
(c.query['${C}'][i].charCodeAt(0) === 123 ||
|
|
173
|
+
c.query['${C}'][i].charCodeAt(0) === 91)
|
|
174
|
+
)
|
|
175
|
+
try {
|
|
176
|
+
c.query['${C}'][i] = JSON.parse(c.query['${C}'][i])
|
|
177
|
+
} catch {}
|
|
178
|
+
}
|
|
179
|
+
} else if(typeof c.query['${C}'] === "object") {
|
|
180
|
+
c.query['${C}'] = JSON.parse(c.query['${C}'])
|
|
181
|
+
}\n`}if(Q+=`if(query.Check(c.query) === false) {
|
|
172
182
|
${Y0("query")}
|
|
173
183
|
}`,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) {
|
|
174
184
|
if (typeof c.body === 'object') {
|
|
@@ -183,16 +193,16 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
183
193
|
for(const [key, value] of Object.entries(c.cookie))
|
|
184
194
|
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) {
|
|
185
195
|
${Y0("cookie","cookieValue")}
|
|
186
|
-
}`}}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}),
|
|
196
|
+
}`}}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}),k0=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])
|
|
187
197
|
throw resolved
|
|
188
198
|
else
|
|
189
|
-
Object.assign(c, resolved)\n`}else if(!
|
|
199
|
+
Object.assign(c, resolved)\n`}else if(!k0)Q+=x(q)?`await beforeHandle[${z}](c);\n`:`beforeHandle[${z}](c);\n`,H();else{if(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) {
|
|
190
200
|
mr = onMapResponse[${N0}](c)
|
|
191
201
|
if(mr instanceof Promise) mr = await mr
|
|
192
202
|
if(mr !== undefined) be = c.response = mr
|
|
193
|
-
}\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()),
|
|
203
|
+
}\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()),k0=E("afterHandle.unit",{name:q.fn.name});if(!H)Q+=x(q.fn)?`await afterHandle[${z}](c)\n`:`afterHandle[${z}](c)\n`,k0();else if(Q+=x(q.fn)?`af = await afterHandle[${z}](c)\n`:`af = afterHandle[${z}](c)\n`,k0(),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)
|
|
194
204
|
if(mr instanceof Promise) mr = await mr
|
|
195
|
-
if(mr !== undefined) r = c.response = mr\n`;if(
|
|
205
|
+
if(mr !== undefined) r = c.response = mr\n`;if(v0)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) {
|
|
196
206
|
mr = onMapResponse[${K}](c)
|
|
197
207
|
if(mr instanceof Promise) mr = await mr
|
|
198
208
|
if(mr !== undefined) r = c.response = mr
|
|
@@ -204,11 +214,11 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
204
214
|
)
|
|
205
215
|
return mapResponse(${U}.clone(), c.set)
|
|
206
216
|
else
|
|
207
|
-
return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(
|
|
217
|
+
return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(v0)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) {
|
|
208
218
|
mr = onMapResponse[${K}](c)
|
|
209
219
|
if(mr instanceof Promise) mr = await mr
|
|
210
220
|
if(mr !== undefined) r = c.response = mr
|
|
211
|
-
}\n`}if(Q+=N,
|
|
221
|
+
}\n`}if(Q+=N,v0)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(
|
|
212
222
|
isNotEmpty(c.set.headers) ||
|
|
213
223
|
c.set.status !== 200 ||
|
|
214
224
|
c.set.redirect ||
|
|
@@ -216,7 +226,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
216
226
|
)
|
|
217
227
|
return mapResponse(${U}.clone(), c.set)
|
|
218
228
|
else
|
|
219
|
-
return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(
|
|
229
|
+
return ${U}.clone()`:`return ${U}.clone()`,Q+="\n";else if(v0)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+=`
|
|
220
230
|
c.error = error
|
|
221
231
|
c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
|
|
222
232
|
`;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 {
|
|
@@ -273,7 +283,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
273
283
|
|
|
274
284
|
${W?"c.schema = schema; c.defs = definitions":""}
|
|
275
285
|
${Q}
|
|
276
|
-
}`,Function("hooks",Q)({handler:X,hooks:ww(R),validator:S,handleError:w.handleError,utils:{mapResponse:
|
|
286
|
+
}`,Function("hooks",Q)({handler:X,hooks:ww(R),validator:S,handleError:w.handleError,utils:{mapResponse:k,mapCompactResponse:i,mapEarlyResponse:v,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=`
|
|
277
287
|
const route = router.find(request.method, path) ${S.http.root.ALL?'?? router.find("ALL", path)':""}
|
|
278
288
|
|
|
279
289
|
if (route === null)
|
|
@@ -386,7 +396,7 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
386
396
|
}
|
|
387
397
|
|
|
388
398
|
${W}
|
|
389
|
-
}`;const P=P1(w);return w.handleError=P,Function("data",B)({app:w,mapEarlyResponse:
|
|
399
|
+
}`;const P=P1(w);return w.handleError=P,Function("data",B)({app:w,mapEarlyResponse:v,NotFoundError:Z0,getReporter:()=>w.reporter,requestId:_w,handleError:P,error:_1,redirect:I0})},P1=(w)=>{let $=`const {
|
|
390
400
|
app: { event: { error: onErrorContainer, onResponse: resContainer } },
|
|
391
401
|
mapResponse,
|
|
392
402
|
ERROR_CODE,
|
|
@@ -438,9 +448,9 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
|
|
|
438
448
|
|
|
439
449
|
return mapResponse(error, set, context.request)
|
|
440
450
|
}
|
|
441
|
-
}`,Function("inject",$)({app:w,mapResponse:
|
|
451
|
+
}`,Function("inject",$)({app:w,mapResponse:k,ERROR_CODE:W0,ELYSIA_RESPONSE:d})},H0=(w)=>`if(stc${w}) return stc${w}(ctx)
|
|
442
452
|
if(st${w}.compose) return (stc${w} = st${w}.compose())(ctx)
|
|
443
453
|
|
|
444
|
-
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};
|
|
454
|
+
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=v(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=v(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=v(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 k(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 k(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),w.extender.macros=this.extender.macros.concat(w.extender.macros);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,k as mapResponse,v 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};
|
|
445
455
|
|
|
446
|
-
//# debugId=
|
|
456
|
+
//# debugId=E9E60DF5F70AB1B664756E2164756E21
|