elysia 2.0.0-beta.12 → 2.0.0-beta.13
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/adapter/bun/index.js +28 -17
- package/dist/adapter/bun/index.mjs +28 -17
- package/dist/adapter/utils.js +1 -0
- package/dist/adapter/utils.mjs +1 -0
- package/dist/adapter/web-standard/handler.js +2 -2
- package/dist/adapter/web-standard/handler.mjs +2 -2
- package/dist/compile/aot-emit.js +1 -1
- package/dist/compile/aot-emit.mjs +1 -1
- package/dist/compile/aot.d.ts +1 -1
- package/dist/compile/aot.js +2 -2
- package/dist/compile/aot.mjs +2 -2
- package/dist/compile/handler/descriptor.d.ts +2 -3
- package/dist/compile/handler/descriptor.js +6 -16
- package/dist/compile/handler/descriptor.mjs +7 -16
- package/dist/compile/handler/index.d.ts +1 -1
- package/dist/compile/handler/index.js +15 -6
- package/dist/compile/handler/index.mjs +15 -6
- package/dist/compile/handler/jit.js +71 -66
- package/dist/compile/handler/jit.mjs +72 -67
- package/dist/compile/handler/params.js +3 -2
- package/dist/compile/handler/params.mjs +4 -3
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +7 -6
- package/dist/compile/handler/utils.js +23 -18
- package/dist/compile/handler/utils.mjs +23 -19
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/cookie/lib.js +2 -1
- package/dist/cookie/lib.mjs +2 -1
- package/dist/cookie/utils.d.ts +1 -1
- package/dist/cookie/utils.js +9 -23
- package/dist/cookie/utils.mjs +9 -23
- package/dist/handler/error.js +3 -4
- package/dist/handler/error.mjs +3 -4
- package/dist/handler/fetch.js +17 -13
- package/dist/handler/fetch.mjs +17 -13
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +2 -0
- package/dist/plugin/aot/core.js +6 -0
- package/dist/plugin/aot/core.mjs +6 -0
- package/dist/plugin/aot/hooks.js +5 -1
- package/dist/plugin/aot/hooks.mjs +5 -1
- package/dist/trace.js +14 -5
- package/dist/trace.mjs +14 -5
- package/dist/type/constants.d.ts +1 -1
- package/dist/types.d.ts +5 -4
- package/dist/utils.d.ts +0 -1
- package/package.json +4 -4
|
@@ -24,7 +24,9 @@ function cloneResponse(r) {
|
|
|
24
24
|
}
|
|
25
25
|
function cloneStaticValue(value) {
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
const cloned = structuredClone(value);
|
|
28
|
+
if (Object.getPrototypeOf(value) === ElysiaStatus.prototype) Object.setPrototypeOf(cloned, ElysiaStatus.prototype);
|
|
29
|
+
return cloned;
|
|
28
30
|
} catch {
|
|
29
31
|
return value;
|
|
30
32
|
}
|
|
@@ -50,10 +52,9 @@ function armEntryAbort(context) {
|
|
|
50
52
|
}
|
|
51
53
|
const trace = (report, fn) => report?.resolveChild(childName(fn)) ?? noTrace;
|
|
52
54
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
53
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report]) => {
|
|
55
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report, arm]) => {
|
|
54
56
|
const t = trace(report, fn);
|
|
55
|
-
const
|
|
56
|
-
const call = guard ? `_tf=tf${at(i)}(c)\n${guard}` : `${Await(fn)}tf${at(i)}(c)\n`;
|
|
57
|
+
const call = isAsync ? `_tf=tf${at(i)}(c)\n${awaitGuard(fn, isAsync, "_tf", arm)}` : `tf${at(i)}(c)\n`;
|
|
57
58
|
return t.begin + call + t.end();
|
|
58
59
|
});
|
|
59
60
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -317,7 +318,7 @@ function skipValue(src, i) {
|
|
|
317
318
|
}
|
|
318
319
|
return -1;
|
|
319
320
|
}
|
|
320
|
-
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
321
|
+
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
|
|
321
322
|
const hooks = toArray(_hooks);
|
|
322
323
|
const modes = deriveModes(hooks, derive);
|
|
323
324
|
let code = "";
|
|
@@ -331,8 +332,8 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
|
331
332
|
}
|
|
332
333
|
const t = trace(report, fn);
|
|
333
334
|
code += t.begin;
|
|
334
|
-
code += `tmp
|
|
335
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
335
|
+
code += `tmp=bf${at(i)}(c)\n`;
|
|
336
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
336
337
|
if (modes?.[i] !== void 0) {
|
|
337
338
|
needsEs = true;
|
|
338
339
|
if (modes[i]) {
|
|
@@ -378,7 +379,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
378
379
|
if (!first && abort && context["~sig"]?.aborted) return;
|
|
379
380
|
first = false;
|
|
380
381
|
let result = values[j](context);
|
|
381
|
-
if (result
|
|
382
|
+
if (typeof result?.then === "function") {
|
|
382
383
|
result = await result;
|
|
383
384
|
if (abort) context["~sig"] ??= context.request.signal;
|
|
384
385
|
}
|
|
@@ -386,7 +387,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
|
-
function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
390
|
+
function mapChainHook(hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
390
391
|
let code = "";
|
|
391
392
|
let depth = 0;
|
|
392
393
|
for (let i = 0; i < hooks.length; i++) {
|
|
@@ -397,25 +398,25 @@ function mapChainHook(hooks, prefix, isAsync, report, abortGuard) {
|
|
|
397
398
|
}
|
|
398
399
|
const t = trace(report, fn);
|
|
399
400
|
code += t.begin;
|
|
400
|
-
code += `tmp=${
|
|
401
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
401
|
+
code += `tmp=${prefix}${at(i)}(c)\n`;
|
|
402
|
+
code += awaitGuard(fn, isAsync, "tmp", arm);
|
|
402
403
|
code += t.end("tmp");
|
|
403
404
|
}
|
|
404
405
|
code += "}".repeat(depth);
|
|
405
406
|
code += `if(tmp!==undefined)_r=c.responseValue=tmp\n`;
|
|
406
407
|
return code;
|
|
407
408
|
}
|
|
408
|
-
const mapAfterHandle = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard);
|
|
409
|
-
const mapMapResponse = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard);
|
|
409
|
+
const mapAfterHandle = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard, arm);
|
|
410
|
+
const mapMapResponse = (_hooks, isAsync, report, abortGuard, arm) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard, arm);
|
|
410
411
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
411
412
|
const t = trace(report, fn);
|
|
412
|
-
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(_ar
|
|
413
|
+
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
413
414
|
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
414
415
|
});
|
|
415
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync]) => {
|
|
416
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync, arm]) => {
|
|
416
417
|
link(mapResponse, "rm");
|
|
417
418
|
link(adoptErrorType, "aet");
|
|
418
|
-
return `_r
|
|
419
|
+
return `_r=er${at(i)}(c)\n` + awaitGuard(fn, isAsync, "_r", arm) + "if(_r!==undefined){\nif(_r instanceof Response)c.set.status=_r.status\nelse if(c.set.status===undefined||c.set.status===200)c.set.status=500\n" + schedule + sign + `return _em(c,${map}(aet(_r,e),c.set,c.request,true))\n}\n`;
|
|
419
420
|
});
|
|
420
421
|
function map(map) {
|
|
421
422
|
return function(event, rest, abortGuard) {
|
|
@@ -501,8 +502,11 @@ function getQueryParseChannels(querySchema) {
|
|
|
501
502
|
queryParseChannelsCache.set(querySchema, result);
|
|
502
503
|
return result ?? void 0;
|
|
503
504
|
}
|
|
504
|
-
|
|
505
|
-
|
|
505
|
+
function awaitGuard(fn, isAsync, target, arm = "") {
|
|
506
|
+
if (!isAsync) return "";
|
|
507
|
+
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
508
|
+
return isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
509
|
+
}
|
|
506
510
|
|
|
507
511
|
//#endregion
|
|
508
|
-
export { armEntryAbort, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
|
512
|
+
export { armEntryAbort, awaitGuard, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
package/dist/compile/utils.js
CHANGED
|
@@ -4,14 +4,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
function isAsyncFunction(fn) {
|
|
5
5
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
8
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
9
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
9
10
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
10
11
|
function mayReturnPromise(fn) {
|
|
11
12
|
let result = mayReturnPromiseCache.get(fn);
|
|
12
13
|
if (result !== void 0) return result;
|
|
13
|
-
const literal =
|
|
14
|
-
|
|
14
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
15
|
+
const arrow = matchArrow.exec(literal);
|
|
16
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
17
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
15
18
|
mayReturnPromiseCache.set(fn, result);
|
|
16
19
|
return result;
|
|
17
20
|
}
|
package/dist/compile/utils.mjs
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
function isAsyncFunction(fn) {
|
|
3
3
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
4
4
|
}
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
6
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
7
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
7
8
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function mayReturnPromise(fn) {
|
|
9
10
|
let result = mayReturnPromiseCache.get(fn);
|
|
10
11
|
if (result !== void 0) return result;
|
|
11
|
-
const literal =
|
|
12
|
-
|
|
12
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
13
|
+
const arrow = matchArrow.exec(literal);
|
|
14
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
15
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
13
16
|
mayReturnPromiseCache.set(fn, result);
|
|
14
17
|
return result;
|
|
15
18
|
}
|
package/dist/cookie/lib.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_constants = require('../constants.js');
|
|
2
3
|
const require_utils = require('../utils.js');
|
|
3
4
|
const require_cookie_error = require('./error.js');
|
|
4
5
|
|
|
@@ -21,7 +22,7 @@ function parse(str) {
|
|
|
21
22
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
22
23
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
23
24
|
const key = str.slice(ks, ke);
|
|
24
|
-
if (obj[key] === void 0) {
|
|
25
|
+
if (obj[key] === void 0 && !require_constants.dangerousKeys.has(key)) {
|
|
25
26
|
let vs = eq + 1, ve = semi;
|
|
26
27
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
27
28
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
package/dist/cookie/lib.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dangerousKeys } from "../constants.mjs";
|
|
1
2
|
import { nullObject } from "../utils.mjs";
|
|
2
3
|
import { InvalidCookie } from "./error.mjs";
|
|
3
4
|
|
|
@@ -20,7 +21,7 @@ function parse(str) {
|
|
|
20
21
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
21
22
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
22
23
|
const key = str.slice(ks, ke);
|
|
23
|
-
if (obj[key] === void 0) {
|
|
24
|
+
if (obj[key] === void 0 && !dangerousKeys.has(key)) {
|
|
24
25
|
let vs = eq + 1, ve = semi;
|
|
25
26
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
26
27
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
package/dist/cookie/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { hasSyncHmac } from "./crypto.js";
|
|
|
4
4
|
import { CompiledCookieConfig } from "./config.js";
|
|
5
5
|
|
|
6
6
|
//#region src/cookie/utils.d.ts
|
|
7
|
-
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig):
|
|
7
|
+
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig): any;
|
|
8
8
|
/**
|
|
9
9
|
* Unsigned + unvalidated lane only
|
|
10
10
|
*
|
package/dist/cookie/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_constants = require('../constants.js');
|
|
4
3
|
const require_utils = require('../utils.js');
|
|
5
4
|
const require_cookie_lib = require('./lib.js');
|
|
6
5
|
const require_cookie_crypto = require('./crypto.js');
|
|
@@ -11,11 +10,10 @@ deuri = require_runtime.__toESM(deuri);
|
|
|
11
10
|
|
|
12
11
|
//#region src/cookie/utils.ts
|
|
13
12
|
function parseCookieRawSync(cookieString, _config) {
|
|
14
|
-
|
|
15
|
-
if (!cookieString) return out;
|
|
13
|
+
if (!cookieString) return require_utils.nullObject();
|
|
16
14
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
15
|
+
const out = cookies;
|
|
17
16
|
for (const name in cookies) {
|
|
18
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
19
17
|
const v = cookies[name];
|
|
20
18
|
if (v === void 0) continue;
|
|
21
19
|
out[name] = require_cookie_crypto.maybeJsonDecode((0, deuri.default)(v) ?? v);
|
|
@@ -29,23 +27,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
29
27
|
* the raw record before the handler touches a name.
|
|
30
28
|
*/
|
|
31
29
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
32
|
-
|
|
33
|
-
if (!cookieString) return out;
|
|
34
|
-
const cookies = require_cookie_lib.parse(cookieString);
|
|
35
|
-
for (const name in cookies) {
|
|
36
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
37
|
-
const v = cookies[name];
|
|
38
|
-
if (v === void 0) continue;
|
|
39
|
-
out[name] = v;
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
30
|
+
return cookieString ? require_cookie_lib.parse(cookieString) : require_utils.nullObject();
|
|
42
31
|
}
|
|
43
32
|
function parseCookieRawLazy(cookieString, config) {
|
|
44
|
-
|
|
45
|
-
if (!cookieString) return out;
|
|
33
|
+
if (!cookieString) return require_utils.nullObject();
|
|
46
34
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
35
|
+
const out = cookies;
|
|
47
36
|
for (const name in cookies) {
|
|
48
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
49
37
|
const v = cookies[name];
|
|
50
38
|
if (v === void 0) continue;
|
|
51
39
|
const decoded = (0, deuri.default)(v) ?? v;
|
|
@@ -56,11 +44,10 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
56
44
|
async function parseCookieRaw(cookieString, config) {
|
|
57
45
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
58
46
|
if (require_cookie_crypto.hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
59
|
-
|
|
60
|
-
if (!cookieString) return out;
|
|
47
|
+
if (!cookieString) return require_utils.nullObject();
|
|
61
48
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
49
|
+
const out = cookies;
|
|
62
50
|
for (const name in cookies) {
|
|
63
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
64
51
|
const v = cookies[name];
|
|
65
52
|
if (v === void 0) continue;
|
|
66
53
|
let value = (0, deuri.default)(v) ?? v;
|
|
@@ -72,11 +59,10 @@ async function parseCookieRaw(cookieString, config) {
|
|
|
72
59
|
}
|
|
73
60
|
function parseCookieRawSigned(cookieString, config) {
|
|
74
61
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
75
|
-
|
|
76
|
-
if (!cookieString) return out;
|
|
62
|
+
if (!cookieString) return require_utils.nullObject();
|
|
77
63
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
64
|
+
const out = cookies;
|
|
78
65
|
for (const name in cookies) {
|
|
79
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
80
66
|
const v = cookies[name];
|
|
81
67
|
if (v === void 0) continue;
|
|
82
68
|
let value = (0, deuri.default)(v) ?? v;
|
package/dist/cookie/utils.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { dangerousKeys } from "../constants.mjs";
|
|
2
1
|
import { nullObject } from "../utils.mjs";
|
|
3
2
|
import { parse } from "./lib.mjs";
|
|
4
3
|
import { deriveSignKey, hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieSyncImpl, unsignWithSecrets, unsignWithSecretsSync } from "./crypto.mjs";
|
|
@@ -8,11 +7,10 @@ import decodeComponent from "deuri";
|
|
|
8
7
|
|
|
9
8
|
//#region src/cookie/utils.ts
|
|
10
9
|
function parseCookieRawSync(cookieString, _config) {
|
|
11
|
-
|
|
12
|
-
if (!cookieString) return out;
|
|
10
|
+
if (!cookieString) return nullObject();
|
|
13
11
|
const cookies = parse(cookieString);
|
|
12
|
+
const out = cookies;
|
|
14
13
|
for (const name in cookies) {
|
|
15
|
-
if (dangerousKeys.has(name)) continue;
|
|
16
14
|
const v = cookies[name];
|
|
17
15
|
if (v === void 0) continue;
|
|
18
16
|
out[name] = maybeJsonDecode(decodeComponent(v) ?? v);
|
|
@@ -26,23 +24,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
26
24
|
* the raw record before the handler touches a name.
|
|
27
25
|
*/
|
|
28
26
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
29
|
-
|
|
30
|
-
if (!cookieString) return out;
|
|
31
|
-
const cookies = parse(cookieString);
|
|
32
|
-
for (const name in cookies) {
|
|
33
|
-
if (dangerousKeys.has(name)) continue;
|
|
34
|
-
const v = cookies[name];
|
|
35
|
-
if (v === void 0) continue;
|
|
36
|
-
out[name] = v;
|
|
37
|
-
}
|
|
38
|
-
return out;
|
|
27
|
+
return cookieString ? parse(cookieString) : nullObject();
|
|
39
28
|
}
|
|
40
29
|
function parseCookieRawLazy(cookieString, config) {
|
|
41
|
-
|
|
42
|
-
if (!cookieString) return out;
|
|
30
|
+
if (!cookieString) return nullObject();
|
|
43
31
|
const cookies = parse(cookieString);
|
|
32
|
+
const out = cookies;
|
|
44
33
|
for (const name in cookies) {
|
|
45
|
-
if (dangerousKeys.has(name)) continue;
|
|
46
34
|
const v = cookies[name];
|
|
47
35
|
if (v === void 0) continue;
|
|
48
36
|
const decoded = decodeComponent(v) ?? v;
|
|
@@ -53,11 +41,10 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
53
41
|
async function parseCookieRaw(cookieString, config) {
|
|
54
42
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
55
43
|
if (hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
56
|
-
|
|
57
|
-
if (!cookieString) return out;
|
|
44
|
+
if (!cookieString) return nullObject();
|
|
58
45
|
const cookies = parse(cookieString);
|
|
46
|
+
const out = cookies;
|
|
59
47
|
for (const name in cookies) {
|
|
60
|
-
if (dangerousKeys.has(name)) continue;
|
|
61
48
|
const v = cookies[name];
|
|
62
49
|
if (v === void 0) continue;
|
|
63
50
|
let value = decodeComponent(v) ?? v;
|
|
@@ -69,11 +56,10 @@ async function parseCookieRaw(cookieString, config) {
|
|
|
69
56
|
}
|
|
70
57
|
function parseCookieRawSigned(cookieString, config) {
|
|
71
58
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
72
|
-
|
|
73
|
-
if (!cookieString) return out;
|
|
59
|
+
if (!cookieString) return nullObject();
|
|
74
60
|
const cookies = parse(cookieString);
|
|
61
|
+
const out = cookies;
|
|
75
62
|
for (const name in cookies) {
|
|
76
|
-
if (dangerousKeys.has(name)) continue;
|
|
77
63
|
const v = cookies[name];
|
|
78
64
|
if (v === void 0) continue;
|
|
79
65
|
let value = decodeComponent(v) ?? v;
|
package/dist/handler/error.js
CHANGED
|
@@ -174,16 +174,15 @@ function createErrorHandler(onErrors, mapResponse, defaultError, allowUnsafe = f
|
|
|
174
174
|
parseQuery(context);
|
|
175
175
|
return fallbackResponse(context, error, mapResponse, defaultError);
|
|
176
176
|
};
|
|
177
|
-
|
|
178
|
-
if (asyncIndexes) return async (context, error) => {
|
|
177
|
+
if (require_handler_utils.getAsyncIndexes(onErrors)) return async (context, error) => {
|
|
179
178
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
180
179
|
context.error = error;
|
|
181
180
|
if (allowUnsafe && error instanceof require_error.ValidationError) error.allowUnsafeValidationDetails = true;
|
|
182
181
|
applyErrorStatus(context, error);
|
|
183
182
|
parseQuery(context);
|
|
184
183
|
for (let i = 0; i < onErrors.length; i++) {
|
|
185
|
-
let result =
|
|
186
|
-
if (result
|
|
184
|
+
let result = onErrors[i](context);
|
|
185
|
+
if (typeof result?.then === "function") result = await result;
|
|
187
186
|
if (result !== void 0) {
|
|
188
187
|
if (result instanceof require_error.ElysiaStatus || result instanceof Response) context.set.status = result.status;
|
|
189
188
|
else if (context.set.status === void 0 || context.set.status === 200) context.set.status = 500;
|
package/dist/handler/error.mjs
CHANGED
|
@@ -173,16 +173,15 @@ function createErrorHandler(onErrors, mapResponse, defaultError, allowUnsafe = f
|
|
|
173
173
|
parseQuery(context);
|
|
174
174
|
return fallbackResponse(context, error, mapResponse, defaultError);
|
|
175
175
|
};
|
|
176
|
-
|
|
177
|
-
if (asyncIndexes) return async (context, error) => {
|
|
176
|
+
if (getAsyncIndexes(onErrors)) return async (context, error) => {
|
|
178
177
|
materializeSetHeaders(context.set);
|
|
179
178
|
context.error = error;
|
|
180
179
|
if (allowUnsafe && error instanceof ValidationError) error.allowUnsafeValidationDetails = true;
|
|
181
180
|
applyErrorStatus(context, error);
|
|
182
181
|
parseQuery(context);
|
|
183
182
|
for (let i = 0; i < onErrors.length; i++) {
|
|
184
|
-
let result =
|
|
185
|
-
if (result
|
|
183
|
+
let result = onErrors[i](context);
|
|
184
|
+
if (typeof result?.then === "function") result = await result;
|
|
186
185
|
if (result !== void 0) {
|
|
187
186
|
if (result instanceof ElysiaStatus || result instanceof Response) context.set.status = result.status;
|
|
188
187
|
else if (context.set.status === void 0 || context.set.status === 200) context.set.status = 500;
|
package/dist/handler/fetch.js
CHANGED
|
@@ -136,11 +136,10 @@ function createFetchHandler(app) {
|
|
|
136
136
|
return (context["~sig"] = request.signal).aborted;
|
|
137
137
|
};
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* never reaches it.
|
|
139
|
+
* Peek after each callback. The actual await branch arms deferred requests;
|
|
140
|
+
* immediate callbacks must not materialize a signal just for this check.
|
|
142
141
|
*/
|
|
143
|
-
const armedAbort = (
|
|
142
|
+
const armedAbort = (context) => abortSignal && context["~sig"]?.aborted === true;
|
|
144
143
|
const baseMapResponse = (app["~config"]?.adapter ?? require_adapter_constants.defaultAdapter).response.map;
|
|
145
144
|
const mapResponseHooks = hook?.mapResponse;
|
|
146
145
|
const mapResponse = mapResponseHooks?.length ? (response, set, context) => {
|
|
@@ -150,7 +149,7 @@ function createFetchHandler(app) {
|
|
|
150
149
|
const run = (i) => {
|
|
151
150
|
for (; i < mapResponseHooks.length; i++) {
|
|
152
151
|
const result = mapResponseHooks[i](context);
|
|
153
|
-
if (result
|
|
152
|
+
if (typeof result?.then === "function") return Promise.resolve(result).then((resolved) => {
|
|
154
153
|
if (resolved !== void 0) return baseMapResponse(resolved, set, request, true);
|
|
155
154
|
return run(i + 1);
|
|
156
155
|
});
|
|
@@ -218,7 +217,6 @@ function createFetchHandler(app) {
|
|
|
218
217
|
app["~finalizeError"] = (context, error) => finalizeError(context, handleError, afterResponse, error);
|
|
219
218
|
if (traceRequestPhase) {
|
|
220
219
|
const onRequests = hook?.request ?? [];
|
|
221
|
-
const asyncIndexes = onRequests.length ? require_handler_utils.getAsyncIndexes(onRequests) : void 0;
|
|
222
220
|
return async (request, server) => {
|
|
223
221
|
const context = new Context(request);
|
|
224
222
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
@@ -247,10 +245,14 @@ function createFetchHandler(app) {
|
|
|
247
245
|
name: onRequests[i].name || "anonymous",
|
|
248
246
|
begin: performance.now()
|
|
249
247
|
});
|
|
250
|
-
|
|
248
|
+
let result = onRequests[i](context);
|
|
249
|
+
if (typeof result?.then === "function") {
|
|
250
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
251
|
+
result = await result;
|
|
252
|
+
}
|
|
251
253
|
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
252
254
|
for (let i = 0; i < traceLength; i++) endReports[i]?.();
|
|
253
|
-
if (armedAbort(
|
|
255
|
+
if (armedAbort(context)) {
|
|
254
256
|
for (let j = 0; j < traceLength; j++) trace[j].r(requestReports[j]);
|
|
255
257
|
return require_handler_utils.emptyResponse.clone();
|
|
256
258
|
}
|
|
@@ -271,8 +273,7 @@ function createFetchHandler(app) {
|
|
|
271
273
|
}
|
|
272
274
|
if (hook?.request) {
|
|
273
275
|
const onRequests = hook.request;
|
|
274
|
-
|
|
275
|
-
if (asyncIndexes) return async (request, server) => {
|
|
276
|
+
if (require_handler_utils.getAsyncIndexes(onRequests)) return async (request, server) => {
|
|
276
277
|
const context = new Context(request);
|
|
277
278
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
278
279
|
if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
|
|
@@ -280,10 +281,13 @@ function createFetchHandler(app) {
|
|
|
280
281
|
context.server = server ?? null;
|
|
281
282
|
try {
|
|
282
283
|
for (let i = 0; i < onRequests.length; i++) {
|
|
283
|
-
let result =
|
|
284
|
-
if (result
|
|
284
|
+
let result = onRequests[i](context);
|
|
285
|
+
if (typeof result?.then === "function") {
|
|
286
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
287
|
+
result = await result;
|
|
288
|
+
}
|
|
285
289
|
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
286
|
-
if (armedAbort(
|
|
290
|
+
if (armedAbort(context)) return require_handler_utils.emptyResponse.clone();
|
|
287
291
|
if (result !== void 0) {
|
|
288
292
|
const response = await mapResponse(result, context.set, context);
|
|
289
293
|
afterResponse?.(context);
|
package/dist/handler/fetch.mjs
CHANGED
|
@@ -133,11 +133,10 @@ function createFetchHandler(app) {
|
|
|
133
133
|
return (context["~sig"] = request.signal).aborted;
|
|
134
134
|
};
|
|
135
135
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* never reaches it.
|
|
136
|
+
* Peek after each callback. The actual await branch arms deferred requests;
|
|
137
|
+
* immediate callbacks must not materialize a signal just for this check.
|
|
139
138
|
*/
|
|
140
|
-
const armedAbort = (
|
|
139
|
+
const armedAbort = (context) => abortSignal && context["~sig"]?.aborted === true;
|
|
141
140
|
const baseMapResponse = (app["~config"]?.adapter ?? defaultAdapter).response.map;
|
|
142
141
|
const mapResponseHooks = hook?.mapResponse;
|
|
143
142
|
const mapResponse = mapResponseHooks?.length ? (response, set, context) => {
|
|
@@ -147,7 +146,7 @@ function createFetchHandler(app) {
|
|
|
147
146
|
const run = (i) => {
|
|
148
147
|
for (; i < mapResponseHooks.length; i++) {
|
|
149
148
|
const result = mapResponseHooks[i](context);
|
|
150
|
-
if (result
|
|
149
|
+
if (typeof result?.then === "function") return Promise.resolve(result).then((resolved) => {
|
|
151
150
|
if (resolved !== void 0) return baseMapResponse(resolved, set, request, true);
|
|
152
151
|
return run(i + 1);
|
|
153
152
|
});
|
|
@@ -215,7 +214,6 @@ function createFetchHandler(app) {
|
|
|
215
214
|
app["~finalizeError"] = (context, error) => finalizeError(context, handleError, afterResponse, error);
|
|
216
215
|
if (traceRequestPhase) {
|
|
217
216
|
const onRequests = hook?.request ?? [];
|
|
218
|
-
const asyncIndexes = onRequests.length ? getAsyncIndexes(onRequests) : void 0;
|
|
219
217
|
return async (request, server) => {
|
|
220
218
|
const context = new Context(request);
|
|
221
219
|
materializeSetHeaders(context.set);
|
|
@@ -244,10 +242,14 @@ function createFetchHandler(app) {
|
|
|
244
242
|
name: onRequests[i].name || "anonymous",
|
|
245
243
|
begin: performance.now()
|
|
246
244
|
});
|
|
247
|
-
|
|
245
|
+
let result = onRequests[i](context);
|
|
246
|
+
if (typeof result?.then === "function") {
|
|
247
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
248
|
+
result = await result;
|
|
249
|
+
}
|
|
248
250
|
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
249
251
|
for (let i = 0; i < traceLength; i++) endReports[i]?.();
|
|
250
|
-
if (armedAbort(
|
|
252
|
+
if (armedAbort(context)) {
|
|
251
253
|
for (let j = 0; j < traceLength; j++) trace[j].r(requestReports[j]);
|
|
252
254
|
return emptyResponse.clone();
|
|
253
255
|
}
|
|
@@ -268,8 +270,7 @@ function createFetchHandler(app) {
|
|
|
268
270
|
}
|
|
269
271
|
if (hook?.request) {
|
|
270
272
|
const onRequests = hook.request;
|
|
271
|
-
|
|
272
|
-
if (asyncIndexes) return async (request, server) => {
|
|
273
|
+
if (getAsyncIndexes(onRequests)) return async (request, server) => {
|
|
273
274
|
const context = new Context(request);
|
|
274
275
|
materializeSetHeaders(context.set);
|
|
275
276
|
if (armEager(request, context)) return emptyResponse.clone();
|
|
@@ -277,10 +278,13 @@ function createFetchHandler(app) {
|
|
|
277
278
|
context.server = server ?? null;
|
|
278
279
|
try {
|
|
279
280
|
for (let i = 0; i < onRequests.length; i++) {
|
|
280
|
-
let result =
|
|
281
|
-
if (result
|
|
281
|
+
let result = onRequests[i](context);
|
|
282
|
+
if (typeof result?.then === "function") {
|
|
283
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
284
|
+
result = await result;
|
|
285
|
+
}
|
|
282
286
|
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
283
|
-
if (armedAbort(
|
|
287
|
+
if (armedAbort(context)) return emptyResponse.clone();
|
|
284
288
|
if (result !== void 0) {
|
|
285
289
|
const response = await mapResponse(result, context.set, context);
|
|
286
290
|
afterResponse?.(context);
|
package/dist/package.js
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -100,6 +100,8 @@ declare const resolveEntryModuleKind: (entry: string) => "cjs" | "esm";
|
|
|
100
100
|
interface StubPlan {
|
|
101
101
|
/** Stub the internal handler codegen module. */
|
|
102
102
|
jit: boolean;
|
|
103
|
+
/** Omit the static-clone resolver when no captured handler aliases scl. */
|
|
104
|
+
staticClone: boolean;
|
|
103
105
|
/** Stub internal WS route builders when the app declares no WS routes. */
|
|
104
106
|
ws: boolean;
|
|
105
107
|
/**
|
package/dist/plugin/aot/core.js
CHANGED
|
@@ -44,6 +44,7 @@ const resolveEntryModuleKind = (entry) => {
|
|
|
44
44
|
};
|
|
45
45
|
const NO_STUB = {
|
|
46
46
|
jit: false,
|
|
47
|
+
staticClone: false,
|
|
47
48
|
ws: false,
|
|
48
49
|
reconstruct: false,
|
|
49
50
|
cookie: false,
|
|
@@ -81,6 +82,7 @@ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree,
|
|
|
81
82
|
return {
|
|
82
83
|
plan: {
|
|
83
84
|
jit,
|
|
85
|
+
staticClone: jit && !aliases.has("scl"),
|
|
84
86
|
ws: !hasWS,
|
|
85
87
|
reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
|
|
86
88
|
cookie: jit && !aliases.has("cc") && !wsCookie,
|
|
@@ -129,6 +131,10 @@ function makeIsElysiaModule(elysiaRoot) {
|
|
|
129
131
|
const rewriteIsProductionCalls = (code) => code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
|
|
130
132
|
const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={name:'bun',runtime:'bun',isWebStandard:true,parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
|
|
131
133
|
const STUB_SOURCES = {
|
|
134
|
+
staticClone: [{
|
|
135
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]static-clone-resolver\.(m?js|ts)$/,
|
|
136
|
+
source: `export const staticCloneResolver = undefined\n`
|
|
137
|
+
}],
|
|
132
138
|
jit: [{
|
|
133
139
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]jit\.(m?js|ts)$/,
|
|
134
140
|
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
|
package/dist/plugin/aot/core.mjs
CHANGED
|
@@ -42,6 +42,7 @@ const resolveEntryModuleKind = (entry) => {
|
|
|
42
42
|
};
|
|
43
43
|
const NO_STUB = {
|
|
44
44
|
jit: false,
|
|
45
|
+
staticClone: false,
|
|
45
46
|
ws: false,
|
|
46
47
|
reconstruct: false,
|
|
47
48
|
cookie: false,
|
|
@@ -79,6 +80,7 @@ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree,
|
|
|
79
80
|
return {
|
|
80
81
|
plan: {
|
|
81
82
|
jit,
|
|
83
|
+
staticClone: jit && !aliases.has("scl"),
|
|
82
84
|
ws: !hasWS,
|
|
83
85
|
reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
|
|
84
86
|
cookie: jit && !aliases.has("cc") && !wsCookie,
|
|
@@ -127,6 +129,10 @@ function makeIsElysiaModule(elysiaRoot) {
|
|
|
127
129
|
const rewriteIsProductionCalls = (code) => code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
|
|
128
130
|
const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={name:'bun',runtime:'bun',isWebStandard:true,parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
|
|
129
131
|
const STUB_SOURCES = {
|
|
132
|
+
staticClone: [{
|
|
133
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]static-clone-resolver\.(m?js|ts)$/,
|
|
134
|
+
source: `export const staticCloneResolver = undefined\n`
|
|
135
|
+
}],
|
|
130
136
|
jit: [{
|
|
131
137
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]jit\.(m?js|ts)$/,
|
|
132
138
|
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
|