elysia 2.0.0-beta.3 → 2.0.0-beta.31

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 (369) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  3. package/dist/adapter/bun/index.d.ts +16 -2
  4. package/dist/adapter/bun/index.js +458 -119
  5. package/dist/adapter/bun/index.mjs +459 -121
  6. package/dist/adapter/constants.mjs +1 -0
  7. package/dist/adapter/default-headers.mjs +1 -0
  8. package/dist/adapter/index.mjs +1 -0
  9. package/dist/adapter/origin.js +0 -57
  10. package/dist/adapter/origin.mjs +1 -57
  11. package/dist/adapter/response-ownership.mjs +1 -0
  12. package/dist/adapter/skip-clone.mjs +1 -0
  13. package/dist/adapter/types.d.ts +2 -21
  14. package/dist/adapter/types.mjs +1 -0
  15. package/dist/adapter/utils.d.ts +11 -3
  16. package/dist/adapter/utils.js +147 -112
  17. package/dist/adapter/utils.mjs +149 -114
  18. package/dist/adapter/web-standard/handler.d.ts +1 -1
  19. package/dist/adapter/web-standard/handler.js +39 -36
  20. package/dist/adapter/web-standard/handler.mjs +41 -37
  21. package/dist/adapter/web-standard/index.js +2 -30
  22. package/dist/adapter/web-standard/index.mjs +3 -30
  23. package/dist/adapter/web-standard/utils.js +5 -18
  24. package/dist/adapter/web-standard/utils.mjs +6 -18
  25. package/dist/base.d.ts +387 -207
  26. package/dist/base.js +742 -676
  27. package/dist/base.mjs +747 -680
  28. package/dist/compile/aot-capture.d.ts +2 -13
  29. package/dist/compile/aot-capture.js +39 -89
  30. package/dist/compile/aot-capture.mjs +43 -88
  31. package/dist/compile/aot-emit.d.ts +9 -8
  32. package/dist/compile/aot-emit.js +36 -38
  33. package/dist/compile/aot-emit.mjs +37 -38
  34. package/dist/compile/aot-reconstruct.js +7 -30
  35. package/dist/compile/aot-reconstruct.mjs +8 -30
  36. package/dist/compile/aot.d.ts +15 -17
  37. package/dist/compile/aot.js +36 -58
  38. package/dist/compile/aot.mjs +34 -57
  39. package/dist/compile/handler/descriptor.d.ts +10 -17
  40. package/dist/compile/handler/descriptor.js +25 -58
  41. package/dist/compile/handler/descriptor.mjs +29 -58
  42. package/dist/compile/handler/frozen-validator.d.ts +7 -12
  43. package/dist/compile/handler/frozen-validator.js +57 -118
  44. package/dist/compile/handler/frozen-validator.mjs +56 -118
  45. package/dist/compile/handler/index.d.ts +8 -4
  46. package/dist/compile/handler/index.js +322 -206
  47. package/dist/compile/handler/index.mjs +324 -211
  48. package/dist/compile/handler/jit.d.ts +28 -21
  49. package/dist/compile/handler/jit.js +232 -159
  50. package/dist/compile/handler/jit.mjs +235 -165
  51. package/dist/compile/handler/params.d.ts +5 -4
  52. package/dist/compile/handler/params.js +21 -9
  53. package/dist/compile/handler/params.mjs +25 -12
  54. package/dist/compile/handler/reconstruct.d.ts +4 -4
  55. package/dist/compile/handler/reconstruct.js +8 -6
  56. package/dist/compile/handler/reconstruct.mjs +9 -6
  57. package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
  58. package/dist/compile/handler/static-clone-resolver.js +8 -0
  59. package/dist/compile/handler/static-clone-resolver.mjs +8 -0
  60. package/dist/compile/handler/utils.d.ts +29 -11
  61. package/dist/compile/handler/utils.js +184 -276
  62. package/dist/compile/handler/utils.mjs +179 -275
  63. package/dist/compile/jit-probe.d.ts +2 -2
  64. package/dist/compile/jit-probe.js +2 -3
  65. package/dist/compile/jit-probe.mjs +3 -3
  66. package/dist/compile/lexer.d.ts +7 -4
  67. package/dist/compile/lexer.js +268 -6
  68. package/dist/compile/lexer.mjs +269 -4
  69. package/dist/compile/utils.d.ts +2 -1
  70. package/dist/compile/utils.js +14 -6
  71. package/dist/compile/utils.mjs +14 -6
  72. package/dist/compiled.d.ts +0 -1
  73. package/dist/compiled.js +0 -10
  74. package/dist/compiled.mjs +1 -10
  75. package/dist/constants.js +19 -4
  76. package/dist/constants.mjs +20 -4
  77. package/dist/context.d.ts +15 -5
  78. package/dist/context.js +17 -36
  79. package/dist/context.mjs +20 -38
  80. package/dist/cookie/config.d.ts +6 -2
  81. package/dist/cookie/config.js +77 -23
  82. package/dist/cookie/config.mjs +79 -25
  83. package/dist/cookie/cookie.d.ts +7 -5
  84. package/dist/cookie/cookie.js +12 -10
  85. package/dist/cookie/cookie.mjs +13 -10
  86. package/dist/cookie/crypto.d.ts +1 -1
  87. package/dist/cookie/crypto.js +19 -14
  88. package/dist/cookie/crypto.mjs +20 -14
  89. package/dist/cookie/error.d.ts +1 -2
  90. package/dist/cookie/error.js +6 -3
  91. package/dist/cookie/error.mjs +7 -3
  92. package/dist/cookie/lib.js +2 -1
  93. package/dist/cookie/lib.mjs +3 -1
  94. package/dist/cookie/serialize.mjs +1 -0
  95. package/dist/cookie/types.d.ts +1 -1
  96. package/dist/cookie/types.mjs +1 -0
  97. package/dist/cookie/utils.d.ts +5 -9
  98. package/dist/cookie/utils.js +109 -83
  99. package/dist/cookie/utils.mjs +112 -84
  100. package/dist/error.d.ts +127 -111
  101. package/dist/error.js +187 -180
  102. package/dist/error.mjs +185 -181
  103. package/dist/generation.d.ts +2 -2
  104. package/dist/generation.mjs +1 -0
  105. package/dist/handler/error.d.ts +18 -18
  106. package/dist/handler/error.js +77 -120
  107. package/dist/handler/error.mjs +80 -122
  108. package/dist/handler/fetch.js +165 -153
  109. package/dist/handler/fetch.mjs +168 -155
  110. package/dist/handler/utils.d.ts +25 -6
  111. package/dist/handler/utils.js +81 -26
  112. package/dist/handler/utils.mjs +76 -25
  113. package/dist/index.d.ts +11 -11
  114. package/dist/index.js +3 -1
  115. package/dist/index.mjs +5 -4
  116. package/dist/memory.js +2 -2
  117. package/dist/memory.mjs +3 -2
  118. package/dist/package.js +1 -1
  119. package/dist/package.mjs +2 -1
  120. package/dist/parse-query.js +76 -80
  121. package/dist/parse-query.mjs +77 -80
  122. package/dist/plugin/aot/bun.d.ts +8 -1
  123. package/dist/plugin/aot/bun.js +9 -28
  124. package/dist/plugin/aot/bun.mjs +11 -29
  125. package/dist/plugin/aot/core.d.ts +37 -66
  126. package/dist/plugin/aot/core.js +197 -153
  127. package/dist/plugin/aot/core.mjs +195 -156
  128. package/dist/plugin/aot/esbuild.js +8 -24
  129. package/dist/plugin/aot/esbuild.mjs +10 -25
  130. package/dist/plugin/aot/hooks.d.ts +6 -17
  131. package/dist/plugin/aot/hooks.js +37 -17
  132. package/dist/plugin/aot/hooks.mjs +38 -19
  133. package/dist/plugin/aot/rspack-loader.d.ts +1 -5
  134. package/dist/plugin/aot/rspack-loader.js +1 -26
  135. package/dist/plugin/aot/rspack-loader.mjs +2 -26
  136. package/dist/plugin/aot/rspack.js +2 -19
  137. package/dist/plugin/aot/rspack.mjs +4 -20
  138. package/dist/plugin/aot/source.d.ts +7 -43
  139. package/dist/plugin/aot/source.js +73 -73
  140. package/dist/plugin/aot/source.mjs +74 -74
  141. package/dist/plugin/aot/treeshake.js +2 -6
  142. package/dist/plugin/aot/treeshake.mjs +3 -6
  143. package/dist/plugin/aot/unplugin.d.ts +1 -4
  144. package/dist/plugin/aot/unplugin.js +4 -32
  145. package/dist/plugin/aot/unplugin.mjs +5 -32
  146. package/dist/plugin/aot/vite.d.ts +2 -6
  147. package/dist/plugin/aot/vite.js +0 -14
  148. package/dist/plugin/aot/vite.mjs +1 -14
  149. package/dist/plugin/aot/worker.js +2 -2
  150. package/dist/plugin/aot/worker.mjs +3 -2
  151. package/dist/plugin/auto-head.js +1 -10
  152. package/dist/plugin/auto-head.mjs +2 -10
  153. package/dist/plugin/trace.d.ts +18 -1
  154. package/dist/plugin/trace.js +0 -16
  155. package/dist/plugin/trace.mjs +1 -16
  156. package/dist/plugin/websocket.d.ts +21 -0
  157. package/dist/plugin/websocket.js +0 -21
  158. package/dist/plugin/websocket.mjs +1 -21
  159. package/dist/route-table.d.ts +3 -0
  160. package/dist/route-table.js +4 -1
  161. package/dist/route-table.mjs +5 -1
  162. package/dist/schema-snapshot.d.ts +0 -4
  163. package/dist/schema-snapshot.js +60 -56
  164. package/dist/schema-snapshot.mjs +61 -56
  165. package/dist/sucrose.d.ts +7 -56
  166. package/dist/sucrose.js +103 -735
  167. package/dist/sucrose.mjs +103 -728
  168. package/dist/trace.d.ts +16 -10
  169. package/dist/trace.js +20 -134
  170. package/dist/trace.mjs +22 -135
  171. package/dist/type/bridge-live.d.ts +5 -3
  172. package/dist/type/bridge-live.js +6 -3
  173. package/dist/type/bridge-live.mjs +6 -3
  174. package/dist/type/bridge.d.ts +7 -5
  175. package/dist/type/bridge.js +38 -28
  176. package/dist/type/bridge.mjs +27 -22
  177. package/dist/type/coerce-plan.d.ts +5 -5
  178. package/dist/type/coerce-plan.js +53 -43
  179. package/dist/type/coerce-plan.mjs +56 -44
  180. package/dist/type/coerce.d.ts +3 -7
  181. package/dist/type/coerce.js +18 -79
  182. package/dist/type/coerce.mjs +20 -80
  183. package/dist/type/compat.js +10 -19
  184. package/dist/type/compat.mjs +12 -20
  185. package/dist/type/constants.d.ts +1 -1
  186. package/dist/type/constants.mjs +1 -0
  187. package/dist/type/elysia/accelerate.mjs +1 -0
  188. package/dist/type/elysia/array-buffer.d.ts +6 -2
  189. package/dist/type/elysia/array-buffer.js +16 -15
  190. package/dist/type/elysia/array-buffer.mjs +17 -16
  191. package/dist/type/elysia/array-string.js +2 -43
  192. package/dist/type/elysia/array-string.mjs +3 -43
  193. package/dist/type/elysia/array.js +5 -9
  194. package/dist/type/elysia/array.mjs +6 -9
  195. package/dist/type/elysia/boolean-string.mjs +1 -0
  196. package/dist/type/elysia/boolean.js +3 -13
  197. package/dist/type/elysia/boolean.mjs +4 -13
  198. package/dist/type/elysia/cookie.d.ts +3 -4
  199. package/dist/type/elysia/cookie.js +3 -14
  200. package/dist/type/elysia/cookie.mjs +4 -14
  201. package/dist/type/elysia/date.d.ts +2 -1
  202. package/dist/type/elysia/date.js +7 -14
  203. package/dist/type/elysia/date.mjs +8 -14
  204. package/dist/type/elysia/file-type.d.ts +2 -2
  205. package/dist/type/elysia/file-type.js +4 -3
  206. package/dist/type/elysia/file-type.mjs +5 -3
  207. package/dist/type/elysia/file.d.ts +1 -3
  208. package/dist/type/elysia/file.js +3 -23
  209. package/dist/type/elysia/file.mjs +5 -10
  210. package/dist/type/elysia/files.js +1 -7
  211. package/dist/type/elysia/files.mjs +3 -8
  212. package/dist/type/elysia/form.mjs +1 -0
  213. package/dist/type/elysia/integer-string.d.ts +1 -1
  214. package/dist/type/elysia/integer-string.js +3 -28
  215. package/dist/type/elysia/integer-string.mjs +5 -29
  216. package/dist/type/elysia/integer.js +3 -13
  217. package/dist/type/elysia/integer.mjs +4 -13
  218. package/dist/type/elysia/intersect.js +0 -5
  219. package/dist/type/elysia/intersect.mjs +1 -5
  220. package/dist/type/elysia/json-string.d.ts +7 -0
  221. package/dist/type/elysia/json-string.js +47 -0
  222. package/dist/type/elysia/json-string.mjs +47 -0
  223. package/dist/type/elysia/keep-config.d.ts +14 -0
  224. package/dist/type/elysia/keep-config.js +62 -0
  225. package/dist/type/elysia/keep-config.mjs +54 -0
  226. package/dist/type/elysia/maybe-empty.mjs +1 -0
  227. package/dist/type/elysia/no-validate.mjs +1 -0
  228. package/dist/type/elysia/nullable.mjs +1 -0
  229. package/dist/type/elysia/number.d.ts +2 -1
  230. package/dist/type/elysia/number.js +19 -12
  231. package/dist/type/elysia/number.mjs +19 -12
  232. package/dist/type/elysia/numeric-enum.d.ts +5 -3
  233. package/dist/type/elysia/numeric-enum.js +1 -5
  234. package/dist/type/elysia/numeric-enum.mjs +2 -5
  235. package/dist/type/elysia/numeric.d.ts +4 -2
  236. package/dist/type/elysia/numeric.js +17 -14
  237. package/dist/type/elysia/numeric.mjs +17 -14
  238. package/dist/type/elysia/object-string.js +2 -40
  239. package/dist/type/elysia/object-string.mjs +3 -40
  240. package/dist/type/elysia/object.js +5 -9
  241. package/dist/type/elysia/object.mjs +6 -9
  242. package/dist/type/elysia/optional.js +8 -8
  243. package/dist/type/elysia/optional.mjs +8 -7
  244. package/dist/type/elysia/problem.d.ts +20 -0
  245. package/dist/type/elysia/problem.js +19 -0
  246. package/dist/type/elysia/problem.mjs +19 -0
  247. package/dist/type/elysia/string.mjs +1 -0
  248. package/dist/type/elysia/uint8-array.d.ts +2 -1
  249. package/dist/type/elysia/uint8-array.js +4 -18
  250. package/dist/type/elysia/uint8-array.mjs +5 -18
  251. package/dist/type/elysia/union-enum.js +5 -6
  252. package/dist/type/elysia/union-enum.mjs +6 -6
  253. package/dist/type/elysia/union.js +0 -5
  254. package/dist/type/elysia/union.mjs +1 -5
  255. package/dist/type/elysia/utils.d.ts +4 -6
  256. package/dist/type/elysia/utils.js +16 -40
  257. package/dist/type/elysia/utils.mjs +15 -36
  258. package/dist/type/exports.d.ts +4 -2
  259. package/dist/type/exports.js +13 -1
  260. package/dist/type/exports.mjs +5 -2
  261. package/dist/type/index.d.ts +1 -1
  262. package/dist/type/index.js +31 -23
  263. package/dist/type/index.mjs +33 -24
  264. package/dist/type/shared.d.ts +12 -10
  265. package/dist/type/shared.js +75 -109
  266. package/dist/type/shared.mjs +72 -108
  267. package/dist/type/sync-require.d.ts +11 -0
  268. package/dist/type/sync-require.js +7 -0
  269. package/dist/type/sync-require.mjs +6 -0
  270. package/dist/type/typebox-system-lite.d.ts +2 -0
  271. package/dist/type/typebox-system-lite.js +34 -0
  272. package/dist/type/typebox-system-lite.mjs +4 -0
  273. package/dist/type/typebox-system-require.d.ts +7 -0
  274. package/dist/type/typebox-system-require.js +24 -0
  275. package/dist/type/typebox-system-require.mjs +24 -0
  276. package/dist/type/typebox-type-live.d.ts +6 -4
  277. package/dist/type/typebox-type-live.js +23 -9
  278. package/dist/type/typebox-type-live.mjs +11 -6
  279. package/dist/type/typebox-type.d.ts +14 -4
  280. package/dist/type/typebox-type.js +85 -22
  281. package/dist/type/typebox-type.mjs +35 -21
  282. package/dist/type/typebox-value-live.d.ts +3 -1
  283. package/dist/type/typebox-value-live.js +5 -1
  284. package/dist/type/typebox-value-live.mjs +4 -1
  285. package/dist/type/typebox-value-ops.d.ts +4 -0
  286. package/dist/type/typebox-value-ops.js +90 -0
  287. package/dist/type/typebox-value-ops.mjs +6 -0
  288. package/dist/type/typebox-value-require.d.ts +8 -0
  289. package/dist/type/typebox-value-require.js +28 -0
  290. package/dist/type/typebox-value-require.mjs +25 -0
  291. package/dist/type/typebox-value.d.ts +9 -4
  292. package/dist/type/typebox-value.js +19 -8
  293. package/dist/type/typebox-value.mjs +19 -9
  294. package/dist/type/types.d.ts +1 -1
  295. package/dist/type/types.mjs +1 -0
  296. package/dist/type/utils.js +1 -10
  297. package/dist/type/utils.mjs +2 -10
  298. package/dist/type/validator/clean-safe.d.ts +2 -4
  299. package/dist/type/validator/clean-safe.js +15 -11
  300. package/dist/type/validator/clean-safe.mjs +17 -10
  301. package/dist/type/validator/custom-error.js +50 -48
  302. package/dist/type/validator/custom-error.mjs +51 -48
  303. package/dist/type/validator/default-precompute.d.ts +10 -2
  304. package/dist/type/validator/default-precompute.js +33 -77
  305. package/dist/type/validator/default-precompute.mjs +33 -77
  306. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  307. package/dist/type/validator/exact-mirror-live.js +15 -0
  308. package/dist/type/validator/exact-mirror-live.mjs +11 -0
  309. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  310. package/dist/type/validator/exact-mirror-require.js +11 -0
  311. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  312. package/dist/type/validator/exact-mirror.js +15 -7
  313. package/dist/type/validator/exact-mirror.mjs +17 -7
  314. package/dist/type/validator/frozen-check.js +7 -8
  315. package/dist/type/validator/frozen-check.mjs +9 -9
  316. package/dist/type/validator/index.d.ts +2 -1
  317. package/dist/type/validator/index.js +149 -168
  318. package/dist/type/validator/index.mjs +155 -173
  319. package/dist/type/validator/string-codec-aot.d.ts +3 -2
  320. package/dist/type/validator/string-codec-aot.js +11 -7
  321. package/dist/type/validator/string-codec-aot.mjs +11 -7
  322. package/dist/type/validator/validator-cache.d.ts +5 -4
  323. package/dist/type/validator/validator-cache.js +49 -37
  324. package/dist/type/validator/validator-cache.mjs +49 -36
  325. package/dist/types.d.ts +596 -187
  326. package/dist/types.mjs +1 -0
  327. package/dist/universal/constants.mjs +1 -0
  328. package/dist/universal/env.js +2 -3
  329. package/dist/universal/env.mjs +2 -3
  330. package/dist/universal/file.d.ts +6 -4
  331. package/dist/universal/file.js +7 -19
  332. package/dist/universal/file.mjs +9 -19
  333. package/dist/universal/index.d.ts +2 -2
  334. package/dist/universal/index.mjs +1 -0
  335. package/dist/universal/is-production.d.ts +1 -2
  336. package/dist/universal/is-production.js +1 -3
  337. package/dist/universal/is-production.mjs +3 -3
  338. package/dist/universal/server.d.ts +0 -272
  339. package/dist/universal/server.mjs +1 -0
  340. package/dist/utils.d.ts +62 -22
  341. package/dist/utils.js +342 -277
  342. package/dist/utils.mjs +327 -273
  343. package/dist/validator/index.d.ts +3 -3
  344. package/dist/validator/index.js +20 -34
  345. package/dist/validator/index.mjs +23 -36
  346. package/dist/validator/route.d.ts +3 -10
  347. package/dist/validator/route.js +2 -1
  348. package/dist/validator/route.mjs +3 -1
  349. package/dist/ws/context.d.ts +4 -1
  350. package/dist/ws/context.js +41 -36
  351. package/dist/ws/context.mjs +41 -36
  352. package/dist/ws/index.mjs +1 -0
  353. package/dist/ws/parser.js +12 -22
  354. package/dist/ws/parser.mjs +13 -22
  355. package/dist/ws/route.d.ts +2 -2
  356. package/dist/ws/route.js +295 -221
  357. package/dist/ws/route.mjs +302 -227
  358. package/dist/ws/types.d.ts +6 -7
  359. package/dist/ws/types.mjs +1 -0
  360. package/package.json +22 -55
  361. package/dist/compile/analysis-cache.d.ts +0 -6
  362. package/dist/compile/analysis-cache.js +0 -12
  363. package/dist/compile/analysis-cache.mjs +0 -11
  364. package/dist/cookie/index.d.ts +0 -7
  365. package/dist/cookie/index.js +0 -13
  366. package/dist/cookie/index.mjs +0 -7
  367. package/dist/handler/index.d.ts +0 -2
  368. package/dist/handler/index.js +0 -5
  369. package/dist/handler/index.mjs +0 -3
