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

elysia

Package Overview
Dependencies
Maintainers
1
Versions
442
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia - npm Package Compare versions

Comparing version 0.5.0-exp-230427.2021 to 0.5.0-exp-230427.2352

37

dist/compose.js

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

let e;import{parse as r}from"fast-querystring";import{mapEarlyResponse as t,mapResponse as s}from"./handler";import{SCHEMA as a,DEFS as n,createValidationError as o,removeHostnameRegex as c,removeFragmentRegex as l,removePathRegex as i,removeQueryRegex as u}from"./utils";import{mapErrorCode as f}from"./error";let d="AsyncFunction",p=e=>e.constructor.name===d,h=Bun?.Transpiler?new Bun.Transpiler({minifyWhitespace:!0,inline:!0,platform:"bun",allowBunRuntime:!0}):void 0;export const composeHandler=({method:e,hooks:c,validator:l,handler:i,handleError:u,meta:m})=>{let y="try {\n",$="GET"!==e||i.constructor.name===d||c.parse.length||c.afterHandle.find(p)||c.beforeHandle.find(p)||c.transform.find(p);if($){if(y+=`
let contentType = c.request.headers.get('Content-Type');
let e;import{parse as r}from"fast-querystring";import{mapEarlyResponse as t,mapResponse as s}from"./handler";import{SCHEMA as a,DEFS as n,createValidationError as o,removeHostnameRegex as c,removeFragmentRegex as l,removePathRegex as i,removeQueryRegex as u}from"./utils";import{mapErrorCode as d}from"./error";let f="AsyncFunction",p=e=>e.constructor.name===f,h=(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.includes(`${t}.${e}`))return!0;let s=RegExp(" (\\w+) = context","g"),a=[t];for(let e of r.matchAll(s))a.push(e[1]);let n=RegExp(`{.*?} = (${a.join("|")})`,"g");for(let[t]of r.matchAll(n))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1};export const composeHandler=({method:e,hooks:c,validator:l,handler:i,handleError:u,meta:m})=>{let y="try {\n",$="GET"!==e&&(l.body||[i,...c.transform,...c.beforeHandle,...c.afterHandle].some(e=>h("body",e.toString()))),g=i.constructor.name===f||c.parse.length||c.afterHandle.find(p)||c.beforeHandle.find(p)||c.transform.find(p)||$;if($){if(y+=`
let contentType = c.request.headers.get('content-type')
if (contentType) {
const i = contentType.indexOf(';', 3)
if (i !== -1) contentType = contentType.substring(0, i)
`,c.parse.length){y+=`used = false
`;for(let e=0;e<c.parse.length;e++){let r=`bo${e}`;y+=`if(!used) {
const index = contentType.indexOf(';')
if (index !== -1) contentType = contentType.substring(0, index)
`,c.parse.length){y+=`let used = false
`;for(let e=0;e<c.parse.length;e++){let r=`bo${e}`;y+=`if(!c.request.bodyUsed) {
let ${r} = parse[${e}](c, contentType);

@@ -42,3 +42,3 @@ if(${r} instanceof Promise) ${r} = await ${r}

}}
`}if(c?.transform)for(let e=0;e<c.transform.length;e++)y+=c.transform[e].constructor.name===d?`await transform[${e}](c);`:`transform[${e}](c);`;if(l&&(l.headers&&(y+=`
`}if(c?.transform)for(let e=0;e<c.transform.length;e++)y+=c.transform[e].constructor.name===f?`await transform[${e}](c);`:`transform[${e}](c);`;if(l&&(l.headers&&(y+=`
const h = {}

@@ -55,6 +55,6 @@ for (const key of c.request.headers.keys())

}
`),l.params&&(y+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),l.query&&(y+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),l.body&&(y+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),c?.beforeHandle)for(let e=0;e<c.beforeHandle.length;e++){let r=`be${e}`;if(y+=(c.beforeHandle[e].constructor.name===d?`let ${r} = await beforeHandle[${e}](c);
`),l.params&&(y+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),l.query&&(y+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),l.body&&(y+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),c?.beforeHandle)for(let e=0;e<c.beforeHandle.length;e++){let r=`be${e}`;if(y+=(c.beforeHandle[e].constructor.name===f?`let ${r} = await beforeHandle[${e}](c);
`:`let ${r} = beforeHandle[${e}](c);
`)+`if(${r} !== undefined) {
`,c?.afterHandle)for(let e=0;e<c.afterHandle.length;e++){let t=`af${e}`;y+=(c.afterHandle[e].constructor.name===d?`const ${t} = await afterHandle[${e}](c, ${r});
`,c?.afterHandle)for(let e=0;e<c.afterHandle.length;e++){let t=`af${e}`;y+=(c.afterHandle[e].constructor.name===f?`const ${t} = await afterHandle[${e}](c, ${r});
`:`const ${t} = afterHandle[${e}](c, ${r});

@@ -64,5 +64,5 @@ `)+`if(${t} !== undefined) { ${r} = ${t} }

`),y+=`return mapEarlyResponse(${r}, c.set)}
`}if(c?.afterHandle.length){y+=i.constructor.name===d?`let r = await handler(c);
`}if(c?.afterHandle.length){y+=i.constructor.name===f?`let r = await handler(c);
`:`let r = handler(c);
`;for(let e=0;e<c.afterHandle.length;e++){let r=`af${e}`;y+=c.afterHandle[e].constructor.name===d?`let ${r} = await afterHandle[${e}](c, r)
`;for(let e=0;e<c.afterHandle.length;e++){let r=`af${e}`;y+=c.afterHandle[e].constructor.name===f?`let ${r} = await afterHandle[${e}](c, r)
`:`let ${r} = afterHandle[${e}](c, r)

@@ -75,8 +75,8 @@ `,l.response?y+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) }

`),y+=`return mapResponse(r, c.set);
`}else l.response?y+=(i.constructor.name===d?`const r = await handler(c);
`}else l.response?y+=(i.constructor.name===f?`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);":y+=i.constructor.name===d?"return handler(c).then((v) => mapResponse(v, c.set))":"return mapResponse(handler(c), c.set);";y+=`
`+"return mapResponse(r, c.set);":y+=i.constructor.name===f?"return handler(c).then((v) => mapResponse(v, c.set))":"return mapResponse(handler(c), c.set);";y+=`
} catch(error) {
${$?"":"return (async () => {"}
${g?"":"return (async () => {"}
const set = c.set

@@ -104,3 +104,3 @@

return handleError(c.request, error, set)
${$?"":"})()"}
${g?"":"})()"}
}`,y=`const {

@@ -136,7 +136,7 @@ handler,

return ${$?"async":""} function(c) {
return ${g?"async":""} function(c) {
${m?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""}
${y}
}`,h&&(y=h.transformSync(y));let g=Function("hooks",y);return g({handler:i,hooks:c,validator:l,handleError:u,utils:{createValidationError:o,mapResponse:s,mapEarlyResponse:t,mapErrorCode:f,parseQuery:r},meta:m,SCHEMA:m?a:void 0,DEFS:m?n:void 0})};export const composeGeneralHandler=s=>{let a=s.decorators,n=Object.keys(a).length;if(e?.[0]===n&&e[1]===s.event.request.length)return Function("data",e?.[2])({app:s,parseQuery:r,mapEarlyResponse:t,removeHostnameRegex:c,removeQueryRegex:u,removePathRegex:i,removeFragmentRegex:l});let o="";for(let e of Object.keys(a))o+=`,${e}: app.decorators.${e}`;let f=`const {
}`;let b=Function("hooks",y);return b({handler:i,hooks:c,validator:l,handleError:u,utils:{createValidationError:o,mapResponse:s,mapEarlyResponse:t,mapErrorCode:d,parseQuery:r},meta:m,SCHEMA:m?a:void 0,DEFS:m?n:void 0})};export const composeGeneralHandler=s=>{let a=s.decorators,n=Object.keys(a).length;if(e?.[0]===n&&e[1]===s.event.request.length)return Function("data",e?.[2])({app:s,parseQuery:r,mapEarlyResponse:t,removeHostnameRegex:c,removeQueryRegex:u,removePathRegex:i,removeFragmentRegex:l});let o="";for(let e of Object.keys(a))o+=`,${e}: app.decorators.${e}`;let d=`const {
app,

@@ -204,3 +204,2 @@ app: { store, router, _s: _static },

const handle = _static.get(request.method)?.get(path)
// const handle = _static.get(request.method + path)
if (handle) {

@@ -222,2 +221,2 @@ return handle(ctx)

}
}`;return h&&(f=h.transformSync(f)),e=[n,s.event.request.length,f],Function("data",f)({app:s,parseQuery:r,mapEarlyResponse:t,removeHostnameRegex:c,removeQueryRegex:u,removePathRegex:i,removeFragmentRegex:l})};
}`;return e=[n,s.event.request.length,d],Function("data",d)({app:s,parseQuery:r,mapEarlyResponse:t,removeHostnameRegex:c,removeQueryRegex:u,removePathRegex:i,removeFragmentRegex:l})};
{
"name": "elysia",
"description": "Fast, and friendly Bun web framework",
"version": "0.5.0-exp-230427.2021",
"version": "0.5.0-exp-230427.2352",
"author": {

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

@@ -28,11 +28,40 @@ import { Elysia } from '.'

const transpiler = Bun?.Transpiler
? new Bun.Transpiler({
minifyWhitespace: true,
inline: true,
platform: 'bun',
allowBunRuntime: true
})
: undefined
const isFnUse = (keyword: string, fnLiteral: string) => {
const argument = fnLiteral.slice(
fnLiteral.indexOf('(') + 1,
fnLiteral.indexOf(')')
)
if (argument === '') return false
// Using object destructuring
if (argument.charCodeAt(0) === 123) {
// Since Function already format the code, styling is confirmed
if (
argument.includes(`{ ${keyword}`) ||
argument.includes(`, ${keyword}`)
)
return true
return false
}
// Match dot notation
if (fnLiteral.includes(`${argument}.${keyword}`)) return true
const findAliases = new RegExp(` (\\w+) = context`, 'g')
const aliases = [argument]
for (const found of fnLiteral.matchAll(findAliases)) aliases.push(found[1])
const destructuringRegex = new RegExp(`{.*?} = (${aliases.join('|')})`, 'g')
for (const [params] of fnLiteral.matchAll(destructuringRegex)) {
if (params.includes(`{ ${keyword}`) || params.includes(`, ${keyword}`))
return true
}
return false
}
export const composeHandler = ({

@@ -55,4 +84,13 @@ method,

const hasBody =
method !== 'GET' &&
(validator.body ||
[
handler,
...hooks.transform,
...hooks.beforeHandle,
...hooks.afterHandle
].some((fn) => isFnUse('body', fn.toString())))
const maybeAsync =
method !== 'GET' ||
handler.constructor.name === ASYNC_FN ||

@@ -62,15 +100,16 @@ hooks.parse.length ||

hooks.beforeHandle.find(isAsync) ||
hooks.transform.find(isAsync)
hooks.transform.find(isAsync) ||
hasBody
if (maybeAsync) {
if (hasBody) {
fnLiteral += `
let contentType = c.request.headers.get('Content-Type');
let contentType = c.request.headers.get('content-type')
if (contentType) {
const i = contentType.indexOf(';', 3)
if (i !== -1) contentType = contentType.substring(0, i)
const index = contentType.indexOf(';')
if (index !== -1) contentType = contentType.substring(0, index)
`
if (hooks.parse.length) {
fnLiteral += `used = false\n`
fnLiteral += `let used = false\n`

@@ -80,3 +119,3 @@ for (let i = 0; i < hooks.parse.length; i++) {

fnLiteral += `if(!used) {
fnLiteral += `if(!c.request.bodyUsed) {
let ${name} = parse[${i}](c, contentType);

@@ -300,4 +339,2 @@ if(${name} instanceof Promise) ${name} = await ${name}

if (transpiler) fnLiteral = transpiler.transformSync(fnLiteral)
const createHandler = Function('hooks', fnLiteral)

@@ -319,3 +356,3 @@

SCHEMA: meta ? SCHEMA : undefined,
DEFS: meta ? DEFS : undefined,
DEFS: meta ? DEFS : undefined
})

@@ -355,3 +392,3 @@ }

let fnLiteral = `const {
const fnLiteral = `const {
app,

@@ -427,3 +464,2 @@ app: { store, router, _s: _static },

const handle = _static.get(request.method)?.get(path)
// const handle = _static.get(request.method + path)
if (handle) {

@@ -447,4 +483,2 @@ return handle(ctx)

if (transpiler) fnLiteral = transpiler.transformSync(fnLiteral)
generalCached = [totalDecorators, app.event.request.length, fnLiteral]

@@ -451,0 +485,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc