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,31 +1,28 @@
|
|
|
1
1
|
import { isBun } from "../../universal/constants.mjs";
|
|
2
2
|
import { ElysiaFile } from "../../universal/file.mjs";
|
|
3
|
-
import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, eventProperties, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, isCompactBeforeHandleOnly, isLocalScope, isNotEmpty, macroEpoch, mergeHook, nullObject, replaceUrlPath } from "../../utils.mjs";
|
|
4
|
-
import {
|
|
3
|
+
import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, eventProperties, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, isCompactBeforeHandleOnly, isHTMLBundle, isLocalScope, isNotEmpty, macroEpoch, mergeHook, nullObject, refTargets, replaceUrlPath, rootSnapshot } from "../../utils.mjs";
|
|
4
|
+
import { ElysiaStatus } from "../../error.mjs";
|
|
5
|
+
import { mapResponse } from "../../adapter/web-standard/handler.mjs";
|
|
6
|
+
import { Capture, Compiled, aotDrift, warnAotDrift } from "../aot.mjs";
|
|
5
7
|
import { frozenRootOf } from "../../generation.mjs";
|
|
8
|
+
import { isAsyncFunction } from "../utils.mjs";
|
|
9
|
+
import { returnedErrorClasses } from "../../handler/utils.mjs";
|
|
10
|
+
import { deriveModes } from "./utils.mjs";
|
|
6
11
|
import { resolveHandlerParams } from "./params.mjs";
|
|
7
12
|
import { compileHandlerJit, createInlineHandler, setCaptureHeaderShorthand } from "./jit.mjs";
|
|
8
|
-
import {
|
|
13
|
+
import { isResponseMap } from "./frozen-validator.mjs";
|
|
9
14
|
import { Reconstrct } from "./reconstruct.mjs";
|
|
15
|
+
import { describeRoute, routeDescriptors } from "./descriptor.mjs";
|
|
10
16
|
import { defaultAdapter } from "../../adapter/constants.mjs";
|
|
11
17
|
|
|
12
18
|
//#region src/compile/handler/index.ts
|
|
13
|
-
function
|
|
14
|
-
const { handle, suffixLen } = meta;
|
|
15
|
-
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
16
|
-
const encRoot = encodeURI(rawRoot);
|
|
17
|
-
const rawLen = rawRoot.length;
|
|
18
|
-
const encLen = encRoot.length;
|
|
19
|
-
return (c) => handle(new Request(replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
20
|
-
}
|
|
21
|
-
function applyHook(localHook, appHook, rootHook, appHookFresh = false) {
|
|
19
|
+
function applyHook(localHook, appHook, rootHook) {
|
|
22
20
|
let hook;
|
|
23
21
|
if (localHook && appHook) hook = mergeHook(cloneHook(localHook), appHook, true);
|
|
24
22
|
else {
|
|
25
|
-
const base = localHook
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
hook = ownsBase ? base : base ? cloneHook(base) : nullObject();
|
|
23
|
+
const base = localHook ? cloneHook(localHook) : appHook;
|
|
24
|
+
if (!rootHook) return base;
|
|
25
|
+
hook = base ?? nullObject();
|
|
29
26
|
}
|
|
30
27
|
if (rootHook) mergeHook(hook, rootHook, true, true);
|
|
31
28
|
return hook;
|
|
@@ -77,21 +74,6 @@ function dropHooksByOrigin(hook, skip) {
|
|
|
77
74
|
}
|
|
78
75
|
return out;
|
|
79
76
|
}
|
|
80
|
-
function reconstructNeedsHookState(names) {
|
|
81
|
-
for (let i = 0; i < names.length; i++) switch (names[i]) {
|
|
82
|
-
case "ho":
|
|
83
|
-
case "tf":
|
|
84
|
-
case "bf":
|
|
85
|
-
case "af":
|
|
86
|
-
case "mr":
|
|
87
|
-
case "er":
|
|
88
|
-
case "ar":
|
|
89
|
-
case "va":
|
|
90
|
-
case "cc":
|
|
91
|
-
case "tr": return true;
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
77
|
function promoteDerive(hook) {
|
|
96
78
|
const derive = hook.derive;
|
|
97
79
|
if (derive === void 0) return;
|
|
@@ -120,30 +102,33 @@ function memoScope(memos, root, scope) {
|
|
|
120
102
|
}
|
|
121
103
|
return perScope;
|
|
122
104
|
}
|
|
105
|
+
function hasMacroKey(hook, scopeMacro, rootMacro) {
|
|
106
|
+
if (scopeMacro || rootMacro) {
|
|
107
|
+
for (const key in hook) if (scopeMacro && key in scopeMacro || rootMacro && key in rootMacro) return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function applyMacros(hook, scope, frozenRoot, scopeMacro, rootMacro) {
|
|
112
|
+
if (scopeMacro) {
|
|
113
|
+
frozenRootOf(scope)["~applyMacro"](hook);
|
|
114
|
+
if (rootMacro) {
|
|
115
|
+
for (const k in hook) if (k in scopeMacro) delete hook[k];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (rootMacro) frozenRoot["~applyMacro"](hook);
|
|
119
|
+
}
|
|
123
120
|
const localHookMemos = /* @__PURE__ */ new WeakMap();
|
|
124
121
|
function resolveLocalHook(scope, hook, root = scope) {
|
|
125
122
|
if (!hook) return hook;
|
|
126
123
|
const frozenRoot = frozenRootOf(root);
|
|
127
124
|
const scopeMacro = frozenRootOf(scope)["~ext"]?.macro;
|
|
128
125
|
const rootMacro = root === scope ? void 0 : frozenRoot["~ext"]?.macro;
|
|
129
|
-
if (!scopeMacro
|
|
130
|
-
let hasMacroKey = false;
|
|
131
|
-
for (const key in hook) if (scopeMacro && key in scopeMacro || rootMacro && key in rootMacro) {
|
|
132
|
-
hasMacroKey = true;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
if (!hasMacroKey) return hook;
|
|
126
|
+
if (!hasMacroKey(hook, scopeMacro, rootMacro)) return hook;
|
|
136
127
|
const perScope = memoScope(localHookMemos, root, scope);
|
|
137
128
|
let resolved = perScope.get(hook);
|
|
138
129
|
if (resolved === void 0) {
|
|
139
130
|
resolved = cloneHook(hook);
|
|
140
|
-
|
|
141
|
-
frozenRootOf(scope)["~applyMacro"](resolved);
|
|
142
|
-
if (rootMacro) {
|
|
143
|
-
for (const k in resolved) if (k in scopeMacro) delete resolved[k];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (rootMacro) frozenRoot["~applyMacro"](resolved);
|
|
131
|
+
applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
147
132
|
perScope.set(hook, resolved);
|
|
148
133
|
}
|
|
149
134
|
return resolved;
|
|
@@ -171,84 +156,110 @@ function resolveChainNode(root, node) {
|
|
|
171
156
|
const frozenRoot = frozenRootOf(root);
|
|
172
157
|
const scopeMacro = frozenRootOf(scope)["~ext"]?.macro;
|
|
173
158
|
const rootMacro = root === scope ? void 0 : frozenRoot["~ext"]?.macro;
|
|
174
|
-
|
|
175
|
-
if (scopeMacro || rootMacro) {
|
|
176
|
-
for (const key in added) if (scopeMacro && key in scopeMacro || rootMacro && key in rootMacro) {
|
|
177
|
-
needsMacro = true;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
159
|
+
const needsMacro = hasMacroKey(added, scopeMacro, rootMacro);
|
|
181
160
|
if (!needsMacro && added.derive === void 0) return added;
|
|
182
161
|
const perScope = memoScope(chainNodeMemos, root, scope);
|
|
183
162
|
let resolved = perScope.get(added);
|
|
184
163
|
if (resolved === void 0) {
|
|
185
164
|
resolved = cloneHook(added);
|
|
186
|
-
if (needsMacro)
|
|
187
|
-
if (scopeMacro) {
|
|
188
|
-
frozenRootOf(scope)["~applyMacro"](resolved);
|
|
189
|
-
if (rootMacro) {
|
|
190
|
-
for (const k in resolved) if (k in scopeMacro) delete resolved[k];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (rootMacro) frozenRoot["~applyMacro"](resolved);
|
|
194
|
-
}
|
|
165
|
+
if (needsMacro) applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
195
166
|
promoteDerive(resolved);
|
|
196
167
|
perScope.set(added, resolved);
|
|
197
168
|
}
|
|
198
169
|
return resolved;
|
|
199
170
|
}
|
|
200
|
-
|
|
171
|
+
function chainResolver(root) {
|
|
201
172
|
const frozenRoot = frozenRootOf(root);
|
|
202
173
|
return frozenRoot["~ext"]?.macro || frozenRoot["~scopeChildren"] ? (node) => resolveChainNode(root, node) : void 0;
|
|
203
|
-
}
|
|
174
|
+
}
|
|
204
175
|
const localMacroRoot = (instance, root) => instance !== root && instance["~scopeChild"] === true && frozenRootOf(instance)["~ext"]?.macro ? instance : root;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
176
|
+
/** Whether a hook can be skipped by a native static response. */
|
|
177
|
+
function isEmptyPipelineHook(hook) {
|
|
178
|
+
if (!hook) return true;
|
|
179
|
+
for (const key in hook) {
|
|
180
|
+
if (key === "detail" || key === "tags" || key === "error") continue;
|
|
181
|
+
const value = hook[key];
|
|
182
|
+
if (value !== void 0 && value !== false && (!Array.isArray(value) || value.length)) return false;
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
function mapStaticValue(response, map, set, value) {
|
|
187
|
+
const mapped = map === mapResponse ? mapResponse(value, set, null) : Reflect.apply(map, response, [value, set]);
|
|
188
|
+
if (!(mapped instanceof Response)) return;
|
|
189
|
+
const body = value instanceof ElysiaStatus ? value.response : value;
|
|
190
|
+
if ((typeof body === "string" || typeof body === "number" || typeof body === "boolean") && !mapped.headers.has("content-type")) mapped.headers.set("content-type", "text/plain;charset=utf-8");
|
|
191
|
+
return mapped;
|
|
212
192
|
}
|
|
213
|
-
function
|
|
193
|
+
function afterUseHooks(node, resolve) {
|
|
194
|
+
let after;
|
|
195
|
+
while (node && "combine" in node) {
|
|
196
|
+
if (node.tail) {
|
|
197
|
+
const own = flattenChain(node.tail, isLocalScope, rootSnapshot(node.combine), resolve);
|
|
198
|
+
if (own) after = after ? mergeHook(own, after, false, true) : own;
|
|
199
|
+
}
|
|
200
|
+
node = node.combine;
|
|
201
|
+
}
|
|
202
|
+
return after;
|
|
203
|
+
}
|
|
204
|
+
function buildNativeStaticResponse(route, root) {
|
|
205
|
+
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
214
206
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
215
207
|
const frozenRoot = frozenRootOf(root);
|
|
216
208
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
217
|
-
const
|
|
209
|
+
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
210
|
+
const resolve = chainResolver(root);
|
|
211
|
+
const flatAppHook = flattenChainMemo(root, appHook, resolve);
|
|
212
|
+
let rootHook;
|
|
213
|
+
if (instance !== root) {
|
|
214
|
+
const locals = flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, rootSnapshot(inheritedChain), resolve);
|
|
215
|
+
const inherited = locals ? flattenChainMemo(root, inheritedChain, resolve) : flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
216
|
+
if (!inherited) rootHook = locals;
|
|
217
|
+
else if (!locals) rootHook = inherited;
|
|
218
|
+
else rootHook = mergeHook(inherited, locals);
|
|
219
|
+
const after = afterUseHooks(inheritedChain, resolve);
|
|
220
|
+
if (after) rootHook = rootHook ? mergeHook(after, rootHook) : after;
|
|
221
|
+
}
|
|
222
|
+
const hook = applyHook(ownedHook, flatAppHook, rootHook);
|
|
218
223
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
224
|
+
if (returnedErrorClasses(hook, root)?.some((C) => handler instanceof C)) return;
|
|
219
225
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
220
226
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return mapped;
|
|
225
|
-
}
|
|
227
|
+
const response = adapter.response;
|
|
228
|
+
const map = response.map;
|
|
229
|
+
return mapStaticValue(response, map, { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() }, handler);
|
|
226
230
|
}
|
|
227
231
|
function toArray(name, hook) {
|
|
228
232
|
if (typeof hook[name] === "function") hook[name] = [hook[name]];
|
|
229
233
|
}
|
|
230
|
-
function composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope) {
|
|
234
|
+
function composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, allowCompactPrefix = false) {
|
|
231
235
|
const resolve = chainResolver(root);
|
|
232
236
|
localHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
237
|
+
if (localHook && localHook.derive !== void 0) {
|
|
238
|
+
localHook = cloneHook(localHook);
|
|
239
|
+
promoteDerive(localHook);
|
|
240
|
+
}
|
|
233
241
|
const flatAppHook = appHook ? flattenChainMemo(root, appHook, resolve) : void 0;
|
|
234
|
-
let locals = instance !== root ? flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, inheritedChain, resolve) : void 0;
|
|
242
|
+
let locals = instance !== root ? flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, rootSnapshot(inheritedChain), resolve) : void 0;
|
|
235
243
|
const instanceLocal = instance !== root ? flattenChain(instance["~hookChain"], isLocalScope) : void 0;
|
|
236
|
-
const compactPrefix = instance !== root && !Capture.isCapturing() && !Capture.isAotBuildEnv() && resolve === void 0 && isCompactBeforeHandleOnly(localHook) && isCompactBeforeHandleOnly(flatAppHook) && isCompactBeforeHandleOnly(locals) && !instanceLocal?.error ? compactBeforeHandlePrefix(inheritedChain) : void 0;
|
|
244
|
+
const compactPrefix = allowCompactPrefix && instance !== root && !Capture.isCapturing() && !Capture.isAotBuildEnv() && resolve === void 0 && isCompactBeforeHandleOnly(localHook) && isCompactBeforeHandleOnly(flatAppHook) && isCompactBeforeHandleOnly(locals) && !instanceLocal?.error ? compactBeforeHandlePrefix(inheritedChain) : void 0;
|
|
237
245
|
let present = collectHookOrigins(localHook, void 0);
|
|
238
246
|
present = collectHookOrigins(flatAppHook, present);
|
|
239
247
|
if (compactPrefix && !present?.size && !compactBeforeHandleConflicts(localHook) && !compactBeforeHandleConflicts(flatAppHook) && !compactBeforeHandleConflicts(locals)) {
|
|
240
|
-
let hook = applyHook(localHook, flatAppHook, void 0
|
|
248
|
+
let hook = applyHook(localHook, flatAppHook, void 0);
|
|
241
249
|
if (locals) hook = hook ? mergeHook(hook, locals, false, true) : locals;
|
|
242
250
|
hook ??= nullObject();
|
|
243
251
|
hook["~beforeHandlePrefix"] = compactPrefix;
|
|
244
252
|
return hook;
|
|
245
253
|
}
|
|
246
254
|
let inherited = instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
|
|
247
|
-
|
|
255
|
+
let after = instance !== root ? afterUseHooks(inheritedChain, resolve) : void 0;
|
|
256
|
+
if ((inherited || after || locals) && (flatAppHook || localHook) && present?.size) {
|
|
248
257
|
if (inherited) inherited = dropHooksByOrigin(inherited, present);
|
|
258
|
+
if (after) after = dropHooksByOrigin(after, present);
|
|
249
259
|
if (locals) locals = dropHooksByOrigin(locals, present);
|
|
250
260
|
}
|
|
251
|
-
let hook = applyHook(localHook, flatAppHook, inherited ? cloneHook(inherited) : void 0
|
|
261
|
+
let hook = applyHook(localHook, flatAppHook, inherited ? cloneHook(inherited) : void 0);
|
|
262
|
+
if (after) hook = hook ? mergeHook(hook, after, false, true) : after;
|
|
252
263
|
if (locals) hook = hook ? mergeHook(hook, locals, false, true) : locals;
|
|
253
264
|
if (instance !== root) {
|
|
254
265
|
const errors = instanceLocal?.error;
|
|
@@ -265,30 +276,148 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
265
276
|
}
|
|
266
277
|
return hook;
|
|
267
278
|
}
|
|
279
|
+
const shapeEvents = [
|
|
280
|
+
"parse",
|
|
281
|
+
"transform",
|
|
282
|
+
"beforeHandle",
|
|
283
|
+
"afterHandle",
|
|
284
|
+
"mapResponse",
|
|
285
|
+
"afterResponse",
|
|
286
|
+
"error",
|
|
287
|
+
"trace"
|
|
288
|
+
];
|
|
289
|
+
const shapeSlots = [
|
|
290
|
+
"body",
|
|
291
|
+
"headers",
|
|
292
|
+
"params",
|
|
293
|
+
"query",
|
|
294
|
+
"cookie",
|
|
295
|
+
"response"
|
|
296
|
+
];
|
|
297
|
+
const isCookieAt = (at) => at === "cookie" || at === "field";
|
|
298
|
+
function childAt(at, k, value, deferred) {
|
|
299
|
+
if (at.endsWith("*")) return at.slice(0, -1);
|
|
300
|
+
if (at.endsWith("^")) return k === "0" ? at.slice(0, -1) + (Array.isArray(value) ? "*" : "") : "";
|
|
301
|
+
if (!isCookieAt(at)) return "";
|
|
302
|
+
switch (k) {
|
|
303
|
+
case "$ref": return at;
|
|
304
|
+
case "properties": return at === "cookie" ? "field*" : "";
|
|
305
|
+
case "parameters": return deferred ? at + "^" : "";
|
|
306
|
+
}
|
|
307
|
+
return k === "$defs" || compositionKeys.includes(k) ? at + "*" : "";
|
|
308
|
+
}
|
|
309
|
+
function routeShape(hook, handler, root) {
|
|
310
|
+
const frozenRoot = frozenRootOf(root);
|
|
311
|
+
const config = frozenRoot["~config"];
|
|
312
|
+
const models = frozenRoot["~ext"]?.models;
|
|
313
|
+
const refs = /* @__PURE__ */ new Map();
|
|
314
|
+
const addRef = (name, at = "") => {
|
|
315
|
+
if (!isCookieAt(at)) at = "";
|
|
316
|
+
if (at === "cookie" || !refs.get(name)) refs.set(name, at);
|
|
317
|
+
};
|
|
318
|
+
const ids = /* @__PURE__ */ new Map();
|
|
319
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
320
|
+
let unsupported = false;
|
|
321
|
+
for (const _ in []) return;
|
|
322
|
+
const shape = (v, at = "") => {
|
|
323
|
+
switch (typeof v) {
|
|
324
|
+
case "string": return JSON.stringify(v);
|
|
325
|
+
case "number": return "n" + (Object.is(v, -0) ? "-0" : v);
|
|
326
|
+
case "bigint": return "b" + v;
|
|
327
|
+
case "boolean": return v ? "T" : "F";
|
|
328
|
+
case "undefined": return "U";
|
|
329
|
+
case "function":
|
|
330
|
+
if (ids.has(v)) return "#" + ids.get(v);
|
|
331
|
+
ids.set(v, ids.size);
|
|
332
|
+
return isAsyncFunction(v) ? "fa" : "fs";
|
|
333
|
+
case "symbol":
|
|
334
|
+
unsupported = true;
|
|
335
|
+
return "";
|
|
336
|
+
}
|
|
337
|
+
if (v === null) return "N";
|
|
338
|
+
if ("~standard" in v) return "S";
|
|
339
|
+
if (visiting.has(v)) {
|
|
340
|
+
unsupported = true;
|
|
341
|
+
return "";
|
|
342
|
+
}
|
|
343
|
+
let tag = "";
|
|
344
|
+
const list = Array.isArray(v);
|
|
345
|
+
const proto = Object.getPrototypeOf(v);
|
|
346
|
+
if (list ? proto !== Array.prototype : proto !== null && proto !== Object.prototype) {
|
|
347
|
+
const kind = proto && Object.getOwnPropertyDescriptor(proto, "~kind");
|
|
348
|
+
if (!kind || !("value" in kind) || Reflect.ownKeys(proto).length !== 1 || Object.getPrototypeOf(proto) !== Object.prototype) {
|
|
349
|
+
unsupported = true;
|
|
350
|
+
return "";
|
|
351
|
+
}
|
|
352
|
+
tag = shape(kind.value);
|
|
353
|
+
}
|
|
354
|
+
visiting.add(v);
|
|
355
|
+
const map = at === "response" && isResponseMap(v);
|
|
356
|
+
const deferred = v["~kind"] === "Deferred";
|
|
357
|
+
let s = (list ? "[" : "{") + tag;
|
|
358
|
+
for (const k of Reflect.ownKeys(v)) {
|
|
359
|
+
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
360
|
+
if (typeof k === "symbol" || !("value" in d)) {
|
|
361
|
+
unsupported = true;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
const value = d.value;
|
|
365
|
+
if (k === "$ref" && typeof value === "string") addRef(value, at);
|
|
366
|
+
s += "," + (d.enumerable ? "" : "!") + JSON.stringify(k) + ":";
|
|
367
|
+
if (map) s += named(value);
|
|
368
|
+
else if (k === "config" && isCookieAt(at)) s += shape([value?.sign, !!value?.secrets]);
|
|
369
|
+
else if (k === "secrets" && (typeof value === "string" || Array.isArray(value))) s += shape(!!value);
|
|
370
|
+
else s += shape(value, childAt(at, k, value, deferred));
|
|
371
|
+
}
|
|
372
|
+
visiting.delete(v);
|
|
373
|
+
return s + (list ? "]" : "}");
|
|
374
|
+
};
|
|
375
|
+
const named = (v, at) => {
|
|
376
|
+
if (typeof v === "string") addRef(v, at);
|
|
377
|
+
return shape(v, at);
|
|
378
|
+
};
|
|
379
|
+
let s = typeof handler === "function" || handler == null ? shape(handler) : handler instanceof Response ? "R" : handler instanceof Promise ? "P" : typeof handler === "object" ? "O" : "V";
|
|
380
|
+
for (const event of shapeEvents) {
|
|
381
|
+
s += "|";
|
|
382
|
+
const fns = hook?.[event];
|
|
383
|
+
if (fns) for (const fn of Array.isArray(fns) ? fns : [fns]) s += shape(fn);
|
|
384
|
+
}
|
|
385
|
+
const bf = hook?.beforeHandle;
|
|
386
|
+
s += "|" + JSON.stringify(bf && deriveModes(Array.isArray(bf) ? bf : [bf], hook["~deriveEntries"]));
|
|
387
|
+
for (const from of [hook, ...hook?.schemas || []]) for (const slot of shapeSlots) s += "|" + named(from?.[slot], slot);
|
|
388
|
+
let targets;
|
|
389
|
+
for (const [ref, at] of refs) for (const target of at ? (targets ??= refTargets([], models))(ref) : [models?.[ref]]) s += "|" + JSON.stringify(ref) + shape(target, at);
|
|
390
|
+
s += "|" + JSON.stringify([
|
|
391
|
+
config?.cookie?.sign,
|
|
392
|
+
config?.cookie?.verify,
|
|
393
|
+
config?.normalize,
|
|
394
|
+
!!config?.allowUnsafeValidationDetails,
|
|
395
|
+
config?.abortSignal !== false,
|
|
396
|
+
isNotEmpty(frozenRoot["~ext"]?.headers),
|
|
397
|
+
!!(config?.adapter ?? defaultAdapter).response.supportsDefaultHeaderSink,
|
|
398
|
+
!!returnedErrorClasses(hook, root)
|
|
399
|
+
]) + shape(config?.sanitize);
|
|
400
|
+
return unsupported ? void 0 : fnv1a(s);
|
|
401
|
+
}
|
|
268
402
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
269
403
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
270
|
-
function
|
|
271
|
-
|
|
272
|
-
const source = Function.prototype.toString.call(handler);
|
|
273
|
-
return isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
274
|
-
}
|
|
275
|
-
function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope], root, precomputedStatic) {
|
|
404
|
+
function compileHandler(route, root, liveOnly = false) {
|
|
405
|
+
let [_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
276
406
|
const frozenRoot = frozenRootOf(root);
|
|
277
407
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
278
408
|
const method = _method;
|
|
279
409
|
const mountMeta = typeof handler === "function" ? handler["~mount"] : void 0;
|
|
280
|
-
if (mountMeta)
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope);
|
|
410
|
+
if (mountMeta) {
|
|
411
|
+
const { handle, suffixLen } = mountMeta;
|
|
412
|
+
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
413
|
+
const encRoot = encodeURI(rawRoot);
|
|
414
|
+
const rawLen = rawRoot.length;
|
|
415
|
+
const encLen = encRoot.length;
|
|
416
|
+
handler = (c) => handle(new Request(replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
417
|
+
}
|
|
418
|
+
const reconstructed = liveOnly ? void 0 : Compiled.getHandler(frozenRoot["~programId"], method, path);
|
|
419
|
+
if (!reconstructed) liveOnly ||= Compiled.hasProgram(frozenRoot["~programId"]);
|
|
420
|
+
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
292
421
|
if (hook) {
|
|
293
422
|
promoteDerive(hook);
|
|
294
423
|
toArray("parse", hook);
|
|
@@ -299,20 +428,24 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
299
428
|
toArray("afterResponse", hook);
|
|
300
429
|
toArray("error", hook);
|
|
301
430
|
}
|
|
302
|
-
const buildValidator = () => hook ? Reconstrct.validator(hook, root, method, path) : void 0;
|
|
303
|
-
|
|
431
|
+
const buildValidator = () => hook ? Reconstrct.validator(hook, root, method, path, liveOnly) : void 0;
|
|
432
|
+
const errorClasses = returnedErrorClasses(hook, root);
|
|
433
|
+
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) {
|
|
304
434
|
const error = handler;
|
|
305
435
|
handler = () => {
|
|
306
436
|
throw error;
|
|
307
437
|
};
|
|
308
|
-
}
|
|
438
|
+
} else if (isHTMLBundle(handler)) handler = () => {
|
|
439
|
+
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
440
|
+
};
|
|
441
|
+
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
309
442
|
const isHandleFunction = typeof handler === "function";
|
|
310
|
-
if (
|
|
311
|
-
else if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile)) {
|
|
443
|
+
if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile) && !declaresResponse) {
|
|
312
444
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
313
445
|
const set = { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() };
|
|
314
|
-
const
|
|
315
|
-
|
|
446
|
+
const response = adapter.response;
|
|
447
|
+
const mapped = mapStaticValue(response, response.map, set, handler);
|
|
448
|
+
if (mapped) handler = mapped;
|
|
316
449
|
}
|
|
317
450
|
const isStaticResponse = !isHandleFunction && handler instanceof Response;
|
|
318
451
|
const isPromiseHandler = !isHandleFunction && handler instanceof Promise;
|
|
@@ -321,6 +454,20 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
321
454
|
const resolve = (p) => typeof p === "string" && p in namedParsers ? namedParsers[p] : p;
|
|
322
455
|
hook.parse = Array.isArray(hook.parse) ? hook.parse.map(resolve) : resolve(hook.parse);
|
|
323
456
|
}
|
|
457
|
+
let shape;
|
|
458
|
+
if (reconstructed || Capture.isCapturing()) {
|
|
459
|
+
shape = routeShape(hook, handler, root);
|
|
460
|
+
if (reconstructed && (!shape || reconstructed.k !== shape)) {
|
|
461
|
+
let live;
|
|
462
|
+
try {
|
|
463
|
+
live = compileHandler(route, root, true);
|
|
464
|
+
} catch (cause) {
|
|
465
|
+
throw new Error(aotDrift(method, path), { cause });
|
|
466
|
+
}
|
|
467
|
+
warnAotDrift(method, path);
|
|
468
|
+
return live;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
324
471
|
if (reconstructed) return reconstructed.f(handler, ...resolveHandlerParams(reconstructed.a, {
|
|
325
472
|
root,
|
|
326
473
|
parse: adapter.parse,
|
|
@@ -330,10 +477,19 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
330
477
|
cookieConfig: reconstructed.a.includes("cc") ? Reconstrct.cookie(hook, root) : void 0,
|
|
331
478
|
tracers: reconstructed.a.includes("tr") ? Reconstrct.trace(hook, root) : void 0
|
|
332
479
|
}));
|
|
333
|
-
if (hook === void 0 &&
|
|
480
|
+
if (hook === void 0 && !errorClasses && isHandleFunction && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !isNotEmpty(frozenRoot["~ext"]?.headers) && !Capture.isAotBuildEnv() && !Capture.isCapturing()) {
|
|
481
|
+
let isContextFree = false;
|
|
482
|
+
if (!Object.hasOwn(handler, "toString")) {
|
|
483
|
+
const source = Function.prototype.toString.call(handler);
|
|
484
|
+
isContextFree = isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
485
|
+
}
|
|
486
|
+
if (isContextFree) {
|
|
487
|
+
const compact = adapter.response.compact;
|
|
488
|
+
if (compact) return createInlineHandler(compact, handler);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
334
491
|
const state = describeRoute({
|
|
335
492
|
method,
|
|
336
|
-
path,
|
|
337
493
|
handler,
|
|
338
494
|
root,
|
|
339
495
|
adapter,
|
|
@@ -355,7 +511,6 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
355
511
|
method,
|
|
356
512
|
path,
|
|
357
513
|
handler,
|
|
358
|
-
instance,
|
|
359
514
|
root: frozenRoot,
|
|
360
515
|
errorRoot: root,
|
|
361
516
|
hook,
|
|
@@ -363,9 +518,11 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
363
518
|
isHandleFunction,
|
|
364
519
|
isStaticResponse,
|
|
365
520
|
isPromiseHandler,
|
|
366
|
-
|
|
521
|
+
errorClasses,
|
|
522
|
+
state,
|
|
523
|
+
shape
|
|
367
524
|
});
|
|
368
525
|
}
|
|
369
526
|
|
|
370
527
|
//#endregion
|
|
371
|
-
export { buildNativeStaticResponse, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, setCaptureHeaderShorthand };
|
|
528
|
+
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, routeShape, setCaptureHeaderShorthand };
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { AnyLocalHook, CompiledHandler } from "../../types.js";
|
|
2
1
|
import { Context } from "../../context.js";
|
|
2
|
+
import { AnyLocalHook, CompiledHandler } from "../../types.js";
|
|
3
3
|
import { AnyElysia } from "../../base.js";
|
|
4
4
|
import { ElysiaAdapter } from "../../adapter/index.js";
|
|
5
5
|
import { RouteCompileState } from "./descriptor.js";
|
|
6
|
+
import { TailMode } from "./utils.js";
|
|
6
7
|
|
|
7
8
|
//#region src/compile/handler/jit.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* @internal test hook: receives each route's emitted source. A sync-first
|
|
11
|
+
* route's async tail is a helper beside it, so `toString()` of the compiled
|
|
12
|
+
* handler does not show the whole pipeline
|
|
13
|
+
*/
|
|
14
|
+
declare let onEmit: ((code: string) => void) | undefined;
|
|
15
|
+
declare const setOnEmit: (fn: typeof onEmit) => void;
|
|
16
|
+
declare const setAsyncTail: (on: boolean | undefined) => void;
|
|
8
17
|
declare const setCaptureHeaderShorthand: (value: boolean | undefined) => void;
|
|
9
|
-
declare function schemaMediaKind(schema: any): number | undefined;
|
|
10
18
|
declare const createInlineHandler: (map: (value: unknown, ...rest: unknown[]) => unknown, h: (context: Context) => unknown) => CompiledHandler;
|
|
11
19
|
interface CompileHandlerJitOptions {
|
|
12
20
|
method: string;
|
|
13
21
|
path: string;
|
|
14
22
|
handler: unknown;
|
|
15
|
-
instance: AnyElysia;
|
|
16
23
|
root: AnyElysia;
|
|
17
24
|
errorRoot: AnyElysia;
|
|
18
25
|
hook: AnyLocalHook | undefined;
|
|
@@ -20,24 +27,19 @@ interface CompileHandlerJitOptions {
|
|
|
20
27
|
isHandleFunction: boolean;
|
|
21
28
|
isStaticResponse: boolean;
|
|
22
29
|
isPromiseHandler: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Non-Error classes a returned value is rethrown for, see
|
|
32
|
+
* `returnedErrorClasses`
|
|
33
|
+
*/
|
|
34
|
+
errorClasses?: Function[];
|
|
23
35
|
/**
|
|
24
36
|
* Per-route descriptor + compile artifacts, computed by `describeRoute`.
|
|
25
37
|
* The JIT no longer re-derives these facts; it names its emissions off them.
|
|
26
38
|
*/
|
|
27
39
|
state: RouteCompileState;
|
|
40
|
+
/** `routeShape`, recorded with the captured code */
|
|
41
|
+
shape?: number;
|
|
28
42
|
}
|
|
29
|
-
declare function compileHandlerJit(
|
|
30
|
-
method,
|
|
31
|
-
path,
|
|
32
|
-
handler,
|
|
33
|
-
root,
|
|
34
|
-
errorRoot,
|
|
35
|
-
hook,
|
|
36
|
-
adapter,
|
|
37
|
-
isHandleFunction,
|
|
38
|
-
isStaticResponse,
|
|
39
|
-
isPromiseHandler,
|
|
40
|
-
state
|
|
41
|
-
}: CompileHandlerJitOptions): CompiledHandler;
|
|
43
|
+
declare function compileHandlerJit(options: CompileHandlerJitOptions, tailPass?: TailMode): CompiledHandler;
|
|
42
44
|
//#endregion
|
|
43
|
-
export { CompileHandlerJitOptions, compileHandlerJit, createInlineHandler,
|
|
45
|
+
export { CompileHandlerJitOptions, compileHandlerJit, createInlineHandler, setAsyncTail, setCaptureHeaderShorthand, setOnEmit };
|