elysia 1.0.11 → 1.0.13
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 +71 -68
- package/dist/bun/index.js.map +8 -8
- package/dist/cjs/compose.js +13 -10
- package/dist/cjs/context.d.ts +2 -2
- package/dist/cjs/cookies.d.ts +1 -2
- package/dist/cjs/cookies.js +6 -6
- package/dist/cjs/dynamic-handle.js +7 -7
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +14 -11
- package/dist/cjs/types.d.ts +8 -0
- package/dist/compose.mjs +13 -10
- package/dist/context.d.ts +2 -2
- package/dist/cookies.d.ts +1 -2
- package/dist/cookies.mjs +6 -6
- package/dist/dynamic-handle.mjs +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +14 -11
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/tsconfig.test.tsbuildinfo +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames:v$}=Object;var k$=Object.prototype.hasOwnProperty;var V0=($,J,W)=>{W=$!=null?g$(y$($)):{};const X=J||!$||!$.__esModule?L1(W,"default",{value:$,enumerable:!0}):W;for(let Z of v$($))if(!k$.call(X,Z))L1(X,Z,{get:()=>$[Z],enumerable:!0});return X};var F0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var H1=F0((m8,Y1)=>{var S0=function(){},u$=function($,J,W){this.fn=$,this.context=J,this.once=W||!1},b1=function($,J,W,X,Z){if(typeof W!=="function")throw new TypeError("The listener must be a function");var Q=new u$(W,X||$,Z),Y=y?y+J:J;if(!$._events[Y])$._events[Y]=Q,$._eventsCount++;else if(!$._events[Y].fn)$._events[Y].push(Q);else $._events[Y]=[$._events[Y],Q];return $},u0=function($,J){if(--$._eventsCount===0)$._events=new S0;else delete $._events[J]},g=function(){this._events=new S0,this._eventsCount=0},f$=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(S0.prototype=Object.create(null),!new S0().__proto__)y=!1}g.prototype.eventNames=function $(){var J=[],W,X;if(this._eventsCount===0)return J;for(X in W=this._events)if(f$.call(W,X))J.push(y?X.slice(1):X);if(Object.getOwnPropertySymbols)return J.concat(Object.getOwnPropertySymbols(W));return J};g.prototype.listeners=function $(J){var W=y?y+J:J,X=this._events[W];if(!X)return[];if(X.fn)return[X.fn];for(var Z=0,Q=X.length,Y=new Array(Q);Z<Q;Z++)Y[Z]=X[Z].fn;return Y};g.prototype.listenerCount=function $(J){var W=y?y+J:J,X=this._events[W];if(!X)return 0;if(X.fn)return 1;return X.length};g.prototype.emit=function $(J,W,X,Z,Q,Y){var G=y?y+J:J;if(!this._events[G])return!1;var B=this._events[G],_=arguments.length,K,z;if(B.fn){if(B.once)this.removeListener(J,B.fn,void 0,!0);switch(_){case 1:return B.fn.call(B.context),!0;case 2:return B.fn.call(B.context,W),!0;case 3:return B.fn.call(B.context,W,X),!0;case 4:return B.fn.call(B.context,W,X,Z),!0;case 5:return B.fn.call(B.context,W,X,Z,Q),!0;case 6:return B.fn.call(B.context,W,X,Z,Q,Y),!0}for(z=1,K=new Array(_-1);z<_;z++)K[z-1]=arguments[z];B.fn.apply(B.context,K)}else{var F=B.length,w;for(z=0;z<F;z++){if(B[z].once)this.removeListener(J,B[z].fn,void 0,!0);switch(_){case 1:B[z].fn.call(B[z].context);break;case 2:B[z].fn.call(B[z].context,W);break;case 3:B[z].fn.call(B[z].context,W,X);break;case 4:B[z].fn.call(B[z].context,W,X,Z);break;default:if(!K)for(w=1,K=new Array(_-1);w<_;w++)K[w-1]=arguments[w];B[z].fn.apply(B[z].context,K)}}}return!0};g.prototype.on=function $(J,W,X){return b1(this,J,W,X,!1)};g.prototype.once=function $(J,W,X){return b1(this,J,W,X,!0)};g.prototype.removeListener=function $(J,W,X,Z){var Q=y?y+J:J;if(!this._events[Q])return this;if(!W)return u0(this,Q),this;var Y=this._events[Q];if(Y.fn){if(Y.fn===W&&(!Z||Y.once)&&(!X||Y.context===X))u0(this,Q)}else{for(var G=0,B=[],_=Y.length;G<_;G++)if(Y[G].fn!==W||Z&&!Y[G].once||X&&Y[G].context!==X)B.push(Y[G]);if(B.length)this._events[Q]=B.length===1?B[0]:B;else u0(this,Q)}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 S0,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 Y1!=="undefined")Y1.exports=g});var p0=F0((i8,l1)=>{var J8=function($){var J=$.indexOf("%");if(J===-1)return $;var W=$.length,X="",Z=0,Q=0,Y=J,G=c1;while(J>-1&&J<W){var B=p1($[J+1],4),_=p1($[J+2],0),K=B|_,z=K1[K];if(G=K1[256+G+z],Q=Q<<6|K&K1[364+z],G===c1)X+=$.slice(Z,Y),X+=Q<=65535?String.fromCharCode(Q):String.fromCharCode(55232+(Q>>10),56320+(Q&1023)),Q=0,Z=J+3,J=Y=$.indexOf("%",Z);else if(G===$8)return null;else{if(J+=3,J<W&&$.charCodeAt(J)===37)continue;return null}}return X+$.slice(Z)},p1=function($,J){var W=W8[$];return W===void 0?255:W<<J},c1=12,$8=0,K1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],W8={"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};l1.exports=J8});var G$=F0((M9,Y$)=>{var _8=function($){const J=new Q$;if(typeof $!=="string")return J;let W=$.length,X="",Z="",Q=-1,Y=-1,G=!1,B=!1,_=!1,K=!1,z=!1,F=0;for(let w=0;w<W+1;w++)if(F=w!==W?$.charCodeAt(w):38,F===38){if(z=Y>Q,!z)Y=w;if(X=$.slice(Q+1,Y),z||X.length>0){if(_)X=X.replace(Z$," ");if(G)X=X$(X)||X;if(z){if(Z=$.slice(Y+1,w),K)Z=Z.replace(Z$," ");if(B)Z=X$(Z)||Z}const j=J[X];if(j===void 0)J[X]=Z;else if(j.pop)j.push(Z);else J[X]=[j,Z]}Z="",Q=w,Y=w,G=!1,B=!1,_=!1,K=!1}else if(F===61)if(Y<=Q)Y=w;else B=!0;else if(F===43)if(Y>Q)K=!0;else _=!0;else if(F===37)if(Y>Q)B=!0;else G=!0;return J},X$=p0(),Z$=/\+/g,Q$=function(){};Q$.prototype=Object.create(null);Y$.exports=_8});var U$=F0((w9,B$)=>{var F8=function($){const J=$.length;if(J===0)return"";let W="",X=0,Z=0;$:for(;Z<J;Z++){let Q=$.charCodeAt(Z);while(Q<128){if(z8[Q]!==1){if(X<Z)W+=$.slice(X,Z);X=Z+1,W+=s[Q]}if(++Z===J)break $;Q=$.charCodeAt(Z)}if(X<Z)W+=$.slice(X,Z);if(Q<2048){X=Z+1,W+=s[192|Q>>6]+s[128|Q&63];continue}if(Q<55296||Q>=57344){X=Z+1,W+=s[224|Q>>12]+s[128|Q>>6&63]+s[128|Q&63];continue}if(++Z,Z>=J)throw new Error("URI malformed");const Y=$.charCodeAt(Z)&1023;X=Z+1,Q=65536+((Q&1023)<<10|Y),W+=s[240|Q>>18]+s[128|Q>>12&63]+s[128|Q>>6&63]+s[128|Q&63]}if(X===0)return $;if(X<J)return W+$.slice(X);return W},s=Array.from({length:256},($,J)=>"%"+((J<16?"0":"")+J.toString(16)).toUpperCase()),z8=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]);B$.exports={encodeString:F8}});var z$=F0((A9,_$)=>{var K$=function($){const J=typeof $;if(J==="string")return O1($);else if(J==="bigint")return $.toString();else if(J==="boolean")return $?"true":"false";else if(J==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:O1(""+$);return""},D8=function($){let J="";if($===null||typeof $!=="object")return J;const W="&",X=Object.keys($),Z=X.length;let Q=0;for(let Y=0;Y<Z;Y++){const G=X[Y],B=$[G],_=O1(G)+"=";if(Y)J+=W;if(Array.isArray(B)){Q=B.length;for(let K=0;K<Q;K++){if(K)J+=W;J+=_,J+=K$(B[K])}}else J+=_,J+=K$(B)}return J},{encodeString:O1}=U$();_$.exports=D8});var P1=F0((j9,E0)=>{var F$=G$(),D$=z$(),M$={parse:F$,stringify:D$};E0.exports=M$;E0.exports.default=M$;E0.exports.parse=F$;E0.exports.stringify=D$});var D0=($,J)=>({part:$,store:null,inert:J!==void 0?new Map(J.map((W)=>[W.part.charCodeAt(0),W])):null,params:null,wildcardStore:null}),R1=($,J)=>({...$,part:J}),E1=($)=>({paramName:$,store:null,inert:null});class X0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,J,W){let X;if(typeof J!="string")throw TypeError("Route path must be a string");J===""?J="/":J[0]!=="/"&&(J=`/${J}`),this.history.push([$,J,W]);let Z=J[J.length-1]==="*";Z&&(J=J.slice(0,-1));let Q=J.split(X0.regex.static),Y=J.match(X0.regex.params)||[];Q[Q.length-1]===""&&Q.pop(),X=this.root[$]?this.root[$]:this.root[$]=D0("/");let G=0;for(let B=0;B<Q.length;++B){let _=Q[B];if(B>0){let K=Y[G++].slice(1);if(X.params===null)X.params=E1(K);else if(X.params.paramName!==K)throw Error(`Cannot create route "${J}" with parameter "${K}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);let z=X.params;if(z.inert===null){X=z.inert=D0(_);continue}X=z.inert}for(let K=0;;){if(K===_.length){if(K<X.part.length){let z=R1(X,X.part.slice(K));Object.assign(X,D0(_,[z]))}break}if(K===X.part.length){if(X.inert===null)X.inert=new Map;else if(X.inert.has(_.charCodeAt(K))){X=X.inert.get(_.charCodeAt(K)),_=_.slice(K),K=0;continue}let z=D0(_.slice(K));X.inert.set(_.charCodeAt(K),z),X=z;break}if(_[K]!==X.part[K]){let z=R1(X,X.part.slice(K)),F=D0(_.slice(K));Object.assign(X,D0(X.part.slice(0,K),[z,F])),X=F;break}++K}}if(G<Y.length){let B=Y[G],_=B.slice(1);if(X.params===null)X.params=E1(_);else if(X.params.paramName!==_)throw Error(`Cannot create route "${J}" with parameter "${_}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);return X.params.store===null&&(X.params.store=W),X.params.store}return Z?(X.wildcardStore===null&&(X.wildcardStore=W),X.wildcardStore):(X.store===null&&(X.store=W),X.store)}find($,J){let W=this.root[$];return W?Q1(J,J.length,W,0):null}}var Q1=($,J,W,X)=>{let Z=W?.part,Q=X+Z.length;if(Z.length>1){if(Q>J)return null;if(Z.length<15){for(let Y=1,G=X+1;Y<Z.length;++Y,++G)if(Z.charCodeAt(Y)!==$.charCodeAt(G))return null}else if($.substring(X,Q)!==Z)return null}if(Q===J)return W.store!==null?{store:W.store,params:{}}:W.wildcardStore!==null?{store:W.wildcardStore,params:{"*":""}}:null;if(W.inert!==null){let Y=W.inert.get($.charCodeAt(Q));if(Y!==void 0){let G=Q1($,J,Y,Q);if(G!==null)return G}}if(W.params!==null){let Y=W.params,G=$.indexOf("/",Q);if(G!==Q){if(G===-1||G>=J){if(Y.store!==null){let B={};return B[Y.paramName]=$.substring(Q,J),{store:Y.store,params:B}}}else if(Y.inert!==null){let B=Q1($,J,Y.inert,G);if(B!==null)return B.params[Y.paramName]=$.substring(Q,G),B}}}return W.wildcardStore!==null?{store:W.wildcardStore,params:{"*":$.substring(Q,J)}}:null};var x1=V0(H1(),1);var g1=x1.default;var h0=()=>{let $;return[new Promise((W)=>{$=W}),$]},J0=()=>{const[$,J]=h0(),[W,X]=h0(),Z=[],Q=[];return{signal:$,consume:(Y)=>{switch(Y.type){case"begin":if(Y.unit&&Z.length===0)for(let G=0;G<Y.unit;G++){const[B,_]=h0(),[K,z]=h0();Z.push(B),Q.push([(F)=>{_({children:[],end:K,name:F.name??"",skip:!1,time:F.time})},(F)=>{z(F)}])}J({children:Z,end:W,name:Y.name??"",skip:!1,time:Y.time});break;case"end":X(Y.time);break}},consumeChild(Y){switch(Y.type){case"begin":if(!Q[0])return;const[G]=Q[0];G({children:[],end:W,name:Y.name??"",skip:!1,time:Y.time});break;case"end":const B=Q.shift();if(!B)return;B[1](Y.time)}},resolve(){J({children:[],end:new Promise((Y)=>Y(0)),name:"",skip:!0,time:0});for(let[Y,G]of Q)Y({children:[],end:new Promise((B)=>B(0)),name:"",skip:!0,time:0}),G(0);X(0)}}},y1=($,J,W)=>{if(typeof W==="object")W=W.fn;return async function X(X){if(X.event!=="request"||X.type!=="begin")return;const Z=X.id,Q=$(),Y=J0(),G=J0(),B=J0(),_=J0(),K=J0(),z=J0(),F=J0(),w=J0();Y.consume(X);const j=(I)=>{if(I.id===Z)switch(I.event){case"request":Y.consume(I);break;case"request.unit":Y.consumeChild(I);break;case"parse":G.consume(I);break;case"parse.unit":G.consumeChild(I);break;case"transform":B.consume(I);break;case"transform.unit":B.consumeChild(I);break;case"beforeHandle":_.consume(I);break;case"beforeHandle.unit":_.consumeChild(I);break;case"handle":K.consume(I);break;case"afterHandle":z.consume(I);break;case"afterHandle.unit":z.consumeChild(I);break;case"error":F.consume(I);break;case"error.unit":F.consumeChild(I);break;case"response":if(I.type==="begin")Y.resolve(),G.resolve(),B.resolve(),_.resolve(),K.resolve(),z.resolve(),F.resolve();else Q.off("event",j);w.consume(I);break;case"response.unit":w.consumeChild(I);break;case"exit":Y.resolve(),G.resolve(),B.resolve(),_.resolve(),K.resolve(),z.resolve(),F.resolve();break}};Q.on("event",j),await W({id:Z,context:X.ctx,set:X.ctx?.set,store:X.ctx?.store,time:X.time,request:Y.signal,parse:G.signal,transform:B.signal,beforeHandle:_.signal,handle:K.signal,afterHandle:z.signal,error:F.signal,response:w.signal}),Q.emit(`res${Z}.${J}`,void 0)}};var k1=($)=>{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)];if(J=$.indexOf(") => "),J!==-1)return[$.slice(1,J),$.slice(J+5)]}if($.startsWith("function")){J=$.indexOf("(");const X=$.indexOf(")");return[$.slice(J+1,X),$.slice(X+2)]}const W=$.indexOf("(");if(W!==-1){const[X,Z]=$.split("\n",2),Q=X.lastIndexOf(")")+1;return[X.slice(W,Q),"{"+Z]}return $.split("\n",2)},f1=($)=>{const J=$.indexOf("{");if(J===-1)return[-1,0];let W=J+1,X=1;for(;W<$.length;W++){const Z=$.charCodeAt(W);if(Z===123)X++;else if(Z===125)X--;if(X===0)break}if(X!==0)return[0,$.length];return[J,W+1]},h$=($)=>{const J=$.lastIndexOf("}");if(J===-1)return[-1,0];let W=J-1,X=1;for(;W>=0;W--){const Z=$.charCodeAt(W);if(Z===125)X++;else if(Z===123)X--;if(X===0)break}if(X!==0)return[-1,0];return[W,J+1]},m0=($)=>{if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)$=$.slice(2,-2);while(!0){const[J,W]=f1($);if(J===-1)break;$=$.slice(0,J-2)+$.slice(W+1)}return $.replace(/:/g,"").trim()},m$=($,J)=>{const W=m0($);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},d$=($,J)=>{const W=m0($);if(!J.request&&W.includes("request"))J.request=!0;if(!J.parse&&W.includes("parse"))J.parse=!0;if(!J.transform&&W.includes("transform"))J.transform=!0;if(!J.handle&&W.includes("handle"))J.handle=!0;if(!J.beforeHandle&&W.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&W.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&W.includes("error"))J.error=!0;if(!J.context&&W.includes("context"))J.context=!0;if(!J.store&&W.includes("store"))J.store=!0;if(!J.set&&W.includes("set"))J.set=!0;return W},u1=($,J,W)=>{const X=J.indexOf($+"\n",W),Z=J.indexOf($+"\t",W),Q=J.indexOf($+",",W),Y=J.indexOf($+";",W),G=J.indexOf($+" ",W);return[X,Z,Q,Y,G].filter((B)=>B>0).sort((B,_)=>B-_)[0]||-1},c$=($,J,W)=>{const X=J.indexOf($+"]",W),Z=J.indexOf($+"'",W),Q=J.indexOf($+'"',W);return[X,Z,Q].filter((Y)=>Y>0).sort((Y,G)=>Y-G)[0]||-1},G1=($,J,W=0)=>{if(W>5)return[];const X=[];let Z=J;while(!0){let Q=u1(" = "+$,Z);if(Q===-1){const B=Z.indexOf(" = "+$);if(B+3+$.length!==Z.length)break;Q=B}const Y=Z.slice(0,Q);let G=Y.slice(Y.lastIndexOf(" ")+1);if(G==="}"){const[B,_]=h$(Y);X.push(Z.slice(B,_)),Z=Z.slice(Q+3+$.length);continue}while(G.charCodeAt(0)===44)G=G.slice(1);while(G.charCodeAt(0)===9)G=G.slice(1);X.push(G),Z=Z.slice(Q+3+$.length)}for(let Q of X){if(Q.charCodeAt(0)===123)continue;const Y=G1(Q,J);if(Y.length>0)X.push(...Y)}return X},h1=($,J)=>[$+"."+J,$+'["'+J+'"]',$+"['"+J+"']"],m1=($)=>{if(!$)return;if(!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return $}const W=$.indexOf("...");if(W===-1)return;return $.slice(W+3).trimEnd()},v1=($,J,W)=>{const X=(Z,Q)=>$.includes(Q+"."+Z)||$.includes(Q+'["'+Z+'"]')||$.includes(Q+"['"+Z+"']");for(let Z of J){if(!Z)continue;if(Z.charCodeAt(0)===123){if(Z=m0(Z),!W.query&&Z.includes("query"))W.query=!0;if(!W.headers&&Z.includes("headers"))W.headers=!0;if(!W.body&&Z.includes("body"))W.body=!0;if(!W.cookie&&Z.includes("cookie"))W.cookie=!0;if(!W.set&&Z.includes("set"))W.set=!0;continue}if($.includes("("+Z+")")){W.query=!0,W.headers=!0,W.body=!0,W.cookie=!0,W.set=!0,W.queries=[],W.unknownQueries=!0;break}if(!W.query&&X("query",Z))W.query=!0;if($.includes("return "+Z)||h1("return "+Z,"query").some((Q)=>$.includes(Q)))W.query=!0,W.unknownQueries=!0;if(W.query&&!W.unknownQueries)while(!0){let Q=Z+".";if($.includes(Q+"query"))Q=Z+".query";let Y=!1,G=$.indexOf(Q);if(G===-1)Y=!0,G=$.indexOf(Z+'["');if(G===-1)Y=!0,G=$.indexOf(Z+"['");if(G===-1&&$.indexOf(Z+"[")!==-1){W.queries=[],W.unknownQueries=!0;break}if(G!==-1){let B=Y?c$("",$,G+Q.length+1):u1("",$,G+Q.length+1);if(B===-1)B=void 0;const _=G+Z.length+1;$=$.slice(G+Z.length+1);let K=$.slice(0,B?B-_:B).trimEnd();while(G!==-1)if(G=K.indexOf("."),G!==-1)K=K.slice(G+1);if(K.charCodeAt(K.length-1)===59)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===44)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===93)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===41)K=K.slice(0,-1);if(Y)K=K.replaceAll(/("|')/g,"");if(K&&!W.queries.includes(K)){W.queries.push(K);continue}}break}if(!W.headers&&X("headers",Z))W.headers=!0;if(!W.body&&X("body",Z))W.body=!0;if(!W.cookie&&X("cookie",Z))W.cookie=!0;if(!W.set&&X("set",Z))W.set=!0;if(W.query&&W.headers&&W.body&&W.cookie&&W.set)break}return J},p$=($)=>{while(!0){const J=$.indexOf("=");if(J===-1)break;const W=$.indexOf(",",J),X=$.indexOf("}",J),Z=[W,X].filter((Q)=>Q>0).sort((Q,Y)=>Q-Y)[0]||-1;if(Z===-1){$=$.slice(0,J);break}$=$.slice(0,J)+$.slice(Z)}return $.split(",").map((J)=>J.trim()).join(", ")},l$=($)=>{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},i$=($,J,W)=>{const X=(Z,Q)=>$.includes(Z+"."+Q)||$.includes(Z+'["'+Q+'"]')||$.includes(Z+"['"+Q+"']");for(let Z of J){if(Z.charCodeAt(0)===123){if(Z=m0(Z),!W.request&&Z.includes("request"))W.request=!0;if(!W.parse&&Z.includes("parse"))W.parse=!0;if(!W.transform&&Z.includes("transform"))W.transform=!0;if(!W.handle&&Z.includes("handle"))W.handle=!0;if(!W.beforeHandle&&Z.includes("beforeHandle"))W.beforeHandle=!0;if(!W.afterHandle&&Z.includes("afterHandle"))W.afterHandle=!0;if(!W.error&&Z.includes("error"))W.error=!0;if(!W.context&&Z.includes("context"))W.context=!0;if(!W.store&&Z.includes("store"))W.store=!0;if(!W.set&&Z.includes("set"))W.set=!0;continue}if($.includes("("+Z+")")){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&&X("request",Z))W.request=!0;if(!W.parse&&X("parse",Z))W.parse=!0;if(!W.transform&&X("transform",Z))W.transform=!0;if(!W.handle&&X("handle",Z))W.handle=!0;if(!W.beforeHandle&&X("beforeHandle",Z))W.beforeHandle=!0;if(!W.afterHandle&&X("afterHandle",Z))W.afterHandle=!0;if(!W.error&&X("error",Z))W.error=!0;if(!W.context&&X("context",Z))W.context=!0;if(!W.store&&X("store",Z))W.store=!0;if(!W.set&&X("set",Z))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},d0=($,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 X of W){if(!X)continue;const Z="fn"in X?X.fn:X,[Q,Y]=k1(Z.toString()),G=m$(Q,J),B=m1(G);if(B){const K=G1(B,Y);K.splice(0,-1,B),v1(Y,K,J)}const _=G||B;if(_&&["","return "].some((K)=>h1(K+_,"query").some((z)=>Y.includes(z))))J.query=!0,J.unknownQueries=!0;if(J.query){v1(Y,["query"],J);const K=Q.indexOf("query: {");if(K!==-1){const z=Q.slice(K+7),[F,w]=f1(z),j=p$(z.slice(F,w));for(let I of j.slice(1,-1).split(",")){const U=I.indexOf(":");if(U!==-1)I=I.slice(0,U);if(I=I.trim(),I&&!J.queries.includes(I))J.queries.push(I.trim())}}}if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}if(!l$(J.queries))J.unknownQueries=!0,J.queries=[];return J},d1=($,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[X,Z]=k1(W.toString()),Q=d$(X,J),Y=m1(Q);if(Y){const G=G1(Y,Z);G.splice(0,-1,Y),i$(Z,G,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 o0} from"@sinclair/typebox/value";import{Kind as z1} from"@sinclair/typebox";import{Value as w0} from"@sinclair/typebox/value";import{TypeCompiler as o1} from"@sinclair/typebox/compiler";var s$=function($,J){if(typeof $!=="string")throw new TypeError("argument str must be a string");var W={},X=J||{},Z=X.decode||r$,Q=0;while(Q<$.length){var Y=$.indexOf("=",Q);if(Y===-1)break;var G=$.indexOf(";",Q);if(G===-1)G=$.length;else if(G<Y){Q=$.lastIndexOf(";",Y-1)+1;continue}var B=$.slice(Q,Y).trim();if(W[B]===void 0){var _=$.slice(Y+1,G).trim();if(_.charCodeAt(0)===34)_=_.slice(1,-1);W[B]=e$(_,Z)}Q=G+1}return W},n$=function($,J,W){var X=W||{},Z=X.encode||o$;if(typeof Z!=="function")throw new TypeError("option encode is invalid");if(!c0.test($))throw new TypeError("argument name is invalid");var Q=Z(J);if(Q&&!c0.test(Q))throw new TypeError("argument val is invalid");var Y=$+"="+Q;if(X.maxAge!=null){var G=X.maxAge-0;if(isNaN(G)||!isFinite(G))throw new TypeError("option maxAge is invalid");Y+="; Max-Age="+Math.floor(G)}if(X.domain){if(!c0.test(X.domain))throw new TypeError("option domain is invalid");Y+="; Domain="+X.domain}if(X.path){if(!c0.test(X.path))throw new TypeError("option path is invalid");Y+="; Path="+X.path}if(X.expires){var B=X.expires;if(!a$(B)||isNaN(B.valueOf()))throw new TypeError("option expires is invalid");Y+="; Expires="+B.toUTCString()}if(X.httpOnly)Y+="; HttpOnly";if(X.secure)Y+="; Secure";if(X.partitioned)Y+="; Partitioned";if(X.priority){var _=typeof X.priority==="string"?X.priority.toLowerCase():X.priority;switch(_){case"low":Y+="; Priority=Low";break;case"medium":Y+="; Priority=Medium";break;case"high":Y+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(X.sameSite){var K=typeof X.sameSite==="string"?X.sameSite.toLowerCase():X.sameSite;switch(K){case!0:Y+="; SameSite=Strict";break;case"lax":Y+="; SameSite=Lax";break;case"strict":Y+="; SameSite=Strict";break;case"none":Y+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return Y},r$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},o$=function($){return encodeURIComponent($)},a$=function($){return t$.call($)==="[object Date]"||$ instanceof Date},e$=function($,J){try{return J($)}catch(W){return $}};/*!
|
|
2
|
+
var g$=Object.create;var{defineProperty:R1,getPrototypeOf:y$,getOwnPropertyNames:v$}=Object;var k$=Object.prototype.hasOwnProperty;var V0=($,J,W)=>{W=$!=null?g$(y$($)):{};const X=J||!$||!$.__esModule?R1(W,"default",{value:$,enumerable:!0}):W;for(let Z of v$($))if(!k$.call(X,Z))R1(X,Z,{get:()=>$[Z],enumerable:!0});return X};var F0=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var H1=F0((m8,G1)=>{var S0=function(){},u$=function($,J,W){this.fn=$,this.context=J,this.once=W||!1},b1=function($,J,W,X,Z){if(typeof W!=="function")throw new TypeError("The listener must be a function");var Q=new u$(W,X||$,Z),G=y?y+J:J;if(!$._events[G])$._events[G]=Q,$._eventsCount++;else if(!$._events[G].fn)$._events[G].push(Q);else $._events[G]=[$._events[G],Q];return $},u0=function($,J){if(--$._eventsCount===0)$._events=new S0;else delete $._events[J]},g=function(){this._events=new S0,this._eventsCount=0},f$=Object.prototype.hasOwnProperty,y="~";if(Object.create){if(S0.prototype=Object.create(null),!new S0().__proto__)y=!1}g.prototype.eventNames=function $(){var J=[],W,X;if(this._eventsCount===0)return J;for(X in W=this._events)if(f$.call(W,X))J.push(y?X.slice(1):X);if(Object.getOwnPropertySymbols)return J.concat(Object.getOwnPropertySymbols(W));return J};g.prototype.listeners=function $(J){var W=y?y+J:J,X=this._events[W];if(!X)return[];if(X.fn)return[X.fn];for(var Z=0,Q=X.length,G=new Array(Q);Z<Q;Z++)G[Z]=X[Z].fn;return G};g.prototype.listenerCount=function $(J){var W=y?y+J:J,X=this._events[W];if(!X)return 0;if(X.fn)return 1;return X.length};g.prototype.emit=function $(J,W,X,Z,Q,G){var Y=y?y+J:J;if(!this._events[Y])return!1;var B=this._events[Y],_=arguments.length,K,z;if(B.fn){if(B.once)this.removeListener(J,B.fn,void 0,!0);switch(_){case 1:return B.fn.call(B.context),!0;case 2:return B.fn.call(B.context,W),!0;case 3:return B.fn.call(B.context,W,X),!0;case 4:return B.fn.call(B.context,W,X,Z),!0;case 5:return B.fn.call(B.context,W,X,Z,Q),!0;case 6:return B.fn.call(B.context,W,X,Z,Q,G),!0}for(z=1,K=new Array(_-1);z<_;z++)K[z-1]=arguments[z];B.fn.apply(B.context,K)}else{var F=B.length,M;for(z=0;z<F;z++){if(B[z].once)this.removeListener(J,B[z].fn,void 0,!0);switch(_){case 1:B[z].fn.call(B[z].context);break;case 2:B[z].fn.call(B[z].context,W);break;case 3:B[z].fn.call(B[z].context,W,X);break;case 4:B[z].fn.call(B[z].context,W,X,Z);break;default:if(!K)for(M=1,K=new Array(_-1);M<_;M++)K[M-1]=arguments[M];B[z].fn.apply(B[z].context,K)}}}return!0};g.prototype.on=function $(J,W,X){return b1(this,J,W,X,!1)};g.prototype.once=function $(J,W,X){return b1(this,J,W,X,!0)};g.prototype.removeListener=function $(J,W,X,Z){var Q=y?y+J:J;if(!this._events[Q])return this;if(!W)return u0(this,Q),this;var G=this._events[Q];if(G.fn){if(G.fn===W&&(!Z||G.once)&&(!X||G.context===X))u0(this,Q)}else{for(var Y=0,B=[],_=G.length;Y<_;Y++)if(G[Y].fn!==W||Z&&!G[Y].once||X&&G[Y].context!==X)B.push(G[Y]);if(B.length)this._events[Q]=B.length===1?B[0]:B;else u0(this,Q)}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 S0,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 G1!=="undefined")G1.exports=g});var p0=F0((i8,l1)=>{var J8=function($){var J=$.indexOf("%");if(J===-1)return $;var W=$.length,X="",Z=0,Q=0,G=J,Y=c1;while(J>-1&&J<W){var B=p1($[J+1],4),_=p1($[J+2],0),K=B|_,z=K1[K];if(Y=K1[256+Y+z],Q=Q<<6|K&K1[364+z],Y===c1)X+=$.slice(Z,G),X+=Q<=65535?String.fromCharCode(Q):String.fromCharCode(55232+(Q>>10),56320+(Q&1023)),Q=0,Z=J+3,J=G=$.indexOf("%",Z);else if(Y===$8)return null;else{if(J+=3,J<W&&$.charCodeAt(J)===37)continue;return null}}return X+$.slice(Z)},p1=function($,J){var W=W8[$];return W===void 0?255:W<<J},c1=12,$8=0,K1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],W8={"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};l1.exports=J8});var Y$=F0((A9,G$)=>{var _8=function($){const J=new Q$;if(typeof $!=="string")return J;let W=$.length,X="",Z="",Q=-1,G=-1,Y=!1,B=!1,_=!1,K=!1,z=!1,F=0;for(let M=0;M<W+1;M++)if(F=M!==W?$.charCodeAt(M):38,F===38){if(z=G>Q,!z)G=M;if(X=$.slice(Q+1,G),z||X.length>0){if(_)X=X.replace(Z$," ");if(Y)X=X$(X)||X;if(z){if(Z=$.slice(G+1,M),K)Z=Z.replace(Z$," ");if(B)Z=X$(Z)||Z}const w=J[X];if(w===void 0)J[X]=Z;else if(w.pop)w.push(Z);else J[X]=[w,Z]}Z="",Q=M,G=M,Y=!1,B=!1,_=!1,K=!1}else if(F===61)if(G<=Q)G=M;else B=!0;else if(F===43)if(G>Q)K=!0;else _=!0;else if(F===37)if(G>Q)B=!0;else Y=!0;return J},X$=p0(),Z$=/\+/g,Q$=function(){};Q$.prototype=Object.create(null);G$.exports=_8});var U$=F0((M9,B$)=>{var F8=function($){const J=$.length;if(J===0)return"";let W="",X=0,Z=0;$:for(;Z<J;Z++){let Q=$.charCodeAt(Z);while(Q<128){if(z8[Q]!==1){if(X<Z)W+=$.slice(X,Z);X=Z+1,W+=s[Q]}if(++Z===J)break $;Q=$.charCodeAt(Z)}if(X<Z)W+=$.slice(X,Z);if(Q<2048){X=Z+1,W+=s[192|Q>>6]+s[128|Q&63];continue}if(Q<55296||Q>=57344){X=Z+1,W+=s[224|Q>>12]+s[128|Q>>6&63]+s[128|Q&63];continue}if(++Z,Z>=J)throw new Error("URI malformed");const G=$.charCodeAt(Z)&1023;X=Z+1,Q=65536+((Q&1023)<<10|G),W+=s[240|Q>>18]+s[128|Q>>12&63]+s[128|Q>>6&63]+s[128|Q&63]}if(X===0)return $;if(X<J)return W+$.slice(X);return W},s=Array.from({length:256},($,J)=>"%"+((J<16?"0":"")+J.toString(16)).toUpperCase()),z8=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]);B$.exports={encodeString:F8}});var z$=F0((j9,_$)=>{var K$=function($){const J=typeof $;if(J==="string")return P1($);else if(J==="bigint")return $.toString();else if(J==="boolean")return $?"true":"false";else if(J==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:P1(""+$);return""},D8=function($){let J="";if($===null||typeof $!=="object")return J;const W="&",X=Object.keys($),Z=X.length;let Q=0;for(let G=0;G<Z;G++){const Y=X[G],B=$[Y],_=P1(Y)+"=";if(G)J+=W;if(Array.isArray(B)){Q=B.length;for(let K=0;K<Q;K++){if(K)J+=W;J+=_,J+=K$(B[K])}}else J+=_,J+=K$(B)}return J},{encodeString:P1}=U$();_$.exports=D8});var O1=F0((w9,E0)=>{var F$=Y$(),D$=z$(),A$={parse:F$,stringify:D$};E0.exports=A$;E0.exports.default=A$;E0.exports.parse=F$;E0.exports.stringify=D$});var D0=($,J)=>({part:$,store:null,inert:J!==void 0?new Map(J.map((W)=>[W.part.charCodeAt(0),W])):null,params:null,wildcardStore:null}),L1=($,J)=>({...$,part:J}),E1=($)=>({paramName:$,store:null,inert:null});class X0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,J,W){let X;if(typeof J!="string")throw TypeError("Route path must be a string");J===""?J="/":J[0]!=="/"&&(J=`/${J}`),this.history.push([$,J,W]);let Z=J[J.length-1]==="*";Z&&(J=J.slice(0,-1));let Q=J.split(X0.regex.static),G=J.match(X0.regex.params)||[];Q[Q.length-1]===""&&Q.pop(),X=this.root[$]?this.root[$]:this.root[$]=D0("/");let Y=0;for(let B=0;B<Q.length;++B){let _=Q[B];if(B>0){let K=G[Y++].slice(1);if(X.params===null)X.params=E1(K);else if(X.params.paramName!==K)throw Error(`Cannot create route "${J}" with parameter "${K}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);let z=X.params;if(z.inert===null){X=z.inert=D0(_);continue}X=z.inert}for(let K=0;;){if(K===_.length){if(K<X.part.length){let z=L1(X,X.part.slice(K));Object.assign(X,D0(_,[z]))}break}if(K===X.part.length){if(X.inert===null)X.inert=new Map;else if(X.inert.has(_.charCodeAt(K))){X=X.inert.get(_.charCodeAt(K)),_=_.slice(K),K=0;continue}let z=D0(_.slice(K));X.inert.set(_.charCodeAt(K),z),X=z;break}if(_[K]!==X.part[K]){let z=L1(X,X.part.slice(K)),F=D0(_.slice(K));Object.assign(X,D0(X.part.slice(0,K),[z,F])),X=F;break}++K}}if(Y<G.length){let B=G[Y],_=B.slice(1);if(X.params===null)X.params=E1(_);else if(X.params.paramName!==_)throw Error(`Cannot create route "${J}" with parameter "${_}" because a route already exists with a different parameter name ("${X.params.paramName}") in the same location`);return X.params.store===null&&(X.params.store=W),X.params.store}return Z?(X.wildcardStore===null&&(X.wildcardStore=W),X.wildcardStore):(X.store===null&&(X.store=W),X.store)}find($,J){let W=this.root[$];return W?Q1(J,J.length,W,0):null}}var Q1=($,J,W,X)=>{let Z=W?.part,Q=X+Z.length;if(Z.length>1){if(Q>J)return null;if(Z.length<15){for(let G=1,Y=X+1;G<Z.length;++G,++Y)if(Z.charCodeAt(G)!==$.charCodeAt(Y))return null}else if($.substring(X,Q)!==Z)return null}if(Q===J)return W.store!==null?{store:W.store,params:{}}:W.wildcardStore!==null?{store:W.wildcardStore,params:{"*":""}}:null;if(W.inert!==null){let G=W.inert.get($.charCodeAt(Q));if(G!==void 0){let Y=Q1($,J,G,Q);if(Y!==null)return Y}}if(W.params!==null){let G=W.params,Y=$.indexOf("/",Q);if(Y!==Q){if(Y===-1||Y>=J){if(G.store!==null){let B={};return B[G.paramName]=$.substring(Q,J),{store:G.store,params:B}}}else if(G.inert!==null){let B=Q1($,J,G.inert,Y);if(B!==null)return B.params[G.paramName]=$.substring(Q,Y),B}}}return W.wildcardStore!==null?{store:W.wildcardStore,params:{"*":$.substring(Q,J)}}:null};var x1=V0(H1(),1);var g1=x1.default;var h0=()=>{let $;return[new Promise((W)=>{$=W}),$]},J0=()=>{const[$,J]=h0(),[W,X]=h0(),Z=[],Q=[];return{signal:$,consume:(G)=>{switch(G.type){case"begin":if(G.unit&&Z.length===0)for(let Y=0;Y<G.unit;Y++){const[B,_]=h0(),[K,z]=h0();Z.push(B),Q.push([(F)=>{_({children:[],end:K,name:F.name??"",skip:!1,time:F.time})},(F)=>{z(F)}])}J({children:Z,end:W,name:G.name??"",skip:!1,time:G.time});break;case"end":X(G.time);break}},consumeChild(G){switch(G.type){case"begin":if(!Q[0])return;const[Y]=Q[0];Y({children:[],end:W,name:G.name??"",skip:!1,time:G.time});break;case"end":const B=Q.shift();if(!B)return;B[1](G.time)}},resolve(){J({children:[],end:new Promise((G)=>G(0)),name:"",skip:!0,time:0});for(let[G,Y]of Q)G({children:[],end:new Promise((B)=>B(0)),name:"",skip:!0,time:0}),Y(0);X(0)}}},y1=($,J,W)=>{if(typeof W==="object")W=W.fn;return async function X(X){if(X.event!=="request"||X.type!=="begin")return;const Z=X.id,Q=$(),G=J0(),Y=J0(),B=J0(),_=J0(),K=J0(),z=J0(),F=J0(),M=J0();G.consume(X);const w=(I)=>{if(I.id===Z)switch(I.event){case"request":G.consume(I);break;case"request.unit":G.consumeChild(I);break;case"parse":Y.consume(I);break;case"parse.unit":Y.consumeChild(I);break;case"transform":B.consume(I);break;case"transform.unit":B.consumeChild(I);break;case"beforeHandle":_.consume(I);break;case"beforeHandle.unit":_.consumeChild(I);break;case"handle":K.consume(I);break;case"afterHandle":z.consume(I);break;case"afterHandle.unit":z.consumeChild(I);break;case"error":F.consume(I);break;case"error.unit":F.consumeChild(I);break;case"response":if(I.type==="begin")G.resolve(),Y.resolve(),B.resolve(),_.resolve(),K.resolve(),z.resolve(),F.resolve();else Q.off("event",w);M.consume(I);break;case"response.unit":M.consumeChild(I);break;case"exit":G.resolve(),Y.resolve(),B.resolve(),_.resolve(),K.resolve(),z.resolve(),F.resolve();break}};Q.on("event",w),await W({id:Z,context:X.ctx,set:X.ctx?.set,store:X.ctx?.store,time:X.time,request:G.signal,parse:Y.signal,transform:B.signal,beforeHandle:_.signal,handle:K.signal,afterHandle:z.signal,error:F.signal,response:M.signal}),Q.emit(`res${Z}.${J}`,void 0)}};var k1=($)=>{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)];if(J=$.indexOf(") => "),J!==-1)return[$.slice(1,J),$.slice(J+5)]}if($.startsWith("function")){J=$.indexOf("(");const X=$.indexOf(")");return[$.slice(J+1,X),$.slice(X+2)]}const W=$.indexOf("(");if(W!==-1){const[X,Z]=$.split("\n",2),Q=X.lastIndexOf(")")+1;return[X.slice(W,Q),"{"+Z]}return $.split("\n",2)},f1=($)=>{const J=$.indexOf("{");if(J===-1)return[-1,0];let W=J+1,X=1;for(;W<$.length;W++){const Z=$.charCodeAt(W);if(Z===123)X++;else if(Z===125)X--;if(X===0)break}if(X!==0)return[0,$.length];return[J,W+1]},h$=($)=>{const J=$.lastIndexOf("}");if(J===-1)return[-1,0];let W=J-1,X=1;for(;W>=0;W--){const Z=$.charCodeAt(W);if(Z===125)X++;else if(Z===123)X--;if(X===0)break}if(X!==0)return[-1,0];return[W,J+1]},m0=($)=>{if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)$=$.slice(2,-2);while(!0){const[J,W]=f1($);if(J===-1)break;$=$.slice(0,J-2)+$.slice(W+1)}return $.replace(/:/g,"").trim()},m$=($,J)=>{const W=m0($);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},d$=($,J)=>{const W=m0($);if(!J.request&&W.includes("request"))J.request=!0;if(!J.parse&&W.includes("parse"))J.parse=!0;if(!J.transform&&W.includes("transform"))J.transform=!0;if(!J.handle&&W.includes("handle"))J.handle=!0;if(!J.beforeHandle&&W.includes("beforeHandle"))J.beforeHandle=!0;if(!J.afterHandle&&W.includes("afterHandle"))J.afterHandle=!0;if(!J.error&&W.includes("error"))J.error=!0;if(!J.context&&W.includes("context"))J.context=!0;if(!J.store&&W.includes("store"))J.store=!0;if(!J.set&&W.includes("set"))J.set=!0;return W},u1=($,J,W)=>{const X=J.indexOf($+"\n",W),Z=J.indexOf($+"\t",W),Q=J.indexOf($+",",W),G=J.indexOf($+";",W),Y=J.indexOf($+" ",W);return[X,Z,Q,G,Y].filter((B)=>B>0).sort((B,_)=>B-_)[0]||-1},c$=($,J,W)=>{const X=J.indexOf($+"]",W),Z=J.indexOf($+"'",W),Q=J.indexOf($+'"',W);return[X,Z,Q].filter((G)=>G>0).sort((G,Y)=>G-Y)[0]||-1},Y1=($,J,W=0)=>{if(W>5)return[];const X=[];let Z=J;while(!0){let Q=u1(" = "+$,Z);if(Q===-1){const B=Z.indexOf(" = "+$);if(B+3+$.length!==Z.length)break;Q=B}const G=Z.slice(0,Q);let Y=G.slice(G.lastIndexOf(" ")+1);if(Y==="}"){const[B,_]=h$(G);X.push(Z.slice(B,_)),Z=Z.slice(Q+3+$.length);continue}while(Y.charCodeAt(0)===44)Y=Y.slice(1);while(Y.charCodeAt(0)===9)Y=Y.slice(1);X.push(Y),Z=Z.slice(Q+3+$.length)}for(let Q of X){if(Q.charCodeAt(0)===123)continue;const G=Y1(Q,J);if(G.length>0)X.push(...G)}return X},h1=($,J)=>[$+"."+J,$+'["'+J+'"]',$+"['"+J+"']"],m1=($)=>{if(!$)return;if(!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return $}const W=$.indexOf("...");if(W===-1)return;return $.slice(W+3).trimEnd()},v1=($,J,W)=>{const X=(Z,Q)=>$.includes(Q+"."+Z)||$.includes(Q+'["'+Z+'"]')||$.includes(Q+"['"+Z+"']");for(let Z of J){if(!Z)continue;if(Z.charCodeAt(0)===123){if(Z=m0(Z),!W.query&&Z.includes("query"))W.query=!0;if(!W.headers&&Z.includes("headers"))W.headers=!0;if(!W.body&&Z.includes("body"))W.body=!0;if(!W.cookie&&Z.includes("cookie"))W.cookie=!0;if(!W.set&&Z.includes("set"))W.set=!0;continue}if($.includes("("+Z+")")){W.query=!0,W.headers=!0,W.body=!0,W.cookie=!0,W.set=!0,W.queries=[],W.unknownQueries=!0;break}if(!W.query&&X("query",Z))W.query=!0;if($.includes("return "+Z)||h1("return "+Z,"query").some((Q)=>$.includes(Q)))W.query=!0,W.unknownQueries=!0;if(W.query&&!W.unknownQueries)while(!0){let Q=Z+".";if($.includes(Q+"query"))Q=Z+".query";let G=!1,Y=$.indexOf(Q);if(Y===-1)G=!0,Y=$.indexOf(Z+'["');if(Y===-1)G=!0,Y=$.indexOf(Z+"['");if(Y===-1&&$.indexOf(Z+"[")!==-1){W.queries=[],W.unknownQueries=!0;break}if(Y!==-1){let B=G?c$("",$,Y+Q.length+1):u1("",$,Y+Q.length+1);if(B===-1)B=void 0;const _=Y+Z.length+1;$=$.slice(Y+Z.length+1);let K=$.slice(0,B?B-_:B).trimEnd();while(Y!==-1)if(Y=K.indexOf("."),Y!==-1)K=K.slice(Y+1);if(K.charCodeAt(K.length-1)===59)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===44)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===93)K=K.slice(0,-1);if(K.charCodeAt(K.length-1)===41)K=K.slice(0,-1);if(G)K=K.replaceAll(/("|')/g,"");if(K&&!W.queries.includes(K)){W.queries.push(K);continue}}break}if(!W.headers&&X("headers",Z))W.headers=!0;if(!W.body&&X("body",Z))W.body=!0;if(!W.cookie&&X("cookie",Z))W.cookie=!0;if(!W.set&&X("set",Z))W.set=!0;if(W.query&&W.headers&&W.body&&W.cookie&&W.set)break}return J},p$=($)=>{while(!0){const J=$.indexOf("=");if(J===-1)break;const W=$.indexOf(",",J),X=$.indexOf("}",J),Z=[W,X].filter((Q)=>Q>0).sort((Q,G)=>Q-G)[0]||-1;if(Z===-1){$=$.slice(0,J);break}$=$.slice(0,J)+$.slice(Z)}return $.split(",").map((J)=>J.trim()).join(", ")},l$=($)=>{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},i$=($,J,W)=>{const X=(Z,Q)=>$.includes(Z+"."+Q)||$.includes(Z+'["'+Q+'"]')||$.includes(Z+"['"+Q+"']");for(let Z of J){if(Z.charCodeAt(0)===123){if(Z=m0(Z),!W.request&&Z.includes("request"))W.request=!0;if(!W.parse&&Z.includes("parse"))W.parse=!0;if(!W.transform&&Z.includes("transform"))W.transform=!0;if(!W.handle&&Z.includes("handle"))W.handle=!0;if(!W.beforeHandle&&Z.includes("beforeHandle"))W.beforeHandle=!0;if(!W.afterHandle&&Z.includes("afterHandle"))W.afterHandle=!0;if(!W.error&&Z.includes("error"))W.error=!0;if(!W.context&&Z.includes("context"))W.context=!0;if(!W.store&&Z.includes("store"))W.store=!0;if(!W.set&&Z.includes("set"))W.set=!0;continue}if($.includes("("+Z+")")){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&&X("request",Z))W.request=!0;if(!W.parse&&X("parse",Z))W.parse=!0;if(!W.transform&&X("transform",Z))W.transform=!0;if(!W.handle&&X("handle",Z))W.handle=!0;if(!W.beforeHandle&&X("beforeHandle",Z))W.beforeHandle=!0;if(!W.afterHandle&&X("afterHandle",Z))W.afterHandle=!0;if(!W.error&&X("error",Z))W.error=!0;if(!W.context&&X("context",Z))W.context=!0;if(!W.store&&X("store",Z))W.store=!0;if(!W.set&&X("set",Z))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},d0=($,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 X of W){if(!X)continue;const Z="fn"in X?X.fn:X,[Q,G]=k1(Z.toString()),Y=m$(Q,J),B=m1(Y);if(B){const K=Y1(B,G);K.splice(0,-1,B),v1(G,K,J)}const _=Y||B;if(_&&["","return "].some((K)=>h1(K+_,"query").some((z)=>G.includes(z))))J.query=!0,J.unknownQueries=!0;if(J.query){v1(G,["query"],J);const K=Q.indexOf("query: {");if(K!==-1){const z=Q.slice(K+7),[F,M]=f1(z),w=p$(z.slice(F,M));for(let I of w.slice(1,-1).split(",")){const U=I.indexOf(":");if(U!==-1)I=I.slice(0,U);if(I=I.trim(),I&&!J.queries.includes(I))J.queries.push(I.trim())}}}if(J.query&&J.headers&&J.body&&J.cookie&&J.set)break}if(!l$(J.queries))J.unknownQueries=!0,J.queries=[];return J},d1=($,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[X,Z]=k1(W.toString()),Q=d$(X,J),G=m1(Q);if(G){const Y=Y1(G,Z);Y.splice(0,-1,G),i$(Z,Y,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 o0} from"@sinclair/typebox/value";import{Kind as z1} from"@sinclair/typebox";import{Value as M0} from"@sinclair/typebox/value";import{TypeCompiler as o1} from"@sinclair/typebox/compiler";var s$=function($,J){if(typeof $!=="string")throw new TypeError("argument str must be a string");var W={},X=J||{},Z=X.decode||r$,Q=0;while(Q<$.length){var G=$.indexOf("=",Q);if(G===-1)break;var Y=$.indexOf(";",Q);if(Y===-1)Y=$.length;else if(Y<G){Q=$.lastIndexOf(";",G-1)+1;continue}var B=$.slice(Q,G).trim();if(W[B]===void 0){var _=$.slice(G+1,Y).trim();if(_.charCodeAt(0)===34)_=_.slice(1,-1);W[B]=e$(_,Z)}Q=Y+1}return W},n$=function($,J,W){var X=W||{},Z=X.encode||o$;if(typeof Z!=="function")throw new TypeError("option encode is invalid");if(!c0.test($))throw new TypeError("argument name is invalid");var Q=Z(J);if(Q&&!c0.test(Q))throw new TypeError("argument val is invalid");var G=$+"="+Q;if(X.maxAge!=null){var Y=X.maxAge-0;if(isNaN(Y)||!isFinite(Y))throw new TypeError("option maxAge is invalid");G+="; Max-Age="+Math.floor(Y)}if(X.domain){if(!c0.test(X.domain))throw new TypeError("option domain is invalid");G+="; Domain="+X.domain}if(X.path){if(!c0.test(X.path))throw new TypeError("option path is invalid");G+="; Path="+X.path}if(X.expires){var B=X.expires;if(!a$(B)||isNaN(B.valueOf()))throw new TypeError("option expires is invalid");G+="; Expires="+B.toUTCString()}if(X.httpOnly)G+="; HttpOnly";if(X.secure)G+="; Secure";if(X.partitioned)G+="; Partitioned";if(X.priority){var _=typeof X.priority==="string"?X.priority.toLowerCase():X.priority;switch(_){case"low":G+="; Priority=Low";break;case"medium":G+="; Priority=Medium";break;case"high":G+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(X.sameSite){var K=typeof X.sameSite==="string"?X.sameSite.toLowerCase():X.sameSite;switch(K){case!0:G+="; SameSite=Strict";break;case"lax":G+="; SameSite=Lax";break;case"strict":G+="; SameSite=Strict";break;case"none":G+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return G},r$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},o$=function($){return encodeURIComponent($)},a$=function($){return t$.call($)==="[object Date]"||$ instanceof Date},e$=function($,J){try{return J($)}catch(W){return $}};/*!
|
|
3
3
|
* cookie
|
|
4
4
|
* Copyright(c) 2012-2014 Roman Shtylman
|
|
5
5
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
6
6
|
* MIT Licensed
|
|
7
|
-
*/var B1=s$,U1=n$;var t$=Object.prototype.toString,c0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var t1=V0(p0(),1);class r{$;J;W;constructor($,J,W={}){this.name=$;this.jar=J;this.initial=W}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var i1=($,J,W)=>{if(!$.cookie)$.cookie={};return new Proxy(J,{get(X,Z){if(Z in J)return new r(Z,$.cookie,Object.assign({},W??{},J[Z]));return new r(Z,$.cookie,Object.assign({},W))}})},l0=async($,J,{secret:W,sign:X,...Z}={})=>{if(!J)return i1($,{},Z);const Q=typeof W==="string";if(X&&X!==!0&&!Array.isArray(X))X=[X];const Y={},G=B1(J);for(let[B,_]of Object.entries(G)){let K=t1.default(_);if(X===!0||X?.includes(B)){if(!W)throw new Error("No secret is provided to cookie plugin");if(Q){const F=await _1(K,W);if(F===!1)throw new C0(B);K=F}else{let F=!0;for(let w=0;w<W.length;w++){const j=await _1(K,W[w]);if(j!==!1){F=!0,K=j;break}}if(!F)throw new C0(B)}}const z=K.charCodeAt(0);if(z===123||z===91)try{Y[B]={value:JSON.parse(K)};continue}catch{}if(M0(K)){Y[B]={value:parseInt(K)};continue}if(K==="true"){Y[B]={value:!0};continue}if(K==="false"){Y[B]={value:!1};continue}Y[B]={value:K}}return i1($,Y,Z)};var T0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let J in $)return!0;return!1},q0=($,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(T0)J.headers=J.headers.toJSON();else for(let[X,Z]of J.headers.entries())if(X in J.headers)J.headers[X]=Z}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($)},s1=($,J)=>{if(!$)return $;$.delete("Set-Cookie");for(let W=0;W<J.length;W++){const X=J[W].indexOf("=");$.append("Set-Cookie",`${J[W].slice(0,X)}=${J[W].slice(X+1)||""}`)}return $},n1=($)=>{if(!$||!m($))return;const J=[];for(let[W,X]of Object.entries($)){if(!W||!X)continue;const Z=X.value;if(Z===void 0||Z===null)continue;J.push(U1(W,typeof Z==="object"?JSON.stringify(Z):Z+"",X))}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=Z0[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"]=n1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=s1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return q0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,J);case void 0:if(!$)return new Response("",J);return Response.json($,J);case"Response":const X={...J.headers};if(T0)J.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(Z in J.headers)J.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);return $;case"Error":return t($,J);case"Promise":return $.then((Z)=>h(Z,J));case"Function":return h($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const Z=Object.assign({},J.headers);if(T0)J.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in J.headers)J.headers[Q]=Y;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>h(Z,J));if($ instanceof Error)return t($,J);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===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 q0($,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 t($,J);case"Promise":return $.then((X)=>{const Z=o(X);if(Z!==void 0)return Z;return new Response("")});case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((X)=>h(X,J));if($ instanceof Error)return t($,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($)}},u=($,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=Z0[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"]=n1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=s1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return q0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,J);case void 0:if(!$)return;return Response.json($,J);case"Response":const X=Object.assign({},J.headers);if(T0)J.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(!(Z in J.headers))J.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);if($.status!==J.status)J.status=$.status;return $;case"Promise":return $.then((Z)=>{const Q=u(Z,J);if(Q!==void 0)return Q});case"Error":return t($,J);case"Function":return u($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const Z={...J.headers};if(T0)J.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in J.headers)J.headers[Q]=Y;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>u(Z,J));if($ instanceof Error)return t($,J);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===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 q0($,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((X)=>{const Z=u(X,J);if(Z!==void 0)return Z});case"Error":return t($,J);case"Function":return o($());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((X)=>u(X,J));if($ instanceof Error)return t($,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($)}},o=($,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return h($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return q0($);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 t($);case"Promise":return $.then(o);case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(o);if($ instanceof Error)return t($);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($)}},t=($,J)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:J?.status!==200?J?.status??500:500,headers:J?.headers});var K8=function($){let J=$;while(J.endsWith("="))J=J.slice(0,-1);return J},D1=($,J)=>{const W=new URL($);return W.pathname=J,W.toString()},X8=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),F1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,J,{skipKeys:W}={})=>{if(F1($)&&F1(J))for(let[X,Z]of Object.entries(J)){if(W?.includes(X))continue;if(!F1(Z)||!(X in $)||X8(Z)){$[X]=Z;continue}$[X]=p($[X],Z)}return $},Z8=($,J)=>{const{properties:W,...X}=$??{},{properties:Z,...Q}=J??{};return p(X,Q)},H=($=[],J=[])=>{if(!$)return[];if(!J)return $;const W=[],X=[];if(!Array.isArray($))$=[$];if(!Array.isArray(J))J=[J];for(let Z of $)if(W.push(Z),Z.checksum)X.push(Z.checksum);for(let Z of J)if(!X.includes(Z.checksum))W.push(Z);return W},Q8=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],Y8=Q8.reduce(($,J)=>($[J]=!0,$),{}),G8=($,J)=>{const W=(X)=>typeof X==="object"&&Object.keys(X).every(M0);if(W($)&&W(J))return{...$,...J};return J??$},f=($,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:G8($?.response,J?.response),type:$?.type||J?.type,detail:p(J?.detail??{},$?.detail??{}),parse:H($?.parse,J?.parse),transform:H($?.transform,J?.transform),beforeHandle:H($?.beforeHandle,J?.beforeHandle),afterHandle:H($?.afterHandle,J?.afterHandle),onResponse:H($?.onResponse,J?.onResponse),mapResponse:H($?.mapResponse,J?.mapResponse),trace:H($?.trace,J?.trace),error:H($?.error,J?.error)}},k=($,{models:J={},dynamic:W=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const Q=typeof $==="string"?J[$]:$;if(Q.type==="object"&&"additionalProperties"in Q===!1)Q.additionalProperties=Z;const Y=(B)=>w0.Clean(Q,B);if(W){const B={schema:Q,references:"",checkFunc:()=>{},code:"",Check:(_)=>w0.Check(Q,_),Errors:(_)=>w0.Errors(Q,_),Code:()=>""};if(X&&Q.additionalProperties===!0)B.Clean=Y;if(Q.config){if(B.config=Q.config,B?.schema?.config)delete B.schema.config}return B}const G=o1.Compile(Q,Object.values(J));if(G.Clean=Y,Q.config){if(G.config=Q.config,G?.schema?.config)delete G.schema.config}return G},i0=($,{models:J={},dynamic:W=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const Q=typeof $==="string"?J[$]:$,Y=(B,_)=>{const K=(F)=>w0.Clean(B,F);if(W)return{schema:B,references:"",checkFunc:()=>{},code:"",Check:(F)=>w0.Check(B,F),Errors:(F)=>w0.Errors(B,F),Code:()=>""};const z=o1.Compile(B,_);if(X&&B.additionalProperties===!0)z.Clean=K;return z};if(z1 in Q){if("additionalProperties"in Q===!1)Q.additionalProperties=Z;return{200:Y(Q,Object.values(J))}}const G={};return Object.keys(Q).forEach((B)=>{const _=Q[+B];if(typeof _==="string"){if(_ in J){const K=J[_];K.type==="object"&&"additionalProperties"in K,G[+B]=z1 in K?Y(K,Object.values(J)):K}return}if(_.type==="object"&&"additionalProperties"in _===!1)_.additionalProperties=Z;G[+B]=z1 in _?Y(_,Object.values(J)):_}),G},B8=typeof Bun!=="undefined",U8=B8&&typeof Bun.hash==="function",L0=($)=>{if(U8)return Bun.hash($);let J=9;for(let W=0;W<$.length;)J=Math.imul(J^$.charCodeAt(W++),387420489);return J=J^J>>>9},t0=({validator:$,defaultConfig:J={},config:W,dynamic:X,models:Z})=>{let Q=k($,{dynamic:X,models:Z,additionalProperties:!0});if(m(J))if(Q)Q.config=Z8(Q.config,W);else Q=k(C.Cookie({}),{dynamic:X,models:Z,additionalProperties:!0}),Q.config=J;return Q},s0=($,J,W)=>{const X=(Z)=>{if(!Z)return;if(!Array.isArray(Z)){const Y=Z;if(W&&!Y.checksum)Y.checksum=W;if(Y.scope==="scoped")Y.scope="local";return Y}const Q=[...Z];for(let Y of Q){if(W&&!Y.checksum)Y.checksum=W;if(Y.scope==="scoped")Y.scope="local"}return Q};return{start:H($.start,X(J?.start)),request:H($.request,X(J?.request)),parse:H($.parse,X(J?.parse)),transform:H($.transform,X(J?.transform)),beforeHandle:H($.beforeHandle,X(J?.beforeHandle)),afterHandle:H($.afterHandle,X(J?.afterHandle)),mapResponse:H($.mapResponse,X(J?.mapResponse)),onResponse:H($.onResponse,X(J?.onResponse)),trace:$.trace,error:H($.error,X(J?.error)),stop:H($.stop,X(J?.stop))}},a1=($,J,{skipIfHasType:W=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(W)$.scope??=J;else $.scope=J;return $}for(let X of $)if(W)X.scope??=J;else X.scope=J;return $},Q0=($)=>{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},M1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:Q0($?.parse),transform:Q0($?.transform),beforeHandle:Q0($?.beforeHandle),afterHandle:Q0($?.afterHandle),onResponse:Q0($?.onResponse),error:Q0($?.error),mapResponse:Q0($?.mapResponse)}},Z0={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},n0=Object.fromEntries(Object.entries(Z0).map(([$,J])=>[J,$])),r1=new TextEncoder,A0=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",r1.encode(J),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),X=await crypto.subtle.sign("HMAC",W,r1.encode($));return $+"."+K8(Buffer.from(X).toString("base64"))},_1=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 A0(W,J)===$?W:!1},w1=($,J,W=J)=>{if(!$||typeof $!=="object"||!J)return;for(let[X,Z]of Object.entries(J)){if(X in Y8||!(X in $))continue;const Q=$[X];if(typeof Q==="function")Q(Z);else if(typeof Q==="object")w1(Q,Z,W)}},e1=({globalHook:$,localHook:J})=>(W)=>(X,Z)=>{if(typeof X==="function")X={fn:X};if("fn"in X||Array.isArray(X)){if(!J[W])J[W]=[];if(typeof J[W]==="function")J[W]=[J[W]];if(Array.isArray(X))J[W]=J[W].concat(X);else J[W].push(X);return}const{insert:Q="after",stack:Y="local"}=X;if(typeof Z==="function")Z={fn:Z};if(Y==="global")if(!Array.isArray(Z))if(Q==="before")$[W].unshift(Z);else $[W].push(Z);else if(Q==="before")$[W]=Z.concat($[W]);else $[W]=$[W].concat(Z);else{if(!J[W])J[W]=[];if(typeof J[W]==="function")J[W]=[J[W]];if(!Array.isArray(Z))if(Q==="before")J[W].unshift(Z);else J[W].push(Z);else if(Q==="before")J[W]=Z.concat(J[W]);else J[W]=J[W].concat(Z)}},M0=($)=>{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 A1{$;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},$$=($)=>{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)}},J$=($)=>{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}});var W$=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,Y0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),R0=(W$?.NODE_ENV??W$?.ENV)==="production",j1=($,J)=>({[d]:Z0[$]??$,response:J??($ in n0?n0[$]:$),_type:void 0});class a0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class G0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class e0 extends Error{J;code="PARSE";status=400;constructor($,J){super($??"PARSE");this.body=J}}class C0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,J){super(J??`"${$}" has invalid cookie signature`);this.key=$}}class L extends Error{$;J;W;code="VALIDATION";status=422;constructor($,J,W){if(typeof W==="object"&&d in W)W=W.response;const X=R0?void 0:("Errors"in J)?J.Errors(W).First():o0.Errors(J,W).First(),Z=X?.schema.error?typeof X.schema.error==="function"?X.schema.error($,J,W):X.schema.error:void 0,Q=X?.path||"root";let Y="";if(Z)Y=typeof Z==="object"?JSON.stringify(Z):Z+"";else if(R0)Y=JSON.stringify({type:"validation",on:$,message:X?.message,found:W});else{const G=J?.schema??J,B="Errors"in J?[...J.Errors(W)]:[...o0.Errors(J,W)];let _;try{_=o0.Create(G)}catch(K){_={type:"Could not create expected value",message:K?.message,error:K}}Y=JSON.stringify({type:"validation",on:$,property:Q,message:X?.message,expected:_,found:W,errors:B},null,2)}super(Y);this.type=$;this.validator=J;this.value=W;Object.setPrototypeOf(this,L.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const J="schema"in $?$.schema:$;try{return o0.Create(J)}catch{return J}}get model(){return L.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var N1={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 L("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 L("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 w$=V0(P1(),1),A$=V0(p0(),1);import{Value as b0} from"@sinclair/typebox/value";var M8=(new Headers()).toJSON,j$={value:0},N$=({hasTrace:$,hasTraceSet:J=!1,addFn:W,condition:X={}})=>{if($)return W("\nconst reporter = getReporter()\n"),(Z,{name:Q,attribute:Y="",unit:G=0}={})=>{const B=Z.indexOf("."),_=B===-1;if(Z!=="request"&&Z!=="response"&&!X[_?Z:Z.slice(0,B)])return()=>{if(J&&Z==="afterHandle")W("\nawait traceDone\n")};if(_)Q||=Z;else Q||="anonymous";return W("\n"+`reporter.emit('event', {
|
|
7
|
+
*/var B1=s$,U1=n$;var t$=Object.prototype.toString,c0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var t1=V0(p0(),1);class r{$;J;W;constructor($,J,W={}){this.name=$;this.jar=J;this.initial=W}get cookie(){if(!(this.name in this.jar))return this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name].value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var i1=($,J,W)=>{if(!$.cookie)$.cookie={};return new Proxy(J,{get(X,Z){if(Z in J)return new r(Z,$.cookie,Object.assign({},W??{},J[Z]));return new r(Z,$.cookie,Object.assign({},W))}})},l0=async($,J,{secrets:W,sign:X,...Z}={})=>{if(!J)return i1($,{},Z);const Q=typeof W==="string";if(X&&X!==!0&&!Array.isArray(X))X=[X];const G={},Y=B1(J);for(let[B,_]of Object.entries(Y)){let K=t1.default(_);if(X===!0||X?.includes(B)){if(!W)throw new Error("No secret is provided to cookie plugin");if(Q){const F=await _1(K,W);if(F===!1)throw new C0(B);K=F}else{let F=!0;for(let M=0;M<W.length;M++){const w=await _1(K,W[M]);if(w!==!1){F=!0,K=w;break}}if(!F)throw new C0(B)}}const z=K.charCodeAt(0);if(z===123||z===91)try{G[B]={value:JSON.parse(K)};continue}catch{}if(A0(K)){G[B]={value:parseInt(K)};continue}if(K==="true"){G[B]={value:!0};continue}if(K==="false"){G[B]={value:!1};continue}G[B]={value:K}}return i1($,G,Z)};var T0="toJSON"in new Headers,m=($)=>{if(!$)return!1;for(let J in $)return!0;return!1},q0=($,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(T0)J.headers=J.headers.toJSON();else for(let[X,Z]of J.headers.entries())if(X in J.headers)J.headers[X]=Z}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($)},s1=($,J)=>{if(!$)return $;$.delete("Set-Cookie");for(let W=0;W<J.length;W++){const X=J[W].indexOf("=");$.append("Set-Cookie",`${J[W].slice(0,X)}=${J[W].slice(X+1)||""}`)}return $},n1=($)=>{if(!$||!m($))return;const J=[];for(let[W,X]of Object.entries($)){if(!W||!X)continue;const Z=X.value;if(Z===void 0||Z===null)continue;J.push(U1(W,typeof Z==="object"?JSON.stringify(Z):Z+"",X))}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=Z0[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"]=n1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=s1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return q0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,J);case void 0:if(!$)return new Response("",J);return Response.json($,J);case"Response":const X={...J.headers};if(T0)J.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(Z in J.headers)J.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);return $;case"Error":return t($,J);case"Promise":return $.then((Z)=>h(Z,J));case"Function":return h($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const Z=Object.assign({},J.headers);if(T0)J.headers=$.headers.toJSON();else for(let[Q,G]of $.headers.entries())if(Q in J.headers)J.headers[Q]=G;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>h(Z,J));if($ instanceof Error)return t($,J);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===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 q0($,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 t($,J);case"Promise":return $.then((X)=>{const Z=o(X);if(Z!==void 0)return Z;return new Response("")});case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((X)=>h(X,J));if($ instanceof Error)return t($,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($)}},u=($,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=Z0[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"]=n1(J.cookie);if(J.headers["Set-Cookie"]&&Array.isArray(J.headers["Set-Cookie"]))J.headers=s1(new Headers(J.headers),J.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,J);case"Blob":return q0($,J);case"Object":case"Array":return Response.json($,J);case"ReadableStream":if(!J.headers["content-type"]?.startsWith("text/event-stream"))J.headers["content-type"]="text/event-stream; charset=utf-8";return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,J);case void 0:if(!$)return;return Response.json($,J);case"Response":const X=Object.assign({},J.headers);if(T0)J.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(!(Z in J.headers))J.headers[Z]=Q;for(let Z in X)$.headers.append(Z,X[Z]);if($.status!==J.status)J.status=$.status;return $;case"Promise":return $.then((Z)=>{const Q=u(Z,J);if(Q!==void 0)return Q});case"Error":return t($,J);case"Function":return u($(),J);case"Number":case"Boolean":return new Response($.toString(),J);case"Cookie":if($ instanceof r)return new Response($.value,J);return new Response($?.toString(),J);default:if($ instanceof Response){const Z={...J.headers};if(T0)J.headers=$.headers.toJSON();else for(let[Q,G]of $.headers.entries())if(Q in J.headers)J.headers[Q]=G;for(let Q in Z)$.headers.append(Q,Z[Q]);return $}if($ instanceof Promise)return $.then((Z)=>u(Z,J));if($ instanceof Error)return t($,J);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===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 q0($,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((X)=>{const Z=u(X,J);if(Z!==void 0)return Z});case"Error":return t($,J);case"Function":return o($());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((X)=>u(X,J));if($ instanceof Error)return t($,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($)}},o=($,J)=>{if($?.$passthrough)$=$?.[$.$passthrough];if($?.[d])return h($.response,{status:$[d],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return q0($);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 t($);case"Promise":return $.then(o);case"Function":return o($());case"Number":case"Boolean":return new Response($.toString());default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then(o);if($ instanceof Error)return t($);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($)}},t=($,J)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:J?.status!==200?J?.status??500:500,headers:J?.headers});var K8=function($){let J=$;while(J.endsWith("="))J=J.slice(0,-1);return J},D1=($,J)=>{const W=new URL($);return W.pathname=J,W.toString()},X8=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||m(Object.getPrototypeOf($)),F1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,J,{skipKeys:W}={})=>{if(F1($)&&F1(J))for(let[X,Z]of Object.entries(J)){if(W?.includes(X))continue;if(!F1(Z)||!(X in $)||X8(Z)){$[X]=Z;continue}$[X]=p($[X],Z)}return $},Z8=($,J)=>{const{properties:W,...X}=$??{},{properties:Z,...Q}=J??{};return p(X,Q)},H=($=[],J=[])=>{if(!$)return[];if(!J)return $;const W=[],X=[];if(!Array.isArray($))$=[$];if(!Array.isArray(J))J=[J];for(let Z of $)if(W.push(Z),Z.checksum)X.push(Z.checksum);for(let Z of J)if(!X.includes(Z.checksum))W.push(Z);return W},Q8=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],G8=Q8.reduce(($,J)=>($[J]=!0,$),{}),Y8=($,J)=>{const W=(X)=>typeof X==="object"&&Object.keys(X).every(A0);if(W($)&&W(J))return{...$,...J};return J??$},f=($,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:Y8($?.response,J?.response),type:$?.type||J?.type,detail:p(J?.detail??{},$?.detail??{}),parse:H($?.parse,J?.parse),transform:H($?.transform,J?.transform),beforeHandle:H($?.beforeHandle,J?.beforeHandle),afterHandle:H($?.afterHandle,J?.afterHandle),onResponse:H($?.onResponse,J?.onResponse),mapResponse:H($?.mapResponse,J?.mapResponse),trace:H($?.trace,J?.trace),error:H($?.error,J?.error)}},k=($,{models:J={},dynamic:W=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const Q=typeof $==="string"?J[$]:$;if(Q.type==="object"&&"additionalProperties"in Q===!1)Q.additionalProperties=Z;const G=(B)=>M0.Clean(Q,B);if(W){const B={schema:Q,references:"",checkFunc:()=>{},code:"",Check:(_)=>M0.Check(Q,_),Errors:(_)=>M0.Errors(Q,_),Code:()=>""};if(X&&Q.additionalProperties===!0)B.Clean=G;if(Q.config){if(B.config=Q.config,B?.schema?.config)delete B.schema.config}return B}const Y=o1.Compile(Q,Object.values(J));if(Y.Clean=G,Q.config){if(Y.config=Q.config,Y?.schema?.config)delete Y.schema.config}return Y},i0=($,{models:J={},dynamic:W=!1,normalize:X=!1,additionalProperties:Z=X})=>{if(!$)return;if(typeof $==="string"&&!($ in J))return;const Q=typeof $==="string"?J[$]:$,G=(B,_)=>{const K=(F)=>M0.Clean(B,F);if(W)return{schema:B,references:"",checkFunc:()=>{},code:"",Check:(F)=>M0.Check(B,F),Errors:(F)=>M0.Errors(B,F),Code:()=>""};const z=o1.Compile(B,_);if(X&&B.additionalProperties===!0)z.Clean=K;return z};if(z1 in Q){if("additionalProperties"in Q===!1)Q.additionalProperties=Z;return{200:G(Q,Object.values(J))}}const Y={};return Object.keys(Q).forEach((B)=>{const _=Q[+B];if(typeof _==="string"){if(_ in J){const K=J[_];K.type==="object"&&"additionalProperties"in K,Y[+B]=z1 in K?G(K,Object.values(J)):K}return}if(_.type==="object"&&"additionalProperties"in _===!1)_.additionalProperties=Z;Y[+B]=z1 in _?G(_,Object.values(J)):_}),Y},B8=typeof Bun!=="undefined",U8=B8&&typeof Bun.hash==="function",R0=($)=>{if(U8)return Bun.hash($);let J=9;for(let W=0;W<$.length;)J=Math.imul(J^$.charCodeAt(W++),387420489);return J=J^J>>>9},t0=({validator:$,defaultConfig:J={},config:W,dynamic:X,models:Z})=>{let Q=k($,{dynamic:X,models:Z,additionalProperties:!0});if(m(J))if(Q)Q.config=Z8(Q.config,W);else Q=k(C.Cookie({}),{dynamic:X,models:Z,additionalProperties:!0}),Q.config=J;return Q},s0=($,J,W)=>{const X=(Z)=>{if(!Z)return;if(!Array.isArray(Z)){const G=Z;if(W&&!G.checksum)G.checksum=W;if(G.scope==="scoped")G.scope="local";return G}const Q=[...Z];for(let G of Q){if(W&&!G.checksum)G.checksum=W;if(G.scope==="scoped")G.scope="local"}return Q};return{start:H($.start,X(J?.start)),request:H($.request,X(J?.request)),parse:H($.parse,X(J?.parse)),transform:H($.transform,X(J?.transform)),beforeHandle:H($.beforeHandle,X(J?.beforeHandle)),afterHandle:H($.afterHandle,X(J?.afterHandle)),mapResponse:H($.mapResponse,X(J?.mapResponse)),onResponse:H($.onResponse,X(J?.onResponse)),trace:$.trace,error:H($.error,X(J?.error)),stop:H($.stop,X(J?.stop))}},a1=($,J,{skipIfHasType:W=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(W)$.scope??=J;else $.scope=J;return $}for(let X of $)if(W)X.scope??=J;else X.scope=J;return $},Q0=($)=>{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},A1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:Q0($?.parse),transform:Q0($?.transform),beforeHandle:Q0($?.beforeHandle),afterHandle:Q0($?.afterHandle),onResponse:Q0($?.onResponse),error:Q0($?.error),mapResponse:Q0($?.mapResponse)}},Z0={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},n0=Object.fromEntries(Object.entries(Z0).map(([$,J])=>[J,$])),r1=new TextEncoder,j0=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",r1.encode(J),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),X=await crypto.subtle.sign("HMAC",W,r1.encode($));return $+"."+K8(Buffer.from(X).toString("base64"))},_1=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 j0(W,J)===$?W:!1},M1=($,J,W=J)=>{if(!$||typeof $!=="object"||!J)return;for(let[X,Z]of Object.entries(J)){if(X in G8||!(X in $))continue;const Q=$[X];if(typeof Q==="function")Q(Z);else if(typeof Q==="object")M1(Q,Z,W)}},e1=({globalHook:$,localHook:J})=>(W)=>(X,Z)=>{if(typeof X==="function")X={fn:X};if("fn"in X||Array.isArray(X)){if(!J[W])J[W]=[];if(typeof J[W]==="function")J[W]=[J[W]];if(Array.isArray(X))J[W]=J[W].concat(X);else J[W].push(X);return}const{insert:Q="after",stack:G="local"}=X;if(typeof Z==="function")Z={fn:Z};if(G==="global")if(!Array.isArray(Z))if(Q==="before")$[W].unshift(Z);else $[W].push(Z);else if(Q==="before")$[W]=Z.concat($[W]);else $[W]=$[W].concat(Z);else{if(!J[W])J[W]=[];if(typeof J[W]==="function")J[W]=[J[W]];if(!Array.isArray(Z))if(Q==="before")J[W].unshift(Z);else J[W].push(Z);else if(Q==="before")J[W]=Z.concat(J[W]);else J[W]=J[W].concat(Z)}},A0=($)=>{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 j1{$;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},$$=($)=>{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)}},J$=($)=>{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}});var W$=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,G0=Symbol("ElysiaErrorCode"),d=Symbol("ElysiaResponse"),L0=(W$?.NODE_ENV??W$?.ENV)==="production",w1=($,J)=>({[d]:Z0[$]??$,response:J??($ in n0?n0[$]:$),_type:void 0});class a0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class Y0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class e0 extends Error{J;code="PARSE";status=400;constructor($,J){super($??"PARSE");this.body=J}}class C0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,J){super(J??`"${$}" has invalid cookie signature`);this.key=$}}class R extends Error{$;J;W;code="VALIDATION";status=422;constructor($,J,W){if(typeof W==="object"&&d in W)W=W.response;const X=L0?void 0:("Errors"in J)?J.Errors(W).First():o0.Errors(J,W).First(),Z=X?.schema.error?typeof X.schema.error==="function"?X.schema.error($,J,W):X.schema.error:void 0,Q=X?.path||"root";let G="";if(Z)G=typeof Z==="object"?JSON.stringify(Z):Z+"";else if(L0)G=JSON.stringify({type:"validation",on:$,message:X?.message,found:W});else{const Y=J?.schema??J,B="Errors"in J?[...J.Errors(W)]:[...o0.Errors(J,W)];let _;try{_=o0.Create(Y)}catch(K){_={type:"Could not create expected value",message:K?.message,error:K}}G=JSON.stringify({type:"validation",on:$,property:Q,message:X?.message,expected:_,found:W,errors:B},null,2)}super(G);this.type=$;this.validator=J;this.value=W;Object.setPrototypeOf(this,R.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const J="schema"in $?$.schema:$;try{return o0.Create(J)}catch{return J}}get model(){return R.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var N1={open($){$.data.open?.($)},message($,J){$.data.message?.($,J)},drain($){$.data.drain?.($)},close($,J,W){$.data.close?.($,J,W)}};class w0{$;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 R("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 R("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 M$=V0(O1(),1),j$=V0(p0(),1);import{Value as b0} from"@sinclair/typebox/value";var A8=(new Headers()).toJSON,w$={value:0},N$=({hasTrace:$,hasTraceSet:J=!1,addFn:W,condition:X={}})=>{if($)return W("\nconst reporter = getReporter()\n"),(Z,{name:Q,attribute:G="",unit:Y=0}={})=>{const B=Z.indexOf("."),_=B===-1;if(Z!=="request"&&Z!=="response"&&!X[_?Z:Z.slice(0,B)])return()=>{if(J&&Z==="afterHandle")W("\nawait traceDone\n")};if(_)Q||=Z;else Q||="anonymous";return W("\n"+`reporter.emit('event', {
|
|
8
8
|
id,
|
|
9
9
|
event: '${Z}',
|
|
10
10
|
type: 'begin',
|
|
11
11
|
name: '${Q}',
|
|
12
12
|
time: performance.now(),
|
|
13
|
-
${_?`unit: ${
|
|
14
|
-
${
|
|
13
|
+
${_?`unit: ${Y},`:""}
|
|
14
|
+
${G}
|
|
15
15
|
})`.replace(/(\t| |\n)/g,"")+"\n"),()=>{if(W("\n"+`reporter.emit('event', {
|
|
16
16
|
id,
|
|
17
17
|
event: '${Z}',
|
|
18
18
|
type: 'end',
|
|
19
19
|
time: performance.now()
|
|
20
|
-
})`.replace(/(\t| |\n)/g,"")+"\n"),J&&Z==="afterHandle")W("\nawait traceDone\n")}};else return()=>()=>{}},H0=($)=>{const J=$.indexOf(")");if($.charCodeAt(J+2)===61&&$.charCodeAt(J+5)!==123)return!0;return $.includes("return")},
|
|
20
|
+
})`.replace(/(\t| |\n)/g,"")+"\n"),J&&Z==="afterHandle")W("\nawait traceDone\n")}};else return()=>()=>{}},H0=($)=>{const J=$.indexOf(")");if($.charCodeAt(J+2)===61&&$.charCodeAt(J+5)!==123)return!0;return $.includes("return")},M8=($,{injectResponse:J="",normalize:W=!1}={})=>({composeValidation:(X,Z=`c.${X}`)=>$?`c.set.status = 422; throw new ValidationError('${X}', ${X}, ${Z})`:`c.set.status = 422; return new ValidationError('${X}', ${X}, ${Z}).toResponse(c.set.headers)`,composeResponseValidation:(X="r")=>{const Z=$?`throw new ValidationError('response', response[c.set.status], ${X})`:`return new ValidationError('response', response[c.set.status], ${X}).toResponse(c.set.headers)`;let Q="\n"+J+"\n";if(Q+=`let er
|
|
21
|
+
|
|
22
|
+
if(${X} && typeof ${X} === "object" && ELYSIA_RESPONSE in ${X})
|
|
23
|
+
er = ${X}[ELYSIA_RESPONSE]\n`,W)Q+=`
|
|
21
24
|
if(!er && response[c.set.status]?.Clean)
|
|
22
25
|
${X} = response[c.set.status]?.Clean(${X})
|
|
23
26
|
else if(response[er]?.Clean)
|
|
24
27
|
${X}.response = response[er]?.Clean(${X}.response)`;return Q+=`
|
|
25
|
-
if(
|
|
28
|
+
if(er) {
|
|
26
29
|
if(!(${X} instanceof Response) && response[er]?.Check(${X}.response) === false) {
|
|
27
30
|
if(!(response instanceof Error)) {
|
|
28
31
|
c.set.status = ${X}[ELYSIA_RESPONSE]
|
|
@@ -33,24 +36,24 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
33
36
|
} else if(!(${X} instanceof Response) && response[c.set.status]?.Check(${X}) === false) {
|
|
34
37
|
if(!(response instanceof Error))
|
|
35
38
|
${Z}
|
|
36
|
-
}\n`,Q}}),N0=Symbol.for("TypeBox.Kind"),$1=($,J)=>{if(!J)return;if(N0 in J&&J[N0]===$)return!0;if(J.type==="object"){const W=J.properties;for(let X of Object.keys(W)){const Z=W[X];if(Z.type==="object"){if($1($,Z))return!0}else if(Z.anyOf){for(let Q=0;Q<Z.anyOf.length;Q++)if($1($,Z.anyOf[Q]))return!0}if(N0 in Z&&Z[N0]===$)return!0}return!1}return J.properties&&N0 in J.properties&&J.properties[N0]===$},B0=($,J)=>{if(!J)return;if(J.type==="object"){const W=J.properties;if(!W)return!1;for(let X of Object.keys(W)){const Z=W[X];if($ in Z)return!0;if(Z.type==="object"){if(B0($,Z))return!0}else if(Z.anyOf){for(let Q=0;Q<Z.anyOf.length;Q++)if(B0($,Z.anyOf[Q]))return!0}}return!1}return $ in J},I1=Symbol.for("TypeBox.Transform"),
|
|
39
|
+
}\n`,Q}}),N0=Symbol.for("TypeBox.Kind"),$1=($,J)=>{if(!J)return;if(N0 in J&&J[N0]===$)return!0;if(J.type==="object"){const W=J.properties;for(let X of Object.keys(W)){const Z=W[X];if(Z.type==="object"){if($1($,Z))return!0}else if(Z.anyOf){for(let Q=0;Q<Z.anyOf.length;Q++)if($1($,Z.anyOf[Q]))return!0}if(N0 in Z&&Z[N0]===$)return!0}return!1}return J.properties&&N0 in J.properties&&J.properties[N0]===$},B0=($,J)=>{if(!J)return;if(J.type==="object"){const W=J.properties;if(!W)return!1;for(let X of Object.keys(W)){const Z=W[X];if($ in Z)return!0;if(Z.type==="object"){if(B0($,Z))return!0}else if(Z.anyOf){for(let Q=0;Q<Z.anyOf.length;Q++)if(B0($,Z.anyOf[Q]))return!0}}return!1}return $ in J},I1=Symbol.for("TypeBox.Transform"),P0=($)=>{if(!$)return;if($.type==="object"&&$.properties){const J=$.properties;for(let W of Object.keys(J)){const X=J[W];if(X.type==="object"){if(P0(X))return!0}else if(X.anyOf){for(let Q=0;Q<X.anyOf.length;Q++)if(P0(X.anyOf[Q]))return!0}if(I1 in X)return!0}return!1}return I1 in $||$.properties&&I1 in $.properties},j8=($)=>{if(!$)return;const J=$?.schema;if(J&&"anyOf"in J){let W=!1;const X=J.anyOf[0].type;for(let Z of J.anyOf)if(Z.type!==X){W=!0;break}if(!W)return X}return $.schema?.type},w8=/(?:return|=>) \S+\(/g,x=($)=>{const J="fn"in $?$.fn:$;if(J.constructor.name==="AsyncFunction")return!0;const W=J.toString();if(W.includes("=> response.clone("))return!1;return!!W.match(w8)},J1=({app:$,path:J,method:W,localHook:X,hooks:Z,validator:Q,handler:G,allowMeta:Y=!1,appInference:{event:B,trace:_}})=>{const K=typeof G==="function";if(!K)G=h(G,{headers:$.setHeaders??{}});const z=$.config.forceErrorEncapsulation&&(K||Z.afterHandle.length>0||Z.beforeHandle.length>0||Z.transform.length>0)||Z.error.length>0||$.event.error.length>0||typeof Bun==="undefined"||Z.onResponse.length>0||Z.onResponse.length>0||!!Z.trace.length,F=K?"handler(c)":"handler",M=Z.onResponse.length?`\n;(async () => {${Z.onResponse.map((O,D)=>`await res${D}(c)`).join(";")}})();\n`:"",w=_,I=Z.trace.length>0;let U="";const A=d0(Object.assign(X,{handler:G}),B),P=A.query||!!Q.query,N=W!=="$INTERNALWS"&&W!=="GET"&&W!=="HEAD"&&Z.type!=="none"&&(A.body||!!Q.body),L=$.setHeaders,q=L&&!!Object.keys(L).length,e=A.headers||Q.headers,v=A.cookie||!!Q.cookie,n=v?t0({validator:Q.cookie,defaultConfig:$.config.cookie,dynamic:!!$.config.aot,config:Q.cookie?.config??{},models:$.definitions.type}):void 0,S=n?.config;let V="";if(S?.sign){if(!S.secrets)throw new Error(`t.Cookie required secret which is not set in (${W}) ${J}.`);const O=!S.secrets?void 0:typeof S.secrets==="string"?S.secrets:S.secrets[0];if(V+=`const _setCookie = c.set.cookie
|
|
37
40
|
if(_setCookie) {`,S.sign===!0)V+=`for(const [key, cookie] of Object.entries(_setCookie)) {
|
|
38
|
-
c.set.cookie[key].value = await signCookie(cookie.value, '${
|
|
39
|
-
}`;else for(let D of S.sign)V+=`if(_setCookie['${D}']?.value) { c.set.cookie['${D}'].value = await signCookie(_setCookie['${D}'].value, '${
|
|
41
|
+
c.set.cookie[key].value = await signCookie(cookie.value, '${O}')
|
|
42
|
+
}`;else for(let D of S.sign)V+=`if(_setCookie['${D}']?.value) { c.set.cookie['${D}'].value = await signCookie(_setCookie['${D}'].value, '${O}') }\n`;V+="}\n"}const $0=$.config.normalize,{composeValidation:K0,composeResponseValidation:y0}=M8(z,{normalize:$0});if(e)U+=A8?"c.headers = c.request.headers.toJSON()\n":`c.headers = {}
|
|
40
43
|
for (const [key, value] of c.request.headers.entries())
|
|
41
44
|
c.headers[key] = value
|
|
42
|
-
`;if(v){const
|
|
43
|
-
|
|
44
|
-
sign: ${S.sign===!0?!0:S.sign!==void 0?"["+S.sign.reduce((
|
|
45
|
-
${
|
|
46
|
-
${
|
|
47
|
-
${
|
|
48
|
-
${
|
|
49
|
-
${
|
|
50
|
-
${
|
|
51
|
-
${
|
|
52
|
-
${
|
|
53
|
-
}`:"undefined";if(e)U+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${D})\n`;else U+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${D})\n`}if(
|
|
45
|
+
`;if(v){const O=(j,T)=>{const b=S?.[j]??T;if(!b)return typeof T==="string"?`${j}: "${T}",`:`${j}: ${T},`;if(typeof b==="string")return`${j}: '${b}',`;if(b instanceof Date)return`${j}: new Date(${b.getTime()}),`;return`${j}: ${b},`},D=S?`{
|
|
46
|
+
secrets: ${S.secrets!==void 0?typeof S.secrets==="string"?`'${S.secrets}'`:"["+S.secrets.reduce((j,T)=>j+`'${T}',`,"")+"]":"undefined"},
|
|
47
|
+
sign: ${S.sign===!0?!0:S.sign!==void 0?"["+S.sign.reduce((j,T)=>j+`'${T}',`,"")+"]":"undefined"},
|
|
48
|
+
${O("domain")}
|
|
49
|
+
${O("expires")}
|
|
50
|
+
${O("httpOnly")}
|
|
51
|
+
${O("maxAge")}
|
|
52
|
+
${O("path","/")}
|
|
53
|
+
${O("priority")}
|
|
54
|
+
${O("sameSite")}
|
|
55
|
+
${O("secure")}
|
|
56
|
+
}`:"undefined";if(e)U+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${D})\n`;else U+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${D})\n`}if(P){let O=[];if(Q.query&&Q.query.schema.type==="object")O=Object.keys(Q.query.schema.properties);else for(let D of A.queries)if(O.indexOf(D)===-1)O.push(D);if($.config.forceDynamicQuery===!0||A.unknownQueries===!0||!O.length)U+=`if(c.qi !== -1) {
|
|
54
57
|
c.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\+/g, ' '))
|
|
55
58
|
|
|
56
59
|
for(const key of Object.keys(c.query))
|
|
@@ -58,25 +61,25 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
58
61
|
} else c.query = {}`;else U+=`if(c.qi !== -1) {
|
|
59
62
|
let url = c.request.url.slice(c.qi).replace(/\\+/g, ' ')
|
|
60
63
|
|
|
61
|
-
${
|
|
62
|
-
${
|
|
64
|
+
${O.map((D,j)=>`
|
|
65
|
+
${j===0?"let":""} memory = url.indexOf('&${D}=')
|
|
63
66
|
if(memory === -1) memory = url.indexOf('?${D}=')
|
|
64
|
-
let a${
|
|
67
|
+
let a${j}
|
|
65
68
|
|
|
66
69
|
if(memory !== -1) {
|
|
67
70
|
const start = memory + ${D.length+2}
|
|
68
71
|
memory = url.indexOf('&', start)
|
|
69
72
|
|
|
70
|
-
if(memory === -1) a${
|
|
71
|
-
else a${
|
|
73
|
+
if(memory === -1) a${j} = decodeURIComponent(url.slice(start))
|
|
74
|
+
else a${j} = decodeURIComponent(url.slice(start, memory))
|
|
72
75
|
}`).join("\n")}
|
|
73
76
|
|
|
74
77
|
c.query = {
|
|
75
|
-
${
|
|
78
|
+
${O.map((D,j)=>`'${D}': a${j}`).join(", ")}
|
|
76
79
|
}
|
|
77
80
|
} else {
|
|
78
81
|
c.query = {}
|
|
79
|
-
}`}const v0=_.set,k0=
|
|
82
|
+
}`}const v0=_.set,k0=A.cookie||A.set||v0||e||K&&q;if(I)U+="\nconst id = c.$$requestId\n";const E=N$({hasTrace:I,hasTraceSet:v0,condition:w,addFn:(O)=>{U+=O}});if(U+=z?"\n try {\n":"",v0){U+="\nconst traceDone = Promise.all([";for(let O=0;O<Z.trace.length;O++)U+=`new Promise(r => { reporter.once(\`res\${id}.${O}\`, r) }),`;U+="])\n"}const _0=typeof G==="function"&&x(G),Z1=v||N||v0||_0||!!Z.mapResponse.length||Z.parse.length>0||Z.afterHandle.some(x)||Z.beforeHandle.some(x)||Z.transform.some(x),E$=E("parse",{unit:Z.parse.length});if(N){const O=j8(Q?.body);if(Z.type&&!Array.isArray(Z.type)){if(Z.type)switch(Z.type){case"json":case"application/json":if(z)U+=`const tempBody = await c.request.text()
|
|
80
83
|
|
|
81
84
|
try {
|
|
82
85
|
c.body = JSON.parse(tempBody)
|
|
@@ -93,7 +96,7 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
93
96
|
if (value.length === 1)
|
|
94
97
|
c.body[key] = value[0]
|
|
95
98
|
else c.body[key] = value
|
|
96
|
-
}\n`;break}if(Z.parse.length)U+="}}"}else{const
|
|
99
|
+
}\n`;break}if(Z.parse.length)U+="}}"}else{const j=(()=>{if(Z.parse.length&&O&&!Array.isArray(Z.type)){const T=Q?.body?.schema;if(typeof T==="object"&&($1("File",T)||$1("Files",T)))return`c.body = {}
|
|
97
100
|
|
|
98
101
|
const form = await c.request.formData()
|
|
99
102
|
for (const key of form.keys()) {
|
|
@@ -104,7 +107,7 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
104
107
|
if (value.length === 1)
|
|
105
108
|
c.body[key] = value[0]
|
|
106
109
|
else c.body[key] = value
|
|
107
|
-
}`}})();if(
|
|
110
|
+
}`}})();if(j)U+=j;else{if(U+="\n",U+=e?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')",U+=`
|
|
108
111
|
if (contentType) {
|
|
109
112
|
const index = contentType.indexOf(';')
|
|
110
113
|
if (index !== -1) contentType = contentType.substring(0, index)\n`,Z.parse.length){U+="let used = false\n";const T=E("parse",{unit:Z.parse.length});for(let b=0;b<Z.parse.length;b++){const z0=E("parse.unit",{name:Z.parse[b].fn.name}),W0=`bo${b}`;if(b!==0)U+="if(!used) {\n";if(U+=`let ${W0} = parse[${b}](c, contentType)\n`,U+=`if(${W0} instanceof Promise) ${W0} = await ${W0}\n`,U+=`if(${W0} !== undefined) { c.body = ${W0}; used = true }\n`,z0(),b!==0)U+="}"}T()}if(Z.parse.length)U+="if (!used)";U+=`
|
|
@@ -148,16 +151,16 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
break
|
|
151
|
-
}\n`,U+="}\n"}}U+="\n"}if(E$(),Z?.transform){const
|
|
154
|
+
}\n`,U+="}\n"}}U+="\n"}if(E$(),Z?.transform){const O=E("transform",{unit:Z.transform.length});if(Z.transform.length)U+="\nlet transformed\n";for(let D=0;D<Z.transform.length;D++){const j=Z.transform[D],T=E("transform.unit",{name:j.fn.name});U+=x(j)?`transformed = await transform[${D}](c)\n`:`transformed = transform[${D}](c)\n`,U+=`if(transformed?.[ELYSIA_RESPONSE])
|
|
152
155
|
throw transformed
|
|
153
156
|
else
|
|
154
|
-
Object.assign(c, transformed)\n`,T()}
|
|
157
|
+
Object.assign(c, transformed)\n`,T()}O()}if(Q){if(U+="\n",Q.headers){if(B0("default",Q.headers.params))for(let[O,D]of Object.entries(b0.Default(Q.headers.schema,{}))){const j=typeof D==="object"?JSON.stringify(D):`'${D}'`;if(j)U+=`c.headers['${O}'] ??= ${j}\n`}if(U+=`if(headers.Check(c.headers) === false) {
|
|
155
158
|
${K0("headers")}
|
|
156
|
-
}`,
|
|
159
|
+
}`,P0(Q.headers.schema))U+="\nc.headers = headers.Decode(c.headers)\n"}if(Q.params){if(B0("default",Q.params.schema))for(let[O,D]of Object.entries(b0.Default(Q.params.schema,{}))){const j=typeof D==="object"?JSON.stringify(D):`'${D}'`;if(j)U+=`c.params['${O}'] ??= ${j}\n`}if(U+=`if(params.Check(c.params) === false) {
|
|
157
160
|
${K0("params")}
|
|
158
|
-
}`,
|
|
161
|
+
}`,P0(Q.params.schema))U+="\nc.params = params.Decode(c.params)\n"}if(Q.query){if($0)U+="c.query = query.Clean(c.query);\n";if(B0("default",Q.query.schema))for(let[O,D]of Object.entries(b0.Default(Q.query.schema,{}))){const j=typeof D==="object"?JSON.stringify(D):`'${D}'`;if(j)U+=`c.query['${O}'] ??= ${j}\n`}if(U+=`if(query.Check(c.query) === false) {
|
|
159
162
|
${K0("query")}
|
|
160
|
-
}`,
|
|
163
|
+
}`,P0(Q.query.schema))U+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(Q.body){if($0)U+="c.body = body.Clean(c.body);\n";if(B0("default",Q.body.schema))U+=`if(body.Check(c.body) === false) {
|
|
161
164
|
c.body = Object.assign(${JSON.stringify(b0.Default(Q.body.schema,null)??{})}, c.body)
|
|
162
165
|
|
|
163
166
|
if(body.Check(c.query) === false) {
|
|
@@ -165,24 +168,24 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
165
168
|
}
|
|
166
169
|
}`;else U+=`if(body.Check(c.body) === false) {
|
|
167
170
|
${K0("body")}
|
|
168
|
-
}`;if(
|
|
171
|
+
}`;if(P0(Q.body.schema))U+="\nc.body = body.Decode(c.body)\n"}if(m(n?.schema.properties??{})){if(U+=`const cookieValue = {}
|
|
169
172
|
for(const [key, value] of Object.entries(c.cookie))
|
|
170
|
-
cookieValue[key] = value.value\n`,B0("default",n.schema))for(let[
|
|
173
|
+
cookieValue[key] = value.value\n`,B0("default",n.schema))for(let[O,D]of Object.entries(b0.Default(n.schema,{})))U+=`cookieValue['${O}'] = ${typeof D==="object"?JSON.stringify(D):D}\n`;U+=`if(cookie.Check(cookieValue) === false) {
|
|
171
174
|
${K0("cookie","cookieValue")}
|
|
172
|
-
}`}}if(Z?.beforeHandle){const
|
|
175
|
+
}`}}if(Z?.beforeHandle){const O=E("beforeHandle",{unit:Z.beforeHandle.length});let D=!1;for(let j=0;j<Z.beforeHandle.length;j++){const T=Z.beforeHandle[j],b=E("beforeHandle.unit",{name:T.fn.name}),z0=H0(T.fn.toString());if(T.subType==="resolve"){if(!D)D=!0,U+="\nlet resolved\n";U+=x(T)?`resolved = await beforeHandle[${j}](c);\n`:`resolved = beforeHandle[${j}](c);\n`,U+=`if(resolved[ELYSIA_RESPONSE])
|
|
173
176
|
throw resolved
|
|
174
177
|
else
|
|
175
|
-
Object.assign(c, resolved)\n`}else if(!z0)U+=x(T)?`await beforeHandle[${
|
|
178
|
+
Object.assign(c, resolved)\n`}else if(!z0)U+=x(T)?`await beforeHandle[${j}](c);\n`:`beforeHandle[${j}](c);\n`,b();else{U+="Object.assign(c, be);",U+=x(T)?`be = await beforeHandle[${j}](c);\n`:`be = beforeHandle[${j}](c);\n`,b(),U+="if(be !== undefined) {\n",O();const b$=E("afterHandle",{unit:Z.transform.length});if(Z.afterHandle){E("handle",{name:K?G.name:void 0})();for(let l=0;l<Z.afterHandle.length;l++){const f0=Z.afterHandle[l],H$=H0(f0.fn.toString()),x$=E("afterHandle.unit",{name:f0.fn.name});if(U+="c.response = be\n",!H$)U+=x(f0.fn)?`await afterHandle[${l}](c, be)\n`:`afterHandle[${l}](c, be)\n`;else U+=x(f0.fn)?`af = await afterHandle[${l}](c)\n`:`af = afterHandle[${l}](c)\n`,U+="if(af !== undefined) { c.response = be = af }\n";x$()}}if(b$(),Q.response)U+=y0("be");if(Z.mapResponse.length){U+="c.response = be";for(let l=0;l<Z.mapResponse.length;l++)U+=`\nif(mr === undefined) {
|
|
176
179
|
mr = onMapResponse[${l}](c)
|
|
177
180
|
if(mr instanceof Promise) mr = await mr
|
|
178
181
|
if(mr !== undefined) c.response = mr
|
|
179
|
-
}\n`}U+=V,U+="return mapEarlyResponse(be, c.set, c.request)}\n"}}
|
|
182
|
+
}\n`}U+=V,U+="return mapEarlyResponse(be, c.set, c.request)}\n"}}O()}if(Z?.afterHandle.length){const O=E("handle",{name:K?G.name:void 0});if(Z.afterHandle.length)U+=_0?`let r = c.response = await ${F};\n`:`let r = c.response = ${F};\n`;else U+=_0?`let r = await ${F};\n`:`let r = ${F};\n`;O();const D=E("afterHandle",{unit:Z.afterHandle.length});for(let j=0;j<Z.afterHandle.length;j++){const T=Z.afterHandle[j],b=H0(T.fn.toString()),z0=E("afterHandle.unit",{name:T.fn.name});if(!b)U+=x(T.fn)?`await afterHandle[${j}](c)\n`:`afterHandle[${j}](c)\n`,z0();else if(U+=x(T.fn)?`af = await afterHandle[${j}](c)\n`:`af = afterHandle[${j}](c)\n`,z0(),Q.response)U+="if(af !== undefined) {",D(),U+=y0("af"),U+="c.response = af }";else U+="if(af !== undefined) {",D(),U+="c.response = af}\n"}if(D(),U+="r = c.response\n",Q.response)U+=y0();if(U+=V,Z.mapResponse.length)for(let j=0;j<Z.mapResponse.length;j++)U+=`\nmr = onMapResponse[${j}](c)
|
|
180
183
|
if(mr instanceof Promise) mr = await mr
|
|
181
|
-
if(mr !== undefined) c.response = mr\n`;if(k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else{const
|
|
184
|
+
if(mr !== undefined) c.response = mr\n`;if(k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else{const O=E("handle",{name:K?G.name:void 0});if(Q.response||Z.mapResponse.length){if(U+=_0?`let r = await ${F};\n`:`let r = ${F};\n`,O(),Q.response)U+=y0();if(E("afterHandle")(),Z.mapResponse.length){U+="c.response = r";for(let D=0;D<Z.mapResponse.length;D++)U+=`\nif(mr === undefined) {
|
|
182
185
|
mr = onMapResponse[${D}](c)
|
|
183
186
|
if(mr instanceof Promise) mr = await mr
|
|
184
187
|
if(mr !== undefined) r = c.response = mr
|
|
185
|
-
}\n`}if(U+=V,
|
|
188
|
+
}\n`}if(U+=V,G instanceof Response)U+=A.set?`if(
|
|
186
189
|
isNotEmpty(c.set.headers) ||
|
|
187
190
|
c.set.status !== 200 ||
|
|
188
191
|
c.set.redirect ||
|
|
@@ -190,11 +193,11 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
190
193
|
)
|
|
191
194
|
return mapResponse(${F}.clone(), c.set, c.request)
|
|
192
195
|
else
|
|
193
|
-
return ${F}.clone()`:`return ${F}.clone()`,U+="\n";else if(k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else if(
|
|
196
|
+
return ${F}.clone()`:`return ${F}.clone()`,U+="\n";else if(k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else if(w.handle||v){if(U+=_0?`let r = await ${F};\n`:`let r = ${F};\n`,O(),E("afterHandle")(),Z.mapResponse.length){U+="c.response = r";for(let D=0;D<Z.mapResponse.length;D++)U+=`\nif(mr === undefined) {
|
|
194
197
|
mr = onMapResponse[${D}](c)
|
|
195
198
|
if(mr instanceof Promise) mr = await mr
|
|
196
199
|
if(mr !== undefined) r = c.response = mr
|
|
197
|
-
}\n`}if(U+=V,k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else{
|
|
200
|
+
}\n`}if(U+=V,k0)U+="return mapResponse(r, c.set, c.request)\n";else U+="return mapCompactResponse(r, c.request)\n"}else{O();const D=_0?`await ${F}`:F;if(E("afterHandle")(),G instanceof Response)U+=A.set?`if(
|
|
198
201
|
isNotEmpty(c.set.headers) ||
|
|
199
202
|
c.set.status !== 200 ||
|
|
200
203
|
c.set.redirect ||
|
|
@@ -202,10 +205,10 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
202
205
|
)
|
|
203
206
|
return mapResponse(${F}.clone(), c.set, c.request)
|
|
204
207
|
else
|
|
205
|
-
return ${F}.clone()`:`return ${F}.clone()`,U+="\n";else if(k0)U+=`return mapResponse(${D}, c.set, c.request)\n`;else U+=`return mapCompactResponse(${D}, c.request)\n`}}if(z||
|
|
208
|
+
return ${F}.clone()`:`return ${F}.clone()`,U+="\n";else if(k0)U+=`return mapResponse(${D}, c.set, c.request)\n`;else U+=`return mapCompactResponse(${D}, c.request)\n`}}if(z||M){if(U+="\n} catch(error) {",!Z1)U+="return (async () => {";U+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const O=E("error",{unit:Z.error.length});if(Z.error.length){U+=`
|
|
206
209
|
c.error = error
|
|
207
210
|
c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
|
|
208
|
-
`;for(let D=0;D<Z.error.length;D++){const
|
|
211
|
+
`;for(let D=0;D<Z.error.length;D++){const j=`er${D}`,T=E("error.unit",{name:Z.error[D].fn.name});if(U+=`\nlet ${j} = handleErrors[${D}](c)\n`,x(Z.error[D]))U+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;T(),U+=`${j} = mapEarlyResponse(${j}, set, c.request)\n`,U+=`if (${j}) {`,U+=`return ${j} }\n`}}if(O(),U+="return handleError(c, error, true)\n\n",!Z1)U+="})()";if(U+="}",M||I){U+=" finally { ";const D=E("response",{unit:Z.onResponse.length});U+=M,D(),U+="}"}}return U=`const {
|
|
209
212
|
handler,
|
|
210
213
|
handleError,
|
|
211
214
|
hooks: {
|
|
@@ -250,16 +253,16 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
250
253
|
ELYSIA_RESPONSE
|
|
251
254
|
} = hooks
|
|
252
255
|
|
|
253
|
-
${Z.onResponse.length?`const ${Z.onResponse.map((
|
|
256
|
+
${Z.onResponse.length?`const ${Z.onResponse.map((O,D)=>`res${D} = onResponse[${D}]`).join(",")}`:""}
|
|
254
257
|
|
|
255
258
|
return ${Z1?"async":""} function handle(c) {
|
|
256
259
|
${Z.beforeHandle.length?"let be":""}
|
|
257
260
|
${Z.afterHandle.length?"let af":""}
|
|
258
261
|
${Z.mapResponse.length?"let mr":""}
|
|
259
262
|
|
|
260
|
-
${
|
|
263
|
+
${Y?"c.schema = schema; c.defs = definitions":""}
|
|
261
264
|
${U}
|
|
262
|
-
}`,Function("hooks",U)({handler:
|
|
265
|
+
}`,Function("hooks",U)({handler:G,hooks:J$(Z),validator:Q,handleError:$.handleError,utils:{mapResponse:h,mapCompactResponse:o,mapEarlyResponse:u,parseQuery:M$.parse,isNotEmpty:m},error:{NotFoundError:Y0,ValidationError:R,InternalServerError:a0,ParseError:e0},schema:$.router.history,definitions:$.definitions.type,ERROR_CODE:G0,getReporter:()=>$.reporter,requestId:w$,parseCookie:l0,signCookie:j0,decodeURIComponent:j$.default,ELYSIA_RESPONSE:d})},V1=($)=>{const J={event:{...$.inference.event,queries:[...$.inference.event.queries]},trace:{...$.inference.trace}};let W="",X="";const Z=$.setHeaders;for(let U of Object.keys($.singleton.decorator))W+=`,${U}: app.singleton.decorator.${U}`;const Q=$.router,G=$.event.trace.length>0;let Y=`
|
|
263
266
|
const route = router.find(request.method, path) ${Q.http.root.ALL?'?? router.find("ALL", path)':""}
|
|
264
267
|
|
|
265
268
|
if (route === null)
|
|
@@ -268,12 +271,12 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
268
271
|
headers: ctx.set.headers
|
|
269
272
|
})`:"error404.clone()"}
|
|
270
273
|
|
|
271
|
-
ctx.params = route.params\n`;if(!($.config.precompile===!0||typeof $.config.precompile==="object"&&$.config.precompile.compose===!0))
|
|
274
|
+
ctx.params = route.params\n`;if(!($.config.precompile===!0||typeof $.config.precompile==="object"&&$.config.precompile.compose===!0))Y+=`
|
|
272
275
|
if(route.store.composed)
|
|
273
276
|
return route.store.composed(ctx)
|
|
274
277
|
|
|
275
278
|
if(route.store.compose)
|
|
276
|
-
return (route.store.compose())(ctx)`;else
|
|
279
|
+
return (route.store.compose())(ctx)`;else Y+="return route.store(ctx)";Y+="\n";let _="";for(let[U,{code:A,all:P}]of Object.entries(Q.static.http.map))_+=`case '${U}':\nswitch(request.method) {\n${A}\n${P??"default: break map"}}\n\n`;const K=$.event.request.some(x),z=`\n
|
|
277
280
|
const url = request.url
|
|
278
281
|
const s = url.indexOf('/', 11)
|
|
279
282
|
const qi = url.indexOf('?', s + 1)
|
|
@@ -305,8 +308,8 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
305
308
|
const error404 = new Response(error404Message, { status: 404 });
|
|
306
309
|
`}
|
|
307
310
|
|
|
308
|
-
return ${K?"async":""} function map(request) {\n`,$.event.request.length)X+="let re";const F=N$({hasTrace:
|
|
309
|
-
${
|
|
311
|
+
return ${K?"async":""} function map(request) {\n`,$.event.request.length)X+="let re";const F=N$({hasTrace:G,hasTraceSet:J.trace.set,condition:{request:J.trace.request},addFn:(U)=>{X+=U}});if($.event.request.length){X+=`
|
|
312
|
+
${G?"const id = +requestId.value++":""}
|
|
310
313
|
|
|
311
314
|
const ctx = {
|
|
312
315
|
request,
|
|
@@ -316,16 +319,16 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
316
319
|
status: 200
|
|
317
320
|
},
|
|
318
321
|
error
|
|
319
|
-
${
|
|
322
|
+
${G?",$$requestId: +id":""}
|
|
320
323
|
${W}
|
|
321
324
|
}
|
|
322
|
-
`;const U=F("request",{attribute:"ctx",unit:$.event.request.length});X+="\n try {\n";for(let
|
|
323
|
-
${
|
|
325
|
+
`;const U=F("request",{attribute:"ctx",unit:$.event.request.length});X+="\n try {\n";for(let A=0;A<$.event.request.length;A++){const P=$.event.request[A],N=H0(P.fn.toString()),L=x(P),q=F("request.unit",{name:$.event.request[A].fn.name});if(N)X+=`re = mapEarlyResponse(
|
|
326
|
+
${L?"await":""} onRequest[${A}](ctx),
|
|
324
327
|
ctx.set,
|
|
325
328
|
request
|
|
326
|
-
)\n`,q(),X+="if(re !== undefined) return re\n";else X+=`${
|
|
329
|
+
)\n`,q(),X+="if(re !== undefined) return re\n";else X+=`${L?"await":""} onRequest[${A}](ctx)\n`,q()}X+=`} catch (error) {
|
|
327
330
|
return app.handleError(ctx, error)
|
|
328
|
-
}`,U(),X+=z,X+="\nctx.qi = qi\n ctx.path = path\n"}else X+=z,X+=`${
|
|
331
|
+
}`,U(),X+=z,X+="\nctx.qi = qi\n ctx.path = path\n"}else X+=z,X+=`${G?"const id = +requestId.value++":""}
|
|
329
332
|
const ctx = {
|
|
330
333
|
request,
|
|
331
334
|
store,
|
|
@@ -336,14 +339,14 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
336
339
|
status: 200
|
|
337
340
|
},
|
|
338
341
|
error
|
|
339
|
-
${
|
|
342
|
+
${G?",$$requestId: id":""}
|
|
340
343
|
${W}
|
|
341
|
-
}`,F("request",{unit:$.event.request.length,attribute:J.trace.context||J.trace.store||J.trace.set?"ctx":""})();const
|
|
344
|
+
}`,F("request",{unit:$.event.request.length,attribute:J.trace.context||J.trace.store||J.trace.set?"ctx":""})();const M=$.router.static.ws,w=$.router.ws;if(Object.keys(M).length||w.history.length){X+=`
|
|
342
345
|
if(request.method === 'GET') {
|
|
343
|
-
switch(path) {`;for(let[U,
|
|
346
|
+
switch(path) {`;for(let[U,A]of Object.entries(M))X+=`
|
|
344
347
|
case '${U}':
|
|
345
348
|
if(request.headers.get('upgrade') === 'websocket')
|
|
346
|
-
return st${
|
|
349
|
+
return st${A}(ctx)
|
|
347
350
|
|
|
348
351
|
break`;X+=`
|
|
349
352
|
default:
|
|
@@ -367,8 +370,8 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
367
370
|
break
|
|
368
371
|
}
|
|
369
372
|
|
|
370
|
-
${
|
|
371
|
-
}`;const I=S1($);return $.handleError=I,Function("data",X)({app:$,mapEarlyResponse:u,NotFoundError:
|
|
373
|
+
${Y}
|
|
374
|
+
}`;const I=S1($);return $.handleError=I,Function("data",X)({app:$,mapEarlyResponse:u,NotFoundError:Y0,getReporter:()=>$.reporter,requestId:w$,handleError:I,error:w1})},S1=($)=>{let J=`const {
|
|
372
375
|
app: { event: { error: onErrorContainer, onResponse: resContainer } },
|
|
373
376
|
mapResponse,
|
|
374
377
|
ERROR_CODE,
|
|
@@ -386,7 +389,7 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
386
389
|
context.code = error.code
|
|
387
390
|
context.error = error
|
|
388
391
|
|
|
389
|
-
if(error
|
|
392
|
+
if(ELYSIA_RESPONSE in error) {
|
|
390
393
|
error.status = error[ELYSIA_RESPONSE]
|
|
391
394
|
error.message = error.response
|
|
392
395
|
}\n`;for(let W=0;W<$.event.error.length;W++){const X=$.event.error[W],Z=`${x(X)?"await ":""}onError[${W}](context)`;if(J+="\nif(skipGlobal !== true) {\n",H0(X.fn.toString()))J+=`r = ${Z}; if(r !== undefined) {
|
|
@@ -420,9 +423,9 @@ var g$=Object.create;var{defineProperty:L1,getPrototypeOf:y$,getOwnPropertyNames
|
|
|
420
423
|
|
|
421
424
|
return mapResponse(error, set, context.request)
|
|
422
425
|
}
|
|
423
|
-
}`,Function("inject",J)({app:$,mapResponse:h,ERROR_CODE:
|
|
426
|
+
}`,Function("inject",J)({app:$,mapResponse:h,ERROR_CODE:G0,ELYSIA_RESPONSE:d})},x0=($)=>`if(stc${$}) return stc${$}(ctx)
|
|
424
427
|
if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
|
|
425
428
|
|
|
426
|
-
return st${$}(ctx)`;var W1=V0(P1(),1);var C1=($)=>async(J)=>{const W=J.url,X=W.indexOf("/",11),Z=W.indexOf("?",X+1),Q=Z===-1?W.substring(X):W.substring(X,Z),Y={cookie:{},status:200,headers:{}},G=Object.assign({},$.singleton.decorator,{set:Y,store:$.singleton.store,request:J,path:Q,qi:Z});try{for(let M=0;M<$.event.request.length;M++){const O=$.event.request[M].fn;let N=O(G);if(N instanceof Promise)N=await N;if(N=u(N,Y),N)return N}const B=$.router.dynamic.find(J.method,Q)??$.router.dynamic.find("ALL",Q);if(!B)throw new G0;const{handle:_,hooks:K,validator:z,content:F}=B.store;let w;if(J.method!=="GET"&&J.method!=="HEAD")if(F)switch(F){case"application/json":w=await J.json();break;case"text/plain":w=await J.text();break;case"application/x-www-form-urlencoded":w=W1.parse(await J.text());break;case"application/octet-stream":w=await J.arrayBuffer();break;case"multipart/form-data":w={};const M=await J.formData();for(let O of M.keys()){if(w[O])continue;const N=M.getAll(O);if(N.length===1)w[O]=N[0];else w[O]=N}break}else{let M=J.headers.get("content-type");if(M){const O=M.indexOf(";");if(O!==-1)M=M.slice(0,O);for(let N=0;N<K.parse.length;N++){const R=K.parse[N].fn;let q=R(G,M);if(q instanceof Promise)q=await q;if(q){w=q;break}}if(w===void 0)switch(M){case"application/json":w=await J.json();break;case"text/plain":w=await J.text();break;case"application/x-www-form-urlencoded":w=W1.parse(await J.text());break;case"application/octet-stream":w=await J.arrayBuffer();break;case"multipart/form-data":w={};const N=await J.formData();for(let R of N.keys()){if(w[R])continue;const q=N.getAll(R);if(q.length===1)w[R]=q[0];else w[R]=q}break}}}G.body=w,G.params=B?.params||void 0,G.query=Z===-1?{}:W1.parse(W.substring(Z+1)),G.headers={};for(let[M,O]of J.headers.entries())G.headers[M]=O;const j=Object.assign({},$.config?.cookie,z?.cookie?.config),I=J.headers.get("cookie");G.cookie=await l0(G.set,I,j?{secret:j.secrets!==void 0?typeof j.secrets==="string"?j.secrets:j.secrets.join(","):void 0,sign:j.sign===!0?!0:j.sign!==void 0?typeof j.sign==="string"?j.sign:j.sign.join(","):void 0}:void 0);for(let M=0;M<K.transform.length;M++){const O=K.transform[M],N=O.fn(G);if(O.subType==="derive")if(N instanceof Promise)Object.assign(G,await N);else Object.assign(G,N);else if(N instanceof Promise)await N}if(z){if(z.headers){const M={};for(let O in J.headers)M[O]=J.headers.get(O);if(z.headers.Check(M)===!1)throw new L("header",z.headers,M)}if(z.params?.Check(G.params)===!1)throw new L("params",z.params,G.params);if(z.query?.Check(G.query)===!1)throw new L("query",z.query,G.query);if(z.cookie){const M={};for(let[O,N]of Object.entries(G.cookie))M[O]=N.value;if(z.cookie?.Check(M)===!1)throw new L("cookie",z.cookie,M)}if(z.body?.Check(w)===!1)throw new L("body",z.body,w)}for(let M=0;M<K.beforeHandle.length;M++){let O=K.beforeHandle[M].fn(G);if(O instanceof Promise)O=await O;if(O!==void 0){G.response=O;for(let R=0;R<K.afterHandle.length;R++){let q=K.afterHandle[R].fn(G);if(q instanceof Promise)q=await q;if(q)O=q}const N=u(O,G.set);if(N)return N}}let U=_(G);if(U instanceof Promise)U=await U;if(!K.afterHandle.length){const M=z?.response?.[U.status];if(M?.Check(U)===!1)throw new L("response",M,U)}else{G.response=U;for(let M=0;M<K.afterHandle.length;M++){let O=K.afterHandle[M].fn(G);if(O instanceof Promise)O=await O;const N=u(O,G.set);if(N!==void 0){const R=z?.response?.[U.status];if(R?.Check(N)===!1)throw new L("response",R,N);return N}}}if(G.set.cookie&&j?.sign){const M=!j.secrets?void 0:typeof j.secrets==="string"?j.secrets:j.secrets[0];if(j.sign===!0)for(let[O,N]of Object.entries(G.set.cookie))G.set.cookie[O].value=await A0(N.value,"${secret}");else{const O=z?.cookie?.schema?.properties;for(let N of j.sign){if(!(N in O))continue;if(G.set.cookie[N]?.value)G.set.cookie[N].value=await A0(G.set.cookie[N].value,M)}}}return h(U,G.set)}catch(B){if(B.status)Y.status=B.status;return $.handleError(G,B)}finally{for(let B of $.event.onResponse)await B.fn(G)}},O$=($)=>async(J,W)=>{const X=Object.assign(J,{error:W,code:W.code});X.set=J.set;for(let Z=0;Z<$.event.error.length;Z++){let Y=$.event.error[Z].fn(X);if(Y instanceof Promise)Y=await Y;if(Y!==void 0&&Y!==null)return h(Y,J.set)}return new Response(typeof W.cause==="string"?W.cause:W.message,{headers:J.set.headers,status:W.status??500})};import{TypeRegistry as T$} from"@sinclair/typebox";import{TypeSystem as I0} from"@sinclair/typebox/system";import{Type as g0,FormatRegistry as U0} from"@sinclair/typebox";import{Value as P0} from"@sinclair/typebox/value";var N8=function($){return $%4===0&&($%100!==0||$%400===0)},S$=function($){const J=O8.exec($);if(!J)return!1;const W=+J[1],X=+J[2],Z=+J[3];return X>=1&&X<=12&&Z>=1&&Z<=(X===2&&N8(W)?29:P8[X])},T1=function($){return function J(W){const X=I8.exec(W);if(!X)return!1;const Z=+X[1],Q=+X[2],Y=+X[3],G=X[4],B=X[5]==="-"?-1:1,_=+(X[6]||0),K=+(X[7]||0);if(_>23||K>59||$&&!G)return!1;if(Z<=23&&Q<=59&&Y<60)return!0;const z=Q-K*B,F=Z-_*B-(z<0?1:0);return(F===23||F===-1)&&(z===59||z===-1)&&Y<61}},P$=function($){const J=T1($);return function W(X){const Z=X.split(V8);return Z.length===2&&S$(Z[0])&&J(Z[1])}},T8=function($){return S8.test($)&&C8.test($)},q8=function($){return I$.lastIndex=0,I$.test($)},E8=function($){return Number.isInteger($)&&$<=R8&&$>=L8},b8=function($){return Number.isInteger($)},V$=function(){return!0},x8=function($){if(H8.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},X1={date:S$,time:T1(!0),"date-time":P$(!0),"iso-time":T1(!1),"iso-date-time":P$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:T8,"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:x8,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:q8,int32:{type:"number",validate:E8},int64:{type:"number",validate:b8},float:{type:"number",validate:V$},double:{type:"number",validate:V$},password:!0,binary:!0},O8=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,P8=[0,31,28,31,30,31,30,31,31,30,31,30,31],I8=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,V8=/t|\s/i,S8=/\/|:/,C8=/^(?:[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,I$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,L8=-2147483648,R8=2147483647,H8=/[^\\]\\Z/;import{TypeSystemPolicy as a9,TypeSystem as e9,TypeSystemDuplicateFormat as $J,TypeSystemDuplicateTypeKind as JJ} from"@sinclair/typebox/system";import{TypeCompiler as XJ,TypeCheck as ZJ} from"@sinclair/typebox/compiler";var q$=/(\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))/,L$=/(?: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\([^)]+\)/,R$=/^(?:(?:(?:(?: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)?)?$/,g8=X1.date,y8=X1["date-time"];I0.Format("date",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||L$.test(J)||R$.test(J)||g8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});I0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||L$.test(J)||R$.test(J)||y8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});Object.entries(X1).forEach(($)=>{const[J,W]=$;if(!U0.Has(J)){if(W instanceof RegExp)I0.Format(J,(X)=>W.test(X));else if(typeof W==="function")I0.Format(J,W)}});var C=Object.assign({},g0),C$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<C$($.minSize))return!1;if($.maxSize&&J.size>C$($.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},v8=T$.Get("Files")??I0.Type("File",q1),k8=T$.Get("Files")??I0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let W=0;W<J.length;W++)if(!q1($,J[W]))return!1;return!0});if(!U0.Has("numeric"))U0.Set("numeric",($)=>!!$&&!isNaN(+$));if(!U0.Has("boolean"))U0.Set("boolean",($)=>$==="true"||$==="false");if(!U0.Has("ObjectString"))U0.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=g0.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((W)=>{const X=+W;if(isNaN(X))return W;if($&&!P0.Check(J,X))throw new L("property",J,X);return X}).Encode((W)=>W)},Date:($)=>{const J=g0.Date($);return C.Transform(C.Union([g0.Date($),C.String({format:"date",default:(new Date()).toISOString()}),C.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((W)=>{if(W instanceof Date)return W;const X=new Date(W);if(!P0.Check(J,X))throw new L("property",J,X);return X}).Encode((W)=>{if(typeof W==="string")return new Date(W);return W})},BooleanString:($)=>{const J=g0.Boolean($);return C.Transform(C.Union([C.String({format:"boolean",default:!1}),C.Boolean($)],$)).Decode((W)=>{if(typeof W==="string")return W==="true";if($&&!P0.Check(J,W))throw new L("property",J,W);return W}).Encode((W)=>W)},ObjectString:($={},J)=>{const W=C.Object($,J),X=JSON.stringify(P0.Create(W));return C.Transform(C.Union([C.String({format:"ObjectString",default:X}),W])).Decode((Z)=>{if(typeof Z==="string"){try{Z=JSON.parse(Z)}catch{throw new L("property",W,Z)}if(!P0.Check(W,Z))throw new L("property",W,Z);return Z}return Z}).Encode((Z)=>{if(typeof Z==="string")try{Z=JSON.parse(Z)}catch{throw new L("property",W,Z)}if(!P0.Check(W,Z))throw new L("property",W,Z);return JSON.stringify(Z)})},File:v8,Files:($={})=>C.Transform(k8($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,{domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:Y,sameSite:G,secure:B,secrets:_,sign:K,...z}={})=>{const F=C.Object($,z);return F.config={domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:Y,sameSite:G,secure:B,secrets:_,sign:K},F}};C.BooleanString=a.BooleanString;C.ObjectString=a.ObjectString;C.Numeric=a.Numeric;C.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>a.Nullable($);C.MaybeEmpty=a.MaybeEmpty;C.Cookie=a.Cookie;C.Date=a.Date;class i{config;server=null;dependencies={};reporter=new g1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new X0,ws:new X0,dynamic:new X0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new A1;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=e1({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 X of this.extender.macros)w1(X.fn(W),$)}}add($,J,W,X,{allowMeta:Z=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(X=$$(X),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!Q&&!this.config.scoped)J=this.config.prefix+J;if(X?.type)switch(X.type){case"text":X.type="text/plain";break;case"json":X.type="application/json";break;case"formdata":X.type="multipart/form-data";break;case"urlencoded":X.type="application/x-www-form-urlencoded";break;case"arrayBuffer":X.type="application/octet-stream";break;default:break}const Y=this.definitions.type;let G,B,_,K,z,F;const w=!this.config.aot,j={body:X?.body??this.validator?.body,headers:X?.headers??this.validator?.headers,params:X?.params??this.validator?.params,query:X?.query??this.validator?.query,cookie:X?.cookie??this.validator?.cookie,response:X?.response??this.validator?.response},I=()=>j.cookie?t0({validator:j.cookie,defaultConfig:this.config.cookie,config:j.cookie?.config??{},dynamic:w,models:Y}):void 0,U=this.config.normalize,M=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(j.body,{dynamic:w,models:Y,normalize:U}),headers:k(j.headers,{dynamic:w,models:Y,additionalProperties:!0}),params:k(j.params,{dynamic:w,models:Y}),query:k(j.query,{dynamic:w,models:Y,normalize:U}),cookie:I(),response:i0(j.response,{dynamic:w,models:Y,normalize:U})}:{get body(){if(G)return G;return G=k(j.body,{dynamic:w,models:Y,normalize:U})},get headers(){if(B)return B;return k(j.headers,{dynamic:w,models:Y,additionalProperties:!0})},get params(){if(_)return _;return _=k(j.params,{dynamic:w,models:Y})},get query(){if(K)return K;return K=k(j.query,{dynamic:w,models:Y})},get cookie(){if(z)return z;return z=I()},get response(){if(F)return F;return F=i0(j.response,{dynamic:w,models:Y,normalize:U})}},O=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(X=f(X,{},{allowMacro:!0}),X.tags)if(!X.detail)X.detail={tags:X.tags};else X.detail.tags=X.tags;if(m(this.config.detail))X.detail=p(Object.assign({},this.config.detail),X.detail);this.applyMacro(X);const N=f(this.event,X);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:M,hooks:N,content:X?.type,handle:W}),this.config.strictPath===!1)this.router.dynamic.add($,O,{validator:M,hooks:N,content:X?.type,handle:W});this.router.history.push({method:$,path:J,composed:null,handler:W,hooks:N});return}let R=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:M,handler:W,allowMeta:Z,appInference:e}):(V)=>{if(R)return R(V);return(R=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:M,handler:W,allowMeta:Z,appInference:e}))(V)};if(!q)v.compose=()=>{return v.composed=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:M,handler:W,allowMeta:Z,appInference:e})};let n=this.router.history.length;if(this.routeTree.has($+J)){if(n=this.router.history.findIndex((V)=>V.path===J&&V.method===$),n!==-1){const V=this.router.history.splice(n,1)[0];if(V&&this.routeTree.has(V?.method+V?.path))this.routeTree.delete(V.method+V.path)}}this.routeTree.set($+J,n),this.router.history.push({method:$,path:J,composed:v,handler:W,hooks:N});const S=this.router.static.http;if($==="$INTERNALWS"){const V=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=S.handlers.length;if(S.handlers.push(v),S.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,V)this.router.static.ws[V]=$0}else if(this.router.ws.add("ws",J,v),V)this.router.ws.add("ws",V,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const V=S.handlers.length;if(S.handlers.push(v),S.variables+=q?`const st${V} = staticRouter.handlers[${V}]\n`:`let st${V} = staticRouter.handlers[${V}]\nlet stc${V}\n`,!S.map[J])S.map[J]={code:""};if($==="ALL")S.map[J].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[J].code=q?`case '${$}': return st${V}(ctx)\n${S.map[J].code}`:`case '${$}': ${x0(V)}\n${S.map[J].code}`;if(!this.config.strictPath){if(!S.map[O])S.map[O]={code:""};if($==="ALL")S.map[O].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[O].code=q?`case '${$}': return st${V}(ctx)\n${S.map[O].code}`:`case '${$}': ${x0(V)}\n${S.map[O].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",y1(()=>this.reporter,this.event.trace.length,W));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Y0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[W,X]of Object.entries($))X.prototype[Y0]=W,this.definitions.error[W]=X;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 X;switch(typeof $){case"string":X=$,W=J;break;case"object":X=J;break}if(X==="response")X="onResponse";if(Array.isArray(W))W=c(W);else if(typeof W==="function")W=[{fn:W}];else W=[W];const Z=W;for(let Q of Z)Q.scope=typeof $==="string"?"local":$?.as??"local";if(X==="trace")d1(Z.map((Q)=>Q.fn),this.inference.trace);else d0({[X]:Z.map((Q)=>Q.fn)},this.inference.event);for(let Q of Z){const Y=a1(Q,"global",{skipIfHasType:!0});switch(X){case"start":this.event.start.push(Y);break;case"request":this.event.request.push(Y);break;case"parse":this.event.parse.push(Y);break;case"transform":this.event.transform.push(Y);break;case"beforeHandle":this.event.beforeHandle.push(Y);break;case"afterHandle":this.event.afterHandle.push(Y);break;case"mapResponse":this.event.mapResponse.push(Y);break;case"onResponse":this.event.onResponse.push(Y);break;case"trace":this.event.trace.push(Y);break;case"error":this.event.error.push(Y);break;case"stop":this.event.stop.push(Y);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 X=new i({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.getServer=()=>this.server,X.inference=r0(this.inference);const Z=typeof J==="object",Q=(Z?W:J)(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Q.event.request.length)this.event.request=[...this.event.request||[],...Q.event.request||[]];if(Q.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...Q.event.onResponse||[]];return this.model(Q.definitions.type),Object.values(X.router.history).forEach(({method:Y,path:G,handler:B,hooks:_})=>{if(G=(Z?"":this.config.prefix)+$+G,Z){const K=J,z=_;this.add(Y,G,B,f(K,{...z||{},error:!z.error?Q.event.error:Array.isArray(z.error)?[...z.error||{},...Q.event.error||{}]:[z.error,...Q.event.error||{}]}))}else this.add(Y,G,B,f(_,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=s0(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 i({...this.config,prefix:""});W.singleton={...this.singleton},W.definitions={...this.definitions},W.inference=r0(this.inference);const X=J(W);if(this.singleton=p(this.singleton,W.singleton),this.definitions=p(this.definitions,W.definitions),X.getServer=()=>this.server,X.event.request.length)this.event.request=[...this.event.request||[],...X.event.request||[]];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...X.event.onResponse||[]];return this.model(X.definitions.type),Object.values(W.router.history).forEach(({method:Z,path:Q,handler:Y,hooks:G})=>{this.add(Z,Q,Y,f($,{...G||{},error:!G.error?X.event.error:Array.isArray(G.error)?[...G.error||{},...X.event.error||[]]:[G.error,...X.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(W)=>W.use($));if(Array.isArray($)){let W=this;for(let X of $)W=this.use(X);return W}if($ instanceof Promise)return this.promisedModules.add($.then((W)=>{if(typeof W==="function")return W(this);if(W instanceof i)return this._use(W);if(typeof W.default==="function")return W.default(this);if(W.default instanceof i)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 Z=$(this);if(Z instanceof Promise)return this.promisedModules.add(Z.then((Q)=>{if(Q instanceof i){this.compile();for(let{method:Y,path:G,handler:B,hooks:_}of Object.values(Q.router.history))this.add(Y,G,B,f(_,{error:Q.event.error}));return Q}if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return Z}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((Z)=>Z.compile())),this;const{name:J,seed:W}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const X=$.config.scoped;if(X){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?L0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:Y})=>Q===Y))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.subType==="derive").map((Y)=>({fn:Y.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.subType==="derive").map((Y)=>({fn:Y.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<$.extender.macros.length;Q++){const Y=this.extender.macros[Q];if(Z.includes(Y.checksum))$.extender.macros.splice(Q,1),Q--;Z.push(Y.checksum)}if($.onRequest((Q)=>{Object.assign(Q,this.singleton.decorator),Object.assign(Q.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(X===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let Q of $.event.trace)if(Q.scope&&Q.scope!=="local")this.trace(Q);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?L0(J+JSON.stringify(W)):0;if(!this.dependencies[J].some(({checksum:Y})=>Q===Y))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<this.extender.macros.length;Q++){const Y=this.extender.macros[Q];if(Y.checksum){if(Z.includes(Y.checksum))this.extender.macros.splice(Q,1),Q--;Z.push(Y.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:Z,path:Q,handler:Y,hooks:G}of Object.values($.router.history))this.add(Z,Q,Y,f(G,{error:$.event.error}));if(!X)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Z=W!==void 0?L0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:Q})=>Z===Q))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q?.subType==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q?.subType==="resolve").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))}),this.event=s0(this.event,M1($.event),Z)}else this.event=s0(this.event,M1($.event));return this}macro($){const J={checksum:L0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof i||typeof $==="function"||$.length===0||$==="/"){const Z=typeof $==="function"?$:$ instanceof i?$.compile().fetch:J instanceof i?J.compile().fetch:J,Q=async({request:Y,path:G})=>Z(new Request(D1(Y.url,G||"/"),Y));return this.all("/*",Q,{type:"none"}),this}const W=$.length;if(J instanceof i)J=J.compile().fetch;const X=async({request:Z,path:Q})=>J(new Request(D1(Z.url,Q.slice(W)||"/"),Z));return this.all($,X,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),X,{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,X){return this.add($.toUpperCase(),J,W,X,X?.config),this}ws($,J){const W=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let X=null;const Z=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),Q=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Y=(G)=>{if(typeof G==="string"){const B=G?.charCodeAt(0);if(B===47||B===123)try{G=JSON.parse(G)}catch{}else if(M0(G))G=+G}if(W?.length)for(let B=0;B<W.length;B++){const _=W[B](G);if(_!==void 0)G=_}return G};return this.route("$INTERNALWS",$,(G)=>{const{set:B,path:_,qi:K,headers:z,query:F,params:w}=G;if(X===null)X=this.getServer();if(X?.upgrade(G.request,{headers:typeof J.upgrade==="function"?J.upgrade(G):J.upgrade,data:{validator:Q,open(j){J.open?.(new j0(j,G))},message:(j,I)=>{const U=Y(I);if(Z?.Check(U)===!1)return void j.send(new L("message",Z,U).message);J.message?.(new j0(j,G),U)},drain(j){J.drain?.(new j0(j,G))},close(j,I,U){J.close?.(new j0(j,G),I,U)}}}))return;return B.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,X])=>{if(!(W in this.definitions.type))this.definitions.type[W]=X}),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 X=["_","-"," "],Z=(B)=>B[0].toUpperCase()+B.slice(1),Q=$==="prefix"?(B,_)=>X.includes(B.at(-1)??"")?B+_:B+Z(_):X.includes(W.at(-1)??"")?(B,_)=>_+B:(B,_)=>_+Z(B),Y=(B)=>{const _={};switch(B){case"decorator":for(let K in this.singleton.decorator)_[Q(W,K)]=this.singleton.decorator[K];this.singleton.decorator=_;break;case"state":for(let K in this.singleton.store)_[Q(W,K)]=this.singleton.store[K];this.singleton.store=_;break;case"model":for(let K in this.definitions.type)_[Q(W,K)]=this.definitions.type[K];this.definitions.type=_;break;case"error":for(let K in this.definitions.error)_[Q(W,K)]=this.definitions.error[K];this.definitions.error=_;break}},G=Array.isArray(J)?J:[J];for(let B of G.some((_)=>_==="all")?["decorator","state","model","error"]:G)Y(B);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?V1(this):C1(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?V1(this):C1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?S1(this):O$(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(!M0($))throw new Error("Port must be a numeric value");$=parseInt($)}const W=this.fetch,X=typeof $==="object"?{development:!R0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...N1||{}},fetch:W,error:this.outerErrorHandler}:{development:!R0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...N1||{}},port:$,fetch:W,error:this.outerErrorHandler};this.server=Bun?.serve(X);for(let Z=0;Z<this.event.start.length;Z++)this.event.start[Z].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let Z=0;Z<this.event.stop.length;Z++)this.event.stop[Z].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{C as t,H as mergeObjectArray,f as mergeHook,h as mapResponse,u as mapEarlyResponse,o as mapCompactResponse,k as getSchemaValidator,i0 as getResponseSchemaValidator,j1 as error,i as default,L as ValidationError,Z0 as StatusMap,e0 as ParseError,G0 as NotFoundError,n0 as InvertedStatusMap,C0 as InvalidCookieSignature,a0 as InternalServerError,i as Elysia,Y0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
429
|
+
return st${$}(ctx)`;var W1=V0(O1(),1);var C1=($)=>async(J)=>{const W=J.url,X=W.indexOf("/",11),Z=W.indexOf("?",X+1),Q=Z===-1?W.substring(X):W.substring(X,Z),G={cookie:{},status:200,headers:{}},Y=Object.assign({},$.singleton.decorator,{set:G,store:$.singleton.store,request:J,path:Q,qi:Z});try{for(let A=0;A<$.event.request.length;A++){const P=$.event.request[A].fn;let N=P(Y);if(N instanceof Promise)N=await N;if(N=u(N,G),N)return N}const B=$.router.dynamic.find(J.method,Q)??$.router.dynamic.find("ALL",Q);if(!B)throw new Y0;const{handle:_,hooks:K,validator:z,content:F}=B.store;let M;if(J.method!=="GET"&&J.method!=="HEAD")if(F)switch(F){case"application/json":M=await J.json();break;case"text/plain":M=await J.text();break;case"application/x-www-form-urlencoded":M=W1.parse(await J.text());break;case"application/octet-stream":M=await J.arrayBuffer();break;case"multipart/form-data":M={};const A=await J.formData();for(let P of A.keys()){if(M[P])continue;const N=A.getAll(P);if(N.length===1)M[P]=N[0];else M[P]=N}break}else{let A=J.headers.get("content-type");if(A){const P=A.indexOf(";");if(P!==-1)A=A.slice(0,P);for(let N=0;N<K.parse.length;N++){const L=K.parse[N].fn;let q=L(Y,A);if(q instanceof Promise)q=await q;if(q){M=q;break}}if(M===void 0)switch(A){case"application/json":M=await J.json();break;case"text/plain":M=await J.text();break;case"application/x-www-form-urlencoded":M=W1.parse(await J.text());break;case"application/octet-stream":M=await J.arrayBuffer();break;case"multipart/form-data":M={};const N=await J.formData();for(let L of N.keys()){if(M[L])continue;const q=N.getAll(L);if(q.length===1)M[L]=q[0];else M[L]=q}break}}}Y.body=M,Y.params=B?.params||void 0,Y.query=Z===-1?{}:W1.parse(W.substring(Z+1)),Y.headers={};for(let[A,P]of J.headers.entries())Y.headers[A]=P;const w=Object.assign({},$.config?.cookie,z?.cookie?.config),I=J.headers.get("cookie");Y.cookie=await l0(Y.set,I,w?{secrets:w.secrets!==void 0?typeof w.secrets==="string"?w.secrets:w.secrets.join(","):void 0,sign:w.sign===!0?!0:w.sign!==void 0?typeof w.sign==="string"?w.sign:w.sign.join(","):void 0}:void 0);for(let A=0;A<K.transform.length;A++){const P=K.transform[A],N=P.fn(Y);if(P.subType==="derive")if(N instanceof Promise)Object.assign(Y,await N);else Object.assign(Y,N);else if(N instanceof Promise)await N}if(z){if(z.headers){const A={};for(let P in J.headers)A[P]=J.headers.get(P);if(z.headers.Check(A)===!1)throw new R("header",z.headers,A)}if(z.params?.Check(Y.params)===!1)throw new R("params",z.params,Y.params);if(z.query?.Check(Y.query)===!1)throw new R("query",z.query,Y.query);if(z.cookie){const A={};for(let[P,N]of Object.entries(Y.cookie))A[P]=N.value;if(z.cookie?.Check(A)===!1)throw new R("cookie",z.cookie,A)}if(z.body?.Check(M)===!1)throw new R("body",z.body,M)}for(let A=0;A<K.beforeHandle.length;A++){let P=K.beforeHandle[A].fn(Y);if(P instanceof Promise)P=await P;if(P!==void 0){Y.response=P;for(let L=0;L<K.afterHandle.length;L++){let q=K.afterHandle[L].fn(Y);if(q instanceof Promise)q=await q;if(q)P=q}const N=u(P,Y.set);if(N)return N}}let U=_(Y);if(U instanceof Promise)U=await U;if(!K.afterHandle.length){const A=z?.response?.[U.status];if(A?.Check(U)===!1)throw new R("response",A,U)}else{Y.response=U;for(let A=0;A<K.afterHandle.length;A++){let P=K.afterHandle[A].fn(Y);if(P instanceof Promise)P=await P;const N=u(P,Y.set);if(N!==void 0){const L=z?.response?.[U.status];if(L?.Check(N)===!1)throw new R("response",L,N);return N}}}if(Y.set.cookie&&w?.sign){const A=!w.secrets?void 0:typeof w.secrets==="string"?w.secrets:w.secrets[0];if(w.sign===!0)for(let[P,N]of Object.entries(Y.set.cookie))Y.set.cookie[P].value=await j0(N.value,"${secret}");else{const P=z?.cookie?.schema?.properties;for(let N of w.sign){if(!(N in P))continue;if(Y.set.cookie[N]?.value)Y.set.cookie[N].value=await j0(Y.set.cookie[N].value,A)}}}return h(U,Y.set)}catch(B){if(B.status)G.status=B.status;return $.handleError(Y,B)}finally{for(let B of $.event.onResponse)await B.fn(Y)}},P$=($)=>async(J,W)=>{const X=Object.assign(J,{error:W,code:W.code});X.set=J.set;for(let Z=0;Z<$.event.error.length;Z++){let G=$.event.error[Z].fn(X);if(G instanceof Promise)G=await G;if(G!==void 0&&G!==null)return h(G,J.set)}return new Response(typeof W.cause==="string"?W.cause:W.message,{headers:J.set.headers,status:W.status??500})};import{TypeRegistry as T$} from"@sinclair/typebox";import{TypeSystem as I0} from"@sinclair/typebox/system";import{Type as g0,FormatRegistry as U0} from"@sinclair/typebox";import{Value as O0} from"@sinclair/typebox/value";var N8=function($){return $%4===0&&($%100!==0||$%400===0)},S$=function($){const J=P8.exec($);if(!J)return!1;const W=+J[1],X=+J[2],Z=+J[3];return X>=1&&X<=12&&Z>=1&&Z<=(X===2&&N8(W)?29:O8[X])},T1=function($){return function J(W){const X=I8.exec(W);if(!X)return!1;const Z=+X[1],Q=+X[2],G=+X[3],Y=X[4],B=X[5]==="-"?-1:1,_=+(X[6]||0),K=+(X[7]||0);if(_>23||K>59||$&&!Y)return!1;if(Z<=23&&Q<=59&&G<60)return!0;const z=Q-K*B,F=Z-_*B-(z<0?1:0);return(F===23||F===-1)&&(z===59||z===-1)&&G<61}},O$=function($){const J=T1($);return function W(X){const Z=X.split(V8);return Z.length===2&&S$(Z[0])&&J(Z[1])}},T8=function($){return S8.test($)&&C8.test($)},q8=function($){return I$.lastIndex=0,I$.test($)},E8=function($){return Number.isInteger($)&&$<=L8&&$>=R8},b8=function($){return Number.isInteger($)},V$=function(){return!0},x8=function($){if(H8.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},X1={date:S$,time:T1(!0),"date-time":O$(!0),"iso-time":T1(!1),"iso-date-time":O$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:T8,"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:x8,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:q8,int32:{type:"number",validate:E8},int64:{type:"number",validate:b8},float:{type:"number",validate:V$},double:{type:"number",validate:V$},password:!0,binary:!0},P8=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,O8=[0,31,28,31,30,31,30,31,31,30,31,30,31],I8=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,V8=/t|\s/i,S8=/\/|:/,C8=/^(?:[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,I$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,R8=-2147483648,L8=2147483647,H8=/[^\\]\\Z/;import{TypeSystemPolicy as a9,TypeSystem as e9,TypeSystemDuplicateFormat as $J,TypeSystemDuplicateTypeKind as JJ} from"@sinclair/typebox/system";import{TypeCompiler as XJ,TypeCheck as ZJ} from"@sinclair/typebox/compiler";var q$=/(\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))/,R$=/(?: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\([^)]+\)/,L$=/^(?:(?:(?:(?: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)?)?$/,g8=X1.date,y8=X1["date-time"];I0.Format("date",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||R$.test(J)||L$.test(J)||g8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});I0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||R$.test(J)||L$.test(J)||y8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});Object.entries(X1).forEach(($)=>{const[J,W]=$;if(!U0.Has(J)){if(W instanceof RegExp)I0.Format(J,(X)=>W.test(X));else if(typeof W==="function")I0.Format(J,W)}});var C=Object.assign({},g0),C$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<C$($.minSize))return!1;if($.maxSize&&J.size>C$($.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},v8=T$.Get("Files")??I0.Type("File",q1),k8=T$.Get("Files")??I0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let W=0;W<J.length;W++)if(!q1($,J[W]))return!1;return!0});if(!U0.Has("numeric"))U0.Set("numeric",($)=>!!$&&!isNaN(+$));if(!U0.Has("boolean"))U0.Set("boolean",($)=>$==="true"||$==="false");if(!U0.Has("ObjectString"))U0.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=g0.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((W)=>{const X=+W;if(isNaN(X))return W;if($&&!O0.Check(J,X))throw new R("property",J,X);return X}).Encode((W)=>W)},Date:($)=>{const J=g0.Date($);return C.Transform(C.Union([g0.Date($),C.String({format:"date",default:(new Date()).toISOString()}),C.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((W)=>{if(W instanceof Date)return W;const X=new Date(W);if(!O0.Check(J,X))throw new R("property",J,X);return X}).Encode((W)=>{if(typeof W==="string")return new Date(W);return W})},BooleanString:($)=>{const J=g0.Boolean($);return C.Transform(C.Union([C.String({format:"boolean",default:!1}),C.Boolean($)],$)).Decode((W)=>{if(typeof W==="string")return W==="true";if($&&!O0.Check(J,W))throw new R("property",J,W);return W}).Encode((W)=>W)},ObjectString:($={},J)=>{const W=C.Object($,J),X=JSON.stringify(O0.Create(W));return C.Transform(C.Union([C.String({format:"ObjectString",default:X}),W])).Decode((Z)=>{if(typeof Z==="string"){try{Z=JSON.parse(Z)}catch{throw new R("property",W,Z)}if(!O0.Check(W,Z))throw new R("property",W,Z);return Z}return Z}).Encode((Z)=>{if(typeof Z==="string")try{Z=JSON.parse(Z)}catch{throw new R("property",W,Z)}if(!O0.Check(W,Z))throw new R("property",W,Z);return JSON.stringify(Z)})},File:v8,Files:($={})=>C.Transform(k8($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,{domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:G,sameSite:Y,secure:B,secrets:_,sign:K,...z}={})=>{const F=C.Object($,z);return F.config={domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:G,sameSite:Y,secure:B,secrets:_,sign:K},F}};C.BooleanString=a.BooleanString;C.ObjectString=a.ObjectString;C.Numeric=a.Numeric;C.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>a.Nullable($);C.MaybeEmpty=a.MaybeEmpty;C.Cookie=a.Cookie;C.Date=a.Date;class i{config;server=null;dependencies={};reporter=new g1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new X0,ws:new X0,dynamic:new X0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new j1;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=e1({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 X of this.extender.macros)M1(X.fn(W),$)}}add($,J,W,X,{allowMeta:Z=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(X=$$(X),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!Q&&!this.config.scoped)J=this.config.prefix+J;if(X?.type)switch(X.type){case"text":X.type="text/plain";break;case"json":X.type="application/json";break;case"formdata":X.type="multipart/form-data";break;case"urlencoded":X.type="application/x-www-form-urlencoded";break;case"arrayBuffer":X.type="application/octet-stream";break;default:break}const G=this.definitions.type;let Y,B,_,K,z,F;const M=!this.config.aot,w={body:X?.body??this.validator?.body,headers:X?.headers??this.validator?.headers,params:X?.params??this.validator?.params,query:X?.query??this.validator?.query,cookie:X?.cookie??this.validator?.cookie,response:X?.response??this.validator?.response},I=()=>w.cookie?t0({validator:w.cookie,defaultConfig:this.config.cookie,config:w.cookie?.config??{},dynamic:M,models:G}):void 0,U=this.config.normalize,A=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(w.body,{dynamic:M,models:G,normalize:U}),headers:k(w.headers,{dynamic:M,models:G,additionalProperties:!0}),params:k(w.params,{dynamic:M,models:G}),query:k(w.query,{dynamic:M,models:G,normalize:U}),cookie:I(),response:i0(w.response,{dynamic:M,models:G,normalize:U})}:{get body(){if(Y)return Y;return Y=k(w.body,{dynamic:M,models:G,normalize:U})},get headers(){if(B)return B;return k(w.headers,{dynamic:M,models:G,additionalProperties:!0})},get params(){if(_)return _;return _=k(w.params,{dynamic:M,models:G})},get query(){if(K)return K;return K=k(w.query,{dynamic:M,models:G})},get cookie(){if(z)return z;return z=I()},get response(){if(F)return F;return F=i0(w.response,{dynamic:M,models:G,normalize:U})}},P=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(X=f(X,{},{allowMacro:!0}),X.tags)if(!X.detail)X.detail={tags:X.tags};else X.detail.tags=X.tags;if(m(this.config.detail))X.detail=p(Object.assign({},this.config.detail),X.detail);this.applyMacro(X);const N=f(this.event,X);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:A,hooks:N,content:X?.type,handle:W}),this.config.strictPath===!1)this.router.dynamic.add($,P,{validator:A,hooks:N,content:X?.type,handle:W});this.router.history.push({method:$,path:J,composed:null,handler:W,hooks:N});return}let L=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e}):(V)=>{if(L)return L(V);return(L=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e}))(V)};if(!q)v.compose=()=>{return v.composed=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e})};let n=this.router.history.length;if(this.routeTree.has($+J)){if(n=this.router.history.findIndex((V)=>V.path===J&&V.method===$),n!==-1){const V=this.router.history.splice(n,1)[0];if(V&&this.routeTree.has(V?.method+V?.path))this.routeTree.delete(V.method+V.path)}}this.routeTree.set($+J,n),this.router.history.push({method:$,path:J,composed:v,handler:W,hooks:N});const S=this.router.static.http;if($==="$INTERNALWS"){const V=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=S.handlers.length;if(S.handlers.push(v),S.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,V)this.router.static.ws[V]=$0}else if(this.router.ws.add("ws",J,v),V)this.router.ws.add("ws",V,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const V=S.handlers.length;if(S.handlers.push(v),S.variables+=q?`const st${V} = staticRouter.handlers[${V}]\n`:`let st${V} = staticRouter.handlers[${V}]\nlet stc${V}\n`,!S.map[J])S.map[J]={code:""};if($==="ALL")S.map[J].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[J].code=q?`case '${$}': return st${V}(ctx)\n${S.map[J].code}`:`case '${$}': ${x0(V)}\n${S.map[J].code}`;if(!this.config.strictPath){if(!S.map[P])S.map[P]={code:""};if($==="ALL")S.map[P].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[P].code=q?`case '${$}': return st${V}(ctx)\n${S.map[P].code}`:`case '${$}': ${x0(V)}\n${S.map[P].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",y1(()=>this.reporter,this.event.trace.length,W));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[G0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[W,X]of Object.entries($))X.prototype[G0]=W,this.definitions.error[W]=X;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 X;switch(typeof $){case"string":X=$,W=J;break;case"object":X=J;break}if(X==="response")X="onResponse";if(Array.isArray(W))W=c(W);else if(typeof W==="function")W=[{fn:W}];else W=[W];const Z=W;for(let Q of Z)Q.scope=typeof $==="string"?"local":$?.as??"local";if(X==="trace")d1(Z.map((Q)=>Q.fn),this.inference.trace);else d0({[X]:Z.map((Q)=>Q.fn)},this.inference.event);for(let Q of Z){const G=a1(Q,"global",{skipIfHasType:!0});switch(X){case"start":this.event.start.push(G);break;case"request":this.event.request.push(G);break;case"parse":this.event.parse.push(G);break;case"transform":this.event.transform.push(G);break;case"beforeHandle":this.event.beforeHandle.push(G);break;case"afterHandle":this.event.afterHandle.push(G);break;case"mapResponse":this.event.mapResponse.push(G);break;case"onResponse":this.event.onResponse.push(G);break;case"trace":this.event.trace.push(G);break;case"error":this.event.error.push(G);break;case"stop":this.event.stop.push(G);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 X=new i({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.getServer=()=>this.server,X.inference=r0(this.inference);const Z=typeof J==="object",Q=(Z?W:J)(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Q.event.request.length)this.event.request=[...this.event.request||[],...Q.event.request||[]];if(Q.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...Q.event.onResponse||[]];return this.model(Q.definitions.type),Object.values(X.router.history).forEach(({method:G,path:Y,handler:B,hooks:_})=>{if(Y=(Z?"":this.config.prefix)+$+Y,Z){const K=J,z=_;this.add(G,Y,B,f(K,{...z||{},error:!z.error?Q.event.error:Array.isArray(z.error)?[...z.error||{},...Q.event.error||{}]:[z.error,...Q.event.error||{}]}))}else this.add(G,Y,B,f(_,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=s0(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 i({...this.config,prefix:""});W.singleton={...this.singleton},W.definitions={...this.definitions},W.inference=r0(this.inference);const X=J(W);if(this.singleton=p(this.singleton,W.singleton),this.definitions=p(this.definitions,W.definitions),X.getServer=()=>this.server,X.event.request.length)this.event.request=[...this.event.request||[],...X.event.request||[]];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...X.event.onResponse||[]];return this.model(X.definitions.type),Object.values(W.router.history).forEach(({method:Z,path:Q,handler:G,hooks:Y})=>{this.add(Z,Q,G,f($,{...Y||{},error:!Y.error?X.event.error:Array.isArray(Y.error)?[...Y.error||{},...X.event.error||[]]:[Y.error,...X.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(W)=>W.use($));if(Array.isArray($)){let W=this;for(let X of $)W=this.use(X);return W}if($ instanceof Promise)return this.promisedModules.add($.then((W)=>{if(typeof W==="function")return W(this);if(W instanceof i)return this._use(W);if(typeof W.default==="function")return W.default(this);if(W.default instanceof i)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 Z=$(this);if(Z instanceof Promise)return this.promisedModules.add(Z.then((Q)=>{if(Q instanceof i){this.compile();for(let{method:G,path:Y,handler:B,hooks:_}of Object.values(Q.router.history))this.add(G,Y,B,f(_,{error:Q.event.error}));return Q}if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return Z}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((Z)=>Z.compile())),this;const{name:J,seed:W}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const X=$.config.scoped;if(X){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?R0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:G})=>Q===G))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((G)=>G.subType==="derive").map((G)=>({fn:G.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((G)=>G.subType==="derive").map((G)=>({fn:G.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<$.extender.macros.length;Q++){const G=this.extender.macros[Q];if(Z.includes(G.checksum))$.extender.macros.splice(Q,1),Q--;Z.push(G.checksum)}if($.onRequest((Q)=>{Object.assign(Q,this.singleton.decorator),Object.assign(Q.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(X===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let Q of $.event.trace)if(Q.scope&&Q.scope!=="local")this.trace(Q);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?R0(J+JSON.stringify(W)):0;if(!this.dependencies[J].some(({checksum:G})=>Q===G))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<this.extender.macros.length;Q++){const G=this.extender.macros[Q];if(G.checksum){if(Z.includes(G.checksum))this.extender.macros.splice(Q,1),Q--;Z.push(G.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:Z,path:Q,handler:G,hooks:Y}of Object.values($.router.history))this.add(Z,Q,G,f(Y,{error:$.event.error}));if(!X)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Z=W!==void 0?R0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:Q})=>Z===Q))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q?.subType==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q?.subType==="resolve").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))}),this.event=s0(this.event,A1($.event),Z)}else this.event=s0(this.event,A1($.event));return this}macro($){const J={checksum:R0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof i||typeof $==="function"||$.length===0||$==="/"){const Z=typeof $==="function"?$:$ instanceof i?$.compile().fetch:J instanceof i?J.compile().fetch:J,Q=async({request:G,path:Y})=>Z(new Request(D1(G.url,Y||"/"),G));return this.all("/*",Q,{type:"none"}),this}const W=$.length;if(J instanceof i)J=J.compile().fetch;const X=async({request:Z,path:Q})=>J(new Request(D1(Z.url,Q.slice(W)||"/"),Z));return this.all($,X,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),X,{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,X){return this.add($.toUpperCase(),J,W,X,X?.config),this}ws($,J){const W=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let X=null;const Z=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),Q=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),G=(Y)=>{if(typeof Y==="string"){const B=Y?.charCodeAt(0);if(B===47||B===123)try{Y=JSON.parse(Y)}catch{}else if(A0(Y))Y=+Y}if(W?.length)for(let B=0;B<W.length;B++){const _=W[B](Y);if(_!==void 0)Y=_}return Y};return this.route("$INTERNALWS",$,(Y)=>{const{set:B,path:_,qi:K,headers:z,query:F,params:M}=Y;if(X===null)X=this.getServer();if(X?.upgrade(Y.request,{headers:typeof J.upgrade==="function"?J.upgrade(Y):J.upgrade,data:{validator:Q,open(w){J.open?.(new w0(w,Y))},message:(w,I)=>{const U=G(I);if(Z?.Check(U)===!1)return void w.send(new R("message",Z,U).message);J.message?.(new w0(w,Y),U)},drain(w){J.drain?.(new w0(w,Y))},close(w,I,U){J.close?.(new w0(w,Y),I,U)}}}))return;return B.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,X])=>{if(!(W in this.definitions.type))this.definitions.type[W]=X}),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 X=["_","-"," "],Z=(B)=>B[0].toUpperCase()+B.slice(1),Q=$==="prefix"?(B,_)=>X.includes(B.at(-1)??"")?B+_:B+Z(_):X.includes(W.at(-1)??"")?(B,_)=>_+B:(B,_)=>_+Z(B),G=(B)=>{const _={};switch(B){case"decorator":for(let K in this.singleton.decorator)_[Q(W,K)]=this.singleton.decorator[K];this.singleton.decorator=_;break;case"state":for(let K in this.singleton.store)_[Q(W,K)]=this.singleton.store[K];this.singleton.store=_;break;case"model":for(let K in this.definitions.type)_[Q(W,K)]=this.definitions.type[K];this.definitions.type=_;break;case"error":for(let K in this.definitions.error)_[Q(W,K)]=this.definitions.error[K];this.definitions.error=_;break}},Y=Array.isArray(J)?J:[J];for(let B of Y.some((_)=>_==="all")?["decorator","state","model","error"]:Y)G(B);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?V1(this):C1(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?V1(this):C1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?S1(this):P$(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(!A0($))throw new Error("Port must be a numeric value");$=parseInt($)}const W=this.fetch,X=typeof $==="object"?{development:!L0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...N1||{}},fetch:W,error:this.outerErrorHandler}:{development:!L0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...N1||{}},port:$,fetch:W,error:this.outerErrorHandler};this.server=Bun?.serve(X);for(let Z=0;Z<this.event.start.length;Z++)this.event.start[Z].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let Z=0;Z<this.event.stop.length;Z++)this.event.stop[Z].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{C as t,H as mergeObjectArray,f as mergeHook,h as mapResponse,u as mapEarlyResponse,o as mapCompactResponse,k as getSchemaValidator,i0 as getResponseSchemaValidator,w1 as error,i as default,R as ValidationError,Z0 as StatusMap,e0 as ParseError,Y0 as NotFoundError,n0 as InvertedStatusMap,C0 as InvalidCookieSignature,a0 as InternalServerError,i as Elysia,G0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
427
430
|
|
|
428
|
-
//# debugId=
|
|
431
|
+
//# debugId=2A3322A1A3C1AD6B64756e2164756e21
|