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.5 to 0.5.6

24

dist/cjs/compose.js

@@ -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":"",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()
).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()
`:`c.headers = {}

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

${q("headers")}
`);let v=p.query||x.some(e=>u("query",e));v&&(w+=`const url = c.request.url
`);let v=p.query||k.some(e=>u("query",e));v&&(w+=`const url = c.request.url

@@ -33,3 +33,3 @@ if(c.query !== -1) {

}
`);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')")+`
`);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')")+`
if (contentType) {

@@ -54,3 +54,3 @@ const index = contentType.indexOf(';')

}
})`: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 = {}
})`: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 = {}

@@ -75,3 +75,3 @@ for (const key of (await c.request.formData()).keys()) {

case 'application/json':
c.body = await c.request.json()
c.body = JSON.parse(await c.request.text())
break

@@ -139,3 +139,3 @@

}
`),C?w+=`return mapResponse(r, c.set)
`),O?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);

}
`,C?w+=`return mapResponse(r, c.set)
`,O?w+=`return mapResponse(r, c.set)
`:w+=`return mapCompactResponse(r)
`;else{let e=y.constructor.name===s?"await handler(c) ":"handler(c)";C?w+=`return mapResponse(${e}, c.set)
`;else{let e=y.constructor.name===s?"await handler(c) ":"handler(c)";O?w+=`return mapResponse(${e}, c.set)
`:w+=`return mapCompactResponse(${e})

@@ -157,3 +157,3 @@ `}E&&(w+=`

${O?"":"return (async () => {"}
${S?"":"return (async () => {"}
const set = c.set

@@ -177,3 +177,3 @@

return handleError(c.request, error, set)
${O?"":"})()"}
${S?"":"})()"}
}`),w=`const {

@@ -216,6 +216,6 @@ handler,

return ${O?"async":""} function(c) {
return ${S?"async":""} function(c) {
${h?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""}
${w}
}`;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=`
}`;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=`
const route = find(request.method, path) ${s.root.ALL?'?? find("ALL", path)':""}

@@ -222,0 +222,0 @@ if (route === null)

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),function(e,r){for(var s in r)Object.defineProperty(e,s,{enumerable:!0,get:r[s]})}(exports,{isNotEmpty:function(){return e},mapEarlyResponse:function(){return s},mapResponse:function(){return n},mapCompactResponse:function(){return t},errorToResponse:function(){return o}});const e=e=>{for(let r in e)return!0;return!1},r=(e,r)=>{e.delete("Set-Cookie");for(let s=0;s<r.length;s++){let n=r[s].indexOf("=");e.append("Set-Cookie",`${r[s].slice(0,n)}=${r[s].slice(n+1)}`)}return e},s=(n,t)=>{if(e(t.headers)||200!==t.status||t.redirect)switch(t.redirect&&(t.headers.Location=t.redirect,t.status=302),t.headers["Set-Cookie"]&&Array.isArray(t.headers["Set-Cookie"])&&(t.headers=r(new Headers(t.headers),t.headers["Set-Cookie"])),n?.constructor?.name){case"String":case"Blob":return new Response(n,t);case"Object":case"Array":return Response.json(n,t);case void 0:if(!n)return;return Response.json(n,t);case"Response":for(let e in t.headers)n.headers.append(e,t.headers[e]);return n;case"Promise":return n.then(e=>{let r=s(e,t);if(void 0!==r)return r});case"Error":return o(n,t.headers);case"Function":return n();case"Number":case"Boolean":return new Response(n.toString(),t);default:return}else switch(n?.constructor?.name){case"String":case"Blob":return new Response(n);case"Object":case"Array":return Response.json(n);case void 0:if(!n)return new Response("");return Response.json(n);case"Response":return n;case"Promise":return n.then(e=>{let r=s(e,t);if(void 0!==r)return r});case"Error":return o(n,t.headers);case"Function":return n();case"Number":case"Boolean":return new Response(n.toString());default:return}},n=(s,t)=>{if(e(t.headers)||200!==t.status||t.redirect)switch(t.redirect&&(t.headers.Location=t.redirect,t.status=302),t.headers["Set-Cookie"]&&Array.isArray(t.headers["Set-Cookie"])&&(t.headers=r(new Headers(t.headers),t.headers["Set-Cookie"])),s?.constructor?.name){case"String":case"Blob":return new Response(s,{status:t.status,headers:t.headers});case"Object":case"Array":return Response.json(s,t);case void 0:if(!s)return new Response("",t);return Response.json(s,t);case"Response":for(let e in t.headers)s.headers.append(e,t.headers[e]);return s;case"Error":return o(s,t.headers);case"Promise":return s.then(e=>n(e,t));case"Function":return s();case"Number":case"Boolean":return new Response(s.toString(),t);default:return new Response(s,t)}else switch(s?.constructor?.name){case"String":case"Blob":return new Response(s);case"Object":case"Array":return Response.json(s);case void 0:if(!s)return new Response("");return Response.json(s);case"Response":default:return s;case"Error":return o(s);case"Promise":return s.then(e=>{let r=n(e,t);return void 0!==r?r:new Response("")});case"Function":return s();case"Number":case"Boolean":return new Response(s.toString())}},t=e=>{switch(e.constructor?.name){case"String":case"Blob":return new Response(e);case"Object":case"Array":return Response.json(e);case void 0:if(!e)return new Response("");return Response.json(e);case"Response":default:return e;case"Error":return o(e);case"Promise":return e.then(e=>{let r=t(e);return void 0!==r?r:new Response("")});case"Function":return e();case"Number":case"Boolean":return new Response(e.toString())}},o=(e,r)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:r});
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),function(e,r){for(var n in r)Object.defineProperty(e,n,{enumerable:!0,get:r[n]})}(exports,{isNotEmpty:function(){return e},mapEarlyResponse:function(){return n},mapResponse:function(){return s},mapCompactResponse:function(){return t},errorToResponse:function(){return o}});const e=e=>{for(let r in e)return!0;return!1},r=(e,r)=>{e.delete("Set-Cookie");for(let n=0;n<r.length;n++){let s=r[n].indexOf("=");e.append("Set-Cookie",`${r[n].slice(0,s)}=${r[n].slice(s+1)}`)}return e},n=(s,t)=>{if(e(t.headers)||200!==t.status||t.redirect)switch(t.redirect&&(t.headers.Location=t.redirect,t.status=302),t.headers["Set-Cookie"]&&Array.isArray(t.headers["Set-Cookie"])&&(t.headers=r(new Headers(t.headers),t.headers["Set-Cookie"])),s?.constructor?.name){case"String":case"Blob":return new Response(s,t);case"Object":case"Array":return Response.json(s,t);case void 0:if(!s)return;return Response.json(s,t);case"Response":for(let e in t.headers)s.headers.append(e,t.headers[e]);return s;case"Promise":return s.then(e=>{let r=n(e,t);if(void 0!==r)return r});case"Error":return o(s,t.headers);case"Function":return s();case"Number":case"Boolean":return new Response(s.toString(),t);default:return}else switch(s?.constructor?.name){case"String":case"Blob":return new Response(s);case"Object":case"Array":return new Response(JSON.stringify(s),{headers:{"content-type":"application/json"}});case void 0:if(!s)return new Response("");return new Response(JSON.stringify(s),{headers:{"content-type":"application/json"}});case"Response":return s;case"Promise":return s.then(e=>{let r=n(e,t);if(void 0!==r)return r});case"Error":return o(s,t.headers);case"Function":return s();case"Number":case"Boolean":return new Response(s.toString());default:return}},s=(n,t)=>{if(e(t.headers)||200!==t.status||t.redirect)switch(t.redirect&&(t.headers.Location=t.redirect,t.status=302),t.headers["Set-Cookie"]&&Array.isArray(t.headers["Set-Cookie"])&&(t.headers=r(new Headers(t.headers),t.headers["Set-Cookie"])),n?.constructor?.name){case"String":case"Blob":return new Response(n,{status:t.status,headers:t.headers});case"Object":case"Array":return Response.json(n,t);case void 0:if(!n)return new Response("",t);return Response.json(n,t);case"Response":for(let e in t.headers)n.headers.append(e,t.headers[e]);return n;case"Error":return o(n,t.headers);case"Promise":return n.then(e=>s(e,t));case"Function":return n();case"Number":case"Boolean":return new Response(n.toString(),t);default:return new Response(n,t)}else switch(n?.constructor?.name){case"String":case"Blob":return new Response(n);case"Object":case"Array":return new Response(JSON.stringify(n),{headers:{"content-type":"application/json"}});case void 0:if(!n)return new Response("");return new Response(JSON.stringify(n),{headers:{"content-type":"application/json"}});case"Response":default:return n;case"Error":return o(n);case"Promise":return n.then(e=>{let r=s(e,t);return void 0!==r?r:new Response("")});case"Function":return n();case"Number":case"Boolean":return new Response(n.toString())}},t=e=>{switch(e.constructor?.name){case"String":case"Blob":return new Response(e);case"Object":case"Array":return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}});case void 0:if(!e)return new Response("");return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}});case"Response":default:return e;case"Error":return o(e);case"Promise":return e.then(e=>{let r=t(e);return void 0!==r?r:new Response("")});case"Function":return e();case"Number":case"Boolean":return new Response(e.toString())}},o=(e,r)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:r});

@@ -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 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()
).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()
`:`c.headers = {}

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

if (headers.Check(c.headers) === false)
${x("headers")}
`);let F=$.query||v.some(e=>isFnUse("query",e));F&&(H+=`const url = c.request.url
${w("headers")}
`);let C=$.query||v.some(e=>isFnUse("query",e));C&&(H+=`const url = c.request.url

@@ -33,3 +33,3 @@ if(c.query !== -1) {

}
`);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')")+`
`);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')")+`
if (contentType) {

@@ -54,3 +54,3 @@ const index = contentType.indexOf(';')

}
})`: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 = {}
})`: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 = {}

