elysia 2.0.0-beta.2 → 2.0.0-beta.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/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- 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 +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_universal_file = require('../../universal/file.js');
|
|
2
3
|
const require_utils = require('../../utils.js');
|
|
3
4
|
const require_type_constants = require('../../type/constants.js');
|
|
4
5
|
const require_adapter_skip_clone = require('../../adapter/skip-clone.js');
|
|
@@ -10,7 +11,6 @@ const require_adapter_origin = require('../../adapter/origin.js');
|
|
|
10
11
|
const require_compile_lexer = require('../lexer.js');
|
|
11
12
|
|
|
12
13
|
//#region src/compile/handler/utils.ts
|
|
13
|
-
const childName = (fn) => fn?.name && typeof fn.name === "string" ? fn.name : "anonymous";
|
|
14
14
|
const noTrace = {
|
|
15
15
|
begin: "",
|
|
16
16
|
end: () => ""
|
|
@@ -23,6 +23,16 @@ function cloneResponse(r) {
|
|
|
23
23
|
}
|
|
24
24
|
return r;
|
|
25
25
|
}
|
|
26
|
+
function cloneStaticValue(value) {
|
|
27
|
+
if (require_universal_file.ElysiaFile.isElysiaFile(value)) return value;
|
|
28
|
+
try {
|
|
29
|
+
const cloned = structuredClone(value);
|
|
30
|
+
if (Object.getPrototypeOf(value) === require_error.ElysiaStatus.prototype) Object.setPrototypeOf(cloned, require_error.ElysiaStatus.prototype);
|
|
31
|
+
return cloned;
|
|
32
|
+
} catch {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
26
36
|
function hasRequestBody(request) {
|
|
27
37
|
const length = request.headers.get("content-length");
|
|
28
38
|
if (length !== null) return length !== "0";
|
|
@@ -42,28 +52,102 @@ function armEntryAbort(context) {
|
|
|
42
52
|
if (context.request === require_adapter_origin.origin.request) return false;
|
|
43
53
|
return (context["~sig"] = context.request.signal).aborted;
|
|
44
54
|
}
|
|
45
|
-
const trace = (report, fn) => report?.resolveChild(
|
|
55
|
+
const trace = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
|
|
46
56
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
47
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report]) => {
|
|
57
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report, arm]) => {
|
|
48
58
|
const t = trace(report, fn);
|
|
49
|
-
const
|
|
50
|
-
const call = guard ? `_tf=tf${at(i)}(c)\n${guard}` : `${Await(fn)}tf${at(i)}(c)\n`;
|
|
59
|
+
const call = isAsync ? awaitSite(`tf${at(i)}(c)`, fn, isAsync, "_tf", arm) : `tf${at(i)}(c)\n`;
|
|
51
60
|
return t.begin + call + t.end();
|
|
52
61
|
});
|
|
53
62
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
54
63
|
function extractDeriveKeys(fn) {
|
|
55
64
|
const cached = deriveKeyCache.get(fn);
|
|
56
65
|
if (cached !== void 0) return cached;
|
|
57
|
-
|
|
66
|
+
let src;
|
|
67
|
+
try {
|
|
68
|
+
src = Function.prototype.toString.call(fn);
|
|
69
|
+
} catch {
|
|
70
|
+
src = void 0;
|
|
71
|
+
}
|
|
72
|
+
const result = src === void 0 || src.includes("[native code]") || src.includes("...") ? null : returnedObjectKeys(src);
|
|
58
73
|
deriveKeyCache.set(fn, result);
|
|
59
74
|
return result;
|
|
60
75
|
}
|
|
76
|
+
function returnedObjectKeys(src) {
|
|
77
|
+
const tokens = require_compile_lexer.scanTokens(src);
|
|
78
|
+
if (!tokens) return null;
|
|
79
|
+
const is = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
|
|
80
|
+
const blank = (i) => {
|
|
81
|
+
const token = tokens[i];
|
|
82
|
+
return /^[ \t\n\r]*$/.test(src.slice(token.at + token.value.length + (token.k === "s" ? 2 : 0), tokens[i + 1]?.at));
|
|
83
|
+
};
|
|
84
|
+
let open = -1;
|
|
85
|
+
let parens = 0;
|
|
86
|
+
let depth = 0;
|
|
87
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
88
|
+
const { k, value } = tokens[i];
|
|
89
|
+
if (k === "i") {
|
|
90
|
+
if (depth === 0 && value === "function") break;
|
|
91
|
+
} else if (k !== "p") continue;
|
|
92
|
+
else if (value === "(" || value === "[" || value === "{") depth++;
|
|
93
|
+
else if (value === ")" || value === "]" || value === "}") depth--;
|
|
94
|
+
else if (depth === 0 && value === "=>") {
|
|
95
|
+
if (!blank(i)) return null;
|
|
96
|
+
if (is(i + 1, "(")) {
|
|
97
|
+
if (!blank(i + 1) || !is(i + 2, "{")) return null;
|
|
98
|
+
open = i + 2;
|
|
99
|
+
parens = 1;
|
|
100
|
+
} else if (!is(i + 1, "{")) return null;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (open === -1) {
|
|
105
|
+
let at = -1;
|
|
106
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
107
|
+
const { k, value } = tokens[i];
|
|
108
|
+
if (k !== "i") continue;
|
|
109
|
+
if (value === "return") {
|
|
110
|
+
if (at !== -1) return null;
|
|
111
|
+
at = i;
|
|
112
|
+
} else if (value.includes("return") && /[^\w$]/.test(value)) return null;
|
|
113
|
+
}
|
|
114
|
+
if (at === -1) return null;
|
|
115
|
+
for (; blank(at) && is(at + 1, "("); at++) parens++;
|
|
116
|
+
if (!blank(at) || !is(at + 1, "{")) return null;
|
|
117
|
+
open = at + 1;
|
|
118
|
+
}
|
|
119
|
+
const keys = [];
|
|
120
|
+
let i = open + 1;
|
|
121
|
+
while (!is(i, "}")) {
|
|
122
|
+
const key = tokens[i];
|
|
123
|
+
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !blank(i) || !is(i + 1, ":")) return null;
|
|
124
|
+
keys.push(key.value);
|
|
125
|
+
for (depth = 0, i += 2;; i++) {
|
|
126
|
+
const token = tokens[i];
|
|
127
|
+
if (!token) return null;
|
|
128
|
+
if (token.k !== "p") continue;
|
|
129
|
+
const { value } = token;
|
|
130
|
+
if (value === "(" || value === "[" || value === "{") depth++;
|
|
131
|
+
else if (value === ")" || value === "]" || value === "}") {
|
|
132
|
+
if (depth === 0) {
|
|
133
|
+
if (value !== "}") return null;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
depth--;
|
|
137
|
+
} else if (value === "," && depth === 0) break;
|
|
138
|
+
}
|
|
139
|
+
if (is(i, ",")) i++;
|
|
140
|
+
}
|
|
141
|
+
for (; parens; parens--) if (!is(++i, ")")) return null;
|
|
142
|
+
return i + 1 === tokens.length || is(i + 1, ";") || is(i + 1, "}") ? keys : null;
|
|
143
|
+
}
|
|
61
144
|
function replaceDeriveContext(context, derivative) {
|
|
62
145
|
const next = Object.create(Object.getPrototypeOf(context));
|
|
63
|
-
|
|
146
|
+
require_utils.assignOwn(next, derivative);
|
|
64
147
|
next.request = context.request;
|
|
65
148
|
next["~sig"] = context["~sig"];
|
|
66
149
|
next["~afterResponse"] = context["~afterResponse"];
|
|
150
|
+
next["~dispose"] = context["~dispose"];
|
|
67
151
|
next.store = context.store;
|
|
68
152
|
next.set = context.set;
|
|
69
153
|
next.body = context.body;
|
|
@@ -83,21 +167,19 @@ function replaceDeriveContext(context, derivative) {
|
|
|
83
167
|
next.redirect = context.redirect;
|
|
84
168
|
return next;
|
|
85
169
|
}
|
|
86
|
-
function deriveModeQueues(entries) {
|
|
87
|
-
if (!entries?.length) return;
|
|
88
|
-
const queues = /* @__PURE__ */ new Map();
|
|
89
|
-
for (let i = 0; i < entries.length; i++) {
|
|
90
|
-
const entry = entries[i];
|
|
91
|
-
const fn = require_utils.deriveEntryFn(entry);
|
|
92
|
-
const queue = queues.get(fn);
|
|
93
|
-
const mode = require_utils.isMapDeriveEntry(entry);
|
|
94
|
-
if (queue) queue.push(mode);
|
|
95
|
-
else queues.set(fn, [mode]);
|
|
96
|
-
}
|
|
97
|
-
return queues;
|
|
98
|
-
}
|
|
99
170
|
function deriveModes(hooks, entries) {
|
|
100
|
-
|
|
171
|
+
let queues;
|
|
172
|
+
if (entries?.length) {
|
|
173
|
+
queues = /* @__PURE__ */ new Map();
|
|
174
|
+
for (let i = 0; i < entries.length; i++) {
|
|
175
|
+
const entry = entries[i];
|
|
176
|
+
const fn = require_utils.deriveEntryFn(entry);
|
|
177
|
+
const queue = queues.get(fn);
|
|
178
|
+
const mode = require_utils.isMapDeriveEntry(entry);
|
|
179
|
+
if (queue) queue.push(mode);
|
|
180
|
+
else queues.set(fn, [mode]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
101
183
|
if (!queues) return;
|
|
102
184
|
let found = false;
|
|
103
185
|
const modes = Array(hooks.length);
|
|
@@ -110,236 +192,39 @@ function deriveModes(hooks, entries) {
|
|
|
110
192
|
}
|
|
111
193
|
return found ? modes : void 0;
|
|
112
194
|
}
|
|
113
|
-
function
|
|
114
|
-
let src;
|
|
115
|
-
try {
|
|
116
|
-
src = Function.prototype.toString.call(fn);
|
|
117
|
-
} catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
if (src.includes("[native code]")) return null;
|
|
121
|
-
if (src.includes("...")) return null;
|
|
122
|
-
const objStart = findReturnedObjectStart(src);
|
|
123
|
-
if (objStart === -1) return null;
|
|
124
|
-
return scanObjectLiteralKeys(src, objStart);
|
|
125
|
-
}
|
|
126
|
-
function findReturnedObjectStart(src) {
|
|
127
|
-
const arrow = topLevelArrowIndex(src);
|
|
128
|
-
if (arrow !== -1) {
|
|
129
|
-
let i = arrow + 2;
|
|
130
|
-
while (i < src.length && require_compile_lexer.isSpace(src[i])) i++;
|
|
131
|
-
if (src[i] === "(") {
|
|
132
|
-
let j = i + 1;
|
|
133
|
-
while (j < src.length && require_compile_lexer.isSpace(src[j])) j++;
|
|
134
|
-
if (src[j] === "{") return j;
|
|
135
|
-
return -1;
|
|
136
|
-
}
|
|
137
|
-
if (src[i] !== "{") return -1;
|
|
138
|
-
}
|
|
139
|
-
const { count: returns, firstIndex: idx } = scanReturns(src);
|
|
140
|
-
if (returns !== 1) return -1;
|
|
141
|
-
if (idx === -1) return -1;
|
|
142
|
-
let i = idx + 6;
|
|
143
|
-
while (i < src.length && require_compile_lexer.isSpace(src[i])) i++;
|
|
144
|
-
while (i < src.length && src[i] === "(") {
|
|
145
|
-
i++;
|
|
146
|
-
while (i < src.length && require_compile_lexer.isSpace(src[i])) i++;
|
|
147
|
-
}
|
|
148
|
-
return src[i] === "{" ? i : -1;
|
|
149
|
-
}
|
|
150
|
-
function topLevelArrowIndex(src) {
|
|
151
|
-
let depth = 0;
|
|
152
|
-
for (let i = 0; i < src.length;) {
|
|
153
|
-
const ch = src[i];
|
|
154
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
155
|
-
i = require_compile_lexer.skipString(src, i);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
159
|
-
const nl = src.indexOf("\n", i);
|
|
160
|
-
if (nl === -1) return -1;
|
|
161
|
-
i = nl + 1;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
165
|
-
const end = src.indexOf("*/", i);
|
|
166
|
-
if (end === -1) return -1;
|
|
167
|
-
i = end + 2;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (depth === 0 && ch === "f" && src.startsWith("function", i) && !require_compile_lexer.isIdentChar(src[i - 1] ?? " ") && !require_compile_lexer.isIdentChar(src[i + 8] ?? " ")) return -1;
|
|
171
|
-
if (ch === "(" || ch === "[" || ch === "{") {
|
|
172
|
-
depth++;
|
|
173
|
-
i++;
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (ch === ")" || ch === "]" || ch === "}") {
|
|
177
|
-
depth--;
|
|
178
|
-
i++;
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (depth === 0 && ch === "=" && src[i + 1] === ">") return i;
|
|
182
|
-
i++;
|
|
183
|
-
}
|
|
184
|
-
return -1;
|
|
185
|
-
}
|
|
186
|
-
function scanReturns(src) {
|
|
187
|
-
let count = 0;
|
|
188
|
-
let firstIndex = -1;
|
|
189
|
-
for (let i = 0; i < src.length;) {
|
|
190
|
-
const ch = src[i];
|
|
191
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
192
|
-
i = require_compile_lexer.skipString(src, i);
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
196
|
-
const nl = src.indexOf("\n", i);
|
|
197
|
-
if (nl === -1) break;
|
|
198
|
-
i = nl;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
202
|
-
const end = src.indexOf("*/", i);
|
|
203
|
-
if (end === -1) break;
|
|
204
|
-
i = end + 2;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (ch === "r" && src.startsWith("return", i) && !require_compile_lexer.isIdentChar(src[i - 1] ?? " ") && !require_compile_lexer.isIdentChar(src[i + 6] ?? " ")) {
|
|
208
|
-
if (firstIndex === -1) firstIndex = i;
|
|
209
|
-
count++;
|
|
210
|
-
i += 6;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
i++;
|
|
214
|
-
}
|
|
215
|
-
return {
|
|
216
|
-
count,
|
|
217
|
-
firstIndex
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function scanObjectLiteralKeys(src, open) {
|
|
221
|
-
const keys = [];
|
|
222
|
-
let i = open + 1;
|
|
223
|
-
let expectKey = true;
|
|
224
|
-
while (i < src.length) {
|
|
225
|
-
const ch = src[i];
|
|
226
|
-
if (require_compile_lexer.isSpace(ch)) {
|
|
227
|
-
i++;
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
231
|
-
const nl = src.indexOf("\n", i);
|
|
232
|
-
if (nl === -1) return null;
|
|
233
|
-
i = nl + 1;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
237
|
-
const end = src.indexOf("*/", i);
|
|
238
|
-
if (end === -1) return null;
|
|
239
|
-
i = end + 2;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (ch === "}") return keys;
|
|
243
|
-
if (expectKey) {
|
|
244
|
-
if (ch === "[") return null;
|
|
245
|
-
let key;
|
|
246
|
-
if (ch === "\"" || ch === "'") {
|
|
247
|
-
const end = require_compile_lexer.skipString(src, i);
|
|
248
|
-
key = src.slice(i + 1, end - 1);
|
|
249
|
-
if (key.includes("\\")) return null;
|
|
250
|
-
i = end;
|
|
251
|
-
} else if (require_compile_lexer.isIdentChar(ch) && !(ch >= "0" && ch <= "9")) {
|
|
252
|
-
const start = i;
|
|
253
|
-
while (i < src.length && require_compile_lexer.isIdentChar(src[i])) i++;
|
|
254
|
-
key = src.slice(start, i);
|
|
255
|
-
} else return null;
|
|
256
|
-
let j = i;
|
|
257
|
-
while (j < src.length && require_compile_lexer.isSpace(src[j])) j++;
|
|
258
|
-
if (src[j] !== ":") return null;
|
|
259
|
-
keys.push(key);
|
|
260
|
-
i = j + 1;
|
|
261
|
-
i = skipValue(src, i);
|
|
262
|
-
if (i === -1) return null;
|
|
263
|
-
expectKey = false;
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (ch === ",") {
|
|
267
|
-
expectKey = true;
|
|
268
|
-
i++;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
function skipValue(src, i) {
|
|
276
|
-
let depth = 0;
|
|
277
|
-
while (i < src.length) {
|
|
278
|
-
const ch = src[i];
|
|
279
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
280
|
-
i = require_compile_lexer.skipString(src, i);
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
284
|
-
const nl = src.indexOf("\n", i);
|
|
285
|
-
if (nl === -1) return -1;
|
|
286
|
-
i = nl + 1;
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
290
|
-
const end = src.indexOf("*/", i);
|
|
291
|
-
if (end === -1) return -1;
|
|
292
|
-
i = end + 2;
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
if (ch === "{" || ch === "(" || ch === "[") {
|
|
296
|
-
depth++;
|
|
297
|
-
i++;
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
if (ch === "}" || ch === ")" || ch === "]") {
|
|
301
|
-
if (depth === 0) {
|
|
302
|
-
if (ch === "}") return i;
|
|
303
|
-
return -1;
|
|
304
|
-
}
|
|
305
|
-
depth--;
|
|
306
|
-
i++;
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (ch === "," && depth === 0) return i;
|
|
310
|
-
i++;
|
|
311
|
-
}
|
|
312
|
-
return -1;
|
|
313
|
-
}
|
|
314
|
-
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
195
|
+
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
|
|
315
196
|
const hooks = toArray(_hooks);
|
|
316
197
|
const modes = deriveModes(hooks, derive);
|
|
198
|
+
const tail = asyncTail(isAsync);
|
|
317
199
|
let code = "";
|
|
318
200
|
let depth = 0;
|
|
319
201
|
let needsEs = false;
|
|
320
202
|
for (let i = 0; i < hooks.length; i++) {
|
|
321
203
|
const fn = hooks[i];
|
|
322
|
-
|
|
323
|
-
|
|
204
|
+
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}_r===undefined` : void 0;
|
|
205
|
+
if (tail) code += tailStage(tail, guard);
|
|
206
|
+
else if (guard) {
|
|
207
|
+
code += `if(${guard}){\n`;
|
|
324
208
|
depth++;
|
|
325
209
|
}
|
|
326
210
|
const t = trace(report, fn);
|
|
327
211
|
code += t.begin;
|
|
328
|
-
code += `
|
|
329
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
212
|
+
code += awaitSite(`bf${at(i)}(c)`, fn, isAsync, "tmp", arm);
|
|
330
213
|
if (modes?.[i] !== void 0) {
|
|
331
214
|
needsEs = true;
|
|
215
|
+
link(require_handler_utils.registerDeriveDisposable, "dsp");
|
|
332
216
|
if (modes[i]) {
|
|
333
217
|
link(replaceDeriveContext, "rdc");
|
|
334
|
-
code += "if(tmp instanceof es)_r=tmp\nelse if(tmp){if(typeof tmp==='object'||typeof tmp==='function')c=rdc(c,tmp);tmp=undefined}\n";
|
|
218
|
+
code += "if(tmp instanceof es)_r=tmp\nelse if(tmp){if(typeof tmp==='object'||typeof tmp==='function'){const _pc=c;c=rdc(c,tmp);for(const _k of Object.keys(tmp))dsp(c,c[_k],_pc)}tmp=undefined}\n";
|
|
335
219
|
} else {
|
|
336
220
|
const keys = extractDeriveKeys(fn);
|
|
337
|
-
const merge = keys && keys.length ? keys.map((k) => `
|
|
221
|
+
const merge = !!keys && !!keys.length && !keys.includes("__proto__") ? keys.map((k) => `_v=tmp[${JSON.stringify(k)}];dsp(c,_v);c[${JSON.stringify(k)}]=_v`).join(";") : "if(Object.hasOwn(tmp,'__proto__')){for(const _k of Object.keys(tmp))dsp(c,tmp[_k]);Object.defineProperties(c,Object.getOwnPropertyDescriptors(tmp))}else{_v=Object.assign({},tmp);for(const _k of Reflect.ownKeys(_v)){dsp(c,_v[_k]);c[_k]=_v[_k]}}";
|
|
338
222
|
code += `if(tmp instanceof es)_r=tmp
|
|
339
223
|
else if(tmp){${merge};tmp=undefined}\n`;
|
|
340
224
|
}
|
|
341
225
|
} else code += "if(tmp!==undefined)_r=tmp\n";
|
|
342
226
|
code += t.end("tmp");
|
|
227
|
+
if (tail) code += "}\n";
|
|
343
228
|
}
|
|
344
229
|
code += "}".repeat(depth);
|
|
345
230
|
if (needsEs) link(require_error.ElysiaStatus, "es");
|
|
@@ -372,7 +257,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
372
257
|
if (!first && abort && context["~sig"]?.aborted) return;
|
|
373
258
|
first = false;
|
|
374
259
|
let result = values[j](context);
|
|
375
|
-
if (result
|
|
260
|
+
if (typeof result?.then === "function") {
|
|
376
261
|
result = await result;
|
|
377
262
|
if (abort) context["~sig"] ??= context.request.signal;
|
|
378
263
|
}
|
|
@@ -380,52 +265,58 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
380
265
|
}
|
|
381
266
|
}
|
|
382
267
|
}
|
|
383
|
-
function mapChainHook(
|
|
268
|
+
function mapChainHook(_hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
269
|
+
const hooks = toArray(_hooks);
|
|
270
|
+
const tail = asyncTail(isAsync);
|
|
384
271
|
let code = "";
|
|
385
272
|
let depth = 0;
|
|
386
273
|
for (let i = 0; i < hooks.length; i++) {
|
|
387
274
|
const fn = hooks[i];
|
|
388
|
-
|
|
389
|
-
|
|
275
|
+
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}tmp===undefined` : void 0;
|
|
276
|
+
if (tail) code += tailStage(tail, guard);
|
|
277
|
+
else if (guard) {
|
|
278
|
+
code += `if(${guard}){\n`;
|
|
390
279
|
depth++;
|
|
391
280
|
}
|
|
392
281
|
const t = trace(report, fn);
|
|
393
282
|
code += t.begin;
|
|
394
|
-
code +=
|
|
395
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
283
|
+
code += awaitSite(`${prefix}${at(i)}(c)`, fn, isAsync, "tmp", arm);
|
|
396
284
|
code += t.end("tmp");
|
|
285
|
+
if (tail) code += "}\n";
|
|
397
286
|
}
|
|
398
287
|
code += "}".repeat(depth);
|
|
399
|
-
code += `if(tmp!==undefined)_r=c.responseValue=tmp\n
|
|
288
|
+
code += tailPlain(isAsync, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
400
289
|
return code;
|
|
401
290
|
}
|
|
402
|
-
const mapAfterHandle = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard);
|
|
403
|
-
const mapMapResponse = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard);
|
|
404
291
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
405
292
|
const t = trace(report, fn);
|
|
406
|
-
const call = require_compile_utils.isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(_ar
|
|
407
|
-
return `try{
|
|
293
|
+
const call = require_compile_utils.isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
294
|
+
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
408
295
|
});
|
|
409
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync]) => {
|
|
296
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync, arm]) => {
|
|
410
297
|
link(mapResponse, "rm");
|
|
411
298
|
link(require_handler_error.adoptErrorType, "aet");
|
|
412
|
-
return `
|
|
299
|
+
return awaitSite(`er${at(i)}(c)`, 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`;
|
|
413
300
|
});
|
|
414
301
|
function map(map) {
|
|
415
|
-
return function(event, rest, abortGuard) {
|
|
302
|
+
return function(event, rest, abortGuard, tail) {
|
|
416
303
|
if (Array.isArray(event)) {
|
|
417
304
|
let code = "";
|
|
418
305
|
let depth = 0;
|
|
419
306
|
for (let i = 0; i < event.length; i++) {
|
|
420
|
-
|
|
421
|
-
|
|
307
|
+
const guard = i > 0 && abortGuard ? `!${abortGuard}` : void 0;
|
|
308
|
+
if (tail) code += tailStage(tail, guard);
|
|
309
|
+
else if (guard) {
|
|
310
|
+
code += `if(${guard}){\n`;
|
|
422
311
|
depth++;
|
|
423
312
|
}
|
|
424
313
|
code += map(i, event[i], rest);
|
|
314
|
+
if (tail) code += "}\n";
|
|
425
315
|
}
|
|
426
316
|
code += "}".repeat(depth);
|
|
427
317
|
return code;
|
|
428
|
-
} else return map(void 0, event, rest);
|
|
318
|
+
} else if (tail) return tailStage(tail) + map(void 0, event, rest) + "}\n";
|
|
319
|
+
else return map(void 0, event, rest);
|
|
429
320
|
};
|
|
430
321
|
}
|
|
431
322
|
const at = (index) => index === void 0 ? "" : `[${index}]`;
|
|
@@ -495,23 +386,38 @@ function getQueryParseChannels(querySchema) {
|
|
|
495
386
|
queryParseChannelsCache.set(querySchema, result);
|
|
496
387
|
return result ?? void 0;
|
|
497
388
|
}
|
|
498
|
-
const
|
|
499
|
-
|
|
389
|
+
const asyncTail = (mode) => typeof mode === "object" && mode.async ? mode : void 0;
|
|
390
|
+
function awaitSite(call, fn, isAsync, target, arm = "") {
|
|
391
|
+
if (typeof isAsync !== "object") return `${target}=${call}\n${awaitGuard(fn, isAsync, target, arm)}`;
|
|
392
|
+
const k = isAsync.n++;
|
|
393
|
+
isAsync.sites.push(`${isAsync.e ? "e:" : ""}${target}=${call}`);
|
|
394
|
+
return isAsync.async ? `${target}=_rk===${k}?_y:${call}\nif(_rk===${k}||typeof ${target}?.then==='function'){${arm ? `;${arm}\n` : ""}${target}=await ${target}}\n` : `${target}=${call}\nif(typeof ${target}?.then==='function')return _t(c,${k},${target},${isAsync.r ? "_r" : "undefined"},${isAsync.e ? "e" : "undefined"}${isAsync.live})\n`;
|
|
395
|
+
}
|
|
396
|
+
const tailStage = (mode, guard) => `if(_rk<=${mode.n}${guard ? `&&(_rk===${mode.n}||${guard})` : ""}){\n`;
|
|
397
|
+
const tailPlain = (mode, code) => !code || !asyncTail(mode) ? code : mode.n ? `if(_rk<${mode.n}){\n${code}}\n` : "";
|
|
398
|
+
function awaitGuard(fn, isAsync, target, arm = "") {
|
|
399
|
+
if (!isAsync) return "";
|
|
400
|
+
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
401
|
+
return require_compile_utils.isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
402
|
+
}
|
|
500
403
|
|
|
501
404
|
//#endregion
|
|
502
405
|
exports.armEntryAbort = armEntryAbort;
|
|
406
|
+
exports.asyncTail = asyncTail;
|
|
407
|
+
exports.awaitGuard = awaitGuard;
|
|
408
|
+
exports.awaitSite = awaitSite;
|
|
503
409
|
exports.cloneResponse = cloneResponse;
|
|
410
|
+
exports.cloneStaticValue = cloneStaticValue;
|
|
504
411
|
exports.deriveModes = deriveModes;
|
|
505
|
-
exports.emptyResponse = require_handler_utils.emptyResponse;
|
|
506
|
-
exports.extractDeriveKeys = extractDeriveKeys;
|
|
507
412
|
exports.getQueryParseChannels = getQueryParseChannels;
|
|
508
413
|
exports.hasRequestBody = hasRequestBody;
|
|
509
|
-
exports.mapAfterHandle = mapAfterHandle;
|
|
510
414
|
exports.mapAfterResponse = mapAfterResponse;
|
|
511
415
|
exports.mapBeforeHandle = mapBeforeHandle;
|
|
416
|
+
exports.mapChainHook = mapChainHook;
|
|
512
417
|
exports.mapError = mapError;
|
|
513
|
-
exports.mapMapResponse = mapMapResponse;
|
|
514
418
|
exports.mapTransform = mapTransform;
|
|
515
419
|
exports.replaceDeriveContext = replaceDeriveContext;
|
|
516
420
|
exports.runBeforeHandlePrefix = runBeforeHandlePrefix;
|
|
517
|
-
exports.runBeforeHandlePrefixAsync = runBeforeHandlePrefixAsync;
|
|
421
|
+
exports.runBeforeHandlePrefixAsync = runBeforeHandlePrefixAsync;
|
|
422
|
+
exports.tailPlain = tailPlain;
|
|
423
|
+
exports.tailStage = tailStage;
|