elysia 1.1.20 → 1.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bun/index.js +2 -2
- package/dist/bun/index.js.map +3 -3
- package/dist/cjs/compose.js +21 -16
- package/dist/cjs/cookies.d.ts +2 -0
- package/dist/cjs/cookies.js +21 -16
- package/dist/cjs/dynamic-handle.js +21 -16
- package/dist/cjs/handler.js +21 -16
- package/dist/cjs/index.js +22 -17
- package/dist/cjs/types.d.ts +4 -3
- package/dist/compose.mjs +21 -16
- package/dist/cookies.d.ts +2 -0
- package/dist/cookies.mjs +21 -16
- package/dist/dynamic-handle.mjs +21 -16
- package/dist/handler.mjs +21 -16
- package/dist/index.mjs +22 -17
- package/dist/types.d.ts +4 -3
- package/package.json +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var L1=Object.create;var{getPrototypeOf:T1,defineProperty:k2,getOwnPropertyNames
|
|
|
4
4
|
* Copyright(c) 2012-2014 Roman Shtylman
|
|
5
5
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
6
6
|
* MIT Licensed
|
|
7
|
-
*/var z2=Q3,D2=Y3;var J3=Object.prototype.toString,a0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var X1=U2(o0(),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 W1=($,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))}})},e0=async($,W,{secrets:X,sign:Z,...j}={})=>{if(!W)return W1($,{},j);const J=typeof X==="string";if(Z&&Z!==!0&&!Array.isArray(Z))Z=[Z];const Y={},G=z2(W);for(let[K,B]of Object.entries(G)){let U=X1.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 P2(U,X);if(w===!1)throw new v0(K);U=w}else{let w=!0;for(let F=0;F<X.length;F++){const Q=await P2(U,X[F]);if(Q!==!1){w=!0,U=Q;break}}if(!w)throw new v0(K)}}Y[K]={value:U}}return W1($,Y,j)};async function*h0($){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 Z1="toJSON"in new Headers,c=($)=>{if(!$)return!1;for(let W in $)return!0;return!1},u0=($,W)=>{const X=$.size;if(!W&&X||X&&W&&W.status!==206&&W.status!==304&&W.status!==412&&W.status!==416){if(W&&c(W.headers)){if(W.headers instanceof Headers){if(Z1)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($)},j1=($,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 $},J1=($)=>{if(!$||!c($))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(D2(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 x(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 Y of $){if(J)break;if(Y===void 0||Y===null)continue;if(typeof Y==="object")try{j.enqueue(Buffer.from(JSON.stringify(Y)))}catch{j.enqueue(Buffer.from(Y.toString()))}else j.enqueue(Buffer.from(Y.toString()));await new Promise((G)=>setTimeout(()=>G(),0))}try{j.close()}catch{}}}),{...W,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...W?.headers}})},x=($,W,X)=>{if(c(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&&c(W.cookie)){const Z=J1(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=j1(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return u0($,W);case"Array":return Response.json($,W);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,x($.response,W,X);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 Z=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(Z)continue;Z=!0;for(let J of W.headers.getSetCookie())$.headers.append("set-cookie",J)}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(h0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((j)=>x(j,W));case"Function":return x($(),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 J of W.headers.keys())if(J==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(J,W.headers?.get(J)??"");else for(let J in W.headers)$.headers.append(J,W.headers[J]);if(Z1)W.headers=$.headers.toJSON();else for(let[J,Y]of $.headers.entries())if(J in W.headers)W.headers[J]=Y;return $}if($ instanceof Promise)return $.then((j)=>x(j,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,x($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return x($.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 u0($,W);case"Array":return Response.json($);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,x($.response,W,X);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(h0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((Z)=>{const j=Z0(Z,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((Z)=>x(Z,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,x($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return x($.toResponse(),W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},y=($,W,X)=>{if($===void 0||$===null)return;if(c(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&&c(W.cookie)){const Z=J1(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=j1(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return u0($,W);case"Array":return Response.json($,W);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,y($.response,W,X);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 Z=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(Z)continue;Z=!0;for(let J of W.headers.getSetCookie())$.headers.append("set-cookie",J)}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(h0($),W,X);return $;case"Promise":return $.then((j)=>{const J=y(j,W);if(J!==void 0)return J});case"Error":return K0($,W);case"Function":return y($(),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 J of W.headers.keys())if(J==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}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;return $}if($ instanceof Promise)return $.then((j)=>y(j,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,y($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return y($.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 u0($,W);case"Array":return Response.json($);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,y($.response,W,X);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(h0($));return $;case"Promise":return $.then((Z)=>{const j=y(Z,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((Z)=>y(Z,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,y($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return y($.toResponse(),W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},Z0=($,W)=>{switch($?.constructor?.name){case"String":return new Response($);case"Blob":return u0($);case"Array":return Response.json($);case"Object":return Response.json($);case"ElysiaCustomStatusResponse":return x($.response,{status:$.code,headers:{}});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(h0($));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($ instanceof p)return x($.response,{status:$.code,headers:{}});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}),Q1=($,W,X={})=>{if(typeof $==="function")return;const Z=x($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0)return Z.clone.bind(Z)},Y1=($,W,X={})=>{if(typeof $==="function"||$ instanceof Blob)return;const Z=x($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0){if(!Z.headers.has("content-type"))Z.headers.append("content-type","text/plain;charset=utf-8");return Z.clone.bind(Z)}};function A3($){let W=$;while(W.endsWith("="))W=W.slice(0,-1);return W}var R0=($,W)=>{const X=new URL($);return X.pathname=W,X.toString()},M3=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")&&$.toString()!=="[object Object]"||c(Object.getPrototypeOf($)),I2=($)=>$&&typeof $==="object"&&!Array.isArray($),d=($,W,{skipKeys:X,override:Z=!0}={})=>{if(!I2($)||!I2(W))return $;for(let[j,J]of Object.entries(W)){if(X?.includes(j))continue;if(!I2(J)||!(j in $)||M3(J)){if(Z||!(j in $))$[j]=J;continue}$[j]=d($[j],J,{skipKeys:X,override:Z})}return $},z3=($,W)=>{const{properties:X,...Z}=$??{},{properties:j,...J}=W??{};return d(Z,J)},f=($=[],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},D3=["start","request","parse","transform","resolve","beforeHandle","afterHandle","mapResponse","afterResponse","trace","error","stop","body","headers","params","query","response","type","detail"],N3=D3.reduce(($,W)=>($[W]=!0,$),{}),U1=($,W)=>{const X=(Z)=>typeof Z==="object"&&Object.keys(Z).every(Z2);if(X($)&&X(W))return{...$,...W};else if($&&!X($)&&X(W))return{200:$,...W};return W??$},b0=($,W)=>{return{body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:U1($?.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:U1($?.response,W?.response),type:$?.type||W?.type,detail:d(W?.detail??{},$?.detail??{}),parse:f($?.parse,W?.parse),transform:f($?.transform,W?.transform),beforeHandle:f($?.beforeHandle,W?.beforeHandle),afterHandle:f($?.afterHandle,W?.afterHandle),mapResponse:f($?.mapResponse,W?.mapResponse),afterResponse:f($?.afterResponse,W?.afterResponse),trace:f($?.trace,W?.trace),error:f($?.error,W?.error)}},V2=($,W,X=!0)=>{if(!Array.isArray(W))return h($,W,X);for(let Z of W)$=h($,Z,X);return $},h=($,W,X=!0)=>{if(!$)return $;if(W.untilObjectFound&&!X&&$.type==="object")return $;const Z=W.from[H0];if($.oneOf){for(let Y=0;Y<$.oneOf.length;Y++)$.oneOf[Y]=h($.oneOf[Y],W,X);return $}if($.anyOf){for(let Y=0;Y<$.anyOf.length;Y++)$.anyOf[Y]=h($.anyOf[Y],W,X);return $}if($.allOf){for(let Y=0;Y<$.allOf.length;Y++)$.allOf[Y]=h($.allOf[Y],W,X);return $}if($.not){for(let Y=0;Y<$.not.length;Y++)$.not[Y]=h($.not[Y],W,X);return $}const j=X&&!!W.excludeRoot;if($[H0]===Z){const{anyOf:Y,oneOf:G,allOf:K,not:B,properties:U,items:w,...F}=$,Q=W.to(F);let z;const D=(M)=>{if(U&&M.type==="object"){const O={};for(let[P,b]of Object.entries(U))O[P]=h(b,W,!1);return{...F,...M,properties:O}}if(w&&M.type==="array")return{...F,...M,items:h(w,W,!1)};const I={...F,...M};if(delete I.required,U&&M.type==="string"&&M.format==="ObjectString"&&M.default==="{}")z=V.ObjectString(U,F),I.default=JSON.stringify(l.Create(V.Object(U))),I.properties=U;if(w&&M.type==="string"&&M.format==="ArrayString"&&M.default==="[]")z=V.ArrayString(w,F),I.default=JSON.stringify(l.Create(V.Array(w))),I.items=w;return I};if(j){if(U){const M={};for(let[I,O]of Object.entries(U))M[I]=h(O,W,!1);return{...F,properties:M}}else if(w?.map)return{...F,items:w.map((M)=>h(M,W,!1))};return F}if(Q.anyOf)for(let M=0;M<Q.anyOf.length;M++)Q.anyOf[M]=D(Q.anyOf[M]);else if(Q.oneOf)for(let M=0;M<Q.oneOf.length;M++)Q.oneOf[M]=D(Q.oneOf[M]);else if(Q.allOf)for(let M=0;M<Q.allOf.length;M++)Q.allOf[M]=D(Q.allOf[M]);else if(Q.not)for(let M=0;M<Q.not.length;M++)Q.not[M]=D(Q.not[M]);if(z)Q[G1]=z[G1];if(Q.anyOf||Q.oneOf||Q.allOf||Q.not)return Q;if(U){const M={};for(let[I,O]of Object.entries(U))M[I]=h(O,W,!1);return{...F,...Q,properties:M}}else if(w?.map)return{...F,...Q,items:w.map((M)=>h(M,W,!1))};return{...F,...Q}}const J=$?.properties;if(J&&X&&W.rootOnly!==!0)for(let[Y,G]of Object.entries(J))switch(G[H0]){case Z:const{anyOf:K,oneOf:B,allOf:U,not:w,type:F,...Q}=G,z=W.to(Q);if(z.anyOf)for(let D=0;D<z.anyOf.length;D++)z.anyOf[D]={...Q,...z.anyOf[D]};else if(z.oneOf)for(let D=0;D<z.oneOf.length;D++)z.oneOf[D]={...Q,...z.oneOf[D]};else if(z.allOf)for(let D=0;D<z.allOf.length;D++)z.allOf[D]={...Q,...z.allOf[D]};else if(z.not)for(let D=0;D<z.not.length;D++)z.not[D]={...Q,...z.not[D]};J[Y]={...Q,...h(Q,W,!1)};break;case"Object":case"Union":J[Y]=h(G,W,!1);break;default:if(G.items)for(let D=0;D<G.items.length;D++)G.items[D]=h(G.items[D],W,!1);else if(G.anyOf||G.oneOf||G.allOf||G.not)J[Y]=h(G,W,!1);break}return $},m=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:j=!1,coerce:J=!1,additionalCoerce:Y=[]}={})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;let G=typeof $==="string"?W[$]:$;if(J||Y)if(J)G=V2(G,[{from:V.Number(),to:(U)=>V.Numeric(U),untilObjectFound:!0},{from:V.Boolean(),to:(U)=>V.BooleanString(U),untilObjectFound:!0},...Array.isArray(Y)?Y:[Y]]);else G=V2(G,[...Array.isArray(Y)?Y:[Y]]);if(G.type==="object"&&"additionalProperties"in G===!1)G.additionalProperties=j;const K=(U)=>l.Clean(G,U);if(X){const U={schema:G,references:"",checkFunc:()=>{},code:"",Check:(w)=>l.Check(G,w),Errors:(w)=>l.Errors(G,w),Code:()=>"",Clean:K,Decode:(w)=>l.Decode(G,w),Encode:(w)=>l.Encode(G,w)};if(Z&&G.additionalProperties===!1)U.Clean=K;if(G.config){if(U.config=G.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 Q=[...B.Errors(w)].map(o);return{success:!1,data:null,error:Q[0]?.summary,errors:Q}}},U}const B=K1.Compile(G,Object.values(W));if(B.Clean=K,G.config){if(B.config=G.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},$2=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:j=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const J=typeof $==="string"?W[$]:$,Y=(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=K1.Compile(K,B);if(Z&&K.additionalProperties===!1)w.Clean=U;return w};if(H0 in J){if("additionalProperties"in J===!1)J.additionalProperties=j;return{200:Y(J,Object.values(W))}}const G={};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,G[+K]=H0 in U?Y(U,Object.values(W)):U}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=j;G[+K]=H0 in B?Y(B,Object.values(W)):B}),G},P3=typeof Bun!=="undefined",I3=P3&&typeof Bun.hash==="function",N0=($)=>{if(I3)return Bun.hash($);let W=9;for(let X=0;X<$.length;)W=Math.imul(W^$.charCodeAt(X++),387420489);return W=W^W>>>9},A2,D0=()=>{if(!A2)A2=[{from:V.Object({}),to:()=>V.ObjectString({}),excludeRoot:!0},{from:V.Array(V.Any()),to:()=>V.ArrayString(V.Any())}];return A2},O2,S2=()=>{if(!O2)O2=[{from:V.Number(),to:($)=>V.Numeric($),rootOnly:!0},{from:V.Boolean(),to:($)=>V.BooleanString($),rootOnly:!0}];return O2},W2=({validator:$,defaultConfig:W={},config:X,dynamic:Z,models:j})=>{let J=m($,{dynamic:Z,models:j,additionalProperties:!0,coerce:!0,additionalCoerce:D0()});if(c(W))if(J)J.config=z3(J.config,X);else J=m(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},C2=($,W,X)=>{return{start:f($.start,j0(X,W?.start)),request:f($.request,j0(X,W?.request)),parse:f($.parse,j0(X,W?.parse)),transform:f($.transform,j0(X,W?.transform)),beforeHandle:f($.beforeHandle,j0(X,W?.beforeHandle)),afterHandle:f($.afterHandle,j0(X,W?.afterHandle)),mapResponse:f($.mapResponse,j0(X,W?.mapResponse)),afterResponse:f($.afterResponse,j0(X,W?.afterResponse)),trace:f($.trace,j0(X,W?.trace)),error:f($.error,j0(X,W?.error)),stop:f($.stop,j0(X,W?.stop))}},w1=($,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},L2=($)=>{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},X2=Object.fromEntries(Object.entries(_0).map(([$,W])=>[W,$])),B1=new TextEncoder,x0=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",B1.encode(W),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,B1.encode($));return $+"."+A3(Buffer.from(Z).toString("base64"))},P2=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 x0(X,W)===$?X:!1},_1=($,W)=>{if(!$||typeof $!=="object"||!W)return;for(let[X,Z]of Object.entries(W)){if(X in N3||!(X in $))continue;const j=$[X];if(typeof j==="function")j(Z),delete W[X]}},F1=({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:Y="local"}=Z;if(typeof j==="function")j={fn:j};if(Y==="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)}},O3=($)=>{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},Z2=($)=>O3($)!==null;class T2{$;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 n=($)=>{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},M1=($)=>{return{...$,start:n($?.start),request:n($?.request),parse:n($?.parse),transform:n($?.transform),beforeHandle:n($?.beforeHandle),afterHandle:n($?.afterHandle),mapResponse:n($?.mapResponse),afterResponse:n($?.afterResponse),trace:n($?.trace),error:n($?.error),stop:n($?.stop)}},E2=($)=>{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)}},m0=($)=>({body:$.body,cookie:$.cookie,headers:$.headers,query:$.query,set:$.set,server:$.server}),d0=($,W=302)=>Response.redirect($,W),V3=Symbol("ElysiaFormData"),P0=Symbol("ElysiaRequestId"),S3=($)=>{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},j2=()=>crypto.getRandomValues(new Uint32Array(1))[0],J2=($)=>{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 $},v=($,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 z1=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,I0=Symbol("ElysiaErrorCode"),p0=(z1?.NODE_ENV??z1?.ENV)==="production";class p{code;response;constructor($,W){const X=W??($ in X2?X2[$]:$);this.code=_0[$]??$,this.response=X}}var q2=($,W)=>new p($,W);class Q2 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class A0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class Y2 extends Error{code="PARSE";status=400;constructor(){super("Failed to parse body")}}class v0 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("/","."),Y=X==="";switch(j){case 42:return{...$,summary:Y?"Value should not be provided":`Property '${J}' should not be provided`};case 45:return{...$,summary:Y?"Value is missing":`Property '${J}' is missing`};case 50:const G=W.indexOf("'"),K=W.slice(G+1,W.indexOf("'",G+1));return{...$,summary:Y?"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:Y?`Value should be one of ${B}`:`Property '${J}' should be one of: ${B}`};default:return{summary:W,...$}}};class q extends Error{$;W;X;code="VALIDATION";status=422;constructor($,W,X){if(X&&typeof X==="object"&&X instanceof p)X=X.response;const Z=p0?void 0:("Errors"in W)?W.Errors(X).First():c0.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 Y="";if(j!==void 0)Y=typeof j==="object"?JSON.stringify(j):j+"";else if(p0)Y=JSON.stringify({type:"validation",on:$,summary:o(Z).summary,message:Z?.message,found:X});else{const G=W?.schema??W,K="Errors"in W?[...W.Errors(X)].map(o):[...c0.Errors(W,X)].map(o);let B;try{B=c0.Create(G)}catch(U){B={type:"Could not create expected value",message:U?.message,error:U}}Y=JSON.stringify({type:"validation",on:$,summary:K[0]?.summary,property:J,message:Z?.message,expected:B,found:X,errors:K},null,2)}super(Y);this.type=$;this.validator=W;this.value=X;Object.setPrototypeOf(this,q.prototype)}get all(){return"Errors"in this.validator?[...this.validator.Errors(this.value)].map(o):[...c0.Errors(this.validator,this.value)].map(o)}static simplifyModel($){const W="schema"in $?$.schema:$;try{return c0.Create(W)}catch{return W}}get model(){return q.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var H2={open($){$.data.open?.($)},message($,W){$.data.message?.($,W)},drain($){$.data.drain?.($)},close($,W,X){$.data.close?.($,W,X)}};class g0{$;W;validator;_validator;constructor($,W){this.raw=$;this.data=W;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else this.id=j2().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 q("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 q("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var R2="1.1.20";import{Value as n0}from"@sinclair/typebox/value";import{TypeBoxError as L3}from"@sinclair/typebox";var O0=U2(o0(),1);function G2($){const W={};if(typeof $!=="string")return W;let X="",Z="",j=-1,J=-1,Y=0;const G=$.length;for(let K=0;K<G;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(Y&1)X=X.replace(f0," ");if(Y&2)X=O0.default(X)||X;if(!W[X]){if(B){if(Z=$.slice(J+1,K),Y&4)Z=Z.replace(f0," ");if(Y&8)Z=O0.default(Z)||Z}W[X]=Z}}X="",Z="",j=K,J=K,Y=0;break;case 61:if(J<=j)J=K;else Y|=8;break;case 43:if(J>j)Y|=4;else Y|=1;break;case 37:if(J>j)Y|=8;else Y|=2;break}if(j<G){const K=J>j;if(X=$.slice(j+1,K?J:G),K||X.length>0){if(Y&1)X=X.replace(f0," ");if(Y&2)X=O0.default(X)||X;if(!W[X]){if(K){if(Z=$.slice(J+1,G),Y&4)Z=Z.replace(f0," ");if(Y&8)Z=O0.default(Z)||Z}W[X]=Z}}}return W}var f0=/\+/g,l0=($)=>{const W={};if(typeof $!=="string")return W;const X=$.length;let Z="",j="",J=-1,Y=-1,G=!1,K=!1,B=!1,U=!1,w=!1,F=0;for(let Q=0;Q<X+1;Q++){if(Q!==X)F=$.charCodeAt(Q);else F=38;switch(F){case 38:{if(w=Y>J,!w)Y=Q;if(Z=$.slice(J+1,Y),w||Z.length>0){if(B)Z=Z.replace(f0," ");if(G)Z=O0.default(Z)||Z;if(w){if(j=$.slice(Y+1,Q),U)j=j.replace(f0," ");if(K)j=O0.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=Q,Y=Q,G=!1,K=!1,B=!1,U=!1;break}case 61:if(Y<=J)Y=Q;else K=!0;break;case 43:if(Y>J)U=!0;else B=!0;break;case 37:if(Y>J)K=!0;else G=!0;break}}return W};var N1=U2(o0(),1);var i0=Symbol("ElysiaTrace"),F0=()=>{const{promise:$,resolve:W}=Promise.withResolvers(),{promise:X,resolve:Z}=Promise.withResolvers(),{promise:j,resolve:J}=Promise.withResolvers(),Y=[],G=[];return[(K)=>{if(K)Y.push(K);return $},(K)=>{const B=[],U=[];let w=null;for(let Q=0;Q<(K.total??0);Q++){const{promise:z,resolve:D}=Promise.withResolvers(),{promise:M,resolve:I}=Promise.withResolvers(),{promise:O,resolve:P}=Promise.withResolvers(),b=[],T=[];B.push((E)=>{if(E)b.push(E);return z}),U.push((E)=>{const r={...E,end:M,error:O,index:Q,onStop(L){if(L)T.push(L);return M}};D(r);for(let L=0;L<b.length;L++)b[L](r);return(L=null)=>{const g=performance.now();if(L)w=L;const R={end:g,error:L,get elapsed(){return g-E.begin}};for(let Y0=0;Y0<T.length;Y0++)T[Y0](R);I(g),P(L)}})}const F={...K,end:X,error:j,onEvent(Q){for(let z=0;z<B.length;z++)B[z](Q)},onStop(Q){if(Q)G.push(Q);return X}};W(F);for(let Q=0;Q<Y.length;Q++)Y[Q](F);return{resolveChild:U,resolve(Q=null){const z=performance.now();if(!Q&&w)Q=w;const D={end:z,error:Q,get elapsed(){return z-K.begin}};for(let M=0;M<G.length;M++)G[M](D);Z(z),J(Q)}}}]},D1=($)=>{return(W)=>{const[X,Z]=F0(),[j,J]=F0(),[Y,G]=F0(),[K,B]=F0(),[U,w]=F0(),[F,Q]=F0(),[z,D]=F0(),[M,I]=F0(),[O,P]=F0();return $({id:W[P0],context:W,set:W.set,onRequest:X,onParse:j,onTransform:Y,onBeforeHandle:K,onHandle:U,onAfterHandle:F,onMapResponse:M,onAfterResponse:O,onError:z}),{request:Z,parse:J,transform:G,beforeHandle:B,handle:w,afterHandle:Q,error:D,mapResponse:I,afterResponse:P}}};var T3=new Headers().toJSON,P1={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},t=($)=>{if(!$)return!1;const W=$?.schema;return!!W&&P1.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},x2=({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 Y=Z==="error"?"reportErr":"report";for(let G=0;G<W.length;G++)X(`\n${Y}${G} = trace${G}.${Z}({id,event: '${Z}',name: '${j}',begin: performance.now(),total: ${J}})\n`);return{resolve(){for(let G=0;G<W.length;G++)X(`\n${Y}${G}.resolve()\n`)},resolveChild(G){for(let K=0;K<W.length;K++)X(`${Y}Child${K} = ${Y}${K}.resolveChild?.shift()?.({id,event: '${Z}',name: '${G}',begin: performance.now()})\n`);return(K)=>{for(let B=0;B<W.length;B++)if(K)X(`
|
|
7
|
+
*/var z2=Q3,D2=Y3;var J3=Object.prototype.toString,a0=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var X1=U2(o0(),1);class w0{$;W;X;constructor($,W,X={}){this.name=$;this.jar=W;this.initial=X}get cookie(){return this.jar[this.name]??this.initial}set cookie($){if(!(this.name in this.jar))this.jar[this.name]=this.initial;this.jar[this.name]=$}get setCookie(){if(!(this.name in this.jar))this.jar[this.name]=this.initial;return this.jar[this.name]}set setCookie($){this.cookie=$}get value(){return this.cookie.value}set value($){this.setCookie.value=$}get expires(){return this.cookie.expires}set expires($){this.setCookie.expires=$}get maxAge(){return this.cookie.maxAge}set maxAge($){this.setCookie.maxAge=$}get domain(){return this.cookie.domain}set domain($){this.setCookie.domain=$}get path(){return this.cookie.path}set path($){this.setCookie.path=$}get secure(){return this.cookie.secure}set secure($){this.setCookie.secure=$}get httpOnly(){return this.cookie.httpOnly}set httpOnly($){this.setCookie.httpOnly=$}get sameSite(){return this.cookie.sameSite}set sameSite($){this.setCookie.sameSite=$}get priority(){return this.cookie.priority}set priority($){this.setCookie.priority=$}get partitioned(){return this.cookie.partitioned}set partitioned($){this.setCookie.partitioned=$}get secrets(){return this.cookie.secrets}set secrets($){this.setCookie.secrets=$}update($){return this.setCookie=Object.assign(this.cookie,typeof $==="function"?$(this.cookie):$),this}set($){return this.setCookie=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 W1=($,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))}})},e0=async($,W,{secrets:X,sign:Z,...j}={})=>{if(!W)return W1($,{},j);const J=typeof X==="string";if(Z&&Z!==!0&&!Array.isArray(Z))Z=[Z];const Y={},G=z2(W);for(let[K,B]of Object.entries(G)){let U=X1.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 P2(U,X);if(w===!1)throw new v0(K);U=w}else{let w=!0;for(let F=0;F<X.length;F++){const Q=await P2(U,X[F]);if(Q!==!1){w=!0,U=Q;break}}if(!w)throw new v0(K)}}Y[K]={value:U}}return W1($,Y,j)};async function*h0($){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 Z1="toJSON"in new Headers,c=($)=>{if(!$)return!1;for(let W in $)return!0;return!1},u0=($,W)=>{const X=$.size;if(!W&&X||X&&W&&W.status!==206&&W.status!==304&&W.status!==412&&W.status!==416){if(W&&c(W.headers)){if(W.headers instanceof Headers){if(Z1)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($)},j1=($,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 $},J1=($)=>{if(!$||!c($))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(D2(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 x(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 Y of $){if(J)break;if(Y===void 0||Y===null)continue;if(typeof Y==="object")try{j.enqueue(Buffer.from(JSON.stringify(Y)))}catch{j.enqueue(Buffer.from(Y.toString()))}else j.enqueue(Buffer.from(Y.toString()));await new Promise((G)=>setTimeout(()=>G(),0))}try{j.close()}catch{}}}),{...W,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...W?.headers}})},x=($,W,X)=>{if(c(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&&c(W.cookie)){const Z=J1(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=j1(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return u0($,W);case"Array":return Response.json($,W);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,x($.response,W,X);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 Z=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(Z)continue;Z=!0;for(let J of W.headers.getSetCookie())$.headers.append("set-cookie",J)}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(h0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((j)=>x(j,W));case"Function":return x($(),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 J of W.headers.keys())if(J==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}else $.headers.append(J,W.headers?.get(J)??"");else for(let J in W.headers)$.headers.append(J,W.headers[J]);if(Z1)W.headers=$.headers.toJSON();else for(let[J,Y]of $.headers.entries())if(J in W.headers)W.headers[J]=Y;return $}if($ instanceof Promise)return $.then((j)=>x(j,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,x($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return x($.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 u0($,W);case"Array":return Response.json($);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,x($.response,W,X);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(h0($),W,X);return $;case"Error":return K0($,W);case"Promise":return $.then((Z)=>{const j=Z0(Z,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((Z)=>x(Z,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,x($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return x($.toResponse(),W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},y=($,W,X)=>{if($===void 0||$===null)return;if(c(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&&c(W.cookie)){const Z=J1(W.cookie);if(Z)W.headers["set-cookie"]=Z}if(W.headers["set-cookie"]&&Array.isArray(W.headers["set-cookie"]))W.headers=j1(new Headers(W.headers),W.headers["set-cookie"]);switch($?.constructor?.name){case"String":return new Response($,W);case"Blob":return u0($,W);case"Array":return Response.json($,W);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,y($.response,W,X);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 Z=!1;if(W.headers instanceof Headers)for(let j of W.headers.keys())if(j==="set-cookie"){if(Z)continue;Z=!0;for(let J of W.headers.getSetCookie())$.headers.append("set-cookie",J)}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(h0($),W,X);return $;case"Promise":return $.then((j)=>{const J=y(j,W);if(J!==void 0)return J});case"Error":return K0($,W);case"Function":return y($(),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 J of W.headers.keys())if(J==="set-cookie"){if(j)continue;j=!0;for(let Y of W.headers.getSetCookie())$.headers.append("set-cookie",Y)}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;return $}if($ instanceof Promise)return $.then((j)=>y(j,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,y($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return y($.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 u0($,W);case"Array":return Response.json($);case"Object":return Response.json($,W);case"ElysiaCustomStatusResponse":return W.status=$.code,y($.response,W,X);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(h0($));return $;case"Promise":return $.then((Z)=>{const j=y(Z,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((Z)=>y(Z,W));if($ instanceof Error)return K0($,W);if($ instanceof p)return W.status=$.code,y($.response,W,X);if(typeof $?.next==="function")return B0($,W,X);if("toResponse"in $)return y($.toResponse(),W);if("charCodeAt"in $){const Z=$.charCodeAt(0);if(Z===123||Z===91){if(!W.headers["Content-Type"])W.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),W)}}return new Response($)}},Z0=($,W)=>{switch($?.constructor?.name){case"String":return new Response($);case"Blob":return u0($);case"Array":return Response.json($);case"Object":return Response.json($);case"ElysiaCustomStatusResponse":return x($.response,{status:$.code,headers:{}});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(h0($));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($ instanceof p)return x($.response,{status:$.code,headers:{}});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}),Q1=($,W,X={})=>{if(typeof $==="function")return;const Z=x($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0)return Z.clone.bind(Z)},Y1=($,W,X={})=>{if(typeof $==="function"||$ instanceof Blob)return;const Z=x($,{headers:X});if(W.parse.length===0&&W.transform.length===0&&W.beforeHandle.length===0&&W.afterHandle.length===0){if(!Z.headers.has("content-type"))Z.headers.append("content-type","text/plain;charset=utf-8");return Z.clone.bind(Z)}};function A3($){let W=$;while(W.endsWith("="))W=W.slice(0,-1);return W}var R0=($,W)=>{const X=new URL($);return X.pathname=W,X.toString()},M3=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")&&$.toString()!=="[object Object]"||c(Object.getPrototypeOf($)),I2=($)=>$&&typeof $==="object"&&!Array.isArray($),d=($,W,{skipKeys:X,override:Z=!0}={})=>{if(!I2($)||!I2(W))return $;for(let[j,J]of Object.entries(W)){if(X?.includes(j))continue;if(!I2(J)||!(j in $)||M3(J)){if(Z||!(j in $))$[j]=J;continue}$[j]=d($[j],J,{skipKeys:X,override:Z})}return $},z3=($,W)=>{const{properties:X,...Z}=$??{},{properties:j,...J}=W??{};return d(Z,J)},f=($=[],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},D3=["start","request","parse","transform","resolve","beforeHandle","afterHandle","mapResponse","afterResponse","trace","error","stop","body","headers","params","query","response","type","detail"],N3=D3.reduce(($,W)=>($[W]=!0,$),{}),U1=($,W)=>{const X=(Z)=>typeof Z==="object"&&Object.keys(Z).every(Z2);if(X($)&&X(W))return{...$,...W};else if($&&!X($)&&X(W))return{200:$,...W};return W??$},b0=($,W)=>{return{body:W?.body??$?.body,headers:W?.headers??$?.headers,params:W?.params??$?.params,query:W?.query??$?.query,cookie:W?.cookie??$?.cookie,response:U1($?.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:U1($?.response,W?.response),type:$?.type||W?.type,detail:d(W?.detail??{},$?.detail??{}),parse:f($?.parse,W?.parse),transform:f($?.transform,W?.transform),beforeHandle:f($?.beforeHandle,W?.beforeHandle),afterHandle:f($?.afterHandle,W?.afterHandle),mapResponse:f($?.mapResponse,W?.mapResponse),afterResponse:f($?.afterResponse,W?.afterResponse),trace:f($?.trace,W?.trace),error:f($?.error,W?.error)}},V2=($,W,X=!0)=>{if(!Array.isArray(W))return h($,W,X);for(let Z of W)$=h($,Z,X);return $},h=($,W,X=!0)=>{if(!$)return $;if(W.untilObjectFound&&!X&&$.type==="object")return $;const Z=W.from[H0];if($.oneOf){for(let Y=0;Y<$.oneOf.length;Y++)$.oneOf[Y]=h($.oneOf[Y],W,X);return $}if($.anyOf){for(let Y=0;Y<$.anyOf.length;Y++)$.anyOf[Y]=h($.anyOf[Y],W,X);return $}if($.allOf){for(let Y=0;Y<$.allOf.length;Y++)$.allOf[Y]=h($.allOf[Y],W,X);return $}if($.not){for(let Y=0;Y<$.not.length;Y++)$.not[Y]=h($.not[Y],W,X);return $}const j=X&&!!W.excludeRoot;if($[H0]===Z){const{anyOf:Y,oneOf:G,allOf:K,not:B,properties:U,items:w,...F}=$,Q=W.to(F);let z;const D=(M)=>{if(U&&M.type==="object"){const O={};for(let[P,b]of Object.entries(U))O[P]=h(b,W,!1);return{...F,...M,properties:O}}if(w&&M.type==="array")return{...F,...M,items:h(w,W,!1)};const I={...F,...M};if(delete I.required,U&&M.type==="string"&&M.format==="ObjectString"&&M.default==="{}")z=V.ObjectString(U,F),I.default=JSON.stringify(l.Create(V.Object(U))),I.properties=U;if(w&&M.type==="string"&&M.format==="ArrayString"&&M.default==="[]")z=V.ArrayString(w,F),I.default=JSON.stringify(l.Create(V.Array(w))),I.items=w;return I};if(j){if(U){const M={};for(let[I,O]of Object.entries(U))M[I]=h(O,W,!1);return{...F,properties:M}}else if(w?.map)return{...F,items:w.map((M)=>h(M,W,!1))};return F}if(Q.anyOf)for(let M=0;M<Q.anyOf.length;M++)Q.anyOf[M]=D(Q.anyOf[M]);else if(Q.oneOf)for(let M=0;M<Q.oneOf.length;M++)Q.oneOf[M]=D(Q.oneOf[M]);else if(Q.allOf)for(let M=0;M<Q.allOf.length;M++)Q.allOf[M]=D(Q.allOf[M]);else if(Q.not)for(let M=0;M<Q.not.length;M++)Q.not[M]=D(Q.not[M]);if(z)Q[G1]=z[G1];if(Q.anyOf||Q.oneOf||Q.allOf||Q.not)return Q;if(U){const M={};for(let[I,O]of Object.entries(U))M[I]=h(O,W,!1);return{...F,...Q,properties:M}}else if(w?.map)return{...F,...Q,items:w.map((M)=>h(M,W,!1))};return{...F,...Q}}const J=$?.properties;if(J&&X&&W.rootOnly!==!0)for(let[Y,G]of Object.entries(J))switch(G[H0]){case Z:const{anyOf:K,oneOf:B,allOf:U,not:w,type:F,...Q}=G,z=W.to(Q);if(z.anyOf)for(let D=0;D<z.anyOf.length;D++)z.anyOf[D]={...Q,...z.anyOf[D]};else if(z.oneOf)for(let D=0;D<z.oneOf.length;D++)z.oneOf[D]={...Q,...z.oneOf[D]};else if(z.allOf)for(let D=0;D<z.allOf.length;D++)z.allOf[D]={...Q,...z.allOf[D]};else if(z.not)for(let D=0;D<z.not.length;D++)z.not[D]={...Q,...z.not[D]};J[Y]={...Q,...h(Q,W,!1)};break;case"Object":case"Union":J[Y]=h(G,W,!1);break;default:if(G.items)for(let D=0;D<G.items.length;D++)G.items[D]=h(G.items[D],W,!1);else if(G.anyOf||G.oneOf||G.allOf||G.not)J[Y]=h(G,W,!1);break}return $},m=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:j=!1,coerce:J=!1,additionalCoerce:Y=[]}={})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;let G=typeof $==="string"?W[$]:$;if(J||Y)if(J)G=V2(G,[{from:V.Number(),to:(U)=>V.Numeric(U),untilObjectFound:!0},{from:V.Boolean(),to:(U)=>V.BooleanString(U),untilObjectFound:!0},...Array.isArray(Y)?Y:[Y]]);else G=V2(G,[...Array.isArray(Y)?Y:[Y]]);if(G.type==="object"&&"additionalProperties"in G===!1)G.additionalProperties=j;const K=(U)=>l.Clean(G,U);if(X){const U={schema:G,references:"",checkFunc:()=>{},code:"",Check:(w)=>l.Check(G,w),Errors:(w)=>l.Errors(G,w),Code:()=>"",Clean:K,Decode:(w)=>l.Decode(G,w),Encode:(w)=>l.Encode(G,w)};if(Z&&G.additionalProperties===!1)U.Clean=K;if(G.config){if(U.config=G.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 Q=[...B.Errors(w)].map(o);return{success:!1,data:null,error:Q[0]?.summary,errors:Q}}},U}const B=K1.Compile(G,Object.values(W));if(B.Clean=K,G.config){if(B.config=G.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},$2=($,{models:W={},dynamic:X=!1,normalize:Z=!1,additionalProperties:j=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in W))return;const J=typeof $==="string"?W[$]:$,Y=(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=K1.Compile(K,B);if(Z&&K.additionalProperties===!1)w.Clean=U;return w};if(H0 in J){if("additionalProperties"in J===!1)J.additionalProperties=j;return{200:Y(J,Object.values(W))}}const G={};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,G[+K]=H0 in U?Y(U,Object.values(W)):U}return}if(B.type==="object"&&"additionalProperties"in B===!1)B.additionalProperties=j;G[+K]=H0 in B?Y(B,Object.values(W)):B}),G},P3=typeof Bun!=="undefined",I3=P3&&typeof Bun.hash==="function",N0=($)=>{if(I3)return Bun.hash($);let W=9;for(let X=0;X<$.length;)W=Math.imul(W^$.charCodeAt(X++),387420489);return W=W^W>>>9},A2,D0=()=>{if(!A2)A2=[{from:V.Object({}),to:()=>V.ObjectString({}),excludeRoot:!0},{from:V.Array(V.Any()),to:()=>V.ArrayString(V.Any())}];return A2},O2,S2=()=>{if(!O2)O2=[{from:V.Number(),to:($)=>V.Numeric($),rootOnly:!0},{from:V.Boolean(),to:($)=>V.BooleanString($),rootOnly:!0}];return O2},W2=({validator:$,defaultConfig:W={},config:X,dynamic:Z,models:j})=>{let J=m($,{dynamic:Z,models:j,additionalProperties:!0,coerce:!0,additionalCoerce:D0()});if(c(W))if(J)J.config=z3(J.config,X);else J=m(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},C2=($,W,X)=>{return{start:f($.start,j0(X,W?.start)),request:f($.request,j0(X,W?.request)),parse:f($.parse,j0(X,W?.parse)),transform:f($.transform,j0(X,W?.transform)),beforeHandle:f($.beforeHandle,j0(X,W?.beforeHandle)),afterHandle:f($.afterHandle,j0(X,W?.afterHandle)),mapResponse:f($.mapResponse,j0(X,W?.mapResponse)),afterResponse:f($.afterResponse,j0(X,W?.afterResponse)),trace:f($.trace,j0(X,W?.trace)),error:f($.error,j0(X,W?.error)),stop:f($.stop,j0(X,W?.stop))}},w1=($,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},L2=($)=>{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},X2=Object.fromEntries(Object.entries(_0).map(([$,W])=>[W,$])),B1=new TextEncoder,x0=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",B1.encode(W),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,B1.encode($));return $+"."+A3(Buffer.from(Z).toString("base64"))},P2=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 x0(X,W)===$?X:!1},_1=($,W)=>{if(!$||typeof $!=="object"||!W)return;for(let[X,Z]of Object.entries(W)){if(X in N3||!(X in $))continue;const j=$[X];if(typeof j==="function")j(Z),delete W[X]}},F1=({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:Y="local"}=Z;if(typeof j==="function")j={fn:j};if(Y==="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)}},O3=($)=>{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},Z2=($)=>O3($)!==null;class T2{$;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 n=($)=>{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},M1=($)=>{return{...$,start:n($?.start),request:n($?.request),parse:n($?.parse),transform:n($?.transform),beforeHandle:n($?.beforeHandle),afterHandle:n($?.afterHandle),mapResponse:n($?.mapResponse),afterResponse:n($?.afterResponse),trace:n($?.trace),error:n($?.error),stop:n($?.stop)}},E2=($)=>{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)}},m0=($)=>({body:$.body,cookie:$.cookie,headers:$.headers,query:$.query,set:$.set,server:$.server}),d0=($,W=302)=>Response.redirect($,W),V3=Symbol("ElysiaFormData"),P0=Symbol("ElysiaRequestId"),S3=($)=>{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},j2=()=>crypto.getRandomValues(new Uint32Array(1))[0],J2=($)=>{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 $},v=($,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 z1=typeof Bun!=="undefined"?Bun.env:typeof process!=="undefined"?process?.env:void 0,I0=Symbol("ElysiaErrorCode"),p0=(z1?.NODE_ENV??z1?.ENV)==="production";class p{code;response;constructor($,W){const X=W??($ in X2?X2[$]:$);this.code=_0[$]??$,this.response=X}}var q2=($,W)=>new p($,W);class Q2 extends Error{code="INTERNAL_SERVER_ERROR";status=500;constructor($){super($??"INTERNAL_SERVER_ERROR")}}class A0 extends Error{code="NOT_FOUND";status=404;constructor($){super($??"NOT_FOUND")}}class Y2 extends Error{code="PARSE";status=400;constructor(){super("Failed to parse body")}}class v0 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("/","."),Y=X==="";switch(j){case 42:return{...$,summary:Y?"Value should not be provided":`Property '${J}' should not be provided`};case 45:return{...$,summary:Y?"Value is missing":`Property '${J}' is missing`};case 50:const G=W.indexOf("'"),K=W.slice(G+1,W.indexOf("'",G+1));return{...$,summary:Y?"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:Y?`Value should be one of ${B}`:`Property '${J}' should be one of: ${B}`};default:return{summary:W,...$}}};class q extends Error{$;W;X;code="VALIDATION";status=422;constructor($,W,X){if(X&&typeof X==="object"&&X instanceof p)X=X.response;const Z=p0?void 0:("Errors"in W)?W.Errors(X).First():c0.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 Y="";if(j!==void 0)Y=typeof j==="object"?JSON.stringify(j):j+"";else if(p0)Y=JSON.stringify({type:"validation",on:$,summary:o(Z).summary,message:Z?.message,found:X});else{const G=W?.schema??W,K="Errors"in W?[...W.Errors(X)].map(o):[...c0.Errors(W,X)].map(o);let B;try{B=c0.Create(G)}catch(U){B={type:"Could not create expected value",message:U?.message,error:U}}Y=JSON.stringify({type:"validation",on:$,summary:K[0]?.summary,property:J,message:Z?.message,expected:B,found:X,errors:K},null,2)}super(Y);this.type=$;this.validator=W;this.value=X;Object.setPrototypeOf(this,q.prototype)}get all(){return"Errors"in this.validator?[...this.validator.Errors(this.value)].map(o):[...c0.Errors(this.validator,this.value)].map(o)}static simplifyModel($){const W="schema"in $?$.schema:$;try{return c0.Create(W)}catch{return W}}get model(){return q.simplifyModel(this.validator)}toResponse($){return new Response(this.message,{status:400,headers:{...$,"content-type":"application/json"}})}}var H2={open($){$.data.open?.($)},message($,W){$.data.message?.($,W)},drain($){$.data.drain?.($)},close($,W,X){$.data.close?.($,W,X)}};class g0{$;W;validator;_validator;constructor($,W){this.raw=$;this.data=W;if(this.validator=$.data.validator,$.data.id)this.id=$.data.id;else this.id=j2().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 q("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 q("message",this.validator,$);if(Buffer.isBuffer($))return this.raw.send($),this;if(typeof $==="object")$=JSON.stringify($);return this.raw.send($),this}}get subscribe(){return($)=>{return this.raw.subscribe($),this}}get unsubscribe(){return($)=>{return this.raw.unsubscribe($),this}}get cork(){return($)=>{return this.raw.cork($),this}}get close(){return()=>{return this.raw.close(),this}}get terminate(){return this.raw.terminate.bind(this.raw)}get isSubscribed(){return this.raw.isSubscribed.bind(this.raw)}get remoteAddress(){return this.raw.remoteAddress}}var R2="1.1.22";import{Value as n0}from"@sinclair/typebox/value";import{TypeBoxError as L3}from"@sinclair/typebox";var O0=U2(o0(),1);function G2($){const W={};if(typeof $!=="string")return W;let X="",Z="",j=-1,J=-1,Y=0;const G=$.length;for(let K=0;K<G;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(Y&1)X=X.replace(f0," ");if(Y&2)X=O0.default(X)||X;if(!W[X]){if(B){if(Z=$.slice(J+1,K),Y&4)Z=Z.replace(f0," ");if(Y&8)Z=O0.default(Z)||Z}W[X]=Z}}X="",Z="",j=K,J=K,Y=0;break;case 61:if(J<=j)J=K;else Y|=8;break;case 43:if(J>j)Y|=4;else Y|=1;break;case 37:if(J>j)Y|=8;else Y|=2;break}if(j<G){const K=J>j;if(X=$.slice(j+1,K?J:G),K||X.length>0){if(Y&1)X=X.replace(f0," ");if(Y&2)X=O0.default(X)||X;if(!W[X]){if(K){if(Z=$.slice(J+1,G),Y&4)Z=Z.replace(f0," ");if(Y&8)Z=O0.default(Z)||Z}W[X]=Z}}}return W}var f0=/\+/g,l0=($)=>{const W={};if(typeof $!=="string")return W;const X=$.length;let Z="",j="",J=-1,Y=-1,G=!1,K=!1,B=!1,U=!1,w=!1,F=0;for(let Q=0;Q<X+1;Q++){if(Q!==X)F=$.charCodeAt(Q);else F=38;switch(F){case 38:{if(w=Y>J,!w)Y=Q;if(Z=$.slice(J+1,Y),w||Z.length>0){if(B)Z=Z.replace(f0," ");if(G)Z=O0.default(Z)||Z;if(w){if(j=$.slice(Y+1,Q),U)j=j.replace(f0," ");if(K)j=O0.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=Q,Y=Q,G=!1,K=!1,B=!1,U=!1;break}case 61:if(Y<=J)Y=Q;else K=!0;break;case 43:if(Y>J)U=!0;else B=!0;break;case 37:if(Y>J)K=!0;else G=!0;break}}return W};var N1=U2(o0(),1);var i0=Symbol("ElysiaTrace"),F0=()=>{const{promise:$,resolve:W}=Promise.withResolvers(),{promise:X,resolve:Z}=Promise.withResolvers(),{promise:j,resolve:J}=Promise.withResolvers(),Y=[],G=[];return[(K)=>{if(K)Y.push(K);return $},(K)=>{const B=[],U=[];let w=null;for(let Q=0;Q<(K.total??0);Q++){const{promise:z,resolve:D}=Promise.withResolvers(),{promise:M,resolve:I}=Promise.withResolvers(),{promise:O,resolve:P}=Promise.withResolvers(),b=[],T=[];B.push((E)=>{if(E)b.push(E);return z}),U.push((E)=>{const r={...E,end:M,error:O,index:Q,onStop(L){if(L)T.push(L);return M}};D(r);for(let L=0;L<b.length;L++)b[L](r);return(L=null)=>{const g=performance.now();if(L)w=L;const R={end:g,error:L,get elapsed(){return g-E.begin}};for(let Y0=0;Y0<T.length;Y0++)T[Y0](R);I(g),P(L)}})}const F={...K,end:X,error:j,onEvent(Q){for(let z=0;z<B.length;z++)B[z](Q)},onStop(Q){if(Q)G.push(Q);return X}};W(F);for(let Q=0;Q<Y.length;Q++)Y[Q](F);return{resolveChild:U,resolve(Q=null){const z=performance.now();if(!Q&&w)Q=w;const D={end:z,error:Q,get elapsed(){return z-K.begin}};for(let M=0;M<G.length;M++)G[M](D);Z(z),J(Q)}}}]},D1=($)=>{return(W)=>{const[X,Z]=F0(),[j,J]=F0(),[Y,G]=F0(),[K,B]=F0(),[U,w]=F0(),[F,Q]=F0(),[z,D]=F0(),[M,I]=F0(),[O,P]=F0();return $({id:W[P0],context:W,set:W.set,onRequest:X,onParse:j,onTransform:Y,onBeforeHandle:K,onHandle:U,onAfterHandle:F,onMapResponse:M,onAfterResponse:O,onError:z}),{request:Z,parse:J,transform:G,beforeHandle:B,handle:w,afterHandle:Q,error:D,mapResponse:I,afterResponse:P}}};var T3=new Headers().toJSON,P1={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},t=($)=>{if(!$)return!1;const W=$?.schema;return!!W&&P1.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},x2=({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 Y=Z==="error"?"reportErr":"report";for(let G=0;G<W.length;G++)X(`\n${Y}${G} = trace${G}.${Z}({id,event: '${Z}',name: '${j}',begin: performance.now(),total: ${J}})\n`);return{resolve(){for(let G=0;G<W.length;G++)X(`\n${Y}${G}.resolve()\n`)},resolveChild(G){for(let K=0;K<W.length;K++)X(`${Y}Child${K} = ${Y}${K}.resolveChild?.shift()?.({id,event: '${Z}',name: '${G}',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
|
${Y}Child${B}?.(${K})
|
|
10
10
|
else
|
|
@@ -523,4 +523,4 @@ var L1=Object.create;var{getPrototypeOf:T1,defineProperty:k2,getOwnPropertyNames
|
|
|
523
523
|
)\n`;const Y=j("mapResponse",{total:W.mapResponse.length,name:"context"});if(W.mapResponse.length)for(let G=0;G<W.mapResponse.length;G++){const K=W.mapResponse[G],B=Y.resolveChild(K.fn.name);X+=`\ncontext.response = error
|
|
524
524
|
error = ${C0(K)?"await":""} onMapResponse[${G}](context)\n`,B()}return Y.resolve(),X+=`\nreturn mapResponse(${J} error, set, context.request)\n}\n}`,Function("inject",X)({app:$,mapResponse:x,ERROR_CODE:I0,ElysiaCustomStatusResponse:p,ELYSIA_TRACE:i0,ELYSIA_REQUEST_ID:P0})};var y2=($)=>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),Y={cookie:{},status:200,headers:{}},G=Object.assign({},$.singleton.decorator,{set:Y,store:$.singleton.store,request:W,path:J,qi:j,redirect:d0});try{for(let I=0;I<$.event.request.length;I++){const O=$.event.request[I].fn;let P=O(G);if(P instanceof Promise)P=await P;if(P=y(P,Y),P)return G.response=P}const K=$.router.dynamic.find(W.method,J)??$.router.dynamic.find("ALL",J);if(!K)throw new A0;const{handle:B,hooks:U,validator:w,content:F}=K.store;let Q;if(W.method!=="GET"&&W.method!=="HEAD")if(F)switch(F){case"application/json":Q=await W.json();break;case"text/plain":Q=await W.text();break;case"application/x-www-form-urlencoded":Q=l0(await W.text());break;case"application/octet-stream":Q=await W.arrayBuffer();break;case"multipart/form-data":Q={};const I=await W.formData();for(let O of I.keys()){if(Q[O])continue;const P=I.getAll(O);if(P.length===1)Q[O]=P[0];else Q[O]=P}break}else{let I=W.headers.get("content-type");if(I){const O=I.indexOf(";");if(O!==-1)I=I.slice(0,O);G.contentType=I;for(let P=0;P<U.parse.length;P++){const b=U.parse[P].fn;let T=b(G,I);if(T instanceof Promise)T=await T;if(T){Q=T;break}}if(delete G.contentType,Q===void 0)switch(I){case"application/json":Q=await W.json();break;case"text/plain":Q=await W.text();break;case"application/x-www-form-urlencoded":Q=l0(await W.text());break;case"application/octet-stream":Q=await W.arrayBuffer();break;case"multipart/form-data":Q={};const P=await W.formData();for(let b of P.keys()){if(Q[b])continue;const T=P.getAll(b);if(T.length===1)Q[b]=T[0];else Q[b]=T}break}}}G.body=Q,G.params=K?.params||void 0,G.query=j===-1?{}:G2(X.substring(j+1)),G.headers={};for(let[I,O]of W.headers.entries())G.headers[I]=O;const z=Object.assign({},$.config?.cookie,w?.cookie?.config),D=W.headers.get("cookie");G.cookie=await e0(G.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 I=0;I<U.transform.length;I++){const O=U.transform[I],P=O.fn(G);if(O.subType==="derive")if(P instanceof Promise)Object.assign(G,await P);else Object.assign(G,P);else if(P instanceof Promise)await P}if(w){if(w.createHeaders?.()){const I={};for(let O in W.headers)I[O]=W.headers.get(O);if(w.headers.Check(I)===!1)throw new q("header",w.headers,I)}else if(w.headers?.Decode)G.headers=w.headers.Decode(G.headers);if(w.createParams?.()?.Check(G.params)===!1)throw new q("params",w.params,G.params);else if(w.params?.Decode)G.params=w.params.Decode(G.params);if(w.createQuery?.()?.Check(G.query)===!1)throw new q("query",w.query,G.query);else if(w.query?.Decode)G.query=w.query.Decode(G.query);if(w.createCookie?.()){let I={};for(let[O,P]of Object.entries(G.cookie))I[O]=P.value;if(w.cookie.Check(I)===!1)throw new q("cookie",w.cookie,I);else if(w.cookie?.Decode)I=w.cookie.Decode(I)}if(w.createBody?.()?.Check(Q)===!1)throw new q("body",w.body,Q);else if(w.body?.Decode)G.body=w.body.Decode(Q)}for(let I=0;I<U.beforeHandle.length;I++){const O=U.beforeHandle[I];let P=O.fn(G);if(O.subType==="resolve"){if(P instanceof Promise)Object.assign(G,await P);else Object.assign(G,P);continue}else if(P instanceof Promise)P=await P;if(P!==void 0){G.response=P;for(let T=0;T<U.afterHandle.length;T++){let E=U.afterHandle[T].fn(G);if(E instanceof Promise)E=await E;if(E)P=E}const b=y(P,G.set);if(b)return G.response=b}}let M=B(G);if(M instanceof Promise)M=await M;if(!U.afterHandle.length){const I=M instanceof p?M.code:Y.status?typeof Y.status==="string"?_0[Y.status]:Y.status:200,O=w?.createResponse?.()?.[I];if(O?.Check(M)===!1)throw new q("response",O,M);else if(O?.Decode)M=O.Decode(M)}else{G.response=M;for(let I=0;I<U.afterHandle.length;I++){let O=U.afterHandle[I].fn(G);if(O instanceof Promise)O=await O;const P=y(O,G.set);if(P!==void 0){const b=w?.response?.[P.status];if(b?.Check(P)===!1)throw new q("response",b,P);else if(b?.Decode)M=b.Decode(M);return G.response=P}}}if(G.set.cookie&&z?.sign){const I=!z.secrets?void 0:typeof z.secrets==="string"?z.secrets:z.secrets[0];if(z.sign===!0)for(let[O,P]of Object.entries(G.set.cookie))G.set.cookie[O].value=await x0(P.value,"${secret}");else{const O=w?.cookie?.schema?.properties;for(let P of z.sign){if(!(P in O))continue;if(G.set.cookie[P]?.value)G.set.cookie[P].value=await x0(G.set.cookie[P].value,I)}}}return G.response=x(M,G.set)}catch(K){if(K.status)Y.status=K.status;return $.handleError(G,K)}finally{for(let K of $.event.afterResponse)await K.fn(G)}},A1=($)=>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 Y=$.event.error[j].fn(Z);if(Y instanceof Promise)Y=await Y;if(Y!==void 0&&Y!==null)return W.response=x(Y,W.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:W.set.headers,status:X.status??500})};import{TypeSystemPolicy as O5}from"@sinclair/typebox/system";class Q0{config;server=null;dependencies={};_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};static version=R2;version=R2;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 b0(b0(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 T2;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(m($,{dynamic:!0,additionalProperties:!0,coerce:!0}).Check(W)===!1){const Z=new q("env",$,W);throw new Error(Z.all.map((j)=>j.summary).join("\n"))}return this}wrap($){return this.extender.higherOrderFunctions.push({checksum:N0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$}),this}applyMacro($){if(this.extender.macros.length){const W=F1({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)_1(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]=m(X);return $}add($,W,X,Z,{allowMeta:j=!1,skipPrefix:J=!1}={allowMeta:!1,skipPrefix:!1}){if(Z=M1(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 Y=this.definitions.type,G=!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?W2({validator:B.cookie,defaultConfig:this.config.cookie,config:B.cookie?.config??{},dynamic:G,models:Y}):void 0,w=this.config.normalize,F=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:m(B.body,{dynamic:G,models:Y,normalize:w,additionalCoerce:S2()}),headers:m(B.headers,{dynamic:G,models:Y,additionalProperties:!this.config.normalize,coerce:!0,additionalCoerce:D0()}),params:m(B.params,{dynamic:G,models:Y,coerce:!0,additionalCoerce:D0()}),query:m(B.query,{dynamic:G,models:Y,normalize:w,coerce:!0,additionalCoerce:D0()}),cookie:U(),response:$2(B.response,{dynamic:G,models:Y,normalize:w})}:{createBody(){if(this.body)return this.body;return this.body=m(B.body,{dynamic:G,models:Y,normalize:w,additionalCoerce:S2()})},createHeaders(){if(this.headers)return this.headers;return this.headers=m(B.headers,{dynamic:G,models:Y,additionalProperties:!w,coerce:!0,additionalCoerce:D0()})},createParams(){if(this.params)return this.params;return this.params=m(B.params,{dynamic:G,models:Y,coerce:!0,additionalCoerce:D0()})},createQuery(){if(this.query)return this.query;return this.query=m(B.query,{dynamic:G,models:Y,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=$2(B.response,{dynamic:G,models:Y,normalize:w})}},Q=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(c(this.config.detail))Z.detail=d(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($,Q,{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=m0(this.inference),I=typeof X!=="function"?Q1(X,z,this.setHeaders):void 0,O=typeof X!=="function"?Y1(X,z,this.setHeaders):void 0;if(this.config.nativeStaticResponse===!0&&O&&($==="GET"||$==="ALL"))this.router.static.http.static[W]=O();const P=()=>I1({app:this,path:W,method:$,localHook:i(Z),hooks:z,validator:F,handler:X,allowMeta:j,inference:M}),b=D?P():(L)=>{return P()(L)},T=this.router.history.length;if(this.routeTree.has($+W))for(let L=0;L<this.router.history.length;L++){const g=this.router.history[L];if(g.path===W&&g.method===$){const R=this.router.history.splice(L,1)[0];if(R&&this.routeTree.has(R?.method+R?.path))this.routeTree.delete(R.method+R.path)}}else this.routeTree.set($+W,T);this.router.history.push({method:$,path:W,composed:b,handler:X,hooks:z});const E=this.router.static.http,r={handler:D?b:void 0,compile:P};if($==="$INTERNALWS"){const L=this.config.strictPath?void 0:W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const g=E.handlers.length;if(E.handlers.push((R)=>(E.handlers[g]=P())(R)),this.router.static.ws[W]=g,L)this.router.static.ws[L]=g}else if(this.router.ws.add("ws",W,r),L)this.router.ws.add("ws",L,r);return}if(W.indexOf(":")===-1&&W.indexOf("*")===-1){const L=E.handlers.length;if(E.handlers.push(I??((R)=>(E.handlers[L]=P())(R))),!E.map[W])E.map[W]={code:""};const g=I?"":"ctx";if($==="ALL")E.map[W].all=`default: return st[${L}](${g})\n`;else E.map[W].code=`case '${$}': return st[${L}](${g})\n${E.map[W].code}`;if(!this.config.strictPath){if(!E.map[Q])E.map[Q]={code:""};if(this.config.nativeStaticResponse===!0&&O&&($==="GET"||$==="ALL"))this.router.static.http.static[Q]=O();if($==="ALL")E.map[Q].all=`default: return st[${L}](${g})\n`;else E.map[Q].code=`case '${$}': return st[${L}](${g})\n${E.map[Q].code}`}}else if(this.router.http.add($,W,r),!this.config.strictPath){const L=W.endsWith("/")?W.slice(0,W.length-1):W+"/";if(this.config.nativeStaticResponse===!0&&I&&($==="GET"||$==="ALL"))this.router.static.http.static[L]=I();this.router.http.add($,L,r)}}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=d(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,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",D1(X));return this}error($,W){switch(typeof $){case"string":return W.prototype[I0]=$,this.definitions.error[$]=W,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,Z]of Object.entries($))Z.prototype[I0]=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=n(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 Y=w1(J,"global",{skipIfHasType:!0});switch(Z){case"start":this.event.start.push(Y);break;case"request":this.event.request.push(Y);break;case"parse":this.event.parse.push(Y);break;case"transform":this.event.transform.push(Y);break;case"beforeHandle":this.event.beforeHandle.push(Y);break;case"afterHandle":this.event.afterHandle.push(Y);break;case"mapResponse":this.event.mapResponse.push(Y);break;case"afterResponse":this.event.afterResponse.push(Y);break;case"trace":this.event.trace.push(Y);break;case"error":this.event.error.push(Y);break;case"stop":this.event.stop.push(Y);break}}return this}propagate(){return v(this.event.parse),v(this.event.transform),v(this.event.beforeHandle),v(this.event.afterHandle),v(this.event.mapResponse),v(this.event.afterResponse),v(this.event.trace),v(this.event.error),this}as($){const W={plugin:"scoped",global:"global"}[$];if(v(this.event.parse,W),v(this.event.transform,W),v(this.event.beforeHandle,W),v(this.event.afterHandle,W),v(this.event.mapResponse,W),v(this.event.afterResponse,W),v(this.event.trace,W),v(this.event.error,W),$==="plugin")this.validator.scoped=b0(this.validator.scoped,this.validator.local),this.validator.local=null;else if($==="global")this.validator.global=b0(this.validator.global,b0(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=m0(this.inference),Z.extender={...this.extender};const j=typeof W==="object",J=(j?X:W)(Z);if(this.singleton=d(this.singleton,Z.singleton),this.definitions=d(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:Y,path:G,handler:K,hooks:B})=>{if(G=(j?"":this.config.prefix)+$+G,j){const U=W,w=B;this.add(Y,G,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(Y,G,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=d(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=m0(this.inference),X.extender={...this.extender};const Z=W(X);if(this.singleton=d(this.singleton,X.singleton),this.definitions=d(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:Y,hooks:G})=>{this.add(j,J,Y,i($,{...G||{},error:!G.error?Z.event.error:Array.isArray(G.error)?[...G.error||{},...Z.event.error||[]]:[G.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:Y,path:G,handler:K,hooks:B}of Object.values(J.router.history))this.add(Y,G,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?N0(W+JSON.stringify(X)):0;if(this.dependencies[W].some(({checksum:Y})=>J===Y))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((Y)=>Y.subType==="derive").map((Y)=>({fn:Y.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.subType==="derive").map((Y)=>({fn:Y.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const j=[];for(let J=0;J<$.extender.macros.length;J++){const Y=this.extender.macros[J];if(j.includes(Y.checksum))$.extender.macros.splice(J,1),J--;j.push(Y.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?N0(W+JSON.stringify(X)):0;if(!this.dependencies[W].some(({checksum:Y})=>J===Y))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);J2(this.extender.macros),J2(this.extender.higherOrderFunctions);const j=[];for(let J=0;J<this.extender.higherOrderFunctions.length;J++){const Y=this.extender.higherOrderFunctions[J];if(Y.checksum){if(j.includes(Y.checksum))this.extender.higherOrderFunctions.splice(J,1),J--;j.push(Y.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:Y,hooks:G}of Object.values($.router.history))this.add(j,J,Y,i(G,{error:$.event.error}));if(!Z)if(W){if(!(W in this.dependencies))this.dependencies[W]=[];const j=X!==void 0?N0(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=C2(this.event,L2($.event),j)}else this.event=C2(this.event,L2($.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:N0(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:Y,path:G})=>{if(Y.method==="GET"||Y.method==="HEAD"||!Y.headers.get("content-type"))return j(new Request(R0(Y.url,G||"/"),Y));return j(new Request(R0(Y.url,G||"/"),{...Y,body:await Y.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(R0(j.url,J.slice(X)||"/"),j));return W(new Request(R0(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=m(W?.body,{models:this.definitions.type,normalize:this.config.normalize}),J=m(W?.response,{models:this.definitions.type,normalize:this.config.normalize}),Y=(G)=>{if(typeof G==="string"){const K=G?.charCodeAt(0);if(K===47||K===123)try{G=JSON.parse(G)}catch{}else if(Z2(G))G=+G}if(X?.length)for(let K=0;K<X.length;K++){const B=X[K](G);if(B!==void 0)G=B}return G};return this.route("$INTERNALWS",$,(G)=>{const{set:K,path:B,qi:U,headers:w,query:F,params:Q}=G;if(Z===null)Z=this.getServer();if(Z?.upgrade(G.request,{headers:typeof W.upgrade==="function"?W.upgrade(G):W.upgrade,data:{validator:J,open(z){W.open?.(new g0(z,G))},message:(z,D)=>{const M=Y(D);if(j?.Check(M)===!1)return void z.send(new q("message",j,M).message);W.message?.(new g0(z,G),M)},drain(z){W.drain?.(new g0(z,G))},close(z,D,M){W.close?.(new g0(z,G),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]=d(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=d(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]=d(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=d(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),Y=(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}},G=Array.isArray(W)?W:[W];for(let K of G.some((B)=>B==="all")?["decorator","state","model","error"]:G)Y(K);return this}prefix($,W){return this.affix("prefix",$,W)}suffix($,W){return this.affix("suffix",$,W)}compile(){if(this.fetch=this.config.aot?g2(this):y2(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?g2(this):y2(this))($)};handleError=async($,W)=>(this.handleError=this.config.aot?f2(this):A1(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(!Z2($))throw new Error("Port must be a numeric value");$=parseInt($)}const X=this.fetch,Z=typeof $==="object"?{development:!p0,reusePort:!0,...this.config.serve||{},...$||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...H2||{}},fetch:X,error:this.outerErrorHandler}:{development:!p0,reusePort:!0,...this.config.serve||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...H2||{}},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,R0 as replaceUrlPath,V2 as replaceSchemaType,d0 as redirect,f as mergeObjectArray,i as mergeHook,o as mapValueError,x as mapResponse,y as mapEarlyResponse,Z0 as mapCompactResponse,m as getSchemaValidator,$2 as getResponseSchemaValidator,S3 as form,q2 as error,Q0 as default,J2 as deduplicateChecksum,m0 as cloneInference,N0 as checksum,q as ValidationError,O5 as TypeSystemPolicy,_0 as StatusMap,Y2 as ParseError,A0 as NotFoundError,X2 as InvertedStatusMap,v0 as InvalidCookieSignature,Q2 as InternalServerError,Q0 as Elysia,I0 as ERROR_CODE,i0 as ELYSIA_TRACE,P0 as ELYSIA_REQUEST_ID,V3 as ELYSIA_FORM_DATA,w0 as Cookie};
|
|
525
525
|
|
|
526
|
-
//# debugId=
|
|
526
|
+
//# debugId=57DAC4D2043C699D64756E2164756E21
|