elysia 1.4.28 → 2.0.0-beta.0

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 (454) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +29 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +38 -0
  3. package/dist/adapter/bun/index.d.ts +7 -6
  4. package/dist/adapter/bun/index.js +219 -380
  5. package/dist/adapter/bun/index.mjs +217 -382
  6. package/dist/adapter/constants.d.ts +6 -0
  7. package/dist/adapter/constants.js +10 -0
  8. package/dist/adapter/constants.mjs +9 -0
  9. package/dist/adapter/default-headers.d.ts +4 -0
  10. package/dist/adapter/default-headers.js +7 -0
  11. package/dist/adapter/default-headers.mjs +5 -0
  12. package/dist/adapter/index.d.ts +8 -1
  13. package/dist/adapter/index.js +7 -14
  14. package/dist/adapter/index.mjs +5 -0
  15. package/dist/adapter/origin.d.ts +63 -0
  16. package/dist/adapter/origin.js +64 -0
  17. package/dist/adapter/origin.mjs +62 -0
  18. package/dist/adapter/response-ownership.d.ts +5 -0
  19. package/dist/adapter/response-ownership.js +13 -0
  20. package/dist/adapter/response-ownership.mjs +10 -0
  21. package/dist/adapter/skip-clone.d.ts +4 -0
  22. package/dist/adapter/skip-clone.js +7 -0
  23. package/dist/adapter/skip-clone.mjs +5 -0
  24. package/dist/adapter/types.d.ts +50 -125
  25. package/dist/adapter/types.js +1 -14
  26. package/dist/adapter/types.mjs +1 -0
  27. package/dist/adapter/utils.d.ts +47 -19
  28. package/dist/adapter/utils.js +561 -311
  29. package/dist/adapter/utils.mjs +551 -283
  30. package/dist/adapter/web-standard/handler.d.ts +11 -9
  31. package/dist/adapter/web-standard/handler.js +146 -415
  32. package/dist/adapter/web-standard/handler.mjs +144 -400
  33. package/dist/adapter/web-standard/index.d.ts +5 -2
  34. package/dist/adapter/web-standard/index.js +68 -161
  35. package/dist/adapter/web-standard/index.mjs +68 -146
  36. package/dist/adapter/web-standard/utils.d.ts +4 -0
  37. package/dist/adapter/web-standard/utils.js +153 -0
  38. package/dist/adapter/web-standard/utils.mjs +152 -0
  39. package/dist/base.d.ts +898 -0
  40. package/dist/base.js +1564 -0
  41. package/dist/base.mjs +1561 -0
  42. package/dist/compile/analysis-cache.d.ts +6 -0
  43. package/dist/compile/analysis-cache.js +12 -0
  44. package/dist/compile/analysis-cache.mjs +11 -0
  45. package/dist/compile/aot-capture.d.ts +24 -0
  46. package/dist/compile/aot-capture.js +376 -0
  47. package/dist/compile/aot-capture.mjs +365 -0
  48. package/dist/compile/aot-emit.d.ts +29 -0
  49. package/dist/compile/aot-emit.js +107 -0
  50. package/dist/compile/aot-emit.mjs +101 -0
  51. package/dist/compile/aot-reconstruct.d.ts +30 -0
  52. package/dist/compile/aot-reconstruct.js +156 -0
  53. package/dist/compile/aot-reconstruct.mjs +147 -0
  54. package/dist/compile/aot.d.ts +287 -0
  55. package/dist/compile/aot.js +220 -0
  56. package/dist/compile/aot.mjs +200 -0
  57. package/dist/compile/handler/descriptor.d.ts +77 -0
  58. package/dist/compile/handler/descriptor.js +199 -0
  59. package/dist/compile/handler/descriptor.mjs +194 -0
  60. package/dist/compile/handler/frozen-validator.d.ts +39 -0
  61. package/dist/compile/handler/frozen-validator.js +319 -0
  62. package/dist/compile/handler/frozen-validator.mjs +313 -0
  63. package/dist/compile/handler/index.d.ts +19 -0
  64. package/dist/compile/handler/index.js +379 -0
  65. package/dist/compile/handler/index.mjs +371 -0
  66. package/dist/compile/handler/jit.d.ts +43 -0
  67. package/dist/compile/handler/jit.js +536 -0
  68. package/dist/compile/handler/jit.mjs +532 -0
  69. package/dist/compile/handler/params.d.ts +28 -0
  70. package/dist/compile/handler/params.js +78 -0
  71. package/dist/compile/handler/params.mjs +76 -0
  72. package/dist/compile/handler/reconstruct.d.ts +12 -0
  73. package/dist/compile/handler/reconstruct.js +50 -0
  74. package/dist/compile/handler/reconstruct.mjs +49 -0
  75. package/dist/compile/handler/utils.d.ts +45 -0
  76. package/dist/compile/handler/utils.js +514 -0
  77. package/dist/compile/handler/utils.mjs +498 -0
  78. package/dist/compile/jit-probe.d.ts +15 -0
  79. package/dist/compile/jit-probe.js +28 -0
  80. package/dist/compile/jit-probe.mjs +26 -0
  81. package/dist/compile/lexer.d.ts +7 -0
  82. package/dist/compile/lexer.js +53 -0
  83. package/dist/compile/lexer.mjs +48 -0
  84. package/dist/compile/utils.d.ts +8 -0
  85. package/dist/compile/utils.js +23 -0
  86. package/dist/compile/utils.mjs +19 -0
  87. package/dist/compiled.d.ts +17 -0
  88. package/dist/compiled.js +20 -0
  89. package/dist/compiled.mjs +16 -0
  90. package/dist/constants.d.ts +137 -0
  91. package/dist/constants.js +96 -0
  92. package/dist/constants.mjs +88 -0
  93. package/dist/context.d.ts +86 -129
  94. package/dist/context.js +110 -13
  95. package/dist/context.mjs +108 -0
  96. package/dist/cookie/config.d.ts +31 -0
  97. package/dist/cookie/config.js +98 -0
  98. package/dist/cookie/config.mjs +95 -0
  99. package/dist/cookie/cookie.d.ts +26 -0
  100. package/dist/cookie/cookie.js +105 -0
  101. package/dist/cookie/cookie.mjs +104 -0
  102. package/dist/cookie/crypto.d.ts +20 -0
  103. package/dist/cookie/crypto.js +168 -0
  104. package/dist/cookie/crypto.mjs +151 -0
  105. package/dist/cookie/error.d.ts +17 -0
  106. package/dist/cookie/error.js +25 -0
  107. package/dist/cookie/error.mjs +24 -0
  108. package/dist/cookie/index.d.ts +7 -0
  109. package/dist/cookie/index.js +13 -0
  110. package/dist/cookie/index.mjs +7 -0
  111. package/dist/cookie/lib.d.ts +7 -0
  112. package/dist/cookie/lib.js +76 -0
  113. package/dist/cookie/lib.mjs +74 -0
  114. package/dist/cookie/serialize.d.ts +6 -0
  115. package/dist/cookie/serialize.js +32 -0
  116. package/dist/cookie/serialize.mjs +31 -0
  117. package/dist/cookie/types.d.ts +113 -0
  118. package/dist/cookie/types.js +1 -0
  119. package/dist/cookie/types.mjs +1 -0
  120. package/dist/cookie/utils.d.ts +25 -0
  121. package/dist/cookie/utils.js +182 -0
  122. package/dist/cookie/utils.mjs +171 -0
  123. package/dist/error.d.ts +226 -188
  124. package/dist/error.js +519 -357
  125. package/dist/error.mjs +503 -327
  126. package/dist/generation.d.ts +30 -0
  127. package/dist/generation.js +23 -0
  128. package/dist/generation.mjs +17 -0
  129. package/dist/handler/error.d.ts +7 -0
  130. package/dist/handler/error.js +105 -0
  131. package/dist/handler/error.mjs +104 -0
  132. package/dist/handler/fetch.d.ts +8 -0
  133. package/dist/handler/fetch.js +371 -0
  134. package/dist/handler/fetch.mjs +367 -0
  135. package/dist/handler/index.d.ts +2 -0
  136. package/dist/handler/index.js +5 -0
  137. package/dist/handler/index.mjs +3 -0
  138. package/dist/handler/utils.d.ts +15 -0
  139. package/dist/handler/utils.js +48 -0
  140. package/dist/handler/utils.mjs +42 -0
  141. package/dist/index.d.ts +23 -2198
  142. package/dist/index.js +62 -1948
  143. package/dist/index.mjs +20 -1986
  144. package/dist/memory.d.ts +4 -0
  145. package/dist/memory.js +17 -0
  146. package/dist/memory.mjs +16 -0
  147. package/dist/package.js +11 -0
  148. package/dist/package.mjs +5 -0
  149. package/dist/parse-query.d.ts +7 -9
  150. package/dist/parse-query.js +154 -164
  151. package/dist/parse-query.mjs +150 -133
  152. package/dist/plugin/aot/bun.d.ts +26 -0
  153. package/dist/plugin/aot/bun.js +35 -0
  154. package/dist/plugin/aot/bun.mjs +34 -0
  155. package/dist/plugin/aot/core.d.ts +291 -0
  156. package/dist/plugin/aot/core.js +505 -0
  157. package/dist/plugin/aot/core.mjs +481 -0
  158. package/dist/plugin/aot/esbuild.d.ts +28 -0
  159. package/dist/plugin/aot/esbuild.js +48 -0
  160. package/dist/plugin/aot/esbuild.mjs +46 -0
  161. package/dist/plugin/aot/hooks.d.ts +28 -0
  162. package/dist/plugin/aot/hooks.js +114 -0
  163. package/dist/plugin/aot/hooks.mjs +112 -0
  164. package/dist/plugin/aot/rspack-loader.d.ts +23 -0
  165. package/dist/plugin/aot/rspack-loader.js +44 -0
  166. package/dist/plugin/aot/rspack-loader.mjs +40 -0
  167. package/dist/plugin/aot/rspack.d.ts +23 -0
  168. package/dist/plugin/aot/rspack.js +85 -0
  169. package/dist/plugin/aot/rspack.mjs +82 -0
  170. package/dist/plugin/aot/source.d.ts +60 -0
  171. package/dist/plugin/aot/source.js +422 -0
  172. package/dist/plugin/aot/source.mjs +418 -0
  173. package/dist/plugin/aot/treeshake.d.ts +4 -0
  174. package/dist/plugin/aot/treeshake.js +95 -0
  175. package/dist/plugin/aot/treeshake.mjs +94 -0
  176. package/dist/plugin/aot/unplugin.d.ts +50 -0
  177. package/dist/plugin/aot/unplugin.js +64 -0
  178. package/dist/plugin/aot/unplugin.mjs +62 -0
  179. package/dist/plugin/aot/vite.d.ts +30 -0
  180. package/dist/plugin/aot/vite.js +34 -0
  181. package/dist/plugin/aot/vite.mjs +33 -0
  182. package/dist/plugin/aot/worker.d.ts +1 -0
  183. package/dist/plugin/aot/worker.js +28 -0
  184. package/dist/plugin/aot/worker.mjs +27 -0
  185. package/dist/plugin/auto-head.d.ts +6 -0
  186. package/dist/plugin/auto-head.js +38 -0
  187. package/dist/plugin/auto-head.mjs +36 -0
  188. package/dist/plugin/trace.d.ts +10 -0
  189. package/dist/plugin/trace.js +39 -0
  190. package/dist/plugin/trace.mjs +36 -0
  191. package/dist/plugin/websocket.d.ts +6 -0
  192. package/dist/plugin/websocket.js +61 -0
  193. package/dist/plugin/websocket.mjs +60 -0
  194. package/dist/route-table.d.ts +28 -0
  195. package/dist/route-table.js +64 -0
  196. package/dist/route-table.mjs +61 -0
  197. package/dist/schema-snapshot.d.ts +9 -0
  198. package/dist/schema-snapshot.js +271 -0
  199. package/dist/schema-snapshot.mjs +269 -0
  200. package/dist/sucrose.d.ts +28 -63
  201. package/dist/sucrose.js +814 -306
  202. package/dist/sucrose.mjs +805 -274
  203. package/dist/trace.d.ts +145 -130
  204. package/dist/trace.js +387 -135
  205. package/dist/trace.mjs +385 -113
  206. package/dist/type/bridge-live.d.ts +15 -0
  207. package/dist/type/bridge-live.js +39 -0
  208. package/dist/type/bridge-live.mjs +17 -0
  209. package/dist/type/bridge.d.ts +56 -0
  210. package/dist/type/bridge.js +180 -0
  211. package/dist/type/bridge.mjs +63 -0
  212. package/dist/type/coerce-plan.d.ts +38 -0
  213. package/dist/type/coerce-plan.js +107 -0
  214. package/dist/type/coerce-plan.mjs +98 -0
  215. package/dist/type/coerce.d.ts +43 -0
  216. package/dist/type/coerce.js +351 -0
  217. package/dist/type/coerce.mjs +339 -0
  218. package/dist/type/compat.d.ts +8 -0
  219. package/dist/type/compat.js +46 -0
  220. package/dist/type/compat.mjs +44 -0
  221. package/dist/type/constants.d.ts +25 -0
  222. package/dist/type/constants.js +36 -0
  223. package/dist/type/constants.mjs +32 -0
  224. package/dist/type/elysia/accelerate.d.ts +6 -0
  225. package/dist/type/elysia/accelerate.js +12 -0
  226. package/dist/type/elysia/accelerate.mjs +10 -0
  227. package/dist/type/elysia/array-buffer.d.ts +6 -0
  228. package/dist/type/elysia/array-buffer.js +27 -0
  229. package/dist/type/elysia/array-buffer.mjs +25 -0
  230. package/dist/type/elysia/array-string.d.ts +7 -0
  231. package/dist/type/elysia/array-string.js +28 -0
  232. package/dist/type/elysia/array-string.mjs +26 -0
  233. package/dist/type/elysia/array.d.ts +6 -0
  234. package/dist/type/elysia/array.js +32 -0
  235. package/dist/type/elysia/array.mjs +31 -0
  236. package/dist/type/elysia/boolean-string.d.ts +6 -0
  237. package/dist/type/elysia/boolean-string.js +24 -0
  238. package/dist/type/elysia/boolean-string.mjs +22 -0
  239. package/dist/type/elysia/boolean.d.ts +6 -0
  240. package/dist/type/elysia/boolean.js +20 -0
  241. package/dist/type/elysia/boolean.mjs +18 -0
  242. package/dist/type/elysia/cookie.d.ts +15 -0
  243. package/dist/type/elysia/cookie.js +51 -0
  244. package/dist/type/elysia/cookie.mjs +50 -0
  245. package/dist/type/elysia/date.d.ts +7 -0
  246. package/dist/type/elysia/date.js +98 -0
  247. package/dist/type/elysia/date.mjs +96 -0
  248. package/dist/type/elysia/file-type.d.ts +25 -0
  249. package/dist/type/elysia/file-type.js +81 -0
  250. package/dist/type/elysia/file-type.mjs +71 -0
  251. package/dist/type/elysia/file.d.ts +9 -0
  252. package/dist/type/elysia/file.js +64 -0
  253. package/dist/type/elysia/file.mjs +48 -0
  254. package/dist/type/elysia/files.d.ts +8 -0
  255. package/dist/type/elysia/files.js +45 -0
  256. package/dist/type/elysia/files.mjs +43 -0
  257. package/dist/type/elysia/form.d.ts +8 -0
  258. package/dist/type/elysia/form.js +17 -0
  259. package/dist/type/elysia/form.mjs +15 -0
  260. package/dist/type/elysia/integer-string.d.ts +7 -0
  261. package/dist/type/elysia/integer-string.js +40 -0
  262. package/dist/type/elysia/integer-string.mjs +38 -0
  263. package/dist/type/elysia/integer.d.ts +6 -0
  264. package/dist/type/elysia/integer.js +20 -0
  265. package/dist/type/elysia/integer.mjs +18 -0
  266. package/dist/type/elysia/intersect.d.ts +6 -0
  267. package/dist/type/elysia/intersect.js +20 -0
  268. package/dist/type/elysia/intersect.mjs +19 -0
  269. package/dist/type/elysia/maybe-empty.d.ts +7 -0
  270. package/dist/type/elysia/maybe-empty.js +21 -0
  271. package/dist/type/elysia/maybe-empty.mjs +19 -0
  272. package/dist/type/elysia/no-validate.d.ts +6 -0
  273. package/dist/type/elysia/no-validate.js +9 -0
  274. package/dist/type/elysia/no-validate.mjs +8 -0
  275. package/dist/type/elysia/nullable.d.ts +7 -0
  276. package/dist/type/elysia/nullable.js +15 -0
  277. package/dist/type/elysia/nullable.mjs +13 -0
  278. package/dist/type/elysia/number.d.ts +6 -0
  279. package/dist/type/elysia/number.js +20 -0
  280. package/dist/type/elysia/number.mjs +18 -0
  281. package/dist/type/elysia/numeric-enum.d.ts +11 -0
  282. package/dist/type/elysia/numeric-enum.js +26 -0
  283. package/dist/type/elysia/numeric-enum.mjs +24 -0
  284. package/dist/type/elysia/numeric.d.ts +7 -0
  285. package/dist/type/elysia/numeric.js +62 -0
  286. package/dist/type/elysia/numeric.mjs +60 -0
  287. package/dist/type/elysia/object-string.d.ts +7 -0
  288. package/dist/type/elysia/object-string.js +28 -0
  289. package/dist/type/elysia/object-string.mjs +26 -0
  290. package/dist/type/elysia/object.d.ts +6 -0
  291. package/dist/type/elysia/object.js +47 -0
  292. package/dist/type/elysia/object.mjs +46 -0
  293. package/dist/type/elysia/optional.d.ts +6 -0
  294. package/dist/type/elysia/optional.js +22 -0
  295. package/dist/type/elysia/optional.mjs +21 -0
  296. package/dist/type/elysia/string.d.ts +6 -0
  297. package/dist/type/elysia/string.js +43 -0
  298. package/dist/type/elysia/string.mjs +41 -0
  299. package/dist/type/elysia/uint8-array.d.ts +6 -0
  300. package/dist/type/elysia/uint8-array.js +27 -0
  301. package/dist/type/elysia/uint8-array.mjs +25 -0
  302. package/dist/type/elysia/union-enum.d.ts +8 -0
  303. package/dist/type/elysia/union-enum.js +31 -0
  304. package/dist/type/elysia/union-enum.mjs +29 -0
  305. package/dist/type/elysia/union.d.ts +6 -0
  306. package/dist/type/elysia/union.js +20 -0
  307. package/dist/type/elysia/union.mjs +19 -0
  308. package/dist/type/elysia/utils.d.ts +53 -0
  309. package/dist/type/elysia/utils.js +98 -0
  310. package/dist/type/elysia/utils.mjs +88 -0
  311. package/dist/type/exports.d.ts +36 -0
  312. package/dist/type/exports.js +68 -0
  313. package/dist/type/exports.mjs +36 -0
  314. package/dist/type/index.d.ts +13 -0
  315. package/dist/type/index.js +81 -0
  316. package/dist/type/index.mjs +68 -0
  317. package/dist/type/shared.d.ts +27 -0
  318. package/dist/type/shared.js +171 -0
  319. package/dist/type/shared.mjs +161 -0
  320. package/dist/type/types.d.ts +206 -0
  321. package/dist/type/types.js +1 -0
  322. package/dist/type/types.mjs +1 -0
  323. package/dist/type/utils.d.ts +7 -0
  324. package/dist/type/utils.js +43 -0
  325. package/dist/type/utils.mjs +41 -0
  326. package/dist/type/validator/clean-safe.d.ts +8 -0
  327. package/dist/type/validator/clean-safe.js +82 -0
  328. package/dist/type/validator/clean-safe.mjs +77 -0
  329. package/dist/type/validator/custom-error.d.ts +10 -0
  330. package/dist/type/validator/custom-error.js +191 -0
  331. package/dist/type/validator/custom-error.mjs +188 -0
  332. package/dist/type/validator/default-precompute.d.ts +26 -0
  333. package/dist/type/validator/default-precompute.js +432 -0
  334. package/dist/type/validator/default-precompute.mjs +421 -0
  335. package/dist/type/validator/exact-mirror.d.ts +7 -0
  336. package/dist/type/validator/exact-mirror.js +19 -0
  337. package/dist/type/validator/exact-mirror.mjs +15 -0
  338. package/dist/type/validator/frozen-check.d.ts +11 -0
  339. package/dist/type/validator/frozen-check.js +20 -0
  340. package/dist/type/validator/frozen-check.mjs +19 -0
  341. package/dist/type/validator/index.d.ts +32 -0
  342. package/dist/type/validator/index.js +657 -0
  343. package/dist/type/validator/index.mjs +651 -0
  344. package/dist/type/validator/string-codec-aot.d.ts +8 -0
  345. package/dist/type/validator/string-codec-aot.js +68 -0
  346. package/dist/type/validator/string-codec-aot.mjs +66 -0
  347. package/dist/type/validator/validator-cache.d.ts +26 -0
  348. package/dist/type/validator/validator-cache.js +247 -0
  349. package/dist/type/validator/validator-cache.mjs +242 -0
  350. package/dist/types.d.ts +938 -1235
  351. package/dist/types.js +1 -14
  352. package/dist/types.mjs +1 -0
  353. package/dist/universal/constants.d.ts +6 -0
  354. package/dist/universal/constants.js +19 -0
  355. package/dist/universal/constants.mjs +15 -0
  356. package/dist/universal/env.d.ts +5 -1
  357. package/dist/universal/env.js +12 -26
  358. package/dist/universal/env.mjs +10 -5
  359. package/dist/universal/file.d.ts +55 -86
  360. package/dist/universal/file.js +116 -157
  361. package/dist/universal/file.mjs +111 -132
  362. package/dist/universal/index.d.ts +5 -3
  363. package/dist/universal/index.js +8 -27
  364. package/dist/universal/index.mjs +4 -5
  365. package/dist/universal/is-production.d.ts +5 -0
  366. package/dist/universal/is-production.js +10 -0
  367. package/dist/universal/is-production.mjs +8 -0
  368. package/dist/universal/server.d.ts +318 -313
  369. package/dist/universal/server.js +1 -14
  370. package/dist/universal/server.mjs +1 -0
  371. package/dist/utils.d.ts +162 -191
  372. package/dist/utils.js +732 -693
  373. package/dist/utils.mjs +683 -631
  374. package/dist/validator/index.d.ts +63 -0
  375. package/dist/validator/index.js +299 -0
  376. package/dist/validator/index.mjs +296 -0
  377. package/dist/validator/route.d.ts +32 -0
  378. package/dist/validator/route.js +51 -0
  379. package/dist/validator/route.mjs +50 -0
  380. package/dist/ws/context.d.ts +49 -0
  381. package/dist/ws/context.js +152 -0
  382. package/dist/ws/context.mjs +150 -0
  383. package/dist/ws/index.d.ts +5 -77
  384. package/dist/ws/index.js +11 -180
  385. package/dist/ws/index.mjs +5 -157
  386. package/dist/ws/parser.d.ts +5 -0
  387. package/dist/ws/parser.js +69 -0
  388. package/dist/ws/parser.mjs +66 -0
  389. package/dist/ws/route.d.ts +16 -0
  390. package/dist/ws/route.js +560 -0
  391. package/dist/ws/route.mjs +554 -0
  392. package/dist/ws/types.d.ts +154 -57
  393. package/dist/ws/types.js +1 -14
  394. package/dist/ws/types.mjs +1 -0
  395. package/package.json +179 -120
  396. package/bunfig.toml +0 -2
  397. package/dist/adapter/bun/compose.d.ts +0 -3
  398. package/dist/adapter/bun/compose.js +0 -90
  399. package/dist/adapter/bun/compose.mjs +0 -74
  400. package/dist/adapter/bun/handler-native.d.ts +0 -3
  401. package/dist/adapter/bun/handler-native.js +0 -42
  402. package/dist/adapter/bun/handler-native.mjs +0 -22
  403. package/dist/adapter/bun/handler.d.ts +0 -7
  404. package/dist/adapter/bun/handler.js +0 -363
  405. package/dist/adapter/bun/handler.mjs +0 -346
  406. package/dist/adapter/cloudflare-worker/index.d.ts +0 -20
  407. package/dist/adapter/cloudflare-worker/index.js +0 -59
  408. package/dist/adapter/cloudflare-worker/index.mjs +0 -39
  409. package/dist/compose.d.ts +0 -30
  410. package/dist/compose.js +0 -1324
  411. package/dist/compose.mjs +0 -1336
  412. package/dist/cookies.d.ts +0 -158
  413. package/dist/cookies.js +0 -250
  414. package/dist/cookies.mjs +0 -221
  415. package/dist/dynamic-handle.d.ts +0 -15
  416. package/dist/dynamic-handle.js +0 -521
  417. package/dist/dynamic-handle.mjs +0 -509
  418. package/dist/formats.d.ts +0 -79
  419. package/dist/formats.js +0 -153
  420. package/dist/formats.mjs +0 -132
  421. package/dist/manifest.d.ts +0 -0
  422. package/dist/manifest.js +0 -1
  423. package/dist/manifest.mjs +0 -0
  424. package/dist/replace-schema.d.ts +0 -60
  425. package/dist/replace-schema.js +0 -140
  426. package/dist/replace-schema.mjs +0 -115
  427. package/dist/schema.d.ts +0 -107
  428. package/dist/schema.js +0 -833
  429. package/dist/schema.mjs +0 -814
  430. package/dist/type-system/format.d.ts +0 -55
  431. package/dist/type-system/format.js +0 -197
  432. package/dist/type-system/format.mjs +0 -175
  433. package/dist/type-system/index.d.ts +0 -45
  434. package/dist/type-system/index.js +0 -406
  435. package/dist/type-system/index.mjs +0 -394
  436. package/dist/type-system/types.d.ts +0 -155
  437. package/dist/type-system/types.js +0 -14
  438. package/dist/type-system/types.mjs +0 -0
  439. package/dist/type-system/utils.d.ts +0 -62
  440. package/dist/type-system/utils.js +0 -141
  441. package/dist/type-system/utils.mjs +0 -111
  442. package/dist/universal/request.d.ts +0 -29
  443. package/dist/universal/request.js +0 -126
  444. package/dist/universal/request.mjs +0 -105
  445. package/dist/universal/types.d.ts +0 -124
  446. package/dist/universal/types.js +0 -41
  447. package/dist/universal/types.mjs +0 -19
  448. package/dist/universal/utils.d.ts +0 -3
  449. package/dist/universal/utils.js +0 -41
  450. package/dist/universal/utils.mjs +0 -18
  451. package/dist/ws/bun.d.ts +0 -419
  452. package/dist/ws/bun.js +0 -14
  453. package/dist/ws/bun.mjs +0 -0
  454. package/knip.json +0 -22
