elysia 2.0.0-beta.2 → 2.0.0-beta.20

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 (337) 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 +11 -13
  25. package/dist/compile/aot.js +34 -46
  26. package/dist/compile/aot.mjs +35 -45
  27. package/dist/compile/handler/descriptor.d.ts +9 -12
  28. package/dist/compile/handler/descriptor.js +17 -41
  29. package/dist/compile/handler/descriptor.mjs +18 -39
  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 +6 -5
  34. package/dist/compile/handler/index.js +148 -109
  35. package/dist/compile/handler/index.mjs +149 -111
  36. package/dist/compile/handler/jit.d.ts +17 -17
  37. package/dist/compile/handler/jit.js +220 -148
  38. package/dist/compile/handler/jit.mjs +222 -151
  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 +4 -3
  44. package/dist/compile/handler/reconstruct.mjs +4 -3
  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 +1 -0
  66. package/dist/cookie/config.js +9 -9
  67. package/dist/cookie/config.mjs +9 -9
  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 +47 -60
  108. package/dist/plugin/aot/core.js +172 -109
  109. package/dist/plugin/aot/core.mjs +169 -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 +47 -62
  122. package/dist/plugin/aot/source.mjs +48 -63
  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 +29 -47
  139. package/dist/schema-snapshot.mjs +29 -47
  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 +2 -6
  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/constants.d.ts +1 -1
  162. package/dist/type/elysia/array-buffer.d.ts +4 -1
  163. package/dist/type/elysia/array-buffer.js +17 -17
  164. package/dist/type/elysia/array-buffer.mjs +17 -17
  165. package/dist/type/elysia/array-string.js +2 -40
  166. package/dist/type/elysia/array-string.mjs +2 -39
  167. package/dist/type/elysia/array.js +5 -9
  168. package/dist/type/elysia/array.mjs +5 -9
  169. package/dist/type/elysia/boolean-string.js +2 -3
  170. package/dist/type/elysia/boolean-string.mjs +1 -1
  171. package/dist/type/elysia/boolean.js +3 -12
  172. package/dist/type/elysia/boolean.mjs +3 -11
  173. package/dist/type/elysia/cookie.d.ts +3 -4
  174. package/dist/type/elysia/cookie.js +5 -15
  175. package/dist/type/elysia/cookie.mjs +5 -15
  176. package/dist/type/elysia/date.js +13 -20
  177. package/dist/type/elysia/date.mjs +10 -16
  178. package/dist/type/elysia/file-type.d.ts +11 -4
  179. package/dist/type/elysia/file-type.js +17 -2
  180. package/dist/type/elysia/file-type.mjs +17 -3
  181. package/dist/type/elysia/file.d.ts +1 -3
  182. package/dist/type/elysia/file.js +11 -27
  183. package/dist/type/elysia/file.mjs +11 -12
  184. package/dist/type/elysia/files.js +7 -11
  185. package/dist/type/elysia/files.mjs +7 -10
  186. package/dist/type/elysia/form.js +2 -3
  187. package/dist/type/elysia/form.mjs +3 -3
  188. package/dist/type/elysia/integer-string.d.ts +1 -1
  189. package/dist/type/elysia/integer-string.js +4 -30
  190. package/dist/type/elysia/integer-string.mjs +5 -30
  191. package/dist/type/elysia/integer.js +3 -12
  192. package/dist/type/elysia/integer.mjs +3 -11
  193. package/dist/type/elysia/intersect.js +0 -5
  194. package/dist/type/elysia/intersect.mjs +0 -5
  195. package/dist/type/elysia/json-string.d.ts +7 -0
  196. package/dist/type/elysia/json-string.js +47 -0
  197. package/dist/type/elysia/json-string.mjs +46 -0
  198. package/dist/type/elysia/maybe-empty.js +3 -4
  199. package/dist/type/elysia/maybe-empty.mjs +1 -1
  200. package/dist/type/elysia/nullable.js +2 -3
  201. package/dist/type/elysia/nullable.mjs +1 -1
  202. package/dist/type/elysia/number.d.ts +2 -1
  203. package/dist/type/elysia/number.js +19 -11
  204. package/dist/type/elysia/number.mjs +18 -10
  205. package/dist/type/elysia/numeric-enum.d.ts +1 -1
  206. package/dist/type/elysia/numeric-enum.js +4 -5
  207. package/dist/type/elysia/numeric-enum.mjs +3 -3
  208. package/dist/type/elysia/numeric.d.ts +4 -2
  209. package/dist/type/elysia/numeric.js +20 -17
  210. package/dist/type/elysia/numeric.mjs +19 -16
  211. package/dist/type/elysia/object-string.js +2 -37
  212. package/dist/type/elysia/object-string.mjs +2 -36
  213. package/dist/type/elysia/object.js +5 -9
  214. package/dist/type/elysia/object.mjs +5 -9
  215. package/dist/type/elysia/optional.js +8 -8
  216. package/dist/type/elysia/optional.mjs +7 -7
  217. package/dist/type/elysia/problem.d.ts +20 -0
  218. package/dist/type/elysia/problem.js +25 -0
  219. package/dist/type/elysia/problem.mjs +24 -0
  220. package/dist/type/elysia/string.js +4 -3
  221. package/dist/type/elysia/string.mjs +4 -2
  222. package/dist/type/elysia/uint8-array.d.ts +1 -1
  223. package/dist/type/elysia/uint8-array.js +5 -20
  224. package/dist/type/elysia/uint8-array.mjs +5 -19
  225. package/dist/type/elysia/union-enum.js +7 -8
  226. package/dist/type/elysia/union-enum.mjs +6 -6
  227. package/dist/type/elysia/union.js +0 -5
  228. package/dist/type/elysia/union.mjs +0 -5
  229. package/dist/type/elysia/utils.d.ts +2 -4
  230. package/dist/type/elysia/utils.js +10 -21
  231. package/dist/type/elysia/utils.mjs +7 -15
  232. package/dist/type/exports.d.ts +3 -2
  233. package/dist/type/exports.js +13 -2
  234. package/dist/type/exports.mjs +10 -2
  235. package/dist/type/index.d.ts +10 -2
  236. package/dist/type/index.js +52 -15
  237. package/dist/type/index.mjs +55 -11
  238. package/dist/type/shared.d.ts +3 -9
  239. package/dist/type/shared.js +44 -97
  240. package/dist/type/shared.mjs +43 -97
  241. package/dist/type/sync-require.d.ts +11 -0
  242. package/dist/type/sync-require.js +14 -0
  243. package/dist/type/sync-require.mjs +12 -0
  244. package/dist/type/typebox-system-lite.d.ts +2 -0
  245. package/dist/type/typebox-system-lite.js +34 -0
  246. package/dist/type/typebox-system-lite.mjs +3 -0
  247. package/dist/type/typebox-system-require.d.ts +7 -0
  248. package/dist/type/typebox-system-require.js +24 -0
  249. package/dist/type/typebox-system-require.mjs +23 -0
  250. package/dist/type/typebox-type-live.d.ts +11 -0
  251. package/dist/type/typebox-type-live.js +37 -0
  252. package/dist/type/typebox-type-live.mjs +20 -0
  253. package/dist/type/typebox-type.d.ts +26 -0
  254. package/dist/type/typebox-type.js +135 -0
  255. package/dist/type/typebox-type.mjs +70 -0
  256. package/dist/type/typebox-value-live.d.ts +11 -0
  257. package/dist/type/typebox-value-live.js +31 -0
  258. package/dist/type/typebox-value-live.mjs +13 -0
  259. package/dist/type/typebox-value-ops.d.ts +4 -0
  260. package/dist/type/typebox-value-ops.js +90 -0
  261. package/dist/type/typebox-value-ops.mjs +5 -0
  262. package/dist/type/typebox-value-require.d.ts +8 -0
  263. package/dist/type/typebox-value-require.js +28 -0
  264. package/dist/type/typebox-value-require.mjs +25 -0
  265. package/dist/type/typebox-value.d.ts +35 -0
  266. package/dist/type/typebox-value.js +161 -0
  267. package/dist/type/typebox-value.mjs +74 -0
  268. package/dist/type/utils.js +1 -10
  269. package/dist/type/utils.mjs +1 -10
  270. package/dist/type/validator/clean-safe.d.ts +2 -4
  271. package/dist/type/validator/clean-safe.js +15 -11
  272. package/dist/type/validator/clean-safe.mjs +16 -10
  273. package/dist/type/validator/custom-error.js +12 -16
  274. package/dist/type/validator/custom-error.mjs +11 -14
  275. package/dist/type/validator/default-precompute.d.ts +9 -1
  276. package/dist/type/validator/default-precompute.js +40 -77
  277. package/dist/type/validator/default-precompute.mjs +37 -74
  278. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  279. package/dist/type/validator/exact-mirror-live.js +22 -0
  280. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  281. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  282. package/dist/type/validator/exact-mirror-require.js +11 -0
  283. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  284. package/dist/type/validator/exact-mirror.js +8 -8
  285. package/dist/type/validator/exact-mirror.mjs +9 -8
  286. package/dist/type/validator/frozen-check.js +5 -6
  287. package/dist/type/validator/frozen-check.mjs +6 -7
  288. package/dist/type/validator/index.d.ts +1 -0
  289. package/dist/type/validator/index.js +169 -166
  290. package/dist/type/validator/index.mjs +162 -158
  291. package/dist/type/validator/string-codec-aot.d.ts +2 -1
  292. package/dist/type/validator/string-codec-aot.js +8 -2
  293. package/dist/type/validator/string-codec-aot.mjs +7 -2
  294. package/dist/type/validator/validator-cache.d.ts +5 -4
  295. package/dist/type/validator/validator-cache.js +41 -24
  296. package/dist/type/validator/validator-cache.mjs +40 -22
  297. package/dist/types.d.ts +261 -94
  298. package/dist/universal/constants.d.ts +2 -1
  299. package/dist/universal/constants.js +3 -1
  300. package/dist/universal/constants.mjs +2 -1
  301. package/dist/universal/env.js +2 -3
  302. package/dist/universal/env.mjs +2 -3
  303. package/dist/universal/file.d.ts +6 -4
  304. package/dist/universal/file.js +11 -16
  305. package/dist/universal/file.mjs +12 -16
  306. package/dist/universal/index.d.ts +2 -2
  307. package/dist/universal/is-production.d.ts +1 -2
  308. package/dist/universal/is-production.js +1 -3
  309. package/dist/universal/is-production.mjs +2 -3
  310. package/dist/universal/server.d.ts +0 -272
  311. package/dist/utils.d.ts +41 -7
  312. package/dist/utils.js +158 -126
  313. package/dist/utils.mjs +147 -126
  314. package/dist/validator/index.d.ts +1 -1
  315. package/dist/validator/index.js +17 -30
  316. package/dist/validator/index.mjs +18 -31
  317. package/dist/validator/route.js +2 -1
  318. package/dist/validator/route.mjs +2 -1
  319. package/dist/ws/context.d.ts +8 -1
  320. package/dist/ws/context.js +68 -44
  321. package/dist/ws/context.mjs +67 -44
  322. package/dist/ws/parser.js +10 -20
  323. package/dist/ws/parser.mjs +10 -20
  324. package/dist/ws/route.d.ts +2 -2
  325. package/dist/ws/route.js +219 -139
  326. package/dist/ws/route.mjs +223 -143
  327. package/dist/ws/types.d.ts +2 -2
  328. package/package.json +23 -49
  329. package/dist/compile/analysis-cache.d.ts +0 -6
  330. package/dist/compile/analysis-cache.js +0 -12
  331. package/dist/compile/analysis-cache.mjs +0 -11
  332. package/dist/cookie/index.d.ts +0 -7
  333. package/dist/cookie/index.js +0 -13
  334. package/dist/cookie/index.mjs +0 -7
  335. package/dist/handler/index.d.ts +0 -2
  336. package/dist/handler/index.js +0 -5
  337. package/dist/handler/index.mjs +0 -3
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_adapter_index = require('../index.js');
3
- const require_constants = require('../../constants.js');
4
3
  const require_utils = require('../../utils.js');
