elysia 0.5.20 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/compose.js +3 -1
- package/dist/compose.js +8 -7
- package/package.json +2 -1
package/dist/cjs/compose.js
CHANGED
|
@@ -446,8 +446,10 @@ const composeHandler = ({ method, hooks, validator, handler, handleError, meta,
|
|
|
446
446
|
fnLiteral += `${name} = mapEarlyResponse(${name}, c.set)\n`;
|
|
447
447
|
fnLiteral += `if(${name}) return ${name};\n}`;
|
|
448
448
|
}
|
|
449
|
-
else
|
|
449
|
+
else {
|
|
450
|
+
fnLiteral += `${name} = mapEarlyResponse(${name}, c.set)\n`;
|
|
450
451
|
fnLiteral += `if(${name}) return ${name};\n`;
|
|
452
|
+
}
|
|
451
453
|
}
|
|
452
454
|
}
|
|
453
455
|
if (validator.response)
|
package/dist/compose.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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
|
|
1
|
+
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 a}from"./utils";import{NotFoundError as o,ValidationError as c,InternalServerError as l}from"./error";let i="AsyncFunction",f=e=>e.constructor.name===i,u=new Headers,d=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 p=e=>({composeValidation:(r,t=`c.${r}`)=>e?`throw new ValidationError(
|
|
2
2
|
'${r}',
|
|
3
3
|
${r},
|
|
4
4
|
${t}
|
|
@@ -14,7 +14,7 @@ ${r}
|
|
|
14
14
|
'response',
|
|
15
15
|
response[c.set.status],
|
|
16
16
|
${r}
|
|
17
|
-
).toResponse(c.set.headers)`});export const isFnUse=(e,r)=>{r=(r=r.trimStart()).replaceAll(/^async /g,"");let t=40===r.charCodeAt(0)||r.startsWith("function")?r.slice(r.indexOf("(")+1,r.indexOf(")")):r.slice(0,r.indexOf("=")-1);if(""===t)return!1;if(123===t.charCodeAt(0))return!!t.includes(e);if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let s=[t];for(let e of r.matchAll(d))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
|
|
17
|
+
).toResponse(c.set.headers)`});export const isFnUse=(e,r)=>{r=(r=r.trimStart()).replaceAll(/^async /g,"");let t=40===r.charCodeAt(0)||r.startsWith("function")?r.slice(r.indexOf("(")+1,r.indexOf(")")):r.slice(0,r.indexOf("=")-1);if(""===t)return!1;if(123===t.charCodeAt(0))return!!t.includes(e);if(r.match(RegExp(`${t}(.${e}|\\["${e}"\\])`)))return!0;let s=[t];for(let e of r.matchAll(d))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 a=n[r],o=s?s+"."+r:r;if("object"===a.type){findElysiaMeta(e,a,t,o);continue}if(a.anyOf){for(let r of a.anyOf)findElysiaMeta(e,r,t,o);continue}a.elysiaMeta===e&&t.push(o)}return 0===t.length?null:t}return r?.elysiaMeta===e?(s&&t.push(s),"root"):null};let y=e=>{if(!e)return;let r=e?.schema;if(r&&"anyOf"in r){let e=!1,t=r.anyOf[0].type;for(let s of r.anyOf)if(s.type!==t){e=!0;break}if(!e)return t}};export const composeHandler=({method:d,hooks:m,validator:h,handler:$,handleError:b,meta:q,onRequest:E,config:g})=>{let w=g.forceErrorEncapsulation||m.error.length>0||"undefined"==typeof Bun,{composeValidation:x,composeResponseValidation:k}=p(w),H=w?"try {\n":"",R=h||"GET"!==d?[$,...m.transform,...m.beforeHandle,...m.afterHandle].map(e=>e.toString()):[],v="GET"!==d&&"none"!==m.type&&(h.body||m.type||R.some(e=>isFnUse("body",e))),O=h.headers||R.some(e=>isFnUse("headers",e));O&&(H+=u.toJSON?`c.headers = c.request.headers.toJSON()
|
|
18
18
|
`:`c.headers = {}
|
|
19
19
|
for (const [key, value] of c.request.headers.entries())
|
|
20
20
|
c.headers[key] = value
|
|
@@ -118,7 +118,8 @@ ${r}
|
|
|
118
118
|
}
|
|
119
119
|
${r} = mapEarlyResponse(${r}, c.set)
|
|
120
120
|
if(${r}) return ${r};
|
|
121
|
-
}`:H
|
|
121
|
+
}`:H+=`${r} = mapEarlyResponse(${r}, c.set)
|
|
122
|
+
if(${r}) return ${r};
|
|
122
123
|
`):H+=m.afterHandle[e].constructor.name===i?`await afterHandle[${e}](c, r)
|
|
123
124
|
`:`afterHandle[${e}](c, r)
|
|
124
125
|
`}h.response&&(H+=`if(response[c.set.status]?.Check(r) === false) {
|
|
@@ -198,7 +199,7 @@ if(${r}) return ${r};
|
|
|
198
199
|
return ${F?"async":""} function(c) {
|
|
199
200
|
${q?"c[SCHEMA] = meta[SCHEMA]; c[DEFS] = meta[DEFS];":""}
|
|
200
201
|
${H}
|
|
201
|
-
}`;let N=Function("hooks",H);return N({handler:$,hooks:m,validator:h,handleError:b,utils:{mapResponse:t,mapCompactResponse:s,mapEarlyResponse:r,parseQuery:e},error:{NotFoundError:
|
|
202
|
+
}`;let N=Function("hooks",H);return N({handler:$,hooks:m,validator:h,handleError:b,utils:{mapResponse:t,mapCompactResponse:s,mapEarlyResponse:r,parseQuery:e},error:{NotFoundError:o,ValidationError:c,InternalServerError:l},meta:q,SCHEMA:q?n:void 0,DEFS:q?a:void 0})};export const composeGeneralHandler=e=>{let t="";for(let r of Object.keys(e.decorators))t+=`,${r}: app.decorators.${r}`;let{router:s,staticRouter:n}=e,a=`
|
|
202
203
|
const route = find(request.method, path) ${s.root.ALL?'?? find("ALL", path)':""}
|
|
203
204
|
if (route === null)
|
|
204
205
|
return ${e.event.error.length?`handleError(
|
|
@@ -214,7 +215,7 @@ if(${r}) return ${r};
|
|
|
214
215
|
return route.store(ctx)`,c="";for(let[e,{code:r,all:t}]of Object.entries(n.map))c+=`case '${e}':
|
|
215
216
|
switch(request.method) {
|
|
216
217
|
${r}
|
|
217
|
-
${t??`default: ${
|
|
218
|
+
${t??`default: ${a}`}}
|
|
218
219
|
|
|
219
220
|
`;let l=`const {
|
|
220
221
|
app,
|
|
@@ -282,9 +283,9 @@ ${t??`default: ${o}`}}
|
|
|
282
283
|
${c}
|
|
283
284
|
|
|
284
285
|
default:
|
|
285
|
-
${
|
|
286
|
+
${a}
|
|
286
287
|
}
|
|
287
|
-
}`,e.handleError=composeErrorHandler(e),Function("data",l)({app:e,mapEarlyResponse:r,NotFoundError:
|
|
288
|
+
}`,e.handleError=composeErrorHandler(e),Function("data",l)({app:e,mapEarlyResponse:r,NotFoundError:o})};export const composeErrorHandler=e=>{let r=`const {
|
|
288
289
|
app: { event: { error: onError } },
|
|
289
290
|
mapResponse
|
|
290
291
|
} = inject
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elysia",
|
|
3
3
|
"description": "Fast, and friendly Bun web framework",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.21",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
7
7
|
"url": "https://github.com/SaltyAom",
|
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
"devDependencies": {
|
|
120
120
|
"@elysiajs/cors": "^0.5.0",
|
|
121
121
|
"@elysiajs/html": "^0.5.2",
|
|
122
|
+
"@elysiajs/swagger": "^0.5.2",
|
|
122
123
|
"@swc/cli": "^0.1.62",
|
|
123
124
|
"@swc/core": "^1.3.41",
|
|
124
125
|
"@types/node": "^18.15.5",
|