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-230424.1141 to 0.5.0-exp-230424.2222

108

dist/compose.js

@@ -1,2 +0,2 @@

let e;import{parse as r}from"fast-querystring";import{mapEarlyResponse as t,mapResponse as a}from"./handler";import{createValidationError as s,removeHostnameRegex as n,removeFragmentRegex as o,removePathRegex as c,removeQueryRegex as l}from"./utils";import{mapErrorCode as u}from"./error";let i="AsyncFunction",p=e=>e.constructor.name===i,d=Bun?.Transpiler?new Bun.Transpiler({minifyWhitespace:!0,inline:!0,platform:"bun",allowBunRuntime:!0}):null;export const composeHandler=({method:e,hooks:n,validator:o,handler:c,handleError:l})=>{let f="try {\n",h="GET"!==e||c.constructor.name===i||n.parse.length||n.afterHandle.find(p)||n.beforeHandle.find(p)||n.transform.find(p);if(h){if(f+=`
let e;import{parse as r}from"fast-querystring";import{mapEarlyResponse as t,mapResponse as s}from"./handler";import{createValidationError as a,removeHostnameRegex as n,removeFragmentRegex as o,removePathRegex as c,removeQueryRegex as l}from"./utils";import{mapErrorCode as i}from"./error";let u="AsyncFunction",d=e=>e.constructor.name===u,f=Bun?.Transpiler?new Bun.Transpiler({minifyWhitespace:!0,inline:!0,platform:"bun",allowBunRuntime:!0}):null;export const composeHandler=({method:e,hooks:n,validator:o,handler:c,handleError:l})=>{let p="try {\n",h="GET"!==e||c.constructor.name===u||n.parse.length||n.afterHandle.find(d)||n.beforeHandle.find(d)||n.transform.find(d);if(h){if(p+=`
let contentType = c.request.headers.get('content-type');

@@ -9,8 +9,8 @@

}
`,n.parse.length){f+=`used = false
`;for(let e=0;e<n.parse.length;e++){let r=`bo${e}`;f+=`if(!c.request.bodyUsed) {
`,n.parse.length){p+=`used = false
`;for(let e=0;e<n.parse.length;e++){let r=`bo${e}`;p+=`if(!c.request.bodyUsed) {
let ${r} = parse[${e}](c, contentType);
if(${r} instanceof Promise) ${r} = await ${r}
if(${r} !== undefined) { c.body = ${r}; used = true }
}`}f+="if (!used)"}f+=`switch (contentType) {
}`}p+="if (!used)"}p+=`switch (contentType) {
case 'application/json':

@@ -45,3 +45,3 @@ c.body = await c.request.json()

}}
`}if(n?.transform)for(let e=0;e<n.transform.length;e++)f+=n.transform[e].constructor.name===i?`await transform[${e}](c);`:`transform[${e}](c);`;if(o&&(o.headers&&(f+=`
`}if(n?.transform)for(let e=0;e<n.transform.length;e++)p+=n.transform[e].constructor.name===u?`await transform[${e}](c);`:`transform[${e}](c);`;if(o&&(o.headers&&(p+=`
const h = {}

@@ -58,24 +58,24 @@ for (const key of c.request.headers.keys())

}
`),o.params&&(f+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),o.query&&(f+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),o.body&&(f+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),n?.beforeHandle)for(let e=0;e<n.beforeHandle.length;e++){let r=`be${e}`;if(f+=(n.beforeHandle[e].constructor.name===i?`let ${r} = await beforeHandle[${e}](c);
`),o.params&&(p+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),o.query&&(p+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),o.body&&(p+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),n?.beforeHandle)for(let e=0;e<n.beforeHandle.length;e++){let r=`be${e}`;if(p+=(n.beforeHandle[e].constructor.name===u?`let ${r} = await beforeHandle[${e}](c);
`:`let ${r} = beforeHandle[${e}](c);
`)+`if(${r} !== undefined) {
`,n?.afterHandle)for(let e=0;e<n.afterHandle.length;e++){let t=`af${e}`;f+=(n.afterHandle[e].constructor.name===i?`const ${t} = await afterHandle[${e}](c, ${r});
`,n?.afterHandle)for(let e=0;e<n.afterHandle.length;e++){let t=`af${e}`;p+=(n.afterHandle[e].constructor.name===u?`const ${t} = await afterHandle[${e}](c, ${r});
`:`const ${t} = afterHandle[${e}](c, ${r});
`)+`if(${t} !== undefined) { ${r} = ${t} }
`}o.response&&(f+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) }
`),f+=`return mapEarlyResponse(${r}, c.set)}
`}if(n?.afterHandle.length){f+=c.constructor.name===i?`let r = await handler(c);
`}o.response&&(p+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) }
`),p+=`return mapEarlyResponse(${r}, c.set)}
`}if(n?.afterHandle.length){p+=c.constructor.name===u?`let r = await handler(c);
`:`let r = handler(c);
`;for(let e=0;e<n.afterHandle.length;e++){let r=`af${e}`;f+=n.afterHandle[e].constructor.name===i?`let ${r} = await afterHandle[${e}](c, r)
`;for(let e=0;e<n.afterHandle.length;e++){let r=`af${e}`;p+=n.afterHandle[e].constructor.name===u?`let ${r} = await afterHandle[${e}](c, r)
`:`let ${r} = afterHandle[${e}](c, r)
`,o.response?f+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) }
`,o.response?p+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) }
${r} = mapEarlyResponse(${r}, c.set)
if(${r}) return ${r};
`:f+=`if(${r}) return ${r};
`}o.response&&(f+=`if(response[c.set.status]?.Check(r) === false) { throw createValidationError('response', response[c.set.status], r) }
`),f+=`return mapResponse(r, c.set);
`}else o.response?f+=(c.constructor.name===i?`const r = await handler(c);
`:p+=`if(${r}) return ${r};
`}o.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 o.response?p+=(c.constructor.name===u?`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);":f+=c.constructor.name===i?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";f+=`
`+"return mapResponse(r, c.set);":p+=c.constructor.name===u?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";p+=`
} catch(error) {

@@ -106,3 +106,3 @@ ${h?"":"return (async () => {"}

${h?"":"})()"}
}`,f=`const {
}`,p=`const {
handler,

@@ -133,6 +133,6 @@ handleError,

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

@@ -161,22 +161,21 @@ removeQueryRegex: rQuery,

return function(request) {
${u?`
ctx.set = {
headers: {},
status: 200
}
ctx.request = request
`:`
const ctx = {
set: {
${i?`
ctx.request = request
ctx.set = {
headers: {},
status: 200
},
params: {},
query: {}
},
request
}`}
}`:`
const ctx = {
set: {
headers: {},
status: 200
},
params: {},
query: {}
},
request
}`}
${a.event.request.length?`
${s.event.request.length?`
try {

@@ -194,12 +193,31 @@ for (let i = 0; i < app.event.request.length; i++) {

const p = request.url.replace(rHost, '')
const path = p.replace(rQuery, '').replace(rFrag, '')
const query = p.replace(rPath, '').replace(rFrag, '')
if (query) ctx.query = parseQuery(query)
${u?"else ctx.query = {}":""}
let path;
const url = request.url,
i = request.url.indexOf('?', 11),
f = request.url.indexOf('#', 12)
if (i !== -1) {
path = url.slice(url.indexOf('/', 10), i)
if(f === -1) {
ctx.query = parseQuery(url.slice(i + 1), i)
} else {
ctx.query = parseQuery(url.slice(i + 1, f), i)
}
} else {
if(f === -1) {
path = url.slice(url.indexOf('/', 10))
} else {
path = url.slice(url.indexOf('/', 10), f)
}
${i?"ctx.query = {}":""}
}
const handle = _static.get(request.method + path)
if (handle) {
${u?"ctx.params = {}":""}
${i?"ctx.params = {}":""}

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

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

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

@@ -356,20 +356,19 @@ import { Elysia } from '.'

? `
ctx.set = {
headers: {},
status: 200
}
ctx.request = request
`
: `
const ctx = {
set: {
ctx.request = request
ctx.set = {
headers: {},
status: 200
},
params: {},
query: {}
},
request
}`
}`
: `
const ctx = {
set: {
headers: {},
status: 200
},
params: {},
query: {}
},
request
}`
}

@@ -394,9 +393,31 @@

const p = request.url.replace(rHost, '')
const path = p.replace(rQuery, '').replace(rFrag, '')
const query = p.replace(rPath, '').replace(rFrag, '')
if (query) ctx.query = parseQuery(query)
${hasDecorators ? `else ctx.query = {}` : ''}
let path;
const url = request.url,
i = request.url.indexOf('?', 11),
f = request.url.indexOf('#', 12)
${
// path = url.slice(url.indexOf('/', 10), i !== -1 ? i : f !== -1 ? f : undefined)
''
}
if (i !== -1) {
path = url.slice(url.indexOf('/', 10), i)
if(f === -1) {
ctx.query = parseQuery(url.slice(i + 1), i)
} else {
ctx.query = parseQuery(url.slice(i + 1, f), i)
}
} else {
if(f === -1) {
path = url.slice(url.indexOf('/', 10))
} else {
path = url.slice(url.indexOf('/', 10), f)
}
${hasDecorators ? `ctx.query = {}` : ''}
}
const handle = _static.get(request.method + path)

@@ -403,0 +424,0 @@ if (handle) {

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