elysia 1.0.23 → 1.0.24

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.
@@ -262,7 +262,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
262
262
  } : {
263
263
  derive: Ephemeral['derive'] & Volatile['derive'];
264
264
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
265
- })>>) => MaybePromise<Resolver>): Type extends 'global' ? Elysia<BasePath, Scoped, {
265
+ })>>) => MaybePromise<Resolver | void>): Type extends 'global' ? Elysia<BasePath, Scoped, {
266
266
  decorator: Singleton['decorator'];
267
267
  store: Singleton['store'];
268
268
  derive: Singleton['resolve'];
@@ -291,10 +291,10 @@ export default class Elysia<const in out BasePath extends string = '', const in
291
291
  * }
292
292
  * }))
293
293
  */
294
- resolve<const Resolver extends Record<string, unknown>>(resolver: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
294
+ resolve<const Resolver extends Record<string, unknown> | void>(resolver: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
295
295
  derive: Ephemeral['derive'] & Volatile['derive'];
296
296
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
297
- }, BasePath>>) => MaybePromise<Resolver>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
297
+ }, BasePath>>) => MaybePromise<Resolver | void>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
298
298
  derive: Volatile['resolve'];
299
299
  resolve: Prettify<Volatile['resolve'] & ExcludeElysiaResponse<Resolver>>;
300
300
  schema: Volatile['schema'];
@@ -302,7 +302,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
302
302
  mapResolve<const NewResolver extends Record<string, unknown>>(mapper: (context: Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
303
303
  derive: Ephemeral['derive'] & Volatile['derive'];
304
304
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
305
- }, BasePath>) => MaybePromise<NewResolver>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
305
+ }, BasePath>) => MaybePromise<NewResolver | void>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
306
306
  derive: Volatile['derive'];
307
307
  resolve: NewResolver;
308
308
  schema: Volatile['schema'];
@@ -318,7 +318,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
318
318
  } : {
319
319
  derive: Ephemeral['derive'] & Volatile['derive'];
320
320
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
321
- })>) => MaybePromise<NewResolver>): Type extends 'global' ? Elysia<BasePath, Scoped, {
321
+ })>) => MaybePromise<NewResolver | void>): Type extends 'global' ? Elysia<BasePath, Scoped, {
322
322
  decorator: Singleton['decorator'];
323
323
  store: Singleton['store'];
324
324
  derive: Singleton['resolve'];
@@ -1242,7 +1242,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1242
1242
  * }
1243
1243
  * }))
1244
1244
  */
1245
- derive<const Derivative extends Record<string, unknown>>(transform: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
1245
+ derive<const Derivative extends Record<string, unknown> | void>(transform: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & {
1246
1246
  derive: Ephemeral['derive'] & Volatile['derive'];
1247
1247
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
1248
1248
  }>>) => MaybePromise<Derivative>): Elysia<BasePath, Scoped, Singleton, Definitions, Metadata, Routes, Ephemeral, {
@@ -1265,7 +1265,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1265
1265
  * }
1266
1266
  * }))
1267
1267
  */
