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
@@ -20,8 +20,31 @@ function findPackageRoot(from = process.cwd()) {
20
20
  return dir;
21
21
  }
22
22
  const resolveEntry = (entry) => (0, node_path.resolve)(findPackageRoot(), entry);
23
+ /** @internal Resolve the package condition used to evaluate an AOT entry. */
24
+ const resolveEntryModuleKind = (entry) => {
25
+ const entryPath = resolveEntry(entry);
26
+ switch ((0, node_path.extname)(entryPath)) {
27
+ case ".cjs":
28
+ case ".cts": return "cjs";
29
+ case ".mjs":
30
+ case ".mts":
31
+ case ".ts":
32
+ case ".tsx": return "esm";
33
+ case ".js":
34
+ case ".jsx": {
35
+ const packagePath = (0, node_path.join)(findPackageRoot((0, node_path.dirname)(entryPath)), "package.json");
36
+ if (!(0, node_fs.existsSync)(packagePath)) return "cjs";
37
+ const pkg = JSON.parse((0, node_fs.readFileSync)(packagePath, "utf8"));
38
+ if (pkg.type === "module") return "esm";
39
+ if (pkg.type === void 0 || pkg.type === "commonjs") return "cjs";
40
+ throw new Error(`[elysia-aot] package.json has unsupported "type" ${JSON.stringify(pkg.type)} for JavaScript entry ${JSON.stringify(entryPath)}.`);
41
+ }
42
+ default: throw new Error(`[elysia-aot] entry ${JSON.stringify(entryPath)} has an ambiguous module condition. Use a .cjs/.cts CommonJS entry or a .mjs/.mts/.ts/.tsx ESM entry; .js/.jsx follows the nearest package.json "type".`);
43
+ }
44
+ };
23
45
  const NO_STUB = {
24
46
  jit: false,
47
+ staticClone: false,
25
48
  ws: false,
26
49
  reconstruct: false,
27
50
  cookie: false,
@@ -29,6 +52,8 @@ const NO_STUB = {
29
52
  sucrose: false,
30
53
  compat: false,
31
54
  bridge: false,
55
+ typeboxValue: false,
56
+ exactMirror: false,
32
57
  adapter: false,
33
58
  isProduction: false
34
59
  };
@@ -49,20 +74,23 @@ const NO_STUB = {
49
74
  * is not active, so the bridge must stay wired the ordinary way. No compat
50
75
  * stub, no reroute.
51
76
  */
52
- function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true) {
77
+ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true, wsCookie = false, exactMirror = false) {
53
78
  const jit = report.jit;
54
79
  if (strip === true && !jit) throw new Error(`[elysia-aot] strip: true requires every route to be covered by the AOT handler manifest, but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Use strip: 'auto' to skip stubbing when the app is not fully precompiled.`);
55
80
  const mode = !jit ? "off" : allBridgeFree ? "sealed" : hasWS && zeroCapture ? "off" : "wired";
56
81
  return {
57
82
  plan: {
58
83
  jit,
84
+ staticClone: jit && !aliases.has("scl"),
59
85
  ws: !hasWS,
60
86
  reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
61
- cookie: jit && !aliases.has("cc"),
87
+ cookie: jit && !aliases.has("cc") && !wsCookie,
62
88
  trace: !aliases.has("tr") && (jit || !mayTrace),
63
89
  sucrose: jit,
64
90
  compat: mode !== "off",
65
91
  bridge: mode === "wired",
92
+ typeboxValue: mode !== "sealed",
93
+ exactMirror: exactMirror && mode !== "sealed",
66
94
  adapter: adapterStub,
67
95
  isProduction: productionStub
68
96
  },
@@ -73,71 +101,48 @@ function adapterConstantsSource(target) {
73
101
  if (target === "bun") return "import { BunAdapter } from './bun/index'\nexport const defaultAdapter = BunAdapter\n";
74
102
  return "import { WebStandardAdapter } from './web-standard/index'\nexport const defaultAdapter = WebStandardAdapter\n";
75
103
  }
76
- /** Filter matching elysia's own `adapter/constants` module (src + dist). */
77
104
  const ADAPTER_CONSTANTS_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]adapter[\\/]constants\.(m?js|ts)$/;
78
105
  const ADAPTER_BUN_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]adapter[\\/]bun[\\/]index\.(m?js|ts)$/;
79
106
  const IS_PRODUCTION_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]universal[\\/]is-production\.(m?js|ts)$/;
