Comparing version 1.2.0-exp.3 to 1.2.0-exp.4
@@ -1,7 +0,7 @@ | ||
"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+` | ||
"use strict";var Re=Object.create;var te=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Oe=(t,a)=>{for(var f in a)te(t,f,{get:a[f],enumerable:!0})},pe=(t,a,f,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let r of Se(a))!Ce.call(t,r)&&r!==f&&te(t,r,{get:()=>a[r],enumerable:!(o=Ee(a,r))||o.enumerable});return t};var we=(t,a,f)=>(f=t!=null?Re(ve(t)):{},pe(a||!t||!t.__esModule?te(f,"default",{value:t,enumerable:!0}):f,t)),xe=t=>pe(te({},"__esModule",{value:!0}),t);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=t=>{if(!t)return!1;const a=t?.schema;return!!a&&de.optional in a},H=t=>{if(!t)return!1;const a=t?.schema??t;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:t="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} = ${t}[ELYSIA_TRACE]?.[${o}] ?? trace[${o}](${t}); | ||
`);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:t="",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=t+` | ||
`;r+=`if(typeof ${o}==="object"&&${o}&&ELYSIA_RESPONSE in ${o}){c.set.status=${o}[ELYSIA_RESPONSE] | ||
@@ -13,21 +13,21 @@ ${o}=${o}.response}const isResponse=${o} instanceof 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+=qe?`c.headers = c.request.headers.toJSON() | ||
`;return r+"}"}}),G=Symbol.for("TypeBox.Kind"),le=(t,a)=>{if(a){if(G in a&&a[G]===t)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(t,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(le(t,r.anyOf[s]))return!0}if(G in r&&r[G]===t)return!0}return!1}return a.properties&&G in a.properties&&a.properties[G]===t}},D=(t,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(t in r)return!0;if(r.type==="object"){if(D(t,r))return!0}else if(r.anyOf){for(let s=0;s<r.anyOf.length;s++)if(D(t,r.anyOf[s]))return!0}}return!1}return t in a}},fe=Symbol.for("TypeBox.Transform"),F=t=>{if(t){if(t.type==="object"&&t.properties){const a=t.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 t||t.properties&&fe in t.properties}},je=/(?:return|=>) \S+\(/g,M=t=>(t?.fn??t).constructor.name==="AsyncFunction",g=t=>{const a=t?.fn??t;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=t=>{const a=t?.fn??t;return a.constructor.name==="AsyncGeneratorFunction"||a.constructor.name==="GeneratorFunction"},ke=({app:t,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:t.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=t.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:t.config.cookie,dynamic:!!t.config.aot,config:s.cookie?.config??{},models:t.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 n of E.sign)L+=`if(_setCookie['${n}']?.value){c.set.cookie['${n}'].value=await signCookie(_setCookie['${n}'].value,'${i}')}`;L+="}"}const ee=t.config.normalize,{composeValidation:U,composeResponseValidation:re}=He({normalize:ee,validator:s});if(I&&(e+=qe?`c.headers = c.request.headers.toJSON() | ||
`:`c.headers = {} | ||
for (const [key, value] of c.request.headers.entries()) | ||
c.headers[key] = value`),Y){const i=(c,l)=>{const p=E?.[c]??l;return p?typeof p=="string"?`${c}:'${p}',`:p instanceof Date?`${c}: new Date(${p.getTime()}),`:`${c}:${p},`:typeof l=="string"?`${c}:"${l}",`:`${c}:${l},`},t=E?`{secrets:${E.secrets!==void 0?typeof E.secrets=="string"?`'${E.secrets}'`:"["+E.secrets.reduce((c,l)=>c+`'${l}',`,"")+"]":"undefined"},sign:${E.sign===!0?!0:E.sign!==void 0?"["+E.sign.reduce((c,l)=>c+`'${l}',`,"")+"]":"undefined"},`+i("domain")+i("expires")+i("httpOnly")+i("maxAge")+i("path","/")+i("priority")+i("sameSite")+i("secure")+"}":"undefined";I?e+=` | ||
c.cookie=await parseCookie(c.set,c.headers.cookie,${t}) | ||
c.headers[key] = value`),Y){const i=(c,l)=>{const p=E?.[c]??l;return p?typeof p=="string"?`${c}:'${p}',`:p instanceof Date?`${c}: new Date(${p.getTime()}),`:`${c}:${p},`:typeof l=="string"?`${c}:"${l}",`:`${c}:${l},`},n=E?`{secrets:${E.secrets!==void 0?typeof E.secrets=="string"?`'${E.secrets}'`:"["+E.secrets.reduce((c,l)=>c+`'${l}',`,"")+"]":"undefined"},sign:${E.sign===!0?!0:E.sign!==void 0?"["+E.sign.reduce((c,l)=>c+`'${l}',`,"")+"]":"undefined"},`+i("domain")+i("expires")+i("httpOnly")+i("maxAge")+i("path","/")+i("priority")+i("sameSite")+i("secure")+"}":"undefined";I?e+=` | ||
c.cookie=await parseCookie(c.set,c.headers.cookie,${n}) | ||
`:e+=` | ||
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: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} | ||
c.cookie=await parseCookie(c.set,c.request.headers.get('cookie'),${n}) | ||
`}if(Z){const i=[];if(s.query&&s.query.schema.type==="object"){const n=s.query.schema.properties;if(!H(s.query))for(let[c,l]of Object.entries(n)){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 n=0;for(const{key:c,isArray:l,isObject:p,isNestedObjectArray:q,anyOf:_}of i){const N=(n===0?"let ":"")+`memory=url.indexOf('&${c}=') | ||
let a${n} | ||
`;l?(e+=N,q?e+=`while(memory!==-1){const start=memory+${c.length+2} | ||
memory=url.indexOf('&',start) | ||
if(a${t}===undefined) | ||
a${t}='' | ||
if(a${n}===undefined) | ||
a${n}='' | ||
else | ||
a${t}+=',' | ||
a${n}+=',' | ||
let temp | ||
@@ -39,13 +39,13 @@ if(memory===-1)temp=decodeURIComponent(url.slice(start).replace(/\\+/g,' ')) | ||
temp='"'+temp+'"' | ||
a${t} += temp | ||
a${n} += temp | ||
if(memory === -1)break | ||
memory=url.indexOf('&${c}=',memory) | ||
if(memory === -1)break}try{if(a${t}.charCodeAt(0) === 91)a${t} = JSON.parse(a${t}) | ||
if(memory === -1)break}try{if(a${n}.charCodeAt(0) === 91)a${n} = JSON.parse(a${n}) | ||
else | ||
a${t}=JSON.parse('['+a${t}+']')}catch{} | ||
a${n}=JSON.parse('['+a${n}+']')}catch{} | ||
`:e+=`while(memory!==-1){const start=memory+${c.length+2} | ||
memory=url.indexOf('&',start) | ||
if(a${t}===undefined)a${t}=[] | ||
if(memory===-1){a${t}.push(decodeURIComponent(url.slice(start)).replace(/\\+/g,' ')) | ||
break}else a${t}.push(decodeURIComponent(url.slice(start, memory)).replace(/\\+/g,' ')) | ||
if(a${n}===undefined)a${n}=[] | ||
if(memory===-1){a${n}.push(decodeURIComponent(url.slice(start)).replace(/\\+/g,' ')) | ||
break}else a${n}.push(decodeURIComponent(url.slice(start, memory)).replace(/\\+/g,' ')) | ||
memory=url.indexOf('&${c}=',memory) | ||
@@ -55,8 +55,8 @@ if(memory===-1) break | ||
memory=url.indexOf('&',start) | ||
if(memory===-1)a${t}=decodeURIComponent(url.slice(start).replace(/\\+/g,' '))else a${t}=decodeURIComponent(url.slice(start,memory).replace(/\\+/g,' '))if(a${t}!==undefined)try{a${t}=JSON.parse(a${t})}catch{}}`:(e+=N+`if(memory!==-1){const start=memory+${c.length+2} | ||
if(memory===-1)a${n}=decodeURIComponent(url.slice(start).replace(/\\+/g,' '))else a${n}=decodeURIComponent(url.slice(start,memory).replace(/\\+/g,' '))if(a${n}!==undefined)try{a${n}=JSON.parse(a${n})}catch{}}`:(e+=N+`if(memory!==-1){const start=memory+${c.length+2} | ||
memory=url.indexOf('&',start) | ||
if(memory===-1)a${t}=decodeURIComponent(url.slice(start).replace(/\\+/g,' ')) | ||
else{a${t}=decodeURIComponent(url.slice(start,memory).replace(/\\+/g,' '))`,_&&(e+=` | ||
if(memory===-1)a${n}=decodeURIComponent(url.slice(start).replace(/\\+/g,' ')) | ||
else{a${n}=decodeURIComponent(url.slice(start,memory).replace(/\\+/g,' '))`,_&&(e+=` | ||
let deepMemory=url.indexOf('&${c}=',memory) | ||
if(deepMemory!==-1){a${t}=[a${t}] | ||
if(deepMemory!==-1){a${n}=[a${n}] | ||
let first=true | ||
@@ -72,7 +72,7 @@ while(true){const start=deepMemory+${c.length+2} | ||
if((vStart===91&&vEnd===93)||(vStart===123&&vEnd===125)) | ||
try{a${t}.push(JSON.parse(value))}catch{a${t}.push(value)}if(deepMemory===-1)break}}`),e+="}}"),t++,e+=` | ||
try{a${n}.push(JSON.parse(value))}catch{a${n}.push(value)}if(deepMemory===-1)break}}`),e+="}}"),n++,e+=` | ||
`}e+="c.query={"+i.map(({key:c},l)=>`'${c}':a${l}`).join(",")+"}",e+=`} else c.query = {} | ||
`}}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,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 | ||
`);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),ne=u.cookie||u.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||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() | ||
@@ -92,5 +92,5 @@ `;break;case"urlencoded":case"application/x-www-form-urlencoded":e+=`c.body=parseQuery(await c.request.text()) | ||
`,r.parse.length){e+=`let used=false | ||
`;const t=R("parse",{total:r.parse.length});for(let c=0;c<r.parse.length;c++){const l=t.resolveChild(r.parse[c].fn.name),p=`bo${c}`;c!==0&&(e+="if(!used){"),e+=`let ${p}=parse[${c}](c,contentType) | ||
`;const n=R("parse",{total:r.parse.length});for(let c=0;c<r.parse.length;c++){const l=n.resolveChild(r.parse[c].fn.name),p=`bo${c}`;c!==0&&(e+="if(!used){"),e+=`let ${p}=parse[${c}](c,contentType) | ||
if(${p} instanceof Promise)${p}=await ${p} | ||
if(${p}!==undefined){c.body=${p};used=true}`,l(),c!==0&&(e+="}")}t.resolve()}if(e+=` | ||
if(${p}!==undefined){c.body=${p};used=true}`,l(),c!==0&&(e+="}")}n.resolve()}if(e+=` | ||
delete c.contentType | ||
@@ -121,4 +121,4 @@ `,r.parse.length&&(e+="if(!used){"),r.type&&!Array.isArray(r.type))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() | ||
`}if(ge.resolve(),r?.transform){const i=R("transform",{total:r.transform.length});r.transform.length&&(e+=`let transformed | ||
`);for(let t=0;t<r.transform.length;t++){const c=r.transform[t],l=i.resolveChild(c.fn.name);e+=g(c)?`transformed=await transform[${t}](c) | ||
`:`transformed=transform[${t}](c) | ||
`);for(let n=0;n<r.transform.length;n++){const c=r.transform[n],l=i.resolveChild(c.fn.name);e+=g(c)?`transformed=await transform[${n}](c) | ||
`:`transformed=transform[${n}](c) | ||
`,c.subType==="mapDerive"?e+=`if(transformed?.[ELYSIA_RESPONSE])throw transformed | ||
@@ -136,12 +136,12 @@ else{transformed.request=c.request | ||
`,l()}i.resolve()}if(s){if(s.headers){if(ee&&"Clean"in s.headers&&!H(s.headers)&&(e+=`c.headers=validator.headers.Clean(c.headers); | ||
`),D("default",s.headers.schema))for(const[i,t]of Object.entries(z.Value.Default(s.headers.schema,{}))){const c=typeof t=="object"?JSON.stringify(t):typeof t=="string"?`'${t}'`:t;c!==void 0&&(e+=`c.headers['${i}']??=${c} | ||
`),D("default",s.headers.schema))for(const[i,n]of Object.entries(z.Value.Default(s.headers.schema,{}))){const c=typeof n=="object"?JSON.stringify(n):typeof n=="string"?`'${n}'`:n;c!==void 0&&(e+=`c.headers['${i}']??=${c} | ||
`)}O(s.headers)&&(e+="if(isNotEmpty(c.headers)){"),e+="if(validator.headers.Check(c.headers) === false){"+U("headers")+"}",F(s.headers.schema)&&(e+=`c.headers=validator.headers.Decode(c.headers) | ||
`),O(s.headers)&&(e+="}")}if(s.params){if(D("default",s.params.schema))for(const[i,t]of Object.entries(z.Value.Default(s.params.schema,{}))){const c=typeof t=="object"?JSON.stringify(t):typeof t=="string"?`'${t}'`:t;c!==void 0&&(e+=`c.params['${i}']??=${c} | ||
`),O(s.headers)&&(e+="}")}if(s.params){if(D("default",s.params.schema))for(const[i,n]of Object.entries(z.Value.Default(s.params.schema,{}))){const c=typeof n=="object"?JSON.stringify(n):typeof n=="string"?`'${n}'`:n;c!==void 0&&(e+=`c.params['${i}']??=${c} | ||
`)}e+="if(validator.params.Check(c.params)===false){"+U("params")+"}",F(s.params.schema)&&(e+=`c.params=validator.params.Decode(c.params) | ||
`)}if(s.query){if(ee&&"Clean"in s.query&&!H(s.query)&&(e+=`c.query=validator.query.Clean(c.query) | ||
`),D("default",s.query.schema))for(const[i,t]of Object.entries(z.Value.Default(s.query.schema,{}))){const c=typeof t=="object"?JSON.stringify(t):typeof t=="string"?`'${t}'`:t;c!==void 0&&(e+=`if(c.query['${i}']===undefined)c.query['${i}']=${c} | ||
`),D("default",s.query.schema))for(const[i,n]of Object.entries(z.Value.Default(s.query.schema,{}))){const c=typeof n=="object"?JSON.stringify(n):typeof n=="string"?`'${n}'`:n;c!==void 0&&(e+=`if(c.query['${i}']===undefined)c.query['${i}']=${c} | ||
`)}O(s.query)&&(e+="if(isNotEmpty(c.query)){"),e+="if(validator.query.Check(c.query)===false){"+U("query")+"}",F(s.query.schema)&&(e+=`c.query=validator.query.Decode(Object.assign({},c.query)) | ||
`),O(s.query)&&(e+="}")}if(s.body){ee&&"Clean"in s.body&&!H(s.body)&&(e+=`c.body=validator.body.Clean(c.body) | ||
`);const i=F(s.body.schema);if((i||O(s.body))&&(e+=`const isNotEmptyObject=c.body&&(typeof c.body==="object"&&isNotEmpty(c.body)) | ||
`),D("default",s.body.schema)){const t=z.Value.Default(s.body.schema,s.body.schema.type==="object"?{}:void 0),c=typeof t=="object"?JSON.stringify(t):typeof t=="string"?`'${t}'`:t;e+=`if(validator.body.Check(c.body)===false){if(typeof c.body==='object')c.body=Object.assign(${c},c.body) | ||
`),D("default",s.body.schema)){const n=z.Value.Default(s.body.schema,s.body.schema.type==="object"?{}:void 0),c=typeof n=="object"?JSON.stringify(n):typeof n=="string"?`'${n}'`:n;e+=`if(validator.body.Check(c.body)===false){if(typeof c.body==='object')c.body=Object.assign(${c},c.body) | ||
else c.body=${c} | ||
@@ -151,5 +151,5 @@ `,O(s.body)?e+="if(isNotEmptyObject&&validator.body.Check(c.body)===false){"+U("body")+"}":e+="if(validator.body.Check(c.body)===false){"+U("body")+"}",e+="}"}else O(s.body)?e+="if(isNotEmptyObject&&validator.body.Check(c.body)===false){"+U("body")+"}":e+="if(validator.body.Check(c.body)===false){"+U("body")+"}";i&&(e+=`if(isNotEmptyObject)c.body=validator.body.Decode(c.body) | ||
for(const [key,value] of Object.entries(c.cookie))cookieValue[key]=value.value | ||
`,D("default",K.schema))for(const[i,t]of Object.entries(z.Value.Default(K.schema,{})))e+=`cookieValue['${i}'] = ${typeof t=="object"?JSON.stringify(t):t} | ||
`,D("default",K.schema))for(const[i,n]of Object.entries(z.Value.Default(K.schema,{})))e+=`cookieValue['${i}'] = ${typeof n=="object"?JSON.stringify(n):n} | ||
`;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),q=(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 n=!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")n||(n=!0,e+=` | ||
let resolved | ||
@@ -186,30 +186,30 @@ `),e+=g(l)?`resolved=await beforeHandle[${c}](c); | ||
`:`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],q=(0,P.hasReturn)(p),_=t.resolveChild(p.fn.name);q?(e+=g(p.fn)?`af=await afterHandle[${l}](c) | ||
`,i.resolve();const n=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),_=n.resolveChild(p.fn.name);q?(e+=g(p.fn)?`af=await afterHandle[${l}](c) | ||
`:`af=afterHandle[${l}](c) | ||
`,_("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) | ||
`,_("af"),s.response?(e+="if(af!==undefined){",n.resolve(),e+=re("af"),e+="c.response=af}"):(e+="if(af!==undefined){",n.resolve(),e+="c.response=af}")):(e+=g(p.fn)?`await afterHandle[${l}](c) | ||
`:`afterHandle[${l}](c) | ||
`,_())}t.resolve(),e+=`r=c.response | ||
`,_())}n.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],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${x}) | ||
if(mr!==undefined)r=c.response=mr`,q()}c.resolve(),ne?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} | ||
`:`let r=${h} | ||
`,i.resolve(),s.response&&(e+=re()),R("afterHandle").resolve();const t=R("mapResponse",{total:r.mapResponse.length});if(r.mapResponse.length){e+=` | ||
`,i.resolve(),s.response&&(e+=re()),R("afterHandle").resolve();const n=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+=` | ||
`;for(let c=0;c<r.mapResponse.length;c++){const l=r.mapResponse[c],p=n.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,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}) | ||
`,p()}}n.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${x})else return ${h}.clone()`:`return ${h}.clone()`,e+=` | ||
`):ne?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${x}) | ||
`,i.resolve(),R("afterHandle").resolve();const n=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=n.resolveChild(l.fn.name);e+=`if(mr===undefined){mr=${M(l)?"await ":""}onMapResponse[${c}](c)if(mr!==undefined)r=c.response=mr}`,p()}}n.resolve(),e+=L,ne?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{i.resolve();const n=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${x}) | ||
else return ${h}.clone() | ||
`:`return ${h}.clone() | ||
`:te?e+=`return mapResponse(${k}${t},c.set${x}) | ||
`:e+=`return mapCompactResponse(${k}${t}${x}) | ||
`:ne?e+=`return mapResponse(${k}${n},c.set${x}) | ||
`:e+=`return mapCompactResponse(${k}${n}${x}) | ||
`}}if(e+=` | ||
@@ -223,11 +223,11 @@ }catch(error){`,y&&(e+=`if(isParsing)error=new ParseError() | ||
let er | ||
`;for(let i=0;i<r.error.length;i++){const t=ce.resolveChild(r.error[i].fn.name);g(r.error[i])?e+=`er=await handleErrors[${i}](c) | ||
`;for(let i=0;i<r.error.length;i++){const n=ce.resolveChild(r.error[i].fn.name);g(r.error[i])?e+=`er=await handleErrors[${i}](c) | ||
`:e+=`er=handleErrors[${i}](c) | ||
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],q=c.resolveChild(p.fn.name);e+=`c.response=er | ||
`,n();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`,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() | ||
`;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+=` | ||
await afterResponse[${t}](c) | ||
`;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 n=0;n<r.afterResponse.length;n++){const c=i.resolveChild(r.afterResponse[n].fn.name);e+=` | ||
await afterResponse[${n}](c) | ||
`,c()}i.resolve(),W||(e+="})()"),e+="}"}let B=`const {handler,handleError,hooks: {transform,resolve,beforeHandle,afterHandle,mapResponse: onMapResponse,parse,error: handleErrors,afterResponse,trace: _trace},validator,utils: {mapResponse,mapCompactResponse,mapEarlyResponse,parseQuery,parseQueryFromURL,isNotEmpty},error: {NotFoundError,ValidationError,InternalServerError,ParseError},schema,definitions,ERROR_CODE,parseCookie,signCookie,decodeURIComponent,ELYSIA_RESPONSE,ELYSIA_TRACE,ELYSIA_REQUEST_ID,getServer}=hooks | ||
@@ -238,12 +238,14 @@ const trace=_trace.map(x=>typeof x==='function'?x:x.fn) | ||
`),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(r.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:t.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:t.router.history,definitions:t.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:()=>t.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?.(n=>n.toString()),resolve:i?.resolve?.map?.(n=>n.toString()),beforeHandle:i?.beforeHandle?.map?.(n=>n.toString()),afterHandle:i?.afterHandle?.map?.(n=>n.toString()),mapResponse:i?.mapResponse?.map?.(n=>n.toString()),parse:i?.parse?.map?.(n=>n.toString()),error:i?.error?.map?.(n=>n.toString()),afterResponse:i?.afterResponse?.map?.(n=>n.toString()),stop:i?.stop?.map?.(n=>n.toString())},validator:s,definitions:t.definitions.type,fnLiteral:e}),console.log("---"),process.exit(1)}},Ae=t=>{const a=t.config.handler?.standardHostname??!0;let f="",o="";const r=t.setHeaders;for(const y of Object.keys(t.singleton.decorator))f+=`,${y}: app.singleton.decorator.${y}`;const s=t.router,d=t.event.trace.length>0;let m="const route=router.find(r.method,p)";m+=s.http.root.ALL?`??router.find("ALL",p) | ||
`:` | ||
`,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+=` | ||
`,m+="if(route===null)return ",t.event.error.length?m+="app.handleError(c,notFound)":m+=t.event.request.length?"new Response(error404Message,{status:c.set.status===200?404:c.set.status,headers:c.set.headers})":"error404.clone()",m+=` | ||
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+=` | ||
`;let u="";for(const[y,{code:b,all:V,static:I}]of Object.entries(s.static.http.map))I&&(u+=`case'${y}':switch(r.method){${b} | ||
${V??`default:break map | ||
`}}`),u+=`case'${y}':switch(r.method){${b}${V??`default:break map | ||
`}}`;const $=t.event.request.some(g);o+=` | ||
const {app,mapEarlyResponse,NotFoundError,randomId,handleError,error,redirect,ELYSIA_TRACE,ELYSIA_REQUEST_ID,getServer}=data | ||
@@ -258,7 +260,7 @@ const store=app.singleton.store | ||
const hoc=app.extender.higherOrderFunctions.map(x=>x.fn) | ||
`,n.event.request.length&&(o+=`const onRequest=app.event.request.map(x=>x.fn) | ||
`),n.event.error.length||(o+=`const error404Message=notFound.message.toString() | ||
`,t.event.request.length&&(o+=`const onRequest=app.event.request.map(x=>x.fn) | ||
`),t.event.error.length||(o+=`const error404Message=notFound.message.toString() | ||
const error404=new Response(error404Message,{status:404}) | ||
`),n.event.trace.length&&(o+="const "+n.event.trace.map((y,b)=>`tr${b}=app.event.trace[${b}].fn`).join(",")+` | ||
`),o+=`${$?"async ":""}function map(r){`,n.event.request.length&&(o+=`let re | ||
`),t.event.trace.length&&(o+="const "+t.event.trace.map((y,b)=>`tr${b}=app.event.trace[${b}].fn`).join(",")+` | ||
`),o+=`${$?"async ":""}function map(r){`,t.event.request.length&&(o+=`let re | ||
`),o+=`const u=r.url,s=u.indexOf('/',${a?11:7}),qi=u.indexOf('?', s + 1);let p | ||
@@ -268,14 +270,14 @@ if(qi===-1)p=u.substring(s) | ||
`,d&&(o+=`const id=randomId() | ||
`),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) | ||
`),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}",t.inference.server&&(o+=",get server(){return getServer()}"),d&&(o+=",[ELYSIA_REQUEST_ID]:id"),o+=f,o+=`} | ||
`,t.event.trace.length&&(o+="c[ELYSIA_TRACE]=["+t.event.trace.map((y,b)=>`tr${b}(c)`).join(",")+`] | ||
`);const A=ie({context:"c",trace:t.event.trace,addFn(y){o+=y}})("request",{attribute:"c",total:t.event.request.length});if(t.event.request.length){o+="try{";for(let y=0;y<t.event.request.length;y++){const b=t.event.request[y],V=(0,P.hasReturn)(b),I=g(b),Y=A.resolveChild(t.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}](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) | ||
`,Y())}o+="}catch(error){return app.handleError(c,error)}"}A.resolve();const C=t.router.static.ws,e=t.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 | ||
return (route.store.handler=route.store.compile())(c)}}break}}`}if(o+="map:switch(p){"+u+` | ||
default:break}`+m+`} | ||
`,t.extender.higherOrderFunctions.length){let y="map";for(let b=0;b<t.extender.higherOrderFunctions.length;b++)y=`hoc[${b}](${y},r)`;o+=`return function hocMap(r){return ${y}(r)}`}else o+="return map";const Z=ye(t);return t.handleError=Z,Function("data",o)({app:t,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:()=>t.getServer()})},ye=t=>{const a=t.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,4 +289,4 @@ const onMapResponse=[] | ||
const res=resContainer.map(x=>x.fn) | ||
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 | ||
return ${t.event.error.find(g)||t.event.mapResponse.find(g)?"async ":""}function(context,error,skipGlobal){`;const o=t.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 | ||
let r | ||
@@ -295,4 +297,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<t.event.error.length;m++){const u=t.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 | ||
@@ -304,5 +306,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:t,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}); |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.0-exp.3", | ||
"version": "1.2.0-exp.4", | ||
"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
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
1302953
10908