package/dist/utils.js CHANGED
@@ -1,697 +1,736 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_universal_constants = require('./universal/constants.js');
3
+ const require_constants = require('./constants.js');
4
+ const require_universal_file = require('./universal/file.js');
5
+
6
+ //#region src/utils.ts
7
+ const nullObject = () => Object.create(null);
8
+ const mapDeriveEntry = (fn) => [fn, "mapDerive"];
9
+ const deriveEntryFn = (entry) => Array.isArray(entry) ? entry[0] : entry;
10
+ const isMapDeriveEntry = (entry) => Array.isArray(entry) && entry[1] === "mapDerive";
11
+ function isEmpty(obj) {
12
+ for (const _ in obj) return false;
13
+ return true;
14
+ }
15
+ const isNotEmpty = (obj) => obj && !isEmpty(obj);
16
+ const FNV_OFFSET_BASIS = 2166136261;
17
+ const FNV_PRIME = 16777619;
18
+ /**
19
+ * @internal Generational cache eviction at cap, drop the oldest half.
20
+ *
21
+ * `map.delete(oldest)` per insert leaks ~1KB/eviction on JSC in ~1/3 of
22
+ * processes (churned bucket cells permanently grow the heap and are never
23
+ * reclaimed); clear + reinsert of the newest half measures clean and
24
+ * amortizes to O(1) per insertion.
25
+ */
26
+ function evictOldestHalf(cache) {
27
+ const keep = [...cache].slice(cache.size >> 1);
28
+ cache.clear();
29
+ for (const entry of keep) cache.set(entry[0], entry[1]);
30
+ }
31
+ function fnv1a(str) {
32
+ let hash = FNV_OFFSET_BASIS;
33
+ const len = str.length;
34
+ for (let i = 0; i < len; i++) {
35
+ hash ^= str.charCodeAt(i);
36
+ hash = Math.imul(hash, FNV_PRIME);
37
+ }
38
+ return hash >>> 0;
39
+ }
40
+ /**
41
+ * Maps each lifecycle/derive function to the hash of the named plugin it was
42
+ * first registered on. Used by `.use()` to dedup absorbed hooks: if a fn's
43
+ * origin is already in `parent.#apps`, the parent has already absorbed that
44
+ * named plugin via another path and should skip re-adding the fn.
45
+ *
46
+ * Anonymous plugins (no name) don't tag their fns - there's no hash to dedup
47
+ * by, so their fns always propagate.
48
+ */
49
+ const fnOrigin = /* @__PURE__ */ new WeakMap();
50
+ const macroOrigin = /* @__PURE__ */ new WeakMap();
51
+ const isLocalScope = (s) => s === "local" || s === void 0;
52
+ const COMPACT_CHUNK_SIZE = 32;
53
+ const emptyCompactBeforeHandlePrefix = {
54
+ length: 0,
55
+ added: []
14
56
  };
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
- var utils_exports = {};
17
- __export(utils_exports, {
18
- ELYSIA_FORM_DATA: () => ELYSIA_FORM_DATA,
19
- ELYSIA_REQUEST_ID: () => ELYSIA_REQUEST_ID,
20
- InvertedStatusMap: () => InvertedStatusMap,
21
- PromiseGroup: () => PromiseGroup,
22
- StatusMap: () => StatusMap,
23
- asHookType: () => asHookType,
24
- checksum: () => checksum,
25
- cloneInference: () => cloneInference,
26
- deduplicateChecksum: () => deduplicateChecksum,
27
- deepClone: () => deepClone,
28
- emptySchema: () => emptySchema,
29
- encodePath: () => encodePath,
30
- filterGlobalHook: () => filterGlobalHook,
31
- fnToContainer: () => fnToContainer,
32
- form: () => form,
33
- getLoosePath: () => getLoosePath,
34
- getResponseLength: () => getResponseLength,
35
- hasHeaderShorthand: () => hasHeaderShorthand,
36
- hasSetImmediate: () => hasSetImmediate,
37
- injectChecksum: () => injectChecksum,
38
- insertStandaloneValidator: () => insertStandaloneValidator,
39
- isClass: () => isClass,
40
- isNotEmpty: () => isNotEmpty,
41
- isNumericString: () => isNumericString,
42
- lifeCycleToArray: () => lifeCycleToArray,
43
- lifeCycleToFn: () => lifeCycleToFn,
44
- localHookToLifeCycleStore: () => localHookToLifeCycleStore,
45
- mergeCookie: () => mergeCookie,
46
- mergeDeep: () => mergeDeep,
47
- mergeHook: () => mergeHook,
48
- mergeLifeCycle: () => mergeLifeCycle,
49
- mergeObjectArray: () => mergeObjectArray,
50
- mergeResponse: () => mergeResponse,
51
- mergeSchemaValidator: () => mergeSchemaValidator,
52
- primitiveHooks: () => primitiveHooks,
53
- promoteEvent: () => promoteEvent,
54
- randomId: () => randomId,
55
- redirect: () => redirect,
56
- replaceUrlPath: () => replaceUrlPath,
57
- signCookie: () => signCookie,
58
- sse: () => sse,
59
- supportPerMethodInlineHandler: () => supportPerMethodInlineHandler,
60
- unsignCookie: () => unsignCookie
61
- });
62
- module.exports = __toCommonJS(utils_exports);
63
- var import_file = require('./universal/file.js'), import_utils = require('./universal/utils.js');
64
- const replaceUrlPath = (url, pathname) => {
65
- const pathStartIndex = url.indexOf("/", 11), queryIndex = url.indexOf("?", pathStartIndex);
66
- return queryIndex === -1 ? `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}` : `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}${url.slice(queryIndex)}`;
67
- }, isClass = (v) => typeof v == "function" && /^\s*class\s+/.test(v.toString()) || // Handle Object.create(null)
68
- v.toString && // Handle import * as Sentry from '@sentry/bun'
69
- // This also handle [object Date], [object Array]
70
- // and FFI value like [object Prisma]
71
- v.toString().startsWith("[object ") && v.toString() !== "[object Object]" || // If object prototype is not pure, then probably a class-like object
72
- isNotEmpty(Object.getPrototypeOf(v)), isObject = (item) => item && typeof item == "object" && !Array.isArray(item), mergeDeep = (target, source, options) => {
73
- const skipKeys = options?.skipKeys, override = options?.override ?? !0, mergeArray = options?.mergeArray ?? !1, seen = options?.seen ?? /* @__PURE__ */ new WeakSet();
74
- if (!isObject(target) || !isObject(source) || seen.has(source)) return target;
75
- seen.add(source);
76
- for (const [key, value] of Object.entries(source))
77
- if (!(skipKeys?.includes(key) || ["__proto__", "constructor", "prototype"].includes(key))) {
78
- if (mergeArray && Array.isArray(value)) {
79
- target[key] = Array.isArray(
80
- target[key]
81
- ) ? [...target[key], ...value] : target[key] = value;
82
- continue;
83
- }
84
- if (!isObject(value) || !(key in target) || isClass(value)) {
85
- if ((override || !(key in target)) && !Object.isFrozen(target))
86
- try {
87
- target[key] = value;
88
- } catch {
89
- }
90
- continue;
91
- }
92
- if (!Object.isFrozen(target[key]))
93
- try {
94
- target[key] = mergeDeep(
95
- target[key],
96
- value,
97
- { skipKeys, override, mergeArray, seen }
98
- );
99
- } catch {
100
- }
101
- }
102
- return seen.delete(source), target;
103
- }, mergeCookie = (a, b) => {
104
- const v = mergeDeep(Object.assign({}, a), b, {
105
- skipKeys: ["properties"],
106
- mergeArray: !1
107
- });
108
- return v.properties && delete v.properties, v;
109
- }, mergeObjectArray = (a, b) => {
110
- if (!b) return a;
111
- const array = [], checksums = [];
112
- if (a) {
113
- Array.isArray(a) || (a = [a]);
114
- for (const item of a)
115
- array.push(item), item.checksum && checksums.push(item.checksum);
116
- }
117
- if (b) {
118
- Array.isArray(b) || (b = [b]);
119
- for (const item of b)
120
- checksums.includes(item.checksum) || array.push(item);
121
- }
122
- return array;
123
- }, primitiveHooks = [
124
- "start",
125
- "request",
126
- "parse",
127
- "transform",
128
- "resolve",
129
- "beforeHandle",
130
- "afterHandle",
131
- "mapResponse",
132
- "afterResponse",
133
- "trace",
134
- "error",
135
- "stop",
136
- "body",
137
- "headers",
138
- "params",
139
- "query",
140
- "response",
141
- "type",
142
- "detail"
143
- ], primitiveHookMap = primitiveHooks.reduce(
144
- (acc, x) => (acc[x] = !0, acc),
145
- {}
146
- ), isRecordNumber = (x) => typeof x == "object" && Object.keys(x).every((x2) => !isNaN(+x2)), mergeResponse = (a, b) => isRecordNumber(a) && isRecordNumber(b) ? Object.assign({}, a, b) : a && !isRecordNumber(a) && isRecordNumber(b) ? Object.assign({ 200: a }, b) : b ?? a, mergeSchemaValidator = (a, b) => !a && !b ? {
147
- body: void 0,
148
- headers: void 0,
149
- params: void 0,
150
- query: void 0,
151
- cookie: void 0,
152
- response: void 0
153
- } : {
154
- body: b?.body ?? a?.body,
155
- headers: b?.headers ?? a?.headers,
156
- params: b?.params ?? a?.params,
157
- query: b?.query ?? a?.query,
158
- cookie: b?.cookie ?? a?.cookie,
159
- // @ts-ignore ? This order is correct - SaltyAom
160
- response: mergeResponse(
161
- // @ts-ignore
162
- a?.response,
163
- // @ts-ignore
164
- b?.response
165
- )
166
- }, mergeHook = (a, b) => {
167
- if (!b) return a ?? {};
168
- if (!a) return b ?? {};
169
- if (!Object.values(b).find((x) => x != null))
170
- return { ...a };
171
- const hook = {
172
- ...a,
173
- ...b,
174
- // Merge local hook first
175
- // @ts-ignore
176
- body: b.body ?? a.body,
177
- // @ts-ignore
178
- headers: b.headers ?? a.headers,
179
- // @ts-ignore
180
- params: b.params ?? a.params,
181
- // @ts-ignore
182
- query: b.query ?? a.query,
183
- // @ts-ignore
184
- cookie: b.cookie ?? a.cookie,
185
- // ? This order is correct - SaltyAom
186
- response: mergeResponse(
187
- // @ts-ignore
188
- a.response,
189
- // @ts-ignore
190
- b.response
191
- ),
192
- type: a.type || b.type,
193
- detail: mergeDeep(
194
- // @ts-ignore
195
- b.detail ?? {},
196
- // @ts-ignore
197
- a.detail ?? {}
198
- ),
199
- parse: mergeObjectArray(a.parse, b.parse),
200
- transform: mergeObjectArray(a.transform, b.transform),
201
- beforeHandle: mergeObjectArray(
202
- mergeObjectArray(
203
- // @ts-ignore
204
- fnToContainer(a.resolve, "resolve"),
205
- a.beforeHandle
206
- ),
207
- mergeObjectArray(
208
- fnToContainer(b.resolve, "resolve"),
209
- b.beforeHandle
210
- )
211
- ),
212
- afterHandle: mergeObjectArray(a.afterHandle, b.afterHandle),
213
- mapResponse: mergeObjectArray(a.mapResponse, b.mapResponse),
214
- afterResponse: mergeObjectArray(
215
- a.afterResponse,
216
- b.afterResponse
217
- ),
218
- trace: mergeObjectArray(a.trace, b.trace),
219
- error: mergeObjectArray(a.error, b.error),
220
- // @ts-ignore
221
- standaloneSchema: (
222
- // @ts-ignore
223
- a.standaloneSchema || b.standaloneSchema ? (
224
- // @ts-ignore
225
- a.standaloneSchema && !b.standaloneSchema ? (
226
- // @ts-ignore
227
- a.standaloneSchema
228
- ) : (
229
- // @ts-ignore
230
- b.standaloneSchema && !a.standaloneSchema ? b.standaloneSchema : [
231
- // @ts-ignore
232
- ...a.standaloneSchema ?? [],
233
- ...b.standaloneSchema ?? []
234
- ]
235
- )
236
- ) : void 0
237
- )
238
- };
239
- return hook.resolve && delete hook.resolve, hook;
240
- }, lifeCycleToArray = (a) => {
241
- a.parse && !Array.isArray(a.parse) && (a.parse = [a.parse]), a.transform && !Array.isArray(a.transform) && (a.transform = [a.transform]), a.afterHandle && !Array.isArray(a.afterHandle) && (a.afterHandle = [a.afterHandle]), a.mapResponse && !Array.isArray(a.mapResponse) && (a.mapResponse = [a.mapResponse]), a.afterResponse && !Array.isArray(a.afterResponse) && (a.afterResponse = [a.afterResponse]), a.trace && !Array.isArray(a.trace) && (a.trace = [a.trace]), a.error && !Array.isArray(a.error) && (a.error = [a.error]);
242
- let beforeHandle = [];
243
- return a.resolve && (beforeHandle = fnToContainer(
244
- // @ts-expect-error
245
- Array.isArray(a.resolve) ? a.resolve : [a.resolve],
246
- "resolve"
247
- ), delete a.resolve), a.beforeHandle && (beforeHandle.length ? beforeHandle = beforeHandle.concat(
248
- Array.isArray(a.beforeHandle) ? a.beforeHandle : [a.beforeHandle]
249
- ) : beforeHandle = Array.isArray(a.beforeHandle) ? a.beforeHandle : [a.beforeHandle]), beforeHandle.length && (a.beforeHandle = beforeHandle), a;
250
- }, hasHeaderShorthand = import_utils.isBun ? "toJSON" in new Headers() : !1, hasSetImmediate = typeof setImmediate == "function", checksum = (s) => {
251
- let h = 9;
252
- for (let i = 0; i < s.length; ) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
253
- return h = h ^ h >>> 9;
254
- }, injectChecksum = (checksum2, x) => {
255
- if (!x) return;
256
- if (!Array.isArray(x)) {
257
- const fn = x;
258
- return checksum2 && !fn.checksum && (fn.checksum = checksum2), fn.scope === "scoped" && (fn.scope = "local"), fn;
259
- }
260
- const fns = [...x];
261
- for (const fn of fns)
262
- checksum2 && !fn.checksum && (fn.checksum = checksum2), fn.scope === "scoped" && (fn.scope = "local");
263
- return fns;
264
- }, mergeLifeCycle = (a, b, checksum2) => ({
265
- start: mergeObjectArray(
266
- a.start,
267
- injectChecksum(checksum2, b?.start)
268
- ),
269
- request: mergeObjectArray(
270
- a.request,
271
- injectChecksum(checksum2, b?.request)
272
- ),
273
- parse: mergeObjectArray(
274
- a.parse,
275
- injectChecksum(checksum2, b?.parse)
276
- ),
277
- transform: mergeObjectArray(
278
- a.transform,
279
- injectChecksum(checksum2, b?.transform)
280
- ),
281
- beforeHandle: mergeObjectArray(
282
- mergeObjectArray(
283
- // @ts-ignore
284
- fnToContainer(a.resolve, "resolve"),
285
- a.beforeHandle
286
- ),
287
- injectChecksum(
288
- checksum2,
289
- mergeObjectArray(
290
- fnToContainer(b?.resolve, "resolve"),
291
- b?.beforeHandle
292
- )
293
- )
294
- ),
295
- afterHandle: mergeObjectArray(
296
- a.afterHandle,
297
- injectChecksum(checksum2, b?.afterHandle)
298
- ),
299
- mapResponse: mergeObjectArray(
300
- a.mapResponse,
301
- injectChecksum(checksum2, b?.mapResponse)
302
- ),
303
- afterResponse: mergeObjectArray(
304
- a.afterResponse,
305
- injectChecksum(checksum2, b?.afterResponse)
306
- ),
307
- // Already merged on Elysia._use, also logic is more complicated, can't directly merge
308
- trace: mergeObjectArray(
309
- a.trace,
310
- injectChecksum(checksum2, b?.trace)
311
- ),
312
- error: mergeObjectArray(
313
- a.error,
314
- injectChecksum(checksum2, b?.error)
315
- ),
316
- stop: mergeObjectArray(
317
- a.stop,
318
- injectChecksum(checksum2, b?.stop)
319
- )
320
- }), asHookType = (fn, inject, { skipIfHasType = !1 }) => {
321
- if (!fn) return fn;
322
- if (!Array.isArray(fn))
323
- return skipIfHasType ? fn.scope ??= inject : fn.scope = inject, fn;
324
- for (const x of fn)
325
- skipIfHasType ? x.scope ??= inject : x.scope = inject;
326
- return fn;
327
- }, filterGlobal = (fn) => {
328
- if (!fn) return fn;
329
- if (!Array.isArray(fn))
330
- switch (fn.scope) {
331
- case "global":
332
- case "scoped":
333
- return { ...fn };
334
- default:
335
- return { fn };
336
- }
337
- const array = [];
338
- for (const x of fn)
339
- switch (x.scope) {
340
- case "global":
341
- case "scoped":
342
- array.push({
343
- ...x
344
- });
345
- break;
346
- }
347
- return array;
348
- }, filterGlobalHook = (hook) => ({
349
- // rest is validator
350
- ...hook,
351
- type: hook?.type,
352
- detail: hook?.detail,
353
- parse: filterGlobal(hook?.parse),
354
- transform: filterGlobal(hook?.transform),
355
- beforeHandle: filterGlobal(hook?.beforeHandle),
356
- afterHandle: filterGlobal(hook?.afterHandle),
357
- mapResponse: filterGlobal(hook?.mapResponse),
358
- afterResponse: filterGlobal(hook?.afterResponse),
359
- error: filterGlobal(hook?.error),
360
- trace: filterGlobal(hook?.trace)
361
- }), StatusMap = {
362
- Continue: 100,
363
- "Switching Protocols": 101,
364
- Processing: 102,
365
- "Early Hints": 103,
366
- OK: 200,
367
- Created: 201,
368
- Accepted: 202,
369
- "Non-Authoritative Information": 203,
370
- "No Content": 204,
371
- "Reset Content": 205,
372
- "Partial Content": 206,
373
- "Multi-Status": 207,
374
- "Already Reported": 208,
375
- "Multiple Choices": 300,
376
- "Moved Permanently": 301,
377
- Found: 302,
378
- "See Other": 303,
379
- "Not Modified": 304,
380
- "Temporary Redirect": 307,
381
- "Permanent Redirect": 308,
382
- "Bad Request": 400,
383
- Unauthorized: 401,
384
- "Payment Required": 402,
385
- Forbidden: 403,
386
- "Not Found": 404,
387
- "Method Not Allowed": 405,
388
- "Not Acceptable": 406,
389
- "Proxy Authentication Required": 407,
390
- "Request Timeout": 408,
391
- Conflict: 409,
392
- Gone: 410,
393
- "Length Required": 411,
394
- "Precondition Failed": 412,
395
- "Payload Too Large": 413,
396
- "URI Too Long": 414,
397
- "Unsupported Media Type": 415,
398
- "Range Not Satisfiable": 416,
399
- "Expectation Failed": 417,
400
- "I'm a teapot": 418,
401
- "Enhance Your Calm": 420,
402
- "Misdirected Request": 421,
403
- "Unprocessable Content": 422,
404
- Locked: 423,
405
- "Failed Dependency": 424,
406
- "Too Early": 425,
407
- "Upgrade Required": 426,
408
- "Precondition Required": 428,
409
- "Too Many Requests": 429,
410
- "Request Header Fields Too Large": 431,
411
- "Unavailable For Legal Reasons": 451,
412
- "Internal Server Error": 500,
413
- "Not Implemented": 501,
414
- "Bad Gateway": 502,
415
- "Service Unavailable": 503,
416
- "Gateway Timeout": 504,
417
- "HTTP Version Not Supported": 505,
418
- "Variant Also Negotiates": 506,
419
- "Insufficient Storage": 507,
420
- "Loop Detected": 508,
421
- "Not Extended": 510,
422
- "Network Authentication Required": 511
423
- }, InvertedStatusMap = Object.fromEntries(
424
- Object.entries(StatusMap).map(([k, v]) => [v, k])
425
- );
426
- function removeTrailingEquals(digest) {
427
- let trimmedDigest = digest;
428
- for (; trimmedDigest.endsWith("="); )
429
- trimmedDigest = trimmedDigest.slice(0, -1);
430
- return trimmedDigest;
431
- }
432
- const encoder = new TextEncoder(), signCookie = async (val, secret) => {
433
- if (typeof val == "object" ? val = JSON.stringify(val) : typeof val != "string" && (val = val + ""), secret == null)
434
- throw new TypeError("Secret key must be provided");
435
- const secretKey = await crypto.subtle.importKey(
436
- "raw",
437
- encoder.encode(secret),
438
- { name: "HMAC", hash: "SHA-256" },
439
- !1,
440
- ["sign"]
441
- ), hmacBuffer = await crypto.subtle.sign(
442
- "HMAC",
443
- secretKey,
444
- encoder.encode(val)
445
- );
446
- return val + "." + removeTrailingEquals(Buffer.from(hmacBuffer).toString("base64"));
447
- }, constantTimeEqual = typeof crypto?.timingSafeEqual == "function" ? (a, b) => {
448
- const ab = Buffer.from(a, "utf8"), bb = Buffer.from(b, "utf8");
449
- return ab.length !== bb.length ? !1 : crypto.timingSafeEqual(ab, bb);
450
- } : (a, b) => a === b, unsignCookie = async (input, secret) => {
451
- if (typeof input != "string")
452
- throw new TypeError("Signed cookie string must be provided.");
453
- const dot = input.lastIndexOf(".");
454
- if (dot === -1)
455
- return secret === null ? input : !1;
456
- const tentativeValue = input.slice(0, dot), expectedInput = await signCookie(tentativeValue, secret);
457
- return constantTimeEqual(expectedInput, input) ? tentativeValue : !1;
458
- }, insertStandaloneValidator = (hook, name, value) => {
459
- if (!hook.standaloneValidator?.length || !Array.isArray(hook.standaloneValidator)) {
460
- hook.standaloneValidator = [
461
- {
462
- [name]: value
463
- }
464
- ];
465
- return;
466
- }
467
- const last = hook.standaloneValidator[hook.standaloneValidator.length - 1];
468
- name in last ? hook.standaloneValidator.push({
469
- [name]: value
470
- }) : last[name] = value;
471
- }, parseNumericString = (message) => {
472
- if (typeof message == "number") return message;
473
- if (message.length < 16) {
474
- if (message.trim().length === 0) return null;
475
- const length = Number(message);
476
- return Number.isNaN(length) ? null : length;
477
- }
478
- if (message.length === 16) {
479
- if (message.trim().length === 0) return null;
480
- const number = Number(message);
481
- return Number.isNaN(number) || number.toString() !== message ? null : number;
482
- }
483
- return null;
484
- }, isNumericString = (message) => parseNumericString(message) !== null;
485
- class PromiseGroup {
486
- constructor(onError = console.error, onFinally = () => {
487
- }) {
488
- this.onError = onError;
489
- this.onFinally = onFinally;
490
- this.root = null;
491
- this.promises = [];
492
- }
493
- /**
494
- * The number of promises still being awaited.
495
- */
496
- get size() {
497
- return this.promises.length;
498
- }
499
- /**
500
- * Add a promise to the group.
501
- * @returns The promise that was added.
502
- */
503
- add(promise) {
504
- return this.promises.push(promise), this.root ||= this.drain(), this.promises.length === 1 && this.then(this.onFinally), promise;
505
- }
506
- async drain() {
507
- for (; this.promises.length > 0; ) {
508
- try {
509
- await this.promises[0];
510
- } catch (error) {
511
- this.onError(error);
512
- }
513
- this.promises.shift();
514
- }
515
- this.root = null;
516
- }
517
- // Allow the group to be awaited.
518
- then(onfulfilled, onrejected) {
519
- return (this.root ?? Promise.resolve()).then(onfulfilled, onrejected);
520
- }
521
- }
522
- const fnToContainer = (fn, subType) => {
523
- if (!fn) return fn;
524
- if (!Array.isArray(fn)) {
525
- if (typeof fn == "function" || typeof fn == "string")
526
- return subType ? { fn, subType } : { fn };
527
- if ("fn" in fn) return fn;
528
- }
529
- const fns = [];
530
- for (const x of fn)
531
- typeof x == "function" || typeof x == "string" ? fns.push(subType ? { fn: x, subType } : { fn: x }) : "fn" in x && fns.push(x);
532
- return fns;
533
- }, localHookToLifeCycleStore = (a) => (a.start && (a.start = fnToContainer(a.start)), a.request && (a.request = fnToContainer(a.request)), a.parse && (a.parse = fnToContainer(a.parse)), a.transform && (a.transform = fnToContainer(a.transform)), a.beforeHandle && (a.beforeHandle = fnToContainer(a.beforeHandle)), a.afterHandle && (a.afterHandle = fnToContainer(a.afterHandle)), a.mapResponse && (a.mapResponse = fnToContainer(a.mapResponse)), a.afterResponse && (a.afterResponse = fnToContainer(a.afterResponse)), a.trace && (a.trace = fnToContainer(a.trace)), a.error && (a.error = fnToContainer(a.error)), a.stop && (a.stop = fnToContainer(a.stop)), a), lifeCycleToFn = (a) => {
534
- const lifecycle = /* @__PURE__ */ Object.create(null);
535
- return a.start?.map && (lifecycle.start = a.start.map((x) => x.fn)), a.request?.map && (lifecycle.request = a.request.map((x) => x.fn)), a.parse?.map && (lifecycle.parse = a.parse.map((x) => x.fn)), a.transform?.map && (lifecycle.transform = a.transform.map((x) => x.fn)), a.beforeHandle?.map && (lifecycle.beforeHandle = a.beforeHandle.map((x) => x.fn)), a.afterHandle?.map && (lifecycle.afterHandle = a.afterHandle.map((x) => x.fn)), a.mapResponse?.map && (lifecycle.mapResponse = a.mapResponse.map((x) => x.fn)), a.afterResponse?.map && (lifecycle.afterResponse = a.afterResponse.map((x) => x.fn)), a.error?.map && (lifecycle.error = a.error.map((x) => x.fn)), a.stop?.map && (lifecycle.stop = a.stop.map((x) => x.fn)), a.trace?.map ? lifecycle.trace = a.trace.map((x) => x.fn) : lifecycle.trace = [], lifecycle;
536
- }, cloneInference = (inference) => ({
537
- body: inference.body,
538
- cookie: inference.cookie,
539
- headers: inference.headers,
540
- query: inference.query,
541
- set: inference.set,
542
- server: inference.server,
543
- path: inference.path,
544
- route: inference.route,
545
- url: inference.url
546
- }), redirect = (url, status = 302) => Response.redirect(url, status), ELYSIA_FORM_DATA = Symbol("ElysiaFormData"), ELYSIA_REQUEST_ID = Symbol("ElysiaRequestId"), form = (items) => {
547
- const formData = new FormData();
548
- if (formData[ELYSIA_FORM_DATA] = {}, items)
549
- for (const [key, value] of Object.entries(items)) {
550
- if (Array.isArray(value)) {
551
- formData[ELYSIA_FORM_DATA][key] = [];
552
- for (const v of value)
553
- value instanceof File ? formData.append(key, value, value.name) : value instanceof import_file.ElysiaFile ? formData.append(key, value.value, value.value?.name) : formData.append(key, value), formData[ELYSIA_FORM_DATA][key].push(value);
554
- continue;
555
- }
556
- value instanceof File ? formData.append(key, value, value.name) : value instanceof import_file.ElysiaFile ? formData.append(key, value.value, value.value?.name) : formData.append(key, value), formData[ELYSIA_FORM_DATA][key] = value;
557
- }
558
- return formData;
559
- }, randomId = typeof crypto > "u" || (0, import_utils.isCloudflareWorker)() ? () => {
560
- let result = "";
561
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
562
- for (let i = 0; i < 16; i++)
563
- result += characters.charAt(
564
- // 62 is characters.length
565
- Math.floor(Math.random() * 62)
566
- );
567
- return result;
568
- } : () => {
569
- const uuid = crypto.randomUUID();
570
- return uuid.slice(0, 8) + uuid.slice(24, 32);
571
- }, deduplicateChecksum = (array) => {
572
- if (!array.length) return [];
573
- const hashes = [];
574
- for (let i = 0; i < array.length; i++) {
575
- const item = array[i];
576
- item.checksum && (hashes.includes(item.checksum) && (array.splice(i, 1), i--), hashes.push(item.checksum));
577
- }
578
- return array;
579
- }, promoteEvent = (events, as = "scoped") => {
580
- if (events) {
581
- if (as === "scoped") {
582
- for (const event of events)
583
- "scope" in event && event.scope === "local" && (event.scope = "scoped");
584
- return;
585
- }
586
- for (const event of events) "scope" in event && (event.scope = "global");
587
- }
588
- }, getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, path.length - 1) : path + "/", isNotEmpty = (obj) => {
589
- if (!obj) return !1;
590
- for (const _ in obj) return !0;
591
- return !1;
592
- }, encodePath = (path, { dynamic = !1 } = {}) => {
593
- let encoded = encodeURIComponent(path).replace(/%2F/g, "/");
594
- return dynamic && (encoded = encoded.replace(/%3A/g, ":").replace(/%3F/g, "?")), encoded;
595
- }, supportPerMethodInlineHandler = !!(typeof Bun > "u" || Bun.semver?.satisfies?.(Bun.version, ">=1.2.14")), sse = (_payload) => {
596
- if (_payload instanceof ReadableStream)
597
- return _payload.sse = !0, _payload;
598
- const payload = typeof _payload == "string" ? { data: _payload } : _payload;
599
- return payload.sse = !0, payload.toSSE = () => {
600
- let payloadString = "";
601
- return payload.id !== void 0 && payload.id !== null && (payloadString += `id: ${payload.id}
602
- `), payload.event && (payloadString += `event: ${payload.event}
603
- `), payload.retry !== void 0 && (payloadString += `retry: ${payload.retry}
604
- `), payload.data === null ? payloadString += `data: null
605
- ` : typeof payload.data == "string" ? payloadString += `data: ${payload.data}
606
- ` : typeof payload.data == "object" && (payloadString += `data: ${JSON.stringify(payload.data)}
607
- `), payloadString && (payloadString += `
608
- `), payloadString;
609
- }, payload;
57
+ const compactBeforeHandleMemos = /* @__PURE__ */ new WeakMap();
58
+ const compactBeforeHandleFunctions = /* @__PURE__ */ new WeakSet();
59
+ const compactBeforeHandleValues = (hook) => {
60
+ if (!hook) return [];
61
+ for (const key in hook) if (key !== "beforeHandle") return false;
62
+ const value = hook.beforeHandle;
63
+ if (value === void 0) return [];
64
+ if (typeof value === "function") return [value];
65
+ if (!Array.isArray(value)) return false;
66
+ for (let i = 0; i < value.length; i++) if (typeof value[i] !== "function") return false;
67
+ return value.slice();
610
68
  };
611
- async function getResponseLength(response) {
612
- if (response.bodyUsed || !response.body) return 0;
613
- let length = 0;
614
- const reader = response.body.getReader();
615
- for (; ; ) {
616
- const { done, value } = await reader.read();
617
- if (done) break;
618
- length += value.byteLength;
619
- }
620
- return length;
621
- }
622
- const emptySchema = {
623
- headers: !0,
624
- cookie: !0,
625
- query: !0,
626
- params: !0,
627
- body: !0,
628
- response: !0
69
+ const isCompactBeforeHandleOnly = (hook) => compactBeforeHandleValues(hook) !== false;
70
+ function compactBeforeHandleConflicts(hook) {
71
+ const values = compactBeforeHandleValues(hook);
72
+ if (values === false) return true;
73
+ for (let i = 0; i < values.length; i++) if (compactBeforeHandleFunctions.has(values[i])) return true;
74
+ return false;
75
+ }
76
+ function appendCompactBeforeHandle(previous, added) {
77
+ if (!added.length) return previous;
78
+ let tail = previous.tail;
79
+ let length = previous.length;
80
+ for (let i = 0; i < added.length; i++) {
81
+ const fn = added[i];
82
+ compactBeforeHandleFunctions.add(fn);
83
+ if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
84
+ parent: tail.parent,
85
+ values: [...tail.values, fn]
86
+ };
87
+ else tail = {
88
+ parent: tail,
89
+ values: [fn]
90
+ };
91
+ length++;
92
+ }
93
+ return {
94
+ tail,
95
+ length,
96
+ previous: previous.length ? previous : void 0,
97
+ added
98
+ };
99
+ }
100
+ function compactBeforeHandlePrefix(start) {
101
+ if (!start) return;
102
+ const pending = [];
103
+ let node = start;
104
+ let prefix = emptyCompactBeforeHandlePrefix;
105
+ while (node) {
106
+ const cached = compactBeforeHandleMemos.get(node);
107
+ if (cached !== void 0) {
108
+ if (cached === false) {
109
+ for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
110
+ return;
111
+ }
112
+ prefix = cached;
113
+ break;
114
+ }
115
+ if ("combine" in node) {
116
+ compactBeforeHandleMemos.set(node, false);
117
+ for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
118
+ return;
119
+ }
120
+ const values = compactBeforeHandleValues(node.added);
121
+ if (values === false) {
122
+ compactBeforeHandleMemos.set(node, false);
123
+ for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
124
+ return;
125
+ }
126
+ pending.push({
127
+ node,
128
+ values
129
+ });
130
+ node = node.parent;
131
+ }
132
+ for (let i = pending.length - 1; i >= 0; i--) {
133
+ const item = pending[i];
134
+ prefix = appendCompactBeforeHandle(prefix, item.values);
135
+ compactBeforeHandleMemos.set(item.node, prefix);
136
+ }
137
+ return prefix.length ? prefix : void 0;
138
+ }
139
+ const flattenNodeStack = [];
140
+ const flattenPhaseStack = [];
141
+ /**
142
+ * Walk the chain tail-first into a fresh `Partial<AppHook>`
143
+ *
144
+ * Explicit-stack walk (no recursion) so it works uniformly for linear
145
+ * chains and combine nodes without risking stack overflow on deep chains
146
+ */
147
+ function flattenChain(start, keep, stopAt, resolveAdded) {
148
+ if (!start || start === stopAt) return;
149
+ const result = nullObject();
150
+ const nodes = flattenNodeStack;
151
+ const phases = flattenPhaseStack;
152
+ nodes.length = 0;
153
+ phases.length = 0;
154
+ nodes.push(start);
155
+ phases.push(0);
156
+ while (nodes.length) {
157
+ const node = nodes.pop();
158
+ if (phases.pop() === 1) {
159
+ const added = resolveAdded ? resolveAdded(node) : node.added;
160
+ if (added) appendInto(result, added, keep, node.scope);
161
+ continue;
162
+ }
163
+ if (stopAt && node === stopAt) continue;
164
+ if ("combine" in node) {
165
+ nodes.push(node.combine);
166
+ phases.push(0);
167
+ if (node.over) {
168
+ nodes.push(node.over);
169
+ phases.push(0);
170
+ }
171
+ } else {
172
+ nodes.push(node);
173
+ phases.push(1);
174
+ if (node.parent && node.parent !== stopAt) {
175
+ nodes.push(node.parent);
176
+ phases.push(0);
177
+ }
178
+ }
179
+ }
180
+ if (isNotEmpty(result)) return result;
181
+ }
182
+ /**
183
+ * whenever any macro table mutates (`.macro()` / `#use` merge)
184
+ * every macro-resolution memo flattens, localHook/chainNode memos
185
+ * validates against the current epoch
186
+ *
187
+ * @see `compile/handler`
188
+ */
189
+ let macroTableEpoch = 0;
190
+ const macroEpoch = () => macroTableEpoch;
191
+ const invalidateMacroEpoch = () => {
192
+ macroTableEpoch++;
629
193
  };
630
- function deepClone(source, weak = /* @__PURE__ */ new WeakMap()) {
631
- if (source === null || typeof source != "object" || typeof source == "function")
632
- return source;
633
- if (weak.has(source)) return weak.get(source);
634
- if (Array.isArray(source)) {
635
- const copy = new Array(source.length);
636
- weak.set(source, copy);
637
- for (let i = 0; i < source.length; i++)
638
- copy[i] = deepClone(source[i], weak);
639
- return copy;
640
- }
641
- if (typeof source == "object") {
642
- const keys = Object.keys(source).concat(
643
- Object.getOwnPropertySymbols(source)
644
- ), cloned = {};
645
- weak.set(source, cloned);
646
- for (const key of keys)
647
- cloned[key] = deepClone(source[key], weak);
648
- return cloned;
649
- }
650
- return source;
651
- }
652
- // Annotate the CommonJS export names for ESM import in node:
653
- 0 && (module.exports = {
654
- ELYSIA_FORM_DATA,
655
- ELYSIA_REQUEST_ID,
656
- InvertedStatusMap,
657
- PromiseGroup,
658
- StatusMap,
659
- asHookType,
660
- checksum,
661
- cloneInference,
662
- deduplicateChecksum,
663
- deepClone,
664
- emptySchema,
665
- encodePath,
666
- filterGlobalHook,
667
- fnToContainer,
668
- form,
669
- getLoosePath,
670
- getResponseLength,
671
- hasHeaderShorthand,
672
- hasSetImmediate,
673
- injectChecksum,
674
- insertStandaloneValidator,
675
- isClass,
676
- isNotEmpty,
677
- isNumericString,
678
- lifeCycleToArray,
679
- lifeCycleToFn,
680
- localHookToLifeCycleStore,
681
- mergeCookie,
682
- mergeDeep,
683
- mergeHook,
684
- mergeLifeCycle,
685
- mergeObjectArray,
686
- mergeResponse,
687
- mergeSchemaValidator,
688
- primitiveHooks,
689
- promoteEvent,
690
- randomId,
691
- redirect,
692
- replaceUrlPath,
693
- signCookie,
694
- sse,
695
- supportPerMethodInlineHandler,
696
- unsignCookie
194
+ const flattenChainMemos = /* @__PURE__ */ new WeakMap();
195
+ /** Drop this root's flattened-chain memo. Recomputable on next compile. */
196
+ function clearFlattenChainMemo(root) {
197
+ flattenChainMemos.delete(root);
198
+ }
199
+ const emptyFlatten = Object.freeze(nullObject());
200
+ function flattenChainCached(root, start, resolveAdded) {
201
+ let bucket = flattenChainMemos.get(root);
202
+ if (!bucket || bucket.e !== macroTableEpoch) {
203
+ bucket = {
204
+ e: macroTableEpoch,
205
+ per: /* @__PURE__ */ new WeakMap()
206
+ };
207
+ flattenChainMemos.set(root, bucket);
208
+ }
209
+ const perRoot = bucket.per;
210
+ let cached = perRoot.get(start);
211
+ if (cached === void 0) {
212
+ cached = flattenChain(start, void 0, void 0, resolveAdded) ?? emptyFlatten;
213
+ perRoot.set(start, cached);
214
+ }
215
+ if (cached === emptyFlatten) return;
216
+ return cached;
217
+ }
218
+ function flattenChainMemo(root, start, resolveAdded) {
219
+ if (!start) return;
220
+ const cached = flattenChainCached(root, start, resolveAdded);
221
+ if (cached === void 0) return;
222
+ return cloneHook(cached);
223
+ }
224
+ function flattenChainMemoReadonly(root, start, resolveAdded) {
225
+ if (!start) return;
226
+ return flattenChainCached(root, start, resolveAdded);
227
+ }
228
+ function appendInto(target, src, keep, nodeScope) {
229
+ if (keep && !keep(nodeScope)) return;
230
+ for (const key in src) {
231
+ const v = src[key];
232
+ if (v === void 0 || v === null) continue;
233
+ if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
234
+ const existing = target[key];
235
+ if (Array.isArray(v)) if (existing) {
236
+ const arr = existing;
237
+ for (let i = 0; i < v.length; i++) arr.push(v[i]);
238
+ } else target[key] = v.slice();
239
+ else if (existing) existing.push(v);
240
+ else target[key] = [v];
241
+ } else target[key] = v;
242
+ }
243
+ }
244
+ const notLatin = /[^\x00-\xFF]/;
245
+ /**
246
+ *
247
+ * @param url URL to redirect to
248
+ * @param HTTP status code to send,
249
+ */
250
+ const redirect = (url, status = 302) => new Response(null, {
251
+ status,
252
+ headers: { location: notLatin.test(url) ? encodeURI(url) : url }
253
+ });
254
+ function appendFormField(formData, key, value) {
255
+ if (value === void 0 || value === null) return;
256
+ if (value instanceof Blob) formData.append(key, value);
257
+ else if (value instanceof require_universal_file.ElysiaFile) formData.append(key, value.value);
258
+ else if (typeof value === "object") formData.append(key, JSON.stringify(value));
259
+ else formData.append(key, "" + value);
260
+ }
261
+ /**
262
+ * Build `FormData` from a `form()` object, skipping the internal `~ely-form`
263
+ * marker that flags the object as a form.
264
+ */
265
+ function formToFormData(value) {
266
+ const formData = new FormData();
267
+ for (const key in value) {
268
+ if (key === "~ely-form") continue;
269
+ const field = value[key];
270
+ if (Array.isArray(field)) for (const item of field) appendFormField(formData, key, item);
271
+ else appendFormField(formData, key, field);
272
+ }
273
+ return formData;
274
+ }
275
+ /**
276
+ * Return a `multipart/form-data` response.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * import { Elysia, form, file } from 'elysia'
281
+ *
282
+ * new Elysia().get('/', () =>
283
+ * form({
284
+ * name: 'Tea Party',
285
+ * images: [file('1.webp'), file('2.webp')]
286
+ * })
287
+ * )
288
+ * ```
289
+ */
290
+ const form = (value) => ({
291
+ ...value,
292
+ "~ely-form": 1
697
293
  });
294
+ const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
295
+ const byteStreams = /* @__PURE__ */ new WeakSet();
296
+ /**
297
+ * Certify a byte stream for direct Response body pass-through.
298
+ *
299
+ * The returned Response owns this exact stream. Cancel it through the response
300
+ * body reader; preserving identity means Elysia does not install a second
301
+ * request-signal reader after the body is locked.
302
+ */
303
+ function bytes(stream) {
304
+ byteStreams.add(stream);
305
+ return stream;
306
+ }
307
+ const isByteStream = (value) => typeof value === "object" && value !== null && byteStreams.has(value);
308
+ const sseLineBreak = /\r\n|\r|\n/g;
309
+ const sseField = (name, value) => `${name}: ${(value + "").replace(sseLineBreak, "")}\n`;
310
+ const sseData = (value) => {
311
+ if (value.indexOf("\n") === -1 && value.indexOf("\r") === -1) return "data: " + value + "\n";
312
+ return value.split(sseLineBreak).map((line) => `data: ${line}\n`).join("");
313
+ };
314
+ const sse = (_payload) => {
315
+ if (_payload instanceof ReadableStream) {
316
+ _payload.sse = true;
317
+ return _payload;
318
+ }
319
+ const payload = typeof _payload === "string" ? { data: _payload } : _payload;
320
+ payload.sse = true;
321
+ payload.toSSE = () => {
322
+ let s = "";
323
+ if (payload.id !== void 0 && payload.id !== null) s += sseField("id", payload.id);
324
+ if (payload.event) s += sseField("event", payload.event);
325
+ if (typeof payload.retry === "number" && Number.isFinite(payload.retry) && payload.retry >= 0) s += `retry: ${Math.trunc(payload.retry)}\n`;
326
+ if (payload.data === null) s += "data: null\n";
327
+ else if (typeof payload.data === "string") s += sseData(payload.data);
328
+ else if (typeof payload.data === "object") s += `data: ${JSON.stringify(payload.data)}\n`;
329
+ if (s) s += "\n";
330
+ return s;
331
+ };
332
+ return payload;
333
+ };
334
+ const _enc = new TextEncoder();
335
+ let _constantTimeEqual;
336
+ const _resolveConstantTimeEqual = () => {
337
+ let native;
338
+ try {
339
+ const _crypto = globalThis.process?.getBuiltinModule?.("node:crypto");
340
+ if (typeof _crypto?.timingSafeEqual === "function") native = _crypto.timingSafeEqual;
341
+ } catch {}
342
+ if (!native && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
343
+ if (!native) return (a, b) => {
344
+ if (a.length !== b.length) return false;
345
+ let mismatch = 0;
346
+ for (let i = 0; i < a.length; i++) mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i);
347
+ return mismatch === 0;
348
+ };
349
+ const compare = native;
350
+ return (a, b) => {
351
+ const ab = _enc.encode(a);
352
+ const bb = _enc.encode(b);
353
+ return ab.length !== bb.length ? false : compare(ab, bb);
354
+ };
355
+ };
356
+ const constantTimeEqual = (a, b) => (_constantTimeEqual ??= _resolveConstantTimeEqual())(a, b);
357
+ const isRecordNumber = (x) => {
358
+ if (typeof x !== "object") return false;
359
+ const keys = Object.keys(x);
360
+ return keys.length > 0 && keys.every((k) => !isNaN(+k));
361
+ };
362
+ function mergeResponse(a, b) {
363
+ const aRecord = isRecordNumber(a);
364
+ const bRecord = isRecordNumber(b);
365
+ if (aRecord && bRecord) return Object.assign({}, a, b);
366
+ if (aRecord && b) return Object.assign({}, a, { 200: b });
367
+ if (a && bRecord) return Object.assign({ 200: a }, b);
368
+ return b ?? a;
369
+ }
370
+ /**
371
+ * a is mutable, b is immutable
372
+ *
373
+ * If both are arrays, mutates a by pushing/appending b
374
+ */
375
+ function mergeArray(a, b, reverse = false) {
376
+ if (!a) return b;
377
+ if (!b) return a;
378
+ const aIsArray = Array.isArray(a);
379
+ const bIsArray = Array.isArray(b);
380
+ if (reverse) {
381
+ if (aIsArray && bIsArray) {
382
+ if (b.length === 1) {
383
+ a.unshift(b[0]);
384
+ return a;
385
+ }
386
+ return b.concat(a);
387
+ }
388
+ if (aIsArray) {
389
+ a.unshift(b);
390
+ return a;
391
+ }
392
+ if (bIsArray) {
393
+ const out = new Array(b.length + 1);
394
+ for (let i = 0; i < b.length; i++) out[i] = b[i];
395
+ out[b.length] = a;
396
+ return out;
397
+ }
398
+ return [b, a];
399
+ }
400
+ if (aIsArray && bIsArray) {
401
+ for (let i = 0; i < b.length; i++) a.push(b[i]);
402
+ return a;
403
+ }
404
+ if (aIsArray) {
405
+ a.push(b);
406
+ return a;
407
+ }
408
+ if (bIsArray) {
409
+ const out = new Array(b.length + 1);
410
+ out[0] = a;
411
+ for (let i = 0; i < b.length; i++) out[i + 1] = b[i];
412
+ return out;
413
+ }
414
+ return [a, b];
415
+ }
416
+ /**
417
+ * Like {@link mergeArray} but drops entries from `a` that already appear in
418
+ * `b` by reference. Always allocates fresh arrays - never mutates inputs.
419
+ *
420
+ * Used at the compile-time merge of a route's snapshotted `appHook` with the
421
+ * root's current `rootHook`: the same fn can sit on both sides because
422
+ * `.use()` propagates global/plugin-scoped hooks into the parent, while the
423
+ * route's `appHook` was captured on the child and still holds the original.
424
+ * The fn must run once, in `b`'s position.
425
+ */
426
+ function dedupedMergeArray(a, b, reverse = false) {
427
+ if (!a) return Array.isArray(b) ? b.slice() : b;
428
+ if (!b) return Array.isArray(a) ? a.slice() : a;
429
+ const aArr = Array.isArray(a) ? a : [a];
430
+ const bArr = Array.isArray(b) ? b : [b];
431
+ const seen = new Set(bArr);
432
+ const filtered = [];
433
+ for (let i = 0; i < aArr.length; i++) if (!seen.has(aArr[i])) filtered.push(aArr[i]);
434
+ return reverse ? bArr.concat(filtered) : filtered.concat(bArr);
435
+ }
436
+ const schemaProperties = new Set([
437
+ "body",
438
+ "headers",
439
+ "params",
440
+ "query",
441
+ "cookie",
442
+ "response"
443
+ ]);
444
+ const eventProperties = new Set([
445
+ "start",
446
+ "stop",
447
+ "trace",
448
+ "request",
449
+ "parse",
450
+ "transform",
451
+ "beforeHandle",
452
+ "afterHandle",
453
+ "mapResponse",
454
+ "afterResponse",
455
+ "error"
456
+ ]);
457
+ function hookToGuard(a) {
458
+ if (a.schema !== "merge") return a;
459
+ if (a.body || a.headers || a.params || a.query || a.cookie || a.response) {
460
+ a.schemas ??= [];
461
+ const schema = Object.create(null);
462
+ if (a.body) {
463
+ schema.body = a.body;
464
+ a.body = void 0;
465
+ }
466
+ if (a.headers) {
467
+ schema.headers = a.headers;
468
+ a.headers = void 0;
469
+ }
470
+ if (a.params) {
471
+ schema.params = a.params;
472
+ a.params = void 0;
473
+ }
474
+ if (a.query) {
475
+ schema.query = a.query;
476
+ a.query = void 0;
477
+ }
478
+ if (a.cookie) {
479
+ schema.cookie = a.cookie;
480
+ a.cookie = void 0;
481
+ }
482
+ if (a.response) {
483
+ schema.response = a.response;
484
+ a.response = void 0;
485
+ }
486
+ a.schemas.push(schema);
487
+ }
488
+ return a;
489
+ }
490
+ function coalesceSchemas(existing, incoming) {
491
+ for (const entry of incoming) {
492
+ if (!entry || typeof entry !== "object") continue;
493
+ let merged = false;
494
+ for (let i = 0; i < existing.length; i++) {
495
+ const e = existing[i];
496
+ let canMerge = true;
497
+ for (const k in entry) if (k in e && e[k] !== entry[k]) {
498
+ canMerge = false;
499
+ break;
500
+ }
501
+ if (canMerge) {
502
+ existing[i] = Object.assign(nullObject(), e, entry);
503
+ merged = true;
504
+ break;
505
+ }
506
+ }
507
+ if (!merged) existing.push(entry);
508
+ }
509
+ }
510
+ function mergeHook(a, b, reverse = false, dedup = false) {
511
+ if (!b) return a;
512
+ if (!a) return b;
513
+ const merge = dedup ? dedupedMergeArray : mergeArray;
514
+ if (!a.body && b.body) a.body = b.body;
515
+ if (!a.headers && b.headers) a.headers = b.headers;
516
+ if (!a.params && b.params) a.params = b.params;
517
+ if (!a.query && b.query) a.query = b.query;
518
+ if (!a.cookie && b.cookie) a.cookie = b.cookie;
519
+ if (!a.response && b.response) a.response = b.response;
520
+ else if (a.response && b.response) a.response = mergeResponse(b.response, a.response);
521
+ if (a.parse || b.parse) a.parse = merge(a.parse, b.parse, reverse);
522
+ if (a.transform || b.transform) a.transform = merge(a.transform, b.transform, reverse);
523
+ if (a.derive || b.derive) a.derive = merge(a.derive, b.derive, reverse);
524
+ if (a.beforeHandle || b.beforeHandle) a.beforeHandle = merge(a.beforeHandle, b.beforeHandle, reverse);
525
+ if (a.afterHandle || b.afterHandle) a.afterHandle = merge(a.afterHandle, b.afterHandle, reverse);
526
+ if (a.mapResponse || b.mapResponse) a.mapResponse = merge(a.mapResponse, b.mapResponse, reverse);
527
+ if (a.afterResponse || b.afterResponse) a.afterResponse = merge(a.afterResponse, b.afterResponse, reverse);
528
+ if (a.error || b.error) a.error = merge(a.error, b.error, reverse);
529
+ if (a.trace || b.trace) a.trace = merge(a.trace, b.trace, reverse);
530
+ if (a.schemas || b.schemas) a.schemas = mergeArray(a.schemas, b.schemas, reverse);
531
+ const aDerive = a["~deriveEntries"];
532
+ const bDerive = b["~deriveEntries"];
533
+ if (aDerive || bDerive) a["~deriveEntries"] = mergeArray(aDerive, bDerive, reverse);
534
+ return a;
535
+ }
536
+ const createErrorEventHandler = (fn, error) => (context) => {
537
+ if (context.error instanceof error) return fn(context);
538
+ };
539
+ const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
540
+ const isClassRegex = /^\s*class\s+/;
541
+ const isClass = (v) => typeof v === "function" && isClassRegex.test(v.toString()) || v.toString && v.toString().startsWith("[object ") && v.toString() !== "[object Object]" || isNotEmpty(Object.getPrototypeOf(v));
542
+ function mergeDeep(target, source, skipKeys, override = true, mergeArray = false, seen, cloneAdopt) {
543
+ if (!isObject(target) || !isObject(source)) return target;
544
+ if (seen?.has(source)) return target;
545
+ const keys = Object.keys(source);
546
+ const targetFrozen = Object.isFrozen(target);
547
+ for (let i = 0; i < keys.length; i++) {
548
+ const key = keys[i];
549
+ const value = source[key];
550
+ if (skipKeys?.includes(key) || require_constants.dangerousKeys.has(key)) continue;
551
+ if (mergeArray && Array.isArray(value)) {
552
+ const existing = target[key];
553
+ target[key] = Array.isArray(existing) ? existing.concat(value) : value;
554
+ continue;
555
+ }
556
+ const valueIsObject = isObject(value);
557
+ if (!valueIsObject || !(key in target) || isClass(value)) {
558
+ if ((override || !(key in target)) && !targetFrozen) try {
559
+ target[key] = valueIsObject && cloneAdopt !== void 0 && isPlainObject(value) ? clonePlainDecorators(value, cloneAdopt.map ??= /* @__PURE__ */ new WeakMap()) : value;
560
+ } catch {}
561
+ continue;
562
+ }
563
+ if (!Object.isFrozen(target[key])) {
564
+ seen ??= /* @__PURE__ */ new WeakSet();
565
+ seen.add(source);
566
+ try {
567
+ target[key] = mergeDeep(target[key], value, skipKeys, override, mergeArray, seen, cloneAdopt);
568
+ } catch {}
569
+ }
570
+ }
571
+ seen?.delete(source);
572
+ return target;
573
+ }
574
+ const isBlob = (value) => value instanceof Blob || value instanceof require_universal_file.ElysiaFile;
575
+ function cloneHook(src) {
576
+ const out = nullObject();
577
+ for (const key in src) {
578
+ const value = src[key];
579
+ out[key] = Array.isArray(value) ? value.slice() : value;
580
+ }
581
+ return out;
582
+ }
583
+ function clonePlainDeep(value, seen) {
584
+ if (Array.isArray(value)) {
585
+ seen ??= /* @__PURE__ */ new WeakMap();
586
+ const hit = seen.get(value);
587
+ if (hit) return hit;
588
+ const out = [];
589
+ seen.set(value, out);
590
+ for (let i = 0; i < value.length; i++) out[i] = clonePlainDeep(value[i], seen);
591
+ return out;
592
+ }
593
+ if (isPlainObject(value)) {
594
+ seen ??= /* @__PURE__ */ new WeakMap();
595
+ const hit = seen.get(value);
596
+ if (hit) return hit;
597
+ const out = nullObject();
598
+ seen.set(value, out);
599
+ for (const key in value) out[key] = clonePlainDeep(value[key], seen);
600
+ return out;
601
+ }
602
+ return value;
603
+ }
604
+ function guardNonPlainLeaves(target, source) {
605
+ for (const key in source) {
606
+ if (!Object.hasOwn(source, key)) continue;
607
+ const sv = source[key];
608
+ if (!isObject(sv) || isClass(sv)) continue;
609
+ const tv = target[key];
610
+ if (tv === void 0 || !isObject(tv)) continue;
611
+ if (isPlainObject(tv)) {
612
+ guardNonPlainLeaves(tv, sv);
613
+ continue;
614
+ }
615
+ target[key] = clonePlainDeep(sv);
616
+ }
617
+ }
618
+ function joinPath(base, path) {
619
+ if (!path) return base;
620
+ const baseEndsWithSlash = base.charCodeAt(base.length - 1) === 47;
621
+ const pathStartsWithSlash = path.charCodeAt(0) === 47;
622
+ if (baseEndsWithSlash && pathStartsWithSlash) return base + path.slice(1);
623
+ if (!baseEndsWithSlash && !pathStartsWithSlash) return base + "/" + path;
624
+ return base + path;
625
+ }
626
+ function pushField(target, key, item, defaultArray = false) {
627
+ const v = target[key];
628
+ if (v) if (Array.isArray(v)) target[key].push(item);
629
+ else target[key] = [v, item];
630
+ else target[key] = defaultArray ? [item] : item;
631
+ }
632
+ const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto);
633
+ function replaceUrlPath(url, path) {
634
+ const i = url.indexOf("/", 11);
635
+ const qs = url.indexOf("?", i);
636
+ return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
637
+ }
638
+ function isPlainObject(v) {
639
+ if (!v || typeof v !== "object" || Array.isArray(v)) return false;
640
+ const proto = Object.getPrototypeOf(v);
641
+ return proto === Object.prototype || proto === null;
642
+ }
643
+ function clonePlainDecorators(source, seen) {
644
+ if (seen !== void 0) {
645
+ const existing = seen.get(source);
646
+ if (existing) return existing;
647
+ }
648
+ const out = nullObject();
649
+ if (seen !== void 0) seen.set(source, out);
650
+ for (const key in source) {
651
+ const value = source[key];
652
+ if (isPlainObject(value)) {
653
+ if (seen === void 0) (seen = /* @__PURE__ */ new WeakMap()).set(source, out);
654
+ out[key] = clonePlainDecorators(value, seen);
655
+ } else out[key] = value;
656
+ }
657
+ return out;
658
+ }
659
+ const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
660
+ function prefix(prefix, models) {
661
+ const prefixed = nullObject();
662
+ for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
663
+ return prefixed;
664
+ }
665
+ prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
666
+ const prefixed = nullObject();
667
+ for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
668
+ return prefixed;
669
+ };
670
+ const macroSeedRefIds = /* @__PURE__ */ new WeakMap();
671
+ let macroSeedRefCounter = 0;
672
+ function macroSeedRefId(ref) {
673
+ let id = macroSeedRefIds.get(ref);
674
+ if (id === void 0) macroSeedRefIds.set(ref, id = ++macroSeedRefCounter);
675
+ return id;
676
+ }
677
+ function serializeMacroSeed(_key, value) {
678
+ switch (typeof value) {
679
+ case "function": return "\0fn:" + macroSeedRefId(value);
680
+ case "bigint": return "\0bigint:" + value.toString();
681
+ case "symbol": return "\0sym:" + String(value);
682
+ case "undefined": return "\0undefined";
683
+ default: return value;
684
+ }
685
+ }
686
+
687
+ //#endregion
688
+ exports.bytes = bytes;
689
+ exports.clearFlattenChainMemo = clearFlattenChainMemo;
690
+ exports.cloneHook = cloneHook;
691
+ exports.clonePlainDecorators = clonePlainDecorators;
692
+ exports.clonePlainDeep = clonePlainDeep;
693
+ exports.coalesceSchemas = coalesceSchemas;
694
+ exports.compactBeforeHandleConflicts = compactBeforeHandleConflicts;
695
+ exports.compactBeforeHandlePrefix = compactBeforeHandlePrefix;
696
+ exports.constantTimeEqual = constantTimeEqual;
697
+ exports.createErrorEventHandler = createErrorEventHandler;
698
+ exports.deriveEntryFn = deriveEntryFn;
699
+ exports.eventProperties = eventProperties;
700
+ exports.evictOldestHalf = evictOldestHalf;
701
+ exports.flattenChain = flattenChain;
702
+ exports.flattenChainMemo = flattenChainMemo;
703
+ exports.flattenChainMemoReadonly = flattenChainMemoReadonly;
704
+ exports.fnOrigin = fnOrigin;
705
+ exports.fnv1a = fnv1a;
706
+ exports.form = form;
707
+ exports.formToFormData = formToFormData;
708
+ exports.getLoosePath = getLoosePath;
709
+ exports.guardNonPlainLeaves = guardNonPlainLeaves;
710
+ exports.hookToGuard = hookToGuard;
711
+ exports.invalidateMacroEpoch = invalidateMacroEpoch;
712
+ exports.isBlob = isBlob;
713
+ exports.isByteStream = isByteStream;
714
+ exports.isCompactBeforeHandleOnly = isCompactBeforeHandleOnly;
715
+ exports.isEmpty = isEmpty;
716
+ exports.isLocalScope = isLocalScope;
717
+ exports.isMapDeriveEntry = isMapDeriveEntry;
718
+ exports.isNotEmpty = isNotEmpty;
719
+ exports.isRecordNumber = isRecordNumber;
720
+ exports.joinPath = joinPath;
721
+ exports.macroEpoch = macroEpoch;
722
+ exports.macroOrigin = macroOrigin;
723
+ exports.mapDeriveEntry = mapDeriveEntry;
724
+ exports.mergeArray = mergeArray;
725
+ exports.mergeDeep = mergeDeep;
726
+ exports.mergeHook = mergeHook;
727
+ exports.mergeResponse = mergeResponse;
728
+ exports.nullObject = nullObject;
729
+ exports.prefix = prefix;
730
+ exports.pushField = pushField;
731
+ exports.redirect = redirect;
732
+ exports.replaceUrlPath = replaceUrlPath;
733
+ exports.requestId = requestId;
734
+ exports.schemaProperties = schemaProperties;
735
+ exports.serializeMacroSeed = serializeMacroSeed;
736
+ exports.sse = sse;