elysia 2.0.0-beta.20 → 2.0.0-beta.22

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 (227) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  2. package/dist/adapter/bun/index.d.ts +6 -8
  3. package/dist/adapter/bun/index.js +6 -8
  4. package/dist/adapter/bun/index.mjs +7 -8
  5. package/dist/adapter/constants.mjs +1 -0
  6. package/dist/adapter/default-headers.mjs +1 -0
  7. package/dist/adapter/index.mjs +1 -0
  8. package/dist/adapter/origin.mjs +1 -0
  9. package/dist/adapter/response-ownership.mjs +1 -0
  10. package/dist/adapter/skip-clone.mjs +1 -0
  11. package/dist/adapter/types.mjs +1 -0
  12. package/dist/adapter/utils.d.ts +5 -8
  13. package/dist/adapter/utils.js +24 -18
  14. package/dist/adapter/utils.mjs +25 -18
  15. package/dist/adapter/web-standard/handler.mjs +2 -1
  16. package/dist/adapter/web-standard/index.mjs +1 -0
  17. package/dist/adapter/web-standard/utils.mjs +1 -0
  18. package/dist/base.d.ts +118 -69
  19. package/dist/base.js +213 -193
  20. package/dist/base.mjs +220 -199
  21. package/dist/compile/aot-capture.js +2 -2
  22. package/dist/compile/aot-capture.mjs +4 -3
  23. package/dist/compile/aot-emit.js +7 -8
  24. package/dist/compile/aot-emit.mjs +8 -8
  25. package/dist/compile/aot-reconstruct.mjs +3 -2
  26. package/dist/compile/aot.d.ts +8 -8
  27. package/dist/compile/aot.js +16 -14
  28. package/dist/compile/aot.mjs +15 -14
  29. package/dist/compile/handler/descriptor.d.ts +2 -5
  30. package/dist/compile/handler/descriptor.js +13 -19
  31. package/dist/compile/handler/descriptor.mjs +16 -22
  32. package/dist/compile/handler/frozen-validator.d.ts +2 -2
  33. package/dist/compile/handler/frozen-validator.js +3 -3
  34. package/dist/compile/handler/frozen-validator.mjs +4 -3
  35. package/dist/compile/handler/index.d.ts +4 -1
  36. package/dist/compile/handler/index.js +219 -140
  37. package/dist/compile/handler/index.mjs +222 -145
  38. package/dist/compile/handler/jit.d.ts +14 -12
  39. package/dist/compile/handler/jit.js +63 -45
  40. package/dist/compile/handler/jit.mjs +66 -49
  41. package/dist/compile/handler/params.d.ts +5 -1
  42. package/dist/compile/handler/params.js +14 -5
  43. package/dist/compile/handler/params.mjs +16 -7
  44. package/dist/compile/handler/reconstruct.d.ts +2 -2
  45. package/dist/compile/handler/reconstruct.js +5 -4
  46. package/dist/compile/handler/reconstruct.mjs +6 -4
  47. package/dist/compile/handler/static-clone-resolver.mjs +1 -0
  48. package/dist/compile/handler/utils.d.ts +13 -7
  49. package/dist/compile/handler/utils.js +75 -52
  50. package/dist/compile/handler/utils.mjs +77 -54
  51. package/dist/compile/jit-probe.mjs +1 -0
  52. package/dist/compile/lexer.js +4 -4
  53. package/dist/compile/lexer.mjs +5 -4
  54. package/dist/compile/utils.d.ts +2 -1
  55. package/dist/compile/utils.js +8 -3
  56. package/dist/compile/utils.mjs +8 -3
  57. package/dist/compiled.mjs +1 -0
  58. package/dist/constants.mjs +1 -0
  59. package/dist/context.d.ts +1 -1
  60. package/dist/context.js +1 -0
  61. package/dist/context.mjs +3 -1
  62. package/dist/cookie/config.d.ts +6 -2
  63. package/dist/cookie/config.js +72 -17
  64. package/dist/cookie/config.mjs +74 -19
  65. package/dist/cookie/cookie.mjs +1 -0
  66. package/dist/cookie/crypto.mjs +1 -0
  67. package/dist/cookie/error.mjs +1 -0
  68. package/dist/cookie/lib.mjs +1 -0
  69. package/dist/cookie/serialize.mjs +1 -0
  70. package/dist/cookie/types.mjs +1 -0
  71. package/dist/cookie/utils.d.ts +1 -1
  72. package/dist/cookie/utils.js +64 -45
  73. package/dist/cookie/utils.mjs +66 -46
  74. package/dist/error.d.ts +10 -6
  75. package/dist/error.js +22 -6
  76. package/dist/error.mjs +25 -9
  77. package/dist/generation.mjs +1 -0
  78. package/dist/handler/error.d.ts +12 -15
  79. package/dist/handler/error.js +43 -40
  80. package/dist/handler/error.mjs +45 -41
  81. package/dist/handler/fetch.js +59 -21
  82. package/dist/handler/fetch.mjs +61 -22
  83. package/dist/handler/utils.d.ts +16 -3
  84. package/dist/handler/utils.js +14 -13
  85. package/dist/handler/utils.mjs +16 -15
  86. package/dist/index.d.ts +9 -9
  87. package/dist/index.js +1 -0
  88. package/dist/index.mjs +3 -2
  89. package/dist/memory.mjs +1 -0
  90. package/dist/package.js +1 -1
  91. package/dist/package.mjs +2 -1
  92. package/dist/parse-query.js +76 -76
  93. package/dist/parse-query.mjs +77 -76
  94. package/dist/plugin/aot/bun.mjs +1 -0
  95. package/dist/plugin/aot/core.d.ts +5 -0
  96. package/dist/plugin/aot/core.js +43 -4
  97. package/dist/plugin/aot/core.mjs +44 -5
  98. package/dist/plugin/aot/esbuild.mjs +1 -0
  99. package/dist/plugin/aot/rspack-loader.mjs +1 -0
  100. package/dist/plugin/aot/rspack.mjs +1 -0
  101. package/dist/plugin/aot/source.js +24 -9
  102. package/dist/plugin/aot/source.mjs +24 -9
  103. package/dist/plugin/aot/treeshake.mjs +1 -0
  104. package/dist/plugin/aot/unplugin.mjs +4 -3
  105. package/dist/plugin/aot/vite.mjs +1 -0
  106. package/dist/plugin/aot/worker.mjs +1 -0
  107. package/dist/plugin/auto-head.mjs +1 -0
  108. package/dist/plugin/trace.mjs +1 -0
  109. package/dist/plugin/websocket.mjs +1 -0
  110. package/dist/route-table.mjs +1 -0
  111. package/dist/schema-snapshot.js +4 -3
  112. package/dist/schema-snapshot.mjs +5 -3
  113. package/dist/sucrose.d.ts +2 -2
  114. package/dist/sucrose.js +11 -11
  115. package/dist/sucrose.mjs +12 -11
  116. package/dist/trace.js +8 -10
  117. package/dist/trace.mjs +10 -11
  118. package/dist/type/bridge-live.d.ts +1 -1
  119. package/dist/type/bridge-live.mjs +1 -0
  120. package/dist/type/bridge.d.ts +1 -1
  121. package/dist/type/bridge.mjs +1 -0
  122. package/dist/type/coerce-plan.mjs +1 -0
  123. package/dist/type/coerce.mjs +1 -0
  124. package/dist/type/compat.mjs +1 -0
  125. package/dist/type/constants.d.ts +1 -1
  126. package/dist/type/constants.mjs +1 -0
  127. package/dist/type/elysia/accelerate.mjs +1 -0
  128. package/dist/type/elysia/array-buffer.d.ts +3 -2
  129. package/dist/type/elysia/array-buffer.js +5 -5
  130. package/dist/type/elysia/array-buffer.mjs +6 -5
  131. package/dist/type/elysia/array-string.mjs +1 -0
  132. package/dist/type/elysia/array.mjs +1 -0
  133. package/dist/type/elysia/boolean-string.mjs +1 -0
  134. package/dist/type/elysia/boolean.mjs +1 -0
  135. package/dist/type/elysia/cookie.mjs +1 -0
  136. package/dist/type/elysia/date.mjs +1 -0
  137. package/dist/type/elysia/file-type.mjs +1 -0
  138. package/dist/type/elysia/file.mjs +1 -0
  139. package/dist/type/elysia/files.mjs +1 -0
  140. package/dist/type/elysia/form.mjs +1 -0
  141. package/dist/type/elysia/integer-string.mjs +1 -0
  142. package/dist/type/elysia/integer.mjs +1 -0
  143. package/dist/type/elysia/intersect.mjs +1 -0
  144. package/dist/type/elysia/json-string.mjs +1 -0
  145. package/dist/type/elysia/keep-config.d.ts +14 -0
  146. package/dist/type/elysia/keep-config.js +62 -0
  147. package/dist/type/elysia/keep-config.mjs +54 -0
  148. package/dist/type/elysia/maybe-empty.mjs +1 -0
  149. package/dist/type/elysia/no-validate.mjs +1 -0
  150. package/dist/type/elysia/nullable.mjs +1 -0
  151. package/dist/type/elysia/number.mjs +1 -0
  152. package/dist/type/elysia/numeric-enum.d.ts +4 -2
  153. package/dist/type/elysia/numeric-enum.mjs +1 -0
  154. package/dist/type/elysia/numeric.mjs +1 -0
  155. package/dist/type/elysia/object-string.mjs +1 -0
  156. package/dist/type/elysia/object.mjs +1 -0
  157. package/dist/type/elysia/optional.mjs +1 -0
  158. package/dist/type/elysia/problem.mjs +1 -0
  159. package/dist/type/elysia/string.mjs +1 -0
  160. package/dist/type/elysia/uint8-array.d.ts +2 -1
  161. package/dist/type/elysia/uint8-array.js +2 -2
  162. package/dist/type/elysia/uint8-array.mjs +3 -2
  163. package/dist/type/elysia/union-enum.mjs +1 -0
  164. package/dist/type/elysia/union.mjs +1 -0
  165. package/dist/type/elysia/utils.js +3 -3
  166. package/dist/type/elysia/utils.mjs +4 -3
  167. package/dist/type/exports.d.ts +3 -2
  168. package/dist/type/exports.js +10 -0
  169. package/dist/type/exports.mjs +3 -1
  170. package/dist/type/index.js +10 -0
  171. package/dist/type/index.mjs +12 -1
  172. package/dist/type/shared.mjs +1 -0
  173. package/dist/type/sync-require.mjs +1 -0
  174. package/dist/type/typebox-system-lite.mjs +1 -0
  175. package/dist/type/typebox-system-require.mjs +1 -0
  176. package/dist/type/typebox-type-live.d.ts +2 -2
  177. package/dist/type/typebox-type-live.js +8 -0
  178. package/dist/type/typebox-type-live.mjs +3 -2
  179. package/dist/type/typebox-type.d.ts +10 -2
  180. package/dist/type/typebox-type.js +64 -0
  181. package/dist/type/typebox-type.mjs +17 -1
  182. package/dist/type/typebox-value-live.mjs +1 -0
  183. package/dist/type/typebox-value-ops.mjs +1 -0
  184. package/dist/type/typebox-value.mjs +1 -0
  185. package/dist/type/types.d.ts +1 -1
  186. package/dist/type/types.mjs +1 -0
  187. package/dist/type/utils.mjs +1 -0
  188. package/dist/type/validator/clean-safe.mjs +1 -0
  189. package/dist/type/validator/custom-error.js +41 -33
  190. package/dist/type/validator/custom-error.mjs +42 -33
  191. package/dist/type/validator/default-precompute.d.ts +2 -2
  192. package/dist/type/validator/default-precompute.js +10 -11
  193. package/dist/type/validator/default-precompute.mjs +13 -13
  194. package/dist/type/validator/exact-mirror.mjs +1 -0
  195. package/dist/type/validator/frozen-check.js +7 -7
  196. package/dist/type/validator/frozen-check.mjs +8 -7
  197. package/dist/type/validator/index.d.ts +2 -2
  198. package/dist/type/validator/index.js +4 -8
  199. package/dist/type/validator/index.mjs +5 -8
  200. package/dist/type/validator/string-codec-aot.d.ts +1 -1
  201. package/dist/type/validator/string-codec-aot.mjs +1 -0
  202. package/dist/type/validator/validator-cache.js +18 -18
  203. package/dist/type/validator/validator-cache.mjs +19 -18
  204. package/dist/types.d.ts +108 -71
  205. package/dist/types.mjs +1 -0
  206. package/dist/universal/constants.mjs +1 -0
  207. package/dist/universal/file.mjs +1 -0
  208. package/dist/universal/index.mjs +1 -0
  209. package/dist/universal/is-production.mjs +1 -0
  210. package/dist/universal/server.mjs +1 -0
  211. package/dist/utils.d.ts +50 -30
  212. package/dist/utils.js +243 -108
  213. package/dist/utils.mjs +235 -105
  214. package/dist/validator/index.d.ts +3 -3
  215. package/dist/validator/index.js +4 -4
  216. package/dist/validator/index.mjs +5 -4
  217. package/dist/validator/route.d.ts +2 -2
  218. package/dist/validator/route.mjs +1 -0
  219. package/dist/ws/context.js +1 -1
  220. package/dist/ws/context.mjs +2 -1
  221. package/dist/ws/index.mjs +1 -0
  222. package/dist/ws/parser.mjs +1 -0
  223. package/dist/ws/route.js +64 -27
  224. package/dist/ws/route.mjs +70 -32
  225. package/dist/ws/types.d.ts +2 -3
  226. package/dist/ws/types.mjs +1 -0
  227. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { createRequire } from "node:module";
