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,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ElysiaFile } from "../../universal/file.mjs";
|
|
2
|
+
import { assignOwn, deriveEntryFn, isMapDeriveEntry } from "../../utils.mjs";
|
|
2
3
|
import { ELYSIA_TYPES } from "../../type/constants.mjs";
|
|
3
4
|
import { skipClone } from "../../adapter/skip-clone.mjs";
|
|
4
5
|
import { ElysiaStatus } from "../../error.mjs";
|
|
5
6
|
import { isAsyncFunction } from "../utils.mjs";
|
|
6
|
-
import {
|
|
7
|
+
import { registerDeriveDisposable } from "../../handler/utils.mjs";
|
|
7
8
|
import { adoptErrorType } from "../../handler/error.mjs";
|
|
8
9
|
import { origin } from "../../adapter/origin.mjs";
|
|
9
|
-
import {
|
|
10
|
+
import { scanTokens } from "../lexer.mjs";
|
|
10
11
|
|
|
11
12
|
//#region src/compile/handler/utils.ts
|
|
12
|
-
const childName = (fn) => fn?.name && typeof fn.name === "string" ? fn.name : "anonymous";
|
|
13
13
|
const noTrace = {
|
|
14
14
|
begin: "",
|
|
15
15
|
end: () => ""
|
|
@@ -22,6 +22,16 @@ function cloneResponse(r) {
|
|
|
22
22
|
}
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
|
+
function cloneStaticValue(value) {
|
|
26
|
+
if (ElysiaFile.isElysiaFile(value)) return value;
|
|
27
|
+
try {
|
|
28
|
+
const cloned = structuredClone(value);
|
|
29
|
+
if (Object.getPrototypeOf(value) === ElysiaStatus.prototype) Object.setPrototypeOf(cloned, ElysiaStatus.prototype);
|
|
30
|
+
return cloned;
|
|
31
|
+
} catch {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
function hasRequestBody(request) {
|
|
26
36
|
const length = request.headers.get("content-length");
|
|
27
37
|
if (length !== null) return length !== "0";
|
|
@@ -41,28 +51,102 @@ function armEntryAbort(context) {
|
|
|
41
51
|
if (context.request === origin.request) return false;
|
|
42
52
|
return (context["~sig"] = context.request.signal).aborted;
|
|
43
53
|
}
|
|
44
|
-
const trace = (report, fn) => report?.resolveChild(
|
|
54
|
+
const trace = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
|
|
45
55
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
46
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report]) => {
|
|
56
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [isAsync, report, arm]) => {
|
|
47
57
|
const t = trace(report, fn);
|
|
48
|
-
const
|
|
49
|
-
const call = guard ? `_tf=tf${at(i)}(c)\n${guard}` : `${Await(fn)}tf${at(i)}(c)\n`;
|
|
58
|
+
const call = isAsync ? awaitSite(`tf${at(i)}(c)`, fn, isAsync, "_tf", arm) : `tf${at(i)}(c)\n`;
|
|
50
59
|
return t.begin + call + t.end();
|
|
51
60
|
});
|
|
52
61
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
53
62
|
function extractDeriveKeys(fn) {
|
|
54
63
|
const cached = deriveKeyCache.get(fn);
|
|
55
64
|
if (cached !== void 0) return cached;
|
|
56
|
-
|
|
65
|
+
let src;
|
|
66
|
+
try {
|
|
67
|
+
src = Function.prototype.toString.call(fn);
|
|
68
|
+
} catch {
|
|
69
|
+
src = void 0;
|
|
70
|
+
}
|
|
71
|
+
const result = src === void 0 || src.includes("[native code]") || src.includes("...") ? null : returnedObjectKeys(src);
|
|
57
72
|
deriveKeyCache.set(fn, result);
|
|
58
73
|
return result;
|
|
59
74
|
}
|
|
75
|
+
function returnedObjectKeys(src) {
|
|
76
|
+
const tokens = scanTokens(src);
|
|
77
|
+
if (!tokens) return null;
|
|
78
|
+
const is = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
|
|
79
|
+
const blank = (i) => {
|
|
80
|
+
const token = tokens[i];
|
|
81
|
+
return /^[ \t\n\r]*$/.test(src.slice(token.at + token.value.length + (token.k === "s" ? 2 : 0), tokens[i + 1]?.at));
|
|
82
|
+
};
|
|
83
|
+
let open = -1;
|
|
84
|
+
let parens = 0;
|
|
85
|
+
let depth = 0;
|
|
86
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
87
|
+
const { k, value } = tokens[i];
|
|
88
|
+
if (k === "i") {
|
|
89
|
+
if (depth === 0 && value === "function") break;
|
|
90
|
+
} else if (k !== "p") continue;
|
|
91
|
+
else if (value === "(" || value === "[" || value === "{") depth++;
|
|
92
|
+
else if (value === ")" || value === "]" || value === "}") depth--;
|
|
93
|
+
else if (depth === 0 && value === "=>") {
|
|
94
|
+
if (!blank(i)) return null;
|
|
95
|
+
if (is(i + 1, "(")) {
|
|
96
|
+
if (!blank(i + 1) || !is(i + 2, "{")) return null;
|
|
97
|
+
open = i + 2;
|
|
98
|
+
parens = 1;
|
|
99
|
+
} else if (!is(i + 1, "{")) return null;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (open === -1) {
|
|
104
|
+
let at = -1;
|
|
105
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
106
|
+
const { k, value } = tokens[i];
|
|
107
|
+
if (k !== "i") continue;
|
|
108
|
+
if (value === "return") {
|
|
109
|
+
if (at !== -1) return null;
|
|
110
|
+
at = i;
|
|
111
|
+
} else if (value.includes("return") && /[^\w$]/.test(value)) return null;
|
|
112
|
+
}
|
|
113
|
+
if (at === -1) return null;
|
|
114
|
+
for (; blank(at) && is(at + 1, "("); at++) parens++;
|
|
115
|
+
if (!blank(at) || !is(at + 1, "{")) return null;
|
|
116
|
+
open = at + 1;
|
|
117
|
+
}
|
|
118
|
+
const keys = [];
|
|
119
|
+
let i = open + 1;
|
|
120
|
+
while (!is(i, "}")) {
|
|
121
|
+
const key = tokens[i];
|
|
122
|
+
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !blank(i) || !is(i + 1, ":")) return null;
|
|
123
|
+
keys.push(key.value);
|
|
124
|
+
for (depth = 0, i += 2;; i++) {
|
|
125
|
+
const token = tokens[i];
|
|
126
|
+
if (!token) return null;
|
|
127
|
+
if (token.k !== "p") continue;
|
|
128
|
+
const { value } = token;
|
|
129
|
+
if (value === "(" || value === "[" || value === "{") depth++;
|
|
130
|
+
else if (value === ")" || value === "]" || value === "}") {
|
|
131
|
+
if (depth === 0) {
|
|
132
|
+
if (value !== "}") return null;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
depth--;
|
|
136
|
+
} else if (value === "," && depth === 0) break;
|
|
137
|
+
}
|
|
138
|
+
if (is(i, ",")) i++;
|
|
139
|
+
}
|
|
140
|
+
for (; parens; parens--) if (!is(++i, ")")) return null;
|
|
141
|
+
return i + 1 === tokens.length || is(i + 1, ";") || is(i + 1, "}") ? keys : null;
|
|
142
|
+
}
|
|
60
143
|
function replaceDeriveContext(context, derivative) {
|
|
61
144
|
const next = Object.create(Object.getPrototypeOf(context));
|
|
62
|
-
|
|
145
|
+
assignOwn(next, derivative);
|
|
63
146
|
next.request = context.request;
|
|
64
147
|
next["~sig"] = context["~sig"];
|
|
65
148
|
next["~afterResponse"] = context["~afterResponse"];
|
|
149
|
+
next["~dispose"] = context["~dispose"];
|
|
66
150
|
next.store = context.store;
|
|
67
151
|
next.set = context.set;
|
|
68
152
|
next.body = context.body;
|
|
@@ -82,21 +166,19 @@ function replaceDeriveContext(context, derivative) {
|
|
|
82
166
|
next.redirect = context.redirect;
|
|
83
167
|
return next;
|
|
84
168
|
}
|
|
85
|
-
function deriveModeQueues(entries) {
|
|
86
|
-
if (!entries?.length) return;
|
|
87
|
-
const queues = /* @__PURE__ */ new Map();
|
|
88
|
-
for (let i = 0; i < entries.length; i++) {
|
|
89
|
-
const entry = entries[i];
|
|
90
|
-
const fn = deriveEntryFn(entry);
|
|
91
|
-
const queue = queues.get(fn);
|
|
92
|
-
const mode = isMapDeriveEntry(entry);
|
|
93
|
-
if (queue) queue.push(mode);
|
|
94
|
-
else queues.set(fn, [mode]);
|
|
95
|
-
}
|
|
96
|
-
return queues;
|
|
97
|
-
}
|
|
98
169
|
function deriveModes(hooks, entries) {
|
|
99
|
-
|
|
170
|
+
let queues;
|
|
171
|
+
if (entries?.length) {
|
|
172
|
+
queues = /* @__PURE__ */ new Map();
|
|
173
|
+
for (let i = 0; i < entries.length; i++) {
|
|
174
|
+
const entry = entries[i];
|
|
175
|
+
const fn = deriveEntryFn(entry);
|
|
176
|
+
const queue = queues.get(fn);
|
|
177
|
+
const mode = isMapDeriveEntry(entry);
|
|
178
|
+
if (queue) queue.push(mode);
|
|
179
|
+
else queues.set(fn, [mode]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
100
182
|
if (!queues) return;
|
|
101
183
|
let found = false;
|
|
102
184
|
const modes = Array(hooks.length);
|
|
@@ -109,236 +191,39 @@ function deriveModes(hooks, entries) {
|
|
|
109
191
|
}
|
|
110
192
|
return found ? modes : void 0;
|
|
111
193
|
}
|
|
112
|
-
function
|
|
113
|
-
let src;
|
|
114
|
-
try {
|
|
115
|
-
src = Function.prototype.toString.call(fn);
|
|
116
|
-
} catch {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
if (src.includes("[native code]")) return null;
|
|
120
|
-
if (src.includes("...")) return null;
|
|
121
|
-
const objStart = findReturnedObjectStart(src);
|
|
122
|
-
if (objStart === -1) return null;
|
|
123
|
-
return scanObjectLiteralKeys(src, objStart);
|
|
124
|
-
}
|
|
125
|
-
function findReturnedObjectStart(src) {
|
|
126
|
-
const arrow = topLevelArrowIndex(src);
|
|
127
|
-
if (arrow !== -1) {
|
|
128
|
-
let i = arrow + 2;
|
|
129
|
-
while (i < src.length && isSpace(src[i])) i++;
|
|
130
|
-
if (src[i] === "(") {
|
|
131
|
-
let j = i + 1;
|
|
132
|
-
while (j < src.length && isSpace(src[j])) j++;
|
|
133
|
-
if (src[j] === "{") return j;
|
|
134
|
-
return -1;
|
|
135
|
-
}
|
|
136
|
-
if (src[i] !== "{") return -1;
|
|
137
|
-
}
|
|
138
|
-
const { count: returns, firstIndex: idx } = scanReturns(src);
|
|
139
|
-
if (returns !== 1) return -1;
|
|
140
|
-
if (idx === -1) return -1;
|
|
141
|
-
let i = idx + 6;
|
|
142
|
-
while (i < src.length && isSpace(src[i])) i++;
|
|
143
|
-
while (i < src.length && src[i] === "(") {
|
|
144
|
-
i++;
|
|
145
|
-
while (i < src.length && isSpace(src[i])) i++;
|
|
146
|
-
}
|
|
147
|
-
return src[i] === "{" ? i : -1;
|
|
148
|
-
}
|
|
149
|
-
function topLevelArrowIndex(src) {
|
|
150
|
-
let depth = 0;
|
|
151
|
-
for (let i = 0; i < src.length;) {
|
|
152
|
-
const ch = src[i];
|
|
153
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
154
|
-
i = skipString(src, i);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
158
|
-
const nl = src.indexOf("\n", i);
|
|
159
|
-
if (nl === -1) return -1;
|
|
160
|
-
i = nl + 1;
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
164
|
-
const end = src.indexOf("*/", i);
|
|
165
|
-
if (end === -1) return -1;
|
|
166
|
-
i = end + 2;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (depth === 0 && ch === "f" && src.startsWith("function", i) && !isIdentChar(src[i - 1] ?? " ") && !isIdentChar(src[i + 8] ?? " ")) return -1;
|
|
170
|
-
if (ch === "(" || ch === "[" || ch === "{") {
|
|
171
|
-
depth++;
|
|
172
|
-
i++;
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if (ch === ")" || ch === "]" || ch === "}") {
|
|
176
|
-
depth--;
|
|
177
|
-
i++;
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
if (depth === 0 && ch === "=" && src[i + 1] === ">") return i;
|
|
181
|
-
i++;
|
|
182
|
-
}
|
|
183
|
-
return -1;
|
|
184
|
-
}
|
|
185
|
-
function scanReturns(src) {
|
|
186
|
-
let count = 0;
|
|
187
|
-
let firstIndex = -1;
|
|
188
|
-
for (let i = 0; i < src.length;) {
|
|
189
|
-
const ch = src[i];
|
|
190
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
191
|
-
i = skipString(src, i);
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
195
|
-
const nl = src.indexOf("\n", i);
|
|
196
|
-
if (nl === -1) break;
|
|
197
|
-
i = nl;
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
201
|
-
const end = src.indexOf("*/", i);
|
|
202
|
-
if (end === -1) break;
|
|
203
|
-
i = end + 2;
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
if (ch === "r" && src.startsWith("return", i) && !isIdentChar(src[i - 1] ?? " ") && !isIdentChar(src[i + 6] ?? " ")) {
|
|
207
|
-
if (firstIndex === -1) firstIndex = i;
|
|
208
|
-
count++;
|
|
209
|
-
i += 6;
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
i++;
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
count,
|
|
216
|
-
firstIndex
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function scanObjectLiteralKeys(src, open) {
|
|
220
|
-
const keys = [];
|
|
221
|
-
let i = open + 1;
|
|
222
|
-
let expectKey = true;
|
|
223
|
-
while (i < src.length) {
|
|
224
|
-
const ch = src[i];
|
|
225
|
-
if (isSpace(ch)) {
|
|
226
|
-
i++;
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
230
|
-
const nl = src.indexOf("\n", i);
|
|
231
|
-
if (nl === -1) return null;
|
|
232
|
-
i = nl + 1;
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
236
|
-
const end = src.indexOf("*/", i);
|
|
237
|
-
if (end === -1) return null;
|
|
238
|
-
i = end + 2;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (ch === "}") return keys;
|
|
242
|
-
if (expectKey) {
|
|
243
|
-
if (ch === "[") return null;
|
|
244
|
-
let key;
|
|
245
|
-
if (ch === "\"" || ch === "'") {
|
|
246
|
-
const end = skipString(src, i);
|
|
247
|
-
key = src.slice(i + 1, end - 1);
|
|
248
|
-
if (key.includes("\\")) return null;
|
|
249
|
-
i = end;
|
|
250
|
-
} else if (isIdentChar(ch) && !(ch >= "0" && ch <= "9")) {
|
|
251
|
-
const start = i;
|
|
252
|
-
while (i < src.length && isIdentChar(src[i])) i++;
|
|
253
|
-
key = src.slice(start, i);
|
|
254
|
-
} else return null;
|
|
255
|
-
let j = i;
|
|
256
|
-
while (j < src.length && isSpace(src[j])) j++;
|
|
257
|
-
if (src[j] !== ":") return null;
|
|
258
|
-
keys.push(key);
|
|
259
|
-
i = j + 1;
|
|
260
|
-
i = skipValue(src, i);
|
|
261
|
-
if (i === -1) return null;
|
|
262
|
-
expectKey = false;
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
if (ch === ",") {
|
|
266
|
-
expectKey = true;
|
|
267
|
-
i++;
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
function skipValue(src, i) {
|
|
275
|
-
let depth = 0;
|
|
276
|
-
while (i < src.length) {
|
|
277
|
-
const ch = src[i];
|
|
278
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
279
|
-
i = skipString(src, i);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
if (ch === "/" && src[i + 1] === "/") {
|
|
283
|
-
const nl = src.indexOf("\n", i);
|
|
284
|
-
if (nl === -1) return -1;
|
|
285
|
-
i = nl + 1;
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
if (ch === "/" && src[i + 1] === "*") {
|
|
289
|
-
const end = src.indexOf("*/", i);
|
|
290
|
-
if (end === -1) return -1;
|
|
291
|
-
i = end + 2;
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (ch === "{" || ch === "(" || ch === "[") {
|
|
295
|
-
depth++;
|
|
296
|
-
i++;
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
if (ch === "}" || ch === ")" || ch === "]") {
|
|
300
|
-
if (depth === 0) {
|
|
301
|
-
if (ch === "}") return i;
|
|
302
|
-
return -1;
|
|
303
|
-
}
|
|
304
|
-
depth--;
|
|
305
|
-
i++;
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if (ch === "," && depth === 0) return i;
|
|
309
|
-
i++;
|
|
310
|
-
}
|
|
311
|
-
return -1;
|
|
312
|
-
}
|
|
313
|
-
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
|
|
194
|
+
function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
|
|
314
195
|
const hooks = toArray(_hooks);
|
|
315
196
|
const modes = deriveModes(hooks, derive);
|
|
197
|
+
const tail = asyncTail(isAsync);
|
|
316
198
|
let code = "";
|
|
317
199
|
let depth = 0;
|
|
318
200
|
let needsEs = false;
|
|
319
201
|
for (let i = 0; i < hooks.length; i++) {
|
|
320
202
|
const fn = hooks[i];
|
|
321
|
-
|
|
322
|
-
|
|
203
|
+
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}_r===undefined` : void 0;
|
|
204
|
+
if (tail) code += tailStage(tail, guard);
|
|
205
|
+
else if (guard) {
|
|
206
|
+
code += `if(${guard}){\n`;
|
|
323
207
|
depth++;
|
|
324
208
|
}
|
|
325
209
|
const t = trace(report, fn);
|
|
326
210
|
code += t.begin;
|
|
327
|
-
code += `
|
|
328
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
211
|
+
code += awaitSite(`bf${at(i)}(c)`, fn, isAsync, "tmp", arm);
|
|
329
212
|
if (modes?.[i] !== void 0) {
|
|
330
213
|
needsEs = true;
|
|
214
|
+
link(registerDeriveDisposable, "dsp");
|
|
331
215
|
if (modes[i]) {
|
|
332
216
|
link(replaceDeriveContext, "rdc");
|
|
333
|
-
code += "if(tmp instanceof es)_r=tmp\nelse if(tmp){if(typeof tmp==='object'||typeof tmp==='function')c=rdc(c,tmp);tmp=undefined}\n";
|
|
217
|
+
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";
|
|
334
218
|
} else {
|
|
335
219
|
const keys = extractDeriveKeys(fn);
|
|
336
|
-
const merge = keys && keys.length ? keys.map((k) => `
|
|
220
|
+
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]}}";
|
|
337
221
|
code += `if(tmp instanceof es)_r=tmp
|
|
338
222
|
else if(tmp){${merge};tmp=undefined}\n`;
|
|
339
223
|
}
|
|
340
224
|
} else code += "if(tmp!==undefined)_r=tmp\n";
|
|
341
225
|
code += t.end("tmp");
|
|
226
|
+
if (tail) code += "}\n";
|
|
342
227
|
}
|
|
343
228
|
code += "}".repeat(depth);
|
|
344
229
|
if (needsEs) link(ElysiaStatus, "es");
|
|
@@ -371,7 +256,7 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
371
256
|
if (!first && abort && context["~sig"]?.aborted) return;
|
|
372
257
|
first = false;
|
|
373
258
|
let result = values[j](context);
|
|
374
|
-
if (result
|
|
259
|
+
if (typeof result?.then === "function") {
|
|
375
260
|
result = await result;
|
|
376
261
|
if (abort) context["~sig"] ??= context.request.signal;
|
|
377
262
|
}
|
|
@@ -379,52 +264,58 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
379
264
|
}
|
|
380
265
|
}
|
|
381
266
|
}
|
|
382
|
-
function mapChainHook(
|
|
267
|
+
function mapChainHook(_hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
268
|
+
const hooks = toArray(_hooks);
|
|
269
|
+
const tail = asyncTail(isAsync);
|
|
383
270
|
let code = "";
|
|
384
271
|
let depth = 0;
|
|
385
272
|
for (let i = 0; i < hooks.length; i++) {
|
|
386
273
|
const fn = hooks[i];
|
|
387
|
-
|
|
388
|
-
|
|
274
|
+
const guard = i > 0 ? `${abortGuard ? `!${abortGuard}&&` : ""}tmp===undefined` : void 0;
|
|
275
|
+
if (tail) code += tailStage(tail, guard);
|
|
276
|
+
else if (guard) {
|
|
277
|
+
code += `if(${guard}){\n`;
|
|
389
278
|
depth++;
|
|
390
279
|
}
|
|
391
280
|
const t = trace(report, fn);
|
|
392
281
|
code += t.begin;
|
|
393
|
-
code +=
|
|
394
|
-
code += awaitGuard(fn, isAsync, "tmp");
|
|
282
|
+
code += awaitSite(`${prefix}${at(i)}(c)`, fn, isAsync, "tmp", arm);
|
|
395
283
|
code += t.end("tmp");
|
|
284
|
+
if (tail) code += "}\n";
|
|
396
285
|
}
|
|
397
286
|
code += "}".repeat(depth);
|
|
398
|
-
code += `if(tmp!==undefined)_r=c.responseValue=tmp\n
|
|
287
|
+
code += tailPlain(isAsync, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
399
288
|
return code;
|
|
400
289
|
}
|
|
401
|
-
const mapAfterHandle = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "af", isAsync, report, abortGuard);
|
|
402
|
-
const mapMapResponse = (_hooks, isAsync, report, abortGuard) => mapChainHook(toArray(_hooks), "mr", isAsync, report, abortGuard);
|
|
403
290
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
404
291
|
const t = trace(report, fn);
|
|
405
|
-
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(_ar
|
|
406
|
-
return `try{
|
|
292
|
+
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
293
|
+
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
407
294
|
});
|
|
408
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync]) => {
|
|
295
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, isAsync, arm]) => {
|
|
409
296
|
link(mapResponse, "rm");
|
|
410
297
|
link(adoptErrorType, "aet");
|
|
411
|
-
return `
|
|
298
|
+
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`;
|
|
412
299
|
});
|
|
413
300
|
function map(map) {
|
|
414
|
-
return function(event, rest, abortGuard) {
|
|
301
|
+
return function(event, rest, abortGuard, tail) {
|
|
415
302
|
if (Array.isArray(event)) {
|
|
416
303
|
let code = "";
|
|
417
304
|
let depth = 0;
|
|
418
305
|
for (let i = 0; i < event.length; i++) {
|
|
419
|
-
|
|
420
|
-
|
|
306
|
+
const guard = i > 0 && abortGuard ? `!${abortGuard}` : void 0;
|
|
307
|
+
if (tail) code += tailStage(tail, guard);
|
|
308
|
+
else if (guard) {
|
|
309
|
+
code += `if(${guard}){\n`;
|
|
421
310
|
depth++;
|
|
422
311
|
}
|
|
423
312
|
code += map(i, event[i], rest);
|
|
313
|
+
if (tail) code += "}\n";
|
|
424
314
|
}
|
|
425
315
|
code += "}".repeat(depth);
|
|
426
316
|
return code;
|
|
427
|
-
} else return map(void 0, event, rest);
|
|
317
|
+
} else if (tail) return tailStage(tail) + map(void 0, event, rest) + "}\n";
|
|
318
|
+
else return map(void 0, event, rest);
|
|
428
319
|
};
|
|
429
320
|
}
|
|
430
321
|
const at = (index) => index === void 0 ? "" : `[${index}]`;
|
|
@@ -494,8 +385,20 @@ function getQueryParseChannels(querySchema) {
|
|
|
494
385
|
queryParseChannelsCache.set(querySchema, result);
|
|
495
386
|
return result ?? void 0;
|
|
496
387
|
}
|
|
497
|
-
const
|
|
498
|
-
|
|
388
|
+
const asyncTail = (mode) => typeof mode === "object" && mode.async ? mode : void 0;
|
|
389
|
+
function awaitSite(call, fn, isAsync, target, arm = "") {
|
|
390
|
+
if (typeof isAsync !== "object") return `${target}=${call}\n${awaitGuard(fn, isAsync, target, arm)}`;
|
|
391
|
+
const k = isAsync.n++;
|
|
392
|
+
isAsync.sites.push(`${isAsync.e ? "e:" : ""}${target}=${call}`);
|
|
393
|
+
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`;
|
|
394
|
+
}
|
|
395
|
+
const tailStage = (mode, guard) => `if(_rk<=${mode.n}${guard ? `&&(_rk===${mode.n}||${guard})` : ""}){\n`;
|
|
396
|
+
const tailPlain = (mode, code) => !code || !asyncTail(mode) ? code : mode.n ? `if(_rk<${mode.n}){\n${code}}\n` : "";
|
|
397
|
+
function awaitGuard(fn, isAsync, target, arm = "") {
|
|
398
|
+
if (!isAsync) return "";
|
|
399
|
+
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
400
|
+
return isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
401
|
+
}
|
|
499
402
|
|
|
500
403
|
//#endregion
|
|
501
|
-
export { armEntryAbort,
|
|
404
|
+
export { armEntryAbort, asyncTail, awaitGuard, awaitSite, cloneResponse, cloneStaticValue, deriveModes, getQueryParseChannels, hasRequestBody, mapAfterResponse, mapBeforeHandle, mapChainHook, mapError, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync, tailPlain, tailStage };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//#region src/compile/jit-probe.d.ts
|
|
2
2
|
/** A handler-JIT entry point the frozen replay can trip over. */
|
|
3
|
-
type JITProbeReason = 'sucrose' | 'handler:new-function';
|
|
3
|
+
type JITProbeReason = 'sucrose' | 'handler:new-function' | 'handler:indexed-duplicate';
|
|
4
4
|
interface JITProbeResult {
|
|
5
|
-
/**
|
|
5
|
+
/** No route needs sucrose, handler codegen, or indexed duplicate replay. */
|
|
6
6
|
jit: boolean;
|
|
7
7
|
reasons: JITProbeReason[];
|
|
8
8
|
}
|
|
@@ -15,12 +15,11 @@ var JITProbe = class {
|
|
|
15
15
|
static end() {
|
|
16
16
|
armed = false;
|
|
17
17
|
const fired = [...reasons];
|
|
18
|
-
|
|
18
|
+
reasons.clear();
|
|
19
|
+
return {
|
|
19
20
|
jit: fired.length === 0,
|
|
20
21
|
reasons: fired
|
|
21
22
|
};
|
|
22
|
-
reasons.clear();
|
|
23
|
-
return result;
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
25
|
|
|
@@ -13,12 +13,11 @@ var JITProbe = class {
|
|
|
13
13
|
static end() {
|
|
14
14
|
armed = false;
|
|
15
15
|
const fired = [...reasons];
|
|
16
|
-
|
|
16
|
+
reasons.clear();
|
|
17
|
+
return {
|
|
17
18
|
jit: fired.length === 0,
|
|
18
19
|
reasons: fired
|
|
19
20
|
};
|
|
20
|
-
reasons.clear();
|
|
21
|
-
return result;
|
|
22
21
|
}
|
|
23
22
|
};
|
|
24
23
|
|
package/dist/compile/lexer.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
//#region src/compile/lexer.d.ts
|
|
2
|
-
declare const isSpace: (ch: string) => ch is "\n" | " " | "\t" | "\r";
|
|
3
|
-
declare const isIdentChar: (ch: string) => boolean;
|
|
4
|
-
declare const isIdentCharCode: (code: number) => boolean;
|
|
5
2
|
declare function skipString(src: string, start: number): number;
|
|
3
|
+
interface ScanToken {
|
|
4
|
+
k: 'i' | 's' | 'p';
|
|
5
|
+
value: string;
|
|
6
|
+
at: number;
|
|
7
|
+
}
|
|
8
|
+
declare function scanTokens(source: string): ScanToken[] | undefined;
|
|
6
9
|
//#endregion
|
|
7
|
-
export {
|
|
10
|
+
export { ScanToken, scanTokens, skipString };
|