elysia 2.0.0-beta.21 → 2.0.0-beta.22
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/_virtual/_rolldown/runtime.mjs +1 -0
- package/dist/adapter/bun/index.d.ts +6 -8
- package/dist/adapter/bun/index.js +6 -8
- package/dist/adapter/bun/index.mjs +7 -8
- package/dist/adapter/constants.mjs +1 -0
- package/dist/adapter/default-headers.mjs +1 -0
- package/dist/adapter/index.mjs +1 -0
- package/dist/adapter/origin.mjs +1 -0
- package/dist/adapter/response-ownership.mjs +1 -0
- package/dist/adapter/skip-clone.mjs +1 -0
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +5 -8
- package/dist/adapter/utils.js +24 -18
- package/dist/adapter/utils.mjs +25 -18
- package/dist/adapter/web-standard/handler.mjs +2 -1
- package/dist/adapter/web-standard/index.mjs +1 -0
- package/dist/adapter/web-standard/utils.mjs +1 -0
- package/dist/base.d.ts +118 -69
- package/dist/base.js +213 -193
- package/dist/base.mjs +220 -199
- package/dist/compile/aot-capture.js +2 -2
- package/dist/compile/aot-capture.mjs +4 -3
- package/dist/compile/aot-emit.js +7 -8
- package/dist/compile/aot-emit.mjs +8 -8
- package/dist/compile/aot-reconstruct.mjs +3 -2
- package/dist/compile/aot.d.ts +3 -3
- package/dist/compile/aot.js +5 -5
- package/dist/compile/aot.mjs +6 -5
- package/dist/compile/handler/descriptor.d.ts +2 -5
- package/dist/compile/handler/descriptor.js +12 -17
- package/dist/compile/handler/descriptor.mjs +16 -21
- package/dist/compile/handler/frozen-validator.d.ts +2 -2
- package/dist/compile/handler/frozen-validator.js +3 -3
- package/dist/compile/handler/frozen-validator.mjs +4 -3
- package/dist/compile/handler/index.d.ts +3 -1
- package/dist/compile/handler/index.js +77 -118
- package/dist/compile/handler/index.mjs +83 -125
- package/dist/compile/handler/jit.d.ts +12 -12
- package/dist/compile/handler/jit.js +60 -43
- package/dist/compile/handler/jit.mjs +63 -47
- package/dist/compile/handler/params.d.ts +5 -1
- package/dist/compile/handler/params.js +14 -5
- package/dist/compile/handler/params.mjs +16 -7
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +2 -2
- package/dist/compile/handler/reconstruct.mjs +3 -2
- package/dist/compile/handler/static-clone-resolver.mjs +1 -0
- package/dist/compile/handler/utils.d.ts +13 -7
- package/dist/compile/handler/utils.js +75 -52
- package/dist/compile/handler/utils.mjs +77 -54
- package/dist/compile/jit-probe.mjs +1 -0
- package/dist/compile/lexer.js +4 -4
- package/dist/compile/lexer.mjs +5 -4
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +8 -3
- package/dist/compile/utils.mjs +8 -3
- package/dist/compiled.mjs +1 -0
- package/dist/constants.mjs +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.d.ts +2 -2
- package/dist/cookie/config.js +21 -26
- package/dist/cookie/config.mjs +22 -26
- package/dist/cookie/cookie.mjs +1 -0
- package/dist/cookie/crypto.mjs +1 -0
- package/dist/cookie/error.mjs +1 -0
- package/dist/cookie/lib.mjs +1 -0
- package/dist/cookie/serialize.mjs +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +1 -1
- package/dist/cookie/utils.js +64 -45
- package/dist/cookie/utils.mjs +66 -46
- package/dist/error.d.ts +10 -6
- package/dist/error.js +22 -6
- package/dist/error.mjs +25 -9
- package/dist/generation.mjs +1 -0
- package/dist/handler/error.d.ts +12 -15
- package/dist/handler/error.js +43 -40
- package/dist/handler/error.mjs +45 -41
- package/dist/handler/fetch.js +59 -21
- package/dist/handler/fetch.mjs +61 -22
- package/dist/handler/utils.d.ts +16 -3
- package/dist/handler/utils.js +14 -13
- package/dist/handler/utils.mjs +16 -15
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -0
- package/dist/index.mjs +3 -2
- package/dist/memory.mjs +1 -0
- package/dist/package.js +1 -1
- package/dist/package.mjs +2 -1
- package/dist/parse-query.js +76 -76
- package/dist/parse-query.mjs +77 -76
- package/dist/plugin/aot/bun.mjs +1 -0
- package/dist/plugin/aot/core.js +7 -4
- package/dist/plugin/aot/core.mjs +8 -5
- package/dist/plugin/aot/esbuild.mjs +1 -0
- package/dist/plugin/aot/rspack-loader.mjs +1 -0
- package/dist/plugin/aot/rspack.mjs +1 -0
- package/dist/plugin/aot/treeshake.mjs +1 -0
- package/dist/plugin/aot/unplugin.mjs +4 -3
- package/dist/plugin/aot/vite.mjs +1 -0
- package/dist/plugin/aot/worker.mjs +1 -0
- package/dist/plugin/auto-head.mjs +1 -0
- package/dist/plugin/trace.mjs +1 -0
- package/dist/plugin/websocket.mjs +1 -0
- package/dist/route-table.mjs +1 -0
- package/dist/schema-snapshot.mjs +1 -0
- package/dist/sucrose.d.ts +2 -2
- package/dist/sucrose.js +11 -11
- package/dist/sucrose.mjs +12 -11
- package/dist/trace.js +8 -10
- package/dist/trace.mjs +10 -11
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.mjs +1 -0
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/bridge.mjs +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.mjs +1 -0
- package/dist/type/compat.mjs +1 -0
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/constants.mjs +1 -0
- package/dist/type/elysia/accelerate.mjs +1 -0
- package/dist/type/elysia/array-buffer.d.ts +3 -2
- package/dist/type/elysia/array-buffer.js +5 -5
- package/dist/type/elysia/array-buffer.mjs +6 -5
- package/dist/type/elysia/array-string.mjs +1 -0
- package/dist/type/elysia/array.mjs +1 -0
- package/dist/type/elysia/boolean-string.mjs +1 -0
- package/dist/type/elysia/boolean.mjs +1 -0
- package/dist/type/elysia/cookie.mjs +1 -0
- package/dist/type/elysia/date.mjs +1 -0
- package/dist/type/elysia/file-type.mjs +1 -0
- package/dist/type/elysia/file.mjs +1 -0
- package/dist/type/elysia/files.mjs +1 -0
- package/dist/type/elysia/form.mjs +1 -0
- package/dist/type/elysia/integer-string.mjs +1 -0
- package/dist/type/elysia/integer.mjs +1 -0
- package/dist/type/elysia/intersect.mjs +1 -0
- package/dist/type/elysia/json-string.mjs +1 -0
- package/dist/type/elysia/keep-config.js +8 -8
- package/dist/type/elysia/keep-config.mjs +9 -8
- package/dist/type/elysia/maybe-empty.mjs +1 -0
- package/dist/type/elysia/no-validate.mjs +1 -0
- package/dist/type/elysia/nullable.mjs +1 -0
- package/dist/type/elysia/number.mjs +1 -0
- package/dist/type/elysia/numeric-enum.d.ts +4 -2
- package/dist/type/elysia/numeric-enum.mjs +1 -0
- package/dist/type/elysia/numeric.mjs +1 -0
- package/dist/type/elysia/object-string.mjs +1 -0
- package/dist/type/elysia/object.mjs +1 -0
- package/dist/type/elysia/optional.mjs +1 -0
- package/dist/type/elysia/problem.mjs +1 -0
- package/dist/type/elysia/string.mjs +1 -0
- package/dist/type/elysia/uint8-array.d.ts +2 -1
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +3 -2
- package/dist/type/elysia/union-enum.mjs +1 -0
- package/dist/type/elysia/union.mjs +1 -0
- package/dist/type/elysia/utils.js +3 -3
- package/dist/type/elysia/utils.mjs +4 -3
- package/dist/type/exports.mjs +1 -0
- package/dist/type/index.mjs +2 -1
- package/dist/type/shared.mjs +1 -0
- package/dist/type/sync-require.mjs +1 -0
- package/dist/type/typebox-system-lite.mjs +1 -0
- package/dist/type/typebox-system-require.mjs +1 -0
- package/dist/type/typebox-type-live.mjs +1 -0
- package/dist/type/typebox-value-live.mjs +1 -0
- package/dist/type/typebox-value-ops.mjs +1 -0
- package/dist/type/typebox-value.mjs +1 -0
- package/dist/type/types.d.ts +1 -1
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.mjs +1 -0
- package/dist/type/validator/clean-safe.mjs +1 -0
- package/dist/type/validator/custom-error.js +41 -33
- package/dist/type/validator/custom-error.mjs +42 -33
- package/dist/type/validator/default-precompute.d.ts +2 -2
- package/dist/type/validator/default-precompute.js +10 -11
- package/dist/type/validator/default-precompute.mjs +13 -13
- package/dist/type/validator/exact-mirror.mjs +1 -0
- package/dist/type/validator/frozen-check.js +7 -7
- package/dist/type/validator/frozen-check.mjs +8 -7
- package/dist/type/validator/index.d.ts +2 -2
- package/dist/type/validator/index.js +4 -8
- package/dist/type/validator/index.mjs +5 -8
- package/dist/type/validator/string-codec-aot.d.ts +1 -1
- package/dist/type/validator/string-codec-aot.mjs +1 -0
- package/dist/type/validator/validator-cache.js +18 -18
- package/dist/type/validator/validator-cache.mjs +19 -18
- package/dist/types.d.ts +105 -69
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.mjs +1 -0
- package/dist/universal/file.mjs +1 -0
- package/dist/universal/index.mjs +1 -0
- package/dist/universal/is-production.mjs +1 -0
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +49 -31
- package/dist/utils.js +221 -109
- package/dist/utils.mjs +215 -106
- package/dist/validator/index.d.ts +3 -3
- package/dist/validator/index.js +4 -4
- package/dist/validator/index.mjs +5 -4
- package/dist/validator/route.d.ts +2 -2
- package/dist/validator/route.mjs +1 -0
- package/dist/ws/context.js +1 -1
- package/dist/ws/context.mjs +2 -1
- package/dist/ws/index.mjs +1 -0
- package/dist/ws/parser.mjs +1 -0
- package/dist/ws/route.js +34 -25
- package/dist/ws/route.mjs +40 -30
- package/dist/ws/types.d.ts +2 -3
- package/dist/ws/types.mjs +1 -0
- package/package.json +2 -2
|
@@ -19,62 +19,15 @@ const require_adapter_constants = require('../../adapter/constants.js');
|
|
|
19
19
|
//#region src/compile/handler/index.ts
|
|
20
20
|
function applyHook(localHook, appHook, rootHook) {
|
|
21
21
|
let hook;
|
|
22
|
-
if (localHook && appHook) hook = require_utils.mergeHook(require_utils.cloneHook(localHook), appHook
|
|
22
|
+
if (localHook && appHook) hook = require_utils.mergeHook(require_utils.cloneHook(localHook), appHook);
|
|
23
23
|
else {
|
|
24
24
|
const base = localHook ? require_utils.cloneHook(localHook) : appHook;
|
|
25
25
|
if (!rootHook) return base;
|
|
26
26
|
hook = base ?? require_utils.nullObject();
|
|
27
27
|
}
|
|
28
|
-
if (rootHook) require_utils.mergeHook(hook, rootHook
|
|
28
|
+
if (rootHook) require_utils.mergeHook(hook, rootHook);
|
|
29
29
|
return hook;
|
|
30
30
|
}
|
|
31
|
-
function collectHookOrigins(hook, into) {
|
|
32
|
-
if (!hook) return into;
|
|
33
|
-
for (const key in hook) {
|
|
34
|
-
if (!require_utils.eventProperties.has(key)) continue;
|
|
35
|
-
const v = hook[key];
|
|
36
|
-
if (!v) continue;
|
|
37
|
-
if (Array.isArray(v)) for (const fn of v) {
|
|
38
|
-
const origin = require_utils.fnOrigin.get(fn);
|
|
39
|
-
if (origin !== void 0) (into ??= /* @__PURE__ */ new Set()).add(origin);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const origin = require_utils.fnOrigin.get(v);
|
|
43
|
-
if (origin !== void 0) (into ??= /* @__PURE__ */ new Set()).add(origin);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return into;
|
|
47
|
-
}
|
|
48
|
-
function dropHooksByOrigin(hook, skip) {
|
|
49
|
-
let out = hook;
|
|
50
|
-
for (const key in hook) {
|
|
51
|
-
if (!require_utils.eventProperties.has(key)) continue;
|
|
52
|
-
const v = hook[key];
|
|
53
|
-
if (!v) continue;
|
|
54
|
-
if (Array.isArray(v)) {
|
|
55
|
-
let kept;
|
|
56
|
-
for (let i = 0; i < v.length; i++) {
|
|
57
|
-
const fn = v[i];
|
|
58
|
-
const origin = require_utils.fnOrigin.get(fn);
|
|
59
|
-
const keep = origin === void 0 || !skip.has(origin);
|
|
60
|
-
if (kept) {
|
|
61
|
-
if (keep) kept.push(fn);
|
|
62
|
-
} else if (!keep) kept = v.slice(0, i);
|
|
63
|
-
}
|
|
64
|
-
if (kept) {
|
|
65
|
-
if (out === hook) out = { ...hook };
|
|
66
|
-
out[key] = kept;
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const origin = require_utils.fnOrigin.get(v);
|
|
70
|
-
if (origin !== void 0 && skip.has(origin)) {
|
|
71
|
-
if (out === hook) out = { ...hook };
|
|
72
|
-
out[key] = [];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
31
|
function promoteDerive(hook) {
|
|
79
32
|
const derive = hook.derive;
|
|
80
33
|
if (derive === void 0) return;
|
|
@@ -87,6 +40,12 @@ function promoteDerive(hook) {
|
|
|
87
40
|
}
|
|
88
41
|
hook.derive = void 0;
|
|
89
42
|
}
|
|
43
|
+
function runIntrospect(hook) {
|
|
44
|
+
const introspects = hook?.["~introspect"];
|
|
45
|
+
if (!introspects) return;
|
|
46
|
+
for (let i = 0; i < introspects.length; i++) introspects[i](hook);
|
|
47
|
+
delete hook["~introspect"];
|
|
48
|
+
}
|
|
90
49
|
function memoScope(memos, root, scope) {
|
|
91
50
|
let bucket = memos.get(root);
|
|
92
51
|
if (!bucket || bucket.e !== require_utils.macroEpoch()) {
|
|
@@ -136,9 +95,10 @@ function resolveLocalHook(scope, hook, root = scope) {
|
|
|
136
95
|
}
|
|
137
96
|
function resolveWSLocalHook(scope, hook, root = scope) {
|
|
138
97
|
const resolved = resolveLocalHook(scope, hook, root);
|
|
139
|
-
if (!resolved || resolved.derive === void 0) return resolved;
|
|
98
|
+
if (!resolved || resolved.derive === void 0 && !resolved["~introspect"]) return resolved;
|
|
140
99
|
const owned = require_utils.cloneHook(resolved);
|
|
141
100
|
promoteDerive(owned);
|
|
101
|
+
runIntrospect(owned);
|
|
142
102
|
return owned;
|
|
143
103
|
}
|
|
144
104
|
const chainNodeMemos = /* @__PURE__ */ new WeakMap();
|
|
@@ -165,6 +125,7 @@ function resolveChainNode(root, node) {
|
|
|
165
125
|
resolved = require_utils.cloneHook(added);
|
|
166
126
|
if (needsMacro) applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
167
127
|
promoteDerive(resolved);
|
|
128
|
+
runIntrospect(resolved);
|
|
168
129
|
perScope.set(added, resolved);
|
|
169
130
|
}
|
|
170
131
|
return resolved;
|
|
@@ -191,17 +152,6 @@ function mapStaticValue(response, map, set, value) {
|
|
|
191
152
|
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");
|
|
192
153
|
return mapped;
|
|
193
154
|
}
|
|
194
|
-
function afterUseHooks(node, resolve) {
|
|
195
|
-
let after;
|
|
196
|
-
while (node && "combine" in node) {
|
|
197
|
-
if (node.tail) {
|
|
198
|
-
const own = require_utils.flattenChain(node.tail, require_utils.isLocalScope, require_utils.rootSnapshot(node.combine), resolve);
|
|
199
|
-
if (own) after = after ? require_utils.mergeHook(own, after, false, true) : own;
|
|
200
|
-
}
|
|
201
|
-
node = node.combine;
|
|
202
|
-
}
|
|
203
|
-
return after;
|
|
204
|
-
}
|
|
205
155
|
function buildNativeStaticResponse(route, root) {
|
|
206
156
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
207
157
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -209,20 +159,10 @@ function buildNativeStaticResponse(route, root) {
|
|
|
209
159
|
const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
210
160
|
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
211
161
|
const resolve = chainResolver(root);
|
|
212
|
-
const
|
|
213
|
-
let rootHook;
|
|
214
|
-
if (instance !== root) {
|
|
215
|
-
const locals = require_utils.flattenChain(require_generation.frozenRootOf(root)["~hookChain"], require_utils.isLocalScope, require_utils.rootSnapshot(inheritedChain), resolve);
|
|
216
|
-
const inherited = locals ? require_utils.flattenChainMemo(root, inheritedChain, resolve) : require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
217
|
-
if (!inherited) rootHook = locals;
|
|
218
|
-
else if (!locals) rootHook = inherited;
|
|
219
|
-
else rootHook = require_utils.mergeHook(inherited, locals);
|
|
220
|
-
const after = afterUseHooks(inheritedChain, resolve);
|
|
221
|
-
if (after) rootHook = rootHook ? require_utils.mergeHook(after, rootHook) : after;
|
|
222
|
-
}
|
|
223
|
-
const hook = applyHook(ownedHook, flatAppHook, rootHook);
|
|
162
|
+
const hook = applyHook(ownedHook, require_utils.flattenChainMemo(root, appHook, resolve), instance !== root ? require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0);
|
|
224
163
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
225
|
-
|
|
164
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
165
|
+
if (require_handler_utils.returnedErrorClasses({ error: withCallbackErrors(hook?.error, callback ?? []) })?.some((C) => handler instanceof C)) return;
|
|
226
166
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
227
167
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
228
168
|
const response = adapter.response;
|
|
@@ -239,44 +179,57 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
239
179
|
localHook = require_utils.cloneHook(localHook);
|
|
240
180
|
promoteDerive(localHook);
|
|
241
181
|
}
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
182
|
+
const own = require_utils.flattenChainInfo(root, appHook, resolve);
|
|
183
|
+
let skip;
|
|
184
|
+
if (own?.installs && instance !== root) {
|
|
185
|
+
const outer = require_utils.flattenChainInfo(root, inheritedChain, resolve)?.installs;
|
|
186
|
+
if (outer && !outer.isDisjointFrom(own.installs)) skip = outer;
|
|
187
|
+
}
|
|
188
|
+
const flatAppHook = require_utils.flattenChainMemo(root, appHook, resolve, skip);
|
|
189
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
190
|
+
const compactPrefix = allowCompactPrefix && instance !== root && !require_compile_aot.Capture.isCapturing() && !require_compile_aot.Capture.isAotBuildEnv() && resolve === void 0 && require_utils.isCompactBeforeHandleOnly(localHook) && require_utils.isCompactBeforeHandleOnly(flatAppHook) && !callback ? require_utils.compactBeforeHandlePrefix(inheritedChain) : void 0;
|
|
191
|
+
if (compactPrefix && !own?.named && !require_utils.compactBeforeHandleConflicts(localHook) && !require_utils.compactBeforeHandleConflicts(flatAppHook)) {
|
|
249
192
|
let hook = applyHook(localHook, flatAppHook, void 0);
|
|
250
|
-
if (locals) hook = hook ? require_utils.mergeHook(hook, locals, false, true) : locals;
|
|
251
193
|
hook ??= require_utils.nullObject();
|
|
252
194
|
hook["~beforeHandlePrefix"] = compactPrefix;
|
|
253
195
|
return hook;
|
|
254
196
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
197
|
+
const inherited = instance !== root ? require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
|
|
198
|
+
const deriveEntries = require_compile_handler_utils.joinDeriveEntries([
|
|
199
|
+
inherited,
|
|
200
|
+
flatAppHook,
|
|
201
|
+
localHook
|
|
202
|
+
]);
|
|
262
203
|
let hook = applyHook(localHook, flatAppHook, inherited ? require_utils.cloneHook(inherited) : void 0);
|
|
263
|
-
if (
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (errors) {
|
|
268
|
-
hook ??= require_utils.nullObject();
|
|
269
|
-
let existing = hook.error;
|
|
270
|
-
if (existing) {
|
|
271
|
-
if (!Array.isArray(existing)) existing = hook.error = [existing];
|
|
272
|
-
if (Array.isArray(errors)) {
|
|
273
|
-
for (const fn of errors) if (!existing.includes(fn)) existing.push(fn);
|
|
274
|
-
} else if (!existing.includes(errors)) existing.push(errors);
|
|
275
|
-
} else hook.error = Array.isArray(errors) ? errors.slice() : [errors];
|
|
276
|
-
}
|
|
204
|
+
if (deriveEntries) hook["~deriveEntries"] = deriveEntries;
|
|
205
|
+
if (callback) {
|
|
206
|
+
hook ??= require_utils.nullObject();
|
|
207
|
+
hook.error = withCallbackErrors(hook.error, callback);
|
|
277
208
|
}
|
|
278
209
|
return hook;
|
|
279
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Error hooks of the `.group()`/`.guard()` callbacks a route came out of
|
|
213
|
+
* innermost first (see `ChainNode`)
|
|
214
|
+
*/
|
|
215
|
+
function callbackErrors(start, appHook, root, resolve) {
|
|
216
|
+
let out;
|
|
217
|
+
let outer = null;
|
|
218
|
+
for (let node = start; node && "combine" in node; node = node.combine) if (node.callback) {
|
|
219
|
+
if (outer === null) outer = require_utils.flattenChainInfo(root, start, resolve)?.installs;
|
|
220
|
+
if (!require_utils.flattenChainMemoReadonly(root, node.callback, resolve, outer)?.error) continue;
|
|
221
|
+
const has = /* @__PURE__ */ new Set();
|
|
222
|
+
const collect = (n) => {
|
|
223
|
+
has.add(n.registration ?? n);
|
|
224
|
+
};
|
|
225
|
+
require_utils.flattenChain(node.inner, collect);
|
|
226
|
+
require_utils.flattenChain(appHook, collect);
|
|
227
|
+
const error = require_utils.flattenChain(node.callback, (n) => has.has(n.registration ?? n) ? void 0 : resolve ? resolve(n) : n.added, outer)?.error;
|
|
228
|
+
if (error) out = [].concat(error, out ?? []);
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
const withCallbackErrors = (own, callback) => [].concat(own ?? [], callback);
|
|
280
233
|
const shapeEvents = [
|
|
281
234
|
"parse",
|
|
282
235
|
"transform",
|
|
@@ -396,10 +349,16 @@ function routeShape(hook, handler, root) {
|
|
|
396
349
|
config?.abortSignal !== false,
|
|
397
350
|
require_utils.isNotEmpty(frozenRoot["~ext"]?.headers),
|
|
398
351
|
!!(config?.adapter ?? require_adapter_constants.defaultAdapter).response.supportsDefaultHeaderSink,
|
|
399
|
-
!!require_handler_utils.returnedErrorClasses(hook
|
|
352
|
+
!!require_handler_utils.returnedErrorClasses(hook)
|
|
400
353
|
]) + shape(config?.sanitize);
|
|
401
354
|
return unsupported ? void 0 : require_utils.fnv1a(s);
|
|
402
355
|
}
|
|
356
|
+
const throwsOnCall = (error) => () => {
|
|
357
|
+
throw error;
|
|
358
|
+
};
|
|
359
|
+
const htmlBundleHandler = (method, path) => () => {
|
|
360
|
+
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
361
|
+
};
|
|
403
362
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
404
363
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
405
364
|
function compileHandler(route, root, liveOnly = false) {
|
|
@@ -421,6 +380,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
421
380
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
422
381
|
if (hook) {
|
|
423
382
|
promoteDerive(hook);
|
|
383
|
+
runIntrospect(hook);
|
|
424
384
|
toArray("parse", hook);
|
|
425
385
|
toArray("transform", hook);
|
|
426
386
|
toArray("beforeHandle", hook);
|
|
@@ -428,17 +388,14 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
428
388
|
toArray("mapResponse", hook);
|
|
429
389
|
toArray("afterResponse", hook);
|
|
430
390
|
toArray("error", hook);
|
|
391
|
+
toArray("handler", hook);
|
|
431
392
|
}
|
|
432
|
-
const buildValidator = () => hook ? require_compile_handler_reconstruct.
|
|
433
|
-
const errorClasses = require_handler_utils.returnedErrorClasses(hook
|
|
434
|
-
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C))
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
} else if (require_utils.isHTMLBundle(handler)) handler = () => {
|
|
440
|
-
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
441
|
-
};
|
|
393
|
+
const buildValidator = () => hook ? require_compile_handler_reconstruct.Reconstruct.validator(hook, root, method, path, liveOnly) : void 0;
|
|
394
|
+
const errorClasses = require_handler_utils.returnedErrorClasses(hook);
|
|
395
|
+
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) handler = throwsOnCall(handler);
|
|
396
|
+
else if (require_utils.isHTMLBundle(handler)) handler = htmlBundleHandler(method, path);
|
|
397
|
+
const wrappers = hook?.handler;
|
|
398
|
+
if (wrappers && typeof handler === "function") for (let i = wrappers.length - 1; i >= 0; i--) handler = wrappers[i](handler);
|
|
442
399
|
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
443
400
|
const isHandleFunction = typeof handler === "function";
|
|
444
401
|
if (!isHandleFunction && !(handler instanceof Promise) && !(!require_universal_constants.isBun && handler instanceof require_universal_file.ElysiaFile) && !declaresResponse) {
|
|
@@ -463,7 +420,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
463
420
|
try {
|
|
464
421
|
live = compileHandler(route, root, true);
|
|
465
422
|
} catch (cause) {
|
|
466
|
-
throw new Error(require_compile_aot.
|
|
423
|
+
throw new Error(require_compile_aot.aotDriftMessage(method, path), { cause });
|
|
467
424
|
}
|
|
468
425
|
require_compile_aot.warnAotDrift(method, path);
|
|
469
426
|
return live;
|
|
@@ -474,9 +431,9 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
474
431
|
parse: adapter.parse,
|
|
475
432
|
res: adapter.response,
|
|
476
433
|
hook: hook ?? require_utils.nullObject(),
|
|
477
|
-
vali: reconstructed.a.
|
|
478
|
-
cookieConfig: reconstructed.a.includes("cc") ? require_compile_handler_reconstruct.
|
|
479
|
-
tracers: reconstructed.a.includes("tr") ? require_compile_handler_reconstruct.
|
|
434
|
+
vali: reconstructed.a.some((name) => name === "va" || require_compile_handler_params.isResponseParam(name)) ? buildValidator() : void 0,
|
|
435
|
+
cookieConfig: reconstructed.a.includes("cc") ? require_compile_handler_reconstruct.Reconstruct.cookie(hook, root) : void 0,
|
|
436
|
+
tracers: reconstructed.a.includes("tr") ? require_compile_handler_reconstruct.Reconstruct.trace(hook, root) : void 0
|
|
480
437
|
}));
|
|
481
438
|
if (hook === void 0 && !errorClasses && isHandleFunction && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !require_utils.isNotEmpty(frozenRoot["~ext"]?.headers) && !require_compile_aot.Capture.isAotBuildEnv() && !require_compile_aot.Capture.isCapturing()) {
|
|
482
439
|
let isContextFree = false;
|
|
@@ -532,7 +489,9 @@ exports.clearHandlerAnalysisCaches = clearHandlerAnalysisCaches;
|
|
|
532
489
|
exports.compileHandler = compileHandler;
|
|
533
490
|
exports.composeRouteHook = composeRouteHook;
|
|
534
491
|
exports.localMacroRoot = localMacroRoot;
|
|
492
|
+
exports.releaseAnalysisCaches = require_compile_handler_descriptor.releaseAnalysisCaches;
|
|
535
493
|
exports.resolveLocalHook = resolveLocalHook;
|
|
536
494
|
exports.resolveWSLocalHook = resolveWSLocalHook;
|
|
537
495
|
exports.routeShape = routeShape;
|
|
496
|
+
exports.runIntrospect = runIntrospect;
|
|
538
497
|
exports.setCaptureHeaderShorthand = require_compile_handler_jit.setCaptureHeaderShorthand;
|
|
@@ -1,79 +1,33 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { isBun } from "../../universal/constants.mjs";
|
|
2
3
|
import { ElysiaFile } from "../../universal/file.mjs";
|
|
3
|
-
import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys,
|
|
4
|
+
import { cloneHook, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, flattenChain, flattenChainInfo, flattenChainMemo, flattenChainMemoReadonly, fnv1a, isCompactBeforeHandleOnly, isHTMLBundle, isNotEmpty, macroEpoch, mergeHook, nullObject, refTargets, replaceUrlPath } from "../../utils.mjs";
|
|
4
5
|
import { ElysiaStatus } from "../../error.mjs";
|
|
5
6
|
import { mapResponse } from "../../adapter/web-standard/handler.mjs";
|
|
6
|
-
import { Capture, Compiled,
|
|
7
|
+
import { Capture, Compiled, aotDriftMessage, warnAotDrift } from "../aot.mjs";
|
|
7
8
|
import { frozenRootOf } from "../../generation.mjs";
|
|
8
9
|
import { isAsyncFunction } from "../utils.mjs";
|
|
9
10
|
import { returnedErrorClasses } from "../../handler/utils.mjs";
|
|
10
|
-
import { deriveModes } from "./utils.mjs";
|
|
11
|
-
import { resolveHandlerParams } from "./params.mjs";
|
|
11
|
+
import { deriveModes, joinDeriveEntries } from "./utils.mjs";
|
|
12
|
+
import { isResponseParam, resolveHandlerParams } from "./params.mjs";
|
|
12
13
|
import { compileHandlerJit, createInlineHandler, setCaptureHeaderShorthand } from "./jit.mjs";
|
|
13
14
|
import { isResponseMap } from "./frozen-validator.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import { describeRoute, routeDescriptors } from "./descriptor.mjs";
|
|
15
|
+
import { Reconstruct } from "./reconstruct.mjs";
|
|
16
|
+
import { describeRoute, releaseAnalysisCaches, routeDescriptors } from "./descriptor.mjs";
|
|
16
17
|
import { defaultAdapter } from "../../adapter/constants.mjs";
|
|
17
18
|
|
|
18
19
|
//#region src/compile/handler/index.ts
|
|
19
20
|
function applyHook(localHook, appHook, rootHook) {
|
|
20
21
|
let hook;
|
|
21
|
-
if (localHook && appHook) hook = mergeHook(cloneHook(localHook), appHook
|
|
22
|
+
if (localHook && appHook) hook = mergeHook(cloneHook(localHook), appHook);
|
|
22
23
|
else {
|
|
23
24
|
const base = localHook ? cloneHook(localHook) : appHook;
|
|
24
25
|
if (!rootHook) return base;
|
|
25
26
|
hook = base ?? nullObject();
|
|
26
27
|
}
|
|
27
|
-
if (rootHook) mergeHook(hook, rootHook
|
|
28
|
+
if (rootHook) mergeHook(hook, rootHook);
|
|
28
29
|
return hook;
|
|
29
30
|
}
|
|
30
|
-
function collectHookOrigins(hook, into) {
|
|
31
|
-
if (!hook) return into;
|
|
32
|
-
for (const key in hook) {
|
|
33
|
-
if (!eventProperties.has(key)) continue;
|
|
34
|
-
const v = hook[key];
|
|
35
|
-
if (!v) continue;
|
|
36
|
-
if (Array.isArray(v)) for (const fn of v) {
|
|
37
|
-
const origin = fnOrigin.get(fn);
|
|
38
|
-
if (origin !== void 0) (into ??= /* @__PURE__ */ new Set()).add(origin);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const origin = fnOrigin.get(v);
|
|
42
|
-
if (origin !== void 0) (into ??= /* @__PURE__ */ new Set()).add(origin);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return into;
|
|
46
|
-
}
|
|
47
|
-
function dropHooksByOrigin(hook, skip) {
|
|
48
|
-
let out = hook;
|
|
49
|
-
for (const key in hook) {
|
|
50
|
-
if (!eventProperties.has(key)) continue;
|
|
51
|
-
const v = hook[key];
|
|
52
|
-
if (!v) continue;
|
|
53
|
-
if (Array.isArray(v)) {
|
|
54
|
-
let kept;
|
|
55
|
-
for (let i = 0; i < v.length; i++) {
|
|
56
|
-
const fn = v[i];
|
|
57
|
-
const origin = fnOrigin.get(fn);
|
|
58
|
-
const keep = origin === void 0 || !skip.has(origin);
|
|
59
|
-
if (kept) {
|
|
60
|
-
if (keep) kept.push(fn);
|
|
61
|
-
} else if (!keep) kept = v.slice(0, i);
|
|
62
|
-
}
|
|
63
|
-
if (kept) {
|
|
64
|
-
if (out === hook) out = { ...hook };
|
|
65
|
-
out[key] = kept;
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
const origin = fnOrigin.get(v);
|
|
69
|
-
if (origin !== void 0 && skip.has(origin)) {
|
|
70
|
-
if (out === hook) out = { ...hook };
|
|
71
|
-
out[key] = [];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
31
|
function promoteDerive(hook) {
|
|
78
32
|
const derive = hook.derive;
|
|
79
33
|
if (derive === void 0) return;
|
|
@@ -86,6 +40,12 @@ function promoteDerive(hook) {
|
|
|
86
40
|
}
|
|
87
41
|
hook.derive = void 0;
|
|
88
42
|
}
|
|
43
|
+
function runIntrospect(hook) {
|
|
44
|
+
const introspects = hook?.["~introspect"];
|
|
45
|
+
if (!introspects) return;
|
|
46
|
+
for (let i = 0; i < introspects.length; i++) introspects[i](hook);
|
|
47
|
+
delete hook["~introspect"];
|
|
48
|
+
}
|
|
89
49
|
function memoScope(memos, root, scope) {
|
|
90
50
|
let bucket = memos.get(root);
|
|
91
51
|
if (!bucket || bucket.e !== macroEpoch()) {
|
|
@@ -135,9 +95,10 @@ function resolveLocalHook(scope, hook, root = scope) {
|
|
|
135
95
|
}
|
|
136
96
|
function resolveWSLocalHook(scope, hook, root = scope) {
|
|
137
97
|
const resolved = resolveLocalHook(scope, hook, root);
|
|
138
|
-
if (!resolved || resolved.derive === void 0) return resolved;
|
|
98
|
+
if (!resolved || resolved.derive === void 0 && !resolved["~introspect"]) return resolved;
|
|
139
99
|
const owned = cloneHook(resolved);
|
|
140
100
|
promoteDerive(owned);
|
|
101
|
+
runIntrospect(owned);
|
|
141
102
|
return owned;
|
|
142
103
|
}
|
|
143
104
|
const chainNodeMemos = /* @__PURE__ */ new WeakMap();
|
|
@@ -164,6 +125,7 @@ function resolveChainNode(root, node) {
|
|
|
164
125
|
resolved = cloneHook(added);
|
|
165
126
|
if (needsMacro) applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
166
127
|
promoteDerive(resolved);
|
|
128
|
+
runIntrospect(resolved);
|
|
167
129
|
perScope.set(added, resolved);
|
|
168
130
|
}
|
|
169
131
|
return resolved;
|
|
@@ -190,17 +152,6 @@ function mapStaticValue(response, map, set, value) {
|
|
|
190
152
|
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
153
|
return mapped;
|
|
192
154
|
}
|
|
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
155
|
function buildNativeStaticResponse(route, root) {
|
|
205
156
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
206
157
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -208,20 +159,10 @@ function buildNativeStaticResponse(route, root) {
|
|
|
208
159
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
209
160
|
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
210
161
|
const resolve = chainResolver(root);
|
|
211
|
-
const
|
|
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);
|
|
162
|
+
const hook = applyHook(ownedHook, flattenChainMemo(root, appHook, resolve), instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0);
|
|
223
163
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
224
|
-
|
|
164
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
165
|
+
if (returnedErrorClasses({ error: withCallbackErrors(hook?.error, callback ?? []) })?.some((C) => handler instanceof C)) return;
|
|
225
166
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
226
167
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
227
168
|
const response = adapter.response;
|
|
@@ -238,44 +179,57 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
238
179
|
localHook = cloneHook(localHook);
|
|
239
180
|
promoteDerive(localHook);
|
|
240
181
|
}
|
|
241
|
-
const
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
182
|
+
const own = flattenChainInfo(root, appHook, resolve);
|
|
183
|
+
let skip;
|
|
184
|
+
if (own?.installs && instance !== root) {
|
|
185
|
+
const outer = flattenChainInfo(root, inheritedChain, resolve)?.installs;
|
|
186
|
+
if (outer && !outer.isDisjointFrom(own.installs)) skip = outer;
|
|
187
|
+
}
|
|
188
|
+
const flatAppHook = flattenChainMemo(root, appHook, resolve, skip);
|
|
189
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
190
|
+
const compactPrefix = allowCompactPrefix && instance !== root && !Capture.isCapturing() && !Capture.isAotBuildEnv() && resolve === void 0 && isCompactBeforeHandleOnly(localHook) && isCompactBeforeHandleOnly(flatAppHook) && !callback ? compactBeforeHandlePrefix(inheritedChain) : void 0;
|
|
191
|
+
if (compactPrefix && !own?.named && !compactBeforeHandleConflicts(localHook) && !compactBeforeHandleConflicts(flatAppHook)) {
|
|
248
192
|
let hook = applyHook(localHook, flatAppHook, void 0);
|
|
249
|
-
if (locals) hook = hook ? mergeHook(hook, locals, false, true) : locals;
|
|
250
193
|
hook ??= nullObject();
|
|
251
194
|
hook["~beforeHandlePrefix"] = compactPrefix;
|
|
252
195
|
return hook;
|
|
253
196
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
197
|
+
const inherited = instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
|
|
198
|
+
const deriveEntries = joinDeriveEntries([
|
|
199
|
+
inherited,
|
|
200
|
+
flatAppHook,
|
|
201
|
+
localHook
|
|
202
|
+
]);
|
|
261
203
|
let hook = applyHook(localHook, flatAppHook, inherited ? cloneHook(inherited) : void 0);
|
|
262
|
-
if (
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (errors) {
|
|
267
|
-
hook ??= nullObject();
|
|
268
|
-
let existing = hook.error;
|
|
269
|
-
if (existing) {
|
|
270
|
-
if (!Array.isArray(existing)) existing = hook.error = [existing];
|
|
271
|
-
if (Array.isArray(errors)) {
|
|
272
|
-
for (const fn of errors) if (!existing.includes(fn)) existing.push(fn);
|
|
273
|
-
} else if (!existing.includes(errors)) existing.push(errors);
|
|
274
|
-
} else hook.error = Array.isArray(errors) ? errors.slice() : [errors];
|
|
275
|
-
}
|
|
204
|
+
if (deriveEntries) hook["~deriveEntries"] = deriveEntries;
|
|
205
|
+
if (callback) {
|
|
206
|
+
hook ??= nullObject();
|
|
207
|
+
hook.error = withCallbackErrors(hook.error, callback);
|
|
276
208
|
}
|
|
277
209
|
return hook;
|
|
278
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Error hooks of the `.group()`/`.guard()` callbacks a route came out of
|
|
213
|
+
* innermost first (see `ChainNode`)
|
|
214
|
+
*/
|
|
215
|
+
function callbackErrors(start, appHook, root, resolve) {
|
|
216
|
+
let out;
|
|
217
|
+
let outer = null;
|
|
218
|
+
for (let node = start; node && "combine" in node; node = node.combine) if (node.callback) {
|
|
219
|
+
if (outer === null) outer = flattenChainInfo(root, start, resolve)?.installs;
|
|
220
|
+
if (!flattenChainMemoReadonly(root, node.callback, resolve, outer)?.error) continue;
|
|
221
|
+
const has = /* @__PURE__ */ new Set();
|
|
222
|
+
const collect = (n) => {
|
|
223
|
+
has.add(n.registration ?? n);
|
|
224
|
+
};
|
|
225
|
+
flattenChain(node.inner, collect);
|
|
226
|
+
flattenChain(appHook, collect);
|
|
227
|
+
const error = flattenChain(node.callback, (n) => has.has(n.registration ?? n) ? void 0 : resolve ? resolve(n) : n.added, outer)?.error;
|
|
228
|
+
if (error) out = [].concat(error, out ?? []);
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
const withCallbackErrors = (own, callback) => [].concat(own ?? [], callback);
|
|
279
233
|
const shapeEvents = [
|
|
280
234
|
"parse",
|
|
281
235
|
"transform",
|
|
@@ -395,10 +349,16 @@ function routeShape(hook, handler, root) {
|
|
|
395
349
|
config?.abortSignal !== false,
|
|
396
350
|
isNotEmpty(frozenRoot["~ext"]?.headers),
|
|
397
351
|
!!(config?.adapter ?? defaultAdapter).response.supportsDefaultHeaderSink,
|
|
398
|
-
!!returnedErrorClasses(hook
|
|
352
|
+
!!returnedErrorClasses(hook)
|
|
399
353
|
]) + shape(config?.sanitize);
|
|
400
354
|
return unsupported ? void 0 : fnv1a(s);
|
|
401
355
|
}
|
|
356
|
+
const throwsOnCall = (error) => () => {
|
|
357
|
+
throw error;
|
|
358
|
+
};
|
|
359
|
+
const htmlBundleHandler = (method, path) => () => {
|
|
360
|
+
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
361
|
+
};
|
|
402
362
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
403
363
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
404
364
|
function compileHandler(route, root, liveOnly = false) {
|
|
@@ -420,6 +380,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
420
380
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
421
381
|
if (hook) {
|
|
422
382
|
promoteDerive(hook);
|
|
383
|
+
runIntrospect(hook);
|
|
423
384
|
toArray("parse", hook);
|
|
424
385
|
toArray("transform", hook);
|
|
425
386
|
toArray("beforeHandle", hook);
|
|
@@ -427,17 +388,14 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
427
388
|
toArray("mapResponse", hook);
|
|
428
389
|
toArray("afterResponse", hook);
|
|
429
390
|
toArray("error", hook);
|
|
391
|
+
toArray("handler", hook);
|
|
430
392
|
}
|
|
431
|
-
const buildValidator = () => hook ?
|
|
432
|
-
const errorClasses = returnedErrorClasses(hook
|
|
433
|
-
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C))
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
};
|
|
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
|
-
};
|
|
393
|
+
const buildValidator = () => hook ? Reconstruct.validator(hook, root, method, path, liveOnly) : void 0;
|
|
394
|
+
const errorClasses = returnedErrorClasses(hook);
|
|
395
|
+
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) handler = throwsOnCall(handler);
|
|
396
|
+
else if (isHTMLBundle(handler)) handler = htmlBundleHandler(method, path);
|
|
397
|
+
const wrappers = hook?.handler;
|
|
398
|
+
if (wrappers && typeof handler === "function") for (let i = wrappers.length - 1; i >= 0; i--) handler = wrappers[i](handler);
|
|
441
399
|
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
442
400
|
const isHandleFunction = typeof handler === "function";
|
|
443
401
|
if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile) && !declaresResponse) {
|
|
@@ -462,7 +420,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
462
420
|
try {
|
|
463
421
|
live = compileHandler(route, root, true);
|
|
464
422
|
} catch (cause) {
|
|
465
|
-
throw new Error(
|
|
423
|
+
throw new Error(aotDriftMessage(method, path), { cause });
|
|
466
424
|
}
|
|
467
425
|
warnAotDrift(method, path);
|
|
468
426
|
return live;
|
|
@@ -473,9 +431,9 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
473
431
|
parse: adapter.parse,
|
|
474
432
|
res: adapter.response,
|
|
475
433
|
hook: hook ?? nullObject(),
|
|
476
|
-
vali: reconstructed.a.
|
|
477
|
-
cookieConfig: reconstructed.a.includes("cc") ?
|
|
478
|
-
tracers: reconstructed.a.includes("tr") ?
|
|
434
|
+
vali: reconstructed.a.some((name) => name === "va" || isResponseParam(name)) ? buildValidator() : void 0,
|
|
435
|
+
cookieConfig: reconstructed.a.includes("cc") ? Reconstruct.cookie(hook, root) : void 0,
|
|
436
|
+
tracers: reconstructed.a.includes("tr") ? Reconstruct.trace(hook, root) : void 0
|
|
479
437
|
}));
|
|
480
438
|
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
439
|
let isContextFree = false;
|
|
@@ -525,4 +483,4 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
525
483
|
}
|
|
526
484
|
|
|
527
485
|
//#endregion
|
|
528
|
-
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, routeShape, setCaptureHeaderShorthand };
|
|
486
|
+
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, releaseAnalysisCaches, resolveLocalHook, resolveWSLocalHook, routeShape, runIntrospect, setCaptureHeaderShorthand };
|