2
3
 
3
4
  //#region \0rolldown/runtime.js
@@ -7,14 +7,12 @@ type NativeRoutes = Record<string, Record<string, unknown>>;
7
7
  /**
8
8
  * HTML bundles served by Bun's native router.
9
9
  *
10
- * A `:param` / `*` bundle (SPA fallback) matches before `fetch`, so with a
11
- * `handoff` every other route of that method is registered natively too,
12
- * handing off to `fetch`: Bun's specificity (exact > param > wildcard) then
13
- * picks the Elysia route, and only unmatched paths reach the bundle (Elysia's
14
- * own router leaves these bundles out, see `#buildRouterUnsafe`).
15
- *
16
- * All or nothing: when any route cannot be expressed in Bun's router, dynamic
17
- * bundles are not served natively at all, since that route would be shadowed.
10
+ * A `:param` / `*` bundle matches before `fetch`, so with a `handoff` every
11
+ * other route of that method is registered natively too, pointing at `fetch`;
12
+ * Bun's specificity (exact > param > wildcard) then picks the Elysia route over
13
+ * the bundle (Elysia's own router skips these bundles, see `#buildRouterUnsafe`).
14
+ * If any route can't be expressed in Bun's router, dynamic bundles are skipped
15
+ * entirely, since the bundle would shadow that route.
18
16
  */
