elysia 1.1.13 → 1.1.14
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 +6 -6
- package/dist/bun/index.js.map +3 -3
- package/dist/cjs/compose.js +6 -8
- package/dist/cjs/dynamic-handle.js +6 -8
- package/dist/cjs/handler.js +9 -9
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/types.d.ts +2 -1
- package/dist/compose.mjs +6 -8
- package/dist/dynamic-handle.mjs +6 -8
- package/dist/handler.mjs +9 -9
- package/dist/index.mjs +10 -10
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var C2=Object.create;var{getPrototypeOf:S2,defineProperty:f1,getOwnPropertyNames:L2}=Object;var T2=Object.prototype.hasOwnProperty;var w1=($,W,X)=>{X=$!=null?C2(S2($)):{};const Z=W||!$||!$.__esModule?f1(X,"default",{value:$,enumerable:!0}):X;for(let J of L2($))if(!T2.call(Z,J))f1(Z,J,{get:()=>$[J],enumerable:!0});return Z};var q2=($,W)=>()=>(W||$((W={exports:{}}).exports,W),W.exports);var e0=q2((J8,o1)=>{function U3($){var W=$.indexOf("%");if(W===-1)return $;var X=$.length,Z="",J=0,j=0,Q=W,Y=r1;while(W>-1&&W<X){var K=a1($[W+1],4),B=a1($[W+2],0),U=K|B,w=P1[U];if(Y=P1[256+Y+w],j=j<<6|U&P1[364+w],Y===r1)Z+=$.slice(J,Q),Z+=j<=65535?String.fromCharCode(j):String.fromCharCode(55232+(j>>10),56320+(j&1023)),j=0,J=W+3,W=Q=$.indexOf("%",J);else if(Y===K3)return null;else{if(W+=3,W<X&&$.charCodeAt(W)===37)continue;return null}}return Z+$.slice(J)}function a1($,W){var X=w3[$];return X===void 0?255:X<<W}var r1=12,K3=0,P1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],w3={"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};o1.exports=U3});var q0=($,W)=>{const X=W?.length?{}:null;if(X)for(let Z of W)X[Z.part.charCodeAt(0)]=Z;return{part:$,store:null,inert:X,params:null,wildcardStore:null}},y1=($,W)=>({...$,part:W}),k1=($)=>({name:$,store:null,inert:null});class M0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g,optionalParams:/:.+?\?(?=\/|$)/g};add($,W,X,{ignoreError:Z=!1,ignoreHistory:J=!1}={}){if(typeof W!=="string")throw new TypeError("Route path must be a string");if(W==="")W="/";else if(W[0]!=="/")W=`/${W}`;const j=W[W.length-1]==="*",Q=W.match(M0.regex.optionalParams);if(Q){const w=W.replaceAll("?","");this.add($,w,X,{ignoreError:Z});for(let F=0;F<Q.length;F++){let G=W.replace("/"+Q[F],"");this.add($,G,X,{ignoreError:!0})}return X}if(Q)W=W.replaceAll("?","");if(this.history.find(([w,F,G])=>w===$&&F===W))return X;if(j||Q&&W.charCodeAt(W.length-1)===63)W=W.slice(0,-1);if(!J)this.history.push([$,W,X]);const Y=W.split(M0.regex.static),K=W.match(M0.regex.params)||[];if(Y[Y.length-1]==="")Y.pop();let B;if(!this.root[$])B=this.root[$]=q0("/");else B=this.root[$];let U=0;for(let w=0;w<Y.length;++w){let F=Y[w];if(w>0){const G=K[U++].slice(1);if(B.params===null)B.params=k1(G);else if(B.params.name!==G)if(Z)return X;else throw new Error(`Cannot create route "${W}" with parameter "${G}" because a route already exists with a different parameter name ("${B.params.name}") in the same location`);const z=B.params;if(z.inert===null){B=z.inert=q0(F);continue}B=z.inert}for(let G=0;;){if(G===F.length){if(G<B.part.length){const z=y1(B,B.part.slice(G));Object.assign(B,q0(F,[z]))}break}if(G===B.part.length){if(B.inert===null)B.inert={};const z=B.inert[F.charCodeAt(G)];if(z){B=z,F=F.slice(G),G=0;continue}const D=q0(F.slice(G));B.inert[F.charCodeAt(G)]=D,B=D;break}if(F[G]!==B.part[G]){const z=y1(B,B.part.slice(G)),D=q0(F.slice(G));Object.assign(B,q0(B.part.slice(0,G),[z,D])),B=D;break}++G}}if(U<K.length){const w=K[U].slice(1);if(B.params===null)B.params=k1(w);else if(B.params.name!==w)if(Z)return X;else throw new Error(`Cannot create route "${W}" with parameter "${w}" because a route already exists with a different parameter name ("${B.params.name}") in the same location`);if(B.params.store===null)B.params.store=X;return B.params.store}if(j){if(B.wildcardStore===null)B.wildcardStore=X;return B.wildcardStore}if(B.store===null)B.store=X;return B.store}find($,W){const X=this.root[$];if(!X)return null;return _1(W,W.length,X,0)}}var _1=($,W,X,Z)=>{const J=X.part,j=J.length,Q=Z+j;if(j>1){if(Q>W)return null;if(j<15){for(let Y=1,K=Z+1;Y<j;++Y,++K)if(J.charCodeAt(Y)!==$.charCodeAt(K))return null}else if($.slice(Z,Q)!==J)return null}if(Q===W){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[$.charCodeAt(Q)];if(Y!==void 0){const K=_1($,W,Y,Q);if(K!==null)return K}}if(X.params!==null){const{store:Y,name:K,inert:B}=X.params,U=$.indexOf("/",Q);if(U!==Q){if(U===-1||U>=W){if(Y!==null){const w={};return w[K]=$.substring(Q,W),{store:Y,params:w}}}else if(B!==null){const w=_1($,W,B,U);if(w!==null)return w.params[K]=$.substring(Q,U),w}}}if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":$.substring(Q,W)}};return null};var E0=($)=>{const W=typeof $==="object"?$.fn.toString():typeof $==="string"?$.toString():$,X=W.indexOf(")");if(W.charCodeAt(X+2)===61&&W.charCodeAt(X+5)!==123)return!0;return W.includes("return")},E2=($)=>{if($.startsWith("async"))$=$.slice(5);$=$.trimStart();let W=-1;if($.charCodeAt(0)===40){if(W=$.indexOf("=>",$.indexOf(")")),W!==-1){let J=W;while(J>0)if($.charCodeAt(--J)===41)break;let j=$.slice(W+2);if(j.charCodeAt(0)===32)j=j.trimStart();return[$.slice(1,J),j,{isArrowReturn:j.charCodeAt(0)!==123}]}}if($.startsWith("function")){W=$.indexOf("(");const J=$.indexOf(")");return[$.slice(W+1,J),$.slice(J+2),{isArrowReturn:!1}]}const X=$.indexOf("(");if(X!==-1){const J=$.indexOf("\n",2),j=$.slice(0,J),Q=j.lastIndexOf(")")+1,Y=$.slice(J+1);return[j.slice(X,Q),"{"+Y,{isArrowReturn:!1}]}const Z=$.split("\n",2);return[Z[0],Z[1],{isArrowReturn:!1}]},H2=($)=>{const W=$.indexOf("{");if(W===-1)return[-1,0];let X=W+1,Z=1;for(;X<$.length;X++){const J=$.charCodeAt(X);if(J===123)Z++;else if(J===125)Z--;if(Z===0)break}if(Z!==0)return[0,$.length];return[W,X+1]},R2=($)=>{const W=$.lastIndexOf("}");if(W===-1)return[-1,0];let X=W-1,Z=1;for(;X>=0;X--){const J=$.charCodeAt(X);if(J===125)Z++;else if(J===123)Z--;if(Z===0)break}if(Z!==0)return[-1,0];return[X,W+1]},v1=($)=>{while(!0){const W=$.indexOf(":");if(W===-1)break;let X=$.indexOf(",",W);if(X===-1)X=$.indexOf("}",W)-1;if(X===-2)X=$.length;$=$.slice(0,W)+$.slice(X)}return $},u1=($)=>{let W=!1;if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)W=!0,$=$.slice(1,-1);$=$.replace(/( |\t|\n)/g,"").trim();let X=[];while(!0){let[J,j]=H2($);if(J===-1)break;if(X.push($.slice(0,J-1)),$.charCodeAt(j)===44)j++;$=$.slice(j)}if($=v1($),$)X=X.concat($.split(","));const Z=[];for(let J of X){if(J.indexOf(",")===-1){Z.push(J);continue}for(let j of J.split(","))Z.push(j.trim())}return X=Z,{hasParenthesis:W,parameters:X}},b2=($,W)=>{const{parameters:X,hasParenthesis:Z}=u1($);if(!W.query&&X.includes("query"))W.query=!0;if(!W.headers&&X.includes("headers"))W.headers=!0;if(!W.body&&X.includes("body"))W.body=!0;if(!W.cookie&&X.includes("cookie"))W.cookie=!0;if(!W.set&&X.includes("set"))W.set=!0;if(!W.server&&X.includes("server"))W.server=!0;if(Z)return`{ ${X.join(", ")} }`;return X.join(", ")},x2=($,W,X)=>{const Z=W.indexOf($+"\n",X),J=W.indexOf($+"\t",X),j=W.indexOf($+",",X),Q=W.indexOf($+";",X),Y=W.indexOf($+" ",X);return[Z,J,j,Q,Y].filter((K)=>K>0).sort((K,B)=>K-B)[0]||-1};var h1=($,W,X=0)=>{if(X>5)return[];const Z=[];let J=W;while(!0){let j=x2(" = "+$,J);if(j===-1){const K=J.indexOf(" = "+$);if(K+3+$.length!==J.length)break;j=K}const Q=J.slice(0,j);let Y=Q.slice(Q.lastIndexOf(" ")+1);if(Y==="}"){const[K,B]=R2(Q);Z.push(v1(J.slice(K,B))),J=J.slice(j+3+$.length);continue}while(Y.charCodeAt(0)===44)Y=Y.slice(1);while(Y.charCodeAt(0)===9)Y=Y.slice(1);if(!Y.includes("("))Z.push(Y);J=J.slice(j+3+$.length)}for(let j of Z){if(j.charCodeAt(0)===123)continue;const Q=h1(j,W);if(Q.length>0)Z.push(...Q)}return Z},g2=($)=>{if(!$)return;if($.charCodeAt(0)!==123)return $;if($=$.slice(2,-2),!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return}const X=$.indexOf("...");if(X===-1)return;return $.slice(X+3).trimEnd()},f2=($,W,X)=>{const Z=(J,j)=>$.includes(j+"."+J)||$.includes(j+'["'+J+'"]')||$.includes(j+"['"+J+"']");for(let J of W){if(!J)continue;if(J.charCodeAt(0)===123){const j=u1(J).parameters;if(!X.query&&j.includes("query"))X.query=!0;if(!X.headers&&j.includes("headers"))X.headers=!0;if(!X.body&&j.includes("body"))X.body=!0;if(!X.cookie&&j.includes("cookie"))X.cookie=!0;if(!X.set&&j.includes("set"))X.set=!0;if(!X.query&&j.includes("server"))X.server=!0;continue}if(!X.query&&Z("query",J))X.query=!0;if($.includes("return "+J)||$.includes("return "+J+".query"))X.query=!0;if(!X.headers&&Z("headers",J))X.headers=!0;if(!X.body&&Z("body",J))X.body=!0;if(!X.cookie&&Z("cookie",J))X.cookie=!0;if(!X.set&&Z("set",J))X.set=!0;if(!X.server&&Z("server",J))X.server=!0;if(X.query&&X.headers&&X.body&&X.cookie&&X.set&&X.server)break}return W};var y2=($,W,X)=>{try{const Z=new RegExp(`(?:\\w)\\((?:.*)?${$}`,"gs");Z.test(W);const J=W.charCodeAt(Z.lastIndex);if(J===41||J===44)return X.query=!0,X.headers=!0,X.body=!0,X.cookie=!0,X.set=!0,X.server=!0,!0;return!1}catch(Z){return console.log("[Sucrose] warning: unexpected isContextPassToFunction error, you may continue development as usual but please report the following to maintainers:"),console.log("--- body ---"),console.log(W),console.log("--- context ---"),console.log($),!0}},r0=($,W={query:!1,headers:!1,body:!1,cookie:!1,set:!1,server:!1})=>{const X=[];if($.handler&&typeof $.handler==="function")X.push($.handler);if($.request?.length)X.push(...$.request);if($.beforeHandle?.length)X.push(...$.beforeHandle);if($.parse?.length)X.push(...$.parse);if($.error?.length)X.push(...$.error);if($.transform?.length)X.push(...$.transform);if($.afterHandle?.length)X.push(...$.afterHandle);if($.mapResponse?.length)X.push(...$.mapResponse);if($.afterResponse?.length)X.push(...$.afterResponse);for(let Z of X){if(!Z)continue;const J="fn"in Z?Z.fn:Z,[j,Q,{isArrowReturn:Y}]=E2(J.toString()),K=b2(j,W),B=g2(K);if(B){const U=h1(B,Q);if(U.splice(0,-1,B),!y2(B,Q,W))f2(Q,U,W);if(!W.query&&Q.includes("return "+B+".query"))W.query=!0}if(W.query&&W.headers&&W.body&&W.cookie&&W.set&&W.server)break}return W};import{Value as p0}from"@sinclair/typebox/value";import{Kind as R0,TransformKind as j2}from"@sinclair/typebox";import{Value as l}from"@sinclair/typebox/value";import{TypeCompiler as G2}from"@sinclair/typebox/compiler";import{Kind as o2,TypeRegistry as z1}from"@sinclair/typebox";import{TypeSystem as H0}from"@sinclair/typebox/system";import{Type as v0,FormatRegistry as W0}from"@sinclair/typebox";import{TypeCompiler as l1}from"@sinclair/typebox/compiler";import{Value as $0}from"@sinclair/typebox/value";function k2($){return $%4===0&&($%100!==0||$%400===0)}function p1($){const W=v2.exec($);if(!W)return!1;const X=+W[1],Z=+W[2],J=+W[3];return Z>=1&&Z<=12&&J>=1&&J<=(Z===2&&k2(X)?29:u2[Z])}function F1($){return function W(X){const Z=h2.exec(X);if(!Z)return!1;const J=+Z[1],j=+Z[2],Q=+Z[3],Y=Z[4],K=Z[5]==="-"?-1:1,B=+(Z[6]||0),U=+(Z[7]||0);if(B>23||U>59||$&&!Y)return!1;if(J<=23&&j<=59&&Q<60)return!0;const w=j-U*K,F=J-B*K-(w<0?1:0);return(F===23||F===-1)&&(w===59||w===-1)&&Q<61}}function m1($){const W=F1($);return function X(Z){const J=Z.split(m2);return J.length===2&&p1(J[0])&&W(J[1])}}function p2($){return d2.test($)&&c2.test($)}function l2($){return d1.lastIndex=0,d1.test($)}function t2($){return Number.isInteger($)&&$<=n2&&$>=i2}function s2($){return Number.isInteger($)}function c1(){return!0}function a2($){if(r2.test($))return!1;try{return new RegExp($),!0}catch(W){return!1}}var a0={date:p1,time:F1(!0),"date-time":m1(!0),"iso-time":F1(!1),"iso-date-time":m1(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:p2,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:a2,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:l2,int32:{type:"number",validate:t2},int64:{type:"number",validate:s2},float:{type:"number",validate:c1},double:{type:"number",validate:c1},password:!0,binary:!0},v2=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,u2=[0,31,28,31,30,31,30,31,31,30,31,30,31],h2=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,m2=/t|\s/i,d2=/\/|:/,c2=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,d1=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,i2=-2147483648,n2=2147483647,r2=/[^\\]\\Z/;import{TypeSystemPolicy as r3,TypeSystem as a3,TypeSystemDuplicateFormat as o3,TypeSystemDuplicateTypeKind as e3}from"@sinclair/typebox/system";import{TypeCompiler as W8,TypeCheck as X8}from"@sinclair/typebox/compiler";var n1=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,t1=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,s1=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,e2=a0.date,$3=a0["date-time"];if(!W0.Has("date"))H0.Format("date",($)=>{const W=$.replace(/"/g,"");if(n1.test(W)||t1.test(W)||s1.test(W)||e2(W)){const X=new Date(W);if(!Number.isNaN(X.getTime()))return!0}return!1});if(!W0.Has("date-time"))H0.Format("date-time",($)=>{const W=$.replace(/"/g,"");if(n1.test(W)||t1.test(W)||s1.test(W)||$3(W)){const X=new Date(W);if(!Number.isNaN(X.getTime()))return!0}return!1});Object.entries(a0).forEach(($)=>{const[W,X]=$;if(!W0.Has(W)){if(X instanceof RegExp)H0.Format(W,(Z)=>X.test(Z));else if(typeof X==="function")H0.Format(W,X)}});var V=Object.assign({},v0),i1=($)=>{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 $},M1=($,W)=>{if(!(W instanceof Blob))return!1;if($.minSize&&W.size<i1($.minSize))return!1;if($.maxSize&&W.size>i1($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!W.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(W.type.startsWith($.extension[X]))return!0;return!1}return!0},W3=z1.Get("Files")??H0.Type("File",M1),X3=z1.Get("Files")??H0.Type("Files",($,W)=>{if(!Array.isArray(W))return M1($,W);if($.minItems&&W.length<$.minItems)return!1;if($.maxItems&&W.length>$.maxItems)return!1;for(let X=0;X<W.length;X++)if(!M1($,W[X]))return!1;return!0});if(!W0.Has("numeric"))W0.Set("numeric",($)=>!!$&&!isNaN(+$));if(!W0.Has("boolean"))W0.Set("boolean",($)=>$==="true"||$==="false");if(!W0.Has("ObjectString"))W0.Set("ObjectString",($)=>{let W=$.charCodeAt(0);if(W===9||W===10||W===32)W=$.trimStart().charCodeAt(0);if(W!==123&&W!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});if(!W0.Has("ArrayString"))W0.Set("ArrayString",($)=>{let W=$.charCodeAt(0);if(W===9||W===10||W===32)W=$.trimStart().charCodeAt(0);if(W!==123&&W!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});z1.Set("UnionEnum",($,W)=>{return(typeof W==="number"||typeof W==="string"||W===null)&&$.enum.includes(W)});var X0={Numeric:($)=>{const W=v0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((X)=>{const Z=+X;if(isNaN(Z))return X;if($&&!$0.Check(W,Z))throw new T("property",W,Z);return Z}).Encode((X)=>X)},Date:($)=>{const W=v0.Date($);return V.Transform(V.Union([v0.Date($),V.String({format:"date",default:new Date().toISOString()}),V.String({format:"date-time",default:new Date().toISOString()})],$)).Decode((X)=>{if(X instanceof Date)return X;const Z=new Date(X);if(!$0.Check(W,Z))throw new T("property",W,Z);return Z}).Encode((X)=>{if(typeof X==="string")return new Date(X);return X})},BooleanString:($)=>{const W=v0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((X)=>{if(typeof X==="string")return X==="true";if($&&!$0.Check(W,X))throw new T("property",W,X);return X}).Encode((X)=>X)},ObjectString:($,W)=>{const X=V.Object($,W),Z=JSON.stringify($0.Create(X));let J;try{J=l1.Compile(X)}catch{}return V.Transform(V.Union([V.String({format:"ObjectString",default:Z}),X])).Decode((j)=>{if(typeof j==="string"){if(j.charCodeAt(0)!==123)throw new T("property",X,j);try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(J){if(!J.Check(j))throw new T("property",X,j);return J.Decode(j)}if(!$0.Check(X,j))throw new T("property",X,j);return $0.Decode(X,j)}return j}).Encode((j)=>{if(typeof j==="string")try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(!$0.Check(X,j))throw new T("property",X,j);return JSON.stringify(j)})},ArrayString:($={},W)=>{const X=V.Array($,W),Z=JSON.stringify($0.Create(X));let J;try{J=l1.Compile(X)}catch{}return V.Transform(V.Union([V.String({format:"ArrayString",default:Z}),X])).Decode((j)=>{if(typeof j==="string"){if(j.charCodeAt(0)!==91)throw new T("property",X,j);try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(J){if(!J.Check(j))throw new T("property",X,j);return J.Decode(j)}if(!$0.Check(X,j))throw new T("property",X,j);return $0.Decode(X,j)}return j}).Encode((j)=>{if(typeof j==="string")try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(!$0.Check(X,j))throw new T("property",X,j);return JSON.stringify(j)})},File:W3,Files:($={})=>V.Transform(X3($)).Decode((W)=>{if(Array.isArray(W))return W;return[W]}).Encode((W)=>W),Nullable:($)=>V.Union([$,V.Null()]),MaybeEmpty:($)=>V.Union([$,V.Null(),V.Undefined()]),Cookie:($,{domain:W,expires:X,httpOnly:Z,maxAge:J,path:j,priority:Q,sameSite:Y,secure:K,secrets:B,sign:U,...w}={})=>{const F=V.Object($,w);return F.config={domain:W,expires:X,httpOnly:Z,maxAge:J,path:j,priority:Q,sameSite:Y,secure:K,secrets:B,sign:U},F},UnionEnum:($,W={})=>{const X=$.every((Z)=>typeof Z==="string")?{type:"string"}:$.every((Z)=>typeof Z==="number")?{type:"number"}:$.every((Z)=>Z===null)?{type:"null"}:{};if($.some((Z)=>typeof Z==="object"&&Z!==null))throw new Error("This type does not support objects or arrays");return{default:$[0],...W,[o2]:"UnionEnum",...X,enum:$}}};V.BooleanString=X0.BooleanString;V.ObjectString=X0.ObjectString;V.ArrayString=X0.ArrayString;V.Numeric=X0.Numeric;V.File=($={})=>X0.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>X0.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>X0.Nullable($);V.MaybeEmpty=X0.MaybeEmpty;V.Cookie=X0.Cookie;V.Date=X0.Date;V.UnionEnum=X0.UnionEnum;function J3($,W){if(typeof $!=="string")throw new TypeError("argument str must be a string");var X={},Z=W||{},J=Z.decode||Q3,j=0;while(j<$.length){var Q=$.indexOf("=",j);if(Q===-1)break;var Y=$.indexOf(";",j);if(Y===-1)Y=$.length;else if(Y<Q){j=$.lastIndexOf(";",Q-1)+1;continue}var K=$.slice(j,Q).trim();if(X[K]===void 0){var B=$.slice(Q+1,Y).trim();if(B.charCodeAt(0)===34)B=B.slice(1,-1);X[K]=B3(B,J)}j=Y+1}return X}function j3($,W,X){var Z=X||{},J=Z.encode||G3;if(typeof J!=="function")throw new TypeError("option encode is invalid");if(!o0.test($))throw new TypeError("argument name is invalid");var j=J(W);if(j&&!o0.test(j))throw new TypeError("argument val is invalid");var Q=$+"="+j;if(Z.maxAge!=null){var Y=Z.maxAge-0;if(isNaN(Y)||!isFinite(Y))throw new TypeError("option maxAge is invalid");Q+="; Max-Age="+Math.floor(Y)}if(Z.domain){if(!o0.test(Z.domain))throw new TypeError("option domain is invalid");Q+="; Domain="+Z.domain}if(Z.path){if(!o0.test(Z.path))throw new TypeError("option path is invalid");Q+="; Path="+Z.path}if(Z.expires){var K=Z.expires;if(!Y3(K)||isNaN(K.valueOf()))throw new TypeError("option expires is invalid");Q+="; Expires="+K.toUTCString()}if(Z.httpOnly)Q+="; HttpOnly";if(Z.secure)Q+="; Secure";if(Z.partitioned)Q+="; Partitioned";if(Z.priority){var B=typeof Z.priority==="string"?Z.priority.toLowerCase():Z.priority;switch(B){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(Z.sameSite){var U=typeof Z.sameSite==="string"?Z.sameSite.toLowerCase():Z.sameSite;switch(U){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}function Q3($){return $.indexOf("%")!==-1?decodeURIComponent($):$}function G3($){return encodeURIComponent($)}function Y3($){return Z3.call($)==="[object Date]"||$ instanceof Date}function B3($,W){try{return W($)}catch(X){return $}}/*!
|
|
2
|
+
var C2=Object.create;var{getPrototypeOf:S2,defineProperty:f1,getOwnPropertyNames:L2}=Object;var T2=Object.prototype.hasOwnProperty;var w1=($,W,X)=>{X=$!=null?C2(S2($)):{};const Z=W||!$||!$.__esModule?f1(X,"default",{value:$,enumerable:!0}):X;for(let J of L2($))if(!T2.call(Z,J))f1(Z,J,{get:()=>$[J],enumerable:!0});return Z};var q2=($,W)=>()=>(W||$((W={exports:{}}).exports,W),W.exports);var e0=q2((J8,o1)=>{function U3($){var W=$.indexOf("%");if(W===-1)return $;var X=$.length,Z="",J=0,j=0,Q=W,Y=r1;while(W>-1&&W<X){var K=a1($[W+1],4),B=a1($[W+2],0),U=K|B,w=P1[U];if(Y=P1[256+Y+w],j=j<<6|U&P1[364+w],Y===r1)Z+=$.slice(J,Q),Z+=j<=65535?String.fromCharCode(j):String.fromCharCode(55232+(j>>10),56320+(j&1023)),j=0,J=W+3,W=Q=$.indexOf("%",J);else if(Y===K3)return null;else{if(W+=3,W<X&&$.charCodeAt(W)===37)continue;return null}}return Z+$.slice(J)}function a1($,W){var X=w3[$];return X===void 0?255:X<<W}var r1=12,K3=0,P1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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],w3={"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};o1.exports=U3});var q0=($,W)=>{const X=W?.length?{}:null;if(X)for(let Z of W)X[Z.part.charCodeAt(0)]=Z;return{part:$,store:null,inert:X,params:null,wildcardStore:null}},y1=($,W)=>({...$,part:W}),k1=($)=>({name:$,store:null,inert:null});class M0{root={};history=[];static regex={static:/:.+?(?=\/|$)/,params:/:.+?(?=\/|$)/g,optionalParams:/:.+?\?(?=\/|$)/g};add($,W,X,{ignoreError:Z=!1,ignoreHistory:J=!1}={}){if(typeof W!=="string")throw new TypeError("Route path must be a string");if(W==="")W="/";else if(W[0]!=="/")W=`/${W}`;const j=W[W.length-1]==="*",Q=W.match(M0.regex.optionalParams);if(Q){const w=W.replaceAll("?","");this.add($,w,X,{ignoreError:Z});for(let F=0;F<Q.length;F++){let G=W.replace("/"+Q[F],"");this.add($,G,X,{ignoreError:!0})}return X}if(Q)W=W.replaceAll("?","");if(this.history.find(([w,F,G])=>w===$&&F===W))return X;if(j||Q&&W.charCodeAt(W.length-1)===63)W=W.slice(0,-1);if(!J)this.history.push([$,W,X]);const Y=W.split(M0.regex.static),K=W.match(M0.regex.params)||[];if(Y[Y.length-1]==="")Y.pop();let B;if(!this.root[$])B=this.root[$]=q0("/");else B=this.root[$];let U=0;for(let w=0;w<Y.length;++w){let F=Y[w];if(w>0){const G=K[U++].slice(1);if(B.params===null)B.params=k1(G);else if(B.params.name!==G)if(Z)return X;else throw new Error(`Cannot create route "${W}" with parameter "${G}" because a route already exists with a different parameter name ("${B.params.name}") in the same location`);const z=B.params;if(z.inert===null){B=z.inert=q0(F);continue}B=z.inert}for(let G=0;;){if(G===F.length){if(G<B.part.length){const z=y1(B,B.part.slice(G));Object.assign(B,q0(F,[z]))}break}if(G===B.part.length){if(B.inert===null)B.inert={};const z=B.inert[F.charCodeAt(G)];if(z){B=z,F=F.slice(G),G=0;continue}const D=q0(F.slice(G));B.inert[F.charCodeAt(G)]=D,B=D;break}if(F[G]!==B.part[G]){const z=y1(B,B.part.slice(G)),D=q0(F.slice(G));Object.assign(B,q0(B.part.slice(0,G),[z,D])),B=D;break}++G}}if(U<K.length){const w=K[U].slice(1);if(B.params===null)B.params=k1(w);else if(B.params.name!==w)if(Z)return X;else throw new Error(`Cannot create route "${W}" with parameter "${w}" because a route already exists with a different parameter name ("${B.params.name}") in the same location`);if(B.params.store===null)B.params.store=X;return B.params.store}if(j){if(B.wildcardStore===null)B.wildcardStore=X;return B.wildcardStore}if(B.store===null)B.store=X;return B.store}find($,W){const X=this.root[$];if(!X)return null;return _1(W,W.length,X,0)}}var _1=($,W,X,Z)=>{const J=X.part,j=J.length,Q=Z+j;if(j>1){if(Q>W)return null;if(j<15){for(let Y=1,K=Z+1;Y<j;++Y,++K)if(J.charCodeAt(Y)!==$.charCodeAt(K))return null}else if($.slice(Z,Q)!==J)return null}if(Q===W){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[$.charCodeAt(Q)];if(Y!==void 0){const K=_1($,W,Y,Q);if(K!==null)return K}}if(X.params!==null){const{store:Y,name:K,inert:B}=X.params,U=$.indexOf("/",Q);if(U!==Q){if(U===-1||U>=W){if(Y!==null){const w={};return w[K]=$.substring(Q,W),{store:Y,params:w}}}else if(B!==null){const w=_1($,W,B,U);if(w!==null)return w.params[K]=$.substring(Q,U),w}}}if(X.wildcardStore!==null)return{store:X.wildcardStore,params:{"*":$.substring(Q,W)}};return null};var E0=($)=>{const W=typeof $==="object"?$.fn.toString():typeof $==="string"?$.toString():$,X=W.indexOf(")");if(W.charCodeAt(X+2)===61&&W.charCodeAt(X+5)!==123)return!0;return W.includes("return")},E2=($)=>{if($.startsWith("async"))$=$.slice(5);$=$.trimStart();let W=-1;if($.charCodeAt(0)===40){if(W=$.indexOf("=>",$.indexOf(")")),W!==-1){let J=W;while(J>0)if($.charCodeAt(--J)===41)break;let j=$.slice(W+2);if(j.charCodeAt(0)===32)j=j.trimStart();return[$.slice(1,J),j,{isArrowReturn:j.charCodeAt(0)!==123}]}}if($.startsWith("function")){W=$.indexOf("(");const J=$.indexOf(")");return[$.slice(W+1,J),$.slice(J+2),{isArrowReturn:!1}]}const X=$.indexOf("(");if(X!==-1){const J=$.indexOf("\n",2),j=$.slice(0,J),Q=j.lastIndexOf(")")+1,Y=$.slice(J+1);return[j.slice(X,Q),"{"+Y,{isArrowReturn:!1}]}const Z=$.split("\n",2);return[Z[0],Z[1],{isArrowReturn:!1}]},H2=($)=>{const W=$.indexOf("{");if(W===-1)return[-1,0];let X=W+1,Z=1;for(;X<$.length;X++){const J=$.charCodeAt(X);if(J===123)Z++;else if(J===125)Z--;if(Z===0)break}if(Z!==0)return[0,$.length];return[W,X+1]},R2=($)=>{const W=$.lastIndexOf("}");if(W===-1)return[-1,0];let X=W-1,Z=1;for(;X>=0;X--){const J=$.charCodeAt(X);if(J===125)Z++;else if(J===123)Z--;if(Z===0)break}if(Z!==0)return[-1,0];return[X,W+1]},v1=($)=>{while(!0){const W=$.indexOf(":");if(W===-1)break;let X=$.indexOf(",",W);if(X===-1)X=$.indexOf("}",W)-1;if(X===-2)X=$.length;$=$.slice(0,W)+$.slice(X)}return $},u1=($)=>{let W=!1;if($.charCodeAt(0)===40)$=$.slice(1,-1);if($.charCodeAt(0)===123)W=!0,$=$.slice(1,-1);$=$.replace(/( |\t|\n)/g,"").trim();let X=[];while(!0){let[J,j]=H2($);if(J===-1)break;if(X.push($.slice(0,J-1)),$.charCodeAt(j)===44)j++;$=$.slice(j)}if($=v1($),$)X=X.concat($.split(","));const Z=[];for(let J of X){if(J.indexOf(",")===-1){Z.push(J);continue}for(let j of J.split(","))Z.push(j.trim())}return X=Z,{hasParenthesis:W,parameters:X}},b2=($,W)=>{const{parameters:X,hasParenthesis:Z}=u1($);if(!W.query&&X.includes("query"))W.query=!0;if(!W.headers&&X.includes("headers"))W.headers=!0;if(!W.body&&X.includes("body"))W.body=!0;if(!W.cookie&&X.includes("cookie"))W.cookie=!0;if(!W.set&&X.includes("set"))W.set=!0;if(!W.server&&X.includes("server"))W.server=!0;if(Z)return`{ ${X.join(", ")} }`;return X.join(", ")},x2=($,W,X)=>{const Z=W.indexOf($+"\n",X),J=W.indexOf($+"\t",X),j=W.indexOf($+",",X),Q=W.indexOf($+";",X),Y=W.indexOf($+" ",X);return[Z,J,j,Q,Y].filter((K)=>K>0).sort((K,B)=>K-B)[0]||-1};var h1=($,W,X=0)=>{if(X>5)return[];const Z=[];let J=W;while(!0){let j=x2(" = "+$,J);if(j===-1){const K=J.indexOf(" = "+$);if(K+3+$.length!==J.length)break;j=K}const Q=J.slice(0,j);let Y=Q.slice(Q.lastIndexOf(" ")+1);if(Y==="}"){const[K,B]=R2(Q);Z.push(v1(J.slice(K,B))),J=J.slice(j+3+$.length);continue}while(Y.charCodeAt(0)===44)Y=Y.slice(1);while(Y.charCodeAt(0)===9)Y=Y.slice(1);if(!Y.includes("("))Z.push(Y);J=J.slice(j+3+$.length)}for(let j of Z){if(j.charCodeAt(0)===123)continue;const Q=h1(j,W);if(Q.length>0)Z.push(...Q)}return Z},g2=($)=>{if(!$)return;if($.charCodeAt(0)!==123)return $;if($=$.slice(2,-2),!$.includes(",")){if($.includes("..."))return $.slice($.indexOf("...")+3);return}const X=$.indexOf("...");if(X===-1)return;return $.slice(X+3).trimEnd()},f2=($,W,X)=>{const Z=(J,j)=>$.includes(j+"."+J)||$.includes(j+'["'+J+'"]')||$.includes(j+"['"+J+"']");for(let J of W){if(!J)continue;if(J.charCodeAt(0)===123){const j=u1(J).parameters;if(!X.query&&j.includes("query"))X.query=!0;if(!X.headers&&j.includes("headers"))X.headers=!0;if(!X.body&&j.includes("body"))X.body=!0;if(!X.cookie&&j.includes("cookie"))X.cookie=!0;if(!X.set&&j.includes("set"))X.set=!0;if(!X.query&&j.includes("server"))X.server=!0;continue}if(!X.query&&Z("query",J))X.query=!0;if($.includes("return "+J)||$.includes("return "+J+".query"))X.query=!0;if(!X.headers&&Z("headers",J))X.headers=!0;if(!X.body&&Z("body",J))X.body=!0;if(!X.cookie&&Z("cookie",J))X.cookie=!0;if(!X.set&&Z("set",J))X.set=!0;if(!X.server&&Z("server",J))X.server=!0;if(X.query&&X.headers&&X.body&&X.cookie&&X.set&&X.server)break}return W};var y2=($,W,X)=>{try{const Z=new RegExp(`(?:\\w)\\((?:.*)?${$}`,"gs");Z.test(W);const J=W.charCodeAt(Z.lastIndex);if(J===41||J===44)return X.query=!0,X.headers=!0,X.body=!0,X.cookie=!0,X.set=!0,X.server=!0,!0;return!1}catch(Z){return console.log("[Sucrose] warning: unexpected isContextPassToFunction error, you may continue development as usual but please report the following to maintainers:"),console.log("--- body ---"),console.log(W),console.log("--- context ---"),console.log($),!0}},r0=($,W={query:!1,headers:!1,body:!1,cookie:!1,set:!1,server:!1})=>{const X=[];if($.handler&&typeof $.handler==="function")X.push($.handler);if($.request?.length)X.push(...$.request);if($.beforeHandle?.length)X.push(...$.beforeHandle);if($.parse?.length)X.push(...$.parse);if($.error?.length)X.push(...$.error);if($.transform?.length)X.push(...$.transform);if($.afterHandle?.length)X.push(...$.afterHandle);if($.mapResponse?.length)X.push(...$.mapResponse);if($.afterResponse?.length)X.push(...$.afterResponse);for(let Z of X){if(!Z)continue;const J="fn"in Z?Z.fn:Z,[j,Q,{isArrowReturn:Y}]=E2(J.toString()),K=b2(j,W),B=g2(K);if(B){const U=h1(B,Q);if(U.splice(0,-1,B),!y2(B,Q,W))f2(Q,U,W);if(!W.query&&Q.includes("return "+B+".query"))W.query=!0}if(W.query&&W.headers&&W.body&&W.cookie&&W.set&&W.server)break}return W};import{Value as p0}from"@sinclair/typebox/value";import{Kind as R0,TransformKind as j2}from"@sinclair/typebox";import{Value as i}from"@sinclair/typebox/value";import{TypeCompiler as G2}from"@sinclair/typebox/compiler";import{Kind as o2,TypeRegistry as z1}from"@sinclair/typebox";import{TypeSystem as H0}from"@sinclair/typebox/system";import{Type as v0,FormatRegistry as W0}from"@sinclair/typebox";import{TypeCompiler as l1}from"@sinclair/typebox/compiler";import{Value as $0}from"@sinclair/typebox/value";function k2($){return $%4===0&&($%100!==0||$%400===0)}function p1($){const W=v2.exec($);if(!W)return!1;const X=+W[1],Z=+W[2],J=+W[3];return Z>=1&&Z<=12&&J>=1&&J<=(Z===2&&k2(X)?29:u2[Z])}function F1($){return function W(X){const Z=h2.exec(X);if(!Z)return!1;const J=+Z[1],j=+Z[2],Q=+Z[3],Y=Z[4],K=Z[5]==="-"?-1:1,B=+(Z[6]||0),U=+(Z[7]||0);if(B>23||U>59||$&&!Y)return!1;if(J<=23&&j<=59&&Q<60)return!0;const w=j-U*K,F=J-B*K-(w<0?1:0);return(F===23||F===-1)&&(w===59||w===-1)&&Q<61}}function m1($){const W=F1($);return function X(Z){const J=Z.split(m2);return J.length===2&&p1(J[0])&&W(J[1])}}function p2($){return d2.test($)&&c2.test($)}function l2($){return d1.lastIndex=0,d1.test($)}function t2($){return Number.isInteger($)&&$<=n2&&$>=i2}function s2($){return Number.isInteger($)}function c1(){return!0}function a2($){if(r2.test($))return!1;try{return new RegExp($),!0}catch(W){return!1}}var a0={date:p1,time:F1(!0),"date-time":m1(!0),"iso-time":F1(!1),"iso-date-time":m1(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:p2,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:a2,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:l2,int32:{type:"number",validate:t2},int64:{type:"number",validate:s2},float:{type:"number",validate:c1},double:{type:"number",validate:c1},password:!0,binary:!0},v2=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,u2=[0,31,28,31,30,31,30,31,31,30,31,30,31],h2=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,m2=/t|\s/i,d2=/\/|:/,c2=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,d1=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,i2=-2147483648,n2=2147483647,r2=/[^\\]\\Z/;import{TypeSystemPolicy as r3,TypeSystem as a3,TypeSystemDuplicateFormat as o3,TypeSystemDuplicateTypeKind as e3}from"@sinclair/typebox/system";import{TypeCompiler as W8,TypeCheck as X8}from"@sinclair/typebox/compiler";var n1=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,t1=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,s1=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,e2=a0.date,$3=a0["date-time"];if(!W0.Has("date"))H0.Format("date",($)=>{const W=$.replace(/"/g,"");if(n1.test(W)||t1.test(W)||s1.test(W)||e2(W)){const X=new Date(W);if(!Number.isNaN(X.getTime()))return!0}return!1});if(!W0.Has("date-time"))H0.Format("date-time",($)=>{const W=$.replace(/"/g,"");if(n1.test(W)||t1.test(W)||s1.test(W)||$3(W)){const X=new Date(W);if(!Number.isNaN(X.getTime()))return!0}return!1});Object.entries(a0).forEach(($)=>{const[W,X]=$;if(!W0.Has(W)){if(X instanceof RegExp)H0.Format(W,(Z)=>X.test(Z));else if(typeof X==="function")H0.Format(W,X)}});var V=Object.assign({},v0),i1=($)=>{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 $},M1=($,W)=>{if(!(W instanceof Blob))return!1;if($.minSize&&W.size<i1($.minSize))return!1;if($.maxSize&&W.size>i1($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!W.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(W.type.startsWith($.extension[X]))return!0;return!1}return!0},W3=z1.Get("Files")??H0.Type("File",M1),X3=z1.Get("Files")??H0.Type("Files",($,W)=>{if(!Array.isArray(W))return M1($,W);if($.minItems&&W.length<$.minItems)return!1;if($.maxItems&&W.length>$.maxItems)return!1;for(let X=0;X<W.length;X++)if(!M1($,W[X]))return!1;return!0});if(!W0.Has("numeric"))W0.Set("numeric",($)=>!!$&&!isNaN(+$));if(!W0.Has("boolean"))W0.Set("boolean",($)=>$==="true"||$==="false");if(!W0.Has("ObjectString"))W0.Set("ObjectString",($)=>{let W=$.charCodeAt(0);if(W===9||W===10||W===32)W=$.trimStart().charCodeAt(0);if(W!==123&&W!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});if(!W0.Has("ArrayString"))W0.Set("ArrayString",($)=>{let W=$.charCodeAt(0);if(W===9||W===10||W===32)W=$.trimStart().charCodeAt(0);if(W!==123&&W!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});z1.Set("UnionEnum",($,W)=>{return(typeof W==="number"||typeof W==="string"||W===null)&&$.enum.includes(W)});var X0={Numeric:($)=>{const W=v0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((X)=>{const Z=+X;if(isNaN(Z))return X;if($&&!$0.Check(W,Z))throw new T("property",W,Z);return Z}).Encode((X)=>X)},Date:($)=>{const W=v0.Date($);return V.Transform(V.Union([v0.Date($),V.String({format:"date",default:new Date().toISOString()}),V.String({format:"date-time",default:new Date().toISOString()})],$)).Decode((X)=>{if(X instanceof Date)return X;const Z=new Date(X);if(!$0.Check(W,Z))throw new T("property",W,Z);return Z}).Encode((X)=>{if(typeof X==="string")return new Date(X);return X})},BooleanString:($)=>{const W=v0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((X)=>{if(typeof X==="string")return X==="true";if($&&!$0.Check(W,X))throw new T("property",W,X);return X}).Encode((X)=>X)},ObjectString:($,W)=>{const X=V.Object($,W),Z=JSON.stringify($0.Create(X));let J;try{J=l1.Compile(X)}catch{}return V.Transform(V.Union([V.String({format:"ObjectString",default:Z}),X])).Decode((j)=>{if(typeof j==="string"){if(j.charCodeAt(0)!==123)throw new T("property",X,j);try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(J){if(!J.Check(j))throw new T("property",X,j);return J.Decode(j)}if(!$0.Check(X,j))throw new T("property",X,j);return $0.Decode(X,j)}return j}).Encode((j)=>{if(typeof j==="string")try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(!$0.Check(X,j))throw new T("property",X,j);return JSON.stringify(j)})},ArrayString:($={},W)=>{const X=V.Array($,W),Z=JSON.stringify($0.Create(X));let J;try{J=l1.Compile(X)}catch{}return V.Transform(V.Union([V.String({format:"ArrayString",default:Z}),X])).Decode((j)=>{if(typeof j==="string"){if(j.charCodeAt(0)!==91)throw new T("property",X,j);try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(J){if(!J.Check(j))throw new T("property",X,j);return J.Decode(j)}if(!$0.Check(X,j))throw new T("property",X,j);return $0.Decode(X,j)}return j}).Encode((j)=>{if(typeof j==="string")try{j=JSON.parse(j)}catch{throw new T("property",X,j)}if(!$0.Check(X,j))throw new T("property",X,j);return JSON.stringify(j)})},File:W3,Files:($={})=>V.Transform(X3($)).Decode((W)=>{if(Array.isArray(W))return W;return[W]}).Encode((W)=>W),Nullable:($)=>V.Union([$,V.Null()]),MaybeEmpty:($)=>V.Union([$,V.Null(),V.Undefined()]),Cookie:($,{domain:W,expires:X,httpOnly:Z,maxAge:J,path:j,priority:Q,sameSite:Y,secure:K,secrets:B,sign:U,...w}={})=>{const F=V.Object($,w);return F.config={domain:W,expires:X,httpOnly:Z,maxAge:J,path:j,priority:Q,sameSite:Y,secure:K,secrets:B,sign:U},F},UnionEnum:($,W={})=>{const X=$.every((Z)=>typeof Z==="string")?{type:"string"}:$.every((Z)=>typeof Z==="number")?{type:"number"}:$.every((Z)=>Z===null)?{type:"null"}:{};if($.some((Z)=>typeof Z==="object"&&Z!==null))throw new Error("This type does not support objects or arrays");return{default:$[0],...W,[o2]:"UnionEnum",...X,enum:$}}};V.BooleanString=X0.BooleanString;V.ObjectString=X0.ObjectString;V.ArrayString=X0.ArrayString;V.Numeric=X0.Numeric;V.File=($={})=>X0.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>X0.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>X0.Nullable($);V.MaybeEmpty=X0.MaybeEmpty;V.Cookie=X0.Cookie;V.Date=X0.Date;V.UnionEnum=X0.UnionEnum;function J3($,W){if(typeof $!=="string")throw new TypeError("argument str must be a string");var X={},Z=W||{},J=Z.decode||Q3,j=0;while(j<$.length){var Q=$.indexOf("=",j);if(Q===-1)break;var Y=$.indexOf(";",j);if(Y===-1)Y=$.length;else if(Y<Q){j=$.lastIndexOf(";",Q-1)+1;continue}var K=$.slice(j,Q).trim();if(X[K]===void 0){var B=$.slice(Q+1,Y).trim();if(B.charCodeAt(0)===34)B=B.slice(1,-1);X[K]=B3(B,J)}j=Y+1}return X}function j3($,W,X){var Z=X||{},J=Z.encode||G3;if(typeof J!=="function")throw new TypeError("option encode is invalid");if(!o0.test($))throw new TypeError("argument name is invalid");var j=J(W);if(j&&!o0.test(j))throw new TypeError("argument val is invalid");var Q=$+"="+j;if(Z.maxAge!=null){var Y=Z.maxAge-0;if(isNaN(Y)||!isFinite(Y))throw new TypeError("option maxAge is invalid");Q+="; Max-Age="+Math.floor(Y)}if(Z.domain){if(!o0.test(Z.domain))throw new TypeError("option domain is invalid");Q+="; Domain="+Z.domain}if(Z.path){if(!o0.test(Z.path))throw new TypeError("option path is invalid");Q+="; Path="+Z.path}if(Z.expires){var K=Z.expires;if(!Y3(K)||isNaN(K.valueOf()))throw new TypeError("option expires is invalid");Q+="; Expires="+K.toUTCString()}if(Z.httpOnly)Q+="; HttpOnly";if(Z.secure)Q+="; Secure";if(Z.partitioned)Q+="; Partitioned";if(Z.priority){var B=typeof Z.priority==="string"?Z.priority.toLowerCase():Z.priority;switch(B){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(Z.sameSite){var U=typeof Z.sameSite==="string"?Z.sameSite.toLowerCase():Z.sameSite;switch(U){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}function Q3($){return $.indexOf("%")!==-1?decodeURIComponent($):$}function G3($){return encodeURIComponent($)}function Y3($){return Z3.call($)==="[object Date]"||$ instanceof Date}function B3($,W){try{return W($)}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 D1=J3,N1=j3;var Z3=Object.prototype.toString,o0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var $2=w1(e0(),1);class w0{$;W;X;constructor($,W,X={}){this.name=$;this.jar=W;this.initial=X}get cookie(){if(!(this.name in this.jar))this.jar[this.name]=this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){this.cookie.value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$,console.log(this.cookie)}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get partitioned(){return this.cookie.partitioned}set partitioned($){this.cookie.partitioned=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var e1=($,W,X)=>{if(!$.cookie)$.cookie={};return new Proxy(W,{get(Z,J){if(J in W)return new w0(J,$.cookie,Object.assign({},X??{},W[J]));return new w0(J,$.cookie,Object.assign({},X))}})},$1=async($,W,{secrets:X,sign:Z,...J}={})=>{if(!W)return e1($,{},J);const j=typeof X==="string";if(Z&&Z!==!0&&!Array.isArray(Z))Z=[Z];const Q={},Y=D1(W);for(let[K,B]of Object.entries(Y)){let U=$2.default(B);if(Z===!0||Z?.includes(K)){if(!X)throw new Error("No secret is provided to cookie plugin");if(j){const w=await I1(U,X);if(w===!1)throw new u0(K);U=w}else{let w=!0;for(let F=0;F<X.length;F++){const G=await I1(U,X[F]);if(G!==!1){w=!0,U=G;break}}if(!w)throw new u0(K)}}Q[K]={value:U}}return e1($,Q,J)};async function*m0($){const W=$.body;if(!W)return;const X=W.getReader(),Z=new TextDecoder;try{while(!0){const{done:J,value:j}=await X.read();if(J)break;yield Z.decode(j)}}finally{X.releaseLock()}}var W2="toJSON"in new Headers,n=($)=>{if(!$)return!1;for(let W in $)return!0;return!1},h0=($,W)=>{const X=$.size;if(!W&&X||X&&W&&W.status!==206&&W.status!==304&&W.status!==412&&W.status!==416){if(W){if(W.headers instanceof Headers){if(W2)W.headers=W.headers.toJSON();else for(let[Z,J]of W.headers.entries())if(Z in W.headers)W.headers[Z]=J}return new Response($,{status:W.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`},W.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`}})}return new Response($)},X2=($,W)=>{if(!$)return $;$.delete("set-cookie");for(let X=0;X<W.length;X++){const Z=W[X].indexOf("=");$.append("set-cookie",`${W[X].slice(0,Z)}=${W[X].slice(Z+1)||""}`)}return $},Z2=($)=>{if(!$||!n($))return;const W=[];for(let[X,Z]of Object.entries($)){if(!X||!Z)continue;const J=Z.value;if(J===void 0||J===null)continue;W.push(N1(X,typeof J==="object"?JSON.stringify(J):J+"",Z))}if(W.length===0)return;if(W.length===1)return W[0];return W},B0=async($,W,X)=>{let Z=$.next();if(Z instanceof Promise)Z=await Z;if(Z.done){if(W)return f(Z.value,W,X);return Z0(Z.value,X)}return new Response(new ReadableStream({async start(J){let j=!1;if(X?.signal.addEventListener("abort",()=>{j=!0;try{J.close()}catch{}}),Z.value!==void 0&&Z.value!==null)if(typeof Z.value==="object")try{J.enqueue(Buffer.from(JSON.stringify(Z.value)))}catch{J.enqueue(Buffer.from(Z.value.toString()))}else J.enqueue(Buffer.from(Z.value.toString()));for await(let Q of $){if(j)break;if(Q===void 0||Q===null)continue;if(typeof Q==="object")try{J.enqueue(Buffer.from(JSON.stringify(Q)))}catch{J.enqueue(Buffer.from(Q.toString()))}else J.enqueue(Buffer.from(Q.toString()));await new Promise((Y)=>setTimeout(()=>Y(),0))}try{J.close()}catch{}}}),{...W,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...W?.headers}})},f=($,W,X)=>{if(n(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=_0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&n(W.cookie)){const Z=Z2(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=X2(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return h0($,W);case"Array":return Response.json($,W);case"Object":const Z=$[c];if(Z)return W.status=Z,f($.response,W,X);for(let j in Object.values($))switch(j?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($));default:break}return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,W);case void 0:if(!$)return new Response("",W);return Response.json($,W);case"Response":let J=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(J)continue;J=!0;for(let Q of W.headers.getSetCookie())$.headers.append("set-cookie",Q)}else $.headers.append(j,W.headers?.get(j)??"");else for(let j in W.headers)$.headers.append(j,W.headers[j]);if($.status!==W.status)W.status=$.status;if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((j)=>f(j,W));case"Function":return f($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($,W);default:if($ instanceof Response){let j=!1;if(W.headers instanceof Headers)for(let Q of W.headers.keys())if(Q==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(Q,W.headers?.get(Q)??"");else for(let Q in W.headers)$.headers.append(Q,W.headers[Q]);if(W2)W.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in W.headers)W.headers[Q]=Y;return $}if($ instanceof Promise)return $.then((j)=>f(j,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return f($.toResponse(),W);if("charCodeAt"in $){const j=$.charCodeAt(0);if(j===123||j===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($,W);case"Array":return Response.json($);case"Object":const Z=$[c];if(Z)return W.status=Z,f($.response,W,X);for(let J in Object.values($))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((J)=>{const j=Z0(J,X);if(j!==void 0)return j;return new Response("")});case"Function":return Z0($(),X);case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($,W);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((J)=>f(J,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return f($.toResponse(),W);if("charCodeAt"in $){const J=$.charCodeAt(0);if(J===123||J===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},v=($,W,X)=>{if($===void 0||$===null)return;if(n(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=_0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&n(W.cookie)){const Z=Z2(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=X2(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return h0($,W);case"Array":return Response.json($,W);case"Object":const Z=$[c];if(Z)return W.status=Z,v($.response,W,X);for(let j in Object.values($))switch(j?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,W);case void 0:if(!$)return;return Response.json($,W);case"Response":let J=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(J)continue;J=!0;for(let Q of W.headers.getSetCookie())$.headers.append("set-cookie",Q)}else $.headers.append(j,W.headers?.get(j)??"");else for(let j in W.headers)$.headers.append(j,W.headers[j]);if($.status!==W.status)W.status=$.status;if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Promise":return $.then((j)=>{const Q=v(j,W);if(Q!==void 0)return Q});case"Error":return K0($,W);case"Function":return v($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"FormData":return new Response($);case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response){let j=!1;if(W.headers instanceof Headers)for(let Q of W.headers.keys())if(Q==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(Q,W.headers?.get(Q)??"");else for(let Q in W.headers)$.headers.append(Q,W.headers[Q]);if($.status!==W.status)W.status=$.status;return $}if($ instanceof Promise)return $.then((j)=>v(j,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return v($.toResponse(),W);if("charCodeAt"in $){const j=$.charCodeAt(0);if(j===123||j===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($,W);case"Array":return Response.json($);case"Object":const Z=$[c];if(Z)return W.status=Z,v($.response,W,X);for(let J in Object.values($))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($));return $;case"Promise":return $.then((J)=>{const j=v(J,W);if(j!==void 0)return j});case"Error":return K0($,W);case"Function":return Z0($(),X);case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((J)=>v(J,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return v($.toResponse(),W);if("charCodeAt"in $){const J=$.charCodeAt(0);if(J===123||J===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},Z0=($,W)=>{switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($);case"Array":return Response.json($);case"Object":if($[c])return f($.response,{status:$[c],headers:{}});$:for(let X of Object.values($))switch(X?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($));case"Object":break $;default:break}return Response.json($);case"ReadableStream":return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($));return $;case"Error":return K0($);case"Promise":return $.then((X)=>Z0(X,W));case"Function":return Z0($(),W);case"Number":case"Boolean":return new Response($.toString());case"FormData":return new Response($);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((X)=>Z0(X,W));if($ instanceof Error)return K0($);if(typeof $?.next==="function")return B0($,void 0,W);if("toResponse"in $)return Z0($.toResponse());if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},K0=($,W)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:W?.status!==200?W?.status??500:500,headers:W?.headers}),J2=($,W,X={})=>{if(typeof $==="function")return;const Z=f($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0)return Z.clone.bind(Z)};function P3($){let W=$;while(W.endsWith("="))W=W.slice(0,-1);return W}var b0=($,W)=>{const X=new URL($);return X.pathname=W,X.toString()},_3=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")&&$.toString()!=="[object Object]"||n(Object.getPrototypeOf($)),A1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,W,{skipKeys:X,override:Z=!0}={})=>{if(!A1($)||!A1(W))return $;for(let[J,j]of Object.entries(W)){if(X?.includes(J))continue;if(!A1(j)||!(J in $)||_3(j)){if(Z||!(J in $))$[J]=j;continue}$[J]=p($[J],j,{skipKeys:X,override:Z})}return $},F3=($,W)=>{const{properties:X,...Z}=$??{},{properties:J,...j}=W??{};return p(Z,j)},x=($=[],W=[])=>{if(!$)return[];if(!W)return $;const X=[],Z=[];if(!Array.isArray($))$=[$];if(!Array.isArray(W))W=[W];for(let J of $)if(X.push(J),J.checksum)Z.push(J.checksum);for(let J of W)if(!Z.includes(J.checksum))X.push(J);return X},M3=["start","request","parse","transform","resolve","beforeHandle","afterHandle","mapResponse","afterResponse","trace","error","stop","body","headers","params","query","response","type","detail"],z3=M3.reduce(($,W)=>($[W]=!0,$),{}),Y2=($,W)=>{const X=(Z)=>typeof Z==="object"&&Object.keys(Z).every(J1);if(X($)&&X(W))return{...$,...W};return W??$},x0=($,W)=>{return{body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:Y2($?.response,W?.response)}},i=($,W)=>{return{...$,...W,body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:Y2($?.response,W?.response),type:$?.type||W?.type,detail:p(W?.detail??{},$?.detail??{}),parse:x($?.parse,W?.parse),transform:x($?.transform,W?.transform),beforeHandle:x($?.beforeHandle,W?.beforeHandle),afterHandle:x($?.afterHandle,W?.afterHandle),mapResponse:x($?.mapResponse,W?.mapResponse),afterResponse:x($?.afterResponse,W?.afterResponse),trace:x($?.trace,W?.trace),error:x($?.error,W?.error)}},B2=($,W,X=!0)=>{if(!Array.isArray(W))return m($,W,X);for(let Z of W)$=m($,Z,X);return $},m=($,W,X=!0)=>{if(!$)return $;if(W.untilObjectFound&&!X&&$.type==="object")return $;const Z=W.from[R0];if($.oneOf){for(let Q=0;Q<$.oneOf.length;Q++)$.oneOf[Q]=m($.oneOf[Q],W,X);return $}if($.anyOf){for(let Q=0;Q<$.anyOf.length;Q++)$.anyOf[Q]=m($.anyOf[Q],W,X);return $}if($.allOf){for(let Q=0;Q<$.allOf.length;Q++)$.allOf[Q]=m($.allOf[Q],W,X);return $}if($.not){for(let Q=0;Q<$.not.length;Q++)$.not[Q]=m($.not[Q],W,X);return $}const J=X&&!!W.excludeRoot;if($[R0]===Z){const{anyOf:Q,oneOf:Y,allOf:K,not:B,properties:U,items:w,...F}=$,G=W.to();let z;const D=(M)=>{if(U&&M.type==="object"){const I={};for(let[O,H]of Object.entries(U))I[O]=m(H,W,!1);return{...F,...M,properties:I}}if(w&&M.type==="array")return{...F,...M,items:m(w,W,!1)};const N={...F,...M};if(delete N.required,U&&M.type==="string"&&M.format==="ObjectString"&&M.default==="{}")z=V.ObjectString(U,F),N.default=JSON.stringify(l.Create(V.Object(U))),N.properties=U;if(w&&M.type==="string"&&M.format==="ArrayString"&&M.default==="[]")z=V.ArrayString(w,F),N.default=JSON.stringify(l.Create(V.Array(w))),N.items=w;return N};if(J){if(U){const M={};for(let[N,I]of Object.entries(U))M[N]=m(I,W,!1);return{...F,properties:M}}else if(w?.map)return{...F,items:w.map((M)=>m(M,W,!1))};return F}if(G.anyOf)for(let M=0;M<G.anyOf.length;M++)G.anyOf[M]=D(G.anyOf[M]);else if(G.oneOf)for(let M=0;M<G.oneOf.length;M++)G.oneOf[M]=D(G.oneOf[M]);else if(G.allOf)for(let M=0;M<G.allOf.length;M++)G.allOf[M]=D(G.allOf[M]);else if(G.not)for(let M=0;M<G.not.length;M++)G.not[M]=D(G.not[M]);if(z)G[j2]=z[j2];if(G.anyOf||G.oneOf||G.allOf||G.not)return G;if(U){const M={};for(let[N,I]of Object.entries(U))M[N]=m(I,W,!1);return{...F,...G,properties:M}}else if(w?.map)return{...F,...G,items:w.map((M)=>m(M,W,!1))};return{...F,...G}}const j=$?.properties;if(j)for(let[Q,Y]of Object.entries(j))switch(Y[R0]){case Z:const{anyOf:K,oneOf:B,allOf:U,not:w,type:F,...G}=Y,z=W.to();if(z.anyOf)for(let D=0;D<z.anyOf.length;D++)z.anyOf[D]={...G,...z.anyOf[D]};else if(z.oneOf)for(let D=0;D<z.oneOf.length;D++)z.oneOf[D]={...G,...z.oneOf[D]};else if(z.allOf)for(let D=0;D<z.allOf.length;D++)z.allOf[D]={...G,...z.allOf[D]};else if(z.not)for(let D=0;D<z.not.length;D++)z.not[D]={...G,...z.not[D]};j[Q]={...G,...m(G,W,!1)};break;case"Object":case"Union":j[Q]=m(Y,W,!1);break;default:if(Y.items)for(let D=0;D<Y.items.length;D++)Y.items[D]=m(Y.items[D],W,!1);else if(Y.anyOf||Y.oneOf||Y.allOf||Y.not)j[Q]=m(Y,W,!1);break}return $},d=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:J=!1,coerce:j=!1,additionalCoerce:Q=[]}={})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;let Y=typeof $==="string"?W[$]:$;if(j)Y=B2(Y,[{from:V.Number(),to:()=>V.Numeric(),untilObjectFound:!0},{from:V.Boolean(),to:()=>V.BooleanString(),untilObjectFound:!0},...Array.isArray(Q)?Q:[Q]]);if(Y.type==="object"&&"additionalProperties"in Y===!1)Y.additionalProperties=J;const K=(U)=>l.Clean(Y,U);if(X){const U={schema:Y,references:"",checkFunc:()=>{},code:"",Check:(w)=>l.Check(Y,w),Errors:(w)=>l.Errors(Y,w),Code:()=>"",Clean:K,Decode:(w)=>l.Decode(Y,w),Encode:(w)=>l.Encode(Y,w)};if(Z&&Y.additionalProperties===!1)U.Clean=K;if(Y.config){if(U.config=Y.config,U?.schema?.config)delete U.schema.config}return U.parse=(w)=>{try{return U.Decode(w)}catch(F){throw[...U.Errors(w)].map(o)}},U.safeParse=(w)=>{try{return{success:!0,data:U.Decode(w),error:null}}catch(F){const G=[...B.Errors(w)].map(o);return{success:!1,data:null,error:G[0]?.summary,errors:G}}},U}const B=G2.Compile(Y,Object.values(W));if(B.Clean=K,Y.config){if(B.config=Y.config,B?.schema?.config)delete B.schema.config}return B.parse=(U)=>{try{return B.Decode(U)}catch(w){throw[...B.Errors(U)].map(o)}},B.safeParse=(U)=>{try{return{success:!0,data:B.Decode(U),error:null}}catch(w){const F=[...B.Errors(U)].map(o);return{success:!1,data:null,error:F[0]?.summary,errors:F}}},B},W1=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:J=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const j=typeof $==="string"?W[$]:$,Q=(K,B)=>{const U=(F)=>{if(!F||typeof F!=="object")return l.Clean(K,F);if(Array.isArray(F))F=l.Clean(K,F);else F=l.Clean(K,F);return F};if(X)return{schema:K,references:"",checkFunc:()=>{},code:"",Check:(F)=>l.Check(K,F),Errors:(F)=>l.Errors(K,F),Code:()=>"",Decode:(F)=>l.Decode(K,F),Encode:(F)=>l.Encode(K,F)};const w=G2.Compile(K,B);if(Z&&K.additionalProperties===!1)w.Clean=U;return w};if(R0 in j){if("additionalProperties"in j===!1)j.additionalProperties=J;return{200:Q(j,Object.values(W))}}const Y={};return Object.keys(j).forEach((K)=>{const B=j[+K];if(typeof B==="string"){if(B in W){const U=W[B];U.type==="object"&&"additionalProperties"in U,Y[+K]=R0 in U?Q(U,Object.values(W)):U}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=J;Y[+K]=R0 in B?Q(B,Object.values(W)):B}),Y},D3=typeof Bun!=="undefined",N3=D3&&typeof Bun.hash==="function",P0=($)=>{if(N3)return Bun.hash($);let W=9;for(let X=0;X<$.length;)W=Math.imul(W^$.charCodeAt(X++),387420489);return W=W^W>>>9},O1,D0=()=>{if(!O1)O1=[{from:V.Object({}),to:()=>V.ObjectString({}),excludeRoot:!0},{from:V.Array(V.Any()),to:()=>V.ArrayString(V.Any())}];return O1},X1=({validator:$,defaultConfig:W={},config:X,dynamic:Z,models:J})=>{let j=d($,{dynamic:Z,models:J,additionalProperties:!0,coerce:!0,additionalCoerce:D0()});if(n(W))if(j)j.config=F3(j.config,X);else j=d(V.Cookie({}),{dynamic:Z,models:J,additionalProperties:!0}),j.config=W;return j},J0=($,W)=>{if(!W)return;if(!Array.isArray(W)){const Z=W;if($&&!Z.checksum)Z.checksum=$;if(Z.scope==="scoped")Z.scope="local";return Z}const X=[...W];for(let Z of X){if($&&!Z.checksum)Z.checksum=$;if(Z.scope==="scoped")Z.scope="local"}return X},V1=($,W,X)=>{return{start:x($.start,J0(X,W?.start)),request:x($.request,J0(X,W?.request)),parse:x($.parse,J0(X,W?.parse)),transform:x($.transform,J0(X,W?.transform)),beforeHandle:x($.beforeHandle,J0(X,W?.beforeHandle)),afterHandle:x($.afterHandle,J0(X,W?.afterHandle)),mapResponse:x($.mapResponse,J0(X,W?.mapResponse)),afterResponse:x($.afterResponse,J0(X,W?.afterResponse)),trace:x($.trace,J0(X,W?.trace)),error:x($.error,J0(X,W?.error)),stop:x($.stop,J0(X,W?.stop))}},K2=($,W,{skipIfHasType:X=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(X)$.scope??=W;else $.scope=W;return $}for(let Z of $)if(X)Z.scope??=W;else Z.scope=W;return $},z0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const W=[];for(let X of $)switch(X.scope){case"global":case"scoped":W.push({...X});break}return W},C1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:z0($?.parse),transform:z0($?.transform),beforeHandle:z0($?.beforeHandle),afterHandle:z0($?.afterHandle),mapResponse:z0($?.mapResponse),afterResponse:z0($?.afterResponse),error:z0($?.error),trace:z0($?.trace)}},_0={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},Z1=Object.fromEntries(Object.entries(_0).map(([$,W])=>[W,$])),Q2=new TextEncoder,g0=async($,W)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(W===null)throw new TypeError("Secret key must be provided.");const X=await crypto.subtle.importKey("raw",Q2.encode(W),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,Q2.encode($));return $+"."+P3(Buffer.from(Z).toString("base64"))},I1=async($,W)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(W===null)throw new TypeError("Secret key must be provided.");const X=$.slice(0,$.lastIndexOf("."));return await g0(X,W)===$?X:!1},U2=($,W)=>{if(!$||typeof $!=="object"||!W)return;for(let[X,Z]of Object.entries(W)){if(X in z3||!(X in $))continue;const J=$[X];if(typeof J==="function")J(Z),delete W[X]}},w2=({globalHook:$,localHook:W})=>(X)=>(Z,J)=>{if(typeof Z==="function")Z={fn:Z};if("fn"in Z||Array.isArray(Z)){if(!W[X])W[X]=[];if(typeof W[X]==="function")W[X]=[W[X]];if(Array.isArray(Z))W[X]=W[X].concat(Z);else W[X].push(Z);return}const{insert:j="after",stack:Q="local"}=Z;if(typeof J==="function")J={fn:J};if(Q==="global")if(!Array.isArray(J))if(j==="before")$[X].unshift(J);else $[X].push(J);else if(j==="before")$[X]=J.concat($[X]);else $[X]=$[X].concat(J);else{if(!W[X])W[X]=[];if(typeof W[X]==="function")W[X]=[W[X]];if(!Array.isArray(J))if(j==="before")W[X].unshift(J);else W[X].push(J);else if(j==="before")W[X]=J.concat(W[X]);else W[X]=W[X].concat(J)}},I3=($)=>{if(typeof $==="number")return $;if($.length<16){if($.trim().length===0)return null;const W=Number($);if(Number.isNaN(W))return null;return W}if($.length===16){if($.trim().length===0)return null;const W=Number($);if(Number.isNaN(W)||W.toString()!==$)return null;return W}return null},J1=($)=>I3($)!==null;class S1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,W){return(this.root??Promise.resolve()).then($,W)}}var t=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const W=[];for(let X of $)if(typeof X==="function")W.push({fn:X});else if("fn"in X)W.push(X);return W},_2=($)=>{return{...$,start:t($?.start),request:t($?.request),parse:t($?.parse),transform:t($?.transform),beforeHandle:t($?.beforeHandle),afterHandle:t($?.afterHandle),mapResponse:t($?.mapResponse),afterResponse:t($?.afterResponse),trace:t($?.trace),error:t($?.error),stop:t($?.stop)}},L1=($)=>{return{...$,start:$.start?.map((W)=>W.fn),request:$.request?.map((W)=>W.fn),parse:$.parse?.map((W)=>W.fn),transform:$.transform?.map((W)=>W.fn),beforeHandle:$.beforeHandle?.map((W)=>W.fn),afterHandle:$.afterHandle?.map((W)=>W.fn),afterResponse:$.afterResponse?.map((W)=>W.fn),mapResponse:$.mapResponse?.map((W)=>W.fn),trace:$.trace?.map((W)=>W.fn),error:$.error?.map((W)=>W.fn),stop:$.stop?.map((W)=>W.fn)}},d0=($)=>({body:$.body,cookie:$.cookie,headers:$.headers,query:$.query,set:$.set,server:$.server}),c0=($,W=302)=>Response.redirect($,W),A3=Symbol("ElysiaFormData"),I0=Symbol("ElysiaRequestId"),N0=($)=>{const W=new FormData;for(let[X,Z]of Object.entries($)){if(Array.isArray(Z)){for(let J of Z){if(Z instanceof File)W.append(X,Z,Z.name);W.append(X,J)}continue}if(Z instanceof File)W.append(X,Z,Z.name);W.append(X,Z)}return W},j1=()=>crypto.getRandomValues(new Uint32Array(1))[0],Q1=($)=>{const W=[];for(let X=0;X<$.length;X++){const Z=$[X];if(Z.checksum){if(W.includes(Z.checksum))$.splice(X,1),X--;W.push(Z.checksum)}}return $},u=($,W="scoped")=>{if(W==="scoped"){for(let X of $)if("scope"in X&&X.scope==="local")X.scope="scoped";return}for(let X of $)if("scope"in X)X.scope="global"};var F2=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,A0=Symbol("ElysiaErrorCode"),c=Symbol("ElysiaResponse"),l0=(F2?.NODE_ENV??F2?.ENV)==="production",T1=($,W)=>{const X=W??($ in Z1?Z1[$]:$);return{[c]:_0[$]??$,response:X,_type:void 0,error:new Error(X)}};class G1 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class O0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class Y1 extends Error{code="PARSE";status=400;constructor(){super("Failed to parse body")}}class u0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,W){super(W??`"${$}" has invalid cookie signature`);this.key=$}}var o=($)=>{if(!$)return{summary:void 0};const{message:W,path:X,value:Z,type:J}=$,j=X.slice(1).replaceAll("/","."),Q=X==="";switch(J){case 42:return{...$,summary:Q?"Value should not be provided":`Property '${j}' should not be provided`};case 45:return{...$,summary:Q?"Value is missing":`Property '${j}' is missing`};case 50:const Y=W.indexOf("'"),K=W.slice(Y+1,W.indexOf("'",Y+1));return{...$,summary:Q?"Value should be an email":`Property '${j}' should be ${K}`};case 54:return{...$,summary:`${W.slice(0,9)} property '${j}' to be ${W.slice(8)} but found: ${Z}`};case 62:const B=$.schema.anyOf.map((U)=>`'${U?.format??U.type}'`).join(", ");return{...$,summary:Q?`Value should be one of ${B}`:`Property '${j}' should be one of: ${B}`};default:return{summary:W,...$}}};class T extends Error{$;W;X;code="VALIDATION";status=422;constructor($,W,X){if(X&&typeof X==="object"&&c in X)X=X.response;const Z=l0?void 0:("Errors"in W)?W.Errors(X).First():p0.Errors(W,X).First(),J=Z?.schema.error!==void 0?typeof Z.schema.error==="function"?Z.schema.error({type:$,validator:W,value:X,get errors(){return[...W.Errors(X)].map(o)}}):Z.schema.error:void 0,j=Z?.path||"root";let Q="";if(J!==void 0)Q=typeof J==="object"?JSON.stringify(J):J+"";else if(l0)Q=JSON.stringify({type:"validation",on:$,summary:o(Z).summary,message:Z?.message,found:X});else{const Y=W?.schema??W,K="Errors"in W?[...W.Errors(X)].map(o):[...p0.Errors(W,X)].map(o);let B;try{B=p0.Create(Y)}catch(U){B={type:"Could not create expected value",message:U?.message,error:U}}Q=JSON.stringify({type:"validation",on:$,summary:K[0]?.summary,property:j,message:Z?.message,expected:B,found:X,errors:K},null,2)}super(Q);this.type=$;this.validator=W;this.value=X;Object.setPrototypeOf(this,T.prototype)}get all(){return"Errors"in this.validator?[...this.validator.Errors(this.value)].map(o):[...p0.Errors(this.validator,this.value)].map(o)}static simplifyModel($){const W="schema"in $?$.schema:$;try{return p0.Create(W)}catch{return W}}get model(){return T.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var q1={open($){$.data.open?.($)},message($,W){$.data.message?.($,W)},drain($){$.data.drain?.($)},close($,W,X){$.data.close?.($,W,X)}};class f0{$;W;validator;_validator;constructor($,W){this.raw=$;this.data=W;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else this.id=j1().toString()}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,W=void 0,X)=>{if(this.validator?.Check(W)===!1)throw new T("message",this.validator,W);if(typeof W==="object")W=JSON.stringify(W);return this.raw.publish($,W,X),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new T("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 E1="1.1.13";import{Value as t0}from"@sinclair/typebox/value";var V0=w1(e0(),1);function B1($){const W={};if(typeof $!=="string")return W;let X="",Z="",J=-1,j=-1,Q=0;const Y=$.length;for(let K=0;K<Y;K++)switch($.charCodeAt(K)){case 38:const B=j>J;if(!B)j=K;if(X=$.slice(J+1,j),B||X.length>0){if(Q&1)X=X.replace(y0," ");if(Q&2)X=V0.default(X)||X;if(!W[X]){if(B){if(Z=$.slice(j+1,K),Q&4)Z=Z.replace(y0," ");if(Q&8)Z=V0.default(Z)||Z}W[X]=Z}}X="",Z="",J=K,j=K,Q=0;break;case 61:if(j<=J)j=K;else Q|=8;break;case 43:if(j>J)Q|=4;else Q|=1;break;case 37:if(j>J)Q|=8;else Q|=2;break}if(J<Y){const K=j>J;if(X=$.slice(J+1,K?j:Y),K||X.length>0){if(Q&1)X=X.replace(y0," ");if(Q&2)X=V0.default(X)||X;if(!W[X]){if(K){if(Z=$.slice(j+1,Y),Q&4)Z=Z.replace(y0," ");if(Q&8)Z=V0.default(Z)||Z}W[X]=Z}}}return W}var y0=/\+/g,i0=($)=>{const W={};if(typeof $!=="string")return W;const X=$.length;let Z="",J="",j=-1,Q=-1,Y=!1,K=!1,B=!1,U=!1,w=!1,F=0;for(let G=0;G<X+1;G++){if(G!==X)F=$.charCodeAt(G);else F=38;switch(F){case 38:{if(w=Q>j,!w)Q=G;if(Z=$.slice(j+1,Q),w||Z.length>0){if(B)Z=Z.replace(y0," ");if(Y)Z=V0.default(Z)||Z;if(w){if(J=$.slice(Q+1,G),U)J=J.replace(y0," ");if(K)J=V0.default(J)||J}const z=W[Z];if(z===void 0)W[Z]=J;else if(z.pop)z.push(J);else W[Z]=[z,J]}J="",j=G,Q=G,Y=!1,K=!1,B=!1,U=!1;break}case 61:if(Q<=j)Q=G;else K=!0;break;case 43:if(Q>j)U=!0;else B=!0;break;case 37:if(Q>j)K=!0;else Y=!0;break}}return W};var z2=w1(e0(),1);var n0=Symbol("ElysiaTrace"),F0=()=>{const{promise:$,resolve:W}=Promise.withResolvers(),{promise:X,resolve:Z}=Promise.withResolvers(),{promise:J,resolve:j}=Promise.withResolvers(),Q=[],Y=[];return[(K)=>{if(K)Q.push(K);return $},(K)=>{const B=[],U=[];let w=null;for(let G=0;G<(K.total??0);G++){const{promise:z,resolve:D}=Promise.withResolvers(),{promise:M,resolve:N}=Promise.withResolvers(),{promise:I,resolve:O}=Promise.withResolvers(),H=[],C=[];B.push((g)=>{if(g)H.push(g);return z}),U.push((g)=>{const R={...g,end:M,error:I,index:G,onStop(E){if(E)C.push(E);return M}};D(R);for(let E=0;E<H.length;E++)H[E](R);return(E=null)=>{const k=performance.now();if(E)w=E;const b={end:k,error:E,get elapsed(){return k-g.begin}};for(let G0=0;G0<C.length;G0++)C[G0](b);N(k),O(E)}})}const F={...K,end:X,error:J,onEvent(G){for(let z=0;z<B.length;z++)B[z](G)},onStop(G){if(G)Y.push(G);return X}};W(F);for(let G=0;G<Q.length;G++)Q[G](F);return{resolveChild:U,resolve(G=null){const z=performance.now();if(!G&&w)G=w;const D={end:z,error:G,get elapsed(){return z-K.begin}};for(let M=0;M<Y.length;M++)Y[M](D);Z(z),j(G)}}}]},M2=($)=>{return(W)=>{const[X,Z]=F0(),[J,j]=F0(),[Q,Y]=F0(),[K,B]=F0(),[U,w]=F0(),[F,G]=F0(),[z,D]=F0(),[M,N]=F0(),[I,O]=F0();return $({id:W[I0],context:W,set:W.set,onRequest:X,onParse:J,onTransform:Q,onBeforeHandle:K,onHandle:U,onAfterHandle:F,onMapResponse:M,onAfterResponse:I,onError:z}),{request:Z,parse:j,transform:Y,beforeHandle:B,handle:w,afterHandle:G,error:D,mapResponse:N,afterResponse:O}}};var V3=new Headers().toJSON,D2={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},s=($)=>{if(!$)return!1;const W=$?.schema;return!!W&&D2.optional in W},j0=($)=>{if(!$)return!1;const W=$?.schema??$;if(W.anyOf)return W.anyOf.some(j0);if(W.someOf)return W.someOf.some(j0);if(W.allOf)return W.allOf.some(j0);if(W.not)return W.not.some(j0);if(W.type==="object"){const X=W.properties;if("additionalProperties"in W)return W.additionalProperties;for(let Z of Object.keys(X)){const J=X[Z];if(J.type==="object"){if(j0(J))return!0}else if(J.anyOf){for(let j=0;j<J.anyOf.length;j++)if(j0(J.anyOf[j]))return!0}return J.additionalProperties}return!1}return!1},R1=({context:$="c",trace:W,addFn:X})=>{if(!W.length)return()=>{return{resolveChild(){return()=>{}},resolve(){}}};for(let Z=0;Z<W.length;Z++)X(`let report${Z}, reportChild${Z}, reportErr${Z}, reportErrChild${Z}; let trace${Z} = ${$}[ELYSIA_TRACE]?.[${Z}] ?? trace[${Z}](${$});\n`);return(Z,{name:J,total:j=0}={})=>{if(!J)J="anonymous";const Q=Z==="error"?"reportErr":"report";for(let Y=0;Y<W.length;Y++)X(`\n${Q}${Y} = trace${Y}.${Z}({id,event: '${Z}',name: '${J}',begin: performance.now(),total: ${j}})\n`);return{resolve(){for(let Y=0;Y<W.length;Y++)X(`\n${Q}${Y}.resolve()\n`)},resolveChild(Y){for(let K=0;K<W.length;K++)X(`${Q}Child${K} = ${Q}${K}.resolveChild?.shift()?.({id,event: '${Z}',name: '${Y}',begin: performance.now()})\n`);return(K)=>{for(let B=0;B<W.length;B++)if(K)X(`
|
|
7
|
+
*/var D1=J3,N1=j3;var Z3=Object.prototype.toString,o0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var $2=w1(e0(),1);class w0{$;W;X;constructor($,W,X={}){this.name=$;this.jar=W;this.initial=X}get cookie(){if(!(this.name in this.jar))this.jar[this.name]=this.initial;return this.jar[this.name]}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get value(){return this.cookie.value}set value($){this.cookie.value=$}get expires(){return this.cookie.expires}set expires($){this.cookie.expires=$,console.log(this.cookie)}get maxAge(){return this.cookie.maxAge}set maxAge($){this.cookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.cookie.domain=$}get path(){return this.cookie.path}set path($){this.cookie.path=$}get secure(){return this.cookie.secure}set secure($){this.cookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.cookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.cookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.cookie.priority=$}get partitioned(){return this.cookie.partitioned}set partitioned($){this.cookie.partitioned=$}get secrets(){return this.cookie.secrets}set secrets($){this.cookie.secrets=$}update($){return this.cookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.cookie=Object.assign({...this.initial,value:this.value},typeof $==="function"?$(this.cookie):$),this}remove(){if(this.value===void 0)return;return this.set({expires:new Date(0),maxAge:0,value:""}),this}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}}var e1=($,W,X)=>{if(!$.cookie)$.cookie={};return new Proxy(W,{get(Z,J){if(J in W)return new w0(J,$.cookie,Object.assign({},X??{},W[J]));return new w0(J,$.cookie,Object.assign({},X))}})},$1=async($,W,{secrets:X,sign:Z,...J}={})=>{if(!W)return e1($,{},J);const j=typeof X==="string";if(Z&&Z!==!0&&!Array.isArray(Z))Z=[Z];const Q={},Y=D1(W);for(let[K,B]of Object.entries(Y)){let U=$2.default(B);if(Z===!0||Z?.includes(K)){if(!X)throw new Error("No secret is provided to cookie plugin");if(j){const w=await I1(U,X);if(w===!1)throw new u0(K);U=w}else{let w=!0;for(let F=0;F<X.length;F++){const G=await I1(U,X[F]);if(G!==!1){w=!0,U=G;break}}if(!w)throw new u0(K)}}Q[K]={value:U}}return e1($,Q,J)};async function*m0($){const W=$.body;if(!W)return;const X=W.getReader(),Z=new TextDecoder;try{while(!0){const{done:J,value:j}=await X.read();if(J)break;yield Z.decode(j)}}finally{X.releaseLock()}}var W2="toJSON"in new Headers,l=($)=>{if(!$)return!1;for(let W in $)return!0;return!1},h0=($,W)=>{const X=$.size;if(!W&&X||X&&W&&W.status!==206&&W.status!==304&&W.status!==412&&W.status!==416){if(W&&l(W.headers)){if(W.headers instanceof Headers){if(W2)W.headers=W.headers.toJSON();else for(let[Z,J]of W.headers.entries())if(Z in W.headers)W.headers[Z]=J}return new Response($,{status:W.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`},W.headers)})}return new Response($,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${X-1}/${X}`,"transfer-encoding":"chunked"}})}return new Response($)},X2=($,W)=>{if(!$)return $;$.delete("set-cookie");for(let X=0;X<W.length;X++){const Z=W[X].indexOf("=");$.append("set-cookie",`${W[X].slice(0,Z)}=${W[X].slice(Z+1)||""}`)}return $},Z2=($)=>{if(!$||!l($))return;const W=[];for(let[X,Z]of Object.entries($)){if(!X||!Z)continue;const J=Z.value;if(J===void 0||J===null)continue;W.push(N1(X,typeof J==="object"?JSON.stringify(J):J+"",Z))}if(W.length===0)return;if(W.length===1)return W[0];return W},B0=async($,W,X)=>{let Z=$.next();if(Z instanceof Promise)Z=await Z;if(Z.done){if(W)return f(Z.value,W,X);return Z0(Z.value,X)}return new Response(new ReadableStream({async start(J){let j=!1;if(X?.signal.addEventListener("abort",()=>{j=!0;try{J.close()}catch{}}),Z.value!==void 0&&Z.value!==null)if(typeof Z.value==="object")try{J.enqueue(Buffer.from(JSON.stringify(Z.value)))}catch{J.enqueue(Buffer.from(Z.value.toString()))}else J.enqueue(Buffer.from(Z.value.toString()));for await(let Q of $){if(j)break;if(Q===void 0||Q===null)continue;if(typeof Q==="object")try{J.enqueue(Buffer.from(JSON.stringify(Q)))}catch{J.enqueue(Buffer.from(Q.toString()))}else J.enqueue(Buffer.from(Q.toString()));await new Promise((Y)=>setTimeout(()=>Y(),0))}try{J.close()}catch{}}}),{...W,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...W?.headers}})},f=($,W,X)=>{if(l(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=_0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&l(W.cookie)){const Z=Z2(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=X2(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return h0($,W);case"Array":return Response.json($,W);case"Object":const Z=$[c];if(Z)return W.status=Z,f($.response,W,X);for(let j in Object.values($))switch(j?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($));default:break}return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,W);case void 0:if(!$)return new Response("",W);return Response.json($,W);case"Response":let J=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(J)continue;J=!0;for(let Q of W.headers.getSetCookie())$.headers.append("set-cookie",Q)}else $.headers.append(j,W.headers?.get(j)??"");else for(let j in W.headers)$.headers.append(j,W.headers[j]);if($.status!==W.status)W.status=$.status;if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((j)=>f(j,W));case"Function":return f($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($,W);default:if($ instanceof Response){let j=!1;if(W.headers instanceof Headers)for(let Q of W.headers.keys())if(Q==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(Q,W.headers?.get(Q)??"");else for(let Q in W.headers)$.headers.append(Q,W.headers[Q]);if(W2)W.headers=$.headers.toJSON();else for(let[Q,Y]of $.headers.entries())if(Q in W.headers)W.headers[Q]=Y;return $}if($ instanceof Promise)return $.then((j)=>f(j,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return f($.toResponse(),W);if("charCodeAt"in $){const j=$.charCodeAt(0);if(j===123||j===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($,W);case"Array":return Response.json($);case"Object":const Z=$[c];if(Z)return W.status=Z,f($.response,W,X);for(let J in Object.values($))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((J)=>{const j=Z0(J,X);if(j!==void 0)return j;return new Response("")});case"Function":return Z0($(),X);case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($,W);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((J)=>f(J,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return f($.toResponse(),W);if("charCodeAt"in $){const J=$.charCodeAt(0);if(J===123||J===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},v=($,W,X)=>{if($===void 0||$===null)return;if(l(W.headers)||W.status!==200||W.redirect||W.cookie){if(typeof W.status==="string")W.status=_0[W.status];if(W.redirect){if(W.headers.Location=W.redirect,!W.status||W.status<300||W.status>=400)W.status=302}if(W.cookie&&l(W.cookie)){const Z=Z2(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=X2(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return h0($,W);case"Array":return Response.json($,W);case"Object":const Z=$[c];if(Z)return W.status=Z,v($.response,W,X);for(let j in Object.values($))switch(j?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":if(!W.headers["content-type"]?.startsWith("text/event-stream"))W.headers["content-type"]="text/event-stream; charset=utf-8";return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,W);case void 0:if(!$)return;return Response.json($,W);case"Response":let J=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(J)continue;J=!0;for(let Q of W.headers.getSetCookie())$.headers.append("set-cookie",Q)}else $.headers.append(j,W.headers?.get(j)??"");else for(let j in W.headers)$.headers.append(j,W.headers[j]);if($.status!==W.status)W.status=$.status;if($.headers.get("transfer-encoding")==="chunked")return B0(m0($),W,X);return $;case"Promise":return $.then((j)=>{const Q=v(j,W);if(Q!==void 0)return Q});case"Error":return K0($,W);case"Function":return v($(),W);case"Number":case"Boolean":return new Response($.toString(),W);case"FormData":return new Response($);case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);default:if($ instanceof Response){let j=!1;if(W.headers instanceof Headers)for(let Q of W.headers.keys())if(Q==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(Q,W.headers?.get(Q)??"");else for(let Q in W.headers)$.headers.append(Q,W.headers[Q]);if($.status!==W.status)W.status=$.status;return $}if($ instanceof Promise)return $.then((j)=>v(j,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return v($.toResponse(),W);if("charCodeAt"in $){const j=$.charCodeAt(0);if(j===123||j===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($,W)}}else switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($,W);case"Array":return Response.json($);case"Object":const Z=$[c];if(Z)return W.status=Z,v($.response,W,X);for(let J in Object.values($))switch(J?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($),W);default:break}return Response.json($,W);case"ReadableStream":return X?.signal.addEventListener("abort",{handleEvent(){if(!X?.signal.aborted)$.cancel(X)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($));return $;case"Promise":return $.then((J)=>{const j=v(J,W);if(j!==void 0)return j});case"Error":return K0($,W);case"Function":return Z0($(),X);case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof w0)return new Response($.value,W);return new Response($?.toString(),W);case"FormData":return new Response($);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((J)=>v(J,W));if($ instanceof Error)return K0($,W);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return v($.toResponse(),W);if("charCodeAt"in $){const J=$.charCodeAt(0);if(J===123||J===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},Z0=($,W)=>{switch($?.constructor?.name){case"String":return new Response($);case"Blob":return h0($);case"Array":return Response.json($);case"Object":if($[c])return f($.response,{status:$[c],headers:{}});$:for(let X of Object.values($))switch(X?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response(N0($));case"Object":break $;default:break}return Response.json($);case"ReadableStream":return W?.signal.addEventListener("abort",{handleEvent(){if(!W?.signal.aborted)$.cancel(W)}},{once:!0}),new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":if($.headers.get("transfer-encoding")==="chunked")return B0(m0($));return $;case"Error":return K0($);case"Promise":return $.then((X)=>Z0(X,W));case"Function":return Z0($(),W);case"Number":case"Boolean":return new Response($.toString());case"FormData":return new Response($);default:if($ instanceof Response)return $;if($ instanceof Promise)return $.then((X)=>Z0(X,W));if($ instanceof Error)return K0($);if(typeof $?.next==="function")return B0($,void 0,W);if("toResponse"in $)return Z0($.toResponse());if("charCodeAt"in $){const X=$.charCodeAt(0);if(X===123||X===91)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}})}return new Response($)}},K0=($,W)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:W?.status!==200?W?.status??500:500,headers:W?.headers}),J2=($,W,X={})=>{if(typeof $==="function"||$ instanceof Blob)return;if(typeof $==="string"&&X["content-type"]===void 0)X["content-type"]="text/plain;charset=utf-8";const Z=f($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0)return Z.clone.bind(Z)};function P3($){let W=$;while(W.endsWith("="))W=W.slice(0,-1);return W}var b0=($,W)=>{const X=new URL($);return X.pathname=W,X.toString()},_3=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")&&$.toString()!=="[object Object]"||l(Object.getPrototypeOf($)),A1=($)=>$&&typeof $==="object"&&!Array.isArray($),p=($,W,{skipKeys:X,override:Z=!0}={})=>{if(!A1($)||!A1(W))return $;for(let[J,j]of Object.entries(W)){if(X?.includes(J))continue;if(!A1(j)||!(J in $)||_3(j)){if(Z||!(J in $))$[J]=j;continue}$[J]=p($[J],j,{skipKeys:X,override:Z})}return $},F3=($,W)=>{const{properties:X,...Z}=$??{},{properties:J,...j}=W??{};return p(Z,j)},x=($=[],W=[])=>{if(!$)return[];if(!W)return $;const X=[],Z=[];if(!Array.isArray($))$=[$];if(!Array.isArray(W))W=[W];for(let J of $)if(X.push(J),J.checksum)Z.push(J.checksum);for(let J of W)if(!Z.includes(J.checksum))X.push(J);return X},M3=["start","request","parse","transform","resolve","beforeHandle","afterHandle","mapResponse","afterResponse","trace","error","stop","body","headers","params","query","response","type","detail"],z3=M3.reduce(($,W)=>($[W]=!0,$),{}),Y2=($,W)=>{const X=(Z)=>typeof Z==="object"&&Object.keys(Z).every(J1);if(X($)&&X(W))return{...$,...W};return W??$},x0=($,W)=>{return{body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:Y2($?.response,W?.response)}},n=($,W)=>{return{...$,...W,body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:Y2($?.response,W?.response),type:$?.type||W?.type,detail:p(W?.detail??{},$?.detail??{}),parse:x($?.parse,W?.parse),transform:x($?.transform,W?.transform),beforeHandle:x($?.beforeHandle,W?.beforeHandle),afterHandle:x($?.afterHandle,W?.afterHandle),mapResponse:x($?.mapResponse,W?.mapResponse),afterResponse:x($?.afterResponse,W?.afterResponse),trace:x($?.trace,W?.trace),error:x($?.error,W?.error)}},B2=($,W,X=!0)=>{if(!Array.isArray(W))return m($,W,X);for(let Z of W)$=m($,Z,X);return $},m=($,W,X=!0)=>{if(!$)return $;if(W.untilObjectFound&&!X&&$.type==="object")return $;const Z=W.from[R0];if($.oneOf){for(let Q=0;Q<$.oneOf.length;Q++)$.oneOf[Q]=m($.oneOf[Q],W,X);return $}if($.anyOf){for(let Q=0;Q<$.anyOf.length;Q++)$.anyOf[Q]=m($.anyOf[Q],W,X);return $}if($.allOf){for(let Q=0;Q<$.allOf.length;Q++)$.allOf[Q]=m($.allOf[Q],W,X);return $}if($.not){for(let Q=0;Q<$.not.length;Q++)$.not[Q]=m($.not[Q],W,X);return $}const J=X&&!!W.excludeRoot;if($[R0]===Z){const{anyOf:Q,oneOf:Y,allOf:K,not:B,properties:U,items:w,...F}=$,G=W.to();let z;const D=(M)=>{if(U&&M.type==="object"){const I={};for(let[O,H]of Object.entries(U))I[O]=m(H,W,!1);return{...F,...M,properties:I}}if(w&&M.type==="array")return{...F,...M,items:m(w,W,!1)};const N={...F,...M};if(delete N.required,U&&M.type==="string"&&M.format==="ObjectString"&&M.default==="{}")z=V.ObjectString(U,F),N.default=JSON.stringify(i.Create(V.Object(U))),N.properties=U;if(w&&M.type==="string"&&M.format==="ArrayString"&&M.default==="[]")z=V.ArrayString(w,F),N.default=JSON.stringify(i.Create(V.Array(w))),N.items=w;return N};if(J){if(U){const M={};for(let[N,I]of Object.entries(U))M[N]=m(I,W,!1);return{...F,properties:M}}else if(w?.map)return{...F,items:w.map((M)=>m(M,W,!1))};return F}if(G.anyOf)for(let M=0;M<G.anyOf.length;M++)G.anyOf[M]=D(G.anyOf[M]);else if(G.oneOf)for(let M=0;M<G.oneOf.length;M++)G.oneOf[M]=D(G.oneOf[M]);else if(G.allOf)for(let M=0;M<G.allOf.length;M++)G.allOf[M]=D(G.allOf[M]);else if(G.not)for(let M=0;M<G.not.length;M++)G.not[M]=D(G.not[M]);if(z)G[j2]=z[j2];if(G.anyOf||G.oneOf||G.allOf||G.not)return G;if(U){const M={};for(let[N,I]of Object.entries(U))M[N]=m(I,W,!1);return{...F,...G,properties:M}}else if(w?.map)return{...F,...G,items:w.map((M)=>m(M,W,!1))};return{...F,...G}}const j=$?.properties;if(j)for(let[Q,Y]of Object.entries(j))switch(Y[R0]){case Z:const{anyOf:K,oneOf:B,allOf:U,not:w,type:F,...G}=Y,z=W.to();if(z.anyOf)for(let D=0;D<z.anyOf.length;D++)z.anyOf[D]={...G,...z.anyOf[D]};else if(z.oneOf)for(let D=0;D<z.oneOf.length;D++)z.oneOf[D]={...G,...z.oneOf[D]};else if(z.allOf)for(let D=0;D<z.allOf.length;D++)z.allOf[D]={...G,...z.allOf[D]};else if(z.not)for(let D=0;D<z.not.length;D++)z.not[D]={...G,...z.not[D]};j[Q]={...G,...m(G,W,!1)};break;case"Object":case"Union":j[Q]=m(Y,W,!1);break;default:if(Y.items)for(let D=0;D<Y.items.length;D++)Y.items[D]=m(Y.items[D],W,!1);else if(Y.anyOf||Y.oneOf||Y.allOf||Y.not)j[Q]=m(Y,W,!1);break}return $},d=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:J=!1,coerce:j=!1,additionalCoerce:Q=[]}={})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;let Y=typeof $==="string"?W[$]:$;if(j)Y=B2(Y,[{from:V.Number(),to:()=>V.Numeric(),untilObjectFound:!0},{from:V.Boolean(),to:()=>V.BooleanString(),untilObjectFound:!0},...Array.isArray(Q)?Q:[Q]]);if(Y.type==="object"&&"additionalProperties"in Y===!1)Y.additionalProperties=J;const K=(U)=>i.Clean(Y,U);if(X){const U={schema:Y,references:"",checkFunc:()=>{},code:"",Check:(w)=>i.Check(Y,w),Errors:(w)=>i.Errors(Y,w),Code:()=>"",Clean:K,Decode:(w)=>i.Decode(Y,w),Encode:(w)=>i.Encode(Y,w)};if(Z&&Y.additionalProperties===!1)U.Clean=K;if(Y.config){if(U.config=Y.config,U?.schema?.config)delete U.schema.config}return U.parse=(w)=>{try{return U.Decode(w)}catch(F){throw[...U.Errors(w)].map(o)}},U.safeParse=(w)=>{try{return{success:!0,data:U.Decode(w),error:null}}catch(F){const G=[...B.Errors(w)].map(o);return{success:!1,data:null,error:G[0]?.summary,errors:G}}},U}const B=G2.Compile(Y,Object.values(W));if(B.Clean=K,Y.config){if(B.config=Y.config,B?.schema?.config)delete B.schema.config}return B.parse=(U)=>{try{return B.Decode(U)}catch(w){throw[...B.Errors(U)].map(o)}},B.safeParse=(U)=>{try{return{success:!0,data:B.Decode(U),error:null}}catch(w){const F=[...B.Errors(U)].map(o);return{success:!1,data:null,error:F[0]?.summary,errors:F}}},B},W1=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:J=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const j=typeof $==="string"?W[$]:$,Q=(K,B)=>{const U=(F)=>{if(!F||typeof F!=="object")return i.Clean(K,F);if(Array.isArray(F))F=i.Clean(K,F);else F=i.Clean(K,F);return F};if(X)return{schema:K,references:"",checkFunc:()=>{},code:"",Check:(F)=>i.Check(K,F),Errors:(F)=>i.Errors(K,F),Code:()=>"",Decode:(F)=>i.Decode(K,F),Encode:(F)=>i.Encode(K,F)};const w=G2.Compile(K,B);if(Z&&K.additionalProperties===!1)w.Clean=U;return w};if(R0 in j){if("additionalProperties"in j===!1)j.additionalProperties=J;return{200:Q(j,Object.values(W))}}const Y={};return Object.keys(j).forEach((K)=>{const B=j[+K];if(typeof B==="string"){if(B in W){const U=W[B];U.type==="object"&&"additionalProperties"in U,Y[+K]=R0 in U?Q(U,Object.values(W)):U}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=J;Y[+K]=R0 in B?Q(B,Object.values(W)):B}),Y},D3=typeof Bun!=="undefined",N3=D3&&typeof Bun.hash==="function",P0=($)=>{if(N3)return Bun.hash($);let W=9;for(let X=0;X<$.length;)W=Math.imul(W^$.charCodeAt(X++),387420489);return W=W^W>>>9},O1,D0=()=>{if(!O1)O1=[{from:V.Object({}),to:()=>V.ObjectString({}),excludeRoot:!0},{from:V.Array(V.Any()),to:()=>V.ArrayString(V.Any())}];return O1},X1=({validator:$,defaultConfig:W={},config:X,dynamic:Z,models:J})=>{let j=d($,{dynamic:Z,models:J,additionalProperties:!0,coerce:!0,additionalCoerce:D0()});if(l(W))if(j)j.config=F3(j.config,X);else j=d(V.Cookie({}),{dynamic:Z,models:J,additionalProperties:!0}),j.config=W;return j},J0=($,W)=>{if(!W)return;if(!Array.isArray(W)){const Z=W;if($&&!Z.checksum)Z.checksum=$;if(Z.scope==="scoped")Z.scope="local";return Z}const X=[...W];for(let Z of X){if($&&!Z.checksum)Z.checksum=$;if(Z.scope==="scoped")Z.scope="local"}return X},V1=($,W,X)=>{return{start:x($.start,J0(X,W?.start)),request:x($.request,J0(X,W?.request)),parse:x($.parse,J0(X,W?.parse)),transform:x($.transform,J0(X,W?.transform)),beforeHandle:x($.beforeHandle,J0(X,W?.beforeHandle)),afterHandle:x($.afterHandle,J0(X,W?.afterHandle)),mapResponse:x($.mapResponse,J0(X,W?.mapResponse)),afterResponse:x($.afterResponse,J0(X,W?.afterResponse)),trace:x($.trace,J0(X,W?.trace)),error:x($.error,J0(X,W?.error)),stop:x($.stop,J0(X,W?.stop))}},K2=($,W,{skipIfHasType:X=!1}={})=>{if(!$)return $;if(!Array.isArray($)){if(X)$.scope??=W;else $.scope=W;return $}for(let Z of $)if(X)Z.scope??=W;else Z.scope=W;return $},z0=($)=>{if(!$)return $;if(!Array.isArray($))switch($.scope){case"global":case"scoped":return{...$};default:return{fn:$}}const W=[];for(let X of $)switch(X.scope){case"global":case"scoped":W.push({...X});break}return W},C1=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:z0($?.parse),transform:z0($?.transform),beforeHandle:z0($?.beforeHandle),afterHandle:z0($?.afterHandle),mapResponse:z0($?.mapResponse),afterResponse:z0($?.afterResponse),error:z0($?.error),trace:z0($?.trace)}},_0={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},Z1=Object.fromEntries(Object.entries(_0).map(([$,W])=>[W,$])),Q2=new TextEncoder,g0=async($,W)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(W===null)throw new TypeError("Secret key must be provided.");const X=await crypto.subtle.importKey("raw",Q2.encode(W),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,Q2.encode($));return $+"."+P3(Buffer.from(Z).toString("base64"))},I1=async($,W)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(W===null)throw new TypeError("Secret key must be provided.");const X=$.slice(0,$.lastIndexOf("."));return await g0(X,W)===$?X:!1},U2=($,W)=>{if(!$||typeof $!=="object"||!W)return;for(let[X,Z]of Object.entries(W)){if(X in z3||!(X in $))continue;const J=$[X];if(typeof J==="function")J(Z),delete W[X]}},w2=({globalHook:$,localHook:W})=>(X)=>(Z,J)=>{if(typeof Z==="function")Z={fn:Z};if("fn"in Z||Array.isArray(Z)){if(!W[X])W[X]=[];if(typeof W[X]==="function")W[X]=[W[X]];if(Array.isArray(Z))W[X]=W[X].concat(Z);else W[X].push(Z);return}const{insert:j="after",stack:Q="local"}=Z;if(typeof J==="function")J={fn:J};if(Q==="global")if(!Array.isArray(J))if(j==="before")$[X].unshift(J);else $[X].push(J);else if(j==="before")$[X]=J.concat($[X]);else $[X]=$[X].concat(J);else{if(!W[X])W[X]=[];if(typeof W[X]==="function")W[X]=[W[X]];if(!Array.isArray(J))if(j==="before")W[X].unshift(J);else W[X].push(J);else if(j==="before")W[X]=J.concat(W[X]);else W[X]=W[X].concat(J)}},I3=($)=>{if(typeof $==="number")return $;if($.length<16){if($.trim().length===0)return null;const W=Number($);if(Number.isNaN(W))return null;return W}if($.length===16){if($.trim().length===0)return null;const W=Number($);if(Number.isNaN(W)||W.toString()!==$)return null;return W}return null},J1=($)=>I3($)!==null;class S1{$;root=null;promises=[];constructor($=console.error){this.onError=$}get size(){return this.promises.length}add($){return this.promises.push($),this.root||=this.drain(),$}async drain(){while(this.promises.length>0){try{await this.promises[0]}catch($){this.onError($)}this.promises.shift()}this.root=null}then($,W){return(this.root??Promise.resolve()).then($,W)}}var t=($)=>{if(!$)return $;if(!Array.isArray($)){if(typeof $==="function")return{fn:$};else if("fn"in $)return $}const W=[];for(let X of $)if(typeof X==="function")W.push({fn:X});else if("fn"in X)W.push(X);return W},_2=($)=>{return{...$,start:t($?.start),request:t($?.request),parse:t($?.parse),transform:t($?.transform),beforeHandle:t($?.beforeHandle),afterHandle:t($?.afterHandle),mapResponse:t($?.mapResponse),afterResponse:t($?.afterResponse),trace:t($?.trace),error:t($?.error),stop:t($?.stop)}},L1=($)=>{return{...$,start:$.start?.map((W)=>W.fn),request:$.request?.map((W)=>W.fn),parse:$.parse?.map((W)=>W.fn),transform:$.transform?.map((W)=>W.fn),beforeHandle:$.beforeHandle?.map((W)=>W.fn),afterHandle:$.afterHandle?.map((W)=>W.fn),afterResponse:$.afterResponse?.map((W)=>W.fn),mapResponse:$.mapResponse?.map((W)=>W.fn),trace:$.trace?.map((W)=>W.fn),error:$.error?.map((W)=>W.fn),stop:$.stop?.map((W)=>W.fn)}},d0=($)=>({body:$.body,cookie:$.cookie,headers:$.headers,query:$.query,set:$.set,server:$.server}),c0=($,W=302)=>Response.redirect($,W),A3=Symbol("ElysiaFormData"),I0=Symbol("ElysiaRequestId"),N0=($)=>{const W=new FormData;for(let[X,Z]of Object.entries($)){if(Array.isArray(Z)){for(let J of Z){if(Z instanceof File)W.append(X,Z,Z.name);W.append(X,J)}continue}if(Z instanceof File)W.append(X,Z,Z.name);W.append(X,Z)}return W},j1=()=>crypto.getRandomValues(new Uint32Array(1))[0],Q1=($)=>{const W=[];for(let X=0;X<$.length;X++){const Z=$[X];if(Z.checksum){if(W.includes(Z.checksum))$.splice(X,1),X--;W.push(Z.checksum)}}return $},u=($,W="scoped")=>{if(W==="scoped"){for(let X of $)if("scope"in X&&X.scope==="local")X.scope="scoped";return}for(let X of $)if("scope"in X)X.scope="global"};var F2=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,A0=Symbol("ElysiaErrorCode"),c=Symbol("ElysiaResponse"),l0=(F2?.NODE_ENV??F2?.ENV)==="production",T1=($,W)=>{const X=W??($ in Z1?Z1[$]:$);return{[c]:_0[$]??$,response:X,_type:void 0,error:new Error(X)}};class G1 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class O0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class Y1 extends Error{code="PARSE";status=400;constructor(){super("Failed to parse body")}}class u0 extends Error{$;code="INVALID_COOKIE_SIGNATURE";status=400;constructor($,W){super(W??`"${$}" has invalid cookie signature`);this.key=$}}var o=($)=>{if(!$)return{summary:void 0};const{message:W,path:X,value:Z,type:J}=$,j=X.slice(1).replaceAll("/","."),Q=X==="";switch(J){case 42:return{...$,summary:Q?"Value should not be provided":`Property '${j}' should not be provided`};case 45:return{...$,summary:Q?"Value is missing":`Property '${j}' is missing`};case 50:const Y=W.indexOf("'"),K=W.slice(Y+1,W.indexOf("'",Y+1));return{...$,summary:Q?"Value should be an email":`Property '${j}' should be ${K}`};case 54:return{...$,summary:`${W.slice(0,9)} property '${j}' to be ${W.slice(8)} but found: ${Z}`};case 62:const B=$.schema.anyOf.map((U)=>`'${U?.format??U.type}'`).join(", ");return{...$,summary:Q?`Value should be one of ${B}`:`Property '${j}' should be one of: ${B}`};default:return{summary:W,...$}}};class T extends Error{$;W;X;code="VALIDATION";status=422;constructor($,W,X){if(X&&typeof X==="object"&&c in X)X=X.response;const Z=l0?void 0:("Errors"in W)?W.Errors(X).First():p0.Errors(W,X).First(),J=Z?.schema.error!==void 0?typeof Z.schema.error==="function"?Z.schema.error({type:$,validator:W,value:X,get errors(){return[...W.Errors(X)].map(o)}}):Z.schema.error:void 0,j=Z?.path||"root";let Q="";if(J!==void 0)Q=typeof J==="object"?JSON.stringify(J):J+"";else if(l0)Q=JSON.stringify({type:"validation",on:$,summary:o(Z).summary,message:Z?.message,found:X});else{const Y=W?.schema??W,K="Errors"in W?[...W.Errors(X)].map(o):[...p0.Errors(W,X)].map(o);let B;try{B=p0.Create(Y)}catch(U){B={type:"Could not create expected value",message:U?.message,error:U}}Q=JSON.stringify({type:"validation",on:$,summary:K[0]?.summary,property:j,message:Z?.message,expected:B,found:X,errors:K},null,2)}super(Q);this.type=$;this.validator=W;this.value=X;Object.setPrototypeOf(this,T.prototype)}get all(){return"Errors"in this.validator?[...this.validator.Errors(this.value)].map(o):[...p0.Errors(this.validator,this.value)].map(o)}static simplifyModel($){const W="schema"in $?$.schema:$;try{return p0.Create(W)}catch{return W}}get model(){return T.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var q1={open($){$.data.open?.($)},message($,W){$.data.message?.($,W)},drain($){$.data.drain?.($)},close($,W,X){$.data.close?.($,W,X)}};class f0{$;W;validator;_validator;constructor($,W){this.raw=$;this.data=W;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else this.id=j1().toString()}get id(){return this.raw.data.id}set id($){this.raw.data.id=$}get publish(){return($,W=void 0,X)=>{if(this.validator?.Check(W)===!1)throw new T("message",this.validator,W);if(typeof W==="object")W=JSON.stringify(W);return this.raw.publish($,W,X),this}}get send(){return($)=>{if(this.validator?.Check($)===!1)throw new T("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 E1="1.1.14";import{Value as t0}from"@sinclair/typebox/value";var V0=w1(e0(),1);function B1($){const W={};if(typeof $!=="string")return W;let X="",Z="",J=-1,j=-1,Q=0;const Y=$.length;for(let K=0;K<Y;K++)switch($.charCodeAt(K)){case 38:const B=j>J;if(!B)j=K;if(X=$.slice(J+1,j),B||X.length>0){if(Q&1)X=X.replace(y0," ");if(Q&2)X=V0.default(X)||X;if(!W[X]){if(B){if(Z=$.slice(j+1,K),Q&4)Z=Z.replace(y0," ");if(Q&8)Z=V0.default(Z)||Z}W[X]=Z}}X="",Z="",J=K,j=K,Q=0;break;case 61:if(j<=J)j=K;else Q|=8;break;case 43:if(j>J)Q|=4;else Q|=1;break;case 37:if(j>J)Q|=8;else Q|=2;break}if(J<Y){const K=j>J;if(X=$.slice(J+1,K?j:Y),K||X.length>0){if(Q&1)X=X.replace(y0," ");if(Q&2)X=V0.default(X)||X;if(!W[X]){if(K){if(Z=$.slice(j+1,Y),Q&4)Z=Z.replace(y0," ");if(Q&8)Z=V0.default(Z)||Z}W[X]=Z}}}return W}var y0=/\+/g,i0=($)=>{const W={};if(typeof $!=="string")return W;const X=$.length;let Z="",J="",j=-1,Q=-1,Y=!1,K=!1,B=!1,U=!1,w=!1,F=0;for(let G=0;G<X+1;G++){if(G!==X)F=$.charCodeAt(G);else F=38;switch(F){case 38:{if(w=Q>j,!w)Q=G;if(Z=$.slice(j+1,Q),w||Z.length>0){if(B)Z=Z.replace(y0," ");if(Y)Z=V0.default(Z)||Z;if(w){if(J=$.slice(Q+1,G),U)J=J.replace(y0," ");if(K)J=V0.default(J)||J}const z=W[Z];if(z===void 0)W[Z]=J;else if(z.pop)z.push(J);else W[Z]=[z,J]}J="",j=G,Q=G,Y=!1,K=!1,B=!1,U=!1;break}case 61:if(Q<=j)Q=G;else K=!0;break;case 43:if(Q>j)U=!0;else B=!0;break;case 37:if(Q>j)K=!0;else Y=!0;break}}return W};var z2=w1(e0(),1);var n0=Symbol("ElysiaTrace"),F0=()=>{const{promise:$,resolve:W}=Promise.withResolvers(),{promise:X,resolve:Z}=Promise.withResolvers(),{promise:J,resolve:j}=Promise.withResolvers(),Q=[],Y=[];return[(K)=>{if(K)Q.push(K);return $},(K)=>{const B=[],U=[];let w=null;for(let G=0;G<(K.total??0);G++){const{promise:z,resolve:D}=Promise.withResolvers(),{promise:M,resolve:N}=Promise.withResolvers(),{promise:I,resolve:O}=Promise.withResolvers(),H=[],C=[];B.push((g)=>{if(g)H.push(g);return z}),U.push((g)=>{const R={...g,end:M,error:I,index:G,onStop(E){if(E)C.push(E);return M}};D(R);for(let E=0;E<H.length;E++)H[E](R);return(E=null)=>{const k=performance.now();if(E)w=E;const b={end:k,error:E,get elapsed(){return k-g.begin}};for(let G0=0;G0<C.length;G0++)C[G0](b);N(k),O(E)}})}const F={...K,end:X,error:J,onEvent(G){for(let z=0;z<B.length;z++)B[z](G)},onStop(G){if(G)Y.push(G);return X}};W(F);for(let G=0;G<Q.length;G++)Q[G](F);return{resolveChild:U,resolve(G=null){const z=performance.now();if(!G&&w)G=w;const D={end:z,error:G,get elapsed(){return z-K.begin}};for(let M=0;M<Y.length;M++)Y[M](D);Z(z),j(G)}}}]},M2=($)=>{return(W)=>{const[X,Z]=F0(),[J,j]=F0(),[Q,Y]=F0(),[K,B]=F0(),[U,w]=F0(),[F,G]=F0(),[z,D]=F0(),[M,N]=F0(),[I,O]=F0();return $({id:W[I0],context:W,set:W.set,onRequest:X,onParse:J,onTransform:Q,onBeforeHandle:K,onHandle:U,onAfterHandle:F,onMapResponse:M,onAfterResponse:I,onError:z}),{request:Z,parse:j,transform:Y,beforeHandle:B,handle:w,afterHandle:G,error:D,mapResponse:N,afterResponse:O}}};var V3=new Headers().toJSON,D2={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},s=($)=>{if(!$)return!1;const W=$?.schema;return!!W&&D2.optional in W},j0=($)=>{if(!$)return!1;const W=$?.schema??$;if(W.anyOf)return W.anyOf.some(j0);if(W.someOf)return W.someOf.some(j0);if(W.allOf)return W.allOf.some(j0);if(W.not)return W.not.some(j0);if(W.type==="object"){const X=W.properties;if("additionalProperties"in W)return W.additionalProperties;for(let Z of Object.keys(X)){const J=X[Z];if(J.type==="object"){if(j0(J))return!0}else if(J.anyOf){for(let j=0;j<J.anyOf.length;j++)if(j0(J.anyOf[j]))return!0}return J.additionalProperties}return!1}return!1},R1=({context:$="c",trace:W,addFn:X})=>{if(!W.length)return()=>{return{resolveChild(){return()=>{}},resolve(){}}};for(let Z=0;Z<W.length;Z++)X(`let report${Z}, reportChild${Z}, reportErr${Z}, reportErrChild${Z}; let trace${Z} = ${$}[ELYSIA_TRACE]?.[${Z}] ?? trace[${Z}](${$});\n`);return(Z,{name:J,total:j=0}={})=>{if(!J)J="anonymous";const Q=Z==="error"?"reportErr":"report";for(let Y=0;Y<W.length;Y++)X(`\n${Q}${Y} = trace${Y}.${Z}({id,event: '${Z}',name: '${J}',begin: performance.now(),total: ${j}})\n`);return{resolve(){for(let Y=0;Y<W.length;Y++)X(`\n${Q}${Y}.resolve()\n`)},resolveChild(Y){for(let K=0;K<W.length;K++)X(`${Q}Child${K} = ${Q}${K}.resolveChild?.shift()?.({id,event: '${Z}',name: '${Y}',begin: performance.now()})\n`);return(K)=>{for(let B=0;B<W.length;B++)if(K)X(`
|
|
8
8
|
if (${K} instanceof Error)
|
|
9
9
|
${Q}Child${B}?.(${K})
|
|
10
10
|
else
|
|
@@ -250,7 +250,7 @@ var C2=Object.create;var{getPrototypeOf:S2,defineProperty:f1,getOwnPropertyNames
|
|
|
250
250
|
${E("body")}
|
|
251
251
|
}`;else G+=`if(validator.body.Check(c.body) === false) {
|
|
252
252
|
${E("body")}
|
|
253
|
-
}`;if(P)G+="\nif(isNotEmptyObject) c.body = validator.body.Decode(c.body)\n"}if(
|
|
253
|
+
}`;if(P)G+="\nif(isNotEmptyObject) c.body = validator.body.Decode(c.body)\n"}if(l(H?.schema?.properties??H?.schema?.schema??{})){if(G+=`const cookieValue = {}
|
|
254
254
|
for(const [key, value] of Object.entries(c.cookie))
|
|
255
255
|
cookieValue[key] = value.value\n`,C0("default",H.schema))for(let[P,_]of Object.entries(t0.Default(H.schema,{})))G+=`cookieValue['${P}'] = ${typeof _==="object"?JSON.stringify(_):_}\n`;if(s(j.cookie))G+="if(isNotEmpty(c.cookie)) {";if(G+=`if(validator.cookie.Check(cookieValue) === false) {
|
|
256
256
|
${E("cookie","cookieValue")}
|
|
@@ -353,7 +353,7 @@ var C2=Object.create;var{getPrototypeOf:S2,defineProperty:f1,getOwnPropertyNames
|
|
|
353
353
|
|
|
354
354
|
${Y?"c.schema = schema; c.defs = definitions":""}
|
|
355
355
|
${G}
|
|
356
|
-
}`;try{return Function("hooks",G)({handler:Q,hooks:L1(J),validator:j,handleError:$.handleError,utils:{mapResponse:f,mapCompactResponse:Z0,mapEarlyResponse:v,parseQuery:i0,parseQueryFromURL:B1,isNotEmpty:
|
|
356
|
+
}`;try{return Function("hooks",G)({handler:Q,hooks:L1(J),validator:j,handleError:$.handleError,utils:{mapResponse:f,mapCompactResponse:Z0,mapEarlyResponse:v,parseQuery:i0,parseQueryFromURL:B1,isNotEmpty:l},error:{NotFoundError:O0,ValidationError:T,InternalServerError:G1,ParseError:Y1},schema:$.router.history,definitions:$.definitions.type,ERROR_CODE:A0,parseCookie:$1,signCookie:g0,decodeURIComponent:z2.default,ELYSIA_RESPONSE:c,ELYSIA_TRACE:n0,ELYSIA_REQUEST_ID:I0,getServer:()=>$.getServer()})}catch{const P=L1(J);console.log("[Composer] failed to generate optimized handler"),console.log("Please report the following to SaltyAom privately as it may include sensitive information about your codebase:"),console.log("---"),console.log({handler:typeof Q==="function"?Q.toString():Q,hooks:{...P,transform:P?.transform?.map?.((_)=>_.toString()),resolve:P?.resolve?.map?.((_)=>_.toString()),beforeHandle:P?.beforeHandle?.map?.((_)=>_.toString()),afterHandle:P?.afterHandle?.map?.((_)=>_.toString()),mapResponse:P?.mapResponse?.map?.((_)=>_.toString()),parse:P?.parse?.map?.((_)=>_.toString()),error:P?.error?.map?.((_)=>_.toString()),afterResponse:P?.afterResponse?.map?.((_)=>_.toString()),stop:P?.stop?.map?.((_)=>_.toString())},validator:j,definitions:$.definitions.type}),console.log("---"),process.exit(1)}},b1=($)=>{const W=$.config.handler?.standardHostname??!0;let X="",Z="";const J=$.setHeaders;for(let D of Object.keys($.singleton.decorator))X+=`,${D}: app.singleton.decorator.${D}`;const j=$.router,Q=$.event.trace.length>0;let Y=`
|
|
357
357
|
const route = router.find(request.method, path) ${j.http.root.ALL?'?? router.find("ALL", path)':""}
|
|
358
358
|
|
|
359
359
|
if (route === null)
|
|
@@ -516,6 +516,6 @@ var C2=Object.create;var{getPrototypeOf:S2,defineProperty:f1,getOwnPropertyNames
|
|
|
516
516
|
error.message,
|
|
517
517
|
{ headers: set.headers, status: error.status }
|
|
518
518
|
)\n`;const Q=J("mapResponse",{total:W.mapResponse.length,name:"context"});if(W.mapResponse.length)for(let Y=0;Y<W.mapResponse.length;Y++){const K=W.mapResponse[Y],B=Q.resolveChild(K.fn.name);X+=`\ncontext.response = error
|
|
519
|
-
error = ${L0(K)?"await":""} onMapResponse[${Y}](context)\n`,B()}return Q.resolve(),X+=`\nreturn mapResponse(${j} error, set, context.request)\n}\n}`,Function("inject",X)({app:$,mapResponse:f,ERROR_CODE:A0,ELYSIA_RESPONSE:c,ELYSIA_TRACE:n0,ELYSIA_REQUEST_ID:I0})};var g1=($)=>async(W)=>{const X=W.url,Z=X.indexOf("/",11),J=X.indexOf("?",Z+1),j=J===-1?X.substring(Z):X.substring(Z,J),Q={cookie:{},status:200,headers:{}},Y=Object.assign({},$.singleton.decorator,{set:Q,store:$.singleton.store,request:W,path:j,qi:J,redirect:c0});try{for(let N=0;N<$.event.request.length;N++){const I=$.event.request[N].fn;let O=I(Y);if(O instanceof Promise)O=await O;if(O=v(O,Q),O)return Y.response=O}const K=$.router.dynamic.find(W.method,j)??$.router.dynamic.find("ALL",j);if(!K)throw new O0;const{handle:B,hooks:U,validator:w,content:F}=K.store;let G;if(W.method!=="GET"&&W.method!=="HEAD")if(F)switch(F){case"application/json":G=await W.json();break;case"text/plain":G=await W.text();break;case"application/x-www-form-urlencoded":G=i0(await W.text());break;case"application/octet-stream":G=await W.arrayBuffer();break;case"multipart/form-data":G={};const N=await W.formData();for(let I of N.keys()){if(G[I])continue;const O=N.getAll(I);if(O.length===1)G[I]=O[0];else G[I]=O}break}else{let N=W.headers.get("content-type");if(N){const I=N.indexOf(";");if(I!==-1)N=N.slice(0,I);Y.contentType=N;for(let O=0;O<U.parse.length;O++){const H=U.parse[O].fn;let C=H(Y,N);if(C instanceof Promise)C=await C;if(C){G=C;break}}if(delete Y.contentType,G===void 0)switch(N){case"application/json":G=await W.json();break;case"text/plain":G=await W.text();break;case"application/x-www-form-urlencoded":G=i0(await W.text());break;case"application/octet-stream":G=await W.arrayBuffer();break;case"multipart/form-data":G={};const O=await W.formData();for(let H of O.keys()){if(G[H])continue;const C=O.getAll(H);if(C.length===1)G[H]=C[0];else G[H]=C}break}}}Y.body=G,Y.params=K?.params||void 0,Y.query=J===-1?{}:B1(X.substring(J+1)),Y.headers={};for(let[N,I]of W.headers.entries())Y.headers[N]=I;const z=Object.assign({},$.config?.cookie,w?.cookie?.config),D=W.headers.get("cookie");Y.cookie=await $1(Y.set,D,z?{secrets: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 N=0;N<U.transform.length;N++){const I=U.transform[N],O=I.fn(Y);if(I.subType==="derive")if(O instanceof Promise)Object.assign(Y,await O);else Object.assign(Y,O);else if(O instanceof Promise)await O}if(w){if(w.createHeaders?.()){const N={};for(let I in W.headers)N[I]=W.headers.get(I);if(w.headers.Check(N)===!1)throw new T("header",w.headers,N)}else if(w.headers?.Decode)Y.headers=w.headers.Decode(Y.headers);if(w.createParams?.()?.Check(Y.params)===!1)throw new T("params",w.params,Y.params);else if(w.params?.Decode)Y.params=w.params.Decode(Y.params);if(w.createQuery?.()?.Check(Y.query)===!1)throw new T("query",w.query,Y.query);else if(w.query?.Decode)Y.query=w.query.Decode(Y.query);if(w.createCookie?.()){let N={};for(let[I,O]of Object.entries(Y.cookie))N[I]=O.value;if(w.cookie.Check(N)===!1)throw new T("cookie",w.cookie,N);else if(w.cookie?.Decode)N=w.cookie.Decode(N)}if(w.createBody?.()?.Check(G)===!1)throw new T("body",w.body,G);else if(w.body?.Decode)Y.body=w.body.Decode(G)}for(let N=0;N<U.beforeHandle.length;N++){let I=U.beforeHandle[N].fn(Y);if(I instanceof Promise)I=await I;if(I!==void 0){Y.response=I;for(let H=0;H<U.afterHandle.length;H++){let C=U.afterHandle[H].fn(Y);if(C instanceof Promise)C=await C;if(C)I=C}const O=v(I,Y.set);if(O)return Y.response=O}}let M=B(Y);if(M instanceof Promise)M=await M;if(!U.afterHandle.length){const N=M?.[c]??(Q.status?typeof Q.status==="string"?_0[Q.status]:Q.status:200),I=w?.createResponse?.()?.[N];if(I?.Check(M)===!1)throw new T("response",I,M);else if(I?.Decode)M=I.Decode(M)}else{Y.response=M;for(let N=0;N<U.afterHandle.length;N++){let I=U.afterHandle[N].fn(Y);if(I instanceof Promise)I=await I;const O=v(I,Y.set);if(O!==void 0){const H=w?.response?.[O.status];if(H?.Check(O)===!1)throw new T("response",H,O);else if(H?.Decode)M=H.Decode(M);return Y.response=O}}}if(Y.set.cookie&&z?.sign){const N=!z.secrets?void 0:typeof z.secrets==="string"?z.secrets:z.secrets[0];if(z.sign===!0)for(let[I,O]of Object.entries(Y.set.cookie))Y.set.cookie[I].value=await g0(O.value,"${secret}");else{const I=w?.cookie?.schema?.properties;for(let O of z.sign){if(!(O in I))continue;if(Y.set.cookie[O]?.value)Y.set.cookie[O].value=await g0(Y.set.cookie[O].value,N)}}}return Y.response=f(M,Y.set)}catch(K){if(K.status)Q.status=K.status;return $.handleError(Y,K)}finally{for(let K of $.event.afterResponse)await K.fn(Y)}},P2=($)=>async(W,X)=>{const Z=Object.assign(W,{error:X,code:X.code});Z.set=W.set;for(let J=0;J<$.event.error.length;J++){let Q=$.event.error[J].fn(Z);if(Q instanceof Promise)Q=await Q;if(Q!==void 0&&Q!==null)return W.response=f(Q,W.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:W.set.headers,status:X.status??500})};import{TypeSystemPolicy as z5}from"@sinclair/typebox/system";class Q0{config;server=null;dependencies={};_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};static version=E1;version=E1;singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[],higherOrderFunctions:[]};validator={global:null,scoped:null,local:null,getCandidate(){return x0(x0(this.global,this.scoped),this.local)}};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],afterResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new M0,ws:new M0,dynamic:new M0,static:{http:{static:{},handlers:[],map:{},all:""},ws:{}},history:[]};routeTree=new Map;get routes(){return this.router.history}getGlobalRoutes(){return this.router.history}inference={body:!1,cookie:!1,headers:!1,query:!1,set:!1,server:!1};getServer(){return this.server}_promisedModules;get promisedModules(){if(!this._promisedModules)this._promisedModules=new S1;return this._promisedModules}constructor($={}){if($.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if($.nativeStaticResponse===void 0)$.nativeStaticResponse=!0;if(this.config={},this.applyConfig($??{}),$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}env($,W=Bun?.env??process.env){if(d($,{dynamic:!0,additionalProperties:!0,coerce:!0}).Check(W)===!1){const Z=new T("env",$,W);throw new Error(Z.all.map((J)=>J.summary).join("\n"))}return this}wrap($){return this.extender.higherOrderFunctions.push({checksum:P0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$}),this}applyMacro($){if(this.extender.macros.length){const W=w2({globalHook:this.event,localHook:$}),X={events:{global:this.event,local:$},onParse:W("parse"),onTransform:W("transform"),onBeforeHandle:W("beforeHandle"),onAfterHandle:W("afterHandle"),mapResponse:W("mapResponse"),onAfterResponse:W("afterResponse"),onError:W("error")};for(let Z of this.extender.macros)U2(Z.fn(X),$)}}applyConfig($){return this.config={prefix:"",aot:!0,strictPath:!1,global:!1,analytic:!1,normalize:!0,...$,cookie:{path:"/",...$?.cookie},experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},this}get models(){const $={};for(let[W,X]of Object.entries(this.definitions.type))$[W]=d(X);return $}add($,W,X,Z,{allowMeta:J=!1,skipPrefix:j=!1}={allowMeta:!1,skipPrefix:!1}){if(Z=_2(Z),W!==""&&W.charCodeAt(0)!==47)W="/"+W;if(this.config.prefix&&!j&&!this.config.scoped)W=this.config.prefix+W;if(Z?.type)switch(Z.type){case"text":Z.type="text/plain";break;case"json":Z.type="application/json";break;case"formdata":Z.type="multipart/form-data";break;case"urlencoded":Z.type="application/x-www-form-urlencoded";break;case"arrayBuffer":Z.type="application/octet-stream";break;default:break}const Q=this.definitions.type,Y=!this.config.aot,K={...this.validator.getCandidate()},B={body:Z?.body??K?.body,headers:Z?.headers??K?.headers,params:Z?.params??K?.params,query:Z?.query??K?.query,cookie:Z?.cookie??K?.cookie,response:Z?.response??K?.response},U=()=>B.cookie?X1({validator:B.cookie,defaultConfig:this.config.cookie,config:B.cookie?.config??{},dynamic:Y,models:Q}):void 0,w=this.config.normalize,F=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:d(B.body,{dynamic:Y,models:Q,normalize:w}),headers:d(B.headers,{dynamic:Y,models:Q,additionalProperties:!this.config.normalize,coerce:!0,additionalCoerce:D0()}),params:d(B.params,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()}),query:d(B.query,{dynamic:Y,models:Q,normalize:w,coerce:!0,additionalCoerce:D0()}),cookie:U(),response:W1(B.response,{dynamic:Y,models:Q,normalize:w})}:{createBody(){if(this.body)return this.body;return this.body=d(B.body,{dynamic:Y,models:Q,normalize:w})},createHeaders(){if(this.headers)return this.headers;return this.headers=d(B.headers,{dynamic:Y,models:Q,additionalProperties:!w,coerce:!0,additionalCoerce:D0()})},createParams(){if(this.params)return this.params;return this.params=d(B.params,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()})},createQuery(){if(this.query)return this.query;return this.query=d(B.query,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()})},createCookie(){if(this.cookie)return this.cookie;return this.cookie=U()},createResponse(){if(this.response)return this.response;return this.response=W1(B.response,{dynamic:Y,models:Q,normalize:w})}},G=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(Z=i(Z,K),Z.tags)if(!Z.detail)Z.detail={tags:Z.tags};else Z.detail.tags=Z.tags;if(n(this.config.detail))Z.detail=p(Object.assign({},this.config.detail),Z.detail);this.applyMacro(Z);const z=i(this.event,Z);if(this.config.aot===!1){if(this.router.dynamic.add($,W,{validator:F,hooks:z,content:Z?.type,handle:X}),this.config.strictPath===!1)this.router.dynamic.add($,G,{validator:F,hooks:z,content:Z?.type,handle:X});this.router.history.push({method:$,path:W,composed:null,handler:X,hooks:z});return}const D=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,M=d0(this.inference),N=typeof X!=="function"?J2(X,z,this.setHeaders):void 0;if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[W]=N();const I=()=>N2({app:this,path:W,method:$,localHook:i(Z),hooks:z,validator:F,handler:X,allowMeta:J,inference:M}),O=D?I():(R)=>{return I()(R)},H=this.router.history.length;if(this.routeTree.has($+W))for(let R=0;R<this.router.history.length;R++){const E=this.router.history[R];if(E.path===W&&E.method===$){const k=this.router.history.splice(R,1)[0];if(k&&this.routeTree.has(k?.method+k?.path))this.routeTree.delete(k.method+k.path)}}else this.routeTree.set($+W,H);this.router.history.push({method:$,path:W,composed:O,handler:X,hooks:z});const C=this.router.static.http,g={handler:D?O:void 0,compile:I};if($==="$INTERNALWS"){const R=this.config.strictPath?void 0:W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const E=C.handlers.length;if(C.handlers.push((k)=>(C.handlers[E]=I())(k)),this.router.static.ws[W]=E,R)this.router.static.ws[R]=E}else if(this.router.ws.add("ws",W,g),R)this.router.ws.add("ws",R,g);return}if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const R=C.handlers.length;if(C.handlers.push(N??((k)=>(C.handlers[R]=I())(k))),!C.map[W])C.map[W]={code:""};const E=N?"":"ctx";if($==="ALL")C.map[W].all=`default: return st[${R}](${E})\n`;else C.map[W].code=`case '${$}': return st[${R}](${E})\n${C.map[W].code}`;if(!this.config.strictPath){if(!C.map[G])C.map[G]={code:""};if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[G]=N();if($==="ALL")C.map[G].all=`default: return st[${R}](${E})\n`;else C.map[G].code=`case '${$}': return st[${R}](${E})\n${C.map[G].code}`}}else if(this.router.http.add($,W,g),!this.config.strictPath){const R=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[R]=N();this.router.http.add($,R,g)}}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,W){if(!W)return this.on("parse",$);return this.on($,"parse",W)}onTransform($,W){if(!W)return this.on("transform",$);return this.on($,"transform",W)}resolve($,W){if(!W)W=$,$={as:"local"};const X={subType:"resolve",fn:W};return this.onBeforeHandle($,X)}mapResolve($,W){if(!W)W=$,$={as:"local"};const X={subType:"mapResolve",fn:W};return this.onBeforeHandle($,X)}onBeforeHandle($,W){if(!W)return this.on("beforeHandle",$);return this.on($,"beforeHandle",W)}onAfterHandle($,W){if(!W)return this.on("afterHandle",$);return this.on($,"afterHandle",W)}mapResponse($,W){if(!W)return this.on("mapResponse",$);return this.on($,"mapResponse",W)}onAfterResponse($,W){if(!W)return this.on("afterResponse",$);return this.on($,"afterResponse",W)}trace($,W){if(!W)W=$,$={as:"local"};if(!Array.isArray(W))W=[W];for(let X of W)this.on($,"trace",M2(X));return this}error($,W){switch(typeof $){case"string":return W.prototype[A0]=$,this.definitions.error[$]=W,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,Z]of Object.entries($))Z.prototype[A0]=X,this.definitions.error[X]=Z;return this}onError($,W){if(!W)return this.on("error",$);return this.on($,"error",W)}onStop($){return this.on("stop",$),this}on($,W,X){let Z;switch(typeof $){case"string":Z=$,X=W;break;case"object":if(Z=W,!Array.isArray(W)&&typeof W==="object")X=W;break}if(Array.isArray(X))X=t(X);else if(typeof X==="function")X=[{fn:X}];else X=[X];const J=X;for(let j of J)j.scope=typeof $==="string"?"local":$?.as??"local";if(Z!=="trace")r0({[Z]:J.map((j)=>j.fn)},this.inference);for(let j of J){const Q=K2(j,"global",{skipIfHasType:!0});switch(Z){case"start":this.event.start.push(Q);break;case"request":this.event.request.push(Q);break;case"parse":this.event.parse.push(Q);break;case"transform":this.event.transform.push(Q);break;case"beforeHandle":this.event.beforeHandle.push(Q);break;case"afterHandle":this.event.afterHandle.push(Q);break;case"mapResponse":this.event.mapResponse.push(Q);break;case"afterResponse":this.event.afterResponse.push(Q);break;case"trace":this.event.trace.push(Q);break;case"error":this.event.error.push(Q);break;case"stop":this.event.stop.push(Q);break}}return this}propagate(){return u(this.event.parse),u(this.event.transform),u(this.event.beforeHandle),u(this.event.afterHandle),u(this.event.mapResponse),u(this.event.afterResponse),u(this.event.trace),u(this.event.error),this}as($){const W={plugin:"scoped",global:"global"}[$];if(u(this.event.parse,W),u(this.event.transform,W),u(this.event.beforeHandle,W),u(this.event.afterHandle,W),u(this.event.mapResponse,W),u(this.event.afterResponse,W),u(this.event.trace,W),u(this.event.error,W),$==="plugin")this.validator.scoped=x0(this.validator.scoped,this.validator.local),this.validator.local=null;else if($==="global")this.validator.global=x0(this.validator.global,x0(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null;return this}group($,W,X){const Z=new Q0({...this.config,prefix:""});Z.singleton={...this.singleton},Z.definitions={...this.definitions},Z.getServer=()=>this.getServer(),Z.inference=d0(this.inference),Z.extender={...this.extender};const J=typeof W==="object",j=(J?X:W)(Z);if(this.singleton=p(this.singleton,Z.singleton),this.definitions=p(this.definitions,Z.definitions),j.event.request.length)this.event.request=[...this.event.request||[],...j.event.request||[]];if(j.event.mapResponse.length)this.event.mapResponse=[...this.event.mapResponse||[],...j.event.mapResponse||[]];return this.model(j.definitions.type),Object.values(Z.router.history).forEach(({method:Q,path:Y,handler:K,hooks:B})=>{if(Y=(J?"":this.config.prefix)+$+Y,J){const U=W,w=B;this.add(Q,Y,K,i(U,{...w||{},error:!w.error?j.event.error:Array.isArray(w.error)?[...w.error||{},...j.event.error||{}]:[w.error,...j.event.error||{}]}))}else this.add(Q,Y,K,i(B,{error:j.event.error}),{skipPrefix:!0})}),this}guard($,W){if(!W){if(typeof $==="object"){this.applyMacro($);const J=$.as??"local";if(this.validator[J]={body:$.body??this.validator[J]?.body,headers:$.headers??this.validator[J]?.headers,params:$.params??this.validator[J]?.params,query:$.query??this.validator[J]?.query,response:$.response??this.validator[J]?.response,cookie:$.cookie??this.validator[J]?.cookie},$.parse)this.on({as:J},"parse",$.parse);if($.transform)this.on({as:J},"transform",$.transform);if($.beforeHandle)this.on({as:J},"beforeHandle",$.beforeHandle);if($.afterHandle)this.on({as:J},"afterHandle",$.afterHandle);if($.mapResponse)this.on({as:J},"mapResponse",$.mapResponse);if($.afterResponse)this.on({as:J},"afterResponse",$.afterResponse);if($.error)this.on({as:J},"error",$.error);if($.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const X=new Q0({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.inference=d0(this.inference),X.extender={...this.extender};const Z=W(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Z.getServer=()=>this.server,Z.event.request.length)this.event.request=[...this.event.request||[],...Z.event.request||[]];if(Z.event.mapResponse.length)this.event.mapResponse=[...this.event.mapResponse||[],...Z.event.mapResponse||[]];return this.model(Z.definitions.type),Object.values(X.router.history).forEach(({method:J,path:j,handler:Q,hooks:Y})=>{this.add(J,j,Q,i($,{...Y||{},error:!Y.error?Z.event.error:Array.isArray(Y.error)?[...Y.error||{},...Z.event.error||[]]:[Y.error,...Z.event.error||[]]}))}),this}use($,W){if(W?.scoped)return this.guard({},(X)=>X.use($));if(Array.isArray($)){let X=this;for(let Z of $)X=this.use(Z);return X}if($ instanceof Promise)return this.promisedModules.add($.then((X)=>{if(typeof X==="function")return X(this);if(X instanceof Q0)return this._use(X).compile();if(typeof X.default==="function")return X.default(this);if(X.default instanceof Q0)return this._use(X.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((X)=>X.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const J=$(this);if(J instanceof Promise)return this.promisedModules.add(J.then((j)=>{if(j instanceof Q0){j.getServer=()=>this.getServer(),j.getGlobalRoutes=()=>this.getGlobalRoutes(),j.model(this.definitions.type),j.error(this.definitions.error);for(let{method:Q,path:Y,handler:K,hooks:B}of Object.values(j.router.history))this.add(Q,Y,K,i(B,{error:j.event.error}));return j.compile(),j}if(typeof j==="function")return j(this);if(typeof j.default==="function")return j.default(this);return this._use(j)}).then((j)=>j.compile())),this;return J}const{name:W,seed:X}=$.config;$.getServer=()=>this.getServer(),$.getGlobalRoutes=()=>this.getGlobalRoutes(),$.model(this.definitions.type),$.error(this.definitions.error);const Z=$.config.scoped;if(Z){if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const j=X!==void 0?P0(W+JSON.stringify(X)):0;if(this.dependencies[W].some(({checksum:Q})=>j===Q))return this;this.dependencies[W].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:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q.subType==="derive").map((Q)=>({fn:Q.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q.subType==="derive").map((Q)=>({fn:Q.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const J=[];for(let j=0;j<$.extender.macros.length;j++){const Q=this.extender.macros[j];if(J.includes(Q.checksum))$.extender.macros.splice(j,1),j--;J.push(Q.checksum)}if($.onRequest((j)=>{Object.assign(j,this.singleton.decorator),Object.assign(j.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(Z===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let j of $.router.history)this.routeTree.set(j.method+`${$.config.prefix}${j.path}`,this.router.history.length),this.router.history.push({...j,path:`${$.config.prefix}${j.path}`,hooks:i(j.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let j of $.router.history)this.routeTree.set(j.method+`${$.config.prefix}${j.path}`,this.router.history.length),this.router.history.push({...j,path:`${$.config.prefix}${j.path}`,hooks:i(j.hooks,{error:this.event.error})})}return this}else{if(this.headers($.setHeaders),W){if(!(W in this.dependencies))this.dependencies[W]=[];const j=X!==void 0?P0(W+JSON.stringify(X)):0;if(!this.dependencies[W].some(({checksum:Q})=>j===Q))this.extender.macros=this.extender.macros.concat($.extender.macros),this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat($.extender.higherOrderFunctions)}else this.extender.macros=this.extender.macros.concat($.extender.macros),this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat($.extender.higherOrderFunctions);Q1(this.extender.macros),Q1(this.extender.higherOrderFunctions);const J=[];for(let j=0;j<this.extender.higherOrderFunctions.length;j++){const Q=this.extender.higherOrderFunctions[j];if(Q.checksum){if(J.includes(Q.checksum))this.extender.higherOrderFunctions.splice(j,1),j--;J.push(Q.checksum)}}this.inference={body:this.inference.body||$.inference.body,cookie:this.inference.cookie||$.inference.cookie,headers:this.inference.headers||$.inference.headers,query:this.inference.query||$.inference.query,set:this.inference.set||$.inference.set,server:this.inference.server||$.inference.server}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error),$.extender.macros=this.extender.macros.concat($.extender.macros);for(let{method:J,path:j,handler:Q,hooks:Y}of Object.values($.router.history))this.add(J,j,Q,i(Y,{error:$.event.error}));if(!Z)if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const J=X!==void 0?P0(W+JSON.stringify(X)):0;if(this.dependencies[W].some(({checksum:j})=>J===j))return this;this.dependencies[W].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:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((j)=>j?.subType==="derive").map((j)=>({fn:j.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((j)=>j?.subType==="resolve").map((j)=>({fn:j.toString(),stack:new Error().stack??""}))}),this.event=V1(this.event,C1($.event),J)}else this.event=V1(this.event,C1($.event));return this.validator.global=i(this.validator.global,{...$.validator.global}),this.validator.local=i(this.validator.local,{...$.validator.scoped}),this}macro($){const W={checksum:P0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(W),this}mount($,W){if($ instanceof Q0||typeof $==="function"||$.length===0||$==="/"){const J=typeof $==="function"?$:$ instanceof Q0?$.compile().fetch:W instanceof Q0?W.compile().fetch:W,j=async({request:Q,path:Y})=>{if(Q.method==="GET"||Q.method==="HEAD"||!Q.headers.get("content-type"))return J(new Request(b0(Q.url,Y||"/"),Q));return J(new Request(b0(Q.url,Y||"/"),{...Q,body:await Q.arrayBuffer()}))};return this.all("/*",j,{type:"none"}),this}const X=$.length;if(W instanceof Q0)W=W.compile().fetch;const Z=async({request:J,path:j})=>{if(J.method==="GET"||J.method==="HEAD"||!J.headers.get("content-type"))return W(new Request(b0(J.url,j.slice(X)||"/"),J));return W(new Request(b0(J.url,j.slice(X)||"/"),{...J,body:await J.arrayBuffer()}))};return this.all($,Z,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),Z,{type:"none"}),this}get($,W,X){return this.add("GET",$,W,X),this}post($,W,X){return this.add("POST",$,W,X),this}put($,W,X){return this.add("PUT",$,W,X),this}patch($,W,X){return this.add("PATCH",$,W,X),this}delete($,W,X){return this.add("DELETE",$,W,X),this}options($,W,X){return this.add("OPTIONS",$,W,X),this}all($,W,X){return this.add("ALL",$,W,X),this}head($,W,X){return this.add("HEAD",$,W,X),this}connect($,W,X){return this.add("CONNECT",$,W,X),this}route($,W,X,Z){return this.add($.toUpperCase(),W,X,Z,Z?.config),this}ws($,W){const X=W.transformMessage?Array.isArray(W.transformMessage)?W.transformMessage:[W.transformMessage]:void 0;let Z=null;const J=d(W?.body,{models:this.definitions.type,normalize:this.config.normalize}),j=d(W?.response,{models:this.definitions.type,normalize:this.config.normalize}),Q=(Y)=>{if(typeof Y==="string"){const K=Y?.charCodeAt(0);if(K===47||K===123)try{Y=JSON.parse(Y)}catch{}else if(J1(Y))Y=+Y}if(X?.length)for(let K=0;K<X.length;K++){const B=X[K](Y);if(B!==void 0)Y=B}return Y};return this.route("$INTERNALWS",$,(Y)=>{const{set:K,path:B,qi:U,headers:w,query:F,params:G}=Y;if(Z===null)Z=this.getServer();if(Z?.upgrade(Y.request,{headers:typeof W.upgrade==="function"?W.upgrade(Y):W.upgrade,data:{validator:j,open(z){W.open?.(new f0(z,Y))},message:(z,D)=>{const M=Q(D);if(J?.Check(M)===!1)return void z.send(new T("message",J,M).message);W.message?.(new f0(z,Y),M)},drain(z){W.drain?.(new f0(z,Y))},close(z,D,M){W.close?.(new f0(z,Y),D,M)}}}))return;return K.status=400,"Expected a websocket connection"},{beforeHandle:W.beforeHandle,transform:W.transform,headers:W.headers,params:W.params,query:W.query}),this}state($,W,X){if(W===void 0)X=$,$={as:"append"},W="";else if(X===void 0){if(typeof $==="string")X=W,W=$,$={as:"append"};else if(typeof $==="object")X=W,W=""}const{as:Z}=$;if(typeof W!=="string")return this;switch(typeof X){case"object":if(W){if(W in this.singleton.store)this.singleton.store[W]=p(this.singleton.store[W],X,{override:Z==="override"});else this.singleton.store[W]=X;return this}if(X===null)return this;return this.singleton.store=p(this.singleton.store,X,{override:Z==="override"}),this;case"function":if(W){if(Z==="override"||!(W in this.singleton.store))this.singleton.store[W]=X}else this.singleton.store=X(this.singleton.store);return this;default:if(Z==="override"||!(W in this.singleton.store))this.singleton.store[W]=X;return this}}decorate($,W,X){if(W===void 0)X=$,$={as:"append"},W="";else if(X===void 0){if(typeof $==="string")X=W,W=$,$={as:"append"};else if(typeof $==="object")X=W,W=""}const{as:Z}=$;if(typeof W!=="string")return this;switch(typeof X){case"object":if(W){if(W in this.singleton.decorator)this.singleton.decorator[W]=p(this.singleton.decorator[W],X,{override:Z==="override"});else this.singleton.decorator[W]=X;return this}if(X===null)return this;return this.singleton.decorator=p(this.singleton.decorator,X,{override:Z==="override"}),this;case"function":if(W){if(Z==="override"||!(W in this.singleton.decorator))this.singleton.decorator[W]=X}else this.singleton.decorator=X(this.singleton.decorator);return this;default:if(Z==="override"||!(W in this.singleton.decorator))this.singleton.decorator[W]=X;return this}}derive($,W){if(!W)W=$,$={as:"local"};const X={subType:"derive",fn:W};return this.onTransform($,X)}model($,W){switch(typeof $){case"object":return Object.entries($).forEach(([X,Z])=>{if(!(X in this.definitions.type))this.definitions.type[X]=Z}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=W,this}mapDerive($,W){if(!W)W=$,$={as:"local"};const X={subType:"mapDerive",fn:W};return this.onTransform($,X)}affix($,W,X){if(X==="")return this;const Z=["_","-"," "],J=(K)=>K[0].toUpperCase()+K.slice(1),j=$==="prefix"?(K,B)=>Z.includes(K.at(-1)??"")?K+B:K+J(B):Z.includes(X.at(-1)??"")?(K,B)=>B+K:(K,B)=>B+J(K),Q=(K)=>{const B={};switch(K){case"decorator":for(let U in this.singleton.decorator)B[j(X,U)]=this.singleton.decorator[U];this.singleton.decorator=B;break;case"state":for(let U in this.singleton.store)B[j(X,U)]=this.singleton.store[U];this.singleton.store=B;break;case"model":for(let U in this.definitions.type)B[j(X,U)]=this.definitions.type[U];this.definitions.type=B;break;case"error":for(let U in this.definitions.error)B[j(X,U)]=this.definitions.error[U];this.definitions.error=B;break}},Y=Array.isArray(W)?W:[W];for(let K of Y.some((B)=>B==="all")?["decorator","state","model","error"]:Y)Q(K);return this}prefix($,W){return this.affix("prefix",$,W)}suffix($,W){return this.affix("suffix",$,W)}compile(){if(this.fetch=this.config.aot?b1(this):g1(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?b1(this):g1(this))($)};handleError=async($,W)=>(this.handleError=this.config.aot?x1(this):P2(this))($,W);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,W)=>{if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof $==="string"){if(!J1($))throw new Error("Port must be a numeric value");$=parseInt($)}const X=this.fetch,Z=typeof $==="object"?{development:!l0,reusePort:!0,...this.config.serve||{},...$||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...q1||{}},fetch:X,error:this.outerErrorHandler}:{development:!l0,reusePort:!0,...this.config.serve||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...q1||{}},port:$,fetch:X,error:this.outerErrorHandler};this.server=Bun?.serve(Z);for(let J=0;J<this.event.start.length;J++)this.event.start[J].fn(this);if(W)W(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let J=0;J<this.event.stop.length;J++)this.event.stop[J].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async($)=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop($),this.server=null,this.event.stop.length)for(let W=0;W<this.event.stop.length;W++)this.event.stop[W].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,b0 as replaceUrlPath,B2 as replaceSchemaType,c0 as redirect,x as mergeObjectArray,i as mergeHook,o as mapValueError,f as mapResponse,v as mapEarlyResponse,Z0 as mapCompactResponse,d as getSchemaValidator,W1 as getResponseSchemaValidator,N0 as form,T1 as error,Q0 as default,Q1 as deduplicateChecksum,d0 as cloneInference,P0 as checksum,T as ValidationError,z5 as TypeSystemPolicy,_0 as StatusMap,Y1 as ParseError,O0 as NotFoundError,Z1 as InvertedStatusMap,u0 as InvalidCookieSignature,G1 as InternalServerError,Q0 as Elysia,A0 as ERROR_CODE,n0 as ELYSIA_TRACE,c as ELYSIA_RESPONSE,I0 as ELYSIA_REQUEST_ID,A3 as ELYSIA_FORM_DATA,w0 as Cookie};
|
|
519
|
+
error = ${L0(K)?"await":""} onMapResponse[${Y}](context)\n`,B()}return Q.resolve(),X+=`\nreturn mapResponse(${j} error, set, context.request)\n}\n}`,Function("inject",X)({app:$,mapResponse:f,ERROR_CODE:A0,ELYSIA_RESPONSE:c,ELYSIA_TRACE:n0,ELYSIA_REQUEST_ID:I0})};var g1=($)=>async(W)=>{const X=W.url,Z=X.indexOf("/",11),J=X.indexOf("?",Z+1),j=J===-1?X.substring(Z):X.substring(Z,J),Q={cookie:{},status:200,headers:{}},Y=Object.assign({},$.singleton.decorator,{set:Q,store:$.singleton.store,request:W,path:j,qi:J,redirect:c0});try{for(let N=0;N<$.event.request.length;N++){const I=$.event.request[N].fn;let O=I(Y);if(O instanceof Promise)O=await O;if(O=v(O,Q),O)return Y.response=O}const K=$.router.dynamic.find(W.method,j)??$.router.dynamic.find("ALL",j);if(!K)throw new O0;const{handle:B,hooks:U,validator:w,content:F}=K.store;let G;if(W.method!=="GET"&&W.method!=="HEAD")if(F)switch(F){case"application/json":G=await W.json();break;case"text/plain":G=await W.text();break;case"application/x-www-form-urlencoded":G=i0(await W.text());break;case"application/octet-stream":G=await W.arrayBuffer();break;case"multipart/form-data":G={};const N=await W.formData();for(let I of N.keys()){if(G[I])continue;const O=N.getAll(I);if(O.length===1)G[I]=O[0];else G[I]=O}break}else{let N=W.headers.get("content-type");if(N){const I=N.indexOf(";");if(I!==-1)N=N.slice(0,I);Y.contentType=N;for(let O=0;O<U.parse.length;O++){const H=U.parse[O].fn;let C=H(Y,N);if(C instanceof Promise)C=await C;if(C){G=C;break}}if(delete Y.contentType,G===void 0)switch(N){case"application/json":G=await W.json();break;case"text/plain":G=await W.text();break;case"application/x-www-form-urlencoded":G=i0(await W.text());break;case"application/octet-stream":G=await W.arrayBuffer();break;case"multipart/form-data":G={};const O=await W.formData();for(let H of O.keys()){if(G[H])continue;const C=O.getAll(H);if(C.length===1)G[H]=C[0];else G[H]=C}break}}}Y.body=G,Y.params=K?.params||void 0,Y.query=J===-1?{}:B1(X.substring(J+1)),Y.headers={};for(let[N,I]of W.headers.entries())Y.headers[N]=I;const z=Object.assign({},$.config?.cookie,w?.cookie?.config),D=W.headers.get("cookie");Y.cookie=await $1(Y.set,D,z?{secrets: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 N=0;N<U.transform.length;N++){const I=U.transform[N],O=I.fn(Y);if(I.subType==="derive")if(O instanceof Promise)Object.assign(Y,await O);else Object.assign(Y,O);else if(O instanceof Promise)await O}if(w){if(w.createHeaders?.()){const N={};for(let I in W.headers)N[I]=W.headers.get(I);if(w.headers.Check(N)===!1)throw new T("header",w.headers,N)}else if(w.headers?.Decode)Y.headers=w.headers.Decode(Y.headers);if(w.createParams?.()?.Check(Y.params)===!1)throw new T("params",w.params,Y.params);else if(w.params?.Decode)Y.params=w.params.Decode(Y.params);if(w.createQuery?.()?.Check(Y.query)===!1)throw new T("query",w.query,Y.query);else if(w.query?.Decode)Y.query=w.query.Decode(Y.query);if(w.createCookie?.()){let N={};for(let[I,O]of Object.entries(Y.cookie))N[I]=O.value;if(w.cookie.Check(N)===!1)throw new T("cookie",w.cookie,N);else if(w.cookie?.Decode)N=w.cookie.Decode(N)}if(w.createBody?.()?.Check(G)===!1)throw new T("body",w.body,G);else if(w.body?.Decode)Y.body=w.body.Decode(G)}for(let N=0;N<U.beforeHandle.length;N++){let I=U.beforeHandle[N].fn(Y);if(I instanceof Promise)I=await I;if(I!==void 0){Y.response=I;for(let H=0;H<U.afterHandle.length;H++){let C=U.afterHandle[H].fn(Y);if(C instanceof Promise)C=await C;if(C)I=C}const O=v(I,Y.set);if(O)return Y.response=O}}let M=B(Y);if(M instanceof Promise)M=await M;if(!U.afterHandle.length){const N=M?.[c]??(Q.status?typeof Q.status==="string"?_0[Q.status]:Q.status:200),I=w?.createResponse?.()?.[N];if(I?.Check(M)===!1)throw new T("response",I,M);else if(I?.Decode)M=I.Decode(M)}else{Y.response=M;for(let N=0;N<U.afterHandle.length;N++){let I=U.afterHandle[N].fn(Y);if(I instanceof Promise)I=await I;const O=v(I,Y.set);if(O!==void 0){const H=w?.response?.[O.status];if(H?.Check(O)===!1)throw new T("response",H,O);else if(H?.Decode)M=H.Decode(M);return Y.response=O}}}if(Y.set.cookie&&z?.sign){const N=!z.secrets?void 0:typeof z.secrets==="string"?z.secrets:z.secrets[0];if(z.sign===!0)for(let[I,O]of Object.entries(Y.set.cookie))Y.set.cookie[I].value=await g0(O.value,"${secret}");else{const I=w?.cookie?.schema?.properties;for(let O of z.sign){if(!(O in I))continue;if(Y.set.cookie[O]?.value)Y.set.cookie[O].value=await g0(Y.set.cookie[O].value,N)}}}return Y.response=f(M,Y.set)}catch(K){if(K.status)Q.status=K.status;return $.handleError(Y,K)}finally{for(let K of $.event.afterResponse)await K.fn(Y)}},P2=($)=>async(W,X)=>{const Z=Object.assign(W,{error:X,code:X.code});Z.set=W.set;for(let J=0;J<$.event.error.length;J++){let Q=$.event.error[J].fn(Z);if(Q instanceof Promise)Q=await Q;if(Q!==void 0&&Q!==null)return W.response=f(Q,W.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:W.set.headers,status:X.status??500})};import{TypeSystemPolicy as z5}from"@sinclair/typebox/system";class Q0{config;server=null;dependencies={};_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};static version=E1;version=E1;singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[],higherOrderFunctions:[]};validator={global:null,scoped:null,local:null,getCandidate(){return x0(x0(this.global,this.scoped),this.local)}};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],afterResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new M0,ws:new M0,dynamic:new M0,static:{http:{static:{},handlers:[],map:{},all:""},ws:{}},history:[]};routeTree=new Map;get routes(){return this.router.history}getGlobalRoutes(){return this.router.history}inference={body:!1,cookie:!1,headers:!1,query:!1,set:!1,server:!1};getServer(){return this.server}_promisedModules;get promisedModules(){if(!this._promisedModules)this._promisedModules=new S1;return this._promisedModules}constructor($={}){if($.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if($.nativeStaticResponse===void 0)$.nativeStaticResponse=!0;if(this.config={},this.applyConfig($??{}),$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}env($,W=Bun?.env??process.env){if(d($,{dynamic:!0,additionalProperties:!0,coerce:!0}).Check(W)===!1){const Z=new T("env",$,W);throw new Error(Z.all.map((J)=>J.summary).join("\n"))}return this}wrap($){return this.extender.higherOrderFunctions.push({checksum:P0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$}),this}applyMacro($){if(this.extender.macros.length){const W=w2({globalHook:this.event,localHook:$}),X={events:{global:this.event,local:$},onParse:W("parse"),onTransform:W("transform"),onBeforeHandle:W("beforeHandle"),onAfterHandle:W("afterHandle"),mapResponse:W("mapResponse"),onAfterResponse:W("afterResponse"),onError:W("error")};for(let Z of this.extender.macros)U2(Z.fn(X),$)}}applyConfig($){return this.config={prefix:"",aot:!0,strictPath:!1,global:!1,analytic:!1,normalize:!0,...$,cookie:{path:"/",...$?.cookie},experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},this}get models(){const $={};for(let[W,X]of Object.entries(this.definitions.type))$[W]=d(X);return $}add($,W,X,Z,{allowMeta:J=!1,skipPrefix:j=!1}={allowMeta:!1,skipPrefix:!1}){if(Z=_2(Z),W!==""&&W.charCodeAt(0)!==47)W="/"+W;if(this.config.prefix&&!j&&!this.config.scoped)W=this.config.prefix+W;if(Z?.type)switch(Z.type){case"text":Z.type="text/plain";break;case"json":Z.type="application/json";break;case"formdata":Z.type="multipart/form-data";break;case"urlencoded":Z.type="application/x-www-form-urlencoded";break;case"arrayBuffer":Z.type="application/octet-stream";break;default:break}const Q=this.definitions.type,Y=!this.config.aot,K={...this.validator.getCandidate()},B={body:Z?.body??K?.body,headers:Z?.headers??K?.headers,params:Z?.params??K?.params,query:Z?.query??K?.query,cookie:Z?.cookie??K?.cookie,response:Z?.response??K?.response},U=()=>B.cookie?X1({validator:B.cookie,defaultConfig:this.config.cookie,config:B.cookie?.config??{},dynamic:Y,models:Q}):void 0,w=this.config.normalize,F=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:d(B.body,{dynamic:Y,models:Q,normalize:w}),headers:d(B.headers,{dynamic:Y,models:Q,additionalProperties:!this.config.normalize,coerce:!0,additionalCoerce:D0()}),params:d(B.params,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()}),query:d(B.query,{dynamic:Y,models:Q,normalize:w,coerce:!0,additionalCoerce:D0()}),cookie:U(),response:W1(B.response,{dynamic:Y,models:Q,normalize:w})}:{createBody(){if(this.body)return this.body;return this.body=d(B.body,{dynamic:Y,models:Q,normalize:w})},createHeaders(){if(this.headers)return this.headers;return this.headers=d(B.headers,{dynamic:Y,models:Q,additionalProperties:!w,coerce:!0,additionalCoerce:D0()})},createParams(){if(this.params)return this.params;return this.params=d(B.params,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()})},createQuery(){if(this.query)return this.query;return this.query=d(B.query,{dynamic:Y,models:Q,coerce:!0,additionalCoerce:D0()})},createCookie(){if(this.cookie)return this.cookie;return this.cookie=U()},createResponse(){if(this.response)return this.response;return this.response=W1(B.response,{dynamic:Y,models:Q,normalize:w})}},G=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(Z=n(Z,K),Z.tags)if(!Z.detail)Z.detail={tags:Z.tags};else Z.detail.tags=Z.tags;if(l(this.config.detail))Z.detail=p(Object.assign({},this.config.detail),Z.detail);this.applyMacro(Z);const z=n(this.event,Z);if(this.config.aot===!1){if(this.router.dynamic.add($,W,{validator:F,hooks:z,content:Z?.type,handle:X}),this.config.strictPath===!1)this.router.dynamic.add($,G,{validator:F,hooks:z,content:Z?.type,handle:X});this.router.history.push({method:$,path:W,composed:null,handler:X,hooks:z});return}const D=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,M=d0(this.inference),N=typeof X!=="function"?J2(X,z,this.setHeaders):void 0;if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[W]=N();const I=()=>N2({app:this,path:W,method:$,localHook:n(Z),hooks:z,validator:F,handler:X,allowMeta:J,inference:M}),O=D?I():(R)=>{return I()(R)},H=this.router.history.length;if(this.routeTree.has($+W))for(let R=0;R<this.router.history.length;R++){const E=this.router.history[R];if(E.path===W&&E.method===$){const k=this.router.history.splice(R,1)[0];if(k&&this.routeTree.has(k?.method+k?.path))this.routeTree.delete(k.method+k.path)}}else this.routeTree.set($+W,H);this.router.history.push({method:$,path:W,composed:O,handler:X,hooks:z});const C=this.router.static.http,g={handler:D?O:void 0,compile:I};if($==="$INTERNALWS"){const R=this.config.strictPath?void 0:W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const E=C.handlers.length;if(C.handlers.push((k)=>(C.handlers[E]=I())(k)),this.router.static.ws[W]=E,R)this.router.static.ws[R]=E}else if(this.router.ws.add("ws",W,g),R)this.router.ws.add("ws",R,g);return}if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const R=C.handlers.length;if(C.handlers.push(N??((k)=>(C.handlers[R]=I())(k))),!C.map[W])C.map[W]={code:""};const E=N?"":"ctx";if($==="ALL")C.map[W].all=`default: return st[${R}](${E})\n`;else C.map[W].code=`case '${$}': return st[${R}](${E})\n${C.map[W].code}`;if(!this.config.strictPath){if(!C.map[G])C.map[G]={code:""};if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[G]=N();if($==="ALL")C.map[G].all=`default: return st[${R}](${E})\n`;else C.map[G].code=`case '${$}': return st[${R}](${E})\n${C.map[G].code}`}}else if(this.router.http.add($,W,g),!this.config.strictPath){const R=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(this.config.nativeStaticResponse===!0&&N&&($==="GET"||$==="ALL"))this.router.static.http.static[R]=N();this.router.http.add($,R,g)}}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,W){if(!W)return this.on("parse",$);return this.on($,"parse",W)}onTransform($,W){if(!W)return this.on("transform",$);return this.on($,"transform",W)}resolve($,W){if(!W)W=$,$={as:"local"};const X={subType:"resolve",fn:W};return this.onBeforeHandle($,X)}mapResolve($,W){if(!W)W=$,$={as:"local"};const X={subType:"mapResolve",fn:W};return this.onBeforeHandle($,X)}onBeforeHandle($,W){if(!W)return this.on("beforeHandle",$);return this.on($,"beforeHandle",W)}onAfterHandle($,W){if(!W)return this.on("afterHandle",$);return this.on($,"afterHandle",W)}mapResponse($,W){if(!W)return this.on("mapResponse",$);return this.on($,"mapResponse",W)}onAfterResponse($,W){if(!W)return this.on("afterResponse",$);return this.on($,"afterResponse",W)}trace($,W){if(!W)W=$,$={as:"local"};if(!Array.isArray(W))W=[W];for(let X of W)this.on($,"trace",M2(X));return this}error($,W){switch(typeof $){case"string":return W.prototype[A0]=$,this.definitions.error[$]=W,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,Z]of Object.entries($))Z.prototype[A0]=X,this.definitions.error[X]=Z;return this}onError($,W){if(!W)return this.on("error",$);return this.on($,"error",W)}onStop($){return this.on("stop",$),this}on($,W,X){let Z;switch(typeof $){case"string":Z=$,X=W;break;case"object":if(Z=W,!Array.isArray(W)&&typeof W==="object")X=W;break}if(Array.isArray(X))X=t(X);else if(typeof X==="function")X=[{fn:X}];else X=[X];const J=X;for(let j of J)j.scope=typeof $==="string"?"local":$?.as??"local";if(Z!=="trace")r0({[Z]:J.map((j)=>j.fn)},this.inference);for(let j of J){const Q=K2(j,"global",{skipIfHasType:!0});switch(Z){case"start":this.event.start.push(Q);break;case"request":this.event.request.push(Q);break;case"parse":this.event.parse.push(Q);break;case"transform":this.event.transform.push(Q);break;case"beforeHandle":this.event.beforeHandle.push(Q);break;case"afterHandle":this.event.afterHandle.push(Q);break;case"mapResponse":this.event.mapResponse.push(Q);break;case"afterResponse":this.event.afterResponse.push(Q);break;case"trace":this.event.trace.push(Q);break;case"error":this.event.error.push(Q);break;case"stop":this.event.stop.push(Q);break}}return this}propagate(){return u(this.event.parse),u(this.event.transform),u(this.event.beforeHandle),u(this.event.afterHandle),u(this.event.mapResponse),u(this.event.afterResponse),u(this.event.trace),u(this.event.error),this}as($){const W={plugin:"scoped",global:"global"}[$];if(u(this.event.parse,W),u(this.event.transform,W),u(this.event.beforeHandle,W),u(this.event.afterHandle,W),u(this.event.mapResponse,W),u(this.event.afterResponse,W),u(this.event.trace,W),u(this.event.error,W),$==="plugin")this.validator.scoped=x0(this.validator.scoped,this.validator.local),this.validator.local=null;else if($==="global")this.validator.global=x0(this.validator.global,x0(this.validator.scoped,this.validator.local)),this.validator.scoped=null,this.validator.local=null;return this}group($,W,X){const Z=new Q0({...this.config,prefix:""});Z.singleton={...this.singleton},Z.definitions={...this.definitions},Z.getServer=()=>this.getServer(),Z.inference=d0(this.inference),Z.extender={...this.extender};const J=typeof W==="object",j=(J?X:W)(Z);if(this.singleton=p(this.singleton,Z.singleton),this.definitions=p(this.definitions,Z.definitions),j.event.request.length)this.event.request=[...this.event.request||[],...j.event.request||[]];if(j.event.mapResponse.length)this.event.mapResponse=[...this.event.mapResponse||[],...j.event.mapResponse||[]];return this.model(j.definitions.type),Object.values(Z.router.history).forEach(({method:Q,path:Y,handler:K,hooks:B})=>{if(Y=(J?"":this.config.prefix)+$+Y,J){const U=W,w=B;this.add(Q,Y,K,n(U,{...w||{},error:!w.error?j.event.error:Array.isArray(w.error)?[...w.error||{},...j.event.error||{}]:[w.error,...j.event.error||{}]}))}else this.add(Q,Y,K,n(B,{error:j.event.error}),{skipPrefix:!0})}),this}guard($,W){if(!W){if(typeof $==="object"){this.applyMacro($);const J=$.as??"local";if(this.validator[J]={body:$.body??this.validator[J]?.body,headers:$.headers??this.validator[J]?.headers,params:$.params??this.validator[J]?.params,query:$.query??this.validator[J]?.query,response:$.response??this.validator[J]?.response,cookie:$.cookie??this.validator[J]?.cookie},$.parse)this.on({as:J},"parse",$.parse);if($.transform)this.on({as:J},"transform",$.transform);if($.beforeHandle)this.on({as:J},"beforeHandle",$.beforeHandle);if($.afterHandle)this.on({as:J},"afterHandle",$.afterHandle);if($.mapResponse)this.on({as:J},"mapResponse",$.mapResponse);if($.afterResponse)this.on({as:J},"afterResponse",$.afterResponse);if($.error)this.on({as:J},"error",$.error);if($.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const X=new Q0({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.inference=d0(this.inference),X.extender={...this.extender};const Z=W(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Z.getServer=()=>this.server,Z.event.request.length)this.event.request=[...this.event.request||[],...Z.event.request||[]];if(Z.event.mapResponse.length)this.event.mapResponse=[...this.event.mapResponse||[],...Z.event.mapResponse||[]];return this.model(Z.definitions.type),Object.values(X.router.history).forEach(({method:J,path:j,handler:Q,hooks:Y})=>{this.add(J,j,Q,n($,{...Y||{},error:!Y.error?Z.event.error:Array.isArray(Y.error)?[...Y.error||{},...Z.event.error||[]]:[Y.error,...Z.event.error||[]]}))}),this}use($,W){if(W?.scoped)return this.guard({},(X)=>X.use($));if(Array.isArray($)){let X=this;for(let Z of $)X=this.use(Z);return X}if($ instanceof Promise)return this.promisedModules.add($.then((X)=>{if(typeof X==="function")return X(this);if(X instanceof Q0)return this._use(X).compile();if(typeof X.default==="function")return X.default(this);if(X.default instanceof Q0)return this._use(X.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((X)=>X.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const J=$(this);if(J instanceof Promise)return this.promisedModules.add(J.then((j)=>{if(j instanceof Q0){j.getServer=()=>this.getServer(),j.getGlobalRoutes=()=>this.getGlobalRoutes(),j.model(this.definitions.type),j.error(this.definitions.error);for(let{method:Q,path:Y,handler:K,hooks:B}of Object.values(j.router.history))this.add(Q,Y,K,n(B,{error:j.event.error}));return j.compile(),j}if(typeof j==="function")return j(this);if(typeof j.default==="function")return j.default(this);return this._use(j)}).then((j)=>j.compile())),this;return J}const{name:W,seed:X}=$.config;$.getServer=()=>this.getServer(),$.getGlobalRoutes=()=>this.getGlobalRoutes(),$.model(this.definitions.type),$.error(this.definitions.error);const Z=$.config.scoped;if(Z){if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const j=X!==void 0?P0(W+JSON.stringify(X)):0;if(this.dependencies[W].some(({checksum:Q})=>j===Q))return this;this.dependencies[W].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:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q.subType==="derive").map((Q)=>({fn:Q.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q.subType==="derive").map((Q)=>({fn:Q.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const J=[];for(let j=0;j<$.extender.macros.length;j++){const Q=this.extender.macros[j];if(J.includes(Q.checksum))$.extender.macros.splice(j,1),j--;J.push(Q.checksum)}if($.onRequest((j)=>{Object.assign(j,this.singleton.decorator),Object.assign(j.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(Z===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let j of $.router.history)this.routeTree.set(j.method+`${$.config.prefix}${j.path}`,this.router.history.length),this.router.history.push({...j,path:`${$.config.prefix}${j.path}`,hooks:n(j.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let j of $.router.history)this.routeTree.set(j.method+`${$.config.prefix}${j.path}`,this.router.history.length),this.router.history.push({...j,path:`${$.config.prefix}${j.path}`,hooks:n(j.hooks,{error:this.event.error})})}return this}else{if(this.headers($.setHeaders),W){if(!(W in this.dependencies))this.dependencies[W]=[];const j=X!==void 0?P0(W+JSON.stringify(X)):0;if(!this.dependencies[W].some(({checksum:Q})=>j===Q))this.extender.macros=this.extender.macros.concat($.extender.macros),this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat($.extender.higherOrderFunctions)}else this.extender.macros=this.extender.macros.concat($.extender.macros),this.extender.higherOrderFunctions=this.extender.higherOrderFunctions.concat($.extender.higherOrderFunctions);Q1(this.extender.macros),Q1(this.extender.higherOrderFunctions);const J=[];for(let j=0;j<this.extender.higherOrderFunctions.length;j++){const Q=this.extender.higherOrderFunctions[j];if(Q.checksum){if(J.includes(Q.checksum))this.extender.higherOrderFunctions.splice(j,1),j--;J.push(Q.checksum)}}this.inference={body:this.inference.body||$.inference.body,cookie:this.inference.cookie||$.inference.cookie,headers:this.inference.headers||$.inference.headers,query:this.inference.query||$.inference.query,set:this.inference.set||$.inference.set,server:this.inference.server||$.inference.server}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error),$.extender.macros=this.extender.macros.concat($.extender.macros);for(let{method:J,path:j,handler:Q,hooks:Y}of Object.values($.router.history))this.add(J,j,Q,n(Y,{error:$.event.error}));if(!Z)if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const J=X!==void 0?P0(W+JSON.stringify(X)):0;if(this.dependencies[W].some(({checksum:j})=>J===j))return this;this.dependencies[W].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:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((j)=>j?.subType==="derive").map((j)=>({fn:j.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((j)=>j?.subType==="resolve").map((j)=>({fn:j.toString(),stack:new Error().stack??""}))}),this.event=V1(this.event,C1($.event),J)}else this.event=V1(this.event,C1($.event));return this.validator.global=n(this.validator.global,{...$.validator.global}),this.validator.local=n(this.validator.local,{...$.validator.scoped}),this}macro($){const W={checksum:P0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(W),this}mount($,W){if($ instanceof Q0||typeof $==="function"||$.length===0||$==="/"){const J=typeof $==="function"?$:$ instanceof Q0?$.compile().fetch:W instanceof Q0?W.compile().fetch:W,j=async({request:Q,path:Y})=>{if(Q.method==="GET"||Q.method==="HEAD"||!Q.headers.get("content-type"))return J(new Request(b0(Q.url,Y||"/"),Q));return J(new Request(b0(Q.url,Y||"/"),{...Q,body:await Q.arrayBuffer()}))};return this.all("/*",j,{type:"none"}),this}const X=$.length;if(W instanceof Q0)W=W.compile().fetch;const Z=async({request:J,path:j})=>{if(J.method==="GET"||J.method==="HEAD"||!J.headers.get("content-type"))return W(new Request(b0(J.url,j.slice(X)||"/"),J));return W(new Request(b0(J.url,j.slice(X)||"/"),{...J,body:await J.arrayBuffer()}))};return this.all($,Z,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),Z,{type:"none"}),this}get($,W,X){return this.add("GET",$,W,X),this}post($,W,X){return this.add("POST",$,W,X),this}put($,W,X){return this.add("PUT",$,W,X),this}patch($,W,X){return this.add("PATCH",$,W,X),this}delete($,W,X){return this.add("DELETE",$,W,X),this}options($,W,X){return this.add("OPTIONS",$,W,X),this}all($,W,X){return this.add("ALL",$,W,X),this}head($,W,X){return this.add("HEAD",$,W,X),this}connect($,W,X){return this.add("CONNECT",$,W,X),this}route($,W,X,Z){return this.add($.toUpperCase(),W,X,Z,Z?.config),this}ws($,W){const X=W.transformMessage?Array.isArray(W.transformMessage)?W.transformMessage:[W.transformMessage]:void 0;let Z=null;const J=d(W?.body,{models:this.definitions.type,normalize:this.config.normalize}),j=d(W?.response,{models:this.definitions.type,normalize:this.config.normalize}),Q=(Y)=>{if(typeof Y==="string"){const K=Y?.charCodeAt(0);if(K===47||K===123)try{Y=JSON.parse(Y)}catch{}else if(J1(Y))Y=+Y}if(X?.length)for(let K=0;K<X.length;K++){const B=X[K](Y);if(B!==void 0)Y=B}return Y};return this.route("$INTERNALWS",$,(Y)=>{const{set:K,path:B,qi:U,headers:w,query:F,params:G}=Y;if(Z===null)Z=this.getServer();if(Z?.upgrade(Y.request,{headers:typeof W.upgrade==="function"?W.upgrade(Y):W.upgrade,data:{validator:j,open(z){W.open?.(new f0(z,Y))},message:(z,D)=>{const M=Q(D);if(J?.Check(M)===!1)return void z.send(new T("message",J,M).message);W.message?.(new f0(z,Y),M)},drain(z){W.drain?.(new f0(z,Y))},close(z,D,M){W.close?.(new f0(z,Y),D,M)}}}))return;return K.status=400,"Expected a websocket connection"},{beforeHandle:W.beforeHandle,transform:W.transform,headers:W.headers,params:W.params,query:W.query}),this}state($,W,X){if(W===void 0)X=$,$={as:"append"},W="";else if(X===void 0){if(typeof $==="string")X=W,W=$,$={as:"append"};else if(typeof $==="object")X=W,W=""}const{as:Z}=$;if(typeof W!=="string")return this;switch(typeof X){case"object":if(W){if(W in this.singleton.store)this.singleton.store[W]=p(this.singleton.store[W],X,{override:Z==="override"});else this.singleton.store[W]=X;return this}if(X===null)return this;return this.singleton.store=p(this.singleton.store,X,{override:Z==="override"}),this;case"function":if(W){if(Z==="override"||!(W in this.singleton.store))this.singleton.store[W]=X}else this.singleton.store=X(this.singleton.store);return this;default:if(Z==="override"||!(W in this.singleton.store))this.singleton.store[W]=X;return this}}decorate($,W,X){if(W===void 0)X=$,$={as:"append"},W="";else if(X===void 0){if(typeof $==="string")X=W,W=$,$={as:"append"};else if(typeof $==="object")X=W,W=""}const{as:Z}=$;if(typeof W!=="string")return this;switch(typeof X){case"object":if(W){if(W in this.singleton.decorator)this.singleton.decorator[W]=p(this.singleton.decorator[W],X,{override:Z==="override"});else this.singleton.decorator[W]=X;return this}if(X===null)return this;return this.singleton.decorator=p(this.singleton.decorator,X,{override:Z==="override"}),this;case"function":if(W){if(Z==="override"||!(W in this.singleton.decorator))this.singleton.decorator[W]=X}else this.singleton.decorator=X(this.singleton.decorator);return this;default:if(Z==="override"||!(W in this.singleton.decorator))this.singleton.decorator[W]=X;return this}}derive($,W){if(!W)W=$,$={as:"local"};const X={subType:"derive",fn:W};return this.onTransform($,X)}model($,W){switch(typeof $){case"object":return Object.entries($).forEach(([X,Z])=>{if(!(X in this.definitions.type))this.definitions.type[X]=Z}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=W,this}mapDerive($,W){if(!W)W=$,$={as:"local"};const X={subType:"mapDerive",fn:W};return this.onTransform($,X)}affix($,W,X){if(X==="")return this;const Z=["_","-"," "],J=(K)=>K[0].toUpperCase()+K.slice(1),j=$==="prefix"?(K,B)=>Z.includes(K.at(-1)??"")?K+B:K+J(B):Z.includes(X.at(-1)??"")?(K,B)=>B+K:(K,B)=>B+J(K),Q=(K)=>{const B={};switch(K){case"decorator":for(let U in this.singleton.decorator)B[j(X,U)]=this.singleton.decorator[U];this.singleton.decorator=B;break;case"state":for(let U in this.singleton.store)B[j(X,U)]=this.singleton.store[U];this.singleton.store=B;break;case"model":for(let U in this.definitions.type)B[j(X,U)]=this.definitions.type[U];this.definitions.type=B;break;case"error":for(let U in this.definitions.error)B[j(X,U)]=this.definitions.error[U];this.definitions.error=B;break}},Y=Array.isArray(W)?W:[W];for(let K of Y.some((B)=>B==="all")?["decorator","state","model","error"]:Y)Q(K);return this}prefix($,W){return this.affix("prefix",$,W)}suffix($,W){return this.affix("suffix",$,W)}compile(){if(this.fetch=this.config.aot?b1(this):g1(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?b1(this):g1(this))($)};handleError=async($,W)=>(this.handleError=this.config.aot?x1(this):P2(this))($,W);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,W)=>{if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof $==="string"){if(!J1($))throw new Error("Port must be a numeric value");$=parseInt($)}const X=this.fetch,Z=typeof $==="object"?{development:!l0,reusePort:!0,...this.config.serve||{},...$||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...q1||{}},fetch:X,error:this.outerErrorHandler}:{development:!l0,reusePort:!0,...this.config.serve||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...q1||{}},port:$,fetch:X,error:this.outerErrorHandler};this.server=Bun?.serve(Z);for(let J=0;J<this.event.start.length;J++)this.event.start[J].fn(this);if(W)W(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let J=0;J<this.event.stop.length;J++)this.event.stop[J].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async($)=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop($),this.server=null,this.event.stop.length)for(let W=0;W<this.event.stop.length;W++)this.event.stop[W].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,b0 as replaceUrlPath,B2 as replaceSchemaType,c0 as redirect,x as mergeObjectArray,n as mergeHook,o as mapValueError,f as mapResponse,v as mapEarlyResponse,Z0 as mapCompactResponse,d as getSchemaValidator,W1 as getResponseSchemaValidator,N0 as form,T1 as error,Q0 as default,Q1 as deduplicateChecksum,d0 as cloneInference,P0 as checksum,T as ValidationError,z5 as TypeSystemPolicy,_0 as StatusMap,Y1 as ParseError,O0 as NotFoundError,Z1 as InvertedStatusMap,u0 as InvalidCookieSignature,G1 as InternalServerError,Q0 as Elysia,A0 as ERROR_CODE,n0 as ELYSIA_TRACE,c as ELYSIA_RESPONSE,I0 as ELYSIA_REQUEST_ID,A3 as ELYSIA_FORM_DATA,w0 as Cookie};
|
|
520
520
|
|
|
521
|
-
//# debugId=
|
|
521
|
+
//# debugId=CAC9075949F3890664756E2164756E21
|