elysia 1.0.12 → 1.0.13

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.
@@ -1412,5 +1412,5 @@ export { Cookie, type CookieOptions } from './cookies';
1412
1412
  export { getSchemaValidator, mergeHook, mergeObjectArray, getResponseSchemaValidator, StatusMap, InvertedStatusMap } from './utils';
1413
1413
  export { error, ParseError, NotFoundError, ValidationError, InternalServerError, InvalidCookieSignature, ERROR_CODE, ELYSIA_RESPONSE } from './error';
1414
1414
  export type { Context, PreContext } from './context';
1415
- export type { EphemeralType, CreateEden, ComposeElysiaResponse, ElysiaConfig, SingletonBase, DefinitionBase, RouteBase, Handler, ComposedHandler, InputSchema, LocalHook, MergeSchema, RouteSchema, UnwrapRoute, InternalRoute, HTTPMethod, SchemaValidator, VoidHandler, PreHandler, BodyHandler, OptionalHandler, ErrorHandler, AfterHandler, LifeCycleEvent, TraceEvent, LifeCycleStore, LifeCycleType, MaybePromise, ListenCallback, UnwrapSchema, TraceHandler, TraceProcess, TraceReporter, TraceStream, Checksum, DocumentDecoration } from './types';
1415
+ export type { EphemeralType, CreateEden, ComposeElysiaResponse, ElysiaConfig, SingletonBase, DefinitionBase, RouteBase, Handler, ComposedHandler, InputSchema, LocalHook, MergeSchema, RouteSchema, UnwrapRoute, InternalRoute, HTTPMethod, SchemaValidator, VoidHandler, PreHandler, BodyHandler, OptionalHandler, ErrorHandler, AfterHandler, LifeCycleEvent, TraceEvent, LifeCycleStore, LifeCycleType, MaybePromise, ListenCallback, UnwrapSchema, TraceHandler, TraceProcess, TraceReporter, TraceStream, Checksum, DocumentDecoration, InferContext, InferHandler } from './types';
1416
1416
  export type { Static, TSchema } from '@sinclair/typebox';
