Comparing version 1.2.0-exp.5 to 1.2.0-exp.6
@@ -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 we=(n,a,f)=>(f=n!=null?Re(ve(n)):{},pe(a||!n||!n.__esModule?ne(f,"default",{value:n,enumerable:!0}):f,n)),qe=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=qe(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 xe=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${$}?.() | ||
"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${$}?.() | ||
`)}}}}},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,6 +13,6 @@ `;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: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+=xe?`c.headers = c.request.headers.toJSON() | ||
`;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 | ||
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() | ||
`:`c.headers = {} | ||
@@ -24,6 +24,6 @@ for (const [key, value] of c.request.headers.entries()) | ||
c.cookie=await parseCookie(c.set,c.request.headers.get('cookie'),${t}) | ||
`}if(Z){const i=[];if(s.query&&s.query.schema.type==="object"){const t=s.query.schema.properties;if(!H(s.query))for(let[c,l]of Object.entries(t)){let p=l;p&&de.optional in p&&p.type==="array"&&p.items&&(p=p.items);const{type:x,anyOf:_}=p,N=x==="array"||_?.some(S=>S.type==="string"&&S.format==="ArrayString");i.push({key:c,isArray:N,isNestedObjectArray:N&&p.items?.type==="object"||!!p.items?.anyOf?.some(S=>S.type==="object"||S.type==="array"),isObject:x==="object"||_?.some(S=>S.type==="string"&&S.format==="ArrayString"),anyOf:!!_})}}if(!i.length)e+="if(c.qi===-1){c.query={}}else{c.query=parseQueryFromURL(c.url.slice(c.qi + 1))}";else{e+=`if(c.qi!==-1){let url = '&' + c.url.slice(c.qi + 1) | ||
`;let t=0;for(const{key:c,isArray:l,isObject:p,isNestedObjectArray:x,anyOf:_}of i){const N=(t===0?"let ":"")+`memory=url.indexOf('&${c}=') | ||
`}if(Z){const i=[];if(s.query&&s.query.schema.type==="object"){const t=s.query.schema.properties;if(!H(s.query))for(let[c,l]of Object.entries(t)){let p=l;p&&de.optional in p&&p.type==="array"&&p.items&&(p=p.items);const{type:q,anyOf:_}=p,N=q==="array"||_?.some(S=>S.type==="string"&&S.format==="ArrayString");i.push({key:c,isArray:N,isNestedObjectArray:N&&p.items?.type==="object"||!!p.items?.anyOf?.some(S=>S.type==="object"||S.type==="array"),isObject:q==="object"||_?.some(S=>S.type==="string"&&S.format==="ArrayString"),anyOf:!!_})}}if(!i.length)e+="if(c.qi===-1){c.query={}}else{c.query=parseQueryFromURL(c.url.slice(c.qi + 1))}";else{e+=`if(c.qi!==-1){let url = '&' + c.url.slice(c.qi + 1) | ||
`;let t=0;for(const{key:c,isArray:l,isObject:p,isNestedObjectArray:q,anyOf:_}of i){const N=(t===0?"let ":"")+`memory=url.indexOf('&${c}=') | ||
let a${t} | ||
`;l?(e+=N,x?e+=`while(memory!==-1){const start=memory+${c.length+2} | ||
`;l?(e+=N,q?e+=`while(memory!==-1){const start=memory+${c.length+2} | ||
memory=url.indexOf('&',start) | ||
@@ -74,4 +74,4 @@ if(a${t}===undefined) | ||
`}}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=m.cookie||m.set||I||C||s.response||$&&V||he,q=",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 | ||
`);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 | ||
`,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() | ||
@@ -149,3 +149,3 @@ `;break;case"urlencoded":case"application/x-www-form-urlencoded":e+=`c.body=parseQuery(await c.request.text()) | ||
`;O(s.cookie)&&(e+="if(isNotEmpty(c.cookie)){"),e+="if(validator.cookie.Check(cookieValue)===false){"+U("cookie","cookieValue")+"}",F(s.cookie.schema)&&(e+=`for(const [key,value] of Object.entries(validator.cookie.Decode(cookieValue)))c.cookie[key].value=value | ||
`),O(s.cookie)&&(e+="}")}}if(r?.beforeHandle){const i=R("beforeHandle",{total:r.beforeHandle.length});let t=!1;for(let c=0;c<r.beforeHandle.length;c++){const l=r.beforeHandle[c],p=i.resolveChild(l.fn.name),x=(0,P.hasReturn)(l);if(l.subType==="resolve"||l.subType==="mapResolve")t||(t=!0,e+=` | ||
`),O(s.cookie)&&(e+="}")}}if(r?.beforeHandle){const i=R("beforeHandle",{total:r.beforeHandle.length});let t=!1;for(let c=0;c<r.beforeHandle.length;c++){const l=r.beforeHandle[c],p=i.resolveChild(l.fn.name),q=(0,P.hasReturn)(l);if(l.subType==="resolve"||l.subType==="mapResolve")t||(t=!0,e+=` | ||
let resolved | ||
@@ -165,3 +165,3 @@ `),e+=g(l)?`resolved=await beforeHandle[${c}](c); | ||
else Object.assign(c, resolved) | ||
`;else if(!x)e+=g(l)?`await beforeHandle[${c}](c) | ||
`;else if(!q)e+=g(l)?`await beforeHandle[${c}](c) | ||
`:`beforeHandle[${c}](c) | ||
@@ -178,3 +178,3 @@ `,p();else{if(e+=g(l)?`be=await beforeHandle[${c}](c) | ||
`;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${q})} | ||
if(mr!==undefined)be=c.response=mr}`,J()}}N.resolve(),e+=L,e+=`return mapEarlyResponse(${k}be,c.set${w})} | ||
`}}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} | ||
@@ -184,3 +184,3 @@ `:`let r=c.response=${h} | ||
`:`let r=${h} | ||
`,i.resolve();const t=R("afterHandle",{total:r.afterHandle.length});for(let l=0;l<r.afterHandle.length;l++){const p=r.afterHandle[l],x=(0,P.hasReturn)(p),_=t.resolveChild(p.fn.name);x?(e+=g(p.fn)?`af=await afterHandle[${l}](c) | ||
`,i.resolve();const t=R("afterHandle",{total:r.afterHandle.length});for(let l=0;l<r.afterHandle.length;l++){const p=r.afterHandle[l],q=(0,P.hasReturn)(p),_=t.resolveChild(p.fn.name);q?(e+=g(p.fn)?`af=await afterHandle[${l}](c) | ||
`:`af=afterHandle[${l}](c) | ||
@@ -190,5 +190,5 @@ `,_("af"),s.response?(e+="if(af!==undefined){",t.resolve(),e+=re("af"),e+="c.response=af}"):(e+="if(af!==undefined){",t.resolve(),e+="c.response=af}")):(e+=g(p.fn)?`await afterHandle[${l}](c) | ||
`,_())}t.resolve(),e+=`r=c.response | ||
`,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],x=c.resolveChild(p.fn.name);e+=`mr=${M(p)?"await":""} onMapResponse[${l}](c) | ||
if(mr!==undefined)r=c.response=mr`,x()}c.resolve(),te?e+=`return mapResponse(${k}r,c.set${q}) | ||
`:e+=`return mapCompactResponse(${k}r${q}) | ||
`,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}) | ||
`}else{const i=R("handle",{name:$?d.name:void 0});if(s.response||r.mapResponse.length){e+=Q?`let r=await ${h} | ||
@@ -201,15 +201,15 @@ `:`let r=${h} | ||
if(mr!==undefined)r=c.response=mr} | ||
`,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${q})else return ${h}.clone()`:`return ${h}.clone()`,e+=` | ||
`):te?e+=`return mapResponse(${k}r,c.set${q}) | ||
`:e+=`return mapCompactResponse(${k}r${q}) | ||
`,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}) | ||
`}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${q}) | ||
`:e+=`return mapCompactResponse(${k}r${q}) | ||
`}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${q}) | ||
`;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}) | ||
else return ${h}.clone() | ||
`:`return ${h}.clone() | ||
`:te?e+=`return mapResponse(${k}${t},c.set${q}) | ||
`:e+=`return mapCompactResponse(${k}${t}${q}) | ||
`:te?e+=`return mapResponse(${k}${t},c.set${w}) | ||
`:e+=`return mapCompactResponse(${k}${t}${w}) | ||
`}}if(e+=` | ||
@@ -226,5 +226,5 @@ }catch(error){`,y&&(e+=`if(isParsing)error=new ParseError() | ||
if(er instanceof Promise)er=await er | ||
`,t();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],x=c.resolveChild(p.fn.name);e+=`c.response=er | ||
`,t();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+=`c.response=er | ||
er=${M(p)?"await ":""}onMapResponse[${l}](c) | ||
if(er instanceof Promise)er=await er`,x()}if(c.resolve(),e+=`er=mapEarlyResponse(er,set${q}) | ||
if(er instanceof Promise)er=await er`,q()}if(c.resolve(),e+=`er=mapEarlyResponse(er,set${w}) | ||
`,e+="if(er){",C){for(let l=0;l<r.trace.length;l++)e+=`report${l}.resolve() | ||
@@ -238,12 +238,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 | ||
`),u&&(B+=`c.schema = schema | ||
`),m&&(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: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(request.method,p)";u+=s.http.root.ALL?`??router.find("ALL",p) | ||
`),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) | ||
`:` | ||
`,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(request.method){${b} | ||
${V??"default:"+u}}`),m+=`case'${y}':switch(request.method){${b}${V??"default:"+u}}`;const $=n.event.request.some(g);o+=` | ||
`,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+=` | ||
const {app,mapEarlyResponse,NotFoundError,randomId,handleError,error,redirect,ELYSIA_TRACE,ELYSIA_REQUEST_ID,getServer}=data | ||
@@ -263,18 +263,19 @@ const store=app.singleton.store | ||
`),o+=`${$?"async ":""}function map(request){`,n.event.request.length&&(o+=`let re | ||
`),o+=`const u=request.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) | ||
`),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) | ||
`,d&&(o+=`const id=randomId() | ||
`),o+="const c={request,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,request) | ||
`),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) | ||
`,Y("re"),o+=`if(re!==undefined)return re | ||
`):(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(request.method==='GET'){switch(p){";for(const[y,b]of Object.entries(C))o+=`case'${y}':if(request.headers.get('upgrade')==='websocket')return st[${b}](c) | ||
`;o+=`default:if(request.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},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: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 | ||
`):(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 | ||
`,f+=`const trace=_trace.map(x=>typeof x==='function'?x:x.fn) | ||
@@ -287,3 +288,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:u=>{f+=u}});f+=`const set = context.set | ||
`);const r=ie({context:"context",trace:a.trace,addFn:m=>{f+=m}});f+=`const set = context.set | ||
let r | ||
@@ -294,4 +295,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 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=${$} | ||
`;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=${$} | ||
if(r!==undefined){if(r instanceof Response)return r | ||
@@ -303,5 +304,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 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) | ||
`;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) | ||
`,$()}return d.resolve(),f+=` | ||
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}); | ||
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}); |
"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?"":"c";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?"":"ctx";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}) |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.0-exp.5", | ||
"version": "1.2.0-exp.6", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1303531
10906