1268
- derive<const Derivative extends Record<string, unknown>, const Type extends LifeCycleType>(options: {
1268
+ derive<const Derivative extends Record<string, unknown> | void, const Type extends LifeCycleType>(options: {
1269
1269
  as?: Type;
1270
1270
  }, transform: (context: Prettify<Context<Metadata['schema'] & Ephemeral['schema'] & Volatile['schema'], Singleton & ('global' extends Type ? {
1271
1271
  derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
package/dist/bun/index.js CHANGED
@@ -165,7 +165,10 @@ var Hw=Object.create;var{defineProperty:q1,getPrototypeOf:xw,getOwnPropertyNames
165
165
  ${Y0("headers")}
166
166
  }`,D0(S.headers.schema))Q+="\nc.headers = headers.Decode(c.headers)\n"}if(S.params){if(Q0("default",S.params.schema))for(let[C,K]of Object.entries(C0.Default(S.params.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.params['${C}'] ??= ${z}\n`}if(Q+=`if(params.Check(c.params) === false) {
167
167
  ${Y0("params")}
168
- }`,D0(S.params.schema))Q+="\nc.params = params.Decode(c.params)\n"}if(S.query){if(w0)Q+="c.query = query.Clean(c.query);\n";if(Q0("default",S.query.schema))for(let[C,K]of Object.entries(C0.Default(S.query.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.query['${C}'] ??= ${z}\n`}for(let[C,K]of Object.entries(S.query.schema?.properties)){const{type:z,anyOf:q}=K;if(z==="object"||z==="array"){Q+=`c.query['${C}'] = JSON.parse(c.query['${C}'])\n`;continue}if(q)Q+=`if(typeof c.query['${C}'] === "object") c.query['${C}'] = JSON.parse(c.query['${C}'])\n`}if(Q+=`if(query.Check(c.query) === false) {
168
+ }`,D0(S.params.schema))Q+="\nc.params = params.Decode(c.params)\n"}if(S.query){if(w0)Q+="c.query = query.Clean(c.query);\n";if(Q0("default",S.query.schema))for(let[C,K]of Object.entries(C0.Default(S.query.schema,{}))){const z=typeof K==="object"?JSON.stringify(K):typeof K==="string"?`'${K}'`:K;if(z)Q+=`c.query['${C}'] ??= ${z}\n`}for(let[C,K]of Object.entries(S.query.schema?.properties)){const{type:z,anyOf:q}=K;if(z==="object"||z==="array"){Q+=`\nif(typeof c.query['${C}'] === "string")
169
+ try {
170
+ c.query['${C}'] = JSON.parse(c.query['${C}'])
171
+ } catch {}\n`;continue}if(q)Q+=`if(typeof c.query['${C}'] === "object") c.query['${C}'] = JSON.parse(c.query['${C}'])\n`}if(Q+=`if(query.Check(c.query) === false) {
169
172
  ${Y0("query")}
170
173
  }`,D0(S.query.schema))Q+="\nc.query = query.Decode(Object.assign({}, c.query))\n"}if(S.body){if(w0)Q+="c.body = body.Clean(c.body);\n";if(Q0("default",S.body.schema)){Q+=`if(body.Check(c.body) === false) {
171
174
  if (typeof c.body === 'object') {
@@ -440,4 +443,4 @@ if(st${w}.compose) return (stc${w} = st${w}.compose())(ctx)
440
443
 
441
444
  return st${w}(ctx)`;var $1=P0(M1(),1);var O1=(w)=>async($)=>{const J=$.url,B=J.indexOf("/",11),R=J.indexOf("?",B+1),S=R===-1?J.substring(B):J.substring(B,R),X={cookie:{},status:200,headers:{}},W=Object.assign({},w.singleton.decorator,{set:X,store:w.singleton.store,request:$,path:S,qi:R,redirect:I0});try{for(let j=0;j<w.event.request.length;j++){const A=w.event.request[j].fn;let M=A(W);if(M instanceof Promise)M=await M;if(M=k(M,X),M)return M}const Z=w.router.dynamic.find($.method,S)??w.router.dynamic.find("ALL",S);if(!Z)throw new Z0;const{handle:Y,hooks:G,validator:F,content:U}=Z.store;let _;if($.method!=="GET"&&$.method!=="HEAD")if(U)switch(U){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const j=await $.formData();for(let A of j.keys()){if(_[A])continue;const M=j.getAll(A);if(M.length===1)_[A]=M[0];else _[A]=M}break}else{let j=$.headers.get("content-type");if(j){const A=j.indexOf(";");if(A!==-1)j=j.slice(0,A);W.contentType=j;for(let M=0;M<G.parse.length;M++){const T=G.parse[M].fn;let V=T(W,j);if(V instanceof Promise)V=await V;if(V){_=V;break}}if(delete W.contentType,_===void 0)switch(j){case"application/json":_=await $.json();break;case"text/plain":_=await $.text();break;case"application/x-www-form-urlencoded":_=$1.parse(await $.text());break;case"application/octet-stream":_=await $.arrayBuffer();break;case"multipart/form-data":_={};const M=await $.formData();for(let T of M.keys()){if(_[T])continue;const V=M.getAll(T);if(V.length===1)_[T]=V[0];else _[T]=V}break}}}W.body=_,W.params=Z?.params||void 0,W.query=R===-1?{}:$1.parse(J.substring(R+1)),W.headers={};for(let[j,A]of $.headers.entries())W.headers[j]=A;const D=Object.assign({},w.config?.cookie,F?.cookie?.config),P=$.headers.get("cookie");W.cookie=await p0(W.set,P,D?{secrets:D.secrets!==void 0?typeof D.secrets==="string"?D.secrets:D.secrets.join(","):void 0,sign:D.sign===!0?!0:D.sign!==void 0?typeof D.sign==="string"?D.sign:D.sign.join(","):void 0}:void 0);for(let j=0;j<G.transform.length;j++){const A=G.transform[j],M=A.fn(W);if(A.subType==="derive")if(M instanceof Promise)Object.assign(W,await M);else Object.assign(W,M);else if(M instanceof Promise)await M}if(F){if(F.headers){const j={};for(let A in $.headers)j[A]=$.headers.get(A);if(F.headers.Check(j)===!1)throw new I("header",F.headers,j)}if(F.params?.Check(W.params)===!1)throw new I("params",F.params,W.params);if(F.query?.Check(W.query)===!1)throw new I("query",F.query,W.query);if(F.cookie){const j={};for(let[A,M]of Object.entries(W.cookie))j[A]=M.value;if(F.cookie?.Check(j)===!1)throw new I("cookie",F.cookie,j)}if(F.body?.Check(_)===!1)throw new I("body",F.body,_)}for(let j=0;j<G.beforeHandle.length;j++){let A=G.beforeHandle[j].fn(W);if(A instanceof Promise)A=await A;if(A!==void 0){W.response=A;for(let T=0;T<G.afterHandle.length;T++){let V=G.afterHandle[T].fn(W);if(V instanceof Promise)V=await V;if(V)A=V}const M=k(A,W.set);if(M)return M}}let Q=Y(W);if(Q instanceof Promise)Q=await Q;if(!G.afterHandle.length){const j=F?.response?.[Q.status];if(j?.Check(Q)===!1)throw new I("response",j,Q)}else{W.response=Q;for(let j=0;j<G.afterHandle.length;j++){let A=G.afterHandle[j].fn(W);if(A instanceof Promise)A=await A;const M=k(A,W.set);if(M!==void 0){const T=F?.response?.[Q.status];if(T?.Check(M)===!1)throw new I("response",T,M);return M}}}if(W.set.cookie&&D?.sign){const j=!D.secrets?void 0:typeof D.secrets==="string"?D.secrets:D.secrets[0];if(D.sign===!0)for(let[A,M]of Object.entries(W.set.cookie))W.set.cookie[A].value=await z0(M.value,"${secret}");else{const A=F?.cookie?.schema?.properties;for(let M of D.sign){if(!(M in A))continue;if(W.set.cookie[M]?.value)W.set.cookie[M].value=await z0(W.set.cookie[M].value,j)}}}return v(Q,W.set)}catch(Z){if(Z.status)X.status=Z.status;return w.handleError(W,Z)}finally{for(let Z of w.event.onResponse)await Z.fn(W)}},Dw=(w)=>async($,J)=>{const B=Object.assign($,{error:J,code:J.code});B.set=$.set;for(let R=0;R<w.event.error.length;R++){let X=w.event.error[R].fn(B);if(X instanceof Promise)X=await X;if(X!==void 0&&X!==null)return v(X,$.set)}return new Response(typeof J.cause==="string"?J.cause:J.message,{headers:$.set.headers,status:J.status??500})};import{TypeRegistry as bw} from"@sinclair/typebox";import{TypeSystem as A0} from"@sinclair/typebox/system";import{Type as x0,FormatRegistry as o} from"@sinclair/typebox";import{Value as M0} from"@sinclair/typebox/value";var U$=function(w){return w%4===0&&(w%100!==0||w%400===0)},Pw=function(w){const $=z$.exec(w);if(!$)return!1;const J=+$[1],B=+$[2],R=+$[3];return B>=1&&B<=12&&R>=1&&R<=(B===2&&U$(J)?29:_$[B])},b1=function(w){return function $(J){const B=C$.exec(J);if(!B)return!1;const R=+B[1],S=+B[2],X=+B[3],W=B[4],Z=B[5]==="-"?-1:1,Y=+(B[6]||0),G=+(B[7]||0);if(Y>23||G>59||w&&!W)return!1;if(R<=23&&S<=59&&X<60)return!0;const F=S-G*Z,U=R-Y*Z-(F<0?1:0);return(U===23||U===-1)&&(F===59||F===-1)&&X<61}},Mw=function(w){const $=b1(w);return function J(B){const R=B.split(D$);return R.length===2&&Pw(R[0])&&$(R[1])}},N$=function(w){return M$.test(w)&&A$.test(w)},P$=function(w){return Aw.lastIndex=0,Aw.test(w)},V$=function(w){return Number.isInteger(w)&&w<=b$&&w>=O$},q$=function(w){return Number.isInteger(w)},Nw=function(){return!0},T$=function(w){if(I$.test(w))return!1;try{return new RegExp(w),!0}catch($){return!1}},J1={date:Pw,time:b1(!0),"date-time":Mw(!0),"iso-time":b1(!1),"iso-date-time":Mw(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:N$,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:T$,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:P$,int32:{type:"number",validate:V$},int64:{type:"number",validate:q$},float:{type:"number",validate:Nw},double:{type:"number",validate:Nw},password:!0,binary:!0},z$=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,_$=[0,31,28,31,30,31,30,31,31,30,31,30,31],C$=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,D$=/t|\s/i,M$=/\/|:/,A$=/^(?:[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,Aw=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,O$=-2147483648,b$=2147483647,I$=/[^\\]\\Z/;import{TypeSystemPolicy as oJ,TypeSystem as aJ,TypeSystemDuplicateFormat as eJ,TypeSystemDuplicateTypeKind as wB} from"@sinclair/typebox/system";import{TypeCompiler as JB,TypeCheck as BB} from"@sinclair/typebox/compiler";var Vw=/(\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))/,qw=/(?: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\([^)]+\)/,Iw=/^(?:(?:(?:(?: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)?)?$/,E$=J1.date,L$=J1["date-time"];if(!o.Has("date"))A0.Format("date",(w)=>{const $=w.replace(/"/g,"");if(Vw.test($)||qw.test($)||Iw.test($)||E$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});if(!o.Has("date-time"))A0.Format("date-time",(w)=>{const $=w.replace(/"/g,"");if(Vw.test($)||qw.test($)||Iw.test($)||L$($)){const J=new Date($);if(!Number.isNaN(J.getTime()))return!0}return!1});Object.entries(J1).forEach((w)=>{const[$,J]=w;if(!o.Has($)){if(J instanceof RegExp)A0.Format($,(B)=>J.test(B));else if(typeof J==="function")A0.Format($,J)}});var b=Object.assign({},x0),Ow=(w)=>{if(typeof w==="string")switch(w.slice(-1)){case"k":return+w.slice(0,w.length-1)*1024;case"m":return+w.slice(0,w.length-1)*1048576;default:return+w}return w},V1=(w,$)=>{if(!($ instanceof Blob))return!1;if(w.minSize&&$.size<Ow(w.minSize))return!1;if(w.maxSize&&$.size>Ow(w.maxSize))return!1;if(w.extension)if(typeof w.extension==="string"){if(!$.type.startsWith(w.extension))return!1}else{for(let J=0;J<w.extension.length;J++)if($.type.startsWith(w.extension[J]))return!0;return!1}return!0},H$=bw.Get("Files")??A0.Type("File",V1),x$=bw.Get("Files")??A0.Type("Files",(w,$)=>{if(!Array.isArray($))return V1(w,$);if(w.minItems&&$.length<w.minItems)return!1;if(w.maxItems&&$.length>w.maxItems)return!1;for(let J=0;J<$.length;J++)if(!V1(w,$[J]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",(w)=>!!w&&!isNaN(+w));if(!o.Has("boolean"))o.Set("boolean",(w)=>w==="true"||w==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",(w)=>{let $=w.charCodeAt(0);if($===9||$===10||$===32)$=w.trimStart().charCodeAt(0);if($!==123&&$!==91)return!1;try{return JSON.parse(w),!0}catch{return!1}});var a={Numeric:(w)=>{const $=x0.Number(w);return b.Transform(b.Union([b.String({format:"numeric",default:0}),b.Number(w)],w)).Decode((J)=>{const B=+J;if(isNaN(B))return J;if(w&&!M0.Check($,B))throw new I("property",$,B);return B}).Encode((J)=>J)},Date:(w)=>{const $=x0.Date(w);return b.Transform(b.Union([x0.Date(w),b.String({format:"date",default:(new Date()).toISOString()}),b.String({format:"date-time",default:(new Date()).toISOString()})],w)).Decode((J)=>{if(J instanceof Date)return J;const B=new Date(J);if(!M0.Check($,B))throw new I("property",$,B);return B}).Encode((J)=>{if(typeof J==="string")return new Date(J);return J})},BooleanString:(w)=>{const $=x0.Boolean(w);return b.Transform(b.Union([b.String({format:"boolean",default:!1}),b.Boolean(w)],w)).Decode((J)=>{if(typeof J==="string")return J==="true";if(w&&!M0.Check($,J))throw new I("property",$,J);return J}).Encode((J)=>J)},ObjectString:(w={},$)=>{const J=b.Object(w,$),B=JSON.stringify(M0.Create(J));return b.Transform(b.Union([b.String({format:"ObjectString",default:B}),J])).Decode((R)=>{if(typeof R==="string"){try{R=JSON.parse(R)}catch{throw new I("property",J,R)}if(!M0.Check(J,R))throw new I("property",J,R);return R}return R}).Encode((R)=>{if(typeof R==="string")try{R=JSON.parse(R)}catch{throw new I("property",J,R)}if(!M0.Check(J,R))throw new I("property",J,R);return JSON.stringify(R)})},File:H$,Files:(w={})=>b.Transform(x$(w)).Decode(($)=>{if(Array.isArray($))return $;return[$]}).Encode(($)=>$),Nullable:(w)=>b.Union([b.Null(),w]),MaybeEmpty:(w)=>b.Union([b.Null(),b.Undefined(),w]),Cookie:(w,{domain:$,expires:J,httpOnly:B,maxAge:R,path:S,priority:X,sameSite:W,secure:Z,secrets:Y,sign:G,...F}={})=>{const U=b.Object(w,F);return U.config={domain:$,expires:J,httpOnly:B,maxAge:R,path:S,priority:X,sameSite:W,secure:Z,secrets:Y,sign:G},U}};b.BooleanString=a.BooleanString;b.ObjectString=a.ObjectString;b.Numeric=a.Numeric;b.File=(w={})=>a.File({default:"File",...w,extension:w?.type,type:"string",format:"binary"});b.Files=(w={})=>a.Files({...w,elysiaMeta:"Files",default:"Files",extension:w?.type,type:"array",items:{...w,default:"Files",type:"string",format:"binary"}});b.Nullable=(w)=>a.Nullable(w);b.MaybeEmpty=a.MaybeEmpty;b.Cookie=a.Cookie;b.Date=a.Date;class p{config;server=null;dependencies={};reporter=new x1;_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(w){if(w?.tags)if(!w.detail)w.detail={tags:w.tags};else w.detail.tags=w.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{path:"/"},analytic:!1,forceDynamicQuery:!0,...w,experimental:w?.experimental??{},seed:w?.seed===void 0?"":w?.seed},w?.analytic&&(w?.name||w?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro(w){if(this.extender.macros.length){const $=a1({globalHook:this.event,localHook:w}),J={events:{global:this.event,local:w},onParse:$("parse"),onTransform:$("transform"),onBeforeHandle:$("beforeHandle"),onAfterHandle:$("afterHandle"),onResponse:$("onResponse"),mapResponse:$("mapResponse"),onError:$("error")};for(let B of this.extender.macros)U1(B.fn(J),w)}}add(w,$,J,B,{allowMeta:R=!1,skipPrefix:S=!1}={allowMeta:!1,skipPrefix:!1}){if(B=e1(B),$!==""&&$.charCodeAt(0)!==47)$="/"+$;if(this.config.prefix&&!S&&!this.config.scoped)$=this.config.prefix+$;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 X=this.definitions.type;let W,Z,Y,G,F,U;const _=!this.config.aot,D={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=()=>D.cookie?i0({validator:D.cookie,defaultConfig:this.config.cookie,config:D.cookie?.config??{},dynamic:_,models:X}):void 0,Q=this.config.normalize,j=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:f(D.body,{dynamic:_,models:X,normalize:Q}),headers:f(D.headers,{dynamic:_,models:X,additionalProperties:!0}),params:f(D.params,{dynamic:_,models:X}),query:f(D.query,{dynamic:_,models:X,normalize:Q}),cookie:P(),response:l0(D.response,{dynamic:_,models:X,normalize:Q})}:{get body(){if(W)return W;return W=f(D.body,{dynamic:_,models:X,normalize:Q})},get headers(){if(Z)return Z;return f(D.headers,{dynamic:_,models:X,additionalProperties:!0})},get params(){if(Y)return Y;return Y=f(D.params,{dynamic:_,models:X})},get query(){if(G)return G;return G=f(D.query,{dynamic:_,models:X})},get cookie(){if(F)return F;return F=P()},get response(){if(U)return U;return U=l0(D.response,{dynamic:_,models:X,normalize:Q})}},A=$.endsWith("/")?$.slice(0,$.length-1):$+"/";if(B=h(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=s(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const M=h(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add(w,$,{validator:j,hooks:M,content:B?.type,handle:J}),this.config.strictPath===!1)this.router.dynamic.add(w,A,{validator:j,hooks:M,content:B?.type,handle:J});this.router.history.push({method:w,path:$,composed:null,handler:J,hooks:M});return}let T=void 0;const V=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=n0(this.inference),u=V?w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e}):(N)=>{if(T)return T(N);return(T=w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e}))(N)};if(!V)u.compose=()=>{return u.composed=w1({app:this,path:$,method:w,localHook:h(B),hooks:M,validator:j,handler:J,allowMeta:R,appInference:e})};let l=this.router.history.length;if(this.routeTree.has(w+$)){if(l=this.router.history.findIndex((N)=>N.path===$&&N.method===w),l!==-1){const N=this.router.history.splice(l,1)[0];if(N&&this.routeTree.has(N?.method+N?.path))this.routeTree.delete(N.method+N.path)}}this.routeTree.set(w+$,l),this.router.history.push({method:w,path:$,composed:u,handler:J,hooks:M});const O=this.router.static.http;if(w==="$INTERNALWS"){const N=this.config.strictPath?void 0:$.endsWith("/")?$.slice(0,$.length-1):$+"/";if($.indexOf(":")===-1&&$.indexOf("*")===-1){const w0=O.handlers.length;if(O.handlers.push(u),O.variables+=`const st${w0} = staticRouter.handlers[${w0}]\n`,this.router.static.ws[$]=w0,N)this.router.static.ws[N]=w0}else if(this.router.ws.add("ws",$,u),N)this.router.ws.add("ws",N,u);return}if($.indexOf(":")===-1&&$.indexOf("*")===-1){const N=O.handlers.length;if(O.handlers.push(u),O.variables+=V?`const st${N} = staticRouter.handlers[${N}]\n`:`let st${N} = staticRouter.handlers[${N}]\nlet stc${N}\n`,!O.map[$])O.map[$]={code:""};if(w==="ALL")O.map[$].all=V?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[$].code=V?`case '${w}': return st${N}(ctx)\n${O.map[$].code}`:`case '${w}': ${H0(N)}\n${O.map[$].code}`;if(!this.config.strictPath){if(!O.map[A])O.map[A]={code:""};if(w==="ALL")O.map[A].all=V?`default: return st${N}(ctx)\n`:`default: ${H0(N)}\n`;else O.map[A].code=V?`case '${w}': return st${N}(ctx)\n${O.map[A].code}`:`case '${w}': ${H0(N)}\n${O.map[A].code}`}}else if(this.router.http.add(w,$,u),!this.config.strictPath)this.router.http.add(w,$.endsWith("/")?$.slice(0,$.length-1):$+"/",u)}setHeaders;headers(w){if(!w)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=s(this.setHeaders,w),this}onStart(w){return this.on("start",w),this}onRequest(w){return this.on("request",w),this}onParse(w,$){if(!$)return this.on("parse",w);return this.on(w,"parse",$)}onTransform(w,$){if(!$)return this.on("transform",w);return this.on(w,"transform",$)}resolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}mapResolve(w,$){if(!$)$=w,w={as:"local"};const J={subType:"resolve",fn:$};return this.onBeforeHandle(w,J)}onBeforeHandle(w,$){if(!$)return this.on("beforeHandle",w);return this.on(w,"beforeHandle",$)}onAfterHandle(w,$){if(!$)return this.on("afterHandle",w);return this.on(w,"afterHandle",$)}mapResponse(w,$){if(!$)return this.on("mapResponse",w);return this.on(w,"mapResponse",$)}onResponse(w,$){if(!$)return this.on("response",w);return this.on(w,"response",$)}trace(w,$){if(!$)$=w,w={as:"local"};if(!Array.isArray($))$=[$];for(let J of $)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,J));return this.on(w,"trace",$),this}error(w,$){switch(typeof w){case"string":return $.prototype[W0]=w,this.definitions.error[w]=$,this;case"function":return this.definitions.error=w(this.definitions.error),this}for(let[J,B]of Object.entries(w))B.prototype[W0]=J,this.definitions.error[J]=B;return this}onError(w,$){if(!$)return this.on("error",w);return this.on(w,"error",$)}onStop(w){return this.on("stop",w),this}on(w,$,J){let B;switch(typeof w){case"string":B=w,J=$;break;case"object":B=$;break}if(B==="response")B="onResponse";if(Array.isArray(J))J=c(J);else if(typeof J==="function")J=[{fn:J}];else J=[J];const R=J;for(let S of R)S.scope=typeof w==="string"?"local":w?.as??"local";if(B==="trace")h1(R.map((S)=>S.fn),this.inference.trace);else d0({[B]:R.map((S)=>S.fn)},this.inference.event);for(let S of R){const X=o1(S,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.push(X);break;case"transform":this.event.transform.push(X);break;case"beforeHandle":this.event.beforeHandle.push(X);break;case"afterHandle":this.event.afterHandle.push(X);break;case"mapResponse":this.event.mapResponse.push(X);break;case"onResponse":this.event.onResponse.push(X);break;case"trace":this.event.trace.push(X);break;case"error":this.event.error.push(X);break;case"stop":this.event.stop.push(X);break}}return this}propagate(){const w=($)=>{for(let J of $)if("scope"in J&&J.scope==="local")J.scope="scoped"};return w(this.event.parse),w(this.event.transform),w(this.event.beforeHandle),w(this.event.afterHandle),w(this.event.mapResponse),w(this.event.onResponse),w(this.event.trace),w(this.event.error),this}group(w,$,J){const B=new p({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=n0(this.inference),B.extender={...this.extender};const R=typeof $==="object",S=(R?J:$)(B);if(this.singleton=s(this.singleton,B.singleton),this.definitions=s(this.definitions,B.definitions),S.event.request.length)this.event.request=[...this.event.request||[],...S.event.request||[]];if(S.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...S.event.onResponse||[]];return this.model(S.definitions.type),Object.values(B.router.history).forEach(({method:X,path:W,handler:Z,hooks:Y})=>{if(W=(R?"":this.config.prefix)+w+W,R){const G=$,F=Y;this.add(X,W,Z,h(G,{...F||{},error:!F.error?S.event.error:Array.isArray(F.error)?[...F.error||{},...S.event.error||{}]:[F.error,...S.event.error||{}]}))}else this.add(X,W,Z,h(Y,{error:S.event.error}),{skipPrefix:!0})}),this}guard(w,$){if(!$){if(typeof w==="object"){if(this.applyMacro(w),this.event=t0(this.event,w),this.validator={body:w.body??this.validator?.body,headers:w.headers??this.validator?.headers,params:w.params??this.validator?.params,query:w.query??this.validator?.query,response:w.response??this.validator?.response,cookie:w.cookie??this.validator?.cookie},w.detail)if(this.config.detail)this.config.detail=s(Object.assign({},this.config.detail),w.detail);else this.config.detail=w.detail;if(w?.tags)if(!this.config.detail)this.config.detail={tags:w.tags};else this.config.detail.tags=w.tags;return this}return this.guard({},w)}const J=new p({...this.config,prefix:""});J.singleton={...this.singleton},J.definitions={...this.definitions},J.inference=n0(this.inference),J.extender={...this.extender};const B=$(J);if(this.singleton=s(this.singleton,J.singleton),this.definitions=s(this.definitions,J.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(J.router.history).forEach(({method:R,path:S,handler:X,hooks:W})=>{this.add(R,S,X,h(w,{...W||{},error:!W.error?B.event.error:Array.isArray(W.error)?[...W.error||{},...B.event.error||[]]:[W.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use(w,$){if($?.scoped)return this.guard({},(J)=>J.use(w));if(Array.isArray(w)){let J=this;for(let B of w)J=this.use(B);return J}if(w instanceof Promise)return this.promisedModules.add(w.then((J)=>{if(typeof J==="function")return J(this);if(J instanceof p)return this._use(J);if(typeof J.default==="function")return J.default(this);if(J.default instanceof p)return this._use(J.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((J)=>J.compile())),this;return this._use(w)}_use(w){if(typeof w==="function"){const R=w(this);if(R instanceof Promise)return this.promisedModules.add(R.then((S)=>{if(S instanceof p){this.compile();for(let{method:X,path:W,handler:Z,hooks:Y}of Object.values(S.router.history))this.add(X,W,Z,h(Y,{error:S.event.error}));return S}if(typeof S==="function")return S(this);if(typeof S.default==="function")return S.default(this);return this._use(S)}).then((S)=>S.compile())),this;return R}if(w.promisedModules.size)return this.promisedModules.add(w.modules.then(()=>this._use(w)).then((R)=>R.compile())),this;const{name:$,seed:J}=w.config;w.getServer=()=>this.getServer(),w.model(this.definitions.type),w.error(this.definitions.error);const B=w.config.scoped;if(B){if($){if(!($ in this.dependencies))this.dependencies[$]=[];const S=J!==void 0?q0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:X})=>S===X))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:S,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton.decorator,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((X)=>X.subType==="derive").map((X)=>({fn:X.fn.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((X)=>X.subType==="derive").map((X)=>({fn:X.fn.toString(),stack:new Error().stack??""}))})}w.extender.macros=this.extender.macros.concat(w.extender.macros);const R=[];for(let S=0;S<w.extender.macros.length;S++){const X=this.extender.macros[S];if(R.includes(X.checksum))w.extender.macros.splice(S,1),S--;R.push(X.checksum)}if(w.onRequest((S)=>{Object.assign(S,this.singleton.decorator),Object.assign(S.store,this.singleton.store)}),w.event.trace.length)w.event.trace.push(...w.event.trace);if(!w.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if(w.event.error.length)w.event.error.push(...this.event.error);if(w.config.aot)w.compile();if(B===!0&&w.config.prefix){this.mount(w.config.prefix+"/",w.fetch);for(let S of w.router.history)this.routeTree.set(S.method+`${w.config.prefix}${S.path}`,this.router.history.length),this.router.history.push({...S,path:`${w.config.prefix}${S.path}`,hooks:h(S.hooks,{error:this.event.error})})}else{this.mount(w.fetch);for(let S of w.router.history)this.routeTree.set(S.method+`${w.config.prefix}${S.path}`,this.router.history.length),this.router.history.push({...S,path:`${w.config.prefix}${S.path}`,hooks:h(S.hooks,{error:this.event.error})})}return this}else{this.headers(w.setHeaders),w.reporter=this.reporter;for(let S of w.event.trace)if(S.scope&&S.scope!=="local")this.trace(S);if($){if(!($ in this.dependencies))this.dependencies[$]=[];const S=J!==void 0?q0($+JSON.stringify(J)):0;if(!this.dependencies[$].some(({checksum:X})=>S===X))this.extender.macros=this.extender.macros.concat(w.extender.macros)}else this.extender.macros=this.extender.macros.concat(w.extender.macros);const R=[];for(let S=0;S<this.extender.macros.length;S++){const X=this.extender.macros[S];if(X.checksum){if(R.includes(X.checksum))this.extender.macros.splice(S,1),S--;R.push(X.checksum)}}this.inference={event:{body:this.inference.event.body||w.inference.event.body,cookie:this.inference.event.cookie||w.inference.event.cookie,headers:this.inference.event.headers||w.inference.event.headers,queries:[...this.inference.event.queries,...w.inference.event.queries],query:this.inference.event.query||w.inference.event.query,set:this.inference.event.set||w.inference.event.set,unknownQueries:this.inference.event.unknownQueries||w.inference.event.unknownQueries},trace:{request:this.inference.trace.request||w.inference.trace.request,parse:this.inference.trace.parse||w.inference.trace.parse,transform:this.inference.trace.transform||w.inference.trace.transform,handle:this.inference.trace.handle||w.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||w.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||w.inference.trace.afterHandle,error:this.inference.trace.error||w.inference.trace.error,context:this.inference.trace.context||w.inference.trace.context,store:this.inference.trace.store||w.inference.trace.store,set:this.inference.trace.set||w.inference.trace.set}}}this.decorate(w.singleton.decorator),this.state(w.singleton.store),this.model(w.definitions.type),this.error(w.definitions.error);for(let{method:R,path:S,handler:X,hooks:W}of Object.values(w.router.history))this.add(R,S,X,h(W,{error:w.event.error}));if(!B)if($){if(!($ in this.dependencies))this.dependencies[$]=[];const R=J!==void 0?q0($+JSON.stringify(J)):0;if(this.dependencies[$].some(({checksum:S})=>R===S))return this;this.dependencies[$].push(!this.config?.analytic?{name:w.config.name,seed:w.config.seed,checksum:R,dependencies:w.dependencies}:{name:w.config.name,seed:w.config.seed,checksum:R,dependencies:w.dependencies,stack:w.telemetry.stack,routes:w.router.history,decorators:w.singleton,store:w.singleton.store,type:w.definitions.type,error:w.definitions.error,derive:w.event.transform.filter((S)=>S?.subType==="derive").map((S)=>({fn:S.toString(),stack:new Error().stack??""})),resolve:w.event.transform.filter((S)=>S?.subType==="resolve").map((S)=>({fn:S.toString(),stack:new Error().stack??""}))}),this.event=t0(this.event,j1(w.event),R)}else this.event=t0(this.event,j1(w.event));return this}macro(w){const $={checksum:q0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:w.toString()})),fn:w};return this.extender.macros.push($),this}mount(w,$){if(w instanceof p||typeof w==="function"||w.length===0||w==="/"){const R=typeof w==="function"?w:w instanceof p?w.compile().fetch:$ instanceof p?$.compile().fetch:$,S=async({request:X,path:W})=>R(new Request(K1(X.url,W||"/"),X));return this.all("/*",S,{type:"none"}),this}const J=w.length;if($ instanceof p)$=$.compile().fetch;const B=async({request:R,path:S})=>$(new Request(K1(R.url,S.slice(J)||"/"),R));return this.all(w,B,{type:"none"}),this.all(w+(w.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get(w,$,J){return this.add("GET",w,$,J),this}post(w,$,J){return this.add("POST",w,$,J),this}put(w,$,J){return this.add("PUT",w,$,J),this}patch(w,$,J){return this.add("PATCH",w,$,J),this}delete(w,$,J){return this.add("DELETE",w,$,J),this}options(w,$,J){return this.add("OPTIONS",w,$,J),this}all(w,$,J){return this.add("ALL",w,$,J),this}head(w,$,J){return this.add("HEAD",w,$,J),this}connect(w,$,J){return this.add("CONNECT",w,$,J),this}route(w,$,J,B){return this.add(w.toUpperCase(),$,J,B,B?.config),this}ws(w,$){const J=$.transformMessage?Array.isArray($.transformMessage)?$.transformMessage:[$.transformMessage]:void 0;let B=null;const R=f($?.body,{models:this.definitions.type,normalize:this.config.normalize}),S=f($?.response,{models:this.definitions.type,normalize:this.config.normalize}),X=(W)=>{if(typeof W==="string"){const Z=W?.charCodeAt(0);if(Z===47||Z===123)try{W=JSON.parse(W)}catch{}else if(j0(W))W=+W}if(J?.length)for(let Z=0;Z<J.length;Z++){const Y=J[Z](W);if(Y!==void 0)W=Y}return W};return this.route("$INTERNALWS",w,(W)=>{const{set:Z,path:Y,qi:G,headers:F,query:U,params:_}=W;if(B===null)B=this.getServer();if(B?.upgrade(W.request,{headers:typeof $.upgrade==="function"?$.upgrade(W):$.upgrade,data:{validator:S,open(D){$.open?.(new _0(D,W))},message:(D,P)=>{const Q=X(P);if(R?.Check(Q)===!1)return void D.send(new I("message",R,Q).message);$.message?.(new _0(D,W),Q)},drain(D){$.drain?.(new _0(D,W))},close(D,P,Q){$.close?.(new _0(D,W),P,Q)}}}))return;return Z.status=400,"Expected a websocket connection"},{beforeHandle:$.beforeHandle,transform:$.transform,headers:$.headers,params:$.params,query:$.query}),this}state(w,$){switch(typeof w){case"object":return this.singleton.store=s(this.singleton.store,w),this;case"function":return this.singleton.store=w(this.singleton.store),this}if(!(w in this.singleton.store))this.singleton.store[w]=$;return this}decorate(w,$){switch(typeof w){case"object":return this.singleton.decorator=s(this.singleton.decorator,w),this;case"function":return this.singleton.decorator=w(this.singleton.decorator),this}if(!(w in this.singleton.decorator))this.singleton.decorator[w]=$;return this}derive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}model(w,$){switch(typeof w){case"object":return Object.entries(w).forEach(([J,B])=>{if(!(J in this.definitions.type))this.definitions.type[J]=B}),this;case"function":return this.definitions.type=w(this.definitions.type),this}return this.definitions.type[w]=$,this}mapDerive(w,$){if(!$)$=w,w={as:"local"};const J={subType:"derive",fn:$};return this.onTransform(w,J)}affix(w,$,J){if(J==="")return this;const B=["_","-"," "],R=(Z)=>Z[0].toUpperCase()+Z.slice(1),S=w==="prefix"?(Z,Y)=>B.includes(Z.at(-1)??"")?Z+Y:Z+R(Y):B.includes(J.at(-1)??"")?(Z,Y)=>Y+Z:(Z,Y)=>Y+R(Z),X=(Z)=>{const Y={};switch(Z){case"decorator":for(let G in this.singleton.decorator)Y[S(J,G)]=this.singleton.decorator[G];this.singleton.decorator=Y;break;case"state":for(let G in this.singleton.store)Y[S(J,G)]=this.singleton.store[G];this.singleton.store=Y;break;case"model":for(let G in this.definitions.type)Y[S(J,G)]=this.definitions.type[G];this.definitions.type=Y;break;case"error":for(let G in this.definitions.error)Y[S(J,G)]=this.definitions.error[G];this.definitions.error=Y;break}},W=Array.isArray($)?$:[$];for(let Z of W.some((Y)=>Y==="all")?["decorator","state","model","error"]:W)X(Z);return this}prefix(w,$){return this.affix("prefix",w,$)}suffix(w,$){return this.affix("suffix",w,$)}compile(){if(this.fetch=this.config.aot?N1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async(w)=>this.fetch(w);fetch=(w)=>{return(this.fetch=this.config.aot?N1(this):O1(this))(w)};handleError=async(w,$)=>(this.handleError=this.config.aot?P1(this):Dw(this))(w,$);outerErrorHandler=(w)=>new Response(w.message||w.name||"Error",{status:w?.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 w==="string"){if(!j0(w))throw new Error("Port must be a numeric value");w=parseInt(w)}const J=this.fetch,B=typeof w==="object"?{development:!T0,reusePort:!0,...this.config.serve||{},...w||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:J,error:this.outerErrorHandler}:{development:!T0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:w,fetch:J,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let R=0;R<this.event.start.length;R++)this.event.start[R].fn(this);if($)$(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let R=0;R<this.event.stop.length;R++)this.event.stop[R].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{b as t,I0 as redirect,L as mergeObjectArray,h as mergeHook,v as mapResponse,k as mapEarlyResponse,i as mapCompactResponse,f as getSchemaValidator,l0 as getResponseSchemaValidator,R0 as form,_1 as error,p as default,I as ValidationError,S0 as StatusMap,e0 as ParseError,Z0 as NotFoundError,r0 as InvertedStatusMap,b0 as InvalidCookieSignature,a0 as InternalServerError,p as Elysia,W0 as ERROR_CODE,d as ELYSIA_RESPONSE,n as Cookie};
442
445
 
443
- //# debugId=12D0A25E55A7CBE264756e2164756e21
446
+ //# debugId=48E73300C39FF7AC64756e2164756e21