Comparing version 0.5.0-exp-230422.2036 to 0.5.0-exp-230422.2101
@@ -1,2 +0,2 @@ | ||
import{parse as e}from"fast-querystring";import{mapEarlyResponse as r,mapResponse as t}from"./handler";import{createValidationError as a,mapPathnameAndQueryRegEx as s}from"./utils";import{mapErrorCode as n}from"./error";let o="AsyncFunction",c=e=>e.constructor.name===o;export const composeHandler=({method:s,hooks:l,validator:d,handler:i,handleError:u})=>{let p="try {\n",f="GET"!==s||i.constructor.name===o||l.parse.length||l.afterHandle.find(c)||l.beforeHandle.find(c)||l.transform.find(c);if(f){if(p+=` | ||
import{parse as e}from"fast-querystring";import{mapEarlyResponse as r,mapResponse as t}from"./handler";import{createValidationError as a,mapPathnameAndQueryRegEx as s}from"./utils";import{mapErrorCode as n}from"./error";let o="AsyncFunction",c=e=>e.constructor.name===o,l=Bun?.Transpiler?new Bun.Transpiler({minifyWhitespace:!0,inline:!0,platform:"bun",allowBunRuntime:!0}):null;export const composeHandler=({method:s,hooks:i,validator:d,handler:u,handleError:f})=>{let p="try {\n",h="GET"!==s||u.constructor.name===o||i.parse.length||i.afterHandle.find(c)||i.beforeHandle.find(c)||i.transform.find(c);if(h){if(p+=` | ||
let contentType = c.request.headers.get('content-type'); | ||
@@ -9,4 +9,4 @@ | ||
} | ||
`,l.parse.length){p+=`used = false | ||
`;for(let e=0;e<l.parse.length;e++){let r=`bo${e}`;p+=`if(!c.request.bodyUsed) { | ||
`,i.parse.length){p+=`used = false | ||
`;for(let e=0;e<i.parse.length;e++){let r=`bo${e}`;p+=`if(!c.request.bodyUsed) { | ||
let ${r} = parse[${e}](c, contentType); | ||
@@ -44,4 +44,4 @@ if(${r} instanceof Promise) ${r} = await ${r} | ||
break | ||
`.replace(/\t/g,"")+`}} | ||
`}if(l?.transform)for(let e=0;e<l.transform.length;e++)p+=l.transform[e].constructor.name===o?`await transform[${e}](c);`:`transform[${e}](c);`;if(d&&(d.headers&&(p+=` | ||
}} | ||
`}if(i?.transform)for(let e=0;e<i.transform.length;e++)p+=i.transform[e].constructor.name===o?`await transform[${e}](c);`:`transform[${e}](c);`;if(d&&(d.headers&&(p+=` | ||
const _header = {} | ||
@@ -58,6 +58,6 @@ for (const key of c.request.headers.keys()) | ||
} | ||
`.replace(/\t/g,"")),d.params&&(p+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),d.query&&(p+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),d.body&&(p+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),l?.beforeHandle)for(let e=0;e<l.beforeHandle.length;e++){let r=`be${e}`;if(p+=(l.beforeHandle[e].constructor.name===o?`let ${r} = await beforeHandle[${e}](c); | ||
`),d.params&&(p+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),d.query&&(p+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),d.body&&(p+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),i?.beforeHandle)for(let e=0;e<i.beforeHandle.length;e++){let r=`be${e}`;if(p+=(i.beforeHandle[e].constructor.name===o?`let ${r} = await beforeHandle[${e}](c); | ||
`:`let ${r} = beforeHandle[${e}](c); | ||
`)+`if(${r} !== undefined) { | ||
`,l?.afterHandle)for(let e=0;e<l.afterHandle.length;e++){let t=`af${e}`;p+=(l.afterHandle[e].constructor.name===o?`const ${t} = await afterHandle[${e}](c, ${r}); | ||
`,i?.afterHandle)for(let e=0;e<i.afterHandle.length;e++){let t=`af${e}`;p+=(i.afterHandle[e].constructor.name===o?`const ${t} = await afterHandle[${e}](c, ${r}); | ||
`:`const ${t} = afterHandle[${e}](c, ${r}); | ||
@@ -67,5 +67,5 @@ `)+`if(${t} !== undefined) { ${r} = ${t} } | ||
`),p+=`return mapEarlyResponse(${r}, c.set)} | ||
`}if(l?.afterHandle.length){p+=i.constructor.name===o?`let r = await handler(c); | ||
`}if(i?.afterHandle.length){p+=u.constructor.name===o?`let r = await handler(c); | ||
`:`let r = handler(c); | ||
`;for(let e=0;e<l.afterHandle.length;e++){let r=`af${e}`;p+=l.afterHandle[e].constructor.name===o?`let ${r} = await afterHandle[${e}](c, r) | ||
`;for(let e=0;e<i.afterHandle.length;e++){let r=`af${e}`;p+=i.afterHandle[e].constructor.name===o?`let ${r} = await afterHandle[${e}](c, r) | ||
`:`let ${r} = afterHandle[${e}](c, r) | ||
@@ -78,8 +78,8 @@ `,d.response?p+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) } | ||
`),p+=`return mapResponse(r, c.set); | ||
`}else d.response?p+=(i.constructor.name===o?`const r = await handler(c); | ||
`}else d.response?p+=(u.constructor.name===o?`const r = await handler(c); | ||
`:`const r = handler(c); | ||
`)+`if(response[c.set.status]?.Check(r) === false) { throw createValidationError('response', response[c.set.status], r) } | ||
`+"return mapResponse(r, c.set);":p+=i.constructor.name===o?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";p+=` | ||
`+"return mapResponse(r, c.set);":p+=u.constructor.name===o?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";p+=` | ||
} catch(error) { | ||
${f?"":"return (async () => {"} | ||
${h?"":"return (async () => {"} | ||
const set = c.set | ||
@@ -107,3 +107,3 @@ | ||
return handleError(c.request, error, set) | ||
${f?"":"})()"} | ||
${h?"":"})()"} | ||
}`,p=`const { | ||
@@ -135,69 +135,69 @@ handler, | ||
return ${f?"async":""} function(c) {${p}}`.replace(/\t/g,"");let h=Function("hooks",p);return h({handler:i,hooks:l,validator:d,handleError:u,utils:{createValidationError:a,mapResponse:t,mapEarlyResponse:r,mapErrorCode:n,parseQuery:e}})};export const composeGeneralHandler=t=>{let a=Object.keys(t.decorators).length>0;return Function("data",`const { | ||
app, | ||
parseQuery, | ||
mapPathnameAndQueryRegEx: map, | ||
mapEarlyResponse | ||
} = data | ||
return ${h?"async":""} function(c) {${p}}`,l&&(p=l.transformSync(p));let m=Function("hooks",p);return m({handler:u,hooks:i,validator:d,handleError:f,utils:{createValidationError:a,mapResponse:t,mapEarlyResponse:r,mapErrorCode:n,parseQuery:e}})};export const composeGeneralHandler=t=>{let a=Object.keys(t.decorators).length,n=a>0,o=`const { | ||
app, | ||
parseQuery, | ||
mapPathnameAndQueryRegEx: map, | ||
mapEarlyResponse | ||
} = data | ||
// staticRouter | ||
const _static = app._s | ||
// staticRouter | ||
const _static = app._s | ||
// Raikiri | ||
const router = app.router | ||
// Raikiri | ||
const router = app.router | ||
const ctx = ${a?"app.decorators":`{ | ||
set: { | ||
headers: {}, | ||
status: 200 | ||
}, | ||
params: {}, | ||
query: {} | ||
}`} | ||
const ctx = ${n?"app.decorators":`{ | ||
set: { | ||
headers: {}, | ||
status: 200 | ||
}, | ||
params: {}, | ||
query: {} | ||
}`} | ||
return (request) => { | ||
${a?` | ||
ctx.set = { | ||
headers: {}, | ||
status: 200 | ||
}`:""} | ||
return (request) => { | ||
${n?` | ||
ctx.set = { | ||
headers: {}, | ||
status: 200 | ||
}`:""} | ||
ctx.request = request | ||
ctx.request = request | ||
${t.event.request.length?` | ||
try { | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const response = mapEarlyResponse( | ||
app.event.request[i](ctx), | ||
ctx.set | ||
) | ||
if (response) return response | ||
} | ||
} catch (error) { | ||
return app.handleError(request, error, ctx.set) | ||
}`:""} | ||
${t.event.request.length?` | ||
try { | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const response = mapEarlyResponse( | ||
app.event.request[i](ctx), | ||
ctx.set | ||
) | ||
if (response) return response | ||
} | ||
} catch (error) { | ||
return app.handleError(request, error, ctx.set) | ||
}`:""} | ||
const fracture = map.exec(request.url) | ||
if (fracture[2]) ctx.query = parseQuery(fracture[2]) | ||
${a?"else ctx.query = {}":""} | ||
const fracture = map.exec(request.url) | ||
if (fracture[2]) ctx.query = parseQuery(fracture[2]) | ||
${n?"else ctx.query = {}":""} | ||
const handle = _static.get(request.method + fracture[1]) | ||
if (handle) { | ||
${a?"ctx.params = {}":""} | ||
const handle = _static.get(request.method + fracture[1]) | ||
if (handle) { | ||
${n?"ctx.params = {}":""} | ||
return handle(ctx) | ||
} else { | ||
const route = router._m(request.method, fracture[1]) ?? router._m('ALL', fracture[1]) | ||
return handle(ctx) | ||
} else { | ||
const route = router._m(request.method, fracture[1]) ?? router._m('ALL', fracture[1]) | ||
if (!route) | ||
return app.handleError( | ||
request, | ||
new Error('NOT_FOUND'), | ||
ctx.set | ||
) | ||
if (!route) | ||
return app.handleError( | ||
request, | ||
new Error('NOT_FOUND'), | ||
ctx.set | ||
) | ||
ctx.params = route.params | ||
ctx.params = route.params | ||
return route.store(ctx) | ||
} | ||
}`)({app:t,parseQuery:e,mapPathnameAndQueryRegEx:s,mapEarlyResponse:r})}; | ||
return route.store(ctx) | ||
} | ||
}`;return l&&(o=l.transformSync(o)),Function("data",o)({app:t,parseQuery:e,mapPathnameAndQueryRegEx:s,mapEarlyResponse:r})}; |
{ | ||
"name": "elysia", | ||
"description": "Fast, and friendly Bun web framework", | ||
"version": "0.5.0-exp-230422.2036", | ||
"version": "0.5.0-exp-230422.2101", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
@@ -19,2 +19,11 @@ import { Elysia } from '.' | ||
const transpiler = Bun?.Transpiler | ||
? new Bun.Transpiler({ | ||
minifyWhitespace: true, | ||
inline: true, | ||
platform: 'bun', | ||
allowBunRuntime: true | ||
}) | ||
: null | ||
export const composeHandler = ({ | ||
@@ -99,3 +108,3 @@ method, | ||
break | ||
`.replace(/\t/g, '') | ||
` | ||
@@ -127,3 +136,3 @@ fnLiteral += `}}\n` | ||
} | ||
`.replace(/\t/g, '') | ||
` | ||
@@ -267,8 +276,5 @@ if (validator.params) | ||
return ${maybeAsync ? 'async' : ''} function(c) {${fnLiteral}}`.replace( | ||
/\t/g, | ||
'' | ||
) | ||
return ${maybeAsync ? 'async' : ''} function(c) {${fnLiteral}}` | ||
// console.log(fnLiteral) | ||
if (transpiler) fnLiteral = transpiler.transformSync(fnLiteral) | ||
@@ -294,86 +300,91 @@ const createHandler = Function('hooks', fnLiteral) | ||
// @ts-ignore | ||
const hasDecorators = Object.keys(app.decorators).length > 0 | ||
const totalDecorators = Object.keys(app.decorators).length | ||
const hasDecorators = totalDecorators > 0 | ||
return Function( | ||
'data', | ||
`const { | ||
app, | ||
parseQuery, | ||
mapPathnameAndQueryRegEx: map, | ||
mapEarlyResponse | ||
} = data | ||
let fnLiteral = `const { | ||
app, | ||
parseQuery, | ||
mapPathnameAndQueryRegEx: map, | ||
mapEarlyResponse | ||
} = data | ||
// staticRouter | ||
const _static = app._s | ||
// staticRouter | ||
const _static = app._s | ||
// Raikiri | ||
const router = app.router | ||
// Raikiri | ||
const router = app.router | ||
const ctx = ${ | ||
const ctx = ${ | ||
hasDecorators | ||
? `app.decorators` | ||
: `{ | ||
set: { | ||
headers: {}, | ||
status: 200 | ||
}, | ||
params: {}, | ||
query: {} | ||
}` | ||
} | ||
return (request) => { | ||
${ | ||
hasDecorators | ||
? `app.decorators` | ||
: `{ | ||
set: { | ||
headers: {}, | ||
status: 200 | ||
}, | ||
params: {}, | ||
query: {} | ||
? ` | ||
ctx.set = { | ||
headers: {}, | ||
status: 200 | ||
}` | ||
: '' | ||
} | ||
return (request) => { | ||
${ | ||
hasDecorators | ||
? ` | ||
ctx.set = { | ||
headers: {}, | ||
status: 200 | ||
}` | ||
: '' | ||
} | ||
ctx.request = request | ||
ctx.request = request | ||
${ | ||
app.event.request.length | ||
? ` | ||
try { | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const response = mapEarlyResponse( | ||
app.event.request[i](ctx), | ||
ctx.set | ||
) | ||
if (response) return response | ||
} | ||
} catch (error) { | ||
return app.handleError(request, error, ctx.set) | ||
}` | ||
: '' | ||
} | ||
${ | ||
app.event.request.length | ||
? ` | ||
try { | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const response = mapEarlyResponse( | ||
app.event.request[i](ctx), | ||
ctx.set | ||
) | ||
if (response) return response | ||
} | ||
} catch (error) { | ||
return app.handleError(request, error, ctx.set) | ||
}` | ||
: '' | ||
} | ||
const fracture = map.exec(request.url) | ||
if (fracture[2]) ctx.query = parseQuery(fracture[2]) | ||
${hasDecorators ? `else ctx.query = {}` : ''} | ||
const fracture = map.exec(request.url) | ||
if (fracture[2]) ctx.query = parseQuery(fracture[2]) | ||
${hasDecorators ? `else ctx.query = {}` : ''} | ||
const handle = _static.get(request.method + fracture[1]) | ||
if (handle) { | ||
${hasDecorators ? `ctx.params = {}` : ''} | ||
const handle = _static.get(request.method + fracture[1]) | ||
if (handle) { | ||
${hasDecorators ? `ctx.params = {}` : ''} | ||
return handle(ctx) | ||
} else { | ||
const route = router._m(request.method, fracture[1]) ?? router._m('ALL', fracture[1]) | ||
return handle(ctx) | ||
} else { | ||
const route = router._m(request.method, fracture[1]) ?? router._m('ALL', fracture[1]) | ||
if (!route) | ||
return app.handleError( | ||
request, | ||
new Error('NOT_FOUND'), | ||
ctx.set | ||
) | ||
if (!route) | ||
return app.handleError( | ||
request, | ||
new Error('NOT_FOUND'), | ||
ctx.set | ||
) | ||
ctx.params = route.params | ||
ctx.params = route.params | ||
return route.store(ctx) | ||
} | ||
}` | ||
return route.store(ctx) | ||
} | ||
}` | ||
if (transpiler) fnLiteral = transpiler.transformSync(fnLiteral) | ||
return Function( | ||
'data', | ||
fnLiteral | ||
)({ | ||
@@ -380,0 +391,0 @@ app, |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
203834
41249
5314
28
222