80
- /**
81
- * Loose fallback filter
82
- *
83
- * Matches the `/elysia/(dist|src)/` segment anywhere in a path (node_modules layouts,
84
- * monorepos, linked installs). Used by esbuild as a broad pre-filter
85
- *
86
- * The caller must further check that the path is under the resolved elysia package root
87
- * to avoid matching user code in a directory that happens to be named "elysia"
88
- *
89
- * @internal
90
- */
107
+ const TYPEBOX_TYPE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-type\.(m?js|ts)$/;
108
+ const TYPEBOX_SYSTEM_LITE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-system-lite\.(m?js|ts)$/;
109
+ const TYPEBOX_REQUIRE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value-require\.(m?js|ts)$/;
110
+ const EXACT_MIRROR_REQUIRE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]validator[\\/]exact-mirror-require\.(m?js|ts)$/;
91
111
  const ELYSIA_MODULE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/].+\.(m?js|ts)x?$/;
92
- /**
93
- * Build a predicate that returns `true` only for modules that are under the
94
- * resolved elysia package root (i.e. actually elysia's own files).
95
- *
96
- * Anchoring to the real package root prevents user projects rooted in a
97
- * directory named `elysia` (like this repo itself) from having their code
98
- * rewritten.
99
- *
100
- * Pass the result to both the esbuild `filter` (convert to RegExp via
101
- * `makeElysiaModuleFilterRegex`) and the Vite transform (`isElysiaModule`).
102
- */
103
- function resolveElysiaRoot(from = process.cwd()) {
112
+ function resolveElysiaRoot(from) {
104
113
  try {
105
114
  return (0, node_path.dirname)((0, node_module.createRequire)((0, node_path.join)(from, "package.json")).resolve("elysia/package.json"));
106
115
  } catch {
107
116
  return from;
108
117
  }
109
118
  }
110
- /**
111
- * Returns a predicate that is `true` only when the given module path is under
112
- * the resolved elysia package root AND matches the broad module filter.
113
- */
119
+ function resolveExactMirror(from) {
120
+ try {
121
+ (0, node_module.createRequire)((0, node_path.join)(resolveElysiaRoot(from), "package.json")).resolve("exact-mirror");
122
+ return true;
123
+ } catch {
124
+ return false;
125
+ }
126
+ }
114
127
  function makeIsElysiaModule(elysiaRoot) {
115
128
  const root = elysiaRoot.replace(/\\/g, "/");
116
129
  return (path) => {
117
130
  return path.replace(/\\/g, "/").startsWith(root + "/") && ELYSIA_MODULE_FILTER.test(path);
118
131
  };
119
132
  }
120
- /**
121
- * Build an esbuild-compatible RegExp that anchors to the resolved elysia root
122
- * so the `onLoad` pre-filter is as tight as possible. esbuild uses this as an
123
- * initial path filter before calling the callback, so we still double-check
124
- * with `makeIsElysiaModule` inside the callback.
125
- */
126
- function makeElysiaModuleFilterRegex(elysiaRoot) {
127
- const escaped = elysiaRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
128
- return new RegExp("^" + escaped + "[\\\\/](dist|src)[\\\\/].+\\.(m?js|ts)x?$");
129
- }
130
- function rewriteIsProductionCalls(code) {
131
- return code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
132
- }
133
- const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={name:'bun',runtime:'bun',isWebStandard:true,parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
133
+ const rewriteIsProductionCalls = (code) => code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
134
+ const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
134
135
  const STUB_SOURCES = {
136
+ staticClone: [{
137
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]static-clone-resolver\.(m?js|ts)$/,
138
+ source: `export const staticCloneResolver = undefined\n`
139
+ }],
135
140
  jit: [{
136
141
  filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]jit\.(m?js|ts)$/,
137
142
  source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
138
143
  }, {
139
144
  filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]descriptor\.(m?js|ts)$/,
140
- source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\nexport function isEmptyPipelineHook(hook){\n if(!hook)return true\n for(const key in hook){\n if(key==='detail'||key==='tags')continue\n const value=hook[key]\n if(value!==undefined&&value!==false&&(!Array.isArray(value)||value.length))return false\n }\n return true\n}\n"
145
+ source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\n"
141
146
  }],
