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