elysia 1.4.29 → 2.0.0-exp.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (344) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +45 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +36 -0
  3. package/dist/adapter/bun/index.d.ts +30 -6
  4. package/dist/adapter/bun/index.js +81 -381
  5. package/dist/adapter/bun/index.mjs +79 -383
  6. package/dist/adapter/bun/router.d.ts +10 -0
  7. package/dist/adapter/bun/router.js +86 -0
  8. package/dist/adapter/bun/router.mjs +83 -0
  9. package/dist/adapter/constants.d.ts +29 -0
  10. package/dist/adapter/constants.js +10 -0
  11. package/dist/adapter/constants.mjs +9 -0
  12. package/dist/adapter/index.d.ts +32 -1
  13. package/dist/adapter/index.js +25 -14
  14. package/dist/adapter/index.mjs +23 -0
  15. package/dist/adapter/types.d.ts +72 -122
  16. package/dist/adapter/types.js +1 -14
  17. package/dist/adapter/types.mjs +1 -0
  18. package/dist/adapter/utils.d.ts +45 -19
  19. package/dist/adapter/utils.js +364 -309
  20. package/dist/adapter/utils.mjs +354 -281
  21. package/dist/adapter/web-standard/handler.d.ts +11 -9
  22. package/dist/adapter/web-standard/handler.js +141 -415
  23. package/dist/adapter/web-standard/handler.mjs +138 -399
  24. package/dist/adapter/web-standard/index.d.ts +29 -2
  25. package/dist/adapter/web-standard/index.js +25 -164
  26. package/dist/adapter/web-standard/index.mjs +25 -149
  27. package/dist/adapter/web-standard/utils.d.ts +4 -0
  28. package/dist/adapter/web-standard/utils.js +146 -0
  29. package/dist/adapter/web-standard/utils.mjs +145 -0
  30. package/dist/base.d.ts +1075 -0
  31. package/dist/base.js +1019 -0
  32. package/dist/base.mjs +1016 -0
  33. package/dist/compile/aot.d.ts +169 -0
  34. package/dist/compile/aot.js +287 -0
  35. package/dist/compile/aot.mjs +275 -0
  36. package/dist/compile/handler/constants.d.ts +1 -0
  37. package/dist/compile/handler/constants.js +1 -0
  38. package/dist/compile/handler/constants.mjs +1 -0
  39. package/dist/compile/handler/index.d.ts +9 -0
  40. package/dist/compile/handler/index.js +605 -0
  41. package/dist/compile/handler/index.mjs +602 -0
  42. package/dist/compile/handler/params.d.ts +24 -0
  43. package/dist/compile/handler/params.js +57 -0
  44. package/dist/compile/handler/params.mjs +55 -0
  45. package/dist/compile/handler/utils.d.ts +29 -0
  46. package/dist/compile/handler/utils.js +442 -0
  47. package/dist/compile/handler/utils.mjs +431 -0
  48. package/dist/compile/index.d.ts +3 -0
  49. package/dist/compile/index.js +7 -0
  50. package/dist/compile/index.mjs +4 -0
  51. package/dist/compile/types.d.ts +4 -0
  52. package/dist/compile/types.js +1 -0
  53. package/dist/compile/types.mjs +1 -0
  54. package/dist/compile/utils.d.ts +7 -0
  55. package/dist/compile/utils.js +11 -0
  56. package/dist/compile/utils.mjs +8 -0
  57. package/dist/compiled.d.ts +17 -0
  58. package/dist/compiled.js +20 -0
  59. package/dist/compiled.mjs +16 -0
  60. package/dist/constants.d.ts +158 -0
  61. package/dist/constants.js +96 -0
  62. package/dist/constants.mjs +88 -0
  63. package/dist/context.d.ts +113 -126
  64. package/dist/context.js +77 -14
  65. package/dist/context.mjs +74 -0
  66. package/dist/cookie/config.d.ts +27 -0
  67. package/dist/cookie/config.js +100 -0
  68. package/dist/cookie/config.mjs +98 -0
  69. package/dist/cookie/cookie.d.ts +28 -0
  70. package/dist/cookie/cookie.js +88 -0
  71. package/dist/cookie/cookie.mjs +86 -0
  72. package/dist/cookie/index.d.ts +4 -0
  73. package/dist/cookie/index.js +10 -0
  74. package/dist/cookie/index.mjs +4 -0
  75. package/dist/cookie/lib.d.ts +7 -0
  76. package/dist/cookie/lib.js +74 -0
  77. package/dist/cookie/lib.mjs +72 -0
  78. package/dist/cookie/types.d.ts +115 -0
  79. package/dist/cookie/types.js +1 -0
  80. package/dist/cookie/types.mjs +1 -0
  81. package/dist/cookie/utils.d.ts +19 -0
  82. package/dist/cookie/utils.js +188 -0
  83. package/dist/cookie/utils.mjs +178 -0
  84. package/dist/error.d.ts +150 -190
  85. package/dist/error.js +283 -363
  86. package/dist/error.mjs +273 -332
  87. package/dist/handler/error.d.ts +7 -0
  88. package/dist/handler/error.js +74 -0
  89. package/dist/handler/error.mjs +73 -0
  90. package/dist/handler/fetch.d.ts +8 -0
  91. package/dist/handler/fetch.js +256 -0
  92. package/dist/handler/fetch.mjs +253 -0
  93. package/dist/handler/index.d.ts +4 -0
  94. package/dist/handler/index.js +9 -0
  95. package/dist/handler/index.mjs +5 -0
  96. package/dist/handler/utils.d.ts +6 -0
  97. package/dist/handler/utils.js +26 -0
  98. package/dist/handler/utils.mjs +23 -0
  99. package/dist/index.d.ts +16 -2198
  100. package/dist/index.js +54 -1947
  101. package/dist/index.mjs +17 -1986
  102. package/dist/memory.d.ts +4 -0
  103. package/dist/memory.js +17 -0
  104. package/dist/memory.mjs +16 -0
  105. package/dist/parse-query.d.ts +7 -9
  106. package/dist/parse-query.js +138 -165
  107. package/dist/parse-query.mjs +135 -134
  108. package/dist/plugin/bun.d.ts +24 -0
  109. package/dist/plugin/bun.js +49 -0
  110. package/dist/plugin/bun.mjs +48 -0
  111. package/dist/plugin/core.d.ts +35 -0
  112. package/dist/plugin/core.js +41 -0
  113. package/dist/plugin/core.mjs +36 -0
  114. package/dist/plugin/esbuild.d.ts +26 -0
  115. package/dist/plugin/esbuild.js +51 -0
  116. package/dist/plugin/esbuild.mjs +49 -0
  117. package/dist/plugin/source.d.ts +38 -0
  118. package/dist/plugin/source.js +235 -0
  119. package/dist/plugin/source.mjs +233 -0
  120. package/dist/plugin/vite.d.ts +29 -0
  121. package/dist/plugin/vite.js +43 -0
  122. package/dist/plugin/vite.mjs +42 -0
  123. package/dist/sucrose.d.ts +52 -59
  124. package/dist/sucrose.js +470 -307
  125. package/dist/sucrose.mjs +458 -275
  126. package/dist/trace.d.ts +172 -127
  127. package/dist/trace.js +274 -135
  128. package/dist/trace.mjs +272 -113
  129. package/dist/type/bridge.d.ts +50 -0
  130. package/dist/type/bridge.js +157 -0
  131. package/dist/type/bridge.mjs +63 -0
  132. package/dist/type/coerce.d.ts +43 -0
  133. package/dist/type/coerce.js +330 -0
  134. package/dist/type/coerce.mjs +321 -0
  135. package/dist/type/compat.d.ts +4 -0
  136. package/dist/type/compat.js +39 -0
  137. package/dist/type/compat.mjs +37 -0
  138. package/dist/type/constants.d.ts +25 -0
  139. package/dist/type/constants.js +36 -0
  140. package/dist/type/constants.mjs +32 -0
  141. package/dist/type/elysia/accelerate.d.ts +6 -0
  142. package/dist/type/elysia/accelerate.js +11 -0
  143. package/dist/type/elysia/accelerate.mjs +9 -0
  144. package/dist/type/elysia/array-buffer.d.ts +7 -0
  145. package/dist/type/elysia/array-buffer.js +21 -0
  146. package/dist/type/elysia/array-buffer.mjs +19 -0
  147. package/dist/type/elysia/array-string.d.ts +7 -0
  148. package/dist/type/elysia/array-string.js +28 -0
  149. package/dist/type/elysia/array-string.mjs +26 -0
  150. package/dist/type/elysia/array.d.ts +6 -0
  151. package/dist/type/elysia/array.js +26 -0
  152. package/dist/type/elysia/array.mjs +25 -0
  153. package/dist/type/elysia/boolean-string.d.ts +6 -0
  154. package/dist/type/elysia/boolean-string.js +24 -0
  155. package/dist/type/elysia/boolean-string.mjs +22 -0
  156. package/dist/type/elysia/boolean.d.ts +6 -0
  157. package/dist/type/elysia/boolean.js +17 -0
  158. package/dist/type/elysia/boolean.mjs +15 -0
  159. package/dist/type/elysia/cookie.d.ts +18 -0
  160. package/dist/type/elysia/cookie.js +54 -0
  161. package/dist/type/elysia/cookie.mjs +53 -0
  162. package/dist/type/elysia/date.d.ts +7 -0
  163. package/dist/type/elysia/date.js +60 -0
  164. package/dist/type/elysia/date.mjs +58 -0
  165. package/dist/type/elysia/file-type.d.ts +24 -0
  166. package/dist/type/elysia/file-type.js +83 -0
  167. package/dist/type/elysia/file-type.mjs +73 -0
  168. package/dist/type/elysia/file.d.ts +9 -0
  169. package/dist/type/elysia/file.js +58 -0
  170. package/dist/type/elysia/file.mjs +42 -0
  171. package/dist/type/elysia/files.d.ts +8 -0
  172. package/dist/type/elysia/files.js +35 -0
  173. package/dist/type/elysia/files.mjs +33 -0
  174. package/dist/type/elysia/form.d.ts +8 -0
  175. package/dist/type/elysia/form.js +17 -0
  176. package/dist/type/elysia/form.mjs +15 -0
  177. package/dist/type/elysia/integer-string.d.ts +7 -0
  178. package/dist/type/elysia/integer-string.js +37 -0
  179. package/dist/type/elysia/integer-string.mjs +35 -0
  180. package/dist/type/elysia/integer.d.ts +6 -0
  181. package/dist/type/elysia/integer.js +17 -0
  182. package/dist/type/elysia/integer.mjs +15 -0
  183. package/dist/type/elysia/intersect.d.ts +6 -0
  184. package/dist/type/elysia/intersect.js +17 -0
  185. package/dist/type/elysia/intersect.mjs +16 -0
  186. package/dist/type/elysia/maybe-empty.d.ts +6 -0
  187. package/dist/type/elysia/maybe-empty.js +19 -0
  188. package/dist/type/elysia/maybe-empty.mjs +17 -0
  189. package/dist/type/elysia/no-validate.d.ts +6 -0
  190. package/dist/type/elysia/no-validate.js +9 -0
  191. package/dist/type/elysia/no-validate.mjs +8 -0
  192. package/dist/type/elysia/nullable.d.ts +6 -0
  193. package/dist/type/elysia/nullable.js +12 -0
  194. package/dist/type/elysia/nullable.mjs +10 -0
  195. package/dist/type/elysia/number.d.ts +6 -0
  196. package/dist/type/elysia/number.js +17 -0
  197. package/dist/type/elysia/number.mjs +15 -0
  198. package/dist/type/elysia/numeric-enum.d.ts +11 -0
  199. package/dist/type/elysia/numeric-enum.js +25 -0
  200. package/dist/type/elysia/numeric-enum.mjs +23 -0
  201. package/dist/type/elysia/numeric.d.ts +7 -0
  202. package/dist/type/elysia/numeric.js +35 -0
  203. package/dist/type/elysia/numeric.mjs +33 -0
  204. package/dist/type/elysia/object-string.d.ts +7 -0
  205. package/dist/type/elysia/object-string.js +28 -0
  206. package/dist/type/elysia/object-string.mjs +26 -0
  207. package/dist/type/elysia/object.d.ts +6 -0
  208. package/dist/type/elysia/object.js +41 -0
  209. package/dist/type/elysia/object.mjs +40 -0
  210. package/dist/type/elysia/optional.d.ts +6 -0
  211. package/dist/type/elysia/optional.js +17 -0
  212. package/dist/type/elysia/optional.mjs +15 -0
  213. package/dist/type/elysia/string.d.ts +6 -0
  214. package/dist/type/elysia/string.js +27 -0
  215. package/dist/type/elysia/string.mjs +25 -0
  216. package/dist/type/elysia/uint8-array.d.ts +7 -0
  217. package/dist/type/elysia/uint8-array.js +21 -0
  218. package/dist/type/elysia/uint8-array.mjs +19 -0
  219. package/dist/type/elysia/union-enum.d.ts +7 -0
  220. package/dist/type/elysia/union-enum.js +30 -0
  221. package/dist/type/elysia/union-enum.mjs +28 -0
  222. package/dist/type/elysia/union.d.ts +6 -0
  223. package/dist/type/elysia/union.js +17 -0
  224. package/dist/type/elysia/union.mjs +16 -0
  225. package/dist/type/elysia/utils.d.ts +52 -0
  226. package/dist/type/elysia/utils.js +104 -0
  227. package/dist/type/elysia/utils.mjs +95 -0
  228. package/dist/type/exports.d.ts +36 -0
  229. package/dist/type/exports.js +103 -0
  230. package/dist/type/exports.mjs +66 -0
  231. package/dist/type/index.d.ts +9 -0
  232. package/dist/type/index.js +46 -0
  233. package/dist/type/index.mjs +31 -0
  234. package/dist/type/types.d.ts +194 -0
  235. package/dist/type/types.js +1 -0
  236. package/dist/type/types.mjs +1 -0
  237. package/dist/type/utils.d.ts +7 -0
  238. package/dist/type/utils.js +77 -0
  239. package/dist/type/utils.mjs +75 -0
  240. package/dist/type/validator.d.ts +44 -0
  241. package/dist/type/validator.js +603 -0
  242. package/dist/type/validator.mjs +599 -0
  243. package/dist/types.d.ts +835 -1238
  244. package/dist/types.js +1 -14
  245. package/dist/types.mjs +1 -0
  246. package/dist/universal/constants.d.ts +8 -0
  247. package/dist/universal/constants.js +23 -0
  248. package/dist/universal/constants.mjs +17 -0
  249. package/dist/universal/env.d.ts +4 -1
  250. package/dist/universal/env.js +8 -26
  251. package/dist/universal/env.mjs +7 -5
  252. package/dist/universal/file.d.ts +48 -86
  253. package/dist/universal/file.js +87 -158
  254. package/dist/universal/file.mjs +82 -133
  255. package/dist/universal/index.d.ts +4 -3
  256. package/dist/universal/index.js +6 -27
  257. package/dist/universal/index.mjs +3 -5
  258. package/dist/universal/server.d.ts +317 -313
  259. package/dist/universal/server.js +1 -14
  260. package/dist/universal/server.mjs +1 -0
  261. package/dist/universal/types.d.ts +117 -114
  262. package/dist/universal/types.js +19 -40
  263. package/dist/universal/types.mjs +16 -18
  264. package/dist/utils.d.ts +118 -193
  265. package/dist/utils.js +442 -692
  266. package/dist/utils.mjs +408 -629
  267. package/dist/validator/index.d.ts +62 -0
  268. package/dist/validator/index.js +203 -0
  269. package/dist/validator/index.mjs +200 -0
  270. package/dist/validator/route.d.ts +33 -0
  271. package/dist/validator/route.js +49 -0
  272. package/dist/validator/route.mjs +48 -0
  273. package/dist/ws/context.d.ts +48 -0
  274. package/dist/ws/context.js +189 -0
  275. package/dist/ws/context.mjs +187 -0
  276. package/dist/ws/index.d.ts +5 -77
  277. package/dist/ws/index.js +11 -180
  278. package/dist/ws/index.mjs +5 -157
  279. package/dist/ws/parser.d.ts +8 -0
  280. package/dist/ws/parser.js +64 -0
  281. package/dist/ws/parser.mjs +61 -0
  282. package/dist/ws/route.d.ts +11 -0
  283. package/dist/ws/route.js +335 -0
  284. package/dist/ws/route.mjs +333 -0
  285. package/dist/ws/types.d.ts +112 -57
  286. package/dist/ws/types.js +1 -14
  287. package/dist/ws/types.mjs +1 -0
  288. package/package.json +108 -111
  289. package/bunfig.toml +0 -2
  290. package/dist/adapter/bun/compose.d.ts +0 -3
  291. package/dist/adapter/bun/compose.js +0 -90
  292. package/dist/adapter/bun/compose.mjs +0 -74
  293. package/dist/adapter/bun/handler-native.d.ts +0 -3
  294. package/dist/adapter/bun/handler-native.js +0 -42
  295. package/dist/adapter/bun/handler-native.mjs +0 -22
  296. package/dist/adapter/bun/handler.d.ts +0 -7
  297. package/dist/adapter/bun/handler.js +0 -363
  298. package/dist/adapter/bun/handler.mjs +0 -346
  299. package/dist/adapter/cloudflare-worker/index.d.ts +0 -20
  300. package/dist/adapter/cloudflare-worker/index.js +0 -59
  301. package/dist/adapter/cloudflare-worker/index.mjs +0 -39
  302. package/dist/compose.d.ts +0 -30
  303. package/dist/compose.js +0 -1324
  304. package/dist/compose.mjs +0 -1336
  305. package/dist/cookies.d.ts +0 -158
  306. package/dist/cookies.js +0 -250
  307. package/dist/cookies.mjs +0 -221
  308. package/dist/dynamic-handle.d.ts +0 -15
  309. package/dist/dynamic-handle.js +0 -533
  310. package/dist/dynamic-handle.mjs +0 -521
  311. package/dist/formats.d.ts +0 -79
  312. package/dist/formats.js +0 -153
  313. package/dist/formats.mjs +0 -132
  314. package/dist/manifest.d.ts +0 -0
  315. package/dist/manifest.js +0 -1
  316. package/dist/manifest.mjs +0 -0
  317. package/dist/replace-schema.d.ts +0 -60
  318. package/dist/replace-schema.js +0 -140
  319. package/dist/replace-schema.mjs +0 -115
  320. package/dist/schema.d.ts +0 -107
  321. package/dist/schema.js +0 -833
  322. package/dist/schema.mjs +0 -814
  323. package/dist/type-system/format.d.ts +0 -55
  324. package/dist/type-system/format.js +0 -197
  325. package/dist/type-system/format.mjs +0 -175
  326. package/dist/type-system/index.d.ts +0 -45
  327. package/dist/type-system/index.js +0 -406
  328. package/dist/type-system/index.mjs +0 -394
  329. package/dist/type-system/types.d.ts +0 -155
  330. package/dist/type-system/types.js +0 -14
  331. package/dist/type-system/types.mjs +0 -0
  332. package/dist/type-system/utils.d.ts +0 -62
  333. package/dist/type-system/utils.js +0 -141
  334. package/dist/type-system/utils.mjs +0 -111
  335. package/dist/universal/request.d.ts +0 -29
  336. package/dist/universal/request.js +0 -126
  337. package/dist/universal/request.mjs +0 -105
  338. package/dist/universal/utils.d.ts +0 -3
  339. package/dist/universal/utils.js +0 -41
  340. package/dist/universal/utils.mjs +0 -18
  341. package/dist/ws/bun.d.ts +0 -419
  342. package/dist/ws/bun.js +0 -14
  343. package/dist/ws/bun.mjs +0 -0
  344. package/knip.json +0 -22