142
147
  ws: [{
143
148
  filter: /[\\/]elysia[\\/](dist|src)[\\/]ws[\\/]route\.(m?js|ts)$/,
@@ -147,13 +152,20 @@ const STUB_SOURCES = {
147
152
  filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]reconstruct\.(m?js|ts)$/,
148
153
  source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class Reconstrct {\n static validator(){return e()}\n static cookie(){return e()}\n static trace(){return e()}\n}\n"
149
154
  }],
150
- cookie: [{
151
- filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]utils\.(m?js|ts)$/,
152
- source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport const hasSyncHmac=false\nexport function parseCookie(){return e()}\nexport function parseCookieRaw(){return e()}\nexport function parseCookieRawSync(){return e()}\nexport function parseCookieRawSigned(){return e()}\nexport function parseCookieRawLazy(){return e()}\nexport function parseCookieRawDeferred(){return e()}\nexport function buildCookieJar(){return e()}\nexport function signCookieValues(){return e()}\nexport function signCookie(){return e()}\nexport function signCookieSubtle(){return e()}\nexport function signCookieSync(){return e()}\nexport function unsignCookie(){return e()}\nexport function unsignCookieSync(){return e()}\n"
153
- }, {
154
- filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]config\.(m?js|ts)$/,
155
- source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport function compileCookieConfig(){return e()}\nexport function isCookieSigned(){return e()}\n"
156
- }],
155
+ cookie: [
156
+ {
157
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]crypto\.(m?js|ts)$/,
158
+ source: `export function resolvePendingCookie(){throw new Error("[elysia-aot] cookie support was stripped (strip mode) but a signed cookie was read. Rebuild with strip:false.")}\n`
159
+ },
160
+ {
161
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]utils\.(m?js|ts)$/,
162
+ source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport const hasSyncHmac=false\nexport function parseCookieRaw(){return e()}\nexport function parseCookieRawSync(){return e()}\nexport function parseCookieRawSigned(){return e()}\nexport function parseCookieRawLazy(){return e()}\nexport function parseCookieRawDeferred(){return e()}\nexport function buildCookieJar(){return e()}\nexport function signCookieValues(){return e()}\n"
163
+ },
164
+ {
165
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]config\.(m?js|ts)$/,
166
+ source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport function compileCookieConfig(){return e()}\n"
167
+ }
168
+ ],
157
169
  trace: [{
158
170
  filter: /[\\/]elysia[\\/](dist|src)[\\/]trace\.(m?js|ts)$/,
159
171
  source: "const e=()=>{throw new Error(\"[elysia-aot] trace support was stripped (strip mode) but a route used trace. Rebuild with strip:false.\")}\nexport function createTracer(){return e()}\nexport function unionTracePhases(){return new Set()}\n"
@@ -161,9 +173,6 @@ const STUB_SOURCES = {
161
173
  sucrose: [{
162
174
  filter: /[\\/]elysia[\\/](dist|src)[\\/]memory\.(m?js|ts)$/,
163
175
  source: "import { clearContextCache } from './context'\nimport { Validator } from './validator'\nexport function flushMemory() {\n clearContextCache()\n Validator.clear()\n}\n"
164
- }, {
165
- filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]analysis-cache\.(m?js|ts)$/,
166
- source: "import { clearHandlerAnalysisCaches } from './handler/index'\nimport { clearFlattenChainMemo } from '../utils'\nexport function clearAuthoringAnalysisCaches(root) {\n clearHandlerAnalysisCaches(root)\n clearFlattenChainMemo(root)\n}\n"
167
176
  }],
168
177
  compat: [{
169
178
  filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]compat\.(m?js|ts)$/,
@@ -172,11 +181,23 @@ const STUB_SOURCES = {
172
181
  bridge: [{
173
182
  filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]bridge\.(m?js|ts)$/,
174
183
  source: `export * from './bridge-live'\n`
184
+ }],
185
+ typeboxValue: [{
186
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value\.(m?js|ts)$/,
187
+ source: `export * from './typebox-value-live'\n`
188
+ }],
189
+ exactMirror: [{
190
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]validator[\\/]exact-mirror\.(m?js|ts)$/,
191
+ source: `export * from './exact-mirror-live'\n`
175
192
  }]
176
193
  };
177
194
  const alignStubExtensions = (stubSource, targetPath) => {
178
195
  const ext = targetPath.slice(targetPath.lastIndexOf("."));
179
196
  if (ext !== ".mjs" && ext !== ".js" && ext !== ".cjs") return stubSource;
197
+ if (ext !== ".mjs") {
198
+ const reexport = /^export \* from '(\.[^']+)'\n$/.exec(stubSource);
199
+ if (reexport) return `let m;const t=()=>m??=require('${reexport[1]}${ext}'),d=(o,k)=>Reflect.getOwnPropertyDescriptor(o,k)\nmodule.exports=new Proxy({},{get:(_,k)=>t()[k],has:(_,k)=>k in t(),ownKeys:()=>Reflect.ownKeys(t()),getOwnPropertyDescriptor:(o,k)=>{let x=d(o,k);if(x)return x;x=d(t(),k);if(x)x.configurable=true;return x},preventExtensions:o=>{for(const k of Reflect.ownKeys(t()))Object.defineProperty(o,k,d(t(),k));return Reflect.preventExtensions(o)}})\n`;
200
+ }
180
201
  return stubSource.replace(/(from ')(\.[^']+)(')/g, (_m, open, spec, close) => open + (spec === "./validator" ? spec + "/index" : spec) + ext + close);
181
202
  };