package/dist/bun/index.js CHANGED
@@ -395,8 +395,6 @@ var g$=Object.create;var{defineProperty:R1,getPrototypeOf:y$,getOwnPropertyNames
395
395
  }\n`;for(let W=0;W<$.event.error.length;W++){const X=$.event.error[W],Z=`${x(X)?"await ":""}onError[${W}](context)`;if(J+="\nif(skipGlobal !== true) {\n",H0(X.fn.toString()))J+=`r = ${Z}; if(r !== undefined) {
396
396
  if(r instanceof Response) return r
397
397
 
398
- console.log(r, error)
399
-
400
398
  if(r[ELYSIA_RESPONSE]) {
401
399
  error.status = error[ELYSIA_RESPONSE]
402
400
  error.message = error.response
@@ -430,4 +428,4 @@ if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
430
428
 
431
429
  return st${$}(ctx)`;var W1=V0(O1(),1);var C1=($)=>async(J)=>{const W=J.url,X=W.indexOf("/",11),Z=W.indexOf("?",X+1),Q=Z===-1?W.substring(X):W.substring(X,Z),G={cookie:{},status:200,headers:{}},Y=Object.assign({},$.singleton.decorator,{set:G,store:$.singleton.store,request:J,path:Q,qi:Z});try{for(let A=0;A<$.event.request.length;A++){const P=$.event.request[A].fn;let N=P(Y);if(N instanceof Promise)N=await N;if(N=u(N,G),N)return N}const B=$.router.dynamic.find(J.method,Q)??$.router.dynamic.find("ALL",Q);if(!B)throw new Y0;const{handle:_,hooks:K,validator:z,content:F}=B.store;let M;if(J.method!=="GET"&&J.method!=="HEAD")if(F)switch(F){case"application/json":M=await J.json();break;case"text/plain":M=await J.text();break;case"application/x-www-form-urlencoded":M=W1.parse(await J.text());break;case"application/octet-stream":M=await J.arrayBuffer();break;case"multipart/form-data":M={};const A=await J.formData();for(let P of A.keys()){if(M[P])continue;const N=A.getAll(P);if(N.length===1)M[P]=N[0];else M[P]=N}break}else{let A=J.headers.get("content-type");if(A){const P=A.indexOf(";");if(P!==-1)A=A.slice(0,P);for(let N=0;N<K.parse.length;N++){const L=K.parse[N].fn;let q=L(Y,A);if(q instanceof Promise)q=await q;if(q){M=q;break}}if(M===void 0)switch(A){case"application/json":M=await J.json();break;case"text/plain":M=await J.text();break;case"application/x-www-form-urlencoded":M=W1.parse(await J.text());break;case"application/octet-stream":M=await J.arrayBuffer();break;case"multipart/form-data":M={};const N=await J.formData();for(let L of N.keys()){if(M[L])continue;const q=N.getAll(L);if(q.length===1)M[L]=q[0];else M[L]=q}break}}}Y.body=M,Y.params=B?.params||void 0,Y.query=Z===-1?{}:W1.parse(W.substring(Z+1)),Y.headers={};for(let[A,P]of J.headers.entries())Y.headers[A]=P;const w=Object.assign({},$.config?.cookie,z?.cookie?.config),I=J.headers.get("cookie");Y.cookie=await l0(Y.set,I,w?{secrets:w.secrets!==void 0?typeof w.secrets==="string"?w.secrets:w.secrets.join(","):void 0,sign:w.sign===!0?!0:w.sign!==void 0?typeof w.sign==="string"?w.sign:w.sign.join(","):void 0}:void 0);for(let A=0;A<K.transform.length;A++){const P=K.transform[A],N=P.fn(Y);if(P.subType==="derive")if(N instanceof Promise)Object.assign(Y,await N);else Object.assign(Y,N);else if(N instanceof Promise)await N}if(z){if(z.headers){const A={};for(let P in J.headers)A[P]=J.headers.get(P);if(z.headers.Check(A)===!1)throw new R("header",z.headers,A)}if(z.params?.Check(Y.params)===!1)throw new R("params",z.params,Y.params);if(z.query?.Check(Y.query)===!1)throw new R("query",z.query,Y.query);if(z.cookie){const A={};for(let[P,N]of Object.entries(Y.cookie))A[P]=N.value;if(z.cookie?.Check(A)===!1)throw new R("cookie",z.cookie,A)}if(z.body?.Check(M)===!1)throw new R("body",z.body,M)}for(let A=0;A<K.beforeHandle.length;A++){let P=K.beforeHandle[A].fn(Y);if(P instanceof Promise)P=await P;if(P!==void 0){Y.response=P;for(let L=0;L<K.afterHandle.length;L++){let q=K.afterHandle[L].fn(Y);if(q instanceof Promise)q=await q;if(q)P=q}const N=u(P,Y.set);if(N)return N}}let U=_(Y);if(U instanceof Promise)U=await U;if(!K.afterHandle.length){const A=z?.response?.[U.status];if(A?.Check(U)===!1)throw new R("response",A,U)}else{Y.response=U;for(let A=0;A<K.afterHandle.length;A++){let P=K.afterHandle[A].fn(Y);if(P instanceof Promise)P=await P;const N=u(P,Y.set);if(N!==void 0){const L=z?.response?.[U.status];if(L?.Check(N)===!1)throw new R("response",L,N);return N}}}if(Y.set.cookie&&w?.sign){const A=!w.secrets?void 0:typeof w.secrets==="string"?w.secrets:w.secrets[0];if(w.sign===!0)for(let[P,N]of Object.entries(Y.set.cookie))Y.set.cookie[P].value=await j0(N.value,"${secret}");else{const P=z?.cookie?.schema?.properties;for(let N of w.sign){if(!(N in P))continue;if(Y.set.cookie[N]?.value)Y.set.cookie[N].value=await j0(Y.set.cookie[N].value,A)}}}return h(U,Y.set)}catch(B){if(B.status)G.status=B.status;return $.handleError(Y,B)}finally{for(let B of $.event.onResponse)await B.fn(Y)}},P$=($)=>async(J,W)=>{const X=Object.assign(J,{error:W,code:W.code});X.set=J.set;for(let Z=0;Z<$.event.error.length;Z++){let G=$.event.error[Z].fn(X);if(G instanceof Promise)G=await G;if(G!==void 0&&G!==null)return h(G,J.set)}return new Response(typeof W.cause==="string"?W.cause:W.message,{headers:J.set.headers,status:W.status??500})};import{TypeRegistry as T$} from"@sinclair/typebox";import{TypeSystem as I0} from"@sinclair/typebox/system";import{Type as g0,FormatRegistry as U0} from"@sinclair/typebox";import{Value as O0} from"@sinclair/typebox/value";var N8=function($){return $%4===0&&($%100!==0||$%400===0)},S$=function($){const J=P8.exec($);if(!J)return!1;const W=+J[1],X=+J[2],Z=+J[3];return X>=1&&X<=12&&Z>=1&&Z<=(X===2&&N8(W)?29:O8[X])},T1=function($){return function J(W){const X=I8.exec(W);if(!X)return!1;const Z=+X[1],Q=+X[2],G=+X[3],Y=X[4],B=X[5]==="-"?-1:1,_=+(X[6]||0),K=+(X[7]||0);if(_>23||K>59||$&&!Y)return!1;if(Z<=23&&Q<=59&&G<60)return!0;const z=Q-K*B,F=Z-_*B-(z<0?1:0);return(F===23||F===-1)&&(z===59||z===-1)&&G<61}},O$=function($){const J=T1($);return function W(X){const Z=X.split(V8);return Z.length===2&&S$(Z[0])&&J(Z[1])}},T8=function($){return S8.test($)&&C8.test($)},q8=function($){return I$.lastIndex=0,I$.test($)},E8=function($){return Number.isInteger($)&&$<=L8&&$>=R8},b8=function($){return Number.isInteger($)},V$=function(){return!0},x8=function($){if(H8.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},X1={date:S$,time:T1(!0),"date-time":O$(!0),"iso-time":T1(!1),"iso-date-time":O$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:T8,"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:x8,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:q8,int32:{type:"number",validate:E8},int64:{type:"number",validate:b8},float:{type:"number",validate:V$},double:{type:"number",validate:V$},password:!0,binary:!0},P8=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,O8=[0,31,28,31,30,31,30,31,31,30,31,30,31],I8=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,V8=/t|\s/i,S8=/\/|:/,C8=/^(?:[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,I$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,R8=-2147483648,L8=2147483647,H8=/[^\\]\\Z/;import{TypeSystemPolicy as a9,TypeSystem as e9,TypeSystemDuplicateFormat as $J,TypeSystemDuplicateTypeKind as JJ} from"@sinclair/typebox/system";import{TypeCompiler as XJ,TypeCheck as ZJ} from"@sinclair/typebox/compiler";var q$=/(\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))/,R$=/(?: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\([^)]+\)/,L$=/^(?:(?:(?:(?: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)?)?$/,g8=X1.date,y8=X1["date-time"];I0.Format("date",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||R$.test(J)||L$.test(J)||g8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});I0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(q$.test(J)||R$.test(J)||L$.test(J)||y8(J)){const W=new Date(J);if(!Number.isNaN(W.getTime()))return!0}return!1});Object.entries(X1).forEach(($)=>{const[J,W]=$;if(!U0.Has(J)){if(W instanceof RegExp)I0.Format(J,(X)=>W.test(X));else if(typeof W==="function")I0.Format(J,W)}});var C=Object.assign({},g0),C$=($)=>{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 $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<C$($.minSize))return!1;if($.maxSize&&J.size>C$($.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},v8=T$.Get("Files")??I0.Type("File",q1),k8=T$.Get("Files")??I0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let W=0;W<J.length;W++)if(!q1($,J[W]))return!1;return!0});if(!U0.Has("numeric"))U0.Set("numeric",($)=>!!$&&!isNaN(+$));if(!U0.Has("boolean"))U0.Set("boolean",($)=>$==="true"||$==="false");if(!U0.Has("ObjectString"))U0.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=g0.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((W)=>{const X=+W;if(isNaN(X))return W;if($&&!O0.Check(J,X))throw new R("property",J,X);return X}).Encode((W)=>W)},Date:($)=>{const J=g0.Date($);return C.Transform(C.Union([g0.Date($),C.String({format:"date",default:(new Date()).toISOString()}),C.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((W)=>{if(W instanceof Date)return W;const X=new Date(W);if(!O0.Check(J,X))throw new R("property",J,X);return X}).Encode((W)=>{if(typeof W==="string")return new Date(W);return W})},BooleanString:($)=>{const J=g0.Boolean($);return C.Transform(C.Union([C.String({format:"boolean",default:!1}),C.Boolean($)],$)).Decode((W)=>{if(typeof W==="string")return W==="true";if($&&!O0.Check(J,W))throw new R("property",J,W);return W}).Encode((W)=>W)},ObjectString:($={},J)=>{const W=C.Object($,J),X=JSON.stringify(O0.Create(W));return C.Transform(C.Union([C.String({format:"ObjectString",default:X}),W])).Decode((Z)=>{if(typeof Z==="string"){try{Z=JSON.parse(Z)}catch{throw new R("property",W,Z)}if(!O0.Check(W,Z))throw new R("property",W,Z);return Z}return Z}).Encode((Z)=>{if(typeof Z==="string")try{Z=JSON.parse(Z)}catch{throw new R("property",W,Z)}if(!O0.Check(W,Z))throw new R("property",W,Z);return JSON.stringify(Z)})},File:v8,Files:($={})=>C.Transform(k8($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,{domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:G,sameSite:Y,secure:B,secrets:_,sign:K,...z}={})=>{const F=C.Object($,z);return F.config={domain:J,expires:W,httpOnly:X,maxAge:Z,path:Q,priority:G,sameSite:Y,secure:B,secrets:_,sign:K},F}};C.BooleanString=a.BooleanString;C.ObjectString=a.ObjectString;C.Numeric=a.Numeric;C.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>a.Nullable($);C.MaybeEmpty=a.MaybeEmpty;C.Cookie=a.Cookie;C.Date=a.Date;class i{config;server=null;dependencies={};reporter=new g1;_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 X0,ws:new X0,dynamic:new X0,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 j1;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=e1({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 X of this.extender.macros)M1(X.fn(W),$)}}add($,J,W,X,{allowMeta:Z=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(X=$$(X),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!Q&&!this.config.scoped)J=this.config.prefix+J;if(X?.type)switch(X.type){case"text":X.type="text/plain";break;case"json":X.type="application/json";break;case"formdata":X.type="multipart/form-data";break;case"urlencoded":X.type="application/x-www-form-urlencoded";break;case"arrayBuffer":X.type="application/octet-stream";break;default:break}const G=this.definitions.type;let Y,B,_,K,z,F;const M=!this.config.aot,w={body:X?.body??this.validator?.body,headers:X?.headers??this.validator?.headers,params:X?.params??this.validator?.params,query:X?.query??this.validator?.query,cookie:X?.cookie??this.validator?.cookie,response:X?.response??this.validator?.response},I=()=>w.cookie?t0({validator:w.cookie,defaultConfig:this.config.cookie,config:w.cookie?.config??{},dynamic:M,models:G}):void 0,U=this.config.normalize,A=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(w.body,{dynamic:M,models:G,normalize:U}),headers:k(w.headers,{dynamic:M,models:G,additionalProperties:!0}),params:k(w.params,{dynamic:M,models:G}),query:k(w.query,{dynamic:M,models:G,normalize:U}),cookie:I(),response:i0(w.response,{dynamic:M,models:G,normalize:U})}:{get body(){if(Y)return Y;return Y=k(w.body,{dynamic:M,models:G,normalize:U})},get headers(){if(B)return B;return k(w.headers,{dynamic:M,models:G,additionalProperties:!0})},get params(){if(_)return _;return _=k(w.params,{dynamic:M,models:G})},get query(){if(K)return K;return K=k(w.query,{dynamic:M,models:G})},get cookie(){if(z)return z;return z=I()},get response(){if(F)return F;return F=i0(w.response,{dynamic:M,models:G,normalize:U})}},P=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(X=f(X,{},{allowMacro:!0}),X.tags)if(!X.detail)X.detail={tags:X.tags};else X.detail.tags=X.tags;if(m(this.config.detail))X.detail=p(Object.assign({},this.config.detail),X.detail);this.applyMacro(X);const N=f(this.event,X);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:A,hooks:N,content:X?.type,handle:W}),this.config.strictPath===!1)this.router.dynamic.add($,P,{validator:A,hooks:N,content:X?.type,handle:W});this.router.history.push({method:$,path:J,composed:null,handler:W,hooks:N});return}let L=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e}):(V)=>{if(L)return L(V);return(L=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e}))(V)};if(!q)v.compose=()=>{return v.composed=J1({app:this,path:J,method:$,localHook:f(X),hooks:N,validator:A,handler:W,allowMeta:Z,appInference:e})};let n=this.router.history.length;if(this.routeTree.has($+J)){if(n=this.router.history.findIndex((V)=>V.path===J&&V.method===$),n!==-1){const V=this.router.history.splice(n,1)[0];if(V&&this.routeTree.has(V?.method+V?.path))this.routeTree.delete(V.method+V.path)}}this.routeTree.set($+J,n),this.router.history.push({method:$,path:J,composed:v,handler:W,hooks:N});const S=this.router.static.http;if($==="$INTERNALWS"){const V=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=S.handlers.length;if(S.handlers.push(v),S.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,V)this.router.static.ws[V]=$0}else if(this.router.ws.add("ws",J,v),V)this.router.ws.add("ws",V,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const V=S.handlers.length;if(S.handlers.push(v),S.variables+=q?`const st${V} = staticRouter.handlers[${V}]\n`:`let st${V} = staticRouter.handlers[${V}]\nlet stc${V}\n`,!S.map[J])S.map[J]={code:""};if($==="ALL")S.map[J].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[J].code=q?`case '${$}': return st${V}(ctx)\n${S.map[J].code}`:`case '${$}': ${x0(V)}\n${S.map[J].code}`;if(!this.config.strictPath){if(!S.map[P])S.map[P]={code:""};if($==="ALL")S.map[P].all=q?`default: return st${V}(ctx)\n`:`default: ${x0(V)}\n`;else S.map[P].code=q?`case '${$}': return st${V}(ctx)\n${S.map[P].code}`:`case '${$}': ${x0(V)}\n${S.map[P].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",y1(()=>this.reporter,this.event.trace.length,W));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[G0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[W,X]of Object.entries($))X.prototype[G0]=W,this.definitions.error[W]=X;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 X;switch(typeof $){case"string":X=$,W=J;break;case"object":X=J;break}if(X==="response")X="onResponse";if(Array.isArray(W))W=c(W);else if(typeof W==="function")W=[{fn:W}];else W=[W];const Z=W;for(let Q of Z)Q.scope=typeof $==="string"?"local":$?.as??"local";if(X==="trace")d1(Z.map((Q)=>Q.fn),this.inference.trace);else d0({[X]:Z.map((Q)=>Q.fn)},this.inference.event);for(let Q of Z){const G=a1(Q,"global",{skipIfHasType:!0});switch(X){case"start":this.event.start.push(G);break;case"request":this.event.request.push(G);break;case"parse":this.event.parse.push(G);break;case"transform":this.event.transform.push(G);break;case"beforeHandle":this.event.beforeHandle.push(G);break;case"afterHandle":this.event.afterHandle.push(G);break;case"mapResponse":this.event.mapResponse.push(G);break;case"onResponse":this.event.onResponse.push(G);break;case"trace":this.event.trace.push(G);break;case"error":this.event.error.push(G);break;case"stop":this.event.stop.push(G);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 X=new i({...this.config,prefix:""});X.singleton={...this.singleton},X.definitions={...this.definitions},X.getServer=()=>this.server,X.inference=r0(this.inference);const Z=typeof J==="object",Q=(Z?W:J)(X);if(this.singleton=p(this.singleton,X.singleton),this.definitions=p(this.definitions,X.definitions),Q.event.request.length)this.event.request=[...this.event.request||[],...Q.event.request||[]];if(Q.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...Q.event.onResponse||[]];return this.model(Q.definitions.type),Object.values(X.router.history).forEach(({method:G,path:Y,handler:B,hooks:_})=>{if(Y=(Z?"":this.config.prefix)+$+Y,Z){const K=J,z=_;this.add(G,Y,B,f(K,{...z||{},error:!z.error?Q.event.error:Array.isArray(z.error)?[...z.error||{},...Q.event.error||{}]:[z.error,...Q.event.error||{}]}))}else this.add(G,Y,B,f(_,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=s0(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 i({...this.config,prefix:""});W.singleton={...this.singleton},W.definitions={...this.definitions},W.inference=r0(this.inference);const X=J(W);if(this.singleton=p(this.singleton,W.singleton),this.definitions=p(this.definitions,W.definitions),X.getServer=()=>this.server,X.event.request.length)this.event.request=[...this.event.request||[],...X.event.request||[]];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...X.event.onResponse||[]];return this.model(X.definitions.type),Object.values(W.router.history).forEach(({method:Z,path:Q,handler:G,hooks:Y})=>{this.add(Z,Q,G,f($,{...Y||{},error:!Y.error?X.event.error:Array.isArray(Y.error)?[...Y.error||{},...X.event.error||[]]:[Y.error,...X.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(W)=>W.use($));if(Array.isArray($)){let W=this;for(let X of $)W=this.use(X);return W}if($ instanceof Promise)return this.promisedModules.add($.then((W)=>{if(typeof W==="function")return W(this);if(W instanceof i)return this._use(W);if(typeof W.default==="function")return W.default(this);if(W.default instanceof i)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 Z=$(this);if(Z instanceof Promise)return this.promisedModules.add(Z.then((Q)=>{if(Q instanceof i){this.compile();for(let{method:G,path:Y,handler:B,hooks:_}of Object.values(Q.router.history))this.add(G,Y,B,f(_,{error:Q.event.error}));return Q}if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return Z}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((Z)=>Z.compile())),this;const{name:J,seed:W}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const X=$.config.scoped;if(X){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?R0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:G})=>Q===G))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Q,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((G)=>G.subType==="derive").map((G)=>({fn:G.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((G)=>G.subType==="derive").map((G)=>({fn:G.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<$.extender.macros.length;Q++){const G=this.extender.macros[Q];if(Z.includes(G.checksum))$.extender.macros.splice(Q,1),Q--;Z.push(G.checksum)}if($.onRequest((Q)=>{Object.assign(Q,this.singleton.decorator),Object.assign(Q.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(X===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let Q of $.router.history)this.routeTree.set(Q.method+`${$.config.prefix}${Q.path}`,this.router.history.length),this.router.history.push({...Q,path:`${$.config.prefix}${Q.path}`,hooks:f(Q.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let Q of $.event.trace)if(Q.scope&&Q.scope!=="local")this.trace(Q);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Q=W!==void 0?R0(J+JSON.stringify(W)):0;if(!this.dependencies[J].some(({checksum:G})=>Q===G))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const Z=[];for(let Q=0;Q<this.extender.macros.length;Q++){const G=this.extender.macros[Q];if(G.checksum){if(Z.includes(G.checksum))this.extender.macros.splice(Q,1),Q--;Z.push(G.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:Z,path:Q,handler:G,hooks:Y}of Object.values($.router.history))this.add(Z,Q,G,f(Y,{error:$.event.error}));if(!X)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const Z=W!==void 0?R0(J+JSON.stringify(W)):0;if(this.dependencies[J].some(({checksum:Q})=>Z===Q))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:Z,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Q)=>Q?.subType==="derive").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Q)=>Q?.subType==="resolve").map((Q)=>({fn:Q.toString(),stack:new Error().stack??""}))}),this.event=s0(this.event,A1($.event),Z)}else this.event=s0(this.event,A1($.event));return this}macro($){const J={checksum:R0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof i||typeof $==="function"||$.length===0||$==="/"){const Z=typeof $==="function"?$:$ instanceof i?$.compile().fetch:J instanceof i?J.compile().fetch:J,Q=async({request:G,path:Y})=>Z(new Request(D1(G.url,Y||"/"),G));return this.all("/*",Q,{type:"none"}),this}const W=$.length;if(J instanceof i)J=J.compile().fetch;const X=async({request:Z,path:Q})=>J(new Request(D1(Z.url,Q.slice(W)||"/"),Z));return this.all($,X,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),X,{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,X){return this.add($.toUpperCase(),J,W,X,X?.config),this}ws($,J){const W=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let X=null;const Z=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),Q=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),G=(Y)=>{if(typeof Y==="string"){const B=Y?.charCodeAt(0);if(B===47||B===123)try{Y=JSON.parse(Y)}catch{}else if(A0(Y))Y=+Y}if(W?.length)for(let B=0;B<W.length;B++){const _=W[B](Y);if(_!==void 0)Y=_}return Y};return this.route("$INTERNALWS",$,(Y)=>{const{set:B,path:_,qi:K,headers:z,query:F,params:M}=Y;if(X===null)X=this.getServer();if(X?.upgrade(Y.request,{headers:typeof J.upgrade==="function"?J.upgrade(Y):J.upgrade,data:{validator:Q,open(w){J.open?.(new w0(w,Y))},message:(w,I)=>{const U=G(I);if(Z?.Check(U)===!1)return void w.send(new R("message",Z,U).message);J.message?.(new w0(w,Y),U)},drain(w){J.drain?.(new w0(w,Y))},close(w,I,U){J.close?.(new w0(w,Y),I,U)}}}))return;return B.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,X])=>{if(!(W in this.definitions.type))this.definitions.type[W]=X}),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 X=["_","-"," "],Z=(B)=>B[0].toUpperCase()+B.slice(1),Q=$==="prefix"?(B,_)=>X.includes(B.at(-1)??"")?B+_:B+Z(_):X.includes(W.at(-1)??"")?(B,_)=>_+B:(B,_)=>_+Z(B),G=(B)=>{const _={};switch(B){case"decorator":for(let K in this.singleton.decorator)_[Q(W,K)]=this.singleton.decorator[K];this.singleton.decorator=_;break;case"state":for(let K in this.singleton.store)_[Q(W,K)]=this.singleton.store[K];this.singleton.store=_;break;case"model":for(let K in this.definitions.type)_[Q(W,K)]=this.definitions.type[K];this.definitions.type=_;break;case"error":for(let K in this.definitions.error)_[Q(W,K)]=this.definitions.error[K];this.definitions.error=_;break}},Y=Array.isArray(J)?J:[J];for(let B of Y.some((_)=>_==="all")?["decorator","state","model","error"]:Y)G(B);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?V1(this):C1(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?V1(this):C1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?S1(this):P$(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(!A0($))throw new Error("Port must be a numeric value");$=parseInt($)}const W=this.fetch,X=typeof $==="object"?{development:!L0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...N1||{}},fetch:W,error:this.outerErrorHandler}:{development:!L0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...N1||{}},port:$,fetch:W,error:this.outerErrorHandler};this.server=Bun?.serve(X);for(let Z=0;Z<this.event.start.length;Z++)this.event.start[Z].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let Z=0;Z<this.event.stop.length;Z++)this.event.stop[Z].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{C as t,H as mergeObjectArray,f as mergeHook,h as mapResponse,u as mapEarlyResponse,o as mapCompactResponse,k as getSchemaValidator,i0 as getResponseSchemaValidator,w1 as error,i as default,R as ValidationError,Z0 as StatusMap,e0 as ParseError,Y0 as NotFoundError,n0 as InvertedStatusMap,C0 as InvalidCookieSignature,a0 as InternalServerError,i as Elysia,G0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
432
430
 
433
- //# debugId=44E2BC18BA4D278764756e2164756e21
431
+ //# debugId=2A3322A1A3C1AD6B64756e2164756e21