@noodleseed/one 0.22.0 → 0.23.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 (197) hide show
  1. package/dist/commands/author-loop.d.ts.map +1 -1
  2. package/dist/commands/author-loop.js +2 -2
  3. package/dist/commands/author-loop.js.map +1 -1
  4. package/dist/commands/catalog-dispatch.d.ts.map +1 -1
  5. package/dist/commands/catalog-dispatch.js +21 -2
  6. package/dist/commands/catalog-dispatch.js.map +1 -1
  7. package/dist/commands/deploy-ops.d.ts.map +1 -1
  8. package/dist/commands/deploy-ops.js +28 -11
  9. package/dist/commands/deploy-ops.js.map +1 -1
  10. package/dist/first-run.d.ts +11 -0
  11. package/dist/first-run.d.ts.map +1 -1
  12. package/dist/first-run.js +19 -4
  13. package/dist/first-run.js.map +1 -1
  14. package/dist/project-scaffold-templates.d.ts +11 -0
  15. package/dist/project-scaffold-templates.d.ts.map +1 -0
  16. package/dist/project-scaffold-templates.js +359 -0
  17. package/dist/project-scaffold-templates.js.map +1 -0
  18. package/dist/project.d.ts.map +1 -1
  19. package/dist/project.js +1 -323
  20. package/dist/project.js.map +1 -1
  21. package/dist/react.d.ts +2 -2
  22. package/dist/react.d.ts.map +1 -1
  23. package/dist/react.js +1 -1
  24. package/dist/react.js.map +1 -1
  25. package/dist/validate.d.ts +12 -0
  26. package/dist/validate.d.ts.map +1 -1
  27. package/dist/validate.js +11 -0
  28. package/dist/validate.js.map +1 -1
  29. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.d.ts.map +1 -1
  30. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +6 -9
  31. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
  32. package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
  33. package/node_modules/@noodle-borg/authoring/dist/index.d.ts +3 -3
  34. package/node_modules/@noodle-borg/authoring/dist/index.d.ts.map +1 -1
  35. package/node_modules/@noodle-borg/authoring/dist/index.js +1 -1
  36. package/node_modules/@noodle-borg/authoring/dist/index.js.map +1 -1
  37. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts +302 -7
  38. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts.map +1 -1
  39. package/node_modules/@noodle-borg/authoring/dist/react/components.js +39 -7
  40. package/node_modules/@noodle-borg/authoring/dist/react/components.js.map +1 -1
  41. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts +4 -2
  42. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts.map +1 -1
  43. package/node_modules/@noodle-borg/authoring/dist/react/index.js +2 -1
  44. package/node_modules/@noodle-borg/authoring/dist/react/index.js.map +1 -1
  45. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts +2618 -0
  46. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts.map +1 -0
  47. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js +110 -0
  48. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js.map +1 -0
  49. package/node_modules/@noodle-borg/authoring/dist/react.d.ts +2 -2
  50. package/node_modules/@noodle-borg/authoring/dist/react.d.ts.map +1 -1
  51. package/node_modules/@noodle-borg/authoring/dist/react.js +1 -1
  52. package/node_modules/@noodle-borg/authoring/dist/react.js.map +1 -1
  53. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts +1 -1
  54. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts.map +1 -1
  55. package/node_modules/@noodle-borg/authoring/dist/recording.js +14 -1
  56. package/node_modules/@noodle-borg/authoring/dist/recording.js.map +1 -1
  57. package/node_modules/@noodle-borg/authoring/dist/server.d.ts +25 -2
  58. package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
  59. package/node_modules/@noodle-borg/authoring/dist/server.js +7 -3
  60. package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
  61. package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
  62. package/node_modules/@noodle-borg/compiler/dist/compile.js +20 -8
  63. package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
  64. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +2 -0
  65. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
  66. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +6 -0
  67. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
  68. package/node_modules/@noodle-borg/connector-http/package.json +1 -1
  69. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
  70. package/node_modules/@noodle-borg/protocol/dist/mapping.js +8 -0
  71. package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
  72. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +15 -21
  73. package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
  74. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
  75. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +15 -21
  76. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
  77. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
  78. package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
  79. package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
  80. package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
  81. package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
  82. package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
  83. package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
  84. package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
  85. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
  86. package/node_modules/hono/dist/cjs/utils/body.js +12 -4
  87. package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
  88. package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
  89. package/node_modules/hono/dist/helper/css/common.js +3 -1
  90. package/node_modules/hono/dist/helper/css/index.js +9 -1
  91. package/node_modules/hono/dist/jsx/base.js +15 -15
  92. package/node_modules/hono/dist/jsx/components.js +42 -22
  93. package/node_modules/hono/dist/jsx/context.js +129 -5
  94. package/node_modules/hono/dist/jsx/streaming.js +10 -8
  95. package/node_modules/hono/dist/middleware/cors/index.js +2 -5
  96. package/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
  97. package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
  98. package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
  99. package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
  100. package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
  101. package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
  102. package/node_modules/hono/dist/utils/body.js +12 -4
  103. package/node_modules/hono/dist/utils/buffer.js +2 -1
  104. package/node_modules/hono/dist/validator/validator.js +3 -3
  105. package/node_modules/hono/package.json +9 -10
  106. package/node_modules/tailwindcss/dist/chunk-HMCCH6MG.mjs +1 -0
  107. package/node_modules/tailwindcss/dist/default-theme.mjs +1 -1
  108. package/node_modules/tailwindcss/dist/lib.js +13 -13
  109. package/node_modules/tailwindcss/dist/lib.mjs +18 -18
  110. package/node_modules/tailwindcss/package.json +2 -2
  111. package/node_modules/undici/README.md +3 -2
  112. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  113. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  114. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  115. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  116. package/node_modules/undici/docs/docs/api/Client.md +365 -178
  117. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  118. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  119. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  120. package/node_modules/undici/docs/docs/api/Cookies.md +125 -47
  121. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  122. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  123. package/node_modules/undici/docs/docs/api/Dispatcher.md +479 -1093
  124. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
  125. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  126. package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
  127. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  128. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  129. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  130. package/node_modules/undici/docs/docs/api/Interceptors.md +355 -0
  131. package/node_modules/undici/docs/docs/api/MockAgent.md +314 -322
  132. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  133. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  134. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  135. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  136. package/node_modules/undici/docs/docs/api/MockPool.md +299 -263
  137. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  138. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  139. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  140. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  141. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  142. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  143. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  144. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  145. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -186
  146. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  147. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  148. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  149. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  150. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  151. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  152. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  153. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  154. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  155. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  156. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  157. package/node_modules/undici/docs/docs/index.md +779 -0
  158. package/node_modules/undici/docs/docs/site.json +125 -0
  159. package/node_modules/undici/docs/docs/type-map.json +79 -0
  160. package/node_modules/undici/lib/api/api-request.js +7 -1
  161. package/node_modules/undici/lib/api/readable.js +47 -2
  162. package/node_modules/undici/lib/core/errors.js +20 -0
  163. package/node_modules/undici/lib/core/request.js +1 -1
  164. package/node_modules/undici/lib/core/util.js +24 -1
  165. package/node_modules/undici/lib/dispatcher/client-h1.js +92 -1
  166. package/node_modules/undici/lib/dispatcher/client-h2.js +322 -118
  167. package/node_modules/undici/lib/dispatcher/client.js +6 -2
  168. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +1 -0
  169. package/node_modules/undici/lib/dispatcher/proxy-agent.js +42 -7
  170. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +4 -2
  171. package/node_modules/undici/lib/handler/redirect-handler.js +1 -0
  172. package/node_modules/undici/lib/handler/retry-handler.js +57 -19
  173. package/node_modules/undici/lib/util/cache.js +8 -2
  174. package/node_modules/undici/lib/web/cookies/parse.js +20 -27
  175. package/node_modules/undici/lib/web/cookies/util.js +1 -1
  176. package/node_modules/undici/lib/web/eventsource/eventsource.js +7 -18
  177. package/node_modules/undici/lib/web/eventsource/util.js +32 -1
  178. package/node_modules/undici/lib/web/fetch/body.js +43 -0
  179. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  180. package/node_modules/undici/lib/web/fetch/index.js +11 -2
  181. package/node_modules/undici/lib/web/fetch/request.js +1 -0
  182. package/node_modules/undici/lib/web/fetch/util.js +4 -1
  183. package/node_modules/undici/lib/web/websocket/receiver.js +20 -3
  184. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
  185. package/node_modules/undici/lib/web/websocket/websocket.js +3 -1
  186. package/node_modules/undici/package.json +1 -1
  187. package/node_modules/undici/types/client.d.ts +6 -1
  188. package/node_modules/undici/types/cookies.d.ts +1 -1
  189. package/node_modules/undici/types/errors.d.ts +10 -0
  190. package/node_modules/undici/types/fetch.d.ts +1 -0
  191. package/node_modules/undici/types/handlers.d.ts +2 -0
  192. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  193. package/package.json +4 -4
  194. package/react/styles.css +510 -5
  195. package/react/styles.source.css +850 -0
  196. package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
  197. package/node_modules/tailwindcss/dist/chunk-XVOTX5KS.mjs +0 -1
