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
package/dist/utils.js CHANGED
@@ -49,6 +49,12 @@ function fnv1a(str) {
49
49
  const fnOrigin = /* @__PURE__ */ new WeakMap();
50
50
  const macroOrigin = /* @__PURE__ */ new WeakMap();
51
51
  const isLocalScope = (s) => s === "local" || s === void 0;
52
+ /**
53
+ * The absorbing instance's chain as it stood at `.use()`: the `over` of a
54
+ * combine node, or the node itself. A combine node is never on an instance's
55
+ * own chain, so it can't serve as a `stopAt` directly
56
+ */
57
+ const rootSnapshot = (node) => node && "combine" in node ? node.over : node;
52
58
  const COMPACT_CHUNK_SIZE = 32;
53
59
  const emptyCompactBeforeHandlePrefix = {
54
60
  length: 0,
@@ -73,30 +79,6 @@ function compactBeforeHandleConflicts(hook) {
73
79
  for (let i = 0; i < values.length; i++) if (compactBeforeHandleFunctions.has(values[i])) return true;
74
80
  return false;
75
81
  }
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
82
  function compactBeforeHandlePrefix(start) {
101
83
  if (!start) return;
102
84
  const pending = [];
@@ -104,34 +86,51 @@ function compactBeforeHandlePrefix(start) {
104
86
  let prefix = emptyCompactBeforeHandlePrefix;
105
87
  while (node) {
106
88
  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
- }
89
+ if (cached) {
112
90
  prefix = cached;
113
91
  break;
114
92
  }
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;
93
+ if (cached === void 0 && !("combine" in node)) {
94
+ const values = compactBeforeHandleValues(node.added);
95
+ if (values !== false) {
96
+ pending.push({
97
+ node,
98
+ values
99
+ });
100
+ node = node.parent;
101
+ continue;
102
+ }
125
103
  }
126
- pending.push({
127
- node,
128
- values
129
- });
130
- node = node.parent;
104
+ compactBeforeHandleMemos.set(node, false);
105
+ for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
106
+ return;
131
107
  }
132
108
  for (let i = pending.length - 1; i >= 0; i--) {
133
109
  const item = pending[i];
134
- prefix = appendCompactBeforeHandle(prefix, item.values);
110
+ const added = item.values;
111
+ if (added.length) {
112
+ let tail = prefix.tail;
113
+ let length = prefix.length;
114
+ for (let j = 0; j < added.length; j++) {
115
+ const fn = added[j];
116
+ compactBeforeHandleFunctions.add(fn);
117
+ if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
118
+ parent: tail.parent,
119
+ values: [...tail.values, fn]
120
+ };
121
+ else tail = {
122
+ parent: tail,
123
+ values: [fn]
124
+ };
125
+ length++;
126
+ }
127
+ prefix = {
128
+ tail,
129
+ length,
130
+ previous: prefix.length ? prefix : void 0,
131
+ added
132
+ };
133
+ }
135
134
  compactBeforeHandleMemos.set(item.node, prefix);
136
135
  }
137
136
  return prefix.length ? prefix : void 0;
@@ -157,13 +156,30 @@ function flattenChain(start, keep, stopAt, resolveAdded) {
157
156
  const node = nodes.pop();
158
157
  if (phases.pop() === 1) {
159
158
  const added = resolveAdded ? resolveAdded(node) : node.added;
160
- if (added) appendInto(result, added, keep, node.scope);
159
+ if (added) {
160
+ const nodeScope = node.scope;
161
+ if (!(keep && !keep(nodeScope))) for (const key in added) {
162
+ const v = added[key];
163
+ if (v === void 0 || v === null) continue;
164
+ if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
165
+ const existing = result[key];
166
+ if (Array.isArray(v)) if (existing) {
167
+ const arr = existing;
168
+ for (let i = 0; i < v.length; i++) arr.push(v[i]);
169
+ } else result[key] = v.slice();
170
+ else if (existing) existing.push(v);
171
+ else result[key] = [v];
172
+ } else result[key] = v;
173
+ }
174
+ }
161
175
  continue;
162
176
  }
163
177
  if (stopAt && node === stopAt) continue;
164
178
  if ("combine" in node) {
165
- nodes.push(node.combine);
166
- phases.push(0);
179
+ if (node.combine) {
180
+ nodes.push(node.combine);
181
+ phases.push(0);
182
+ }
167
183
  if (node.over) {
168
184
  nodes.push(node.over);
169
185
  phases.push(0);
@@ -197,7 +213,8 @@ function clearFlattenChainMemo(root) {
197
213
  flattenChainMemos.delete(root);
198
214
  }
199
215
  const emptyFlatten = Object.freeze(nullObject());
200
- function flattenChainCached(root, start, resolveAdded) {
216
+ function flattenChainMemoReadonly(root, start, resolveAdded) {
217
+ if (!start) return;
201
218
  let bucket = flattenChainMemos.get(root);
202
219
  if (!bucket || bucket.e !== macroTableEpoch) {
203
220
  bucket = {
@@ -216,30 +233,8 @@ function flattenChainCached(root, start, resolveAdded) {
216
233
  return cached;
217
234
  }
218
235
  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
- }
236
+ const cached = flattenChainMemoReadonly(root, start, resolveAdded);
237
+ if (cached) return cloneHook(cached);
243
238
  }
244
239
  const notLatin = /[^\x00-\xFF]/;
245
240
  /**
@@ -287,6 +282,7 @@ function formToFormData(value) {
287
282
  * ```
288
283
  */
289
284
  const form = (value) => Object.setPrototypeOf({ ...value }, ELYSIA_FORM_PROTOTYPE);
285
+ const assignOwn = (target, source) => source != null && Object.hasOwn(source, "__proto__") ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : Object.assign(target, source);
290
286
  const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
291
287
  const byteStreams = /* @__PURE__ */ new WeakSet();
292
288
  /**
@@ -322,6 +318,7 @@ const sse = (_payload) => {
322
318
  if (payload.data === null) s += "data: null\n";
323
319
  else if (typeof payload.data === "string") s += sseData(payload.data);
324
320
  else if (typeof payload.data === "object") s += `data: ${JSON.stringify(payload.data)}\n`;
321
+ else if (payload.data !== void 0) s += sseData(String(payload.data));
325
322
  if (s) s += "\n";
326
323
  return s;
327
324
  };
@@ -331,11 +328,11 @@ const _enc = new TextEncoder();
331
328
  let _constantTimeEqual;
332
329
  const _resolveConstantTimeEqual = () => {
333
330
  let native;
334
- try {
331
+ if (require_universal_constants.isBun && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
332
+ else try {
335
333
  const _crypto = globalThis.process?.getBuiltinModule?.("node:crypto");
336
334
  if (typeof _crypto?.timingSafeEqual === "function") native = _crypto.timingSafeEqual;
337
335
  } catch {}
338
- if (!native && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
339
336
  if (!native) return (a, b) => {
340
337
  if (a.length !== b.length) return false;
341
338
  let mismatch = 0;
@@ -429,14 +426,26 @@ function dedupedMergeArray(a, b, reverse = false) {
429
426
  for (let i = 0; i < aArr.length; i++) if (!seen.has(aArr[i])) filtered.push(aArr[i]);
430
427
  return reverse ? bArr.concat(filtered) : filtered.concat(bArr);
431
428
  }
432
- const schemaProperties = new Set([
429
+ const hookSchemaKeys = [
433
430
  "body",
434
431
  "headers",
435
432
  "params",
436
433
  "query",
437
434
  "cookie",
438
435
  "response"
439
- ]);
436
+ ];
437
+ const schemaProperties = new Set(hookSchemaKeys);
438
+ const hookEventKeys = [
439
+ "parse",
440
+ "transform",
441
+ "derive",
442
+ "beforeHandle",
443
+ "afterHandle",
444
+ "mapResponse",
445
+ "afterResponse",
446
+ "error",
447
+ "trace"
448
+ ];
440
449
  const eventProperties = new Set([
441
450
  "start",
442
451
  "stop",
@@ -451,33 +460,16 @@ const eventProperties = new Set([
451
460
  "error"
452
461
  ]);
453
462
  function hookToGuard(a) {
454
- if (a.schema !== "merge") return a;
463
+ if (a.schema !== "merge") {
464
+ if (a.schema !== void 0 && a.schema !== "override") throw new Error(`[Elysia] Invalid guard schema ${JSON.stringify(a.schema)}, expected 'merge' or 'override' (1.x 'standalone' is 'merge')`);
465
+ return a;
466
+ }
455
467
  if (a.body || a.headers || a.params || a.query || a.cookie || a.response) {
456
468
  a.schemas ??= [];
457
469
  const schema = Object.create(null);
458
- if (a.body) {
459
- schema.body = a.body;
460
- a.body = void 0;
461
- }
462
- if (a.headers) {
463
- schema.headers = a.headers;
464
- a.headers = void 0;
465
- }
466
- if (a.params) {
467
- schema.params = a.params;
468
- a.params = void 0;
469
- }
470
- if (a.query) {
471
- schema.query = a.query;
472
- a.query = void 0;
473
- }
474
- if (a.cookie) {
475
- schema.cookie = a.cookie;
476
- a.cookie = void 0;
477
- }
478
- if (a.response) {
479
- schema.response = a.response;
480
- a.response = void 0;
470
+ for (const key of hookSchemaKeys) if (a[key]) {
471
+ schema[key] = a[key];
472
+ a[key] = void 0;
481
473
  }
482
474
  a.schemas.push(schema);
483
475
  }
@@ -507,30 +499,22 @@ function mergeHook(a, b, reverse = false, dedup = false) {
507
499
  if (!b) return a;
508
500
  if (!a) return b;
509
501
  const merge = dedup ? dedupedMergeArray : mergeArray;
510
- if (!a.body && b.body) a.body = b.body;
511
- if (!a.headers && b.headers) a.headers = b.headers;
512
- if (!a.params && b.params) a.params = b.params;
513
- if (!a.query && b.query) a.query = b.query;
514
- if (!a.cookie && b.cookie) a.cookie = b.cookie;
515
- if (!a.response && b.response) a.response = b.response;
516
- else if (a.response && b.response) a.response = mergeResponse(b.response, a.response);
517
- if (a.parse || b.parse) a.parse = merge(a.parse, b.parse, reverse);
518
- if (a.transform || b.transform) a.transform = merge(a.transform, b.transform, reverse);
519
- if (a.derive || b.derive) a.derive = merge(a.derive, b.derive, reverse);
520
- if (a.beforeHandle || b.beforeHandle) a.beforeHandle = merge(a.beforeHandle, b.beforeHandle, reverse);
521
- if (a.afterHandle || b.afterHandle) a.afterHandle = merge(a.afterHandle, b.afterHandle, reverse);
522
- if (a.mapResponse || b.mapResponse) a.mapResponse = merge(a.mapResponse, b.mapResponse, reverse);
523
- if (a.afterResponse || b.afterResponse) a.afterResponse = merge(a.afterResponse, b.afterResponse, reverse);
524
- if (a.error || b.error) a.error = merge(a.error, b.error, reverse);
525
- if (a.trace || b.trace) a.trace = merge(a.trace, b.trace, reverse);
502
+ for (const key of hookSchemaKeys) if (!a[key] && b[key]) a[key] = b[key];
503
+ else if (key === "response" && a.response && b.response) a.response = mergeResponse(b.response, a.response);
504
+ for (const key of hookEventKeys) if (a[key] || b[key]) a[key] = merge(a[key], b[key], reverse);
526
505
  if (a.schemas || b.schemas) a.schemas = mergeArray(a.schemas, b.schemas, reverse);
527
506
  const aDerive = a["~deriveEntries"];
528
507
  const bDerive = b["~deriveEntries"];
529
508
  if (aDerive || bDerive) a["~deriveEntries"] = mergeArray(aDerive, bDerive, reverse);
530
509
  return a;
531
510
  }
532
- const createErrorEventHandler = (fn, error) => (context) => {
533
- if (context.error instanceof error) return fn(context);
511
+ const createErrorEventHandler = (fn, error) => {
512
+ const handler = (context) => {
513
+ if (context.error instanceof error) return fn(context);
514
+ };
515
+ const p = error?.prototype;
516
+ if (typeof p === "object" && p !== null && p !== Error.prototype && !(p instanceof Error)) handler["~errorClass"] = error;
517
+ return handler;
534
518
  };
535
519
  const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
536
520
  const isClassRegex = /^\s*class\s+/;
@@ -619,15 +603,21 @@ function joinPath(base, path) {
619
603
  if (!baseEndsWithSlash && !pathStartsWithSlash) return base + "/" + path;
620
604
  return base + path;
621
605
  }
622
- function pushField(target, key, item, defaultArray = false) {
606
+ function pushField(target, key, item) {
623
607
  const v = target[key];
624
608
  if (v) if (Array.isArray(v)) target[key].push(item);
625
609
  else target[key] = [v, item];
626
- else target[key] = defaultArray ? [item] : item;
610
+ else target[key] = item;
627
611
  }
628
- const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto);
612
+ const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.randomUUID.bind(crypto);
613
+ /**
614
+ * Offset of the first byte after `://`, so the authority is never scanned as
615
+ * path. A fixed offset would let the client-supplied `Host` decide how many
616
+ * leading path bytes are dropped
617
+ */
618
+ const authorityEnd = (url) => url.charCodeAt(4) === 58 ? 7 : url.charCodeAt(5) === 58 ? 8 : url.indexOf("://") + 3;
629
619
  function replaceUrlPath(url, path) {
630
- const i = url.indexOf("/", 11);
620
+ const i = url.indexOf("/", authorityEnd(url));
631
621
  const qs = url.indexOf("?", i);
632
622
  return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
633
623
  }
@@ -652,7 +642,6 @@ function clonePlainDecorators(source, seen) {
652
642
  }
653
643
  return out;
654
644
  }
655
- const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
656
645
  function prefix(prefix, models) {
657
646
  const prefixed = nullObject();
658
647
  for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
@@ -660,7 +649,7 @@ function prefix(prefix, models) {
660
649
  }
661
650
  prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
662
651
  const prefixed = nullObject();
663
- for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
652
+ for (const key in models) prefixed[`${prefix}.${key.charAt(0).toUpperCase() + key.slice(1)}`] = models[key];
664
653
  return prefixed;
665
654
  };
666
655
  const macroSeedRefIds = /* @__PURE__ */ new WeakMap();
@@ -679,9 +668,43 @@ function serializeMacroSeed(_key, value) {
679
668
  default: return value;
680
669
  }
681
670
  }
671
+ const throwLifecycleErrors = (errors) => {
672
+ if (errors.length === 1) throw errors[0];
673
+ if (errors.length) throw new AggregateError(errors, "Multiple lifecycle failures");
674
+ };
675
+ const isDisposable = (value) => {
676
+ if (value == null) return false;
677
+ const kind = typeof value;
678
+ if (kind !== "object" && kind !== "function") return false;
679
+ try {
680
+ return typeof value[Symbol.asyncDispose] === "function" || typeof value[Symbol.dispose] === "function";
681
+ } catch {
682
+ return false;
683
+ }
684
+ };
685
+ const singletons = /* @__PURE__ */ new WeakSet();
686
+ const isSingleton = (value) => singletons.has(value);
687
+ const markSingletons = (value, depth = 4, seen = /* @__PURE__ */ new Set()) => {
688
+ if (value == null) return;
689
+ const kind = typeof value;
690
+ if (kind !== "object" && kind !== "function") return;
691
+ const object = value;
692
+ if (seen.has(object)) return;
693
+ seen.add(object);
694
+ singletons.add(object);
695
+ if (depth <= 0) return;
696
+ for (const key of Object.keys(object)) {
697
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
698
+ if (descriptor && "value" in descriptor) markSingletons(descriptor.value, depth - 1, seen);
699
+ }
700
+ };
701
+ const isSocketQuiet = (socket) => socket.readyState === 3 && !socket.data.inflight && !socket.data.opening && !socket.data.settling;
702
+ const isHTMLBundle = (value) => Object.prototype.toString.call(value) === "[object HTMLBundle]" || typeof value?.index === "string" && Array.isArray(value.files);
682
703
 
683
704
  //#endregion
684
705
  exports.ELYSIA_FORM_PROTOTYPE = ELYSIA_FORM_PROTOTYPE;
706
+ exports.assignOwn = assignOwn;
707
+ exports.authorityEnd = authorityEnd;
685
708
  exports.bytes = bytes;
686
709
  exports.clearFlattenChainMemo = clearFlattenChainMemo;
687
710
  exports.cloneHook = cloneHook;
@@ -709,16 +732,22 @@ exports.invalidateMacroEpoch = invalidateMacroEpoch;
709
732
  exports.isBlob = isBlob;
710
733
  exports.isByteStream = isByteStream;
711
734
  exports.isCompactBeforeHandleOnly = isCompactBeforeHandleOnly;
735
+ exports.isDisposable = isDisposable;
712
736
  exports.isElysiaForm = isElysiaForm;
713
737
  exports.isEmpty = isEmpty;
738
+ exports.isHTMLBundle = isHTMLBundle;
714
739
  exports.isLocalScope = isLocalScope;
715
740
  exports.isMapDeriveEntry = isMapDeriveEntry;
716
741
  exports.isNotEmpty = isNotEmpty;
742
+ exports.isPlainObject = isPlainObject;
717
743
  exports.isRecordNumber = isRecordNumber;
744
+ exports.isSingleton = isSingleton;
745
+ exports.isSocketQuiet = isSocketQuiet;
718
746
  exports.joinPath = joinPath;
719
747
  exports.macroEpoch = macroEpoch;
720
748
  exports.macroOrigin = macroOrigin;
721
749
  exports.mapDeriveEntry = mapDeriveEntry;
750
+ exports.markSingletons = markSingletons;
722
751
  exports.mergeArray = mergeArray;
723
752
  exports.mergeDeep = mergeDeep;
724
753
  exports.mergeHook = mergeHook;
@@ -729,6 +758,9 @@ exports.pushField = pushField;
729
758
  exports.redirect = redirect;
730
759
  exports.replaceUrlPath = replaceUrlPath;
731
760
  exports.requestId = requestId;
761
+ exports.rootSnapshot = rootSnapshot;
732
762
  exports.schemaProperties = schemaProperties;
733
763
  exports.serializeMacroSeed = serializeMacroSeed;
734
- exports.sse = sse;
764
+ exports.sse = sse;
765
+ exports.sseData = sseData;
766
+ exports.throwLifecycleErrors = throwLifecycleErrors;