elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.25k stars 219 forks source link

ReferenceError: Can't find variable: k8 #390

Closed aashari closed 9 months ago

aashari commented 9 months ago

This commit a6bf3d866f6d4c57d21513a0e72c7d423d8cff9a got error:

ReferenceError: Can't find variable: k8
      at /Users/andi/Workspaces/new-workspaces/app/node_modules/elysia/dist/bun/index.js:361:4539

How to Reproduce

Machine Information

muradbu commented 9 months ago

Same problem here when following the quick start.

bun dev
$ bun --watch src/index.ts
356 |               { headers: set.headers, status: error.status }
357 |           )
358 |
359 |       return mapResponse(error, set)
360 |   }
361 | }`,Function("inject",Z)({app:$,mapResponse:d,ERROR_CODE:Z0,ELYSIA_RESPONSE:c})};var c0=b0(z1(),1);var O1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let J;if($.decorators)J=$.decorators,J.request=Z,J.set=X,J.store=$.store;else J={set:X,store:$.store,request:Z};const W=Z.url,B=W.indexOf("/",11),Y=W.indexOf("?",B+1),_=Y===-1?W.substring(B):W.substring(B,Y);try{for(let I=0;I<$.event.request.length;I++){const j=$.event.request[I];let F=j(J);if(F instanceof Promise)F=await F;if(F=u(F,X),F)return F}const Q=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!Q)throw new o;const{handle:G,hooks:z,validator:U,content:V}=Q.store;let P;if(Z.method!=="GET"&&Z.method!=="HEAD")if(V)switch(V){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const I=await Z.formData();for(let j of I.keys()){if(P[j])continue;const F=I.getAll(j);if(F.length===1)P[j]=F[0];else P[j]=F}break}else{let I=Z.headers.get("content-type");if(I){const j=I.indexOf(";");if(j!==-1)I=I.slice(0,j);for(let F=0;F<$.event.parse.length;F++){let R=$.event.parse[F](J,I);if(R instanceof Promise)R=await R;if(R){P=R;break}}if(P===void 0)switch(I){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const F=await Z.formData();for(let R of F.keys()){if(P[R])continue;const D=F.getAll(R);if(D.length===1)P[R]=D[0];else P[R]=D}break}}}J.body=P,J.params=Q?.params||void 0,J.query=Y===-1?{}:c0.parse(W.substring(Y+1)),J.headers={};for(let[I,j]of Z.headers.entries())J.headers[I]=j;const K=U?.cookie?.schema;J.cookie=await v0(J.set,J.headers.cookie,K?{secret:K.secrets!==void 0?typeof K.secrets==="string"?K.secrets:K.secrets.join(","):void 0,sign:K.sign===!0?!0:K.sign!==void 0?typeof K.sign==="string"?K.sign:K.sign.join(","):void 0}:void 0);for(let I=0;I<z.transform.length;I++){const j=z.transform[I](J);if(z.transform[I].$elysia==="derive")if(j instanceof Promise)Object.assign(J,await j);else Object.assign(J,j);else if(j instanceof Promise)await j}if(U){if(U.headers){const I={};for(let j in Z.headers)I[j]=Z.headers.get(j);if(U.headers.Check(I)===!1)throw new E("header",U.headers,I)}if(U.params?.Check(J.params)===!1)throw new E("params",U.params,J.params);if(U.query?.Check(J.query)===!1)throw new E("query",U.query,J.query);if(U.cookie){const I={};for(let[j,F]of Object.entries(J.cookie))I[j]=F.value;if(U.cookie?.Check(I)===!1)throw new E("cookie",U.cookie,I)}if(U.body?.Check(P)===!1)throw new E("body",U.body,P)}for(let I=0;I<z.beforeHandle.length;I++){let j=z.beforeHandle[I](J);if(j instanceof Promise)j=await j;if(j!==void 0){J.response=j;for(let R=0;R<z.afterHandle.length;R++){let D=z.afterHandle[R](J);if(D instanceof Promise)D=await D;if(D)j=D}const F=u(j,J.set);if(F)return F}}let N=G(J);if(N instanceof Promise)N=await N;if(!z.afterHandle.length){const I=U?.response?.[N.status];if(I?.Check(N)===!1)throw new E("response",I,N)}else{J.response=N;for(let I=0;I<z.afterHandle.length;I++){let j=z.afterHandle[I](J);if(j instanceof Promise)j=await j;const F=u(j,J.set);if(F!==void 0){const R=U?.response?.[N.status];if(R?.Check(F)===!1)throw new E("response",R,F);return F}}}if(J.set.cookie&&K?.sign){const I=!K.secrets?void 0:typeof K.secrets==="string"?K.secrets:K.secrets[0];if(K.sign===!0)for(let[j,F]of Object.entries(J.set.cookie))J.set.cookie[j].value=await K0(F.value,"${secret}");else for(let j of K.sign){if(!(j in K.properties))continue;if(J.set.cookie[j]?.value)J.set.cookie[j].value=await K0(J.set.cookie[j].value,I)}}return d(N,J.set)}catch(Q){if(Q.status)X.status=Q.status;return $.handleError(J,Q)}finally{for(let Q of $.event.onResponse)await Q(J)}},J$=($)=>async(Z,X)=>{const J=Object.assign(Z,{error:X,code:X.code});J.set=Z.set;for(let W=0;W<$.event.error.length;W++){let B=$.event.error[W](J);if(B instanceof Promise)B=await B;if(B!==void 0&&B!==null)return d(B,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};var w={};F1(w,{t:()=>{{return C}},ElysiaType:()=>{{return e}}});import{TypeSystem as M0} from"@sinclair/typebox/system";import{Type as W$,FormatRegistry as B$} from"@sinclair/typebox";import{Value as f$} from"@sinclair/typebox/value";T(w,k8);T(w,u8);import"@sinclair/typebox/system";import"@sinclair/typebox/compiler";var C=Object.assign({},W$);try{M0.Format("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.test($)),M0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),M0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),M0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch($){}var X$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},M1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<X$($.minSize))return!1;if($.maxSize&&Z.size>X$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},y$=M0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return M1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!M1($,Z[X]))return!1;return!0});B$.Set("numeric",($)=>!!$&&!isNaN(+$));B$.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var e={Numeric:($)=>{const Z=W$.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((X)=>{const J=+X;if(isNaN(J))return X;if($&&!f$.Check(Z,J))throw new E("property",Z,J);return J}).Encode((X)=>X)},ObjectString:($,Z)=>C.Transform(C.Union([C.String({format:"ObjectString",default:""}),C.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:M0.Type("File",M1),Files:($={})=>C.Transform(C.Union([y$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,Z)=>C.Object($,Z)};C.ObjectString=e.ObjectString;C.Numeric=e.Numeric;C.File=($={})=>e.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>e.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>e.Nullable($);C.MaybeEmpty=e.MaybeEmpty;C.Cookie=e.Cookie;class n{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new T1;server=null;getServer(){return this.server}validator=null;router=new $0;wsRouter=new $0;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new $0;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$,seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,J,{allowMeta:W=!1,skipPrefix:B=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Y of Z){if(Y=Y===""?Y:Y.charCodeAt(0)===47?Y:`/${Y}`,this.config.prefix&&!B)Y=this.config.prefix+Y;if(J?.type)switch(J.type){case"text":J.type="text/plain";break;case"json":J.type="application/json";break;case"formdata":J.type="multipart/form-data";break;case"urlencoded":J.type="application/x-www-form-urlencoded";break;case"arrayBuffer":J.type="application/octet-stream";break;default:break}const _=this.definitions.type;let Q=i(J?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(h(this.config.cookie??{}))if(Q)Q.schema=E1(Q.schema,this.config.cookie??{});else Q=i(C.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const G={body:i(J?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:i(J?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:i(J?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:i(J?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:Q,response:J1(J?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},z=this.event,U=Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(this.macros.length){const I=(F)=>(R,D)=>{if(typeof R==="function"||Array.isArray(R)){if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(Array.isArray(R))J[F]=J[F].concat(R);else J[F].push(R);return}const{insert:k="after",stack:W0="local"}=R;if(W0==="global"){if(!Array.isArray(D))if(k==="before")z[F].unshift(D);else z[F].push(D);else if(k==="before")z[F]=D.concat(z[F]);else z[F]=z[F].concat(D);return}else{if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(!Array.isArray(D))if(k==="before")J[F].unshift(D);else J[F].push(D);else if(k==="before")J[F]=D.concat(J[F]);else J[F]=J[F].concat(D);return}},j={events:{global:z,local:J},onParse:I("parse"),onTransform:I("transform"),onBeforeHandle:I("beforeHandle"),onAfterHandle:I("afterHandle"),onResponse:I("onResponse"),onError:I("error")};for(let F of this.macros){const R={};for(let[k,W0]of Object.entries(J??{})){if(Z1.includes(k))continue;R[k]=W0}if(!F.$elysiaChecksum)F.$elysiaChecksum=[];const D=z0(JSON.stringify(R));if(F.$elysiaChecksum.includes(D))continue;F.$elysiaChecksum.push(z0(JSON.stringify(R))),W1(F(j),J)}}const V=a(z,J),P=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Y,{validator:G,hooks:V,content:J?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,U,{validator:G,hooks:V,content:J?.type,handle:X});this.routes.push({method:$,path:Y,composed:null,handler:X,hooks:V});return}const K=Z$({path:Y,method:$,hooks:V,validator:G,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:W?this.definitions.type:void 0,schema:W?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!P){const I=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Y}`),store:this.store,path:Y,set:{headers:this.setHeaders??{},status:200}},this.decorators);let j;for(let F of Object.values(V.request))try{const R=u(F(I),I.set);if(R!==void 0){j=R;break}}catch(R){j=this.handleError(I,R);break}if(j)K.response=j;else try{K.response=K(I)}catch(F){K.response=this.handleError(I,F)}}const N=this.routes.findIndex((I)=>I.path===Y&&I.method===$);if(N!==-1)this.routes.splice(N,1);if(this.routes.push({method:$,path:Y,composed:K,handler:X,hooks:V}),$==="$INTERNALWS"){const I=this.config.strictPath?void 0:Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const j=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}].response\n`;else this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}]\n`;if(this.wsPaths[Y]=j,I)this.wsPaths[I]=j}else if(this.wsRouter.add("ws",Y,K),I)this.wsRouter.add("ws",I,K);return}if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const I=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}].response\n`;else this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}]\n`;if(!this.staticRouter.map[Y])this.staticRouter.map[Y]={code:""};if($==="ALL")this.staticRouter.map[Y].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[Y].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[Y].code}`;else this.staticRouter.map[Y].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[Y].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[U])this.staticRouter.map[U]={code:""};if($==="ALL")this.staticRouter.map[U].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[U].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[U].code}`;else this.staticRouter.map[U].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[U].code}`}}else if(this.router.add($,Y,K),!this.config.strictPath)this.router.add($,Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/",K)}}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($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",V1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[Z0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,J]of Object.entries($))J.prototype[Z0]=X,this.definitions.error[X]=J;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=H1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,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"response":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}group($,Z,X){const J=new n({...this.config,prefix:""});J.store=this.store,J.definitions=this.definitions,J.getServer=()=>this.server;const W=typeof Z==="object",B=(W?X:Z)(J);if(this.decorators=p(this.decorators,J.decorators),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.routes).forEach(({method:Y,path:_,handler:Q,hooks:G})=>{if(_=(W?"":this.config.prefix)+$+_,W){const z=Z,U=G;this.add(Y,_,Q,a(z,{...U,error:!U.error?B.event.error:Array.isArray(U.error)?[...U.error,...B.event.error]:[U.error,...B.event.error]}))}else this.add(Y,_,Q,a(G,{error:B.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=m0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new n({...this.config,prefix:""});X.store=this.store,X.definitions=this.definitions;const J=Z(X);if(this.decorators=p(this.decorators,X.decorators),J.event.request.length)this.event.request=[...this.event.request,...J.event.request];if(J.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...J.event.onResponse];return this.model(J.definitions.type),Object.values(X.routes).forEach(({method:W,path:B,handler:Y,hooks:_})=>{this.add(W,B,Y,a($,{..._,error:!_.error?J.event.error:Array.isArray(_.error)?[..._.error,...J.event.error]:[_.error,...J.event.error]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const W=$(this);if(W instanceof Promise)return this.lazyLoadModules.push(W.then((B)=>{if(B instanceof n){this.compile();for(let{method:Y,path:_,handler:Q,hooks:G}of Object.values(B.routes))this.add(Y,_,Q,a(G,{error:B.event.error}));return B}if(typeof B==="function")return B(this);if(typeof B.default==="function")return B.default(this);return this._use(B)}).then((B)=>B.compile())),this;return W}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const J=$.config.scoped;if(J){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const B=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>B===Y))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros,...$.macros],$.onRequest((B)=>{Object.assign(B,this.decorators),Object.assign(B.store,this.store)}),$.event.trace=[...this.event.trace,...$.event.trace],$.config.aot)$.compile();const W=this.mount($.fetch);return this.routes=this.routes.concat(W.routes),this}else{$.reporter=this.reporter;for(let W of $.event.trace)this.trace(W);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:B})=>W===B))this.macros.push(...$.macros)}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:W,path:B,handler:Y,hooks:_}of Object.values($.routes))this.add(W,B,Y,a(_,{error:$.event.error}));if(!J)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:B})=>W===B))return this;this.dependencies[Z].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:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((B)=>B?.$elysia==="derive").map((B)=>({fn:B.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((B)=>B?.$elysia==="resolve").map((B)=>({fn:B.toString(),stack:new Error().stack??""}))}),this.event=m0(this.event,X1($.event),W)}else this.event=m0(this.event,X1($.event));return this}macro($){return this.macros.push($),this}mount($,Z){if($ instanceof n||typeof $==="function"||$.length===0||$==="/"){const W=typeof $==="function"?$:$ instanceof n?$.compile().fetch:Z instanceof n?Z.compile().fetch:Z,B=async({request:Y,path:_})=>W(new Request($1(Y.url,_||"/"),Y));return this.all("/",B,{type:"none"}),this.all("/*",B,{type:"none"}),this}const X=$.length;if(Z instanceof n)Z=Z.compile().fetch;const J=async({request:W,path:B})=>Z(new Request($1(W.url,B.slice(X)||"/"),W));return this.all($,J,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),J,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let J=null;const W=i(Z?.body,{models:this.definitions.type}),B=i(Z?.response,{models:this.definitions.type}),Y=(_)=>{if(typeof _==="string"){const Q=_?.charCodeAt(0);if(Q===47||Q===123)try{_=JSON.parse(_)}catch{}else if(k0(_))_=+_}if(X?.length)for(let Q=0;Q<X.length;Q++){const G=X[Q](_);if(G!==void 0)_=G}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:Q,path:G,qi:z,headers:U,query:V,params:P}=_;if(J===null)J=this.getServer();if(J?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:B,open(K){Z.open?.(new I0(K,_))},message:(K,N)=>{const I=Y(N);if(W?.Check(I)===!1)return void K.send(new E("message",W,I).message);Z.message?.(new I0(K,_),I)},drain(K){Z.drain?.(new I0(K,_))},close(K,N,I){Z.close?.(new I0(K,_),N,I)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:J,...W}={config:{allowMeta:!1}}){return this.add($,Z,X,W,J),this}state($,Z){switch(typeof $){case"object":return this.store=p(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=p(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,J])=>{if(!(X in this.definitions.type))this.definitions.type[X]=J}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const J=["_","-"," "],W=(Q)=>Q[0].toUpperCase()+Q.slice(1),B=$==="prefix"?(Q,G)=>J.includes(Q.at(-1)??"")?Q+G:Q+W(G):J.includes(X.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+W(Q),Y=(Q)=>{const G={};switch(Q){case"decorator":for(let z in this.decorators)G[B(X,z)]=this.decorators[z];this.decorators=G;break;case"state":for(let z in this.store)G[B(X,z)]=this.store[z];this.store=G;break;case"model":for(let z in this.definitions.type)G[B(X,z)]=this.definitions.type[z];this.definitions.type=G;break;case"error":for(let z in this.definitions.error)G[B(X,z)]=this.definitions.error[z];this.definitions.error=G;break}},_=Array.isArray(Z)?Z:[Z];for(let Q of _.some((G)=>G==="all")?["decorator","state","model","error"]:_)Y(Q);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?U1(this):O1(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?U1(this):O1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?I1(this):J$(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{if(!Bun)throw new Error("Bun to run");if(this.compile(),typeof $==="string"){if($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,J=typeof $==="object"?{development:!U0,reusePort:!0,...this.config.serve,...$,websocket:{...this.config.websocket,...Q1},fetch:X,error:this.outerErrorHandler}:{development:!U0,reusePort:!0,...this.config.serve,websocket:{...this.config.websocket,...Q1},port:$,fetch:X,error:this.outerErrorHandler};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.server=Bun?.serve(J),this.event.start.length)for(let W=0;W<this.event.start.length;W++)this.event.start[W](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let W=0;W<this.event.stop.length;W++)this.event.stop[W](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{C as t,L as mergeObjectArray,a as mergeHook,p as mergeDeep,d as mapResponse,u as mapEarlyResponse,t as mapCompactResponse,i as getSchemaValidator,J1 as getResponseSchemaValidator,L1 as error,n as default,E as ValidationError,Y1 as ParseError,o as NotFoundError,_0 as InvalidCookieSignature,w0 as InternalServerError,n as Elysia,m as Cookie};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^
ReferenceError: Can't find variable: k8
      at /Users/murad/Developer/seedbox/node_modules/elysia/dist/bun/index.js:361:4539
356 |               { headers: set.headers, status: error.status }
357 |           )
358 |
359 |       return mapResponse(error, set)
360 |   }
361 | }`,Function("inject",Z)({app:$,mapResponse:d,ERROR_CODE:Z0,ELYSIA_RESPONSE:c})};var c0=b0(z1(),1);var O1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let J;if($.decorators)J=$.decorators,J.request=Z,J.set=X,J.store=$.store;else J={set:X,store:$.store,request:Z};const W=Z.url,B=W.indexOf("/",11),Y=W.indexOf("?",B+1),_=Y===-1?W.substring(B):W.substring(B,Y);try{for(let I=0;I<$.event.request.length;I++){const j=$.event.request[I];let F=j(J);if(F instanceof Promise)F=await F;if(F=u(F,X),F)return F}const Q=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!Q)throw new o;const{handle:G,hooks:z,validator:U,content:V}=Q.store;let P;if(Z.method!=="GET"&&Z.method!=="HEAD")if(V)switch(V){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const I=await Z.formData();for(let j of I.keys()){if(P[j])continue;const F=I.getAll(j);if(F.length===1)P[j]=F[0];else P[j]=F}break}else{let I=Z.headers.get("content-type");if(I){const j=I.indexOf(";");if(j!==-1)I=I.slice(0,j);for(let F=0;F<$.event.parse.length;F++){let R=$.event.parse[F](J,I);if(R instanceof Promise)R=await R;if(R){P=R;break}}if(P===void 0)switch(I){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const F=await Z.formData();for(let R of F.keys()){if(P[R])continue;const D=F.getAll(R);if(D.length===1)P[R]=D[0];else P[R]=D}break}}}J.body=P,J.params=Q?.params||void 0,J.query=Y===-1?{}:c0.parse(W.substring(Y+1)),J.headers={};for(let[I,j]of Z.headers.entries())J.headers[I]=j;const K=U?.cookie?.schema;J.cookie=await v0(J.set,J.headers.cookie,K?{secret:K.secrets!==void 0?typeof K.secrets==="string"?K.secrets:K.secrets.join(","):void 0,sign:K.sign===!0?!0:K.sign!==void 0?typeof K.sign==="string"?K.sign:K.sign.join(","):void 0}:void 0);for(let I=0;I<z.transform.length;I++){const j=z.transform[I](J);if(z.transform[I].$elysia==="derive")if(j instanceof Promise)Object.assign(J,await j);else Object.assign(J,j);else if(j instanceof Promise)await j}if(U){if(U.headers){const I={};for(let j in Z.headers)I[j]=Z.headers.get(j);if(U.headers.Check(I)===!1)throw new E("header",U.headers,I)}if(U.params?.Check(J.params)===!1)throw new E("params",U.params,J.params);if(U.query?.Check(J.query)===!1)throw new E("query",U.query,J.query);if(U.cookie){const I={};for(let[j,F]of Object.entries(J.cookie))I[j]=F.value;if(U.cookie?.Check(I)===!1)throw new E("cookie",U.cookie,I)}if(U.body?.Check(P)===!1)throw new E("body",U.body,P)}for(let I=0;I<z.beforeHandle.length;I++){let j=z.beforeHandle[I](J);if(j instanceof Promise)j=await j;if(j!==void 0){J.response=j;for(let R=0;R<z.afterHandle.length;R++){let D=z.afterHandle[R](J);if(D instanceof Promise)D=await D;if(D)j=D}const F=u(j,J.set);if(F)return F}}let N=G(J);if(N instanceof Promise)N=await N;if(!z.afterHandle.length){const I=U?.response?.[N.status];if(I?.Check(N)===!1)throw new E("response",I,N)}else{J.response=N;for(let I=0;I<z.afterHandle.length;I++){let j=z.afterHandle[I](J);if(j instanceof Promise)j=await j;const F=u(j,J.set);if(F!==void 0){const R=U?.response?.[N.status];if(R?.Check(F)===!1)throw new E("response",R,F);return F}}}if(J.set.cookie&&K?.sign){const I=!K.secrets?void 0:typeof K.secrets==="string"?K.secrets:K.secrets[0];if(K.sign===!0)for(let[j,F]of Object.entries(J.set.cookie))J.set.cookie[j].value=await K0(F.value,"${secret}");else for(let j of K.sign){if(!(j in K.properties))continue;if(J.set.cookie[j]?.value)J.set.cookie[j].value=await K0(J.set.cookie[j].value,I)}}return d(N,J.set)}catch(Q){if(Q.status)X.status=Q.status;return $.handleError(J,Q)}finally{for(let Q of $.event.onResponse)await Q(J)}},J$=($)=>async(Z,X)=>{const J=Object.assign(Z,{error:X,code:X.code});J.set=Z.set;for(let W=0;W<$.event.error.length;W++){let B=$.event.error[W](J);if(B instanceof Promise)B=await B;if(B!==void 0&&B!==null)return d(B,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};var w={};F1(w,{t:()=>{{return C}},ElysiaType:()=>{{return e}}});import{TypeSystem as M0} from"@sinclair/typebox/system";import{Type as W$,FormatRegistry as B$} from"@sinclair/typebox";import{Value as f$} from"@sinclair/typebox/value";T(w,k8);T(w,u8);import"@sinclair/typebox/system";import"@sinclair/typebox/compiler";var C=Object.assign({},W$);try{M0.Format("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.test($)),M0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),M0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),M0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch($){}var X$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},M1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<X$($.minSize))return!1;if($.maxSize&&Z.size>X$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},y$=M0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return M1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!M1($,Z[X]))return!1;return!0});B$.Set("numeric",($)=>!!$&&!isNaN(+$));B$.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var e={Numeric:($)=>{const Z=W$.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((X)=>{const J=+X;if(isNaN(J))return X;if($&&!f$.Check(Z,J))throw new E("property",Z,J);return J}).Encode((X)=>X)},ObjectString:($,Z)=>C.Transform(C.Union([C.String({format:"ObjectString",default:""}),C.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:M0.Type("File",M1),Files:($={})=>C.Transform(C.Union([y$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,Z)=>C.Object($,Z)};C.ObjectString=e.ObjectString;C.Numeric=e.Numeric;C.File=($={})=>e.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>e.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>e.Nullable($);C.MaybeEmpty=e.MaybeEmpty;C.Cookie=e.Cookie;class n{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new T1;server=null;getServer(){return this.server}validator=null;router=new $0;wsRouter=new $0;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new $0;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$,seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,J,{allowMeta:W=!1,skipPrefix:B=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Y of Z){if(Y=Y===""?Y:Y.charCodeAt(0)===47?Y:`/${Y}`,this.config.prefix&&!B)Y=this.config.prefix+Y;if(J?.type)switch(J.type){case"text":J.type="text/plain";break;case"json":J.type="application/json";break;case"formdata":J.type="multipart/form-data";break;case"urlencoded":J.type="application/x-www-form-urlencoded";break;case"arrayBuffer":J.type="application/octet-stream";break;default:break}const _=this.definitions.type;let Q=i(J?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(h(this.config.cookie??{}))if(Q)Q.schema=E1(Q.schema,this.config.cookie??{});else Q=i(C.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const G={body:i(J?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:i(J?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:i(J?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:i(J?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:Q,response:J1(J?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},z=this.event,U=Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(this.macros.length){const I=(F)=>(R,D)=>{if(typeof R==="function"||Array.isArray(R)){if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(Array.isArray(R))J[F]=J[F].concat(R);else J[F].push(R);return}const{insert:k="after",stack:W0="local"}=R;if(W0==="global"){if(!Array.isArray(D))if(k==="before")z[F].unshift(D);else z[F].push(D);else if(k==="before")z[F]=D.concat(z[F]);else z[F]=z[F].concat(D);return}else{if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(!Array.isArray(D))if(k==="before")J[F].unshift(D);else J[F].push(D);else if(k==="before")J[F]=D.concat(J[F]);else J[F]=J[F].concat(D);return}},j={events:{global:z,local:J},onParse:I("parse"),onTransform:I("transform"),onBeforeHandle:I("beforeHandle"),onAfterHandle:I("afterHandle"),onResponse:I("onResponse"),onError:I("error")};for(let F of this.macros){const R={};for(let[k,W0]of Object.entries(J??{})){if(Z1.includes(k))continue;R[k]=W0}if(!F.$elysiaChecksum)F.$elysiaChecksum=[];const D=z0(JSON.stringify(R));if(F.$elysiaChecksum.includes(D))continue;F.$elysiaChecksum.push(z0(JSON.stringify(R))),W1(F(j),J)}}const V=a(z,J),P=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Y,{validator:G,hooks:V,content:J?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,U,{validator:G,hooks:V,content:J?.type,handle:X});this.routes.push({method:$,path:Y,composed:null,handler:X,hooks:V});return}const K=Z$({path:Y,method:$,hooks:V,validator:G,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:W?this.definitions.type:void 0,schema:W?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!P){const I=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Y}`),store:this.store,path:Y,set:{headers:this.setHeaders??{},status:200}},this.decorators);let j;for(let F of Object.values(V.request))try{const R=u(F(I),I.set);if(R!==void 0){j=R;break}}catch(R){j=this.handleError(I,R);break}if(j)K.response=j;else try{K.response=K(I)}catch(F){K.response=this.handleError(I,F)}}const N=this.routes.findIndex((I)=>I.path===Y&&I.method===$);if(N!==-1)this.routes.splice(N,1);if(this.routes.push({method:$,path:Y,composed:K,handler:X,hooks:V}),$==="$INTERNALWS"){const I=this.config.strictPath?void 0:Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const j=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}].response\n`;else this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}]\n`;if(this.wsPaths[Y]=j,I)this.wsPaths[I]=j}else if(this.wsRouter.add("ws",Y,K),I)this.wsRouter.add("ws",I,K);return}if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const I=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}].response\n`;else this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}]\n`;if(!this.staticRouter.map[Y])this.staticRouter.map[Y]={code:""};if($==="ALL")this.staticRouter.map[Y].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[Y].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[Y].code}`;else this.staticRouter.map[Y].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[Y].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[U])this.staticRouter.map[U]={code:""};if($==="ALL")this.staticRouter.map[U].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[U].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[U].code}`;else this.staticRouter.map[U].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[U].code}`}}else if(this.router.add($,Y,K),!this.config.strictPath)this.router.add($,Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/",K)}}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($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",V1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[Z0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,J]of Object.entries($))J.prototype[Z0]=X,this.definitions.error[X]=J;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=H1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,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"response":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}group($,Z,X){const J=new n({...this.config,prefix:""});J.store=this.store,J.definitions=this.definitions,J.getServer=()=>this.server;const W=typeof Z==="object",B=(W?X:Z)(J);if(this.decorators=p(this.decorators,J.decorators),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.routes).forEach(({method:Y,path:_,handler:Q,hooks:G})=>{if(_=(W?"":this.config.prefix)+$+_,W){const z=Z,U=G;this.add(Y,_,Q,a(z,{...U,error:!U.error?B.event.error:Array.isArray(U.error)?[...U.error,...B.event.error]:[U.error,...B.event.error]}))}else this.add(Y,_,Q,a(G,{error:B.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=m0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new n({...this.config,prefix:""});X.store=this.store,X.definitions=this.definitions;const J=Z(X);if(this.decorators=p(this.decorators,X.decorators),J.event.request.length)this.event.request=[...this.event.request,...J.event.request];if(J.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...J.event.onResponse];return this.model(J.definitions.type),Object.values(X.routes).forEach(({method:W,path:B,handler:Y,hooks:_})=>{this.add(W,B,Y,a($,{..._,error:!_.error?J.event.error:Array.isArray(_.error)?[..._.error,...J.event.error]:[_.error,...J.event.error]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const W=$(this);if(W instanceof Promise)return this.lazyLoadModules.push(W.then((B)=>{if(B instanceof n){this.compile();for(let{method:Y,path:_,handler:Q,hooks:G}of Object.values(B.routes))this.add(Y,_,Q,a(G,{error:B.event.error}));return B}if(typeof B==="function")return B(this);if(typeof B.default==="function")return B.default(this);return this._use(B)}).then((B)=>B.compile())),this;return W}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const J=$.config.scoped;if(J){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const B=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>B===Y))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros,...$.macros],$.onRequest((B)=>{Object.assign(B,this.decorators),Object.assign(B.store,this.store)}),$.event.trace=[...this.event.trace,...$.event.trace],$.config.aot)$.compile();const W=this.mount($.fetch);return this.routes=this.routes.concat(W.routes),this}else{$.reporter=this.reporter;for(let W of $.event.trace)this.trace(W);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:B})=>W===B))this.macros.push(...$.macros)}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:W,path:B,handler:Y,hooks:_}of Object.values($.routes))this.add(W,B,Y,a(_,{error:$.event.error}));if(!J)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:B})=>W===B))return this;this.dependencies[Z].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:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((B)=>B?.$elysia==="derive").map((B)=>({fn:B.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((B)=>B?.$elysia==="resolve").map((B)=>({fn:B.toString(),stack:new Error().stack??""}))}),this.event=m0(this.event,X1($.event),W)}else this.event=m0(this.event,X1($.event));return this}macro($){return this.macros.push($),this}mount($,Z){if($ instanceof n||typeof $==="function"||$.length===0||$==="/"){const W=typeof $==="function"?$:$ instanceof n?$.compile().fetch:Z instanceof n?Z.compile().fetch:Z,B=async({request:Y,path:_})=>W(new Request($1(Y.url,_||"/"),Y));return this.all("/",B,{type:"none"}),this.all("/*",B,{type:"none"}),this}const X=$.length;if(Z instanceof n)Z=Z.compile().fetch;const J=async({request:W,path:B})=>Z(new Request($1(W.url,B.slice(X)||"/"),W));return this.all($,J,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),J,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let J=null;const W=i(Z?.body,{models:this.definitions.type}),B=i(Z?.response,{models:this.definitions.type}),Y=(_)=>{if(typeof _==="string"){const Q=_?.charCodeAt(0);if(Q===47||Q===123)try{_=JSON.parse(_)}catch{}else if(k0(_))_=+_}if(X?.length)for(let Q=0;Q<X.length;Q++){const G=X[Q](_);if(G!==void 0)_=G}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:Q,path:G,qi:z,headers:U,query:V,params:P}=_;if(J===null)J=this.getServer();if(J?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:B,open(K){Z.open?.(new I0(K,_))},message:(K,N)=>{const I=Y(N);if(W?.Check(I)===!1)return void K.send(new E("message",W,I).message);Z.message?.(new I0(K,_),I)},drain(K){Z.drain?.(new I0(K,_))},close(K,N,I){Z.close?.(new I0(K,_),N,I)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:J,...W}={config:{allowMeta:!1}}){return this.add($,Z,X,W,J),this}state($,Z){switch(typeof $){case"object":return this.store=p(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=p(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,J])=>{if(!(X in this.definitions.type))this.definitions.type[X]=J}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const J=["_","-"," "],W=(Q)=>Q[0].toUpperCase()+Q.slice(1),B=$==="prefix"?(Q,G)=>J.includes(Q.at(-1)??"")?Q+G:Q+W(G):J.includes(X.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+W(Q),Y=(Q)=>{const G={};switch(Q){case"decorator":for(let z in this.decorators)G[B(X,z)]=this.decorators[z];this.decorators=G;break;case"state":for(let z in this.store)G[B(X,z)]=this.store[z];this.store=G;break;case"model":for(let z in this.definitions.type)G[B(X,z)]=this.definitions.type[z];this.definitions.type=G;break;case"error":for(let z in this.definitions.error)G[B(X,z)]=this.definitions.error[z];this.definitions.error=G;break}},_=Array.isArray(Z)?Z:[Z];for(let Q of _.some((G)=>G==="all")?["decorator","state","model","error"]:_)Y(Q);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?U1(this):O1(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?U1(this):O1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?I1(this):J$(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{if(!Bun)throw new Error("Bun to run");if(this.compile(),typeof $==="string"){if($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,J=typeof $==="object"?{development:!U0,reusePort:!0,...this.config.serve,...$,websocket:{...this.config.websocket,...Q1},fetch:X,error:this.outerErrorHandler}:{development:!U0,reusePort:!0,...this.config.serve,websocket:{...this.config.websocket,...Q1},port:$,fetch:X,error:this.outerErrorHandler};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.server=Bun?.serve(J),this.event.start.length)for(let W=0;W<this.event.start.length;W++)this.event.start[W](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let W=0;W<this.event.stop.length;W++)this.event.stop[W](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{C as t,L as mergeObjectArray,a as mergeHook,p as mergeDeep,d as mapResponse,u as mapEarlyResponse,t as mapCompactResponse,i as getSchemaValidator,J1 as getResponseSchemaValidator,L1 as error,n as default,E as ValidationError,Y1 as ParseError,o as NotFoundError,_0 as InvalidCookieSignature,w0 as InternalServerError,n as Elysia,m as Cookie};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^
ReferenceError: Can't find variable: k8
      at /Users/murad/Developer/seedbox/node_modules/elysia/dist/bun/index.js:361:4539
bun --version
1.0.20
aashari commented 9 months ago

Same problem here when following the quick start.

bun dev
$ bun --watch src/index.ts
356 |                 { headers: set.headers, status: error.status }
357 |             )
358 |
359 |         return mapResponse(error, set)
360 |     }
361 | }`,Function("inject",Z)({app:$,mapResponse:d,ERROR_CODE:Z0,ELYSIA_RESPONSE:c})};var c0=b0(z1(),1);var O1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let J;if($.decorators)J=$.decorators,J.request=Z,J.set=X,J.store=$.store;else J={set:X,store:$.store,request:Z};const W=Z.url,B=W.indexOf("/",11),Y=W.indexOf("?",B+1),_=Y===-1?W.substring(B):W.substring(B,Y);try{for(let I=0;I<$.event.request.length;I++){const j=$.event.request[I];let F=j(J);if(F instanceof Promise)F=await F;if(F=u(F,X),F)return F}const Q=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!Q)throw new o;const{handle:G,hooks:z,validator:U,content:V}=Q.store;let P;if(Z.method!=="GET"&&Z.method!=="HEAD")if(V)switch(V){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const I=await Z.formData();for(let j of I.keys()){if(P[j])continue;const F=I.getAll(j);if(F.length===1)P[j]=F[0];else P[j]=F}break}else{let I=Z.headers.get("content-type");if(I){const j=I.indexOf(";");if(j!==-1)I=I.slice(0,j);for(let F=0;F<$.event.parse.length;F++){let R=$.event.parse[F](J,I);if(R instanceof Promise)R=await R;if(R){P=R;break}}if(P===void 0)switch(I){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const F=await Z.formData();for(let R of F.keys()){if(P[R])continue;const D=F.getAll(R);if(D.length===1)P[R]=D[0];else P[R]=D}break}}}J.body=P,J.params=Q?.params||void 0,J.query=Y===-1?{}:c0.parse(W.substring(Y+1)),J.headers={};for(let[I,j]of Z.headers.entries())J.headers[I]=j;const K=U?.cookie?.schema;J.cookie=await v0(J.set,J.headers.cookie,K?{secret:K.secrets!==void 0?typeof K.secrets==="string"?K.secrets:K.secrets.join(","):void 0,sign:K.sign===!0?!0:K.sign!==void 0?typeof K.sign==="string"?K.sign:K.sign.join(","):void 0}:void 0);for(let I=0;I<z.transform.length;I++){const j=z.transform[I](J);if(z.transform[I].$elysia==="derive")if(j instanceof Promise)Object.assign(J,await j);else Object.assign(J,j);else if(j instanceof Promise)await j}if(U){if(U.headers){const I={};for(let j in Z.headers)I[j]=Z.headers.get(j);if(U.headers.Check(I)===!1)throw new E("header",U.headers,I)}if(U.params?.Check(J.params)===!1)throw new E("params",U.params,J.params);if(U.query?.Check(J.query)===!1)throw new E("query",U.query,J.query);if(U.cookie){const I={};for(let[j,F]of Object.entries(J.cookie))I[j]=F.value;if(U.cookie?.Check(I)===!1)throw new E("cookie",U.cookie,I)}if(U.body?.Check(P)===!1)throw new E("body",U.body,P)}for(let I=0;I<z.beforeHandle.length;I++){let j=z.beforeHandle[I](J);if(j instanceof Promise)j=await j;if(j!==void 0){J.response=j;for(let R=0;R<z.afterHandle.length;R++){let D=z.afterHandle[R](J);if(D instanceof Promise)D=await D;if(D)j=D}const F=u(j,J.set);if(F)return F}}let N=G(J);if(N instanceof Promise)N=await N;if(!z.afterHandle.length){const I=U?.response?.[N.status];if(I?.Check(N)===!1)throw new E("response",I,N)}else{J.response=N;for(let I=0;I<z.afterHandle.length;I++){let j=z.afterHandle[I](J);if(j instanceof Promise)j=await j;const F=u(j,J.set);if(F!==void 0){const R=U?.response?.[N.status];if(R?.Check(F)===!1)throw new E("response",R,F);return F}}}if(J.set.cookie&&K?.sign){const I=!K.secrets?void 0:typeof K.secrets==="string"?K.secrets:K.secrets[0];if(K.sign===!0)for(let[j,F]of Object.entries(J.set.cookie))J.set.cookie[j].value=await K0(F.value,"${secret}");else for(let j of K.sign){if(!(j in K.properties))continue;if(J.set.cookie[j]?.value)J.set.cookie[j].value=await K0(J.set.cookie[j].value,I)}}return d(N,J.set)}catch(Q){if(Q.status)X.status=Q.status;return $.handleError(J,Q)}finally{for(let Q of $.event.onResponse)await Q(J)}},J$=($)=>async(Z,X)=>{const J=Object.assign(Z,{error:X,code:X.code});J.set=Z.set;for(let W=0;W<$.event.error.length;W++){let B=$.event.error[W](J);if(B instanceof Promise)B=await B;if(B!==void 0&&B!==null)return d(B,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};var w={};F1(w,{t:()=>{{return C}},ElysiaType:()=>{{return e}}});import{TypeSystem as M0} from"@sinclair/typebox/system";import{Type as W$,FormatRegistry as B$} from"@sinclair/typebox";import{Value as f$} from"@sinclair/typebox/value";T(w,k8);T(w,u8);import"@sinclair/typebox/system";import"@sinclair/typebox/compiler";var C=Object.assign({},W$);try{M0.Format("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.test($)),M0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),M0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),M0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch($){}var X$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},M1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<X$($.minSize))return!1;if($.maxSize&&Z.size>X$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},y$=M0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return M1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!M1($,Z[X]))return!1;return!0});B$.Set("numeric",($)=>!!$&&!isNaN(+$));B$.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var e={Numeric:($)=>{const Z=W$.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((X)=>{const J=+X;if(isNaN(J))return X;if($&&!f$.Check(Z,J))throw new E("property",Z,J);return J}).Encode((X)=>X)},ObjectString:($,Z)=>C.Transform(C.Union([C.String({format:"ObjectString",default:""}),C.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:M0.Type("File",M1),Files:($={})=>C.Transform(C.Union([y$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,Z)=>C.Object($,Z)};C.ObjectString=e.ObjectString;C.Numeric=e.Numeric;C.File=($={})=>e.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>e.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>e.Nullable($);C.MaybeEmpty=e.MaybeEmpty;C.Cookie=e.Cookie;class n{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new T1;server=null;getServer(){return this.server}validator=null;router=new $0;wsRouter=new $0;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new $0;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$,seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,J,{allowMeta:W=!1,skipPrefix:B=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Y of Z){if(Y=Y===""?Y:Y.charCodeAt(0)===47?Y:`/${Y}`,this.config.prefix&&!B)Y=this.config.prefix+Y;if(J?.type)switch(J.type){case"text":J.type="text/plain";break;case"json":J.type="application/json";break;case"formdata":J.type="multipart/form-data";break;case"urlencoded":J.type="application/x-www-form-urlencoded";break;case"arrayBuffer":J.type="application/octet-stream";break;default:break}const _=this.definitions.type;let Q=i(J?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(h(this.config.cookie??{}))if(Q)Q.schema=E1(Q.schema,this.config.cookie??{});else Q=i(C.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const G={body:i(J?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:i(J?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:i(J?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:i(J?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:Q,response:J1(J?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},z=this.event,U=Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(this.macros.length){const I=(F)=>(R,D)=>{if(typeof R==="function"||Array.isArray(R)){if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(Array.isArray(R))J[F]=J[F].concat(R);else J[F].push(R);return}const{insert:k="after",stack:W0="local"}=R;if(W0==="global"){if(!Array.isArray(D))if(k==="before")z[F].unshift(D);else z[F].push(D);else if(k==="before")z[F]=D.concat(z[F]);else z[F]=z[F].concat(D);return}else{if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(!Array.isArray(D))if(k==="before")J[F].unshift(D);else J[F].push(D);else if(k==="before")J[F]=D.concat(J[F]);else J[F]=J[F].concat(D);return}},j={events:{global:z,local:J},onParse:I("parse"),onTransform:I("transform"),onBeforeHandle:I("beforeHandle"),onAfterHandle:I("afterHandle"),onResponse:I("onResponse"),onError:I("error")};for(let F of this.macros){const R={};for(let[k,W0]of Object.entries(J??{})){if(Z1.includes(k))continue;R[k]=W0}if(!F.$elysiaChecksum)F.$elysiaChecksum=[];const D=z0(JSON.stringify(R));if(F.$elysiaChecksum.includes(D))continue;F.$elysiaChecksum.push(z0(JSON.stringify(R))),W1(F(j),J)}}const V=a(z,J),P=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Y,{validator:G,hooks:V,content:J?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,U,{validator:G,hooks:V,content:J?.type,handle:X});this.routes.push({method:$,path:Y,composed:null,handler:X,hooks:V});return}const K=Z$({path:Y,method:$,hooks:V,validator:G,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:W?this.definitions.type:void 0,schema:W?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!P){const I=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Y}`),store:this.store,path:Y,set:{headers:this.setHeaders??{},status:200}},this.decorators);let j;for(let F of Object.values(V.request))try{const R=u(F(I),I.set);if(R!==void 0){j=R;break}}catch(R){j=this.handleError(I,R);break}if(j)K.response=j;else try{K.response=K(I)}catch(F){K.response=this.handleError(I,F)}}const N=this.routes.findIndex((I)=>I.path===Y&&I.method===$);if(N!==-1)this.routes.splice(N,1);if(this.routes.push({method:$,path:Y,composed:K,handler:X,hooks:V}),$==="$INTERNALWS"){const I=this.config.strictPath?void 0:Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const j=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}].response\n`;else this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}]\n`;if(this.wsPaths[Y]=j,I)this.wsPaths[I]=j}else if(this.wsRouter.add("ws",Y,K),I)this.wsRouter.add("ws",I,K);return}if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const I=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}].response\n`;else this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}]\n`;if(!this.staticRouter.map[Y])this.staticRouter.map[Y]={code:""};if($==="ALL")this.staticRouter.map[Y].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[Y].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[Y].code}`;else this.staticRouter.map[Y].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[Y].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[U])this.staticRouter.map[U]={code:""};if($==="ALL")this.staticRouter.map[U].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[U].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[U].code}`;else this.staticRouter.map[U].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[U].code}`}}else if(this.router.add($,Y,K),!this.config.strictPath)this.router.add($,Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/",K)}}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($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",V1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[Z0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,J]of Object.entries($))J.prototype[Z0]=X,this.definitions.error[X]=J;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=H1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,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"response":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}group($,Z,X){const J=new n({...this.config,prefix:""});J.store=this.store,J.definitions=this.definitions,J.getServer=()=>this.server;const W=typeof Z==="object",B=(W?X:Z)(J);if(this.decorators=p(this.decorators,J.decorators),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.routes).forEach(({method:Y,path:_,handler:Q,hooks:G})=>{if(_=(W?"":this.config.prefix)+$+_,W){const z=Z,U=G;this.add(Y,_,Q,a(z,{...U,error:!U.error?B.event.error:Array.isArray(U.error)?[...U.error,...B.event.error]:[U.error,...B.event.error]}))}else this.add(Y,_,Q,a(G,{error:B.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=m0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new n({...this.config,prefix:""});X.store=this.store,X.definitions=this.definitions;const J=Z(X);if(this.decorators=p(this.decorators,X.decorators),J.event.request.length)this.event.request=[...this.event.request,...J.event.request];if(J.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...J.event.onResponse];return this.model(J.definitions.type),Object.values(X.routes).forEach(({method:W,path:B,handler:Y,hooks:_})=>{this.add(W,B,Y,a($,{..._,error:!_.error?J.event.error:Array.isArray(_.error)?[..._.error,...J.event.error]:[_.error,...J.event.error]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const W=$(this);if(W instanceof Promise)return this.lazyLoadModules.push(W.then((B)=>{if(B instanceof n){this.compile();for(let{method:Y,path:_,handler:Q,hooks:G}of Object.values(B.routes))this.add(Y,_,Q,a(G,{error:B.event.error}));return B}if(typeof B==="function")return B(this);if(typeof B.default==="function")return B.default(this);return this._use(B)}).then((B)=>B.compile())),this;return W}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const J=$.config.scoped;if(J){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const B=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>B===Y))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros,...$.macros],$.onRequest((B)=>{Object.assign(B,this.decorators),Object.assign(B.store,this.store)}),$.event.trace=[...this.event.trace,...$.event.trace],$.config.aot)$.compile();const W=this.mount($.fetch);return this.routes=this.routes.concat(W.routes),this}else{$.reporter=this.reporter;for(let W of $.event.trace)this.trace(W);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:B})=>W===B))this.macros.push(...$.macros)}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:W,path:B,handler:Y,hooks:_}of Object.values($.routes))this.add(W,B,Y,a(_,{error:$.event.error}));if(!J)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:B})=>W===B))return this;this.dependencies[Z].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:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((B)=>B?.$elysia==="derive").map((B)=>({fn:B.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((B)=>B?.$elysia==="resolve").map((B)=>({fn:B.toString(),stack:new Error().stack??""}))}),this.event=m0(this.event,X1($.event),W)}else this.event=m0(this.event,X1($.event));return this}macro($){return this.macros.push($),this}mount($,Z){if($ instanceof n||typeof $==="function"||$.length===0||$==="/"){const W=typeof $==="function"?$:$ instanceof n?$.compile().fetch:Z instanceof n?Z.compile().fetch:Z,B=async({request:Y,path:_})=>W(new Request($1(Y.url,_||"/"),Y));return this.all("/",B,{type:"none"}),this.all("/*",B,{type:"none"}),this}const X=$.length;if(Z instanceof n)Z=Z.compile().fetch;const J=async({request:W,path:B})=>Z(new Request($1(W.url,B.slice(X)||"/"),W));return this.all($,J,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),J,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let J=null;const W=i(Z?.body,{models:this.definitions.type}),B=i(Z?.response,{models:this.definitions.type}),Y=(_)=>{if(typeof _==="string"){const Q=_?.charCodeAt(0);if(Q===47||Q===123)try{_=JSON.parse(_)}catch{}else if(k0(_))_=+_}if(X?.length)for(let Q=0;Q<X.length;Q++){const G=X[Q](_);if(G!==void 0)_=G}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:Q,path:G,qi:z,headers:U,query:V,params:P}=_;if(J===null)J=this.getServer();if(J?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:B,open(K){Z.open?.(new I0(K,_))},message:(K,N)=>{const I=Y(N);if(W?.Check(I)===!1)return void K.send(new E("message",W,I).message);Z.message?.(new I0(K,_),I)},drain(K){Z.drain?.(new I0(K,_))},close(K,N,I){Z.close?.(new I0(K,_),N,I)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:J,...W}={config:{allowMeta:!1}}){return this.add($,Z,X,W,J),this}state($,Z){switch(typeof $){case"object":return this.store=p(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=p(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,J])=>{if(!(X in this.definitions.type))this.definitions.type[X]=J}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const J=["_","-"," "],W=(Q)=>Q[0].toUpperCase()+Q.slice(1),B=$==="prefix"?(Q,G)=>J.includes(Q.at(-1)??"")?Q+G:Q+W(G):J.includes(X.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+W(Q),Y=(Q)=>{const G={};switch(Q){case"decorator":for(let z in this.decorators)G[B(X,z)]=this.decorators[z];this.decorators=G;break;case"state":for(let z in this.store)G[B(X,z)]=this.store[z];this.store=G;break;case"model":for(let z in this.definitions.type)G[B(X,z)]=this.definitions.type[z];this.definitions.type=G;break;case"error":for(let z in this.definitions.error)G[B(X,z)]=this.definitions.error[z];this.definitions.error=G;break}},_=Array.isArray(Z)?Z:[Z];for(let Q of _.some((G)=>G==="all")?["decorator","state","model","error"]:_)Y(Q);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?U1(this):O1(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?U1(this):O1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?I1(this):J$(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{if(!Bun)throw new Error("Bun to run");if(this.compile(),typeof $==="string"){if($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,J=typeof $==="object"?{development:!U0,reusePort:!0,...this.config.serve,...$,websocket:{...this.config.websocket,...Q1},fetch:X,error:this.outerErrorHandler}:{development:!U0,reusePort:!0,...this.config.serve,websocket:{...this.config.websocket,...Q1},port:$,fetch:X,error:this.outerErrorHandler};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.server=Bun?.serve(J),this.event.start.length)for(let W=0;W<this.event.start.length;W++)this.event.start[W](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let W=0;W<this.event.stop.length;W++)this.event.stop[W](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{C as t,L as mergeObjectArray,a as mergeHook,p as mergeDeep,d as mapResponse,u as mapEarlyResponse,t as mapCompactResponse,i as getSchemaValidator,J1 as getResponseSchemaValidator,L1 as error,n as default,E as ValidationError,Y1 as ParseError,o as NotFoundError,_0 as InvalidCookieSignature,w0 as InternalServerError,n as Elysia,m as Cookie};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^
ReferenceError: Can't find variable: k8
      at /Users/murad/Developer/seedbox/node_modules/elysia/dist/bun/index.js:361:4539
356 |                 { headers: set.headers, status: error.status }
357 |             )
358 |
359 |         return mapResponse(error, set)
360 |     }
361 | }`,Function("inject",Z)({app:$,mapResponse:d,ERROR_CODE:Z0,ELYSIA_RESPONSE:c})};var c0=b0(z1(),1);var O1=($)=>async(Z)=>{const X={cookie:{},status:200,headers:{}};let J;if($.decorators)J=$.decorators,J.request=Z,J.set=X,J.store=$.store;else J={set:X,store:$.store,request:Z};const W=Z.url,B=W.indexOf("/",11),Y=W.indexOf("?",B+1),_=Y===-1?W.substring(B):W.substring(B,Y);try{for(let I=0;I<$.event.request.length;I++){const j=$.event.request[I];let F=j(J);if(F instanceof Promise)F=await F;if(F=u(F,X),F)return F}const Q=$.dynamicRouter.find(Z.method,_)??$.dynamicRouter.find("ALL",_);if(!Q)throw new o;const{handle:G,hooks:z,validator:U,content:V}=Q.store;let P;if(Z.method!=="GET"&&Z.method!=="HEAD")if(V)switch(V){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const I=await Z.formData();for(let j of I.keys()){if(P[j])continue;const F=I.getAll(j);if(F.length===1)P[j]=F[0];else P[j]=F}break}else{let I=Z.headers.get("content-type");if(I){const j=I.indexOf(";");if(j!==-1)I=I.slice(0,j);for(let F=0;F<$.event.parse.length;F++){let R=$.event.parse[F](J,I);if(R instanceof Promise)R=await R;if(R){P=R;break}}if(P===void 0)switch(I){case"application/json":P=await Z.json();break;case"text/plain":P=await Z.text();break;case"application/x-www-form-urlencoded":P=c0.parse(await Z.text());break;case"application/octet-stream":P=await Z.arrayBuffer();break;case"multipart/form-data":P={};const F=await Z.formData();for(let R of F.keys()){if(P[R])continue;const D=F.getAll(R);if(D.length===1)P[R]=D[0];else P[R]=D}break}}}J.body=P,J.params=Q?.params||void 0,J.query=Y===-1?{}:c0.parse(W.substring(Y+1)),J.headers={};for(let[I,j]of Z.headers.entries())J.headers[I]=j;const K=U?.cookie?.schema;J.cookie=await v0(J.set,J.headers.cookie,K?{secret:K.secrets!==void 0?typeof K.secrets==="string"?K.secrets:K.secrets.join(","):void 0,sign:K.sign===!0?!0:K.sign!==void 0?typeof K.sign==="string"?K.sign:K.sign.join(","):void 0}:void 0);for(let I=0;I<z.transform.length;I++){const j=z.transform[I](J);if(z.transform[I].$elysia==="derive")if(j instanceof Promise)Object.assign(J,await j);else Object.assign(J,j);else if(j instanceof Promise)await j}if(U){if(U.headers){const I={};for(let j in Z.headers)I[j]=Z.headers.get(j);if(U.headers.Check(I)===!1)throw new E("header",U.headers,I)}if(U.params?.Check(J.params)===!1)throw new E("params",U.params,J.params);if(U.query?.Check(J.query)===!1)throw new E("query",U.query,J.query);if(U.cookie){const I={};for(let[j,F]of Object.entries(J.cookie))I[j]=F.value;if(U.cookie?.Check(I)===!1)throw new E("cookie",U.cookie,I)}if(U.body?.Check(P)===!1)throw new E("body",U.body,P)}for(let I=0;I<z.beforeHandle.length;I++){let j=z.beforeHandle[I](J);if(j instanceof Promise)j=await j;if(j!==void 0){J.response=j;for(let R=0;R<z.afterHandle.length;R++){let D=z.afterHandle[R](J);if(D instanceof Promise)D=await D;if(D)j=D}const F=u(j,J.set);if(F)return F}}let N=G(J);if(N instanceof Promise)N=await N;if(!z.afterHandle.length){const I=U?.response?.[N.status];if(I?.Check(N)===!1)throw new E("response",I,N)}else{J.response=N;for(let I=0;I<z.afterHandle.length;I++){let j=z.afterHandle[I](J);if(j instanceof Promise)j=await j;const F=u(j,J.set);if(F!==void 0){const R=U?.response?.[N.status];if(R?.Check(F)===!1)throw new E("response",R,F);return F}}}if(J.set.cookie&&K?.sign){const I=!K.secrets?void 0:typeof K.secrets==="string"?K.secrets:K.secrets[0];if(K.sign===!0)for(let[j,F]of Object.entries(J.set.cookie))J.set.cookie[j].value=await K0(F.value,"${secret}");else for(let j of K.sign){if(!(j in K.properties))continue;if(J.set.cookie[j]?.value)J.set.cookie[j].value=await K0(J.set.cookie[j].value,I)}}return d(N,J.set)}catch(Q){if(Q.status)X.status=Q.status;return $.handleError(J,Q)}finally{for(let Q of $.event.onResponse)await Q(J)}},J$=($)=>async(Z,X)=>{const J=Object.assign(Z,{error:X,code:X.code});J.set=Z.set;for(let W=0;W<$.event.error.length;W++){let B=$.event.error[W](J);if(B instanceof Promise)B=await B;if(B!==void 0&&B!==null)return d(B,Z.set)}return new Response(typeof X.cause==="string"?X.cause:X.message,{headers:Z.set.headers,status:X.status??500})};var w={};F1(w,{t:()=>{{return C}},ElysiaType:()=>{{return e}}});import{TypeSystem as M0} from"@sinclair/typebox/system";import{Type as W$,FormatRegistry as B$} from"@sinclair/typebox";import{Value as f$} from"@sinclair/typebox/value";T(w,k8);T(w,u8);import"@sinclair/typebox/system";import"@sinclair/typebox/compiler";var C=Object.assign({},W$);try{M0.Format("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.test($)),M0.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),M0.Format("date",($)=>!Number.isNaN(new Date($).getTime())),M0.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch($){}var X$=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},M1=($,Z)=>{if(!(Z instanceof Blob))return!1;if($.minSize&&Z.size<X$($.minSize))return!1;if($.maxSize&&Z.size>X$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Z.type.startsWith($.extension))return!1}else{for(let X=0;X<$.extension.length;X++)if(Z.type.startsWith($.extension[X]))return!0;return!1}return!0},y$=M0.Type("Files",($,Z)=>{if(!Array.isArray(Z))return M1($,Z);if($.minItems&&Z.length<$.minItems)return!1;if($.maxItems&&Z.length>$.maxItems)return!1;for(let X=0;X<Z.length;X++)if(!M1($,Z[X]))return!1;return!0});B$.Set("numeric",($)=>!!$&&!isNaN(+$));B$.Set("ObjectString",($)=>{let Z=$.charCodeAt(0);if(Z===9||Z===10||Z===32)Z=$.trimStart().charCodeAt(0);if(Z!==123&&Z!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var e={Numeric:($)=>{const Z=W$.Number($);return C.Transform(C.Union([C.String({format:"numeric",default:0}),C.Number($)],$)).Decode((X)=>{const J=+X;if(isNaN(J))return X;if($&&!f$.Check(Z,J))throw new E("property",Z,J);return J}).Encode((X)=>X)},ObjectString:($,Z)=>C.Transform(C.Union([C.String({format:"ObjectString",default:""}),C.Object($,Z)],Z)).Decode((X)=>{if(typeof X==="string")try{return JSON.parse(X)}catch{return X}return X}).Encode((X)=>JSON.stringify(X)),File:M0.Type("File",M1),Files:($={})=>C.Transform(C.Union([y$($)])).Decode((Z)=>{if(Array.isArray(Z))return Z;return[Z]}).Encode((Z)=>Z),Nullable:($)=>C.Union([C.Null(),$]),MaybeEmpty:($)=>C.Union([C.Null(),C.Undefined(),$]),Cookie:($,Z)=>C.Object($,Z)};C.ObjectString=e.ObjectString;C.Numeric=e.Numeric;C.File=($={})=>e.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});C.Files=($={})=>e.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});C.Nullable=($)=>e.Nullable($);C.MaybeEmpty=e.MaybeEmpty;C.Cookie=e.Cookie;class n{config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};macros=[];event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new T1;server=null;getServer(){return this.server}validator=null;router=new $0;wsRouter=new $0;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new $0;lazyLoadModules=[];path="";stack=void 0;constructor($){if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},analytic:!1,...$,seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.stack=new Error().stack}add($,Z,X,J,{allowMeta:W=!1,skipPrefix:B=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Z==="string")Z=[Z];for(let Y of Z){if(Y=Y===""?Y:Y.charCodeAt(0)===47?Y:`/${Y}`,this.config.prefix&&!B)Y=this.config.prefix+Y;if(J?.type)switch(J.type){case"text":J.type="text/plain";break;case"json":J.type="application/json";break;case"formdata":J.type="multipart/form-data";break;case"urlencoded":J.type="application/x-www-form-urlencoded";break;case"arrayBuffer":J.type="application/octet-stream";break;default:break}const _=this.definitions.type;let Q=i(J?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:_,additionalProperties:!0});if(h(this.config.cookie??{}))if(Q)Q.schema=E1(Q.schema,this.config.cookie??{});else Q=i(C.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:_,additionalProperties:!0});const G={body:i(J?.body??this.validator?.body,{dynamic:!this.config.aot,models:_}),headers:i(J?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:_,additionalProperties:!0}),params:i(J?.params??this.validator?.params,{dynamic:!this.config.aot,models:_}),query:i(J?.query??this.validator?.query,{dynamic:!this.config.aot,models:_}),cookie:Q,response:J1(J?.response??this.validator?.response,{dynamic:!this.config.aot,models:_})},z=this.event,U=Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(this.macros.length){const I=(F)=>(R,D)=>{if(typeof R==="function"||Array.isArray(R)){if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(Array.isArray(R))J[F]=J[F].concat(R);else J[F].push(R);return}const{insert:k="after",stack:W0="local"}=R;if(W0==="global"){if(!Array.isArray(D))if(k==="before")z[F].unshift(D);else z[F].push(D);else if(k==="before")z[F]=D.concat(z[F]);else z[F]=z[F].concat(D);return}else{if(!J[F])J[F]=[];if(typeof J[F]==="function")J[F]=[J[F]];if(!Array.isArray(D))if(k==="before")J[F].unshift(D);else J[F].push(D);else if(k==="before")J[F]=D.concat(J[F]);else J[F]=J[F].concat(D);return}},j={events:{global:z,local:J},onParse:I("parse"),onTransform:I("transform"),onBeforeHandle:I("beforeHandle"),onAfterHandle:I("afterHandle"),onResponse:I("onResponse"),onError:I("error")};for(let F of this.macros){const R={};for(let[k,W0]of Object.entries(J??{})){if(Z1.includes(k))continue;R[k]=W0}if(!F.$elysiaChecksum)F.$elysiaChecksum=[];const D=z0(JSON.stringify(R));if(F.$elysiaChecksum.includes(D))continue;F.$elysiaChecksum.push(z0(JSON.stringify(R))),W1(F(j),J)}}const V=a(z,J),P=typeof X==="function";if(this.config.aot===!1){if(this.dynamicRouter.add($,Y,{validator:G,hooks:V,content:J?.type,handle:X}),this.config.strictPath===!1)this.dynamicRouter.add($,U,{validator:G,hooks:V,content:J?.type,handle:X});this.routes.push({method:$,path:Y,composed:null,handler:X,hooks:V});return}const K=Z$({path:Y,method:$,hooks:V,validator:G,handler:X,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:W?this.definitions.type:void 0,schema:W?this.schema:void 0,getReporter:()=>this.reporter,setHeader:this.setHeaders});if(!P){const I=Object.assign({headers:{},query:{},params:{},body:void 0,request:new Request(`http://localhost${Y}`),store:this.store,path:Y,set:{headers:this.setHeaders??{},status:200}},this.decorators);let j;for(let F of Object.values(V.request))try{const R=u(F(I),I.set);if(R!==void 0){j=R;break}}catch(R){j=this.handleError(I,R);break}if(j)K.response=j;else try{K.response=K(I)}catch(F){K.response=this.handleError(I,F)}}const N=this.routes.findIndex((I)=>I.path===Y&&I.method===$);if(N!==-1)this.routes.splice(N,1);if(this.routes.push({method:$,path:Y,composed:K,handler:X,hooks:V}),$==="$INTERNALWS"){const I=this.config.strictPath?void 0:Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/";if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const j=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}].response\n`;else this.staticRouter.variables+=`const st${j} = staticRouter.handlers[${j}]\n`;if(this.wsPaths[Y]=j,I)this.wsPaths[I]=j}else if(this.wsRouter.add("ws",Y,K),I)this.wsRouter.add("ws",I,K);return}if(Y.indexOf(":")===-1&&Y.indexOf("*")===-1){const I=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(K),K.response instanceof Response)this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}].response\n`;else this.staticRouter.variables+=`const st${I} = staticRouter.handlers[${I}]\n`;if(!this.staticRouter.map[Y])this.staticRouter.map[Y]={code:""};if($==="ALL")this.staticRouter.map[Y].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[Y].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[Y].code}`;else this.staticRouter.map[Y].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[Y].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[U])this.staticRouter.map[U]={code:""};if($==="ALL")this.staticRouter.map[U].all=`default: return st${I}(ctx)\n`;else if(K.response instanceof Response)this.staticRouter.map[U].code=`case '${$}': return st${I}.clone()\n${this.staticRouter.map[U].code}`;else this.staticRouter.map[U].code=`case '${$}': return st${I}(ctx)\n${this.staticRouter.map[U].code}`}}else if(this.router.add($,Y,K),!this.config.strictPath)this.router.add($,Y.endsWith("/")?Y.slice(0,Y.length-1):Y+"/",K)}}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($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}resolve($){return $.$elysia="resolve",this.onBeforeHandle($)}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}mapResponse($){return this.on("mapResponse",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",V1(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}error($,Z){switch(typeof $){case"string":return Z.prototype[Z0]=$,this.definitions.error[$]=Z,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[X,J]of Object.entries($))J.prototype[Z0]=X,this.definitions.error[X]=J;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Z){for(let X of Array.isArray(Z)?Z:[Z])switch(X=H1(X),$){case"start":this.event.start.push(X);break;case"request":this.event.request.push(X);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,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"response":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}group($,Z,X){const J=new n({...this.config,prefix:""});J.store=this.store,J.definitions=this.definitions,J.getServer=()=>this.server;const W=typeof Z==="object",B=(W?X:Z)(J);if(this.decorators=p(this.decorators,J.decorators),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.routes).forEach(({method:Y,path:_,handler:Q,hooks:G})=>{if(_=(W?"":this.config.prefix)+$+_,W){const z=Z,U=G;this.add(Y,_,Q,a(z,{...U,error:!U.error?B.event.error:Array.isArray(U.error)?[...U.error,...B.event.error]:[U.error,...B.event.error]}))}else this.add(Y,_,Q,a(G,{error:B.event.error}),{skipPrefix:!0})}),this}guard($,Z){if(!Z)return this.event=m0(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const X=new n({...this.config,prefix:""});X.store=this.store,X.definitions=this.definitions;const J=Z(X);if(this.decorators=p(this.decorators,X.decorators),J.event.request.length)this.event.request=[...this.event.request,...J.event.request];if(J.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...J.event.onResponse];return this.model(J.definitions.type),Object.values(X.routes).forEach(({method:W,path:B,handler:Y,hooks:_})=>{this.add(W,B,Y,a($,{..._,error:!_.error?J.event.error:Array.isArray(_.error)?[..._.error,...J.event.error]:[_.error,...J.event.error]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Z)=>{if(typeof Z==="function")return Z(this);if(typeof Z.default==="function")return Z.default(this);return this._use(Z)}).then((Z)=>Z.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const W=$(this);if(W instanceof Promise)return this.lazyLoadModules.push(W.then((B)=>{if(B instanceof n){this.compile();for(let{method:Y,path:_,handler:Q,hooks:G}of Object.values(B.routes))this.add(Y,_,Q,a(G,{error:B.event.error}));return B}if(typeof B==="function")return B(this);if(typeof B.default==="function")return B.default(this);return this._use(B)}).then((B)=>B.compile())),this;return W}const{name:Z,seed:X}=$.config;$.getServer=()=>this.getServer(),this.headers($.setHeaders);const J=$.config.scoped;if(J){if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const B=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:Y})=>B===Y))return this;this.dependencies[Z].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:B,dependencies:$.dependencies,stack:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Y)=>Y.$elysia==="derive").map((Y)=>({fn:Y.toString(),stack:new Error().stack??""}))})}if($.model(this.definitions.type),$.error(this.definitions.error),$.macros=[...this.macros,...$.macros],$.onRequest((B)=>{Object.assign(B,this.decorators),Object.assign(B.store,this.store)}),$.event.trace=[...this.event.trace,...$.event.trace],$.config.aot)$.compile();const W=this.mount($.fetch);return this.routes=this.routes.concat(W.routes),this}else{$.reporter=this.reporter;for(let W of $.event.trace)this.trace(W);if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(!this.dependencies[Z].some(({checksum:B})=>W===B))this.macros.push(...$.macros)}}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:W,path:B,handler:Y,hooks:_}of Object.values($.routes))this.add(W,B,Y,a(_,{error:$.event.error}));if(!J)if(Z){if(!(Z in this.dependencies))this.dependencies[Z]=[];const W=X!==void 0?z0(Z+JSON.stringify(X)):0;if(this.dependencies[Z].some(({checksum:B})=>W===B))return this;this.dependencies[Z].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:$.stack,routes:$.routes,decorators:$.decorators,store:$.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((B)=>B?.$elysia==="derive").map((B)=>({fn:B.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((B)=>B?.$elysia==="resolve").map((B)=>({fn:B.toString(),stack:new Error().stack??""}))}),this.event=m0(this.event,X1($.event),W)}else this.event=m0(this.event,X1($.event));return this}macro($){return this.macros.push($),this}mount($,Z){if($ instanceof n||typeof $==="function"||$.length===0||$==="/"){const W=typeof $==="function"?$:$ instanceof n?$.compile().fetch:Z instanceof n?Z.compile().fetch:Z,B=async({request:Y,path:_})=>W(new Request($1(Y.url,_||"/"),Y));return this.all("/",B,{type:"none"}),this.all("/*",B,{type:"none"}),this}const X=$.length;if(Z instanceof n)Z=Z.compile().fetch;const J=async({request:W,path:B})=>Z(new Request($1(W.url,B.slice(X)||"/"),W));return this.all($,J,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),J,{type:"none"}),this}get($,Z,X){return this.add("GET",$,Z,X),this}post($,Z,X){return this.add("POST",$,Z,X),this}put($,Z,X){return this.add("PUT",$,Z,X),this}patch($,Z,X){return this.add("PATCH",$,Z,X),this}delete($,Z,X){return this.add("DELETE",$,Z,X),this}options($,Z,X){return this.add("OPTIONS",$,Z,X),this}all($,Z,X){return this.add("ALL",$,Z,X),this}head($,Z,X){return this.add("HEAD",$,Z,X),this}connect($,Z,X){return this.add("CONNECT",$,Z,X),this}ws($,Z){const X=Z.transformMessage?Array.isArray(Z.transformMessage)?Z.transformMessage:[Z.transformMessage]:void 0;let J=null;const W=i(Z?.body,{models:this.definitions.type}),B=i(Z?.response,{models:this.definitions.type}),Y=(_)=>{if(typeof _==="string"){const Q=_?.charCodeAt(0);if(Q===47||Q===123)try{_=JSON.parse(_)}catch{}else if(k0(_))_=+_}if(X?.length)for(let Q=0;Q<X.length;Q++){const G=X[Q](_);if(G!==void 0)_=G}return _};return this.route("$INTERNALWS",$,(_)=>{const{set:Q,path:G,qi:z,headers:U,query:V,params:P}=_;if(J===null)J=this.getServer();if(J?.upgrade(_.request,{headers:typeof Z.upgrade==="function"?Z.upgrade(_):Z.upgrade,data:{validator:B,open(K){Z.open?.(new I0(K,_))},message:(K,N)=>{const I=Y(N);if(W?.Check(I)===!1)return void K.send(new E("message",W,I).message);Z.message?.(new I0(K,_),I)},drain(K){Z.drain?.(new I0(K,_))},close(K,N,I){Z.close?.(new I0(K,_),N,I)}}}))return;return Q.status=400,"Expected a websocket connection"},{beforeHandle:Z.beforeHandle,transform:Z.transform,headers:Z.headers,params:Z.params,query:Z.query}),this}route($,Z,X,{config:J,...W}={config:{allowMeta:!1}}){return this.add($,Z,X,W,J),this}state($,Z){switch(typeof $){case"object":return this.store=p(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Z;return this}decorate($,Z){switch(typeof $){case"object":return this.decorators=p(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Z;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Z){switch(typeof $){case"object":return Object.entries($).forEach(([X,J])=>{if(!(X in this.definitions.type))this.definitions.type[X]=J}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Z,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Z,X){if(X==="")return this;const J=["_","-"," "],W=(Q)=>Q[0].toUpperCase()+Q.slice(1),B=$==="prefix"?(Q,G)=>J.includes(Q.at(-1)??"")?Q+G:Q+W(G):J.includes(X.at(-1)??"")?(Q,G)=>G+Q:(Q,G)=>G+W(Q),Y=(Q)=>{const G={};switch(Q){case"decorator":for(let z in this.decorators)G[B(X,z)]=this.decorators[z];this.decorators=G;break;case"state":for(let z in this.store)G[B(X,z)]=this.store[z];this.store=G;break;case"model":for(let z in this.definitions.type)G[B(X,z)]=this.definitions.type[z];this.definitions.type=G;break;case"error":for(let z in this.definitions.error)G[B(X,z)]=this.definitions.error[z];this.definitions.error=G;break}},_=Array.isArray(Z)?Z:[Z];for(let Q of _.some((G)=>G==="all")?["decorator","state","model","error"]:_)Y(Q);return this}prefix($,Z){return this.affix("prefix",$,Z)}suffix($,Z){return this.affix("suffix",$,Z)}compile(){if(this.fetch=this.config.aot?U1(this):O1(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?U1(this):O1(this))($)};handleError=async($,Z)=>(this.handleError=this.config.aot?I1(this):J$(this))($,Z);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Z)=>{if(!Bun)throw new Error("Bun to run");if(this.compile(),typeof $==="string"){if($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const X=this.fetch,J=typeof $==="object"?{development:!U0,reusePort:!0,...this.config.serve,...$,websocket:{...this.config.websocket,...Q1},fetch:X,error:this.outerErrorHandler}:{development:!U0,reusePort:!0,...this.config.serve,websocket:{...this.config.websocket,...Q1},port:$,fetch:X,error:this.outerErrorHandler};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.server=Bun?.serve(J),this.event.start.length)for(let W=0;W<this.event.start.length;W++)this.event.start[W](this);if(Z)Z(this.server);return process.on("beforeExit",()=>{for(let W=0;W<this.event.stop.length;W++)this.event.stop[W](this)}),Promise.all(this.lazyLoadModules).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.stop(),this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$](this)};get modules(){return Promise.all(this.lazyLoadModules)}}export{C as t,L as mergeObjectArray,a as mergeHook,p as mergeDeep,d as mapResponse,u as mapEarlyResponse,t as mapCompactResponse,i as getSchemaValidator,J1 as getResponseSchemaValidator,L1 as error,n as default,E as ValidationError,Y1 as ParseError,o as NotFoundError,_0 as InvalidCookieSignature,w0 as InternalServerError,n as Elysia,m as Cookie};
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^
ReferenceError: Can't find variable: k8
      at /Users/murad/Developer/seedbox/node_modules/elysia/dist/bun/index.js:361:4539
bun --version
1.0.20

To resolve this issue you might need to change your package.json from "elysia": "latest" to "elysia": "0.8.6"

aashari commented 9 months ago

Downgrading to a previous version was on my mind already. But downgrading from 1.0.x to 0.8.6 seems like a big jump. Is that the first version that doesn't throw the error?

Not downgrading Bun, but downgrading Elysia, latest Elysia version is 0.8.7 from this commit https://github.com/elysiajs/elysia/commit/a6bf3d866f6d4c57d21513a0e72c7d423d8cff9a, before this commit, it working properly, which is 0.8.6

muradbu commented 9 months ago

Downgrading to a previous version was on my mind already. But downgrading from 1.0.x to 0.8.6 seems like a big jump. Is that the first version that doesn't throw the error?

Not downgrading Bun, but downgrading Elysia

Yeah, my bad. Realized my mistake and deleted my comment.

amjed-ali-k commented 9 months ago

same error here. getting same error with bun and pnpm image

Working fine when downgraded elysia

SaltyAom commented 9 months ago

This error is caused by excluding typebox from bundling, see #317.

Revert and should be working on 0.8.8

aashari commented 9 months ago

I'm closing this issue since it is fixed on 0.8.8 version