elysia 2.0.0-beta.21 → 2.0.0-beta.23
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 +214 -194
- package/dist/base.mjs +221 -200
- 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 +78 -118
- package/dist/compile/handler/index.mjs +84 -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.d.ts +1 -1
- 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.js +28 -3
- package/dist/schema-snapshot.mjs +29 -3
- 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 +108 -70
- 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,13 @@ 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
|
+
if (hook.response && require_utils.isRecordNumber(hook.response)) hook.response = { ...hook.response };
|
|
47
|
+
for (let i = 0; i < introspects.length; i++) introspects[i](hook);
|
|
48
|
+
delete hook["~introspect"];
|
|
49
|
+
}
|
|
90
50
|
function memoScope(memos, root, scope) {
|
|
91
51
|
let bucket = memos.get(root);
|
|
92
52
|
if (!bucket || bucket.e !== require_utils.macroEpoch()) {
|
|
@@ -136,9 +96,10 @@ function resolveLocalHook(scope, hook, root = scope) {
|
|
|
136
96
|
}
|
|
137
97
|
function resolveWSLocalHook(scope, hook, root = scope) {
|
|
138
98
|
const resolved = resolveLocalHook(scope, hook, root);
|
|
139
|
-
if (!resolved || resolved.derive === void 0) return resolved;
|
|
99
|
+
if (!resolved || resolved.derive === void 0 && !resolved["~introspect"]) return resolved;
|
|
140
100
|
const owned = require_utils.cloneHook(resolved);
|
|
141
101
|
promoteDerive(owned);
|
|
102
|
+
runIntrospect(owned);
|
|
142
103
|
return owned;
|
|
143
104
|
}
|
|
144
105
|
const chainNodeMemos = /* @__PURE__ */ new WeakMap();
|
|
@@ -165,6 +126,7 @@ function resolveChainNode(root, node) {
|
|
|
165
126
|
resolved = require_utils.cloneHook(added);
|
|
166
127
|
if (needsMacro) applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
167
128
|
promoteDerive(resolved);
|
|
129
|
+
runIntrospect(resolved);
|
|
168
130
|
perScope.set(added, resolved);
|
|
169
131
|
}
|
|
170
132
|
return resolved;
|
|
@@ -191,17 +153,6 @@ function mapStaticValue(response, map, set, value) {
|
|
|
191
153
|
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
154
|
return mapped;
|
|
193
155
|
}
|
|
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
156
|
function buildNativeStaticResponse(route, root) {
|
|
206
157
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
207
158
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -209,20 +160,10 @@ function buildNativeStaticResponse(route, root) {
|
|
|
209
160
|
const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
210
161
|
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
211
162
|
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);
|
|
163
|
+
const hook = applyHook(ownedHook, require_utils.flattenChainMemo(root, appHook, resolve), instance !== root ? require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0);
|
|
224
164
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
225
|
-
|
|
165
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
166
|
+
if (require_handler_utils.returnedErrorClasses({ error: withCallbackErrors(hook?.error, callback ?? []) })?.some((C) => handler instanceof C)) return;
|
|
226
167
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
227
168
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
228
169
|
const response = adapter.response;
|
|
@@ -239,44 +180,57 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
239
180
|
localHook = require_utils.cloneHook(localHook);
|
|
240
181
|
promoteDerive(localHook);
|
|
241
182
|
}
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
183
|
+
const own = require_utils.flattenChainInfo(root, appHook, resolve);
|
|
184
|
+
let skip;
|
|
185
|
+
if (own?.installs && instance !== root) {
|
|
186
|
+
const outer = require_utils.flattenChainInfo(root, inheritedChain, resolve)?.installs;
|
|
187
|
+
if (outer && !outer.isDisjointFrom(own.installs)) skip = outer;
|
|
188
|
+
}
|
|
189
|
+
const flatAppHook = require_utils.flattenChainMemo(root, appHook, resolve, skip);
|
|
190
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
191
|
+
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;
|
|
192
|
+
if (compactPrefix && !own?.named && !require_utils.compactBeforeHandleConflicts(localHook) && !require_utils.compactBeforeHandleConflicts(flatAppHook)) {
|
|
249
193
|
let hook = applyHook(localHook, flatAppHook, void 0);
|
|
250
|
-
if (locals) hook = hook ? require_utils.mergeHook(hook, locals, false, true) : locals;
|
|
251
194
|
hook ??= require_utils.nullObject();
|
|
252
195
|
hook["~beforeHandlePrefix"] = compactPrefix;
|
|
253
196
|
return hook;
|
|
254
197
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
198
|
+
const inherited = instance !== root ? require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
|
|
199
|
+
const deriveEntries = require_compile_handler_utils.joinDeriveEntries([
|
|
200
|
+
inherited,
|
|
201
|
+
flatAppHook,
|
|
202
|
+
localHook
|
|
203
|
+
]);
|
|
262
204
|
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
|
-
}
|
|
205
|
+
if (deriveEntries) hook["~deriveEntries"] = deriveEntries;
|
|
206
|
+
if (callback) {
|
|
207
|
+
hook ??= require_utils.nullObject();
|
|
208
|
+
hook.error = withCallbackErrors(hook.error, callback);
|
|
277
209
|
}
|
|
278
210
|
return hook;
|
|
279
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Error hooks of the `.group()`/`.guard()` callbacks a route came out of
|
|
214
|
+
* innermost first (see `ChainNode`)
|
|
215
|
+
*/
|
|
216
|
+
function callbackErrors(start, appHook, root, resolve) {
|
|
217
|
+
let out;
|
|
218
|
+
let outer = null;
|
|
219
|
+
for (let node = start; node && "combine" in node; node = node.combine) if (node.callback) {
|
|
220
|
+
if (outer === null) outer = require_utils.flattenChainInfo(root, start, resolve)?.installs;
|
|
221
|
+
if (!require_utils.flattenChainMemoReadonly(root, node.callback, resolve, outer)?.error) continue;
|
|
222
|
+
const has = /* @__PURE__ */ new Set();
|
|
223
|
+
const collect = (n) => {
|
|
224
|
+
has.add(n.registration ?? n);
|
|
225
|
+
};
|
|
226
|
+
require_utils.flattenChain(node.inner, collect);
|
|
227
|
+
require_utils.flattenChain(appHook, collect);
|
|
228
|
+
const error = require_utils.flattenChain(node.callback, (n) => has.has(n.registration ?? n) ? void 0 : resolve ? resolve(n) : n.added, outer)?.error;
|
|
229
|
+
if (error) out = [].concat(error, out ?? []);
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
const withCallbackErrors = (own, callback) => [].concat(own ?? [], callback);
|
|
280
234
|
const shapeEvents = [
|
|
281
235
|
"parse",
|
|
282
236
|
"transform",
|
|
@@ -396,10 +350,16 @@ function routeShape(hook, handler, root) {
|
|
|
396
350
|
config?.abortSignal !== false,
|
|
397
351
|
require_utils.isNotEmpty(frozenRoot["~ext"]?.headers),
|
|
398
352
|
!!(config?.adapter ?? require_adapter_constants.defaultAdapter).response.supportsDefaultHeaderSink,
|
|
399
|
-
!!require_handler_utils.returnedErrorClasses(hook
|
|
353
|
+
!!require_handler_utils.returnedErrorClasses(hook)
|
|
400
354
|
]) + shape(config?.sanitize);
|
|
401
355
|
return unsupported ? void 0 : require_utils.fnv1a(s);
|
|
402
356
|
}
|
|
357
|
+
const throwsOnCall = (error) => () => {
|
|
358
|
+
throw error;
|
|
359
|
+
};
|
|
360
|
+
const htmlBundleHandler = (method, path) => () => {
|
|
361
|
+
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
362
|
+
};
|
|
403
363
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
404
364
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
405
365
|
function compileHandler(route, root, liveOnly = false) {
|
|
@@ -421,6 +381,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
421
381
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
422
382
|
if (hook) {
|
|
423
383
|
promoteDerive(hook);
|
|
384
|
+
runIntrospect(hook);
|
|
424
385
|
toArray("parse", hook);
|
|
425
386
|
toArray("transform", hook);
|
|
426
387
|
toArray("beforeHandle", hook);
|
|
@@ -428,17 +389,14 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
428
389
|
toArray("mapResponse", hook);
|
|
429
390
|
toArray("afterResponse", hook);
|
|
430
391
|
toArray("error", hook);
|
|
392
|
+
toArray("handler", hook);
|
|
431
393
|
}
|
|
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
|
-
};
|
|
394
|
+
const buildValidator = () => hook ? require_compile_handler_reconstruct.Reconstruct.validator(hook, root, method, path, liveOnly) : void 0;
|
|
395
|
+
const errorClasses = require_handler_utils.returnedErrorClasses(hook);
|
|
396
|
+
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) handler = throwsOnCall(handler);
|
|
397
|
+
else if (require_utils.isHTMLBundle(handler)) handler = htmlBundleHandler(method, path);
|
|
398
|
+
const wrappers = hook?.handler;
|
|
399
|
+
if (wrappers && typeof handler === "function") for (let i = wrappers.length - 1; i >= 0; i--) handler = wrappers[i](handler);
|
|
442
400
|
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
443
401
|
const isHandleFunction = typeof handler === "function";
|
|
444
402
|
if (!isHandleFunction && !(handler instanceof Promise) && !(!require_universal_constants.isBun && handler instanceof require_universal_file.ElysiaFile) && !declaresResponse) {
|
|
@@ -463,7 +421,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
463
421
|
try {
|
|
464
422
|
live = compileHandler(route, root, true);
|
|
465
423
|
} catch (cause) {
|
|
466
|
-
throw new Error(require_compile_aot.
|
|
424
|
+
throw new Error(require_compile_aot.aotDriftMessage(method, path), { cause });
|
|
467
425
|
}
|
|
468
426
|
require_compile_aot.warnAotDrift(method, path);
|
|
469
427
|
return live;
|
|
@@ -474,9 +432,9 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
474
432
|
parse: adapter.parse,
|
|
475
433
|
res: adapter.response,
|
|
476
434
|
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.
|
|
435
|
+
vali: reconstructed.a.some((name) => name === "va" || require_compile_handler_params.isResponseParam(name)) ? buildValidator() : void 0,
|
|
436
|
+
cookieConfig: reconstructed.a.includes("cc") ? require_compile_handler_reconstruct.Reconstruct.cookie(hook, root) : void 0,
|
|
437
|
+
tracers: reconstructed.a.includes("tr") ? require_compile_handler_reconstruct.Reconstruct.trace(hook, root) : void 0
|
|
480
438
|
}));
|
|
481
439
|
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
440
|
let isContextFree = false;
|
|
@@ -532,7 +490,9 @@ exports.clearHandlerAnalysisCaches = clearHandlerAnalysisCaches;
|
|
|
532
490
|
exports.compileHandler = compileHandler;
|
|
533
491
|
exports.composeRouteHook = composeRouteHook;
|
|
534
492
|
exports.localMacroRoot = localMacroRoot;
|
|
493
|
+
exports.releaseAnalysisCaches = require_compile_handler_descriptor.releaseAnalysisCaches;
|
|
535
494
|
exports.resolveLocalHook = resolveLocalHook;
|
|
536
495
|
exports.resolveWSLocalHook = resolveWSLocalHook;
|
|
537
496
|
exports.routeShape = routeShape;
|
|
497
|
+
exports.runIntrospect = runIntrospect;
|
|
538
498
|
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, isRecordNumber, 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,13 @@ 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
|
+
if (hook.response && isRecordNumber(hook.response)) hook.response = { ...hook.response };
|
|
47
|
+
for (let i = 0; i < introspects.length; i++) introspects[i](hook);
|
|
48
|
+
delete hook["~introspect"];
|
|
49
|
+
}
|
|
89
50
|
function memoScope(memos, root, scope) {
|
|
90
51
|
let bucket = memos.get(root);
|
|
91
52
|
if (!bucket || bucket.e !== macroEpoch()) {
|
|
@@ -135,9 +96,10 @@ function resolveLocalHook(scope, hook, root = scope) {
|
|
|
135
96
|
}
|
|
136
97
|
function resolveWSLocalHook(scope, hook, root = scope) {
|
|
137
98
|
const resolved = resolveLocalHook(scope, hook, root);
|
|
138
|
-
if (!resolved || resolved.derive === void 0) return resolved;
|
|
99
|
+
if (!resolved || resolved.derive === void 0 && !resolved["~introspect"]) return resolved;
|
|
139
100
|
const owned = cloneHook(resolved);
|
|
140
101
|
promoteDerive(owned);
|
|
102
|
+
runIntrospect(owned);
|
|
141
103
|
return owned;
|
|
142
104
|
}
|
|
143
105
|
const chainNodeMemos = /* @__PURE__ */ new WeakMap();
|
|
@@ -164,6 +126,7 @@ function resolveChainNode(root, node) {
|
|
|
164
126
|
resolved = cloneHook(added);
|
|
165
127
|
if (needsMacro) applyMacros(resolved, scope, frozenRoot, scopeMacro, rootMacro);
|
|
166
128
|
promoteDerive(resolved);
|
|
129
|
+
runIntrospect(resolved);
|
|
167
130
|
perScope.set(added, resolved);
|
|
168
131
|
}
|
|
169
132
|
return resolved;
|
|
@@ -190,17 +153,6 @@ function mapStaticValue(response, map, set, value) {
|
|
|
190
153
|
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
154
|
return mapped;
|
|
192
155
|
}
|
|
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
156
|
function buildNativeStaticResponse(route, root) {
|
|
205
157
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
206
158
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -208,20 +160,10 @@ function buildNativeStaticResponse(route, root) {
|
|
|
208
160
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
209
161
|
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
210
162
|
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);
|
|
163
|
+
const hook = applyHook(ownedHook, flattenChainMemo(root, appHook, resolve), instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0);
|
|
223
164
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
224
|
-
|
|
165
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
166
|
+
if (returnedErrorClasses({ error: withCallbackErrors(hook?.error, callback ?? []) })?.some((C) => handler instanceof C)) return;
|
|
225
167
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
226
168
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
227
169
|
const response = adapter.response;
|
|
@@ -238,44 +180,57 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
238
180
|
localHook = cloneHook(localHook);
|
|
239
181
|
promoteDerive(localHook);
|
|
240
182
|
}
|
|
241
|
-
const
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
183
|
+
const own = flattenChainInfo(root, appHook, resolve);
|
|
184
|
+
let skip;
|
|
185
|
+
if (own?.installs && instance !== root) {
|
|
186
|
+
const outer = flattenChainInfo(root, inheritedChain, resolve)?.installs;
|
|
187
|
+
if (outer && !outer.isDisjointFrom(own.installs)) skip = outer;
|
|
188
|
+
}
|
|
189
|
+
const flatAppHook = flattenChainMemo(root, appHook, resolve, skip);
|
|
190
|
+
const callback = instance !== root ? callbackErrors(inheritedChain, appHook, root, resolve) : void 0;
|
|
191
|
+
const compactPrefix = allowCompactPrefix && instance !== root && !Capture.isCapturing() && !Capture.isAotBuildEnv() && resolve === void 0 && isCompactBeforeHandleOnly(localHook) && isCompactBeforeHandleOnly(flatAppHook) && !callback ? compactBeforeHandlePrefix(inheritedChain) : void 0;
|
|
192
|
+
if (compactPrefix && !own?.named && !compactBeforeHandleConflicts(localHook) && !compactBeforeHandleConflicts(flatAppHook)) {
|
|
248
193
|
let hook = applyHook(localHook, flatAppHook, void 0);
|
|
249
|
-
if (locals) hook = hook ? mergeHook(hook, locals, false, true) : locals;
|
|
250
194
|
hook ??= nullObject();
|
|
251
195
|
hook["~beforeHandlePrefix"] = compactPrefix;
|
|
252
196
|
return hook;
|
|
253
197
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
198
|
+
const inherited = instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
|
|
199
|
+
const deriveEntries = joinDeriveEntries([
|
|
200
|
+
inherited,
|
|
201
|
+
flatAppHook,
|
|
202
|
+
localHook
|
|
203
|
+
]);
|
|
261
204
|
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
|
-
}
|
|
205
|
+
if (deriveEntries) hook["~deriveEntries"] = deriveEntries;
|
|
206
|
+
if (callback) {
|
|
207
|
+
hook ??= nullObject();
|
|
208
|
+
hook.error = withCallbackErrors(hook.error, callback);
|
|
276
209
|
}
|
|
277
210
|
return hook;
|
|
278
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Error hooks of the `.group()`/`.guard()` callbacks a route came out of
|
|
214
|
+
* innermost first (see `ChainNode`)
|
|
215
|
+
*/
|
|
216
|
+
function callbackErrors(start, appHook, root, resolve) {
|
|
217
|
+
let out;
|
|
218
|
+
let outer = null;
|
|
219
|
+
for (let node = start; node && "combine" in node; node = node.combine) if (node.callback) {
|
|
220
|
+
if (outer === null) outer = flattenChainInfo(root, start, resolve)?.installs;
|
|
221
|
+
if (!flattenChainMemoReadonly(root, node.callback, resolve, outer)?.error) continue;
|
|
222
|
+
const has = /* @__PURE__ */ new Set();
|
|
223
|
+
const collect = (n) => {
|
|
224
|
+
has.add(n.registration ?? n);
|
|
225
|
+
};
|
|
226
|
+
flattenChain(node.inner, collect);
|
|
227
|
+
flattenChain(appHook, collect);
|
|
228
|
+
const error = flattenChain(node.callback, (n) => has.has(n.registration ?? n) ? void 0 : resolve ? resolve(n) : n.added, outer)?.error;
|
|
229
|
+
if (error) out = [].concat(error, out ?? []);
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
const withCallbackErrors = (own, callback) => [].concat(own ?? [], callback);
|
|
279
234
|
const shapeEvents = [
|
|
280
235
|
"parse",
|
|
281
236
|
"transform",
|
|
@@ -395,10 +350,16 @@ function routeShape(hook, handler, root) {
|
|
|
395
350
|
config?.abortSignal !== false,
|
|
396
351
|
isNotEmpty(frozenRoot["~ext"]?.headers),
|
|
397
352
|
!!(config?.adapter ?? defaultAdapter).response.supportsDefaultHeaderSink,
|
|
398
|
-
!!returnedErrorClasses(hook
|
|
353
|
+
!!returnedErrorClasses(hook)
|
|
399
354
|
]) + shape(config?.sanitize);
|
|
400
355
|
return unsupported ? void 0 : fnv1a(s);
|
|
401
356
|
}
|
|
357
|
+
const throwsOnCall = (error) => () => {
|
|
358
|
+
throw error;
|
|
359
|
+
};
|
|
360
|
+
const htmlBundleHandler = (method, path) => () => {
|
|
361
|
+
throw new Error(`[Elysia] ${method} ${path} is an HTML bundle, only Bun's native router serves it`);
|
|
362
|
+
};
|
|
402
363
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
403
364
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
404
365
|
function compileHandler(route, root, liveOnly = false) {
|
|
@@ -420,6 +381,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
420
381
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
421
382
|
if (hook) {
|
|
422
383
|
promoteDerive(hook);
|
|
384
|
+
runIntrospect(hook);
|
|
423
385
|
toArray("parse", hook);
|
|
424
386
|
toArray("transform", hook);
|
|
425
387
|
toArray("beforeHandle", hook);
|
|
@@ -427,17 +389,14 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
427
389
|
toArray("mapResponse", hook);
|
|
428
390
|
toArray("afterResponse", hook);
|
|
429
391
|
toArray("error", hook);
|
|
392
|
+
toArray("handler", hook);
|
|
430
393
|
}
|
|
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
|
-
};
|
|
394
|
+
const buildValidator = () => hook ? Reconstruct.validator(hook, root, method, path, liveOnly) : void 0;
|
|
395
|
+
const errorClasses = returnedErrorClasses(hook);
|
|
396
|
+
if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) handler = throwsOnCall(handler);
|
|
397
|
+
else if (isHTMLBundle(handler)) handler = htmlBundleHandler(method, path);
|
|
398
|
+
const wrappers = hook?.handler;
|
|
399
|
+
if (wrappers && typeof handler === "function") for (let i = wrappers.length - 1; i >= 0; i--) handler = wrappers[i](handler);
|
|
441
400
|
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
442
401
|
const isHandleFunction = typeof handler === "function";
|
|
443
402
|
if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile) && !declaresResponse) {
|
|
@@ -462,7 +421,7 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
462
421
|
try {
|
|
463
422
|
live = compileHandler(route, root, true);
|
|
464
423
|
} catch (cause) {
|
|
465
|
-
throw new Error(
|
|
424
|
+
throw new Error(aotDriftMessage(method, path), { cause });
|
|
466
425
|
}
|
|
467
426
|
warnAotDrift(method, path);
|
|
468
427
|
return live;
|
|
@@ -473,9 +432,9 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
473
432
|
parse: adapter.parse,
|
|
474
433
|
res: adapter.response,
|
|
475
434
|
hook: hook ?? nullObject(),
|
|
476
|
-
vali: reconstructed.a.
|
|
477
|
-
cookieConfig: reconstructed.a.includes("cc") ?
|
|
478
|
-
tracers: reconstructed.a.includes("tr") ?
|
|
435
|
+
vali: reconstructed.a.some((name) => name === "va" || isResponseParam(name)) ? buildValidator() : void 0,
|
|
436
|
+
cookieConfig: reconstructed.a.includes("cc") ? Reconstruct.cookie(hook, root) : void 0,
|
|
437
|
+
tracers: reconstructed.a.includes("tr") ? Reconstruct.trace(hook, root) : void 0
|
|
479
438
|
}));
|
|
480
439
|
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
440
|
let isContextFree = false;
|
|
@@ -525,4 +484,4 @@ function compileHandler(route, root, liveOnly = false) {
|
|
|
525
484
|
}
|
|
526
485
|
|
|
527
486
|
//#endregion
|
|
528
|
-
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, routeShape, setCaptureHeaderShorthand };
|
|
487
|
+
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, releaseAnalysisCaches, resolveLocalHook, resolveWSLocalHook, routeShape, runIntrospect, setCaptureHeaderShorthand };
|