4
+ const require_type_bridge = require('../../type/bridge.js');
5
+ const require_universal_is_production = require('../../universal/is-production.js');
5
6
  const require_adapter_web_standard_index = require('../web-standard/index.js');
6
7
  const require_generation = require('../../generation.js');
7
8
  const require_adapter_origin = require('../origin.js');
@@ -9,6 +10,48 @@ const require_compile_handler_index = require('../../compile/handler/index.js');
9
10
  const require_route_table = require('../../route-table.js');
10
11
 
11
12
  //#region src/adapter/bun/index.ts
13
+ function runLifecycle(epoch, callback, ...args) {
14
+ const invoking = epoch.invoking;
15
+ epoch.invoking = true;
16
+ try {
17
+ return callback(...args);
18
+ } finally {
19
+ epoch.invoking = invoking;
20
+ }
21
+ }
22
+ const unavailableFetch = () => new Response(null, {
23
+ headers: { connection: "close" },
24
+ status: 503
25
+ });
26
+ function releaseLifecycle(app, ext, createdExt, stop, registerCleanup) {
27
+ if (ext.stop === stop) delete ext.stop;
28
+ if (ext.cleanupEpoch === registerCleanup) delete ext.cleanupEpoch;
29
+ if (createdExt && app["~ext"] === ext && !Object.keys(ext).length) app["~ext"] = void 0;
30
+ }
31
+ async function waitForServerRequests(server, abandoned) {
32
+ while (server.pendingRequests && !abandoned()) await Bun.sleep(1);
33
+ }
34
+ async function settleServerWebSockets(lifecycle, errors) {
35
+ if (!lifecycle) return true;
36
+ lifecycle.closing = true;
37
+ let failed = false;
38
+ do {
39
+ for (const socket of lifecycle.sockets) if (socket.readyState < 3) try {
40
+ socket.terminate();
41
+ } catch (error) {
42
+ errors.push(error);
43
+ failed = true;
44
+ }
45
+ if (failed) return false;
46
+ await Bun.sleep(1);
47
+ const abandon = lifecycle.abandon === true;
48
+ for (const socket of lifecycle.sockets) if (abandon || require_utils.isSocketQuiet(socket)) {
49
+ delete socket.data["~lifecycleRun"];
50
+ lifecycle.sockets.delete(socket);
51
+ }
52
+ } while (lifecycle.sockets.size);
53
+ return true;
54
+ }
12
55
  /**
13
56
  * ! This may looks like it would cause race condition, but it is not
14
57
  * Bun is single-threaded and synchronous, so the `finally` block will
@@ -26,102 +69,186 @@ const withOrigin = (fetch) => (request, server) => {
26
69
  require_adapter_origin.origin.request = void 0;
27
70
  }
28
71
  };
29
- const nativeStaticMethods = new Set([
30
- "GET",
31
- "POST",
32
- "PUT",
33
- "DELETE",
34
- "PATCH",
35
- "HEAD",
36
- "OPTIONS"
37
- ]);
72
+ const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
73
+ function expandOptional(path) {
74
+ const at = path.indexOf("?");
75
+ if (at === -1) return [path];
76
+ const start = path.lastIndexOf("/", at);
77
+ const rest = path.slice(at + 1);
78
+ return [...expandOptional(path.slice(0, start) + rest), ...expandOptional(path.slice(0, at) + rest)].map((variant) => variant || "/");
79
+ }
80
+ function isNativePath(path) {
81
+ const names = /* @__PURE__ */ new Set();
82
+ const segments = path.split("/");
83
+ for (let i = 0; i < segments.length; i++) {
84
+ const segment = segments[i];
85
+ if (segment.indexOf("*") !== -1) {
86
+ if (segment !== "*" || i !== segments.length - 1) return false;
87
+ } else if (segment.indexOf(":") !== -1) {
88
+ if (!/^:[A-Za-z_$][\w$]*$/.test(segment)) return false;
89
+ if (names.has(segment)) return false;
90
+ names.add(segment);
91
+ }
92
+ }
93
+ return true;
94
+ }
95
+ /**
96
+ * HTML bundles served by Bun's native router.
97
+ *
98
+ * A `:param` / `*` bundle (SPA fallback) matches before `fetch`, so with a
99
+ * `handoff` every other route of that method is registered natively too,
100
+ * handing off to `fetch`: Bun's specificity (exact > param > wildcard) then
101
+ * picks the Elysia route, and only unmatched paths reach the bundle (Elysia's
102
+ * own router leaves these bundles out, see `#buildRouterUnsafe`).
103
+ *
104
+ * All or nothing: when any route cannot be expressed in Bun's router, dynamic
105
+ * bundles are not served natively at all, since that route would be shadowed.
106
+ */
107
+ function collectHTMLBundleRoutes(app, handoff, routes) {
108
+ let dynamic;
109
+ let bundles;
110
+ for (const route of app["~routes"]) {
111
+ const [method, path, handler] = route;
112
+ if (!isNativeStaticMethod(method) || !require_utils.isHTMLBundle(handler)) continue;
113
+ if (path.indexOf(":") !== -1 || path.indexOf("*") !== -1) {
114
+ if (!handoff) continue;
115
+ (dynamic ??= /* @__PURE__ */ new Set()).add(method);
116
+ (bundles ??= []).push([
117
+ method,
118
+ path,
119
+ handler
120
+ ]);
121
+ } else ((routes ??= require_utils.nullObject())[path] ??= require_utils.nullObject())[method] = handler;
122
+ if (!require_universal_is_production.isProduction() && (route[4] || route[5] || route[6])) console.warn(`[Elysia] ${method} ${path} is an HTML bundle served natively, hooks do not run for it`);
123
+ }
124
+ if (!dynamic) return routes;
125
+ const strictPath = app["~config"]?.strictPath === true;
126
+ const handoffs = [];
127
+ for (const [method, path, handler] of app["~routes"]) {
128
+ if (require_utils.isHTMLBundle(handler)) continue;
129
+ const targets = method === "*" ? dynamic : dynamic.has(method) ? [method] : void 0;
130
+ if (!targets) continue;
131
+ for (const variant of expandOptional(path)) {
132
+ const loose = strictPath || variant.endsWith("*") ? variant : require_utils.getLoosePath(variant);
133
+ for (const raw of loose === variant ? [variant] : [variant, loose]) {
134
+ if (!isNativePath(raw)) {
135
+ if (!require_universal_is_production.isProduction()) console.warn(`[Elysia] ${method} ${path} cannot be expressed in Bun's router, so :param / * HTML bundles are not served natively (they would shadow it)`);
136
+ return routes;
137
+ }
138
+ const encoded = encodeURI(raw);
139
+ for (const target of targets) {
140
+ if (!/[^ -~]/.test(raw)) handoffs.push([raw, target]);
141
+ if (encoded !== raw) handoffs.push([encoded, target]);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ for (const [method, path, bundle] of bundles) ((routes ??= require_utils.nullObject())[path] ??= require_utils.nullObject())[method] = bundle;
147
+ for (const [key, method] of handoffs) (routes[key] ??= require_utils.nullObject())[method] ??= handoff;
148
+ return routes;
149
+ }
38
150
  function collectStaticRoutes(app) {
39
- if (app["~config"]?.nativeStaticResponse === false) return;
40
151
  app.fetch;
41
152
  const frozenRoot = require_generation.frozenRootOf(app);
42
153
  const fetchLevelHook = require_utils.flattenChain(frozenRoot["~hookChain"]);
43
- if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || frozenRoot["~ext"]?.hoc?.length) return;
154
+ const promoteResponses = app["~config"]?.nativeStaticResponse !== false && !fetchLevelHook?.request?.length && !fetchLevelHook?.trace?.length && !frozenRoot["~ext"]?.hoc?.length;
44
155
  const table = app["~generation"]?.routeTable ?? app["~routeTable"];
45
156
  const length = table?.length ?? 0;
46
157
  if (!table || !length) return;
47
- const methods = table.method;
48
- const paths = table.path;
49
- const handlers = table.handler;
158
+ const { method: methods, path: paths, handler: handlers, flags } = table;
159
+ const isStatic = (i) => isNativeStaticMethod(methods[i]) && (flags[i] & require_route_table.RouteFlag.Dynamic) === 0;
160
+ const isPromotable = (h) => promoteResponses && typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise);
50
161
  let hasCandidate = false;
51
162
  for (let i = 0; i < length; i++) {
163
+ if (!isStatic(i)) continue;
52
164
  const h = handlers[i];
53
- if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
54
- if (!nativeStaticMethods.has(methods[i])) continue;
55
- hasCandidate = true;
56
- break;
165
+ if (require_utils.isHTMLBundle(h) || isPromotable(h)) {
166
+ hasCandidate = true;
167
+ break;
168
+ }
57
169
  }
58
170
  if (!hasCandidate) return;
59
- const ready = require_utils.nullObject();
60
171
  const strictPath = frozenRoot["~config"]?.strictPath === true;
61
- const seen = /* @__PURE__ */ new Map();
62
- for (let i = 0; i < length; i++) seen.set(methods[i] + " " + paths[i], i);
63
- let explicitPaths;
64
- if (!strictPath) {
65
- explicitPaths = /* @__PURE__ */ new Map();
66
- for (let i = 0; i < length; i++) {
67
- const method = methods[i];
68
- const path = paths[i];
69
- let set = explicitPaths.get(method);
70
- if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
71
- set.add(path);
72
- if (require_constants.needEncodeRegex.test(path)) {
73
- const encoded = encodeURI(path);
74
- if (encoded !== path) set.add(encoded);
75
- }
172
+ const routeIndex = /* @__PURE__ */ new Map();
173
+ for (let i = 0; i < length; i++) {
174
+ if (!isStatic(i)) continue;
175
+ const method = methods[i];
176
+ const path = paths[i];
177
+ let pathsByMethod = routeIndex.get(method);
178
+ if (!pathsByMethod) routeIndex.set(method, pathsByMethod = /* @__PURE__ */ new Map());
179
+ pathsByMethod.set(path, i);
180
+ if (!strictPath && (flags[i] & require_route_table.RouteFlag.Encode) !== 0) {
181
+ const encoded = encodeURI(path);
182
+ if (encoded !== path && !pathsByMethod.has(encoded)) pathsByMethod.set(encoded, -1);
76
183
  }
77
184
  }
78
- const add = (method, path, value) => {
79
- if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
185
+ const ready = require_utils.nullObject();
186
+ let hasReady = false;
187
+ const add = (method, path, value, needsEncode) => {
188
+ if (needsEncode) path = encodeURI(path);
80
189
  (ready[path] ??= require_utils.nullObject())[method] = value;
190
+ hasReady = true;
81
191
  };
82
192
  for (let i = 0; i < length; i++) {
193
+ if (!isStatic(i)) continue;
83
194
  const method = methods[i];
84
- if (method === "WS") continue;
195
+ const pathsByMethod = routeIndex.get(method);
85
196
  const path = paths[i];
86
- if (seen.get(method + " " + path) !== i) continue;
87
- if (!nativeStaticMethods.has(method)) continue;
197
+ if (pathsByMethod.get(path) !== i) continue;
88
198
  const h = handlers[i];
89
- if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
90
- const value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
199
+ let value;
200
+ if (require_utils.isHTMLBundle(h)) value = h;
201
+ else if (!isPromotable(h)) continue;
202
+ else value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
91
203
  if (!value) continue;
92
- add(method, path, value);
93
- if (!strictPath && !require_constants.isDynamicRegex.test(path)) {
204
+ const needsEncode = (flags[i] & require_route_table.RouteFlag.Encode) !== 0;
205
+ add(method, path, value, needsEncode);
206
+ if (!strictPath) {
94
207
  const loose = require_utils.getLoosePath(path);
95
- if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
208
+ if (loose !== path && !pathsByMethod.has(loose)) add(method, loose, value, needsEncode);
96
209
  }
97
210
  }
98
- if (!Object.keys(ready).length) return;
99
- return [ready, []];
211
+ if (!hasReady) return;
212
+ return ready;
100
213
  }
101
214
  const BunAdapter = require_adapter_index.createAdapter({
102
- name: "bun",
103
- runtime: "bun",
104
- isWebStandard: true,
105
215
  parse: require_adapter_web_standard_index.WebStandardAdapter.parse,
106
216
  response: require_adapter_web_standard_index.WebStandardAdapter.response,
107
217
  listen(app, options, callback) {
108
- const _config = app["~config"]?.serve;
109
- const optionsIsObject = typeof options === "object";
110
- let live;
111
- const gatedFetch = (request, server) => live ? live(request, server) : Promise.resolve(ready).then(() => {
112
- if (!live) throw new Error("[Elysia] Server was stopped before it was ready");
113
- return live(request, server);
114
- });
115
- const _options = optionsIsObject ? { ...options } : {
218
+ if (app.server || app["~ext"]?.stop) throw new Error("[Elysia] Cannot call listen() while a server or teardown is active");
219
+ const requestReady = Promise.withResolvers();
220
+ function gatedFetch(request, server) {
221
+ return live && !cancelled ? live(request, server) : requestReady.promise.then(() => {
222
+ if (cancelled || !live) return unavailableFetch();
223
+ return live(request, server);
224
+ });
225
+ }
226
+ const _options = typeof options === "object" ? {
227
+ ...options,
228
+ fetch: gatedFetch
229
+ } : {
116
230
  port: +options,
117
231
  fetch: gatedFetch
118
232
  };
119
- if (optionsIsObject) _options.fetch = gatedFetch;
233
+ const _config = app["~config"]?.serve;
120
234
  const serve = _config ? {
121
235
  ..._config,
122
236
  ..._options
123
237
  } : _options;
124
- let ready;
238
+ const handoff = (request, server) => serve.fetch(request, server);
239
+ const htmlRoutes = collectHTMLBundleRoutes(app, app.pending ? void 0 : handoff);
240
+ const server = app.server = Bun.serve(serve.routes || serve.error || htmlRoutes ? {
241
+ ...serve,
242
+ error: unavailableFetch,
243
+ routes: htmlRoutes ?? {}
244
+ } : serve);
245
+ let live;
246
+ let cancelled = false;
247
+ let shutdownAttempt;
248
+ let wsLifecycle;
249
+ let modulesReady;
250
+ let pendingSetups;
251
+ let setupsSettled;
125
252
  const build = () => {
126
253
  const fetch = app.fetch;
127
254
  let routes;
@@ -130,11 +257,22 @@ const BunAdapter = require_adapter_index.createAdapter({
130
257
  } catch (error) {
131
258
  console.warn("[Elysia] Native static promotion was skipped:", error);
132
259
  }
260
+ routes = collectHTMLBundleRoutes(app, handoff, routes);
133
261
  let websocket;
134
262
  if (app["~hasWS"]) {
135
263
  const resolved = require_generation.resolvedWsOf(app);
136
264
  if (!resolved) throw new Error("[Elysia] internal: WebSocket routes are present but no capability provider was resolved");
137
- websocket = resolved.config ? Object.assign(resolved.provider.buildGlobalWSHandler(), resolved.config) : resolved.provider.buildGlobalWSHandler();
265
+ const handler = resolved.provider.buildGlobalWSHandler();
266
+ websocket = resolved.config ? Object.assign(handler, resolved.config) : handler;
267
+ const setter = Object.getOwnPropertyDescriptor(handler, "~lifecycle")?.set;
268
+ if (setter) {
269
+ wsLifecycle = {
270
+ closing: false,
271
+ sockets: /* @__PURE__ */ new Set(),
272
+ run: runLifecycle.bind(null, epoch)
273
+ };
274
+ setter.call(handler, wsLifecycle);
275
+ }
138
276
  }
139
277
  return {
140
278
  fetch,
@@ -142,75 +280,292 @@ const BunAdapter = require_adapter_index.createAdapter({
142
280
  websocket
143
281
  };
144
282
  };
145
- let built;
146
- const server = app.server = Bun.serve(serve);
147
- const reload = () => {
283
+ let startupFailure;
284
+ let forceRequested = false;
285
+ const force = Promise.withResolvers();
286
+ const abandon = Promise.withResolvers();
287
+ let forceDone = false;
288
+ let nativeStopped = false;
289
+ let abandoned = false;
290
+ let published = false;
291
+ let cleanupCompleted = false;
292
+ let idleRequired = false;
293
+ let cleanupFailures;
294
+ let observedOutcome;
295
+ let persistentCleanup;
296
+ let persistentCleanupLength = -1;
297
+ const epochCleanup = [];
298
+ const createdExt = app["~ext"] === void 0;
299
+ const ext = app["~ext"] ??= require_utils.nullObject();
300
+ const epoch = {
301
+ setup: false,
302
+ invoking: false
303
+ };
304
+ const snapshotCleanup = () => {
305
+ if (persistentCleanupLength !== -1) return;
306
+ persistentCleanup = ext.cleanup;
307
+ persistentCleanupLength = persistentCleanup?.length ?? 0;
308
+ };
309
+ const registerCleanup = (handler) => {
310
+ if (ext.cleanupEpoch !== registerCleanup) return false;
311
+ if (!epoch.setup) throw new Error("[Elysia] .cleanup() called after its setup epoch settled");
312
+ if (Array.isArray(handler)) epochCleanup.push(...handler);
313
+ else epochCleanup.push(handler);
314
+ return true;
315
+ };
316
+ const gate = () => {
317
+ if (!published) return;
318
+ live = void 0;
319
+ if (wsLifecycle) wsLifecycle.closing = true;
148
320
  try {
149
- server.reload(serve);
321
+ server.reload({
322
+ ...serve,
323
+ fetch: unavailableFetch,
324
+ error: unavailableFetch,
325
+ routes: {}
326
+ });
150
327
  } catch (error) {
151
- if (!serve.routes) throw error;
152
- delete serve.routes;
153
- console.warn("[Elysia] Native static promotion was skipped:", error);
154
- try {
155
- server.reload(serve);
156
- } catch (fallbackError) {
157
- console.error("[Elysia] Failed to reload Bun server:", fallbackError);
158
- throw fallbackError;
328
+ return { error };
329
+ }
330
+ };
331
+ const nativeStop = async (closeActiveConnections, errors) => {
332
+ try {
333
+ const stopping = server.stop(closeActiveConnections);
334
+ await (closeActiveConnections ? stopping : Promise.race([stopping, force.promise]));
335
+ if (!closeActiveConnections && forceRequested && !forceDone) return false;
336
+ nativeStopped = true;
337
+ if (closeActiveConnections) {
338
+ forceDone = true;
339
+ forceRequested = false;
340
+ }
341
+ return true;
342
+ } catch (error) {
343
+ if (closeActiveConnections) forceRequested = true;
344
+ errors.push(error);
345
+ return false;
346
+ }
347
+ };
348
+ const isAbandoned = () => abandoned;
349
+ const quiesce = async (force) => {
350
+ const errors = [];
351
+ if (!published) return {
352
+ errors,
353
+ releasable: await nativeStop(true, errors),
354
+ safe: true
355
+ };
356
+ if (force && !idleRequired && !wsLifecycle?.closing) {
357
+ const stopped = await nativeStop(true, errors);
358
+ return {
359
+ errors,
360
+ releasable: stopped,
361
+ safe: stopped
362
+ };
363
+ }
364
+ const gateFailure = gate();
365
+ if (gateFailure) errors.push(gateFailure.error);
366
+ let socketsSettled = await settleServerWebSockets(wsLifecycle, errors);
367
+ await Promise.resolve();
368
+ let close = forceRequested || gateFailure !== void 0 || !socketsSettled;
369
+ if (!close && nativeStopped) await waitForServerRequests(server, isAbandoned);
370
+ idleRequired = true;
371
+ let stopped = true;
372
+ while (!nativeStopped || forceRequested && !forceDone) {
373
+ if (nativeStopped) close = true;
374
+ stopped = await nativeStop(close, errors);
375
+ if (stopped) {
376
+ if (socketsSettled) socketsSettled = await settleServerWebSockets(wsLifecycle, errors);
377
+ continue;
378
+ }
379
+ if (close) break;
380
+ await waitForServerRequests(server, isAbandoned);
381
+ close = true;
382
+ }
383
+ let idleClosed = true;
384
+ if (idleRequired) {
385
+ const closeIdle = server.closeIdleConnections;
386
+ if (closeIdle) try {
387
+ closeIdle.call(server);
388
+ } catch (error) {
389
+ errors.push(error);
390
+ idleClosed = false;
159
391
  }
392
+ if (idleClosed && !gateFailure) idleRequired = false;
160
393
  }
394
+ const safe = socketsSettled && stopped && idleClosed && (!gateFailure || forceDone);
395
+ return {
396
+ errors,
397
+ releasable: safe,
398
+ safe
399
+ };
161
400
  };
162
401
  const setup = () => {
163
- const onSetup = app["~ext"]?.setup;
402
+ snapshotCleanup();
403
+ const onSetup = ext.setup;
164
404
  if (!onSetup) return;
165
- let pendingSetups;
405
+ epoch.setup = true;
406
+ ext.cleanupEpoch = registerCleanup;
166
407
  for (let i = 0; i < onSetup.length; i++) {
167
- const result = onSetup[i](app);
168
- if (result && typeof result.then === "function") (pendingSetups ??= []).push(result);
408
+ if (cancelled) break;
409
+ try {
410
+ const result = runLifecycle(epoch, onSetup[i], app);
411
+ if (result && typeof result.then === "function") (pendingSetups ??= []).push(Promise.resolve(result));
412
+ } catch (error) {
413
+ if (!pendingSetups) epoch.setup = false;
414
+ stop(true, { error }).catch(() => {});
415
+ throw error;
416
+ }
169
417
  }
170
- if (pendingSetups) return Promise.all(pendingSetups);
418
+ if (pendingSetups) {
419
+ setupsSettled = Promise.allSettled(pendingSetups);
420
+ return Promise.all(pendingSetups).then(() => epoch.setup = false);
421
+ }
422
+ epoch.setup = false;
171
423
  };
172
- const rollback = (error) => {
173
- if (app.server !== server) return;
174
- try {
175
- server.stop(true);
176
- } catch (stopError) {
177
- console.error(stopError);
178
- } finally {
179
- app.server = void 0;
180
- }
181
- const cleanup = app["~ext"]?.cleanup;
182
- if (cleanup) for (let i = cleanup.length - 1; i >= 0; i--) try {
183
- const result = cleanup[i](app);
184
- if (result && typeof result.then === "function") Promise.resolve(result).catch(console.error);
185
- } catch (cleanupError) {
186
- console.error(cleanupError);
187
- }
188
- return error;
424
+ const stop = (closeActiveConnections, failure) => {
425
+ const reentrant = epoch.invoking;
426
+ if (failure) startupFailure ??= failure;
427
+ if (closeActiveConnections === true) {
428
+ force.resolve();
429
+ if (!failure) abandon.resolve();
430
+ if (!forceDone) forceRequested = true;
431
+ }
432
+ cancelled = true;
433
+ requestReady.resolve();
434
+ if (app.server === server) app.server = void 0;
435
+ let outcome;
436
+ if (shutdownAttempt) {
437
+ if (closeActiveConnections === true && !forceDone) {
438
+ abandoned = true;
439
+ if (wsLifecycle) wsLifecycle.abandon = true;
440
+ }
441
+ outcome = shutdownAttempt;
442
+ } else {
443
+ const { promise, resolve, reject } = Promise.withResolvers();
444
+ outcome = shutdownAttempt = promise;
445
+ const quiescence = quiesce(forceRequested || !published);
446
+ let releasable = false;
447
+ let abandonedSetups;
448
+ (async () => {
449
+ try {
450
+ await Promise.resolve();
451
+ if (modulesReady) try {
452
+ await Promise.race([modulesReady, force.promise]);
453
+ } catch (error) {
454
+ startupFailure ??= { error };
455
+ }
456
+ if (setupsSettled) {
457
+ const setupResults = await Promise.race([setupsSettled, abandon.promise]);
458
+ if (!setupResults) abandonedSetups = setupsSettled;
459
+ else if (!startupFailure) for (let i = 0; i < setupResults.length; i++) {
460
+ const result = setupResults[i];
461
+ if (result.status === "rejected") {
462
+ startupFailure = { error: result.reason };
463
+ break;
464
+ }
465
+ }
466
+ }
467
+ epoch.setup = false;
468
+ const errors = [];
469
+ const quiesced = await quiescence;
470
+ if (startupFailure) errors.push(startupFailure.error);
471
+ errors.push(...quiesced.errors);
472
+ releasable = quiesced.releasable;
473
+ if (!quiesced.safe) {
474
+ if (cleanupFailures) errors.push(...cleanupFailures);
475
+ require_utils.throwLifecycleErrors(errors);
476
+ }
477
+ if (!cleanupCompleted) {
478
+ snapshotCleanup();
479
+ if (ext.stop === stop) {
480
+ const length = persistentCleanupLength + epochCleanup.length;
481
+ for (let n = 0; n < length; n++) {
482
+ if (ext.stop !== stop) break;
483
+ const i = startupFailure ? length - 1 - n : n;
484
+ const handler = i < persistentCleanupLength ? persistentCleanup[i] : epochCleanup[i - persistentCleanupLength];
485
+ try {
486
+ await runLifecycle(epoch, handler, app);
487
+ } catch (error) {
488
+ (cleanupFailures ??= []).push(error);
489
+ }
490
+ }
491
+ }
492
+ cleanupCompleted = true;
493
+ epochCleanup.length = 0;
494
+ }
495
+ if (cleanupFailures) errors.push(...cleanupFailures);
496
+ const release = () => releaseLifecycle(app, ext, createdExt, stop, registerCleanup);
497
+ if (releasable && abandonedSetups) abandonedSetups.then((results) => {
498
+ for (const result of results) if (result.status === "rejected") console.error("[Elysia] setup abandoned by stop(true) failed:", result.reason);
499
+ release();
500
+ });
501
+ else if (releasable) release();
502
+ require_utils.throwLifecycleErrors(errors);
503
+ } finally {
504
+ epoch.setup = false;
505
+ if (!releasable) shutdownAttempt = void 0;
506
+ }
507
+ })().then(resolve, reject);
508
+ }
509
+ if (!reentrant) return outcome;
510
+ if (observedOutcome !== outcome) {
511
+ observedOutcome = outcome;
512
+ outcome.catch((error) => {
513
+ console.error("[Elysia] stop() failed:", error);
514
+ });
515
+ }
516
+ return Promise.resolve();
189
517
  };
518
+ ext.stop = stop;
190
519
  const publish = () => {
191
- if (app.server !== server) return;
192
- built ??= build();
193
- live = serve.fetch = withOrigin(built.fetch);
194
- if (built.websocket) serve.websocket = built.websocket;
195
- if (built.routes) serve.routes = built.routes[0];
196
- reload();
197
- if (callback) callback(server);
520
+ if (cancelled || app.server !== server) {
521
+ requestReady.resolve();
522
+ return;
523
+ }
524
+ try {
525
+ const built = build();
526
+ live = serve.fetch = withOrigin(built.fetch);
527
+ published = true;
528
+ if (built.websocket) serve.websocket = built.websocket;
529
+ if (built.routes) serve.routes = built.routes;
530
+ try {
531
+ server.reload(serve);
532
+ } catch (error) {
533
+ if (!serve.routes) throw error;
534
+ delete serve.routes;
535
+ console.warn("[Elysia] Native static promotion was skipped:", error);
536
+ try {
537
+ server.reload(serve);
538
+ } catch (fallbackError) {
539
+ console.error("[Elysia] Failed to reload Bun server:", fallbackError);
540
+ throw fallbackError;
541
+ }
542
+ }
543
+ if (callback) callback(server);
544
+ } catch (error) {
545
+ startupFailure ??= { error };
546
+ throw error;
547
+ }
548
+ requestReady.resolve();
198
549
  };
199
550
  const start = () => {
200
- if (app.server !== server) return;
551
+ modulesReady = void 0;
552
+ if (cancelled || app.server !== server) {
553
+ requestReady.resolve();
554
+ return;
555
+ }
201
556
  const setupReady = setup();
202
- if (setupReady && typeof setupReady.then === "function") return Promise.resolve(setupReady).then(publish);
557
+ if (setupReady) return setupReady.then(publish);
203
558
  publish();
204
559
  };
205
560
  try {
206
- if (app.pending) ready = app.modules.then(start);
207
- else ready = Promise.resolve().then(start);
208
- ready.catch((error) => {
561
+ const modules = modulesReady = app.modules;
562
+ const preload = require_type_bridge.preloadTypebox();
563
+ (preload ? Promise.all([modules, preload]) : modules).then(start).catch((error) => stop(true, { error })).catch((error) => {
209
564
  console.error("[Elysia] listen() failed:", error);
210
- return rollback(error);
565
+ if (typeof process !== "undefined") process.exitCode = 1;
211
566
  });
212
567
  } catch (error) {
213
- rollback(error);
568
+ stop(true, { error }).catch(console.error);
214
569
  throw error;
215
570
  }
216
571
  }
@@ -218,4 +573,6 @@ const BunAdapter = require_adapter_index.createAdapter({
218
573
 
219
574
  //#endregion
220
575
  exports.BunAdapter = BunAdapter;
221
- exports.collectStaticRoutes = collectStaticRoutes;
576
+ exports.collectHTMLBundleRoutes = collectHTMLBundleRoutes;
577
+ exports.collectStaticRoutes = collectStaticRoutes;
578
+ exports.isHTMLBundle = require_utils.isHTMLBundle;