Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elysia

Package Overview
Dependencies
Maintainers
1
Versions
451
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia - npm Package Compare versions

Comparing version 1.2.0-exp.2 to 1.2.0-exp.3

107

dist/cjs/compose.js

@@ -1,6 +0,6 @@

"use strict";var Re=Object.create;var ne=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Oe=(n,a)=>{for(var f in a)ne(n,f,{get:a[f],enumerable:!0})},pe=(n,a,f,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of Se(a))!Ce.call(n,r)&&r!==f&&ne(n,r,{get:()=>a[r],enumerable:!(o=Ee(a,r))||o.enumerable});return n};var xe=(n,a,f)=>(f=n!=null?Re(ve(n)):{},pe(a||!n||!n.__esModule?ne(f,"default",{value:n,enumerable:!0}):f,n)),we=n=>pe(ne({},"__esModule",{value:!0}),n);var Te={};Oe(Te,{composeErrorHandler:()=>ye,composeGeneralHandler:()=>Ae,composeHandler:()=>ke,hasAdditionalProperties:()=>H,hasProperty:()=>D,hasTransform:()=>F,hasType:()=>le,isAsync:()=>g,isAsyncName:()=>M,isGenerator:()=>X});module.exports=we(Te);var z=require("@sinclair/typebox/value"),oe=require("./fast-querystring"),ue=xe(require("fast-decode-uri-component")),v=require("./utils"),ae=require("./error"),j=require("./handler"),x=require("./error"),se=require("./trace"),P=require("./sucrose"),me=require("./cookies");const qe=new Headers().toJSON,de={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},O=n=>{if(!n)return!1;const a=n?.schema;return!!a&&de.optional in a},H=n=>{if(!n)return!1;const a=n?.schema??n;if(a.anyOf)return a.anyOf.some(H);if(a.someOf)return a.someOf.some(H);if(a.allOf)return a.allOf.some(H);if(a.not)return a.not.some(H);if(a.type==="object"){const f=a.properties;if("additionalProperties"in a)return a.additionalProperties;for(const o of Object.keys(f)){const r=f[o];if(r.type==="object"){if(H(r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(H(r.anyOf[s]))return!0}return r.additionalProperties}return!1}return!1},ie=({context:n="c",trace:a,addFn:f})=>{if(!a.length)return()=>({resolveChild(){return()=>{}},resolve(){}});for(let o=0;o<a.length;o++)f(`let report${o}, reportChild${o}, reportErr${o}, reportErrChild${o};let trace${o} = ${n}[ELYSIA_TRACE]?.[${o}] ?? trace[${o}](${n});
`);return(o,{name:r,total:s=0}={})=>{r||(r="anonymous");const d=o==="error"?"reportErr":"report";for(let m=0;m<a.length;m++)f(`${d}${m} = trace${m}.${o}({id,event:'${o}',name:'${r}',begin:performance.now(),total:${s}})
`);return{resolve(){for(let m=0;m<a.length;m++)f(`${d}${m}.resolve()
`)},resolveChild(m){for(let u=0;u<a.length;u++)f(`${d}Child${u}=${d}${u}.resolveChild?.shift()?.({id,event:'${o}',name:'${m}',begin:performance.now()})
`);return u=>{for(let $=0;$<a.length;$++)f(u?`if(${u} instanceof Error){${d}Child${$}?.(${u}) }else{${d}Child${$}?.()}`:`${d}Child${$}?.()
"use strict";var Re=Object.create;var ne=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Oe=(n,a)=>{for(var f in a)ne(n,f,{get:a[f],enumerable:!0})},pe=(n,a,f,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of Se(a))!Ce.call(n,r)&&r!==f&&ne(n,r,{get:()=>a[r],enumerable:!(o=Ee(a,r))||o.enumerable});return n};var we=(n,a,f)=>(f=n!=null?Re(ve(n)):{},pe(a||!n||!n.__esModule?ne(f,"default",{value:n,enumerable:!0}):f,n)),xe=n=>pe(ne({},"__esModule",{value:!0}),n);var Te={};Oe(Te,{composeErrorHandler:()=>ye,composeGeneralHandler:()=>Ae,composeHandler:()=>ke,hasAdditionalProperties:()=>H,hasProperty:()=>D,hasTransform:()=>F,hasType:()=>le,isAsync:()=>g,isAsyncName:()=>M,isGenerator:()=>X});module.exports=xe(Te);var z=require("@sinclair/typebox/value"),oe=require("./fast-querystring"),ue=we(require("fast-decode-uri-component")),v=require("./utils"),ae=require("./error"),j=require("./handler"),w=require("./error"),se=require("./trace"),P=require("./sucrose"),me=require("./cookies");const qe=new Headers().toJSON,de={optional:Symbol.for("TypeBox.Optional"),kind:Symbol.for("TypeBox.Kind")},O=n=>{if(!n)return!1;const a=n?.schema;return!!a&&de.optional in a},H=n=>{if(!n)return!1;const a=n?.schema??n;if(a.anyOf)return a.anyOf.some(H);if(a.someOf)return a.someOf.some(H);if(a.allOf)return a.allOf.some(H);if(a.not)return a.not.some(H);if(a.type==="object"){const f=a.properties;if("additionalProperties"in a)return a.additionalProperties;for(const o of Object.keys(f)){const r=f[o];if(r.type==="object"){if(H(r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(H(r.anyOf[s]))return!0}return r.additionalProperties}return!1}return!1},ie=({context:n="c",trace:a,addFn:f})=>{if(!a.length)return()=>({resolveChild(){return()=>{}},resolve(){}});for(let o=0;o<a.length;o++)f(`let report${o}, reportChild${o}, reportErr${o}, reportErrChild${o};let trace${o} = ${n}[ELYSIA_TRACE]?.[${o}] ?? trace[${o}](${n});
`);return(o,{name:r,total:s=0}={})=>{r||(r="anonymous");const d=o==="error"?"reportErr":"report";for(let u=0;u<a.length;u++)f(`${d}${u} = trace${u}.${o}({id,event:'${o}',name:'${r}',begin:performance.now(),total:${s}})
`);return{resolve(){for(let u=0;u<a.length;u++)f(`${d}${u}.resolve()
`)},resolveChild(u){for(let m=0;m<a.length;m++)f(`${d}Child${m}=${d}${m}.resolveChild?.shift()?.({id,event:'${o}',name:'${u}',begin:performance.now()})
`);return m=>{for(let $=0;$<a.length;$++)f(m?`if(${m} instanceof Error){${d}Child${$}?.(${m}) }else{${d}Child${$}?.()}`:`${d}Child${$}?.()
`)}}}}},He=({injectResponse:n="",normalize:a=!1,validator:f})=>({composeValidation:(o,r=`c.${o}`)=>`c.set.status=422;throw new ValidationError('${o}',validator.${o},${r})`,composeResponseValidation:(o="r")=>{let r=n+`

@@ -13,5 +13,5 @@ `;r+=`if(typeof ${o}==="object"&&${o}&&ELYSIA_RESPONSE in ${o}){c.set.status=${o}[ELYSIA_RESPONSE]

throw new ValidationError('response',validator.response['${s}'],${o})}c.set.status = ${s}}break
`;return r+"}"}}),G=Symbol.for("TypeBox.Kind"),le=(n,a)=>{if(a){if(G in a&&a[G]===n)return!0;if(a.type==="object"){const f=a.properties;for(const o of Object.keys(f)){const r=f[o];if(r.type==="object"){if(le(n,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(le(n,r.anyOf[s]))return!0}if(G in r&&r[G]===n)return!0}return!1}return a.properties&&G in a.properties&&a.properties[G]===n}},D=(n,a)=>{if(a){if(a.type==="object"){const f=a.properties;if(!f)return!1;for(const o of Object.keys(f)){const r=f[o];if(n in r)return!0;if(r.type==="object"){if(D(n,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(D(n,r.anyOf[s]))return!0}}return!1}return n in a}},fe=Symbol.for("TypeBox.Transform"),F=n=>{if(n){if(n.type==="object"&&n.properties){const a=n.properties;for(const f of Object.keys(a)){const o=a[f];if(o.type==="object"){if(F(o))return!0}else if(o.anyOf){for(let s=0;s<o.anyOf.length;s++)if(F(o.anyOf[s]))return!0}if(fe in o)return!0}return!1}return fe in n||n.properties&&fe in n.properties}},je=/(?:return|=>) \S+\(/g,M=n=>(n?.fn??n).constructor.name==="AsyncFunction",g=n=>{const a=n?.fn??n;if(a.constructor.name==="AsyncFunction")return!0;const f=a.toString();return f.includes("=> response.clone(")?!1:f.includes("await")||f.includes("async")?!0:!!f.match(je)},X=n=>{const a=n?.fn??n;return a.constructor.name==="AsyncGeneratorFunction"||a.constructor.name==="GeneratorFunction"},ke=({app:n,path:a,method:f,localHook:o,hooks:r,validator:s,handler:d,allowMeta:m=!1,inference:u})=>{const $=typeof d=="function";if(!$&&(d=(0,j.mapResponse)(d,{headers:n.setHeaders??{}}),r.parse.length===0&&r.transform.length===0&&r.beforeHandle.length===0&&r.afterHandle.length===0))return Function("a","return function(){return a.clone()}")(d);const h=$?"handler(c)":"handler",A=r.afterResponse.length>0,C=r.trace.length>0;let e="";u=(0,P.sucrose)(Object.assign(o,{handler:d}),u),u.server&&(e+=`Object.defineProperty(c,'server',{get:function(){return getServer()}})
`),u.body&&(e+=`let isParsing = false
`),s.createBody?.(),s.createQuery?.(),s.createHeaders?.(),s.createParams?.(),s.createCookie?.(),s.createResponse?.();const Z=u.query||!!s.query,y=f!=="$INTERNALWS"&&f!=="GET"&&f!=="HEAD"&&(u.body||!!s.body||r.parse.length),b=n.setHeaders,V=b&&!!Object.keys(b).length,I=u.headers||s.headers,Y=u.cookie||!!s.cookie,K=Y?(0,v.getCookieValidator)({validator:s.cookie,defaultConfig:n.config.cookie,dynamic:!!n.config.aot,config:s.cookie?.config??{},models:n.definitions.type}):void 0,E=K?.config;let L="";if(E?.sign){if(!E.secrets)throw new Error(`t.Cookie required secret which is not set in (${f}) ${a}.`);const i=E.secrets?typeof E.secrets=="string"?E.secrets:E.secrets[0]:void 0;if(L+=`const _setCookie = c.set.cookie
`;return r+"}"}}),G=Symbol.for("TypeBox.Kind"),le=(n,a)=>{if(a){if(G in a&&a[G]===n)return!0;if(a.type==="object"){const f=a.properties;for(const o of Object.keys(f)){const r=f[o];if(r.type==="object"){if(le(n,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(le(n,r.anyOf[s]))return!0}if(G in r&&r[G]===n)return!0}return!1}return a.properties&&G in a.properties&&a.properties[G]===n}},D=(n,a)=>{if(a){if(a.type==="object"){const f=a.properties;if(!f)return!1;for(const o of Object.keys(f)){const r=f[o];if(n in r)return!0;if(r.type==="object"){if(D(n,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(D(n,r.anyOf[s]))return!0}}return!1}return n in a}},fe=Symbol.for("TypeBox.Transform"),F=n=>{if(n){if(n.type==="object"&&n.properties){const a=n.properties;for(const f of Object.keys(a)){const o=a[f];if(o.type==="object"){if(F(o))return!0}else if(o.anyOf){for(let s=0;s<o.anyOf.length;s++)if(F(o.anyOf[s]))return!0}if(fe in o)return!0}return!1}return fe in n||n.properties&&fe in n.properties}},je=/(?:return|=>) \S+\(/g,M=n=>(n?.fn??n).constructor.name==="AsyncFunction",g=n=>{const a=n?.fn??n;if(a.constructor.name==="AsyncFunction")return!0;const f=a.toString();return f.includes("=> response.clone(")?!1:f.includes("await")||f.includes("async")?!0:!!f.match(je)},X=n=>{const a=n?.fn??n;return a.constructor.name==="AsyncGeneratorFunction"||a.constructor.name==="GeneratorFunction"},ke=({app:n,path:a,method:f,localHook:o,hooks:r,validator:s,handler:d,allowMeta:u=!1,inference:m})=>{const $=typeof d=="function";if(!$&&(d=(0,j.mapResponse)(d,{headers:n.setHeaders??{}}),r.parse.length===0&&r.transform.length===0&&r.beforeHandle.length===0&&r.afterHandle.length===0))return Function("a","return function(){return a.clone()}")(d);const h=$?"handler(c)":"handler",A=r.afterResponse.length>0,C=r.trace.length>0;let e="";m=(0,P.sucrose)(Object.assign(o,{handler:d}),m),m.server&&(e+=`Object.defineProperty(c,'server',{get:function(){return getServer()}})
`),m.body&&(e+=`let isParsing = false
`),s.createBody?.(),s.createQuery?.(),s.createHeaders?.(),s.createParams?.(),s.createCookie?.(),s.createResponse?.();const Z=m.query||!!s.query,y=f!=="$INTERNALWS"&&f!=="GET"&&f!=="HEAD"&&(m.body||!!s.body||r.parse.length),b=n.setHeaders,V=b&&!!Object.keys(b).length,I=m.headers||s.headers,Y=m.cookie||!!s.cookie,K=Y?(0,v.getCookieValidator)({validator:s.cookie,defaultConfig:n.config.cookie,dynamic:!!n.config.aot,config:s.cookie?.config??{},models:n.definitions.type}):void 0,E=K?.config;let L="";if(E?.sign){if(!E.secrets)throw new Error(`t.Cookie required secret which is not set in (${f}) ${a}.`);const i=E.secrets?typeof E.secrets=="string"?E.secrets:E.secrets[0]:void 0;if(L+=`const _setCookie = c.set.cookie
if(_setCookie){`,E.sign===!0)L+=`for(const [key, cookie] of Object.entries(_setCookie)){c.set.cookie[key].value=await signCookie(cookie.value,'${i}')}`;else for(const t of E.sign)L+=`if(_setCookie['${t}']?.value){c.set.cookie['${t}'].value=await signCookie(_setCookie['${t}'].value,'${i}')}`;L+="}"}const ee=n.config.normalize,{composeValidation:U,composeResponseValidation:re}=He({normalize:ee,validator:s});if(I&&(e+=qe?`c.headers = c.request.headers.toJSON()

@@ -73,4 +73,4 @@ `:`c.headers = {}

`}}C&&(e+=`const id=c[ELYSIA_REQUEST_ID]
`);const R=ie({trace:r.trace,addFn:i=>{e+=i}});e+="try{";const Q=typeof d=="function"&&g(d),k=C||r.afterResponse.length>0?"c.response= ":"",W=Y||y||Q||r.parse.length>0||r.afterHandle.some(g)||r.beforeHandle.some(g)||r.transform.some(g)||r.mapResponse.some(g),he=(typeof d=="function"?X(d):!1)||r.beforeHandle.some(X)||r.afterHandle.some(X)||r.transform.some(X),te=u.cookie||u.set||I||C||s.response||$&&V||he,w=",c.request";e+=`c.route=\`${a}\`
`;const ge=R("parse",{total:r.parse.length});if(y){const i=r.parse.length||u.body||s.body;if(e+=`isParsing=true
`);const R=ie({trace:r.trace,addFn:i=>{e+=i}});e+="try{";const Q=typeof d=="function"&&g(d),k=C||r.afterResponse.length>0?"c.response= ":"",W=Y||y||Q||r.parse.length>0||r.afterHandle.some(g)||r.beforeHandle.some(g)||r.transform.some(g)||r.mapResponse.some(g),he=(typeof d=="function"?X(d):!1)||r.beforeHandle.some(X)||r.afterHandle.some(X)||r.transform.some(X),te=m.cookie||m.set||I||C||s.response||$&&V||he,x=",c.request";e+=`c.route=\`${a}\`
`;const ge=R("parse",{total:r.parse.length});if(y){const i=r.parse.length||m.body||s.body;if(e+=`isParsing=true
`,r.type&&!r.parse.length)switch(r.type){case"json":case"application/json":O(s.body)?e+="try{c.body=await c.request.json()}catch{}":e+="c.body=await c.request.json()";break;case"text":case"text/plain":e+=`c.body=await c.request.text()

@@ -175,3 +175,3 @@ `;break;case"urlencoded":case"application/x-www-form-urlencoded":e+=`c.body=parseQuery(await c.request.text())

`;for(let S=0;S<r.mapResponse.length;S++){const T=r.mapResponse[S],J=N.resolveChild(T.fn.name);e+=`if(mr===undefined){mr=${M(T)?"await":""} onMapResponse[${S}](c)
if(mr!==undefined)be=c.response=mr}`,J()}}N.resolve(),e+=L,e+=`return mapEarlyResponse(${k}be,c.set${w})}
if(mr!==undefined)be=c.response=mr}`,J()}}N.resolve(),e+=L,e+=`return mapEarlyResponse(${k}be,c.set${x})}
`}}i.resolve()}if(r?.afterHandle.length){const i=R("handle",{name:$?d.name:void 0});r.afterHandle.length?e+=Q?`let r=c.response=await ${h}

@@ -187,4 +187,4 @@ `:`let r=c.response=${h}

`,s.response&&(e+=re()),e+=L;const c=R("mapResponse",{total:r.mapResponse.length});if(r.mapResponse.length)for(let l=0;l<r.mapResponse.length;l++){const p=r.mapResponse[l],q=c.resolveChild(p.fn.name);e+=`mr=${M(p)?"await":""} onMapResponse[${l}](c)
if(mr!==undefined)r=c.response=mr`,q()}c.resolve(),te?e+=`return mapResponse(${k}r,c.set${w})
`:e+=`return mapCompactResponse(${k}r${w})
if(mr!==undefined)r=c.response=mr`,q()}c.resolve(),te?e+=`return mapResponse(${k}r,c.set${x})
`:e+=`return mapCompactResponse(${k}r${x})
`}else{const i=R("handle",{name:$?d.name:void 0});if(s.response||r.mapResponse.length){e+=Q?`let r=await ${h}

@@ -197,20 +197,20 @@ `:`let r=${h}

if(mr!==undefined)r=c.response=mr}
`,p()}}t.resolve(),e+=L,d instanceof Response?(e+=u.set?`if(isNotEmpty(c.set.headers)||c.set.status!==200||c.set.redirect||c.set.cookie)return mapResponse(${k}${h}.clone(),c.set${w})else return ${h}.clone()`:`return ${h}.clone()`,e+=`
`):te?e+=`return mapResponse(${k}r,c.set${w})
`:e+=`return mapCompactResponse(${k}r${w})
`,p()}}t.resolve(),e+=L,d instanceof Response?(e+=m.set?`if(isNotEmpty(c.set.headers)||c.set.status!==200||c.set.redirect||c.set.cookie)return mapResponse(${k}${h}.clone(),c.set${x})else return ${h}.clone()`:`return ${h}.clone()`,e+=`
`):te?e+=`return mapResponse(${k}r,c.set${x})
`:e+=`return mapCompactResponse(${k}r${x})
`}else if(Y||C){e+=Q?`let r=await ${h}
`:`let r=${h}
`,i.resolve(),R("afterHandle").resolve();const t=R("mapResponse",{total:r.mapResponse.length});if(r.mapResponse.length){e+=`c.response= r
`;for(let c=0;c<r.mapResponse.length;c++){const l=r.mapResponse[c],p=t.resolveChild(l.fn.name);e+=`if(mr===undefined){mr=${M(l)?"await ":""}onMapResponse[${c}](c)if(mr!==undefined)r=c.response=mr}`,p()}}t.resolve(),e+=L,te?e+=`return mapResponse(${k}r,c.set${w})
`:e+=`return mapCompactResponse(${k}r${w})
`}else{i.resolve();const t=Q?`await ${h}`:h;R("afterHandle").resolve(),d instanceof Response?e+=u.set?`if(isNotEmpty(c.set.headers)||c.set.status!==200||c.set.redirect||c.set.cookie)return mapResponse(${k}${h}.clone(),c.set${w})
`;for(let c=0;c<r.mapResponse.length;c++){const l=r.mapResponse[c],p=t.resolveChild(l.fn.name);e+=`if(mr===undefined){mr=${M(l)?"await ":""}onMapResponse[${c}](c)if(mr!==undefined)r=c.response=mr}`,p()}}t.resolve(),e+=L,te?e+=`return mapResponse(${k}r,c.set${x})
`:e+=`return mapCompactResponse(${k}r${x})
`}else{i.resolve();const t=Q?`await ${h}`:h;R("afterHandle").resolve(),d instanceof Response?e+=m.set?`if(isNotEmpty(c.set.headers)||c.set.status!==200||c.set.redirect||c.set.cookie)return mapResponse(${k}${h}.clone(),c.set${x})
else return ${h}.clone()
`:`return ${h}.clone()
`:te?e+=`return mapResponse(${k}${t},c.set${w})
`:e+=`return mapCompactResponse(${k}${t}${w})
`:te?e+=`return mapResponse(${k}${t},c.set${x})
`:e+=`return mapCompactResponse(${k}${t}${x})
`}}if(e+=`
}catch(error){`,y&&(e+=`if(isParsing)error=new ParseError()
`),W||(e+="return(async()=>{"),e+=`const set=c.set
if(!set.status||set.status<300)set.status=error?.status||500
`,C)for(let i=0;i<r.trace.length;i++)e+=`report${i}?.resolve(error);reportChild${i}?.(error)
if(!set.status||set.status<300){if(error.status)set.status=error.status
else set.status=500}`,C)for(let i=0;i<r.trace.length;i++)e+=`report${i}?.resolve(error);reportChild${i}?.(error)
`;const ce=R("error",{total:r.error.length});if(r.error.length){e+=`c.error=error

@@ -224,3 +224,3 @@ c.code=error.code??error[ERROR_CODE]??"UNKNOWN"

er=${M(p)?"await ":""}onMapResponse[${l}](c)
if(er instanceof Promise)er=await er`,q()}if(c.resolve(),e+=`er=mapEarlyResponse(er,set${w})
if(er instanceof Promise)er=await er`,q()}if(c.resolve(),e+=`er=mapEarlyResponse(er,set${x})
`,e+="if(er){",C){for(let l=0;l<r.trace.length;l++)e+=`report${l}.resolve()

@@ -234,12 +234,12 @@ `;ce.resolve()}e+="return er}"}}if(ce.resolve(),e+="return handleError(c,error,true)",W||(e+="})()"),e+="}",A||C){e+="finally{ ",W||(e+=";(async()=>{");const i=R("afterResponse",{total:r.afterResponse.length});if(A)for(let t=0;t<r.afterResponse.length;t++){const c=i.resolveChild(r.afterResponse[t].fn.name);e+=`

`),r.mapResponse.length&&(B+=`let mr
`),m&&(B+=`c.schema = schema
`),u&&(B+=`c.schema = schema
c.defs = definitions
`),B+=e+"}";try{return Function("hooks",B)({handler:d,hooks:(0,v.lifeCycleToFn)(r),validator:s,handleError:n.handleError,utils:{mapResponse:j.mapResponse,mapCompactResponse:j.mapCompactResponse,mapEarlyResponse:j.mapEarlyResponse,parseQuery:oe.parseQuery,parseQueryFromURL:oe.parseQueryFromURL,isNotEmpty:j.isNotEmpty},error:{NotFoundError:x.NotFoundError,ValidationError:x.ValidationError,InternalServerError:x.InternalServerError,ParseError:ae.ParseError},schema:n.router.history,definitions:n.definitions.type,ERROR_CODE:x.ERROR_CODE,parseCookie:me.parseCookie,signCookie:v.signCookie,decodeURIComponent:ue.default,ELYSIA_RESPONSE:x.ELYSIA_RESPONSE,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID,getServer:()=>n.getServer()})}catch{const i=(0,v.lifeCycleToFn)(r);console.log("[Composer] failed to generate optimized handler"),console.log("Please report the following to Elysia maintainers privately as it may include sensitive information about your codebase:"),console.log("---"),console.log({handler:typeof d=="function"?d.toString():d,hooks:{...i,transform:i?.transform?.map?.(t=>t.toString()),resolve:i?.resolve?.map?.(t=>t.toString()),beforeHandle:i?.beforeHandle?.map?.(t=>t.toString()),afterHandle:i?.afterHandle?.map?.(t=>t.toString()),mapResponse:i?.mapResponse?.map?.(t=>t.toString()),parse:i?.parse?.map?.(t=>t.toString()),error:i?.error?.map?.(t=>t.toString()),afterResponse:i?.afterResponse?.map?.(t=>t.toString()),stop:i?.stop?.map?.(t=>t.toString())},validator:s,definitions:n.definitions.type,fnLiteral:e}),console.log("---"),process.exit(1)}},Ae=n=>{const a=n.config.handler?.standardHostname??!0;let f="",o="";const r=n.setHeaders;for(const y of Object.keys(n.singleton.decorator))f+=`,${y}: app.singleton.decorator.${y}`;const s=n.router,d=n.event.trace.length>0;let m="const route=router.find(request.method,path)";m+=s.http.root.ALL?`??router.find("ALL",path)
`),B+=e+"}";try{return Function("hooks",B)({handler:d,hooks:(0,v.lifeCycleToFn)(r),validator:s,handleError:n.handleError,utils:{mapResponse:j.mapResponse,mapCompactResponse:j.mapCompactResponse,mapEarlyResponse:j.mapEarlyResponse,parseQuery:oe.parseQuery,parseQueryFromURL:oe.parseQueryFromURL,isNotEmpty:j.isNotEmpty},error:{NotFoundError:w.NotFoundError,ValidationError:w.ValidationError,InternalServerError:w.InternalServerError,ParseError:ae.ParseError},schema:n.router.history,definitions:n.definitions.type,ERROR_CODE:w.ERROR_CODE,parseCookie:me.parseCookie,signCookie:v.signCookie,decodeURIComponent:ue.default,ELYSIA_RESPONSE:w.ELYSIA_RESPONSE,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID,getServer:()=>n.getServer()})}catch{const i=(0,v.lifeCycleToFn)(r);console.log("[Composer] failed to generate optimized handler"),console.log("Please report the following to Elysia maintainers privately as it may include sensitive information about your codebase:"),console.log("---"),console.log({handler:typeof d=="function"?d.toString():d,hooks:{...i,transform:i?.transform?.map?.(t=>t.toString()),resolve:i?.resolve?.map?.(t=>t.toString()),beforeHandle:i?.beforeHandle?.map?.(t=>t.toString()),afterHandle:i?.afterHandle?.map?.(t=>t.toString()),mapResponse:i?.mapResponse?.map?.(t=>t.toString()),parse:i?.parse?.map?.(t=>t.toString()),error:i?.error?.map?.(t=>t.toString()),afterResponse:i?.afterResponse?.map?.(t=>t.toString()),stop:i?.stop?.map?.(t=>t.toString())},validator:s,definitions:n.definitions.type,fnLiteral:e}),console.log("---"),process.exit(1)}},Ae=n=>{const a=n.config.handler?.standardHostname??!0;let f="",o="";const r=n.setHeaders;for(const y of Object.keys(n.singleton.decorator))f+=`,${y}: app.singleton.decorator.${y}`;const s=n.router,d=n.event.trace.length>0;let u="const route=router.find(r.method,p)";u+=s.http.root.ALL?`??router.find("ALL",p)
`:`
`,m+="if(route===null)return ",n.event.error.length?m+="app.handleError(ctx,notFound)":m+=n.event.request.length?"new Response(error404Message,{status:ctx.set.status===200?404:ctx.set.status,headers:ctx.set.headers})":"error404.clone()",m+=`
ctx.params=route.params
if(route.store.handler)return route.store.handler(ctx)
return (route.store.handler=route.store.compile())(ctx)
`;let u="";for(const[y,{code:b,all:V,static:I}]of Object.entries(s.static.http.map))I&&(u+=`case'${y}':switch(request.method){${b}
${V??"default:break map"}}`),u+=`case'${y}':switch(request.method){${b}${V??"default:break map"}}`;const $=n.event.request.some(g);o+=`
`,u+="if(route===null)return ",n.event.error.length?u+="app.handleError(c,notFound)":u+=n.event.request.length?"new Response(error404Message,{status:c.set.status===200?404:c.set.status,headers:c.set.headers})":"error404.clone()",u+=`
c.params=route.params
if(route.store.handler)return route.store.handler(c)
return (route.store.handler=route.store.compile())(c)
`;let m="";for(const[y,{code:b,all:V,static:I}]of Object.entries(s.static.http.map))I&&(m+=`case'${y}':switch(r.method){${b}
${V??"default:"+u}}`),m+=`case'${y}':switch(r.method){${b}${V??"default:"+u}}`;const $=n.event.request.some(g);o+=`
const {app,mapEarlyResponse,NotFoundError,randomId,handleError,error,redirect,ELYSIA_TRACE,ELYSIA_REQUEST_ID,getServer}=data

@@ -258,20 +258,19 @@ const store=app.singleton.store

`),n.event.trace.length&&(o+="const "+n.event.trace.map((y,b)=>`tr${b}=app.event.trace[${b}].fn`).join(",")+`
`),o+=`${$?"async ":""}function map(request){`,n.event.request.length&&(o+=`let re
`),o+=`const url=request.url,s=url.indexOf('/',${a?11:7}),qi=url.indexOf('?', s + 1)
let path
if(qi===-1) path = url.substring(s)
else path = url.substring(s, qi)
`),o+=`${$?"async ":""}function map(r){`,n.event.request.length&&(o+=`let re
`),o+=`const u=r.url,s=u.indexOf('/',${a?11:7}),qi=u.indexOf('?', s + 1);let p
if(qi===-1)p=u.substring(s)
else p=u.substring(s,qi)
`,d&&(o+=`const id=randomId()
`),o+="const ctx={request,store,qi,path,url,redirect,error,set: {headers: ",o+=Object.keys(r??{}).length?"Object.assign({}, app.setHeaders)":"{}",o+=",status: 200}",n.inference.server&&(o+=",get server(){return getServer()}"),d&&(o+=",[ELYSIA_REQUEST_ID]:id"),o+=f,o+=`}
`,n.event.trace.length&&(o+="ctx[ELYSIA_TRACE]=["+n.event.trace.map((y,b)=>`tr${b}(ctx)`).join(",")+`]
`);const A=ie({context:"ctx",trace:n.event.trace,addFn(y){o+=y}})("request",{attribute:"ctx",total:n.event.request.length});if(n.event.request.length){o+="try{";for(let y=0;y<n.event.request.length;y++){const b=n.event.request[y],V=(0,P.hasReturn)(b),I=g(b),Y=A.resolveChild(n.event.request[y].fn.name);V?(o+=`re=mapEarlyResponse(${I?"await ":""}onRequest[${y}](ctx),ctx.set,request)
`),o+="const c={request:r,store,qi,path:p,url:u,redirect,error,set:{headers: ",o+=Object.keys(r??{}).length?"Object.assign({},app.setHeaders)":"{}",o+=",status:200}",n.inference.server&&(o+=",get server(){return getServer()}"),d&&(o+=",[ELYSIA_REQUEST_ID]:id"),o+=f,o+=`}
`,n.event.trace.length&&(o+="c[ELYSIA_TRACE]=["+n.event.trace.map((y,b)=>`tr${b}(c)`).join(",")+`]
`);const A=ie({context:"c",trace:n.event.trace,addFn(y){o+=y}})("request",{attribute:"c",total:n.event.request.length});if(n.event.request.length){o+="try{";for(let y=0;y<n.event.request.length;y++){const b=n.event.request[y],V=(0,P.hasReturn)(b),I=g(b),Y=A.resolveChild(n.event.request[y].fn.name);V?(o+=`re=mapEarlyResponse(${I?"await ":""}onRequest[${y}](c),c.set,r)
`,Y("re"),o+=`if(re!==undefined)return re
`):(o+=`${I?"await ":""}onRequest[${y}](ctx)
`,Y())}o+="}catch(error){return app.handleError(ctx,error)}"}A.resolve();const C=n.router.static.ws,e=n.router.ws;if(Object.keys(C).length||e.history.length){o+="if(request.method==='GET'){switch(path){";for(const[y,b]of Object.entries(C))o+=`case'${y}':if(request.headers.get('upgrade')==='websocket')return st[${b}](ctx)
`;o+=`default:if(request.headers.get('upgrade')==='websocket'){const route=wsRouter.find('ws',path)
if(route){ctx.params=route.params
if(route.store.handler)return route.store.handler(ctx)
return (route.store.handler=route.store.compile())(ctx)}}break}}`}if(o+="map:switch(path){"+u+`
default:break}`+m+`}
`,n.extender.higherOrderFunctions.length){let y="map";for(let b=0;b<n.extender.higherOrderFunctions.length;b++)y=`hoc[${b}](${y},request)`;o+=`return function hocMap(request){return ${y}(request)}`}else o+="return map";const Z=ye(n);return n.handleError=Z,Function("data",o)({app:n,mapEarlyResponse:j.mapEarlyResponse,NotFoundError:x.NotFoundError,randomId:v.randomId,handleError:Z,error:ae.error,redirect:v.redirect,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID,getServer:()=>n.getServer()})},ye=n=>{const a=n.event;let f="";f+=`const {app:{event:{error:onErrorContainer,afterResponse:resContainer,mapResponse:_onMapResponse,trace:_trace}},mapResponse,ERROR_CODE,ELYSIA_RESPONSE,ELYSIA_TRACE,ELYSIA_REQUEST_ID}=inject
`):(o+=`${I?"await ":""}onRequest[${y}](c)
`,Y())}o+="}catch(error){return app.handleError(c,error)}"}A.resolve();const C=n.router.static.ws,e=n.router.ws;if(Object.keys(C).length||e.history.length){o+="if(r.method==='GET'){switch(p){";for(const[y,b]of Object.entries(C))o+=`case'${y}':if(r.headers.get('upgrade')==='websocket')return st[${b}](c)
`;o+=`default:if(r.headers.get('upgrade')==='websocket'){const route=wsRouter.find('ws',p)
if(route){c.params=route.params
if(route.store.handler)return route.store.handler(c)
return (route.store.handler=route.store.compile())(c)}}break}}`}if(o+="switch(p){"+m+`
default:break}`+u+`}
`,n.extender.higherOrderFunctions.length){let y="map";for(let b=0;b<n.extender.higherOrderFunctions.length;b++)y=`hoc[${b}](${y},r)`;o+=`return function hocMap(r){return ${y}(r)}`}else o+="return map";const Z=ye(n);return n.handleError=Z,Function("data",o)({app:n,mapEarlyResponse:j.mapEarlyResponse,NotFoundError:w.NotFoundError,randomId:v.randomId,handleError:Z,error:ae.error,redirect:v.redirect,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID,getServer:()=>n.getServer()})},ye=n=>{const a=n.event;let f="";f+=`const {app:{event:{error:onErrorContainer,afterResponse:resContainer,mapResponse:_onMapResponse,trace:_trace}},mapResponse,ERROR_CODE,ELYSIA_RESPONSE,ELYSIA_TRACE,ELYSIA_REQUEST_ID}=inject
`,f+=`const trace=_trace.map(x=>typeof x==='function'?x:x.fn)

@@ -284,3 +283,3 @@ const onMapResponse=[]

return ${n.event.error.find(g)||n.event.mapResponse.find(g)?"async ":""}function(context,error,skipGlobal){`;const o=n.event.trace.length>0;o&&(f+=`const id=context[ELYSIA_REQUEST_ID]
`);const r=ie({context:"context",trace:a.trace,addFn:m=>{f+=m}});f+=`const set = context.set
`);const r=ie({context:"context",trace:a.trace,addFn:u=>{f+=u}});f+=`const set = context.set
let r

@@ -291,4 +290,4 @@ if(!context.code)context.code=error.code??error[ERROR_CODE]

error.message = error.response}
`;const s=o||a.afterResponse.length>0||a.afterResponse.length>0?"context.response = ":"";for(let m=0;m<n.event.error.length;m++){const u=n.event.error[m],$=`${g(u)?"await ":""}onError[${m}](context)
`;if(f+="if(skipGlobal!==true){",(0,P.hasReturn)(u)){f+=`r=${$}
`;const s=o||a.afterResponse.length>0||a.afterResponse.length>0?"context.response = ":"";for(let u=0;u<n.event.error.length;u++){const m=n.event.error[u],$=`${g(m)?"await ":""}onError[${u}](context)
`;if(f+="if(skipGlobal!==true){",(0,P.hasReturn)(m)){f+=`r=${$}
if(r!==undefined){if(r instanceof Response)return r

@@ -300,5 +299,5 @@ if(r[ELYSIA_RESPONSE]){error.status=error[ELYSIA_RESPONSE]

return new Response(error.message,{headers:Object.assign({'content-type':'application/json'},set.headers),status:set.status})}else{if(error.code&&typeof error.status==="number")return new Response(error.message,{headers:set.headers,status:error.status})
`;const d=r("mapResponse",{total:a.mapResponse.length,name:"context"});if(a.mapResponse.length)for(let m=0;m<a.mapResponse.length;m++){const u=a.mapResponse[m],$=d.resolveChild(u.fn.name);f+=`context.response=error
error=${M(u)?"await ":""}onMapResponse[${m}](context)
`;const d=r("mapResponse",{total:a.mapResponse.length,name:"context"});if(a.mapResponse.length)for(let u=0;u<a.mapResponse.length;u++){const m=a.mapResponse[u],$=d.resolveChild(m.fn.name);f+=`context.response=error
error=${M(m)?"await ":""}onMapResponse[${u}](context)
`,$()}return d.resolve(),f+=`
return mapResponse(${s}error,set,context.request)}}`,Function("inject",f)({app:n,mapResponse:j.mapResponse,ERROR_CODE:x.ERROR_CODE,ELYSIA_RESPONSE:x.ELYSIA_RESPONSE,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID})};0&&(module.exports={composeErrorHandler,composeGeneralHandler,composeHandler,hasAdditionalProperties,hasProperty,hasTransform,hasType,isAsync,isAsyncName,isGenerator});
return mapResponse(${s}error,set,context.request)}}`,Function("inject",f)({app:n,mapResponse:j.mapResponse,ERROR_CODE:w.ERROR_CODE,ELYSIA_RESPONSE:w.ELYSIA_RESPONSE,ELYSIA_TRACE:se.ELYSIA_TRACE,ELYSIA_REQUEST_ID:v.ELYSIA_REQUEST_ID})};0&&(module.exports={composeErrorHandler,composeGeneralHandler,composeHandler,hasAdditionalProperties,hasProperty,hasTransform,hasType,isAsync,isAsyncName,isGenerator});

@@ -1,1 +0,1 @@

"use strict";var w=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(e,a)=>{for(var n in a)w(e,n,{get:a[n],enumerable:!0})},F=(e,a,n,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of j(a))!x.call(e,r)&&r!==n&&w(e,r,{get:()=>a[r],enumerable:!(t=C(a,r))||t.enumerable});return e};var O=e=>F(w({},"__esModule",{value:!0}),e);var A={};E(A,{createStaticHandler:()=>B,errorToResponse:()=>c,isNotEmpty:()=>h,mapCompactResponse:()=>d,mapEarlyResponse:()=>f,mapResponse:()=>i,parseSetCookies:()=>g,serializeCookie:()=>k,streamResponse:()=>m});module.exports=O(A);var v=require("cookie"),R=require("./utils"),S=require("./cookies"),y=require("./error");const p="toJSON"in new Headers,h=e=>{if(!e)return!1;for(const a in e)return!0;return!1},b=(e,a)=>{const n=e.size;if(!a&&n||n&&a&&a.status!==206&&a.status!==304&&a.status!==412&&a.status!==416){if(a){if(a.headers instanceof Headers)if(p)a.headers=a.headers.toJSON();else for(const[t,r]of a.headers.entries())t in a.headers&&(a.headers[t]=r);return new Response(e,{status:a.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${n-1}/${n}`},a.headers)})}return new Response(e,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${n-1}/${n}`}})}return new Response(e)},g=(e,a)=>{if(!e)return e;e.delete("set-cookie");for(let n=0;n<a.length;n++){const t=a[n].indexOf("=");e.append("set-cookie",`${a[n].slice(0,t)}=${a[n].slice(t+1)||""}`)}return e},k=e=>{if(!e||!h(e))return;const a=[];for(const[n,t]of Object.entries(e)){if(!n||!t)continue;const r=t.value;r!=null&&a.push((0,v.serialize)(n,typeof r=="object"?JSON.stringify(r):r+"",t))}if(a.length!==0)return a.length===1?a[0]:a},u=async(e,a,n)=>{let t=e.next();return t instanceof Promise&&(t=await t),t.done?a?i(t.value,a,n):d(t.value,n):new Response(new ReadableStream({async start(r){let s=!1;if(n?.signal.addEventListener("abort",()=>{s=!0;try{r.close()}catch{}}),t.value!==void 0&&t.value!==null)if(typeof t.value=="object")try{r.enqueue(Buffer.from(JSON.stringify(t.value)))}catch{r.enqueue(Buffer.from(t.value.toString()))}else r.enqueue(Buffer.from(t.value.toString()));for await(const o of e){if(s)break;if(o!=null){if(typeof o=="object")try{r.enqueue(Buffer.from(JSON.stringify(o)))}catch{r.enqueue(Buffer.from(o.toString()))}else r.enqueue(Buffer.from(o.toString()));await new Promise(l=>setTimeout(()=>l(),0))}}try{r.close()}catch{}}}),{...a,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...a?.headers}})};async function*m(e){const a=e.body;if(!a)return;const n=a.getReader(),t=new TextDecoder;try{for(;;){const{done:r,value:s}=await n.read();if(r)break;yield t.decode(s)}}finally{n.releaseLock()}}const i=(e,a,n)=>{if(h(a.headers)||a.status!==200||a.redirect||a.cookie){if(typeof a.status=="string"&&(a.status=R.StatusMap[a.status]),a.redirect&&(a.headers.Location=a.redirect,(!a.status||a.status<300||a.status>=400)&&(a.status=302)),a.cookie&&h(a.cookie)){const t=k(a.cookie);t&&(a.headers["set-cookie"]=t)}switch(a.headers["set-cookie"]&&Array.isArray(a.headers["set-cookie"])&&(a.headers=g(new Headers(a.headers),a.headers["set-cookie"])),e?.constructor?.name){case"String":return new Response(e,a);case"Blob":return b(e,a);case"Array":return Response.json(e,a);case"Object":const t=e[y.ELYSIA_RESPONSE];if(t)return a.status=t,i(e.response,a,n);for(const s in Object.values(e))switch(s?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e));default:break}return Response.json(e,a);case"ReadableStream":return a.headers["content-type"]?.startsWith("text/event-stream")||(a.headers["content-type"]="text/event-stream; charset=utf-8"),n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,a);case void 0:return e?Response.json(e,a):new Response("",a);case"Response":let r=!1;if(a.headers instanceof Headers)for(const s of a.headers.keys())if(s==="set-cookie"){if(r)continue;r=!0;for(const o of a.headers.getSetCookie())e.headers.append("set-cookie",o)}else e.headers.append(s,a.headers?.get(s)??"");else for(const s in a.headers)e.headers.append(s,a.headers[s]);return e.status!==a.status&&(a.status=e.status),e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Error":return c(e,a);case"Promise":return e.then(s=>i(s,a));case"Function":return i(e(),a);case"Number":case"Boolean":return new Response(e.toString(),a);case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e,a);default:if(e instanceof Response){let s=!1;if(a.headers instanceof Headers)for(const o of a.headers.keys())if(o==="set-cookie"){if(s)continue;s=!0;for(const l of a.headers.getSetCookie())e.headers.append("set-cookie",l)}else e.headers.append(o,a.headers?.get(o)??"");else for(const o in a.headers)e.headers.append(o,a.headers[o]);if(p)a.headers=e.headers.toJSON();else for(const[o,l]of e.headers.entries())o in a.headers&&(a.headers[o]=l);return e}if(e instanceof Promise)return e.then(s=>i(s,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return i(e.toResponse(),a);if("charCodeAt"in e){const s=e.charCodeAt(0);if(s===123||s===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e,a)}}else switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e,a);case"Array":return Response.json(e);case"Object":const t=e[y.ELYSIA_RESPONSE];if(t)return a.status=t,i(e.response,a,n);for(const r in Object.values(e))switch(r?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Error":return c(e,a);case"Promise":return e.then(r=>{const s=d(r,n);return s!==void 0?s:new Response("")});case"Function":return d(e(),n);case"Number":case"Boolean":return new Response(e.toString());case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e,a);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(r=>i(r,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return i(e.toResponse(),a);if("charCodeAt"in e){const r=e.charCodeAt(0);if(r===123||r===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e)}},f=(e,a,n)=>{if(e!=null)if(h(a.headers)||a.status!==200||a.redirect||a.cookie){if(typeof a.status=="string"&&(a.status=R.StatusMap[a.status]),a.redirect&&(a.headers.Location=a.redirect,(!a.status||a.status<300||a.status>=400)&&(a.status=302)),a.cookie&&h(a.cookie)){const t=k(a.cookie);t&&(a.headers["set-cookie"]=t)}switch(a.headers["set-cookie"]&&Array.isArray(a.headers["set-cookie"])&&(a.headers=g(new Headers(a.headers),a.headers["set-cookie"])),e?.constructor?.name){case"String":return new Response(e,a);case"Blob":return b(e,a);case"Array":return Response.json(e,a);case"Object":const t=e[y.ELYSIA_RESPONSE];if(t)return a.status=t,f(e.response,a,n);for(const s in Object.values(e))switch(s?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return a.headers["content-type"]?.startsWith("text/event-stream")||(a.headers["content-type"]="text/event-stream; charset=utf-8"),n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,a);case void 0:return e?Response.json(e,a):void 0;case"Response":let r=!1;if(a.headers instanceof Headers)for(const s of a.headers.keys())if(s==="set-cookie"){if(r)continue;r=!0;for(const o of a.headers.getSetCookie())e.headers.append("set-cookie",o)}else e.headers.append(s,a.headers?.get(s)??"");else for(const s in a.headers)e.headers.append(s,a.headers[s]);return e.status!==a.status&&(a.status=e.status),e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Promise":return e.then(s=>{const o=f(s,a);if(o!==void 0)return o});case"Error":return c(e,a);case"Function":return f(e(),a);case"Number":case"Boolean":return new Response(e.toString(),a);case"FormData":return new Response(e);case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);default:if(e instanceof Response){let s=!1;if(a.headers instanceof Headers)for(const o of a.headers.keys())if(o==="set-cookie"){if(s)continue;s=!0;for(const l of a.headers.getSetCookie())e.headers.append("set-cookie",l)}else e.headers.append(o,a.headers?.get(o)??"");else for(const o in a.headers)e.headers.append(o,a.headers[o]);return e.status!==a.status&&(a.status=e.status),e}if(e instanceof Promise)return e.then(s=>f(s,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return f(e.toResponse(),a);if("charCodeAt"in e){const s=e.charCodeAt(0);if(s===123||s===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e,a)}}else switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e,a);case"Array":return Response.json(e);case"Object":const t=e[y.ELYSIA_RESPONSE];if(t)return a.status=t,f(e.response,a,n);for(const r in Object.values(e))switch(r?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e)):e;case"Promise":return e.then(r=>{const s=f(r,a);if(s!==void 0)return s});case"Error":return c(e,a);case"Function":return d(e(),n);case"Number":case"Boolean":return new Response(e.toString());case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(r=>f(r,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return f(e.toResponse(),a);if("charCodeAt"in e){const r=e.charCodeAt(0);if(r===123||r===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e)}},d=(e,a)=>{switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e);case"Array":return Response.json(e);case"Object":if(e[y.ELYSIA_RESPONSE])return i(e.response,{status:e[y.ELYSIA_RESPONSE],headers:{}});e:for(const n of Object.values(e))switch(n?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e));case"Object":break e;default:break}return Response.json(e);case"ReadableStream":return a?.signal.addEventListener("abort",{handleEvent(){a?.signal.aborted||e.cancel(a)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e)):e;case"Error":return c(e);case"Promise":return e.then(n=>d(n,a));case"Function":return d(e(),a);case"Number":case"Boolean":return new Response(e.toString());case"FormData":return new Response(e);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(n=>d(n,a));if(e instanceof Error)return c(e);if(typeof e?.next=="function")return u(e,void 0,a);if("toResponse"in e)return d(e.toResponse());if("charCodeAt"in e){const n=e.charCodeAt(0);if(n===123||n===91)return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}return new Response(e)}},c=(e,a)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:a?.status!==200?a?.status??500:500,headers:a?.headers}),B=(e,a,n={})=>{if(typeof e=="function")return;const t=i(e,{headers:n});if(a.parse.length===0&&a.transform.length===0&&a.beforeHandle.length===0&&a.afterHandle.length===0)return t.clone.bind(t)};0&&(module.exports={createStaticHandler,errorToResponse,isNotEmpty,mapCompactResponse,mapEarlyResponse,mapResponse,parseSetCookies,serializeCookie,streamResponse});
"use strict";var w=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(e,a)=>{for(var n in a)w(e,n,{get:a[n],enumerable:!0})},F=(e,a,n,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of j(a))!x.call(e,r)&&r!==n&&w(e,r,{get:()=>a[r],enumerable:!(t=C(a,r))||t.enumerable});return e};var O=e=>F(w({},"__esModule",{value:!0}),e);var A={};E(A,{createStaticHandler:()=>B,errorToResponse:()=>c,isNotEmpty:()=>y,mapCompactResponse:()=>d,mapEarlyResponse:()=>f,mapResponse:()=>i,parseSetCookies:()=>g,serializeCookie:()=>k,streamResponse:()=>m});module.exports=O(A);var v=require("cookie"),R=require("./utils"),S=require("./cookies"),h=require("./error");const p="toJSON"in new Headers,y=e=>{if(!e)return!1;for(const a in e)return!0;return!1},b=(e,a)=>{const n=e.size;if(!a&&n||n&&a&&a.status!==206&&a.status!==304&&a.status!==412&&a.status!==416){if(a&&y(a.headers)){if(a.headers instanceof Headers)if(p)a.headers=a.headers.toJSON();else for(const[t,r]of a.headers.entries())t in a.headers&&(a.headers[t]=r);return new Response(e,{status:a.status,headers:Object.assign({"accept-ranges":"bytes","content-range":`bytes 0-${n-1}/${n}`},a.headers)})}return new Response(e,{headers:{"accept-ranges":"bytes","content-range":`bytes 0-${n-1}/${n}`,"transfer-encoding":"chunked"}})}return new Response(e)},g=(e,a)=>{if(!e)return e;e.delete("set-cookie");for(let n=0;n<a.length;n++){const t=a[n].indexOf("=");e.append("set-cookie",`${a[n].slice(0,t)}=${a[n].slice(t+1)||""}`)}return e},k=e=>{if(!e||!y(e))return;const a=[];for(const[n,t]of Object.entries(e)){if(!n||!t)continue;const r=t.value;r!=null&&a.push((0,v.serialize)(n,typeof r=="object"?JSON.stringify(r):r+"",t))}if(a.length!==0)return a.length===1?a[0]:a},u=async(e,a,n)=>{let t=e.next();return t instanceof Promise&&(t=await t),t.done?a?i(t.value,a,n):d(t.value,n):new Response(new ReadableStream({async start(r){let s=!1;if(n?.signal.addEventListener("abort",()=>{s=!0;try{r.close()}catch{}}),t.value!==void 0&&t.value!==null)if(typeof t.value=="object")try{r.enqueue(Buffer.from(JSON.stringify(t.value)))}catch{r.enqueue(Buffer.from(t.value.toString()))}else r.enqueue(Buffer.from(t.value.toString()));for await(const o of e){if(s)break;if(o!=null){if(typeof o=="object")try{r.enqueue(Buffer.from(JSON.stringify(o)))}catch{r.enqueue(Buffer.from(o.toString()))}else r.enqueue(Buffer.from(o.toString()));await new Promise(l=>setTimeout(()=>l(),0))}}try{r.close()}catch{}}}),{...a,headers:{"transfer-encoding":"chunked","content-type":"text/event-stream; charset=utf-8",...a?.headers}})};async function*m(e){const a=e.body;if(!a)return;const n=a.getReader(),t=new TextDecoder;try{for(;;){const{done:r,value:s}=await n.read();if(r)break;yield t.decode(s)}}finally{n.releaseLock()}}const i=(e,a,n)=>{if(y(a.headers)||a.status!==200||a.redirect||a.cookie){if(typeof a.status=="string"&&(a.status=R.StatusMap[a.status]),a.redirect&&(a.headers.Location=a.redirect,(!a.status||a.status<300||a.status>=400)&&(a.status=302)),a.cookie&&y(a.cookie)){const t=k(a.cookie);t&&(a.headers["set-cookie"]=t)}switch(a.headers["set-cookie"]&&Array.isArray(a.headers["set-cookie"])&&(a.headers=g(new Headers(a.headers),a.headers["set-cookie"])),e?.constructor?.name){case"String":return new Response(e,a);case"Blob":return b(e,a);case"Array":return Response.json(e,a);case"Object":const t=e[h.ELYSIA_RESPONSE];if(t)return a.status=t,i(e.response,a,n);for(const s in Object.values(e))switch(s?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e));default:break}return Response.json(e,a);case"ReadableStream":return a.headers["content-type"]?.startsWith("text/event-stream")||(a.headers["content-type"]="text/event-stream; charset=utf-8"),n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,a);case void 0:return e?Response.json(e,a):new Response("",a);case"Response":let r=!1;if(a.headers instanceof Headers)for(const s of a.headers.keys())if(s==="set-cookie"){if(r)continue;r=!0;for(const o of a.headers.getSetCookie())e.headers.append("set-cookie",o)}else e.headers.append(s,a.headers?.get(s)??"");else for(const s in a.headers)e.headers.append(s,a.headers[s]);return e.status!==a.status&&(a.status=e.status),e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Error":return c(e,a);case"Promise":return e.then(s=>i(s,a));case"Function":return i(e(),a);case"Number":case"Boolean":return new Response(e.toString(),a);case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e,a);default:if(e instanceof Response){let s=!1;if(a.headers instanceof Headers)for(const o of a.headers.keys())if(o==="set-cookie"){if(s)continue;s=!0;for(const l of a.headers.getSetCookie())e.headers.append("set-cookie",l)}else e.headers.append(o,a.headers?.get(o)??"");else for(const o in a.headers)e.headers.append(o,a.headers[o]);if(p)a.headers=e.headers.toJSON();else for(const[o,l]of e.headers.entries())o in a.headers&&(a.headers[o]=l);return e}if(e instanceof Promise)return e.then(s=>i(s,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return i(e.toResponse(),a);if("charCodeAt"in e){const s=e.charCodeAt(0);if(s===123||s===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e,a)}}else switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e,a);case"Array":return Response.json(e);case"Object":const t=e[h.ELYSIA_RESPONSE];if(t)return a.status=t,i(e.response,a,n);for(const r in Object.values(e))switch(r?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Error":return c(e,a);case"Promise":return e.then(r=>{const s=d(r,n);return s!==void 0?s:new Response("")});case"Function":return d(e(),n);case"Number":case"Boolean":return new Response(e.toString());case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e,a);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(r=>i(r,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return i(e.toResponse(),a);if("charCodeAt"in e){const r=e.charCodeAt(0);if(r===123||r===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e)}},f=(e,a,n)=>{if(e!=null)if(y(a.headers)||a.status!==200||a.redirect||a.cookie){if(typeof a.status=="string"&&(a.status=R.StatusMap[a.status]),a.redirect&&(a.headers.Location=a.redirect,(!a.status||a.status<300||a.status>=400)&&(a.status=302)),a.cookie&&y(a.cookie)){const t=k(a.cookie);t&&(a.headers["set-cookie"]=t)}switch(a.headers["set-cookie"]&&Array.isArray(a.headers["set-cookie"])&&(a.headers=g(new Headers(a.headers),a.headers["set-cookie"])),e?.constructor?.name){case"String":return new Response(e,a);case"Blob":return b(e,a);case"Array":return Response.json(e,a);case"Object":const t=e[h.ELYSIA_RESPONSE];if(t)return a.status=t,f(e.response,a,n);for(const s in Object.values(e))switch(s?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return a.headers["content-type"]?.startsWith("text/event-stream")||(a.headers["content-type"]="text/event-stream; charset=utf-8"),n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,a);case void 0:return e?Response.json(e,a):void 0;case"Response":let r=!1;if(a.headers instanceof Headers)for(const s of a.headers.keys())if(s==="set-cookie"){if(r)continue;r=!0;for(const o of a.headers.getSetCookie())e.headers.append("set-cookie",o)}else e.headers.append(s,a.headers?.get(s)??"");else for(const s in a.headers)e.headers.append(s,a.headers[s]);return e.status!==a.status&&(a.status=e.status),e.headers.get("transfer-encoding")==="chunked"?u(m(e),a,n):e;case"Promise":return e.then(s=>{const o=f(s,a);if(o!==void 0)return o});case"Error":return c(e,a);case"Function":return f(e(),a);case"Number":case"Boolean":return new Response(e.toString(),a);case"FormData":return new Response(e);case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);default:if(e instanceof Response){let s=!1;if(a.headers instanceof Headers)for(const o of a.headers.keys())if(o==="set-cookie"){if(s)continue;s=!0;for(const l of a.headers.getSetCookie())e.headers.append("set-cookie",l)}else e.headers.append(o,a.headers?.get(o)??"");else for(const o in a.headers)e.headers.append(o,a.headers[o]);return e.status!==a.status&&(a.status=e.status),e}if(e instanceof Promise)return e.then(s=>f(s,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return f(e.toResponse(),a);if("charCodeAt"in e){const s=e.charCodeAt(0);if(s===123||s===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e,a)}}else switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e,a);case"Array":return Response.json(e);case"Object":const t=e[h.ELYSIA_RESPONSE];if(t)return a.status=t,f(e.response,a,n);for(const r in Object.values(e))switch(r?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e),a);default:break}return Response.json(e,a);case"ReadableStream":return n?.signal.addEventListener("abort",{handleEvent(){n?.signal.aborted||e.cancel(n)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e)):e;case"Promise":return e.then(r=>{const s=f(r,a);if(s!==void 0)return s});case"Error":return c(e,a);case"Function":return d(e(),n);case"Number":case"Boolean":return new Response(e.toString());case"Cookie":return e instanceof S.Cookie?new Response(e.value,a):new Response(e?.toString(),a);case"FormData":return new Response(e);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(r=>f(r,a));if(e instanceof Error)return c(e,a);if(typeof e?.next=="function")return u(e,a,n);if("toResponse"in e)return f(e.toResponse(),a);if("charCodeAt"in e){const r=e.charCodeAt(0);if(r===123||r===91)return a.headers["Content-Type"]||(a.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),a)}return new Response(e)}},d=(e,a)=>{switch(e?.constructor?.name){case"String":return new Response(e);case"Blob":return b(e);case"Array":return Response.json(e);case"Object":if(e[h.ELYSIA_RESPONSE])return i(e.response,{status:e[h.ELYSIA_RESPONSE],headers:{}});e:for(const n of Object.values(e))switch(n?.constructor?.name){case"Blob":case"File":case"ArrayBuffer":case"FileRef":return new Response((0,R.form)(e));case"Object":break e;default:break}return Response.json(e);case"ReadableStream":return a?.signal.addEventListener("abort",{handleEvent(){a?.signal.aborted||e.cancel(a)}},{once:!0}),new Response(e,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:return e?new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}}):new Response("");case"Response":return e.headers.get("transfer-encoding")==="chunked"?u(m(e)):e;case"Error":return c(e);case"Promise":return e.then(n=>d(n,a));case"Function":return d(e(),a);case"Number":case"Boolean":return new Response(e.toString());case"FormData":return new Response(e);default:if(e instanceof Response)return e;if(e instanceof Promise)return e.then(n=>d(n,a));if(e instanceof Error)return c(e);if(typeof e?.next=="function")return u(e,void 0,a);if("toResponse"in e)return d(e.toResponse());if("charCodeAt"in e){const n=e.charCodeAt(0);if(n===123||n===91)return new Response(JSON.stringify(e),{headers:{"Content-Type":"application/json"}})}return new Response(e)}},c=(e,a)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:a?.status!==200?a?.status??500:500,headers:a?.headers}),B=(e,a,n={})=>{if(typeof e=="function"||e instanceof Blob)return;const t=i(e,{headers:n});if(a.parse.length===0&&a.transform.length===0&&a.beforeHandle.length===0&&a.afterHandle.length===0)return t.headers.has("content-type")||t.headers.append("content-type","text/plain;charset=utf-8"),t.clone.bind(t)};0&&(module.exports={createStaticHandler,errorToResponse,isNotEmpty,mapCompactResponse,mapEarlyResponse,mapResponse,parseSetCookies,serializeCookie,streamResponse});
"use strict";var F=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var K=(b,e)=>{for(var t in e)F(b,t,{get:e[t],enumerable:!0})},Q=(b,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!G.call(b,r)&&r!==t&&F(b,r,{get:()=>e[r],enumerable:!(a=U(e,r))||a.enumerable});return b};var Y=b=>Q(F({},"__esModule",{value:!0}),b);var X={};K(X,{Cookie:()=>$.Cookie,ELYSIA_FORM_DATA:()=>m.ELYSIA_FORM_DATA,ELYSIA_REQUEST_ID:()=>m.ELYSIA_REQUEST_ID,ELYSIA_RESPONSE:()=>p.ELYSIA_RESPONSE,ELYSIA_TRACE:()=>J.ELYSIA_TRACE,ERROR_CODE:()=>p.ERROR_CODE,Elysia:()=>g,InternalServerError:()=>p.InternalServerError,InvalidCookieSignature:()=>p.InvalidCookieSignature,InvertedStatusMap:()=>m.InvertedStatusMap,NotFoundError:()=>p.NotFoundError,ParseError:()=>p.ParseError,StatusMap:()=>m.StatusMap,TypeSystemPolicy:()=>O.TypeSystemPolicy,ValidationError:()=>p.ValidationError,checksum:()=>m.checksum,cloneInference:()=>m.cloneInference,deduplicateChecksum:()=>m.deduplicateChecksum,default:()=>g,error:()=>p.error,form:()=>m.form,getResponseSchemaValidator:()=>m.getResponseSchemaValidator,getSchemaValidator:()=>m.getSchemaValidator,mapCompactResponse:()=>D.mapCompactResponse,mapEarlyResponse:()=>D.mapEarlyResponse,mapResponse:()=>D.mapResponse,mapValueError:()=>p.mapValueError,mergeHook:()=>m.mergeHook,mergeObjectArray:()=>m.mergeObjectArray,redirect:()=>m.redirect,replaceSchemaType:()=>m.replaceSchemaType,replaceUrlPath:()=>m.replaceUrlPath,t:()=>W.t});module.exports=Y(X);var k=require("memoirist"),_=require("./sucrose"),V=require("./ws/index"),N=require("./handler"),l=require("./utils"),w=require("./compose"),q=require("./trace"),i=require("./utils"),B=require("./dynamic-handle"),x=require("./error"),D=require("./handler"),W=require("./type-system"),$=require("./cookies"),J=require("./trace"),m=require("./utils"),p=require("./error"),O=require("@sinclair/typebox/system");class g{constructor(e={}){this.server=null;this.dependencies={};this._routes={};this._types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};this._ephemeral={};this._volatile={};this.singleton={decorator:{},store:{},derive:{},resolve:{}};this.definitions={type:{},error:{}};this.extender={macros:[],higherOrderFunctions:[]};this.validator={global:null,scoped:null,local:null,getCandidate(){return(0,l.mergeSchemaValidator)((0,l.mergeSchemaValidator)(this.global,this.scoped),this.local)}};this.event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],afterResponse:[],trace:[],error:[],stop:[]};this.telemetry={stack:void 0};this.router={http:new k.Memoirist,ws:new k.Memoirist,dynamic:new k.Memoirist,static:{http:{static:{},handlers:[],map:{},all:""},ws:{}},history:[]};this.routeTree=new Map;this.inference={body:!1,cookie:!1,headers:!1,query:!1,set:!1,server:!1};this.handle=async e=>this.fetch(e);this.fetch=e=>(this.fetch=this.config.aot?(0,w.composeGeneralHandler)(this):(0,B.createDynamicHandler)(this))(e);this.handleError=async(e,t)=>(this.handleError=this.config.aot?(0,w.composeErrorHandler)(this):(0,B.createDynamicErrorHandler)(this))(e,t);this.outerErrorHandler=e=>new Response(e.message||e.name||"Error",{status:e?.status??500});this.listen=(e,t)=>{if(typeof Bun>"u")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.compile(),typeof e=="string"){if(!(0,i.isNumericString)(e))throw new Error("Port must be a numeric value");e=parseInt(e)}const a=this.fetch,r=typeof e=="object"?{development:!x.isProduction,reusePort:!0,...this.config.serve||{},...e||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...V.websocket||{}},fetch:a,error:this.outerErrorHandler}:{development:!x.isProduction,reusePort:!0,...this.config.serve||{},static:this.router.static.http.static,websocket:{...this.config.websocket||{},...V.websocket||{}},port:e,fetch:a,error:this.outerErrorHandler};this.server=Bun?.serve(r);for(let o=0;o<this.event.start.length;o++)this.event.start[o].fn(this);return t&&t(this.server),process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let o=0;o<this.event.stop.length;o++)this.event.stop[o].fn(this)}}),this.promisedModules.then(()=>{Bun?.gc(!1)}),this};this.stop=async e=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server&&(this.server.stop(e),this.server=null,this.event.stop.length))for(let t=0;t<this.event.stop.length;t++)this.event.stop[t].fn(this)};e.tags&&(e.detail?e.detail.tags=e.tags:e.detail={tags:e.tags}),e.nativeStaticResponse===void 0&&(e.nativeStaticResponse=!0),this.config={},this.applyConfig(e??{}),e?.analytic&&(e?.name||e?.seed!==void 0)&&(this.telemetry.stack=new Error().stack)}get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}get routes(){return this.router.history}getGlobalRoutes(){return this.router.history}getServer(){return this.server}get promisedModules(){return this._promisedModules||(this._promisedModules=new l.PromiseGroup),this._promisedModules}env(e,t=Bun?.env??process.env){if((0,i.getSchemaValidator)(e,{dynamic:!0,additionalProperties:!0,coerce:!0}).Check(t)===!1){const r=new x.ValidationError("env",e,t);throw new Error(r.all.map(o=>o.summary).join(`
`))}return this}wrap(e){return this.extender.higherOrderFunctions.push({checksum:(0,i.checksum)(JSON.stringify({name:this.config.name,seed:this.config.seed,content:e.toString()})),fn:e}),this}applyMacro(e){if(this.extender.macros.length){const t=(0,i.createMacroManager)({globalHook:this.event,localHook:e}),a={events:{global:this.event,local:e},onParse:t("parse"),onTransform:t("transform"),onBeforeHandle:t("beforeHandle"),onAfterHandle:t("afterHandle"),mapResponse:t("mapResponse"),onAfterResponse:t("afterResponse"),onError:t("error")};for(const r of this.extender.macros)(0,i.traceBackMacro)(r.fn(a),e)}}applyConfig(e){return this.config={prefix:"",aot:!0,strictPath:!1,global:!1,analytic:!1,normalize:!0,...e,cookie:{path:"/",...e?.cookie},experimental:e?.experimental??{},seed:e?.seed===void 0?"":e?.seed},this}get models(){const e={};for(const[t,a]of Object.entries(this.definitions.type))e[t]=(0,i.getSchemaValidator)(a);return e}add(e,t,a,r,{allowMeta:o=!1,skipPrefix:s=!1}={allowMeta:!1,skipPrefix:!1}){if(r=(0,l.localHookToLifeCycleStore)(r),t!==""&&t.charCodeAt(0)!==47&&(t="/"+t),this.config.prefix&&!s&&!this.config.scoped&&(t=this.config.prefix+t),r?.type)switch(r.type){case"text":r.type="text/plain";break;case"json":r.type="application/json";break;case"formdata":r.type="multipart/form-data";break;case"urlencoded":r.type="application/x-www-form-urlencoded";break;case"arrayBuffer":r.type="application/octet-stream";break;default:break}const n=this.definitions.type,c=!this.config.aot,h={...this.validator.getCandidate()},d={body:r?.body??h?.body,headers:r?.headers??h?.headers,params:r?.params??h?.params,query:r?.query??h?.query,cookie:r?.cookie??h?.cookie,response:r?.response??h?.response},f=()=>d.cookie?(0,i.getCookieValidator)({validator:d.cookie,defaultConfig:this.config.cookie,config:d.cookie?.config??{},dynamic:c,models:n}):void 0,u=this.config.normalize,A=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.schema===!0?{body:(0,i.getSchemaValidator)(d.body,{dynamic:c,models:n,normalize:u}),headers:(0,i.getSchemaValidator)(d.headers,{dynamic:c,models:n,additionalProperties:!this.config.normalize,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),params:(0,i.getSchemaValidator)(d.params,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),query:(0,i.getSchemaValidator)(d.query,{dynamic:c,models:n,normalize:u,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),cookie:f(),response:(0,i.getResponseSchemaValidator)(d.response,{dynamic:c,models:n,normalize:u})}:{createBody(){return this.body?this.body:this.body=(0,i.getSchemaValidator)(d.body,{dynamic:c,models:n,normalize:u})},createHeaders(){return this.headers?this.headers:this.headers=(0,i.getSchemaValidator)(d.headers,{dynamic:c,models:n,additionalProperties:!u,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createParams(){return this.params?this.params:this.params=(0,i.getSchemaValidator)(d.params,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createQuery(){return this.query?this.query:this.query=(0,i.getSchemaValidator)(d.query,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createCookie(){return this.cookie?this.cookie:this.cookie=f()},createResponse(){return this.response?this.response:this.response=(0,i.getResponseSchemaValidator)(d.response,{dynamic:c,models:n,normalize:u})}},M=t.endsWith("/")?t.slice(0,t.length-1):t+"/";r=(0,i.mergeHook)(r,h),r.tags&&(r.detail?r.detail.tags=r.tags:r.detail={tags:r.tags}),(0,N.isNotEmpty)(this.config.detail)&&(r.detail=(0,l.mergeDeep)(Object.assign({},this.config.detail),r.detail)),this.applyMacro(r);const S=(0,i.mergeHook)(this.event,r);if(this.config.aot===!1){this.router.dynamic.add(e,t,{validator:A,hooks:S,content:r?.type,handle:a}),this.config.strictPath===!1&&this.router.dynamic.add(e,M,{validator:A,hooks:S,content:r?.type,handle:a}),this.router.history.push({method:e,path:t,composed:null,handler:a,hooks:S});return}const C=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,T=(0,l.cloneInference)(this.inference),R=typeof a!="function"?(0,N.createStaticHandler)(a,S,this.setHeaders):void 0;this.config.nativeStaticResponse===!0&&R&&(e==="GET"||e==="ALL")&&(this.router.static.http.static[t]=R());const L=()=>(0,w.composeHandler)({app:this,path:t,method:e,localHook:(0,i.mergeHook)(r),hooks:S,validator:A,handler:a,allowMeta:o,inference:T}),I=C?L():y=>L()(y),z=this.router.history.length;if(this.routeTree.has(e+t))for(let y=0;y<this.router.history.length;y++){const E=this.router.history[y];if(E.path===t&&E.method===e){const P=this.router.history.splice(y,1)[0];P&&this.routeTree.has(P?.method+P?.path)&&this.routeTree.delete(P.method+P.path)}}else this.routeTree.set(e+t,z);this.router.history.push({method:e,path:t,composed:I,handler:a,hooks:S});const v=this.router.static.http,H={handler:C?I:void 0,compile:L};if(e==="$INTERNALWS"){const y=this.config.strictPath?void 0:t.endsWith("/")?t.slice(0,t.length-1):t+"/";if(t.indexOf(":")===-1&&t.indexOf("*")===-1){const E=v.handlers.length;v.handlers.push(P=>(v.handlers[E]=L())(P)),this.router.static.ws[t]=E,y&&(this.router.static.ws[y]=E)}else this.router.ws.add("ws",t,H),y&&this.router.ws.add("ws",y,H);return}if(t.indexOf(":")===-1&&t.indexOf("*")===-1){const y=v.handlers.length;v.handlers.push(R??(P=>(v.handlers[y]=L())(P))),v.map[t]||(v.map[t]={code:""});const E=R?"":"ctx";e==="ALL"?v.map[t].all=`default: return st[${y}](${E})
`))}return this}wrap(e){return this.extender.higherOrderFunctions.push({checksum:(0,i.checksum)(JSON.stringify({name:this.config.name,seed:this.config.seed,content:e.toString()})),fn:e}),this}applyMacro(e){if(this.extender.macros.length){const t=(0,i.createMacroManager)({globalHook:this.event,localHook:e}),a={events:{global:this.event,local:e},onParse:t("parse"),onTransform:t("transform"),onBeforeHandle:t("beforeHandle"),onAfterHandle:t("afterHandle"),mapResponse:t("mapResponse"),onAfterResponse:t("afterResponse"),onError:t("error")};for(const r of this.extender.macros)(0,i.traceBackMacro)(r.fn(a),e)}}applyConfig(e){return this.config={prefix:"",aot:!0,strictPath:!1,global:!1,analytic:!1,normalize:!0,...e,cookie:{path:"/",...e?.cookie},experimental:e?.experimental??{},seed:e?.seed===void 0?"":e?.seed},this}get models(){const e={};for(const[t,a]of Object.entries(this.definitions.type))e[t]=(0,i.getSchemaValidator)(a);return e}add(e,t,a,r,{allowMeta:o=!1,skipPrefix:s=!1}={allowMeta:!1,skipPrefix:!1}){if(r=(0,l.localHookToLifeCycleStore)(r),t!==""&&t.charCodeAt(0)!==47&&(t="/"+t),this.config.prefix&&!s&&!this.config.scoped&&(t=this.config.prefix+t),r?.type)switch(r.type){case"text":r.type="text/plain";break;case"json":r.type="application/json";break;case"formdata":r.type="multipart/form-data";break;case"urlencoded":r.type="application/x-www-form-urlencoded";break;case"arrayBuffer":r.type="application/octet-stream";break;default:break}const n=this.definitions.type,c=!this.config.aot,h={...this.validator.getCandidate()},d={body:r?.body??h?.body,headers:r?.headers??h?.headers,params:r?.params??h?.params,query:r?.query??h?.query,cookie:r?.cookie??h?.cookie,response:r?.response??h?.response},f=()=>d.cookie?(0,i.getCookieValidator)({validator:d.cookie,defaultConfig:this.config.cookie,config:d.cookie?.config??{},dynamic:c,models:n}):void 0,u=this.config.normalize,A=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.schema===!0?{body:(0,i.getSchemaValidator)(d.body,{dynamic:c,models:n,normalize:u}),headers:(0,i.getSchemaValidator)(d.headers,{dynamic:c,models:n,additionalProperties:!this.config.normalize,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),params:(0,i.getSchemaValidator)(d.params,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),query:(0,i.getSchemaValidator)(d.query,{dynamic:c,models:n,normalize:u,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()}),cookie:f(),response:(0,i.getResponseSchemaValidator)(d.response,{dynamic:c,models:n,normalize:u})}:{createBody(){return this.body?this.body:this.body=(0,i.getSchemaValidator)(d.body,{dynamic:c,models:n,normalize:u})},createHeaders(){return this.headers?this.headers:this.headers=(0,i.getSchemaValidator)(d.headers,{dynamic:c,models:n,additionalProperties:!u,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createParams(){return this.params?this.params:this.params=(0,i.getSchemaValidator)(d.params,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createQuery(){return this.query?this.query:this.query=(0,i.getSchemaValidator)(d.query,{dynamic:c,models:n,coerce:!0,additionalCoerce:(0,l.stringToStructureCoercions)()})},createCookie(){return this.cookie?this.cookie:this.cookie=f()},createResponse(){return this.response?this.response:this.response=(0,i.getResponseSchemaValidator)(d.response,{dynamic:c,models:n,normalize:u})}},M=t.endsWith("/")?t.slice(0,t.length-1):t+"/";r=(0,i.mergeHook)(r,h),r.tags&&(r.detail?r.detail.tags=r.tags:r.detail={tags:r.tags}),(0,N.isNotEmpty)(this.config.detail)&&(r.detail=(0,l.mergeDeep)(Object.assign({},this.config.detail),r.detail)),this.applyMacro(r);const S=(0,i.mergeHook)(this.event,r);if(this.config.aot===!1){this.router.dynamic.add(e,t,{validator:A,hooks:S,content:r?.type,handle:a}),this.config.strictPath===!1&&this.router.dynamic.add(e,M,{validator:A,hooks:S,content:r?.type,handle:a}),this.router.history.push({method:e,path:t,composed:null,handler:a,hooks:S});return}const C=this.config.precompile===!0||typeof this.config.precompile=="object"&&this.config.precompile.compose===!0,T=(0,l.cloneInference)(this.inference),R=typeof a!="function"?(0,N.createStaticHandler)(a,S,this.setHeaders):void 0;this.config.nativeStaticResponse===!0&&R&&(e==="GET"||e==="ALL")&&(this.router.static.http.static[t]=R());const L=()=>(0,w.composeHandler)({app:this,path:t,method:e,localHook:(0,i.mergeHook)(r),hooks:S,validator:A,handler:a,allowMeta:o,inference:T}),I=C?L():y=>L()(y),z=this.router.history.length;if(this.routeTree.has(e+t))for(let y=0;y<this.router.history.length;y++){const E=this.router.history[y];if(E.path===t&&E.method===e){const P=this.router.history.splice(y,1)[0];P&&this.routeTree.has(P?.method+P?.path)&&this.routeTree.delete(P.method+P.path)}}else this.routeTree.set(e+t,z);this.router.history.push({method:e,path:t,composed:I,handler:a,hooks:S});const v=this.router.static.http,H={handler:C?I:void 0,compile:L};if(e==="$INTERNALWS"){const y=this.config.strictPath?void 0:t.endsWith("/")?t.slice(0,t.length-1):t+"/";if(t.indexOf(":")===-1&&t.indexOf("*")===-1){const E=v.handlers.length;v.handlers.push(P=>(v.handlers[E]=L())(P)),this.router.static.ws[t]=E,y&&(this.router.static.ws[y]=E)}else this.router.ws.add("ws",t,H),y&&this.router.ws.add("ws",y,H);return}if(t.indexOf(":")===-1&&t.indexOf("*")===-1){const y=v.handlers.length;v.handlers.push(R??(P=>(v.handlers[y]=L())(P))),v.map[t]||(v.map[t]={code:""});const E=R?"":"c";e==="ALL"?v.map[t].all=`default: return st[${y}](${E})
`:v.map[t].code=`case '${e}': return st[${y}](${E})

@@ -4,0 +4,0 @@ ${v.map[t].code}`,this.config.strictPath||(v.map[M]||(v.map[M]={code:""}),this.config.nativeStaticResponse===!0&&R&&(e==="GET"||e==="ALL")&&(this.router.static.http.static[M]=R()),e==="ALL"?v.map[M].all=`default: return st[${y}](${E})

@@ -672,2 +672,3 @@ import type { Elysia } from '.';

export type HigherOrderFunction<T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function> = (fn: T, request: Request) => ReturnType<T>;
type SetContentType = 'application/octet-stream' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'application/json' | 'application/ld+json' | 'application/ogg' | 'application/pdf' | 'application/rtf' | 'application/wasm' | 'application/xhtml+xml' | 'application/xml' | 'application/zip' | 'text/css' | 'text/csv' | 'text/html' | 'text/calendar' | 'text/javascript' | 'text/plain' | 'text/xml' | 'image/avif' | 'image/bmp' | 'image/gif' | 'image/x-icon' | 'image/jpeg' | 'image/png' | 'image/svg+xml' | 'image/tiff' | 'image/webp' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/form-data' | 'audio/aac' | 'audio/x-midi' | 'audio/mpeg' | 'audio/ogg' | 'audio/opus' | 'audio/webm' | 'video/x-msvideo' | 'video/quicktime' | 'video/x-ms-wmv' | 'video/x-msvideo' | 'video/x-flv' | 'video/av1' | 'video/mp4' | 'video/mpeg' | 'video/ogg' | 'video/mp2t' | 'video/webm' | 'video/3gpp' | 'video/3gpp2' | 'font/otf' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'model/gltf+json' | 'model/gltf-binary';
export type HTTPHeaders = Record<string, string> & {

@@ -712,3 +713,3 @@ 'www-authenticate'?: string;

'content-length'?: string;
'content-type'?: string;
'content-type'?: SetContentType | (string & {});
'content-encoding'?: string;

@@ -715,0 +716,0 @@ 'content-language'?: string;

@@ -1,1 +0,1 @@

"use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(n,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of i(e))!d.call(n,t)&&t!==a&&o(n,t,{get:()=>e[t],enumerable:!(r=s(e,t))||r.enumerable});return n};var p=n=>l(o({},"__esModule",{value:!0}),n);var c={};module.exports=p(c);
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(n,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of s(e))!d.call(n,t)&&t!==a&&o(n,t,{get:()=>e[t],enumerable:!(r=i(e,t))||r.enumerable});return n};var p=n=>l(o({},"__esModule",{value:!0}),n);var c={};module.exports=p(c);

@@ -672,2 +672,3 @@ import type { Elysia } from '.';

export type HigherOrderFunction<T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function> = (fn: T, request: Request) => ReturnType<T>;
type SetContentType = 'application/octet-stream' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'application/json' | 'application/ld+json' | 'application/ogg' | 'application/pdf' | 'application/rtf' | 'application/wasm' | 'application/xhtml+xml' | 'application/xml' | 'application/zip' | 'text/css' | 'text/csv' | 'text/html' | 'text/calendar' | 'text/javascript' | 'text/plain' | 'text/xml' | 'image/avif' | 'image/bmp' | 'image/gif' | 'image/x-icon' | 'image/jpeg' | 'image/png' | 'image/svg+xml' | 'image/tiff' | 'image/webp' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/form-data' | 'audio/aac' | 'audio/x-midi' | 'audio/mpeg' | 'audio/ogg' | 'audio/opus' | 'audio/webm' | 'video/x-msvideo' | 'video/quicktime' | 'video/x-ms-wmv' | 'video/x-msvideo' | 'video/x-flv' | 'video/av1' | 'video/mp4' | 'video/mpeg' | 'video/ogg' | 'video/mp2t' | 'video/webm' | 'video/3gpp' | 'video/3gpp2' | 'font/otf' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'model/gltf+json' | 'model/gltf-binary';
export type HTTPHeaders = Record<string, string> & {

@@ -712,3 +713,3 @@ 'www-authenticate'?: string;

'content-length'?: string;
'content-type'?: string;
'content-type'?: SetContentType | (string & {});
'content-encoding'?: string;

@@ -715,0 +716,0 @@ 'content-language'?: string;

{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.2.0-exp.2",
"version": "1.2.0-exp.3",
"author": {

@@ -6,0 +6,0 @@ "name": "saltyAom",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc