Comparing version 0.5.0-exp-230422.2101 to 0.5.0-exp-230422.2137
@@ -1,2 +0,130 @@ | ||
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+=` | ||
import{parse as e}from"fast-querystring";import{errorToResponse as r,isNotEmpty as t,mapEarlyResponse as s,mapResponse as a,parseSetCookies as n}from"./handler";import{createValidationError as o,mapPathnameAndQueryRegEx as c}from"./utils";import{mapErrorCode as i}from"./error";let u="AsyncFunction",d=e=>e.constructor.name===u,l=Bun?.Transpiler?new Bun.Transpiler({minifyWhitespace:!0,inline:!0,platform:"bun",allowBunRuntime:!0}):null,p=` | ||
if (isNotEmpty(c.set.headers) || c.set.status !== 200 || c.set.redirect) { | ||
if (c.set.redirect) { | ||
c.set.headers.Location = c.set.redirect | ||
c.set.status = 302 | ||
} | ||
if ( | ||
c.set.headers['Set-Cookie'] && | ||
Array.isArray(c.set.headers['Set-Cookie']) | ||
) | ||
c.set.headers = parseSetCookies( | ||
new Headers(c.set.headers), | ||
c.set.headers['Set-Cookie'] | ||
) | ||
switch (typeof r) { | ||
case 'string': | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case 'object': | ||
switch (r?.constructor) { | ||
case Error: | ||
return errorToResponse(r, c.set.headers) | ||
case Response: | ||
for (const key in c.set.headers) | ||
r.headers.append( | ||
key, | ||
c.set.headers[key] | ||
) | ||
return r | ||
case Blob: | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case Promise: | ||
return r.then((x) => mapResponse(x, c.set)) | ||
default: | ||
if (!c.set.headers['Content-Type']) | ||
c.set.headers['Content-Type'] = 'application/json' | ||
return new Response(JSON.stringify(r), { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
} | ||
// ? Maybe r function or Blob | ||
case 'function': | ||
if (r instanceof Blob) | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
return r() | ||
case 'number': | ||
case 'boolean': | ||
return new Response(r.toString(), { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case 'undefined': | ||
return new Response('', { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
default: | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
} | ||
} else | ||
switch (typeof r) { | ||
case 'string': | ||
return new Response(r) | ||
case 'object': | ||
switch (r?.constructor) { | ||
case Error: | ||
return errorToResponse(r, c.set.headers) | ||
case Response: | ||
return r | ||
case Blob: | ||
return new Response(r) | ||
case Promise: | ||
return r.then((x) => mapResponse(x, c.set)) | ||
default: | ||
return new Response(JSON.stringify(r), { | ||
headers: { | ||
'content-type': 'application/json' | ||
} | ||
}) | ||
} | ||
// ? Maybe r or Blob | ||
case 'function': | ||
if (r instanceof Blob) return new Response(r) | ||
return r() | ||
case 'number': | ||
case 'boolean': | ||
return new Response(r.toString()) | ||
case 'undefined': | ||
return new Response('') | ||
default: | ||
return new Response(r) | ||
} | ||
`;l&&(p=l.transformSync(p));export const composeHandler=({method:c,hooks:f,validator:h,handler:y,handleError:m})=>{let $="try {\n",w="GET"!==c||y.constructor.name===u||f.parse.length||f.afterHandle.find(d)||f.beforeHandle.find(d)||f.transform.find(d);if(w){if($+=` | ||
let contentType = c.request.headers.get('content-type'); | ||
@@ -9,8 +137,8 @@ | ||
} | ||
`,i.parse.length){p+=`used = false | ||
`;for(let e=0;e<i.parse.length;e++){let r=`bo${e}`;p+=`if(!c.request.bodyUsed) { | ||
`,f.parse.length){$+=`used = false | ||
`;for(let e=0;e<f.parse.length;e++){let r=`bo${e}`;$+=`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 } | ||
}`}p+="if (!used)"}p+=`switch (contentType) { | ||
}`}$+="if (!used)"}$+=`switch (contentType) { | ||
case 'application/json': | ||
@@ -45,3 +173,3 @@ c.body = await c.request.json() | ||
}} | ||
`}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+=` | ||
`}if(f?.transform)for(let e=0;e<f.transform.length;e++)$+=f.transform[e].constructor.name===u?`await transform[${e}](c);`:`transform[${e}](c);`;if(h&&(h.headers&&($+=` | ||
const _header = {} | ||
@@ -58,26 +186,27 @@ for (const key of c.request.headers.keys()) | ||
} | ||
`),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); | ||
`),h.params&&($+="if(params.Check(c.params) === false) { throw createValidationError('params', params, c.params) }"),h.query&&($+="if(query.Check(c.query) === false) { throw createValidationError('params', query, c.query) }"),h.body&&($+="if(body.Check(c.body) === false) { throw createValidationError('body', body, c.body) }")),f?.beforeHandle)for(let e=0;e<f.beforeHandle.length;e++){let r=`be${e}`;if($+=(f.beforeHandle[e].constructor.name===u?`let ${r} = await beforeHandle[${e}](c); | ||
`:`let ${r} = beforeHandle[${e}](c); | ||
`)+`if(${r} !== undefined) { | ||
`,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}); | ||
`,f?.afterHandle)for(let e=0;e<f.afterHandle.length;e++){let t=`af${e}`;$+=(f.afterHandle[e].constructor.name===u?`const ${t} = await afterHandle[${e}](c, ${r}); | ||
`:`const ${t} = afterHandle[${e}](c, ${r}); | ||
`)+`if(${t} !== undefined) { ${r} = ${t} } | ||
`}d.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(i?.afterHandle.length){p+=u.constructor.name===o?`let r = await handler(c); | ||
`}h.response&&($+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) } | ||
`),$+=`return mapEarlyResponse(${r}, c.set)} | ||
`}if(f?.afterHandle.length){$+=y.constructor.name===u?`let r = await handler(c); | ||
`:`let r = handler(c); | ||
`;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) | ||
`;for(let e=0;e<f.afterHandle.length;e++){let r=`af${e}`;$+=f.afterHandle[e].constructor.name===u?`let ${r} = await afterHandle[${e}](c, r) | ||
`:`let ${r} = afterHandle[${e}](c, r) | ||
`,d.response?p+=`if(response[c.set.status]?.Check(${r}) === false) { throw createValidationError('response', response[c.set.status], ${r}) } | ||
`,h.response?$+=`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}; | ||
`:p+=`if(${r}) return ${r}; | ||
`}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+=(u.constructor.name===o?`const r = await handler(c); | ||
`:$+=`if(${r}) return ${r}; | ||
`}h.response&&($+=`if(response[c.set.status]?.Check(r) === false) { throw createValidationError('response', response[c.set.status], r) } | ||
`),$+=p}else h.response?$+=(y.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);":p+=u.constructor.name===o?"return mapResponse(await handler(c), c.set);":"return mapResponse(handler(c), c.set);";p+=` | ||
`+p:$+=(y.constructor.name===u?`const r = await handler(c); | ||
`:`const r = handler(c); | ||
`)+p;$+=` | ||
} catch(error) { | ||
${h?"":"return (async () => {"} | ||
${w?"":"return (async () => {"} | ||
const set = c.set | ||
@@ -105,4 +234,4 @@ | ||
return handleError(c.request, error, set) | ||
${h?"":"})()"} | ||
}`,p=`const { | ||
${w?"":"})()"} | ||
}`,$=`const { | ||
handler, | ||
@@ -129,7 +258,10 @@ handleError, | ||
mapErrorCode, | ||
parseQuery | ||
parseQuery, | ||
isNotEmpty, | ||
parseSetCookies, | ||
errorToResponse | ||
} | ||
} = hooks | ||
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 { | ||
return ${w?"async":""} function(c) {${$}}`,l&&($=l.transformSync($));let b=Function("hooks",$);return b({handler:y,hooks:f,validator:h,handleError:m,utils:{createValidationError:o,mapResponse:a,mapEarlyResponse:s,mapErrorCode:i,parseQuery:e,isNotEmpty:t,parseSetCookies:n,errorToResponse:r}})};export const composeGeneralHandler=r=>{let t=Object.keys(r.decorators).length,a=t>0,n=`const { | ||
app, | ||
@@ -147,3 +279,3 @@ parseQuery, | ||
const ctx = ${n?"app.decorators":`{ | ||
const ctx = ${a?"app.decorators":`{ | ||
set: { | ||
@@ -158,3 +290,3 @@ headers: {}, | ||
return (request) => { | ||
${n?` | ||
${a?` | ||
ctx.set = { | ||
@@ -167,3 +299,3 @@ headers: {}, | ||
${t.event.request.length?` | ||
${r.event.request.length?` | ||
try { | ||
@@ -183,7 +315,7 @@ for (let i = 0; i < app.event.request.length; i++) { | ||
if (fracture[2]) ctx.query = parseQuery(fracture[2]) | ||
${n?"else ctx.query = {}":""} | ||
${a?"else ctx.query = {}":""} | ||
const handle = _static.get(request.method + fracture[1]) | ||
if (handle) { | ||
${n?"ctx.params = {}":""} | ||
${a?"ctx.params = {}":""} | ||
@@ -205,2 +337,2 @@ return handle(ctx) | ||
} | ||
}`;return l&&(o=l.transformSync(o)),Function("data",o)({app:t,parseQuery:e,mapPathnameAndQueryRegEx:s,mapEarlyResponse:r})}; | ||
}`;return l&&(n=l.transformSync(n)),Function("data",n)({app:r,parseQuery:e,mapPathnameAndQueryRegEx:c,mapEarlyResponse:s})}; |
/// <reference types="bun-types" /> | ||
import type { Context } from './context'; | ||
export declare const isNotEmpty: (obj: Object) => boolean; | ||
export declare const parseSetCookies: (headers: Headers, setCookie: string[]) => Headers; | ||
export declare const mapEarlyResponse: (response: unknown, set: Context['set']) => Response | undefined; | ||
export declare const mapResponse: (response: unknown, set: Context['set']) => Response; | ||
export declare const errorToResponse: (error: Error, headers?: HeadersInit) => Response; |
@@ -1,1 +0,1 @@ | ||
export const isNotEmpty=e=>{for(let s in e)return!0;return!1};let e=(e,s)=>{e.delete("Set-Cookie");for(let r=0;r<s.length;r++){let t=s[r].indexOf("=");e.append("Set-Cookie",`${s[r].slice(0,t)}=${s[r].slice(t+1)}`)}return e};export const mapEarlyResponse=(s,r)=>{if(isNotEmpty(r.headers)||200!==r.status||r.redirect)switch(r.redirect&&(r.headers.Location=r.redirect,r.status=302),r.headers["Set-Cookie"]&&Array.isArray(r.headers["Set-Cookie"])&&(r.headers=e(new Headers(r.headers),r.headers["Set-Cookie"])),typeof s){case"string":return new Response(s,{status:r.status,headers:r.headers});case"object":switch(s?.constructor){case Error:return errorToResponse(s,r.headers);case Response:for(let e in r.headers)s.headers.append(e,r.headers[e]);return s;case Blob:return new Response(s,{status:r.status,headers:r.headers});case Promise:return s.then(e=>{let s=mapEarlyResponse(e,r);if(void 0!==s)return s});default:return r.headers["Content-Type"]||(r.headers["Content-Type"]="application/json"),new Response(JSON.stringify(s),{status:r.status,headers:r.headers})}case"function":if(s instanceof Blob)return new Response(s,{status:r.status,headers:r.headers});for(let e in r.headers)s.headers.append(e,r.headers[e]);return s;case"number":case"boolean":return new Response(s.toString(),{status:r.status,headers:r.headers})}else switch(typeof s){case"string":return new Response(s);case"object":switch(s?.constructor){case Error:return errorToResponse(s,r.headers);case Response:return s;case Blob:return new Response(s);case Promise:return s.then(e=>{let s=mapEarlyResponse(e,r);if(void 0!==s)return s});default:return new Response(JSON.stringify(s),{headers:{"content-type":"application/json"}})}case"function":if(s instanceof Blob)return new Response(s);return s;case"number":case"boolean":return new Response(s.toString())}};export const mapResponse=(s,r)=>{if(isNotEmpty(r.headers)||200!==r.status||r.redirect)switch(r.redirect&&(r.headers.Location=r.redirect,r.status=302),r.headers["Set-Cookie"]&&Array.isArray(r.headers["Set-Cookie"])&&(r.headers=e(new Headers(r.headers),r.headers["Set-Cookie"])),typeof s){case"string":return new Response(s,{status:r.status,headers:r.headers});case"object":switch(s?.constructor){case Error:return errorToResponse(s,r.headers);case Response:for(let e in r.headers)s.headers.append(e,r.headers[e]);return s;case Blob:return new Response(s,{status:r.status,headers:r.headers});case Promise:return s.then(e=>mapResponse(e,r));default:return r.headers["Content-Type"]||(r.headers["Content-Type"]="application/json"),new Response(JSON.stringify(s),{status:r.status,headers:r.headers})}case"function":if(s instanceof Blob)return new Response(s,{status:r.status,headers:r.headers});return s();case"number":case"boolean":return new Response(s.toString(),{status:r.status,headers:r.headers});case"undefined":return new Response("",{status:r.status,headers:r.headers});default:return new Response(s,{status:r.status,headers:r.headers})}else switch(typeof s){case"string":return new Response(s);case"object":switch(s?.constructor){case Error:return errorToResponse(s,r.headers);case Response:return s;case Blob:return new Response(s);case Promise:return s.then(e=>mapResponse(e,r));default:return new Response(JSON.stringify(s),{headers:{"content-type":"application/json"}})}case"function":if(s instanceof Blob)return new Response(s);return s();case"number":case"boolean":return new Response(s.toString());case"undefined":return new Response("");default:return new Response(s)}};export const errorToResponse=(e,s)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:s}); | ||
export const isNotEmpty=e=>{for(let s in e)return!0;return!1};export const parseSetCookies=(e,s)=>{e.delete("Set-Cookie");for(let r=0;r<s.length;r++){let t=s[r].indexOf("=");e.append("Set-Cookie",`${s[r].slice(0,t)}=${s[r].slice(t+1)}`)}return e};export const mapEarlyResponse=(e,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=parseSetCookies(new Headers(s.headers),s.headers["Set-Cookie"])),typeof e){case"string":return new Response(e,{status:s.status,headers:s.headers});case"object":switch(e?.constructor){case Error:return errorToResponse(e,s.headers);case Response:for(let r in s.headers)e.headers.append(r,s.headers[r]);return e;case Blob:return new Response(e,{status:s.status,headers:s.headers});case Promise:return e.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});default:return s.headers["Content-Type"]||(s.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),{status:s.status,headers:s.headers})}case"function":if(e instanceof Blob)return new Response(e,{status:s.status,headers:s.headers});for(let r in s.headers)e.headers.append(r,s.headers[r]);return e;case"number":case"boolean":return new Response(e.toString(),{status:s.status,headers:s.headers})}else switch(typeof e){case"string":return new Response(e);case"object":switch(e?.constructor){case Error:return errorToResponse(e,s.headers);case Response:return e;case Blob:return new Response(e);case Promise:return e.then(e=>{let r=mapEarlyResponse(e,s);if(void 0!==r)return r});default:return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}})}case"function":if(e instanceof Blob)return new Response(e);return e;case"number":case"boolean":return new Response(e.toString())}};export const mapResponse=(e,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=parseSetCookies(new Headers(s.headers),s.headers["Set-Cookie"])),typeof e){case"string":return new Response(e,{status:s.status,headers:s.headers});case"object":switch(e?.constructor){case Error:return errorToResponse(e,s.headers);case Response:for(let r in s.headers)e.headers.append(r,s.headers[r]);return e;case Blob:return new Response(e,{status:s.status,headers:s.headers});case Promise:return e.then(e=>mapResponse(e,s));default:return s.headers["Content-Type"]||(s.headers["Content-Type"]="application/json"),new Response(JSON.stringify(e),{status:s.status,headers:s.headers})}case"function":if(e instanceof Blob)return new Response(e,{status:s.status,headers:s.headers});return e();case"number":case"boolean":return new Response(e.toString(),{status:s.status,headers:s.headers});case"undefined":return new Response("",{status:s.status,headers:s.headers});default:return new Response(e,{status:s.status,headers:s.headers})}else switch(typeof e){case"string":return new Response(e);case"object":switch(e?.constructor){case Error:return errorToResponse(e,s.headers);case Response:return e;case Blob:return new Response(e);case Promise:return e.then(e=>mapResponse(e,s));default:return new Response(JSON.stringify(e),{headers:{"content-type":"application/json"}})}case"function":if(e instanceof Blob)return new Response(e);return e();case"number":case"boolean":return new Response(e.toString());case"undefined":return new Response("");default:return new Response(e)}};export const errorToResponse=(e,s)=>new Response(JSON.stringify({name:e?.name,message:e?.message,cause:e?.cause}),{status:500,headers:s}); |
{ | ||
"name": "elysia", | ||
"description": "Fast, and friendly Bun web framework", | ||
"version": "0.5.0-exp-230422.2101", | ||
"version": "0.5.0-exp-230422.2137", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
@@ -5,3 +5,9 @@ import { Elysia } from '.' | ||
import { mapEarlyResponse, mapResponse } from './handler' | ||
import { | ||
errorToResponse, | ||
isNotEmpty, | ||
mapEarlyResponse, | ||
mapResponse, | ||
parseSetCookies | ||
} from './handler' | ||
import { createValidationError, mapPathnameAndQueryRegEx } from './utils' | ||
@@ -29,2 +35,135 @@ import { mapErrorCode } from './error' | ||
let mapResponseLiteral = ` | ||
if (isNotEmpty(c.set.headers) || c.set.status !== 200 || c.set.redirect) { | ||
if (c.set.redirect) { | ||
c.set.headers.Location = c.set.redirect | ||
c.set.status = 302 | ||
} | ||
if ( | ||
c.set.headers['Set-Cookie'] && | ||
Array.isArray(c.set.headers['Set-Cookie']) | ||
) | ||
c.set.headers = parseSetCookies( | ||
new Headers(c.set.headers), | ||
c.set.headers['Set-Cookie'] | ||
) | ||
switch (typeof r) { | ||
case 'string': | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case 'object': | ||
switch (r?.constructor) { | ||
case Error: | ||
return errorToResponse(r, c.set.headers) | ||
case Response: | ||
for (const key in c.set.headers) | ||
r.headers.append( | ||
key, | ||
c.set.headers[key] | ||
) | ||
return r | ||
case Blob: | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case Promise: | ||
return r.then((x) => mapResponse(x, c.set)) | ||
default: | ||
if (!c.set.headers['Content-Type']) | ||
c.set.headers['Content-Type'] = 'application/json' | ||
return new Response(JSON.stringify(r), { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
} | ||
// ? Maybe r function or Blob | ||
case 'function': | ||
if (r instanceof Blob) | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
return r() | ||
case 'number': | ||
case 'boolean': | ||
return new Response(r.toString(), { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
case 'undefined': | ||
return new Response('', { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
default: | ||
return new Response(r, { | ||
status: c.set.status, | ||
headers: c.set.headers | ||
}) | ||
} | ||
} else | ||
switch (typeof r) { | ||
case 'string': | ||
return new Response(r) | ||
case 'object': | ||
switch (r?.constructor) { | ||
case Error: | ||
return errorToResponse(r, c.set.headers) | ||
case Response: | ||
return r | ||
case Blob: | ||
return new Response(r) | ||
case Promise: | ||
return r.then((x) => mapResponse(x, c.set)) | ||
default: | ||
return new Response(JSON.stringify(r), { | ||
headers: { | ||
'content-type': 'application/json' | ||
} | ||
}) | ||
} | ||
// ? Maybe r or Blob | ||
case 'function': | ||
if (r instanceof Blob) return new Response(r) | ||
return r() | ||
case 'number': | ||
case 'boolean': | ||
return new Response(r.toString()) | ||
case 'undefined': | ||
return new Response('') | ||
default: | ||
return new Response(r) | ||
} | ||
` | ||
if (transpiler) | ||
mapResponseLiteral = transpiler.transformSync(mapResponseLiteral) | ||
export const composeHandler = ({ | ||
@@ -204,3 +343,3 @@ method, | ||
fnLiteral += `return mapResponse(r, c.set);\n` | ||
fnLiteral += mapResponseLiteral | ||
} else { | ||
@@ -214,8 +353,11 @@ if (validator.response) { | ||
fnLiteral += `if(response[c.set.status]?.Check(r) === false) { throw createValidationError('response', response[c.set.status], r) }\n` | ||
fnLiteral += `return mapResponse(r, c.set);` | ||
} else | ||
fnLiteral += mapResponseLiteral | ||
} else { | ||
fnLiteral += | ||
handler.constructor.name === ASYNC_FN | ||
? `return mapResponse(await handler(c), c.set);` | ||
: `return mapResponse(handler(c), c.set);` | ||
? `const r = await handler(c);\n` | ||
: `const r = handler(c);\n` | ||
fnLiteral += mapResponseLiteral | ||
} | ||
} | ||
@@ -273,3 +415,6 @@ | ||
mapErrorCode, | ||
parseQuery | ||
parseQuery, | ||
isNotEmpty, | ||
parseSetCookies, | ||
errorToResponse | ||
} | ||
@@ -294,3 +439,6 @@ } = hooks | ||
mapErrorCode, | ||
parseQuery | ||
parseQuery, | ||
isNotEmpty, | ||
parseSetCookies, | ||
errorToResponse | ||
} | ||
@@ -297,0 +445,0 @@ }) |
@@ -10,3 +10,3 @@ /* eslint-disable no-case-declarations */ | ||
const parseSetCookies = (headers: Headers, setCookie: string[]) => { | ||
export const parseSetCookies = (headers: Headers, setCookie: string[]) => { | ||
headers.delete('Set-Cookie') | ||
@@ -13,0 +13,0 @@ |
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
209152
5544