@@ -52,8 +52,7 @@ function isImmutableNode(value) {
52
52
  immutableNodes.set(value, immutable);
53
53
  return immutable;
54
54
  }
55
- let freezeClones = false;
56
- function deepCloneSchema(value, seen, canShare = true) {
55
+ function deepCloneSchema(value, freeze, seen, canShare = true) {
57
56
  if (value === null || typeof value !== "object") return value;
58
57
  const cached = seen?.get(value);
59
58
  if (cached) return cached;
@@ -61,8 +60,8 @@ function deepCloneSchema(value, seen, canShare = true) {
61
60
  const out = [];
62
61
  seen ??= /* @__PURE__ */ new Map();
63
62
  seen.set(value, out);
64
- for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
65
- return freezeClones ? Object.freeze(out) : out;
63
+ for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
64
+ return freeze ? Object.freeze(out) : out;
66
65
  }
67
66
  if (canShare && isImmutableNode(value)) return value;
68
67
  const proto = Object.getPrototypeOf(value);
@@ -77,14 +76,14 @@ function deepCloneSchema(value, seen, canShare = true) {
77
76
  const property = value[key];
78
77
  if (!allEnumerable && !isEnumerable.call(value, key)) {
79
78
  Object.defineProperty(out, key, {
80
- value: property,
79
+ value: key === "~cookieFrom" ? deepCloneSchema(property, freeze, seen) : property,
81
80
  enumerable: false,
82
81
  writable: true,
83
82
  configurable: true
84
83
  });
85
84
  continue;
86
85
  }
87
- const cloned = deepCloneSchema(property, seen);
86
+ const cloned = deepCloneSchema(property, freeze, seen);
88
87
  if (key === "__proto__") Object.defineProperty(out, key, {
89
88
  value: cloned,
90
89
  enumerable: true,
@@ -97,7 +96,7 @@ function deepCloneSchema(value, seen, canShare = true) {
97
96
  for (let i = 0; i < symbols.length; i++) {
98
97
  const key = symbols[i];
99
98
  const property = value[key];
100
- if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
99
+ if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
101
100
  else Object.defineProperty(out, key, {
102
101
  value: property,
103
102
  enumerable: false,
@@ -105,7 +104,7 @@ function deepCloneSchema(value, seen, canShare = true) {
105
104
  configurable: true
106
105
  });
107
106
  }
108
- return freezeClones ? Object.freeze(out) : out;
107
+ return freeze ? Object.freeze(out) : out;
109
108
  }
110
109
  const refIds = /* @__PURE__ */ new WeakMap();
111
110
  let nextRefId = 0;
@@ -114,20 +113,19 @@ function refKey(value) {
114
113
  if (id === void 0) refIds.set(value, id = ++nextRefId);
115
114
  return "r" + id + ";";
116
115
  }
117
- let fingerprintBail = false;
118
- const byRefKey = (value) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0);
119
- function fingerprint(value, seen, canShare = true) {
116
+ const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
117
+ function fingerprint(value, seen, state, canShare = true) {
120
118
  if (value === null) return "z;";
121
119
  const type = typeof value;
122
120
  if (type !== "object") switch (type) {
123
121
  case "string": return "s" + value.length + ":" + value;
124
- case "number": return "n" + value + ";";
122
+ case "number": return "n" + (Object.is(value, -0) ? "-0" : value) + ";";
125
123
  case "boolean": return value ? "T;" : "F;";
126
124
  case "function": return refKey(value);
127
125
  case "undefined": return "u;";
128
126
  case "bigint": return "g" + value + ";";
129
127
  default:
130
- fingerprintBail = true;
128
+ state.bail = true;
131
129
  return "y;";
132
130
  }
133
131
  const backReference = seen?.get(value);
@@ -136,7 +134,7 @@ function fingerprint(value, seen, canShare = true) {
136
134
  seen ??= /* @__PURE__ */ new Map();
137
135
  seen.set(value, seen.size);
138
136
  let out = "[";
139
- for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
137
+ for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
140
138
  return out + "];";
141
139
  }
142
140
  if (canShare && isImmutableNode(value)) return refKey(value);
@@ -151,15 +149,19 @@ function fingerprint(value, seen, canShare = true) {
151
149
  const key = keys[i];
152
150
  const property = value[key];
153
151
  out += "k" + key.length + ":" + key;
154
- out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
152
+ const hidden = !allEnumerable && !isEnumerable.call(value, key);
153
+ out += hidden && key !== "~cookieFrom" ? "!" + byRefKey(property, state) : (hidden ? "~" : "=") + fingerprint(property, seen, state);
155
154
  }
156
- if (Object.getOwnPropertySymbols(value).length) fingerprintBail = true;
155
+ if (Object.getOwnPropertySymbols(value).length) state.bail = true;
157
156
  return out + "};";
158
157
  }
159
- /**
160
- * The `.model()` snapshot: a private, MUTABLE clone. `base.ts` stamps `$id` onto
161
- * the node this returns, so it is never frozen and never interned.
162
- */
158
+ function cloneOrWarn(object, freeze) {
159
+ try {
160
+ return deepCloneSchema(object, freeze, void 0, false);
161
+ } catch (error) {
162
+ console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
163
+ }
164
+ }
163
165
  function snapshotSchema(schema) {
164
166
  if (schema === null || typeof schema !== "object") return schema;
165
167
  const object = schema;
@@ -167,21 +169,12 @@ function snapshotSchema(schema) {
167
169
  if (produced.has(object) && !Object.isFrozen(object)) return schema;
168
170
  const existing = modelSnapshots.get(object);
169
171
  if (existing) return existing;
170
- let cloned;
171
- try {
172
- cloned = deepCloneSchema(object, void 0, false);
173
- } catch (error) {
174
- console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
175
- return schema;
176
- }
172
+ const cloned = cloneOrWarn(object, false);
173
+ if (cloned === void 0) return schema;
177
174
  modelSnapshots.set(object, cloned);
178
175
  produced.add(cloned);
179
176
  return cloned;
180
177
  }
181
- /**
182
- * The route/guard hook snapshot: deep-frozen, and shared with every
183
- * structurally identical schema in the process.
184
- */
185
178
  function internSchema(schema, intern) {
186
179
  if (schema === null || typeof schema !== "object") return schema;
187
180
  const object = schema;
@@ -193,11 +186,11 @@ function internSchema(schema, intern) {
193
186
  if (existing) return existing;
194
187
  let key;
195
188
  if (intern) {
196
- fingerprintBail = false;
189
+ const state = { bail: false };
197
190
  try {
198
- key = fingerprint(object, void 0, false);
191
+ key = fingerprint(object, void 0, state, false);
199
192
  } catch {}
200
- if (fingerprintBail) key = void 0;
193
+ if (state.bail) key = void 0;
201
194
  }
202
195
  if (key !== void 0) {
203
196
  const shared = interned.get(key);
@@ -210,16 +203,8 @@ function internSchema(schema, intern) {
210
203
  return shared;
211
204
  }
212
205
  }
213
- let cloned;
214
- freezeClones = true;
215
- try {
216
- cloned = deepCloneSchema(object, void 0, false);
217
- } catch (error) {
218
- console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
219
- return schema;
220
- } finally {
221
- freezeClones = false;
222
- }
206
+ const cloned = cloneOrWarn(object, true);
207
+ if (cloned === void 0) return schema;
223
208
  hookSnapshots.set(object, cloned);
224
209
  produced.add(cloned);
225
210
  if (key !== void 0) {
@@ -232,9 +217,34 @@ function snapshotSlots(target, intern) {
232
217
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
233
218
  const response = target.response;
234
219
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
235
- const next = {};
236
- for (const status in response) next[status] = internSchema(response[status], intern);
237
- target.response = next;
220
+ let next = {};
221
+ const state = { bail: false };
222
+ let key = "M";
223
+ for (const status in response) {
224
+ const schema = internSchema(response[status], intern);
225
+ Object.defineProperty(next, status, {
226
+ value: schema,
227
+ enumerable: true
228
+ });
229
+ key += status.length + ":" + status + byRefKey(schema, state);
230
+ }
231
+ if (key === "M") target.response = next;
232
+ else {
233
+ if (intern && !state.bail) {
234
+ const shared = interned.get(key);
235
+ if (shared === void 0) {
236
+ if (interned.size >= INTERN_LIMIT) require_utils.evictOldestHalf(interned);
237
+ interned.set(key, next);
238
+ } else {
239
+ if (interned.size >= INTERN_LIMIT) {
240
+ interned.delete(key);
241
+ interned.set(key, shared);
242
+ }
243
+ next = shared;
244
+ }
245
+ }
246
+ target.response = Object.freeze(next);
247
+ }
238
248
  } else target.response = internSchema(response, intern);
239
249
  }
240
250
  function isStatusMap(response) {
@@ -242,18 +252,12 @@ function isStatusMap(response) {
242
252
  for (const key in response) if (!Number.isInteger(Number(key))) return false;
243
253
  return true;
244
254
  }
255
+ const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
245
256
  function snapshotHookSchemas(hook) {
246
257
  if (!hook) return hook;
247
- let needsCopy = false;
248
- if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
258
+ const needsCopy = hasSlot(hook);
249
259
  const schemas = hook.schemas;
250
- if (!needsCopy && Array.isArray(schemas)) {
251
- for (const entry of schemas) if (entry && (schemaSlots.some((slot) => entry[slot] != null) || entry.response != null)) {
252
- needsCopy = true;
253
- break;
254
- }
255
- }
256
- if (!needsCopy) return hook;
260
+ if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
257
261
  const intern = !require_universal_env.env.ELYSIA_AOT_BUILD;
258
262
  const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
259
263
  snapshotSlots(copy, intern);
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { evictOldestHalf } from "./utils.mjs";
2
3
  import { env } from "./universal/env.mjs";
3
4
 
@@ -51,8 +52,7 @@ function isImmutableNode(value) {
51
52
  immutableNodes.set(value, immutable);
52
53
  return immutable;
53
54
  }
54
- let freezeClones = false;
55
- function deepCloneSchema(value, seen, canShare = true) {
55
+ function deepCloneSchema(value, freeze, seen, canShare = true) {
56
56
  if (value === null || typeof value !== "object") return value;
57
57
  const cached = seen?.get(value);
58
58
  if (cached) return cached;
@@ -60,8 +60,8 @@ function deepCloneSchema(value, seen, canShare = true) {
60
60
  const out = [];
61
61
  seen ??= /* @__PURE__ */ new Map();
62
62
  seen.set(value, out);
63
- for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
64
- return freezeClones ? Object.freeze(out) : out;
63
+ for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
64
+ return freeze ? Object.freeze(out) : out;
65
65
  }
66
66
  if (canShare && isImmutableNode(value)) return value;
67
67
  const proto = Object.getPrototypeOf(value);
@@ -76,14 +76,14 @@ function deepCloneSchema(value, seen, canShare = true) {
76
76
  const property = value[key];
77
77
  if (!allEnumerable && !isEnumerable.call(value, key)) {
78
78
  Object.defineProperty(out, key, {
79
- value: property,
79
+ value: key === "~cookieFrom" ? deepCloneSchema(property, freeze, seen) : property,
80
80
  enumerable: false,
81
81
  writable: true,
82
82
  configurable: true
83
83
  });
84
84
  continue;
85
85
  }
86
- const cloned = deepCloneSchema(property, seen);
86
+ const cloned = deepCloneSchema(property, freeze, seen);
87
87
  if (key === "__proto__") Object.defineProperty(out, key, {
88
88
  value: cloned,
89
89
  enumerable: true,
@@ -96,7 +96,7 @@ function deepCloneSchema(value, seen, canShare = true) {
96
96
  for (let i = 0; i < symbols.length; i++) {
97
97
  const key = symbols[i];
98
98
  const property = value[key];
99
- if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
99
+ if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
100
100
  else Object.defineProperty(out, key, {
101
101
  value: property,
102
102
  enumerable: false,
@@ -104,7 +104,7 @@ function deepCloneSchema(value, seen, canShare = true) {
104
104
  configurable: true
105
105
  });
106
106
  }
107
- return freezeClones ? Object.freeze(out) : out;
107
+ return freeze ? Object.freeze(out) : out;
108
108
  }
109
109
  const refIds = /* @__PURE__ */ new WeakMap();
110
110
  let nextRefId = 0;
@@ -113,20 +113,19 @@ function refKey(value) {
113
113
  if (id === void 0) refIds.set(value, id = ++nextRefId);
114
114
  return "r" + id + ";";
115
115
  }
116
- let fingerprintBail = false;
117
- const byRefKey = (value) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0);
118
- function fingerprint(value, seen, canShare = true) {
116
+ const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
117
+ function fingerprint(value, seen, state, canShare = true) {
119
118
  if (value === null) return "z;";
120
119
  const type = typeof value;
121
120
  if (type !== "object") switch (type) {
122
121
  case "string": return "s" + value.length + ":" + value;
123
- case "number": return "n" + value + ";";
122
+ case "number": return "n" + (Object.is(value, -0) ? "-0" : value) + ";";
124
123
  case "boolean": return value ? "T;" : "F;";
125
124
  case "function": return refKey(value);
126
125
  case "undefined": return "u;";
127
126
  case "bigint": return "g" + value + ";";
128
127
  default:
129
- fingerprintBail = true;
128
+ state.bail = true;
130
129
  return "y;";
131
130
  }
132
131
  const backReference = seen?.get(value);
@@ -135,7 +134,7 @@ function fingerprint(value, seen, canShare = true) {
135
134
  seen ??= /* @__PURE__ */ new Map();
136
135
  seen.set(value, seen.size);
137
136
  let out = "[";
138
- for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
137
+ for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
139
138
  return out + "];";
140
139
  }
141
140
  if (canShare && isImmutableNode(value)) return refKey(value);
@@ -150,15 +149,19 @@ function fingerprint(value, seen, canShare = true) {
150
149
  const key = keys[i];
151
150
  const property = value[key];
152
151
  out += "k" + key.length + ":" + key;
153
- out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
152
+ const hidden = !allEnumerable && !isEnumerable.call(value, key);
153
+ out += hidden && key !== "~cookieFrom" ? "!" + byRefKey(property, state) : (hidden ? "~" : "=") + fingerprint(property, seen, state);
154
154
  }
155
- if (Object.getOwnPropertySymbols(value).length) fingerprintBail = true;
155
+ if (Object.getOwnPropertySymbols(value).length) state.bail = true;
156
156
  return out + "};";
157
157
  }
158
- /**
159
- * The `.model()` snapshot: a private, MUTABLE clone. `base.ts` stamps `$id` onto
160
- * the node this returns, so it is never frozen and never interned.
161
- */
158
+ function cloneOrWarn(object, freeze) {
159
+ try {
160
+ return deepCloneSchema(object, freeze, void 0, false);
161
+ } catch (error) {
162
+ console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
163
+ }
164
+ }
162
165
  function snapshotSchema(schema) {
163
166
  if (schema === null || typeof schema !== "object") return schema;
164
167
  const object = schema;
@@ -166,21 +169,12 @@ function snapshotSchema(schema) {
166
169
  if (produced.has(object) && !Object.isFrozen(object)) return schema;
167
170
  const existing = modelSnapshots.get(object);
168
171
  if (existing) return existing;
169
- let cloned;
170
- try {
171
- cloned = deepCloneSchema(object, void 0, false);
172
- } catch (error) {
173
- console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
174
- return schema;
175
- }
172
+ const cloned = cloneOrWarn(object, false);
173
+ if (cloned === void 0) return schema;
176
174
  modelSnapshots.set(object, cloned);
177
175
  produced.add(cloned);
178
176
  return cloned;
179
177
  }
180
- /**
181
- * The route/guard hook snapshot: deep-frozen, and shared with every
182
- * structurally identical schema in the process.
183
- */
184
178
  function internSchema(schema, intern) {
185
179
  if (schema === null || typeof schema !== "object") return schema;
186
180
  const object = schema;
@@ -192,11 +186,11 @@ function internSchema(schema, intern) {
192
186
  if (existing) return existing;
193
187
  let key;
194
188
  if (intern) {
195
- fingerprintBail = false;
189
+ const state = { bail: false };
196
190
  try {
197
- key = fingerprint(object, void 0, false);
191
+ key = fingerprint(object, void 0, state, false);
198
192
  } catch {}
199
- if (fingerprintBail) key = void 0;
193
+ if (state.bail) key = void 0;
200
194
  }
201
195
  if (key !== void 0) {
202
196
  const shared = interned.get(key);
@@ -209,16 +203,8 @@ function internSchema(schema, intern) {
209
203
  return shared;
210
204
  }
211
205
  }
212
- let cloned;
213
- freezeClones = true;
214
- try {
215
- cloned = deepCloneSchema(object, void 0, false);
216
- } catch (error) {
217
- console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
218
- return schema;
219
- } finally {
220
- freezeClones = false;
221
- }
206
+ const cloned = cloneOrWarn(object, true);
207
+ if (cloned === void 0) return schema;
222
208
  hookSnapshots.set(object, cloned);
223
209
  produced.add(cloned);
224
210
  if (key !== void 0) {
@@ -231,9 +217,34 @@ function snapshotSlots(target, intern) {
231
217
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
232
218
  const response = target.response;
233
219
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
234
- const next = {};
235
- for (const status in response) next[status] = internSchema(response[status], intern);
236
- target.response = next;
220
+ let next = {};
221
+ const state = { bail: false };
222
+ let key = "M";
223
+ for (const status in response) {
224
+ const schema = internSchema(response[status], intern);
225
+ Object.defineProperty(next, status, {
226
+ value: schema,
227
+ enumerable: true
228
+ });
229
+ key += status.length + ":" + status + byRefKey(schema, state);
230
+ }
231
+ if (key === "M") target.response = next;
232
+ else {
233
+ if (intern && !state.bail) {
234
+ const shared = interned.get(key);
235
+ if (shared === void 0) {
236
+ if (interned.size >= INTERN_LIMIT) evictOldestHalf(interned);
237
+ interned.set(key, next);
238
+ } else {
239
+ if (interned.size >= INTERN_LIMIT) {
240
+ interned.delete(key);
241
+ interned.set(key, shared);
242
+ }
243
+ next = shared;
244
+ }
245
+ }
246
+ target.response = Object.freeze(next);
247
+ }
237
248
  } else target.response = internSchema(response, intern);
238
249
  }
239
250
  function isStatusMap(response) {
@@ -241,18 +252,12 @@ function isStatusMap(response) {
241
252
  for (const key in response) if (!Number.isInteger(Number(key))) return false;
242
253
  return true;
243
254
  }
255
+ const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
244
256
  function snapshotHookSchemas(hook) {
245
257
  if (!hook) return hook;
246
- let needsCopy = false;
247
- if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
258
+ const needsCopy = hasSlot(hook);
248
259
  const schemas = hook.schemas;
249
- if (!needsCopy && Array.isArray(schemas)) {
250
- for (const entry of schemas) if (entry && (schemaSlots.some((slot) => entry[slot] != null) || entry.response != null)) {
251
- needsCopy = true;
252
- break;
253
- }
254
- }
255
- if (!needsCopy) return hook;
260
+ if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
256
261
  const intern = !env.ELYSIA_AOT_BUILD;
257
262
  const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
258
263
  snapshotSlots(copy, intern);
package/dist/sucrose.d.ts CHANGED
@@ -11,64 +11,15 @@ declare namespace Sucrose {
11
11
  route: boolean;
12
12
  afterResponse?: boolean;
13
13
  }
14
- type LifeCycle = Partial<Partial<AppHook>>;
14
+ type LifeCycle = Partial<AppHook>;
15
15
  }
16
+ declare function clearSucroseCache(): void;
17
+ declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Sucrose.Inference;
16
18
  /**
17
- * Separate stringified function body and parameter
18
- *
19
- * @example
20
- * ```typescript
21
- * separateFunction('async ({ hello }) => { return hello }') // => ['({ hello })', '{ return hello }']
22
- * ```
23
- */
24
- declare function separateFunction(code: string): [string, string];
25
- /**
26
- * Get range between bracket pair
27
- *
28
- * @example
29
- * ```typescript
30
- * bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
31
- * ```
32
- */
33
- declare function bracketPairRange(parameter: string): [number, number];
34
- /**
35
- * Similar to `bracketPairRange` but in reverse order
36
- * Get range between bracket pair from end to beginning
37
- *
38
- * @example
39
- * ```typescript
40
- * bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
41
- * ```
42
- */
43
- declare function bracketPairRangeReverse(parameter: string): [number, number];
44
- declare function removeColonAlias(parameter: string): string;
45
- /**
46
- * Retrieve only root parameters of a function
47
- *
48
- * @example
49
- * ```typescript
50
- * retrieveRootParameters('({ hello: { world: { a } }, elysia })') // => {
51
- * parameters: ['hello', 'elysia'],
52
- * hasParenthesis: true
53
- * }
54
- * ```
55
- */
56
- declare function retrieveRootparameters(parameter: string): {
57
- hasParenthesis: boolean;
58
- parameters: Record<string, true>;
59
- };
60
- /**
61
- * Find alias of variable from function body
62
- *
63
- * @example
64
- * ```typescript
65
- * findAlias('body', '{ const a = body, b = body }') // => ['a', 'b']
66
- * ```
19
+ * @internal Which `channelOf`-mapped members of a function's first parameter
20
+ * the function may read, or `null` when any member may be read
67
21
  */
68
- declare function findAlias(type: string, body: string, seen?: Set<string>): string[];
69
- declare function removeDefaultParameter(parameter: string): string;
70
- declare function clearSucroseCache(delay?: number | null): void;
71
- declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Sucrose.Inference;
22
+ declare function inferParameterReads<K extends string>(source: string, channelOf: (value: string) => K | undefined, strict?: boolean): Set<K> | null;
72
23
  declare function sucrose(handler: Handler | undefined, lifeCycle: Sucrose.LifeCycle | undefined): Sucrose.Inference;
73
24
  //#endregion
74
- export { Sucrose, bracketPairRange, bracketPairRangeReverse, clearSucroseCache, findAlias, mergeInference, removeColonAlias, removeDefaultParameter, retrieveRootparameters, separateFunction, sucrose };
25
+ export { Sucrose, clearSucroseCache, inferParameterReads, mergeInference, sucrose };