@@ -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"+(C?"let contentType = c.headers['content-type']":"let contentType = c.request.headers.get('content-type')")+`
}`}h.parse.length&&(H+="}}")}else{if(H+="\n"+(S?"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 = await c.request.json()
c.body = JSON.parse(await c.request.text())
break

@@ -106,5 +106,5 @@

if (headers.Check(c.headers) === false) {
${x("headers")}
${w("headers")}
}
`),$.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);
`),$.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);
`:`let ${r} = beforeHandle[${e}](c);

@@ -141,3 +141,3 @@ `)+`if(${r} !== undefined) {

}
`),j?H+=`return mapResponse(r, c.set)
`),F?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);

}
`,j?H+=`return mapResponse(r, c.set)
`,F?H+=`return mapResponse(r, c.set)
`:H+=`return mapCompactResponse(r)
`;else{let e=m.constructor.name===f?"await handler(c) ":"handler(c)";j?H+=`return mapResponse(${e}, c.set)
`;else{let e=m.constructor.name===f?"await handler(c) ":"handler(c)";F?H+=`return mapResponse(${e}, c.set)
`:H+=`return mapCompactResponse(${e})
`}w&&(H+=`
`}x&&(H+=`
} catch(error) {
${S?"":"return (async () => {"}
${N?"":"return (async () => {"}
const set = c.set

@@ -178,3 +178,3 @@

return handleError(c.request, error, set)
${S?"":"})()"}
${N?"":"})()"}
}`),H=`const {

@@ -217,3 +217,3 @@ handler,

return ${S?"async":""} function(c) {
return ${N?"async":""} function(c) {
${q?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""}

@@ -220,0 +220,0 @@ ${H}

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

export const isNotEmpty=e=>{for(let r in e)return!0;return!1};let e=(e,r)=>{e.delete("Set-Cookie");for(let s=0;s<r.length;s++){let n=r[s].indexOf("=");e.append("Set-Cookie",`${r[s].slice(0,n)}=${r[s].slice(n+1)}`)}return e};export const mapEarlyResponse=(r,s)=>{if(isNotEmpty(s.headers)||200!==s.status||s.redirect)switch(s.redirect&&(s.headers.Location=s.redirect,s.status=302),s.headers["Set-Cookie"]&&Array.isArray(s.headers["Set-Cookie"])&&(s.headers=e(new Headers(s.headers),s.headers["Set-Cookie"])),r?.constructor?.name){case"String":case"Blob":return new Response(r,s);case"Object":case"Array":return Response.json(r,s);case void 0:if(!r)return;return Response.json(r,s);case"Response":for(let e in s.headers)r.headers.append(e,s.headers[e]);return r;case"Promise":return r.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});case"Error":return errorToResponse(r,s.headers);case"Function":return r();case"Number":case"Boolean":return new Response(r.toString(),s);default:return}else switch(r?.constructor?.name){case"String":case"Blob":return new Response(r);case"Object":case"Array":return Response.json(r);case void 0:if(!r)return new Response("");return Response.json(r);case"Response":return r;case"Promise":return r.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});case"Error":return errorToResponse(r,s.headers);case"Function":return r();case"Number":case"Boolean":return new Response(r.toString());default:return}};export const mapResponse=(r,s)=>{if(isNotEmpty(s.headers)||200!==s.status||s.redirect)switch(s.redirect&&(s.headers.Location=s.redirect,s.status=302),s.headers["Set-Cookie"]&&Array.isArray(s.headers["Set-Cookie"])&&(s.headers=e(new Headers(s.headers),s.headers["Set-Cookie"])),r?.constructor?.name){case"String":case"Blob":return new Response(r,{status:s.status,headers:s.headers});case"Object":case"Array":return Response.json(r,s);case void 0:if(!r)return new Response("",s);return Response.json(r,s);case"Response":for(let e in s.headers)r.headers.append(e,s.headers[e]);return r;case"Error":return errorToResponse(r,s.headers);case"Promise":return r.then(e=>mapResponse(e,s));case"Function":return r();case"Number":case"Boolean":return new Response(r.toString(),s);default:return new Response(r,s)}else switch(r?.constructor?.name){case"String":case"Blob":return new Response(r);case"Object":case"Array":return Response.json(r);case void 0:if(!r)return new Response("");return Response.json(r);case"Response":default:return r;case"Error":return errorToResponse(r);case"Promise":return r.then(e=>{let r=mapResponse(e,s);return void 0!==r?r:new Response("")});case"Function":return r();case"Number":case"Boolean":return new Response(r.toString())}};export const mapCompactResponse=e=>{switch(e.constructor?.name){case"String":case"Blob":return new Response(e);case"Object":case"Array":return Response.json(e);case void 0:if(!e)return new Response("");return Response.json(e);case"Response":default:return e;case"Error":return errorToResponse(e);case"Promise":return e.then(e=>{let r=mapCompactResponse(e);return void 0!==r?r:new Response("")});case"Function":return e();case"Number":case"Boolean":return new Response(e.toString())}};export const errorToResponse=(e,r)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:r});
export const isNotEmpty=e=>{for(let r in e)return!0;return!1};let e=(e,r)=>{e.delete("Set-Cookie");for(let s=0;s<r.length;s++){let n=r[s].indexOf("=");e.append("Set-Cookie",`${r[s].slice(0,n)}=${r[s].slice(n+1)}`)}return e};export const mapEarlyResponse=(r,s)=>{if(isNotEmpty(s.headers)||200!==s.status||s.redirect)switch(s.redirect&&(s.headers.Location=s.redirect,s.status=302),s.headers["Set-Cookie"]&&Array.isArray(s.headers["Set-Cookie"])&&(s.headers=e(new Headers(s.headers),s.headers["Set-Cookie"])),r?.constructor?.name){case"String":case"Blob":return new Response(r,s);case"Object":case"Array":return Response.json(r,s);case void 0:if(!r)return;return Response.json(r,s);case"Response":for(let e in s.headers)r.headers.append(e,s.headers[e]);return r;case"Promise":return r.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});case"Error":return errorToResponse(r,s.headers);case"Function":return r();case"Number":case"Boolean":return new Response(r.toString(),s);default:return}else switch(r?.constructor?.name){case"String":case"Blob":return new Response(r);case"Object":case"Array":return new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}});case void 0:if(!r)return new Response("");return new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}});case"Response":return r;case"Promise":return r.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});case"Error":return errorToResponse(r,s.headers);case"Function":return r();case"Number":case"Boolean":return new Response(r.toString());default:return}};export const mapResponse=(r,s)=>{if(isNotEmpty(s.headers)||200!==s.status||s.redirect)switch(s.redirect&&(s.headers.Location=s.redirect,s.status=302),s.headers["Set-Cookie"]&&Array.isArray(s.headers["Set-Cookie"])&&(s.headers=e(new Headers(s.headers),s.headers["Set-Cookie"])),r?.constructor?.name){case"String":case"Blob":return new Response(r,{status:s.status,headers:s.headers});case"Object":case"Array":return Response.json(r,s);case void 0:if(!r)return new Response("",s);return Response.json(r,s);case"Response":for(let e in s.headers)r.headers.append(e,s.headers[e]);return r;case"Error":return errorToResponse(r,s.headers);case"Promise":return r.then(e=>mapResponse(e,s));case"Function":return r();case"Number":case"Boolean":return new Response(r.toString(),s);default:return new Response(r,s)}else switch(r?.constructor?.name){case"String":case"Blob":return new Response(r);case"Object":case"Array":return new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}});case void 0:if(!r)return new Response("");return new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}});case"Response":default:return r;case"Error":return errorToResponse(r);case"Promise":return r.then(e=>{let r=mapResponse(e,s);return void 0!==r?r:new Response("")});case"Function":return r();case"Number":case"Boolean":return new Response(r.toString())}};export const mapCompactResponse=e=>{switch(e.constructor?.name){case"String":case"Blob":return new Response(e);case"Object":case"Array":return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}});case void 0:if(!e)return new Response("");return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}});case"Response":default:return e;case"Error":return errorToResponse(e);case"Promise":return e.then(e=>{let r=mapCompactResponse(e);return void 0!==r?r:new Response("")});case"Function":return e();case"Number":case"Boolean":return new Response(e.toString())}};export const errorToResponse=(e,r)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:r});
{
"name": "elysia",
"description": "Fast, and friendly Bun web framework",
"version": "0.5.5",
"version": "0.5.6",
"author": {

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

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