Comparing version 0.5.4 to 0.5.5-exp-230525.21
@@ -17,3 +17,3 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),function(e,r){for(var t in r)Object.defineProperty(e,t,{enumerable:!0,get:r[t]})}(exports,{hasReturn:function(){return l},isFnUse:function(){return u},findElysiaMeta:function(){return f},composeHandler:function(){return d},composeGeneralHandler:function(){return p},composeErrorHandler:function(){return y}});const e=require("fast-querystring"),r=require("./handler"),t=require("./utils"),n=require("./error"),s="AsyncFunction",o=e=>e.constructor.name===s,a=new Headers,c=RegExp(" (\\w+) = context","g"),l=e=>{let r=e.indexOf(")");return 61===e.charCodeAt(r+2)&&123!==e.charCodeAt(r+5)||e.includes("return")},i=e=>({composeValidation:(r,t=`c.${r}`)=>e?`throw new ValidationError( | ||
${r} | ||
).toResponse(c.set.headers)`}),u=(e,r)=>{let t=r.slice(r.indexOf("(")+1,r.indexOf(")"));if(""===t)return!1;if(123===t.charCodeAt(0))return!!(t.includes(`{ ${e}`)||t.includes(`, ${e}`));if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let n=[t];for(let e of r.matchAll(c))n.push(e[1]);let s=RegExp(`{.*?} = (${n.join("|")})`,"g");for(let[t]of r.matchAll(s))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1},f=(e,r,t=[],n="")=>{if("object"===r.type){let s=r.properties;for(let r in s){let o=s[r],a=n?n+"."+r:r;if("object"===o.type){f(e,o,t,a);continue}if(o.anyOf){for(let r of o.anyOf)f(e,r,t,a);continue}o.elysiaMeta===e&&t.push(a)}return 0===t.length?null:t}return r?.elysiaMeta===e?(n&&t.push(n),"root"):null},d=({method:c,hooks:d,validator:p,handler:y,handleError:$,meta:h,onRequest:m,config:b})=>{let E=b.forceErrorEncapsulation||d.error.length>0||void 0===Bun,{composeValidation:q,composeResponseValidation:g}=i(E),w=E?"try {\n":"",x="string"==typeof d.type,k=p||"GET"!==c?[y,...d.transform,...d.beforeHandle,...d.afterHandle].map(e=>e.toString()):[],H="GET"!==c&&(p.body||x||k.some(e=>u("body",e))),R=p.headers||k.some(e=>u("headers",e));R&&(w+=a.toJSON?`c.headers = c.request.headers.toJSON() | ||
).toResponse(c.set.headers)`}),u=(e,r)=>{let t=r.slice(r.indexOf("(")+1,r.indexOf(")"));if(""===t)return!1;if(123===t.charCodeAt(0))return!!(t.includes(`{ ${e}`)||t.includes(`, ${e}`));if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let n=[t];for(let e of r.matchAll(c))n.push(e[1]);let s=RegExp(`{.*?} = (${n.join("|")})`,"g");for(let[t]of r.matchAll(s))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1},f=(e,r,t=[],n="")=>{if("object"===r.type){let s=r.properties;for(let r in s){let o=s[r],a=n?n+"."+r:r;if("object"===o.type){f(e,o,t,a);continue}if(o.anyOf){for(let r of o.anyOf)f(e,r,t,a);continue}o.elysiaMeta===e&&t.push(a)}return 0===t.length?null:t}return r?.elysiaMeta===e?(n&&t.push(n),"root"):null},d=({method:c,hooks:d,validator:p,handler:y,handleError:$,meta:h,onRequest:m,config:b})=>{let E=b.forceErrorEncapsulation||d.error.length>0||void 0===Bun,{composeValidation:q,composeResponseValidation:g}=i(E),w=E?"try {\n":"",k="string"==typeof d.type,x=p||"GET"!==c?[y,...d.transform,...d.beforeHandle,...d.afterHandle].map(e=>e.toString()):[],H="GET"!==c&&(p.body||k||x.some(e=>u("body",e))),R=p.headers||x.some(e=>u("headers",e));R&&(w+=a.toJSON?`c.headers = c.request.headers.toJSON() | ||
`:`c.headers = {} | ||
@@ -25,3 +25,3 @@ for (const key of c.request.headers.keys()) | ||
${q("headers")} | ||
`);let v=p.query||k.some(e=>u("query",e));v&&(w+=`const url = c.request.url | ||
`);let v=p.query||x.some(e=>u("query",e));v&&(w+=`const url = c.request.url | ||
@@ -33,3 +33,3 @@ if(c.query !== -1) { | ||
} | ||
`);let O=k.some(e=>u("set",e))||m.some(e=>u("set",e.toString())),S=H||y.constructor.name===s||d.parse.length||d.afterHandle.find(o)||d.beforeHandle.find(o)||d.transform.find(o);if(H){let e=p?.body?.schema;if(e&&"anyOf"in e){let r=!1,t=e.anyOf[0].type;for(let n of e.anyOf)if(n.type!==t){r=!0;break}r&&(e=void 0)}if(x||e){if(d.parse.length){w+=(R?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
`);let C=x.some(e=>u("set",e))||m.some(e=>u("set",e.toString())),O=H||y.constructor.name===s||d.parse.length||d.afterHandle.find(o)||d.beforeHandle.find(o)||d.transform.find(o);if(H){let e=p?.body?.schema;if(e&&"anyOf"in e){let r=!1,t=e.anyOf[0].type;for(let n of e.anyOf)if(n.type!==t){r=!0;break}r&&(e=void 0)}if(k||e){if(d.parse.length){w+=(R?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
if (contentType) { | ||
@@ -54,3 +54,3 @@ const index = contentType.indexOf(';') | ||
} | ||
})`:w+="c.body = JSON.parse(await c.request.text())":w+="c.body = await c.request.text()";else switch(d.type){case"application/json":w+="c.body = JSON.parse(await c.request.text());";break;case"text/plain":w+="c.body = await c.request.text();";break;case"application/x-www-form-urlencoded":w+="c.body = parseQuery(await c.request.text());";break;case"multipart/form-data":w+=`c.body = {} | ||
})`:w+="c.body = await c.request.json();":w+="c.body = await c.request.text()";else switch(d.type){case"application/json":w+="c.body = await c.request.json();";break;case"text/plain":w+="c.body = await c.request.text();";break;case"application/x-www-form-urlencoded":w+="c.body = parseQuery(await c.request.text());";break;case"multipart/form-data":w+=`c.body = {} | ||
@@ -75,3 +75,3 @@ for (const key of (await c.request.formData()).keys()) { | ||
case 'application/json': | ||
c.body = JSON.parse(await c.request.text()) | ||
c.body = await c.request.json() | ||
break | ||
@@ -139,3 +139,3 @@ | ||
} | ||
`),O?w+=`return mapResponse(r, c.set) | ||
`),C?w+=`return mapResponse(r, c.set) | ||
`:w+=`return mapCompactResponse(r) | ||
@@ -148,5 +148,5 @@ `}else if(p.response)w+=(y.constructor.name===s?`const r = await handler(c); | ||
} | ||
`,O?w+=`return mapResponse(r, c.set) | ||
`,C?w+=`return mapResponse(r, c.set) | ||
`:w+=`return mapCompactResponse(r) | ||
`;else{let e=y.constructor.name===s?"await handler(c) ":"handler(c)";O?w+=`return mapResponse(${e}, c.set) | ||
`;else{let e=y.constructor.name===s?"await handler(c) ":"handler(c)";C?w+=`return mapResponse(${e}, c.set) | ||
`:w+=`return mapCompactResponse(${e}) | ||
@@ -157,3 +157,3 @@ `}E&&(w+=` | ||
${S?"":"return (async () => {"} | ||
${O?"":"return (async () => {"} | ||
const set = c.set | ||
@@ -177,3 +177,3 @@ | ||
return handleError(c.request, error, set) | ||
${S?"":"})()"} | ||
${O?"":"})()"} | ||
}`),w=`const { | ||
@@ -216,6 +216,6 @@ handler, | ||
return ${S?"async":""} function(c) { | ||
return ${O?"async":""} function(c) { | ||
${h?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""} | ||
${w} | ||
}`;let C=Function("hooks",w);return C({handler:y,hooks:d,validator:p,handleError:$,utils:{mapResponse:r.mapResponse,mapCompactResponse:r.mapCompactResponse,mapEarlyResponse:r.mapEarlyResponse,parseQuery:e.parse},error:{ParseError:n.ParseError,NotFoundError:n.NotFoundError,ValidationError:n.ValidationError,InternalServerError:n.InternalServerError},meta:h,SCHEMA:h?t.SCHEMA:void 0,DEFS:h?t.DEFS:void 0})},p=e=>{let t="";for(let r of Object.keys(e.decorators))t+=`,${r}: app.decorators.${r}`;let{router:s,staticRouter:o}=e,a=` | ||
}`;let S=Function("hooks",w);return S({handler:y,hooks:d,validator:p,handleError:$,utils:{mapResponse:r.mapResponse,mapCompactResponse:r.mapCompactResponse,mapEarlyResponse:r.mapEarlyResponse,parseQuery:e.parse},error:{ParseError:n.ParseError,NotFoundError:n.NotFoundError,ValidationError:n.ValidationError,InternalServerError:n.InternalServerError},meta:h,SCHEMA:h?t.SCHEMA:void 0,DEFS:h?t.DEFS:void 0})},p=e=>{let t="";for(let r of Object.keys(e.decorators))t+=`,${r}: app.decorators.${r}`;let{router:s,staticRouter:o}=e,a=` | ||
const route = find(request.method, path) ${s.root.ALL?'?? find("ALL", path)':""} | ||
@@ -222,0 +222,0 @@ if (route === null) |
@@ -17,3 +17,3 @@ import{parse as e}from"fast-querystring";import{mapEarlyResponse as r,mapResponse as t,mapCompactResponse as s}from"./handler";import{SCHEMA as n,DEFS as o}from"./utils";import{ParseError as a,NotFoundError as c,ValidationError as l,InternalServerError as i}from"./error";let f="AsyncFunction",u=e=>e.constructor.name===f,d=new Headers,p=RegExp(" (\\w+) = context","g");export const hasReturn=e=>{let r=e.indexOf(")");return 61===e.charCodeAt(r+2)&&123!==e.charCodeAt(r+5)||e.includes("return")};let y=e=>({composeValidation:(r,t=`c.${r}`)=>e?`throw new ValidationError( | ||
${r} | ||
).toResponse(c.set.headers)`});export const isFnUse=(e,r)=>{let t=r.slice(r.indexOf("(")+1,r.indexOf(")"));if(""===t)return!1;if(123===t.charCodeAt(0))return!!(t.includes(`{ ${e}`)||t.includes(`, ${e}`));if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let s=[t];for(let e of r.matchAll(p))s.push(e[1]);let n=RegExp(`{.*?} = (${s.join("|")})`,"g");for(let[t]of r.matchAll(n))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1};export const findElysiaMeta=(e,r,t=[],s="")=>{if("object"===r.type){let n=r.properties;for(let r in n){let o=n[r],a=s?s+"."+r:r;if("object"===o.type){findElysiaMeta(e,o,t,a);continue}if(o.anyOf){for(let r of o.anyOf)findElysiaMeta(e,r,t,a);continue}o.elysiaMeta===e&&t.push(a)}return 0===t.length?null:t}return r?.elysiaMeta===e?(s&&t.push(s),"root"):null};export const composeHandler=({method:p,hooks:h,validator:$,handler:m,handleError:b,meta:q,onRequest:E,config:g})=>{let x=g.forceErrorEncapsulation||h.error.length>0||void 0===Bun,{composeValidation:w,composeResponseValidation:k}=y(x),H=x?"try {\n":"",R="string"==typeof h.type,v=$||"GET"!==p?[m,...h.transform,...h.beforeHandle,...h.afterHandle].map(e=>e.toString()):[],O="GET"!==p&&($.body||R||v.some(e=>isFnUse("body",e))),S=$.headers||v.some(e=>isFnUse("headers",e));S&&(H+=d.toJSON?`c.headers = c.request.headers.toJSON() | ||
).toResponse(c.set.headers)`});export const isFnUse=(e,r)=>{let t=r.slice(r.indexOf("(")+1,r.indexOf(")"));if(""===t)return!1;if(123===t.charCodeAt(0))return!!(t.includes(`{ ${e}`)||t.includes(`, ${e}`));if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let s=[t];for(let e of r.matchAll(p))s.push(e[1]);let n=RegExp(`{.*?} = (${s.join("|")})`,"g");for(let[t]of r.matchAll(n))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1};export const findElysiaMeta=(e,r,t=[],s="")=>{if("object"===r.type){let n=r.properties;for(let r in n){let o=n[r],a=s?s+"."+r:r;if("object"===o.type){findElysiaMeta(e,o,t,a);continue}if(o.anyOf){for(let r of o.anyOf)findElysiaMeta(e,r,t,a);continue}o.elysiaMeta===e&&t.push(a)}return 0===t.length?null:t}return r?.elysiaMeta===e?(s&&t.push(s),"root"):null};export const composeHandler=({method:p,hooks:h,validator:$,handler:m,handleError:b,meta:q,onRequest:E,config:g})=>{let w=g.forceErrorEncapsulation||h.error.length>0||void 0===Bun,{composeValidation:x,composeResponseValidation:k}=y(w),H=w?"try {\n":"",R="string"==typeof h.type,v=$||"GET"!==p?[m,...h.transform,...h.beforeHandle,...h.afterHandle].map(e=>e.toString()):[],O="GET"!==p&&($.body||R||v.some(e=>isFnUse("body",e))),C=$.headers||v.some(e=>isFnUse("headers",e));C&&(H+=d.toJSON?`c.headers = c.request.headers.toJSON() | ||
`:`c.headers = {} | ||
@@ -24,4 +24,4 @@ for (const key of c.request.headers.keys()) | ||
if (headers.Check(c.headers) === false) | ||
${w("headers")} | ||
`);let C=$.query||v.some(e=>isFnUse("query",e));C&&(H+=`const url = c.request.url | ||
${x("headers")} | ||
`);let F=$.query||v.some(e=>isFnUse("query",e));F&&(H+=`const url = c.request.url | ||
@@ -33,3 +33,3 @@ if(c.query !== -1) { | ||
} | ||
`);let F=v.some(e=>isFnUse("set",e))||E.some(e=>isFnUse("set",e.toString())),N=O||m.constructor.name===f||h.parse.length||h.afterHandle.find(u)||h.beforeHandle.find(u)||h.transform.find(u);if(O){let e=$?.body?.schema;if(e&&"anyOf"in e){let r=!1,t=e.anyOf[0].type;for(let s of e.anyOf)if(s.type!==t){r=!0;break}r&&(e=void 0)}if(R||e){if(h.parse.length){H+=(S?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
`);let j=v.some(e=>isFnUse("set",e))||E.some(e=>isFnUse("set",e.toString())),S=O||m.constructor.name===f||h.parse.length||h.afterHandle.find(u)||h.beforeHandle.find(u)||h.transform.find(u);if(O){let e=$?.body?.schema;if(e&&"anyOf"in e){let r=!1,t=e.anyOf[0].type;for(let s of e.anyOf)if(s.type!==t){r=!0;break}r&&(e=void 0)}if(R||e){if(h.parse.length){H+=(C?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
if (contentType) { | ||
@@ -54,3 +54,3 @@ const index = contentType.indexOf(';') | ||
} | ||
})`:H+="c.body = JSON.parse(await c.request.text())":H+="c.body = await c.request.text()";else switch(h.type){case"application/json":H+="c.body = JSON.parse(await c.request.text());";break;case"text/plain":H+="c.body = await c.request.text();";break;case"application/x-www-form-urlencoded":H+="c.body = parseQuery(await c.request.text());";break;case"multipart/form-data":H+=`c.body = {} | ||
})`:H+="c.body = await c.request.json();":H+="c.body = await c.request.text()";else switch(h.type){case"application/json":H+="c.body = await c.request.json();";break;case"text/plain":H+="c.body = await c.request.text();";break;case"application/x-www-form-urlencoded":H+="c.body = parseQuery(await c.request.text());";break;case"multipart/form-data":H+=`c.body = {} | ||
@@ -65,3 +65,3 @@ for (const key of (await c.request.formData()).keys()) { | ||
else c.body[key] = value | ||
}`}h.parse.length&&(H+="}}")}else{if(H+="\n"+(S?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
}`}h.parse.length&&(H+="}}")}else{if(H+="\n"+(C?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+` | ||
if (contentType) { | ||
@@ -76,3 +76,3 @@ const index = contentType.indexOf(';') | ||
case 'application/json': | ||
c.body = JSON.parse(await c.request.text()) | ||
c.body = await c.request.json() | ||
break | ||
@@ -106,5 +106,5 @@ | ||
if (headers.Check(c.headers) === false) { | ||
${w("headers")} | ||
${x("headers")} | ||
} | ||
`),$.params&&(H+=`if(params.Check(c.params) === false) { ${w("params")} }`),$.query&&(H+=`if(query.Check(c.query) === false) { ${w("query")} }`),$.body&&(H+=`if(body.Check(c.body) === false) { ${w("body")} }`)),h?.beforeHandle)for(let e=0;e<h.beforeHandle.length;e++){let r=`be${e}`,t=hasReturn(h.beforeHandle[e].toString());if(t){if(H+=(h.beforeHandle[e].constructor.name===f?`let ${r} = await beforeHandle[${e}](c); | ||
`),$.params&&(H+=`if(params.Check(c.params) === false) { ${x("params")} }`),$.query&&(H+=`if(query.Check(c.query) === false) { ${x("query")} }`),$.body&&(H+=`if(body.Check(c.body) === false) { ${x("body")} }`)),h?.beforeHandle)for(let e=0;e<h.beforeHandle.length;e++){let r=`be${e}`,t=hasReturn(h.beforeHandle[e].toString());if(t){if(H+=(h.beforeHandle[e].constructor.name===f?`let ${r} = await beforeHandle[${e}](c); | ||
`:`let ${r} = beforeHandle[${e}](c); | ||
@@ -141,3 +141,3 @@ `)+`if(${r} !== undefined) { | ||
} | ||
`),F?H+=`return mapResponse(r, c.set) | ||
`),j?H+=`return mapResponse(r, c.set) | ||
`:H+=`return mapCompactResponse(r) | ||
@@ -150,11 +150,11 @@ `}else if($.response)H+=(m.constructor.name===f?`const r = await handler(c); | ||
} | ||
`,F?H+=`return mapResponse(r, c.set) | ||
`,j?H+=`return mapResponse(r, c.set) | ||
`:H+=`return mapCompactResponse(r) | ||
`;else{let e=m.constructor.name===f?"await handler(c) ":"handler(c)";F?H+=`return mapResponse(${e}, c.set) | ||
`;else{let e=m.constructor.name===f?"await handler(c) ":"handler(c)";j?H+=`return mapResponse(${e}, c.set) | ||
`:H+=`return mapCompactResponse(${e}) | ||
`}x&&(H+=` | ||
`}w&&(H+=` | ||
} catch(error) { | ||
${N?"":"return (async () => {"} | ||
${S?"":"return (async () => {"} | ||
const set = c.set | ||
@@ -178,3 +178,3 @@ | ||
return handleError(c.request, error, set) | ||
${N?"":"})()"} | ||
${S?"":"})()"} | ||
}`),H=`const { | ||
@@ -217,3 +217,3 @@ handler, | ||
return ${N?"async":""} function(c) { | ||
return ${S?"async":""} function(c) { | ||
${q?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""} | ||
@@ -220,0 +220,0 @@ ${H} |
{ | ||
"name": "elysia", | ||
"description": "Fast, and friendly Bun web framework", | ||
"version": "0.5.4", | ||
"version": "0.5.5-exp-230525.0021", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
199344
7