elysia 1.0.15 → 1.0.16
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 +121 -121
- package/dist/bun/index.js.map +5 -5
- package/dist/cjs/compose.js +8 -8
- package/dist/cjs/index.js +8 -8
- package/dist/compose.mjs +8 -8
- package/dist/index.mjs +8 -8
- package/package.json +2 -1
- package/tsconfig.test.tsbuildinfo +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames:x$}=Object;var g$=Object.prototype.hasOwnProperty;var I0=($,W,J)=>{J=$!=null?b$(H$($)):{};const X=W||!$||!$.__esModule?T1(J,"default",{value:$,enumerable:!0}):J;for(let Z of x$($))if(!g$.call(X,Z))T1(X,Z,{get:()=>$[Z],enumerable:!0});return X};var _0=($,W)=>()=>(W||$((W={exports:{}}).exports,W),W.exports);var E1=_0((k9,X1)=>{var O0=function(){},v$=function($,W,J){this.fn=$,this.context=W,this.once=J||!1},R1=function($,W,J,X,Z){if(typeof J!=="function")throw new TypeError("The listener must be a function");var Q=new v$(J,X||$,Z),B=y?y+W:W;if(!$._events[B])$._events[B]=Q,$._eventsCount++;else if(!$._events[B].fn)$._events[B].push(Q);else $._events[B]=[$._events[B],Q];return $},k0=function($,W){if(--$._eventsCount===0)$._events=new O0;else delete $._events[W]},g=function(){this._events=new O0,this._eventsCount=0},y$=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(O0.prototype=Object.create(null),!new O0().__proto__)y=!1}g.prototype.eventNames=function $(){var W=[],J,X;if(this._eventsCount===0)return W;for(X in J=this._events)if(y$.call(J,X))W.push(y?X.slice(1):X);if(Object.getOwnPropertySymbols)return W.concat(Object.getOwnPropertySymbols(J));return W};g.prototype.listeners=function $(W){var J=y?y+W:W,X=this._events[J];if(!X)return[];if(X.fn)return[X.fn];for(var Z=0,Q=X.length,B=new Array(Q);Z<Q;Z++)B[Z]=X[Z].fn;return B};g.prototype.listenerCount=function $(W){var J=y?y+W:W,X=this._events[J];if(!X)return 0;if(X.fn)return 1;return X.length};g.prototype.emit=function $(W,J,X,Z,Q,B){var Y=y?y+W:W;if(!this._events[Y])return!1;var G=this._events[Y],K=arguments.length,_,F;if(G.fn){if(G.once)this.removeListener(W,G.fn,void 0,!0);switch(K){case 1:return G.fn.call(G.context),!0;case 2:return G.fn.call(G.context,J),!0;case 3:return G.fn.call(G.context,J,X),!0;case 4:return G.fn.call(G.context,J,X,Z),!0;case 5:return G.fn.call(G.context,J,X,Z,Q),!0;case 6:return G.fn.call(G.context,J,X,Z,Q,B),!0}for(F=1,_=new Array(K-1);F<K;F++)_[F-1]=arguments[F];G.fn.apply(G.context,_)}else{var z=G.length,A;for(F=0;F<z;F++){if(G[F].once)this.removeListener(W,G[F].fn,void 0,!0);switch(K){case 1:G[F].fn.call(G[F].context);break;case 2:G[F].fn.call(G[F].context,J);break;case 3:G[F].fn.call(G[F].context,J,X);break;case 4:G[F].fn.call(G[F].context,J,X,Z);break;default:if(!_)for(A=1,_=new Array(K-1);A<K;A++)_[A-1]=arguments[A];G[F].fn.apply(G[F].context,_)}}}return!0};g.prototype.on=function $(W,J,X){return R1(this,W,J,X,!1)};g.prototype.once=function $(W,J,X){return R1(this,W,J,X,!0)};g.prototype.removeListener=function $(W,J,X,Z){var Q=y?y+W:W;if(!this._events[Q])return this;if(!J)return k0(this,Q),this;var B=this._events[Q];if(B.fn){if(B.fn===J&&(!Z||B.once)&&(!X||B.context===X))k0(this,Q)}else{for(var Y=0,G=[],K=B.length;Y<K;Y++)if(B[Y].fn!==J||Z&&!B[Y].once||X&&B[Y].context!==X)G.push(B[Y]);if(G.length)this._events[Q]=G.length===1?G[0]:G;else k0(this,Q)}return this};g.prototype.removeAllListeners=function $(W){var J;if(W){if(J=y?y+W:W,this._events[J])k0(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 X1!=="undefined")X1.exports=g});var d0=_0((d9,d1)=>{var o$=function($){var W=$.indexOf("%");if(W===-1)return $;var J=$.length,X="",Z=0,Q=0,B=W,Y=u1;while(W>-1&&W<J){var G=m1($[W+1],4),K=m1($[W+2],0),_=G|K,F=Y1[_];if(Y=Y1[256+Y+F],Q=Q<<6|_&Y1[364+F],Y===u1)X+=$.slice(Z,B),X+=Q<=65535?String.fromCharCode(Q):String.fromCharCode(55232+(Q>>10),56320+(Q&1023)),Q=0,Z=W+3,W=B=$.indexOf("%",Z);else if(Y===r$)return null;else{if(W+=3,W<J&&$.charCodeAt(W)===37)continue;return null}}return X+$.slice(Z)},m1=function($,W){var J=a$[$];return J===void 0?255:J<<W},u1=12,r$=0,Y1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],a$={"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};d1.exports=o$});var Z$=_0((_6,X$)=>{var Y9=function($){const W=new J$;if(typeof $!=="string")return W;let J=$.length,X="",Z="",Q=-1,B=-1,Y=!1,G=!1,K=!1,_=!1,F=!1,z=0;for(let A=0;A<J+1;A++)if(z=A!==J?$.charCodeAt(A):38,z===38){if(F=B>Q,!F)B=A;if(X=$.slice(Q+1,B),F||X.length>0){if(K)X=X.replace(W$," ");if(Y)X=$$(X)||X;if(F){if(Z=$.slice(B+1,A),_)Z=Z.replace(W$," ");if(G)Z=$$(Z)||Z}const j=W[X];if(j===void 0)W[X]=Z;else if(j.pop)j.push(Z);else W[X]=[j,Z]}Z="",Q=A,B=A,Y=!1,G=!1,K=!1,_=!1}else if(z===61)if(B<=Q)B=A;else G=!0;else if(z===43)if(B>Q)_=!0;else K=!0;else if(z===37)if(B>Q)G=!0;else Y=!0;return W},$$=d0(),W$=/\+/g,J$=function(){};J$.prototype=Object.create(null);X$.exports=Y9});var B$=_0((F6,Q$)=>{var U9=function($){const W=$.length;if(W===0)return"";let J="",X=0,Z=0;$:for(;Z<W;Z++){let Q=$.charCodeAt(Z);while(Q<128){if(G9[Q]!==1){if(X<Z)J+=$.slice(X,Z);X=Z+1,J+=t[Q]}if(++Z===W)break $;Q=$.charCodeAt(Z)}if(X<Z)J+=$.slice(X,Z);if(Q<2048){X=Z+1,J+=t[192|Q>>6]+t[128|Q&63];continue}if(Q<55296||Q>=57344){X=Z+1,J+=t[224|Q>>12]+t[128|Q>>6&63]+t[128|Q&63];continue}if(++Z,Z>=W)throw new Error("URI malformed");const B=$.charCodeAt(Z)&1023;X=Z+1,Q=65536+((Q&1023)<<10|B),J+=t[240|Q>>18]+t[128|Q>>12&63]+t[128|Q>>6&63]+t[128|Q&63]}if(X===0)return $;if(X<W)return J+$.slice(X);return J},t=Array.from({length:256},($,W)=>"%"+((W<16?"0":"")+W.toString(16)).toUpperCase()),G9=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]);Q$.exports={encodeString:U9}});var U$=_0((D6,G$)=>{var Y$=function($){const W=typeof $;if(W==="string")return j1($);else if(W==="bigint")return $.toString();else if(W==="boolean")return $?"true":"false";else if(W==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:j1(""+$);return""},K9=function($){let W="";if($===null||typeof $!=="object")return W;const J="&",X=Object.keys($),Z=X.length;let Q=0;for(let B=0;B<Z;B++){const Y=X[B],G=$[Y],K=j1(Y)+"=";if(B)W+=J;if(Array.isArray(G)){Q=G.length;for(let _=0;_<Q;_++){if(_)W+=J;W+=K,W+=Y$(G[_])}}else W+=K,W+=Y$(G)}return W},{encodeString:j1}=B$();G$.exports=K9});var N1=_0((z6,q0)=>{var K$=Z$(),_$=U$(),F$={parse:K$,stringify:_$};q0.exports=F$;q0.exports.default=F$;q0.exports.parse=K$;q0.exports.stringify=_$});var F0=($,W)=>({part:$,store:null,inert:W!==void 0?new Map(W.map((J)=>[J.part.charCodeAt(0),J])):null,params:null,wildcardStore:null}),q1=($,W)=>({...$,part:W}),L1=($)=>({paramName:$,store:null,inert:null});class X0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,W,J){let X;if(typeof W!="string")throw TypeError("Route path must be a string");W===""?W="/":W[0]!=="/"&&(W=`/${W}`),this.history.push([$,W,J]);let Z=W[W.length-1]==="*";Z&&(W=W.slice(0,-1));let Q=W.split(X0.regex.static),B=W.match(X0.regex.params)||[];Q[Q.length-1]===""&&Q.pop(),X=this.root[$]?this.root[$]:this.root[$]=F0("/");let Y=0;for(let G=0;G<Q.length;++G){let K=Q[G];if(G>0){let _=B[Y++].slice(1);if(X.params===null)X.params=L1(_);else if(X.params.paramName!==_)throw Error(`Cannot create route "${W}" with parameter "${_}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);let F=X.params;if(F.inert===null){X=F.inert=F0(K);continue}X=F.inert}for(let _=0;;){if(_===K.length){if(_<X.part.length){let F=q1(X,X.part.slice(_));Object.assign(X,F0(K,[F]))}break}if(_===X.part.length){if(X.inert===null)X.inert=new Map;else if(X.inert.has(K.charCodeAt(_))){X=X.inert.get(K.charCodeAt(_)),K=K.slice(_),_=0;continue}let F=F0(K.slice(_));X.inert.set(K.charCodeAt(_),F),X=F;break}if(K[_]!==X.part[_]){let F=q1(X,X.part.slice(_)),z=F0(K.slice(_));Object.assign(X,F0(X.part.slice(0,_),[F,z])),X=z;break}++_}}if(Y<B.length){let G=B[Y],K=G.slice(1);if(X.params===null)X.params=L1(K);else if(X.params.paramName!==K)throw Error(`Cannot create route "${W}" with parameter "${K}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);return X.params.store===null&&(X.params.store=J),X.params.store}return Z?(X.wildcardStore===null&&(X.wildcardStore=J),X.wildcardStore):(X.store===null&&(X.store=J),X.store)}find($,W){let J=this.root[$];return J?J1(W,W.length,J,0):null}}var J1=($,W,J,X)=>{let Z=J?.part,Q=X+Z.length;if(Z.length>1){if(Q>W)return null;if(Z.length<15){for(let B=1,Y=X+1;B<Z.length;++B,++Y)if(Z.charCodeAt(B)!==$.charCodeAt(Y))return null}else if($.substring(X,Q)!==Z)return null}if(Q===W)return J.store!==null?{store:J.store,params:{}}:J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":""}}:null;if(J.inert!==null){let B=J.inert.get($.charCodeAt(Q));if(B!==void 0){let Y=J1($,W,B,Q);if(Y!==null)return Y}}if(J.params!==null){let B=J.params,Y=$.indexOf("/",Q);if(Y!==Q){if(Y===-1||Y>=W){if(B.store!==null){let G={};return G[B.paramName]=$.substring(Q,W),{store:B.store,params:G}}}else if(B.inert!==null){let G=J1($,W,B.inert,Y);if(G!==null)return G.params[B.paramName]=$.substring(Q,Y),G}}}return J.wildcardStore!==null?{store:J.wildcardStore,params:{"*":$.substring(Q,W)}}:null};var b1=I0(E1(),1);var H1=b1.default;var f0=()=>{let $;return[new Promise((J)=>{$=J}),$]},J0=()=>{const[$,W]=f0(),[J,X]=f0(),Z=[],Q=[];return{signal:$,consume:(B)=>{switch(B.type){case"begin":if(B.unit&&Z.length===0)for(let Y=0;Y<B.unit;Y++){const[G,K]=f0(),[_,F]=f0();Z.push(G),Q.push([(z)=>{K({children:[],end:_,name:z.name??"",skip:!1,time:z.time})},(z)=>{F(z)}])}W({children:Z,end:J,name:B.name??"",skip:!1,time:B.time});break;case"end":X(B.time);break}},consumeChild(B){switch(B.type){case"begin":if(!Q[0])return;const[Y]=Q[0];Y({children:[],end:J,name:B.name??"",skip:!1,time:B.time});break;case"end":const G=Q.shift();if(!G)return;G[1](B.time)}},resolve(){W({children:[],end:new Promise((B)=>B(0)),name:"",skip:!0,time:0});for(let[B,Y]of Q)B({children:[],end:new Promise((G)=>G(0)),name:"",skip:!0,time:0}),Y(0);X(0)}}},x1=($,W,J)=>{if(typeof J==="object")J=J.fn;return async function X(X){if(X.event!=="request"||X.type!=="begin")return;const Z=X.id,Q=$(),B=J0(),Y=J0(),G=J0(),K=J0(),_=J0(),F=J0(),z=J0(),A=J0();B.consume(X);const j=(V)=>{if(V.id===Z)switch(V.event){case"request":B.consume(V);break;case"request.unit":B.consumeChild(V);break;case"parse":Y.consume(V);break;case"parse.unit":Y.consumeChild(V);break;case"transform":G.consume(V);break;case"transform.unit":G.consumeChild(V);break;case"beforeHandle":K.consume(V);break;case"beforeHandle.unit":K.consumeChild(V);break;case"handle":_.consume(V);break;case"afterHandle":F.consume(V);break;case"afterHandle.unit":F.consumeChild(V);break;case"error":z.consume(V);break;case"error.unit":z.consumeChild(V);break;case"response":if(V.type==="begin")B.resolve(),Y.resolve(),G.resolve(),K.resolve(),_.resolve(),F.resolve(),z.resolve();else Q.off("event",j);A.consume(V);break;case"response.unit":A.consumeChild(V);break;case"exit":B.resolve(),Y.resolve(),G.resolve(),K.resolve(),_.resolve(),F.resolve(),z.resolve();break}};Q.on("event",j),await J({id:Z,context:X.ctx,set:X.ctx?.set,store:X.ctx?.store,time:X.time,request:B.signal,parse:Y.signal,transform:G.signal,beforeHandle:K.signal,handle:_.signal,afterHandle:F.signal,error:z.signal,response:A.signal}),Q.emit(`res${Z}.${W}`,void 0)}};var y1=($)=>{if($.startsWith("async"))$=$.slice(6);let W=-1;if($.charCodeAt(0)===40){if(W=$.indexOf(") => {\n"),W!==-1)return[$.slice(1,W),$.slice(W+5),{isArrowReturn:!1}];if(W=$.indexOf(") => "),W!==-1)return[$.slice(1,W),$.slice(W+5),{isArrowReturn:!0}]}if($.startsWith("function")){W=$.indexOf("(");const Z=$.indexOf(")");return[$.slice(W+1,Z),$.slice(Z+2),{isArrowReturn:!1}]}const J=$.indexOf("(");if(J!==-1){const[Z,Q]=$.split("\n",2),B=Z.lastIndexOf(")")+1;return[Z.slice(J,B),"{"+Q,{isArrowReturn:!1}]}const X=$.split("\n",2);return[X[0],X[1],{isArrowReturn:!1}]},v1=($)=>{const W=$.indexOf("{");if(W===-1)return[-1,0];let J=W+1,X=1;for(;J<$.length;J++){const Z=$.charCodeAt(J);if(Z===123)X++;else if(Z===125)X--;if(X===0)break}if(X!==0)return[0,$.length];return[W,J+1]},k$=($)=>{const W=$.lastIndexOf("}");if(W===-1)return[-1,0];let J=W-1,X=1;for(;J>=0;J--){const Z=$.charCodeAt(J);if(Z===125)X++;else if(Z===123)X--;if(X===0)break}if(X!==0)return[-1,0];return[J,W+1]},h0=($)=>{if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)$=$.slice(2,-2);while(!0){const[W,J]=v1($);if(W===-1)break;$=$.slice(0,W-2)+$.slice(J+1)}return $.replace(/:/g,"").trim()},f$=($,W)=>{const J=h0($);if(!W.query&&J.includes("query"))W.query=!0;if(!W.headers&&J.includes("headers"))W.headers=!0;if(!W.body&&J.includes("body"))W.body=!0;if(!W.cookie&&J.includes("cookie"))W.cookie=!0;if(!W.set&&J.includes("set"))W.set=!0;return J},h$=($,W)=>{const J=h0($);if(!W.request&&J.includes("request"))W.request=!0;if(!W.parse&&J.includes("parse"))W.parse=!0;if(!W.transform&&J.includes("transform"))W.transform=!0;if(!W.handle&&J.includes("handle"))W.handle=!0;if(!W.beforeHandle&&J.includes("beforeHandle"))W.beforeHandle=!0;if(!W.afterHandle&&J.includes("afterHandle"))W.afterHandle=!0;if(!W.error&&J.includes("error"))W.error=!0;if(!W.context&&J.includes("context"))W.context=!0;if(!W.store&&J.includes("store"))W.store=!0;if(!W.set&&J.includes("set"))W.set=!0;return J},k1=($,W,J)=>{const X=W.indexOf($+"\n",J),Z=W.indexOf($+"\t",J),Q=W.indexOf($+",",J),B=W.indexOf($+";",J),Y=W.indexOf($+" ",J);return[X,Z,Q,B,Y].filter((G)=>G>0).sort((G,K)=>G-K)[0]||-1};var Z1=($,W,J=0)=>{if(J>5)return[];const X=[];let Z=W;while(!0){let Q=k1(" = "+$,Z);if(Q===-1){const G=Z.indexOf(" = "+$);if(G+3+$.length!==Z.length)break;Q=G}const B=Z.slice(0,Q);let Y=B.slice(B.lastIndexOf(" ")+1);if(Y==="}"){const[G,K]=k$(B);X.push(Z.slice(G,K)),Z=Z.slice(Q+3+$.length);continue}while(Y.charCodeAt(0)===44)Y=Y.slice(1);while(Y.charCodeAt(0)===9)Y=Y.slice(1);X.push(Y),Z=Z.slice(Q+3+$.length)}for(let Q of X){if(Q.charCodeAt(0)===123)continue;const B=Z1(Q,W);if(B.length>0)X.push(...B)}return X},f1=($)=>{if(!$)return;if(!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return $}const J=$.indexOf("...");if(J===-1)return;return $.slice(J+3).trimEnd()},g1=($,W,J)=>{const X=(Z,Q)=>$.includes(Q+"."+Z)||$.includes(Q+'["'+Z+'"]')||$.includes(Q+"['"+Z+"']");for(let Z of W){if(!Z)continue;if(Z.charCodeAt(0)===123){if(Z=h0(Z),!J.query&&Z.includes("query"))J.query=!0;if(!J.headers&&Z.includes("headers"))J.headers=!0;if(!J.body&&Z.includes("body"))J.body=!0;if(!J.cookie&&Z.includes("cookie"))J.cookie=!0;if(!J.set&&Z.includes("set"))J.set=!0;continue}if($.includes("("+Z+")")){J.query=!0,J.headers=!0,J.body=!0,J.cookie=!0,J.set=!0,J.queries=[],J.unknownQueries=!0;break}if(!J.query&&X("query",Z))J.query=!0;if($.includes("return "+Z)||$.includes("return "+Z+".query"))J.query=!0,J.unknownQueries=!0,J.queries=[];if(!J.unknownQueries&&J.query){let Q=Z+".";if($.includes(Q+"query"))Q=Z+".query";while(!0){let B=$.indexOf(Q);if(B===-1&&$.indexOf(Z+"[")!==-1){J.queries=[],J.unknownQueries=!0;break}if(B!==-1){let Y=k1("",$,B+Q.length+1);if(Y===-1)Y=void 0;const G=B+Z.length+1;$=$.slice(B+Z.length+1);let K=$.slice(0,Y?Y-G:Y).trimEnd();while(B!==-1)if(B=K.indexOf("."),B!==-1)K=K.slice(B+1);if(K.charCodeAt(K.length-1)===59)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===44)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===93)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===41)K=K.slice(0,-1);if(K&&!J.queries.includes(K)){J.queries.push(K);continue}}break}}if(!J.headers&&X("headers",Z))J.headers=!0;if(!J.body&&X("body",Z))J.body=!0;if(!J.cookie&&X("cookie",Z))J.cookie=!0;if(!J.set&&X("set",Z))J.set=!0;if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}return W},u$=($)=>{while(!0){const W=$.indexOf("=");if(W===-1)break;const J=$.indexOf(",",W),X=$.indexOf("}",W),Z=[J,X].filter((Q)=>Q>0).sort((Q,B)=>Q-B)[0]||-1;if(Z===-1){$=$.slice(0,W);break}$=$.slice(0,W)+$.slice(Z)}return $.split(",").map((W)=>W.trim()).join(", ")},m$=($)=>{for(let W of $){if(W.charCodeAt(0)===123)return!1;if(W.indexOf("'")!==-1)return!1;if(W.indexOf('"')!==-1)return!1;if(W.indexOf("\n")!==-1)return!1;if(W.indexOf("\t")!==-1)return!1}return!0},d$=($,W,J)=>{const X=(Z,Q)=>$.includes(Z+"."+Q)||$.includes(Z+'["'+Q+'"]')||$.includes(Z+"['"+Q+"']");for(let Z of W){if(Z.charCodeAt(0)===123){if(Z=h0(Z),!J.request&&Z.includes("request"))J.request=!0;if(!J.parse&&Z.includes("parse"))J.parse=!0;if(!J.transform&&Z.includes("transform"))J.transform=!0;if(!J.handle&&Z.includes("handle"))J.handle=!0;if(!J.beforeHandle&&Z.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&Z.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&Z.includes("error"))J.error=!0;if(!J.context&&Z.includes("context"))J.context=!0;if(!J.store&&Z.includes("store"))J.store=!0;if(!J.set&&Z.includes("set"))J.set=!0;continue}if($.includes("("+Z+")")){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&&X("request",Z))J.request=!0;if(!J.parse&&X("parse",Z))J.parse=!0;if(!J.transform&&X("transform",Z))J.transform=!0;if(!J.handle&&X("handle",Z))J.handle=!0;if(!J.beforeHandle&&X("beforeHandle",Z))J.beforeHandle=!0;if(!J.afterHandle&&X("afterHandle",Z))J.afterHandle=!0;if(!J.error&&X("error",Z))J.error=!0;if(!J.context&&X("context",Z))J.context=!0;if(!J.store&&X("store",Z))J.store=!0;if(!J.set&&X("set",Z))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 W},u0=($,W={queries:[],query:!1,headers:!1,body:!1,cookie:!1,set:!1,unknownQueries:!1})=>{const J=[];if($.handler&&typeof $.handler==="function")J.push($.handler);if($.beforeHandle?.length)J.push(...$.beforeHandle);if($.parse?.length)J.push(...$.parse);if($.error?.length)J.push(...$.error);if($.transform?.length)J.push(...$.transform);if($.afterHandle?.length)J.push(...$.afterHandle);if($.mapResponse?.length)J.push(...$.mapResponse);if($.request?.length)J.push(...$.request);if($.onResponse?.length)J.push(...$.onResponse);for(let X of J){if(!X)continue;const Z="fn"in X?X.fn:X,[Q,B,{isArrowReturn:Y}]=y1(Z.toString()),G=f$(Q,W),K=f1(G);if(Y&&(B==="query"||G&&B.startsWith(G+".query")))W.query=!0,W.unknownQueries=!0,W.queries=[];if(K){const F=Z1(K,B);F.splice(0,-1,K),g1(B,F,W)}const _=G||K;if(_&&B.includes("return "+_+".query"))W.query=!0,W.unknownQueries=!0,W.queries=[];if(W.query){g1(B,["query"],W);const F=Q.indexOf("query: {");if(F!==-1){const z=Q.slice(F+7),[A,j]=v1(z),V=u$(z.slice(A,j));for(let U of V.slice(1,-1).split(",")){const D=U.indexOf(":");if(D!==-1)U=U.slice(0,D);if(U=U.trim(),U&&!W.queries.includes(U))W.queries.push(U.trim())}}}if(W.query&&W.headers&&W.body&&W.cookie&&W.set)break}if(!m$(W.queries))W.unknownQueries=!0,W.queries=[];return W},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 $){const[X,Z]=y1(J.toString()),Q=h$(X,W),B=f1(Q);if(B){const Y=Z1(B,Z);Y.splice(0,-1,B),d$(Z,Y,W);continue}if(W.request&&W.parse&&W.transform&&W.handle&&W.beforeHandle&&W.afterHandle&&W.error&&W.context&&W.store&&W.set)break}return W};import{Value as n0} from"@sinclair/typebox/value";import{Kind as U1} from"@sinclair/typebox";import{Value as z0} from"@sinclair/typebox/value";import{TypeCompiler as t1} from"@sinclair/typebox/compiler";var p$=function($,W){if(typeof $!=="string")throw new TypeError("argument str must be a string");var J={},X=W||{},Z=X.decode||i$,Q=0;while(Q<$.length){var B=$.indexOf("=",Q);if(B===-1)break;var Y=$.indexOf(";",Q);if(Y===-1)Y=$.length;else if(Y<B){Q=$.lastIndexOf(";",B-1)+1;continue}var G=$.slice(Q,B).trim();if(J[G]===void 0){var K=$.slice(B+1,Y).trim();if(K.charCodeAt(0)===34)K=K.slice(1,-1);J[G]=n$(K,Z)}Q=Y+1}return J},l$=function($,W,J){var X=J||{},Z=X.encode||s$;if(typeof Z!=="function")throw new TypeError("option encode is invalid");if(!m0.test($))throw new TypeError("argument name is invalid");var Q=Z(W);if(Q&&!m0.test(Q))throw new TypeError("argument val is invalid");var B=$+"="+Q;if(X.maxAge!=null){var Y=X.maxAge-0;if(isNaN(Y)||!isFinite(Y))throw new TypeError("option maxAge is invalid");B+="; Max-Age="+Math.floor(Y)}if(X.domain){if(!m0.test(X.domain))throw new TypeError("option domain is invalid");B+="; Domain="+X.domain}if(X.path){if(!m0.test(X.path))throw new TypeError("option path is invalid");B+="; Path="+X.path}if(X.expires){var G=X.expires;if(!t$(G)||isNaN(G.valueOf()))throw new TypeError("option expires is invalid");B+="; Expires="+G.toUTCString()}if(X.httpOnly)B+="; HttpOnly";if(X.secure)B+="; Secure";if(X.partitioned)B+="; Partitioned";if(X.priority){var K=typeof X.priority==="string"?X.priority.toLowerCase():X.priority;switch(K){case"low":B+="; Priority=Low";break;case"medium":B+="; Priority=Medium";break;case"high":B+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(X.sameSite){var _=typeof X.sameSite==="string"?X.sameSite.toLowerCase():X.sameSite;switch(_){case!0:B+="; SameSite=Strict";break;case"lax":B+="; SameSite=Lax";break;case"strict":B+="; SameSite=Strict";break;case"none":B+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return B},i$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},s$=function($){return encodeURIComponent($)},t$=function($){return c$.call($)==="[object Date]"||$ instanceof Date},n$=function($,W){try{return W($)}catch(J){return $}};/*!
|
|
2
|
+
var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames:x$}=Object;var g$=Object.prototype.hasOwnProperty;var N0=($,J,w)=>{w=$!=null?L$(H$($)):{};const B=J||!$||!$.__esModule?I1(w,"default",{value:$,enumerable:!0}):w;for(let X of x$($))if(!g$.call(B,X))I1(B,X,{get:()=>$[X],enumerable:!0});return B};var K0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var L1=K0((kJ,X1)=>{var A0=function(){},v$=function($,J,w){this.fn=$,this.context=J,this.once=w||!1},E1=function($,J,w,B,X){if(typeof w!=="function")throw new TypeError("The listener must be a function");var W=new v$(w,B||$,X),Z=y?y+J:J;if(!$._events[Z])$._events[Z]=W,$._eventsCount++;else if(!$._events[Z].fn)$._events[Z].push(W);else $._events[Z]=[$._events[Z],W];return $},u0=function($,J){if(--$._eventsCount===0)$._events=new A0;else delete $._events[J]},g=function(){this._events=new A0,this._eventsCount=0},y$=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(A0.prototype=Object.create(null),!new A0().__proto__)y=!1}g.prototype.eventNames=function $(){var J=[],w,B;if(this._eventsCount===0)return J;for(B in w=this._events)if(y$.call(w,B))J.push(y?B.slice(1):B);if(Object.getOwnPropertySymbols)return J.concat(Object.getOwnPropertySymbols(w));return J};g.prototype.listeners=function $(J){var w=y?y+J:J,B=this._events[w];if(!B)return[];if(B.fn)return[B.fn];for(var X=0,W=B.length,Z=new Array(W);X<W;X++)Z[X]=B[X].fn;return Z};g.prototype.listenerCount=function $(J){var w=y?y+J:J,B=this._events[w];if(!B)return 0;if(B.fn)return 1;return B.length};g.prototype.emit=function $(J,w,B,X,W,Z){var Q=y?y+J:J;if(!this._events[Q])return!1;var Y=this._events[Q],G=arguments.length,K,U;if(Y.fn){if(Y.once)this.removeListener(J,Y.fn,void 0,!0);switch(G){case 1:return Y.fn.call(Y.context),!0;case 2:return Y.fn.call(Y.context,w),!0;case 3:return Y.fn.call(Y.context,w,B),!0;case 4:return Y.fn.call(Y.context,w,B,X),!0;case 5:return Y.fn.call(Y.context,w,B,X,W),!0;case 6:return Y.fn.call(Y.context,w,B,X,W,Z),!0}for(U=1,K=new Array(G-1);U<G;U++)K[U-1]=arguments[U];Y.fn.apply(Y.context,K)}else{var R=Y.length,F;for(U=0;U<R;U++){if(Y[U].once)this.removeListener(J,Y[U].fn,void 0,!0);switch(G){case 1:Y[U].fn.call(Y[U].context);break;case 2:Y[U].fn.call(Y[U].context,w);break;case 3:Y[U].fn.call(Y[U].context,w,B);break;case 4:Y[U].fn.call(Y[U].context,w,B,X);break;default:if(!K)for(F=1,K=new Array(G-1);F<G;F++)K[F-1]=arguments[F];Y[U].fn.apply(Y[U].context,K)}}}return!0};g.prototype.on=function $(J,w,B){return E1(this,J,w,B,!1)};g.prototype.once=function $(J,w,B){return E1(this,J,w,B,!0)};g.prototype.removeListener=function $(J,w,B,X){var W=y?y+J:J;if(!this._events[W])return this;if(!w)return u0(this,W),this;var Z=this._events[W];if(Z.fn){if(Z.fn===w&&(!X||Z.once)&&(!B||Z.context===B))u0(this,W)}else{for(var Q=0,Y=[],G=Z.length;Q<G;Q++)if(Z[Q].fn!==w||X&&!Z[Q].once||B&&Z[Q].context!==B)Y.push(Z[Q]);if(Y.length)this._events[W]=Y.length===1?Y[0]:Y;else u0(this,W)}return this};g.prototype.removeAllListeners=function $(J){var w;if(J){if(w=y?y+J:J,this._events[w])u0(this,w)}else this._events=new A0,this._eventsCount=0;return this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=y;g.EventEmitter=g;if(typeof X1!=="undefined")X1.exports=g});var c0=K0((dJ,c1)=>{var o$=function($){var J=$.indexOf("%");if(J===-1)return $;var w=$.length,B="",X=0,W=0,Z=J,Q=m1;while(J>-1&&J<w){var Y=d1($[J+1],4),G=d1($[J+2],0),K=Y|G,U=Y1[K];if(Q=Y1[256+Q+U],W=W<<6|K&Y1[364+U],Q===m1)B+=$.slice(X,Z),B+=W<=65535?String.fromCharCode(W):String.fromCharCode(55232+(W>>10),56320+(W&1023)),W=0,X=J+3,J=Z=$.indexOf("%",X);else if(Q===n$)return null;else{if(J+=3,J<w&&$.charCodeAt(J)===37)continue;return null}}return B+$.slice(X)},d1=function($,J){var w=a$[$];return w===void 0?255:w<<J},m1=12,n$=0,Y1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],a$={"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=o$});var W$=K0((Kw,X$)=>{var QJ=function($){const J=new B$;if(typeof $!=="string")return J;let w=$.length,B="",X="",W=-1,Z=-1,Q=!1,Y=!1,G=!1,K=!1,U=!1,R=0;for(let F=0;F<w+1;F++)if(R=F!==w?$.charCodeAt(F):38,R===38){if(U=Z>W,!U)Z=F;if(B=$.slice(W+1,Z),U||B.length>0){if(G)B=B.replace(w$," ");if(Q)B=J$(B)||B;if(U){if(X=$.slice(Z+1,F),K)X=X.replace(w$," ");if(Y)X=J$(X)||X}const C=J[B];if(C===void 0)J[B]=X;else if(C.pop)C.push(X);else J[B]=[C,X]}X="",W=F,Z=F,Q=!1,Y=!1,G=!1,K=!1}else if(R===61)if(Z<=W)Z=F;else Y=!0;else if(R===43)if(Z>W)K=!0;else G=!0;else if(R===37)if(Z>W)Y=!0;else Q=!0;return J},J$=c0(),w$=/\+/g,B$=function(){};B$.prototype=Object.create(null);X$.exports=QJ});var Q$=K0((Uw,Z$)=>{var SJ=function($){const J=$.length;if(J===0)return"";let w="",B=0,X=0;$:for(;X<J;X++){let W=$.charCodeAt(X);while(W<128){if(YJ[W]!==1){if(B<X)w+=$.slice(B,X);B=X+1,w+=i[W]}if(++X===J)break $;W=$.charCodeAt(X)}if(B<X)w+=$.slice(B,X);if(W<2048){B=X+1,w+=i[192|W>>6]+i[128|W&63];continue}if(W<55296||W>=57344){B=X+1,w+=i[224|W>>12]+i[128|W>>6&63]+i[128|W&63];continue}if(++X,X>=J)throw new Error("URI malformed");const Z=$.charCodeAt(X)&1023;B=X+1,W=65536+((W&1023)<<10|Z),w+=i[240|W>>18]+i[128|W>>12&63]+i[128|W>>6&63]+i[128|W&63]}if(B===0)return $;if(B<J)return w+$.slice(B);return w},i=Array.from({length:256},($,J)=>"%"+((J<16?"0":"")+J.toString(16)).toUpperCase()),YJ=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]);Z$.exports={encodeString:SJ}});var G$=K0((zw,S$)=>{var Y$=function($){const J=typeof $;if(J==="string")return D1($);else if(J==="bigint")return $.toString();else if(J==="boolean")return $?"true":"false";else if(J==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:D1(""+$);return""},GJ=function($){let J="";if($===null||typeof $!=="object")return J;const w="&",B=Object.keys($),X=B.length;let W=0;for(let Z=0;Z<X;Z++){const Q=B[Z],Y=$[Q],G=D1(Q)+"=";if(Z)J+=w;if(Array.isArray(Y)){W=Y.length;for(let K=0;K<W;K++){if(K)J+=w;J+=G,J+=Y$(Y[K])}}else J+=G,J+=Y$(Y)}return J},{encodeString:D1}=Q$();S$.exports=GJ});var M1=K0((Rw,b0)=>{var K$=W$(),U$=G$(),z$={parse:K$,stringify:U$};b0.exports=z$;b0.exports.default=z$;b0.exports.parse=K$;b0.exports.stringify=U$});var U0=($,J)=>({part:$,store:null,inert:J!==void 0?new Map(J.map((w)=>[w.part.charCodeAt(0),w])):null,params:null,wildcardStore:null}),b1=($,J)=>({...$,part:J}),T1=($)=>({paramName:$,store:null,inert:null});class B0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,J,w){let B;if(typeof J!="string")throw TypeError("Route path must be a string");J===""?J="/":J[0]!=="/"&&(J=`/${J}`),this.history.push([$,J,w]);let X=J[J.length-1]==="*";X&&(J=J.slice(0,-1));let W=J.split(B0.regex.static),Z=J.match(B0.regex.params)||[];W[W.length-1]===""&&W.pop(),B=this.root[$]?this.root[$]:this.root[$]=U0("/");let Q=0;for(let Y=0;Y<W.length;++Y){let G=W[Y];if(Y>0){let K=Z[Q++].slice(1);if(B.params===null)B.params=T1(K);else if(B.params.paramName!==K)throw Error(`Cannot create route "${J}" with parameter "${K}" because a route already exists with a different parameter name ("${B.params.paramName}") in the same location`);let U=B.params;if(U.inert===null){B=U.inert=U0(G);continue}B=U.inert}for(let K=0;;){if(K===G.length){if(K<B.part.length){let U=b1(B,B.part.slice(K));Object.assign(B,U0(G,[U]))}break}if(K===B.part.length){if(B.inert===null)B.inert=new Map;else if(B.inert.has(G.charCodeAt(K))){B=B.inert.get(G.charCodeAt(K)),G=G.slice(K),K=0;continue}let U=U0(G.slice(K));B.inert.set(G.charCodeAt(K),U),B=U;break}if(G[K]!==B.part[K]){let U=b1(B,B.part.slice(K)),R=U0(G.slice(K));Object.assign(B,U0(B.part.slice(0,K),[U,R])),B=R;break}++K}}if(Q<Z.length){let Y=Z[Q],G=Y.slice(1);if(B.params===null)B.params=T1(G);else if(B.params.paramName!==G)throw Error(`Cannot create route "${J}" with parameter "${G}" 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=w),B.params.store}return X?(B.wildcardStore===null&&(B.wildcardStore=w),B.wildcardStore):(B.store===null&&(B.store=w),B.store)}find($,J){let w=this.root[$];return w?B1(J,J.length,w,0):null}}var B1=($,J,w,B)=>{let X=w?.part,W=B+X.length;if(X.length>1){if(W>J)return null;if(X.length<15){for(let Z=1,Q=B+1;Z<X.length;++Z,++Q)if(X.charCodeAt(Z)!==$.charCodeAt(Q))return null}else if($.substring(B,W)!==X)return null}if(W===J)return w.store!==null?{store:w.store,params:{}}:w.wildcardStore!==null?{store:w.wildcardStore,params:{"*":""}}:null;if(w.inert!==null){let Z=w.inert.get($.charCodeAt(W));if(Z!==void 0){let Q=B1($,J,Z,W);if(Q!==null)return Q}}if(w.params!==null){let Z=w.params,Q=$.indexOf("/",W);if(Q!==W){if(Q===-1||Q>=J){if(Z.store!==null){let Y={};return Y[Z.paramName]=$.substring(W,J),{store:Z.store,params:Y}}}else if(Z.inert!==null){let Y=B1($,J,Z.inert,Q);if(Y!==null)return Y.params[Z.paramName]=$.substring(W,Q),Y}}}return w.wildcardStore!==null?{store:w.wildcardStore,params:{"*":$.substring(W,J)}}:null};var H1=N0(L1(),1);var x1=H1.default;var f0=()=>{let $;return[new Promise((w)=>{$=w}),$]},J0=()=>{const[$,J]=f0(),[w,B]=f0(),X=[],W=[];return{signal:$,consume:(Z)=>{switch(Z.type){case"begin":if(Z.unit&&X.length===0)for(let Q=0;Q<Z.unit;Q++){const[Y,G]=f0(),[K,U]=f0();X.push(Y),W.push([(R)=>{G({children:[],end:K,name:R.name??"",skip:!1,time:R.time})},(R)=>{U(R)}])}J({children:X,end:w,name:Z.name??"",skip:!1,time:Z.time});break;case"end":B(Z.time);break}},consumeChild(Z){switch(Z.type){case"begin":if(!W[0])return;const[Q]=W[0];Q({children:[],end:w,name:Z.name??"",skip:!1,time:Z.time});break;case"end":const Y=W.shift();if(!Y)return;Y[1](Z.time)}},resolve(){J({children:[],end:new Promise((Z)=>Z(0)),name:"",skip:!0,time:0});for(let[Z,Q]of W)Z({children:[],end:new Promise((Y)=>Y(0)),name:"",skip:!0,time:0}),Q(0);B(0)}}},g1=($,J,w)=>{if(typeof w==="object")w=w.fn;return async function B(B){if(B.event!=="request"||B.type!=="begin")return;const X=B.id,W=$(),Z=J0(),Q=J0(),Y=J0(),G=J0(),K=J0(),U=J0(),R=J0(),F=J0();Z.consume(B);const C=(P)=>{if(P.id===X)switch(P.event){case"request":Z.consume(P);break;case"request.unit":Z.consumeChild(P);break;case"parse":Q.consume(P);break;case"parse.unit":Q.consumeChild(P);break;case"transform":Y.consume(P);break;case"transform.unit":Y.consumeChild(P);break;case"beforeHandle":G.consume(P);break;case"beforeHandle.unit":G.consumeChild(P);break;case"handle":K.consume(P);break;case"afterHandle":U.consume(P);break;case"afterHandle.unit":U.consumeChild(P);break;case"error":R.consume(P);break;case"error.unit":R.consumeChild(P);break;case"response":if(P.type==="begin")Z.resolve(),Q.resolve(),Y.resolve(),G.resolve(),K.resolve(),U.resolve(),R.resolve();else W.off("event",C);F.consume(P);break;case"response.unit":F.consumeChild(P);break;case"exit":Z.resolve(),Q.resolve(),Y.resolve(),G.resolve(),K.resolve(),U.resolve(),R.resolve();break}};W.on("event",C),await w({id:X,context:B.ctx,set:B.ctx?.set,store:B.ctx?.store,time:B.time,request:Z.signal,parse:Q.signal,transform:Y.signal,beforeHandle:G.signal,handle:K.signal,afterHandle:U.signal,error:R.signal,response:F.signal}),W.emit(`res${X}.${J}`,void 0)}};var v1=($)=>{if($.startsWith("async"))$=$.slice(6);let J=-1;if($.charCodeAt(0)===40){if(J=$.indexOf(") => {\n"),J!==-1)return[$.slice(1,J),$.slice(J+5),{isArrowReturn:!1}];if(J=$.indexOf(") => "),J!==-1)return[$.slice(1,J),$.slice(J+5),{isArrowReturn:!0}]}if($.startsWith("function")){J=$.indexOf("(");const X=$.indexOf(")");return[$.slice(J+1,X),$.slice(X+2),{isArrowReturn:!1}]}const w=$.indexOf("(");if(w!==-1){const[X,W]=$.split("\n",2),Z=X.lastIndexOf(")")+1;return[X.slice(w,Z),"{"+W,{isArrowReturn:!1}]}const B=$.split("\n",2);return[B[0],B[1],{isArrowReturn:!1}]},k1=($)=>{const J=$.indexOf("{");if(J===-1)return[-1,0];let w=J+1,B=1;for(;w<$.length;w++){const X=$.charCodeAt(w);if(X===123)B++;else if(X===125)B--;if(B===0)break}if(B!==0)return[0,$.length];return[J,w+1]},k$=($)=>{const J=$.lastIndexOf("}");if(J===-1)return[-1,0];let w=J-1,B=1;for(;w>=0;w--){const X=$.charCodeAt(w);if(X===125)B++;else if(X===123)B--;if(B===0)break}if(B!==0)return[-1,0];return[w,J+1]},h0=($)=>{if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)$=$.slice(2,-2);while(!0){const[J,w]=k1($);if(J===-1)break;$=$.slice(0,J-2)+$.slice(w+1)}return $.replace(/:/g,"").trim()},u$=($,J)=>{const w=h0($);if(!J.query&&w.includes("query"))J.query=!0;if(!J.headers&&w.includes("headers"))J.headers=!0;if(!J.body&&w.includes("body"))J.body=!0;if(!J.cookie&&w.includes("cookie"))J.cookie=!0;if(!J.set&&w.includes("set"))J.set=!0;return w},f$=($,J)=>{const w=h0($);if(!J.request&&w.includes("request"))J.request=!0;if(!J.parse&&w.includes("parse"))J.parse=!0;if(!J.transform&&w.includes("transform"))J.transform=!0;if(!J.handle&&w.includes("handle"))J.handle=!0;if(!J.beforeHandle&&w.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&w.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&w.includes("error"))J.error=!0;if(!J.context&&w.includes("context"))J.context=!0;if(!J.store&&w.includes("store"))J.store=!0;if(!J.set&&w.includes("set"))J.set=!0;return w},u1=($,J,w)=>{const B=J.indexOf($+"\n",w),X=J.indexOf($+"\t",w),W=J.indexOf($+",",w),Z=J.indexOf($+";",w),Q=J.indexOf($+" ",w);return[B,X,W,Z,Q].filter((Y)=>Y>0).sort((Y,G)=>Y-G)[0]||-1};var W1=($,J,w=0)=>{if(w>5)return[];const B=[];let X=J;while(!0){let W=u1(" = "+$,X);if(W===-1){const Y=X.indexOf(" = "+$);if(Y+3+$.length!==X.length)break;W=Y}const Z=X.slice(0,W);let Q=Z.slice(Z.lastIndexOf(" ")+1);if(Q==="}"){const[Y,G]=k$(Z);B.push(X.slice(Y,G)),X=X.slice(W+3+$.length);continue}while(Q.charCodeAt(0)===44)Q=Q.slice(1);while(Q.charCodeAt(0)===9)Q=Q.slice(1);B.push(Q),X=X.slice(W+3+$.length)}for(let W of B){if(W.charCodeAt(0)===123)continue;const Z=W1(W,J);if(Z.length>0)B.push(...Z)}return B},f1=($)=>{if(!$)return;if(!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return $}const w=$.indexOf("...");if(w===-1)return;return $.slice(w+3).trimEnd()},y1=($,J,w)=>{const B=(X,W)=>$.includes(W+"."+X)||$.includes(W+'["'+X+'"]')||$.includes(W+"['"+X+"']");for(let X of J){if(!X)continue;if(X.charCodeAt(0)===123){if(X=h0(X),!w.query&&X.includes("query"))w.query=!0;if(!w.headers&&X.includes("headers"))w.headers=!0;if(!w.body&&X.includes("body"))w.body=!0;if(!w.cookie&&X.includes("cookie"))w.cookie=!0;if(!w.set&&X.includes("set"))w.set=!0;continue}if($.includes("("+X+")")){w.query=!0,w.headers=!0,w.body=!0,w.cookie=!0,w.set=!0,w.queries=[],w.unknownQueries=!0;break}if(!w.query&&B("query",X))w.query=!0;if($.includes("return "+X)||$.includes("return "+X+".query"))w.query=!0,w.unknownQueries=!0,w.queries=[];if(!w.unknownQueries&&w.query){let W=X+".";if($.includes(W+"query"))W=X+".query";while(!0){let Z=$.indexOf(W);if(Z===-1&&$.indexOf(X+"[")!==-1){w.queries=[],w.unknownQueries=!0;break}if(Z!==-1){let Q=u1("",$,Z+W.length+1);if(Q===-1)Q=void 0;const Y=Z+X.length+1;$=$.slice(Z+X.length+1);let G=$.slice(0,Q?Q-Y:Q).trimEnd();while(Z!==-1)if(Z=G.indexOf("."),Z!==-1)G=G.slice(Z+1);if(G.charCodeAt(G.length-1)===59)G=G.slice(0,-1);if(G.charCodeAt(G.length-1)===44)G=G.slice(0,-1);if(G.charCodeAt(G.length-1)===93)G=G.slice(0,-1);if(G.charCodeAt(G.length-1)===41)G=G.slice(0,-1);if(G&&!w.queries.includes(G)){w.queries.push(G);continue}}break}}if(!w.headers&&B("headers",X))w.headers=!0;if(!w.body&&B("body",X))w.body=!0;if(!w.cookie&&B("cookie",X))w.cookie=!0;if(!w.set&&B("set",X))w.set=!0;if(w.query&&w.headers&&w.body&&w.cookie&&w.set)break}return J},h$=($)=>{while(!0){const J=$.indexOf("=");if(J===-1)break;const w=$.indexOf(",",J),B=$.indexOf("}",J),X=[w,B].filter((W)=>W>0).sort((W,Z)=>W-Z)[0]||-1;if(X===-1){$=$.slice(0,J);break}$=$.slice(0,J)+$.slice(X)}return $.split(",").map((J)=>J.trim()).join(", ")},m$=($)=>{for(let J of $){if(J.charCodeAt(0)===123)return!1;if(J.indexOf("'")!==-1)return!1;if(J.indexOf('"')!==-1)return!1;if(J.indexOf("\n")!==-1)return!1;if(J.indexOf("\t")!==-1)return!1}return!0},d$=($,J,w)=>{const B=(X,W)=>$.includes(X+"."+W)||$.includes(X+'["'+W+'"]')||$.includes(X+"['"+W+"']");for(let X of J){if(X.charCodeAt(0)===123){if(X=h0(X),!w.request&&X.includes("request"))w.request=!0;if(!w.parse&&X.includes("parse"))w.parse=!0;if(!w.transform&&X.includes("transform"))w.transform=!0;if(!w.handle&&X.includes("handle"))w.handle=!0;if(!w.beforeHandle&&X.includes("beforeHandle"))w.beforeHandle=!0;if(!w.afterHandle&&X.includes("afterHandle"))w.afterHandle=!0;if(!w.error&&X.includes("error"))w.error=!0;if(!w.context&&X.includes("context"))w.context=!0;if(!w.store&&X.includes("store"))w.store=!0;if(!w.set&&X.includes("set"))w.set=!0;continue}if($.includes("("+X+")")){w.request=!0,w.parse=!0,w.transform=!0,w.handle=!0,w.beforeHandle=!0,w.afterHandle=!0,w.error=!0,w.context=!0,w.store=!0,w.set=!0;break}if(!w.request&&B("request",X))w.request=!0;if(!w.parse&&B("parse",X))w.parse=!0;if(!w.transform&&B("transform",X))w.transform=!0;if(!w.handle&&B("handle",X))w.handle=!0;if(!w.beforeHandle&&B("beforeHandle",X))w.beforeHandle=!0;if(!w.afterHandle&&B("afterHandle",X))w.afterHandle=!0;if(!w.error&&B("error",X))w.error=!0;if(!w.context&&B("context",X))w.context=!0;if(!w.store&&B("store",X))w.store=!0;if(!w.set&&B("set",X))w.set=!0;if(w.request&&w.parse&&w.transform&&w.handle&&w.beforeHandle&&w.afterHandle&&w.error&&w.context&&w.store&&w.set)break}return J},m0=($,J={queries:[],query:!1,headers:!1,body:!1,cookie:!1,set:!1,unknownQueries:!1})=>{const w=[];if($.handler&&typeof $.handler==="function")w.push($.handler);if($.beforeHandle?.length)w.push(...$.beforeHandle);if($.parse?.length)w.push(...$.parse);if($.error?.length)w.push(...$.error);if($.transform?.length)w.push(...$.transform);if($.afterHandle?.length)w.push(...$.afterHandle);if($.mapResponse?.length)w.push(...$.mapResponse);if($.request?.length)w.push(...$.request);if($.onResponse?.length)w.push(...$.onResponse);for(let B of w){if(!B)continue;const X="fn"in B?B.fn:B,[W,Z,{isArrowReturn:Q}]=v1(X.toString()),Y=u$(W,J),G=f1(Y);if(Q&&(Z==="query"||Y&&Z.startsWith(Y+".query")))J.query=!0,J.unknownQueries=!0,J.queries=[];if(G){const U=W1(G,Z);U.splice(0,-1,G),y1(Z,U,J)}const K=Y||G;if(K&&Z.includes("return "+K+".query"))J.query=!0,J.unknownQueries=!0,J.queries=[];if(J.query){y1(Z,["query"],J);const U=W.indexOf("query: {");if(U!==-1){const R=W.slice(U+7),[F,C]=k1(R),P=h$(R.slice(F,C));for(let S of P.slice(1,-1).split(",")){const z=S.indexOf(":");if(z!==-1)S=S.slice(0,z);if(S=S.trim(),S&&!J.queries.includes(S))J.queries.push(S.trim())}}}if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}if(!m$(J.queries))J.unknownQueries=!0,J.queries=[];return J},h1=($,J={request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1})=>{for(let w of $){const[B,X]=v1(w.toString()),W=f$(B,J),Z=f1(W);if(Z){const Q=W1(Z,X);Q.splice(0,-1,Z),d$(X,Q,J);continue}if(J.request&&J.parse&&J.transform&&J.handle&&J.beforeHandle&&J.afterHandle&&J.error&&J.context&&J.store&&J.set)break}return J};import{Value as n0} from"@sinclair/typebox/value";import{Kind as G1} from"@sinclair/typebox";import{Value as R0} from"@sinclair/typebox/value";import{TypeCompiler as r1} from"@sinclair/typebox/compiler";var p$=function($,J){if(typeof $!=="string")throw new TypeError("argument str must be a string");var w={},B=J||{},X=B.decode||l$,W=0;while(W<$.length){var Z=$.indexOf("=",W);if(Z===-1)break;var Q=$.indexOf(";",W);if(Q===-1)Q=$.length;else if(Q<Z){W=$.lastIndexOf(";",Z-1)+1;continue}var Y=$.slice(W,Z).trim();if(w[Y]===void 0){var G=$.slice(Z+1,Q).trim();if(G.charCodeAt(0)===34)G=G.slice(1,-1);w[Y]=r$(G,X)}W=Q+1}return w},s$=function($,J,w){var B=w||{},X=B.encode||i$;if(typeof X!=="function")throw new TypeError("option encode is invalid");if(!d0.test($))throw new TypeError("argument name is invalid");var W=X(J);if(W&&!d0.test(W))throw new TypeError("argument val is invalid");var Z=$+"="+W;if(B.maxAge!=null){var Q=B.maxAge-0;if(isNaN(Q)||!isFinite(Q))throw new TypeError("option maxAge is invalid");Z+="; Max-Age="+Math.floor(Q)}if(B.domain){if(!d0.test(B.domain))throw new TypeError("option domain is invalid");Z+="; Domain="+B.domain}if(B.path){if(!d0.test(B.path))throw new TypeError("option path is invalid");Z+="; Path="+B.path}if(B.expires){var Y=B.expires;if(!t$(Y)||isNaN(Y.valueOf()))throw new TypeError("option expires is invalid");Z+="; Expires="+Y.toUTCString()}if(B.httpOnly)Z+="; HttpOnly";if(B.secure)Z+="; Secure";if(B.partitioned)Z+="; Partitioned";if(B.priority){var G=typeof B.priority==="string"?B.priority.toLowerCase():B.priority;switch(G){case"low":Z+="; Priority=Low";break;case"medium":Z+="; Priority=Medium";break;case"high":Z+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(B.sameSite){var K=typeof B.sameSite==="string"?B.sameSite.toLowerCase():B.sameSite;switch(K){case!0:Z+="; SameSite=Strict";break;case"lax":Z+="; SameSite=Lax";break;case"strict":Z+="; SameSite=Strict";break;case"none":Z+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return Z},l$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},i$=function($){return encodeURIComponent($)},t$=function($){return c$.call($)==="[object Date]"||$ instanceof Date},r$=function($,J){try{return J($)}catch(w){return $}};/*!
|
|
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 Q1=p$,B1=l$;var c$=Object.prototype.toString,m0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var p1=I0(d0(),1);class r{$;W;J;constructor($,W,J={}){this.name=$;this.jar=W;this.initial=J}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var c1=($,W,J)=>{if(!$.cookie)$.cookie={};return new Proxy(W,{get(X,Z){if(Z in W)return new r(Z,$.cookie,Object.assign({},J??{},W[Z]));return new r(Z,$.cookie,Object.assign({},J))}})},c0=async($,W,{secrets:J,sign:X,...Z}={})=>{if(!W)return c1($,{},Z);const Q=typeof J==="string";if(X&&X!==!0&&!Array.isArray(X))X=[X];const B={},Y=Q1(W);for(let[G,K]of Object.entries(Y)){let _=p1.default(K);if(X===!0||X?.includes(G)){if(!J)throw new Error("No secret is provided to cookie plugin");if(Q){const z=await G1(_,J);if(z===!1)throw new P0(G);_=z}else{let z=!0;for(let A=0;A<J.length;A++){const j=await G1(_,J[A]);if(j!==!1){z=!0,_=j;break}}if(!z)throw new P0(G)}}const F=_.charCodeAt(0);if(F===123||F===91)try{B[G]={value:JSON.parse(_)};continue}catch{}if(D0(_)){B[G]={value:parseInt(_)};continue}if(_==="true"){B[G]={value:!0};continue}if(_==="false"){B[G]={value:!1};continue}B[G]={value:_}}return c1($,B,Z)};var V0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let W in $)return!0;return!1},S0=($,W)=>{const J=$.size;if(!W&&J||J&&W&&W.status!==206&&W.status!==304&&W.status!==412&&W.status!==416){if(W){if(W.headers instanceof Headers){if(V0)W.headers=W.headers.toJSON();else for(let[X,Z]of W.headers.entries())if(X in W.headers)W.headers[X]=Z}return new Response($,{status:W.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`},W.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${J-1}/${J}`}})}return new Response($)},l1=($,W)=>{if(!$)return $;$.delete("Set-Cookie");for(let J=0;J<W.length;J++){const X=W[J].indexOf("=");$.append("Set-Cookie",`${W[J].slice(0,X)}=${W[J].slice(X+1)||""}`)}return $},i1=($)=>{if(!$||!m($))return;const W=[];for(let[J,X]of Object.entries($)){if(!J||!X)continue;const Z=X.value;if(Z===void 0||Z===null)continue;W.push(B1(J,typeof Z==="object"?JSON.stringify(Z):Z+"",X))}if(W.length===0)return;if(W.length===1)return W[0];return W},u=($,W,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])W.status=$[d],$=$.response;if(m(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=Z0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&m(W.cookie))W.headers["Set-Cookie"]=i1(W.cookie);if(W.headers["Set-Cookie"]&&Array.isArray(W.headers["Set-Cookie"]))W.headers=l1(new Headers(W.headers),W.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return S0($,W);case"Object":case"Array":return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,W);case void 0:if(!$)return new Response("",W);return Response.json($,W);case"Response":const X={...W.headers};if(V0)W.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(Z in W.headers)W.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);return $;case"Error":return s($,W);case"Promise":return $.then((Z)=>u(Z,W));case"Function":return u($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"Cookie":if($ instanceof r)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response){const Z=Object.assign({},W.headers);if(V0)W.headers=$.headers.toJSON();else for(let[Q,B]of $.headers.entries())if(Q in W.headers)W.headers[Q]=B;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>u(Z,W));if($ instanceof Error)return s($,W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return S0($,W);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return s($,W);case"Promise":return $.then((X)=>{const Z=o(X);if(Z!==void 0)return Z;return new Response("")});case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((X)=>u(X,W));if($ instanceof Error)return s($,W);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},h=($,W,J)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])W.status=$[d],$=$.response;if(m(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=Z0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&m(W.cookie))W.headers["Set-Cookie"]=i1(W.cookie);if(W.headers["Set-Cookie"]&&Array.isArray(W.headers["Set-Cookie"]))W.headers=l1(new Headers(W.headers),W.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return S0($,W);case"Object":case"Array":return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,W);case void 0:if(!$)return;return Response.json($,W);case"Response":const X=Object.assign({},W.headers);if(V0)W.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(!(Z in W.headers))W.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);if($.status!==W.status)W.status=$.status;return $;case"Promise":return $.then((Z)=>{const Q=h(Z,W);if(Q!==void 0)return Q});case"Error":return s($,W);case"Function":return h($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"Cookie":if($ instanceof r)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response){const Z={...W.headers};if(V0)W.headers=$.headers.toJSON();else for(let[Q,B]of $.headers.entries())if(Q in W.headers)W.headers[Q]=B;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>h(Z,W));if($ instanceof Error)return s($,W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return S0($,W);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((X)=>{const Z=h(X,W);if(Z!==void 0)return Z});case"Error":return s($,W);case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((X)=>h(X,W));if($ instanceof Error)return s($,W);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},o=($,W)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return u($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return S0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return s($);case"Promise":return $.then(o);case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(o);if($ instanceof Error)return s($);if("charCodeAt"in $){const J=$.charCodeAt(0);if(J===123||J===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},s=($,W)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:W?.status!==200?W?.status??500:500,headers:W?.headers});var B9=function($){let W=$;while(W.endsWith("="))W=W.slice(0,-1);return W},_1=($,W)=>{const J=new URL($);return J.pathname=W,J.toString()},e$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),K1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,W,{skipKeys:J}={})=>{if(K1($)&&K1(W))for(let[X,Z]of Object.entries(W)){if(J?.includes(X))continue;if(!K1(Z)||!(X in $)||e$(Z)){$[X]=Z;continue}$[X]=p($[X],Z)}return $},$9=($,W)=>{const{properties:J,...X}=$??{},{properties:Z,...Q}=W??{};return p(X,Q)},b=($=[],W=[])=>{if(!$)return[];if(!W)return $;const J=[],X=[];if(!Array.isArray($))$=[$];if(!Array.isArray(W))W=[W];for(let Z of $)if(J.push(Z),Z.checksum)X.push(Z.checksum);for(let Z of W)if(!X.includes(Z.checksum))J.push(Z);return J},W9=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],J9=W9.reduce(($,W)=>($[W]=!0,$),{}),X9=($,W)=>{const J=(X)=>typeof X==="object"&&Object.keys(X).every(D0);if(J($)&&J(W))return{...$,...W};return W??$},f=($,W,{allowMacro:J=!1}={})=>{return{...J?{...$,...W}:void 0,body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,response:X9($?.response,W?.response),type:$?.type||W?.type,detail:p(W?.detail??{},$?.detail??{}),parse:b($?.parse,W?.parse),transform:b($?.transform,W?.transform),beforeHandle:b($?.beforeHandle,W?.beforeHandle),afterHandle:b($?.afterHandle,W?.afterHandle),onResponse:b($?.onResponse,W?.onResponse),mapResponse:b($?.mapResponse,W?.mapResponse),trace:b($?.trace,W?.trace),error:b($?.error,W?.error)}},k=($,{models:W={},dynamic:J=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const Q=typeof $==="string"?W[$]:$;if(Q.type==="object"&&"additionalProperties"in Q===!1)Q.additionalProperties=Z;const B=(G)=>z0.Clean(Q,G);if(J){const G={schema:Q,references:"",checkFunc:()=>{},code:"",Check:(K)=>z0.Check(Q,K),Errors:(K)=>z0.Errors(Q,K),Code:()=>""};if(X&&Q.additionalProperties===!0)G.Clean=B;if(Q.config){if(G.config=Q.config,G?.schema?.config)delete G.schema.config}return G}const Y=t1.Compile(Q,Object.values(W));if(Y.Clean=B,Q.config){if(Y.config=Q.config,Y?.schema?.config)delete Y.schema.config}return Y},p0=($,{models:W={},dynamic:J=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const Q=typeof $==="string"?W[$]:$,B=(G,K)=>{const _=(z)=>z0.Clean(G,z);if(J)return{schema:G,references:"",checkFunc:()=>{},code:"",Check:(z)=>z0.Check(G,z),Errors:(z)=>z0.Errors(G,z),Code:()=>""};const F=t1.Compile(G,K);if(X&&G.additionalProperties===!0)F.Clean=_;return F};if(U1 in Q){if("additionalProperties"in Q===!1)Q.additionalProperties=Z;return{200:B(Q,Object.values(W))}}const Y={};return Object.keys(Q).forEach((G)=>{const K=Q[+G];if(typeof K==="string"){if(K in W){const _=W[K];_.type==="object"&&"additionalProperties"in _,Y[+G]=U1 in _?B(_,Object.values(W)):_}return}if(K.type==="object"&&"additionalProperties"in K===!1)K.additionalProperties=Z;Y[+G]=U1 in K?B(K,Object.values(W)):K}),Y},Z9=typeof Bun!=="undefined",Q9=Z9&&typeof Bun.hash==="function",C0=($)=>{if(Q9)return Bun.hash($);let W=9;for(let J=0;J<$.length;)W=Math.imul(W^$.charCodeAt(J++),387420489);return W=W^W>>>9},l0=({validator:$,defaultConfig:W={},config:J,dynamic:X,models:Z})=>{let Q=k($,{dynamic:X,models:Z,additionalProperties:!0});if(m(W))if(Q)Q.config=$9(Q.config,J);else Q=k(C.Cookie({}),{dynamic:X,models:Z,additionalProperties:!0}),Q.config=W;return Q},i0=($,W,J)=>{const X=(Z)=>{if(!Z)return;if(!Array.isArray(Z)){const B=Z;if(J&&!B.checksum)B.checksum=J;if(B.scope==="scoped")B.scope="local";return B}const Q=[...Z];for(let B of Q){if(J&&!B.checksum)B.checksum=J;if(B.scope==="scoped")B.scope="local"}return Q};return{start:b($.start,X(W?.start)),request:b($.request,X(W?.request)),parse:b($.parse,X(W?.parse)),transform:b($.transform,X(W?.transform)),beforeHandle:b($.beforeHandle,X(W?.beforeHandle)),afterHandle:b($.afterHandle,X(W?.afterHandle)),mapResponse:b($.mapResponse,X(W?.mapResponse)),onResponse:b($.onResponse,X(W?.onResponse)),trace:$.trace,error:b($.error,X(W?.error)),stop:b($.stop,X(W?.stop))}},n1=($,W,{skipIfHasType:J=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(J)$.scope??=W;else $.scope=W;return $}for(let X of $)if(J)X.scope??=W;else X.scope=W;return $},Q0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const W=[];for(let J of $)switch(J.scope){case"global":case"scoped":W.push({...J});break}return W},F1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:Q0($?.parse),transform:Q0($?.transform),beforeHandle:Q0($?.beforeHandle),afterHandle:Q0($?.afterHandle),onResponse:Q0($?.onResponse),error:Q0($?.error),mapResponse:Q0($?.mapResponse)}},Z0={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},s0=Object.fromEntries(Object.entries(Z0).map(([$,W])=>[W,$])),s1=new TextEncoder,w0=async($,W)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(W===null)throw new TypeError("Secret key must be provided.");const J=await crypto.subtle.importKey("raw",s1.encode(W),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),X=await crypto.subtle.sign("HMAC",J,s1.encode($));return $+"."+B9(Buffer.from(X).toString("base64"))},G1=async($,W)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(W===null)throw new TypeError("Secret key must be provided.");const J=$.slice(0,$.lastIndexOf("."));return await w0(J,W)===$?J:!1},D1=($,W,J=W)=>{if(!$||typeof $!=="object"||!W)return;for(let[X,Z]of Object.entries(W)){if(X in J9||!(X in $))continue;const Q=$[X];if(typeof Q==="function")Q(Z);else if(typeof Q==="object")D1(Q,Z,J)}},r1=({globalHook:$,localHook:W})=>(J)=>(X,Z)=>{if(typeof X==="function")X={fn:X};if("fn"in X||Array.isArray(X)){if(!W[J])W[J]=[];if(typeof W[J]==="function")W[J]=[W[J]];if(Array.isArray(X))W[J]=W[J].concat(X);else W[J].push(X);return}const{insert:Q="after",stack:B="local"}=X;if(typeof Z==="function")Z={fn:Z};if(B==="global")if(!Array.isArray(Z))if(Q==="before")$[J].unshift(Z);else $[J].push(Z);else if(Q==="before")$[J]=Z.concat($[J]);else $[J]=$[J].concat(Z);else{if(!W[J])W[J]=[];if(typeof W[J]==="function")W[J]=[W[J]];if(!Array.isArray(Z))if(Q==="before")W[J].unshift(Z);else W[J].push(Z);else if(Q==="before")W[J]=Z.concat(W[J]);else W[J]=W[J].concat(Z)}},D0=($)=>{if($.length<16)return $.trim().length!==0&&!Number.isNaN(Number($));if($.length===16){const W=Number($);if(W.toString()===$)return $.trim().length!==0&&!Number.isNaN(W)}return!1};class z1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,W){return(this.root??Promise.resolve()).then($,W)}}var c=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const W=[];for(let J of $)if(typeof J==="function")W.push({fn:J});else if("fn"in J)W.push(J);return W},o1=($)=>{return{...$,start:c($?.start),request:c($?.request),parse:c($?.parse),transform:c($?.transform),beforeHandle:c($?.beforeHandle),afterHandle:c($?.afterHandle),onResponse:c($?.onResponse),mapResponse:c($?.mapResponse),trace:c($?.trace),error:c($?.error),stop:c($?.stop)}},a1=($)=>{return{...$,start:$.start?.map((W)=>W.fn),request:$.request?.map((W)=>W.fn),parse:$.parse?.map((W)=>W.fn),transform:$.transform?.map((W)=>W.fn),beforeHandle:$.beforeHandle?.map((W)=>W.fn),afterHandle:$.afterHandle?.map((W)=>W.fn),onResponse:$.onResponse?.map((W)=>W.fn),mapResponse:$.mapResponse?.map((W)=>W.fn),trace:$.trace?.map((W)=>W.fn),error:$.error?.map((W)=>W.fn),stop:$.stop?.map((W)=>W.fn)}},t0=($)=>({event:{body:$.event.body,cookie:$.event.cookie,headers:$.event.headers,queries:[...$.event.queries],query:$.event.query,set:$.event.set,unknownQueries:$.event.unknownQueries},trace:{request:$.trace.request,parse:$.trace.parse,transform:$.trace.transform,handle:$.trace.handle,beforeHandle:$.trace.beforeHandle,afterHandle:$.trace.afterHandle,error:$.trace.error,context:$.trace.context,store:$.trace.store,set:$.trace.set}}),w1=($,W=301)=>new Response(null,{status:W,headers:{Location:$}});var e1=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,B0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),T0=(e1?.NODE_ENV??e1?.ENV)==="production",M1=($,W)=>({[d]:Z0[$]??$,response:W??($ in s0?s0[$]:$),_type:void 0});class r0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class Y0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class o0 extends Error{W;code="PARSE";status=400;constructor($,W){super($??"PARSE");this.body=W}}class P0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,W){super(W??`"${$}" has invalid cookie signature`);this.key=$}}class q extends Error{$;W;J;code="VALIDATION";status=422;constructor($,W,J){if(typeof J==="object"&&d in J)J=J.response;const X=T0?void 0:("Errors"in W)?W.Errors(J).First():n0.Errors(W,J).First(),Z=X?.schema.error?typeof X.schema.error==="function"?X.schema.error($,W,J):X.schema.error:void 0,Q=X?.path||"root";let B="";if(Z)B=typeof Z==="object"?JSON.stringify(Z):Z+"";else if(T0)B=JSON.stringify({type:"validation",on:$,message:X?.message,found:J});else{const Y=W?.schema??W,G="Errors"in W?[...W.Errors(J)]:[...n0.Errors(W,J)];let K;try{K=n0.Create(Y)}catch(_){K={type:"Could not create expected value",message:_?.message,error:_}}B=JSON.stringify({type:"validation",on:$,property:Q,message:X?.message,expected:K,found:J,errors:G},null,2)}super(B);this.type=$;this.validator=W;this.value=J;Object.setPrototypeOf(this,q.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const W="schema"in $?$.schema:$;try{return n0.Create(W)}catch{return W}}get model(){return q.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var A1={open($){$.data.open?.($)},message($,W){$.data.message?.($,W)},drain($){$.data.drain?.($)},close($,W,J){$.data.close?.($,W,J)}};class M0{$;W;validator;constructor($,W){this.raw=$;this.data=W;if(this.validator=$.data.validator,$.data.id)this.id=$.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($){this.raw.data.id=$}get publish(){return($,W=void 0,J)=>{if(this.validator?.Check(W)===!1)throw new q("message",this.validator,W);if(typeof W==="object")W=JSON.stringify(W);return this.raw.publish($,W,J),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new q("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var D$=I0(N1(),1),z$=I0(d0(),1);import{Value as L0} from"@sinclair/typebox/value";var _9=(new Headers()).toJSON,w$={value:0},M$=({hasTrace:$,hasTraceSet:W=!1,addFn:J,condition:X={}})=>{if($)return J("\nconst reporter = getReporter()\n"),(Z,{name:Q,attribute:B="",unit:Y=0}={})=>{const G=Z.indexOf("."),K=G===-1;if(Z!=="request"&&Z!=="response"&&!X[K?Z:Z.slice(0,G)])return()=>{if(W&&Z==="afterHandle")J("\nawait traceDone\n")};if(K)Q||=Z;else Q||="anonymous";return J("\n"+`reporter.emit('event', {
|
|
7
|
+
*/var Z1=p$,Q1=s$;var c$=Object.prototype.toString,d0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var s1=N0(c0(),1);class r{$;J;w;constructor($,J,w={}){this.name=$;this.jar=J;this.initial=w}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var p1=($,J,w)=>{if(!$.cookie)$.cookie={};return new Proxy(J,{get(B,X){if(X in J)return new r(X,$.cookie,Object.assign({},w??{},J[X]));return new r(X,$.cookie,Object.assign({},w))}})},p0=async($,J,{secrets:w,sign:B,...X}={})=>{if(!J)return p1($,{},X);const W=typeof w==="string";if(B&&B!==!0&&!Array.isArray(B))B=[B];const Z={},Q=Z1(J);for(let[Y,G]of Object.entries(Q)){let K=s1.default(G);if(B===!0||B?.includes(Y)){if(!w)throw new Error("No secret is provided to cookie plugin");if(W){const R=await S1(K,w);if(R===!1)throw new P0(Y);K=R}else{let R=!0;for(let F=0;F<w.length;F++){const C=await S1(K,w[F]);if(C!==!1){R=!0,K=C;break}}if(!R)throw new P0(Y)}}const U=K.charCodeAt(0);if(U===123||U===91)try{Z[Y]={value:JSON.parse(K)};continue}catch{}if(z0(K)){Z[Y]={value:parseInt(K)};continue}if(K==="true"){Z[Y]={value:!0};continue}if(K==="false"){Z[Y]={value:!1};continue}Z[Y]={value:K}}return p1($,Z,X)};var O0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let J in $)return!0;return!1},V0=($,J)=>{const w=$.size;if(!J&&w||w&&J&&J.status!==206&&J.status!==304&&J.status!==412&&J.status!==416){if(J){if(J.headers instanceof Headers){if(O0)J.headers=J.headers.toJSON();else for(let[B,X]of J.headers.entries())if(B in J.headers)J.headers[B]=X}return new Response($,{status:J.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`},J.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${w-1}/${w}`}})}return new Response($)},l1=($,J)=>{if(!$)return $;$.delete("Set-Cookie");for(let w=0;w<J.length;w++){const B=J[w].indexOf("=");$.append("Set-Cookie",`${J[w].slice(0,B)}=${J[w].slice(B+1)||""}`)}return $},i1=($)=>{if(!$||!m($))return;const J=[];for(let[w,B]of Object.entries($)){if(!w||!B)continue;const X=B.value;if(X===void 0||X===null)continue;J.push(Q1(w,typeof X==="object"?JSON.stringify(X):X+"",B))}if(J.length===0)return;if(J.length===1)return J[0];return J},h=($,J,w)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return new Response("",J);return Response.json($,J);case"Response":const B={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(X in J.headers)J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);return $;case"Error":return l($,J);case"Promise":return $.then((X)=>h(X,J));case"Function":return h($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>h(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($,J);case"Promise":return $.then((B)=>{const X=n(B);if(X!==void 0)return X;return new Response("")});case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>h(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},f=($,J,w)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])J.status=$[d],$=$.response;if(m(J.headers)||J.status!==200||J.redirect||J.cookie){if(typeof J.status==="string")J.status=X0[J.status];if(J.redirect){if(J.headers.Location=J.redirect,!J.status||J.status<300||J.status>=400)J.status=302}if(J.cookie&&m(J.cookie))J.headers["Set-Cookie"]=i1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=l1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return V0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,J);case void 0:if(!$)return;return Response.json($,J);case"Response":const B=Object.assign({},J.headers);if(O0)J.headers=$.headers.toJSON();else for(let[X,W]of $.headers.entries())if(!(X in J.headers))J.headers[X]=W;for(let X in B)$.headers.append(X,B[X]);if($.status!==J.status)J.status=$.status;return $;case"Promise":return $.then((X)=>{const W=f(X,J);if(W!==void 0)return W});case"Error":return l($,J);case"Function":return f($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const X={...J.headers};if(O0)J.headers=$.headers.toJSON();else for(let[W,Z]of $.headers.entries())if(W in J.headers)J.headers[W]=Z;for(let W in X)$.headers.append(W,X[W]);return $}if($ instanceof Promise)return $.then((X)=>f(X,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($,J)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($,J);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return w?.signal.addEventListener("abort",{handleEvent(){if(!w?.signal.aborted)$.cancel(w)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((B)=>{const X=f(B,J);if(X!==void 0)return X});case"Error":return l($,J);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((B)=>f(B,J));if($ instanceof Error)return l($,J);if("charCodeAt"in $){const B=$.charCodeAt(0);if(B===123||B===91){if(!J.headers["Content-Type"])J.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),J)}}return new Response($)}},n=($,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return h($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return V0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return J?.signal.addEventListener("abort",{handleEvent(){if(!J?.signal.aborted)$.cancel(J)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return l($);case"Promise":return $.then(n);case"Function":return n($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(n);if($ instanceof Error)return l($);if("charCodeAt"in $){const w=$.charCodeAt(0);if(w===123||w===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},l=($,J)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:J?.status!==200?J?.status??500:500,headers:J?.headers});var ZJ=function($){let J=$;while(J.endsWith("="))J=J.slice(0,-1);return J},U1=($,J)=>{const w=new URL($);return w.pathname=J,w.toString()},e$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),K1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,J,{skipKeys:w}={})=>{if(K1($)&&K1(J))for(let[B,X]of Object.entries(J)){if(w?.includes(B))continue;if(!K1(X)||!(B in $)||e$(X)){$[B]=X;continue}$[B]=p($[B],X)}return $},$J=($,J)=>{const{properties:w,...B}=$??{},{properties:X,...W}=J??{};return p(B,W)},L=($=[],J=[])=>{if(!$)return[];if(!J)return $;const w=[],B=[];if(!Array.isArray($))$=[$];if(!Array.isArray(J))J=[J];for(let X of $)if(w.push(X),X.checksum)B.push(X.checksum);for(let X of J)if(!B.includes(X.checksum))w.push(X);return w},JJ=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],wJ=JJ.reduce(($,J)=>($[J]=!0,$),{}),BJ=($,J)=>{const w=(B)=>typeof B==="object"&&Object.keys(B).every(z0);if(w($)&&w(J))return{...$,...J};return J??$},u=($,J,{allowMacro:w=!1}={})=>{return{...w?{...$,...J}:void 0,body:J?.body??$?.body,headers:J?.headers??$?.headers,params:J?.params??$?.params,query:J?.query??$?.query,response:BJ($?.response,J?.response),type:$?.type||J?.type,detail:p(J?.detail??{},$?.detail??{}),parse:L($?.parse,J?.parse),transform:L($?.transform,J?.transform),beforeHandle:L($?.beforeHandle,J?.beforeHandle),afterHandle:L($?.afterHandle,J?.afterHandle),onResponse:L($?.onResponse,J?.onResponse),mapResponse:L($?.mapResponse,J?.mapResponse),trace:L($?.trace,J?.trace),error:L($?.error,J?.error)}},k=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$;if(W.type==="object"&&"additionalProperties"in W===!1)W.additionalProperties=X;const Z=(Y)=>R0.Clean(W,Y);if(w){const Y={schema:W,references:"",checkFunc:()=>{},code:"",Check:(G)=>R0.Check(W,G),Errors:(G)=>R0.Errors(W,G),Code:()=>""};if(B&&W.additionalProperties===!0)Y.Clean=Z;if(W.config){if(Y.config=W.config,Y?.schema?.config)delete Y.schema.config}return Y}const Q=r1.Compile(W,Object.values(J));if(Q.Clean=Z,W.config){if(Q.config=W.config,Q?.schema?.config)delete Q.schema.config}return Q},s0=($,{models:J={},dynamic:w=!1,normalize:B=!1,additionalProperties:X=B})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const W=typeof $==="string"?J[$]:$,Z=(Y,G)=>{const K=(R)=>R0.Clean(Y,R);if(w)return{schema:Y,references:"",checkFunc:()=>{},code:"",Check:(R)=>R0.Check(Y,R),Errors:(R)=>R0.Errors(Y,R),Code:()=>""};const U=r1.Compile(Y,G);if(B&&Y.additionalProperties===!0)U.Clean=K;return U};if(G1 in W){if("additionalProperties"in W===!1)W.additionalProperties=X;return{200:Z(W,Object.values(J))}}const Q={};return Object.keys(W).forEach((Y)=>{const G=W[+Y];if(typeof G==="string"){if(G in J){const K=J[G];K.type==="object"&&"additionalProperties"in K,Q[+Y]=G1 in K?Z(K,Object.values(J)):K}return}if(G.type==="object"&&"additionalProperties"in G===!1)G.additionalProperties=X;Q[+Y]=G1 in G?Z(G,Object.values(J)):G}),Q},XJ=typeof Bun!=="undefined",WJ=XJ&&typeof Bun.hash==="function",q0=($)=>{if(WJ)return Bun.hash($);let J=9;for(let w=0;w<$.length;)J=Math.imul(J^$.charCodeAt(w++),387420489);return J=J^J>>>9},l0=({validator:$,defaultConfig:J={},config:w,dynamic:B,models:X})=>{let W=k($,{dynamic:B,models:X,additionalProperties:!0});if(m(J))if(W)W.config=$J(W.config,w);else W=k(V.Cookie({}),{dynamic:B,models:X,additionalProperties:!0}),W.config=J;return W},i0=($,J,w)=>{const B=(X)=>{if(!X)return;if(!Array.isArray(X)){const Z=X;if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local";return Z}const W=[...X];for(let Z of W){if(w&&!Z.checksum)Z.checksum=w;if(Z.scope==="scoped")Z.scope="local"}return W};return{start:L($.start,B(J?.start)),request:L($.request,B(J?.request)),parse:L($.parse,B(J?.parse)),transform:L($.transform,B(J?.transform)),beforeHandle:L($.beforeHandle,B(J?.beforeHandle)),afterHandle:L($.afterHandle,B(J?.afterHandle)),mapResponse:L($.mapResponse,B(J?.mapResponse)),onResponse:L($.onResponse,B(J?.onResponse)),trace:$.trace,error:L($.error,B(J?.error)),stop:L($.stop,B(J?.stop))}},n1=($,J,{skipIfHasType:w=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(w)$.scope??=J;else $.scope=J;return $}for(let B of $)if(w)B.scope??=J;else B.scope=J;return $},W0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const J=[];for(let w of $)switch(w.scope){case"global":case"scoped":J.push({...w});break}return J},z1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:W0($?.parse),transform:W0($?.transform),beforeHandle:W0($?.beforeHandle),afterHandle:W0($?.afterHandle),onResponse:W0($?.onResponse),error:W0($?.error),mapResponse:W0($?.mapResponse)}},X0={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},t0=Object.fromEntries(Object.entries(X0).map(([$,J])=>[J,$])),t1=new TextEncoder,_0=async($,J)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(J===null)throw new TypeError("Secret key must be provided.");const w=await crypto.subtle.importKey("raw",t1.encode(J),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),B=await crypto.subtle.sign("HMAC",w,t1.encode($));return $+"."+ZJ(Buffer.from(B).toString("base64"))},S1=async($,J)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(J===null)throw new TypeError("Secret key must be provided.");const w=$.slice(0,$.lastIndexOf("."));return await _0(w,J)===$?w:!1},R1=($,J,w=J)=>{if(!$||typeof $!=="object"||!J)return;for(let[B,X]of Object.entries(J)){if(B in wJ||!(B in $))continue;const W=$[B];if(typeof W==="function")W(X);else if(typeof W==="object")R1(W,X,w)}},o1=({globalHook:$,localHook:J})=>(w)=>(B,X)=>{if(typeof B==="function")B={fn:B};if("fn"in B||Array.isArray(B)){if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(Array.isArray(B))J[w]=J[w].concat(B);else J[w].push(B);return}const{insert:W="after",stack:Z="local"}=B;if(typeof X==="function")X={fn:X};if(Z==="global")if(!Array.isArray(X))if(W==="before")$[w].unshift(X);else $[w].push(X);else if(W==="before")$[w]=X.concat($[w]);else $[w]=$[w].concat(X);else{if(!J[w])J[w]=[];if(typeof J[w]==="function")J[w]=[J[w]];if(!Array.isArray(X))if(W==="before")J[w].unshift(X);else J[w].push(X);else if(W==="before")J[w]=X.concat(J[w]);else J[w]=J[w].concat(X)}},z0=($)=>{if($.length<16)return $.trim().length!==0&&!Number.isNaN(Number($));if($.length===16){const J=Number($);if(J.toString()===$)return $.trim().length!==0&&!Number.isNaN(J)}return!1};class _1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,J){return(this.root??Promise.resolve()).then($,J)}}var c=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const J=[];for(let w of $)if(typeof w==="function")J.push({fn:w});else if("fn"in w)J.push(w);return J},a1=($)=>{return{...$,start:c($?.start),request:c($?.request),parse:c($?.parse),transform:c($?.transform),beforeHandle:c($?.beforeHandle),afterHandle:c($?.afterHandle),onResponse:c($?.onResponse),mapResponse:c($?.mapResponse),trace:c($?.trace),error:c($?.error),stop:c($?.stop)}},e1=($)=>{return{...$,start:$.start?.map((J)=>J.fn),request:$.request?.map((J)=>J.fn),parse:$.parse?.map((J)=>J.fn),transform:$.transform?.map((J)=>J.fn),beforeHandle:$.beforeHandle?.map((J)=>J.fn),afterHandle:$.afterHandle?.map((J)=>J.fn),onResponse:$.onResponse?.map((J)=>J.fn),mapResponse:$.mapResponse?.map((J)=>J.fn),trace:$.trace?.map((J)=>J.fn),error:$.error?.map((J)=>J.fn),stop:$.stop?.map((J)=>J.fn)}},r0=($)=>({event:{body:$.event.body,cookie:$.event.cookie,headers:$.event.headers,queries:[...$.event.queries],query:$.event.query,set:$.event.set,unknownQueries:$.event.unknownQueries},trace:{request:$.trace.request,parse:$.trace.parse,transform:$.trace.transform,handle:$.trace.handle,beforeHandle:$.trace.beforeHandle,afterHandle:$.trace.afterHandle,error:$.trace.error,context:$.trace.context,store:$.trace.store,set:$.trace.set}}),j1=($,J=301)=>new Response(null,{status:J,headers:{Location:$}});var $$=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,Z0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),I0=($$?.NODE_ENV??$$?.ENV)==="production",F1=($,J)=>({[d]:X0[$]??$,response:J??($ in t0?t0[$]:$),_type:void 0});class o0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class Q0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class a0 extends Error{J;code="PARSE";status=400;constructor($,J){super($??"PARSE");this.body=J}}class P0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,J){super(J??`"${$}" has invalid cookie signature`);this.key=$}}class I extends Error{$;J;w;code="VALIDATION";status=422;constructor($,J,w){if(typeof w==="object"&&d in w)w=w.response;const B=I0?void 0:("Errors"in J)?J.Errors(w).First():n0.Errors(J,w).First(),X=B?.schema.error?typeof B.schema.error==="function"?B.schema.error($,J,w):B.schema.error:void 0,W=B?.path||"root";let Z="";if(X)Z=typeof X==="object"?JSON.stringify(X):X+"";else if(I0)Z=JSON.stringify({type:"validation",on:$,message:B?.message,found:w});else{const Q=J?.schema??J,Y="Errors"in J?[...J.Errors(w)]:[...n0.Errors(J,w)];let G;try{G=n0.Create(Q)}catch(K){G={type:"Could not create expected value",message:K?.message,error:K}}Z=JSON.stringify({type:"validation",on:$,property:W,message:B?.message,expected:G,found:w,errors:Y},null,2)}super(Z);this.type=$;this.validator=J;this.value=w;Object.setPrototypeOf(this,I.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const J="schema"in $?$.schema:$;try{return n0.Create(J)}catch{return J}}get model(){return I.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var C1={open($){$.data.open?.($)},message($,J){$.data.message?.($,J)},drain($){$.data.drain?.($)},close($,J,w){$.data.close?.($,J,w)}};class j0{$;J;validator;constructor($,J){this.raw=$;this.data=J;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else{const w=new Uint32Array(1);crypto.getRandomValues(w),this.id=w[0].toString()}}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,J=void 0,w)=>{if(this.validator?.Check(J)===!1)throw new I("message",this.validator,J);if(typeof J==="object")J=JSON.stringify(J);return this.raw.publish($,J,w),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new I("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var R$=N0(M1(),1),_$=N0(c0(),1);import{Value as T0} from"@sinclair/typebox/value";var KJ=(new Headers()).toJSON,j$={value:0},F$=({hasTrace:$,hasTraceSet:J=!1,addFn:w,condition:B={}})=>{if($)return w("\nconst reporter = getReporter()\n"),(X,{name:W,attribute:Z="",unit:Q=0}={})=>{const Y=X.indexOf("."),G=Y===-1;if(X!=="request"&&X!=="response"&&!B[G?X:X.slice(0,Y)])return()=>{if(J&&X==="afterHandle")w("\nawait traceDone\n")};if(G)W||=X;else W||="anonymous";return w("\n"+`reporter.emit('event', {
|
|
8
8
|
id,
|
|
9
|
-
event: '${
|
|
9
|
+
event: '${X}',
|
|
10
10
|
type: 'begin',
|
|
11
|
-
name: '${
|
|
11
|
+
name: '${W}',
|
|
12
12
|
time: performance.now(),
|
|
13
|
-
${
|
|
14
|
-
${
|
|
15
|
-
})`.replace(/(\t| |\n)/g,"")+"\n"),()=>{if(
|
|
13
|
+
${G?`unit: ${Q},`:""}
|
|
14
|
+
${Z}
|
|
15
|
+
})`.replace(/(\t| |\n)/g,"")+"\n"),()=>{if(w("\n"+`reporter.emit('event', {
|
|
16
16
|
id,
|
|
17
|
-
event: '${
|
|
17
|
+
event: '${X}',
|
|
18
18
|
type: 'end',
|
|
19
19
|
time: performance.now()
|
|
20
|
-
})`.replace(/(\t| |\n)/g,"")+"\n"),
|
|
20
|
+
})`.replace(/(\t| |\n)/g,"")+"\n"),J&&X==="afterHandle")w("\nawait traceDone\n")}};else return()=>()=>{}},E0=($)=>{const J=$.indexOf(")");if($.charCodeAt(J+2)===61&&$.charCodeAt(J+5)!==123)return!0;return $.includes("return")},UJ=($,{injectResponse:J="",normalize:w=!1}={})=>({composeValidation:(B,X=`c.${B}`)=>$?`c.set.status = 422; throw new ValidationError('${B}', ${B}, ${X})`:`c.set.status = 422; return new ValidationError('${B}', ${B}, ${X}).toResponse(c.set.headers)`,composeResponseValidation:(B="r")=>{const X=$?`throw new ValidationError('response', response[c.set.status], ${B})`:`return new ValidationError('response', response[c.set.status], ${B}).toResponse(c.set.headers)`;let W="\n"+J+"\n";if(W+=`let er
|
|
21
21
|
|
|
22
|
-
if(${
|
|
23
|
-
er = ${
|
|
22
|
+
if(${B} && typeof ${B} === "object" && ELYSIA_RESPONSE in ${B})
|
|
23
|
+
er = ${B}[ELYSIA_RESPONSE]\n`,w)W+=`
|
|
24
24
|
if(!er && response[c.set.status]?.Clean)
|
|
25
|
-
${
|
|
25
|
+
${B} = response[c.set.status]?.Clean(${B})
|
|
26
26
|
else if(response[er]?.Clean)
|
|
27
|
-
${
|
|
27
|
+
${B}.response = response[er]?.Clean(${B}.response)`;return W+=`
|
|
28
28
|
if(er) {
|
|
29
|
-
if(!(${
|
|
29
|
+
if(!(${B} instanceof Response) && response[er]?.Check(${B}.response) === false) {
|
|
30
30
|
if(!(response instanceof Error)) {
|
|
31
|
-
c.set.status = ${
|
|
31
|
+
c.set.status = ${B}[ELYSIA_RESPONSE]
|
|
32
32
|
|
|
33
|
-
${
|
|
33
|
+
${X}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
} else if(!(${
|
|
36
|
+
} else if(!(${B} instanceof Response) && response[c.set.status]?.Check(${B}) === false) {
|
|
37
37
|
if(!(response instanceof Error))
|
|
38
|
-
${
|
|
39
|
-
}\n`,
|
|
40
|
-
if(_setCookie) {`,
|
|
41
|
-
c.set.cookie[key].value = await signCookie(cookie.value, '${
|
|
42
|
-
}`;else for(let
|
|
38
|
+
${X}
|
|
39
|
+
}\n`,W}}),Pw=Symbol.for("TypeBox.Kind");var Y0=($,J)=>{if(!J)return;if(J.type==="object"){const w=J.properties;if(!w)return!1;for(let B of Object.keys(w)){const X=w[B];if($ in X)return!0;if(X.type==="object"){if(Y0($,X))return!0}else if(X.anyOf){for(let W=0;W<X.anyOf.length;W++)if(Y0($,X.anyOf[W]))return!0}}return!1}return $ in J},N1=Symbol.for("TypeBox.Transform"),F0=($)=>{if(!$)return;if($.type==="object"&&$.properties){const J=$.properties;for(let w of Object.keys(J)){const B=J[w];if(B.type==="object"){if(F0(B))return!0}else if(B.anyOf){for(let W=0;W<B.anyOf.length;W++)if(F0(B.anyOf[W]))return!0}if(N1 in B)return!0}return!1}return N1 in $||$.properties&&N1 in $.properties},zJ=/(?:return|=>) \S+\(/g,x=($)=>{const J="fn"in $?$.fn:$;if(J.constructor.name==="AsyncFunction")return!0;const w=J.toString();if(w.includes("=> response.clone("))return!1;if(w.includes("await"))return!0;if(w.includes("async"))return!0;return!!w.match(zJ)},e0=({app:$,path:J,method:w,localHook:B,hooks:X,validator:W,handler:Z,allowMeta:Q=!1,appInference:{event:Y,trace:G}})=>{const K=typeof Z==="function";if(!K)Z=h(Z,{headers:$.setHeaders??{}});const U=$.config.forceErrorEncapsulation&&(K||X.afterHandle.length>0||X.beforeHandle.length>0||X.transform.length>0)||X.error.length>0||$.event.error.length>0||typeof Bun==="undefined"||X.onResponse.length>0||!!X.trace.length,R=K?"handler(c)":"handler",F=X.onResponse.length?`\n;(async () => {${X.onResponse.map((N,_)=>`await res${_}(c)`).join(";")}})();\n`:"",C=G,P=X.trace.length>0;let S="";const z=m0(Object.assign(B,{handler:Z}),Y),M=z.query||!!W.query,D=w!=="$INTERNALWS"&&w!=="GET"&&w!=="HEAD"&&X.type!=="none"&&(z.body||!!W.body),T=$.setHeaders,q=T&&!!Object.keys(T).length,e=z.headers||W.headers,v=z.cookie||!!W.cookie,t=v?l0({validator:W.cookie,defaultConfig:$.config.cookie,dynamic:!!$.config.aot,config:W.cookie?.config??{},models:$.definitions.type}):void 0,O=t?.config;let A="";if(O?.sign){if(!O.secrets)throw new Error(`t.Cookie required secret which is not set in (${w}) ${J}.`);const N=!O.secrets?void 0:typeof O.secrets==="string"?O.secrets:O.secrets[0];if(A+=`const _setCookie = c.set.cookie
|
|
40
|
+
if(_setCookie) {`,O.sign===!0)A+=`for(const [key, cookie] of Object.entries(_setCookie)) {
|
|
41
|
+
c.set.cookie[key].value = await signCookie(cookie.value, '${N}')
|
|
42
|
+
}`;else for(let _ of O.sign)A+=`if(_setCookie['${_}']?.value) { c.set.cookie['${_}'].value = await signCookie(_setCookie['${_}'].value, '${N}') }\n`;A+="}\n"}const $0=$.config.normalize,{composeValidation:S0,composeResponseValidation:x0}=UJ(U,{normalize:$0});if(e)S+=KJ?"c.headers = c.request.headers.toJSON()\n":`c.headers = {}
|
|
43
43
|
for (const [key, value] of c.request.headers.entries())
|
|
44
44
|
c.headers[key] = value
|
|
45
|
-
`;if(v){const
|
|
46
|
-
secrets: ${
|
|
47
|
-
sign: ${
|
|
48
|
-
${
|
|
49
|
-
${
|
|
50
|
-
${
|
|
51
|
-
${
|
|
52
|
-
${
|
|
53
|
-
${
|
|
54
|
-
${
|
|
55
|
-
${
|
|
56
|
-
}`:"undefined";if(
|
|
45
|
+
`;if(v){const N=(j,b)=>{const H=O?.[j]??b;if(!H)return typeof b==="string"?`${j}: "${b}",`:`${j}: ${b},`;if(typeof H==="string")return`${j}: '${H}',`;if(H instanceof Date)return`${j}: new Date(${H.getTime()}),`;return`${j}: ${H},`},_=O?`{
|
|
46
|
+
secrets: ${O.secrets!==void 0?typeof O.secrets==="string"?`'${O.secrets}'`:"["+O.secrets.reduce((j,b)=>j+`'${b}',`,"")+"]":"undefined"},
|
|
47
|
+
sign: ${O.sign===!0?!0:O.sign!==void 0?"["+O.sign.reduce((j,b)=>j+`'${b}',`,"")+"]":"undefined"},
|
|
48
|
+
${N("domain")}
|
|
49
|
+
${N("expires")}
|
|
50
|
+
${N("httpOnly")}
|
|
51
|
+
${N("maxAge")}
|
|
52
|
+
${N("path","/")}
|
|
53
|
+
${N("priority")}
|
|
54
|
+
${N("sameSite")}
|
|
55
|
+
${N("secure")}
|
|
56
|
+
}`:"undefined";if(e)S+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${_})\n`;else S+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${_})\n`}if(M){let N=[];if(W.query&&W.query.schema.type==="object")N=Object.keys(W.query.schema.properties);else for(let _ of z.queries)if(N.indexOf(_)===-1)N.push(_);if($.config.forceDynamicQuery===!0||z.unknownQueries===!0||!N.length)S+=`if(c.qi !== -1) {
|
|
57
57
|
c.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\+/g, ' '))
|
|
58
58
|
|
|
59
59
|
for(const key of Object.keys(c.query))
|
|
60
60
|
c.query[key] = decodeURIComponent(c.query[key])
|
|
61
|
-
} else c.query = {}`;else
|
|
61
|
+
} else c.query = {}`;else S+=`if(c.qi !== -1) {
|
|
62
62
|
let url = c.request.url.slice(c.qi).replace(/\\+/g, ' ')
|
|
63
63
|
|
|
64
|
-
${
|
|
65
|
-
${
|
|
66
|
-
if(memory === -1) memory = url.indexOf('?${
|
|
67
|
-
let a${
|
|
64
|
+
${N.map((_,j)=>`
|
|
65
|
+
${j===0?"let":""} memory = url.indexOf('&${_}=')
|
|
66
|
+
if(memory === -1) memory = url.indexOf('?${_}=')
|
|
67
|
+
let a${j}
|
|
68
68
|
|
|
69
69
|
if(memory !== -1) {
|
|
70
|
-
const start = memory + ${
|
|
70
|
+
const start = memory + ${_.length+2}
|
|
71
71
|
memory = url.indexOf('&', start)
|
|
72
72
|
|
|
73
|
-
if(memory === -1) a${
|
|
74
|
-
else a${
|
|
73
|
+
if(memory === -1) a${j} = decodeURIComponent(url.slice(start))
|
|
74
|
+
else a${j} = decodeURIComponent(url.slice(start, memory))
|
|
75
75
|
}`).join("\n")}
|
|
76
76
|
|
|
77
77
|
c.query = {
|
|
78
|
-
${
|
|
78
|
+
${N.map((_,j)=>`'${_}': a${j}`).join(", ")}
|
|
79
79
|
}
|
|
80
80
|
} else {
|
|
81
81
|
c.query = {}
|
|
82
|
-
}`}const
|
|
82
|
+
}`}const g0=G.set,y0=z.cookie||z.set||g0||e||K&&q;if(P)S+="\nconst id = c.$$requestId\n";const E=F$({hasTrace:P,hasTraceSet:g0,condition:C,addFn:(N)=>{S+=N}});if(S+=U?"\n try {\n":"",g0){S+="\nconst traceDone = Promise.all([";for(let N=0;N<X.trace.length;N++)S+=`new Promise(r => { reporter.once(\`res\${id}.${N}\`, r) }),`;S+="])\n"}const G0=typeof Z==="function"&&x(Z),w1=v||D||g0||G0||!!X.mapResponse.length||X.parse.length>0||X.afterHandle.some(x)||X.beforeHandle.some(x)||X.transform.some(x),b$=E("parse",{unit:X.parse.length});if(D){const N=X.parse.length||z.body||W.body;if(X.type&&!X.parse.length)switch(X.type){case"json":case"application/json":if(U)S+=`const tempBody = await c.request.text()
|
|
83
83
|
|
|
84
84
|
try {
|
|
85
85
|
c.body = JSON.parse(tempBody)
|
|
86
86
|
} catch {
|
|
87
87
|
throw new ParseError('Failed to parse body as found: ' + (typeof body === "string" ? "'" + body + "'" : body), body)
|
|
88
|
-
}`;else
|
|
88
|
+
}`;else S+="c.body = await c.request.json()";break;case"text":case"text/plain":S+="c.body = await c.request.text()\n";break;case"urlencoded":case"application/x-www-form-urlencoded":S+="c.body = parseQuery(await c.request.text())\n";break;case"arrayBuffer":case"application/octet-stream":S+="c.body = await c.request.arrayBuffer()\n";break;case"formdata":case"multipart/form-data":S+=`c.body = {}
|
|
89
89
|
|
|
90
90
|
const form = await c.request.formData()
|
|
91
91
|
for (const key of form.keys()) {
|
|
@@ -96,31 +96,31 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
96
96
|
if (value.length === 1)
|
|
97
97
|
c.body[key] = value[0]
|
|
98
98
|
else c.body[key] = value
|
|
99
|
-
}\n`;break}else if(
|
|
99
|
+
}\n`;break}else if(N){if(S+="\n",S+=e?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')",S+=`
|
|
100
100
|
if (contentType) {
|
|
101
101
|
const index = contentType.indexOf(';')
|
|
102
102
|
if (index !== -1) contentType = contentType.substring(0, index)\n
|
|
103
|
-
c.contentType = contentType\n`,
|
|
104
|
-
|
|
103
|
+
c.contentType = contentType\n`,X.parse.length){S+="let used = false\n";const _=E("parse",{unit:X.parse.length});for(let j=0;j<X.parse.length;j++){const b=E("parse.unit",{name:X.parse[j].fn.name}),H=`bo${j}`;if(j!==0)S+="if(!used) {\n";if(S+=`let ${H} = parse[${j}](c, contentType)\n`,S+=`if(${H} instanceof Promise) ${H} = await ${H}\n`,S+=`if(${H} !== undefined) { c.body = ${H}; used = true }\n`,b(),j!==0)S+="}"}_()}if(S+="\ndelete c.contentType\n",X.parse.length)S+="if (!used) {";if(X.type&&!Array.isArray(X.type))switch(X.type){case"json":case"application/json":if(U)S+=`const tempBody = await c.request.text()
|
|
104
|
+
|
|
105
105
|
try {
|
|
106
106
|
c.body = JSON.parse(tempBody)
|
|
107
107
|
} catch {
|
|
108
108
|
throw new ParseError('Failed to parse body as found: ' + (typeof body === "string" ? "'" + body + "'" : body), body)
|
|
109
|
-
}`;else
|
|
110
|
-
|
|
109
|
+
}`;else S+="c.body = await c.request.json()";break;case"text":case"text/plain":S+="c.body = await c.request.text()\n";break;case"urlencoded":case"application/x-www-form-urlencoded":S+="c.body = parseQuery(await c.request.text())\n";break;case"arrayBuffer":case"application/octet-stream":S+="c.body = await c.request.arrayBuffer()\n";break;case"formdata":case"multipart/form-data":S+=`c.body = {}
|
|
110
|
+
|
|
111
111
|
const form = await c.request.formData()
|
|
112
112
|
for (const key of form.keys()) {
|
|
113
113
|
if (c.body[key])
|
|
114
114
|
continue
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
const value = form.getAll(key)
|
|
117
117
|
if (value.length === 1)
|
|
118
118
|
c.body[key] = value[0]
|
|
119
119
|
else c.body[key] = value
|
|
120
|
-
}\n`;break}else
|
|
120
|
+
}\n`;break}else S+=`
|
|
121
121
|
switch (contentType) {
|
|
122
122
|
case 'application/json':
|
|
123
|
-
${
|
|
123
|
+
${U?`
|
|
124
124
|
const tempBody = await c.request.text()
|
|
125
125
|
|
|
126
126
|
try {
|
|
@@ -158,64 +158,64 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
break
|
|
161
|
-
}`;if(
|
|
161
|
+
}`;if(X.parse.length)S+="}";S+="}\n"}S+="\n"}if(b$(),X?.transform){const N=E("transform",{unit:X.transform.length});if(X.transform.length)S+="\nlet transformed\n";for(let _=0;_<X.transform.length;_++){const j=X.transform[_],b=E("transform.unit",{name:j.fn.name});S+=x(j)?`transformed = await transform[${_}](c)\n`:`transformed = transform[${_}](c)\n`,S+=`if(transformed?.[ELYSIA_RESPONSE])
|
|
162
162
|
throw transformed
|
|
163
163
|
else
|
|
164
|
-
Object.assign(c, transformed)\n`,
|
|
165
|
-
${
|
|
166
|
-
}`,
|
|
167
|
-
${
|
|
168
|
-
}`,
|
|
169
|
-
${
|
|
170
|
-
}`,
|
|
171
|
-
c.body = Object.assign(${JSON.stringify(
|
|
164
|
+
Object.assign(c, transformed)\n`,b()}N()}if(W){if(S+="\n",W.headers){if(Y0("default",W.headers.params))for(let[N,_]of Object.entries(T0.Default(W.headers.schema,{}))){const j=typeof _==="object"?JSON.stringify(_):`'${_}'`;if(j)S+=`c.headers['${N}'] ??= ${j}\n`}if(S+=`if(headers.Check(c.headers) === false) {
|
|
165
|
+
${S0("headers")}
|
|
166
|
+
}`,F0(W.headers.schema))S+="\nc.headers = headers.Decode(c.headers)\n"}if(W.params){if(Y0("default",W.params.schema))for(let[N,_]of Object.entries(T0.Default(W.params.schema,{}))){const j=typeof _==="object"?JSON.stringify(_):`'${_}'`;if(j)S+=`c.params['${N}'] ??= ${j}\n`}if(S+=`if(params.Check(c.params) === false) {
|
|
167
|
+
${S0("params")}
|
|
168
|
+
}`,F0(W.params.schema))S+="\nc.params = params.Decode(c.params)\n"}if(W.query){if($0)S+="c.query = query.Clean(c.query);\n";if(Y0("default",W.query.schema))for(let[N,_]of Object.entries(T0.Default(W.query.schema,{}))){const j=typeof _==="object"?JSON.stringify(_):`'${_}'`;if(j)S+=`c.query['${N}'] ??= ${j}\n`}if(S+=`if(query.Check(c.query) === false) {
|
|
169
|
+
${S0("query")}
|
|
170
|
+
}`,F0(W.query.schema))S+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(W.body){if($0)S+="c.body = body.Clean(c.body);\n";if(Y0("default",W.body.schema))S+=`if(body.Check(c.body) === false) {
|
|
171
|
+
c.body = Object.assign(${JSON.stringify(T0.Default(W.body.schema,null)??{})}, c.body)
|
|
172
172
|
|
|
173
173
|
if(body.Check(c.query) === false) {
|
|
174
|
-
${
|
|
174
|
+
${S0("body")}
|
|
175
175
|
}
|
|
176
|
-
}`;else
|
|
177
|
-
${
|
|
178
|
-
}`;if(
|
|
176
|
+
}`;else S+=`if(body.Check(c.body) === false) {
|
|
177
|
+
${S0("body")}
|
|
178
|
+
}`;if(F0(W.body.schema))S+="\nc.body = body.Decode(c.body)\n"}if(m(t?.schema.properties??{})){if(S+=`const cookieValue = {}
|
|
179
179
|
for(const [key, value] of Object.entries(c.cookie))
|
|
180
|
-
cookieValue[key] = value.value\n`,
|
|
181
|
-
${
|
|
182
|
-
}`}}if(
|
|
180
|
+
cookieValue[key] = value.value\n`,Y0("default",t.schema))for(let[N,_]of Object.entries(T0.Default(t.schema,{})))S+=`cookieValue['${N}'] = ${typeof _==="object"?JSON.stringify(_):_}\n`;S+=`if(cookie.Check(cookieValue) === false) {
|
|
181
|
+
${S0("cookie","cookieValue")}
|
|
182
|
+
}`}}if(X?.beforeHandle){const N=E("beforeHandle",{unit:X.beforeHandle.length});let _=!1;for(let j=0;j<X.beforeHandle.length;j++){const b=X.beforeHandle[j],H=E("beforeHandle.unit",{name:b.fn.name}),v0=E0(b.fn.toString());if(b.subType==="resolve"){if(!_)_=!0,S+="\nlet resolved\n";S+=x(b)?`resolved = await beforeHandle[${j}](c);\n`:`resolved = beforeHandle[${j}](c);\n`,S+=`if(resolved[ELYSIA_RESPONSE])
|
|
183
183
|
throw resolved
|
|
184
184
|
else
|
|
185
|
-
Object.assign(c, resolved)\n`}else if(!
|
|
186
|
-
mr = onMapResponse[${
|
|
185
|
+
Object.assign(c, resolved)\n`}else if(!v0)S+=x(b)?`await beforeHandle[${j}](c);\n`:`beforeHandle[${j}](c);\n`,H();else{if(S+="Object.assign(c, be);",S+=x(b)?`be = await beforeHandle[${j}](c);\n`:`be = beforeHandle[${j}](c);\n`,H(),S+="if(be !== undefined) {\n",N(),X.afterHandle?.length){const M0=E("afterHandle",{unit:X.transform.length});E("handle",{name:K?Z.name:void 0})();for(let w0=0;w0<X.afterHandle.length;w0++){const k0=X.afterHandle[w0],T$=E0(k0.fn.toString()),E$=E("afterHandle.unit",{name:k0.fn.name});if(S+="c.response = be\n",!T$)S+=x(k0.fn)?`await afterHandle[${w0}](c, be)\n`:`afterHandle[${w0}](c, be)\n`;else S+=x(k0.fn)?`af = await afterHandle[${w0}](c)\n`:`af = afterHandle[${w0}](c)\n`,S+="if(af !== undefined) { c.response = be = af }\n";E$()}M0()}if(W.response)S+=x0("be");if(X.mapResponse.length){S+="c.response = be";for(let M0=0;M0<X.mapResponse.length;M0++)S+=`\nif(mr === undefined) {
|
|
186
|
+
mr = onMapResponse[${M0}](c)
|
|
187
187
|
if(mr instanceof Promise) mr = await mr
|
|
188
188
|
if(mr !== undefined) c.response = mr
|
|
189
|
-
}\n`}
|
|
189
|
+
}\n`}S+=A,S+="return mapEarlyResponse(be, c.set, c.request)}\n"}}N()}if(X?.afterHandle.length){const N=E("handle",{name:K?Z.name:void 0});if(X.afterHandle.length)S+=G0?`let r = c.response = await ${R};\n`:`let r = c.response = ${R};\n`;else S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`;N();const _=E("afterHandle",{unit:X.afterHandle.length});for(let j=0;j<X.afterHandle.length;j++){const b=X.afterHandle[j],H=E0(b.fn.toString()),v0=E("afterHandle.unit",{name:b.fn.name});if(!H)S+=x(b.fn)?`await afterHandle[${j}](c)\n`:`afterHandle[${j}](c)\n`,v0();else if(S+=x(b.fn)?`af = await afterHandle[${j}](c)\n`:`af = afterHandle[${j}](c)\n`,v0(),W.response)S+="if(af !== undefined) {",_(),S+=x0("af"),S+="c.response = af }";else S+="if(af !== undefined) {",_(),S+="c.response = af}\n"}if(_(),S+="r = c.response\n",W.response)S+=x0();if(S+=A,X.mapResponse.length)for(let j=0;j<X.mapResponse.length;j++)S+=`\nmr = onMapResponse[${j}](c)
|
|
190
190
|
if(mr instanceof Promise) mr = await mr
|
|
191
|
-
if(mr !== undefined) c.response = mr\n`;if(
|
|
192
|
-
mr = onMapResponse[${
|
|
191
|
+
if(mr !== undefined) c.response = mr\n`;if(y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else{const N=E("handle",{name:K?Z.name:void 0});if(W.response||X.mapResponse.length){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),W.response)S+=x0();if(E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
|
|
192
|
+
mr = onMapResponse[${_}](c)
|
|
193
193
|
if(mr instanceof Promise) mr = await mr
|
|
194
194
|
if(mr !== undefined) r = c.response = mr
|
|
195
|
-
}\n`}if(
|
|
195
|
+
}\n`}if(S+=A,Z instanceof Response)S+=z.set?`if(
|
|
196
196
|
isNotEmpty(c.set.headers) ||
|
|
197
197
|
c.set.status !== 200 ||
|
|
198
198
|
c.set.redirect ||
|
|
199
199
|
c.set.cookie
|
|
200
200
|
)
|
|
201
|
-
return mapResponse(${
|
|
201
|
+
return mapResponse(${R}.clone(), c.set, c.request)
|
|
202
202
|
else
|
|
203
|
-
return ${
|
|
204
|
-
mr = onMapResponse[${
|
|
203
|
+
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else if(C.handle||v){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
|
|
204
|
+
mr = onMapResponse[${_}](c)
|
|
205
205
|
if(mr instanceof Promise) mr = await mr
|
|
206
206
|
if(mr !== undefined) r = c.response = mr
|
|
207
|
-
}\n`}if(
|
|
207
|
+
}\n`}if(S+=A,y0)S+="return mapResponse(r, c.set, c.request)\n";else S+="return mapCompactResponse(r, c.request)\n"}else{N();const _=G0?`await ${R}`:R;if(E("afterHandle")(),Z instanceof Response)S+=z.set?`if(
|
|
208
208
|
isNotEmpty(c.set.headers) ||
|
|
209
209
|
c.set.status !== 200 ||
|
|
210
210
|
c.set.redirect ||
|
|
211
211
|
c.set.cookie
|
|
212
212
|
)
|
|
213
|
-
return mapResponse(${
|
|
213
|
+
return mapResponse(${R}.clone(), c.set, c.request)
|
|
214
214
|
else
|
|
215
|
-
return ${
|
|
215
|
+
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+=`return mapResponse(${_}, c.set, c.request)\n`;else S+=`return mapCompactResponse(${_}, c.request)\n`}}if(U||F){if(S+="\n} catch(error) {",!w1)S+="return (async () => {";S+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const N=E("error",{unit:X.error.length});if(X.error.length){S+=`
|
|
216
216
|
c.error = error
|
|
217
217
|
c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
|
|
218
|
-
`;for(let
|
|
218
|
+
`;for(let _=0;_<X.error.length;_++){const j=`er${_}`,b=E("error.unit",{name:X.error[_].fn.name});if(S+=`\nlet ${j} = handleErrors[${_}](c)\n`,x(X.error[_]))S+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;b(),S+=`${j} = mapEarlyResponse(${j}, set, c.request)\n`,S+=`if (${j}) {`,S+=`return ${j} }\n`}}if(N(),S+="return handleError(c, error, true)\n\n",!w1)S+="})()";if(S+="}",F||P){S+=" finally { ";const _=E("response",{unit:X.onResponse.length});S+=F,_(),S+="}"}}return S=`const {
|
|
219
219
|
handler,
|
|
220
220
|
handleError,
|
|
221
221
|
hooks: {
|
|
@@ -260,17 +260,17 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
260
260
|
ELYSIA_RESPONSE
|
|
261
261
|
} = hooks
|
|
262
262
|
|
|
263
|
-
${
|
|
263
|
+
${X.onResponse.length?`const ${X.onResponse.map((N,_)=>`res${_} = onResponse[${_}]`).join(",")}`:""}
|
|
264
264
|
|
|
265
|
-
return ${
|
|
266
|
-
${
|
|
267
|
-
${
|
|
268
|
-
${
|
|
265
|
+
return ${w1?"async":""} function handle(c) {
|
|
266
|
+
${X.beforeHandle.length?"let be":""}
|
|
267
|
+
${X.afterHandle.length?"let af":""}
|
|
268
|
+
${X.mapResponse.length?"let mr":""}
|
|
269
269
|
|
|
270
|
-
${
|
|
271
|
-
${
|
|
272
|
-
}`,Function("hooks",
|
|
273
|
-
const route = router.find(request.method, path) ${
|
|
270
|
+
${Q?"c.schema = schema; c.defs = definitions":""}
|
|
271
|
+
${S}
|
|
272
|
+
}`,Function("hooks",S)({handler:Z,hooks:e1(X),validator:W,handleError:$.handleError,utils:{mapResponse:h,mapCompactResponse:n,mapEarlyResponse:f,parseQuery:R$.parse,isNotEmpty:m},error:{NotFoundError:Q0,ValidationError:I,InternalServerError:o0,ParseError:a0},schema:$.router.history,definitions:$.definitions.type,ERROR_CODE:Z0,getReporter:()=>$.reporter,requestId:j$,parseCookie:p0,signCookie:_0,decodeURIComponent:_$.default,ELYSIA_RESPONSE:d})},A1=($)=>{const J={event:{...$.inference.event,queries:[...$.inference.event.queries]},trace:{...$.inference.trace}};let w="",B="";const X=$.setHeaders;for(let S of Object.keys($.singleton.decorator))w+=`,${S}: app.singleton.decorator.${S}`;const W=$.router,Z=$.event.trace.length>0;let Q=`
|
|
273
|
+
const route = router.find(request.method, path) ${W.http.root.ALL?'?? router.find("ALL", path)':""}
|
|
274
274
|
|
|
275
275
|
if (route === null)
|
|
276
276
|
return ${$.event.error.length?"app.handleError(ctx, notFound)":$.event.request.length?`new Response(error404Message, {
|
|
@@ -278,12 +278,12 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
278
278
|
headers: ctx.set.headers
|
|
279
279
|
})`:"error404.clone()"}
|
|
280
280
|
|
|
281
|
-
ctx.params = route.params\n`;if(!($.config.precompile===!0||typeof $.config.precompile==="object"&&$.config.precompile.compose===!0))
|
|
281
|
+
ctx.params = route.params\n`;if(!($.config.precompile===!0||typeof $.config.precompile==="object"&&$.config.precompile.compose===!0))Q+=`
|
|
282
282
|
if(route.store.composed)
|
|
283
283
|
return route.store.composed(ctx)
|
|
284
284
|
|
|
285
285
|
if(route.store.compose)
|
|
286
|
-
return (route.store.compose())(ctx)`;else
|
|
286
|
+
return (route.store.compose())(ctx)`;else Q+="return route.store(ctx)";Q+="\n";let G="";for(let[S,{code:z,all:M}]of Object.entries(W.static.http.map))G+=`case '${S}':\nswitch(request.method) {\n${z}\n${M??"default: break map"}}\n\n`;const K=$.event.request.some(x),U=`\n
|
|
287
287
|
const url = request.url
|
|
288
288
|
const s = url.indexOf('/', 11)
|
|
289
289
|
const qi = url.indexOf('?', s + 1)
|
|
@@ -291,7 +291,7 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
291
291
|
if(qi === -1)
|
|
292
292
|
path = url.substring(s)
|
|
293
293
|
else
|
|
294
|
-
path = url.substring(s, qi)\n`;if(
|
|
294
|
+
path = url.substring(s, qi)\n`;if(B+=`const {
|
|
295
295
|
app,
|
|
296
296
|
mapEarlyResponse,
|
|
297
297
|
NotFoundError,
|
|
@@ -310,34 +310,34 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
310
310
|
const notFound = new NotFoundError()
|
|
311
311
|
|
|
312
312
|
${$.event.request.length?"const onRequest = app.event.request.map(x => x.fn)":""}
|
|
313
|
-
${
|
|
313
|
+
${W.static.http.variables}
|
|
314
314
|
${$.event.error.length?"":`
|
|
315
315
|
const error404Message = notFound.message.toString()
|
|
316
316
|
const error404 = new Response(error404Message, { status: 404 });
|
|
317
317
|
`}
|
|
318
318
|
|
|
319
|
-
return ${
|
|
320
|
-
${
|
|
319
|
+
return ${K?"async":""} function map(request) {\n`,$.event.request.length)B+="let re";const R=F$({hasTrace:Z,hasTraceSet:J.trace.set,condition:{request:J.trace.request},addFn:(S)=>{B+=S}});if($.event.request.length){B+=`
|
|
320
|
+
${Z?"const id = +requestId.value++":""}
|
|
321
321
|
|
|
322
322
|
const ctx = {
|
|
323
323
|
request,
|
|
324
324
|
store,
|
|
325
325
|
redirect,
|
|
326
326
|
set: {
|
|
327
|
-
headers: ${Object.keys(
|
|
327
|
+
headers: ${Object.keys(X??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
|
|
328
328
|
status: 200
|
|
329
329
|
},
|
|
330
330
|
error
|
|
331
|
-
${
|
|
332
|
-
${
|
|
331
|
+
${Z?",$$requestId: +id":""}
|
|
332
|
+
${w}
|
|
333
333
|
}
|
|
334
|
-
`;const
|
|
335
|
-
${
|
|
334
|
+
`;const S=R("request",{attribute:"ctx",unit:$.event.request.length});B+="\n try {\n";for(let z=0;z<$.event.request.length;z++){const M=$.event.request[z],D=E0(M.fn.toString()),T=x(M),q=R("request.unit",{name:$.event.request[z].fn.name});if(D)B+=`re = mapEarlyResponse(
|
|
335
|
+
${T?"await":""} onRequest[${z}](ctx),
|
|
336
336
|
ctx.set,
|
|
337
337
|
request
|
|
338
|
-
)\n`,
|
|
338
|
+
)\n`,q(),B+="if(re !== undefined) return re\n";else B+=`${T?"await":""} onRequest[${z}](ctx)\n`,q()}B+=`} catch (error) {
|
|
339
339
|
return app.handleError(ctx, error)
|
|
340
|
-
}`,
|
|
340
|
+
}`,S(),B+=U,B+="\nctx.qi = qi\n ctx.path = path\n"}else B+=U,B+=`${Z?"const id = +requestId.value++":""}
|
|
341
341
|
const ctx = {
|
|
342
342
|
request,
|
|
343
343
|
store,
|
|
@@ -345,20 +345,20 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
345
345
|
path,
|
|
346
346
|
redirect,
|
|
347
347
|
set: {
|
|
348
|
-
headers: ${Object.keys(
|
|
348
|
+
headers: ${Object.keys(X??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
|
|
349
349
|
status: 200
|
|
350
350
|
},
|
|
351
351
|
error
|
|
352
|
-
${
|
|
353
|
-
${
|
|
354
|
-
}`,
|
|
352
|
+
${Z?",$$requestId: id":""}
|
|
353
|
+
${w}
|
|
354
|
+
}`,R("request",{unit:$.event.request.length,attribute:J.trace.context||J.trace.store||J.trace.set?"ctx":""})();const F=$.router.static.ws,C=$.router.ws;if(Object.keys(F).length||C.history.length){B+=`
|
|
355
355
|
if(request.method === 'GET') {
|
|
356
|
-
switch(path) {`;for(let[
|
|
357
|
-
case '${
|
|
356
|
+
switch(path) {`;for(let[S,z]of Object.entries(F))B+=`
|
|
357
|
+
case '${S}':
|
|
358
358
|
if(request.headers.get('upgrade') === 'websocket')
|
|
359
|
-
return st${
|
|
359
|
+
return st${z}(ctx)
|
|
360
360
|
|
|
361
|
-
break`;
|
|
361
|
+
break`;B+=`
|
|
362
362
|
default:
|
|
363
363
|
if(request.headers.get('upgrade') === 'websocket') {
|
|
364
364
|
const route = wsRouter.find('ws', path)
|
|
@@ -372,16 +372,16 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
372
372
|
|
|
373
373
|
break
|
|
374
374
|
}
|
|
375
|
-
}\n`}
|
|
375
|
+
}\n`}B+=`
|
|
376
376
|
map: switch(path) {
|
|
377
|
-
${
|
|
377
|
+
${G}
|
|
378
378
|
|
|
379
379
|
default:
|
|
380
380
|
break
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
-
${
|
|
384
|
-
}`;const
|
|
383
|
+
${Q}
|
|
384
|
+
}`;const P=P1($);return $.handleError=P,Function("data",B)({app:$,mapEarlyResponse:f,NotFoundError:Q0,getReporter:()=>$.reporter,requestId:j$,handleError:P,error:F1,redirect:j1})},P1=($)=>{let J=`const {
|
|
385
385
|
app: { event: { error: onErrorContainer, onResponse: resContainer } },
|
|
386
386
|
mapResponse,
|
|
387
387
|
ERROR_CODE,
|
|
@@ -402,7 +402,7 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
402
402
|
if(typeof error === "object" && ELYSIA_RESPONSE in error) {
|
|
403
403
|
error.status = error[ELYSIA_RESPONSE]
|
|
404
404
|
error.message = error.response
|
|
405
|
-
}\n`;for(let
|
|
405
|
+
}\n`;for(let w=0;w<$.event.error.length;w++){const B=$.event.error[w],X=`${x(B)?"await ":""}onError[${w}](context)`;if(J+="\nif(skipGlobal !== true) {\n",E0(B.fn.toString()))J+=`r = ${X}; if(r !== undefined) {
|
|
406
406
|
if(r instanceof Response) return r
|
|
407
407
|
|
|
408
408
|
if(r[ELYSIA_RESPONSE]) {
|
|
@@ -412,7 +412,7 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
412
412
|
|
|
413
413
|
if(set.status === 200) set.status = error.status
|
|
414
414
|
return mapResponse(r, set, context.request)
|
|
415
|
-
}\n`;else
|
|
415
|
+
}\n`;else J+=X+"\n";J+="\n}\n"}return J+=`if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") {
|
|
416
416
|
set.status = error.status ?? 422
|
|
417
417
|
return new Response(
|
|
418
418
|
error.message,
|
|
@@ -433,9 +433,9 @@ var b$=Object.create;var{defineProperty:T1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
433
433
|
|
|
434
434
|
return mapResponse(error, set, context.request)
|
|
435
435
|
}
|
|
436
|
-
}`,Function("inject",
|
|
436
|
+
}`,Function("inject",J)({app:$,mapResponse:h,ERROR_CODE:Z0,ELYSIA_RESPONSE:d})},L0=($)=>`if(stc${$}) return stc${$}(ctx)
|
|
437
437
|
if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
|
|
438
438
|
|
|
439
|
-
return st${$}(ctx)`;var e0=I0(N1(),1);var V1=($)=>async(W)=>{const J=W.url,X=J.indexOf("/",11),Z=J.indexOf("?",X+1),Q=Z===-1?J.substring(X):J.substring(X,Z),B={cookie:{},status:200,headers:{}},Y=Object.assign({},$.singleton.decorator,{set:B,store:$.singleton.store,request:W,path:Q,qi:Z});try{for(let D=0;D<$.event.request.length;D++){const I=$.event.request[D].fn;let N=I(Y);if(N instanceof Promise)N=await N;if(N=h(N,B),N)return N}const G=$.router.dynamic.find(W.method,Q)??$.router.dynamic.find("ALL",Q);if(!G)throw new Y0;const{handle:K,hooks:_,validator:F,content:z}=G.store;let A;if(W.method!=="GET"&&W.method!=="HEAD")if(z)switch(z){case"application/json":A=await W.json();break;case"text/plain":A=await W.text();break;case"application/x-www-form-urlencoded":A=e0.parse(await W.text());break;case"application/octet-stream":A=await W.arrayBuffer();break;case"multipart/form-data":A={};const D=await W.formData();for(let I of D.keys()){if(A[I])continue;const N=D.getAll(I);if(N.length===1)A[I]=N[0];else A[I]=N}break}else{let D=W.headers.get("content-type");if(D){const I=D.indexOf(";");if(I!==-1)D=D.slice(0,I);Y.contentType=D;for(let N=0;N<_.parse.length;N++){const R=_.parse[N].fn;let T=R(Y,D);if(T instanceof Promise)T=await T;if(T){A=T;break}}if(delete Y.contentType,A===void 0)switch(D){case"application/json":A=await W.json();break;case"text/plain":A=await W.text();break;case"application/x-www-form-urlencoded":A=e0.parse(await W.text());break;case"application/octet-stream":A=await W.arrayBuffer();break;case"multipart/form-data":A={};const N=await W.formData();for(let R of N.keys()){if(A[R])continue;const T=N.getAll(R);if(T.length===1)A[R]=T[0];else A[R]=T}break}}}Y.body=A,Y.params=G?.params||void 0,Y.query=Z===-1?{}:e0.parse(J.substring(Z+1)),Y.headers={};for(let[D,I]of W.headers.entries())Y.headers[D]=I;const j=Object.assign({},$.config?.cookie,F?.cookie?.config),V=W.headers.get("cookie");Y.cookie=await c0(Y.set,V,j?{secrets:j.secrets!==void 0?typeof j.secrets==="string"?j.secrets:j.secrets.join(","):void 0,sign:j.sign===!0?!0:j.sign!==void 0?typeof j.sign==="string"?j.sign:j.sign.join(","):void 0}:void 0);for(let D=0;D<_.transform.length;D++){const I=_.transform[D],N=I.fn(Y);if(I.subType==="derive")if(N instanceof Promise)Object.assign(Y,await N);else Object.assign(Y,N);else if(N instanceof Promise)await N}if(F){if(F.headers){const D={};for(let I in W.headers)D[I]=W.headers.get(I);if(F.headers.Check(D)===!1)throw new q("header",F.headers,D)}if(F.params?.Check(Y.params)===!1)throw new q("params",F.params,Y.params);if(F.query?.Check(Y.query)===!1)throw new q("query",F.query,Y.query);if(F.cookie){const D={};for(let[I,N]of Object.entries(Y.cookie))D[I]=N.value;if(F.cookie?.Check(D)===!1)throw new q("cookie",F.cookie,D)}if(F.body?.Check(A)===!1)throw new q("body",F.body,A)}for(let D=0;D<_.beforeHandle.length;D++){let I=_.beforeHandle[D].fn(Y);if(I instanceof Promise)I=await I;if(I!==void 0){Y.response=I;for(let R=0;R<_.afterHandle.length;R++){let T=_.afterHandle[R].fn(Y);if(T instanceof Promise)T=await T;if(T)I=T}const N=h(I,Y.set);if(N)return N}}let U=K(Y);if(U instanceof Promise)U=await U;if(!_.afterHandle.length){const D=F?.response?.[U.status];if(D?.Check(U)===!1)throw new q("response",D,U)}else{Y.response=U;for(let D=0;D<_.afterHandle.length;D++){let I=_.afterHandle[D].fn(Y);if(I instanceof Promise)I=await I;const N=h(I,Y.set);if(N!==void 0){const R=F?.response?.[U.status];if(R?.Check(N)===!1)throw new q("response",R,N);return N}}}if(Y.set.cookie&&j?.sign){const D=!j.secrets?void 0:typeof j.secrets==="string"?j.secrets:j.secrets[0];if(j.sign===!0)for(let[I,N]of Object.entries(Y.set.cookie))Y.set.cookie[I].value=await w0(N.value,"${secret}");else{const I=F?.cookie?.schema?.properties;for(let N of j.sign){if(!(N in I))continue;if(Y.set.cookie[N]?.value)Y.set.cookie[N].value=await w0(Y.set.cookie[N].value,D)}}}return u(U,Y.set)}catch(G){if(G.status)B.status=G.status;return $.handleError(Y,G)}finally{for(let G of $.event.onResponse)await G.fn(Y)}},A$=($)=>async(W,J)=>{const X=Object.assign(W,{error:J,code:J.code});X.set=W.set;for(let Z=0;Z<$.event.error.length;Z++){let B=$.event.error[Z].fn(X);if(B instanceof Promise)B=await B;if(B!==void 0&&B!==null)return u(B,W.set)}return new Response(typeof J.cause==="string"?J.cause:J.message,{headers:W.set.headers,status:J.status??500})};import{TypeRegistry as V$} from"@sinclair/typebox";import{TypeSystem as N0} from"@sinclair/typebox/system";import{Type as b0,FormatRegistry as a} from"@sinclair/typebox";import{Value as j0} from"@sinclair/typebox/value";var z9=function($){return $%4===0&&($%100!==0||$%400===0)},O$=function($){const W=w9.exec($);if(!W)return!1;const J=+W[1],X=+W[2],Z=+W[3];return X>=1&&X<=12&&Z>=1&&Z<=(X===2&&z9(J)?29:M9[X])},S1=function($){return function W(J){const X=A9.exec(J);if(!X)return!1;const Z=+X[1],Q=+X[2],B=+X[3],Y=X[4],G=X[5]==="-"?-1:1,K=+(X[6]||0),_=+(X[7]||0);if(K>23||_>59||$&&!Y)return!1;if(Z<=23&&Q<=59&&B<60)return!0;const F=Q-_*G,z=Z-K*G-(F<0?1:0);return(z===23||z===-1)&&(F===59||F===-1)&&B<61}},j$=function($){const W=S1($);return function J(X){const Z=X.split(j9);return Z.length===2&&O$(Z[0])&&W(Z[1])}},O9=function($){return N9.test($)&&I9.test($)},P9=function($){return N$.lastIndex=0,N$.test($)},C9=function($){return Number.isInteger($)&&$<=S9&&$>=V9},T9=function($){return Number.isInteger($)},I$=function(){return!0},L9=function($){if(q9.test($))return!1;try{return new RegExp($),!0}catch(W){return!1}},$1={date:O$,time:S1(!0),"date-time":j$(!0),"iso-time":S1(!1),"iso-date-time":j$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:O9,"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:L9,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:P9,int32:{type:"number",validate:C9},int64:{type:"number",validate:T9},float:{type:"number",validate:I$},double:{type:"number",validate:I$},password:!0,binary:!0},w9=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,M9=[0,31,28,31,30,31,30,31,31,30,31,30,31],A9=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,j9=/t|\s/i,N9=/\/|:/,I9=/^(?:[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,N$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,V9=-2147483648,S9=2147483647,q9=/[^\\]\\Z/;import{TypeSystemPolicy as n6,TypeSystem as r6,TypeSystemDuplicateFormat as o6,TypeSystemDuplicateTypeKind as a6} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as W8} from"@sinclair/typebox/compiler";var S$=/(\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))/,C$=/(?: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\([^)]+\)/,T$=/^(?:(?:(?:(?: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)?)?$/,R9=$1.date,E9=$1["date-time"];if(!a.Has("date"))N0.Format("date",($)=>{const W=$.replace(/"/g,"");if(S$.test(W)||C$.test(W)||T$.test(W)||R9(W)){const J=new Date(W);if(!Number.isNaN(J.getTime()))return!0}return!1});if(!a.Has("date-time"))N0.Format("date-time",($)=>{const W=$.replace(/"/g,"");if(S$.test(W)||C$.test(W)||T$.test(W)||E9(W)){const J=new Date(W);if(!Number.isNaN(J.getTime()))return!0}return!1});Object.entries($1).forEach(($)=>{const[W,J]=$;if(!a.Has(W)){if(J instanceof RegExp)N0.Format(W,(X)=>J.test(X));else if(typeof J==="function")N0.Format(W,J)}});var C=Object.assign({},b0),P$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},C1=($,W)=>{if(!(W instanceof Blob))return!1;if($.minSize&&W.size<P$($.minSize))return!1;if($.maxSize&&W.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!W.type.startsWith($.extension))return!1}else{for(let J=0;J<$.extension.length;J++)if(W.type.startsWith($.extension[J]))return!0;return!1}return!0},b9=V$.Get("Files")??N0.Type("File",C1),H9=V$.Get("Files")??N0.Type("Files",($,W)=>{if(!Array.isArray(W))return C1($,W);if($.minItems&&W.length<$.minItems)return!1;if($.maxItems&&W.length>$.maxItems)return!1;for(let J=0;J<W.length;J++)if(!C1($,W[J]))return!1;return!0});if(!a.Has("numeric"))a.Set("numeric",($)=>!!$&&!isNaN(+$));if(!a.Has("boolean"))a.Set("boolean",($)=>$==="true"||$==="false");if(!a.Has("ObjectString"))a.Set("ObjectString",($)=>{let W=$.charCodeAt(0);if(W===9||W===10||W===32)W=$.trimStart().charCodeAt(0);if(W!==123&&W!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var e={Numeric:($)=>{const W=b0.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((J)=>{const X=+J;if(isNaN(X))return J;if($&&!j0.Check(W,X))throw new q("property",W,X);return X}).Encode((J)=>J)},Date:($)=>{const W=b0.Date($);return C.Transform(C.Union([b0.Date($),C.String({format:"date",default:(new Date()).toISOString()}),C.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((J)=>{if(J instanceof Date)return J;const X=new Date(J);if(!j0.Check(W,X))throw new q("property",W,X);return X}).Encode((J)=>{if(typeof J==="string")return new Date(J);return J})},BooleanString:($)=>{const W=b0.Boolean($);return C.Transform(C.Union([C.String({format:"boolean",default:!1}),C.Boolean($)],$)).Decode((J)=>{if(typeof J==="string")return J==="true";if($&&!j0.Check(W,J))throw new q("property",W,J);return J}).Encode((J)=>J)},ObjectString:($={},W)=>{const J=C.Object($,W),X=JSON.stringify(j0.Create(J));return C.Transform(C.Union([C.String({format:"ObjectString",default:X}),J])).Decode((Z)=>{if(typeof Z==="string"){try{Z=JSON.parse(Z)}catch{throw new q("property",J,Z)}if(!j0.Check(J,Z))throw new q("property",J,Z);return Z}return Z}).Encode((Z)=>{if(typeof Z==="string")try{Z=JSON.parse(Z)}catch{throw new q("property",J,Z)}if(!j0.Check(J,Z))throw new q("property",J,Z);return JSON.stringify(Z)})},File:b9,Files:($={})=>C.Transform(H9($)).Decode((W)=>{if(Array.isArray(W))return W;return[W]}).Encode((W)=>W),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,{domain:W,expires:J,httpOnly:X,maxAge:Z,path:Q,priority:B,sameSite:Y,secure:G,secrets:K,sign:_,...F}={})=>{const z=C.Object($,F);return z.config={domain:W,expires:J,httpOnly:X,maxAge:Z,path:Q,priority:B,sameSite:Y,secure:G,secrets:K,sign:_},z}};C.BooleanString=e.BooleanString;C.ObjectString=e.ObjectString;C.Numeric=e.Numeric;C.File=($={})=>e.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>e.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>e.Nullable($);C.MaybeEmpty=e.MaybeEmpty;C.Cookie=e.Cookie;C.Date=e.Date;class i{config;server=null;dependencies={};reporter=new H1;_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 X0,ws:new X0,dynamic:new X0,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($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const W=r1({globalHook:this.event,localHook:$}),J={events:{global:this.event,local:$},onParse:W("parse"),onTransform:W("transform"),onBeforeHandle:W("beforeHandle"),onAfterHandle:W("afterHandle"),onResponse:W("onResponse"),mapResponse:W("mapResponse"),onError:W("error")};for(let X of this.extender.macros)D1(X.fn(J),$)}}add($,W,J,X,{allowMeta:Z=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(X=o1(X),W!==""&&W.charCodeAt(0)!==47)W="/"+W;if(this.config.prefix&&!Q&&!this.config.scoped)W=this.config.prefix+W;if(X?.type)switch(X.type){case"text":X.type="text/plain";break;case"json":X.type="application/json";break;case"formdata":X.type="multipart/form-data";break;case"urlencoded":X.type="application/x-www-form-urlencoded";break;case"arrayBuffer":X.type="application/octet-stream";break;default:break}const B=this.definitions.type;let Y,G,K,_,F,z;const A=!this.config.aot,j={body:X?.body??this.validator?.body,headers:X?.headers??this.validator?.headers,params:X?.params??this.validator?.params,query:X?.query??this.validator?.query,cookie:X?.cookie??this.validator?.cookie,response:X?.response??this.validator?.response},V=()=>j.cookie?l0({validator:j.cookie,defaultConfig:this.config.cookie,config:j.cookie?.config??{},dynamic:A,models:B}):void 0,U=this.config.normalize,D=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(j.body,{dynamic:A,models:B,normalize:U}),headers:k(j.headers,{dynamic:A,models:B,additionalProperties:!0}),params:k(j.params,{dynamic:A,models:B}),query:k(j.query,{dynamic:A,models:B,normalize:U}),cookie:V(),response:p0(j.response,{dynamic:A,models:B,normalize:U})}:{get body(){if(Y)return Y;return Y=k(j.body,{dynamic:A,models:B,normalize:U})},get headers(){if(G)return G;return k(j.headers,{dynamic:A,models:B,additionalProperties:!0})},get params(){if(K)return K;return K=k(j.params,{dynamic:A,models:B})},get query(){if(_)return _;return _=k(j.query,{dynamic:A,models:B})},get cookie(){if(F)return F;return F=V()},get response(){if(z)return z;return z=p0(j.response,{dynamic:A,models:B,normalize:U})}},I=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(X=f(X,{},{allowMacro:!0}),X.tags)if(!X.detail)X.detail={tags:X.tags};else X.detail.tags=X.tags;if(m(this.config.detail))X.detail=p(Object.assign({},this.config.detail),X.detail);this.applyMacro(X);const N=f(this.event,X);if(this.config.aot===!1){if(this.router.dynamic.add($,W,{validator:D,hooks:N,content:X?.type,handle:J}),this.config.strictPath===!1)this.router.dynamic.add($,I,{validator:D,hooks:N,content:X?.type,handle:J});this.router.history.push({method:$,path:W,composed:null,handler:J,hooks:N});return}let R=void 0;const T=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,$0=t0(this.inference),v=T?a0({app:this,path:W,method:$,localHook:f(X),hooks:N,validator:D,handler:J,allowMeta:Z,appInference:$0}):(P)=>{if(R)return R(P);return(R=a0({app:this,path:W,method:$,localHook:f(X),hooks:N,validator:D,handler:J,allowMeta:Z,appInference:$0}))(P)};if(!T)v.compose=()=>{return v.composed=a0({app:this,path:W,method:$,localHook:f(X),hooks:N,validator:D,handler:J,allowMeta:Z,appInference:$0})};let n=this.router.history.length;if(this.routeTree.has($+W)){if(n=this.router.history.findIndex((P)=>P.path===W&&P.method===$),n!==-1){const P=this.router.history.splice(n,1)[0];if(P&&this.routeTree.has(P?.method+P?.path))this.routeTree.delete(P.method+P.path)}}this.routeTree.set($+W,n),this.router.history.push({method:$,path:W,composed:v,handler:J,hooks:N});const S=this.router.static.http;if($==="$INTERNALWS"){const P=this.config.strictPath?void 0:W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const W0=S.handlers.length;if(S.handlers.push(v),S.variables+=`const st${W0} = staticRouter.handlers[${W0}]\n`,this.router.static.ws[W]=W0,P)this.router.static.ws[P]=W0}else if(this.router.ws.add("ws",W,v),P)this.router.ws.add("ws",P,v);return}if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const P=S.handlers.length;if(S.handlers.push(v),S.variables+=T?`const st${P} = staticRouter.handlers[${P}]\n`:`let st${P} = staticRouter.handlers[${P}]\nlet stc${P}\n`,!S.map[W])S.map[W]={code:""};if($==="ALL")S.map[W].all=T?`default: return st${P}(ctx)\n`:`default: ${E0(P)}\n`;else S.map[W].code=T?`case '${$}': return st${P}(ctx)\n${S.map[W].code}`:`case '${$}': ${E0(P)}\n${S.map[W].code}`;if(!this.config.strictPath){if(!S.map[I])S.map[I]={code:""};if($==="ALL")S.map[I].all=T?`default: return st${P}(ctx)\n`:`default: ${E0(P)}\n`;else S.map[I].code=T?`case '${$}': return st${P}(ctx)\n${S.map[I].code}`:`case '${$}': ${E0(P)}\n${S.map[I].code}`}}else if(this.router.http.add($,W,v),!this.config.strictPath)this.router.http.add($,W.endsWith("/")?W.slice(0,W.length-1):W+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,W){if(!W)return this.on("parse",$);return this.on($,"parse",W)}onTransform($,W){if(!W)return this.on("transform",$);return this.on($,"transform",W)}resolve($,W){if(!W)W=$,$={as:"local"};const J={subType:"resolve",fn:W};return this.onBeforeHandle($,J)}mapResolve($,W){if(!W)W=$,$={as:"local"};const J={subType:"resolve",fn:W};return this.onBeforeHandle($,J)}onBeforeHandle($,W){if(!W)return this.on("beforeHandle",$);return this.on($,"beforeHandle",W)}onAfterHandle($,W){if(!W)return this.on("afterHandle",$);return this.on($,"afterHandle",W)}mapResponse($,W){if(!W)return this.on("mapResponse",$);return this.on($,"mapResponse",W)}onResponse($,W){if(!W)return this.on("response",$);return this.on($,"response",W)}trace($,W){if(!W)W=$,$={as:"local"};if(!Array.isArray(W))W=[W];for(let J of W)this.reporter.on("event",x1(()=>this.reporter,this.event.trace.length,J));return this.on($,"trace",W),this}error($,W){switch(typeof $){case"string":return W.prototype[B0]=$,this.definitions.error[$]=W,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[J,X]of Object.entries($))X.prototype[B0]=J,this.definitions.error[J]=X;return this}onError($,W){if(!W)return this.on("error",$);return this.on($,"error",W)}onStop($){return this.on("stop",$),this}on($,W,J){let X;switch(typeof $){case"string":X=$,J=W;break;case"object":X=W;break}if(X==="response")X="onResponse";if(Array.isArray(J))J=c(J);else if(typeof J==="function")J=[{fn:J}];else J=[J];const Z=J;for(let Q of Z)Q.scope=typeof $==="string"?"local":$?.as??"local";if(X==="trace")h1(Z.map((Q)=>Q.fn),this.inference.trace);else u0({[X]:Z.map((Q)=>Q.fn)},this.inference.event);for(let Q of Z){const B=n1(Q,"global",{skipIfHasType:!0});switch(X){case"start":this.event.start.push(B);break;case"request":this.event.request.push(B);break;case"parse":this.event.parse.push(B);break;case"transform":this.event.transform.push(B);break;case"beforeHandle":this.event.beforeHandle.push(B);break;case"afterHandle":this.event.afterHandle.push(B);break;case"mapResponse":this.event.mapResponse.push(B);break;case"onResponse":this.event.onResponse.push(B);break;case"trace":this.event.trace.push(B);break;case"error":this.event.error.push(B);break;case"stop":this.event.stop.push(B);break}}return this}propagate(){const $=(W)=>{for(let J of W)if("scope"in J&&J.scope==="local")J.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,W,J){const X=new i({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.getServer=()=>this.server,X.inference=t0(this.inference);const Z=typeof W==="object",Q=(Z?J:W)(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Q.event.request.length)this.event.request=[...this.event.request||[],...Q.event.request||[]];if(Q.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...Q.event.onResponse||[]];return this.model(Q.definitions.type),Object.values(X.router.history).forEach(({method:B,path:Y,handler:G,hooks:K})=>{if(Y=(Z?"":this.config.prefix)+$+Y,Z){const _=W,F=K;this.add(B,Y,G,f(_,{...F||{},error:!F.error?Q.event.error:Array.isArray(F.error)?[...F.error||{},...Q.event.error||{}]:[F.error,...Q.event.error||{}]}))}else this.add(B,Y,G,f(K,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,W){if(!W){if(typeof $==="object"){if(this.applyMacro($),this.event=i0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const J=new i({...this.config,prefix:""});J.singleton={...this.singleton},J.definitions={...this.definitions},J.inference=t0(this.inference);const X=W(J);if(this.singleton=p(this.singleton,J.singleton),this.definitions=p(this.definitions,J.definitions),X.getServer=()=>this.server,X.event.request.length)this.event.request=[...this.event.request||[],...X.event.request||[]];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...X.event.onResponse||[]];return this.model(X.definitions.type),Object.values(J.router.history).forEach(({method:Z,path:Q,handler:B,hooks:Y})=>{this.add(Z,Q,B,f($,{...Y||{},error:!Y.error?X.event.error:Array.isArray(Y.error)?[...Y.error||{},...X.event.error||[]]:[Y.error,...X.event.error||[]]},{allowMacro:!0}))}),this}use($,W){if(W?.scoped)return this.guard({},(J)=>J.use($));if(Array.isArray($)){let J=this;for(let X of $)J=this.use(X);return J}if($ instanceof Promise)return this.promisedModules.add($.then((J)=>{if(typeof J==="function")return J(this);if(J instanceof i)return this._use(J);if(typeof J.default==="function")return J.default(this);if(J.default instanceof i)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($)}_use($){if(typeof $==="function"){const Z=$(this);if(Z instanceof Promise)return this.promisedModules.add(Z.then((Q)=>{if(Q instanceof i){this.compile();for(let{method:B,path:Y,handler:G,hooks:K}of Object.values(Q.router.history))this.add(B,Y,G,f(K,{error:Q.event.error}));return Q}if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return Z}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((Z)=>Z.compile())),this;const{name:W,seed:J}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const X=$.config.scoped;if(X){if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const Q=J!==void 0?C0(W+JSON.stringify(J)):0;if(this.dependencies[W].some(({checksum:B})=>Q===B))return this;this.dependencies[W].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((B)=>B.subType==="derive").map((B)=>({fn:B.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((B)=>B.subType==="derive").map((B)=>({fn:B.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<$.extender.macros.length;Q++){const B=this.extender.macros[Q];if(Z.includes(B.checksum))$.extender.macros.splice(Q,1),Q--;Z.push(B.checksum)}if($.onRequest((Q)=>{Object.assign(Q,this.singleton.decorator),Object.assign(Q.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(X===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let Q of $.event.trace)if(Q.scope&&Q.scope!=="local")this.trace(Q);if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const Q=J!==void 0?C0(W+JSON.stringify(J)):0;if(!this.dependencies[W].some(({checksum:B})=>Q===B))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<this.extender.macros.length;Q++){const B=this.extender.macros[Q];if(B.checksum){if(Z.includes(B.checksum))this.extender.macros.splice(Q,1),Q--;Z.push(B.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:Z,path:Q,handler:B,hooks:Y}of Object.values($.router.history))this.add(Z,Q,B,f(Y,{error:$.event.error}));if(!X)if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const Z=J!==void 0?C0(W+JSON.stringify(J)):0;if(this.dependencies[W].some(({checksum:Q})=>Z===Q))return this;this.dependencies[W].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q?.subType==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q?.subType==="resolve").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))}),this.event=i0(this.event,F1($.event),Z)}else this.event=i0(this.event,F1($.event));return this}macro($){const W={checksum:C0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(W),this}mount($,W){if($ instanceof i||typeof $==="function"||$.length===0||$==="/"){const Z=typeof $==="function"?$:$ instanceof i?$.compile().fetch:W instanceof i?W.compile().fetch:W,Q=async({request:B,path:Y})=>Z(new Request(_1(B.url,Y||"/"),B));return this.all("/*",Q,{type:"none"}),this}const J=$.length;if(W instanceof i)W=W.compile().fetch;const X=async({request:Z,path:Q})=>W(new Request(_1(Z.url,Q.slice(J)||"/"),Z));return this.all($,X,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),X,{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,X){return this.add($.toUpperCase(),W,J,X,X?.config),this}ws($,W){const J=W.transformMessage?Array.isArray(W.transformMessage)?W.transformMessage:[W.transformMessage]:void 0;let X=null;const Z=k(W?.body,{models:this.definitions.type,normalize:this.config.normalize}),Q=k(W?.response,{models:this.definitions.type,normalize:this.config.normalize}),B=(Y)=>{if(typeof Y==="string"){const G=Y?.charCodeAt(0);if(G===47||G===123)try{Y=JSON.parse(Y)}catch{}else if(D0(Y))Y=+Y}if(J?.length)for(let G=0;G<J.length;G++){const K=J[G](Y);if(K!==void 0)Y=K}return Y};return this.route("$INTERNALWS",$,(Y)=>{const{set:G,path:K,qi:_,headers:F,query:z,params:A}=Y;if(X===null)X=this.getServer();if(X?.upgrade(Y.request,{headers:typeof W.upgrade==="function"?W.upgrade(Y):W.upgrade,data:{validator:Q,open(j){W.open?.(new M0(j,Y))},message:(j,V)=>{const U=B(V);if(Z?.Check(U)===!1)return void j.send(new q("message",Z,U).message);W.message?.(new M0(j,Y),U)},drain(j){W.drain?.(new M0(j,Y))},close(j,V,U){W.close?.(new M0(j,Y),V,U)}}}))return;return G.status=400,"Expected a websocket connection"},{beforeHandle:W.beforeHandle,transform:W.transform,headers:W.headers,params:W.params,query:W.query}),this}state($,W){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=W;return this}decorate($,W){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=W;return this}derive($,W){if(!W)W=$,$={as:"local"};const J={subType:"derive",fn:W};return this.onTransform($,J)}model($,W){switch(typeof $){case"object":return Object.entries($).forEach(([J,X])=>{if(!(J in this.definitions.type))this.definitions.type[J]=X}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=W,this}mapDerive($,W){if(!W)W=$,$={as:"local"};const J={subType:"derive",fn:W};return this.onTransform($,J)}affix($,W,J){if(J==="")return this;const X=["_","-"," "],Z=(G)=>G[0].toUpperCase()+G.slice(1),Q=$==="prefix"?(G,K)=>X.includes(G.at(-1)??"")?G+K:G+Z(K):X.includes(J.at(-1)??"")?(G,K)=>K+G:(G,K)=>K+Z(G),B=(G)=>{const K={};switch(G){case"decorator":for(let _ in this.singleton.decorator)K[Q(J,_)]=this.singleton.decorator[_];this.singleton.decorator=K;break;case"state":for(let _ in this.singleton.store)K[Q(J,_)]=this.singleton.store[_];this.singleton.store=K;break;case"model":for(let _ in this.definitions.type)K[Q(J,_)]=this.definitions.type[_];this.definitions.type=K;break;case"error":for(let _ in this.definitions.error)K[Q(J,_)]=this.definitions.error[_];this.definitions.error=K;break}},Y=Array.isArray(W)?W:[W];for(let G of Y.some((K)=>K==="all")?["decorator","state","model","error"]:Y)B(G);return this}prefix($,W){return this.affix("prefix",$,W)}suffix($,W){return this.affix("suffix",$,W)}compile(){if(this.fetch=this.config.aot?O1(this):V1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?O1(this):V1(this))($)};handleError=async($,W)=>(this.handleError=this.config.aot?P1(this):A$(this))($,W);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.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 $==="string"){if(!D0($))throw new Error("Port must be a numeric value");$=parseInt($)}const J=this.fetch,X=typeof $==="object"?{development:!T0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...A1||{}},fetch:J,error:this.outerErrorHandler}:{development:!T0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...A1||{}},port:$,fetch:J,error:this.outerErrorHandler};this.server=Bun?.serve(X);for(let Z=0;Z<this.event.start.length;Z++)this.event.start[Z].fn(this);if(W)W(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let Z=0;Z<this.event.stop.length;Z++)this.event.stop[Z].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{C as t,w1 as redirect,b as mergeObjectArray,f as mergeHook,u as mapResponse,h as mapEarlyResponse,o as mapCompactResponse,k as getSchemaValidator,p0 as getResponseSchemaValidator,M1 as error,i as default,q as ValidationError,Z0 as StatusMap,o0 as ParseError,Y0 as NotFoundError,s0 as InvertedStatusMap,P0 as InvalidCookieSignature,r0 as InternalServerError,i as Elysia,B0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
439
|
+
return st${$}(ctx)`;var $1=N0(M1(),1);var O1=($)=>async(J)=>{const w=J.url,B=w.indexOf("/",11),X=w.indexOf("?",B+1),W=X===-1?w.substring(B):w.substring(B,X),Z={cookie:{},status:200,headers:{}},Q=Object.assign({},$.singleton.decorator,{set:Z,store:$.singleton.store,request:J,path:W,qi:X});try{for(let z=0;z<$.event.request.length;z++){const M=$.event.request[z].fn;let D=M(Q);if(D instanceof Promise)D=await D;if(D=f(D,Z),D)return D}const Y=$.router.dynamic.find(J.method,W)??$.router.dynamic.find("ALL",W);if(!Y)throw new Q0;const{handle:G,hooks:K,validator:U,content:R}=Y.store;let F;if(J.method!=="GET"&&J.method!=="HEAD")if(R)switch(R){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const z=await J.formData();for(let M of z.keys()){if(F[M])continue;const D=z.getAll(M);if(D.length===1)F[M]=D[0];else F[M]=D}break}else{let z=J.headers.get("content-type");if(z){const M=z.indexOf(";");if(M!==-1)z=z.slice(0,M);Q.contentType=z;for(let D=0;D<K.parse.length;D++){const T=K.parse[D].fn;let q=T(Q,z);if(q instanceof Promise)q=await q;if(q){F=q;break}}if(delete Q.contentType,F===void 0)switch(z){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const D=await J.formData();for(let T of D.keys()){if(F[T])continue;const q=D.getAll(T);if(q.length===1)F[T]=q[0];else F[T]=q}break}}}Q.body=F,Q.params=Y?.params||void 0,Q.query=X===-1?{}:$1.parse(w.substring(X+1)),Q.headers={};for(let[z,M]of J.headers.entries())Q.headers[z]=M;const C=Object.assign({},$.config?.cookie,U?.cookie?.config),P=J.headers.get("cookie");Q.cookie=await p0(Q.set,P,C?{secrets:C.secrets!==void 0?typeof C.secrets==="string"?C.secrets:C.secrets.join(","):void 0,sign:C.sign===!0?!0:C.sign!==void 0?typeof C.sign==="string"?C.sign:C.sign.join(","):void 0}:void 0);for(let z=0;z<K.transform.length;z++){const M=K.transform[z],D=M.fn(Q);if(M.subType==="derive")if(D instanceof Promise)Object.assign(Q,await D);else Object.assign(Q,D);else if(D instanceof Promise)await D}if(U){if(U.headers){const z={};for(let M in J.headers)z[M]=J.headers.get(M);if(U.headers.Check(z)===!1)throw new I("header",U.headers,z)}if(U.params?.Check(Q.params)===!1)throw new I("params",U.params,Q.params);if(U.query?.Check(Q.query)===!1)throw new I("query",U.query,Q.query);if(U.cookie){const z={};for(let[M,D]of Object.entries(Q.cookie))z[M]=D.value;if(U.cookie?.Check(z)===!1)throw new I("cookie",U.cookie,z)}if(U.body?.Check(F)===!1)throw new I("body",U.body,F)}for(let z=0;z<K.beforeHandle.length;z++){let M=K.beforeHandle[z].fn(Q);if(M instanceof Promise)M=await M;if(M!==void 0){Q.response=M;for(let T=0;T<K.afterHandle.length;T++){let q=K.afterHandle[T].fn(Q);if(q instanceof Promise)q=await q;if(q)M=q}const D=f(M,Q.set);if(D)return D}}let S=G(Q);if(S instanceof Promise)S=await S;if(!K.afterHandle.length){const z=U?.response?.[S.status];if(z?.Check(S)===!1)throw new I("response",z,S)}else{Q.response=S;for(let z=0;z<K.afterHandle.length;z++){let M=K.afterHandle[z].fn(Q);if(M instanceof Promise)M=await M;const D=f(M,Q.set);if(D!==void 0){const T=U?.response?.[S.status];if(T?.Check(D)===!1)throw new I("response",T,D);return D}}}if(Q.set.cookie&&C?.sign){const z=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(Q.set.cookie))Q.set.cookie[M].value=await _0(D.value,"${secret}");else{const M=U?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(Q.set.cookie[D]?.value)Q.set.cookie[D].value=await _0(Q.set.cookie[D].value,z)}}}return h(S,Q.set)}catch(Y){if(Y.status)Z.status=Y.status;return $.handleError(Q,Y)}finally{for(let Y of $.event.onResponse)await Y.fn(Q)}},C$=($)=>async(J,w)=>{const B=Object.assign(J,{error:w,code:w.code});B.set=J.set;for(let X=0;X<$.event.error.length;X++){let Z=$.event.error[X].fn(B);if(Z instanceof Promise)Z=await Z;if(Z!==void 0&&Z!==null)return h(Z,J.set)}return new Response(typeof w.cause==="string"?w.cause:w.message,{headers:J.set.headers,status:w.status??500})};import{TypeRegistry as O$} from"@sinclair/typebox";import{TypeSystem as D0} from"@sinclair/typebox/system";import{Type as H0,FormatRegistry as o} from"@sinclair/typebox";import{Value as C0} from"@sinclair/typebox/value";var RJ=function($){return $%4===0&&($%100!==0||$%400===0)},A$=function($){const J=_J.exec($);if(!J)return!1;const w=+J[1],B=+J[2],X=+J[3];return B>=1&&B<=12&&X>=1&&X<=(B===2&&RJ(w)?29:jJ[B])},V1=function($){return function J(w){const B=FJ.exec(w);if(!B)return!1;const X=+B[1],W=+B[2],Z=+B[3],Q=B[4],Y=B[5]==="-"?-1:1,G=+(B[6]||0),K=+(B[7]||0);if(G>23||K>59||$&&!Q)return!1;if(X<=23&&W<=59&&Z<60)return!0;const U=W-K*Y,R=X-G*Y-(U<0?1:0);return(R===23||R===-1)&&(U===59||U===-1)&&Z<61}},D$=function($){const J=V1($);return function w(B){const X=B.split(CJ);return X.length===2&&A$(X[0])&&J(X[1])}},NJ=function($){return DJ.test($)&&MJ.test($)},AJ=function($){return M$.lastIndex=0,M$.test($)},VJ=function($){return Number.isInteger($)&&$<=OJ&&$>=PJ},qJ=function($){return Number.isInteger($)},N$=function(){return!0},bJ=function($){if(IJ.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},J1={date:A$,time:V1(!0),"date-time":D$(!0),"iso-time":V1(!1),"iso-date-time":D$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:NJ,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:bJ,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:AJ,int32:{type:"number",validate:VJ},int64:{type:"number",validate:qJ},float:{type:"number",validate:N$},double:{type:"number",validate:N$},password:!0,binary:!0},_J=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,jJ=[0,31,28,31,30,31,30,31,31,30,31,30,31],FJ=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,CJ=/t|\s/i,DJ=/\/|:/,MJ=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,M$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,PJ=-2147483648,OJ=2147483647,IJ=/[^\\]\\Z/;import{TypeSystemPolicy as rw,TypeSystem as nw,TypeSystemDuplicateFormat as ow,TypeSystemDuplicateTypeKind as aw} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as J8} from"@sinclair/typebox/compiler";var V$=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,q$=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,I$=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,TJ=J1.date,EJ=J1["date-time"];if(!o.Has("date"))D0.Format("date",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||TJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});if(!o.Has("date-time"))D0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||EJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});Object.entries(J1).forEach(($)=>{const[J,w]=$;if(!o.Has(J)){if(w instanceof RegExp)D0.Format(J,(B)=>w.test(B));else if(typeof w==="function")D0.Format(J,w)}});var V=Object.assign({},H0),P$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<P$($.minSize))return!1;if($.maxSize&&J.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!J.type.startsWith($.extension))return!1}else{for(let w=0;w<$.extension.length;w++)if(J.type.startsWith($.extension[w]))return!0;return!1}return!0},LJ=O$.Get("Files")??D0.Type("File",q1),HJ=O$.Get("Files")??D0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let w=0;w<J.length;w++)if(!q1($,J[w]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",($)=>!!$&&!isNaN(+$));if(!o.Has("boolean"))o.Set("boolean",($)=>$==="true"||$==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",($)=>{let J=$.charCodeAt(0);if(J===9||J===10||J===32)J=$.trimStart().charCodeAt(0);if(J!==123&&J!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const J=H0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((w)=>{const B=+w;if(isNaN(B))return w;if($&&!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>w)},Date:($)=>{const J=H0.Date($);return V.Transform(V.Union([H0.Date($),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((w)=>{if(w instanceof Date)return w;const B=new Date(w);if(!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>{if(typeof w==="string")return new Date(w);return w})},BooleanString:($)=>{const J=H0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((w)=>{if(typeof w==="string")return w==="true";if($&&!C0.Check(J,w))throw new I("property",J,w);return w}).Encode((w)=>w)},ObjectString:($={},J)=>{const w=V.Object($,J),B=JSON.stringify(C0.Create(w));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),w])).Decode((X)=>{if(typeof X==="string"){try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return X}return X}).Encode((X)=>{if(typeof X==="string")try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return JSON.stringify(X)})},File:LJ,Files:($={})=>V.Transform(HJ($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>V.Union([V.Null(),$]),MaybeEmpty:($)=>V.Union([V.Null(),V.Undefined(),$]),Cookie:($,{domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K,...U}={})=>{const R=V.Object($,U);return R.config={domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K},R}};V.BooleanString=a.BooleanString;V.ObjectString=a.ObjectString;V.Numeric=a.Numeric;V.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>a.Nullable($);V.MaybeEmpty=a.MaybeEmpty;V.Cookie=a.Cookie;V.Date=a.Date;class s{config;server=null;dependencies={};reporter=new x1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new B0,ws:new B0,dynamic:new B0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new _1;constructor($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const J=o1({globalHook:this.event,localHook:$}),w={events:{global:this.event,local:$},onParse:J("parse"),onTransform:J("transform"),onBeforeHandle:J("beforeHandle"),onAfterHandle:J("afterHandle"),onResponse:J("onResponse"),mapResponse:J("mapResponse"),onError:J("error")};for(let B of this.extender.macros)R1(B.fn(w),$)}}add($,J,w,B,{allowMeta:X=!1,skipPrefix:W=!1}={allowMeta:!1,skipPrefix:!1}){if(B=a1(B),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!W&&!this.config.scoped)J=this.config.prefix+J;if(B?.type)switch(B.type){case"text":B.type="text/plain";break;case"json":B.type="application/json";break;case"formdata":B.type="multipart/form-data";break;case"urlencoded":B.type="application/x-www-form-urlencoded";break;case"arrayBuffer":B.type="application/octet-stream";break;default:break}const Z=this.definitions.type;let Q,Y,G,K,U,R;const F=!this.config.aot,C={body:B?.body??this.validator?.body,headers:B?.headers??this.validator?.headers,params:B?.params??this.validator?.params,query:B?.query??this.validator?.query,cookie:B?.cookie??this.validator?.cookie,response:B?.response??this.validator?.response},P=()=>C.cookie?l0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:F,models:Z}):void 0,S=this.config.normalize,z=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:F,models:Z,normalize:S}),headers:k(C.headers,{dynamic:F,models:Z,additionalProperties:!0}),params:k(C.params,{dynamic:F,models:Z}),query:k(C.query,{dynamic:F,models:Z,normalize:S}),cookie:P(),response:s0(C.response,{dynamic:F,models:Z,normalize:S})}:{get body(){if(Q)return Q;return Q=k(C.body,{dynamic:F,models:Z,normalize:S})},get headers(){if(Y)return Y;return k(C.headers,{dynamic:F,models:Z,additionalProperties:!0})},get params(){if(G)return G;return G=k(C.params,{dynamic:F,models:Z})},get query(){if(K)return K;return K=k(C.query,{dynamic:F,models:Z})},get cookie(){if(U)return U;return U=P()},get response(){if(R)return R;return R=s0(C.response,{dynamic:F,models:Z,normalize:S})}},M=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(B=u(B,{},{allowMacro:!0}),B.tags)if(!B.detail)B.detail={tags:B.tags};else B.detail.tags=B.tags;if(m(this.config.detail))B.detail=p(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const D=u(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:z,hooks:D,content:B?.type,handle:w}),this.config.strictPath===!1)this.router.dynamic.add($,M,{validator:z,hooks:D,content:B?.type,handle:w});this.router.history.push({method:$,path:J,composed:null,handler:w,hooks:D});return}let T=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}):(A)=>{if(T)return T(A);return(T=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}))(A)};if(!q)v.compose=()=>{return v.composed=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e})};let t=this.router.history.length;if(this.routeTree.has($+J)){if(t=this.router.history.findIndex((A)=>A.path===J&&A.method===$),t!==-1){const A=this.router.history.splice(t,1)[0];if(A&&this.routeTree.has(A?.method+A?.path))this.routeTree.delete(A.method+A.path)}}this.routeTree.set($+J,t),this.router.history.push({method:$,path:J,composed:v,handler:w,hooks:D});const O=this.router.static.http;if($==="$INTERNALWS"){const A=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,A)this.router.static.ws[A]=$0}else if(this.router.ws.add("ws",J,v),A)this.router.ws.add("ws",A,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const A=O.handlers.length;if(O.handlers.push(v),O.variables+=q?`const st${A} = staticRouter.handlers[${A}]\n`:`let st${A} = staticRouter.handlers[${A}]\nlet stc${A}\n`,!O.map[J])O.map[J]={code:""};if($==="ALL")O.map[J].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[J].code=q?`case '${$}': return st${A}(ctx)\n${O.map[J].code}`:`case '${$}': ${L0(A)}\n${O.map[J].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if($==="ALL")O.map[M].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[M].code=q?`case '${$}': return st${A}(ctx)\n${O.map[M].code}`:`case '${$}': ${L0(A)}\n${O.map[M].code}`}}else if(this.router.http.add($,J,v),!this.config.strictPath)this.router.http.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,J){if(!J)return this.on("parse",$);return this.on($,"parse",J)}onTransform($,J){if(!J)return this.on("transform",$);return this.on($,"transform",J)}resolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}mapResolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}onBeforeHandle($,J){if(!J)return this.on("beforeHandle",$);return this.on($,"beforeHandle",J)}onAfterHandle($,J){if(!J)return this.on("afterHandle",$);return this.on($,"afterHandle",J)}mapResponse($,J){if(!J)return this.on("mapResponse",$);return this.on($,"mapResponse",J)}onResponse($,J){if(!J)return this.on("response",$);return this.on($,"response",J)}trace($,J){if(!J)J=$,$={as:"local"};if(!Array.isArray(J))J=[J];for(let w of J)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,w));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Z0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[w,B]of Object.entries($))B.prototype[Z0]=w,this.definitions.error[w]=B;return this}onError($,J){if(!J)return this.on("error",$);return this.on($,"error",J)}onStop($){return this.on("stop",$),this}on($,J,w){let B;switch(typeof $){case"string":B=$,w=J;break;case"object":B=J;break}if(B==="response")B="onResponse";if(Array.isArray(w))w=c(w);else if(typeof w==="function")w=[{fn:w}];else w=[w];const X=w;for(let W of X)W.scope=typeof $==="string"?"local":$?.as??"local";if(B==="trace")h1(X.map((W)=>W.fn),this.inference.trace);else m0({[B]:X.map((W)=>W.fn)},this.inference.event);for(let W of X){const Z=n1(W,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(Z);break;case"request":this.event.request.push(Z);break;case"parse":this.event.parse.push(Z);break;case"transform":this.event.transform.push(Z);break;case"beforeHandle":this.event.beforeHandle.push(Z);break;case"afterHandle":this.event.afterHandle.push(Z);break;case"mapResponse":this.event.mapResponse.push(Z);break;case"onResponse":this.event.onResponse.push(Z);break;case"trace":this.event.trace.push(Z);break;case"error":this.event.error.push(Z);break;case"stop":this.event.stop.push(Z);break}}return this}propagate(){const $=(J)=>{for(let w of J)if("scope"in w&&w.scope==="local")w.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,J,w){const B=new s({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=r0(this.inference);const X=typeof J==="object",W=(X?w:J)(B);if(this.singleton=p(this.singleton,B.singleton),this.definitions=p(this.definitions,B.definitions),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(B.router.history).forEach(({method:Z,path:Q,handler:Y,hooks:G})=>{if(Q=(X?"":this.config.prefix)+$+Q,X){const K=J,U=G;this.add(Z,Q,Y,u(K,{...U||{},error:!U.error?W.event.error:Array.isArray(U.error)?[...U.error||{},...W.event.error||{}]:[U.error,...W.event.error||{}]}))}else this.add(Z,Q,Y,u(G,{error:W.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=i0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const w=new s({...this.config,prefix:""});w.singleton={...this.singleton},w.definitions={...this.definitions},w.inference=r0(this.inference);const B=J(w);if(this.singleton=p(this.singleton,w.singleton),this.definitions=p(this.definitions,w.definitions),B.getServer=()=>this.server,B.event.request.length)this.event.request=[...this.event.request||[],...B.event.request||[]];if(B.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...B.event.onResponse||[]];return this.model(B.definitions.type),Object.values(w.router.history).forEach(({method:X,path:W,handler:Z,hooks:Q})=>{this.add(X,W,Z,u($,{...Q||{},error:!Q.error?B.event.error:Array.isArray(Q.error)?[...Q.error||{},...B.event.error||[]]:[Q.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(w)=>w.use($));if(Array.isArray($)){let w=this;for(let B of $)w=this.use(B);return w}if($ instanceof Promise)return this.promisedModules.add($.then((w)=>{if(typeof w==="function")return w(this);if(w instanceof s)return this._use(w);if(typeof w.default==="function")return w.default(this);if(w.default instanceof s)return this._use(w.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((w)=>w.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const X=$(this);if(X instanceof Promise)return this.promisedModules.add(X.then((W)=>{if(W instanceof s){this.compile();for(let{method:Z,path:Q,handler:Y,hooks:G}of Object.values(W.router.history))this.add(Z,Q,Y,u(G,{error:W.event.error}));return W}if(typeof W==="function")return W(this);if(typeof W.default==="function")return W.default(this);return this._use(W)}).then((W)=>W.compile())),this;return X}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((X)=>X.compile())),this;const{name:J,seed:w}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const B=$.config.scoped;if(B){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:Z})=>W===Z))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<$.extender.macros.length;W++){const Z=this.extender.macros[W];if(X.includes(Z.checksum))$.extender.macros.splice(W,1),W--;X.push(Z.checksum)}if($.onRequest((W)=>{Object.assign(W,this.singleton.decorator),Object.assign(W.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(B===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let W of $.event.trace)if(W.scope&&W.scope!=="local")this.trace(W);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(!this.dependencies[J].some(({checksum:Z})=>W===Z))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<this.extender.macros.length;W++){const Z=this.extender.macros[W];if(Z.checksum){if(X.includes(Z.checksum))this.extender.macros.splice(W,1),W--;X.push(Z.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:X,path:W,handler:Z,hooks:Q}of Object.values($.router.history))this.add(X,W,Z,u(Q,{error:$.event.error}));if(!B)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const X=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:W})=>X===W))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((W)=>W?.subType==="derive").map((W)=>({fn:W.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((W)=>W?.subType==="resolve").map((W)=>({fn:W.toString(),stack:new Error().stack??""}))}),this.event=i0(this.event,z1($.event),X)}else this.event=i0(this.event,z1($.event));return this}macro($){const J={checksum:q0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof s||typeof $==="function"||$.length===0||$==="/"){const X=typeof $==="function"?$:$ instanceof s?$.compile().fetch:J instanceof s?J.compile().fetch:J,W=async({request:Z,path:Q})=>X(new Request(U1(Z.url,Q||"/"),Z));return this.all("/*",W,{type:"none"}),this}const w=$.length;if(J instanceof s)J=J.compile().fetch;const B=async({request:X,path:W})=>J(new Request(U1(X.url,W.slice(w)||"/"),X));return this.all($,B,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get($,J,w){return this.add("GET",$,J,w),this}post($,J,w){return this.add("POST",$,J,w),this}put($,J,w){return this.add("PUT",$,J,w),this}patch($,J,w){return this.add("PATCH",$,J,w),this}delete($,J,w){return this.add("DELETE",$,J,w),this}options($,J,w){return this.add("OPTIONS",$,J,w),this}all($,J,w){return this.add("ALL",$,J,w),this}head($,J,w){return this.add("HEAD",$,J,w),this}connect($,J,w){return this.add("CONNECT",$,J,w),this}route($,J,w,B){return this.add($.toUpperCase(),J,w,B,B?.config),this}ws($,J){const w=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let B=null;const X=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),W=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Z=(Q)=>{if(typeof Q==="string"){const Y=Q?.charCodeAt(0);if(Y===47||Y===123)try{Q=JSON.parse(Q)}catch{}else if(z0(Q))Q=+Q}if(w?.length)for(let Y=0;Y<w.length;Y++){const G=w[Y](Q);if(G!==void 0)Q=G}return Q};return this.route("$INTERNALWS",$,(Q)=>{const{set:Y,path:G,qi:K,headers:U,query:R,params:F}=Q;if(B===null)B=this.getServer();if(B?.upgrade(Q.request,{headers:typeof J.upgrade==="function"?J.upgrade(Q):J.upgrade,data:{validator:W,open(C){J.open?.(new j0(C,Q))},message:(C,P)=>{const S=Z(P);if(X?.Check(S)===!1)return void C.send(new I("message",X,S).message);J.message?.(new j0(C,Q),S)},drain(C){J.drain?.(new j0(C,Q))},close(C,P,S){J.close?.(new j0(C,Q),P,S)}}}))return;return Y.status=400,"Expected a websocket connection"},{beforeHandle:J.beforeHandle,transform:J.transform,headers:J.headers,params:J.params,query:J.query}),this}state($,J){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=J;return this}decorate($,J){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=J;return this}derive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}model($,J){switch(typeof $){case"object":return Object.entries($).forEach(([w,B])=>{if(!(w in this.definitions.type))this.definitions.type[w]=B}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=J,this}mapDerive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}affix($,J,w){if(w==="")return this;const B=["_","-"," "],X=(Y)=>Y[0].toUpperCase()+Y.slice(1),W=$==="prefix"?(Y,G)=>B.includes(Y.at(-1)??"")?Y+G:Y+X(G):B.includes(w.at(-1)??"")?(Y,G)=>G+Y:(Y,G)=>G+X(Y),Z=(Y)=>{const G={};switch(Y){case"decorator":for(let K in this.singleton.decorator)G[W(w,K)]=this.singleton.decorator[K];this.singleton.decorator=G;break;case"state":for(let K in this.singleton.store)G[W(w,K)]=this.singleton.store[K];this.singleton.store=G;break;case"model":for(let K in this.definitions.type)G[W(w,K)]=this.definitions.type[K];this.definitions.type=G;break;case"error":for(let K in this.definitions.error)G[W(w,K)]=this.definitions.error[K];this.definitions.error=G;break}},Q=Array.isArray(J)?J:[J];for(let Y of Q.some((G)=>G==="all")?["decorator","state","model","error"]:Q)Z(Y);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?A1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?A1(this):O1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?P1(this):C$(this))($,J);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,J)=>{if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof $==="string"){if(!z0($))throw new Error("Port must be a numeric value");$=parseInt($)}const w=this.fetch,B=typeof $==="object"?{development:!I0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:w,error:this.outerErrorHandler}:{development:!I0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:$,fetch:w,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let X=0;X<this.event.start.length;X++)this.event.start[X].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let X=0;X<this.event.stop.length;X++)this.event.stop[X].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,j1 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,s0 as getResponseSchemaValidator,F1 as error,s as default,I as ValidationError,X0 as StatusMap,a0 as ParseError,Q0 as NotFoundError,t0 as InvertedStatusMap,P0 as InvalidCookieSignature,o0 as InternalServerError,s as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
440
440
|
|
|
441
|
-
//# debugId=
|
|
441
|
+
//# debugId=66E63B7DC12E370464756e2164756e21
|