@@ -34,8 +34,9 @@ const childrenToString = async (children) => {
34
34
  return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
35
35
  } catch (e) {
36
36
  if (e instanceof Promise) {
37
+ const resume = (0, import_context.captureRenderContext)();
37
38
  await e;
38
- return childrenToString(children);
39
+ return resume(() => childrenToString(children));
39
40
  } else {
40
41
  throw e;
41
42
  }
@@ -63,51 +64,68 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
63
64
  children = [children];
64
65
  }
65
66
  const nonce = (0, import_context.useContext)(import_streaming.StreamingContext)?.scriptNonce;
66
- let fallbackStr;
67
- const resolveFallbackStr = async () => {
67
+ let resume;
68
+ const getResume = () => resume ||= (0, import_context.captureRenderContext)();
69
+ let fallbackStrPromise;
70
+ const resolveFallbackStr = () => fallbackStrPromise ||= (async () => {
68
71
  const awaitedFallback = await fallback;
69
72
  if (typeof awaitedFallback === "string") {
70
- fallbackStr = awaitedFallback;
73
+ return awaitedFallback;
71
74
  } else {
72
- fallbackStr = await awaitedFallback?.toString();
73
- if (typeof fallbackStr === "string") {
74
- fallbackStr = (0, import_html.raw)(fallbackStr);
75
+ const fallbackResult = await getResume()(() => awaitedFallback?.toString());
76
+ if (typeof fallbackResult === "string") {
77
+ return (0, import_html.raw)(
78
+ fallbackResult,
79
+ fallbackResult.callbacks || awaitedFallback?.callbacks
80
+ );
75
81
  }
76
82
  }
77
- };
78
- const fallbackRes = (error) => {
79
- onError?.(error);
80
- return fallbackStr || fallbackRender && (0, import_base.jsx)(import_base.Fragment, {}, fallbackRender(error)) || "";
83
+ })();
84
+ const renderFallback = async (error) => {
85
+ const fallbackStr = await resolveFallbackStr();
86
+ return getResume()(async () => {
87
+ onError?.(error);
88
+ const fallbackRes = fallbackStr !== void 0 ? fallbackStr : fallbackRender && (0, import_base.jsx)(import_base.Fragment, {}, fallbackRender(error)) || "";
89
+ const fallbackResString = await (0, import_base.Fragment)({
90
+ children: fallbackRes
91
+ }).toString();
92
+ return (0, import_html.raw)(
93
+ fallbackResString,
94
+ fallbackResString.callbacks || fallbackRes.callbacks
95
+ );
96
+ });
81
97
  };
82
98
  let resArray = [];
83
99
  try {
84
100
  resArray = children.map(resolveChildEarly);
85
101
  } catch (e) {
86
- await resolveFallbackStr();
102
+ const resume2 = getResume();
87
103
  if (e instanceof Promise) {
88
104
  resArray = [
89
- e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
105
+ e.then(() => resume2(() => childrenToString(children))).catch((e2) => renderFallback(e2))
90
106
  ];
91
107
  } else {
92
- resArray = [fallbackRes(e)];
108
+ resArray = [await renderFallback(e)];
93
109
  }
94
110
  }
95
111
  if (resArray.some((res) => res instanceof Promise)) {
96
- await resolveFallbackStr();
112
+ getResume();
97
113
  const index = errorBoundaryCounter++;
98
114
  const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
99
- const caught = false;
115
+ let caught = false;
100
116
  const catchCallback = async ({ error: error2, buffer }) => {
101
117
  if (caught) {
102
118
  return "";
103
119
  }
104
- const fallbackResString = await (0, import_base.Fragment)({
105
- children: fallbackRes(error2)
106
- }).toString();
120
+ caught = true;
121
+ const fallbackResString = await renderFallback(error2);
122
+ const fallbackCallbacks = fallbackResString.callbacks;
107
123
  if (buffer) {
108
124
  buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
125
+ return fallbackCallbacks?.length ? (0, import_html.raw)("", fallbackCallbacks) : "";
109
126
  }
110
- return buffer ? "" : `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
127
+ return (0, import_html.raw)(
128
+ `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
111
129
  ((d,c,n) => {
112
130
  c=d.currentScript.previousSibling
113
131
  d=d.getElementById('E:${index}')
@@ -115,7 +133,9 @@ if(!d)return
115
133
  do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
116
134
  d.replaceWith(c.content)
117
135
  })(document)
118
- </script>`;
136
+ </script>`,
137
+ fallbackCallbacks
138
+ );
119
139
  };
120
140
  let error;
121
141
  const promiseAll = Promise.all(resArray).catch((e) => error = e);
@@ -17,8 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var context_exports = {};
19
19
  __export(context_exports, {
20
+ captureRenderContext: () => captureRenderContext,
20
21
  createContext: () => createContext,
21
22
  globalContexts: () => globalContexts,
23
+ runWithRenderContext: () => runWithRenderContext,
22
24
  useContext: () => useContext
23
25
  });
24
26
  module.exports = __toCommonJS(context_exports);
@@ -27,21 +29,143 @@ var import_base = require("./base");
27
29
  var import_constants = require("./constants");
28
30
  var import_context = require("./dom/context");
29
31
  const globalContexts = [];
32
+ let alsProbed = false;
33
+ let asyncLocalStorage;
34
+ let fallbackStore;
35
+ let fallbackRendersInFlight = 0;
36
+ let warnedFallbackDefault = false;
37
+ const loadAsyncLocalStorage = () => {
38
+ if (alsProbed) {
39
+ return asyncLocalStorage;
40
+ }
41
+ alsProbed = true;
42
+ const global = globalThis;
43
+ let AsyncLocalStorage;
44
+ for (const probe of [
45
+ // Node.js >= 20.16, Deno, Bun, Cloudflare Workers (nodejs_compat). Property
46
+ // access only, so bundlers don't statically resolve `node:async_hooks`.
47
+ () => global.process?.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage,
48
+ // Node.js < 20.16 has no `process.getBuiltinModule`, but a CJS entrypoint
49
+ // exposes the main module's `require` here.
50
+ () => global.process?.mainModule?.require?.("node:async_hooks")?.AsyncLocalStorage
51
+ ]) {
52
+ try {
53
+ AsyncLocalStorage = probe();
54
+ } catch {
55
+ }
56
+ if (AsyncLocalStorage) {
57
+ break;
58
+ }
59
+ }
60
+ if (AsyncLocalStorage) {
61
+ asyncLocalStorage = new AsyncLocalStorage();
62
+ }
63
+ return asyncLocalStorage;
64
+ };
65
+ const getCurrentStore = () => {
66
+ return loadAsyncLocalStorage()?.getStore() || fallbackStore;
67
+ };
68
+ const warnIfStorelessAccess = () => {
69
+ if (fallbackRendersInFlight > 0 && !warnedFallbackDefault) {
70
+ warnedFallbackDefault = true;
71
+ console.warn(
72
+ "hono/jsx: AsyncLocalStorage is unavailable in this runtime, so useContext() after an await in an async component falls back to the context default value during server-side rendering. To get provided values across await boundaries, use a runtime with AsyncLocalStorage (Node.js >= 20.16, Deno, Bun, or Cloudflare Workers with the nodejs_compat flag)."
73
+ );
74
+ }
75
+ };
76
+ const getContextValuesIn = (store, context) => {
77
+ if (!store) {
78
+ warnIfStorelessAccess();
79
+ return context.values;
80
+ }
81
+ let values = store.get(context);
82
+ if (!values) {
83
+ values = [context.values[0]];
84
+ store.set(context, values);
85
+ }
86
+ return values;
87
+ };
88
+ const readContextValueIn = (store, context) => {
89
+ if (!store) {
90
+ warnIfStorelessAccess();
91
+ return context.values.at(-1);
92
+ }
93
+ const values = store.get(context);
94
+ return values?.length ? values.at(-1) : context.values[0];
95
+ };
96
+ const captureContextValues = (store) => (store ? globalContexts.filter((c) => store.has(c)) : globalContexts).map((c) => [
97
+ c,
98
+ readContextValueIn(store, c)
99
+ ]);
100
+ const resumeWithContextValues = (callback, store, contexts) => runWithRenderContext(() => {
101
+ const currentStore = getCurrentStore();
102
+ const valuesPerContext = contexts.map(([context, value]) => {
103
+ const values = getContextValuesIn(currentStore, context);
104
+ values.push(value);
105
+ return values;
106
+ });
107
+ const popContextValues = () => {
108
+ valuesPerContext.forEach((values) => {
109
+ values.pop();
110
+ });
111
+ };
112
+ try {
113
+ const result = callback();
114
+ if (result instanceof Promise) {
115
+ return result.finally(popContextValues);
116
+ }
117
+ popContextValues();
118
+ return result;
119
+ } catch (e) {
120
+ popContextValues();
121
+ throw e;
122
+ }
123
+ }, store);
124
+ const runWithRenderContext = (callback, resumeStore) => {
125
+ if (getCurrentStore()) {
126
+ return callback();
127
+ }
128
+ const store = resumeStore ?? /* @__PURE__ */ new WeakMap();
129
+ const storage = loadAsyncLocalStorage();
130
+ if (storage) {
131
+ return storage.run(store, callback);
132
+ }
133
+ fallbackStore = store;
134
+ let result;
135
+ try {
136
+ result = callback();
137
+ } finally {
138
+ fallbackStore = void 0;
139
+ }
140
+ if (!warnedFallbackDefault && result instanceof Promise) {
141
+ fallbackRendersInFlight++;
142
+ result = result.finally(() => {
143
+ fallbackRendersInFlight--;
144
+ });
145
+ }
146
+ return result;
147
+ };
148
+ const captureRenderContext = () => {
149
+ const store = getCurrentStore();
150
+ const contexts = captureContextValues(store);
151
+ return (callback) => resumeWithContextValues(callback, store, contexts);
152
+ };
30
153
  const createContext = (defaultValue) => {
31
154
  const values = [defaultValue];
32
155
  const context = ((props) => {
33
- values.push(props.value);
156
+ const contextValues = getContextValuesIn(getCurrentStore(), context);
157
+ contextValues.push(props.value);
34
158
  let string;
35
159
  try {
36
160
  string = props.children ? (Array.isArray(props.children) ? new import_base.JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
37
161
  } catch (e) {
38
- values.pop();
162
+ contextValues.pop();
39
163
  throw e;
40
164
  }
41
165
  if (string instanceof Promise) {
42
- return string.finally(() => values.pop()).then((resString) => (0, import_html.raw)(resString, resString.callbacks));
166
+ return string.finally(() => contextValues.pop()).then((resString) => (0, import_html.raw)(resString, resString.callbacks));
43
167
  } else {
44
- values.pop();
168
+ contextValues.pop();
45
169
  return (0, import_html.raw)(string);
46
170
  }
47
171
  });
@@ -52,11 +176,13 @@ const createContext = (defaultValue) => {
52
176
  return context;
53
177
  };
54
178
  const useContext = (context) => {
55
- return context.values.at(-1);
179
+ return readContextValueIn(getCurrentStore(), context);
56
180
  };
57
181
  // Annotate the CommonJS export names for ESM import in node:
58
182
  0 && (module.exports = {
183
+ captureRenderContext,
59
184
  createContext,
60
185
  globalContexts,
186
+ runWithRenderContext,
61
187
  useContext
62
188
  });
@@ -42,9 +42,8 @@ const Suspense = async ({
42
42
  const nonce = (0, import_context.useContext)(StreamingContext)?.scriptNonce;
43
43
  let resArray = [];
44
44
  const stackNode = { [import_constants.DOM_STASH]: [0, []] };
45
- const popNodeStack = (value) => {
45
+ const popNodeStack = () => {
46
46
  import_render.buildDataStack.pop();
47
- return value;
48
47
  };
49
48
  try {
50
49
  stackNode[import_constants.DOM_STASH][0] = 0;
@@ -54,12 +53,15 @@ const Suspense = async ({
54
53
  );
55
54
  } catch (e) {
56
55
  if (e instanceof Promise) {
56
+ const resume = (0, import_context.captureRenderContext)();
57
57
  resArray = [
58
- e.then(() => {
59
- stackNode[import_constants.DOM_STASH][0] = 0;
60
- import_render.buildDataStack.push([[], stackNode]);
61
- return (0, import_components.childrenToString)(children).then(popNodeStack);
62
- })
58
+ e.then(
59
+ () => resume(() => {
60
+ stackNode[import_constants.DOM_STASH][0] = 0;
61
+ import_render.buildDataStack.push([[], stackNode]);
62
+ return (0, import_components.childrenToString)(children).finally(popNodeStack);
63
+ })
64
+ )
63
65
  ];
64
66
  } else {
65
67
  throw e;
@@ -31,9 +31,6 @@ const cors = (options) => {
31
31
  const findAllowOrigin = ((optsOrigin) => {
32
32
  if (typeof optsOrigin === "string") {
33
33
  if (optsOrigin === "*") {
34
- if (opts.credentials) {
35
- return (origin) => origin || null;
36
- }
37
34
  return () => optsOrigin;
38
35
  } else {
39
36
  return (origin) => optsOrigin === origin ? origin : null;
@@ -68,7 +65,7 @@ const cors = (options) => {
68
65
  set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
69
66
  }
70
67
  if (c.req.method === "OPTIONS") {
71
- if (opts.origin !== "*" || opts.credentials) {
68
+ if (opts.origin !== "*") {
72
69
  set("Vary", "Origin");
73
70
  }
74
71
  if (opts.maxAge != null) {
@@ -98,7 +95,7 @@ const cors = (options) => {
98
95
  });
99
96
  }
100
97
  await next();
101
- if (opts.origin !== "*" || opts.credentials) {
98
+ if (opts.origin !== "*") {
102
99
  c.header("Vary", "Origin", { append: true });
103
100
  }
104
101
  };
@@ -45,7 +45,7 @@ const serveStatic = (options) => {
45
45
  } else {
46
46
  try {
47
47
  filename = (0, import_url.tryDecodeURI)(c.req.path);
48
- if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}/.test(filename)) {
48
+ if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) {
49
49
  throw new Error();
50
50
  }
51
51
  } catch {
@@ -65,7 +65,7 @@ const serveStatic = (options) => {
65
65
  if (content instanceof Response) {
66
66
  return c.newResponse(content.body, content);
67
67
  }
68
- if (content) {
68
+ if (content != null) {
69
69
  const mimeType = options.mimes && (0, import_mime.getMimeType)(path, options.mimes) || (0, import_mime.getMimeType)(path);
70
70
  c.header("Content-Type", mimeType || "application/octet-stream");
71
71
  if (options.precompressed && (!mimeType || import_compress.COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
@@ -20,18 +20,26 @@ __export(body_exports, {
20
20
  parseBody: () => parseBody
21
21
  });
22
22
  module.exports = __toCommonJS(body_exports);
23
- var import_request = require("../request");
23
+ var import_buffer = require("./buffer");
24
+ const isRawRequest = (request) => "headers" in request;
24
25
  const parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
25
26
  const { all = false, dot = false } = options;
26
- const headers = request instanceof import_request.HonoRequest ? request.raw.headers : request.headers;
27
+ const headers = isRawRequest(request) ? request.headers : request.raw.headers;
27
28
  const contentType = headers.get("Content-Type");
28
- if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
29
+ const mediaType = contentType?.split(";")[0].trim().toLowerCase();
30
+ if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
29
31
  return parseFormData(request, { all, dot });
30
32
  }
31
33
  return {};
32
34
  };
33
35
  async function parseFormData(request, options) {
34
- const formData = await request.formData();
36
+ const headers = isRawRequest(request) ? request.headers : request.raw.headers;
37
+ const arrayBuffer = await request.arrayBuffer();
38
+ const formDataPromise = (0, import_buffer.bufferToFormData)(arrayBuffer, headers.get("Content-Type") || "");
39
+ if (!isRawRequest(request)) {
40
+ request.bodyCache.formData = formDataPromise;
41
+ }
42
+ const formData = await formDataPromise;
35
43
  if (formData) {
36
44
  return convertFormDataToBodyData(formData, options);
37
45
  }
@@ -88,7 +88,8 @@ const bufferToString = (buffer) => {
88
88
  const bufferToFormData = (arrayBuffer, contentType) => {
89
89
  const response = new Response(arrayBuffer, {
90
90
  headers: {
91
- "Content-Type": contentType
91
+ // Normalize the media type (case-insensitive) while keeping parameters like the boundary
92
+ "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase())
92
93
  }
93
94
  });
94
95
  return response.formData();
@@ -23,9 +23,9 @@ module.exports = __toCommonJS(validator_exports);
23
23
  var import_cookie = require("../helper/cookie");
24
24
  var import_http_exception = require("../http-exception");
25
25
  var import_buffer = require("../utils/buffer");
26
- const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
27
- const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/;
28
- const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
26
+ const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
27
+ const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/i;
28
+ const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
29
29
  const validator = (target, validationFunc) => {
30
30
  return async (c, next) => {
31
31
  let value = {};
@@ -25,6 +25,7 @@ var normalizeLabel = (label) => {
25
25
  return label.trim().replace(/\s+/g, "-");
26
26
  };
27
27
  var isValidClassName = (name) => /^-?[_a-zA-Z][_a-zA-Z0-9-]*$/.test(name);
28
+ var hasUnsafeSelectorChar = (name) => /[<{}]/.test(name);
28
29
  var RESERVED_KEYFRAME_NAMES = /* @__PURE__ */ new Set([
29
30
  "default",
30
31
  "inherit",
@@ -162,7 +163,8 @@ var cxCommon = (args) => {
162
163
  [CLASS_NAME]: "",
163
164
  [STYLE_STRING]: "",
164
165
  [SELECTORS]: [],
165
- [EXTERNAL_CLASS_NAMES]: [arg]
166
+ // drop names that are unsafe to emit as a selector
167
+ [EXTERNAL_CLASS_NAMES]: hasUnsafeSelectorChar(arg) ? [] : [arg]
166
168
  };
167
169
  }
168
170
  }
@@ -2,6 +2,7 @@
2
2
  import { raw } from "../../helper/html/index.js";
3
3
  import { DOM_RENDERER } from "../../jsx/constants.js";
4
4
  import { createCssJsxDomObjects } from "../../jsx/dom/css.js";
5
+ import { escapeToBuffer } from "../../utils/html.js";
5
6
  import {
6
7
  CLASS_NAME,
7
8
  DEFAULT_STYLE_ID,
@@ -72,7 +73,14 @@ var createCssContext = ({
72
73
  }
73
74
  return Promise.resolve(raw("", [appendStyle]));
74
75
  };
75
- const className = new String(cssClassName[CLASS_NAME]);
76
+ const rawClassName = cssClassName[CLASS_NAME];
77
+ let escapedClassName = rawClassName;
78
+ if (/[&<>'"]/.test(rawClassName)) {
79
+ const escapedBuffer = [""];
80
+ escapeToBuffer(rawClassName, escapedBuffer);
81
+ escapedClassName = escapedBuffer[0];
82
+ }
83
+ const className = new String(escapedClassName);
76
84
  Object.assign(className, cssClassName);
77
85
  className.isEscaped = true;
78
86
  className.callbacks = [addClassNameToContext];
@@ -2,7 +2,13 @@
2
2
  import { raw } from "../helper/html/index.js";
3
3
  import { escapeToBuffer, resolveCallbackSync, stringBufferToString } from "../utils/html.js";
4
4
  import { DOM_RENDERER, DOM_MEMO } from "./constants.js";
5
- import { createContext, globalContexts, useContext } from "./context.js";
5
+ import {
6
+ captureRenderContext,
7
+ createContext,
8
+ globalContexts,
9
+ runWithRenderContext,
10
+ useContext
11
+ } from "./context.js";
6
12
  import { domRenderers } from "./intrinsic-element/common.js";
7
13
  import * as intrinsicElementTags from "./intrinsic-element/components.js";
8
14
  import {
@@ -88,7 +94,7 @@ var JSXNode = class {
88
94
  key;
89
95
  children;
90
96
  isEscaped = true;
91
- localContexts;
97
+ suspendedContext;
92
98
  constructor(tag, props, children) {
93
99
  if (typeof tag !== "function" && !isValidTagName(tag)) {
94
100
  throw new Error(`Invalid JSX tag name: ${tag}`);
@@ -106,18 +112,12 @@ var JSXNode = class {
106
112
  return this.props.ref || null;
107
113
  }
108
114
  toString() {
109
- const buffer = [""];
110
- this.localContexts?.forEach(([context, value]) => {
111
- context.values.push(value);
112
- });
113
- try {
115
+ const render = () => {
116
+ const buffer = [""];
114
117
  this.toStringToBuffer(buffer);
115
- } finally {
116
- this.localContexts?.forEach(([context]) => {
117
- context.values.pop();
118
- });
119
- }
120
- return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
118
+ return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
119
+ };
120
+ return this.suspendedContext ? this.suspendedContext(render) : runWithRenderContext(render);
121
121
  }
122
122
  toStringToBuffer(buffer) {
123
123
  const tag = this.tag;
@@ -193,12 +193,12 @@ var JSXFunctionNode = class extends JSXNode {
193
193
  if (globalContexts.length === 0) {
194
194
  buffer.unshift("", res);
195
195
  } else {
196
- const currentContexts = globalContexts.map((c) => [c, c.values.at(-1)]);
196
+ const suspendedContext = captureRenderContext();
197
197
  buffer.unshift(
198
198
  "",
199
199
  res.then((childRes) => {
200
200
  if (childRes instanceof JSXNode) {
201
- childRes.localContexts = currentContexts;
201
+ childRes.suspendedContext = suspendedContext;
202
202
  }
203
203
  return childRes;
204
204
  })
@@ -3,7 +3,7 @@ import { raw } from "../helper/html/index.js";
3
3
  import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
4
4
  import { jsx, Fragment } from "./base.js";
5
5
  import { DOM_RENDERER } from "./constants.js";
6
- import { useContext } from "./context.js";
6
+ import { captureRenderContext, useContext } from "./context.js";
7
7
  import { ErrorBoundary as ErrorBoundaryDomRenderer } from "./dom/components.js";
8
8
  import { StreamingContext } from "./streaming.js";
9
9
  var errorBoundaryCounter = 0;
@@ -12,8 +12,9 @@ var childrenToString = async (children) => {
12
12
  return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
13
13
  } catch (e) {
14
14
  if (e instanceof Promise) {
15
+ const resume = captureRenderContext();
15
16
  await e;
16
- return childrenToString(children);
17
+ return resume(() => childrenToString(children));
17
18
  } else {
18
19
  throw e;
19
20
  }
@@ -41,51 +42,68 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
41
42
  children = [children];
42
43
  }
43
44
  const nonce = useContext(StreamingContext)?.scriptNonce;
44
- let fallbackStr;
45
- const resolveFallbackStr = async () => {
45
+ let resume;
46
+ const getResume = () => resume ||= captureRenderContext();
47
+ let fallbackStrPromise;
48
+ const resolveFallbackStr = () => fallbackStrPromise ||= (async () => {
46
49
  const awaitedFallback = await fallback;
47
50
  if (typeof awaitedFallback === "string") {
48
- fallbackStr = awaitedFallback;
51
+ return awaitedFallback;
49
52
  } else {
50
- fallbackStr = await awaitedFallback?.toString();
51
- if (typeof fallbackStr === "string") {
52
- fallbackStr = raw(fallbackStr);
53
+ const fallbackResult = await getResume()(() => awaitedFallback?.toString());
54
+ if (typeof fallbackResult === "string") {
55
+ return raw(
56
+ fallbackResult,
57
+ fallbackResult.callbacks || awaitedFallback?.callbacks
58
+ );
53
59
  }
54
60
  }
55
- };
56
- const fallbackRes = (error) => {
57
- onError?.(error);
58
- return fallbackStr || fallbackRender && jsx(Fragment, {}, fallbackRender(error)) || "";
61
+ })();
62
+ const renderFallback = async (error) => {
63
+ const fallbackStr = await resolveFallbackStr();
64
+ return getResume()(async () => {
65
+ onError?.(error);
66
+ const fallbackRes = fallbackStr !== void 0 ? fallbackStr : fallbackRender && jsx(Fragment, {}, fallbackRender(error)) || "";
67
+ const fallbackResString = await Fragment({
68
+ children: fallbackRes
69
+ }).toString();
70
+ return raw(
71
+ fallbackResString,
72
+ fallbackResString.callbacks || fallbackRes.callbacks
73
+ );
74
+ });
59
75
  };
60
76
  let resArray = [];
61
77
  try {
62
78
  resArray = children.map(resolveChildEarly);
63
79
  } catch (e) {
64
- await resolveFallbackStr();
80
+ const resume2 = getResume();
65
81
  if (e instanceof Promise) {
66
82
  resArray = [
67
- e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
83
+ e.then(() => resume2(() => childrenToString(children))).catch((e2) => renderFallback(e2))
68
84
  ];
69
85
  } else {
70
- resArray = [fallbackRes(e)];
86
+ resArray = [await renderFallback(e)];
71
87
  }
72
88
  }
73
89
  if (resArray.some((res) => res instanceof Promise)) {
74
- await resolveFallbackStr();
90
+ getResume();
75
91
  const index = errorBoundaryCounter++;
76
92
  const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
77
- const caught = false;
93
+ let caught = false;
78
94
  const catchCallback = async ({ error: error2, buffer }) => {
79
95
  if (caught) {
80
96
  return "";
81
97
  }
82
- const fallbackResString = await Fragment({
83
- children: fallbackRes(error2)
84
- }).toString();
98
+ caught = true;
99
+ const fallbackResString = await renderFallback(error2);
100
+ const fallbackCallbacks = fallbackResString.callbacks;
85
101
  if (buffer) {
86
102
  buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
103
+ return fallbackCallbacks?.length ? raw("", fallbackCallbacks) : "";
87
104
  }
88
- return buffer ? "" : `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
105
+ return raw(
106
+ `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
89
107
  ((d,c,n) => {
90
108
  c=d.currentScript.previousSibling
91
109
  d=d.getElementById('E:${index}')
@@ -93,7 +111,9 @@ if(!d)return
93
111
  do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
94
112
  d.replaceWith(c.content)
95
113
  })(document)
96
- </script>`;
114
+ </script>`,
115
+ fallbackCallbacks
116
+ );
97
117
  };
98
118
  let error;
99
119
  const promiseAll = Promise.all(resArray).catch((e) => error = e);