elysia 2.0.0-exp.25 → 2.0.0-exp.27

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 (210) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +0 -16
  2. package/dist/_virtual/_rolldown/runtime.mjs +2 -0
  3. package/dist/adapter/bun/index.js +58 -19
  4. package/dist/adapter/bun/index.mjs +60 -21
  5. package/dist/adapter/transferable.d.ts +4 -0
  6. package/dist/adapter/transferable.js +7 -0
  7. package/dist/adapter/transferable.mjs +5 -0
  8. package/dist/adapter/utils.d.ts +10 -7
  9. package/dist/adapter/utils.js +213 -86
  10. package/dist/adapter/utils.mjs +213 -87
  11. package/dist/adapter/web-standard/handler.js +26 -17
  12. package/dist/adapter/web-standard/handler.mjs +26 -17
  13. package/dist/adapter/web-standard/index.js +27 -5
  14. package/dist/adapter/web-standard/index.mjs +27 -5
  15. package/dist/adapter/web-standard/utils.js +1 -0
  16. package/dist/adapter/web-standard/utils.mjs +1 -0
  17. package/dist/base.d.ts +90 -286
  18. package/dist/base.js +267 -122
  19. package/dist/base.mjs +269 -124
  20. package/dist/compile/aot.d.ts +14 -1
  21. package/dist/compile/aot.js +18 -3
  22. package/dist/compile/aot.mjs +17 -3
  23. package/dist/compile/handler/frozen-validator.d.ts +41 -0
  24. package/dist/compile/handler/frozen-validator.js +221 -0
  25. package/dist/compile/handler/frozen-validator.mjs +218 -0
  26. package/dist/compile/handler/index.d.ts +13 -4
  27. package/dist/compile/handler/index.js +112 -30
  28. package/dist/compile/handler/index.mjs +110 -32
  29. package/dist/compile/handler/jit.d.ts +0 -1
  30. package/dist/compile/handler/jit.js +89 -60
  31. package/dist/compile/handler/jit.mjs +92 -63
  32. package/dist/compile/handler/params.js +8 -2
  33. package/dist/compile/handler/params.mjs +9 -3
  34. package/dist/compile/handler/reconstruct.d.ts +1 -2
  35. package/dist/compile/handler/reconstruct.js +19 -11
  36. package/dist/compile/handler/reconstruct.mjs +19 -11
  37. package/dist/compile/handler/utils.d.ts +6 -8
  38. package/dist/compile/handler/utils.js +27 -27
  39. package/dist/compile/handler/utils.mjs +28 -27
  40. package/dist/compile/index.d.ts +2 -2
  41. package/dist/compile/index.js +3 -1
  42. package/dist/compile/index.mjs +2 -2
  43. package/dist/compile/jit-probe.d.ts +0 -2
  44. package/dist/compile/jit-probe.js +3 -11
  45. package/dist/compile/jit-probe.mjs +3 -11
  46. package/dist/compile/utils.js +2 -2
  47. package/dist/compile/utils.mjs +2 -2
  48. package/dist/constants.d.ts +4 -1
  49. package/dist/constants.js +19 -5
  50. package/dist/constants.mjs +17 -5
  51. package/dist/context.d.ts +1 -1
  52. package/dist/context.js +1 -1
  53. package/dist/context.mjs +1 -1
  54. package/dist/cookie/config.js +5 -5
  55. package/dist/cookie/config.mjs +5 -5
  56. package/dist/cookie/cookie.d.ts +2 -4
  57. package/dist/cookie/cookie.js +37 -23
  58. package/dist/cookie/cookie.mjs +37 -23
  59. package/dist/cookie/error.d.ts +17 -0
  60. package/dist/cookie/error.js +25 -0
  61. package/dist/cookie/error.mjs +24 -0
  62. package/dist/cookie/index.d.ts +2 -1
  63. package/dist/cookie/index.js +2 -0
  64. package/dist/cookie/index.mjs +2 -1
  65. package/dist/cookie/lib.js +12 -2
  66. package/dist/cookie/lib.mjs +12 -2
  67. package/dist/cookie/serialize.js +5 -1
  68. package/dist/cookie/serialize.mjs +5 -1
  69. package/dist/cookie/types.d.ts +1 -3
  70. package/dist/cookie/utils.d.ts +12 -1
  71. package/dist/cookie/utils.js +128 -18
  72. package/dist/cookie/utils.mjs +122 -18
  73. package/dist/error.d.ts +74 -16
  74. package/dist/error.js +263 -88
  75. package/dist/error.mjs +257 -88
  76. package/dist/handler/error.js +35 -4
  77. package/dist/handler/error.mjs +36 -5
  78. package/dist/handler/fetch.js +98 -70
  79. package/dist/handler/fetch.mjs +99 -71
  80. package/dist/handler/utils.d.ts +1 -1
  81. package/dist/handler/utils.js +8 -2
  82. package/dist/handler/utils.mjs +8 -2
  83. package/dist/index.d.ts +7 -6
  84. package/dist/index.js +4 -2
  85. package/dist/index.mjs +4 -3
  86. package/dist/memory.js +1 -1
  87. package/dist/memory.mjs +1 -1
  88. package/dist/parse-query.js +37 -22
  89. package/dist/parse-query.mjs +37 -22
  90. package/dist/plugin/bun.d.ts +0 -8
  91. package/dist/plugin/bun.js +10 -60
  92. package/dist/plugin/bun.mjs +11 -60
  93. package/dist/plugin/core.d.ts +130 -4
  94. package/dist/plugin/core.js +352 -19
  95. package/dist/plugin/core.mjs +347 -20
  96. package/dist/plugin/esbuild.d.ts +0 -8
  97. package/dist/plugin/esbuild.js +10 -57
  98. package/dist/plugin/esbuild.mjs +11 -58
  99. package/dist/plugin/source.d.ts +7 -9
  100. package/dist/plugin/source.js +10 -23
  101. package/dist/plugin/source.mjs +10 -23
  102. package/dist/plugin/treeshake.js +64 -16
  103. package/dist/plugin/treeshake.mjs +64 -16
  104. package/dist/plugin/vite.d.ts +2 -8
  105. package/dist/plugin/vite.js +37 -12
  106. package/dist/plugin/vite.mjs +37 -13
  107. package/dist/sucrose.js +84 -44
  108. package/dist/sucrose.mjs +84 -44
  109. package/dist/trace.d.ts +22 -56
  110. package/dist/trace.js +257 -141
  111. package/dist/trace.mjs +256 -141
  112. package/dist/type/bridge-live.d.ts +14 -0
  113. package/dist/type/bridge-live.js +34 -0
  114. package/dist/type/bridge-live.mjs +16 -0
  115. package/dist/type/bridge.d.ts +9 -7
  116. package/dist/type/bridge.js +8 -0
  117. package/dist/type/bridge.mjs +3 -1
  118. package/dist/type/coerce.d.ts +1 -1
  119. package/dist/type/coerce.js +14 -9
  120. package/dist/type/coerce.mjs +14 -9
  121. package/dist/type/compat.js +3 -2
  122. package/dist/type/compat.mjs +4 -3
  123. package/dist/type/elysia/array-buffer.d.ts +1 -2
  124. package/dist/type/elysia/array-buffer.js +7 -1
  125. package/dist/type/elysia/array-buffer.mjs +8 -2
  126. package/dist/type/elysia/array.js +7 -4
  127. package/dist/type/elysia/array.mjs +7 -4
  128. package/dist/type/elysia/boolean.js +6 -3
  129. package/dist/type/elysia/boolean.mjs +6 -3
  130. package/dist/type/elysia/date.js +38 -7
  131. package/dist/type/elysia/date.mjs +39 -8
  132. package/dist/type/elysia/file-type.d.ts +1 -1
  133. package/dist/type/elysia/file-type.js +5 -11
  134. package/dist/type/elysia/file-type.mjs +5 -11
  135. package/dist/type/elysia/file.js +7 -1
  136. package/dist/type/elysia/file.mjs +8 -2
  137. package/dist/type/elysia/files.js +13 -3
  138. package/dist/type/elysia/files.mjs +15 -5
  139. package/dist/type/elysia/integer.js +6 -3
  140. package/dist/type/elysia/integer.mjs +6 -3
  141. package/dist/type/elysia/intersect.js +6 -3
  142. package/dist/type/elysia/intersect.mjs +6 -3
  143. package/dist/type/elysia/maybe-empty.js +4 -2
  144. package/dist/type/elysia/maybe-empty.mjs +5 -3
  145. package/dist/type/elysia/nullable.js +4 -1
  146. package/dist/type/elysia/nullable.mjs +5 -2
  147. package/dist/type/elysia/number.js +6 -3
  148. package/dist/type/elysia/number.mjs +6 -3
  149. package/dist/type/elysia/numeric.js +1 -1
  150. package/dist/type/elysia/numeric.mjs +1 -1
  151. package/dist/type/elysia/object.js +8 -5
  152. package/dist/type/elysia/object.mjs +8 -5
  153. package/dist/type/elysia/optional.js +11 -13
  154. package/dist/type/elysia/optional.mjs +12 -13
  155. package/dist/type/elysia/string.js +6 -3
  156. package/dist/type/elysia/string.mjs +6 -3
  157. package/dist/type/elysia/uint8-array.d.ts +1 -2
  158. package/dist/type/elysia/uint8-array.js +7 -1
  159. package/dist/type/elysia/uint8-array.mjs +8 -2
  160. package/dist/type/elysia/union-enum.js +3 -2
  161. package/dist/type/elysia/union-enum.mjs +4 -3
  162. package/dist/type/elysia/union.js +6 -3
  163. package/dist/type/elysia/union.mjs +6 -3
  164. package/dist/type/elysia/utils.d.ts +2 -1
  165. package/dist/type/elysia/utils.js +11 -24
  166. package/dist/type/elysia/utils.mjs +11 -25
  167. package/dist/type/exports.js +0 -37
  168. package/dist/type/exports.mjs +1 -33
  169. package/dist/type/index.js +60 -2
  170. package/dist/type/index.mjs +59 -2
  171. package/dist/type/types.d.ts +1 -1
  172. package/dist/type/utils.js +0 -18
  173. package/dist/type/utils.mjs +0 -18
  174. package/dist/type/validator/default-precompute.js +23 -7
  175. package/dist/type/validator/default-precompute.mjs +23 -7
  176. package/dist/type/validator/index.d.ts +2 -2
  177. package/dist/type/validator/index.js +61 -8
  178. package/dist/type/validator/index.mjs +61 -8
  179. package/dist/type/validator/string-codec-aot.js +1 -1
  180. package/dist/type/validator/string-codec-aot.mjs +1 -1
  181. package/dist/type/validator/validator-cache.d.ts +2 -2
  182. package/dist/type/validator/validator-cache.js +32 -12
  183. package/dist/type/validator/validator-cache.mjs +32 -12
  184. package/dist/types.d.ts +55 -22
  185. package/dist/universal/file.d.ts +3 -0
  186. package/dist/universal/file.js +9 -2
  187. package/dist/universal/file.mjs +9 -2
  188. package/dist/universal/server.d.ts +1 -0
  189. package/dist/utils.d.ts +11 -4
  190. package/dist/utils.js +86 -11
  191. package/dist/utils.mjs +81 -12
  192. package/dist/validator/index.d.ts +8 -7
  193. package/dist/validator/index.js +91 -46
  194. package/dist/validator/index.mjs +92 -47
  195. package/dist/validator/route.js +1 -1
  196. package/dist/validator/route.mjs +1 -1
  197. package/dist/ws/context.d.ts +1 -0
  198. package/dist/ws/context.js +12 -25
  199. package/dist/ws/context.mjs +12 -25
  200. package/dist/ws/parser.d.ts +1 -4
  201. package/dist/ws/route.d.ts +5 -2
  202. package/dist/ws/route.js +159 -60
  203. package/dist/ws/route.mjs +159 -62
  204. package/package.json +4 -2
  205. package/dist/adapter/bun/router.d.ts +0 -10
  206. package/dist/adapter/bun/router.js +0 -86
  207. package/dist/adapter/bun/router.mjs +0 -83
  208. package/dist/compile/handler/constants.d.ts +0 -1
  209. package/dist/compile/handler/constants.js +0 -1
  210. package/dist/compile/handler/constants.mjs +0 -1
