elysia 2.0.0-beta.2 → 2.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/dist/adapter/bun/index.d.ts +18 -2
  2. package/dist/adapter/bun/index.js +467 -110
  3. package/dist/adapter/bun/index.mjs +467 -112
  4. package/dist/adapter/types.d.ts +2 -21
  5. package/dist/adapter/utils.d.ts +14 -3
  6. package/dist/adapter/utils.js +146 -87
  7. package/dist/adapter/utils.mjs +148 -90
  8. package/dist/adapter/web-standard/handler.d.ts +1 -1
  9. package/dist/adapter/web-standard/handler.js +47 -36
  10. package/dist/adapter/web-standard/handler.mjs +48 -37
  11. package/dist/adapter/web-standard/index.js +2 -30
  12. package/dist/adapter/web-standard/index.mjs +2 -30
  13. package/dist/adapter/web-standard/utils.js +5 -18
  14. package/dist/adapter/web-standard/utils.mjs +5 -18
  15. package/dist/base.d.ts +99 -67
  16. package/dist/base.js +678 -510
  17. package/dist/base.mjs +682 -514
  18. package/dist/compile/aot-capture.d.ts +2 -13
  19. package/dist/compile/aot-capture.js +26 -69
  20. package/dist/compile/aot-capture.mjs +28 -67
  21. package/dist/compile/aot-emit.d.ts +9 -7
  22. package/dist/compile/aot-emit.js +42 -19
  23. package/dist/compile/aot-emit.mjs +42 -20
  24. package/dist/compile/aot.d.ts +17 -19
  25. package/dist/compile/aot.js +41 -51
  26. package/dist/compile/aot.mjs +39 -49
  27. package/dist/compile/handler/descriptor.d.ts +9 -12
  28. package/dist/compile/handler/descriptor.js +19 -44
  29. package/dist/compile/handler/descriptor.mjs +20 -42
  30. package/dist/compile/handler/frozen-validator.d.ts +5 -10
  31. package/dist/compile/handler/frozen-validator.js +55 -105
  32. package/dist/compile/handler/frozen-validator.mjs +53 -105
  33. package/dist/compile/handler/index.d.ts +7 -5
  34. package/dist/compile/handler/index.js +270 -111
  35. package/dist/compile/handler/index.mjs +270 -113
  36. package/dist/compile/handler/jit.d.ts +19 -17
  37. package/dist/compile/handler/jit.js +222 -149
  38. package/dist/compile/handler/jit.mjs +224 -152
  39. package/dist/compile/handler/params.d.ts +1 -4
  40. package/dist/compile/handler/params.js +10 -5
  41. package/dist/compile/handler/params.mjs +14 -8
  42. package/dist/compile/handler/reconstruct.d.ts +2 -2
  43. package/dist/compile/handler/reconstruct.js +6 -4
  44. package/dist/compile/handler/reconstruct.mjs +6 -4
  45. package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
  46. package/dist/compile/handler/static-clone-resolver.js +8 -0
  47. package/dist/compile/handler/static-clone-resolver.mjs +7 -0
  48. package/dist/compile/handler/utils.d.ts +22 -11
  49. package/dist/compile/handler/utils.js +159 -253
  50. package/dist/compile/handler/utils.mjs +155 -252
  51. package/dist/compile/jit-probe.d.ts +2 -2
  52. package/dist/compile/jit-probe.js +2 -3
  53. package/dist/compile/jit-probe.mjs +2 -3
  54. package/dist/compile/lexer.d.ts +7 -4
  55. package/dist/compile/lexer.js +268 -6
  56. package/dist/compile/lexer.mjs +268 -4
  57. package/dist/compile/utils.js +7 -4
  58. package/dist/compile/utils.mjs +7 -4
  59. package/dist/compiled.d.ts +0 -1
  60. package/dist/compiled.js +0 -1
  61. package/dist/compiled.mjs +0 -1
  62. package/dist/context.d.ts +14 -4
  63. package/dist/context.js +17 -32
  64. package/dist/context.mjs +19 -34
  65. package/dist/cookie/config.d.ts +7 -2
  66. package/dist/cookie/config.js +76 -16
  67. package/dist/cookie/config.mjs +77 -18
  68. package/dist/cookie/cookie.d.ts +1 -1
  69. package/dist/cookie/cookie.js +8 -10
  70. package/dist/cookie/cookie.mjs +8 -10
  71. package/dist/cookie/crypto.d.ts +8 -7
  72. package/dist/cookie/crypto.js +51 -40
  73. package/dist/cookie/crypto.mjs +51 -41
  74. package/dist/cookie/error.d.ts +1 -2
  75. package/dist/cookie/error.js +6 -4
  76. package/dist/cookie/error.mjs +6 -4
  77. package/dist/cookie/lib.js +7 -2
  78. package/dist/cookie/lib.mjs +7 -2
  79. package/dist/cookie/serialize.js +1 -1
  80. package/dist/cookie/serialize.mjs +1 -1
  81. package/dist/cookie/types.d.ts +10 -0
  82. package/dist/cookie/utils.d.ts +4 -8
  83. package/dist/cookie/utils.js +86 -52
  84. package/dist/cookie/utils.mjs +89 -54
  85. package/dist/error.d.ts +113 -103
  86. package/dist/error.js +181 -117
  87. package/dist/error.mjs +179 -118
  88. package/dist/generation.d.ts +2 -2
  89. package/dist/handler/error.d.ts +26 -15
  90. package/dist/handler/error.js +77 -96
  91. package/dist/handler/error.mjs +74 -97
  92. package/dist/handler/fetch.js +87 -108
  93. package/dist/handler/fetch.mjs +89 -110
  94. package/dist/handler/utils.d.ts +12 -6
  95. package/dist/handler/utils.js +84 -28
  96. package/dist/handler/utils.mjs +80 -28
  97. package/dist/index.d.ts +12 -12
  98. package/dist/index.js +2 -9
  99. package/dist/index.mjs +1 -1
  100. package/dist/memory.js +1 -1
  101. package/dist/memory.mjs +1 -1
  102. package/dist/package.js +1 -1
  103. package/dist/package.mjs +1 -1
  104. package/dist/plugin/aot/bun.d.ts +8 -1
  105. package/dist/plugin/aot/bun.js +16 -9
  106. package/dist/plugin/aot/bun.mjs +17 -10
  107. package/dist/plugin/aot/core.d.ts +52 -60
  108. package/dist/plugin/aot/core.js +208 -109
  109. package/dist/plugin/aot/core.mjs +205 -111
  110. package/dist/plugin/aot/esbuild.js +8 -5
  111. package/dist/plugin/aot/esbuild.mjs +9 -6
  112. package/dist/plugin/aot/hooks.d.ts +6 -17
  113. package/dist/plugin/aot/hooks.js +36 -14
  114. package/dist/plugin/aot/hooks.mjs +37 -16
  115. package/dist/plugin/aot/rspack-loader.d.ts +1 -5
  116. package/dist/plugin/aot/rspack-loader.js +1 -10
  117. package/dist/plugin/aot/rspack-loader.mjs +1 -10
  118. package/dist/plugin/aot/rspack.js +2 -5
  119. package/dist/plugin/aot/rspack.mjs +3 -6
  120. package/dist/plugin/aot/source.d.ts +6 -42
  121. package/dist/plugin/aot/source.js +71 -71
  122. package/dist/plugin/aot/source.mjs +72 -72
  123. package/dist/plugin/aot/treeshake.js +2 -6
  124. package/dist/plugin/aot/treeshake.mjs +2 -6
  125. package/dist/plugin/aot/unplugin.d.ts +1 -4
  126. package/dist/plugin/aot/unplugin.js +4 -13
  127. package/dist/plugin/aot/unplugin.mjs +4 -13
  128. package/dist/plugin/aot/vite.d.ts +2 -6
  129. package/dist/plugin/aot/worker.js +2 -2
  130. package/dist/plugin/aot/worker.mjs +2 -2
  131. package/dist/plugin/auto-head.js +1 -10
  132. package/dist/plugin/auto-head.mjs +1 -10
  133. package/dist/plugin/trace.d.ts +2 -1
  134. package/dist/route-table.d.ts +3 -0
  135. package/dist/route-table.js +16 -11
  136. package/dist/route-table.mjs +16 -11
  137. package/dist/schema-snapshot.d.ts +0 -4
  138. package/dist/schema-snapshot.js +32 -49
  139. package/dist/schema-snapshot.mjs +32 -49
  140. package/dist/sucrose.d.ts +6 -55
  141. package/dist/sucrose.js +103 -731
  142. package/dist/sucrose.mjs +102 -724
  143. package/dist/trace.d.ts +5 -8
  144. package/dist/trace.js +23 -134
  145. package/dist/trace.mjs +24 -135
  146. package/dist/type/bridge-live.d.ts +4 -2
  147. package/dist/type/bridge-live.js +6 -3
  148. package/dist/type/bridge-live.mjs +4 -2
  149. package/dist/type/bridge.d.ts +6 -4
  150. package/dist/type/bridge.js +17 -9
  151. package/dist/type/bridge.mjs +5 -3
  152. package/dist/type/coerce-plan.d.ts +5 -5
  153. package/dist/type/coerce-plan.js +41 -39
  154. package/dist/type/coerce-plan.mjs +43 -39
  155. package/dist/type/coerce.d.ts +3 -7
  156. package/dist/type/coerce.js +18 -75
  157. package/dist/type/coerce.mjs +19 -76
  158. package/dist/type/compat.d.ts +3 -0
  159. package/dist/type/compat.js +23 -14
  160. package/dist/type/compat.mjs +20 -10
  161. package/dist/type/elysia/array-buffer.d.ts +4 -1
  162. package/dist/type/elysia/array-buffer.js +17 -17
  163. package/dist/type/elysia/array-buffer.mjs +17 -17
  164. package/dist/type/elysia/array-string.js +2 -40
  165. package/dist/type/elysia/array-string.mjs +2 -39
  166. package/dist/type/elysia/array.js +5 -9
  167. package/dist/type/elysia/array.mjs +5 -9
  168. package/dist/type/elysia/boolean-string.js +2 -3
  169. package/dist/type/elysia/boolean-string.mjs +1 -1
  170. package/dist/type/elysia/boolean.js +3 -12
  171. package/dist/type/elysia/boolean.mjs +3 -11
  172. package/dist/type/elysia/cookie.d.ts +3 -4
  173. package/dist/type/elysia/cookie.js +5 -15
  174. package/dist/type/elysia/cookie.mjs +5 -15
  175. package/dist/type/elysia/date.js +13 -20
  176. package/dist/type/elysia/date.mjs +10 -16
  177. package/dist/type/elysia/file-type.d.ts +11 -4
  178. package/dist/type/elysia/file-type.js +17 -2
  179. package/dist/type/elysia/file-type.mjs +17 -3
  180. package/dist/type/elysia/file.d.ts +1 -3
  181. package/dist/type/elysia/file.js +11 -27
  182. package/dist/type/elysia/file.mjs +11 -12
  183. package/dist/type/elysia/files.js +7 -11
  184. package/dist/type/elysia/files.mjs +7 -10
  185. package/dist/type/elysia/form.js +2 -3
  186. package/dist/type/elysia/form.mjs +3 -3
  187. package/dist/type/elysia/integer-string.d.ts +1 -1
  188. package/dist/type/elysia/integer-string.js +4 -30
  189. package/dist/type/elysia/integer-string.mjs +5 -30
  190. package/dist/type/elysia/integer.js +3 -12
  191. package/dist/type/elysia/integer.mjs +3 -11
  192. package/dist/type/elysia/intersect.js +0 -5
  193. package/dist/type/elysia/intersect.mjs +0 -5
  194. package/dist/type/elysia/json-string.d.ts +7 -0
  195. package/dist/type/elysia/json-string.js +47 -0
  196. package/dist/type/elysia/json-string.mjs +46 -0
  197. package/dist/type/elysia/keep-config.d.ts +14 -0
  198. package/dist/type/elysia/keep-config.js +62 -0
  199. package/dist/type/elysia/keep-config.mjs +53 -0
  200. package/dist/type/elysia/maybe-empty.js +3 -4
  201. package/dist/type/elysia/maybe-empty.mjs +1 -1
  202. package/dist/type/elysia/nullable.js +2 -3
  203. package/dist/type/elysia/nullable.mjs +1 -1
  204. package/dist/type/elysia/number.d.ts +2 -1
  205. package/dist/type/elysia/number.js +19 -11
  206. package/dist/type/elysia/number.mjs +18 -10
  207. package/dist/type/elysia/numeric-enum.d.ts +1 -1
  208. package/dist/type/elysia/numeric-enum.js +4 -5
  209. package/dist/type/elysia/numeric-enum.mjs +3 -3
  210. package/dist/type/elysia/numeric.d.ts +4 -2
  211. package/dist/type/elysia/numeric.js +20 -17
  212. package/dist/type/elysia/numeric.mjs +19 -16
  213. package/dist/type/elysia/object-string.js +2 -37
  214. package/dist/type/elysia/object-string.mjs +2 -36
  215. package/dist/type/elysia/object.js +5 -9
  216. package/dist/type/elysia/object.mjs +5 -9
  217. package/dist/type/elysia/optional.js +8 -8
  218. package/dist/type/elysia/optional.mjs +7 -7
  219. package/dist/type/elysia/problem.d.ts +20 -0
  220. package/dist/type/elysia/problem.js +25 -0
  221. package/dist/type/elysia/problem.mjs +24 -0
  222. package/dist/type/elysia/string.js +4 -3
  223. package/dist/type/elysia/string.mjs +4 -2
  224. package/dist/type/elysia/uint8-array.d.ts +1 -1
  225. package/dist/type/elysia/uint8-array.js +5 -20
  226. package/dist/type/elysia/uint8-array.mjs +5 -19
  227. package/dist/type/elysia/union-enum.js +7 -8
  228. package/dist/type/elysia/union-enum.mjs +6 -6
  229. package/dist/type/elysia/union.js +0 -5
  230. package/dist/type/elysia/union.mjs +0 -5
  231. package/dist/type/elysia/utils.d.ts +2 -4
  232. package/dist/type/elysia/utils.js +10 -21
  233. package/dist/type/elysia/utils.mjs +7 -15
  234. package/dist/type/exports.d.ts +4 -2
  235. package/dist/type/exports.js +23 -2
  236. package/dist/type/exports.mjs +11 -2
  237. package/dist/type/index.d.ts +10 -2
  238. package/dist/type/index.js +62 -15
  239. package/dist/type/index.mjs +65 -11
  240. package/dist/type/shared.d.ts +3 -9
  241. package/dist/type/shared.js +44 -97
  242. package/dist/type/shared.mjs +43 -97
  243. package/dist/type/sync-require.d.ts +11 -0
  244. package/dist/type/sync-require.js +14 -0
  245. package/dist/type/sync-require.mjs +12 -0
  246. package/dist/type/typebox-system-lite.d.ts +2 -0
  247. package/dist/type/typebox-system-lite.js +34 -0
  248. package/dist/type/typebox-system-lite.mjs +3 -0
  249. package/dist/type/typebox-system-require.d.ts +7 -0
  250. package/dist/type/typebox-system-require.js +24 -0
  251. package/dist/type/typebox-system-require.mjs +23 -0
  252. package/dist/type/typebox-type-live.d.ts +11 -0
  253. package/dist/type/typebox-type-live.js +45 -0
  254. package/dist/type/typebox-type-live.mjs +20 -0
  255. package/dist/type/typebox-type.d.ts +34 -0
  256. package/dist/type/typebox-type.js +199 -0
  257. package/dist/type/typebox-type.mjs +86 -0
  258. package/dist/type/typebox-value-live.d.ts +11 -0
  259. package/dist/type/typebox-value-live.js +31 -0
  260. package/dist/type/typebox-value-live.mjs +13 -0
  261. package/dist/type/typebox-value-ops.d.ts +4 -0
  262. package/dist/type/typebox-value-ops.js +90 -0
  263. package/dist/type/typebox-value-ops.mjs +5 -0
  264. package/dist/type/typebox-value-require.d.ts +8 -0
  265. package/dist/type/typebox-value-require.js +28 -0
  266. package/dist/type/typebox-value-require.mjs +25 -0
  267. package/dist/type/typebox-value.d.ts +35 -0
  268. package/dist/type/typebox-value.js +161 -0
  269. package/dist/type/typebox-value.mjs +74 -0
  270. package/dist/type/utils.js +1 -10
  271. package/dist/type/utils.mjs +1 -10
  272. package/dist/type/validator/clean-safe.d.ts +2 -4
  273. package/dist/type/validator/clean-safe.js +15 -11
  274. package/dist/type/validator/clean-safe.mjs +16 -10
  275. package/dist/type/validator/custom-error.js +12 -16
  276. package/dist/type/validator/custom-error.mjs +11 -14
  277. package/dist/type/validator/default-precompute.d.ts +9 -1
  278. package/dist/type/validator/default-precompute.js +40 -77
  279. package/dist/type/validator/default-precompute.mjs +37 -74
  280. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  281. package/dist/type/validator/exact-mirror-live.js +22 -0
  282. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  283. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  284. package/dist/type/validator/exact-mirror-require.js +11 -0
  285. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  286. package/dist/type/validator/exact-mirror.js +8 -8
  287. package/dist/type/validator/exact-mirror.mjs +9 -8
  288. package/dist/type/validator/frozen-check.js +5 -6
  289. package/dist/type/validator/frozen-check.mjs +6 -7
  290. package/dist/type/validator/index.d.ts +1 -0
  291. package/dist/type/validator/index.js +169 -166
  292. package/dist/type/validator/index.mjs +162 -158
  293. package/dist/type/validator/string-codec-aot.d.ts +2 -1
  294. package/dist/type/validator/string-codec-aot.js +8 -2
  295. package/dist/type/validator/string-codec-aot.mjs +7 -2
  296. package/dist/type/validator/validator-cache.d.ts +5 -4
  297. package/dist/type/validator/validator-cache.js +41 -24
  298. package/dist/type/validator/validator-cache.mjs +40 -22
  299. package/dist/types.d.ts +263 -95
  300. package/dist/universal/constants.d.ts +2 -1
  301. package/dist/universal/constants.js +3 -1
  302. package/dist/universal/constants.mjs +2 -1
  303. package/dist/universal/env.js +2 -3
  304. package/dist/universal/env.mjs +2 -3
  305. package/dist/universal/file.d.ts +6 -4
  306. package/dist/universal/file.js +11 -16
  307. package/dist/universal/file.mjs +12 -16
  308. package/dist/universal/index.d.ts +2 -2
  309. package/dist/universal/is-production.d.ts +1 -2
  310. package/dist/universal/is-production.js +1 -3
  311. package/dist/universal/is-production.mjs +2 -3
  312. package/dist/universal/server.d.ts +0 -272
  313. package/dist/utils.d.ts +43 -7
  314. package/dist/utils.js +181 -126
  315. package/dist/utils.mjs +168 -126
  316. package/dist/validator/index.d.ts +1 -1
  317. package/dist/validator/index.js +17 -30
  318. package/dist/validator/index.mjs +18 -31
  319. package/dist/validator/route.js +2 -1
  320. package/dist/validator/route.mjs +2 -1
  321. package/dist/ws/context.d.ts +8 -1
  322. package/dist/ws/context.js +68 -44
  323. package/dist/ws/context.mjs +67 -44
  324. package/dist/ws/parser.js +10 -20
  325. package/dist/ws/parser.mjs +10 -20
  326. package/dist/ws/route.d.ts +2 -2
  327. package/dist/ws/route.js +249 -141
  328. package/dist/ws/route.mjs +254 -146
  329. package/dist/ws/types.d.ts +2 -2
  330. package/package.json +23 -49
  331. package/dist/compile/analysis-cache.d.ts +0 -6
  332. package/dist/compile/analysis-cache.js +0 -12
  333. package/dist/compile/analysis-cache.mjs +0 -11
  334. package/dist/cookie/index.d.ts +0 -7
  335. package/dist/cookie/index.js +0 -13
  336. package/dist/cookie/index.mjs +0 -7
  337. package/dist/handler/index.d.ts +0 -2
  338. package/dist/handler/index.js +0 -5
  339. package/dist/handler/index.mjs +0 -3