182
203
  const OVERRIDE_MAP = {
@@ -204,6 +225,10 @@ const OVERRIDE_MAP = {
204
225
  leaf: "boolean-string",
205
226
  export: "BooleanString"
206
227
  },
228
+ Composite: {
229
+ leaf: "keep-config",
230
+ export: "CompositeType"
231
+ },
207
232
  Cookie: {
208
233
  leaf: "cookie",
209
234
  export: "Cookie"
@@ -212,6 +237,10 @@ const OVERRIDE_MAP = {
212
237
  leaf: "date",
213
238
  export: "DateType"
214
239
  },
240
+ Evaluate: {
241
+ leaf: "keep-config",
242
+ export: "EvaluateType"
243
+ },
215
244
  File: {
216
245
  leaf: "file",
217
246
  export: "File"
@@ -232,10 +261,18 @@ const OVERRIDE_MAP = {
232
261
  leaf: "integer-string",
233
262
  export: "IntegerString"
234
263
  },
264
+ Interface: {
265
+ leaf: "keep-config",
266
+ export: "InterfaceType"
267
+ },
235
268
  Intersect: {
236
269
  leaf: "intersect",
237
270
  export: "Intersect"
238
271
  },
272
+ Mapped: {
273
+ leaf: "keep-config",
274
+ export: "MappedType"
275
+ },
239
276
  MaybeEmpty: {
240
277
  leaf: "maybe-empty",
241
278
  export: "MaybeEmpty"
@@ -268,10 +305,34 @@ const OVERRIDE_MAP = {
268
305
  leaf: "object-string",
269
306
  export: "ObjectString"
270
307
  },
308
+ Omit: {
309
+ leaf: "keep-config",
310
+ export: "OmitType"
311
+ },
271
312
  Optional: {
272
313
  leaf: "optional",
273
314
  export: "Optional"
274
315
  },
316
+ Partial: {
317
+ leaf: "keep-config",
318
+ export: "PartialType"
319
+ },
320
+ Pick: {
321
+ leaf: "keep-config",
322
+ export: "PickType"
323
+ },
324
+ Problem: {
325
+ leaf: "problem",
326
+ export: "Problem"
327
+ },
328
+ ReadonlyObject: {
329
+ leaf: "keep-config",
330
+ export: "ReadonlyObjectType"
331
+ },
332
+ Required: {
333
+ leaf: "keep-config",
334
+ export: "RequiredType"
335
+ },
275
336
  String: {
276
337
  leaf: "string",
277
338
  export: "StringType"
@@ -290,17 +351,20 @@ const OVERRIDE_MAP = {
290
351
  }
291
352
  };
292
353
  const requireFromHere = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
293
- const resolveSpecifier = (specifier) => {
294
- const meta = {};
295
- if (typeof meta.resolve === "function") {
296
- const url = meta.resolve(specifier);
297
- return url.startsWith("file://") ? new URL(url).pathname : url;
354
+ const moduleMeta = {};
355
+ const loadedModuleCondition = require("url").pathToFileURL(__filename).href.endsWith(".js") ? "cjs" : "esm";
356
+ const resolveSpecifier = (specifier, moduleCondition) => {
357
+ if (moduleCondition === "cjs") return requireFromHere.resolve(specifier);
358
+ if (moduleMeta.resolve) {
359
+ const url = moduleMeta.resolve(specifier);
360
+ return url.startsWith("file://") ? (0, node_url.fileURLToPath)(url) : url;
298
361
  }
362
+ if (moduleCondition === "esm") throw new Error("[elysia-aot] CommonJS-loaded build plugin cannot resolve the ESM package condition. Load the build plugin through import for an ESM entry.");
299
363
  return requireFromHere.resolve(specifier);
300
364
  };
301
- async function generateVirtualType(typeSpecifier = "elysia/type") {
302
- const typePath = resolveSpecifier(typeSpecifier);
303
- const typeboxPath = resolveSpecifier("typebox/type");
365
+ async function generateVirtualType(moduleCondition) {
366
+ const typePath = resolveSpecifier("elysia/type", moduleCondition);
367
+ const typeboxPath = resolveSpecifier("typebox/type", moduleCondition);
304
368
  const ext = typePath.slice(typePath.lastIndexOf("."));
305
369
  const leafDir = (0, node_path.join)((0, node_path.dirname)(typePath), "elysia");
306
370
  const typebox = await import((0, node_url.pathToFileURL)(typeboxPath).href);
@@ -316,13 +380,6 @@ async function generateVirtualType(typeSpecifier = "elysia/type") {
316
380
  return source;
317
381
  }
318
382
  const _importedEntries = /* @__PURE__ */ new Set();
319
- let activeGenerationWorkers = 0;
320
- let lastGenerationWorkerExit;
321
- /** @internal Test diagnostic for deterministic worker cleanup. */
322
- const getAotWorkerDiagnostics = () => ({
323
- activeWorkers: activeGenerationWorkers,
324
- lastExit: lastGenerationWorkerExit
325
- });
326
383
  /**
327
384
  * Extension mirroring the running module's own build output, so a sibling
328
385
  * source file can be resolved from `import.meta.url` in `.mjs`/`.js`/`.ts`
@@ -336,16 +393,15 @@ const workerUrl = () => {
336
393
  return new URL("./worker" + siblingModuleExt(moduleUrl), moduleUrl);
337
394
  };
338
395
  /** @internal Re-evaluate an entry in a disposable worker for watch rebuilds. */
339
- async function generateCompiledArtifactsIsolated(file, options) {
396
+ async function generateCompiledArtifactsIsolated(file, options, moduleCondition = resolveEntryModuleKind(file)) {
340
397
  const entry = resolveEntry(file);
341
398
  console.warn("[elysia-aot] re-evaluating \"" + entry + "\" in an isolated worker for rebuild. Top-level side effects run only inside the worker.");
342
399
  const worker = new node_worker_threads.Worker(workerUrl(), { workerData: {
343
400
  file: entry,
344
- options
401
+ options,
402
+ moduleCondition
345
403
  } });
346
- activeGenerationWorkers++;
347
404
  const exit = new Promise((resolve) => worker.once("exit", resolve));
348
- lastGenerationWorkerExit = exit;
349
405
  try {
350
406
  return await new Promise((resolve, reject) => {
351
407
  let received = false;
@@ -367,19 +423,34 @@ async function generateCompiledArtifactsIsolated(file, options) {
367
423
  await worker.terminate();
368
424
  } finally {
369
425
  await exit;
370
- activeGenerationWorkers--;
371
426
  }
372
427
  }
373
428
  }
374
- function isStandardResponse(response) {
375
- if (response == null || typeof response !== "object") return false;
376
- if (require_compile_handler_frozen_validator.isStandardSchema(response)) return true;
377
- if ("~kind" in response || "~elyAcl" in response) return false;
378
- const entries = Object.values(response);
379
- if (entries.length === 0) return false;
380
- return entries.every((v) => require_compile_handler_frozen_validator.isStandardSchema(v));
429
+ const validatorSlotKey = ({ method, path, slot }) => `${method}\0${path}\0${slot}`;
430
+ /** @internal Exact logical-slot gate used by AOT mode selection. */
431
+ function validatorSlotSetsMatch(expected, captured) {
432
+ const expectedKeys = new Set(expected.map(validatorSlotKey));
433
+ const capturedKeys = new Set(captured.map(validatorSlotKey));
434
+ if (expectedKeys.size !== capturedKeys.size) return false;
435
+ for (const key of expectedKeys) if (!capturedKeys.has(key)) return false;
436
+ return true;
381
437
  }
382
- async function generateCompiledArtifacts(file, options) {
438
+ /**
439
+ * The manifest is one flat `method -> path` table with no per-app namespace,
440
+ * bound to whichever app builds a router first, so a mounted sub-app (a second
441
+ * Elysia building on its own schedule) is not representable
442
+ *
443
+ * refuse at build time rather than ship a coin flip
444
+ */
445
+ const assertNoMount = (app, entry) => {
446
+ const routes = app["~routes"];
447
+ const mounted = [];
448
+ for (const route of routes) if (route[2]?.["~mount"] && !mounted.includes(route[1])) mounted.push(route[1]);
449
+ if (!mounted.length) return;
450
+ throw new Error(`[elysia-aot] "${entry}" mounts a sub-app (${mounted.join(", ")}). AOT cannot compile a mounted sub-app. Compose with .use() instead of .mount(), or disable AOT plugin`);
451
+ };
452
+ async function generateCompiledArtifacts(file, options, moduleCondition = resolveEntryModuleKind(file)) {
453
+ if (moduleCondition !== loadedModuleCondition) throw new Error(`[elysia-aot] entry uses the ${moduleCondition === "cjs" ? "CommonJS \"require\"" : "ESM \"import\""} package condition, but the AOT build plugin was loaded through ${loadedModuleCondition === "cjs" ? "CommonJS \"require\"" : "ESM \"import\""}; entry: ${JSON.stringify(resolveEntry(file))}. Load the plugin through ${moduleCondition === "cjs" ? "require()" : "import"} so capture and generated registration share one Elysia module instance.`);
383
454
  const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
384
455
  process.env.ELYSIA_AOT_BUILD = "1";
385
456
  const previousAotVerbose = process.env.ELYSIA_AOT_VERBOSE;
@@ -388,14 +459,15 @@ async function generateCompiledArtifacts(file, options) {
388
459
  try {
389
460
  const entry = resolveEntry(file);
390
461
  const entryReal = realPath(entry);
391
- if (_importedEntries.has(entryReal)) return generateCompiledArtifactsIsolated(file, options);
462
+ if (_importedEntries.has(entryReal)) return generateCompiledArtifactsIsolated(file, options, moduleCondition);
392
463
  _importedEntries.add(entryReal);
393
464
  const mod = await import(entry);
394
465
  const app = mod.app ?? mod.default;
395
466
  if (!app || typeof app.compile !== "function") throw new Error(`[elysia-aot] "${entry}" must export an Elysia app`);
396
467
  const typedApp = app;
468
+ assertNoMount(typedApp, entry);
397
469
  const sourceOptions = {
398
- register: true,
470
+ moduleCondition,
399
471
  registerFrom: options?.registerFrom,
400
472
  reconstructFrom: options?.reconstructFrom,
401
473
  lazy: options?.lazy,
@@ -404,10 +476,13 @@ async function generateCompiledArtifacts(file, options) {
404
476
  const strip = options?.strip ?? "auto";
405
477
  const adapterStub = options?.target === "bun" ? "bun" : options?.target === "node" || options?.target === "workerd" ? "web-standard" : false;
406
478
  const productionStub = options?.production !== false;
479
+ const exactMirror = resolveExactMirror(entry);
407
480
  if (strip === false) return {
408
481
  source: await require_plugin_aot_source.compileToSource(typedApp, sourceOptions),
409
482
  stub: {
410
483
  ...NO_STUB,
484
+ typeboxValue: true,
485
+ exactMirror,
411
486
  adapter: adapterStub,
412
487
  isProduction: productionStub
413
488
  },
@@ -417,32 +492,51 @@ async function generateCompiledArtifacts(file, options) {
417
492
  const report = require_plugin_aot_source.replayStubbability(typedApp, artifacts.handlers);
418
493
  const aliases = /* @__PURE__ */ new Set();
419
494
  for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(name);
420
- const hasWS = !!typedApp["~hasWS"] || !!typedApp["~routes"]?.some((route) => route?.[0] === "WS");
421
- const history = typedApp["~routes"] ?? [];
495
+ const history = typedApp["~routes"];
496
+ const hasWS = !!typedApp["~hasWS"] || history.some((route) => route[0] === "WS");
422
497
  const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
423
- let expectedSlots = 0;
498
+ const expectedSlots = [];
499
+ const declaredTypeBoxSlots = /* @__PURE__ */ new Set();
424
500
  let routesForbidSeal = false;
501
+ let wsCookie = false;
425
502
  for (const route of history) {
503
+ const method = route[0];
504
+ const path = route[1];
505
+ const expectTypeBoxSlot = (slot) => {
506
+ const identity = {
507
+ method,
508
+ path,
509
+ slot
510
+ };
511
+ const key = validatorSlotKey(identity);
512
+ if (declaredTypeBoxSlots.has(key)) routesForbidSeal = true;
513
+ else {
514
+ declaredTypeBoxSlots.add(key);
515
+ expectedSlots.push(identity);
516
+ }
517
+ };
426
518
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
427
519
  const hooks = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
520
+ if (method === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
428
521
  if (!hooks) continue;
429
522
  let routeHasTypeBoxDirectSlot = false;
430
- for (const slot of [
431
- "body",
432
- "query",
433
- "params",
434
- "headers",
435
- "cookie"
436
- ]) {
437
- const value = hooks[slot];
438
- if (value === void 0) continue;
439
- if (require_compile_handler_frozen_validator.isStandardSchema(value)) continue;
523
+ const classify = (schema, slot) => {
524
+ if (schema === void 0) {
525
+ routesForbidSeal = true;
526
+ return;
527
+ }
528
+ if (require_compile_handler_frozen_validator.isStandardSchema(schema)) return;
440
529
  routeHasTypeBoxDirectSlot = true;
441
- expectedSlots++;
530
+ expectTypeBoxSlot(slot);
531
+ };
532
+ for (const slot of require_compile_handler_frozen_validator.REQUEST_SLOTS) {
533
+ const value = hooks[slot];
534
+ if (value !== void 0) classify(require_compile_handler_frozen_validator.resolveModelRef(value, typedApp), slot);
442
535
  }
443
- if (hooks.response !== void 0 && !isStandardResponse(hooks.response)) {
444
- routeHasTypeBoxDirectSlot = true;
445
- expectedSlots++;
536
+ if (hooks.response !== void 0) {
537
+ const response = require_compile_handler_frozen_validator.resolveModelRef(hooks.response, typedApp);
538
+ if (require_compile_handler_frozen_validator.isResponseMap(response)) for (const status in response) classify(require_compile_handler_frozen_validator.resolveModelRef(response[status], typedApp), `response:${status}`);
539
+ else classify(response, "response:200");
446
540
  }
447
541
  const mergeSchemas = hooks.schemas;
448
542
  if (Array.isArray(mergeSchemas) && mergeSchemas.length > 0) {
@@ -450,13 +544,13 @@ async function generateCompiledArtifacts(file, options) {
450
544
  }
451
545
  }
452
546
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
453
- const frozenSlots = artifacts.validators.length;
454
- const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.length > 0 || artifacts.validators.length > 0) && !routesForbidSeal && frozenSlots === expectedSlots && artifacts.validators.every((v) => v.bridgeFree === true), artifacts.handlers.length === 0 && artifacts.validators.length === 0, adapterStub, productionStub);
547
+ const validatorSlotsMatch = validatorSlotSetsMatch(expectedSlots, artifacts.validators);
548
+ const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.some((h) => h.code) || artifacts.validators.length > 0) && !routesForbidSeal && validatorSlotsMatch && artifacts.validators.every((v) => v.bridgeFree === true), !artifacts.handlers.some((h) => h.code) && artifacts.validators.length === 0, adapterStub, productionStub, wsCookie, exactMirror);
455
549
  if (options?.target === "workerd") {
456
550
  if (!report.jit) throw new Error(`[elysia-aot] target 'workerd' but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Every route must be captured into the AOT manifest.`);
457
- if (frozenSlots !== expectedSlots) console.warn(`[elysia-aot] target 'workerd': only ${frozenSlots}/${expectedSlots} validator slots were frozen unfrozen slots compile at runtime and will fail on workerd.`);
551
+ if (!validatorSlotsMatch) console.warn("[elysia-aot] target 'workerd': captured validator slots do not exactly match declared slots; unfrozen slots compile at runtime and will fail on workerd.");
458
552
  }
459
- const virtualType = mode === "off" ? void 0 : await generateVirtualType("elysia/type");
553
+ const virtualType = mode === "off" ? void 0 : await generateVirtualType(moduleCondition);
460
554
  return {
461
555
  source: artifacts.source,
462
556
  stub,
@@ -483,23 +577,28 @@ const realPath = (path) => {
483
577
  exports.ADAPTER_BUN_FILTER = ADAPTER_BUN_FILTER;
484
578
  exports.ADAPTER_CONSTANTS_FILTER = ADAPTER_CONSTANTS_FILTER;
485
579
  exports.ELYSIA_MODULE_FILTER = ELYSIA_MODULE_FILTER;
580
+ exports.EXACT_MIRROR_REQUIRE_FILTER = EXACT_MIRROR_REQUIRE_FILTER;
486
581
  exports.IS_PRODUCTION_FILTER = IS_PRODUCTION_FILTER;
487
582
  exports.NO_STUB = NO_STUB;
488
583
  exports.OVERRIDE_MAP = OVERRIDE_MAP;
489
584
  exports.SOURCE_REGEX = SOURCE_REGEX;
490
585
  exports.STUB_SOURCES = STUB_SOURCES;
586
+ exports.TYPEBOX_REQUIRE_FILTER = TYPEBOX_REQUIRE_FILTER;
587
+ exports.TYPEBOX_SYSTEM_LITE_FILTER = TYPEBOX_SYSTEM_LITE_FILTER;
588
+ exports.TYPEBOX_TYPE_FILTER = TYPEBOX_TYPE_FILTER;
491
589
  exports.adapterConstantsSource = adapterConstantsSource;
492
590
  exports.alignStubExtensions = alignStubExtensions;
493
591
  exports.bunAdapterStubSource = bunAdapterStubSource;
494
592
  exports.generateCompiledArtifacts = generateCompiledArtifacts;
495
593
  exports.generateCompiledArtifactsIsolated = generateCompiledArtifactsIsolated;
496
594
  exports.generateVirtualType = generateVirtualType;
497
- exports.getAotWorkerDiagnostics = getAotWorkerDiagnostics;
498
- exports.makeElysiaModuleFilterRegex = makeElysiaModuleFilterRegex;
499
595
  exports.makeIsElysiaModule = makeIsElysiaModule;
500
596
  exports.planFromReport = planFromReport;
501
597
  exports.realPath = realPath;
502
598
  exports.resolveElysiaRoot = resolveElysiaRoot;
503
599
  exports.resolveEntry = resolveEntry;
600
+ exports.resolveEntryModuleKind = resolveEntryModuleKind;
601
+ exports.resolveExactMirror = resolveExactMirror;
504
602
  exports.rewriteIsProductionCalls = rewriteIsProductionCalls;
505
- exports.siblingModuleExt = siblingModuleExt;
603
+ exports.siblingModuleExt = siblingModuleExt;
604
+ exports.validatorSlotSetsMatch = validatorSlotSetsMatch;