@@ -5,19 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
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
8
  var __copyProps = (to, from, except, desc) => {
22
9
  if (from && typeof from === "object" || typeof from === "function") {
23
10
  for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
@@ -32,7 +19,6 @@ var __copyProps = (to, from, except, desc) => {
32
19
  }
33
20
  return to;
34
21
  };
35
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
36
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
37
23
  value: mod,
38
24
  enumerable: true
@@ -40,6 +26,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
26
 
41
27
  //#endregion
42
28
 
43
- exports.__exportAll = __exportAll;
44
- exports.__reExport = __reExport;
45
29
  exports.__toESM = __toESM;
@@ -1,3 +1,5 @@
1
+ import { createRequire } from "node:module";
2
+
1
3
  //#region \0rolldown/runtime.js
2
4
  var __defProp = Object.defineProperty;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -3,29 +3,67 @@ const require_adapter_index = require('../index.js');
3
3
  const require_constants = require('../../constants.js');
4
4
  const require_utils = require('../../utils.js');
5
5
  const require_adapter_web_standard_index = require('../web-standard/index.js');
6
+ const require_compile_handler_index = require('../../compile/handler/index.js');
6
7
  const require_memory = require('../../memory.js');
7
8
  const require_ws_route = require('../../ws/route.js');
8
9
 
9
10
  //#region src/adapter/bun/index.ts
10
11
  function collectStaticRoutes(app) {
12
+ if (app["~config"]?.nativeStaticResponse === false) return;
11
13
  app.fetch;
12
- const source = app["~staticResponse"];
13
- if (!source) return;
14
+ const fetchLevelHook = require_utils.flattenChain(app["~hookChain"]);
15
+ if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || app["~ext"]?.hoc?.length) return;
16
+ const history = app.history;
17
+ if (!history?.length) return;
14
18
  const ready = require_utils.nullObject();
15
19
  const pending = [];
16
- for (const method in source) {
17
- const paths = source[method];
18
- for (let path in paths) {
19
- const value = paths[path];
20
- if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
21
- if (value instanceof Promise) pending.push(value.then((resolved) => {
22
- if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
23
- }, (err) => {
24
- console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
25
- }));
26
- else (ready[path] ??= require_utils.nullObject())[method] = value;
20
+ const strictPath = app["~config"]?.strictPath === true;
21
+ const seen = /* @__PURE__ */ new Map();
22
+ for (let i = 0; i < history.length; i++) {
23
+ const route = history[i];
24
+ const method = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
25
+ seen.set(method + " " + route[1], i);
26
+ }
27
+ let explicitPaths;
28
+ if (!strictPath) {
29
+ explicitPaths = /* @__PURE__ */ new Map();
30
+ for (let i = 0; i < history.length; i++) {
31
+ const route = history[i];
32
+ const method = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
33
+ const path = route[1];
34
+ let set = explicitPaths.get(method);
35
+ if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
36
+ set.add(path);
37
+ if (require_constants.needEncodeRegex.test(path)) {
38
+ const encoded = encodeURI(path);
39
+ if (encoded !== path) set.add(encoded);
40
+ }
41
+ }
42
+ }
43
+ const add = (method, path, value) => {
44
+ if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
45
+ if (value instanceof Promise) pending.push(value.then((resolved) => {
46
+ if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
47
+ }, (err) => {
48
+ console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
49
+ }));
50
+ else (ready[path] ??= require_utils.nullObject())[method] = value;
51
+ };
52
+ for (let i = 0; i < history.length; i++) {
53
+ const route = history[i];
54
+ if (route[0] === "WS") continue;
55
+ const method = require_utils.mapMethodBack(route[0]);
56
+ const path = route[1];
57
+ if (seen.get(method + " " + path) !== i) continue;
58
+ const value = require_compile_handler_index.buildNativeStaticResponse(route, app);
59
+ if (!value) continue;
60
+ add(method, path, value);
61
+ if (!strictPath && !require_constants.isDynamicRegex.test(path)) {
62
+ const loose = require_utils.getLoosePath(path);
63
+ if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
27
64
  }
28
65
  }
66
+ if (!Object.keys(ready).length && !pending.length) return;
29
67
  return [ready, pending];
30
68
  }
31
69
  const BunAdapter = require_adapter_index.createAdapter({
@@ -37,7 +75,7 @@ const BunAdapter = require_adapter_index.createAdapter({
37
75
  listen(app, options, callback) {
38
76
  const _config = app["~config"]?.serve;
39
77
  const optionsIsObject = typeof options === "object";
40
- const _options = optionsIsObject ? options : {
78
+ const _options = optionsIsObject ? { ...options } : {
41
79
  port: +options,
42
80
  fetch: (request, server) => app.fetch(request, server)
43
81
  };
@@ -46,12 +84,13 @@ const BunAdapter = require_adapter_index.createAdapter({
46
84
  ..._config,
47
85
  ..._options
48
86
  } : _options;
49
- app.server = Bun.serve(serve);
87
+ const server = app.server = Bun.serve(serve);
50
88
  const onSetup = app["~ext"]?.setup;
51
89
  if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
52
90
  const hasWs = app["~hasWS"];
53
91
  if (!hasWs) callback?.(app.server);
54
92
  queueMicrotask(() => {
93
+ if (app.server !== server) return;
55
94
  if (!app.pending) serve.fetch = app.fetch;
56
95
  const buildWebSocket = () => {
57
96
  const defaultConfig = app["~config"]?.websocket;
@@ -62,15 +101,16 @@ const BunAdapter = require_adapter_index.createAdapter({
62
101
  const staticRoutes = collectStaticRoutes(app);
63
102
  if (!staticRoutes) return;
64
103
  if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
104
+ if (app.server !== server) return;
65
105
  serve.routes = staticRoutes[0];
66
106
  app.server.reload(serve);
67
107
  });
68
108
  if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
69
109
  };
70
110
  if (app.pending) {
71
- if (app.server) app.server.reload(serve);
72
- else app.server = Bun.serve(serve);
111
+ app.server.reload(serve);
73
112
  const reloadAfterModules = () => {
113
+ if (app.server !== server) return;
74
114
  serve.fetch = app.fetch;
75
115
  if (hasWs || app["~hasWS"]) buildWebSocket();
76
116
  collectRoutes();
@@ -79,8 +119,7 @@ const BunAdapter = require_adapter_index.createAdapter({
79
119
  app.modules.then(reloadAfterModules, reloadAfterModules);
80
120
  } else {
81
121
  collectRoutes();
82
- if (app.server) app.server.reload(serve);
83
- else app.server = Bun.serve(serve);
122
+ app.server.reload(serve);
84
123
  }
85
124
  require_memory.flushMemory();
86
125
  if (hasWs) callback?.(app.server);
@@ -1,30 +1,68 @@
1
1
  import { createAdapter } from "../index.mjs";
2
- import { needEncodeRegex } from "../../constants.mjs";
3
- import { nullObject } from "../../utils.mjs";
2
+ import { isDynamicRegex, needEncodeRegex } from "../../constants.mjs";
3
+ import { flattenChain, getLoosePath, mapMethodBack, nullObject } from "../../utils.mjs";
4
4
  import { WebStandardAdapter } from "../web-standard/index.mjs";
5
+ import { buildNativeStaticResponse } from "../../compile/handler/index.mjs";
5
6
  import { flushMemory } from "../../memory.mjs";
6
7
  import { buildGlobalWSHandler } from "../../ws/route.mjs";
7
8
 
8
9
  //#region src/adapter/bun/index.ts
9
10
  function collectStaticRoutes(app) {
11
+ if (app["~config"]?.nativeStaticResponse === false) return;
10
12
  app.fetch;
11
- const source = app["~staticResponse"];
12
- if (!source) return;
13
+ const fetchLevelHook = flattenChain(app["~hookChain"]);
14
+ if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || app["~ext"]?.hoc?.length) return;
15
+ const history = app.history;
16
+ if (!history?.length) return;
13
17
  const ready = nullObject();
14
18
  const pending = [];
15
- for (const method in source) {
16
- const paths = source[method];
17
- for (let path in paths) {
18
- const value = paths[path];
19
- if (needEncodeRegex.test(path)) path = encodeURI(path);
20
- if (value instanceof Promise) pending.push(value.then((resolved) => {
21
- if (resolved instanceof Response) (ready[path] ??= nullObject())[method] = resolved;
22
- }, (err) => {
23
- console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
24
- }));
25
- else (ready[path] ??= nullObject())[method] = value;
19
+ const strictPath = app["~config"]?.strictPath === true;
20
+ const seen = /* @__PURE__ */ new Map();
21
+ for (let i = 0; i < history.length; i++) {
22
+ const route = history[i];
23
+ const method = route[0] === "WS" ? "WS" : mapMethodBack(route[0]);
24
+ seen.set(method + " " + route[1], i);
25
+ }
26
+ let explicitPaths;
27
+ if (!strictPath) {
28
+ explicitPaths = /* @__PURE__ */ new Map();
29
+ for (let i = 0; i < history.length; i++) {
30
+ const route = history[i];
31
+ const method = route[0] === "WS" ? "WS" : mapMethodBack(route[0]);
32
+ const path = route[1];
33
+ let set = explicitPaths.get(method);
34
+ if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
35
+ set.add(path);
36
+ if (needEncodeRegex.test(path)) {
37
+ const encoded = encodeURI(path);
38
+ if (encoded !== path) set.add(encoded);
39
+ }
40
+ }
41
+ }
42
+ const add = (method, path, value) => {
43
+ if (needEncodeRegex.test(path)) path = encodeURI(path);
44
+ if (value instanceof Promise) pending.push(value.then((resolved) => {
45
+ if (resolved instanceof Response) (ready[path] ??= nullObject())[method] = resolved;
46
+ }, (err) => {
47
+ console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
48
+ }));
49
+ else (ready[path] ??= nullObject())[method] = value;
50
+ };
51
+ for (let i = 0; i < history.length; i++) {
52
+ const route = history[i];
53
+ if (route[0] === "WS") continue;
54
+ const method = mapMethodBack(route[0]);
55
+ const path = route[1];
56
+ if (seen.get(method + " " + path) !== i) continue;
57
+ const value = buildNativeStaticResponse(route, app);
58
+ if (!value) continue;
59
+ add(method, path, value);
60
+ if (!strictPath && !isDynamicRegex.test(path)) {
61
+ const loose = getLoosePath(path);
62
+ if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
26
63
  }
27
64
  }
65
+ if (!Object.keys(ready).length && !pending.length) return;
28
66
  return [ready, pending];
29
67
  }
30
68
  const BunAdapter = createAdapter({
@@ -36,7 +74,7 @@ const BunAdapter = createAdapter({
36
74
  listen(app, options, callback) {
37
75
  const _config = app["~config"]?.serve;
38
76
  const optionsIsObject = typeof options === "object";
39
- const _options = optionsIsObject ? options : {
77
+ const _options = optionsIsObject ? { ...options } : {
40
78
  port: +options,
41
79
  fetch: (request, server) => app.fetch(request, server)
42
80
  };
@@ -45,12 +83,13 @@ const BunAdapter = createAdapter({
45
83
  ..._config,
46
84
  ..._options
47
85
  } : _options;
48
- app.server = Bun.serve(serve);
86
+ const server = app.server = Bun.serve(serve);
49
87
  const onSetup = app["~ext"]?.setup;
50
88
  if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
51
89
  const hasWs = app["~hasWS"];
52
90
  if (!hasWs) callback?.(app.server);
53
91
  queueMicrotask(() => {
92
+ if (app.server !== server) return;
54
93
  if (!app.pending) serve.fetch = app.fetch;
55
94
  const buildWebSocket = () => {
56
95
  const defaultConfig = app["~config"]?.websocket;
@@ -61,15 +100,16 @@ const BunAdapter = createAdapter({
61
100
  const staticRoutes = collectStaticRoutes(app);
62
101
  if (!staticRoutes) return;
63
102
  if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
103
+ if (app.server !== server) return;
64
104
  serve.routes = staticRoutes[0];
65
105
  app.server.reload(serve);
66
106
  });
67
107
  if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
68
108
  };
69
109
  if (app.pending) {
70
- if (app.server) app.server.reload(serve);
71
- else app.server = Bun.serve(serve);
110
+ app.server.reload(serve);
72
111
  const reloadAfterModules = () => {
112
+ if (app.server !== server) return;
73
113
  serve.fetch = app.fetch;
74
114
  if (hasWs || app["~hasWS"]) buildWebSocket();
75
115
  collectRoutes();
@@ -78,8 +118,7 @@ const BunAdapter = createAdapter({
78
118
  app.modules.then(reloadAfterModules, reloadAfterModules);
79
119
  } else {
80
120
  collectRoutes();
81
- if (app.server) app.server.reload(serve);
82
- else app.server = Bun.serve(serve);
121
+ app.server.reload(serve);
83
122
  }
84
123
  flushMemory();
85
124
  if (hasWs) callback?.(app.server);
@@ -0,0 +1,4 @@
1
+ //#region src/adapter/transferable.d.ts
2
+ declare const skipClone: WeakSet<object>;
3
+ //#endregion
4
+ export { skipClone };
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/adapter/transferable.ts
4
+ const skipClone = /* @__PURE__ */ new WeakSet();
5
+
6
+ //#endregion
7
+ exports.skipClone = skipClone;
@@ -0,0 +1,5 @@
1
+ //#region src/adapter/transferable.ts
2
+ const skipClone = /* @__PURE__ */ new WeakSet();
3
+
4
+ //#endregion
5
+ export { skipClone };
@@ -4,6 +4,7 @@ import { HTTPHeaders } from "../types.js";
4
4
  import { Context } from "../context.js";
5
5
  //#region src/adapter/utils.d.ts
6
6
  declare function handleFile(response: File | Blob, set?: Context['set'], request?: Request): Response;
7
+ declare function normalizeHeaders(set: Context['set']): void;
7
8
  declare function parseSetCookies(headers: Headers, setCookie: string[]): Headers;
8
9
  declare function responseToSetHeaders(response: Response, set?: Context['set']): {
9
10
  headers: HTTPHeaders;
@@ -33,15 +34,17 @@ declare function createResponseHandler(handler: CreateHandlerParameter): (respon
33
34
  *
34
35
  * To prevent long/infinite stream, the unconsumed window is capped:
35
36
  * Consumed-by-every-branch entries are trimmed off the front
36
- * Producer backpressures whenever the window hits `cap`
37
- * Streams shorter than `cap` buffer eagerly;
38
- * Only streams exceeding it gate on the slowest consumer
37
+ * Producer backpressures whenever the window hits `cap` ENTRIES or
38
+ * `capBytes` bytes, whichever comes first
39
+ *
40
+ * Streams below both caps buffer eagerly
41
+ * Only streams exceeding one gate on the slowest consumer
39
42
  *
40
43
  * Branch 0 is the value consumer (response/client)
41
- * When it is `return()`-ed (client abort / early exit) the source is stopped
44
+ * When `return()` (client abort / early exit), source is stopped
42
45
  * so the observer branches can still reach completion instead of spinning
43
- * an infinite source, and so an abandoned branch never pins the window into a deadlock
46
+ * an infinite source
44
47
  */
45
- declare function tee<T>(source: AsyncIterable<T>, branches?: number, cap?: number): Promise<AsyncIterableIterator<T>[]>;
48
+ declare function tee<T>(source: AsyncIterable<T>, branches?: number, cap?: number, capBytes?: number): AsyncIterableIterator<T>[];
46
49
  //#endregion
47
- export { createResponseHandler, createStreamHandler, handleFile, handleSet, mergeHeaders, mergeStatus, parseSetCookies, responseToSetHeaders, streamResponse, tee };
50
+ export { createResponseHandler, createStreamHandler, handleFile, handleSet, mergeHeaders, mergeStatus, normalizeHeaders, parseSetCookies, responseToSetHeaders, streamResponse, tee };