19
17
  declare function collectHTMLBundleRoutes(app: AnyElysia, handoff?: (request: Request, server: unknown) => unknown, routes?: NativeRoutes): NativeRoutes | undefined;
20
18
  declare function collectStaticRoutes(app: AnyElysia): Record<string, Record<string, Response | BunHTMLBundlelike>> | undefined;
@@ -95,14 +95,12 @@ function isNativePath(path) {
95
95
  /**
96
96
  * HTML bundles served by Bun's native router.
97
97
  *
98
- * A `:param` / `*` bundle (SPA fallback) matches before `fetch`, so with a
99
- * `handoff` every other route of that method is registered natively too,
100
- * handing off to `fetch`: Bun's specificity (exact > param > wildcard) then
101
- * picks the Elysia route, and only unmatched paths reach the bundle (Elysia's
102
- * own router leaves these bundles out, see `#buildRouterUnsafe`).
103
- *
104
- * All or nothing: when any route cannot be expressed in Bun's router, dynamic
105
- * bundles are not served natively at all, since that route would be shadowed.
98
+ * A `:param` / `*` bundle matches before `fetch`, so with a `handoff` every
99
+ * other route of that method is registered natively too, pointing at `fetch`;
100
+ * Bun's specificity (exact > param > wildcard) then picks the Elysia route over
101
+ * the bundle (Elysia's own router skips these bundles, see `#buildRouterUnsafe`).
102
+ * If any route can't be expressed in Bun's router, dynamic bundles are skipped
103
+ * entirely, since the bundle would shadow that route.
106
104
  */
107
105
  function collectHTMLBundleRoutes(app, handoff, routes) {
108
106
  let dynamic;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { createAdapter } from "../index.mjs";
2
3
  import { flattenChain, getLoosePath, isHTMLBundle, isSocketQuiet, nullObject, throwLifecycleErrors } from "../../utils.mjs";
3
4
  import { preloadTypebox } from "../../type/bridge.mjs";
@@ -94,14 +95,12 @@ function isNativePath(path) {
94
95
  /**
95
96
  * HTML bundles served by Bun's native router.
96
97
  *
97
- * A `:param` / `*` bundle (SPA fallback) matches before `fetch`, so with a
98
- * `handoff` every other route of that method is registered natively too,
99
- * handing off to `fetch`: Bun's specificity (exact > param > wildcard) then
100
- * picks the Elysia route, and only unmatched paths reach the bundle (Elysia's
101
- * own router leaves these bundles out, see `#buildRouterUnsafe`).
102
- *
103
- * All or nothing: when any route cannot be expressed in Bun's router, dynamic
104
- * bundles are not served natively at all, since that route would be shadowed.
98
+ * A `:param` / `*` bundle matches before `fetch`, so with a `handoff` every
99
+ * other route of that method is registered natively too, pointing at `fetch`;
100
+ * Bun's specificity (exact > param > wildcard) then picks the Elysia route over
101
+ * the bundle (Elysia's own router skips these bundles, see `#buildRouterUnsafe`).
102
+ * If any route can't be expressed in Bun's router, dynamic bundles are skipped
103
+ * entirely, since the bundle would shadow that route.
105
104
  */
106
105
  function collectHTMLBundleRoutes(app, handoff, routes) {
107
106
  let dynamic;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { isBun } from "../universal/constants.mjs";
2
3
  import { WebStandardAdapter } from "./web-standard/index.mjs";
3
4
  import { BunAdapter } from "./bun/index.mjs";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/adapter/default-headers.ts
2
3
  const defaultHeaders = "\0";
3
4
 
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/adapter/index.ts
2
3
  const createAdapter = (adapter) => adapter;
3
4
 
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/adapter/origin.ts
2
3
  /**
3
4
  * Provenance channel for deferred abort-signal arming.
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/adapter/response-ownership.ts
2
3
  const borrowedResponses = /* @__PURE__ */ new WeakSet();
3
4
  function borrow(response) {
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/adapter/skip-clone.ts
2
3
  const skipClone = /* @__PURE__ */ new WeakSet();
3
4
 
@@ -1 +1,2 @@
1
+ // @bun
1
2
  export { };
@@ -1,5 +1,5 @@
1
- import { BaseCookie } from "../cookie/types.js";
2
1
  import { StatusMap } from "../constants.js";
2
+ import { BaseCookie } from "../cookie/types.js";
3
3
  import { Context } from "../context.js";
4
4
  import { ElysiaFile } from "../universal/file.js";
5
5
  import { HTTPHeaders } from "../types.js";
@@ -29,13 +29,10 @@ declare function streamResponse(response: Response): AsyncGenerator<any, void, a
29
29
  declare function handleSet(set: Context['set']): void;
30
30
  declare function createResponseHandler(handler: CreateHandlerParameter): (response: Response, set?: Context["set"], request?: Request, owned?: boolean) => any;
31
31
  /**
32
- * A returned `ReadableStream` is consumed after the handler returns, so
33
- * afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
34
- * generator is waited on
35
- *
36
- * A returned `Response` is not observed, reading `.body` would move
37
- * every Response on these routes off Bun's native send path; a `bytes()`
38
- * stream keeps its exact-stream contract and releases early as before
32
+ * Tee a returned `ReadableStream` so afterResponse, `defer()` and derive
33
+ * dispose wait for it, as for a tee'd generator. A `bytes()` stream is left
34
+ * alone (exact-stream contract), and so is a `Response`: reading its `.body`
35
+ * would move it off Bun's native send path
39
36
  */
40
37
  declare function observeStream(source: ReadableStream): [ReadableStream, AsyncIterable<unknown>, AsyncIterableIterator<unknown>] | undefined;
41
38
  /**
@@ -132,8 +132,17 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
132
132
  const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
133
133
  const sourceIterator = typeof generator.next === "function" ? generator : void 0;
134
134
  let init = typedSSE ? void 0 : generator.next?.();
135
- if (set) handleSet(set);
136
135
  if (init instanceof Promise) init = await init;
136
+ const sign = set?.["~sign"];
137
+ if (sign) try {
138
+ await sign(set);
139
+ } catch (error) {
140
+ try {
141
+ await generator.return?.(void 0);
142
+ } catch {}
143
+ throw error;
144
+ }
145
+ if (set) handleSet(set);
137
146
  const yieldedStream = init?.value instanceof ReadableStream;
138
147
  if (yieldedStream) generator = init.value;
139
148
  else if (init && (typeof init?.done === "undefined" || init?.done)) {
@@ -224,21 +233,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
224
233
  controller.enqueue(textEncoder.encode(value.toSSE()));
225
234
  return;
226
235
  }
227
- let p;
228
- if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
236
+ if (value instanceof Blob) return value.arrayBuffer().then((buffer) => {
229
237
  controller.enqueue(new Uint8Array(buffer));
230
238
  });
231
- else if (value instanceof Uint8Array) {
239
+ if (value instanceof Uint8Array) {
232
240
  controller.enqueue(value);
233
- p = true;
234
- } else if (value instanceof ArrayBuffer) {
241
+ return;
242
+ }
243
+ if (value instanceof ArrayBuffer) {
235
244
  controller.enqueue(new Uint8Array(value));
236
- p = true;
237
- } else if (ArrayBuffer.isView(value)) {
245
+ return;
246
+ }
247
+ if (ArrayBuffer.isView(value)) {
238
248
  controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
239
- p = true;
240
- } else p = false;
241
- if (p !== false) return p === true ? void 0 : p;
249
+ return;
250
+ }
242
251
  if (typeof value === "object") try {
243
252
  controller.enqueue(textEncoder.encode(format(JSON.stringify(value))));
244
253
  } catch {
@@ -422,13 +431,10 @@ const doneResult = {
422
431
  value: void 0
423
432
  };
424
433
  /**
425
- * A returned `ReadableStream` is consumed after the handler returns, so
426
- * afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
427
- * generator is waited on
428
- *
429
- * A returned `Response` is not observed, reading `.body` would move
430
- * every Response on these routes off Bun's native send path; a `bytes()`
431
- * stream keeps its exact-stream contract and releases early as before
434
+ * Tee a returned `ReadableStream` so afterResponse, `defer()` and derive
435
+ * dispose wait for it, as for a tee'd generator. A `bytes()` stream is left
436
+ * alone (exact-stream contract), and so is a `Response`: reading its `.body`
437
+ * would move it off Bun's native send path
432
438
  */
433
439
  function observeStream(source) {
434
440
  if (source.locked || require_utils.isByteStream(source)) return;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { hasHeaderShorthand } from "../universal/constants.mjs";
2
3
  import { StatusMap } from "../constants.mjs";
3
4
  import { isByteStream, isNotEmpty, nullObject, sseData } from "../utils.mjs";
@@ -131,8 +132,17 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
131
132
  const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
132
133
  const sourceIterator = typeof generator.next === "function" ? generator : void 0;
133
134
  let init = typedSSE ? void 0 : generator.next?.();
134
- if (set) handleSet(set);
135
135
  if (init instanceof Promise) init = await init;
136
+ const sign = set?.["~sign"];
137
+ if (sign) try {
138
+ await sign(set);
139
+ } catch (error) {
140
+ try {
141
+ await generator.return?.(void 0);
142
+ } catch {}
143
+ throw error;
144
+ }
145
+ if (set) handleSet(set);
136
146
  const yieldedStream = init?.value instanceof ReadableStream;
137
147
  if (yieldedStream) generator = init.value;
138
148
  else if (init && (typeof init?.done === "undefined" || init?.done)) {
@@ -223,21 +233,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
223
233
  controller.enqueue(textEncoder.encode(value.toSSE()));
224
234
  return;
225
235
  }
226
- let p;
227
- if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
236
+ if (value instanceof Blob) return value.arrayBuffer().then((buffer) => {
228
237
  controller.enqueue(new Uint8Array(buffer));
229
238
  });
230
- else if (value instanceof Uint8Array) {
239
+ if (value instanceof Uint8Array) {
231
240
  controller.enqueue(value);
232
- p = true;
233
- } else if (value instanceof ArrayBuffer) {
241
+ return;
242
+ }
243
+ if (value instanceof ArrayBuffer) {
234
244
  controller.enqueue(new Uint8Array(value));
235
- p = true;
236
- } else if (ArrayBuffer.isView(value)) {
245
+ return;
246
+ }
247
+ if (ArrayBuffer.isView(value)) {
237
248
  controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
238
- p = true;
239
- } else p = false;
240
- if (p !== false) return p === true ? void 0 : p;
249
+ return;
250
+ }
241
251
  if (typeof value === "object") try {
242
252
  controller.enqueue(textEncoder.encode(format(JSON.stringify(value))));
243
253
  } catch {
@@ -421,13 +431,10 @@ const doneResult = {
421
431
  value: void 0
422
432
  };
423
433
  /**
424
- * A returned `ReadableStream` is consumed after the handler returns, so
425
- * afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
426
- * generator is waited on
427
- *
428
- * A returned `Response` is not observed, reading `.body` would move
429
- * every Response on these routes off Bun's native send path; a `bytes()`
430
- * stream keeps its exact-stream contract and releases early as before
434
+ * Tee a returned `ReadableStream` so afterResponse, `defer()` and derive
435
+ * dispose wait for it, as for a tee'd generator. A `bytes()` stream is left
436
+ * alone (exact-stream contract), and so is a `Response`: reading its `.body`
437
+ * would move it off Bun's native send path
431
438
  */
432
439
  function observeStream(source) {
433
440
  if (source.locked || isByteStream(source)) return;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { isBun } from "../../universal/constants.mjs";
2
3
  import { ElysiaFile } from "../../universal/file.mjs";
3
4
  import { formToFormData, isElysiaForm, isNotEmpty, nullObject } from "../../utils.mjs";
@@ -69,7 +70,7 @@ const checkRemovedSetRedirect = !isProduction();
69
70
  function mapResponse(response, set, request, owned) {
70
71
  if (checkRemovedSetRedirect && Object.hasOwn(set, "redirect") && !isProduction()) {
71
72
  delete set.redirect;
72
- throw new Error("[Elysia] set.redirect was removed in 2.0 — return redirect(url) instead");
73
+ throw new Error("[Elysia] set.redirect was removed in 2.0 \u2014 return redirect(url) instead");
73
74
  }
74
75
  const headers = set.headers;
75
76
  if (set.status !== void 0 || set.cookie || headers["\0"] === headers || isNotEmpty(headers)) return mapResponseWithSet(response, set, request, owned);
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { createAdapter } from "../index.mjs";
2
3
  import { mapCompactResponse, mapResponse } from "./handler.mjs";
3
4
  import { formDataToObject } from "./utils.mjs";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { dangerousKeys } from "../../constants.mjs";
2
3
  import { nullObject } from "../../utils.mjs";
3
4