elysia 1.0.19 → 1.0.20
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/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +1 -1
- package/tsconfig.test.tsbuildinfo +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -437,6 +437,6 @@ var L$=Object.create;var{defineProperty:q1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
437
437
|
}`,Function("inject",J)({app:$,mapResponse:h,ERROR_CODE:Z0,ELYSIA_RESPONSE:d})},E0=($)=>`if(stc${$}) return stc${$}(ctx)
|
|
438
438
|
if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
|
|
439
439
|
|
|
440
|
-
return st${$}(ctx)`;var e0=N0(D1(),1);var P1=($)=>async(J)=>{const w=J.url,B=w.indexOf("/",11),X=w.indexOf("?",B+1),W=X===-1?w.substring(B):w.substring(B,X),Z={cookie:{},status:200,headers:{}},S=Object.assign({},$.singleton.decorator,{set:Z,store:$.singleton.store,request:J,path:W,qi:X});try{for(let R=0;R<$.event.request.length;R++){const M=$.event.request[R].fn;let D=M(S);if(D instanceof Promise)D=await D;if(D=f(D,Z),D)return D}const Q=$.router.dynamic.find(J.method,W)??$.router.dynamic.find("ALL",W);if(!Q)throw new S0;const{handle:G,hooks:K,validator:U,content:z}=Q.store;let F;if(J.method!=="GET"&&J.method!=="HEAD")if(z)switch(z){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=e0.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const R=await J.formData();for(let M of R.keys()){if(F[M])continue;const D=R.getAll(M);if(D.length===1)F[M]=D[0];else F[M]=D}break}else{let R=J.headers.get("content-type");if(R){const M=R.indexOf(";");if(M!==-1)R=R.slice(0,M);S.contentType=R;for(let D=0;D<K.parse.length;D++){const T=K.parse[D].fn;let q=T(S,R);if(q instanceof Promise)q=await q;if(q){F=q;break}}if(delete S.contentType,F===void 0)switch(R){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=e0.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const D=await J.formData();for(let T of D.keys()){if(F[T])continue;const q=D.getAll(T);if(q.length===1)F[T]=q[0];else F[T]=q}break}}}S.body=F,S.params=Q?.params||void 0,S.query=X===-1?{}:e0.parse(w.substring(X+1)),S.headers={};for(let[R,M]of J.headers.entries())S.headers[R]=M;const C=Object.assign({},$.config?.cookie,U?.cookie?.config),P=J.headers.get("cookie");S.cookie=await c0(S.set,P,C?{secrets:C.secrets!==void 0?typeof C.secrets==="string"?C.secrets:C.secrets.join(","):void 0,sign:C.sign===!0?!0:C.sign!==void 0?typeof C.sign==="string"?C.sign:C.sign.join(","):void 0}:void 0);for(let R=0;R<K.transform.length;R++){const M=K.transform[R],D=M.fn(S);if(M.subType==="derive")if(D instanceof Promise)Object.assign(S,await D);else Object.assign(S,D);else if(D instanceof Promise)await D}if(U){if(U.headers){const R={};for(let M in J.headers)R[M]=J.headers.get(M);if(U.headers.Check(R)===!1)throw new I("header",U.headers,R)}if(U.params?.Check(S.params)===!1)throw new I("params",U.params,S.params);if(U.query?.Check(S.query)===!1)throw new I("query",U.query,S.query);if(U.cookie){const R={};for(let[M,D]of Object.entries(S.cookie))R[M]=D.value;if(U.cookie?.Check(R)===!1)throw new I("cookie",U.cookie,R)}if(U.body?.Check(F)===!1)throw new I("body",U.body,F)}for(let R=0;R<K.beforeHandle.length;R++){let M=K.beforeHandle[R].fn(S);if(M instanceof Promise)M=await M;if(M!==void 0){S.response=M;for(let T=0;T<K.afterHandle.length;T++){let q=K.afterHandle[T].fn(S);if(q instanceof Promise)q=await q;if(q)M=q}const D=f(M,S.set);if(D)return D}}let Y=G(S);if(Y instanceof Promise)Y=await Y;if(!K.afterHandle.length){const R=U?.response?.[Y.status];if(R?.Check(Y)===!1)throw new I("response",R,Y)}else{S.response=Y;for(let R=0;R<K.afterHandle.length;R++){let M=K.afterHandle[R].fn(S);if(M instanceof Promise)M=await M;const D=f(M,S.set);if(D!==void 0){const T=U?.response?.[Y.status];if(T?.Check(D)===!1)throw new I("response",T,D);return D}}}if(S.set.cookie&&C?.sign){const R=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(S.set.cookie))S.set.cookie[M].value=await _0(D.value,"${secret}");else{const M=U?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(S.set.cookie[D]?.value)S.set.cookie[D].value=await _0(S.set.cookie[D].value,R)}}}return h(Y,S.set)}catch(Q){if(Q.status)Z.status=Q.status;return $.handleError(S,Q)}finally{for(let Q of $.event.onResponse)await Q.fn(S)}},C$=($)=>async(J,w)=>{const B=Object.assign(J,{error:w,code:w.code});B.set=J.set;for(let X=0;X<$.event.error.length;X++){let Z=$.event.error[X].fn(B);if(Z instanceof Promise)Z=await Z;if(Z!==void 0&&Z!==null)return h(Z,J.set)}return new Response(typeof w.cause==="string"?w.cause:w.message,{headers:J.set.headers,status:w.status??500})};import{TypeRegistry as O$} from"@sinclair/typebox";import{TypeSystem as D0} from"@sinclair/typebox/system";import{Type as L0,FormatRegistry as o} from"@sinclair/typebox";import{Value as C0} from"@sinclair/typebox/value";var zJ=function($){return $%4===0&&($%100!==0||$%400===0)},A$=function($){const J=_J.exec($);if(!J)return!1;const w=+J[1],B=+J[2],X=+J[3];return B>=1&&B<=12&&X>=1&&X<=(B===2&&zJ(w)?29:jJ[B])},O1=function($){return function J(w){const B=FJ.exec(w);if(!B)return!1;const X=+B[1],W=+B[2],Z=+B[3],S=B[4],Q=B[5]==="-"?-1:1,G=+(B[6]||0),K=+(B[7]||0);if(G>23||K>59||$&&!S)return!1;if(X<=23&&W<=59&&Z<60)return!0;const U=W-K*Q,z=X-G*Q-(U<0?1:0);return(z===23||z===-1)&&(U===59||U===-1)&&Z<61}},D$=function($){const J=O1($);return function w(B){const X=B.split(CJ);return X.length===2&&A$(X[0])&&J(X[1])}},NJ=function($){return DJ.test($)&&MJ.test($)},AJ=function($){return M$.lastIndex=0,M$.test($)},VJ=function($){return Number.isInteger($)&&$<=OJ&&$>=PJ},qJ=function($){return Number.isInteger($)},N$=function(){return!0},bJ=function($){if(IJ.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},$1={date:A$,time:O1(!0),"date-time":D$(!0),"iso-time":O1(!1),"iso-date-time":D$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:NJ,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]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d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:bJ,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:AJ,int32:{type:"number",validate:VJ},int64:{type:"number",validate:qJ},float:{type:"number",validate:N$},double:{type:"number",validate:N$},password:!0,binary:!0},_J=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,jJ=[0,31,28,31,30,31,30,31,31,30,31,30,31],FJ=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,CJ=/t|\s/i,DJ=/\/|:/,MJ=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,M$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,PJ=-2147483648,OJ=2147483647,IJ=/[^\\]\\Z/;import{TypeSystemPolicy as rw,TypeSystem as nw,TypeSystemDuplicateFormat as ow,TypeSystemDuplicateTypeKind as aw} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as J8} from"@sinclair/typebox/compiler";var V$=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,q$=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,I$=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,TJ=$1.date,EJ=$1["date-time"];if(!o.Has("date"))D0.Format("date",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||TJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});if(!o.Has("date-time"))D0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||EJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});Object.entries($1).forEach(($)=>{const[J,w]=$;if(!o.Has(J)){if(w instanceof RegExp)D0.Format(J,(B)=>w.test(B));else if(typeof w==="function")D0.Format(J,w)}});var V=Object.assign({},L0),P$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},V1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<P$($.minSize))return!1;if($.maxSize&&J.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!J.type.startsWith($.extension))return!1}else{for(let w=0;w<$.extension.length;w++)if(J.type.startsWith($.extension[w]))return!0;return!1}return!0},LJ=O$.Get("Files")??D0.Type("File",V1),HJ=O$.Get("Files")??D0.Type("Files",($,J)=>{if(!Array.isArray(J))return V1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let w=0;w<J.length;w++)if(!V1($,J[w]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",($)=>!!$&&!isNaN(+$));if(!o.Has("boolean"))o.Set("boolean",($)=>$==="true"||$==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",($)=>{let J=$.charCodeAt(0);if(J===9||J===10||J===32)J=$.trimStart().charCodeAt(0);if(J!==123&&J!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const J=L0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((w)=>{const B=+w;if(isNaN(B))return w;if($&&!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>w)},Date:($)=>{const J=L0.Date($);return V.Transform(V.Union([L0.Date($),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((w)=>{if(w instanceof Date)return w;const B=new Date(w);if(!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>{if(typeof w==="string")return new Date(w);return w})},BooleanString:($)=>{const J=L0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((w)=>{if(typeof w==="string")return w==="true";if($&&!C0.Check(J,w))throw new I("property",J,w);return w}).Encode((w)=>w)},ObjectString:($={},J)=>{const w=V.Object($,J),B=JSON.stringify(C0.Create(w));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),w])).Decode((X)=>{if(typeof X==="string"){try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return X}return X}).Encode((X)=>{if(typeof X==="string")try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return JSON.stringify(X)})},File:LJ,Files:($={})=>V.Transform(HJ($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>V.Union([V.Null(),$]),MaybeEmpty:($)=>V.Union([V.Null(),V.Undefined(),$]),Cookie:($,{domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:S,secure:Q,secrets:G,sign:K,...U}={})=>{const z=V.Object($,U);return z.config={domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:S,secure:Q,secrets:G,sign:K},z}};V.BooleanString=a.BooleanString;V.ObjectString=a.ObjectString;V.Numeric=a.Numeric;V.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>a.Nullable($);V.MaybeEmpty=a.MaybeEmpty;V.Cookie=a.Cookie;V.Date=a.Date;class s{config;server=null;dependencies={};reporter=new H1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new B0,ws:new B0,dynamic:new B0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new z1;constructor($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const J=o1({globalHook:this.event,localHook:$}),w={events:{global:this.event,local:$},onParse:J("parse"),onTransform:J("transform"),onBeforeHandle:J("beforeHandle"),onAfterHandle:J("afterHandle"),onResponse:J("onResponse"),mapResponse:J("mapResponse"),onError:J("error")};for(let B of this.extender.macros)R1(B.fn(w),$)}}add($,J,w,B,{allowMeta:X=!1,skipPrefix:W=!1}={allowMeta:!1,skipPrefix:!1}){if(B=a1(B),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!W&&!this.config.scoped)J=this.config.prefix+J;if(B?.type)switch(B.type){case"text":B.type="text/plain";break;case"json":B.type="application/json";break;case"formdata":B.type="multipart/form-data";break;case"urlencoded":B.type="application/x-www-form-urlencoded";break;case"arrayBuffer":B.type="application/octet-stream";break;default:break}const Z=this.definitions.type;let S,Q,G,K,U,z;const F=!this.config.aot,C={body:B?.body??this.validator?.body,headers:B?.headers??this.validator?.headers,params:B?.params??this.validator?.params,query:B?.query??this.validator?.query,cookie:B?.cookie??this.validator?.cookie,response:B?.response??this.validator?.response},P=()=>C.cookie?s0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:F,models:Z}):void 0,Y=this.config.normalize,R=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:F,models:Z,normalize:Y}),headers:k(C.headers,{dynamic:F,models:Z,additionalProperties:!0}),params:k(C.params,{dynamic:F,models:Z}),query:k(C.query,{dynamic:F,models:Z,normalize:Y}),cookie:P(),response:p0(C.response,{dynamic:F,models:Z,normalize:Y})}:{get body(){if(S)return S;return S=k(C.body,{dynamic:F,models:Z,normalize:Y})},get headers(){if(Q)return Q;return k(C.headers,{dynamic:F,models:Z,additionalProperties:!0})},get params(){if(G)return G;return G=k(C.params,{dynamic:F,models:Z})},get query(){if(K)return K;return K=k(C.query,{dynamic:F,models:Z})},get cookie(){if(U)return U;return U=P()},get response(){if(z)return z;return z=p0(C.response,{dynamic:F,models:Z,normalize:Y})}},M=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(B=u(B,{},{allowMacro:!0}),B.tags)if(!B.detail)B.detail={tags:B.tags};else B.detail.tags=B.tags;if(m(this.config.detail))B.detail=p(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const D=u(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:R,hooks:D,content:B?.type,handle:w}),this.config.strictPath===!1)this.router.dynamic.add($,M,{validator:R,hooks:D,content:B?.type,handle:w});this.router.history.push({method:$,path:J,composed:null,handler:w,hooks:D});return}let T=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=t0(this.inference),v=q?a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e}):(A)=>{if(T)return T(A);return(T=a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e}))(A)};if(!q)v.compose=()=>{return v.composed=a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e})};let t=this.router.history.length;if(this.routeTree.has($+J)){if(t=this.router.history.findIndex((A)=>A.path===J&&A.method===$),t!==-1){const A=this.router.history.splice(t,1)[0];if(A&&this.routeTree.has(A?.method+A?.path))this.routeTree.delete(A.method+A.path)}}this.routeTree.set($+J,t),this.router.history.push({method:$,path:J,composed:v,handler:w,hooks:D});const O=this.router.static.http;if($==="$INTERNALWS"){const A=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,A)this.router.static.ws[A]=$0}else if(this.router.ws.add("ws",J,v),A)this.router.ws.add("ws",A,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const A=O.handlers.length;if(O.handlers.push(v),O.variables+=q?`const st${A} = staticRouter.handlers[${A}]\n`:`let st${A} = staticRouter.handlers[${A}]\nlet stc${A}\n`,!O.map[J])O.map[J]={code:""};if($==="ALL")O.map[J].all=q?`default: return st${A}(ctx)\n`:`default: ${E0(A)}\n`;else O.map[J].code=q?`case '${$}': return st${A}(ctx)\n${O.map[J].code}`:`case '${$}': ${E0(A)}\n${O.map[J].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if($==="ALL")O.map[M].all=q?`default: return st${A}(ctx)\n`:`default: ${E0(A)}\n`;else O.map[M].code=q?`case '${$}': return st${A}(ctx)\n${O.map[M].code}`:`case '${$}': ${E0(A)}\n${O.map[M].code}`}}else if(this.router.http.add($,J,v),!this.config.strictPath)this.router.http.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,J){if(!J)return this.on("parse",$);return this.on($,"parse",J)}onTransform($,J){if(!J)return this.on("transform",$);return this.on($,"transform",J)}resolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}mapResolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}onBeforeHandle($,J){if(!J)return this.on("beforeHandle",$);return this.on($,"beforeHandle",J)}onAfterHandle($,J){if(!J)return this.on("afterHandle",$);return this.on($,"afterHandle",J)}mapResponse($,J){if(!J)return this.on("mapResponse",$);return this.on($,"mapResponse",J)}onResponse($,J){if(!J)return this.on("response",$);return this.on($,"response",J)}trace($,J){if(!J)J=$,$={as:"local"};if(!Array.isArray(J))J=[J];for(let w of J)this.reporter.on("event",x1(()=>this.reporter,this.event.trace.length,w));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Z0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[w,B]of Object.entries($))B.prototype[Z0]=w,this.definitions.error[w]=B;return this}onError($,J){if(!J)return this.on("error",$);return this.on($,"error",J)}onStop($){return this.on("stop",$),this}on($,J,w){let B;switch(typeof $){case"string":B=$,w=J;break;case"object":B=J;break}if(B==="response")B="onResponse";if(Array.isArray(w))w=c(w);else if(typeof w==="function")w=[{fn:w}];else w=[w];const X=w;for(let W of X)W.scope=typeof $==="string"?"local":$?.as??"local";if(B==="trace")f1(X.map((W)=>W.fn),this.inference.trace);else h0({[B]:X.map((W)=>W.fn)},this.inference.event);for(let W of X){const Z=n1(W,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(Z);break;case"request":this.event.request.push(Z);break;case"parse":this.event.parse.push(Z);break;case"transform":this.event.transform.push(Z);break;case"beforeHandle":this.event.beforeHandle.push(Z);break;case"afterHandle":this.event.afterHandle.push(Z);break;case"mapResponse":this.event.mapResponse.push(Z);break;case"onResponse":this.event.onResponse.push(Z);break;case"trace":this.event.trace.push(Z);break;case"error":this.event.error.push(Z);break;case"stop":this.event.stop.push(Z);break}}return this}propagate(){const $=(J)=>{for(let w of J)if("scope"in w&&w.scope==="local")w.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,J,w){const B=new s({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=t0(this.inference);const X=typeof J==="object",W=(X?w:J)(B);if(this.singleton=p(this.singleton,B.singleton),this.definitions=p(this.definitions,B.definitions),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(B.router.history).forEach(({method:Z,path:S,handler:Q,hooks:G})=>{if(S=(X?"":this.config.prefix)+$+S,X){const K=J,U=G;this.add(Z,S,Q,u(K,{...U||{},error:!U.error?W.event.error:Array.isArray(U.error)?[...U.error||{},...W.event.error||{}]:[U.error,...W.event.error||{}]}))}else this.add(Z,S,Q,u(G,{error:W.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=l0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const w=new s({...this.config,prefix:""});w.singleton={...this.singleton},w.definitions={...this.definitions},w.inference=t0(this.inference);const B=J(w);if(this.singleton=p(this.singleton,w.singleton),this.definitions=p(this.definitions,w.definitions),B.getServer=()=>this.server,B.event.request.length)this.event.request=[...this.event.request||[],...B.event.request||[]];if(B.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...B.event.onResponse||[]];return this.model(B.definitions.type),Object.values(w.router.history).forEach(({method:X,path:W,handler:Z,hooks:S})=>{this.add(X,W,Z,u($,{...S||{},error:!S.error?B.event.error:Array.isArray(S.error)?[...S.error||{},...B.event.error||[]]:[S.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(w)=>w.use($));if(Array.isArray($)){let w=this;for(let B of $)w=this.use(B);return w}if($ instanceof Promise)return this.promisedModules.add($.then((w)=>{if(typeof w==="function")return w(this);if(w instanceof s)return this._use(w);if(typeof w.default==="function")return w.default(this);if(w.default instanceof s)return this._use(w.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((w)=>w.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const X=$(this);if(X instanceof Promise)return this.promisedModules.add(X.then((W)=>{if(W instanceof s){this.compile();for(let{method:Z,path:S,handler:Q,hooks:G}of Object.values(W.router.history))this.add(Z,S,Q,u(G,{error:W.event.error}));return W}if(typeof W==="function")return W(this);if(typeof W.default==="function")return W.default(this);return this._use(W)}).then((W)=>W.compile())),this;return X}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((X)=>X.compile())),this;const{name:J,seed:w}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const B=$.config.scoped;if(B){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?V0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:Z})=>W===Z))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<$.extender.macros.length;W++){const Z=this.extender.macros[W];if(X.includes(Z.checksum))$.extender.macros.splice(W,1),W--;X.push(Z.checksum)}if($.onRequest((W)=>{Object.assign(W,this.singleton.decorator),Object.assign(W.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(B===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let W of $.event.trace)if(W.scope&&W.scope!=="local")this.trace(W);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?V0(J+JSON.stringify(w)):0;if(!this.dependencies[J].some(({checksum:Z})=>W===Z))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<this.extender.macros.length;W++){const Z=this.extender.macros[W];if(Z.checksum){if(X.includes(Z.checksum))this.extender.macros.splice(W,1),W--;X.push(Z.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:X,path:W,handler:Z,hooks:S}of Object.values($.router.history))this.add(X,W,Z,u(S,{error:$.event.error}));if(!B)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const X=w!==void 0?V0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:W})=>X===W))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((W)=>W?.subType==="derive").map((W)=>({fn:W.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((W)=>W?.subType==="resolve").map((W)=>({fn:W.toString(),stack:new Error().stack??""}))}),this.event=l0(this.event,U1($.event),X)}else this.event=l0(this.event,U1($.event));return this}macro($){const J={checksum:V0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof s||typeof $==="function"||$.length===0||$==="/"){const X=typeof $==="function"?$:$ instanceof s?$.compile().fetch:J instanceof s?J.compile().fetch:J,W=async({request:Z,path:S})=>X(new Request(K1(Z.url,S||"/"),Z));return this.all("/*",W,{type:"none"}),this}const w=$.length;if(J instanceof s)J=J.compile().fetch;const B=async({request:X,path:W})=>J(new Request(K1(X.url,W.slice(w)||"/"),X));return this.all($,B,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get($,J,w){return this.add("GET",$,J,w),this}post($,J,w){return this.add("POST",$,J,w),this}put($,J,w){return this.add("PUT",$,J,w),this}patch($,J,w){return this.add("PATCH",$,J,w),this}delete($,J,w){return this.add("DELETE",$,J,w),this}options($,J,w){return this.add("OPTIONS",$,J,w),this}all($,J,w){return this.add("ALL",$,J,w),this}head($,J,w){return this.add("HEAD",$,J,w),this}connect($,J,w){return this.add("CONNECT",$,J,w),this}route($,J,w,B){return this.add($.toUpperCase(),J,w,B,B?.config),this}ws($,J){const w=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let B=null;const X=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),W=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Z=(S)=>{if(typeof S==="string"){const Q=S?.charCodeAt(0);if(Q===47||Q===123)try{S=JSON.parse(S)}catch{}else if(R0(S))S=+S}if(w?.length)for(let Q=0;Q<w.length;Q++){const G=w[Q](S);if(G!==void 0)S=G}return S};return this.route("$INTERNALWS",$,(S)=>{const{set:Q,path:G,qi:K,headers:U,query:z,params:F}=S;if(B===null)B=this.getServer();if(B?.upgrade(S.request,{headers:typeof J.upgrade==="function"?J.upgrade(S):J.upgrade,data:{validator:W,open(C){J.open?.(new j0(C,S))},message:(C,P)=>{const Y=Z(P);if(X?.Check(Y)===!1)return void C.send(new I("message",X,Y).message);J.message?.(new j0(C,S),Y)},drain(C){J.drain?.(new j0(C,S))},close(C,P,Y){J.close?.(new j0(C,S),P,Y)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:J.beforeHandle,transform:J.transform,headers:J.headers,params:J.params,query:J.query}),this}state($,J){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=J;return this}decorate($,J){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=J;return this}derive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}model($,J){switch(typeof $){case"object":return Object.entries($).forEach(([w,B])=>{if(!(w in this.definitions.type))this.definitions.type[w]=B}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=J,this}mapDerive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}affix($,J,w){if(w==="")return this;const B=["_","-"," "],X=(Q)=>Q[0].toUpperCase()+Q.slice(1),W=$==="prefix"?(Q,G)=>B.includes(Q.at(-1)??"")?Q+G:Q+X(G):B.includes(w.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+X(Q),Z=(Q)=>{const G={};switch(Q){case"decorator":for(let K in this.singleton.decorator)G[W(w,K)]=this.singleton.decorator[K];this.singleton.decorator=G;break;case"state":for(let K in this.singleton.store)G[W(w,K)]=this.singleton.store[K];this.singleton.store=G;break;case"model":for(let K in this.definitions.type)G[W(w,K)]=this.definitions.type[K];this.definitions.type=G;break;case"error":for(let K in this.definitions.error)G[W(w,K)]=this.definitions.error[K];this.definitions.error=G;break}},S=Array.isArray(J)?J:[J];for(let Q of S.some((G)=>G==="all")?["decorator","state","model","error"]:S)Z(Q);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?N1(this):P1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?N1(this):P1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?A1(this):C$(this))($,J);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,J)=>{if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof $==="string"){if(!R0($))throw new Error("Port must be a numeric value");$=parseInt($)}const w=this.fetch,B=typeof $==="object"?{development:!q0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...F1||{}},fetch:w,error:this.outerErrorHandler}:{development:!q0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...F1||{}},port:$,fetch:w,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let X=0;X<this.event.start.length;X++)this.event.start[X].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let X=0;X<this.event.stop.length;X++)this.event.stop[X].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,_1 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,p0 as getResponseSchemaValidator,j1 as error,s as default,I as ValidationError,X0 as StatusMap,o0 as ParseError,S0 as NotFoundError,i0 as InvertedStatusMap,P0 as InvalidCookieSignature,n0 as InternalServerError,s as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
440
|
+
return st${$}(ctx)`;var e0=N0(D1(),1);var P1=($)=>async(J)=>{const w=J.url,B=w.indexOf("/",11),X=w.indexOf("?",B+1),W=X===-1?w.substring(B):w.substring(B,X),Z={cookie:{},status:200,headers:{}},S=Object.assign({},$.singleton.decorator,{set:Z,store:$.singleton.store,request:J,path:W,qi:X});try{for(let R=0;R<$.event.request.length;R++){const M=$.event.request[R].fn;let D=M(S);if(D instanceof Promise)D=await D;if(D=f(D,Z),D)return D}const Q=$.router.dynamic.find(J.method,W)??$.router.dynamic.find("ALL",W);if(!Q)throw new S0;const{handle:G,hooks:K,validator:U,content:z}=Q.store;let F;if(J.method!=="GET"&&J.method!=="HEAD")if(z)switch(z){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=e0.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const R=await J.formData();for(let M of R.keys()){if(F[M])continue;const D=R.getAll(M);if(D.length===1)F[M]=D[0];else F[M]=D}break}else{let R=J.headers.get("content-type");if(R){const M=R.indexOf(";");if(M!==-1)R=R.slice(0,M);S.contentType=R;for(let D=0;D<K.parse.length;D++){const T=K.parse[D].fn;let q=T(S,R);if(q instanceof Promise)q=await q;if(q){F=q;break}}if(delete S.contentType,F===void 0)switch(R){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=e0.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const D=await J.formData();for(let T of D.keys()){if(F[T])continue;const q=D.getAll(T);if(q.length===1)F[T]=q[0];else F[T]=q}break}}}S.body=F,S.params=Q?.params||void 0,S.query=X===-1?{}:e0.parse(w.substring(X+1)),S.headers={};for(let[R,M]of J.headers.entries())S.headers[R]=M;const C=Object.assign({},$.config?.cookie,U?.cookie?.config),P=J.headers.get("cookie");S.cookie=await c0(S.set,P,C?{secrets:C.secrets!==void 0?typeof C.secrets==="string"?C.secrets:C.secrets.join(","):void 0,sign:C.sign===!0?!0:C.sign!==void 0?typeof C.sign==="string"?C.sign:C.sign.join(","):void 0}:void 0);for(let R=0;R<K.transform.length;R++){const M=K.transform[R],D=M.fn(S);if(M.subType==="derive")if(D instanceof Promise)Object.assign(S,await D);else Object.assign(S,D);else if(D instanceof Promise)await D}if(U){if(U.headers){const R={};for(let M in J.headers)R[M]=J.headers.get(M);if(U.headers.Check(R)===!1)throw new I("header",U.headers,R)}if(U.params?.Check(S.params)===!1)throw new I("params",U.params,S.params);if(U.query?.Check(S.query)===!1)throw new I("query",U.query,S.query);if(U.cookie){const R={};for(let[M,D]of Object.entries(S.cookie))R[M]=D.value;if(U.cookie?.Check(R)===!1)throw new I("cookie",U.cookie,R)}if(U.body?.Check(F)===!1)throw new I("body",U.body,F)}for(let R=0;R<K.beforeHandle.length;R++){let M=K.beforeHandle[R].fn(S);if(M instanceof Promise)M=await M;if(M!==void 0){S.response=M;for(let T=0;T<K.afterHandle.length;T++){let q=K.afterHandle[T].fn(S);if(q instanceof Promise)q=await q;if(q)M=q}const D=f(M,S.set);if(D)return D}}let Y=G(S);if(Y instanceof Promise)Y=await Y;if(!K.afterHandle.length){const R=U?.response?.[Y.status];if(R?.Check(Y)===!1)throw new I("response",R,Y)}else{S.response=Y;for(let R=0;R<K.afterHandle.length;R++){let M=K.afterHandle[R].fn(S);if(M instanceof Promise)M=await M;const D=f(M,S.set);if(D!==void 0){const T=U?.response?.[Y.status];if(T?.Check(D)===!1)throw new I("response",T,D);return D}}}if(S.set.cookie&&C?.sign){const R=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(S.set.cookie))S.set.cookie[M].value=await _0(D.value,"${secret}");else{const M=U?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(S.set.cookie[D]?.value)S.set.cookie[D].value=await _0(S.set.cookie[D].value,R)}}}return h(Y,S.set)}catch(Q){if(Q.status)Z.status=Q.status;return $.handleError(S,Q)}finally{for(let Q of $.event.onResponse)await Q.fn(S)}},C$=($)=>async(J,w)=>{const B=Object.assign(J,{error:w,code:w.code});B.set=J.set;for(let X=0;X<$.event.error.length;X++){let Z=$.event.error[X].fn(B);if(Z instanceof Promise)Z=await Z;if(Z!==void 0&&Z!==null)return h(Z,J.set)}return new Response(typeof w.cause==="string"?w.cause:w.message,{headers:J.set.headers,status:w.status??500})};import{TypeRegistry as O$} from"@sinclair/typebox";import{TypeSystem as D0} from"@sinclair/typebox/system";import{Type as L0,FormatRegistry as o} from"@sinclair/typebox";import{Value as C0} from"@sinclair/typebox/value";var zJ=function($){return $%4===0&&($%100!==0||$%400===0)},A$=function($){const J=_J.exec($);if(!J)return!1;const w=+J[1],B=+J[2],X=+J[3];return B>=1&&B<=12&&X>=1&&X<=(B===2&&zJ(w)?29:jJ[B])},O1=function($){return function J(w){const B=FJ.exec(w);if(!B)return!1;const X=+B[1],W=+B[2],Z=+B[3],S=B[4],Q=B[5]==="-"?-1:1,G=+(B[6]||0),K=+(B[7]||0);if(G>23||K>59||$&&!S)return!1;if(X<=23&&W<=59&&Z<60)return!0;const U=W-K*Q,z=X-G*Q-(U<0?1:0);return(z===23||z===-1)&&(U===59||U===-1)&&Z<61}},D$=function($){const J=O1($);return function w(B){const X=B.split(CJ);return X.length===2&&A$(X[0])&&J(X[1])}},NJ=function($){return DJ.test($)&&MJ.test($)},AJ=function($){return M$.lastIndex=0,M$.test($)},VJ=function($){return Number.isInteger($)&&$<=OJ&&$>=PJ},qJ=function($){return Number.isInteger($)},N$=function(){return!0},bJ=function($){if(IJ.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},$1={date:A$,time:O1(!0),"date-time":D$(!0),"iso-time":O1(!1),"iso-date-time":D$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:NJ,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-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}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:bJ,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:AJ,int32:{type:"number",validate:VJ},int64:{type:"number",validate:qJ},float:{type:"number",validate:N$},double:{type:"number",validate:N$},password:!0,binary:!0},_J=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,jJ=[0,31,28,31,30,31,30,31,31,30,31,30,31],FJ=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,CJ=/t|\s/i,DJ=/\/|:/,MJ=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(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/?]|%[0-9a-f]{2})*)?$/i,M$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,PJ=-2147483648,OJ=2147483647,IJ=/[^\\]\\Z/;import{TypeSystemPolicy as rw,TypeSystem as nw,TypeSystemDuplicateFormat as ow,TypeSystemDuplicateTypeKind as aw} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as J8} from"@sinclair/typebox/compiler";var V$=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,q$=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,I$=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,TJ=$1.date,EJ=$1["date-time"];if(!o.Has("date"))D0.Format("date",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||TJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});if(!o.Has("date-time"))D0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||EJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});Object.entries($1).forEach(($)=>{const[J,w]=$;if(!o.Has(J)){if(w instanceof RegExp)D0.Format(J,(B)=>w.test(B));else if(typeof w==="function")D0.Format(J,w)}});var V=Object.assign({},L0),P$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},V1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<P$($.minSize))return!1;if($.maxSize&&J.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!J.type.startsWith($.extension))return!1}else{for(let w=0;w<$.extension.length;w++)if(J.type.startsWith($.extension[w]))return!0;return!1}return!0},LJ=O$.Get("Files")??D0.Type("File",V1),HJ=O$.Get("Files")??D0.Type("Files",($,J)=>{if(!Array.isArray(J))return V1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let w=0;w<J.length;w++)if(!V1($,J[w]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",($)=>!!$&&!isNaN(+$));if(!o.Has("boolean"))o.Set("boolean",($)=>$==="true"||$==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",($)=>{let J=$.charCodeAt(0);if(J===9||J===10||J===32)J=$.trimStart().charCodeAt(0);if(J!==123&&J!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const J=L0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((w)=>{const B=+w;if(isNaN(B))return w;if($&&!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>w)},Date:($)=>{const J=L0.Date($);return V.Transform(V.Union([L0.Date($),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((w)=>{if(w instanceof Date)return w;const B=new Date(w);if(!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>{if(typeof w==="string")return new Date(w);return w})},BooleanString:($)=>{const J=L0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((w)=>{if(typeof w==="string")return w==="true";if($&&!C0.Check(J,w))throw new I("property",J,w);return w}).Encode((w)=>w)},ObjectString:($={},J)=>{const w=V.Object($,J),B=JSON.stringify(C0.Create(w));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),w])).Decode((X)=>{if(typeof X==="string"){try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return X}return X}).Encode((X)=>{if(typeof X==="string")try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return JSON.stringify(X)})},File:LJ,Files:($={})=>V.Transform(HJ($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>V.Union([V.Null(),$]),MaybeEmpty:($)=>V.Union([V.Null(),V.Undefined(),$]),Cookie:($,{domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:S,secure:Q,secrets:G,sign:K,...U}={})=>{const z=V.Object($,U);return z.config={domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:S,secure:Q,secrets:G,sign:K},z}};V.BooleanString=a.BooleanString;V.ObjectString=a.ObjectString;V.Numeric=a.Numeric;V.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>a.Nullable($);V.MaybeEmpty=a.MaybeEmpty;V.Cookie=a.Cookie;V.Date=a.Date;class s{config;server=null;dependencies={};reporter=new H1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new B0,ws:new B0,dynamic:new B0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new z1;constructor($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const J=o1({globalHook:this.event,localHook:$}),w={events:{global:this.event,local:$},onParse:J("parse"),onTransform:J("transform"),onBeforeHandle:J("beforeHandle"),onAfterHandle:J("afterHandle"),onResponse:J("onResponse"),mapResponse:J("mapResponse"),onError:J("error")};for(let B of this.extender.macros)R1(B.fn(w),$)}}add($,J,w,B,{allowMeta:X=!1,skipPrefix:W=!1}={allowMeta:!1,skipPrefix:!1}){if(B=a1(B),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!W&&!this.config.scoped)J=this.config.prefix+J;if(B?.type)switch(B.type){case"text":B.type="text/plain";break;case"json":B.type="application/json";break;case"formdata":B.type="multipart/form-data";break;case"urlencoded":B.type="application/x-www-form-urlencoded";break;case"arrayBuffer":B.type="application/octet-stream";break;default:break}const Z=this.definitions.type;let S,Q,G,K,U,z;const F=!this.config.aot,C={body:B?.body??this.validator?.body,headers:B?.headers??this.validator?.headers,params:B?.params??this.validator?.params,query:B?.query??this.validator?.query,cookie:B?.cookie??this.validator?.cookie,response:B?.response??this.validator?.response},P=()=>C.cookie?s0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:F,models:Z}):void 0,Y=this.config.normalize,R=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:F,models:Z,normalize:Y}),headers:k(C.headers,{dynamic:F,models:Z,additionalProperties:!0}),params:k(C.params,{dynamic:F,models:Z}),query:k(C.query,{dynamic:F,models:Z,normalize:Y}),cookie:P(),response:p0(C.response,{dynamic:F,models:Z,normalize:Y})}:{get body(){if(S)return S;return S=k(C.body,{dynamic:F,models:Z,normalize:Y})},get headers(){if(Q)return Q;return k(C.headers,{dynamic:F,models:Z,additionalProperties:!0})},get params(){if(G)return G;return G=k(C.params,{dynamic:F,models:Z})},get query(){if(K)return K;return K=k(C.query,{dynamic:F,models:Z})},get cookie(){if(U)return U;return U=P()},get response(){if(z)return z;return z=p0(C.response,{dynamic:F,models:Z,normalize:Y})}},M=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(B=u(B,{},{allowMacro:!0}),B.tags)if(!B.detail)B.detail={tags:B.tags};else B.detail.tags=B.tags;if(m(this.config.detail))B.detail=p(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const D=u(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:R,hooks:D,content:B?.type,handle:w}),this.config.strictPath===!1)this.router.dynamic.add($,M,{validator:R,hooks:D,content:B?.type,handle:w});this.router.history.push({method:$,path:J,composed:null,handler:w,hooks:D});return}let T=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=t0(this.inference),v=q?a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e}):(A)=>{if(T)return T(A);return(T=a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e}))(A)};if(!q)v.compose=()=>{return v.composed=a0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:R,handler:w,allowMeta:X,appInference:e})};let t=this.router.history.length;if(this.routeTree.has($+J)){if(t=this.router.history.findIndex((A)=>A.path===J&&A.method===$),t!==-1){const A=this.router.history.splice(t,1)[0];if(A&&this.routeTree.has(A?.method+A?.path))this.routeTree.delete(A.method+A.path)}}this.routeTree.set($+J,t),this.router.history.push({method:$,path:J,composed:v,handler:w,hooks:D});const O=this.router.static.http;if($==="$INTERNALWS"){const A=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,A)this.router.static.ws[A]=$0}else if(this.router.ws.add("ws",J,v),A)this.router.ws.add("ws",A,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const A=O.handlers.length;if(O.handlers.push(v),O.variables+=q?`const st${A} = staticRouter.handlers[${A}]\n`:`let st${A} = staticRouter.handlers[${A}]\nlet stc${A}\n`,!O.map[J])O.map[J]={code:""};if($==="ALL")O.map[J].all=q?`default: return st${A}(ctx)\n`:`default: ${E0(A)}\n`;else O.map[J].code=q?`case '${$}': return st${A}(ctx)\n${O.map[J].code}`:`case '${$}': ${E0(A)}\n${O.map[J].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if($==="ALL")O.map[M].all=q?`default: return st${A}(ctx)\n`:`default: ${E0(A)}\n`;else O.map[M].code=q?`case '${$}': return st${A}(ctx)\n${O.map[M].code}`:`case '${$}': ${E0(A)}\n${O.map[M].code}`}}else if(this.router.http.add($,J,v),!this.config.strictPath)this.router.http.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,J){if(!J)return this.on("parse",$);return this.on($,"parse",J)}onTransform($,J){if(!J)return this.on("transform",$);return this.on($,"transform",J)}resolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}mapResolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}onBeforeHandle($,J){if(!J)return this.on("beforeHandle",$);return this.on($,"beforeHandle",J)}onAfterHandle($,J){if(!J)return this.on("afterHandle",$);return this.on($,"afterHandle",J)}mapResponse($,J){if(!J)return this.on("mapResponse",$);return this.on($,"mapResponse",J)}onResponse($,J){if(!J)return this.on("response",$);return this.on($,"response",J)}trace($,J){if(!J)J=$,$={as:"local"};if(!Array.isArray(J))J=[J];for(let w of J)this.reporter.on("event",x1(()=>this.reporter,this.event.trace.length,w));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Z0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[w,B]of Object.entries($))B.prototype[Z0]=w,this.definitions.error[w]=B;return this}onError($,J){if(!J)return this.on("error",$);return this.on($,"error",J)}onStop($){return this.on("stop",$),this}on($,J,w){let B;switch(typeof $){case"string":B=$,w=J;break;case"object":B=J;break}if(B==="response")B="onResponse";if(Array.isArray(w))w=c(w);else if(typeof w==="function")w=[{fn:w}];else w=[w];const X=w;for(let W of X)W.scope=typeof $==="string"?"local":$?.as??"local";if(B==="trace")f1(X.map((W)=>W.fn),this.inference.trace);else h0({[B]:X.map((W)=>W.fn)},this.inference.event);for(let W of X){const Z=n1(W,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(Z);break;case"request":this.event.request.push(Z);break;case"parse":this.event.parse.push(Z);break;case"transform":this.event.transform.push(Z);break;case"beforeHandle":this.event.beforeHandle.push(Z);break;case"afterHandle":this.event.afterHandle.push(Z);break;case"mapResponse":this.event.mapResponse.push(Z);break;case"onResponse":this.event.onResponse.push(Z);break;case"trace":this.event.trace.push(Z);break;case"error":this.event.error.push(Z);break;case"stop":this.event.stop.push(Z);break}}return this}propagate(){const $=(J)=>{for(let w of J)if("scope"in w&&w.scope==="local")w.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,J,w){const B=new s({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=t0(this.inference),B.extender={...this.extender};const X=typeof J==="object",W=(X?w:J)(B);if(this.singleton=p(this.singleton,B.singleton),this.definitions=p(this.definitions,B.definitions),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(B.router.history).forEach(({method:Z,path:S,handler:Q,hooks:G})=>{if(S=(X?"":this.config.prefix)+$+S,X){const K=J,U=G;this.add(Z,S,Q,u(K,{...U||{},error:!U.error?W.event.error:Array.isArray(U.error)?[...U.error||{},...W.event.error||{}]:[U.error,...W.event.error||{}]}))}else this.add(Z,S,Q,u(G,{error:W.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=l0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const w=new s({...this.config,prefix:""});w.singleton={...this.singleton},w.definitions={...this.definitions},w.inference=t0(this.inference),w.extender={...this.extender};const B=J(w);if(this.singleton=p(this.singleton,w.singleton),this.definitions=p(this.definitions,w.definitions),B.getServer=()=>this.server,B.event.request.length)this.event.request=[...this.event.request||[],...B.event.request||[]];if(B.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...B.event.onResponse||[]];return this.model(B.definitions.type),Object.values(w.router.history).forEach(({method:X,path:W,handler:Z,hooks:S})=>{this.add(X,W,Z,u($,{...S||{},error:!S.error?B.event.error:Array.isArray(S.error)?[...S.error||{},...B.event.error||[]]:[S.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(w)=>w.use($));if(Array.isArray($)){let w=this;for(let B of $)w=this.use(B);return w}if($ instanceof Promise)return this.promisedModules.add($.then((w)=>{if(typeof w==="function")return w(this);if(w instanceof s)return this._use(w);if(typeof w.default==="function")return w.default(this);if(w.default instanceof s)return this._use(w.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((w)=>w.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const X=$(this);if(X instanceof Promise)return this.promisedModules.add(X.then((W)=>{if(W instanceof s){this.compile();for(let{method:Z,path:S,handler:Q,hooks:G}of Object.values(W.router.history))this.add(Z,S,Q,u(G,{error:W.event.error}));return W}if(typeof W==="function")return W(this);if(typeof W.default==="function")return W.default(this);return this._use(W)}).then((W)=>W.compile())),this;return X}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((X)=>X.compile())),this;const{name:J,seed:w}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const B=$.config.scoped;if(B){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?V0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:Z})=>W===Z))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<$.extender.macros.length;W++){const Z=this.extender.macros[W];if(X.includes(Z.checksum))$.extender.macros.splice(W,1),W--;X.push(Z.checksum)}if($.onRequest((W)=>{Object.assign(W,this.singleton.decorator),Object.assign(W.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(B===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let W of $.event.trace)if(W.scope&&W.scope!=="local")this.trace(W);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?V0(J+JSON.stringify(w)):0;if(!this.dependencies[J].some(({checksum:Z})=>W===Z))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<this.extender.macros.length;W++){const Z=this.extender.macros[W];if(Z.checksum){if(X.includes(Z.checksum))this.extender.macros.splice(W,1),W--;X.push(Z.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:X,path:W,handler:Z,hooks:S}of Object.values($.router.history))this.add(X,W,Z,u(S,{error:$.event.error}));if(!B)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const X=w!==void 0?V0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:W})=>X===W))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((W)=>W?.subType==="derive").map((W)=>({fn:W.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((W)=>W?.subType==="resolve").map((W)=>({fn:W.toString(),stack:new Error().stack??""}))}),this.event=l0(this.event,U1($.event),X)}else this.event=l0(this.event,U1($.event));return this}macro($){const J={checksum:V0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof s||typeof $==="function"||$.length===0||$==="/"){const X=typeof $==="function"?$:$ instanceof s?$.compile().fetch:J instanceof s?J.compile().fetch:J,W=async({request:Z,path:S})=>X(new Request(K1(Z.url,S||"/"),Z));return this.all("/*",W,{type:"none"}),this}const w=$.length;if(J instanceof s)J=J.compile().fetch;const B=async({request:X,path:W})=>J(new Request(K1(X.url,W.slice(w)||"/"),X));return this.all($,B,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get($,J,w){return this.add("GET",$,J,w),this}post($,J,w){return this.add("POST",$,J,w),this}put($,J,w){return this.add("PUT",$,J,w),this}patch($,J,w){return this.add("PATCH",$,J,w),this}delete($,J,w){return this.add("DELETE",$,J,w),this}options($,J,w){return this.add("OPTIONS",$,J,w),this}all($,J,w){return this.add("ALL",$,J,w),this}head($,J,w){return this.add("HEAD",$,J,w),this}connect($,J,w){return this.add("CONNECT",$,J,w),this}route($,J,w,B){return this.add($.toUpperCase(),J,w,B,B?.config),this}ws($,J){const w=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let B=null;const X=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),W=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Z=(S)=>{if(typeof S==="string"){const Q=S?.charCodeAt(0);if(Q===47||Q===123)try{S=JSON.parse(S)}catch{}else if(R0(S))S=+S}if(w?.length)for(let Q=0;Q<w.length;Q++){const G=w[Q](S);if(G!==void 0)S=G}return S};return this.route("$INTERNALWS",$,(S)=>{const{set:Q,path:G,qi:K,headers:U,query:z,params:F}=S;if(B===null)B=this.getServer();if(B?.upgrade(S.request,{headers:typeof J.upgrade==="function"?J.upgrade(S):J.upgrade,data:{validator:W,open(C){J.open?.(new j0(C,S))},message:(C,P)=>{const Y=Z(P);if(X?.Check(Y)===!1)return void C.send(new I("message",X,Y).message);J.message?.(new j0(C,S),Y)},drain(C){J.drain?.(new j0(C,S))},close(C,P,Y){J.close?.(new j0(C,S),P,Y)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:J.beforeHandle,transform:J.transform,headers:J.headers,params:J.params,query:J.query}),this}state($,J){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=J;return this}decorate($,J){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=J;return this}derive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}model($,J){switch(typeof $){case"object":return Object.entries($).forEach(([w,B])=>{if(!(w in this.definitions.type))this.definitions.type[w]=B}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=J,this}mapDerive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}affix($,J,w){if(w==="")return this;const B=["_","-"," "],X=(Q)=>Q[0].toUpperCase()+Q.slice(1),W=$==="prefix"?(Q,G)=>B.includes(Q.at(-1)??"")?Q+G:Q+X(G):B.includes(w.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+X(Q),Z=(Q)=>{const G={};switch(Q){case"decorator":for(let K in this.singleton.decorator)G[W(w,K)]=this.singleton.decorator[K];this.singleton.decorator=G;break;case"state":for(let K in this.singleton.store)G[W(w,K)]=this.singleton.store[K];this.singleton.store=G;break;case"model":for(let K in this.definitions.type)G[W(w,K)]=this.definitions.type[K];this.definitions.type=G;break;case"error":for(let K in this.definitions.error)G[W(w,K)]=this.definitions.error[K];this.definitions.error=G;break}},S=Array.isArray(J)?J:[J];for(let Q of S.some((G)=>G==="all")?["decorator","state","model","error"]:S)Z(Q);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?N1(this):P1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?N1(this):P1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?A1(this):C$(this))($,J);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,J)=>{if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof $==="string"){if(!R0($))throw new Error("Port must be a numeric value");$=parseInt($)}const w=this.fetch,B=typeof $==="object"?{development:!q0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...F1||{}},fetch:w,error:this.outerErrorHandler}:{development:!q0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...F1||{}},port:$,fetch:w,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let X=0;X<this.event.start.length;X++)this.event.start[X].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let X=0;X<this.event.stop.length;X++)this.event.stop[X].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,_1 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,p0 as getResponseSchemaValidator,j1 as error,s as default,I as ValidationError,X0 as StatusMap,o0 as ParseError,S0 as NotFoundError,i0 as InvertedStatusMap,P0 as InvalidCookieSignature,n0 as InternalServerError,s as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
441
441
|
|
|
442
|
-
//# debugId=
|
|
442
|
+
//# debugId=5AE97CB2FA56444B64756e2164756e21
|