@@ -0,0 +1,45 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __exportAll = (all, no_symbols) => {
9
+ let target = {};
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ }
16
+ if (!no_symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
32
+ }
33
+ return to;
34
+ };
35
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
37
+ value: mod,
38
+ enumerable: true
39
+ }) : target, mod));
40
+
41
+ //#endregion
42
+
43
+ exports.__exportAll = __exportAll;
44
+ exports.__reExport = __reExport;
45
+ exports.__toESM = __toESM;
@@ -0,0 +1,36 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __exportAll = (all, no_symbols) => {
7
+ let target = {};
8
+ for (var name in all) {
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
13
+ }
14
+ if (!no_symbols) {
15
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ }
17
+ return target;
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
22
+ key = keys[i];
23
+ if (!__hasOwnProp.call(to, key) && key !== except) {
24
+ __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ }
30
+ }
31
+ return to;
32
+ };
33
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
34
+
35
+ //#endregion
36
+ export { __exportAll, __reExport };
@@ -1,6 +1,30 @@
1
- import type { ElysiaAdapter } from '../types';
2
- export declare const isHTMLBundle: (handle: any) => boolean;
3
- type Routes = Record<string, Function | Response | Record<string, unknown>>;
4
- export declare const removeTrailingPath: (routes: Routes) => Routes;
5
- export declare const BunAdapter: ElysiaAdapter;
6
- export {};
1
+ import { ListenCallback, Serve } from "../../universal/server.js";
2
+ import { AnyLocalHook, MaybePromise } from "../../types.js";
3
+ import { Context } from "../../context.js";
4
+ import { AnyElysia } from "../../base.js";
5
+ //#region src/adapter/bun/index.d.ts
6
+ declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
7
+ declare const BunAdapter: {
8
+ parse: {
9
+ default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
10
+ json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
11
+ text: (context: Context) => MaybePromise<string>;
12
+ urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
13
+ arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
14
+ formData: (context: Context) => MaybePromise<Record<string, unknown>>;
15
+ };
16
+ name: string;
17
+ runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
18
+ isWebStandard: boolean;
19
+ listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
20
+ stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
21
+ response: {
22
+ map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
23
+ compact?(response: unknown, ...params: unknown[]): unknown;
24
+ static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
25
+ nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
26
+ };
27
+ fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
28
+ };
29
+ //#endregion
30
+ export { BunAdapter, collectStaticRoutes };
@@ -1,382 +1,82 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
- var bun_exports = {};
17
- __export(bun_exports, {
18
- BunAdapter: () => BunAdapter,
19
- isHTMLBundle: () => isHTMLBundle,
20
- removeTrailingPath: () => removeTrailingPath
21
- });
22
- module.exports = __toCommonJS(bun_exports);
23
- var import_web_standard = require('../web-standard/index.js'), import_utils = require('../utils.js'), import_compose = require('./compose.js'), import_handler_native = require('./handler-native.js'), import_cookies = require('../../cookies.js'), import_error = require('../../error.js'), import_schema = require('../../schema.js'), import_utils2 = require('../../utils.js'), import_handler = require('./handler.js'), import_ws = require('../../ws/index.js');
24
- const optionalParam = /:.+?\?(?=\/|$)/, getPossibleParams = (path) => {
25
- const match = optionalParam.exec(path);
26
- if (!match) return [path];
27
- const routes = [], head = path.slice(0, match.index), param = match[0].slice(0, -1), tail = path.slice(match.index + match[0].length);
28
- routes.push(head.slice(0, -1)), routes.push(head + param);
29
- for (const fragment of getPossibleParams(tail))
30
- fragment && (fragment.startsWith("/:") || routes.push(head.slice(0, -1) + fragment), routes.push(head + param + fragment));
31
- return routes;
32
- }, isHTMLBundle = (handle) => typeof handle == "object" && handle !== null && (handle.toString() === "[object HTMLBundle]" || typeof handle.index == "string"), supportedMethods = {
33
- GET: !0,
34
- HEAD: !0,
35
- OPTIONS: !0,
36
- DELETE: !0,
37
- PATCH: !0,
38
- POST: !0,
39
- PUT: !0
40
- }, mapRoutes = (app) => {
41
- if (!app.config.aot || app.config.systemRouter === !1) return;
42
- const routes = {}, add = (route, handler) => {
43
- const path = encodeURI(route.path);
44
- routes[path] ? routes[path][route.method] || (routes[path][route.method] = handler) : routes[path] = {
45
- [route.method]: handler
46
- };
47
- }, tree = app.routeTree;
48
- for (const route of app.router.history) {
49
- if (typeof route.handler != "function") continue;
50
- const method = route.method;
51
- if (method === "GET" && `WS_${route.path}` in tree || method === "WS" || route.path.charCodeAt(route.path.length - 1) === 42 || !(method in supportedMethods))
52
- continue;
53
- if (method === "ALL") {
54
- `WS_${route.path}` in tree || (routes[route.path] = route.hooks?.config?.mount ? route.hooks.trace || app.event.trace || // @ts-expect-error private property
55
- app.extender.higherOrderFunctions ? (0, import_compose.createBunRouteHandler)(app, route) : route.hooks.mount || route.handler : route.handler);
56
- continue;
57
- }
58
- let compiled;
59
- const handler = app.config.precompile ? (0, import_compose.createBunRouteHandler)(app, route) : (request) => compiled ? compiled(request) : (compiled = (0, import_compose.createBunRouteHandler)(app, route))(
60
- request
61
- );
62
- for (const path of getPossibleParams(route.path))
63
- add(
64
- {
65
- method,
66
- path
67
- },
68
- handler
69
- );
70
- }
71
- return routes;
72
- }, mergeRoutes = (r1, r2) => {
73
- if (!r2) return r1;
74
- for (const key of Object.keys(r2))
75
- if (r1[key] !== r2[key]) {
76
- if (!r1[key]) {
77
- r1[key] = r2[key];
78
- continue;
79
- }
80
- if (r1[key] && r2[key]) {
81
- if (typeof r1[key] == "function" || r1[key] instanceof Response) {
82
- r1[key] = r2[key];
83
- continue;
84
- }
85
- r1[key] = {
86
- ...r1[key],
87
- ...r2[key]
88
- };
89
- }
90
- }
91
- return r1;
92
- }, removeTrailingPath = (routes) => {
93
- for (const key of Object.keys(routes))
94
- key.length > 1 && key.charCodeAt(key.length - 1) === 47 && (routes[key.slice(0, -1)] = routes[key], delete routes[key]);
95
- return routes;
96
- }, BunAdapter = {
97
- ...import_web_standard.WebStandardAdapter,
98
- name: "bun",
99
- handler: {
100
- mapResponse: import_handler.mapResponse,
101
- mapEarlyResponse: import_handler.mapEarlyResponse,
102
- mapCompactResponse: import_handler.mapCompactResponse,
103
- createStaticHandler: import_handler.createStaticHandler,
104
- createNativeStaticHandler: import_handler_native.createNativeStaticHandler
105
- },
106
- composeHandler: {
107
- ...import_web_standard.WebStandardAdapter.composeHandler,
108
- headers: import_utils2.hasHeaderShorthand ? `c.headers=c.request.headers.toJSON()
109
- ` : `c.headers={}
110
- for(const [k,v] of c.request.headers.entries())c.headers[k]=v
111
- `
112
- },
113
- listen(app) {
114
- return (options, callback) => {
115
- if (typeof Bun > "u")
116
- throw new Error(
117
- ".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch"
118
- );
119
- if (app.compile(), typeof options == "string") {
120
- if (!(0, import_utils2.isNumericString)(options))
121
- throw new Error("Port must be a numeric value");
122
- options = parseInt(options);
123
- }
124
- const createStaticRoute = (iterator, { withAsync = !1 } = {}) => {
125
- const staticRoutes = {}, ops = [];
126
- for (let [path, route] of Object.entries(iterator))
127
- if (path = encodeURI(path), import_utils2.supportPerMethodInlineHandler) {
128
- if (!route) continue;
129
- for (const [method, value] of Object.entries(route))
130
- if (!(!value || !(method in supportedMethods))) {
131
- if (value instanceof Promise) {
132
- withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
133
- value.then((awaited) => {
134
- awaited instanceof Response && (staticRoutes[path][method] = awaited), isHTMLBundle(awaited) && (staticRoutes[path][method] = awaited);
135
- })
136
- ));
137
- continue;
138
- }
139
- !(value instanceof Response) && !isHTMLBundle(value) || (staticRoutes[path] || (staticRoutes[path] = {}), staticRoutes[path][method] = value);
140
- }
141
- } else {
142
- if (!route) continue;
143
- if (route instanceof Promise) {
144
- withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
145
- route.then((awaited) => {
146
- awaited instanceof Response && (staticRoutes[path] = awaited);
147
- })
148
- ));
149
- continue;
150
- }
151
- if (!(route instanceof Response)) continue;
152
- staticRoutes[path] = route;
153
- }
154
- return withAsync ? Promise.all(ops).then(() => staticRoutes) : staticRoutes;
155
- }, routes = removeTrailingPath(
156
- mergeRoutes(
157
- mergeRoutes(
158
- createStaticRoute(app.router.response),
159
- mapRoutes(app)
160
- ),
161
- // @ts-ignore
162
- app.config.serve?.routes
163
- )
164
- ), serve = typeof options == "object" ? {
165
- development: !import_error.isProduction,
166
- reusePort: !0,
167
- idleTimeout: 30,
168
- ...app.config.serve || {},
169
- ...options || {},
170
- routes,
171
- websocket: {
172
- ...app.config.websocket || {},
173
- ...import_ws.websocket || {},
174
- ...options.websocket || {}
175
- },
176
- fetch: app.fetch
177
- } : {
178
- development: !import_error.isProduction,
179
- reusePort: !0,
180
- idleTimeout: 30,
181
- ...app.config.serve || {},
182
- routes,
183
- websocket: {
184
- ...app.config.websocket || {},
185
- ...import_ws.websocket || {}
186
- },
187
- port: options,
188
- fetch: app.fetch
189
- };
190
- if (app.server = Bun.serve(serve), app.event.start)
191
- for (let i = 0; i < app.event.start.length; i++)
192
- app.event.start[i].fn(app);
193
- callback && callback(app.server), process.on("beforeExit", async () => {
194
- if (app.server && (await app.server.stop?.(), app.server = null, app.event.stop))
195
- for (let i = 0; i < app.event.stop.length; i++)
196
- app.event.stop[i].fn(app);
197
- }), app.promisedModules.then(async () => {
198
- app.config.aot, app.compile();
199
- const routes2 = removeTrailingPath(
200
- mergeRoutes(
201
- mergeRoutes(
202
- await createStaticRoute(app.router.response, {
203
- withAsync: !0
204
- }),
205
- mapRoutes(app)
206
- ),
207
- // @ts-ignore
208
- app.config.serve?.routes
209
- )
210
- );
211
- app.server?.reload({
212
- ...serve,
213
- fetch: app.fetch,
214
- // @ts-ignore
215
- routes: routes2
216
- }), Bun?.gc(!1);
217
- });
218
- };
219
- },
220
- async stop(app, closeActiveConnections) {
221
- if (app.server) {
222
- if (await app.server.stop(closeActiveConnections), app.server = null, app.event.stop?.length)
223
- for (let i = 0; i < app.event.stop.length; i++)
224
- app.event.stop[i].fn(app);
225
- } else
226
- console.log(
227
- "Elysia isn't running. Call `app.listen` to start the server.",
228
- new Error().stack
229
- );
230
- },
231
- ws(app, path, options) {
232
- const { parse, body, response, ...rest } = options, messageValidator = (0, import_schema.getSchemaValidator)(body, {
233
- // @ts-expect-error private property
234
- modules: app.definitions.typebox,
235
- // @ts-expect-error private property
236
- models: app.definitions.type,
237
- normalize: app.config.normalize
238
- }), validateMessage = messageValidator ? messageValidator.provider === "standard" ? (data) => messageValidator.schema["~standard"].validate(data).issues : (data) => messageValidator.Check(data) === !1 : void 0, responseValidator = (0, import_schema.getSchemaValidator)(response, {
239
- // @ts-expect-error private property
240
- modules: app.definitions.typebox,
241
- // @ts-expect-error private property
242
- models: app.definitions.type,
243
- normalize: app.config.normalize
244
- });
245
- app.route(
246
- "WS",
247
- path,
248
- async (context) => {
249
- const server = context.server ?? app.server, { set, path: path2, qi, headers, query, params } = context;
250
- if (context.validator = responseValidator, options.upgrade)
251
- if (typeof options.upgrade == "function") {
252
- const temp = options.upgrade(context);
253
- temp instanceof Promise && await temp;
254
- } else options.upgrade && Object.assign(
255
- set.headers,
256
- options.upgrade
257
- );
258
- if (set.cookie && (0, import_utils2.isNotEmpty)(set.cookie)) {
259
- const cookie = (0, import_cookies.serializeCookie)(set.cookie);
260
- cookie && (set.headers["set-cookie"] = cookie);
261
- }
262
- set.headers["set-cookie"] && Array.isArray(set.headers["set-cookie"]) && (set.headers = (0, import_utils.parseSetCookies)(
263
- new Headers(set.headers),
264
- set.headers["set-cookie"]
265
- ));
266
- const handleResponse = (0, import_ws.createHandleWSResponse)(responseValidator), parseMessage = (0, import_ws.createWSMessageParser)(parse);
267
- let _id;
268
- if (typeof options.beforeHandle == "function") {
269
- const result = options.beforeHandle(context);
270
- result instanceof Promise && await result;
271
- }
272
- const errorHandlers = [
273
- ...options.error ? Array.isArray(options.error) ? options.error : [options.error] : [],
274
- ...(app.event.error ?? []).map(
275
- (x) => typeof x == "function" ? x : x.fn
276
- )
277
- ].filter((x) => x), hasCustomErrorHandlers = errorHandlers.length > 0, handleErrors = hasCustomErrorHandlers ? async (ws, error) => {
278
- for (const handleError of errorHandlers) {
279
- let response2 = handleError(
280
- Object.assign(context, { error })
281
- );
282
- if (response2 instanceof Promise && (response2 = await response2), await handleResponse(ws, response2), response2) break;
283
- }
284
- } : () => {
285
- };
286
- if (!server?.upgrade(context.request, {
287
- headers: (0, import_utils2.isNotEmpty)(set.headers) ? set.headers : void 0,
288
- data: {
289
- ...context,
290
- get id() {
291
- return _id || (_id = (0, import_utils2.randomId)());
292
- },
293
- validator: responseValidator,
294
- ping(ws, data) {
295
- options.ping?.(ws, data);
296
- },
297
- pong(ws, data) {
298
- options.pong?.(ws, data);
299
- },
300
- open: async (ws) => {
301
- try {
302
- await handleResponse(
303
- ws,
304
- options.open?.(
305
- new import_ws.ElysiaWS(ws, context)
306
- )
307
- );
308
- } catch (error) {
309
- handleErrors(ws, error);
310
- }
311
- },
312
- message: async (ws, _message) => {
313
- const message = await parseMessage(ws, _message);
314
- if (validateMessage && validateMessage(message)) {
315
- const validationError = new import_error.ValidationError(
316
- "message",
317
- messageValidator,
318
- message
319
- );
320
- return hasCustomErrorHandlers ? handleErrors(ws, validationError) : void ws.send(
321
- validationError.message
322
- );
323
- }
324
- try {
325
- await handleResponse(
326
- ws,
327
- options.message?.(
328
- new import_ws.ElysiaWS(
329
- ws,
330
- context,
331
- message
332
- ),
333
- message
334
- )
335
- );
336
- } catch (error) {
337
- handleErrors(ws, error);
338
- }
339
- },
340
- drain: async (ws) => {
341
- try {
342
- await handleResponse(
343
- ws,
344
- options.drain?.(
345
- new import_ws.ElysiaWS(ws, context)
346
- )
347
- );
348
- } catch (error) {
349
- handleErrors(ws, error);
350
- }
351
- },
352
- close: async (ws, code, reason) => {
353
- try {
354
- await handleResponse(
355
- ws,
356
- options.close?.(
357
- new import_ws.ElysiaWS(ws, context),
358
- code,
359
- reason
360
- )
361
- );
362
- } catch (error) {
363
- handleErrors(ws, error);
364
- }
365
- }
366
- }
367
- }))
368
- return (0, import_error.status)(400, "Expected a websocket connection");
369
- },
370
- {
371
- ...rest,
372
- websocket: options
373
- }
374
- );
375
- }
376
- };
377
- // Annotate the CommonJS export names for ESM import in node:
378
- 0 && (module.exports = {
379
- BunAdapter,
380
- isHTMLBundle,
381
- removeTrailingPath
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_adapter_index = require('../index.js');
3
+ const require_utils = require('../../utils.js');
4
+ const require_adapter_web_standard_index = require('../web-standard/index.js');
5
+ const require_memory = require('../../memory.js');
6
+ const require_ws_route = require('../../ws/route.js');
7
+
8
+ //#region src/adapter/bun/index.ts
9
+ function collectStaticRoutes(app) {
10
+ if (app["~ext"]?.hoc?.length) return;
11
+ const hook = require_utils.flattenChain(app["~hookChain"]);
12
+ if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
13
+ app.fetch;
14
+ const source = app["~staticResponse"];
15
+ if (!source) return;
16
+ const ready = require_utils.nullObject();
17
+ const pending = [];
18
+ for (const rawPath in source) {
19
+ const path = encodeURI(rawPath);
20
+ const methods = source[rawPath];
21
+ for (const method in methods) {
22
+ const value = methods[method];
23
+ if (value instanceof Promise) pending.push(value.then((resolved) => {
24
+ if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
25
+ }, (err) => {
26
+ console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
27
+ }));
28
+ else (ready[path] ??= require_utils.nullObject())[method] = value;
29
+ }
30
+ }
31
+ return [ready, pending];
32
+ }
33
+ const BunAdapter = require_adapter_index.createAdapter({
34
+ ...require_adapter_web_standard_index.WebStandardAdapter,
35
+ name: "bun",
36
+ runtime: "bun",
37
+ listen(app, options, callback) {
38
+ const serve = typeof options === "object" ? options : { port: +options };
39
+ const hasWs = app["~hasWS"];
40
+ serve.fetch = (request, server) => app.fetch(request, server);
41
+ app.server = Bun.serve(serve);
42
+ if (!hasWs) callback?.(app.server);
43
+ queueMicrotask(() => {
44
+ if (!app.pending) serve.fetch = app.fetch;
45
+ const buildWebSocket = () => {
46
+ const defaultConfig = app["~config"]?.websocket;
47
+ serve.websocket = defaultConfig ? Object.assign(require_ws_route.buildGlobalWSHandler(), defaultConfig) : require_ws_route.buildGlobalWSHandler();
48
+ };
49
+ if (hasWs) buildWebSocket();
50
+ const collectRoutes = () => {
51
+ const staticRoutes = collectStaticRoutes(app);
52
+ if (!staticRoutes) return;
53
+ if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
54
+ serve.routes = staticRoutes[0];
55
+ app.server.reload(serve);
56
+ });
57
+ if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
58
+ };
59
+ if (app.pending) {
60
+ if (app.server) app.server.reload(serve);
61
+ else app.server = Bun.serve(serve);
62
+ const reloadAfterModules = () => {
63
+ serve.fetch = app.fetch;
64
+ if (hasWs || app["~hasWS"]) buildWebSocket();
65
+ collectRoutes();
66
+ app.server.reload(serve);
67
+ };
68
+ app.modules.then(reloadAfterModules, reloadAfterModules);
69
+ } else {
70
+ collectRoutes();
71
+ if (app.server) app.server.reload(serve);
72
+ else app.server = Bun.serve(serve);
73
+ }
74
+ require_memory.flushMemory();
75
+ if (hasWs) callback?.(app.server);
76
+ });
77
+ }
382
78
  });
79
+
80
+ //#endregion
81
+ exports.BunAdapter = BunAdapter;
82
+ exports.collectStaticRoutes = collectStaticRoutes;