elysia 0.8.16 → 0.8.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bun/index.js +50 -50
- package/dist/bun/index.js.map +8 -8
- package/dist/cjs/compose.js +11 -2
- package/dist/cjs/cookie.js +10 -1
- package/dist/cjs/dynamic-handle.js +10 -1
- package/dist/cjs/index.js +30 -11
- package/dist/cjs/utils.js +10 -1
- package/dist/compose.mjs +11 -2
- package/dist/cookie.mjs +10 -1
- package/dist/dynamic-handle.mjs +10 -1
- package/dist/index.mjs +30 -11
- package/dist/utils.mjs +10 -1
- package/package.json +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var X$=Object.create;var{defineProperty:z1,getPrototypeOf:W$,getOwnPropertyNames:J$}=Object;var Y$=Object.prototype.hasOwnProperty;var T0=($,Z,X)=>{X=$!=null?X$(W$($)):{};const W=Z||!$||!$.__esModule?z1(X,"default",{value:$,enumerable:!0}):X;for(let J of J$($))if(!Y$.call(W,J))z1(W,J,{get:()=>$[J],enumerable:!0});return W};var J0=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var I1=J0((m$,i0)=>{var z0=function(){},B$=function($,Z,X){this.fn=$,this.context=Z,this.once=X||!1},O1=function($,Z,X,W,J){if(typeof X!=="function")throw new TypeError("The listener must be a function");var Q=new B$(X,W||$,J),Y=f?f+Z:Z;if(!$._events[Y])$._events[Y]=Q,$._eventsCount++;else if(!$._events[Y].fn)$._events[Y].push(Q);else $._events[Y]=[$._events[Y],Q];return $},E0=function($,Z){if(--$._eventsCount===0)$._events=new z0;else delete $._events[Z]},g=function(){this._events=new z0,this._eventsCount=0},Q$=Object.prototype.hasOwnProperty,f="~";if(Object.create){if(z0.prototype=Object.create(null),!new z0().__proto__)f=!1}g.prototype.eventNames=function $(){var Z=[],X,W;if(this._eventsCount===0)return Z;for(W in X=this._events)if(Q$.call(X,W))Z.push(f?W.slice(1):W);if(Object.getOwnPropertySymbols)return Z.concat(Object.getOwnPropertySymbols(X));return Z};g.prototype.listeners=function $(Z){var X=f?f+Z:Z,W=this._events[X];if(!W)return[];if(W.fn)return[W.fn];for(var J=0,Q=W.length,Y=new Array(Q);J<Q;J++)Y[J]=W[J].fn;return Y};g.prototype.listenerCount=function $(Z){var X=f?f+Z:Z,W=this._events[X];if(!W)return 0;if(W.fn)return 1;return W.length};g.prototype.emit=function $(Z,X,W,J,Q,Y){var _=f?f+Z:Z;if(!this._events[_])return!1;var B=this._events[_],K=arguments.length,G,U;if(B.fn){if(B.once)this.removeListener(Z,B.fn,void 0,!0);switch(K){case 1:return B.fn.call(B.context),!0;case 2:return B.fn.call(B.context,X),!0;case 3:return B.fn.call(B.context,X,W),!0;case 4:return B.fn.call(B.context,X,W,J),!0;case 5:return B.fn.call(B.context,X,W,J,Q),!0;case 6:return B.fn.call(B.context,X,W,J,Q,Y),!0}for(U=1,G=new Array(K-1);U<K;U++)G[U-1]=arguments[U];B.fn.apply(B.context,G)}else{var w=B.length,A;for(U=0;U<w;U++){if(B[U].once)this.removeListener(Z,B[U].fn,void 0,!0);switch(K){case 1:B[U].fn.call(B[U].context);break;case 2:B[U].fn.call(B[U].context,X);break;case 3:B[U].fn.call(B[U].context,X,W);break;case 4:B[U].fn.call(B[U].context,X,W,J);break;default:if(!G)for(A=1,G=new Array(K-1);A<K;A++)G[A-1]=arguments[A];B[U].fn.apply(B[U].context,G)}}}return!0};g.prototype.on=function $(Z,X,W){return O1(this,Z,X,W,!1)};g.prototype.once=function $(Z,X,W){return O1(this,Z,X,W,!0)};g.prototype.removeListener=function $(Z,X,W,J){var Q=f?f+Z:Z;if(!this._events[Q])return this;if(!X)return E0(this,Q),this;var Y=this._events[Q];if(Y.fn){if(Y.fn===X&&(!J||Y.once)&&(!W||Y.context===W))E0(this,Q)}else{for(var _=0,B=[],K=Y.length;_<K;_++)if(Y[_].fn!==X||J&&!Y[_].once||W&&Y[_].context!==W)B.push(Y[_]);if(B.length)this._events[Q]=B.length===1?B[0]:B;else E0(this,Q)}return this};g.prototype.removeAllListeners=function $(Z){var X;if(Z){if(X=f?f+Z:Z,this._events[X])E0(this,X)}else this._events=new z0,this._eventsCount=0;return this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=f;g.EventEmitter=g;if(typeof i0!=="undefined")i0.exports=g});var X1=J0((D6,H1)=>{var P$=function($){var Z=$.indexOf("%");if(Z===-1)return $;var X=$.length,W="",J=0,Q=0,Y=Z,_=T1;while(Z>-1&&Z<X){var B=E1($[Z+1],4),K=E1($[Z+2],0),G=B|K,U=Z1[G];if(_=Z1[256+_+U],Q=Q<<6|G&Z1[364+U],_===T1)W+=$.slice(J,Y),W+=Q<=65535?String.fromCharCode(Q):String.fromCharCode(55232+(Q>>10),56320+(Q&1023)),Q=0,J=Z+3,Z=Y=$.indexOf("%",J);else if(_===A$)return null;else{if(Z+=3,Z<X&&$.charCodeAt(Z)===37)continue;return null}}return W+$.slice(J)},E1=function($,Z){var X=w$[$];return X===void 0?255:X<<Z},T1=12,A$=0,Z1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],w$={"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};H1.exports=P$});var f1=J0((G6,g1)=>{var V$=function($){const Z=new x1;if(typeof $!=="string")return Z;let X=$.length,W="",J="",Q=-1,Y=-1,_=!1,B=!1,K=!1,G=!1,U=!1,w=0;for(let A=0;A<X+1;A++)if(w=A!==X?$.charCodeAt(A):38,w===38){if(U=Y>Q,!U)Y=A;if(W=$.slice(Q+1,Y),U||W.length>0){if(K)W=W.replace(L1," ");if(_)W=b1(W)||W;if(U){if(J=$.slice(Y+1,A),G)J=J.replace(L1," ");if(B)J=b1(J)||J}const z=Z[W];if(z===void 0)Z[W]=J;else if(z.pop)z.push(J);else Z[W]=[z,J]}J="",Q=A,Y=A,_=!1,B=!1,K=!1,G=!1}else if(w===61)if(Y<=Q)Y=A;else B=!0;else if(w===43)if(Y>Q)G=!0;else K=!0;else if(w===37)if(Y>Q)B=!0;else _=!0;return Z},b1=X1(),L1=/\+/g,x1=function(){};x1.prototype=Object.create(null);g1.exports=V$});var v1=J0((K6,y1)=>{var C$=function($){const Z=$.length;if(Z===0)return"";let X="",W=0,J=0;$:for(;J<Z;J++){let Q=$.charCodeAt(J);while(Q<128){if(R$[Q]!==1){if(W<J)X+=$.slice(W,J);W=J+1,X+=i[Q]}if(++J===Z)break $;Q=$.charCodeAt(J)}if(W<J)X+=$.slice(W,J);if(Q<2048){W=J+1,X+=i[192|Q>>6]+i[128|Q&63];continue}if(Q<55296||Q>=57344){W=J+1,X+=i[224|Q>>12]+i[128|Q>>6&63]+i[128|Q&63];continue}if(++J,J>=Z)throw new Error("URI malformed");const Y=$.charCodeAt(J)&1023;W=J+1,Q=65536+((Q&1023)<<10|Y),X+=i[240|Q>>18]+i[128|Q>>12&63]+i[128|Q>>6&63]+i[128|Q&63]}if(W===0)return $;if(W<Z)return X+$.slice(W);return X},i=Array.from({length:256},($,Z)=>"%"+((Z<16?"0":"")+Z.toString(16)).toUpperCase()),R$=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]);y1.exports={encodeString:C$}});var u1=J0((z6,k1)=>{var m1=function($){const Z=typeof $;if(Z==="string")return W1($);else if(Z==="bigint")return $.toString();else if(Z==="boolean")return $?"true":"false";else if(Z==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:W1(""+$);return""},S$=function($){let Z="";if($===null||typeof $!=="object")return Z;const X="&",W=Object.keys($),J=W.length;let Q=0;for(let Y=0;Y<J;Y++){const _=W[Y],B=$[_],K=W1(_)+"=";if(Y)Z+=X;if(Array.isArray(B)){Q=B.length;for(let G=0;G<Q;G++){if(G)Z+=X;Z+=K,Z+=m1(B[G])}}else Z+=K,Z+=m1(B)}return Z},{encodeString:W1}=v1();k1.exports=S$});var J1=J0((U6,j0)=>{var h1=f1(),c1=u1(),d1={parse:h1,stringify:c1};j0.exports=d1;j0.exports.default=d1;j0.exports.parse=h1;j0.exports.stringify=c1});var Y0=($,Z)=>({part:$,store:null,inert:Z!==void 0?new Map(Z.map((X)=>[X.part.charCodeAt(0),X])):null,params:null,wildcardStore:null}),U1=($,Z)=>({...$,part:Z}),M1=($)=>({paramName:$,store:null,inert:null});class o{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,Z,X){if(typeof Z!=="string")throw new TypeError("Route path must be a string");if(Z==="")Z="/";else if(Z[0]!=="/")Z=`/${Z}`;this.history.push([$,Z,X]);const W=Z[Z.length-1]==="*";if(W)Z=Z.slice(0,-1);const J=Z.split(o.regex.static),Q=Z.match(o.regex.params)||[];if(J[J.length-1]==="")J.pop();let Y;if(!this.root[$])Y=this.root[$]=Y0("/");else Y=this.root[$];let _=0;for(let B=0;B<J.length;++B){let K=J[B];if(B>0){const G=Q[_++].slice(1);if(Y.params===null)Y.params=M1(G);else if(Y.params.paramName!==G)throw new Error(`Cannot create route "${Z}" with parameter "${G}" `+"because a route already exists with a different parameter name "+`("${Y.params.paramName}") in the same location`);const U=Y.params;if(U.inert===null){Y=U.inert=Y0(K);continue}Y=U.inert}for(let G=0;;){if(G===K.length){if(G<Y.part.length){const U=U1(Y,Y.part.slice(G));Object.assign(Y,Y0(K,[U]))}break}if(G===Y.part.length){if(Y.inert===null)Y.inert=new Map;else if(Y.inert.has(K.charCodeAt(G))){Y=Y.inert.get(K.charCodeAt(G)),K=K.slice(G),G=0;continue}const U=Y0(K.slice(G));Y.inert.set(K.charCodeAt(G),U),Y=U;break}if(K[G]!==Y.part[G]){const U=U1(Y,Y.part.slice(G)),w=Y0(K.slice(G));Object.assign(Y,Y0(Y.part.slice(0,G),[U,w])),Y=w;break}++G}}if(_<Q.length){const B=Q[_].slice(1);if(Y.params===null)Y.params=M1(B);else if(Y.params.paramName!==B)throw new Error(`Cannot create route "${Z}" with parameter "${B}" `+"because a route already exists with a different parameter name "+`("${Y.params.paramName}") in the same location`);if(Y.params.store===null)Y.params.store=X;return Y.params.store}if(W){if(Y.wildcardStore===null)Y.wildcardStore=X;return Y.wildcardStore}if(Y.store===null)Y.store=X;return Y.store}find($,Z){const X=this.root[$];if(!X)return null;return p0(Z,Z.length,X,0)}}var p0=($,Z,X,W)=>{const J=X?.part,Q=W+J.length;if(J.length>1){if(Q>Z)return null;if(J.length<15){for(let Y=1,_=W+1;Y<J.length;++Y,++_)if(J.charCodeAt(Y)!==$.charCodeAt(_))return null}else if($.substring(W,Q)!==J)return null}if(Q===Z){if(X.store!==null)return{store:X.store,params:{}};if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":""}};return null}if(X.inert!==null){const Y=X.inert.get($.charCodeAt(Q));if(Y!==void 0){const _=p0($,Z,Y,Q);if(_!==null)return _}}if(X.params!==null){const Y=X.params,_=$.indexOf("/",Q);if(_!==Q){if(_===-1||_>=Z){if(Y.store!==null){const B={};return B[Y.paramName]=$.substring(Q,Z),{store:Y.store,params:B}}}else if(Y.inert!==null){const B=p0($,Z,Y.inert,_);if(B!==null)return B.params[Y.paramName]=$.substring(Q,_),B}}}if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":$.substring(Q,Z)}};return null};var N1=T0(I1(),1);var F1=N1.default;var H0=()=>{let $;return[new Promise((X)=>{$=X}),$]},t=()=>{const[$,Z]=H0(),[X,W]=H0(),J=[],Q=[];return{signal:$,consume:(Y)=>{switch(Y.type){case"begin":if(Y.unit&&J.length===0)for(let _=0;_<Y.unit;_++){const[B,K]=H0(),[G,U]=H0();J.push(B),Q.push([(w)=>{K({children:[],end:G,name:w.name??"",skip:!1,time:w.time})},(w)=>{U(w)}])}Z({children:J,end:X,name:Y.name??"",skip:!1,time:Y.time});break;case"end":W(Y.time);break}},consumeChild(Y){switch(Y.type){case"begin":if(!Q[0])return;const[_]=Q[0];_({children:[],end:X,name:Y.name??"",skip:!1,time:Y.time});break;case"end":const B=Q.shift();if(!B)return;B[1](Y.time)}},resolve(){Z({children:[],end:new Promise((Y)=>Y(0)),name:"",skip:!0,time:0});for(let[Y,_]of Q)Y({children:[],end:new Promise((B)=>B(0)),name:"",skip:!0,time:0}),_(0);W(0)}}},j1=($,Z,X)=>{return async function W(W){if(W.event!=="request"||W.type!=="begin")return;const J=W.id,Q=$(),Y=t(),_=t(),B=t(),K=t(),G=t(),U=t(),w=t(),A=t();Y.consume(W);const z=(P)=>{if(P.id===J)switch(P.event){case"request":Y.consume(P);break;case"request.unit":Y.consumeChild(P);break;case"parse":_.consume(P);break;case"parse.unit":_.consumeChild(P);break;case"transform":B.consume(P);break;case"transform.unit":B.consumeChild(P);break;case"beforeHandle":K.consume(P);break;case"beforeHandle.unit":K.consumeChild(P);break;case"handle":G.consume(P);break;case"afterHandle":U.consume(P);break;case"afterHandle.unit":U.consumeChild(P);break;case"error":w.consume(P);break;case"error.unit":w.consumeChild(P);break;case"response":if(P.type==="begin")Y.resolve(),_.resolve(),B.resolve(),K.resolve(),G.resolve(),U.resolve(),w.resolve();else Q.off("event",z);A.consume(P);break;case"response.unit":A.consumeChild(P);break;case"exit":Y.resolve(),_.resolve(),B.resolve(),K.resolve(),G.resolve(),U.resolve(),w.resolve();break}};Q.on("event",z),await X({id:J,context:W.ctx,set:W.ctx?.set,store:W.ctx?.store,time:W.time,request:Y.signal,parse:_.signal,transform:B.signal,beforeHandle:K.signal,handle:G.signal,afterHandle:U.signal,error:w.signal,response:A.signal}),Q.emit(`res${J}.${Z}`,void 0)}};import{Value as e0} from"@sinclair/typebox/value";import{Kind as n0} from"@sinclair/typebox";import{Value as y0} from"@sinclair/typebox/value";import{TypeCompiler as V1} from"@sinclair/typebox/compiler";var D$=function($,Z){if(typeof $!=="string")throw new TypeError("argument str must be a string");var X={},W=Z||{},J=W.decode||K$,Q=0;while(Q<$.length){var Y=$.indexOf("=",Q);if(Y===-1)break;var _=$.indexOf(";",Q);if(_===-1)_=$.length;else if(_<Y){Q=$.lastIndexOf(";",Y-1)+1;continue}var B=$.slice(Q,Y).trim();if(X[B]===void 0){var K=$.slice(Y+1,_).trim();if(K.charCodeAt(0)===34)K=K.slice(1,-1);X[B]=M$(K,J)}Q=_+1}return X},G$=function($,Z,X){var W=X||{},J=W.encode||z$;if(typeof J!=="function")throw new TypeError("option encode is invalid");if(!b0.test($))throw new TypeError("argument name is invalid");var Q=J(Z);if(Q&&!b0.test(Q))throw new TypeError("argument val is invalid");var Y=$+"="+Q;if(W.maxAge!=null){var _=W.maxAge-0;if(isNaN(_)||!isFinite(_))throw new TypeError("option maxAge is invalid");Y+="; Max-Age="+Math.floor(_)}if(W.domain){if(!b0.test(W.domain))throw new TypeError("option domain is invalid");Y+="; Domain="+W.domain}if(W.path){if(!b0.test(W.path))throw new TypeError("option path is invalid");Y+="; Path="+W.path}if(W.expires){var B=W.expires;if(!U$(B)||isNaN(B.valueOf()))throw new TypeError("option expires is invalid");Y+="; Expires="+B.toUTCString()}if(W.httpOnly)Y+="; HttpOnly";if(W.secure)Y+="; Secure";if(W.partitioned)Y+="; Partitioned";if(W.priority){var K=typeof W.priority==="string"?W.priority.toLowerCase():W.priority;switch(K){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(W.sameSite){var G=typeof W.sameSite==="string"?W.sameSite.toLowerCase():W.sameSite;switch(G){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},K$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},z$=function($){return encodeURIComponent($)},U$=function($){return _$.call($)==="[object Date]"||$ instanceof Date},M$=function($,Z){try{return Z($)}catch(X){return $}};/*!
|
|
2
|
+
var X$=Object.create;var{defineProperty:z1,getPrototypeOf:W$,getOwnPropertyNames:J$}=Object;var Q$=Object.prototype.hasOwnProperty;var T0=($,Z,X)=>{X=$!=null?X$(W$($)):{};const W=Z||!$||!$.__esModule?z1(X,"default",{value:$,enumerable:!0}):X;for(let J of J$($))if(!Q$.call(W,J))z1(W,J,{get:()=>$[J],enumerable:!0});return W};var J0=($,Z)=>()=>(Z||$((Z={exports:{}}).exports,Z),Z.exports);var I1=J0((k$,i0)=>{var z0=function(){},B$=function($,Z,X){this.fn=$,this.context=Z,this.once=X||!1},O1=function($,Z,X,W,J){if(typeof X!=="function")throw new TypeError("The listener must be a function");var Y=new B$(X,W||$,J),Q=f?f+Z:Z;if(!$._events[Q])$._events[Q]=Y,$._eventsCount++;else if(!$._events[Q].fn)$._events[Q].push(Y);else $._events[Q]=[$._events[Q],Y];return $},E0=function($,Z){if(--$._eventsCount===0)$._events=new z0;else delete $._events[Z]},g=function(){this._events=new z0,this._eventsCount=0},Y$=Object.prototype.hasOwnProperty,f="~";if(Object.create){if(z0.prototype=Object.create(null),!new z0().__proto__)f=!1}g.prototype.eventNames=function $(){var Z=[],X,W;if(this._eventsCount===0)return Z;for(W in X=this._events)if(Y$.call(X,W))Z.push(f?W.slice(1):W);if(Object.getOwnPropertySymbols)return Z.concat(Object.getOwnPropertySymbols(X));return Z};g.prototype.listeners=function $(Z){var X=f?f+Z:Z,W=this._events[X];if(!W)return[];if(W.fn)return[W.fn];for(var J=0,Y=W.length,Q=new Array(Y);J<Y;J++)Q[J]=W[J].fn;return Q};g.prototype.listenerCount=function $(Z){var X=f?f+Z:Z,W=this._events[X];if(!W)return 0;if(W.fn)return 1;return W.length};g.prototype.emit=function $(Z,X,W,J,Y,Q){var _=f?f+Z:Z;if(!this._events[_])return!1;var B=this._events[_],K=arguments.length,G,M;if(B.fn){if(B.once)this.removeListener(Z,B.fn,void 0,!0);switch(K){case 1:return B.fn.call(B.context),!0;case 2:return B.fn.call(B.context,X),!0;case 3:return B.fn.call(B.context,X,W),!0;case 4:return B.fn.call(B.context,X,W,J),!0;case 5:return B.fn.call(B.context,X,W,J,Y),!0;case 6:return B.fn.call(B.context,X,W,J,Y,Q),!0}for(M=1,G=new Array(K-1);M<K;M++)G[M-1]=arguments[M];B.fn.apply(B.context,G)}else{var V=B.length,P;for(M=0;M<V;M++){if(B[M].once)this.removeListener(Z,B[M].fn,void 0,!0);switch(K){case 1:B[M].fn.call(B[M].context);break;case 2:B[M].fn.call(B[M].context,X);break;case 3:B[M].fn.call(B[M].context,X,W);break;case 4:B[M].fn.call(B[M].context,X,W,J);break;default:if(!G)for(P=1,G=new Array(K-1);P<K;P++)G[P-1]=arguments[P];B[M].fn.apply(B[M].context,G)}}}return!0};g.prototype.on=function $(Z,X,W){return O1(this,Z,X,W,!1)};g.prototype.once=function $(Z,X,W){return O1(this,Z,X,W,!0)};g.prototype.removeListener=function $(Z,X,W,J){var Y=f?f+Z:Z;if(!this._events[Y])return this;if(!X)return E0(this,Y),this;var Q=this._events[Y];if(Q.fn){if(Q.fn===X&&(!J||Q.once)&&(!W||Q.context===W))E0(this,Y)}else{for(var _=0,B=[],K=Q.length;_<K;_++)if(Q[_].fn!==X||J&&!Q[_].once||W&&Q[_].context!==W)B.push(Q[_]);if(B.length)this._events[Y]=B.length===1?B[0]:B;else E0(this,Y)}return this};g.prototype.removeAllListeners=function $(Z){var X;if(Z){if(X=f?f+Z:Z,this._events[X])E0(this,X)}else this._events=new z0,this._eventsCount=0;return this};g.prototype.off=g.prototype.removeListener;g.prototype.addListener=g.prototype.on;g.prefixed=f;g.EventEmitter=g;if(typeof i0!=="undefined")i0.exports=g});var X1=J0((D6,H1)=>{var A$=function($){var Z=$.indexOf("%");if(Z===-1)return $;var X=$.length,W="",J=0,Y=0,Q=Z,_=T1;while(Z>-1&&Z<X){var B=E1($[Z+1],4),K=E1($[Z+2],0),G=B|K,M=Z1[G];if(_=Z1[256+_+M],Y=Y<<6|G&Z1[364+M],_===T1)W+=$.slice(J,Q),W+=Y<=65535?String.fromCharCode(Y):String.fromCharCode(55232+(Y>>10),56320+(Y&1023)),Y=0,J=Z+3,Z=Q=$.indexOf("%",J);else if(_===P$)return null;else{if(Z+=3,Z<X&&$.charCodeAt(Z)===37)continue;return null}}return W+$.slice(J)},E1=function($,Z){var X=V$[$];return X===void 0?255:X<<Z},T1=12,P$=0,Z1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],V$={"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};H1.exports=A$});var f1=J0((G6,g1)=>{var w$=function($){const Z=new x1;if(typeof $!=="string")return Z;let X=$.length,W="",J="",Y=-1,Q=-1,_=!1,B=!1,K=!1,G=!1,M=!1,V=0;for(let P=0;P<X+1;P++)if(V=P!==X?$.charCodeAt(P):38,V===38){if(M=Q>Y,!M)Q=P;if(W=$.slice(Y+1,Q),M||W.length>0){if(K)W=W.replace(L1," ");if(_)W=b1(W)||W;if(M){if(J=$.slice(Q+1,P),G)J=J.replace(L1," ");if(B)J=b1(J)||J}const z=Z[W];if(z===void 0)Z[W]=J;else if(z.pop)z.push(J);else Z[W]=[z,J]}J="",Y=P,Q=P,_=!1,B=!1,K=!1,G=!1}else if(V===61)if(Q<=Y)Q=P;else B=!0;else if(V===43)if(Q>Y)G=!0;else K=!0;else if(V===37)if(Q>Y)B=!0;else _=!0;return Z},b1=X1(),L1=/\+/g,x1=function(){};x1.prototype=Object.create(null);g1.exports=w$});var v1=J0((K6,y1)=>{var R$=function($){const Z=$.length;if(Z===0)return"";let X="",W=0,J=0;$:for(;J<Z;J++){let Y=$.charCodeAt(J);while(Y<128){if(C$[Y]!==1){if(W<J)X+=$.slice(W,J);W=J+1,X+=i[Y]}if(++J===Z)break $;Y=$.charCodeAt(J)}if(W<J)X+=$.slice(W,J);if(Y<2048){W=J+1,X+=i[192|Y>>6]+i[128|Y&63];continue}if(Y<55296||Y>=57344){W=J+1,X+=i[224|Y>>12]+i[128|Y>>6&63]+i[128|Y&63];continue}if(++J,J>=Z)throw new Error("URI malformed");const Q=$.charCodeAt(J)&1023;W=J+1,Y=65536+((Y&1023)<<10|Q),X+=i[240|Y>>18]+i[128|Y>>12&63]+i[128|Y>>6&63]+i[128|Y&63]}if(W===0)return $;if(W<Z)return X+$.slice(W);return X},i=Array.from({length:256},($,Z)=>"%"+((Z<16?"0":"")+Z.toString(16)).toUpperCase()),C$=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]);y1.exports={encodeString:R$}});var u1=J0((z6,m1)=>{var k1=function($){const Z=typeof $;if(Z==="string")return W1($);else if(Z==="bigint")return $.toString();else if(Z==="boolean")return $?"true":"false";else if(Z==="number"&&Number.isFinite($))return $<1000000000000000000000?""+$:W1(""+$);return""},S$=function($){let Z="";if($===null||typeof $!=="object")return Z;const X="&",W=Object.keys($),J=W.length;let Y=0;for(let Q=0;Q<J;Q++){const _=W[Q],B=$[_],K=W1(_)+"=";if(Q)Z+=X;if(Array.isArray(B)){Y=B.length;for(let G=0;G<Y;G++){if(G)Z+=X;Z+=K,Z+=k1(B[G])}}else Z+=K,Z+=k1(B)}return Z},{encodeString:W1}=v1();m1.exports=S$});var J1=J0((M6,F0)=>{var h1=f1(),c1=u1(),d1={parse:h1,stringify:c1};F0.exports=d1;F0.exports.default=d1;F0.exports.parse=h1;F0.exports.stringify=c1});var Q0=($,Z)=>({part:$,store:null,inert:Z!==void 0?new Map(Z.map((X)=>[X.part.charCodeAt(0),X])):null,params:null,wildcardStore:null}),M1=($,Z)=>({...$,part:Z}),U1=($)=>({paramName:$,store:null,inert:null});class o{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g};add($,Z,X){if(typeof Z!=="string")throw new TypeError("Route path must be a string");if(Z==="")Z="/";else if(Z[0]!=="/")Z=`/${Z}`;this.history.push([$,Z,X]);const W=Z[Z.length-1]==="*";if(W)Z=Z.slice(0,-1);const J=Z.split(o.regex.static),Y=Z.match(o.regex.params)||[];if(J[J.length-1]==="")J.pop();let Q;if(!this.root[$])Q=this.root[$]=Q0("/");else Q=this.root[$];let _=0;for(let B=0;B<J.length;++B){let K=J[B];if(B>0){const G=Y[_++].slice(1);if(Q.params===null)Q.params=U1(G);else if(Q.params.paramName!==G)throw new Error(`Cannot create route "${Z}" with parameter "${G}" `+"because a route already exists with a different parameter name "+`("${Q.params.paramName}") in the same location`);const M=Q.params;if(M.inert===null){Q=M.inert=Q0(K);continue}Q=M.inert}for(let G=0;;){if(G===K.length){if(G<Q.part.length){const M=M1(Q,Q.part.slice(G));Object.assign(Q,Q0(K,[M]))}break}if(G===Q.part.length){if(Q.inert===null)Q.inert=new Map;else if(Q.inert.has(K.charCodeAt(G))){Q=Q.inert.get(K.charCodeAt(G)),K=K.slice(G),G=0;continue}const M=Q0(K.slice(G));Q.inert.set(K.charCodeAt(G),M),Q=M;break}if(K[G]!==Q.part[G]){const M=M1(Q,Q.part.slice(G)),V=Q0(K.slice(G));Object.assign(Q,Q0(Q.part.slice(0,G),[M,V])),Q=V;break}++G}}if(_<Y.length){const B=Y[_].slice(1);if(Q.params===null)Q.params=U1(B);else if(Q.params.paramName!==B)throw new Error(`Cannot create route "${Z}" with parameter "${B}" `+"because a route already exists with a different parameter name "+`("${Q.params.paramName}") in the same location`);if(Q.params.store===null)Q.params.store=X;return Q.params.store}if(W){if(Q.wildcardStore===null)Q.wildcardStore=X;return Q.wildcardStore}if(Q.store===null)Q.store=X;return Q.store}find($,Z){const X=this.root[$];if(!X)return null;return p0(Z,Z.length,X,0)}}var p0=($,Z,X,W)=>{const J=X?.part,Y=W+J.length;if(J.length>1){if(Y>Z)return null;if(J.length<15){for(let Q=1,_=W+1;Q<J.length;++Q,++_)if(J.charCodeAt(Q)!==$.charCodeAt(_))return null}else if($.substring(W,Y)!==J)return null}if(Y===Z){if(X.store!==null)return{store:X.store,params:{}};if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":""}};return null}if(X.inert!==null){const Q=X.inert.get($.charCodeAt(Y));if(Q!==void 0){const _=p0($,Z,Q,Y);if(_!==null)return _}}if(X.params!==null){const Q=X.params,_=$.indexOf("/",Y);if(_!==Y){if(_===-1||_>=Z){if(Q.store!==null){const B={};return B[Q.paramName]=$.substring(Y,Z),{store:Q.store,params:B}}}else if(Q.inert!==null){const B=p0($,Z,Q.inert,_);if(B!==null)return B.params[Q.paramName]=$.substring(Y,_),B}}}if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":$.substring(Y,Z)}};return null};var j1=T0(I1(),1);var N1=j1.default;var H0=()=>{let $;return[new Promise((X)=>{$=X}),$]},s=()=>{const[$,Z]=H0(),[X,W]=H0(),J=[],Y=[];return{signal:$,consume:(Q)=>{switch(Q.type){case"begin":if(Q.unit&&J.length===0)for(let _=0;_<Q.unit;_++){const[B,K]=H0(),[G,M]=H0();J.push(B),Y.push([(V)=>{K({children:[],end:G,name:V.name??"",skip:!1,time:V.time})},(V)=>{M(V)}])}Z({children:J,end:X,name:Q.name??"",skip:!1,time:Q.time});break;case"end":W(Q.time);break}},consumeChild(Q){switch(Q.type){case"begin":if(!Y[0])return;const[_]=Y[0];_({children:[],end:X,name:Q.name??"",skip:!1,time:Q.time});break;case"end":const B=Y.shift();if(!B)return;B[1](Q.time)}},resolve(){Z({children:[],end:new Promise((Q)=>Q(0)),name:"",skip:!0,time:0});for(let[Q,_]of Y)Q({children:[],end:new Promise((B)=>B(0)),name:"",skip:!0,time:0}),_(0);W(0)}}},F1=($,Z,X)=>{return async function W(W){if(W.event!=="request"||W.type!=="begin")return;const J=W.id,Y=$(),Q=s(),_=s(),B=s(),K=s(),G=s(),M=s(),V=s(),P=s();Q.consume(W);const z=(A)=>{if(A.id===J)switch(A.event){case"request":Q.consume(A);break;case"request.unit":Q.consumeChild(A);break;case"parse":_.consume(A);break;case"parse.unit":_.consumeChild(A);break;case"transform":B.consume(A);break;case"transform.unit":B.consumeChild(A);break;case"beforeHandle":K.consume(A);break;case"beforeHandle.unit":K.consumeChild(A);break;case"handle":G.consume(A);break;case"afterHandle":M.consume(A);break;case"afterHandle.unit":M.consumeChild(A);break;case"error":V.consume(A);break;case"error.unit":V.consumeChild(A);break;case"response":if(A.type==="begin")Q.resolve(),_.resolve(),B.resolve(),K.resolve(),G.resolve(),M.resolve(),V.resolve();else Y.off("event",z);P.consume(A);break;case"response.unit":P.consumeChild(A);break;case"exit":Q.resolve(),_.resolve(),B.resolve(),K.resolve(),G.resolve(),M.resolve(),V.resolve();break}};Y.on("event",z),await X({id:J,context:W.ctx,set:W.ctx?.set,store:W.ctx?.store,time:W.time,request:Q.signal,parse:_.signal,transform:B.signal,beforeHandle:K.signal,handle:G.signal,afterHandle:M.signal,error:V.signal,response:P.signal}),Y.emit(`res${J}.${Z}`,void 0)}};import{Value as e0} from"@sinclair/typebox/value";import{Kind as n0} from"@sinclair/typebox";import{Value as y0} from"@sinclair/typebox/value";import{TypeCompiler as w1} from"@sinclair/typebox/compiler";var D$=function($,Z){if(typeof $!=="string")throw new TypeError("argument str must be a string");var X={},W=Z||{},J=W.decode||K$,Y=0;while(Y<$.length){var Q=$.indexOf("=",Y);if(Q===-1)break;var _=$.indexOf(";",Y);if(_===-1)_=$.length;else if(_<Q){Y=$.lastIndexOf(";",Q-1)+1;continue}var B=$.slice(Y,Q).trim();if(X[B]===void 0){var K=$.slice(Q+1,_).trim();if(K.charCodeAt(0)===34)K=K.slice(1,-1);X[B]=U$(K,J)}Y=_+1}return X},G$=function($,Z,X){var W=X||{},J=W.encode||z$;if(typeof J!=="function")throw new TypeError("option encode is invalid");if(!b0.test($))throw new TypeError("argument name is invalid");var Y=J(Z);if(Y&&!b0.test(Y))throw new TypeError("argument val is invalid");var Q=$+"="+Y;if(W.maxAge!=null){var _=W.maxAge-0;if(isNaN(_)||!isFinite(_))throw new TypeError("option maxAge is invalid");Q+="; Max-Age="+Math.floor(_)}if(W.domain){if(!b0.test(W.domain))throw new TypeError("option domain is invalid");Q+="; Domain="+W.domain}if(W.path){if(!b0.test(W.path))throw new TypeError("option path is invalid");Q+="; Path="+W.path}if(W.expires){var B=W.expires;if(!M$(B)||isNaN(B.valueOf()))throw new TypeError("option expires is invalid");Q+="; Expires="+B.toUTCString()}if(W.httpOnly)Q+="; HttpOnly";if(W.secure)Q+="; Secure";if(W.partitioned)Q+="; Partitioned";if(W.priority){var K=typeof W.priority==="string"?W.priority.toLowerCase():W.priority;switch(K){case"low":Q+="; Priority=Low";break;case"medium":Q+="; Priority=Medium";break;case"high":Q+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(W.sameSite){var G=typeof W.sameSite==="string"?W.sameSite.toLowerCase():W.sameSite;switch(G){case!0:Q+="; SameSite=Strict";break;case"lax":Q+="; SameSite=Lax";break;case"strict":Q+="; SameSite=Strict";break;case"none":Q+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return Q},K$=function($){return $.indexOf("%")!==-1?decodeURIComponent($):$},z$=function($){return encodeURIComponent($)},M$=function($){return _$.call($)==="[object Date]"||$ instanceof Date},U$=function($,Z){try{return Z($)}catch(X){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 L0=D$,x0=G$;var _$=Object.prototype.toString,b0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;class k{$;Z;name;setter;constructor($,Z={}){this._value=$;this.property=Z}get(){return this._value}get value(){return this._value}set value($){if(typeof $==="object"){if(JSON.stringify(this.value)===JSON.stringify($))return}else if(this.value===$)return;this._value=$,this.sync()}add($){const Z=Object.assign(this.property,typeof $==="function"?$(Object.assign(this.property,this.value)):$);if("value"in Z)this._value=Z.value,delete Z.value;return this.property=Z,this.sync()}set($){const Z=typeof $==="function"?$(Object.assign(this.property,this.value)):$;if("value"in Z)this._value=Z.value,delete Z.value;return this.property=Z,this.sync()}remove($){if(this.value===void 0)return;this.set({domain:$?.domain,expires:new Date(0),maxAge:0,path:$?.path,sameSite:$?.sameSite,secure:$?.secure,value:""})}get domain(){return this.property.domain}set domain($){if(this.property.domain===$)return;this.property.domain=$,this.sync()}get expires(){return this.property.expires}set expires($){if(this.property.expires?.getTime()===$?.getTime())return;this.property.expires=$,this.sync()}get httpOnly(){return this.property.httpOnly}set httpOnly($){if(this.property.domain===$)return;this.property.httpOnly=$,this.sync()}get maxAge(){return this.property.maxAge}set maxAge($){if(this.property.maxAge===$)return;this.property.maxAge=$,this.sync()}get path(){return this.property.path}set path($){if(this.property.path===$)return;this.property.path=$,this.sync()}get priority(){return this.property.priority}set priority($){if(this.property.priority===$)return;this.property.priority=$,this.sync()}get sameSite(){return this.property.sameSite}set sameSite($){if(this.property.sameSite===$)return;this.property.sameSite=$,this.sync()}get secure(){return this.property.secure}set secure($){if(this.property.secure===$)return;this.property.secure=$,this.sync()}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}sync(){if(!this.name||!this.setter)return this;if(!this.setter.cookie)this.setter.cookie={[this.name]:Object.assign(this.property,{value:this.toString()})};else this.setter.cookie[this.name]=Object.assign(this.property,{value:this.toString()});return this}}var A1=($,Z,X)=>new Proxy($,{get(W,J){if(J in W)return W[J];const Q=new k(void 0,X?{...X}:void 0);return Q.setter=Z,Q.name=J,Q},set(W,J,Q){if(!(Q instanceof k))return!1;if(!Z.cookie)Z.cookie={};return Q.setter=Z,Q.name=J,Q.sync(),W[J]=Q,!0}}),g0=async($,Z,{secret:X,sign:W,...J}={})=>{if(!Z)return A1({},$,J);const Q={},Y=typeof X==="string";if(W&&W!==!0&&!Array.isArray(W))W=[W];const _=Object.keys(L0(Z));for(let B=0;B<_.length;B++){const K=_[B];let G=L0(Z)[K];if(W===!0||W?.includes(K)){if(!X)throw new Error("No secret is provided to cookie plugin");if(Y){if(G=await l0(G,X),G===!1)throw new U0(K)}else{let A=!0;for(let z=0;z<X.length;z++){const P=await l0(G,X[z]);if(P!==!1){G=P,A=!1;break}}if(A)throw new U0(K)}}if(G===void 0)continue;const U=G.charCodeAt(0);if(U===123||U===91)try{const A=new k(JSON.parse(G));A.setter=$,A.name=K,Q[K]=A;continue}catch{}if(f0(G))G=+G;else if(G==="true")G=!0;else if(G==="false")G=!1;const w=new k(G,J);w.setter=$,w.name=K,Q[K]=w}return A1(Q,$)};var M0="toJSON"in new Headers,u=($)=>{for(let Z in $)return!0;return!1},O0=($,Z)=>{const X=$.size;if(X&&Z&&Z.status!==206&&Z.status!==304&&Z.status!==412&&Z.status!==416||!Z&&X){if(Z){if(Z.headers instanceof Headers){if(M0)Z.headers=Z.headers.toJSON();else for(let[W,J]of Z.headers.entries())if(W in Z.headers)Z.headers[W]=J}return new Response($,{status:Z.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`},Z.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`}})}return new Response($)},P1=($,Z)=>{if(!$||!Array.isArray(Z))return $;$.delete("Set-Cookie");for(let X=0;X<Z.length;X++){const W=Z[X].indexOf("=");$.append("Set-Cookie",`${Z[X].slice(0,W)}=${Z[X].slice(W+1)}`)}return $},w1=($)=>{if(!$||typeof $!=="object"||!u($))return;const Z=[];for(let[X,W]of Object.entries($)){if(!X||!W)continue;if(Array.isArray(W.value))for(let J=0;J<W.value.length;J++){let Q=W.value[J];if(Q===void 0||Q===null)continue;if(typeof Q==="object")Q=JSON.stringify(Q);Z.push(x0(X,Q,W))}else{let J=W.value;if(J===void 0||J===null)continue;if(typeof J==="object")J=JSON.stringify(J);Z.push(x0(X,W.value,W))}}if(Z.length===0)return;if(Z.length===1)return Z[0];return Z},v=($,Z)=>{if($?.[$.$passthrough])$=$[$.$passthrough];if($?.[c])Z.status=$[c],$=$.response;if(u(Z.headers)||Z.status!==200||Z.redirect||Z.cookie){if(typeof Z.status==="string")Z.status=I0[Z.status];if(Z.redirect){if(Z.headers.Location=Z.redirect,!Z.status||Z.status<300||Z.status>=400)Z.status=302}if(Z.cookie&&u(Z.cookie))Z.headers["Set-Cookie"]=w1(Z.cookie);if(Z.headers["Set-Cookie"]&&Array.isArray(Z.headers["Set-Cookie"]))Z.headers=P1(new Headers(Z.headers),Z.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,Z);case"Blob":return O0($,Z);case"Object":case"Array":return Response.json($,Z);case"ReadableStream":if(!Z.headers["content-type"]?.startsWith("text/event-stream"))Z.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Z);case void 0:if(!$)return new Response("",Z);return Response.json($,Z);case"Response":const X={...Z.headers};if(M0)Z.headers=$.headers.toJSON();else for(let[J,Q]of $.headers.entries())if(J in Z.headers)Z.headers[J]=Q;for(let J in X)$.headers.append(J,X[J]);return $;case"Error":return h($,Z);case"Promise":return $.then((J)=>v(J,Z));case"Function":return v($(),Z);case"Number":case"Boolean":return new Response($.toString(),Z);case"Cookie":if($ instanceof k)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response){const J={...Z.headers};if(M0)Z.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in Z.headers)Z.headers[Q]=Y;for(let Q in J)$.headers.append(Q,J[Q]);return $}if($ instanceof Promise)return $.then((J)=>v(J,Z));if($ instanceof Error)return h($,Z);const W=JSON.stringify($);if(W.charCodeAt(0)===123){if(!Z.headers["Content-Type"])Z.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Z)}return new Response(W,Z)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($,Z);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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 h($,Z);case"Promise":return $.then((W)=>{const J=l(W);if(J!==void 0)return J;return new Response("")});case"Function":return l($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof k)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((W)=>v(W,Z));if($ instanceof Error)return h($,Z);const X=JSON.stringify($);if(X.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(X)}},y=($,Z)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$[$.$passthrough];if($?.[c])Z.status=$[c],$=$.response;if(u(Z.headers)||Z.status!==200||Z.redirect||Z.cookie){if(typeof Z.status==="string")Z.status=I0[Z.status];if(Z.redirect){if(Z.headers.Location=Z.redirect,!Z.status||Z.status<300||Z.status>=400)Z.status=302}if(Z.cookie&&u(Z.cookie))Z.headers["Set-Cookie"]=w1(Z.cookie);if(Z.headers["Set-Cookie"]&&Array.isArray(Z.headers["Set-Cookie"]))Z.headers=P1(new Headers(Z.headers),Z.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,Z);case"Blob":return O0($,Z);case"Object":case"Array":return Response.json($,Z);case"ReadableStream":if(!Z.headers["content-type"]?.startsWith("text/event-stream"))Z.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Z);case void 0:if(!$)return;return Response.json($,Z);case"Response":const X=Object.assign({},Z.headers);if(M0)Z.headers=$.headers.toJSON();else for(let[J,Q]of $.headers.entries())if(!(J in Z.headers))Z.headers[J]=Q;for(let J in X)$.headers.append(J,X[J]);if($.status!==Z.status)Z.status=$.status;return $;case"Promise":return $.then((J)=>{const Q=y(J,Z);if(Q!==void 0)return Q;return});case"Error":return h($,Z);case"Function":return y($(),Z);case"Number":case"Boolean":return new Response($.toString(),Z);case"Cookie":if($ instanceof k)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response){const J={...Z.headers};if(M0)Z.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in Z.headers)Z.headers[Q]=Y;for(let Q in J)$.headers.append(Q,J[Q]);return $}if($ instanceof Promise)return $.then((J)=>y(J,Z));if($ instanceof Error)return h($,Z);const W=JSON.stringify($);if(W.charCodeAt(0)===123){if(!Z.headers["Content-Type"])Z.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Z)}return new Response(W,Z)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($,Z);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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((W)=>{const J=y(W,Z);if(J!==void 0)return J;return});case"Error":return h($,Z);case"Function":return l($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof k)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((W)=>y(W,Z));if($ instanceof Error)return h($,Z);const X=JSON.stringify($);if(X.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(X)}},l=($)=>{if($?.$passthrough)$=$[$.$passthrough];if($?.[c])return v($.response,{status:$[c],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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 h($);case"Promise":return $.then(l);case"Function":return l($());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(l);if($ instanceof Error)return h($);const Z=JSON.stringify($);if(Z.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(Z)}},h=($,Z)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:Z?.status!==200?Z?.status??500:500,headers:Z?.headers});var r0=($)=>$&&typeof $==="object"&&!Array.isArray($),t0=($,Z)=>{const X=new URL($);return X.pathname=Z,X.toString()},O$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||u(Object.getPrototypeOf($)),d=($,Z,{skipKeys:X}={})=>{if(r0($)&&r0(Z))for(let[W,J]of Object.entries(Z)){if(X?.includes(W))continue;if(!r0(J)){$[W]=J;continue}if(!(W in $)){$[W]=J;continue}if(O$(J)){$[W]=J;continue}$[W]=d($[W],J)}return $},R1=($,Z)=>d($,Z,{skipKeys:["properties"]}),H=($,Z)=>{if(!$)return[];const X=[...Array.isArray($)?$:[$]],W=[];for(let J of X)if(J.$elysiaChecksum)W.push(J.$elysiaChecksum);for(let J of Array.isArray(Z)?Z:[Z])if(!W.includes(J?.$elysiaChecksum))X.push(J);return X},I$=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],s=($,Z)=>{return{...$,...Z,body:Z?.body??$?.body,headers:Z?.headers??$?.headers,params:Z?.params??$?.params,query:Z?.query??$?.query,response:Z?.response??$?.response,type:$?.type||Z?.type,detail:d(Z?.detail??{},$?.detail??{}),parse:H($?.parse??[],Z?.parse??[]),transform:H($?.transform??[],Z?.transform??[]),beforeHandle:H($?.beforeHandle??[],Z?.beforeHandle??[]),afterHandle:H($?.afterHandle??[],Z?.afterHandle??[]),onResponse:H($?.onResponse??[],Z?.onResponse??[]),mapResponse:H($?.mapResponse??[],Z?.mapResponse??[]),trace:H($?.trace??[],Z?.trace??[]),error:H($?.error??[],Z?.error??[])}},p=($,{models:Z={},additionalProperties:X=!1,dynamic:W=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Z))return;const J=typeof $==="string"?Z[$]:$;if(J.type==="object"&&"additionalProperties"in J===!1)J.additionalProperties=X;if(W)return{schema:J,references:"",checkFunc:()=>{},code:"",Check:(Q)=>y0.Check(J,Q),Errors:(Q)=>y0.Errors(J,Q),Code:()=>""};return V1.Compile(J,Object.values(Z))},s0=($,{models:Z={},additionalProperties:X=!1,dynamic:W=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Z))return;const J=typeof $==="string"?Z[$]:$,Q=(_,B)=>{if(W)return{schema:_,references:"",checkFunc:()=>{},code:"",Check:(K)=>y0.Check(_,K),Errors:(K)=>y0.Errors(_,K),Code:()=>""};return V1.Compile(_,B)};if(n0 in J){if("additionalProperties"in J===!1)J.additionalProperties=X;return{200:Q(J,Object.values(Z))}}const Y={};return Object.keys(J).forEach((_)=>{const B=J[+_];if(typeof B==="string"){if(B in Z){const K=Z[B];K.type==="object"&&"additionalProperties"in K,Y[+_]=n0 in K?Q(K,Object.values(Z)):K}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=X;Y[+_]=n0 in B?Q(B,Object.values(Z)):B}),Y},N$=typeof Bun!=="undefined",F$=N$&&typeof Bun.hash==="function",N0=($)=>{if(F$)return Bun.hash($);let Z=9;for(let X=0;X<$.length;)Z=Math.imul(Z^$.charCodeAt(X++),387420489);return Z=Z^Z>>>9},v0=($,Z,X)=>{const W=(J)=>{if(X&&!J.$elysiaChecksum)J.$elysiaChecksum=X;return J};return{...$,...Z,start:H($.start,("start"in Z?Z.start??[]:[]).map(W)),request:H($.request,("request"in Z?Z.request??[]:[]).map(W)),parse:H($.parse,"parse"in Z?Z?.parse??[]:[]).map(W),transform:H($.transform,(Z?.transform??[]).map(W)),beforeHandle:H($.beforeHandle,(Z?.beforeHandle??[]).map(W)),afterHandle:H($.afterHandle,(Z?.afterHandle??[]).map(W)),mapResponse:H($.mapResponse,(Z?.mapResponse??[]).map(W)),onResponse:H($.onResponse,(Z?.onResponse??[]).map(W)),trace:$.trace,error:H($.error,(Z?.error??[]).map(W)),stop:H($.stop,("stop"in Z?Z.stop??[]:[]).map(W))}};var C1=($,Z=!0)=>{if(!$)return $;if(typeof $==="function"){if(Z)$.$elysiaHookType="global";else $.$elysiaHookType=void 0;return $}return $.map((X)=>{if(Z)X.$elysiaHookType="global";else X.$elysiaHookType=void 0;return X})},Q0=($)=>{if(!$)return $;if(typeof $==="function")return $.$elysiaHookType==="global"?$:void 0;return $.filter((Z)=>Z.$elysiaHookType==="global")},a0=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:Q0($?.parse),transform:Q0($?.transform),beforeHandle:Q0($?.beforeHandle),afterHandle:Q0($?.afterHandle),onResponse:Q0($?.onResponse),error:Q0($?.error)}},I0={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},B0=async($,Z)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(Z===null)throw new TypeError("Secret key must be provided.");const X=new TextEncoder,W=await crypto.subtle.importKey("raw",X.encode(Z),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),J=await crypto.subtle.sign("HMAC",W,X.encode($)),Q=Array.from(new Uint8Array(J)),Y=btoa(String.fromCharCode(...Q));return`${$}.${Y.replace(/=+$/,"")}`},l0=async($,Z)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(Z===null)throw new TypeError("Secret key must be provided.");const X=$.slice(0,$.lastIndexOf("."));return await B0(X,Z)===$?X:!1},o0=($,Z,X=Z)=>{for(let[W,J]of Object.entries(Z??{})){if(I$.includes(W)||!(W in $))continue;if(typeof $[W]==="function")$[W](J);else if(typeof $[W]==="object")o0($[W],J,X)}},f0=($)=>$.trim().length!==0&&!Number.isNaN(Number($));var S1=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,_0=Symbol("ElysiaErrorCode"),c=Symbol("ElysiaResponse"),F0=(S1?.NODE_ENV??S1?.ENV)==="production",j$=($,Z)=>({[c]:I0[$]??$,response:Z});class m0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class e extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class q1 extends Error{code="PARSE";status=400;constructor($){super($??"PARSE")}}class U0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,Z){super(Z??`"${$}" has invalid cookie signature`);this.key=$}}class q extends Error{$;Z;X;code="VALIDATION";status=400;constructor($,Z,X){const W=F0?void 0:("Errors"in Z)?Z.Errors(X).First():e0.Errors(Z,X).First(),J=W?.schema.error?typeof W.schema.error==="function"?W.schema.error($,Z,X):W.schema.error:void 0,Q=W?.path?.slice(1)||"root";let Y="";if(J)Y=typeof J==="object"?JSON.stringify(J):J+"";else if(F0)Y=JSON.stringify({type:$,message:W?.message});else Y=JSON.stringify({type:$,at:Q,message:W?.message,expected:e0.Create(Z.schema),found:X,errors:[...Z.Errors(X)]},null,2);super(Y);this.type=$;this.validator=Z;this.value=X;Object.setPrototypeOf(this,q.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const Z="schema"in $?$.schema:$;try{return e0.Create(Z)}catch{return Z}}get model(){return q.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:$})}}var $1={open($){$.data.open?.($)},message($,Z){$.data.message?.($,Z)},drain($){$.data.drain?.($)},close($,Z,X){$.data.close?.($,Z,X)}};class D0{$;Z;validator;constructor($,Z){this.raw=$;this.data=Z;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else{const X=new Uint32Array(1);crypto.getRandomValues(X),this.id=X[0].toString()}}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,Z=void 0,X)=>{if(this.validator?.Check(Z)===!1)throw new q("message",this.validator,Z);if(typeof Z==="object")Z=JSON.stringify(Z);return this.raw.publish($,Z,X),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new q("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var p1=T0(J1(),1),i1=T0(X1(),1);import{Value as A0} from"@sinclair/typebox/value";var q$=(new Headers()).toJSON,l1=new RegExp(" (\\w+) = context","g"),n1={value:0},r1=({hasTrace:$,hasTraceSet:Z=!1,addFn:X,condition:W={}})=>{if($)return X("\nconst reporter = getReporter()\n"),(J,{name:Q,attribute:Y="",unit:_=0}={})=>{const B=J.indexOf("."),K=B===-1;if(J!=="request"&&J!=="response"&&!W[K?J:J.slice(0,B)])return()=>{if(Z&&J==="afterHandle")X("\nawait traceDone\n")};if(K)Q||=J;else Q||="anonymous";X("\n"+`reporter.emit('event', {
|
|
7
|
+
*/var L0=D$,x0=G$;var _$=Object.prototype.toString,b0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;class m{$;Z;name;setter;constructor($,Z={}){this._value=$;this.property=Z}get(){return this._value}get value(){return this._value}set value($){if(typeof $==="object"){if(JSON.stringify(this.value)===JSON.stringify($))return}else if(this.value===$)return;this._value=$,this.sync()}add($){const Z=Object.assign(this.property,typeof $==="function"?$(Object.assign(this.property,this.value)):$);if("value"in Z)this._value=Z.value,delete Z.value;return this.property=Z,this.sync()}set($){const Z=typeof $==="function"?$(Object.assign(this.property,this.value)):$;if("value"in Z)this._value=Z.value,delete Z.value;return this.property=Z,this.sync()}remove($){if(this.value===void 0)return;this.set({domain:$?.domain,expires:new Date(0),maxAge:0,path:$?.path,sameSite:$?.sameSite,secure:$?.secure,value:""})}get domain(){return this.property.domain}set domain($){if(this.property.domain===$)return;this.property.domain=$,this.sync()}get expires(){return this.property.expires}set expires($){if(this.property.expires?.getTime()===$?.getTime())return;this.property.expires=$,this.sync()}get httpOnly(){return this.property.httpOnly}set httpOnly($){if(this.property.domain===$)return;this.property.httpOnly=$,this.sync()}get maxAge(){return this.property.maxAge}set maxAge($){if(this.property.maxAge===$)return;this.property.maxAge=$,this.sync()}get path(){return this.property.path}set path($){if(this.property.path===$)return;this.property.path=$,this.sync()}get priority(){return this.property.priority}set priority($){if(this.property.priority===$)return;this.property.priority=$,this.sync()}get sameSite(){return this.property.sameSite}set sameSite($){if(this.property.sameSite===$)return;this.property.sameSite=$,this.sync()}get secure(){return this.property.secure}set secure($){if(this.property.secure===$)return;this.property.secure=$,this.sync()}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}sync(){if(!this.name||!this.setter)return this;if(!this.setter.cookie)this.setter.cookie={[this.name]:Object.assign(this.property,{value:this.toString()})};else this.setter.cookie[this.name]=Object.assign(this.property,{value:this.toString()});return this}}var P1=($,Z,X)=>new Proxy($,{get(W,J){if(J in W)return W[J];const Y=new m(void 0,X?{...X}:void 0);return Y.setter=Z,Y.name=J,Y},set(W,J,Y){if(!(Y instanceof m))return!1;if(!Z.cookie)Z.cookie={};return Y.setter=Z,Y.name=J,Y.sync(),W[J]=Y,!0}}),g0=async($,Z,{secret:X,sign:W,...J}={})=>{if(!Z)return P1({},$,J);const Y={},Q=typeof X==="string";if(W&&W!==!0&&!Array.isArray(W))W=[W];const _=Object.keys(L0(Z));for(let B=0;B<_.length;B++){const K=_[B];let G=L0(Z)[K];if(W===!0||W?.includes(K)){if(!X)throw new Error("No secret is provided to cookie plugin");if(Q){if(G=await l0(G,X),G===!1)throw new M0(K)}else{let P=!0;for(let z=0;z<X.length;z++){const A=await l0(G,X[z]);if(A!==!1){G=A,P=!1;break}}if(P)throw new M0(K)}}if(G===void 0)continue;const M=G.charCodeAt(0);if(M===123||M===91)try{const P=new m(JSON.parse(G));P.setter=$,P.name=K,Y[K]=P;continue}catch{}if(f0(G))G=+G;else if(G==="true")G=!0;else if(G==="false")G=!1;const V=new m(G,J);V.setter=$,V.name=K,Y[K]=V}return P1(Y,$)};var U0="toJSON"in new Headers,u=($)=>{for(let Z in $)return!0;return!1},O0=($,Z)=>{const X=$.size;if(X&&Z&&Z.status!==206&&Z.status!==304&&Z.status!==412&&Z.status!==416||!Z&&X){if(Z){if(Z.headers instanceof Headers){if(U0)Z.headers=Z.headers.toJSON();else for(let[W,J]of Z.headers.entries())if(W in Z.headers)Z.headers[W]=J}return new Response($,{status:Z.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`},Z.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`}})}return new Response($)},A1=($,Z)=>{if(!$||!Array.isArray(Z))return $;$.delete("Set-Cookie");for(let X=0;X<Z.length;X++){const W=Z[X].indexOf("=");$.append("Set-Cookie",`${Z[X].slice(0,W)}=${Z[X].slice(W+1)}`)}return $},V1=($)=>{if(!$||typeof $!=="object"||!u($))return;const Z=[];for(let[X,W]of Object.entries($)){if(!X||!W)continue;if(Array.isArray(W.value))for(let J=0;J<W.value.length;J++){let Y=W.value[J];if(Y===void 0||Y===null)continue;if(typeof Y==="object")Y=JSON.stringify(Y);Z.push(x0(X,Y,W))}else{let J=W.value;if(J===void 0||J===null)continue;if(typeof J==="object")J=JSON.stringify(J);Z.push(x0(X,W.value,W))}}if(Z.length===0)return;if(Z.length===1)return Z[0];return Z},v=($,Z)=>{if($?.[$.$passthrough])$=$[$.$passthrough];if($?.[c])Z.status=$[c],$=$.response;if(u(Z.headers)||Z.status!==200||Z.redirect||Z.cookie){if(typeof Z.status==="string")Z.status=I0[Z.status];if(Z.redirect){if(Z.headers.Location=Z.redirect,!Z.status||Z.status<300||Z.status>=400)Z.status=302}if(Z.cookie&&u(Z.cookie))Z.headers["Set-Cookie"]=V1(Z.cookie);if(Z.headers["Set-Cookie"]&&Array.isArray(Z.headers["Set-Cookie"]))Z.headers=A1(new Headers(Z.headers),Z.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,Z);case"Blob":return O0($,Z);case"Object":case"Array":return Response.json($,Z);case"ReadableStream":if(!Z.headers["content-type"]?.startsWith("text/event-stream"))Z.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Z);case void 0:if(!$)return new Response("",Z);return Response.json($,Z);case"Response":const X={...Z.headers};if(U0)Z.headers=$.headers.toJSON();else for(let[J,Y]of $.headers.entries())if(J in Z.headers)Z.headers[J]=Y;for(let J in X)$.headers.append(J,X[J]);return $;case"Error":return h($,Z);case"Promise":return $.then((J)=>v(J,Z));case"Function":return v($(),Z);case"Number":case"Boolean":return new Response($.toString(),Z);case"Cookie":if($ instanceof m)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response){const J={...Z.headers};if(U0)Z.headers=$.headers.toJSON();else for(let[Y,Q]of $.headers.entries())if(Y in Z.headers)Z.headers[Y]=Q;for(let Y in J)$.headers.append(Y,J[Y]);return $}if($ instanceof Promise)return $.then((J)=>v(J,Z));if($ instanceof Error)return h($,Z);const W=JSON.stringify($);if(W.charCodeAt(0)===123){if(!Z.headers["Content-Type"])Z.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Z)}return new Response(W,Z)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($,Z);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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 h($,Z);case"Promise":return $.then((W)=>{const J=l(W);if(J!==void 0)return J;return new Response("")});case"Function":return l($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof m)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((W)=>v(W,Z));if($ instanceof Error)return h($,Z);const X=JSON.stringify($);if(X.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(X)}},y=($,Z)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$[$.$passthrough];if($?.[c])Z.status=$[c],$=$.response;if(u(Z.headers)||Z.status!==200||Z.redirect||Z.cookie){if(typeof Z.status==="string")Z.status=I0[Z.status];if(Z.redirect){if(Z.headers.Location=Z.redirect,!Z.status||Z.status<300||Z.status>=400)Z.status=302}if(Z.cookie&&u(Z.cookie))Z.headers["Set-Cookie"]=V1(Z.cookie);if(Z.headers["Set-Cookie"]&&Array.isArray(Z.headers["Set-Cookie"]))Z.headers=A1(new Headers(Z.headers),Z.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":return new Response($,Z);case"Blob":return O0($,Z);case"Object":case"Array":return Response.json($,Z);case"ReadableStream":if(!Z.headers["content-type"]?.startsWith("text/event-stream"))Z.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Z);case void 0:if(!$)return;return Response.json($,Z);case"Response":const X=Object.assign({},Z.headers);if(U0)Z.headers=$.headers.toJSON();else for(let[J,Y]of $.headers.entries())if(!(J in Z.headers))Z.headers[J]=Y;for(let J in X)$.headers.append(J,X[J]);if($.status!==Z.status)Z.status=$.status;return $;case"Promise":return $.then((J)=>{const Y=y(J,Z);if(Y!==void 0)return Y;return});case"Error":return h($,Z);case"Function":return y($(),Z);case"Number":case"Boolean":return new Response($.toString(),Z);case"Cookie":if($ instanceof m)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response){const J={...Z.headers};if(U0)Z.headers=$.headers.toJSON();else for(let[Y,Q]of $.headers.entries())if(Y in Z.headers)Z.headers[Y]=Q;for(let Y in J)$.headers.append(Y,J[Y]);return $}if($ instanceof Promise)return $.then((J)=>y(J,Z));if($ instanceof Error)return h($,Z);const W=JSON.stringify($);if(W.charCodeAt(0)===123){if(!Z.headers["Content-Type"])Z.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Z)}return new Response(W,Z)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($,Z);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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((W)=>{const J=y(W,Z);if(J!==void 0)return J;return});case"Error":return h($,Z);case"Function":return l($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof m)return new Response($.value,Z);return new Response($?.toString(),Z);default:if($ instanceof Response)return new Response($.body,{headers:{"Content-Type":"application/json"}});if($ instanceof Promise)return $.then((W)=>y(W,Z));if($ instanceof Error)return h($,Z);const X=JSON.stringify($);if(X.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(X)}},l=($)=>{if($?.$passthrough)$=$[$.$passthrough];if($?.[c])return v($.response,{status:$[c],headers:{}});switch($?.constructor?.name){case"String":return new Response($);case"Blob":return O0($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return 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 h($);case"Promise":return $.then(l);case"Function":return l($());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(l);if($ instanceof Error)return h($);const Z=JSON.stringify($);if(Z.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(Z)}},h=($,Z)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:Z?.status!==200?Z?.status??500:500,headers:Z?.headers});var r0=($)=>$&&typeof $==="object"&&!Array.isArray($),t0=($,Z)=>{const X=new URL($);return X.pathname=Z,X.toString()},O$=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||u(Object.getPrototypeOf($)),d=($,Z,{skipKeys:X}={})=>{if(r0($)&&r0(Z))for(let[W,J]of Object.entries(Z)){if(X?.includes(W))continue;if(!r0(J)){$[W]=J;continue}if(!(W in $)){$[W]=J;continue}if(O$(J)){$[W]=J;continue}$[W]=d($[W],J)}return $},C1=($,Z)=>d($,Z,{skipKeys:["properties"]}),H=($,Z)=>{if(!$)return[];const X=[...Array.isArray($)?$:[$]],W=[];for(let J of X)if(J.$elysiaChecksum)W.push(J.$elysiaChecksum);for(let J of Array.isArray(Z)?Z:[Z])if(!W.includes(J?.$elysiaChecksum))X.push(J);return X},I$=["start","request","parse","transform","resolve","beforeHandle","afterHandle","onResponse","mapResponse","trace","error","stop","body","headers","params","query","response","type","detail"],n=($,Z)=>{return{...$,...Z,body:Z?.body??$?.body,headers:Z?.headers??$?.headers,params:Z?.params??$?.params,query:Z?.query??$?.query,response:Z?.response??$?.response,type:$?.type||Z?.type,detail:d(Z?.detail??{},$?.detail??{}),parse:H($?.parse??[],Z?.parse??[]),transform:H($?.transform??[],Z?.transform??[]),beforeHandle:H($?.beforeHandle??[],Z?.beforeHandle??[]),afterHandle:H($?.afterHandle??[],Z?.afterHandle??[]),onResponse:H($?.onResponse??[],Z?.onResponse??[]),mapResponse:H($?.mapResponse??[],Z?.mapResponse??[]),trace:H($?.trace??[],Z?.trace??[]),error:H($?.error??[],Z?.error??[])}},p=($,{models:Z={},additionalProperties:X=!1,dynamic:W=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Z))return;const J=typeof $==="string"?Z[$]:$;if(J.type==="object"&&"additionalProperties"in J===!1)J.additionalProperties=X;if(W)return{schema:J,references:"",checkFunc:()=>{},code:"",Check:(Y)=>y0.Check(J,Y),Errors:(Y)=>y0.Errors(J,Y),Code:()=>""};return w1.Compile(J,Object.values(Z))},s0=($,{models:Z={},additionalProperties:X=!1,dynamic:W=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Z))return;const J=typeof $==="string"?Z[$]:$,Y=(_,B)=>{if(W)return{schema:_,references:"",checkFunc:()=>{},code:"",Check:(K)=>y0.Check(_,K),Errors:(K)=>y0.Errors(_,K),Code:()=>""};return w1.Compile(_,B)};if(n0 in J){if("additionalProperties"in J===!1)J.additionalProperties=X;return{200:Y(J,Object.values(Z))}}const Q={};return Object.keys(J).forEach((_)=>{const B=J[+_];if(typeof B==="string"){if(B in Z){const K=Z[B];K.type==="object"&&"additionalProperties"in K,Q[+_]=n0 in K?Y(K,Object.values(Z)):K}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=X;Q[+_]=n0 in B?Y(B,Object.values(Z)):B}),Q},j$=typeof Bun!=="undefined",N$=j$&&typeof Bun.hash==="function",j0=($)=>{if(N$)return Bun.hash($);let Z=9;for(let X=0;X<$.length;)Z=Math.imul(Z^$.charCodeAt(X++),387420489);return Z=Z^Z>>>9},v0=($,Z,X)=>{const W=(J)=>{if(X&&!J.$elysiaChecksum)J.$elysiaChecksum=X;return J};return{...$,...Z,start:H($.start,("start"in Z?Z.start??[]:[]).map(W)),request:H($.request,("request"in Z?Z.request??[]:[]).map(W)),parse:H($.parse,"parse"in Z?Z?.parse??[]:[]).map(W),transform:H($.transform,(Z?.transform??[]).map(W)),beforeHandle:H($.beforeHandle,(Z?.beforeHandle??[]).map(W)),afterHandle:H($.afterHandle,(Z?.afterHandle??[]).map(W)),mapResponse:H($.mapResponse,(Z?.mapResponse??[]).map(W)),onResponse:H($.onResponse,(Z?.onResponse??[]).map(W)),trace:$.trace,error:H($.error,(Z?.error??[]).map(W)),stop:H($.stop,("stop"in Z?Z.stop??[]:[]).map(W))}};var R1=($,Z=!0)=>{if(!$)return $;if(typeof $==="function"){if(Z)$.$elysiaHookType="global";else $.$elysiaHookType=void 0;return $}return $.map((X)=>{if(Z)X.$elysiaHookType="global";else X.$elysiaHookType=void 0;return X})},Y0=($)=>{if(!$)return $;if(typeof $==="function")return $.$elysiaHookType==="global"?$:void 0;return $.filter((Z)=>Z.$elysiaHookType==="global")},a0=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:Y0($?.parse),transform:Y0($?.transform),beforeHandle:Y0($?.beforeHandle),afterHandle:Y0($?.afterHandle),onResponse:Y0($?.onResponse),error:Y0($?.error)}},I0={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},B0=async($,Z)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(Z===null)throw new TypeError("Secret key must be provided.");const X=new TextEncoder,W=await crypto.subtle.importKey("raw",X.encode(Z),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),J=await crypto.subtle.sign("HMAC",W,X.encode($)),Y=Array.from(new Uint8Array(J)),Q=btoa(String.fromCharCode(...Y));return`${$}.${Q.replace(/=+$/,"")}`},l0=async($,Z)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(Z===null)throw new TypeError("Secret key must be provided.");const X=$.slice(0,$.lastIndexOf("."));return await B0(X,Z)===$?X:!1},o0=($,Z,X=Z)=>{for(let[W,J]of Object.entries(Z??{})){if(I$.includes(W)||!(W in $))continue;if(typeof $[W]==="function")$[W](J);else if(typeof $[W]==="object")o0($[W],J,X)}},f0=($)=>{if($.length<16)return $.trim().length!==0&&!Number.isNaN(Number($));if($.length===16){const Z=Number($);if(Z.toString()===$)return $.trim().length!==0&&!Number.isNaN(Z)}return!1};var S1=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,_0=Symbol("ElysiaErrorCode"),c=Symbol("ElysiaResponse"),N0=(S1?.NODE_ENV??S1?.ENV)==="production",F$=($,Z)=>({[c]:I0[$]??$,response:Z});class k0 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class e extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class q1 extends Error{code="PARSE";status=400;constructor($){super($??"PARSE")}}class M0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,Z){super(Z??`"${$}" has invalid cookie signature`);this.key=$}}class q extends Error{$;Z;X;code="VALIDATION";status=400;constructor($,Z,X){const W=N0?void 0:("Errors"in Z)?Z.Errors(X).First():e0.Errors(Z,X).First(),J=W?.schema.error?typeof W.schema.error==="function"?W.schema.error($,Z,X):W.schema.error:void 0,Y=W?.path?.slice(1)||"root";let Q="";if(J)Q=typeof J==="object"?JSON.stringify(J):J+"";else if(N0)Q=JSON.stringify({type:$,message:W?.message});else Q=JSON.stringify({type:$,at:Y,message:W?.message,expected:e0.Create(Z.schema),found:X,errors:[...Z.Errors(X)]},null,2);super(Q);this.type=$;this.validator=Z;this.value=X;Object.setPrototypeOf(this,q.prototype)}get all(){return[...this.validator.Errors(this.value)]}static simplifyModel($){const Z="schema"in $?$.schema:$;try{return e0.Create(Z)}catch{return Z}}get model(){return q.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:$})}}var $1={open($){$.data.open?.($)},message($,Z){$.data.message?.($,Z)},drain($){$.data.drain?.($)},close($,Z,X){$.data.close?.($,Z,X)}};class D0{$;Z;validator;constructor($,Z){this.raw=$;this.data=Z;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else{const X=new Uint32Array(1);crypto.getRandomValues(X),this.id=X[0].toString()}}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,Z=void 0,X)=>{if(this.validator?.Check(Z)===!1)throw new q("message",this.validator,Z);if(typeof Z==="object")Z=JSON.stringify(Z);return this.raw.publish($,Z,X),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new q("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var p1=T0(J1(),1),i1=T0(X1(),1);import{Value as P0} from"@sinclair/typebox/value";var q$=(new Headers()).toJSON,l1=new RegExp(" (\\w+) = context","g"),n1={value:0},r1=({hasTrace:$,hasTraceSet:Z=!1,addFn:X,condition:W={}})=>{if($)return X("\nconst reporter = getReporter()\n"),(J,{name:Y,attribute:Q="",unit:_=0}={})=>{const B=J.indexOf("."),K=B===-1;if(J!=="request"&&J!=="response"&&!W[K?J:J.slice(0,B)])return()=>{if(Z&&J==="afterHandle")X("\nawait traceDone\n")};if(K)Y||=J;else Y||="anonymous";X("\n"+`reporter.emit('event', {
|
|
8
8
|
id,
|
|
9
9
|
event: '${J}',
|
|
10
10
|
type: 'begin',
|
|
11
|
-
name: '${
|
|
11
|
+
name: '${Y}',
|
|
12
12
|
time: performance.now(),
|
|
13
13
|
${K?`unit: ${_},`:""}
|
|
14
|
-
${
|
|
14
|
+
${Q}
|
|
15
15
|
})`.replace(/(\t| |\n)/g,"")+"\n");let G=!1;return()=>{if(G)return;if(G=!0,X("\n"+`reporter.emit('event', {
|
|
16
16
|
id,
|
|
17
17
|
event: '${J}',
|
|
18
18
|
type: 'end',
|
|
19
19
|
time: performance.now()
|
|
20
|
-
})`.replace(/(\t| |\n)/g,"")+"\n"),Z&&J==="afterHandle")X("\nawait traceDone\n")}};else return()=>()=>{}},
|
|
20
|
+
})`.replace(/(\t| |\n)/g,"")+"\n"),Z&&J==="afterHandle")X("\nawait traceDone\n")}};else return()=>()=>{}},A0=($)=>{const Z=$.indexOf(")");if($.charCodeAt(Z+2)===61&&$.charCodeAt(Z+5)!==123)return!0;return $.includes("return")},T$=($,{injectResponse:Z=""}={})=>({composeValidation:(X,W=`c.${X}`)=>$?`c.set.status = 400; throw new ValidationError(
|
|
21
21
|
'${X}',
|
|
22
22
|
${X},
|
|
23
23
|
${W}
|
|
@@ -37,15 +37,15 @@ ${X}
|
|
|
37
37
|
if(!(${X} instanceof Response) && response[c.set.status]?.Check(${X}) === false) {
|
|
38
38
|
if(!(response instanceof Error))
|
|
39
39
|
${W}
|
|
40
|
-
}\n`}}),b=($,Z)=>{if(Z.startsWith("[object "))return!1;if(Z=Z.trimStart(),Z=Z.replaceAll(/^async /g,""),/^(\w+)\(/g.test(Z))Z=Z.slice(Z.indexOf("("));const X=Z.charCodeAt(0)===40||Z.startsWith("function")?Z.slice(Z.indexOf("(")+1,Z.indexOf(")")):Z.slice(0,Z.indexOf("=")-1);if(X==="")return!1;const W=X.charCodeAt(0)===123?X.indexOf("..."):-1;if(X.charCodeAt(0)===123){if(X.includes($))return!0;if(W===-1)return!1}if(Z.match(new RegExp(`${X}(.${$}|\\["${$}"\\])`)))return!0;const J=W!==-1?X.slice(W+3,X.indexOf(" ",W+3)):void 0;if(Z.match(new RegExp(`${J}(.${$}|\\["${$}"\\])`)))return!0;const
|
|
41
|
-
if(_setCookie) {`,x.sign===!0)
|
|
40
|
+
}\n`}}),b=($,Z)=>{if(Z.startsWith("[object "))return!1;if(Z=Z.trimStart(),Z=Z.replaceAll(/^async /g,""),/^(\w+)\(/g.test(Z))Z=Z.slice(Z.indexOf("("));const X=Z.charCodeAt(0)===40||Z.startsWith("function")?Z.slice(Z.indexOf("(")+1,Z.indexOf(")")):Z.slice(0,Z.indexOf("=")-1);if(X==="")return!1;const W=X.charCodeAt(0)===123?X.indexOf("..."):-1;if(X.charCodeAt(0)===123){if(X.includes($))return!0;if(W===-1)return!1}if(Z.match(new RegExp(`${X}(.${$}|\\["${$}"\\])`)))return!0;const J=W!==-1?X.slice(W+3,X.indexOf(" ",W+3)):void 0;if(Z.match(new RegExp(`${J}(.${$}|\\["${$}"\\])`)))return!0;const Y=[X];if(J)Y.push(J);for(let _ of Z.matchAll(l1))Y.push(_[1]);const Q=new RegExp(`{.*?} = (${Y.join("|")})`,"g");for(let[_]of Z.matchAll(Q))if(_.includes(`{ ${$}`)||_.includes(`, ${$}`))return!0;return!1},V0=($)=>{if($=$.trimStart(),$.startsWith("[object"))return!1;if($=$.replaceAll(/^async /g,""),/^(\w+)\(/g.test($))$=$.slice($.indexOf("("));const Z=$.charCodeAt(0)===40||$.startsWith("function")?$.slice($.indexOf("(")+1,$.indexOf(")")):$.slice(0,$.indexOf("=")-1);if(Z==="")return!1;const X=Z.charCodeAt(0)===123?Z.indexOf("..."):-1,W=X!==-1?Z.slice(X+3,Z.indexOf(" ",X+3)):void 0,J=[Z];if(W)J.push(W);for(let Q of $.matchAll(l1))J.push(Q[1]);for(let Q of J)if(new RegExp(`\\b\\w+\\([^)]*\\b${Q}\\b[^)]*\\)`).test($))return!0;const Y=new RegExp(`{.*?} = (${J.join("|")})`,"g");for(let[Q]of $.matchAll(Y))if(new RegExp(`\\b\\w+\\([^)]*\\b${Q}\\b[^)]*\\)`).test($))return!0;return!1},G0=Symbol.for("TypeBox.Kind"),m0=($,Z)=>{if(!Z)return;if(G0 in Z&&Z[G0]===$)return!0;if(Z.type==="object"){const X=Z.properties;for(let W of Object.keys(X)){const J=X[W];if(J.type==="object"){if(m0($,J))return!0}else if(J.anyOf){for(let Y=0;Y<J.anyOf.length;Y++)if(m0($,J.anyOf[Y]))return!0}if(G0 in J&&J[G0]===$)return!0}return!1}return Z.properties&&G0 in Z.properties&&Z.properties[G0]===$},$0=($,Z)=>{if(!Z)return;if(Z.type==="object"){const X=Z.properties;if(!X)return!1;for(let W of Object.keys(X)){const J=X[W];if($ in J)return!0;if(J.type==="object"){if($0($,J))return!0}else if(J.anyOf){for(let Y=0;Y<J.anyOf.length;Y++)if($0($,J.anyOf[Y]))return!0}}return!1}return $ in Z},Q1=Symbol.for("TypeBox.Transform"),Z0=($)=>{if(!$)return;if($.type==="object"&&$.properties){const Z=$.properties;for(let X of Object.keys(Z)){const W=Z[X];if(W.type==="object"){if(Z0(W))return!0}else if(W.anyOf){for(let Y=0;Y<W.anyOf.length;Y++)if(Z0(W.anyOf[Y]))return!0}if(Q1 in W)return!0}return!1}return Q1 in $||$.properties&&Q1 in $.properties},E$=($)=>{if(!$)return;const Z=$?.schema;if(Z&&"anyOf"in Z){let X=!1;const W=Z.anyOf[0].type;for(let J of Z.anyOf)if(J.type!==W){X=!0;break}if(!X)return W}return $.schema?.type},H$=/(?:return|=>) \S+\(/g,L=($)=>{if($.constructor.name==="AsyncFunction")return!0;const Z=$.toString();if(Z.includes("=> response.clone("))return!1;return!!Z.match(H$)},b$=($)=>{if(!$.includes("query: {")||$.includes("query,")||$.includes("query }"))return!1;const Z=$.indexOf("query: {");return $=$.slice(Z+9),$=$.slice(0,$.indexOf("}")),$.split(",").map((X)=>{const W=X.indexOf(":");if(W===-1)return X.trim();return X.slice(0,W).trim()})},t1=({path:$,method:Z,hooks:X,validator:W,handler:J,handleError:Y,definitions:Q,schema:_,onRequest:B,config:K,getReporter:G,setHeader:M})=>{const V=K.forceErrorEncapsulation||X.error.length>0||typeof Bun==="undefined"||X.onResponse.length>0||!!X.trace.length,P=typeof J==="function",z=P?"handler(c)":"handler",A=X.onResponse.length?`\n;(async () => {${X.onResponse.map((O,I)=>`await res${I}(c)`).join(";")}})();\n`:"",U=X.trace.map((O)=>O.toString());let j=!1;if(P&&V0(J.toString()))j=!0;if(!j)for(let[O,I]of Object.entries(X)){if(!Array.isArray(I)||!I.length||!["parse","transform","beforeHandle","afterHandle","onResponse"].includes(O))continue;for(let F of I){if(typeof F!=="function")continue;if(V0(F.toString())){j=!0;break}}if(j)break}const N={parse:U.some((O)=>b("parse",O)),transform:U.some((O)=>b("transform",O)),handle:U.some((O)=>b("handle",O)),beforeHandle:U.some((O)=>b("beforeHandle",O)),afterHandle:U.some((O)=>b("afterHandle",O)),error:V||U.some((O)=>b("error",O))},w=X.trace.length>0;let D="";const k=W||Z!=="GET"&&Z!=="HEAD"?[J,...X.transform,...X.beforeHandle,...X.afterHandle,...X.mapResponse].map((O)=>typeof O==="function"?O.toString():`${O}`):[],w0=Z!=="GET"&&Z!=="HEAD"&&(j||X.type!=="none"&&(!!W.body||!!X.type||k.some((O)=>b("body",O)))),h0=j||W.headers||k.some((O)=>b("headers",O))||M&&Object.keys(M).length,C0=j||!!W.cookie||k.some((O)=>b("cookie",O)),x=W?.cookie?.schema;let t="";if(x?.sign){if(!x.secrets)throw new Error(`t.Cookie required secret which is not set in (${Z}) ${$}.`);const O=!x.secrets?void 0:typeof x.secrets==="string"?x.secrets:x.secrets[0];if(t+=`const _setCookie = c.set.cookie
|
|
41
|
+
if(_setCookie) {`,x.sign===!0)t+=`for(const [key, cookie] of Object.entries(_setCookie)) {
|
|
42
42
|
c.set.cookie[key].value = await signCookie(cookie.value, '${O}')
|
|
43
|
-
}`;else for(let I of x.sign)
|
|
43
|
+
}`;else for(let I of x.sign)t+=`if(_setCookie['${I}']?.value) { c.set.cookie['${I}'].value = await signCookie(_setCookie['${I}'].value, '${O}') }\n`;t+="}\n"}const{composeValidation:X0,composeResponseValidation:R0}=T$(V);if(h0)D+=q$?"c.headers = c.request.headers.toJSON()\n":`c.headers = {}
|
|
44
44
|
for (const [key, value] of c.request.headers.entries())
|
|
45
45
|
c.headers[key] = value
|
|
46
|
-
`;if(
|
|
47
|
-
secret: ${x.secrets!==void 0?typeof x.secrets==="string"?`'${x.secrets}'`:"["+x.secrets.reduce((
|
|
48
|
-
sign: ${x.sign===!0?!0:x.sign!==void 0?"["+x.sign.reduce((
|
|
46
|
+
`;if(C0){const O=(F,R)=>{const S=x?.[F]??R;if(!S)return typeof R==="string"?`${F}: "${R}",`:`${F}: ${R},`;if(typeof S==="string")return`${F}: '${S}',`;if(S instanceof Date)return`${F}: new Date(${S.getTime()}),`;return`${F}: ${S},`},I=x?`{
|
|
47
|
+
secret: ${x.secrets!==void 0?typeof x.secrets==="string"?`'${x.secrets}'`:"["+x.secrets.reduce((F,R)=>F+`'${R}',`,"")+"]":"undefined"},
|
|
48
|
+
sign: ${x.sign===!0?!0:x.sign!==void 0?"["+x.sign.reduce((F,R)=>F+`'${R}',`,"")+"]":"undefined"},
|
|
49
49
|
${O("domain")}
|
|
50
50
|
${O("expires")}
|
|
51
51
|
${O("httpOnly")}
|
|
@@ -54,7 +54,7 @@ ${X}
|
|
|
54
54
|
${O("priority")}
|
|
55
55
|
${O("sameSite")}
|
|
56
56
|
${O("secure")}
|
|
57
|
-
}`:"undefined";if(h0)D+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${I})\n`;else D+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${I})\n`}if(
|
|
57
|
+
}`:"undefined";if(h0)D+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${I})\n`;else D+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${I})\n`}if(j||W.query||k.some((O)=>b("query",O))){let O=[],I=!1;if(W.query&&W.query.schema.type==="object")O=Object.keys(W.query.schema.properties);else for(let F of k){const R=b$(F);if(!R){I=!0;continue}for(let S of R)if(O.indexOf(S)===-1)O.push(S)}if(!I&&O.length)D+=`
|
|
58
58
|
let requestUrl = c.request.url.slice(c.qi + 1)
|
|
59
59
|
if(requestUrl.includes('+')) requestUrl = requestUrl.replaceAll('+', ' ')
|
|
60
60
|
|
|
@@ -62,17 +62,17 @@ ${X}
|
|
|
62
62
|
const url = decodeURIComponent(requestUrl)
|
|
63
63
|
let memory = 0
|
|
64
64
|
|
|
65
|
-
${O.map((
|
|
66
|
-
memory = url.indexOf('${
|
|
65
|
+
${O.map((F,R)=>`
|
|
66
|
+
memory = url.indexOf('${F}=')
|
|
67
67
|
|
|
68
|
-
const a${
|
|
68
|
+
const a${R} = memory === -1 ? undefined : url.slice(memory = memory + ${F.length+1}, (memory = url.indexOf('&', memory)) === -1 ? undefined : memory)`).join("\n")}
|
|
69
69
|
|
|
70
70
|
c.query = {
|
|
71
|
-
${O.map((
|
|
71
|
+
${O.map((F,R)=>`'${F}': a${R}`).join(", ")}
|
|
72
72
|
}
|
|
73
73
|
} else {
|
|
74
74
|
c.query = {}
|
|
75
|
-
}`;else D+="c.query = c.qi !== -1 ? parseQuery(decodeURIComponent(c.request.url.slice(c.qi + 1))) : {}"}const S0=X.trace.map((O)=>O.toString()).some((O)=>b("set",O)||
|
|
75
|
+
}`;else D+="c.query = c.qi !== -1 ? parseQuery(decodeURIComponent(c.request.url.slice(c.qi + 1))) : {}"}const S0=X.trace.map((O)=>O.toString()).some((O)=>b("set",O)||V0(O));j||X.trace.some((O)=>b("set",O.toString()));const q0=M&&Object.keys(M).length||S0||C0||k.some((O)=>b("set",O))||B.some((O)=>b("set",O.toString()));if(w)D+="\nconst id = c.$$requestId\n";const E=r1({hasTrace:w,hasTraceSet:S0,condition:N,addFn:(O)=>{D+=O}});if(D+=V?"\n try {\n":"",S0){D+="\nconst traceDone = Promise.all([";for(let O=0;O<X.trace.length;O++)D+=`new Promise(r => { reporter.once(\`res\${id}.${O}\`, r) }),`;D+="])\n"}const W0=typeof J==="function"&&L(J),c0=C0||w0||S0||W0||!!X.mapResponse.length||X.parse.length>0||X.afterHandle.some(L)||X.beforeHandle.some(L)||X.transform.some(L),e1=E("parse",{unit:X.parse.length});if(w0){const O=E$(W?.body);if(X.type&&!Array.isArray(X.type)){if(X.type)switch(X.type){case"json":case"application/json":D+="c.body = await c.request.json()\n";break;case"text":case"text/plain":D+="c.body = await c.request.text()\n";break;case"urlencoded":case"application/x-www-form-urlencoded":D+="c.body = parseQuery(await c.request.text())\n";break;case"arrayBuffer":case"application/octet-stream":D+="c.body = await c.request.arrayBuffer()\n";break;case"formdata":case"multipart/form-data":D+=`c.body = {}
|
|
76
76
|
|
|
77
77
|
const form = await c.request.formData()
|
|
78
78
|
for (const key of form.keys()) {
|
|
@@ -83,7 +83,7 @@ ${X}
|
|
|
83
83
|
if (value.length === 1)
|
|
84
84
|
c.body[key] = value[0]
|
|
85
85
|
else c.body[key] = value
|
|
86
|
-
}\n`;break}if(X.parse.length)D+="}}"}else{const
|
|
86
|
+
}\n`;break}if(X.parse.length)D+="}}"}else{const F=(()=>{if(X.parse.length&&O&&!Array.isArray(X.type)){const R=W?.body?.schema;switch(O){case"object":if(m0("File",R)||m0("Files",R))return`c.body = {}
|
|
87
87
|
|
|
88
88
|
const form = await c.request.formData()
|
|
89
89
|
for (const key of form.keys()) {
|
|
@@ -94,10 +94,10 @@ ${X}
|
|
|
94
94
|
if (value.length === 1)
|
|
95
95
|
c.body[key] = value[0]
|
|
96
96
|
else c.body[key] = value
|
|
97
|
-
}`;break;default:break}}})();if(
|
|
97
|
+
}`;break;default:break}}})();if(F)D+=F;else{if(D+="\n",D+=h0?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')",D+=`
|
|
98
98
|
if (contentType) {
|
|
99
99
|
const index = contentType.indexOf(';')
|
|
100
|
-
if (index !== -1) contentType = contentType.substring(0, index)\n`,X.parse.length){D+="let used = false\n";const
|
|
100
|
+
if (index !== -1) contentType = contentType.substring(0, index)\n`,X.parse.length){D+="let used = false\n";const R=E("parse",{unit:X.parse.length});for(let S=0;S<X.parse.length;S++){const d0=E("parse.unit",{name:X.parse[S].name}),T=`bo${S}`;if(S!==0)D+="if(!used) {\n";if(D+=`let ${T} = parse[${S}](c, contentType)\n`,D+=`if(${T} instanceof Promise) ${T} = await ${T}\n`,D+=`if(${T} !== undefined) { c.body = ${T}; used = true }\n`,d0(),S!==0)D+="}"}R()}if(X.parse.length)D+="if (!used)";D+=`
|
|
101
101
|
switch (contentType) {
|
|
102
102
|
case 'application/json':
|
|
103
103
|
c.body = await c.request.json()
|
|
@@ -130,14 +130,14 @@ ${X}
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
break
|
|
133
|
-
}\n`,D+="}\n"}}D+="\n"}if(e1(),X?.transform){const O=E("transform",{unit:X.transform.length});for(let I=0;I<X.transform.length;I++){const
|
|
133
|
+
}\n`,D+="}\n"}}D+="\n"}if(e1(),X?.transform){const O=E("transform",{unit:X.transform.length});for(let I=0;I<X.transform.length;I++){const F=X.transform[I],R=E("transform.unit",{name:F.name});if(F.$elysia==="derive")D+=L(F)?`Object.assign(c, await transform[${I}](c));`:`Object.assign(c, transform[${I}](c));`;else D+=L(F)?`await transform[${I}](c);`:`transform[${I}](c);`;R()}O()}if(W){if(D+="\n",W.headers){if($0("default",W.headers.params))for(let[O,I]of Object.entries(P0.Default(W.headers.schema,{}))){const F=typeof I==="object"?JSON.stringify(I):`'${I}'`;if(F)D+=`c.headers['${O}'] ??= ${F}\n`}if(D+=`if(headers.Check(c.headers) === false) {
|
|
134
134
|
${X0("headers")}
|
|
135
|
-
}`,Z0(W.headers.schema))D+="\nc.headers = headers.Decode(c.headers)\n"}if(W.params){if($0("default",W.params.schema))for(let[O,I]of Object.entries(
|
|
135
|
+
}`,Z0(W.headers.schema))D+="\nc.headers = headers.Decode(c.headers)\n"}if(W.params){if($0("default",W.params.schema))for(let[O,I]of Object.entries(P0.Default(W.params.schema,{}))){const F=typeof I==="object"?JSON.stringify(I):`'${I}'`;if(F)D+=`c.params['${O}'] ??= ${F}\n`}if(D+=`if(params.Check(c.params) === false) {
|
|
136
136
|
${X0("params")}
|
|
137
|
-
}`,Z0(W.params.schema))D+="\nc.params = params.Decode(c.params)\n"}if(W.query){if($0("default",W.query.schema))for(let[O,I]of Object.entries(
|
|
137
|
+
}`,Z0(W.params.schema))D+="\nc.params = params.Decode(c.params)\n"}if(W.query){if($0("default",W.query.schema))for(let[O,I]of Object.entries(P0.Default(W.query.schema,{}))){const F=typeof I==="object"?JSON.stringify(I):`'${I}'`;if(F)D+=`c.query['${O}'] ??= ${F}\n`}if(D+=`if(query.Check(c.query) === false) {
|
|
138
138
|
${X0("query")}
|
|
139
139
|
}`,Z0(W.query.schema))D+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(W.body){if($0("default",W.body.schema))D+=`if(body.Check(c.body) === false) {
|
|
140
|
-
c.body = Object.assign(${JSON.stringify(
|
|
140
|
+
c.body = Object.assign(${JSON.stringify(P0.Default(W.body.schema,null)??{})}, c.body)
|
|
141
141
|
|
|
142
142
|
if(body.Check(c.query) === false) {
|
|
143
143
|
${X0("body")}
|
|
@@ -146,30 +146,30 @@ ${X}
|
|
|
146
146
|
${X0("body")}
|
|
147
147
|
}`;if(Z0(W.body.schema))D+="\nc.body = body.Decode(c.body)\n"}if(u(W.cookie?.schema.properties??{})){if(D+=`const cookieValue = {}
|
|
148
148
|
for(const [key, value] of Object.entries(c.cookie))
|
|
149
|
-
cookieValue[key] = value.value\n`,$0("default",W.cookie.schema))for(let[O,I]of Object.entries(
|
|
149
|
+
cookieValue[key] = value.value\n`,$0("default",W.cookie.schema))for(let[O,I]of Object.entries(P0.Default(W.cookie.schema,{})))D+=`cookieValue['${O}'] = ${typeof I==="object"?JSON.stringify(I):I}\n`;if(D+=`if(cookie.Check(cookieValue) === false) {
|
|
150
150
|
${X0("cookie","cookieValue")}
|
|
151
|
-
}`,Z0(W.cookie.schema))D+="\nc.cookie = params.Decode(c.cookie)\n"}}if(X?.beforeHandle){const O=E("beforeHandle",{unit:X.beforeHandle.length});for(let I=0;I<X.beforeHandle.length;I++){const
|
|
151
|
+
}`,Z0(W.cookie.schema))D+="\nc.cookie = params.Decode(c.cookie)\n"}}if(X?.beforeHandle){const O=E("beforeHandle",{unit:X.beforeHandle.length});for(let I=0;I<X.beforeHandle.length;I++){const F=X.beforeHandle[I],R=E("beforeHandle.unit",{name:F.name}),S=A0(F.toString());if(F.$elysia==="resolve")D+=L(F)?`Object.assign(c, await beforeHandle[${I}](c));`:`Object.assign(c, beforeHandle[${I}](c));`;else if(!S)D+=L(F)?`await beforeHandle[${I}](c);\n`:`beforeHandle[${I}](c);\n`,R();else{D+=L(F)?`be = await beforeHandle[${I}](c);\n`:`be = beforeHandle[${I}](c);\n`,R(),D+="if(be !== undefined) {\n";const d0=E("afterHandle",{unit:X.transform.length});if(X.afterHandle){E("handle",{name:P?J.name:void 0})();for(let T=0;T<X.afterHandle.length;T++){const $$=A0(X.afterHandle[T].toString()),Z$=E("afterHandle.unit",{name:X.afterHandle[T].name});if(D+="c.response = be\n",!$$)D+=L(X.afterHandle[T])?`await afterHandle[${T}](c, be)\n`:`afterHandle[${T}](c, be)\n`;else D+=L(X.afterHandle[T])?`af = await afterHandle[${T}](c)\n`:`af = afterHandle[${T}](c)\n`,D+="if(af !== undefined) { c.response = be = af }\n";Z$()}}if(d0(),W.response)D+=R0("be");if(X.mapResponse.length){D+="c.response = be";for(let T=0;T<X.mapResponse.length;T++)D+=`\nif(mr === undefined) {
|
|
152
152
|
mr = onMapResponse[${T}](c)
|
|
153
153
|
if(mr instanceof Promise) mr = await mr
|
|
154
154
|
if(mr !== undefined) c.response = mr
|
|
155
|
-
}\n`}D+=
|
|
155
|
+
}\n`}D+=t,D+="return mapEarlyResponse(be, c.set)}\n"}}O()}if(X?.afterHandle.length){const O=E("handle",{name:P?J.name:void 0});if(X.afterHandle.length)D+=W0?`let r = c.response = await ${z};\n`:`let r = c.response = ${z};\n`;else D+=W0?`let r = await ${z};\n`:`let r = ${z};\n`;O();const I=E("afterHandle",{unit:X.afterHandle.length});for(let F=0;F<X.afterHandle.length;F++){const R=A0(X.afterHandle[F].toString()),S=E("afterHandle.unit",{name:X.afterHandle[F].name});if(!R)D+=L(X.afterHandle[F])?`await afterHandle[${F}](c)\n`:`afterHandle[${F}](c)\n`,S();else if(D+=L(X.afterHandle[F])?`af = await afterHandle[${F}](c)\n`:`af = afterHandle[${F}](c)\n`,S(),W.response)D+="if(af !== undefined) {",I(),D+=R0("af"),D+="c.response = af }";else D+="if(af !== undefined) {",I(),D+="c.response = af}\n"}if(I(),D+="r = c.response\n",W.response)D+=R0();if(D+=t,X.mapResponse.length)for(let F=0;F<X.mapResponse.length;F++)D+=`\nmr = onMapResponse[${F}](c)
|
|
156
156
|
if(mr instanceof Promise) mr = await mr
|
|
157
|
-
if(mr !== undefined) c.response = mr\n`;if(q0)D+="return mapResponse(r, c.set)\n";else D+="return mapCompactResponse(r)\n"}else{const O=E("handle",{name:
|
|
157
|
+
if(mr !== undefined) c.response = mr\n`;if(q0)D+="return mapResponse(r, c.set)\n";else D+="return mapCompactResponse(r)\n"}else{const O=E("handle",{name:P?J.name:void 0});if(W.response||X.mapResponse.length){if(D+=W0?`let r = await ${z};\n`:`let r = ${z};\n`,O(),W.response)D+=R0();if(E("afterHandle")(),X.mapResponse.length){D+="c.response = r";for(let I=0;I<X.mapResponse.length;I++)D+=`\nif(mr === undefined) {
|
|
158
158
|
mr = onMapResponse[${I}](c)
|
|
159
159
|
if(mr instanceof Promise) mr = await mr
|
|
160
160
|
if(mr !== undefined) r = c.response = mr
|
|
161
|
-
}\n`}if(D+=
|
|
161
|
+
}\n`}if(D+=t,J instanceof Response)D+=`return ${z}.clone()\n`;else if(q0)D+="return mapResponse(r, c.set)\n";else D+="return mapCompactResponse(r)\n"}else if(N.handle||C0){if(D+=W0?`let r = await ${z};\n`:`let r = ${z};\n`,O(),E("afterHandle")(),X.mapResponse.length){D+="c.response = r";for(let I=0;I<X.mapResponse.length;I++)D+=`\nif(mr === undefined) {
|
|
162
162
|
mr = onMapResponse[${I}](c)
|
|
163
163
|
if(mr instanceof Promise) mr = await mr
|
|
164
164
|
if(mr !== undefined) r = c.response = mr
|
|
165
|
-
}\n`}if(D+=
|
|
165
|
+
}\n`}if(D+=t,q0)D+="return mapResponse(r, c.set)\n";else D+="return mapCompactResponse(r)\n"}else{O();const I=W0?`await ${z}`:z;if(E("afterHandle")(),J instanceof Response)D+=`return ${z}.clone()\n`;else if(q0)D+=`return mapResponse(${I}, c.set)\n`;else D+=`return mapCompactResponse(${I})\n`}}if(V||A){if(D+=`
|
|
166
166
|
} catch(error) {`,!c0)D+="return (async () => {";D+=`const set = c.set
|
|
167
167
|
|
|
168
168
|
if (!set.status || set.status < 300) set.status = error?.status || 500
|
|
169
169
|
`;const O=E("error",{unit:X.error.length});if(X.error.length){D+=`
|
|
170
170
|
c.error = error
|
|
171
171
|
c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
|
|
172
|
-
`;for(let I=0;I<X.error.length;I++){const
|
|
172
|
+
`;for(let I=0;I<X.error.length;I++){const F=`er${I}`,R=E("error.unit",{name:X.error[I].name});if(D+=`\nlet ${F} = handleErrors[${I}](c)\n`,L(X.error[I]))D+=`if (${F} instanceof Promise) ${F} = await ${F}\n`;R(),D+=`${F} = mapEarlyResponse(${F}, set)\n`,D+=`if (${F}) {`,D+=`return ${F} }\n`}}if(O(),D+="return handleError(c, error)\n\n",!c0)D+="})()";if(D+="}",A||w){D+=" finally { ";const I=E("response",{unit:X.onResponse.length});D+=A,I(),D+="}"}}return D=`const {
|
|
173
173
|
handler,
|
|
174
174
|
handleError,
|
|
175
175
|
hooks: {
|
|
@@ -218,9 +218,9 @@ ${X}
|
|
|
218
218
|
${X.afterHandle.length?"let af":""}
|
|
219
219
|
${X.mapResponse.length?"let mr":""}
|
|
220
220
|
|
|
221
|
-
${_&&
|
|
221
|
+
${_&&Q?"c.schema = schema; c.defs = definitions;":""}
|
|
222
222
|
${D}
|
|
223
|
-
}`,Function("hooks",D)({handler:J,hooks:X,validator:W,handleError:
|
|
223
|
+
}`,Function("hooks",D)({handler:J,hooks:X,validator:W,handleError:Y,utils:{mapResponse:v,mapCompactResponse:l,mapEarlyResponse:y,parseQuery:p1.parse},error:{NotFoundError:e,ValidationError:q,InternalServerError:k0},schema:_,definitions:Q,ERROR_CODE:_0,getReporter:G,requestId:n1,parseCookie:g0,signCookie:B0,decodeURIComponent:i1.default})},Y1=($)=>{let Z="",X="";for(let z of Object.keys($.decorators))Z+=`,${z}: app.decorators.${z}`;const{router:W,staticRouter:J}=$,Y=$.event.trace.length>0,Q=`
|
|
224
224
|
const route = router.find(request.method, path) ${W.root.ALL?'?? router.find("ALL", path)':""}
|
|
225
225
|
if (route === null)
|
|
226
226
|
return ${$.event.error.length?"app.handleError(ctx, notFound)":$.event.request.length?`new Response(error404Message, {
|
|
@@ -230,7 +230,7 @@ ${X}
|
|
|
230
230
|
|
|
231
231
|
ctx.params = route.params
|
|
232
232
|
|
|
233
|
-
return route.store(ctx)`;let _="";for(let[z,{code:
|
|
233
|
+
return route.store(ctx)`;let _="";for(let[z,{code:A,all:U}]of Object.entries(J.map))_+=`case '${z}':\nswitch(request.method) {\n${A}\n${U??"default: break map"}}\n\n`;const B=$.event.request.some(L);if(X+=`const {
|
|
234
234
|
app,
|
|
235
235
|
app: { store, router, staticRouter, wsRouter },
|
|
236
236
|
mapEarlyResponse,
|
|
@@ -249,8 +249,8 @@ ${X}
|
|
|
249
249
|
const error404 = new Response(error404Message, { status: 404 });
|
|
250
250
|
`}
|
|
251
251
|
|
|
252
|
-
return ${B?"async":""} function map(request) {\n`,$.event.request.length)X+="let re";const K=$.event.trace.map((z)=>z.toString()),G=r1({hasTrace:
|
|
253
|
-
${
|
|
252
|
+
return ${B?"async":""} function map(request) {\n`,$.event.request.length)X+="let re";const K=$.event.trace.map((z)=>z.toString()),G=r1({hasTrace:Y,hasTraceSet:$.event.trace.some((z)=>{const A=z.toString();return b("set",A)||V0(A)}),condition:{request:K.some((z)=>b("request",z)||V0(z))},addFn:(z)=>{X+=z}});if($.event.request.length){X+=`
|
|
253
|
+
${Y?"const id = +requestId.value++":""}
|
|
254
254
|
|
|
255
255
|
const ctx = {
|
|
256
256
|
request,
|
|
@@ -259,13 +259,13 @@ ${X}
|
|
|
259
259
|
headers: ${Object.keys($.setHeaders??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
|
|
260
260
|
status: 200
|
|
261
261
|
}
|
|
262
|
-
${
|
|
262
|
+
${Y?",$$requestId: +id":""}
|
|
263
263
|
${Z}
|
|
264
264
|
}
|
|
265
|
-
`;const z=G("request",{attribute:"ctx",unit:$.event.request.length});X+="\n try {\n";for(let
|
|
266
|
-
${
|
|
265
|
+
`;const z=G("request",{attribute:"ctx",unit:$.event.request.length});X+="\n try {\n";for(let A=0;A<$.event.request.length;A++){const U=$.event.request[A],j=A0(U.toString()),N=L(U),w=G("request.unit",{name:$.event.request[A].name});if(j){if(X+=`re = mapEarlyResponse(
|
|
266
|
+
${N?"await":""} onRequest[${A}](ctx),
|
|
267
267
|
ctx.set
|
|
268
|
-
)\n`,
|
|
268
|
+
)\n`,w(),j)X+="if(re !== undefined) return re\n"}else X+=`${N?"await":""} onRequest[${A}](ctx)\n`,w()}X+=`} catch (error) {
|
|
269
269
|
return app.handleError(ctx, error)
|
|
270
270
|
}`,z(),X+=`
|
|
271
271
|
const url = request.url
|
|
@@ -276,7 +276,7 @@ ${X}
|
|
|
276
276
|
const s = url.indexOf('/', 11)
|
|
277
277
|
const qi = url.indexOf('?', s + 1)
|
|
278
278
|
const path = url.substring(s, qi === -1 ? undefined : qi)
|
|
279
|
-
${
|
|
279
|
+
${Y?"const id = +requestId.value++":""}
|
|
280
280
|
const ctx = {
|
|
281
281
|
request,
|
|
282
282
|
store,
|
|
@@ -286,14 +286,14 @@ ${X}
|
|
|
286
286
|
headers: ${Object.keys($.setHeaders??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
|
|
287
287
|
status: 200
|
|
288
288
|
}
|
|
289
|
-
${
|
|
289
|
+
${Y?",$$requestId: id":""}
|
|
290
290
|
${Z}
|
|
291
|
-
}`,G("request",{unit:$.event.request.length,attribute:K.some((z)=>b("context",z))||K.some((z)=>b("store",z))||K.some((z)=>b("set",z))?"ctx":""})();const{wsPaths:
|
|
291
|
+
}`,G("request",{unit:$.event.request.length,attribute:K.some((z)=>b("context",z))||K.some((z)=>b("store",z))||K.some((z)=>b("set",z))?"ctx":""})();const{wsPaths:M,wsRouter:V}=$;if(Object.keys(M).length||V.history.length){X+=`
|
|
292
292
|
if(request.method === 'GET') {
|
|
293
|
-
switch(path) {`;for(let[z,
|
|
293
|
+
switch(path) {`;for(let[z,A]of Object.entries(M))X+=`
|
|
294
294
|
case '${z}':
|
|
295
295
|
if(request.headers.get('upgrade') === 'websocket')
|
|
296
|
-
return st${
|
|
296
|
+
return st${A}(ctx)
|
|
297
297
|
|
|
298
298
|
break`;X+=`
|
|
299
299
|
default:
|
|
@@ -317,8 +317,8 @@ ${X}
|
|
|
317
317
|
break
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
${
|
|
321
|
-
}`;const
|
|
320
|
+
${Q}
|
|
321
|
+
}`;const P=B1($);return $.handleError=P,Function("data",X)({app:$,mapEarlyResponse:y,NotFoundError:e,getReporter:()=>$.reporter,requestId:n1,handleError:P})},B1=($)=>{let Z=`const {
|
|
322
322
|
app: { event: { error: onError, onResponse: res } },
|
|
323
323
|
mapResponse,
|
|
324
324
|
ERROR_CODE,
|
|
@@ -337,7 +337,7 @@ ${X}
|
|
|
337
337
|
error.status = error[ELYSIA_RESPONSE]
|
|
338
338
|
error.message = error.response
|
|
339
339
|
}
|
|
340
|
-
`;for(let X=0;X<$.event.error.length;X++){const W=$.event.error[X],J=`${L(W)?"await ":""}onError[${X}](context)`;if(
|
|
340
|
+
`;for(let X=0;X<$.event.error.length;X++){const W=$.event.error[X],J=`${L(W)?"await ":""}onError[${X}](context)`;if(A0(W.toString()))Z+=`r = ${J}; if(r !== undefined) {
|
|
341
341
|
if(r instanceof Response) return r
|
|
342
342
|
|
|
343
343
|
if(r[ELYSIA_RESPONSE]) {
|
|
@@ -362,6 +362,6 @@ ${X}
|
|
|
362
362
|
|
|
363
363
|
return mapResponse(error, set)
|
|
364
364
|
}
|
|
365
|
-
}`,Function("inject",Z)({app:$,mapResponse:v,ERROR_CODE:_0,ELYSIA_RESPONSE:c})};var u0=T0(J1(),1);var _1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let W;if($.decorators)W=$.decorators,W.request=Z,W.set=X,W.store=$.store;else W={set:X,store:$.store,request:Z};const J=Z.url,Q=J.indexOf("/",11),Y=J.indexOf("?",Q+1),_=Y===-1?J.substring(Q):J.substring(Q,Y);try{for(let M=0;M<$.event.request.length;M++){const N=$.event.request[M];let F=N(W);if(F instanceof Promise)F=await F;if(F=y(F,X),F)return F}const B=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!B)throw new e;const{handle:K,hooks:G,validator:U,content:w}=B.store;let A;if(Z.method!=="GET"&&Z.method!=="HEAD")if(w)switch(w){case"application/json":A=await Z.json();break;case"text/plain":A=await Z.text();break;case"application/x-www-form-urlencoded":A=u0.parse(await Z.text());break;case"application/octet-stream":A=await Z.arrayBuffer();break;case"multipart/form-data":A={};const M=await Z.formData();for(let N of M.keys()){if(A[N])continue;const F=M.getAll(N);if(F.length===1)A[N]=F[0];else A[N]=F}break}else{let M=Z.headers.get("content-type");if(M){const N=M.indexOf(";");if(N!==-1)M=M.slice(0,N);for(let F=0;F<G.parse.length;F++){let V=G.parse[F](W,M);if(V instanceof Promise)V=await V;if(V){A=V;break}}if(A===void 0)switch(M){case"application/json":A=await Z.json();break;case"text/plain":A=await Z.text();break;case"application/x-www-form-urlencoded":A=u0.parse(await Z.text());break;case"application/octet-stream":A=await Z.arrayBuffer();break;case"multipart/form-data":A={};const F=await Z.formData();for(let V of F.keys()){if(A[V])continue;const D=F.getAll(V);if(D.length===1)A[V]=D[0];else A[V]=D}break}}}W.body=A,W.params=B?.params||void 0,W.query=Y===-1?{}:u0.parse(J.substring(Y+1)),W.headers={};for(let[M,N]of Z.headers.entries())W.headers[M]=N;const z=U?.cookie?.schema;W.cookie=await g0(W.set,W.headers.cookie,z?{secret:z.secrets!==void 0?typeof z.secrets==="string"?z.secrets:z.secrets.join(","):void 0,sign:z.sign===!0?!0:z.sign!==void 0?typeof z.sign==="string"?z.sign:z.sign.join(","):void 0}:void 0);for(let M=0;M<G.transform.length;M++){const N=G.transform[M](W);if(G.transform[M].$elysia==="derive")if(N instanceof Promise)Object.assign(W,await N);else Object.assign(W,N);else if(N instanceof Promise)await N}if(U){if(U.headers){const M={};for(let N in Z.headers)M[N]=Z.headers.get(N);if(U.headers.Check(M)===!1)throw new q("header",U.headers,M)}if(U.params?.Check(W.params)===!1)throw new q("params",U.params,W.params);if(U.query?.Check(W.query)===!1)throw new q("query",U.query,W.query);if(U.cookie){const M={};for(let[N,F]of Object.entries(W.cookie))M[N]=F.value;if(U.cookie?.Check(M)===!1)throw new q("cookie",U.cookie,M)}if(U.body?.Check(A)===!1)throw new q("body",U.body,A)}for(let M=0;M<G.beforeHandle.length;M++){let N=G.beforeHandle[M](W);if(N instanceof Promise)N=await N;if(N!==void 0){W.response=N;for(let V=0;V<G.afterHandle.length;V++){let D=G.afterHandle[V](W);if(D instanceof Promise)D=await D;if(D)N=D}const F=y(N,W.set);if(F)return F}}let P=K(W);if(P instanceof Promise)P=await P;if(!G.afterHandle.length){const M=U?.response?.[P.status];if(M?.Check(P)===!1)throw new q("response",M,P)}else{W.response=P;for(let M=0;M<G.afterHandle.length;M++){let N=G.afterHandle[M](W);if(N instanceof Promise)N=await N;const F=y(N,W.set);if(F!==void 0){const V=U?.response?.[P.status];if(V?.Check(F)===!1)throw new q("response",V,F);return F}}}if(W.set.cookie&&z?.sign){const M=!z.secrets?void 0:typeof z.secrets==="string"?z.secrets:z.secrets[0];if(z.sign===!0)for(let[N,F]of Object.entries(W.set.cookie))W.set.cookie[N].value=await B0(F.value,"${secret}");else for(let N of z.sign){if(!(N in z.properties))continue;if(W.set.cookie[N]?.value)W.set.cookie[N].value=await B0(W.set.cookie[N].value,M)}}return v(P,W.set)}catch(B){if(B.status)X.status=B.status;return $.handleError(W,B)}finally{for(let B of $.event.onResponse)await B(W)}},s1=($)=>async(Z,X)=>{const W=Object.assign(Z,{error:X,code:X.code});W.set=Z.set;for(let J=0;J<$.event.error.length;J++){let Q=$.event.error[J](W);if(Q instanceof Promise)Q=await Q;if(Q!==void 0&&Q!==null)return v(Q,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};import{TypeSystem as K0} from"@sinclair/typebox/system";import{Type as D1,FormatRegistry as K1} from"@sinclair/typebox";import{Value as a1} from"@sinclair/typebox/value";import{TypeSystemPolicy as m6,TypeSystem as k6,TypeSystemDuplicateFormat as u6,TypeSystemDuplicateTypeKind as h6} from"@sinclair/typebox/system";import{TypeCompiler as d6,TypeCheck as p6} from"@sinclair/typebox/compiler";var R=Object.assign({},D1);try{K0.Format("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.test($)),K0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),K0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),K0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch{}var o1=($)=>{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 $},G1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<o1($.minSize))return!1;if($.maxSize&&Z.size>o1($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},L$=K0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return G1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!G1($,Z[X]))return!1;return!0});K1.Set("numeric",($)=>!!$&&!isNaN(+$));K1.Set("boolean",($)=>$==="true"||$==="false");K1.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const Z=D1.Number($);return R.Transform(R.Union([R.String({format:"numeric",default:0}),R.Number($)],$)).Decode((X)=>{const W=+X;if(isNaN(W))return X;if($&&!a1.Check(Z,W))throw new q("property",Z,W);return W}).Encode((X)=>X)},BooleanString:($)=>{const Z=D1.Boolean($);return R.Transform(R.Union([R.String({format:"boolean",default:!1}),R.Boolean($)],$)).Decode((X)=>{if(typeof X==="string")return X==="true";if($&&!a1.Check(Z,X))throw new q("property",Z,X);return X}).Encode((X)=>X)},ObjectString:($,Z)=>R.Transform(R.Union([R.String({format:"ObjectString",default:""}),R.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:K0.Type("File",G1),Files:($={})=>R.Transform(R.Union([L$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>R.Union([R.Null(),$]),MaybeEmpty:($)=>R.Union([R.Null(),R.Undefined(),$]),Cookie:($,Z)=>R.Object($,Z)};R.BooleanString=a.BooleanString;R.ObjectString=a.ObjectString;R.Numeric=a.Numeric;R.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});R.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});R.Nullable=($)=>a.Nullable($);R.MaybeEmpty=a.MaybeEmpty;R.Cookie=a.Cookie;class n{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new F1;server=null;getServer(){return this.server}validator=null;router=new o;wsRouter=new o;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new o;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$||{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,W,{allowMeta:J=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Y of Z){if(Y=Y===""?Y:Y.charCodeAt(0)===47?Y:`/${Y}`,this.config.prefix&&!Q&&!this.config.scoped)Y=this.config.prefix+Y;if(W?.type)switch(W.type){case"text":W.type="text/plain";break;case"json":W.type="application/json";break;case"formdata":W.type="multipart/form-data";break;case"urlencoded":W.type="application/x-www-form-urlencoded";break;case"arrayBuffer":W.type="application/octet-stream";break;default:break}const _=this.definitions.type;let B=p(W?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(u(this.config.cookie??{}))if(B)B.schema=R1(B.schema,this.config.cookie??{});else B=p(R.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const K={body:p(W?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:p(W?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:p(W?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:p(W?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:B,response:s0(W?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},G=this.event,U=Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(this.macros.length){const M=(F)=>(V,D)=>{if(typeof V==="function"||Array.isArray(V)){if(!W[F])W[F]=[];if(typeof W[F]==="function")W[F]=[W[F]];if(Array.isArray(V))W[F]=W[F].concat(V);else W[F].push(V);return}const{insert:m="after",stack:V0="local"}=V;if(V0==="global"){if(!Array.isArray(D))if(m==="before")G[F].unshift(D);else G[F].push(D);else if(m==="before")G[F]=D.concat(G[F]);else G[F]=G[F].concat(D);return}else{if(!W[F])W[F]=[];if(typeof W[F]==="function")W[F]=[W[F]];if(!Array.isArray(D))if(m==="before")W[F].unshift(D);else W[F].push(D);else if(m==="before")W[F]=D.concat(W[F]);else W[F]=W[F].concat(D);return}},N={events:{global:G,local:W},onParse:M("parse"),onTransform:M("transform"),onBeforeHandle:M("beforeHandle"),onAfterHandle:M("afterHandle"),onResponse:M("onResponse"),onError:M("error")};for(let F of this.macros)o0(F(N),W)}const w=s(G,W),A=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Y,{validator:K,hooks:w,content:W?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,U,{validator:K,hooks:w,content:W?.type,handle:X});this.routes.push({method:$,path:Y,composed:null,handler:X,hooks:w});return}const z=t1({path:Y,method:$,hooks:w,validator:K,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:J?this.definitions.type:void 0,schema:J?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!A){const M=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Y}`),store:this.store,path:Y,set:{headers:this.setHeaders??{},status:200}},this.decorators);let N;for(let F of Object.values(w.request))try{const V=y(F(M),M.set);if(V!==void 0){N=V;break}}catch(V){N=this.handleError(M,V);break}if(N)z.response=N;else try{z.response=z(M)}catch(F){z.response=this.handleError(M,F)}}const P=this.routes.findIndex((M)=>M.path===Y&&M.method===$);if(P!==-1)this.routes.splice(P,1);if(this.routes.push({method:$,path:Y,composed:z,handler:X,hooks:w}),$==="$INTERNALWS"){const M=this.config.strictPath?void 0:Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const N=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(z),z.response instanceof Response)this.staticRouter.variables+=`const st${N} = staticRouter.handlers[${N}].response\n`;else this.staticRouter.variables+=`const st${N} = staticRouter.handlers[${N}]\n`;if(this.wsPaths[Y]=N,M)this.wsPaths[M]=N}else if(this.wsRouter.add("ws",Y,z),M)this.wsRouter.add("ws",M,z);return}if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const M=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(z),z.response instanceof Response)this.staticRouter.variables+=`const st${M} = staticRouter.handlers[${M}].response\n`;else this.staticRouter.variables+=`const st${M} = staticRouter.handlers[${M}]\n`;if(!this.staticRouter.map[Y])this.staticRouter.map[Y]={code:""};if($==="ALL")this.staticRouter.map[Y].all=`default: return st${M}(ctx)\n`;else if(z.response instanceof Response)this.staticRouter.map[Y].code=`case '${$}': return st${M}.clone()\n${this.staticRouter.map[Y].code}`;else this.staticRouter.map[Y].code=`case '${$}': return st${M}(ctx)\n${this.staticRouter.map[Y].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[U])this.staticRouter.map[U]={code:""};if($==="ALL")this.staticRouter.map[U].all=`default: return st${M}(ctx)\n`;else if(z.response instanceof Response)this.staticRouter.map[U].code=`case '${$}': return st${M}.clone()\n${this.staticRouter.map[U].code}`;else this.staticRouter.map[U].code=`case '${$}': return st${M}(ctx)\n${this.staticRouter.map[U].code}`}}else if(this.router.add($,Y,z),!this.config.strictPath)this.router.add($,Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/",z)}}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=d(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",j1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[_0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,W]of Object.entries($))W.prototype[_0]=X,this.definitions.error[X]=W;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=C1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,X);break;case"transform":this.event.transform.push(X);break;case"beforeHandle":this.event.beforeHandle.push(X);break;case"afterHandle":this.event.afterHandle.push(X);break;case"mapResponse":this.event.mapResponse.push(X);break;case"response":this.event.onResponse.push(X);break;case"trace":this.event.trace.push(X);break;case"error":this.event.error.push(X);break;case"stop":this.event.stop.push(X);break}return this}group($,Z,X){const W=new n({...this.config||{},prefix:""});W.store=this.store,W.definitions=this.definitions,W.getServer=()=>this.server;const J=typeof Z==="object",Q=(J?X:Z)(W);if(this.decorators=d(this.decorators,W.decorators),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(W.routes).forEach(({method:Y,path:_,handler:B,hooks:K})=>{if(_=(J?"":this.config.prefix)+$+_,J){const G=Z,U=K;this.add(Y,_,B,s(G,{...U||{},error:!U.error?Q.event.error:Array.isArray(U.error)?[...U.error||{},...Q.event.error||{}]:[U.error,...Q.event.error||{}]}))}else this.add(Y,_,B,s(K,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=v0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new n({...this.config||{},prefix:""});X.store=this.store,X.definitions=this.definitions;const W=Z(X);if(this.decorators=d(this.decorators,X.decorators),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(X.routes).forEach(({method:J,path:Q,handler:Y,hooks:_})=>{this.add(J,Q,Y,s($,{..._||{},error:!_.error?W.event.error:Array.isArray(_.error)?[..._.error||{},...W.event.error||[]]:[_.error,...W.event.error||[]]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const J=$(this);if(J instanceof Promise)return this.lazyLoadModules.push(J.then((Q)=>{if(Q instanceof n){this.compile();for(let{method:Y,path:_,handler:B,hooks:K}of Object.values(Q.routes))this.add(Y,_,B,s(K,{error:Q.event.error}));return Q}if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return J}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const W=$.config.scoped;if(W){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const Q=X!==void 0?N0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>Q===Y))return this;this.dependencies[Z].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:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros||[],...$.macros||[]],$.onRequest((Q)=>{Object.assign(Q,this.decorators),Object.assign(Q.store,this.store)}),$.event.trace=[...this.event.trace||[],...$.event.trace||[]],$.config.aot)$.compile();if(W&&!$.config.prefix)console.warn("When using scoped plugins it is recommended to use a prefix, else routing may not work correctly for the second scoped instance");let J;if(W&&$.config.prefix)J=this.mount($.config.prefix+"/",$.fetch);else J=this.mount($.fetch);return this.routes=this.routes.concat(J.routes),this}else{$.reporter=this.reporter;for(let J of $.event.trace)this.trace(J);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const J=X!==void 0?N0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:Y})=>J===Y))this.macros.push(...$.macros||[]);const Q=[];for(let Y=0;Y<this.macros.length;Y++){const _=this.macros[Y];if(Q.includes(_.$elysiaChecksum))this.macros.splice(Y,1),Y--;Q.push(_.$elysiaChecksum)}}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:J,path:Q,handler:Y,hooks:_}of Object.values($.routes))this.add(J,Q,Y,s(_,{error:$.event.error}));if(!W)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const J=X!==void 0?N0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Q})=>J===Q))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:J,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:J,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q?.$elysia==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q?.$elysia==="resolve").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))}),this.event=v0(this.event,a0($.event),J)}else this.event=v0(this.event,a0($.event));return this}macro($){return $.$elysiaChecksum=N0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),this.macros.push($),this}mount($,Z){if($ instanceof n||typeof $==="function"||$.length===0||$==="/"){const J=typeof $==="function"?$:$ instanceof n?$.compile().fetch:Z instanceof n?Z.compile().fetch:Z,Q=async({request:Y,path:_})=>J(new Request(t0(Y.url,_||"/"),Y));return this.all("/",Q,{type:"none"}),this.all("/*",Q,{type:"none"}),this}const X=$.length;if(Z instanceof n)Z=Z.compile().fetch;const W=async({request:J,path:Q})=>Z(new Request(t0(J.url,Q.slice(X)||"/"),J));return this.all($,W,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),W,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let W=null;const J=p(Z?.body,{models:this.definitions.type}),Q=p(Z?.response,{models:this.definitions.type}),Y=(_)=>{if(typeof _==="string"){const B=_?.charCodeAt(0);if(B===47||B===123)try{_=JSON.parse(_)}catch{}else if(f0(_))_=+_}if(X?.length)for(let B=0;B<X.length;B++){const K=X[B](_);if(K!==void 0)_=K}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:B,path:K,qi:G,headers:U,query:w,params:A}=_;if(W===null)W=this.getServer();if(W?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:Q,open(z){Z.open?.(new D0(z,_))},message:(z,P)=>{const M=Y(P);if(J?.Check(M)===!1)return void z.send(new q("message",J,M).message);Z.message?.(new D0(z,_),M)},drain(z){Z.drain?.(new D0(z,_))},close(z,P,M){Z.close?.(new D0(z,_),P,M)}}}))return;return B.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:W,...J}={config:{allowMeta:!1}}){return this.add($,Z,X,J,W),this}state($,Z){switch(typeof $){case"object":return this.store=d(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=d(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,W])=>{if(!(X in this.definitions.type))this.definitions.type[X]=W}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const W=["_","-"," "],J=(B)=>B[0].toUpperCase()+B.slice(1),Q=$==="prefix"?(B,K)=>W.includes(B.at(-1)??"")?B+K:B+J(K):W.includes(X.at(-1)??"")?(B,K)=>K+B:(B,K)=>K+J(B),Y=(B)=>{const K={};switch(B){case"decorator":for(let G in this.decorators)K[Q(X,G)]=this.decorators[G];this.decorators=K;break;case"state":for(let G in this.store)K[Q(X,G)]=this.store[G];this.store=K;break;case"model":for(let G in this.definitions.type)K[Q(X,G)]=this.definitions.type[G];this.definitions.type=K;break;case"error":for(let G in this.definitions.error)K[Q(X,G)]=this.definitions.error[G];this.definitions.error=K;break}},_=Array.isArray(Z)?Z:[Z];for(let B of _.some((K)=>K==="all")?["decorator","state","model","error"]:_)Y(B);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?Q1(this):_1(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?Q1(this):_1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?B1(this):s1(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{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($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,W=typeof $==="object"?{development:!F0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...$1||{}},fetch:X,error:this.outerErrorHandler}:{development:!F0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...$1||{}},port:$,fetch:X,error:this.outerErrorHandler};if(this.server=Bun?.serve(W),this.event.start.length)for(let J=0;J<this.event.start.length;J++)this.event.start[J](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let J=0;J<this.event.stop.length;J++)this.event.stop[J](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{R as t,H as mergeObjectArray,s as mergeHook,d as mergeDeep,v as mapResponse,y as mapEarlyResponse,l as mapCompactResponse,p as getSchemaValidator,s0 as getResponseSchemaValidator,j$ as error,n as default,q as ValidationError,q1 as ParseError,e as NotFoundError,U0 as InvalidCookieSignature,m0 as InternalServerError,n as Elysia,k as Cookie};
|
|
365
|
+
}`,Function("inject",Z)({app:$,mapResponse:v,ERROR_CODE:_0,ELYSIA_RESPONSE:c})};var u0=T0(J1(),1);var _1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let W;if($.decorators)W=$.decorators,W.request=Z,W.set=X,W.store=$.store;else W={set:X,store:$.store,request:Z};const J=Z.url,Y=J.indexOf("/",11),Q=J.indexOf("?",Y+1),_=Q===-1?J.substring(Y):J.substring(Y,Q);try{for(let U=0;U<$.event.request.length;U++){const j=$.event.request[U];let N=j(W);if(N instanceof Promise)N=await N;if(N=y(N,X),N)return N}const B=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!B)throw new e;const{handle:K,hooks:G,validator:M,content:V}=B.store;let P;if(Z.method!=="GET"&&Z.method!=="HEAD")if(V)switch(V){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=u0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const U=await Z.formData();for(let j of U.keys()){if(P[j])continue;const N=U.getAll(j);if(N.length===1)P[j]=N[0];else P[j]=N}break}else{let U=Z.headers.get("content-type");if(U){const j=U.indexOf(";");if(j!==-1)U=U.slice(0,j);for(let N=0;N<G.parse.length;N++){let w=G.parse[N](W,U);if(w instanceof Promise)w=await w;if(w){P=w;break}}if(P===void 0)switch(U){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=u0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const N=await Z.formData();for(let w of N.keys()){if(P[w])continue;const D=N.getAll(w);if(D.length===1)P[w]=D[0];else P[w]=D}break}}}W.body=P,W.params=B?.params||void 0,W.query=Q===-1?{}:u0.parse(J.substring(Q+1)),W.headers={};for(let[U,j]of Z.headers.entries())W.headers[U]=j;const z=M?.cookie?.schema;W.cookie=await g0(W.set,W.headers.cookie,z?{secret:z.secrets!==void 0?typeof z.secrets==="string"?z.secrets:z.secrets.join(","):void 0,sign:z.sign===!0?!0:z.sign!==void 0?typeof z.sign==="string"?z.sign:z.sign.join(","):void 0}:void 0);for(let U=0;U<G.transform.length;U++){const j=G.transform[U](W);if(G.transform[U].$elysia==="derive")if(j instanceof Promise)Object.assign(W,await j);else Object.assign(W,j);else if(j instanceof Promise)await j}if(M){if(M.headers){const U={};for(let j in Z.headers)U[j]=Z.headers.get(j);if(M.headers.Check(U)===!1)throw new q("header",M.headers,U)}if(M.params?.Check(W.params)===!1)throw new q("params",M.params,W.params);if(M.query?.Check(W.query)===!1)throw new q("query",M.query,W.query);if(M.cookie){const U={};for(let[j,N]of Object.entries(W.cookie))U[j]=N.value;if(M.cookie?.Check(U)===!1)throw new q("cookie",M.cookie,U)}if(M.body?.Check(P)===!1)throw new q("body",M.body,P)}for(let U=0;U<G.beforeHandle.length;U++){let j=G.beforeHandle[U](W);if(j instanceof Promise)j=await j;if(j!==void 0){W.response=j;for(let w=0;w<G.afterHandle.length;w++){let D=G.afterHandle[w](W);if(D instanceof Promise)D=await D;if(D)j=D}const N=y(j,W.set);if(N)return N}}let A=K(W);if(A instanceof Promise)A=await A;if(!G.afterHandle.length){const U=M?.response?.[A.status];if(U?.Check(A)===!1)throw new q("response",U,A)}else{W.response=A;for(let U=0;U<G.afterHandle.length;U++){let j=G.afterHandle[U](W);if(j instanceof Promise)j=await j;const N=y(j,W.set);if(N!==void 0){const w=M?.response?.[A.status];if(w?.Check(N)===!1)throw new q("response",w,N);return N}}}if(W.set.cookie&&z?.sign){const U=!z.secrets?void 0:typeof z.secrets==="string"?z.secrets:z.secrets[0];if(z.sign===!0)for(let[j,N]of Object.entries(W.set.cookie))W.set.cookie[j].value=await B0(N.value,"${secret}");else for(let j of z.sign){if(!(j in z.properties))continue;if(W.set.cookie[j]?.value)W.set.cookie[j].value=await B0(W.set.cookie[j].value,U)}}return v(A,W.set)}catch(B){if(B.status)X.status=B.status;return $.handleError(W,B)}finally{for(let B of $.event.onResponse)await B(W)}},s1=($)=>async(Z,X)=>{const W=Object.assign(Z,{error:X,code:X.code});W.set=Z.set;for(let J=0;J<$.event.error.length;J++){let Y=$.event.error[J](W);if(Y instanceof Promise)Y=await Y;if(Y!==void 0&&Y!==null)return v(Y,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};import{TypeSystem as K0} from"@sinclair/typebox/system";import{Type as D1,FormatRegistry as K1} from"@sinclair/typebox";import{Value as a1} from"@sinclair/typebox/value";import{TypeSystemPolicy as k6,TypeSystem as m6,TypeSystemDuplicateFormat as u6,TypeSystemDuplicateTypeKind as h6} from"@sinclair/typebox/system";import{TypeCompiler as d6,TypeCheck as p6} from"@sinclair/typebox/compiler";var C=Object.assign({},D1);try{K0.Format("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.test($)),K0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),K0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),K0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch{}var o1=($)=>{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 $},G1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<o1($.minSize))return!1;if($.maxSize&&Z.size>o1($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},L$=K0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return G1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!G1($,Z[X]))return!1;return!0});K1.Set("numeric",($)=>!!$&&!isNaN(+$));K1.Set("boolean",($)=>$==="true"||$==="false");K1.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const Z=D1.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((X)=>{const W=+X;if(isNaN(W))return X;if($&&!a1.Check(Z,W))throw new q("property",Z,W);return W}).Encode((X)=>X)},BooleanString:($)=>{const Z=D1.Boolean($);return C.Transform(C.Union([C.String({format:"boolean",default:!1}),C.Boolean($)],$)).Decode((X)=>{if(typeof X==="string")return X==="true";if($&&!a1.Check(Z,X))throw new q("property",Z,X);return X}).Encode((X)=>X)},ObjectString:($,Z)=>C.Transform(C.Union([C.String({format:"ObjectString",default:""}),C.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:K0.Type("File",G1),Files:($={})=>C.Transform(C.Union([L$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,Z)=>C.Object($,Z)};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;class r{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new N1;server=null;getServer(){return this.server}validator=null;router=new o;wsRouter=new o;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new o;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$||{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,W,{allowMeta:J=!1,skipPrefix:Y=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Q of Z){if(Q=Q===""?Q:Q.charCodeAt(0)===47?Q:`/${Q}`,this.config.prefix&&!Y&&!this.config.scoped)Q=this.config.prefix+Q;if(W?.type)switch(W.type){case"text":W.type="text/plain";break;case"json":W.type="application/json";break;case"formdata":W.type="multipart/form-data";break;case"urlencoded":W.type="application/x-www-form-urlencoded";break;case"arrayBuffer":W.type="application/octet-stream";break;default:break}const _=this.definitions.type;let B=p(W?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(u(this.config.cookie??{}))if(B)B.schema=C1(B.schema,this.config.cookie??{});else B=p(C.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const K={body:p(W?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:p(W?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:p(W?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:p(W?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:B,response:s0(W?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},G=this.event,M=Q.endsWith("/")?Q.slice(0,Q.length-1):Q+"/";if(this.macros.length){const U=(N)=>(w,D)=>{if(typeof w==="function"||Array.isArray(w)){if(!W[N])W[N]=[];if(typeof W[N]==="function")W[N]=[W[N]];if(Array.isArray(w))W[N]=W[N].concat(w);else W[N].push(w);return}const{insert:k="after",stack:w0="local"}=w;if(w0==="global"){if(!Array.isArray(D))if(k==="before")G[N].unshift(D);else G[N].push(D);else if(k==="before")G[N]=D.concat(G[N]);else G[N]=G[N].concat(D);return}else{if(!W[N])W[N]=[];if(typeof W[N]==="function")W[N]=[W[N]];if(!Array.isArray(D))if(k==="before")W[N].unshift(D);else W[N].push(D);else if(k==="before")W[N]=D.concat(W[N]);else W[N]=W[N].concat(D);return}},j={events:{global:G,local:W},onParse:U("parse"),onTransform:U("transform"),onBeforeHandle:U("beforeHandle"),onAfterHandle:U("afterHandle"),onResponse:U("onResponse"),onError:U("error")};for(let N of this.macros)o0(N(j),W)}const V=n(G,W),P=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Q,{validator:K,hooks:V,content:W?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,M,{validator:K,hooks:V,content:W?.type,handle:X});this.routes.push({method:$,path:Q,composed:null,handler:X,hooks:V});return}const z=t1({path:Q,method:$,hooks:V,validator:K,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:J?this.definitions.type:void 0,schema:J?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!P){const U=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Q}`),store:this.store,path:Q,set:{headers:this.setHeaders??{},status:200}},this.decorators);let j;for(let N of Object.values(V.request))try{const w=y(N(U),U.set);if(w!==void 0){j=w;break}}catch(w){j=this.handleError(U,w);break}if(j)z.response=j;else try{z.response=z(U)}catch(N){z.response=this.handleError(U,N)}}const A=this.routes.findIndex((U)=>U.path===Q&&U.method===$);if(A!==-1)this.routes.splice(A,1);if(this.routes.push({method:$,path:Q,composed:z,handler:X,hooks:V}),$==="$INTERNALWS"){const U=this.config.strictPath?void 0:Q.endsWith("/")?Q.slice(0,Q.length-1):Q+"/";if(Q.indexOf(":")===-1&&Q.indexOf("*")===-1){const j=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(z),z.response instanceof Response)this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}].response\n`;else this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}]\n`;if(this.wsPaths[Q]=j,U)this.wsPaths[U]=j}else if(this.wsRouter.add("ws",Q,z),U)this.wsRouter.add("ws",U,z);return}if(Q.indexOf(":")===-1&&Q.indexOf("*")===-1){const U=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(z),z.response instanceof Response)this.staticRouter.variables+=`const st${U} = staticRouter.handlers[${U}].response\n`;else this.staticRouter.variables+=`const st${U} = staticRouter.handlers[${U}]\n`;if(!this.staticRouter.map[Q])this.staticRouter.map[Q]={code:""};if($==="ALL")this.staticRouter.map[Q].all=`default: return st${U}(ctx)\n`;else if(z.response instanceof Response)this.staticRouter.map[Q].code=`case '${$}': return st${U}.clone()\n${this.staticRouter.map[Q].code}`;else this.staticRouter.map[Q].code=`case '${$}': return st${U}(ctx)\n${this.staticRouter.map[Q].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[M])this.staticRouter.map[M]={code:""};if($==="ALL")this.staticRouter.map[M].all=`default: return st${U}(ctx)\n`;else if(z.response instanceof Response)this.staticRouter.map[M].code=`case '${$}': return st${U}.clone()\n${this.staticRouter.map[M].code}`;else this.staticRouter.map[M].code=`case '${$}': return st${U}(ctx)\n${this.staticRouter.map[M].code}`}}else if(this.router.add($,Q,z),!this.config.strictPath)this.router.add($,Q.endsWith("/")?Q.slice(0,Q.length-1):Q+"/",z)}}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=d(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",F1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[_0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,W]of Object.entries($))W.prototype[_0]=X,this.definitions.error[X]=W;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=R1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,X);break;case"transform":this.event.transform.push(X);break;case"beforeHandle":this.event.beforeHandle.push(X);break;case"afterHandle":this.event.afterHandle.push(X);break;case"mapResponse":this.event.mapResponse.push(X);break;case"response":this.event.onResponse.push(X);break;case"trace":this.event.trace.push(X);break;case"error":this.event.error.push(X);break;case"stop":this.event.stop.push(X);break}return this}group($,Z,X){const W=new r({...this.config||{},prefix:""});W.store=this.store,W.definitions=this.definitions,W.getServer=()=>this.server;const J=typeof Z==="object",Y=(J?X:Z)(W);if(this.decorators=d(this.decorators,W.decorators),Y.event.request.length)this.event.request=[...this.event.request||[],...Y.event.request||[]];if(Y.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...Y.event.onResponse||[]];return this.model(Y.definitions.type),Object.values(W.routes).forEach(({method:Q,path:_,handler:B,hooks:K})=>{if(_=(J?"":this.config.prefix)+$+_,J){const G=Z,M=K;this.add(Q,_,B,n(G,{...M||{},error:!M.error?Y.event.error:Array.isArray(M.error)?[...M.error||{},...Y.event.error||{}]:[M.error,...Y.event.error||{}]}))}else this.add(Q,_,B,n(K,{error:Y.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=v0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new r({...this.config||{},prefix:""});X.store=this.store,X.definitions=this.definitions;const W=Z(X);if(this.decorators=d(this.decorators,X.decorators),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(X.routes).forEach(({method:J,path:Y,handler:Q,hooks:_})=>{this.add(J,Y,Q,n($,{..._||{},error:!_.error?W.event.error:Array.isArray(_.error)?[..._.error||{},...W.event.error||[]]:[_.error,...W.event.error||[]]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const J=$(this);if(J instanceof Promise)return this.lazyLoadModules.push(J.then((Y)=>{if(Y instanceof r){this.compile();for(let{method:Q,path:_,handler:B,hooks:K}of Object.values(Y.routes))this.add(Q,_,B,n(K,{error:Y.event.error}));return Y}if(typeof Y==="function")return Y(this);if(typeof Y.default==="function")return Y.default(this);return this._use(Y)}).then((Y)=>Y.compile())),this;return J}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const W=$.config.scoped;if(W){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const Y=X!==void 0?j0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Q})=>Y===Q))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Y,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Y,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q.$elysia==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q.$elysia==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros||[],...$.macros||[]],$.onRequest((Y)=>{Object.assign(Y,this.decorators),Object.assign(Y.store,this.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(W&&!$.config.prefix)console.warn("When using scoped plugins it is recommended to use a prefix, else routing may not work correctly for the second scoped instance");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();let J;if(W&&$.config.prefix){J=this.mount($.config.prefix+"/",$.fetch);for(let Y of $.routes)this.routes.push({...Y,path:`${$.config.prefix}${Y.path}`,hooks:n(Y.hooks,{error:this.event.error})})}else if(J=this.mount($.fetch),J.routes.length)this.routes.push(...J.routes);return this}else{$.reporter=this.reporter;for(let J of $.event.trace)this.trace(J);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const J=X!==void 0?j0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:Q})=>J===Q))this.macros.push(...$.macros||[]);const Y=[];for(let Q=0;Q<this.macros.length;Q++){const _=this.macros[Q];if(Y.includes(_.$elysiaChecksum))this.macros.splice(Q,1),Q--;Y.push(_.$elysiaChecksum)}}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:J,path:Y,handler:Q,hooks:_}of Object.values($.routes))this.add(J,Y,Q,n(_,{error:$.event.error}));if(!W)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const J=X!==void 0?j0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>J===Y))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:J,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:J,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y?.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y?.$elysia==="resolve").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))}),this.event=v0(this.event,a0($.event),J)}else this.event=v0(this.event,a0($.event));return this}macro($){return $.$elysiaChecksum=j0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),this.macros.push($),this}mount($,Z){if($ instanceof r||typeof $==="function"||$.length===0||$==="/"){const J=typeof $==="function"?$:$ instanceof r?$.compile().fetch:Z instanceof r?Z.compile().fetch:Z,Y=async({request:Q,path:_})=>J(new Request(t0(Q.url,_||"/"),Q));return this.all("/",Y,{type:"none"}),this.all("/*",Y,{type:"none"}),this}const X=$.length;if(Z instanceof r)Z=Z.compile().fetch;const W=async({request:J,path:Y})=>Z(new Request(t0(J.url,Y.slice(X)||"/"),J));return this.all($,W,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),W,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let W=null;const J=p(Z?.body,{models:this.definitions.type}),Y=p(Z?.response,{models:this.definitions.type}),Q=(_)=>{if(typeof _==="string"){const B=_?.charCodeAt(0);if(B===47||B===123)try{_=JSON.parse(_)}catch{}else if(f0(_))_=+_}if(X?.length)for(let B=0;B<X.length;B++){const K=X[B](_);if(K!==void 0)_=K}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:B,path:K,qi:G,headers:M,query:V,params:P}=_;if(W===null)W=this.getServer();if(W?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:Y,open(z){Z.open?.(new D0(z,_))},message:(z,A)=>{const U=Q(A);if(J?.Check(U)===!1)return void z.send(new q("message",J,U).message);Z.message?.(new D0(z,_),U)},drain(z){Z.drain?.(new D0(z,_))},close(z,A,U){Z.close?.(new D0(z,_),A,U)}}}))return;return B.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:W,...J}={config:{allowMeta:!1}}){return this.add($,Z,X,J,W),this}state($,Z){switch(typeof $){case"object":return this.store=d(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=d(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,W])=>{if(!(X in this.definitions.type))this.definitions.type[X]=W}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const W=["_","-"," "],J=(B)=>B[0].toUpperCase()+B.slice(1),Y=$==="prefix"?(B,K)=>W.includes(B.at(-1)??"")?B+K:B+J(K):W.includes(X.at(-1)??"")?(B,K)=>K+B:(B,K)=>K+J(B),Q=(B)=>{const K={};switch(B){case"decorator":for(let G in this.decorators)K[Y(X,G)]=this.decorators[G];this.decorators=K;break;case"state":for(let G in this.store)K[Y(X,G)]=this.store[G];this.store=K;break;case"model":for(let G in this.definitions.type)K[Y(X,G)]=this.definitions.type[G];this.definitions.type=K;break;case"error":for(let G in this.definitions.error)K[Y(X,G)]=this.definitions.error[G];this.definitions.error=K;break}},_=Array.isArray(Z)?Z:[Z];for(let B of _.some((K)=>K==="all")?["decorator","state","model","error"]:_)Q(B);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?Y1(this):_1(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?Y1(this):_1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?B1(this):s1(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{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($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,W=typeof $==="object"?{development:!N0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...$1||{}},fetch:X,error:this.outerErrorHandler}:{development:!N0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...$1||{}},port:$,fetch:X,error:this.outerErrorHandler};if(this.server=Bun?.serve(W),this.event.start.length)for(let J=0;J<this.event.start.length;J++)this.event.start[J](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let J=0;J<this.event.stop.length;J++)this.event.stop[J](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{C as t,H as mergeObjectArray,n as mergeHook,d as mergeDeep,v as mapResponse,y as mapEarlyResponse,l as mapCompactResponse,p as getSchemaValidator,s0 as getResponseSchemaValidator,F$ as error,r as default,q as ValidationError,q1 as ParseError,e as NotFoundError,M0 as InvalidCookieSignature,k0 as InternalServerError,r as Elysia,m as Cookie};
|
|
366
366
|
|
|
367
|
-
//# debugId=
|
|
367
|
+
//# debugId=665184B9A978EC0364756e2164756e21
|