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
@@ -1,44 +1,95 @@
1
+ // @bun
1
2
  import { isCloudflareWorker, isFastly } from "../universal/constants.mjs";
3
+ import { isDisposable, isSingleton } from "../utils.mjs";
2
4
  import { env } from "../universal/env.mjs";
3
- import { PROBLEM_JSON } from "../error.mjs";
5
+ import { HTTPError, PROBLEM_JSON, problemTypeOf } from "../error.mjs";
4
6
  import { isAsyncFunction, mayReturnPromise } from "../compile/utils.mjs";
5
7
 
6
8
  //#region src/handler/utils.ts
7
9
  const isPreallocateResponseUnsafe = isCloudflareWorker || isFastly || env.ELYSIA_PREALLOCATE_RESPONSE === "false";
8
10
  const emptyResponse = isPreallocateResponseUnsafe ? { clone: () => new Response(null) } : new Response(null);
9
- function cachedResponse(body, status, headers) {
10
- let cached;
11
- return () => isPreallocateResponseUnsafe ? new Response(body, {
12
- status,
13
- headers
14
- }) : (cached ??= new Response(body, {
15
- status,
16
- headers
17
- })).clone();
11
+ let notFoundBase;
12
+ let notFoundBody;
13
+ let notFoundResponse;
14
+ function getNotFoundBody() {
15
+ const base = HTTPError.typeBase;
16
+ if (notFoundBody === void 0 || base !== notFoundBase) {
17
+ notFoundBase = base;
18
+ notFoundResponse = void 0;
19
+ notFoundBody = JSON.stringify({
20
+ type: problemTypeOf("not-found"),
21
+ code: "not-found",
22
+ status: 404,
23
+ title: "Not Found"
24
+ });
25
+ }
26
+ return notFoundBody;
27
+ }
28
+ const notFoundInit = {
29
+ status: 404,
30
+ headers: { "content-type": PROBLEM_JSON }
31
+ };
32
+ function getNotFound() {
33
+ const body = getNotFoundBody();
34
+ if (isPreallocateResponseUnsafe) return new Response(body, notFoundInit);
35
+ return (notFoundResponse ??= new Response(body, notFoundInit)).clone();
18
36
  }
19
- const NOT_FOUND_BODY = JSON.stringify({
20
- type: "not-found",
21
- title: "Not Found",
22
- status: 404
23
- });
24
- const getNotFound = cachedResponse(NOT_FOUND_BODY, 404, { "content-type": PROBLEM_JSON });
25
37
  function forwardError(value) {
26
38
  if (value instanceof Error) throw value;
27
39
  return value;
28
40
  }
29
- function finalizeRouteError(app, context, error) {
41
+ function returnedErrorClasses(hook) {
42
+ const error = hook?.error;
43
+ if (!error) return;
44
+ let into;
45
+ const list = Array.isArray(error) ? error : [error];
46
+ for (let i = 0; i < list.length; i++) {
47
+ const errorClass = list[i]?.["~errorClass"];
48
+ if (errorClass && !into?.includes(errorClass)) (into ??= []).push(errorClass);
49
+ }
50
+ return into;
51
+ }
52
+ const forwardErrorOf = (classes) => (value) => {
53
+ if (value instanceof Error) throw value;
54
+ for (let i = 0; i < classes.length; i++) if (value instanceof classes[i]) throw value;
55
+ return value;
56
+ };
57
+ function finalizeRouteError(app, context, error, sign, route) {
30
58
  const finalize = app["~finalizeError"];
31
59
  if (!finalize) throw error;
32
- return finalize(context, error);
60
+ return finalize(context, error, sign, false, route);
61
+ }
62
+ const finalizeRouteErrorOf = (route) => route?.error?.length || route?.mapResponse?.length ? (app, context, error, sign) => finalizeRouteError(app, context, error, sign, route) : finalizeRouteError;
63
+ function registerDeriveDisposable(context, value, scan = context) {
64
+ if (!isDisposable(value)) return;
65
+ if (isSingleton(value)) return;
66
+ for (const key in scan) if (scan[key] === value) return;
67
+ const stack = context["~dispose"] ??= [];
68
+ for (const release of stack) if (release.value === value) return;
69
+ const disposable = value;
70
+ const asyncDispose = disposable[Symbol.asyncDispose];
71
+ const dispose = typeof asyncDispose === "function" ? asyncDispose : disposable[Symbol.dispose];
72
+ const release = () => dispose.call(value);
73
+ release.value = value;
74
+ stack.push(release);
33
75
  }
34
- function getAsyncIndexes(onRequests) {
35
- let asyncIndexes;
36
- for (let i = 0; i < onRequests.length; i++) if (isAsyncFunction(onRequests[i]) || mayReturnPromise(onRequests[i])) {
37
- asyncIndexes ??= new Array(onRequests.length);
38
- asyncIndexes[i] = true;
76
+ async function drainDisposables(context) {
77
+ const stack = context["~dispose"];
78
+ if (!stack) return;
79
+ try {
80
+ if (!Array.isArray(stack)) throw new TypeError("Invalid disposable stack");
81
+ const errors = [];
82
+ while (stack.length) try {
83
+ await stack.pop()();
84
+ } catch (error) {
85
+ errors.push(error);
86
+ }
87
+ if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Multiple disposers failed");
88
+ } catch (error) {
89
+ console.error(error);
39
90
  }
40
- return asyncIndexes;
41
91
  }
92
+ const hasAsync = (fns) => fns.some((fn) => isAsyncFunction(fn) || mayReturnPromise(fn));
42
93
 
43
94
  //#endregion
44
- export { NOT_FOUND_BODY, emptyResponse, finalizeRouteError, forwardError, getAsyncIndexes, getNotFound };
95
+ export { drainDisposables, emptyResponse, finalizeRouteError, finalizeRouteErrorOf, forwardError, forwardErrorOf, getNotFound, getNotFoundBody, hasAsync, registerDeriveDisposable, returnedErrorClasses };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- import { BaseCookie, CookieOptions } from "./cookie/types.js";
2
- import { Cookie } from "./cookie/cookie.js";
3
- import { ElysiaFile, file } from "./universal/file.js";
4
1
  import { StatusMap, StatusMapBack } from "./constants.js";
5
- import { env } from "./universal/env.js";
2
+ import { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, NumericStatus, ParseError, Problem, SelectiveProblem, SelectiveStatus, StatusResponse, TaggedHTTPError, ValidationError, ValidationErrorResponse, problem, status, validationDetail } from "./error.js";
3
+ import { bytes, form, macroType, prefix, redirect, sse } from "./utils.js";
6
4
  import { Server } from "./universal/server.js";
7
- import { bytes, form, prefix, redirect, sse } from "./utils.js";
8
- import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
9
- import { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, ParseError, Problem, SelectiveStatus, TaggedHTTPError, ValidationError, problem, status, validationDetail } from "./error.js";
5
+ import { BaseCookie, CookieOptions } from "./cookie/types.js";
6
+ import { Cookie } from "./cookie/cookie.js";
10
7
  import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
11
- import { InvalidCookie } from "./cookie/error.js";
8
+ import { ElysiaFile, file } from "./universal/file.js";
12
9
  import { AnySchema, BaseSchema, StandardJSONSchemaV1Like, StandardSchemaV1Like } from "./type/types.js";
13
10
  import { TCookieField, TCookieObject } from "./type/elysia/cookie.js";
14
- import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
15
11
  import { TFiles } from "./type/elysia/files.js";
16
12
  import { setupTypebox } from "./type/compat.js";
13
+ import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
14
+ import { AotFingerprint, Capture, Compiled, CompilerSession, ProgramId, inAotBuild } from "./compile/aot.js";
17
15
  import { MultiValidator, StandardValidator, Validator } from "./validator/index.js";
18
16
  import { TypeBoxValidator } from "./type/validator/index.js";
19
17
  import { TypeSystem, t } from "./type/index.js";
20
- import { AotFingerprint, Capture, Compiled, CompilerSession, ProgramId } from "./compile/aot.js";
18
+ import { env } from "./universal/env.js";
19
+ import { DefaultEphemeral, DefaultMetadata, DefaultSingleton, HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, MacroTypeLambda, RouteSchema, SSEPayload, UnwrapModels, UnwrapRoute, UnwrapSchema } from "./types.js";
21
20
  import { AnyElysia, Elysia } from "./base.js";
22
21
  import { borrow } from "./adapter/response-ownership.js";
23
- export { AnyElysia, type AnySchema, type AotFingerprint, type BaseCookie, type BaseSchema, Compiled, type CompilerSession, type Context, type Cookie, type CookieOptions, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, HTTPError, type HTTPHeaders, type InputSchema, InternalServerError, InvalidCookie, type Macro, type MacroToContext, type MacroToProperty, Capture as Manifest, MultiValidator, NotFound, ParseError, type Problem, type ProgramId, type RouteSchema, type SSEPayload, type SelectiveStatus, type Server, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type TCookieField, type TCookieObject, type TFiles, type TaggedHTTPError, TypeBoxValidator, TypeSystem, type UnwrapRoute, type UnwrapSchema, ValidationError, Validator, borrow, bytes, createBaseContext, createContext, env, file, fileType, form, prefix, problem, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
22
+ import { InvalidCookie } from "./cookie/error.js";
23
+ export { AnyElysia, type AnySchema, type AotFingerprint, type BaseCookie, type BaseSchema, Compiled, type CompilerSession, type Context, type Cookie, type CookieOptions, type DefaultEphemeral, type DefaultMetadata, type DefaultSingleton, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, HTTPError, type HTTPHeaders, type InputSchema, InternalServerError, InvalidCookie, type Macro, type MacroToContext, type MacroToProperty, type MacroTypeLambda, Capture as Manifest, MultiValidator, NotFound, type NumericStatus, ParseError, type Problem, type ProgramId, type RouteSchema, type SSEPayload, type SelectiveProblem, type SelectiveStatus, type Server, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type StatusResponse, type TCookieField, type TCookieObject, type TFiles, type TaggedHTTPError, TypeBoxValidator, TypeSystem, type UnwrapModels, type UnwrapRoute, type UnwrapSchema, ValidationError, type ValidationErrorResponse, Validator, borrow, bytes, createBaseContext, createContext, env, file, fileType, form, inAotBuild, macroType, prefix, problem, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
package/dist/index.js CHANGED
@@ -7,10 +7,10 @@ const require_error = require('./error.js');
7
7
  const require_cookie_error = require('./cookie/error.js');
8
8
  const require_adapter_response_ownership = require('./adapter/response-ownership.js');
9
9
  const require_compile_aot = require('./compile/aot.js');
10
- const require_type_elysia_file_type = require('./type/elysia/file-type.js');
11
10
  const require_validator_index = require('./validator/index.js');
12
11
  const require_context = require('./context.js');
13
12
  const require_base = require('./base.js');
13
+ const require_type_elysia_file_type = require('./type/elysia/file-type.js');
14
14
  const require_type_validator_index = require('./type/validator/index.js');
15
15
  const require_type_compat = require('./type/compat.js');
16
16
  const require_type_index = require('./type/index.js');
@@ -47,6 +47,8 @@ exports.env = require_universal_env.env;
47
47
  exports.file = require_universal_file.file;
48
48
  exports.fileType = require_type_elysia_file_type.fileType;
49
49
  exports.form = require_utils.form;
50
+ exports.inAotBuild = require_compile_aot.inAotBuild;
51
+ exports.macroType = require_utils.macroType;
50
52
  exports.prefix = require_utils.prefix;
51
53
  exports.problem = require_error.problem;
52
54
  exports.redirect = require_utils.redirect;
package/dist/index.mjs CHANGED
@@ -1,15 +1,16 @@
1
+ // @bun
1
2
  import { StatusMap, StatusMapBack } from "./constants.mjs";
2
3
  import { ElysiaFile, file } from "./universal/file.mjs";
3
- import { bytes, form, prefix, redirect, sse } from "./utils.mjs";
4
+ import { bytes, form, macroType, prefix, redirect, sse } from "./utils.mjs";
4
5
  import { env } from "./universal/env.mjs";
5
6
  import { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, ParseError, ValidationError, problem, status, validationDetail } from "./error.mjs";
6
7
  import { InvalidCookie } from "./cookie/error.mjs";
7
8
  import { borrow } from "./adapter/response-ownership.mjs";
8
- import { Capture, Compiled } from "./compile/aot.mjs";
9
- import { fileType, setFileTypeDetector } from "./type/elysia/file-type.mjs";
9
+ import { Capture, Compiled, inAotBuild } from "./compile/aot.mjs";
10
10
  import { MultiValidator, StandardValidator, Validator } from "./validator/index.mjs";
11
11
  import { createBaseContext, createContext } from "./context.mjs";
12
12
  import { Elysia } from "./base.mjs";
13
+ import { fileType, setFileTypeDetector } from "./type/elysia/file-type.mjs";
13
14
  import { TypeBoxValidator } from "./type/validator/index.mjs";
14
15
  import { setupTypebox } from "./type/compat.mjs";
15
16
  import { TypeSystem, t } from "./type/index.mjs";
@@ -18,4 +19,4 @@ import { TypeSystem, t } from "./type/index.mjs";
18
19
  var src_default = Elysia;
19
20
 
20
21
  //#endregion
21
- export { Compiled, Elysia, ElysiaError, ElysiaFile, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, Capture as Manifest, MultiValidator, NotFound, ParseError, StandardValidator, StatusMap, StatusMapBack, TypeBoxValidator, TypeSystem, ValidationError, Validator, borrow, bytes, createBaseContext, createContext, src_default as default, env, file, fileType, form, prefix, problem, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
22
+ export { Compiled, Elysia, ElysiaError, ElysiaFile, ElysiaStatus, HTTPError, InternalServerError, InvalidCookie, Capture as Manifest, MultiValidator, NotFound, ParseError, StandardValidator, StatusMap, StatusMapBack, TypeBoxValidator, TypeSystem, ValidationError, Validator, borrow, bytes, createBaseContext, createContext, src_default as default, env, file, fileType, form, inAotBuild, macroType, prefix, problem, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
package/dist/memory.js CHANGED
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_universal_constants = require('./universal/constants.js');
3
- const require_sucrose = require('./sucrose.js');
4
3
  const require_validator_index = require('./validator/index.js');
4
+ const require_sucrose = require('./sucrose.js');
5
5
  const require_context = require('./context.js');
6
6
 
7
7
  //#region src/memory.ts
8
8
  function flushMemory() {
9
- require_sucrose.clearSucroseCache(0);
9
+ require_sucrose.clearSucroseCache();
10
10
  require_context.clearContextCache();
11
11
  require_validator_index.Validator.clear();
12
12
  if (require_universal_constants.isBun) Bun.gc();
package/dist/memory.mjs CHANGED
@@ -1,11 +1,12 @@
1
+ // @bun
1
2
  import { isBun } from "./universal/constants.mjs";
2
- import { clearSucroseCache } from "./sucrose.mjs";
3
3
  import { Validator } from "./validator/index.mjs";
4
+ import { clearSucroseCache } from "./sucrose.mjs";
4
5
  import { clearContextCache } from "./context.mjs";
5
6
 
6
7
  //#region src/memory.ts
7
8
  function flushMemory() {
8
- clearSucroseCache(0);
9
+ clearSucroseCache();
9
10
  clearContextCache();
10
11
  Validator.clear();
11
12
  if (isBun) Bun.gc();
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-beta.3";
3
+ var version = "2.0.0-beta.31";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ // @bun
1
2
  //#region package.json
2
- var version = "2.0.0-beta.3";
3
+ var version = "2.0.0-beta.31";
3
4
 
4
5
  //#endregion
5
6
  export { version };
@@ -22,7 +22,7 @@ function parseQueryFromURL(input, startIndex = input.indexOf("?", 11), array, ob
22
22
  let equalityIndex = startingIndex;
23
23
  for (let i = startIndex + 1; i < inputLength; i++) switch (input.charCodeAt(i)) {
24
24
  case 38:
25
- processKeyValuePair(input, i);
25
+ processKeyValuePairFromURL(input, i, result, startingIndex, equalityIndex, flags, array, object);
26
26
  startingIndex = i;
27
27
  equalityIndex = i;
28
28
  flags = 0;
@@ -40,69 +40,65 @@ function parseQueryFromURL(input, startIndex = input.indexOf("?", 11), array, ob
40
40
  else flags |= KEY_NEEDS_DECODE;
41
41
  break;
42
42
  }
43
- if (startingIndex < inputLength) processKeyValuePair(input, inputLength);
43
+ if (startingIndex < inputLength) processKeyValuePairFromURL(input, inputLength, result, startingIndex, equalityIndex, flags, array, object);
44
44
  return result;
45
- function processKeyValuePair(input, endIndex) {
46
- const hasBothKeyValuePair = equalityIndex > startingIndex;
47
- const effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : endIndex;
48
- const keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
49
- if (!hasBothKeyValuePair && keySlice.length === 0) return;
50
- let finalKey = keySlice;
51
- if (flags & KEY_HAS_PLUS) finalKey = finalKey.replace(/\+/g, " ");
52
- if (flags & KEY_NEEDS_DECODE) finalKey = (0, deuri.default)(finalKey) || finalKey;
53
- let finalValue = "";
54
- if (hasBothKeyValuePair) {
55
- let valueSlice = input.slice(equalityIndex + 1, endIndex);
56
- if (flags & VALUE_HAS_PLUS) valueSlice = valueSlice.replace(/\+/g, " ");
57
- if (flags & VALUE_NEEDS_DECODE) valueSlice = (0, deuri.default)(valueSlice) || valueSlice;
58
- finalValue = valueSlice;
59
- }
60
- const currentValue = result[finalKey];
61
- if (array && array?.[finalKey]) {
62
- let rawValue = hasBothKeyValuePair ? input.slice(equalityIndex + 1, endIndex) : "";
63
- if (flags & VALUE_HAS_PLUS) rawValue = rawValue.replace(/\+/g, " ");
64
- const rawBracket = rawValue.charCodeAt(0) === 91 && rawValue.charCodeAt(rawValue.length - 1) === 93;
65
- const decodedBracket = !rawBracket && finalValue.charCodeAt(0) === 91 && finalValue.charCodeAt(finalValue.length - 1) === 93;
66
- if (rawBracket || decodedBracket) {
67
- let toBracketArray;
68
- if (rawBracket) toBracketArray = rawValue.length === 2 ? [] : splitRawParts(rawValue.slice(1, -1), flags);
69
- else {
70
- const inner = finalValue.slice(1, -1);
71
- toBracketArray = inner === "" ? [] : inner.split(",");
72
- }
73
- if (object && object?.[finalKey]) try {
74
- finalValue = JSON.parse(finalValue);
75
- } catch {
76
- finalValue = toBracketArray;
77
- }
78
- else finalValue = toBracketArray;
79
- if (currentValue === void 0) result[finalKey] = finalValue;
80
- else if (Array.isArray(currentValue)) for (let i = 0; i < finalValue.length; i++) currentValue.push(finalValue[i]);
81
- else {
82
- result[finalKey] = finalValue;
83
- result[finalKey].unshift(currentValue);
84
- }
85
- } else {
86
- if (object && object?.[finalKey] && finalValue.charCodeAt(0) === 123) try {
87
- finalValue = JSON.parse(finalValue);
88
- } catch {}
89
- else if (currentValue === void 0 && !(object && object?.[finalKey]) && rawValue.indexOf(",") !== -1) finalValue = splitRawParts(rawValue, flags);
90
- if (currentValue === void 0) result[finalKey] = Array.isArray(finalValue) ? finalValue : [finalValue];
91
- else if (Array.isArray(currentValue)) currentValue.push(finalValue);
92
- else result[finalKey] = [currentValue, finalValue];
45
+ }
46
+ function processKeyValuePairFromURL(input, endIndex, result, startingIndex, equalityIndex, flags, array, object) {
47
+ const hasBothKeyValuePair = equalityIndex > startingIndex;
48
+ const effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : endIndex;
49
+ const keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
50
+ if (!hasBothKeyValuePair && keySlice.length === 0) return;
51
+ let finalKey = keySlice;
52
+ if (flags & KEY_HAS_PLUS) finalKey = finalKey.replace(/\+/g, " ");
53
+ if (flags & KEY_NEEDS_DECODE) finalKey = (0, deuri.default)(finalKey) || finalKey;
54
+ let finalValue = "";
55
+ if (hasBothKeyValuePair) {
56
+ let valueSlice = input.slice(equalityIndex + 1, endIndex);
57
+ if (flags & VALUE_HAS_PLUS) valueSlice = valueSlice.replace(/\+/g, " ");
58
+ if (flags & VALUE_NEEDS_DECODE) valueSlice = (0, deuri.default)(valueSlice) || valueSlice;
59
+ finalValue = valueSlice;
60
+ }
61
+ const currentValue = result[finalKey];
62
+ if (array && array?.[finalKey]) {
63
+ let rawValue = hasBothKeyValuePair ? input.slice(equalityIndex + 1, endIndex) : "";
64
+ if (flags & VALUE_HAS_PLUS) rawValue = rawValue.replace(/\+/g, " ");
65
+ const rawBracket = rawValue.charCodeAt(0) === 91 && rawValue.charCodeAt(rawValue.length - 1) === 93;
66
+ const decodedBracket = !rawBracket && finalValue.charCodeAt(0) === 91 && finalValue.charCodeAt(finalValue.length - 1) === 93;
67
+ if (rawBracket || decodedBracket) {
68
+ let toBracketArray;
69
+ if (rawBracket) toBracketArray = rawValue.length === 2 ? [] : splitRawParts(rawValue.slice(1, -1), flags);
70
+ else {
71
+ const inner = finalValue.slice(1, -1);
72
+ toBracketArray = inner === "" ? [] : inner.split(",");
73
+ }
74
+ if (object && object?.[finalKey]) try {
75
+ finalValue = JSON.parse(finalValue);
76
+ } catch {
77
+ finalValue = toBracketArray;
93
78
  }
94
- } else if (object?.[finalKey] && finalValue.charCodeAt(0) === 123) try {
95
- result[finalKey] = JSON.parse(finalValue);
96
- } catch {
97
- result[finalKey] = finalValue;
79
+ else finalValue = toBracketArray;
80
+ if (currentValue === void 0) result[finalKey] = finalValue;
81
+ else if (Array.isArray(currentValue)) for (let i = 0; i < finalValue.length; i++) currentValue.push(finalValue[i]);
82
+ else {
83
+ result[finalKey] = finalValue;
84
+ result[finalKey].unshift(currentValue);
85
+ }
86
+ } else {
87
+ if (object && object?.[finalKey] && finalValue.charCodeAt(0) === 123) try {
88
+ finalValue = JSON.parse(finalValue);
89
+ } catch {}
90
+ else if (currentValue === void 0 && !(object && object?.[finalKey]) && rawValue.indexOf(",") !== -1) finalValue = splitRawParts(rawValue, flags);
91
+ if (currentValue === void 0) result[finalKey] = Array.isArray(finalValue) ? finalValue : [finalValue];
92
+ else if (Array.isArray(currentValue)) currentValue.push(finalValue);
93
+ else result[finalKey] = [currentValue, finalValue];
98
94
  }
99
- else result[finalKey] = finalValue;
95
+ } else if (object?.[finalKey] && finalValue.charCodeAt(0) === 123) try {
96
+ result[finalKey] = JSON.parse(finalValue);
97
+ } catch {
98
+ result[finalKey] = finalValue;
100
99
  }
100
+ else result[finalKey] = finalValue;
101
101
  }
102
- /**
103
- * @callback parse
104
- * @param {string} input
105
- */
106
102
  function parseQuery(input) {
107
103
  const result = Object.create(null);
108
104
  let flags = 0;
@@ -111,7 +107,7 @@ function parseQuery(input) {
111
107
  let equalityIndex = -1;
112
108
  for (let i = 0; i < inputLength; i++) switch (input.charCodeAt(i)) {
113
109
  case 38:
114
- processKeyValuePair(input, i);
110
+ processKeyValuePair(input, i, result, startingIndex, equalityIndex, flags);
115
111
  startingIndex = i;
116
112
  equalityIndex = i;
117
113
  flags = 0;
@@ -129,28 +125,28 @@ function parseQuery(input) {
129
125
  else flags |= KEY_NEEDS_DECODE;
130
126
  break;
131
127
  }
132
- if (startingIndex < inputLength) processKeyValuePair(input, inputLength);
128
+ if (startingIndex < inputLength) processKeyValuePair(input, inputLength, result, startingIndex, equalityIndex, flags);
133
129
  return result;
134
- function processKeyValuePair(input, endIndex) {
135
- const hasBothKeyValuePair = equalityIndex > startingIndex;
136
- const effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : endIndex;
137
- const keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
138
- if (!hasBothKeyValuePair && keySlice.length === 0) return;
139
- let finalKey = keySlice;
140
- if (flags & KEY_HAS_PLUS) finalKey = finalKey.replace(/\+/g, " ");
141
- if (flags & KEY_NEEDS_DECODE) finalKey = (0, deuri.default)(finalKey) || finalKey;
142
- let finalValue = "";
143
- if (hasBothKeyValuePair) {
144
- let valueSlice = input.slice(equalityIndex + 1, endIndex);
145
- if (flags & VALUE_HAS_PLUS) valueSlice = valueSlice.replace(/\+/g, " ");
146
- if (flags & VALUE_NEEDS_DECODE) valueSlice = (0, deuri.default)(valueSlice) || valueSlice;
147
- finalValue = valueSlice;
148
- }
149
- const currentValue = result[finalKey];
150
- if (currentValue === void 0) result[finalKey] = finalValue;
151
- else if (Array.isArray(currentValue)) currentValue.push(finalValue);
152
- else result[finalKey] = [currentValue, finalValue];
130
+ }
131
+ function processKeyValuePair(input, endIndex, result, startingIndex, equalityIndex, flags) {
132
+ const hasBothKeyValuePair = equalityIndex > startingIndex;
133
+ const effectiveEqualityIndex = hasBothKeyValuePair ? equalityIndex : endIndex;
134
+ const keySlice = input.slice(startingIndex + 1, effectiveEqualityIndex);
135
+ if (!hasBothKeyValuePair && keySlice.length === 0) return;
136
+ let finalKey = keySlice;
137
+ if (flags & KEY_HAS_PLUS) finalKey = finalKey.replace(/\+/g, " ");
138
+ if (flags & KEY_NEEDS_DECODE) finalKey = (0, deuri.default)(finalKey) || finalKey;
139
+ let finalValue = "";
140
+ if (hasBothKeyValuePair) {
141
+ let valueSlice = input.slice(equalityIndex + 1, endIndex);
142
+ if (flags & VALUE_HAS_PLUS) valueSlice = valueSlice.replace(/\+/g, " ");
143
+ if (flags & VALUE_NEEDS_DECODE) valueSlice = (0, deuri.default)(valueSlice) || valueSlice;
144
+ finalValue = valueSlice;
153
145
  }
146
+ const currentValue = result[finalKey];
147
+ if (currentValue === void 0) result[finalKey] = finalValue;
148
+ else if (Array.isArray(currentValue)) currentValue.push(finalValue);
149
+ else result[finalKey] = [currentValue, finalValue];
154
150
  }
155
151
 
156
152
  //#endregion