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

elysia

Package Overview
Dependencies
Maintainers
1
Versions
429
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-230506.2 to 0.5.0-exp-230506.1231

23

dist/compose.js

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

import{parse as e}from"fast-querystring";import{mapEarlyResponse as r,mapResponse as t}from"./handler";import{SCHEMA as s,DEFS as a}from"./utils";import{ParseError as o,NotFoundError as n,ValidationError as c,InternalServerError as l}from"./error";let d="AsyncFunction",i=e=>e.constructor.name===d,u=new 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.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 o=RegExp(`{.*?} = (${a.join("|")})`,"g");for(let[t]of r.matchAll(o))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1};export const composeHandler=({path:f,method:p,hooks:h,validator:y,handler:m,handleError:$,meta:b})=>{let w="try {\n",q="string"==typeof h.type,k="GET"!==p&&(y.body||q||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("body",e.toString()))),E=y.headers||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("headers",e.toString()));E&&(w+=u.toJSON?`c.headers = c.request.headers.toJSON()
import{parse as e}from"fast-querystring";import{mapEarlyResponse as r,mapResponse as t}from"./handler";import{SCHEMA as a,DEFS as s}from"./utils";import{ParseError as o,NotFoundError as n,ValidationError as c,InternalServerError as l}from"./error";let d="AsyncFunction",i=e=>e.constructor.name===d,u=new 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.includes(`${t}.${e}`))return!0;let a=RegExp(" (\\w+) = context","g"),s=[t];for(let e of r.matchAll(a))s.push(e[1]);let o=RegExp(`{.*?} = (${s.join("|")})`,"g");for(let[t]of r.matchAll(o))if(t.includes(`{ ${e}`)||t.includes(`, ${e}`))return!0;return!1};export const composeHandler=({path:f,method:p,hooks:h,validator:y,handler:m,handleError:$,meta:b})=>{let w="try {\n",q="string"==typeof h.type,k="GET"!==p&&(y.body||q||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("body",e.toString()))),g=y.headers||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("headers",e.toString()));g&&(w+=u.toJSON?`c.headers = c.request.headers.toJSON()
`:`c.headers = {}

@@ -13,3 +13,3 @@ for (const key of c.request.headers.keys())

}
`);let g=y.query||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("query",e.toString()));g&&(w+=`const url = c.request.url
`);let E=y.query||[m,...h.transform,...h.beforeHandle,...h.afterHandle].some(e=>isFnUse("query",e.toString()));E&&(w+=`const url = c.request.url

@@ -21,3 +21,3 @@ if(url.charCodeAt(c.query) === 63 || (c.query = url.indexOf("?", ${10+f.length})) !== -1) {

}
`);let x=k||m.constructor.name===d||h.parse.length||h.afterHandle.find(i)||h.beforeHandle.find(i)||h.transform.find(i);if(k){let e=y?.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(q||e){if(w+=`try {
`);let x=k||m.constructor.name===d||h.parse.length||h.afterHandle.find(i)||h.beforeHandle.find(i)||h.transform.find(i);if(k){let e=y?.body?.schema;if(e&&"anyOf"in e){let r=!1,t=e.anyOf[0].type;for(let a of e.anyOf)if(a.type!==t){r=!0;break}r&&(e=void 0)}if(q||e){if(w+=`try {
`,e)switch(e.type){case"object":"URLEncoded"===e.elysiaMeta?w+="c.body = parseQuery(await c.request.text())":y.body.Code().includes("custom('File")?w+=`c.body = {}

@@ -47,3 +47,3 @@

throw new ParseError()
}`}else{if(w+="\n"+(E?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+`
}`}else{if(w+="\n"+(g?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+`
if (contentType) {

@@ -115,5 +115,4 @@ const index = contentType.indexOf(';')

`)+`if(response[c.set.status]?.Check(r) === false) { throw new ValidationError('response', response[c.set.status], r) }
`+"return mapResponse(r, c.set);":w+=m.constructor.name===d?"return handler(c).then((v) => mapResponse(v, c.set))":"return mapResponse(handler(c), c.set);";w+=`
`+"return mapResponse(r, c.set);":w+=m.constructor.name===d?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";w+=`
} catch(error) {
// Optimize this error return
${x?"":"return (async () => {"}

@@ -124,4 +123,3 @@ const set = c.set

if (handleErrors) {
for (let i = 0; i < handleErrors.length; i++) {
${h.error.length?`for (let i = 0; i < handleErrors.length; i++) {
let handled = handleErrors[i]({

@@ -137,4 +135,3 @@ request: c.request,

if (response) return response
}
}
}`:""}

@@ -181,3 +178,3 @@ return handleError(c.request, error, set)

${w}
}`;let H=Function("hooks",w);return H({handler:m,hooks:h,validator:y,handleError:$,utils:{mapResponse:t,mapEarlyResponse:r,parseQuery:e},error:{ParseError:o,NotFoundError:n,ValidationError:c,InternalServerError:l},meta:b,SCHEMA:b?s:void 0,DEFS:b?a:void 0})};export const composeGeneralHandler=e=>{let t="";for(let r of Object.keys(e.decorators))t+=`,${r}: app.decorators.${r}`;let s=e.staticRouter,a="";for(let[e,r]of Object.entries(s.map))a+=`case '${e}':
}`;let H=Function("hooks",w);return H({handler:m,hooks:h,validator:y,handleError:$,utils:{mapResponse:t,mapEarlyResponse:r,parseQuery:e},error:{ParseError:o,NotFoundError:n,ValidationError:c,InternalServerError:l},meta:b,SCHEMA:b?a:void 0,DEFS:b?s:void 0})};export const composeGeneralHandler=e=>{let t="";for(let r of Object.keys(e.decorators))t+=`,${r}: app.decorators.${r}`;let a=e.staticRouter,s="";for(let[e,r]of Object.entries(a.map))s+=`case '${e}':
switch(method) {

@@ -199,3 +196,3 @@ ${r}}

${s.variables}
${a.variables}

@@ -235,3 +232,3 @@ return function(request) {

switch(path) {
${a}
${s}
}

@@ -238,0 +235,0 @@

{
"name": "elysia",
"description": "Fast, and friendly Bun web framework",
"version": "0.5.0-exp-230506.0002",
"version": "0.5.0-exp-230506.1231",
"author": {

@@ -98,3 +98,3 @@ "name": "saltyAom",

"lodash.clonedeep": "^4.5.0",
"memoirist": "0.1.2",
"memoirist": "0.1.3",
"nanoid": "^4.0.1",

@@ -101,0 +101,0 @@ "openapi-types": "^12.1.0",

@@ -401,3 +401,3 @@ import type { Elysia } from '.'

handler.constructor.name === ASYNC_FN
? `return handler(c).then((v) => mapResponse(v, c.set))`
? `return mapResponse(await handler(c), c.set);`
: `return mapResponse(handler(c), c.set);`

@@ -408,3 +408,2 @@ }

} catch(error) {
// Optimize this error return
${maybeAsync ? '' : 'return (async () => {'}

@@ -415,4 +414,5 @@ const set = c.set

if (handleErrors) {
for (let i = 0; i < handleErrors.length; i++) {
${
hooks.error.length
? `for (let i = 0; i < handleErrors.length; i++) {
let handled = handleErrors[i]({

@@ -428,3 +428,4 @@ request: c.request,

if (response) return response
}
}`
: ''
}

@@ -436,4 +437,2 @@

// console.log(fnLiteral)
fnLiteral = `const {

@@ -483,2 +482,4 @@ handler,

// console.log(fnLiteral)
const createHandler = Function('hooks', fnLiteral)

@@ -485,0 +486,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