elysia 2.0.0-beta.24 → 2.0.0-beta.25
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/compile/handler/utils.js +6 -21
- package/dist/compile/handler/utils.mjs +6 -21
- package/dist/handler/fetch.js +24 -18
- package/dist/handler/fetch.mjs +24 -18
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/type/constants.d.ts +1 -1
- package/package.json +1 -1
|
@@ -219,16 +219,12 @@ function mapBeforeHandle(_hooks, derive, link, mode, report, abortGuard, arm) {
|
|
|
219
219
|
const modes = deriveModes(hooks, derive);
|
|
220
220
|
const tail = asyncTail(mode);
|
|
221
221
|
let code = "";
|
|
222
|
-
let depth = 0;
|
|
223
222
|
let needsEs = false;
|
|
224
223
|
for (let i = 0; i < hooks.length; i++) {
|
|
225
224
|
const fn = hooks[i];
|
|
226
225
|
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}_r===undefined` : void 0;
|
|
227
226
|
if (tail) code += tailStage(tail, guard);
|
|
228
|
-
else if (guard) {
|
|
229
|
-
code += `if(${guard}){\n`;
|
|
230
|
-
depth++;
|
|
231
|
-
}
|
|
227
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
232
228
|
const t = traceChild(report, fn);
|
|
233
229
|
code += t.begin;
|
|
234
230
|
code += awaitSite(`bf${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
@@ -246,9 +242,8 @@ else if(tmp){${merge};tmp=undefined}\n`;
|
|
|
246
242
|
}
|
|
247
243
|
} else code += "if(tmp!==undefined)_r=tmp\n";
|
|
248
244
|
code += t.end("tmp");
|
|
249
|
-
if (tail) code += "}\n";
|
|
245
|
+
if (tail || guard) code += "}\n";
|
|
250
246
|
}
|
|
251
|
-
code += "}".repeat(depth);
|
|
252
247
|
if (needsEs) link(require_error.ElysiaStatus, "es");
|
|
253
248
|
return code;
|
|
254
249
|
}
|
|
@@ -291,22 +286,17 @@ function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
|
|
|
291
286
|
const hooks = toArray(_hooks);
|
|
292
287
|
const tail = asyncTail(mode);
|
|
293
288
|
let code = "";
|
|
294
|
-
let depth = 0;
|
|
295
289
|
for (let i = 0; i < hooks.length; i++) {
|
|
296
290
|
const fn = hooks[i];
|
|
297
291
|
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}tmp===undefined` : void 0;
|
|
298
292
|
if (tail) code += tailStage(tail, guard);
|
|
299
|
-
else if (guard) {
|
|
300
|
-
code += `if(${guard}){\n`;
|
|
301
|
-
depth++;
|
|
302
|
-
}
|
|
293
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
303
294
|
const t = traceChild(report, fn);
|
|
304
295
|
code += t.begin;
|
|
305
296
|
code += awaitSite(`${prefix}${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
306
297
|
code += t.end("tmp");
|
|
307
|
-
if (tail) code += "}\n";
|
|
298
|
+
if (tail || guard) code += "}\n";
|
|
308
299
|
}
|
|
309
|
-
code += "}".repeat(depth);
|
|
310
300
|
code += tailPlain(mode, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
311
301
|
return code;
|
|
312
302
|
}
|
|
@@ -324,18 +314,13 @@ function map(map) {
|
|
|
324
314
|
return function(event, rest, abortGuard, tail) {
|
|
325
315
|
if (Array.isArray(event)) {
|
|
326
316
|
let code = "";
|
|
327
|
-
let depth = 0;
|
|
328
317
|
for (let i = 0; i < event.length; i++) {
|
|
329
318
|
const guard = i > 0 && abortGuard ? `!${abortGuard}` : void 0;
|
|
330
319
|
if (tail) code += tailStage(tail, guard);
|
|
331
|
-
else if (guard) {
|
|
332
|
-
code += `if(${guard}){\n`;
|
|
333
|
-
depth++;
|
|
334
|
-
}
|
|
320
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
335
321
|
code += map(i, event[i], rest);
|
|
336
|
-
if (tail) code += "}\n";
|
|
322
|
+
if (tail || guard) code += "}\n";
|
|
337
323
|
}
|
|
338
|
-
code += "}".repeat(depth);
|
|
339
324
|
return code;
|
|
340
325
|
} else if (tail) return tailStage(tail) + map(void 0, event, rest) + "}\n";
|
|
341
326
|
else return map(void 0, event, rest);
|
|
@@ -219,16 +219,12 @@ function mapBeforeHandle(_hooks, derive, link, mode, report, abortGuard, arm) {
|
|
|
219
219
|
const modes = deriveModes(hooks, derive);
|
|
220
220
|
const tail = asyncTail(mode);
|
|
221
221
|
let code = "";
|
|
222
|
-
let depth = 0;
|
|
223
222
|
let needsEs = false;
|
|
224
223
|
for (let i = 0; i < hooks.length; i++) {
|
|
225
224
|
const fn = hooks[i];
|
|
226
225
|
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}_r===undefined` : void 0;
|
|
227
226
|
if (tail) code += tailStage(tail, guard);
|
|
228
|
-
else if (guard) {
|
|
229
|
-
code += `if(${guard}){\n`;
|
|
230
|
-
depth++;
|
|
231
|
-
}
|
|
227
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
232
228
|
const t = traceChild(report, fn);
|
|
233
229
|
code += t.begin;
|
|
234
230
|
code += awaitSite(`bf${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
@@ -246,9 +242,8 @@ else if(tmp){${merge};tmp=undefined}\n`;
|
|
|
246
242
|
}
|
|
247
243
|
} else code += "if(tmp!==undefined)_r=tmp\n";
|
|
248
244
|
code += t.end("tmp");
|
|
249
|
-
if (tail) code += "}\n";
|
|
245
|
+
if (tail || guard) code += "}\n";
|
|
250
246
|
}
|
|
251
|
-
code += "}".repeat(depth);
|
|
252
247
|
if (needsEs) link(ElysiaStatus, "es");
|
|
253
248
|
return code;
|
|
254
249
|
}
|
|
@@ -291,22 +286,17 @@ function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
|
|
|
291
286
|
const hooks = toArray(_hooks);
|
|
292
287
|
const tail = asyncTail(mode);
|
|
293
288
|
let code = "";
|
|
294
|
-
let depth = 0;
|
|
295
289
|
for (let i = 0; i < hooks.length; i++) {
|
|
296
290
|
const fn = hooks[i];
|
|
297
291
|
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}tmp===undefined` : void 0;
|
|
298
292
|
if (tail) code += tailStage(tail, guard);
|
|
299
|
-
else if (guard) {
|
|
300
|
-
code += `if(${guard}){\n`;
|
|
301
|
-
depth++;
|
|
302
|
-
}
|
|
293
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
303
294
|
const t = traceChild(report, fn);
|
|
304
295
|
code += t.begin;
|
|
305
296
|
code += awaitSite(`${prefix}${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
306
297
|
code += t.end("tmp");
|
|
307
|
-
if (tail) code += "}\n";
|
|
298
|
+
if (tail || guard) code += "}\n";
|
|
308
299
|
}
|
|
309
|
-
code += "}".repeat(depth);
|
|
310
300
|
code += tailPlain(mode, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
311
301
|
return code;
|
|
312
302
|
}
|
|
@@ -324,18 +314,13 @@ function map(map) {
|
|
|
324
314
|
return function(event, rest, abortGuard, tail) {
|
|
325
315
|
if (Array.isArray(event)) {
|
|
326
316
|
let code = "";
|
|
327
|
-
let depth = 0;
|
|
328
317
|
for (let i = 0; i < event.length; i++) {
|
|
329
318
|
const guard = i > 0 && abortGuard ? `!${abortGuard}` : void 0;
|
|
330
319
|
if (tail) code += tailStage(tail, guard);
|
|
331
|
-
else if (guard) {
|
|
332
|
-
code += `if(${guard}){\n`;
|
|
333
|
-
depth++;
|
|
334
|
-
}
|
|
320
|
+
else if (guard) code += `if(${guard}){\n`;
|
|
335
321
|
code += map(i, event[i], rest);
|
|
336
|
-
if (tail) code += "}\n";
|
|
322
|
+
if (tail || guard) code += "}\n";
|
|
337
323
|
}
|
|
338
|
-
code += "}".repeat(depth);
|
|
339
324
|
return code;
|
|
340
325
|
} else if (tail) return tailStage(tail) + map(void 0, event, rest) + "}\n";
|
|
341
326
|
else return map(void 0, event, rest);
|
package/dist/handler/fetch.js
CHANGED
|
@@ -72,28 +72,34 @@ function dispatchResult(result, context, handleError, afterResponse) {
|
|
|
72
72
|
function findRoute(context, request, map, router, onNotFound, handleError, afterResponse, strictPath, hasWS, hasDynamicWS, app) {
|
|
73
73
|
const path = context.path;
|
|
74
74
|
const method = request.method;
|
|
75
|
-
if (hasWS
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
if (hasWS) {
|
|
76
|
+
const wsMap = map["WS"];
|
|
77
|
+
if (method === "GET") {
|
|
78
|
+
const handler = path.length === 1 && path === "/" ? wsMap?.["/"] : wsMap?.[path];
|
|
79
|
+
const found = handler === void 0 && hasDynamicWS ? router?.find("WS", path) : void 0;
|
|
80
|
+
if (handler !== void 0 || found) {
|
|
81
|
+
const upgrade = request.headers.get("upgrade");
|
|
82
|
+
if (upgrade && upgrade.toLowerCase() === "websocket") {
|
|
83
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
84
|
+
context.params = path.indexOf("%") === -1 ? found.params : decodeParams(found.params);
|
|
85
|
+
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
86
|
+
}
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
const methodMap = map[method];
|
|
88
|
-
let handler
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
handler
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
handler
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
let handler;
|
|
92
|
+
if (path.length > 1) {
|
|
93
|
+
handler = methodMap?.[path];
|
|
94
|
+
if (!handler) if (!strictPath && path.charCodeAt(path.length - 1) === 47) {
|
|
95
|
+
const loose = path.slice(0, -1);
|
|
96
|
+
handler = loose.length > 1 ? methodMap?.[loose] : methodMap?.[path[0]];
|
|
97
|
+
if (!handler) {
|
|
98
|
+
const anyMap = map["*"];
|
|
99
|
+
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
100
|
+
}
|
|
101
|
+
} else handler = map["*"]?.[path];
|
|
102
|
+
} else handler = methodMap?.[context.path] || map["*"]?.[path];
|
|
97
103
|
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
98
104
|
const found = router?.find(method, path) ?? router?.find("*", path);
|
|
99
105
|
if (found) {
|
package/dist/handler/fetch.mjs
CHANGED
|
@@ -70,28 +70,34 @@ function dispatchResult(result, context, handleError, afterResponse) {
|
|
|
70
70
|
function findRoute(context, request, map, router, onNotFound, handleError, afterResponse, strictPath, hasWS, hasDynamicWS, app) {
|
|
71
71
|
const path = context.path;
|
|
72
72
|
const method = request.method;
|
|
73
|
-
if (hasWS
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
if (hasWS) {
|
|
74
|
+
const wsMap = map["WS"];
|
|
75
|
+
if (method === "GET") {
|
|
76
|
+
const handler = path.length === 1 && path === "/" ? wsMap?.["/"] : wsMap?.[path];
|
|
77
|
+
const found = handler === void 0 && hasDynamicWS ? router?.find("WS", path) : void 0;
|
|
78
|
+
if (handler !== void 0 || found) {
|
|
79
|
+
const upgrade = request.headers.get("upgrade");
|
|
80
|
+
if (upgrade && upgrade.toLowerCase() === "websocket") {
|
|
81
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
82
|
+
context.params = path.indexOf("%") === -1 ? found.params : decodeParams(found.params);
|
|
83
|
+
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
const methodMap = map[method];
|
|
86
|
-
let handler
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
handler
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
handler
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
let handler;
|
|
90
|
+
if (path.length > 1) {
|
|
91
|
+
handler = methodMap?.[path];
|
|
92
|
+
if (!handler) if (!strictPath && path.charCodeAt(path.length - 1) === 47) {
|
|
93
|
+
const loose = path.slice(0, -1);
|
|
94
|
+
handler = loose.length > 1 ? methodMap?.[loose] : methodMap?.[path[0]];
|
|
95
|
+
if (!handler) {
|
|
96
|
+
const anyMap = map["*"];
|
|
97
|
+
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
98
|
+
}
|
|
99
|
+
} else handler = map["*"]?.[path];
|
|
100
|
+
} else handler = methodMap?.[context.path] || map["*"]?.[path];
|
|
95
101
|
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
96
102
|
const found = router?.find(method, path) ?? router?.find("*", path);
|
|
97
103
|
if (found) {
|
package/dist/package.js
CHANGED
package/dist/package.mjs
CHANGED
package/dist/type/constants.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
|
|
|
17
17
|
readonly NoValidate: 15;
|
|
18
18
|
};
|
|
19
19
|
type ELYSIA_TYPES = typeof ELYSIA_TYPES;
|
|
20
|
-
declare const primitiveElysiaTypes: Set<
|
|
20
|
+
declare const primitiveElysiaTypes: Set<6 | 1 | 2 | 3 | 10 | 11 | 13 | 14>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|