@@ -18,10 +18,8 @@ async function captureArtifacts(app, options) {
18
18
  const previousAotBuild = require_universal_env.env.ELYSIA_AOT_BUILD;
19
19
  require_universal_env.env.ELYSIA_AOT_BUILD = "1";
20
20
  try {
21
- if (!require_compile_aot.Capture.isCapturing()) throw new Error("[elysia-aot]: ELYSIA_AOT_BUILD=1 must be set to enable AOT capture mode");
22
21
  require_compile_aot_capture.beginValidatorCapture();
23
- const modules = app.modules;
24
- if (modules) await modules;
22
+ await app.modules;
25
23
  if (options?.target !== void 0) require_compile_handler_jit.setCaptureHeaderShorthand(options.target === "bun");
26
24
  app.compile();
27
25
  const captured = require_compile_aot_capture.endValidatorCapture();
@@ -42,10 +40,14 @@ async function captureArtifacts(app, options) {
42
40
  }
43
41
  const materialiseHandlersForReplay = (captured) => {
44
42
  const manifest = {};
45
- for (const h of captured) (manifest[h.method] ??= {})[h.path] = {
46
- a: h.alias ? h.alias.split(",") : [],
47
- f: new Function(`return ${require_compile_aot_emit.Source.handlerFactory(h.alias, h.code)}`)()
48
- };
43
+ for (const h of captured) {
44
+ if (!h.code) continue;
45
+ (manifest[h.method] ??= {})[h.path] = {
46
+ a: h.alias ? h.alias.split(",") : [],
47
+ f: new Function(`return ${require_compile_aot_emit.Source.handlerFactory(h.alias, h.code)}`)(),
48
+ k: h.k
49
+ };
50
+ }
49
51
  return manifest;
50
52
  };
51
53
  function replayStubbability(app, handlers) {
@@ -56,23 +58,28 @@ function replayStubbability(app, handlers) {
56
58
  require_compile_aot.Compiled.clear();
57
59
  const fingerprint = require_compile_aot.createAotFingerprint();
58
60
  require_compile_aot.Compiled.register({
59
- bf: 1,
60
61
  fingerprint,
61
62
  handlers: materialiseHandlersForReplay(handlers)
62
63
  });
63
64
  require_compile_aot.Compiled.claim(app["~programId"], fingerprint);
64
65
  require_validator_index.Validator.clear();
65
- const history = app["~routes"] ?? [];
66
+ const history = app["~routes"];
66
67
  require_compile_jit_probe.JITProbe.begin();
68
+ const exact = /* @__PURE__ */ new Map();
69
+ for (const route of history) {
70
+ const method = route[0];
71
+ if (method === "WS") continue;
72
+ let paths = exact.get(method);
73
+ if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
74
+ if (paths.has(route[1])) require_compile_jit_probe.JITProbe.record("handler:indexed-duplicate");
75
+ else paths.add(route[1]);
76
+ }
67
77
  for (const route of history) try {
68
78
  if (route[0] === "WS") continue;
69
79
  require_compile_handler_index.compileHandler(route, app);
70
80
  } catch {
71
- require_compile_jit_probe.JITProbe.end();
72
- return {
73
- jit: false,
74
- reasons: ["handler:new-function"]
75
- };
81
+ require_compile_jit_probe.JITProbe.record("handler:new-function");
82
+ return require_compile_jit_probe.JITProbe.end();
76
83
  }
77
84
  return require_compile_jit_probe.JITProbe.end();
78
85
  } finally {
@@ -95,45 +102,33 @@ const normalizeCheckIdentifiers = (src) => {
95
102
  };
96
103
  function createEntryEncoder() {
97
104
  const branchRef = /* @__PURE__ */ new Map();
98
- let branchDecls = "";
99
105
  const branchTable = (u) => "[" + u.map((branch) => "[" + branch.map((b) => {
100
106
  const src = normalizeCheckIdentifiers(require_compile_aot_emit.Source.checkFactory(b.identifier, b.code));
101
107
  let ref = branchRef.get(src);
102
108
  if (ref === void 0) {
103
109
  ref = `_b${branchRef.size}`;
104
110
  branchRef.set(src, ref);
105
- branchDecls += `const ${ref} = ${src}\n`;
111
+ enc.branchDecls += `const ${ref} = ${src}\n`;
106
112
  }
107
113
  return ref;
108
114
  }).join(", ") + "]").join(", ") + "]";
109
115
  const unionRef = /* @__PURE__ */ new Map();
110
- let unionDecls = "";
111
- let hasCoercePlan = false;
112
- const unionTable = (u) => {
113
- const str = branchTable(u);
114
- let ref = unionRef.get(str);
115
- if (ref === void 0) {
116
- ref = `_u${unionRef.size}`;
117
- unionRef.set(str, ref);
118
- unionDecls += `const ${ref} = ${str}\n`;
119
- }
120
- return ref;
121
- };
122
- return {
123
- unionTable,
124
- setCoercePlan() {
125
- hasCoercePlan = true;
126
- },
127
- get branchDecls() {
128
- return branchDecls;
129
- },
130
- get unionDecls() {
131
- return unionDecls;
132
- },
133
- get hasCoercePlan() {
134
- return hasCoercePlan;
116
+ const enc = {
117
+ branchDecls: "",
118
+ unionDecls: "",
119
+ hasCoercePlan: false,
120
+ unionTable(u) {
121
+ const str = branchTable(u);
122
+ let ref = unionRef.get(str);
123
+ if (ref === void 0) {
124
+ ref = `_u${unionRef.size}`;
125
+ unionRef.set(str, ref);
126
+ enc.unionDecls += `const ${ref} = ${str}\n`;
127
+ }
128
+ return ref;
135
129
  }
136
130
  };
131
+ return enc;
137
132
  }
138
133
  function entryParts(c, enc) {
139
134
  const parts = [];
@@ -193,14 +188,15 @@ function entryParts(c, enc) {
193
188
  parts.push(`ic: [${ic}]`);
194
189
  }
195
190
  if (c.coercePlan) {
196
- enc.setCoercePlan();
191
+ enc.hasCoercePlan = true;
197
192
  parts.push(`cp: ${JSON.stringify(c.coercePlan)}`);
198
193
  }
199
194
  return parts;
200
195
  }
201
196
  function emitModule(captured, handlers, fingerprint, options) {
202
197
  const enc = createEntryEncoder();
203
- const treeToSource = (tree, slotRef, sink) => {
198
+ const treeToSource = (tree) => {
199
+ const slotRef = /* @__PURE__ */ new Map();
204
200
  const methods = [];
205
201
  for (const method in tree) {
206
202
  const paths = [];
@@ -210,7 +206,7 @@ function emitModule(captured, handlers, fingerprint, options) {
210
206
  if (ref === void 0) {
211
207
  ref = `_s${slotRef.size}`;
212
208
  slotRef.set(slotObj, ref);
213
- sink(`const ${ref} = ${slotObj}\n`);
209
+ validatorDecls += `const ${ref} = ${slotObj}\n`;
214
210
  }
215
211
  paths.push(`${JSON.stringify(path)}:${ref}`);
216
212
  }
@@ -342,7 +338,6 @@ function emitModule(captured, handlers, fingerprint, options) {
342
338
  }
343
339
  validatorDecls += `const _groups = [${thunks.join(", ")}]\n`;
344
340
  validatorDecls += `const _groupOf = ${JSON.stringify(groupOf)}\n`;
345
- validatorExport = options?.register ? "" : "export const groups = _groups\nexport const groupOf = _groupOf\n";
346
341
  } else {
347
342
  const factoryRef = /* @__PURE__ */ new Map();
348
343
  const tree = require_utils.nullObject();
@@ -359,59 +354,64 @@ function emitModule(captured, handlers, fingerprint, options) {
359
354
  const byPath = tree[c.method] ??= require_utils.nullObject();
360
355
  (byPath[c.path] ??= require_utils.nullObject())[c.slot] = ref;
361
356
  }
362
- const treeStr = treeToSource(tree, /* @__PURE__ */ new Map(), (d) => {
363
- validatorDecls += d;
364
- });
365
- validatorExport = options?.register ? `const validators = ${treeStr}\n` : `export const validators = ${treeStr}\n`;
357
+ validatorExport = `const validators = ${treeToSource(tree)}\n`;
366
358
  }
367
359
  const aliasRef = /* @__PURE__ */ new Map();
360
+ const factoryRef = /* @__PURE__ */ new Map();
368
361
  const handlerRef = /* @__PURE__ */ new Map();
369
362
  let handlerDecls = "";
370
363
  const handlerTree = require_utils.nullObject();
371
364
  for (const h of handlers) {
365
+ const k = h.k === void 0 ? "" : `k: ${JSON.stringify(h.k)}`;
366
+ if (!h.code) {
367
+ (handlerTree[h.method] ??= {})[h.path] = `{ ${k} }`;
368
+ continue;
369
+ }
372
370
  const src = require_compile_aot_emit.Source.handlerFactory(h.alias, h.code);
373
- let wref = handlerRef.get(src);
371
+ let fref = factoryRef.get(src);
372
+ if (fref === void 0) {
373
+ fref = `_h${factoryRef.size}`;
374
+ factoryRef.set(src, fref);
375
+ handlerDecls += `const ${fref} = ${src}\n`;
376
+ }
377
+ let wref = handlerRef.get(fref + k);
374
378
  if (wref === void 0) {
375
- const n = handlerRef.size;
376
379
  let aref = aliasRef.get(h.alias);
377
380
  if (aref === void 0) {
378
381
  aref = `_a${aliasRef.size}`;
379
382
  aliasRef.set(h.alias, aref);
380
383
  handlerDecls += `const ${aref} = ${JSON.stringify(h.alias ? h.alias.split(",") : [])}\n`;
381
384
  }
382
- wref = `_w${n}`;
383
- handlerRef.set(src, wref);
384
- handlerDecls += `const _h${n} = ${src}\nconst ${wref} = { a: ${aref}, f: _h${n} }\n`;
385
+ wref = `_w${handlerRef.size}`;
386
+ handlerRef.set(fref + k, wref);
387
+ handlerDecls += `const ${wref} = { a: ${aref}, f: ${fref}, ${k} }\n`;
385
388
  }
386
389
  (handlerTree[h.method] ??= {})[h.path] = wref;
387
390
  }
388
- let handlerExport = options?.register ? "const handlers = {\n" : "export const handlers = {\n";
391
+ let handlerExport = "const handlers = {\n";
389
392
  for (const method in handlerTree) {
390
393
  handlerExport += `\t${JSON.stringify(method)}: {\n`;
391
394
  for (const path in handlerTree[method]) handlerExport += `\t\t${JSON.stringify(path)}: ${handlerTree[method][path]},\n`;
392
395
  handlerExport += " },\n";
393
396
  }
394
397
  handlerExport += "}\n";
395
- const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
396
398
  let body = "// Generated by Elysia build plugin. Do not edit.\n";
397
- if (options?.register) body += `import { Compiled } from ${JSON.stringify(options.registerFrom ?? "elysia")}\n`;
398
- if (options?.register && enc.hasCoercePlan) body += `import { buildCoercedFromPlan } from ${JSON.stringify("elysia/coerce-plan")}\n`;
399
- if (options?.register && captured.length) body += `import { Reconstruct } from ${JSON.stringify(options.reconstructFrom ?? "elysia/reconstruct")}\n`;
399
+ const moduleCondition = options?.moduleCondition ?? "esm";
400
+ const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
401
+ body += importNamed("Compiled", options?.registerFrom ?? "elysia");
402
+ if (enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
403
+ if (captured.length) body += importNamed("Reconstruct", options?.reconstructFrom ?? "elysia/reconstruct");
400
404
  const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
401
405
  const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
402
- if (needs("CheckContext")) body += "import { CheckContext } from 'typebox/schema'\n";
403
- if (needs("Guard")) body += "import { Guard } from 'typebox/guard'\n";
404
- if (needs("Format")) body += "import { Format } from 'typebox/format'\n";
405
- if (needs("Hashing")) body += "import { Hashing } from 'typebox/system'\n";
406
- if (options?.register) {
407
- body += "\n";
408
- if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
409
- body += fingerprintExport + "Compiled.register((() => {\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { bf: 1, fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
406
+ if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
407
+ if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
408
+ if (needs("Format")) body += importNamed("Format", "typebox/format");
409
+ if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
410
+ body += "\n";
411
+ if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
412
+ body += `export const fingerprint = ${JSON.stringify(fingerprint)}\nCompiled.register((() => {
413
+ ` + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
410
414
  `;
411
- } else {
412
- body += "\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\n";
413
- if (!lazy) body += "\nexport default validators\n";
414
- }
415
415
  return body;
416
416
  }
417
417
 
@@ -1,6 +1,6 @@
1
1
  import { nullObject } from "../../utils.mjs";
2
2
  import { env } from "../../universal/env.mjs";
3
- import { Capture, Compiled, createAotFingerprint } from "../../compile/aot.mjs";
3
+ import { Compiled, createAotFingerprint } from "../../compile/aot.mjs";
4
4
  import { JITProbe } from "../../compile/jit-probe.mjs";
5
5
  import { setCaptureHeaderShorthand } from "../../compile/handler/jit.mjs";
6
6
  import { Validator } from "../../validator/index.mjs";
@@ -17,10 +17,8 @@ async function captureArtifacts(app, options) {
17
17
  const previousAotBuild = env.ELYSIA_AOT_BUILD;
18
18
  env.ELYSIA_AOT_BUILD = "1";
19
19
  try {
20
- if (!Capture.isCapturing()) throw new Error("[elysia-aot]: ELYSIA_AOT_BUILD=1 must be set to enable AOT capture mode");
21
20
  beginValidatorCapture();
22
- const modules = app.modules;
23
- if (modules) await modules;
21
+ await app.modules;
24
22
  if (options?.target !== void 0) setCaptureHeaderShorthand(options.target === "bun");
25
23
  app.compile();
26
24
  const captured = endValidatorCapture();
@@ -41,10 +39,14 @@ async function captureArtifacts(app, options) {
41
39
  }
42
40
  const materialiseHandlersForReplay = (captured) => {
43
41
  const manifest = {};
44
- for (const h of captured) (manifest[h.method] ??= {})[h.path] = {
45
- a: h.alias ? h.alias.split(",") : [],
46
- f: new Function(`return ${Source.handlerFactory(h.alias, h.code)}`)()
47
- };
42
+ for (const h of captured) {
43
+ if (!h.code) continue;
44
+ (manifest[h.method] ??= {})[h.path] = {
45
+ a: h.alias ? h.alias.split(",") : [],
46
+ f: new Function(`return ${Source.handlerFactory(h.alias, h.code)}`)(),
47
+ k: h.k
48
+ };
49
+ }
48
50
  return manifest;
49
51
  };
50
52
  function replayStubbability(app, handlers) {
@@ -55,23 +57,28 @@ function replayStubbability(app, handlers) {
55
57
  Compiled.clear();
56
58
  const fingerprint = createAotFingerprint();
57
59
  Compiled.register({
58
- bf: 1,
59
60
  fingerprint,
60
61
  handlers: materialiseHandlersForReplay(handlers)
61
62
  });
62
63
  Compiled.claim(app["~programId"], fingerprint);
63
64
  Validator.clear();
64
- const history = app["~routes"] ?? [];
65
+ const history = app["~routes"];
65
66
  JITProbe.begin();
67
+ const exact = /* @__PURE__ */ new Map();
68
+ for (const route of history) {
69
+ const method = route[0];
70
+ if (method === "WS") continue;
71
+ let paths = exact.get(method);
72
+ if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
73
+ if (paths.has(route[1])) JITProbe.record("handler:indexed-duplicate");
74
+ else paths.add(route[1]);
75
+ }
66
76
  for (const route of history) try {
67
77
  if (route[0] === "WS") continue;
68
78
  compileHandler(route, app);
69
79
  } catch {
70
- JITProbe.end();
71
- return {
72
- jit: false,
73
- reasons: ["handler:new-function"]
74
- };
80
+ JITProbe.record("handler:new-function");
81
+ return JITProbe.end();
75
82
  }
76
83
  return JITProbe.end();
77
84
  } finally {
@@ -94,45 +101,33 @@ const normalizeCheckIdentifiers = (src) => {
94
101
  };
95
102
  function createEntryEncoder() {
96
103
  const branchRef = /* @__PURE__ */ new Map();
97
- let branchDecls = "";
98
104
  const branchTable = (u) => "[" + u.map((branch) => "[" + branch.map((b) => {
99
105
  const src = normalizeCheckIdentifiers(Source.checkFactory(b.identifier, b.code));
100
106
  let ref = branchRef.get(src);
101
107
  if (ref === void 0) {
102
108
  ref = `_b${branchRef.size}`;
103
109
  branchRef.set(src, ref);
104
- branchDecls += `const ${ref} = ${src}\n`;
110
+ enc.branchDecls += `const ${ref} = ${src}\n`;
105
111
  }
106
112
  return ref;
107
113
  }).join(", ") + "]").join(", ") + "]";
108
114
  const unionRef = /* @__PURE__ */ new Map();
109
- let unionDecls = "";
110
- let hasCoercePlan = false;
111
- const unionTable = (u) => {
112
- const str = branchTable(u);
113
- let ref = unionRef.get(str);
114
- if (ref === void 0) {
115
- ref = `_u${unionRef.size}`;
116
- unionRef.set(str, ref);
117
- unionDecls += `const ${ref} = ${str}\n`;
118
- }
119
- return ref;
120
- };
121
- return {
122
- unionTable,
123
- setCoercePlan() {
124
- hasCoercePlan = true;
125
- },
126
- get branchDecls() {
127
- return branchDecls;
128
- },
129
- get unionDecls() {
130
- return unionDecls;
131
- },
132
- get hasCoercePlan() {
133
- return hasCoercePlan;
115
+ const enc = {
116
+ branchDecls: "",
117
+ unionDecls: "",
118
+ hasCoercePlan: false,
119
+ unionTable(u) {
120
+ const str = branchTable(u);
121
+ let ref = unionRef.get(str);
122
+ if (ref === void 0) {
123
+ ref = `_u${unionRef.size}`;
124
+ unionRef.set(str, ref);
125
+ enc.unionDecls += `const ${ref} = ${str}\n`;
126
+ }
127
+ return ref;
134
128
  }
135
129
  };
130
+ return enc;
136
131
  }
137
132
  function entryParts(c, enc) {
138
133
  const parts = [];
@@ -192,14 +187,15 @@ function entryParts(c, enc) {
192
187
  parts.push(`ic: [${ic}]`);
193
188
  }
194
189
  if (c.coercePlan) {
195
- enc.setCoercePlan();
190
+ enc.hasCoercePlan = true;
196
191
  parts.push(`cp: ${JSON.stringify(c.coercePlan)}`);
197
192
  }
198
193
  return parts;
199
194
  }
200
195
  function emitModule(captured, handlers, fingerprint, options) {
201
196
  const enc = createEntryEncoder();
202
- const treeToSource = (tree, slotRef, sink) => {
197
+ const treeToSource = (tree) => {
198
+ const slotRef = /* @__PURE__ */ new Map();
203
199
  const methods = [];
204
200
  for (const method in tree) {
205
201
  const paths = [];
@@ -209,7 +205,7 @@ function emitModule(captured, handlers, fingerprint, options) {
209
205
  if (ref === void 0) {
210
206
  ref = `_s${slotRef.size}`;
211
207
  slotRef.set(slotObj, ref);
212
- sink(`const ${ref} = ${slotObj}\n`);
208
+ validatorDecls += `const ${ref} = ${slotObj}\n`;
213
209
  }
214
210
  paths.push(`${JSON.stringify(path)}:${ref}`);
215
211
  }
@@ -341,7 +337,6 @@ function emitModule(captured, handlers, fingerprint, options) {
341
337
  }
342
338
  validatorDecls += `const _groups = [${thunks.join(", ")}]\n`;
343
339
  validatorDecls += `const _groupOf = ${JSON.stringify(groupOf)}\n`;
344
- validatorExport = options?.register ? "" : "export const groups = _groups\nexport const groupOf = _groupOf\n";
345
340
  } else {
346
341
  const factoryRef = /* @__PURE__ */ new Map();
347
342
  const tree = nullObject();
@@ -358,59 +353,64 @@ function emitModule(captured, handlers, fingerprint, options) {
358
353
  const byPath = tree[c.method] ??= nullObject();
359
354
  (byPath[c.path] ??= nullObject())[c.slot] = ref;
360
355
  }
361
- const treeStr = treeToSource(tree, /* @__PURE__ */ new Map(), (d) => {
362
- validatorDecls += d;
363
- });
364
- validatorExport = options?.register ? `const validators = ${treeStr}\n` : `export const validators = ${treeStr}\n`;
356
+ validatorExport = `const validators = ${treeToSource(tree)}\n`;
365
357
  }
366
358
  const aliasRef = /* @__PURE__ */ new Map();
359
+ const factoryRef = /* @__PURE__ */ new Map();
367
360
  const handlerRef = /* @__PURE__ */ new Map();
368
361
  let handlerDecls = "";
369
362
  const handlerTree = nullObject();
370
363
  for (const h of handlers) {
364
+ const k = h.k === void 0 ? "" : `k: ${JSON.stringify(h.k)}`;
365
+ if (!h.code) {
366
+ (handlerTree[h.method] ??= {})[h.path] = `{ ${k} }`;
367
+ continue;
368
+ }
371
369
  const src = Source.handlerFactory(h.alias, h.code);
372
- let wref = handlerRef.get(src);
370
+ let fref = factoryRef.get(src);
371
+ if (fref === void 0) {
372
+ fref = `_h${factoryRef.size}`;
373
+ factoryRef.set(src, fref);
374
+ handlerDecls += `const ${fref} = ${src}\n`;
375
+ }
376
+ let wref = handlerRef.get(fref + k);
373
377
  if (wref === void 0) {
374
- const n = handlerRef.size;
375
378
  let aref = aliasRef.get(h.alias);
376
379
  if (aref === void 0) {
377
380
  aref = `_a${aliasRef.size}`;
378
381
  aliasRef.set(h.alias, aref);
379
382
  handlerDecls += `const ${aref} = ${JSON.stringify(h.alias ? h.alias.split(",") : [])}\n`;
380
383
  }
381
- wref = `_w${n}`;
382
- handlerRef.set(src, wref);
383
- handlerDecls += `const _h${n} = ${src}\nconst ${wref} = { a: ${aref}, f: _h${n} }\n`;
384
+ wref = `_w${handlerRef.size}`;
385
+ handlerRef.set(fref + k, wref);
386
+ handlerDecls += `const ${wref} = { a: ${aref}, f: ${fref}, ${k} }\n`;
384
387
  }
385
388
  (handlerTree[h.method] ??= {})[h.path] = wref;
386
389
  }
387
- let handlerExport = options?.register ? "const handlers = {\n" : "export const handlers = {\n";
390
+ let handlerExport = "const handlers = {\n";
388
391
  for (const method in handlerTree) {
389
392
  handlerExport += `\t${JSON.stringify(method)}: {\n`;
390
393
  for (const path in handlerTree[method]) handlerExport += `\t\t${JSON.stringify(path)}: ${handlerTree[method][path]},\n`;
391
394
  handlerExport += " },\n";
392
395
  }
393
396
  handlerExport += "}\n";
394
- const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
395
397
  let body = "// Generated by Elysia build plugin. Do not edit.\n";
396
- if (options?.register) body += `import { Compiled } from ${JSON.stringify(options.registerFrom ?? "elysia")}\n`;
397
- if (options?.register && enc.hasCoercePlan) body += `import { buildCoercedFromPlan } from ${JSON.stringify("elysia/coerce-plan")}\n`;
398
- if (options?.register && captured.length) body += `import { Reconstruct } from ${JSON.stringify(options.reconstructFrom ?? "elysia/reconstruct")}\n`;
398
+ const moduleCondition = options?.moduleCondition ?? "esm";
399
+ const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
400
+ body += importNamed("Compiled", options?.registerFrom ?? "elysia");
401
+ if (enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
402
+ if (captured.length) body += importNamed("Reconstruct", options?.reconstructFrom ?? "elysia/reconstruct");
399
403
  const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
400
404
  const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
401
- if (needs("CheckContext")) body += "import { CheckContext } from 'typebox/schema'\n";
402
- if (needs("Guard")) body += "import { Guard } from 'typebox/guard'\n";
403
- if (needs("Format")) body += "import { Format } from 'typebox/format'\n";
404
- if (needs("Hashing")) body += "import { Hashing } from 'typebox/system'\n";
405
- if (options?.register) {
406
- body += "\n";
407
- if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
408
- body += fingerprintExport + "Compiled.register((() => {\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { bf: 1, fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
405
+ if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
406
+ if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
407
+ if (needs("Format")) body += importNamed("Format", "typebox/format");
408
+ if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
409
+ body += "\n";
410
+ if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
411
+ body += `export const fingerprint = ${JSON.stringify(fingerprint)}\nCompiled.register((() => {
412
+ ` + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
409
413
  `;
410
- } else {
411
- body += "\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\n";
412
- if (!lazy) body += "\nexport default validators\n";
413
- }
414
414
  return body;
415
415
  }
416
416
 
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_compile_lexer = require('../../compile/lexer.js');
3
3
 
4
4
  //#region src/plugin/aot/treeshake.ts
5
- const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
5
  function nonCodeSpans(code) {
7
6
  const spans = [];
8
7
  const length = code.length;
@@ -49,7 +48,7 @@ function rewriteTypeImport(code) {
49
48
  const from = "elysia";
50
49
  const typeFrom = "elysia/type";
51
50
  if (!code.includes(from)) return code;
52
- const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${escape(from)}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
51
+ const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${from}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
53
52
  const spans = nonCodeSpans(code);
54
53
  const edits = [];
55
54
  let m;
@@ -58,9 +57,7 @@ function rewriteTypeImport(code) {
58
57
  const keyword = m.index + lead.length + indent.length;
59
58
  if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
60
59
  const braceStart = clause.indexOf("{");
61
- if (braceStart === -1) continue;
62
60
  const braceEnd = clause.indexOf("}", braceStart);
63
- if (braceEnd === -1) continue;
64
61
  const before = clause.slice(0, braceStart).trim();
65
62
  const memberSource = clause.slice(braceStart + 1, braceEnd);
66
63
  if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
@@ -73,8 +70,7 @@ function rewriteTypeImport(code) {
73
70
  else kept.push(member);
74
71
  }
75
72
  if (!alias) continue;
76
- const head = before.replace(/,\s*$/, "").trim();
77
- const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
73
+ const keptClause = [before.replace(/,\s*$/, "").trim(), kept.length ? `{ ${kept.join(", ")} }` : ""].filter(Boolean).join(", ");
78
74
  const attr = attributes ?? "";
79
75
  const lines = [];
80
76
  if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
@@ -1,7 +1,6 @@
1
1
  import { skipString } from "../../compile/lexer.mjs";
2
2
 
3
3
  //#region src/plugin/aot/treeshake.ts
4
- const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5
4
  function nonCodeSpans(code) {
6
5
  const spans = [];
7
6
  const length = code.length;
@@ -48,7 +47,7 @@ function rewriteTypeImport(code) {
48
47
  const from = "elysia";
49
48
  const typeFrom = "elysia/type";
50
49
  if (!code.includes(from)) return code;
51
- const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${escape(from)}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
50
+ const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${from}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
52
51
  const spans = nonCodeSpans(code);
53
52
  const edits = [];
54
53
  let m;
@@ -57,9 +56,7 @@ function rewriteTypeImport(code) {
57
56
  const keyword = m.index + lead.length + indent.length;
58
57
  if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
59
58
  const braceStart = clause.indexOf("{");
60
- if (braceStart === -1) continue;
61
59
  const braceEnd = clause.indexOf("}", braceStart);
62
- if (braceEnd === -1) continue;
63
60
  const before = clause.slice(0, braceStart).trim();
64
61
  const memberSource = clause.slice(braceStart + 1, braceEnd);
65
62
  if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
@@ -72,8 +69,7 @@ function rewriteTypeImport(code) {
72
69
  else kept.push(member);
73
70
  }
74
71
  if (!alias) continue;
75
- const head = before.replace(/,\s*$/, "").trim();
76
- const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
72
+ const keptClause = [before.replace(/,\s*$/, "").trim(), kept.length ? `{ ${kept.join(", ")} }` : ""].filter(Boolean).join(", ");
77
73
  const attr = attributes ?? "";
78
74
  const lines = [];
79
75
  if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
@@ -16,14 +16,11 @@ interface ElysiaAotUnpluginFactoryResult {
16
16
  resolveId?: (id: string) => string | undefined;
17
17
  load?: (id: string) => string | undefined;
18
18
  transformInclude?: (id: string) => boolean;
19
- transform?: (code: string, id: string) => string | undefined | Promise<string | undefined>;
20
- /** Vite-specific override (`apply: 'build'` keeps dev on runtime JIT). */
19
+ transform?: (code: string, id: string) => string | undefined;
21
20
  vite?: {
22
21
  apply?: 'build' | 'serve';
23
22
  };
24
- /** rspack compiler hook: forces the manifest module side-effectful. */
25
23
  rspack?: (compiler: unknown) => void;
26
- /** webpack compiler hook: forces the manifest module side-effectful. */
27
24
  webpack?: (compiler: unknown) => void;
28
25
  }
29
26
  /**
@@ -2,7 +2,6 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
2
2
  const require_plugin_aot_hooks = require('./hooks.js');
3
3
 
4
4
  //#region src/plugin/aot/unplugin.ts
5
- const cleanIdOf = (id) => id.split("?", 1)[0];
6
5
  const VIRTUAL_MANIFEST_RESOURCE = /%00elysia%2Fcompiled/;
7
6
  const forceManifestSideEffect = (compiler) => {
8
7
  compiler.options.module.rules.push({
@@ -37,18 +36,10 @@ const aotFactory = (options) => {
37
36
  enforce: "pre",
38
37
  buildStart: hooks.buildStart,
39
38
  buildEnd: hooks.buildEnd,
40
- resolveId(id) {
41
- return hooks.resolveId(id) ?? void 0;
42
- },
43
- load(id) {
44
- return hooks.load(id) ?? void 0;
45
- },
46
- transformInclude(id) {
47
- return hooks.isTransformCandidate(cleanIdOf(id));
48
- },
49
- transform(code, id) {
50
- return hooks.transform(code, id);
51
- },
39
+ resolveId: hooks.resolveId,
40
+ load: hooks.load,
41
+ transformInclude: hooks.isTransformCandidate,
42
+ transform: hooks.transform,
52
43
  vite: { apply: "build" },
53
44
  rspack(compiler) {
54
45
  forceManifestSideEffect(compiler);