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.
Files changed (215) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  2. package/dist/adapter/bun/index.d.ts +6 -8
  3. package/dist/adapter/bun/index.js +6 -8
  4. package/dist/adapter/bun/index.mjs +7 -8
  5. package/dist/adapter/constants.mjs +1 -0
  6. package/dist/adapter/default-headers.mjs +1 -0
  7. package/dist/adapter/index.mjs +1 -0
  8. package/dist/adapter/origin.mjs +1 -0
  9. package/dist/adapter/response-ownership.mjs +1 -0
  10. package/dist/adapter/skip-clone.mjs +1 -0
  11. package/dist/adapter/types.mjs +1 -0
  12. package/dist/adapter/utils.d.ts +5 -8
  13. package/dist/adapter/utils.js +24 -18
  14. package/dist/adapter/utils.mjs +25 -18
  15. package/dist/adapter/web-standard/handler.mjs +2 -1
  16. package/dist/adapter/web-standard/index.mjs +1 -0
  17. package/dist/adapter/web-standard/utils.mjs +1 -0
  18. package/dist/base.d.ts +118 -69
  19. package/dist/base.js +213 -193
  20. package/dist/base.mjs +220 -199
  21. package/dist/compile/aot-capture.js +2 -2
  22. package/dist/compile/aot-capture.mjs +4 -3
  23. package/dist/compile/aot-emit.js +7 -8
  24. package/dist/compile/aot-emit.mjs +8 -8
  25. package/dist/compile/aot-reconstruct.mjs +3 -2
  26. package/dist/compile/aot.d.ts +3 -3
  27. package/dist/compile/aot.js +5 -5
  28. package/dist/compile/aot.mjs +6 -5
  29. package/dist/compile/handler/descriptor.d.ts +2 -5
  30. package/dist/compile/handler/descriptor.js +12 -17
  31. package/dist/compile/handler/descriptor.mjs +16 -21
  32. package/dist/compile/handler/frozen-validator.d.ts +2 -2
  33. package/dist/compile/handler/frozen-validator.js +3 -3
  34. package/dist/compile/handler/frozen-validator.mjs +4 -3
  35. package/dist/compile/handler/index.d.ts +3 -1
  36. package/dist/compile/handler/index.js +77 -118
  37. package/dist/compile/handler/index.mjs +83 -125
  38. package/dist/compile/handler/jit.d.ts +12 -12
  39. package/dist/compile/handler/jit.js +60 -43
  40. package/dist/compile/handler/jit.mjs +63 -47
  41. package/dist/compile/handler/params.d.ts +5 -1
  42. package/dist/compile/handler/params.js +14 -5
  43. package/dist/compile/handler/params.mjs +16 -7
  44. package/dist/compile/handler/reconstruct.d.ts +2 -2
  45. package/dist/compile/handler/reconstruct.js +2 -2
  46. package/dist/compile/handler/reconstruct.mjs +3 -2
  47. package/dist/compile/handler/static-clone-resolver.mjs +1 -0
  48. package/dist/compile/handler/utils.d.ts +13 -7
  49. package/dist/compile/handler/utils.js +75 -52
  50. package/dist/compile/handler/utils.mjs +77 -54
  51. package/dist/compile/jit-probe.mjs +1 -0
  52. package/dist/compile/lexer.js +4 -4
  53. package/dist/compile/lexer.mjs +5 -4
  54. package/dist/compile/utils.d.ts +2 -1
  55. package/dist/compile/utils.js +8 -3
  56. package/dist/compile/utils.mjs +8 -3
  57. package/dist/compiled.mjs +1 -0
  58. package/dist/constants.mjs +1 -0
  59. package/dist/context.d.ts +1 -1
  60. package/dist/context.js +1 -0
  61. package/dist/context.mjs +3 -1
  62. package/dist/cookie/config.d.ts +2 -2
  63. package/dist/cookie/config.js +21 -26
  64. package/dist/cookie/config.mjs +22 -26
  65. package/dist/cookie/cookie.mjs +1 -0
  66. package/dist/cookie/crypto.mjs +1 -0
  67. package/dist/cookie/error.mjs +1 -0
  68. package/dist/cookie/lib.mjs +1 -0
  69. package/dist/cookie/serialize.mjs +1 -0
  70. package/dist/cookie/types.mjs +1 -0
  71. package/dist/cookie/utils.d.ts +1 -1
  72. package/dist/cookie/utils.js +64 -45
  73. package/dist/cookie/utils.mjs +66 -46
  74. package/dist/error.d.ts +10 -6
  75. package/dist/error.js +22 -6
  76. package/dist/error.mjs +25 -9
  77. package/dist/generation.mjs +1 -0
  78. package/dist/handler/error.d.ts +12 -15
  79. package/dist/handler/error.js +43 -40
  80. package/dist/handler/error.mjs +45 -41
  81. package/dist/handler/fetch.js +59 -21
  82. package/dist/handler/fetch.mjs +61 -22
  83. package/dist/handler/utils.d.ts +16 -3
  84. package/dist/handler/utils.js +14 -13
  85. package/dist/handler/utils.mjs +16 -15
  86. package/dist/index.d.ts +9 -9
  87. package/dist/index.js +1 -0
  88. package/dist/index.mjs +3 -2
  89. package/dist/memory.mjs +1 -0
  90. package/dist/package.js +1 -1
  91. package/dist/package.mjs +2 -1
  92. package/dist/parse-query.js +76 -76
  93. package/dist/parse-query.mjs +77 -76
  94. package/dist/plugin/aot/bun.mjs +1 -0
  95. package/dist/plugin/aot/core.js +7 -4
  96. package/dist/plugin/aot/core.mjs +8 -5
  97. package/dist/plugin/aot/esbuild.mjs +1 -0
  98. package/dist/plugin/aot/rspack-loader.mjs +1 -0
  99. package/dist/plugin/aot/rspack.mjs +1 -0
  100. package/dist/plugin/aot/treeshake.mjs +1 -0
  101. package/dist/plugin/aot/unplugin.mjs +4 -3
  102. package/dist/plugin/aot/vite.mjs +1 -0
  103. package/dist/plugin/aot/worker.mjs +1 -0
  104. package/dist/plugin/auto-head.mjs +1 -0
  105. package/dist/plugin/trace.mjs +1 -0
  106. package/dist/plugin/websocket.mjs +1 -0
  107. package/dist/route-table.mjs +1 -0
  108. package/dist/schema-snapshot.mjs +1 -0
  109. package/dist/sucrose.d.ts +2 -2
  110. package/dist/sucrose.js +11 -11
  111. package/dist/sucrose.mjs +12 -11
  112. package/dist/trace.js +8 -10
  113. package/dist/trace.mjs +10 -11
  114. package/dist/type/bridge-live.d.ts +1 -1
  115. package/dist/type/bridge-live.mjs +1 -0
  116. package/dist/type/bridge.d.ts +1 -1
  117. package/dist/type/bridge.mjs +1 -0
  118. package/dist/type/coerce-plan.mjs +1 -0
  119. package/dist/type/coerce.d.ts +1 -1
  120. package/dist/type/coerce.mjs +1 -0
  121. package/dist/type/compat.mjs +1 -0
  122. package/dist/type/constants.d.ts +1 -1
  123. package/dist/type/constants.mjs +1 -0
  124. package/dist/type/elysia/accelerate.mjs +1 -0
  125. package/dist/type/elysia/array-buffer.d.ts +3 -2
  126. package/dist/type/elysia/array-buffer.js +5 -5
  127. package/dist/type/elysia/array-buffer.mjs +6 -5
  128. package/dist/type/elysia/array-string.mjs +1 -0
  129. package/dist/type/elysia/array.mjs +1 -0
  130. package/dist/type/elysia/boolean-string.mjs +1 -0
  131. package/dist/type/elysia/boolean.mjs +1 -0
  132. package/dist/type/elysia/cookie.mjs +1 -0
  133. package/dist/type/elysia/date.mjs +1 -0
  134. package/dist/type/elysia/file-type.mjs +1 -0
  135. package/dist/type/elysia/file.mjs +1 -0
  136. package/dist/type/elysia/files.mjs +1 -0
  137. package/dist/type/elysia/form.mjs +1 -0
  138. package/dist/type/elysia/integer-string.mjs +1 -0
  139. package/dist/type/elysia/integer.mjs +1 -0
  140. package/dist/type/elysia/intersect.mjs +1 -0
  141. package/dist/type/elysia/json-string.mjs +1 -0
  142. package/dist/type/elysia/keep-config.js +8 -8
  143. package/dist/type/elysia/keep-config.mjs +9 -8
  144. package/dist/type/elysia/maybe-empty.mjs +1 -0
  145. package/dist/type/elysia/no-validate.mjs +1 -0
  146. package/dist/type/elysia/nullable.mjs +1 -0
  147. package/dist/type/elysia/number.mjs +1 -0
  148. package/dist/type/elysia/numeric-enum.d.ts +4 -2
  149. package/dist/type/elysia/numeric-enum.mjs +1 -0
  150. package/dist/type/elysia/numeric.mjs +1 -0
  151. package/dist/type/elysia/object-string.mjs +1 -0
  152. package/dist/type/elysia/object.mjs +1 -0
  153. package/dist/type/elysia/optional.mjs +1 -0
  154. package/dist/type/elysia/problem.mjs +1 -0
  155. package/dist/type/elysia/string.mjs +1 -0
  156. package/dist/type/elysia/uint8-array.d.ts +2 -1
  157. package/dist/type/elysia/uint8-array.js +2 -2
  158. package/dist/type/elysia/uint8-array.mjs +3 -2
  159. package/dist/type/elysia/union-enum.mjs +1 -0
  160. package/dist/type/elysia/union.mjs +1 -0
  161. package/dist/type/elysia/utils.js +3 -3
  162. package/dist/type/elysia/utils.mjs +4 -3
  163. package/dist/type/exports.mjs +1 -0
  164. package/dist/type/index.mjs +2 -1
  165. package/dist/type/shared.mjs +1 -0
  166. package/dist/type/sync-require.mjs +1 -0
  167. package/dist/type/typebox-system-lite.mjs +1 -0
  168. package/dist/type/typebox-system-require.mjs +1 -0
  169. package/dist/type/typebox-type-live.mjs +1 -0
  170. package/dist/type/typebox-value-live.mjs +1 -0
  171. package/dist/type/typebox-value-ops.mjs +1 -0
  172. package/dist/type/typebox-value.mjs +1 -0
  173. package/dist/type/types.d.ts +1 -1
  174. package/dist/type/types.mjs +1 -0
  175. package/dist/type/utils.mjs +1 -0
  176. package/dist/type/validator/clean-safe.mjs +1 -0
  177. package/dist/type/validator/custom-error.js +41 -33
  178. package/dist/type/validator/custom-error.mjs +42 -33
  179. package/dist/type/validator/default-precompute.d.ts +2 -2
  180. package/dist/type/validator/default-precompute.js +10 -11
  181. package/dist/type/validator/default-precompute.mjs +13 -13
  182. package/dist/type/validator/exact-mirror.mjs +1 -0
  183. package/dist/type/validator/frozen-check.js +7 -7
  184. package/dist/type/validator/frozen-check.mjs +8 -7
  185. package/dist/type/validator/index.d.ts +2 -2
  186. package/dist/type/validator/index.js +4 -8
  187. package/dist/type/validator/index.mjs +5 -8
  188. package/dist/type/validator/string-codec-aot.d.ts +1 -1
  189. package/dist/type/validator/string-codec-aot.mjs +1 -0
  190. package/dist/type/validator/validator-cache.js +18 -18
  191. package/dist/type/validator/validator-cache.mjs +19 -18
  192. package/dist/types.d.ts +105 -69
  193. package/dist/types.mjs +1 -0
  194. package/dist/universal/constants.mjs +1 -0
  195. package/dist/universal/file.mjs +1 -0
  196. package/dist/universal/index.mjs +1 -0
  197. package/dist/universal/is-production.mjs +1 -0
  198. package/dist/universal/server.mjs +1 -0
  199. package/dist/utils.d.ts +49 -31
  200. package/dist/utils.js +221 -109
  201. package/dist/utils.mjs +215 -106
  202. package/dist/validator/index.d.ts +3 -3
  203. package/dist/validator/index.js +4 -4
  204. package/dist/validator/index.mjs +5 -4
  205. package/dist/validator/route.d.ts +2 -2
  206. package/dist/validator/route.mjs +1 -0
  207. package/dist/ws/context.js +1 -1
  208. package/dist/ws/context.mjs +2 -1
  209. package/dist/ws/index.mjs +1 -0
  210. package/dist/ws/parser.mjs +1 -0
  211. package/dist/ws/route.js +34 -25
  212. package/dist/ws/route.mjs +40 -30
  213. package/dist/ws/types.d.ts +2 -3
  214. package/dist/ws/types.mjs +1 -0
  215. 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, true);
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, true, true);
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 flatAppHook = require_utils.flattenChainMemo(root, appHook, resolve);
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
- if (require_handler_utils.returnedErrorClasses(hook, root)?.some((C) => handler instanceof C)) return;
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 flatAppHook = appHook ? require_utils.flattenChainMemo(root, appHook, resolve) : void 0;
243
- let locals = instance !== root ? require_utils.flattenChain(require_generation.frozenRootOf(root)["~hookChain"], require_utils.isLocalScope, require_utils.rootSnapshot(inheritedChain), resolve) : void 0;
244
- const instanceLocal = instance !== root ? require_utils.flattenChain(instance["~hookChain"], require_utils.isLocalScope) : void 0;
245
- 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) && require_utils.isCompactBeforeHandleOnly(locals) && !instanceLocal?.error ? require_utils.compactBeforeHandlePrefix(inheritedChain) : void 0;
246
- let present = collectHookOrigins(localHook, void 0);
247
- present = collectHookOrigins(flatAppHook, present);
248
- if (compactPrefix && !present?.size && !require_utils.compactBeforeHandleConflicts(localHook) && !require_utils.compactBeforeHandleConflicts(flatAppHook) && !require_utils.compactBeforeHandleConflicts(locals)) {
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
- let inherited = instance !== root ? require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
256
- let after = instance !== root ? afterUseHooks(inheritedChain, resolve) : void 0;
257
- if ((inherited || after || locals) && (flatAppHook || localHook) && present?.size) {
258
- if (inherited) inherited = dropHooksByOrigin(inherited, present);
259
- if (after) after = dropHooksByOrigin(after, present);
260
- if (locals) locals = dropHooksByOrigin(locals, present);
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 (after) hook = hook ? require_utils.mergeHook(hook, after, false, true) : after;
264
- if (locals) hook = hook ? require_utils.mergeHook(hook, locals, false, true) : locals;
265
- if (instance !== root) {
266
- const errors = instanceLocal?.error;
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, root)
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.Reconstrct.validator(hook, root, method, path, liveOnly) : void 0;
433
- const errorClasses = require_handler_utils.returnedErrorClasses(hook, root);
434
- if (handler instanceof Error || typeof handler !== "function" && errorClasses?.some((C) => handler instanceof C)) {
435
- const error = handler;
436
- handler = () => {
437
- throw error;
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.aotDrift(method, path), { cause });
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.includes("va") ? buildValidator() : void 0,
478
- cookieConfig: reconstructed.a.includes("cc") ? require_compile_handler_reconstruct.Reconstrct.cookie(hook, root) : void 0,
479
- tracers: reconstructed.a.includes("tr") ? require_compile_handler_reconstruct.Reconstrct.trace(hook, root) : void 0
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, eventProperties, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, isCompactBeforeHandleOnly, isHTMLBundle, isLocalScope, isNotEmpty, macroEpoch, mergeHook, nullObject, refTargets, replaceUrlPath, rootSnapshot } from "../../utils.mjs";
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, aotDrift, warnAotDrift } from "../aot.mjs";
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 { Reconstrct } from "./reconstruct.mjs";
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, true);
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, true, true);
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 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);
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
- if (returnedErrorClasses(hook, root)?.some((C) => handler instanceof C)) return;
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 flatAppHook = appHook ? flattenChainMemo(root, appHook, resolve) : void 0;
242
- let locals = instance !== root ? flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, rootSnapshot(inheritedChain), resolve) : void 0;
243
- const instanceLocal = instance !== root ? flattenChain(instance["~hookChain"], isLocalScope) : 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;
245
- let present = collectHookOrigins(localHook, void 0);
246
- present = collectHookOrigins(flatAppHook, present);
247
- if (compactPrefix && !present?.size && !compactBeforeHandleConflicts(localHook) && !compactBeforeHandleConflicts(flatAppHook) && !compactBeforeHandleConflicts(locals)) {
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
- let inherited = instance !== root ? flattenChainMemoReadonly(root, inheritedChain, resolve) : void 0;
255
- let after = instance !== root ? afterUseHooks(inheritedChain, resolve) : void 0;
256
- if ((inherited || after || locals) && (flatAppHook || localHook) && present?.size) {
257
- if (inherited) inherited = dropHooksByOrigin(inherited, present);
258
- if (after) after = dropHooksByOrigin(after, present);
259
- if (locals) locals = dropHooksByOrigin(locals, present);
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 (after) hook = hook ? mergeHook(hook, after, false, true) : after;
263
- if (locals) hook = hook ? mergeHook(hook, locals, false, true) : locals;
264
- if (instance !== root) {
265
- const errors = instanceLocal?.error;
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, root)
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 ? 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)) {
434
- const error = handler;
435
- handler = () => {
436
- throw error;
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(aotDrift(method, path), { cause });
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.includes("va") ? buildValidator() : void 0,
477
- cookieConfig: reconstructed.a.includes("cc") ? Reconstrct.cookie(hook, root) : void 0,
478
- tracers: reconstructed.a.includes("tr") ? Reconstrct.trace(hook, root) : void 0
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 };