@timber-js/app 0.2.0-alpha.8 → 0.2.0-alpha.80

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 (573) hide show
  1. package/LICENSE +8 -0
  2. package/dist/_chunks/actions-Dg-ANYHb.js +421 -0
  3. package/dist/_chunks/actions-Dg-ANYHb.js.map +1 -0
  4. package/dist/_chunks/{als-registry-B7DbZ2hS.js → als-registry-HS0LGUl2.js} +1 -1
  5. package/dist/_chunks/als-registry-HS0LGUl2.js.map +1 -0
  6. package/dist/_chunks/chunk-DYhsFzuS.js +33 -0
  7. package/dist/_chunks/{debug-gwlJkDuf.js → debug-ECi_61pb.js} +2 -2
  8. package/dist/_chunks/debug-ECi_61pb.js.map +1 -0
  9. package/dist/_chunks/define-C77ScO0m.js +106 -0
  10. package/dist/_chunks/define-C77ScO0m.js.map +1 -0
  11. package/dist/_chunks/define-CZqDwhSu.js +199 -0
  12. package/dist/_chunks/define-CZqDwhSu.js.map +1 -0
  13. package/dist/_chunks/define-cookie-C2IkoFGN.js +94 -0
  14. package/dist/_chunks/define-cookie-C2IkoFGN.js.map +1 -0
  15. package/dist/_chunks/{format-DviM89f0.js → dev-warnings-DpGRGoDi.js} +5 -44
  16. package/dist/_chunks/dev-warnings-DpGRGoDi.js.map +1 -0
  17. package/dist/_chunks/format-CYBGxKtc.js +14 -0
  18. package/dist/_chunks/format-CYBGxKtc.js.map +1 -0
  19. package/dist/_chunks/{interception-BOoWmLUA.js → interception-Dpn_UfAD.js} +171 -97
  20. package/dist/_chunks/interception-Dpn_UfAD.js.map +1 -0
  21. package/dist/_chunks/merge-search-params-Cm_KIWDX.js +41 -0
  22. package/dist/_chunks/merge-search-params-Cm_KIWDX.js.map +1 -0
  23. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → metadata-routes-DS3eKNmf.js} +1 -1
  24. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js.map → metadata-routes-DS3eKNmf.js.map} +1 -1
  25. package/dist/_chunks/request-context-qMsWgy9C.js +478 -0
  26. package/dist/_chunks/request-context-qMsWgy9C.js.map +1 -0
  27. package/dist/_chunks/schema-bridge-C3xl_vfb.js +86 -0
  28. package/dist/_chunks/schema-bridge-C3xl_vfb.js.map +1 -0
  29. package/dist/_chunks/segment-classify-BDNn6EzD.js +65 -0
  30. package/dist/_chunks/segment-classify-BDNn6EzD.js.map +1 -0
  31. package/dist/_chunks/segment-context-fHFLF1PE.js +34 -0
  32. package/dist/_chunks/segment-context-fHFLF1PE.js.map +1 -0
  33. package/dist/_chunks/{ssr-data-MjmprTmO.js → ssr-data-DzuI0bIV.js} +1 -1
  34. package/dist/_chunks/{ssr-data-MjmprTmO.js.map → ssr-data-DzuI0bIV.js.map} +1 -1
  35. package/dist/_chunks/stale-reload-C2plcNtG.js +64 -0
  36. package/dist/_chunks/stale-reload-C2plcNtG.js.map +1 -0
  37. package/dist/_chunks/{tracing-CemImE6h.js → tracing-CCYbKn5n.js} +60 -9
  38. package/dist/_chunks/tracing-CCYbKn5n.js.map +1 -0
  39. package/dist/_chunks/use-params-Br9YSUFV.js +295 -0
  40. package/dist/_chunks/use-params-Br9YSUFV.js.map +1 -0
  41. package/dist/_chunks/{use-query-states-D5KaffOK.js → use-query-states-Lo_s_pw2.js} +4 -4
  42. package/dist/_chunks/use-query-states-Lo_s_pw2.js.map +1 -0
  43. package/dist/_chunks/wrappers-_DTmImGt.js +63 -0
  44. package/dist/_chunks/wrappers-_DTmImGt.js.map +1 -0
  45. package/dist/adapters/cloudflare-dev.d.ts +109 -0
  46. package/dist/adapters/cloudflare-dev.d.ts.map +1 -0
  47. package/dist/adapters/cloudflare-dev.js +73 -0
  48. package/dist/adapters/cloudflare-dev.js.map +1 -0
  49. package/dist/adapters/cloudflare-kv-cache.d.ts +64 -0
  50. package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -0
  51. package/dist/adapters/cloudflare-kv-cache.js +95 -0
  52. package/dist/adapters/cloudflare-kv-cache.js.map +1 -0
  53. package/dist/adapters/cloudflare.d.ts +148 -12
  54. package/dist/adapters/cloudflare.d.ts.map +1 -1
  55. package/dist/adapters/cloudflare.js +135 -11
  56. package/dist/adapters/cloudflare.js.map +1 -1
  57. package/dist/adapters/compress-module.d.ts.map +1 -1
  58. package/dist/adapters/nitro.d.ts +17 -1
  59. package/dist/adapters/nitro.d.ts.map +1 -1
  60. package/dist/adapters/nitro.js +56 -13
  61. package/dist/adapters/nitro.js.map +1 -1
  62. package/dist/cache/cache-api.d.ts +24 -0
  63. package/dist/cache/cache-api.d.ts.map +1 -0
  64. package/dist/cache/handler-store.d.ts +31 -0
  65. package/dist/cache/handler-store.d.ts.map +1 -0
  66. package/dist/cache/index.d.ts +23 -7
  67. package/dist/cache/index.d.ts.map +1 -1
  68. package/dist/cache/index.js +142 -80
  69. package/dist/cache/index.js.map +1 -1
  70. package/dist/cache/singleflight.d.ts +18 -1
  71. package/dist/cache/singleflight.d.ts.map +1 -1
  72. package/dist/cache/sizeof.d.ts +22 -0
  73. package/dist/cache/sizeof.d.ts.map +1 -0
  74. package/dist/cache/timber-cache.d.ts +1 -1
  75. package/dist/cache/timber-cache.d.ts.map +1 -1
  76. package/dist/cli.d.ts +6 -1
  77. package/dist/cli.d.ts.map +1 -1
  78. package/dist/cli.js +6 -1
  79. package/dist/cli.js.map +1 -1
  80. package/dist/client/browser-dev.d.ts +27 -1
  81. package/dist/client/browser-dev.d.ts.map +1 -1
  82. package/dist/client/browser-entry/action-dispatch.d.ts +17 -0
  83. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -0
  84. package/dist/client/browser-entry/hmr.d.ts +21 -0
  85. package/dist/client/browser-entry/hmr.d.ts.map +1 -0
  86. package/dist/client/browser-entry/hydrate.d.ts +46 -0
  87. package/dist/client/browser-entry/hydrate.d.ts.map +1 -0
  88. package/dist/client/browser-entry/index.d.ts +30 -0
  89. package/dist/client/browser-entry/index.d.ts.map +1 -0
  90. package/dist/client/browser-entry/post-hydration.d.ts +26 -0
  91. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -0
  92. package/dist/client/browser-entry/router-init.d.ts +23 -0
  93. package/dist/client/browser-entry/router-init.d.ts.map +1 -0
  94. package/dist/client/browser-entry/rsc-stream.d.ts +24 -0
  95. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -0
  96. package/dist/client/browser-entry/scroll.d.ts +19 -0
  97. package/dist/client/browser-entry/scroll.d.ts.map +1 -0
  98. package/dist/client/error-boundary.d.ts +12 -5
  99. package/dist/client/error-boundary.d.ts.map +1 -1
  100. package/dist/client/error-boundary.js +10 -4
  101. package/dist/client/error-boundary.js.map +1 -1
  102. package/dist/client/error-reconstituter.d.ts +54 -0
  103. package/dist/client/error-reconstituter.d.ts.map +1 -0
  104. package/dist/client/form.d.ts +2 -2
  105. package/dist/client/form.d.ts.map +1 -1
  106. package/dist/client/history.d.ts +19 -4
  107. package/dist/client/history.d.ts.map +1 -1
  108. package/dist/client/index.d.ts +7 -21
  109. package/dist/client/index.d.ts.map +1 -1
  110. package/dist/client/index.js +210 -1017
  111. package/dist/client/index.js.map +1 -1
  112. package/dist/client/internal.d.ts +18 -0
  113. package/dist/client/internal.d.ts.map +1 -0
  114. package/dist/client/internal.js +890 -0
  115. package/dist/client/internal.js.map +1 -0
  116. package/dist/client/link-pending-store.d.ts +63 -0
  117. package/dist/client/link-pending-store.d.ts.map +1 -0
  118. package/dist/client/link.d.ts +90 -32
  119. package/dist/client/link.d.ts.map +1 -1
  120. package/dist/client/nav-link-store.d.ts +36 -0
  121. package/dist/client/nav-link-store.d.ts.map +1 -0
  122. package/dist/client/navigation-api-types.d.ts +90 -0
  123. package/dist/client/navigation-api-types.d.ts.map +1 -0
  124. package/dist/client/navigation-api.d.ts +115 -0
  125. package/dist/client/navigation-api.d.ts.map +1 -0
  126. package/dist/client/navigation-context.d.ts +13 -2
  127. package/dist/client/navigation-context.d.ts.map +1 -1
  128. package/dist/client/{transition-root.d.ts → navigation-root.d.ts} +42 -8
  129. package/dist/client/navigation-root.d.ts.map +1 -0
  130. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  131. package/dist/client/router-ref.d.ts +1 -1
  132. package/dist/client/router.d.ts +70 -4
  133. package/dist/client/router.d.ts.map +1 -1
  134. package/dist/client/rsc-fetch.d.ts +38 -3
  135. package/dist/client/rsc-fetch.d.ts.map +1 -1
  136. package/dist/client/segment-cache.d.ts +1 -1
  137. package/dist/client/segment-cache.d.ts.map +1 -1
  138. package/dist/client/segment-outlet.d.ts +63 -0
  139. package/dist/client/segment-outlet.d.ts.map +1 -0
  140. package/dist/client/ssr-data.d.ts +13 -4
  141. package/dist/client/ssr-data.d.ts.map +1 -1
  142. package/dist/client/stale-reload.d.ts +15 -0
  143. package/dist/client/stale-reload.d.ts.map +1 -1
  144. package/dist/client/top-loader.d.ts +5 -5
  145. package/dist/client/top-loader.d.ts.map +1 -1
  146. package/dist/client/use-link-status.d.ts +5 -5
  147. package/dist/client/use-link-status.d.ts.map +1 -1
  148. package/dist/client/use-params.d.ts +6 -4
  149. package/dist/client/use-params.d.ts.map +1 -1
  150. package/dist/client/{use-navigation-pending.d.ts → use-pending-navigation.d.ts} +4 -4
  151. package/dist/client/use-pending-navigation.d.ts.map +1 -0
  152. package/dist/client/use-query-states.d.ts +1 -1
  153. package/dist/client/use-query-states.d.ts.map +1 -1
  154. package/dist/client/use-router.d.ts +1 -1
  155. package/dist/codec.d.ts +33 -0
  156. package/dist/codec.d.ts.map +1 -0
  157. package/dist/codec.js +2 -0
  158. package/dist/config-types.d.ts +210 -0
  159. package/dist/config-types.d.ts.map +1 -0
  160. package/dist/content/index.d.ts +1 -10
  161. package/dist/content/index.d.ts.map +1 -1
  162. package/dist/content/index.js +0 -2
  163. package/dist/cookies/define-cookie.d.ts +35 -14
  164. package/dist/cookies/define-cookie.d.ts.map +1 -1
  165. package/dist/cookies/index.js +1 -83
  166. package/dist/fonts/css.d.ts +1 -0
  167. package/dist/fonts/css.d.ts.map +1 -1
  168. package/dist/index.d.ts +45 -192
  169. package/dist/index.d.ts.map +1 -1
  170. package/dist/index.js +12296 -11901
  171. package/dist/index.js.map +1 -1
  172. package/dist/plugin-context.d.ts +84 -0
  173. package/dist/plugin-context.d.ts.map +1 -0
  174. package/dist/plugins/adapter-build.d.ts +1 -1
  175. package/dist/plugins/adapter-build.d.ts.map +1 -1
  176. package/dist/plugins/build-manifest.d.ts +2 -2
  177. package/dist/plugins/build-manifest.d.ts.map +1 -1
  178. package/dist/plugins/build-report.d.ts +3 -3
  179. package/dist/plugins/build-report.d.ts.map +1 -1
  180. package/dist/plugins/client-chunks.d.ts +32 -0
  181. package/dist/plugins/client-chunks.d.ts.map +1 -0
  182. package/dist/plugins/content.d.ts +1 -1
  183. package/dist/plugins/content.d.ts.map +1 -1
  184. package/dist/plugins/dev-browser-logs.d.ts +84 -0
  185. package/dist/plugins/dev-browser-logs.d.ts.map +1 -0
  186. package/dist/plugins/dev-error-overlay.d.ts +26 -1
  187. package/dist/plugins/dev-error-overlay.d.ts.map +1 -1
  188. package/dist/plugins/dev-logs.d.ts +1 -1
  189. package/dist/plugins/dev-logs.d.ts.map +1 -1
  190. package/dist/plugins/dev-server.d.ts +1 -1
  191. package/dist/plugins/dev-server.d.ts.map +1 -1
  192. package/dist/plugins/entries.d.ts +1 -1
  193. package/dist/plugins/entries.d.ts.map +1 -1
  194. package/dist/plugins/fonts.d.ts +19 -5
  195. package/dist/plugins/fonts.d.ts.map +1 -1
  196. package/dist/plugins/mdx.d.ts +1 -1
  197. package/dist/plugins/mdx.d.ts.map +1 -1
  198. package/dist/plugins/routing.d.ts +1 -1
  199. package/dist/plugins/routing.d.ts.map +1 -1
  200. package/dist/plugins/server-bundle.d.ts.map +1 -1
  201. package/dist/plugins/shims.d.ts +6 -5
  202. package/dist/plugins/shims.d.ts.map +1 -1
  203. package/dist/plugins/static-build.d.ts +4 -4
  204. package/dist/plugins/static-build.d.ts.map +1 -1
  205. package/dist/routing/codegen.d.ts +2 -2
  206. package/dist/routing/codegen.d.ts.map +1 -1
  207. package/dist/routing/index.d.ts +2 -0
  208. package/dist/routing/index.d.ts.map +1 -1
  209. package/dist/routing/index.js +3 -2
  210. package/dist/routing/scanner.d.ts.map +1 -1
  211. package/dist/routing/segment-classify.d.ts +46 -0
  212. package/dist/routing/segment-classify.d.ts.map +1 -0
  213. package/dist/routing/status-file-lint.d.ts +2 -1
  214. package/dist/routing/status-file-lint.d.ts.map +1 -1
  215. package/dist/routing/types.d.ts +16 -4
  216. package/dist/routing/types.d.ts.map +1 -1
  217. package/dist/rsc-runtime/rsc.d.ts +1 -1
  218. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  219. package/dist/rsc-runtime/ssr.d.ts +12 -0
  220. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  221. package/dist/schema-bridge.d.ts +76 -0
  222. package/dist/schema-bridge.d.ts.map +1 -0
  223. package/dist/search-params/define.d.ts +139 -0
  224. package/dist/search-params/define.d.ts.map +1 -0
  225. package/dist/search-params/index.d.ts +4 -7
  226. package/dist/search-params/index.d.ts.map +1 -1
  227. package/dist/search-params/index.js +4 -474
  228. package/dist/search-params/registry.d.ts +2 -2
  229. package/dist/search-params/registry.d.ts.map +1 -1
  230. package/dist/search-params/wrappers.d.ts +53 -0
  231. package/dist/search-params/wrappers.d.ts.map +1 -0
  232. package/dist/segment-params/define.d.ts +78 -0
  233. package/dist/segment-params/define.d.ts.map +1 -0
  234. package/dist/segment-params/index.d.ts +6 -0
  235. package/dist/segment-params/index.d.ts.map +1 -0
  236. package/dist/segment-params/index.js +4 -0
  237. package/dist/server/access-gate.d.ts +4 -0
  238. package/dist/server/access-gate.d.ts.map +1 -1
  239. package/dist/server/action-client.d.ts +12 -1
  240. package/dist/server/action-client.d.ts.map +1 -1
  241. package/dist/server/action-encryption.d.ts +76 -0
  242. package/dist/server/action-encryption.d.ts.map +1 -0
  243. package/dist/server/action-handler.d.ts.map +1 -1
  244. package/dist/server/actions.d.ts +3 -6
  245. package/dist/server/actions.d.ts.map +1 -1
  246. package/dist/server/als-registry.d.ts +32 -4
  247. package/dist/server/als-registry.d.ts.map +1 -1
  248. package/dist/server/build-manifest.d.ts +2 -2
  249. package/dist/server/build-manifest.d.ts.map +1 -1
  250. package/dist/server/debug.d.ts +1 -1
  251. package/dist/server/default-logger.d.ts +22 -0
  252. package/dist/server/default-logger.d.ts.map +1 -0
  253. package/dist/server/deny-page-resolver.d.ts +52 -0
  254. package/dist/server/deny-page-resolver.d.ts.map +1 -0
  255. package/dist/server/deny-renderer.d.ts.map +1 -1
  256. package/dist/server/dev-holding-server.d.ts +52 -0
  257. package/dist/server/dev-holding-server.d.ts.map +1 -0
  258. package/dist/server/dev-warnings.d.ts +1 -21
  259. package/dist/server/dev-warnings.d.ts.map +1 -1
  260. package/dist/server/early-hints.d.ts +13 -5
  261. package/dist/server/early-hints.d.ts.map +1 -1
  262. package/dist/server/error-boundary-wrapper.d.ts +7 -1
  263. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  264. package/dist/server/fallback-error.d.ts +4 -3
  265. package/dist/server/fallback-error.d.ts.map +1 -1
  266. package/dist/server/flight-injection-state.d.ts +66 -0
  267. package/dist/server/flight-injection-state.d.ts.map +1 -0
  268. package/dist/server/flight-scripts.d.ts +42 -0
  269. package/dist/server/flight-scripts.d.ts.map +1 -0
  270. package/dist/server/flush.d.ts.map +1 -1
  271. package/dist/server/form-data.d.ts +29 -0
  272. package/dist/server/form-data.d.ts.map +1 -1
  273. package/dist/server/html-injectors.d.ts +51 -11
  274. package/dist/server/html-injectors.d.ts.map +1 -1
  275. package/dist/server/index.d.ts +6 -43
  276. package/dist/server/index.d.ts.map +1 -1
  277. package/dist/server/index.js +38 -2798
  278. package/dist/server/index.js.map +1 -1
  279. package/dist/server/internal.d.ts +46 -0
  280. package/dist/server/internal.d.ts.map +1 -0
  281. package/dist/server/internal.js +2883 -0
  282. package/dist/server/internal.js.map +1 -0
  283. package/dist/server/logger.d.ts +25 -7
  284. package/dist/server/logger.d.ts.map +1 -1
  285. package/dist/server/middleware-runner.d.ts +19 -4
  286. package/dist/server/middleware-runner.d.ts.map +1 -1
  287. package/dist/server/node-stream-transforms.d.ts +113 -0
  288. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  289. package/dist/server/page-deny-boundary.d.ts +31 -0
  290. package/dist/server/page-deny-boundary.d.ts.map +1 -0
  291. package/dist/server/pipeline-interception.d.ts +1 -1
  292. package/dist/server/pipeline-interception.d.ts.map +1 -1
  293. package/dist/server/pipeline-metadata.d.ts +6 -0
  294. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  295. package/dist/server/pipeline.d.ts +42 -10
  296. package/dist/server/pipeline.d.ts.map +1 -1
  297. package/dist/server/primitives.d.ts +69 -18
  298. package/dist/server/primitives.d.ts.map +1 -1
  299. package/dist/server/render-timeout.d.ts +51 -0
  300. package/dist/server/render-timeout.d.ts.map +1 -0
  301. package/dist/server/request-context.d.ts +112 -43
  302. package/dist/server/request-context.d.ts.map +1 -1
  303. package/dist/server/route-element-builder.d.ts +27 -1
  304. package/dist/server/route-element-builder.d.ts.map +1 -1
  305. package/dist/server/route-handler.d.ts.map +1 -1
  306. package/dist/server/route-matcher.d.ts +9 -2
  307. package/dist/server/route-matcher.d.ts.map +1 -1
  308. package/dist/server/rsc-entry/api-handler.d.ts +2 -2
  309. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  310. package/dist/server/rsc-entry/error-renderer.d.ts +26 -13
  311. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  312. package/dist/server/rsc-entry/helpers.d.ts +48 -5
  313. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  314. package/dist/server/rsc-entry/index.d.ts +8 -3
  315. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  316. package/dist/server/rsc-entry/rsc-payload.d.ts +3 -3
  317. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  318. package/dist/server/rsc-entry/rsc-stream.d.ts +4 -1
  319. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  320. package/dist/server/rsc-entry/ssr-bridge.d.ts +1 -1
  321. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  322. package/dist/server/rsc-entry/ssr-renderer.d.ts +19 -4
  323. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  324. package/dist/server/safe-load.d.ts +46 -0
  325. package/dist/server/safe-load.d.ts.map +1 -0
  326. package/dist/server/sitemap-generator.d.ts +129 -0
  327. package/dist/server/sitemap-generator.d.ts.map +1 -0
  328. package/dist/server/sitemap-handler.d.ts +22 -0
  329. package/dist/server/sitemap-handler.d.ts.map +1 -0
  330. package/dist/server/slot-resolver.d.ts +1 -1
  331. package/dist/server/slot-resolver.d.ts.map +1 -1
  332. package/dist/server/ssr-entry.d.ts +22 -0
  333. package/dist/server/ssr-entry.d.ts.map +1 -1
  334. package/dist/server/ssr-render.d.ts +39 -21
  335. package/dist/server/ssr-render.d.ts.map +1 -1
  336. package/dist/server/ssr-wrappers.d.ts +50 -0
  337. package/dist/server/ssr-wrappers.d.ts.map +1 -0
  338. package/dist/server/status-code-resolver.d.ts +1 -1
  339. package/dist/server/status-code-resolver.d.ts.map +1 -1
  340. package/dist/server/stream-utils.d.ts +36 -0
  341. package/dist/server/stream-utils.d.ts.map +1 -0
  342. package/dist/server/tracing.d.ts +4 -4
  343. package/dist/server/tracing.d.ts.map +1 -1
  344. package/dist/server/tree-builder.d.ts +22 -19
  345. package/dist/server/tree-builder.d.ts.map +1 -1
  346. package/dist/server/types.d.ts +1 -4
  347. package/dist/server/types.d.ts.map +1 -1
  348. package/dist/server/version-skew.d.ts +61 -0
  349. package/dist/server/version-skew.d.ts.map +1 -0
  350. package/dist/shared/merge-search-params.d.ts +22 -0
  351. package/dist/shared/merge-search-params.d.ts.map +1 -0
  352. package/dist/shims/font-google.d.ts +1 -1
  353. package/dist/shims/font-google.d.ts.map +1 -1
  354. package/dist/shims/font-google.js +42 -0
  355. package/dist/shims/font-google.js.map +1 -0
  356. package/dist/shims/font-local.d.ts +26 -0
  357. package/dist/shims/font-local.d.ts.map +1 -0
  358. package/dist/shims/font-local.js +20 -0
  359. package/dist/shims/font-local.js.map +1 -0
  360. package/dist/shims/headers.d.ts +2 -1
  361. package/dist/shims/headers.d.ts.map +1 -1
  362. package/dist/shims/navigation-client.d.ts +1 -1
  363. package/dist/shims/navigation-client.d.ts.map +1 -1
  364. package/dist/shims/navigation.d.ts +3 -2
  365. package/dist/shims/navigation.d.ts.map +1 -1
  366. package/dist/utils/directive-parser.d.ts +5 -2
  367. package/dist/utils/directive-parser.d.ts.map +1 -1
  368. package/dist/utils/state-machine.d.ts +80 -0
  369. package/dist/utils/state-machine.d.ts.map +1 -0
  370. package/package.json +53 -23
  371. package/src/adapters/cloudflare-dev.ts +177 -0
  372. package/src/adapters/cloudflare-kv-cache.ts +142 -0
  373. package/src/adapters/cloudflare.ts +342 -28
  374. package/src/adapters/compress-module.ts +24 -4
  375. package/src/adapters/nitro.ts +52 -8
  376. package/src/adapters/wrangler.d.ts +7 -0
  377. package/src/cache/cache-api.ts +38 -0
  378. package/src/cache/handler-store.ts +68 -0
  379. package/src/cache/index.ts +81 -18
  380. package/src/cache/singleflight.ts +62 -4
  381. package/src/cache/sizeof.ts +31 -0
  382. package/src/cache/timber-cache.ts +24 -20
  383. package/src/cli.ts +6 -1
  384. package/src/client/browser-dev.ts +128 -1
  385. package/src/client/browser-entry/action-dispatch.ts +116 -0
  386. package/src/client/browser-entry/hmr.ts +81 -0
  387. package/src/client/browser-entry/hydrate.ts +145 -0
  388. package/src/client/browser-entry/index.ts +138 -0
  389. package/src/client/browser-entry/post-hydration.ts +119 -0
  390. package/src/client/browser-entry/router-init.ts +193 -0
  391. package/src/client/browser-entry/rsc-stream.ts +157 -0
  392. package/src/client/browser-entry/scroll.ts +27 -0
  393. package/src/client/error-boundary.tsx +48 -16
  394. package/src/client/error-reconstituter.tsx +65 -0
  395. package/src/client/form.tsx +2 -2
  396. package/src/client/history.ts +26 -4
  397. package/src/client/index.ts +19 -38
  398. package/src/client/internal.ts +57 -0
  399. package/src/client/link-pending-store.ts +111 -0
  400. package/src/client/link.tsx +329 -97
  401. package/src/client/nav-link-store.ts +47 -0
  402. package/src/client/navigation-api-types.ts +112 -0
  403. package/src/client/navigation-api.ts +332 -0
  404. package/src/client/navigation-context.ts +31 -6
  405. package/src/client/navigation-root.tsx +342 -0
  406. package/src/client/nuqs-adapter.tsx +16 -3
  407. package/src/client/router-ref.ts +1 -1
  408. package/src/client/router.ts +299 -72
  409. package/src/client/rsc-fetch.ts +97 -8
  410. package/src/client/segment-cache.ts +1 -1
  411. package/src/client/segment-outlet.tsx +86 -0
  412. package/src/client/ssr-data.ts +13 -5
  413. package/src/client/stale-reload.ts +72 -3
  414. package/src/client/top-loader.tsx +16 -8
  415. package/src/client/use-link-status.ts +7 -7
  416. package/src/client/use-params.ts +7 -5
  417. package/src/client/{use-navigation-pending.ts → use-pending-navigation.ts} +6 -6
  418. package/src/client/use-query-states.ts +3 -3
  419. package/src/client/use-router.ts +1 -1
  420. package/src/codec.ts +49 -0
  421. package/src/config-types.ts +208 -0
  422. package/src/content/index.ts +5 -13
  423. package/src/cookies/define-cookie.ts +78 -25
  424. package/src/cookies/index.ts +8 -0
  425. package/src/fonts/css.ts +2 -1
  426. package/src/index.ts +258 -354
  427. package/src/plugin-context.ts +200 -0
  428. package/src/plugins/adapter-build.ts +8 -2
  429. package/src/plugins/build-manifest.ts +13 -2
  430. package/src/plugins/build-report.ts +3 -3
  431. package/src/plugins/client-chunks.ts +65 -0
  432. package/src/plugins/content.ts +1 -1
  433. package/src/plugins/dev-browser-logs.ts +288 -0
  434. package/src/plugins/dev-error-overlay.ts +70 -1
  435. package/src/plugins/dev-logs.ts +1 -1
  436. package/src/plugins/dev-server.ts +70 -9
  437. package/src/plugins/entries.ts +71 -10
  438. package/src/plugins/fonts.ts +168 -61
  439. package/src/plugins/mdx.ts +1 -1
  440. package/src/plugins/routing.ts +57 -17
  441. package/src/plugins/server-action-exports.ts +1 -1
  442. package/src/plugins/server-bundle.ts +32 -1
  443. package/src/plugins/shims.ts +135 -35
  444. package/src/plugins/static-build.ts +17 -11
  445. package/src/routing/codegen.ts +165 -105
  446. package/src/routing/index.ts +2 -0
  447. package/src/routing/scanner.ts +93 -23
  448. package/src/routing/segment-classify.ts +89 -0
  449. package/src/routing/status-file-lint.ts +3 -2
  450. package/src/routing/types.ts +17 -4
  451. package/src/rsc-runtime/rsc.ts +2 -0
  452. package/src/rsc-runtime/ssr.ts +50 -0
  453. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  454. package/src/{search-params/codecs.ts → schema-bridge.ts} +57 -20
  455. package/src/search-params/define.ts +482 -0
  456. package/src/search-params/index.ts +14 -20
  457. package/src/search-params/registry.ts +2 -2
  458. package/src/search-params/wrappers.ts +85 -0
  459. package/src/segment-params/define.ts +279 -0
  460. package/src/segment-params/index.ts +29 -0
  461. package/src/server/access-gate.tsx +70 -29
  462. package/src/server/action-client.ts +21 -2
  463. package/src/server/action-encryption.ts +144 -0
  464. package/src/server/action-handler.ts +21 -4
  465. package/src/server/actions.ts +10 -9
  466. package/src/server/als-registry.ts +34 -6
  467. package/src/server/build-manifest.ts +10 -4
  468. package/src/server/compress.ts +25 -7
  469. package/src/server/debug.ts +1 -1
  470. package/src/server/default-logger.ts +99 -0
  471. package/src/server/deny-page-resolver.ts +154 -0
  472. package/src/server/deny-renderer.ts +24 -38
  473. package/src/server/dev-holding-server.ts +185 -0
  474. package/src/server/dev-warnings.ts +4 -49
  475. package/src/server/early-hints.ts +36 -15
  476. package/src/server/error-boundary-wrapper.ts +74 -22
  477. package/src/server/fallback-error.ts +31 -15
  478. package/src/server/flight-injection-state.ts +113 -0
  479. package/src/server/flight-scripts.ts +62 -0
  480. package/src/server/flush.ts +2 -1
  481. package/src/server/form-data.ts +76 -0
  482. package/src/server/html-injectors.ts +280 -120
  483. package/src/server/index.ts +26 -177
  484. package/src/server/internal.ts +169 -0
  485. package/src/server/logger.ts +44 -36
  486. package/src/server/middleware-runner.ts +31 -4
  487. package/src/server/node-stream-transforms.ts +509 -0
  488. package/src/server/page-deny-boundary.tsx +56 -0
  489. package/src/server/pipeline-interception.ts +17 -16
  490. package/src/server/pipeline-metadata.ts +13 -0
  491. package/src/server/pipeline.ts +227 -62
  492. package/src/server/primitives.ts +111 -28
  493. package/src/server/render-timeout.ts +108 -0
  494. package/src/server/request-context.ts +293 -132
  495. package/src/server/route-element-builder.ts +283 -191
  496. package/src/server/route-handler.ts +24 -4
  497. package/src/server/route-matcher.ts +24 -20
  498. package/src/server/rsc-entry/api-handler.ts +15 -16
  499. package/src/server/rsc-entry/error-renderer.ts +300 -89
  500. package/src/server/rsc-entry/helpers.ts +134 -5
  501. package/src/server/rsc-entry/index.ts +200 -112
  502. package/src/server/rsc-entry/rsc-payload.ts +65 -18
  503. package/src/server/rsc-entry/rsc-stream.ts +65 -13
  504. package/src/server/rsc-entry/ssr-bridge.ts +14 -5
  505. package/src/server/rsc-entry/ssr-renderer.ts +168 -38
  506. package/src/server/safe-load.ts +60 -0
  507. package/src/server/sitemap-generator.ts +338 -0
  508. package/src/server/sitemap-handler.ts +126 -0
  509. package/src/server/slot-resolver.ts +244 -229
  510. package/src/server/ssr-entry.ts +211 -32
  511. package/src/server/ssr-render.ts +289 -67
  512. package/src/server/ssr-wrappers.tsx +139 -0
  513. package/src/server/status-code-resolver.ts +1 -1
  514. package/src/server/stream-utils.ts +213 -0
  515. package/src/server/tracing.ts +20 -9
  516. package/src/server/tree-builder.ts +92 -58
  517. package/src/server/types.ts +3 -6
  518. package/src/server/version-skew.ts +104 -0
  519. package/src/shared/merge-search-params.ts +55 -0
  520. package/src/shims/font-google.ts +1 -1
  521. package/src/shims/font-local.ts +34 -0
  522. package/src/shims/headers.ts +5 -1
  523. package/src/shims/navigation-client.ts +1 -1
  524. package/src/shims/navigation.ts +7 -2
  525. package/src/utils/directive-parser.ts +5 -2
  526. package/src/utils/state-machine.ts +111 -0
  527. package/dist/_chunks/als-registry-B7DbZ2hS.js.map +0 -1
  528. package/dist/_chunks/debug-gwlJkDuf.js.map +0 -1
  529. package/dist/_chunks/format-DviM89f0.js.map +0 -1
  530. package/dist/_chunks/interception-BOoWmLUA.js.map +0 -1
  531. package/dist/_chunks/request-context-DIkVh_jG.js +0 -330
  532. package/dist/_chunks/request-context-DIkVh_jG.js.map +0 -1
  533. package/dist/_chunks/tracing-CemImE6h.js.map +0 -1
  534. package/dist/_chunks/use-cookie-DX-l1_5E.js +0 -91
  535. package/dist/_chunks/use-cookie-DX-l1_5E.js.map +0 -1
  536. package/dist/_chunks/use-query-states-D5KaffOK.js.map +0 -1
  537. package/dist/cache/register-cached-function.d.ts +0 -17
  538. package/dist/cache/register-cached-function.d.ts.map +0 -1
  539. package/dist/client/browser-entry.d.ts +0 -21
  540. package/dist/client/browser-entry.d.ts.map +0 -1
  541. package/dist/client/link-status-provider.d.ts +0 -11
  542. package/dist/client/link-status-provider.d.ts.map +0 -1
  543. package/dist/client/transition-root.d.ts.map +0 -1
  544. package/dist/client/use-navigation-pending.d.ts.map +0 -1
  545. package/dist/cookies/index.js.map +0 -1
  546. package/dist/plugins/cache-transform.d.ts +0 -36
  547. package/dist/plugins/cache-transform.d.ts.map +0 -1
  548. package/dist/plugins/dynamic-transform.d.ts +0 -72
  549. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  550. package/dist/search-params/analyze.d.ts +0 -54
  551. package/dist/search-params/analyze.d.ts.map +0 -1
  552. package/dist/search-params/builtin-codecs.d.ts +0 -105
  553. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  554. package/dist/search-params/codecs.d.ts +0 -53
  555. package/dist/search-params/codecs.d.ts.map +0 -1
  556. package/dist/search-params/create.d.ts +0 -106
  557. package/dist/search-params/create.d.ts.map +0 -1
  558. package/dist/search-params/index.js.map +0 -1
  559. package/dist/server/prerender.d.ts +0 -77
  560. package/dist/server/prerender.d.ts.map +0 -1
  561. package/dist/server/response-cache.d.ts +0 -54
  562. package/dist/server/response-cache.d.ts.map +0 -1
  563. package/src/cache/register-cached-function.ts +0 -103
  564. package/src/client/browser-entry.ts +0 -678
  565. package/src/client/link-status-provider.tsx +0 -30
  566. package/src/client/transition-root.tsx +0 -166
  567. package/src/plugins/cache-transform.ts +0 -199
  568. package/src/plugins/dynamic-transform.ts +0 -161
  569. package/src/search-params/analyze.ts +0 -192
  570. package/src/search-params/builtin-codecs.ts +0 -228
  571. package/src/search-params/create.ts +0 -321
  572. package/src/server/prerender.ts +0 -139
  573. package/src/server/response-cache.ts +0 -410
@@ -1,2592 +1,10 @@
1
- import { n as isDevMode, t as isDebug } from "../_chunks/debug-gwlJkDuf.js";
2
- import { a as warnDenyAfterFlush, c as warnRedirectInAccess, d as warnSlowSlotWithoutSuspense, f as warnStaticRequestApi, i as warnCacheRequestProps, l as warnRedirectInSlotAccess, n as WarningId, o as warnDenyInSuspense, p as warnSuspenseWrappingChildren, r as setViteServer, s as warnDynamicApiInStaticBuild, t as formatSize, u as warnRedirectInSuspense } from "../_chunks/format-DviM89f0.js";
3
- import { i as getMetadataRouteServePath, n as classifyMetadataRoute, r as getMetadataRouteAutoLink, t as METADATA_ROUTE_CONVENTIONS } from "../_chunks/metadata-routes-Cjmvi3rQ.js";
4
- import { a as timingAls, i as revalidationAls, n as formFlashAls, s as waitUntilAls, t as earlyHintsSenderAls } from "../_chunks/als-registry-B7DbZ2hS.js";
5
- import { a as markResponseFlushed, c as setCookieSecrets, i as headers, l as setMutableCookieContext, n as cookies, o as runWithRequestContext, r as getSetCookieHeaders, s as searchParams, t as applyRequestHeaderOverlay, u as setParsedSearchParams } from "../_chunks/request-context-DIkVh_jG.js";
6
- import { a as getTraceStore, c as setSpanAttribute, d as withSpan, i as getOtelTraceId, l as spanId, o as replaceTraceId, r as generateTraceId, s as runWithTraceId, t as addSpanEvent, u as traceId } from "../_chunks/tracing-CemImE6h.js";
7
- import { readFile } from "node:fs/promises";
8
- //#region src/server/waituntil-bridge.ts
9
- /**
10
- * Per-request waitUntil bridge — ALS bridge for platform adapters.
11
- *
12
- * The generated entry point (Nitro, Cloudflare) wraps the handler with
13
- * `runWithWaitUntil`, binding the platform's lifecycle extension function
14
- * (e.g., h3's `event.waitUntil()` or CF's `ctx.waitUntil()`) for the
15
- * request duration. The `waitUntil()` primitive reads from this ALS to
16
- * dispatch background work to the correct platform API.
17
- *
18
- * Design doc: design/11-platform.md §"waitUntil()"
19
- */
20
- /**
21
- * Get the current request's waitUntil function, if available.
22
- *
23
- * Returns undefined when no platform adapter has installed a waitUntil
24
- * handler for the current request (e.g., on platforms that don't support
25
- * lifecycle extension, or outside a request context).
26
- */
27
- function getWaitUntil() {
28
- return waitUntilAls.getStore();
29
- }
30
- //#endregion
31
- //#region src/server/primitives.ts
32
- /**
33
- * Check if a value is JSON-serializable without data loss.
34
- * Returns a description of the first non-serializable value found, or null if OK.
35
- *
36
- * @internal Exported for testing only.
37
- */
38
- function findNonSerializable(value, path = "data") {
39
- if (value === null || value === void 0) return null;
40
- switch (typeof value) {
41
- case "string":
42
- case "number":
43
- case "boolean": return null;
44
- case "bigint": return `${path} contains a BigInt — BigInt throws in JSON.stringify`;
45
- case "function": return `${path} is a function — functions are not JSON-serializable`;
46
- case "symbol": return `${path} is a symbol — symbols are not JSON-serializable`;
47
- case "object": break;
48
- default: return `${path} has unsupported type "${typeof value}"`;
49
- }
50
- if (value instanceof Date) return `${path} is a Date — Dates silently coerce to strings in JSON.stringify`;
51
- if (value instanceof Map) return `${path} is a Map — Maps serialize as {} in JSON.stringify (data loss)`;
52
- if (value instanceof Set) return `${path} is a Set — Sets serialize as {} in JSON.stringify (data loss)`;
53
- if (value instanceof RegExp) return `${path} is a RegExp — RegExps serialize as {} in JSON.stringify`;
54
- if (value instanceof Error) return `${path} is an Error — Errors serialize as {} in JSON.stringify`;
55
- if (Array.isArray(value)) {
56
- for (let i = 0; i < value.length; i++) {
57
- const result = findNonSerializable(value[i], `${path}[${i}]`);
58
- if (result) return result;
59
- }
60
- return null;
61
- }
62
- const proto = Object.getPrototypeOf(value);
63
- if (proto === null) return `${path} is a null-prototype object — React Flight rejects null prototypes`;
64
- if (proto !== Object.prototype) return `${path} is a ${value.constructor?.name ?? "unknown"} instance — class instances may lose data in JSON.stringify`;
65
- for (const key of Object.keys(value)) {
66
- const result = findNonSerializable(value[key], `${path}.${key}`);
67
- if (result) return result;
68
- }
69
- return null;
70
- }
71
- /**
72
- * Emit a dev-mode warning if data is not JSON-serializable.
73
- * No-op in production.
74
- */
75
- function warnIfNotSerializable(data, callerName) {
76
- if (!isDebug()) return;
77
- if (data === void 0) return;
78
- const issue = findNonSerializable(data);
79
- if (issue) console.warn(`[timber] ${callerName}: ${issue}. Data passed to deny() or RenderError must be JSON-serializable because the post-flush path uses JSON.stringify, not React Flight.`);
80
- }
81
- /**
82
- * Render-phase signal thrown by `deny()`. Caught by the framework to produce
83
- * the correct HTTP status code (segment context) or graceful degradation (slot context).
84
- */
85
- var DenySignal = class extends Error {
86
- status;
87
- data;
88
- constructor(status, data) {
89
- super(`Access denied with status ${status}`);
90
- this.name = "DenySignal";
91
- this.status = status;
92
- this.data = data;
93
- }
94
- /**
95
- * Extract the file that called deny() from the stack trace.
96
- * Returns a short path (e.g. "app/auth/access.ts") or undefined if
97
- * the stack can't be parsed. Dev-only — used for dev log output.
98
- */
99
- get sourceFile() {
100
- if (!this.stack) return void 0;
101
- const frames = this.stack.split("\n");
102
- for (let i = 2; i < frames.length; i++) {
103
- const frame = frames[i];
104
- if (!frame) continue;
105
- if (frame.includes("primitives.ts") || frame.includes("node_modules")) continue;
106
- const match = frame.match(/\(([^)]+?)(?::\d+:\d+)\)/) ?? frame.match(/at\s+([^\s]+?)(?::\d+:\d+)/);
107
- if (match?.[1]) {
108
- const full = match[1];
109
- const appIdx = full.indexOf("/app/");
110
- return appIdx >= 0 ? full.slice(appIdx + 1) : full;
111
- }
112
- }
113
- }
114
- };
115
- /**
116
- * Universal denial primitive. Throws a `DenySignal` that the framework catches.
117
- *
118
- * - In segment context (outside Suspense): produces HTTP status code
119
- * - In slot context: graceful degradation → denied.tsx → default.tsx → null
120
- * - Inside Suspense (hold window): promoted to pre-flush behavior
121
- * - Inside Suspense (after flush): error boundary + noindex meta
122
- *
123
- * @param status - Any 4xx HTTP status code. Defaults to 403.
124
- * @param data - Optional JSON-serializable data passed as `dangerouslyPassData` prop to status-code files.
125
- */
126
- function deny(status = 403, data) {
127
- if (status < 400 || status > 499) throw new Error(`deny() requires a 4xx status code, got ${status}. For 5xx errors, throw a RenderError instead.`);
128
- warnIfNotSerializable(data, "deny()");
129
- throw new DenySignal(status, data);
130
- }
131
- /**
132
- * Convenience alias for `deny(404)`.
133
- *
134
- * Provided for Next.js API compatibility — libraries and user code that
135
- * call `notFound()` from `next/navigation` get the same behavior as
136
- * `deny(404)` in timber.
137
- */
138
- function notFound() {
139
- throw new DenySignal(404);
140
- }
141
- /**
142
- * Next.js redirect type discriminator.
143
- *
144
- * Provided for API compatibility with libraries that import `RedirectType`
145
- * from `next/navigation`. In timber, `redirect()` always uses `replace`
146
- * semantics (no history entry for the redirect itself).
147
- */
148
- var RedirectType = {
149
- push: "push",
150
- replace: "replace"
151
- };
152
- /**
153
- * Render-phase signal thrown by `redirect()` and `redirectExternal()`.
154
- * Caught by the framework to produce a 3xx response or client-side navigation.
155
- */
156
- var RedirectSignal = class extends Error {
157
- location;
158
- status;
159
- constructor(location, status) {
160
- super(`Redirect to ${location}`);
161
- this.name = "RedirectSignal";
162
- this.location = location;
163
- this.status = status;
164
- }
165
- };
166
- /** Pattern matching absolute URLs: http(s):// or protocol-relative // */
167
- var ABSOLUTE_URL_RE = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/)/;
168
- /**
169
- * Redirect to a relative path. Rejects absolute and protocol-relative URLs.
170
- * Use `redirectExternal()` for external redirects with an allow-list.
171
- *
172
- * @param path - Relative path (e.g. '/login', 'settings', '/login?returnTo=/dash')
173
- * @param status - HTTP redirect status code (3xx). Defaults to 302.
174
- */
175
- function redirect(path, status = 302) {
176
- if (status < 300 || status > 399) throw new Error(`redirect() requires a 3xx status code, got ${status}.`);
177
- if (ABSOLUTE_URL_RE.test(path)) throw new Error(`redirect() only accepts relative URLs. Got absolute URL: "${path}". Use redirectExternal(url, allowList) for external redirects.`);
178
- throw new RedirectSignal(path, status);
179
- }
180
- /**
181
- * Permanent redirect to a relative path. Shorthand for `redirect(path, 308)`.
182
- *
183
- * Uses 308 (Permanent Redirect) which preserves the HTTP method — the browser
184
- * will replay POST requests to the new location. This matches Next.js behavior.
185
- *
186
- * @param path - Relative path (e.g. '/new-page', '/dashboard')
187
- */
188
- function permanentRedirect(path) {
189
- redirect(path, 308);
190
- }
191
- /**
192
- * Redirect to an external URL. The hostname must be in the provided allow-list.
193
- *
194
- * @param url - Absolute URL to redirect to.
195
- * @param allowList - Array of allowed hostnames (e.g. ['example.com', 'auth.example.com']).
196
- * @param status - HTTP redirect status code (3xx). Defaults to 302.
197
- */
198
- function redirectExternal(url, allowList, status = 302) {
199
- if (status < 300 || status > 399) throw new Error(`redirectExternal() requires a 3xx status code, got ${status}.`);
200
- let hostname;
201
- try {
202
- hostname = new URL(url).hostname;
203
- } catch {
204
- throw new Error(`redirectExternal() received an invalid URL: "${url}"`);
205
- }
206
- if (!allowList.includes(hostname)) throw new Error(`redirectExternal() target "${hostname}" is not in the allow-list. Allowed: [${allowList.join(", ")}]`);
207
- throw new RedirectSignal(url, status);
208
- }
209
- /**
210
- * Typed throw for render-phase errors that carry structured context to error boundaries.
211
- *
212
- * The `digest` (code + data) is serialized into the RSC stream separately from the
213
- * Error instance — only the digest crosses the RSC → client boundary.
214
- *
215
- * @example
216
- * ```ts
217
- * throw new RenderError('PRODUCT_NOT_FOUND', {
218
- * title: 'Product not found',
219
- * resourceId: params.id,
220
- * })
221
- * ```
222
- */
223
- var RenderError = class extends Error {
224
- code;
225
- digest;
226
- status;
227
- constructor(code, data, options) {
228
- super(`RenderError: ${code}`);
229
- this.name = "RenderError";
230
- this.code = code;
231
- this.digest = {
232
- code,
233
- data
234
- };
235
- warnIfNotSerializable(data, "RenderError");
236
- const status = options?.status ?? 500;
237
- if (status < 400 || status > 599) throw new Error(`RenderError status must be 4xx or 5xx, got ${status}.`);
238
- this.status = status;
239
- }
240
- };
241
- var _waitUntilWarned = false;
242
- /**
243
- * Register a promise to be kept alive after the response is sent.
244
- * Maps to `ctx.waitUntil()` on Cloudflare Workers and similar platforms.
245
- *
246
- * In production, the platform adapter installs a per-request waitUntil
247
- * function via ALS (see waituntil-bridge.ts). This function checks the
248
- * ALS bridge first, then falls back to the legacy adapter argument.
249
- *
250
- * If neither is available, a warning is logged once and the promise is
251
- * left to resolve (or reject) without being tracked.
252
- *
253
- * @param promise - The background work to keep alive.
254
- * @param adapter - Optional legacy adapter (prefer ALS bridge in production).
255
- */
256
- function waitUntil(promise, adapter) {
257
- const alsFn = getWaitUntil();
258
- if (alsFn) {
259
- alsFn(promise);
260
- return;
261
- }
262
- if (adapter && typeof adapter.waitUntil === "function") {
263
- adapter.waitUntil(promise);
264
- return;
265
- }
266
- if (!_waitUntilWarned) {
267
- _waitUntilWarned = true;
268
- console.warn("[timber] waitUntil() is not supported by the current adapter. Background work will not be tracked. This warning is shown once.");
269
- }
270
- }
271
- //#endregion
272
- //#region src/server/canonicalize.ts
273
- /**
274
- * Encoded separators that produce a 400 rejection.
275
- * %2f (/) and %5c (\) cause path-confusion attacks.
276
- */
277
- var ENCODED_SEPARATOR_RE = /%2f|%5c/i;
278
- /** Null byte — rejected. */
279
- var NULL_BYTE_RE = /%00/i;
280
- /**
281
- * Canonicalize a URL pathname.
282
- *
283
- * 1. Reject encoded separators (%2f, %5c) and null bytes (%00)
284
- * 2. Single percent-decode
285
- * 3. Collapse // → /
286
- * 4. Resolve .. segments (reject if escaping root)
287
- * 5. Strip trailing slash (except root "/")
288
- *
289
- * @param rawPathname - The raw pathname from the request URL (percent-encoded)
290
- * @param stripTrailingSlash - Whether to strip trailing slashes. Default: true.
291
- */
292
- function canonicalize(rawPathname, stripTrailingSlash = true) {
293
- if (ENCODED_SEPARATOR_RE.test(rawPathname)) return {
294
- ok: false,
295
- status: 400
296
- };
297
- if (NULL_BYTE_RE.test(rawPathname)) return {
298
- ok: false,
299
- status: 400
300
- };
301
- let decoded;
302
- try {
303
- decoded = decodeURIComponent(rawPathname);
304
- } catch {
305
- return {
306
- ok: false,
307
- status: 400
308
- };
309
- }
310
- if (decoded.includes("\0")) return {
311
- ok: false,
312
- status: 400
313
- };
314
- let pathname = decoded.replace(/\/\/+/g, "/");
315
- const segments = pathname.split("/");
316
- const resolved = [];
317
- for (const seg of segments) if (seg === "..") {
318
- if (resolved.length <= 1) return {
319
- ok: false,
320
- status: 400
321
- };
322
- resolved.pop();
323
- } else if (seg !== ".") resolved.push(seg);
324
- pathname = resolved.join("/") || "/";
325
- if (stripTrailingSlash && pathname.length > 1 && pathname.endsWith("/")) pathname = pathname.slice(0, -1);
326
- return {
327
- ok: true,
328
- pathname
329
- };
330
- }
331
- //#endregion
332
- //#region src/server/proxy.ts
333
- /**
334
- * Run the proxy pipeline.
335
- *
336
- * @param proxyExport - The default export from proxy.ts (function or array)
337
- * @param req - The incoming request
338
- * @param next - The continuation that proceeds to route matching and rendering
339
- * @returns The final response
340
- */
341
- async function runProxy(proxyExport, req, next) {
342
- const fns = Array.isArray(proxyExport) ? proxyExport : [proxyExport];
343
- let i = fns.length;
344
- let composed = next;
345
- while (i--) {
346
- const fn = fns[i];
347
- const downstream = composed;
348
- composed = () => Promise.resolve(fn(req, downstream));
349
- }
350
- return composed();
351
- }
352
- //#endregion
353
- //#region src/server/middleware-runner.ts
354
- /**
355
- * Run a route's middleware function.
356
- *
357
- * @param middlewareFn - The default export from the route's middleware.ts
358
- * @param ctx - The middleware context (req, params, headers, requestHeaders, searchParams)
359
- * @returns A Response if middleware short-circuited, or undefined to continue
360
- */
361
- async function runMiddleware(middlewareFn, ctx) {
362
- const result = await middlewareFn(ctx);
363
- if (result instanceof Response) return result;
364
- }
365
- //#endregion
366
- //#region src/server/server-timing.ts
367
- /**
368
- * Server-Timing header — dev-mode timing breakdowns for Chrome DevTools.
369
- *
370
- * Collects timing entries per request using ALS. Each pipeline phase
371
- * (proxy, middleware, render, SSR, access, fetch) records an entry.
372
- * Before response flush, entries are formatted into a Server-Timing header.
373
- *
374
- * Only active in dev mode — zero overhead in production.
375
- *
376
- * See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Server-Timing
377
- * Task: LOCAL-290
378
- */
379
- /**
380
- * Run a callback with a per-request timing collector.
381
- * Must be called at the top of the request pipeline (wraps the full request).
382
- */
383
- function runWithTimingCollector(fn) {
384
- return timingAls.run({ entries: [] }, fn);
385
- }
386
- /**
387
- * Run a function and automatically record its duration as a timing entry.
388
- * Returns the function's result. No-ops the recording if outside a collector.
389
- */
390
- async function withTiming(name, desc, fn) {
391
- const store = timingAls.getStore();
392
- if (!store) return fn();
393
- const start = performance.now();
394
- try {
395
- return await fn();
396
- } finally {
397
- const dur = Math.round(performance.now() - start);
398
- store.entries.push({
399
- name,
400
- dur,
401
- desc
402
- });
403
- }
404
- }
405
- /**
406
- * Get the Server-Timing header value for the current request.
407
- * Returns null if no entries exist or outside a collector.
408
- *
409
- * Format: `name;dur=123;desc="description", name2;dur=456`
410
- * See RFC 6797 / Server-Timing spec for format details.
411
- */
412
- function getServerTimingHeader() {
413
- const store = timingAls.getStore();
414
- if (!store || store.entries.length === 0) return null;
415
- const nameCounts = /* @__PURE__ */ new Map();
416
- const parts = store.entries.map((entry) => {
417
- const count = nameCounts.get(entry.name) ?? 0;
418
- nameCounts.set(entry.name, count + 1);
419
- const uniqueName = count > 0 ? `${entry.name}-${count}` : entry.name;
420
- return {
421
- ...entry,
422
- name: uniqueName
423
- };
424
- }).map((entry) => {
425
- let part = `${entry.name};dur=${entry.dur}`;
426
- if (entry.desc) {
427
- const safeDesc = entry.desc.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
428
- part += `;desc="${safeDesc}"`;
429
- }
430
- return part;
431
- });
432
- const MAX_HEADER_SIZE = 4096;
433
- let result = "";
434
- for (let i = 0; i < parts.length; i++) {
435
- const candidate = result ? `${result}, ${parts[i]}` : parts[i];
436
- if (candidate.length > MAX_HEADER_SIZE) break;
437
- result = candidate;
438
- }
439
- return result || null;
440
- }
441
- //#endregion
442
- //#region src/server/error-formatter.ts
443
- /**
444
- * Error Formatter — rewrites SSR/RSC error messages to surface user code.
445
- *
446
- * When React or Vite throw errors during SSR, stack traces reference
447
- * vendored dependency paths (e.g. `.vite/deps_ssr/@vitejs_plugin-rsc_vendor_...`)
448
- * and mangled export names (`__vite_ssr_export_default__`). This module
449
- * rewrites error messages and stack traces to point at user code instead.
450
- *
451
- * Dev-only — in production, errors go through the structured logger
452
- * without formatting.
453
- */
454
- /**
455
- * Patterns that identify internal Vite/RSC vendor paths in stack traces.
456
- * These are replaced with human-readable labels.
457
- */
458
- var VENDOR_PATH_PATTERNS = [
459
- {
460
- pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor_react-server-dom[^\s)]+/g,
461
- replacement: "<react-server-dom>"
462
- },
463
- {
464
- pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor[^\s)]+/g,
465
- replacement: "<rsc-vendor>"
466
- },
467
- {
468
- pattern: /node_modules\/\.vite\/deps_ssr\/[^\s)]+/g,
469
- replacement: "<vite-dep>"
470
- },
471
- {
472
- pattern: /node_modules\/\.vite\/deps\/[^\s)]+/g,
473
- replacement: "<vite-dep>"
474
- }
475
- ];
476
- /**
477
- * Patterns that identify Vite-mangled export names in error messages.
478
- */
479
- var MANGLED_NAME_PATTERNS = [{
480
- pattern: /__vite_ssr_export_default__/g,
481
- replacement: "<default export>"
482
- }, {
483
- pattern: /__vite_ssr_export_(\w+)__/g,
484
- replacement: "<export $1>"
485
- }];
486
- /**
487
- * Rewrite an error's message and stack to replace internal Vite paths
488
- * and mangled names with human-readable labels.
489
- */
490
- function formatSsrError(error) {
491
- if (!(error instanceof Error)) return String(error);
492
- let message = error.message;
493
- let stack = error.stack ?? "";
494
- for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) message = message.replace(pattern, replacement);
495
- for (const { pattern, replacement } of VENDOR_PATH_PATTERNS) stack = stack.replace(pattern, replacement);
496
- for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) stack = stack.replace(pattern, replacement);
497
- const hint = extractErrorHint(error.message);
498
- const parts = [];
499
- parts.push(message);
500
- if (hint) parts.push(` → ${hint}`);
501
- const userFrames = extractUserFrames(stack);
502
- if (userFrames.length > 0) {
503
- parts.push("");
504
- parts.push(" User code in stack:");
505
- for (const frame of userFrames) parts.push(` ${frame}`);
506
- }
507
- return parts.join("\n");
508
- }
509
- /**
510
- * Extract a human-readable hint from common React/RSC error messages.
511
- *
512
- * React error messages contain useful information but the surrounding
513
- * context (vendor paths, mangled names) obscures it. This extracts the
514
- * actionable part as a one-line hint.
515
- */
516
- function extractErrorHint(message) {
517
- if (message.match(/Functions cannot be passed directly to Client Components/)) {
518
- const propMatch = message.match(/<[^>]*?\s(\w+)=\{function/);
519
- if (propMatch) return `Prop "${propMatch[1]}" is a function — mark it "use server" or call it before passing`;
520
- return "A function prop was passed to a Client Component — mark it \"use server\" or call it before passing";
521
- }
522
- if (message.includes("Objects are not valid as a React child")) return "An object was rendered as JSX children — convert to string or extract the value";
523
- const nullRefMatch = message.match(/Cannot read propert(?:y|ies) of (undefined|null) \(reading '(\w+)'\)/);
524
- if (nullRefMatch) return `Accessed .${nullRefMatch[2]} on ${nullRefMatch[1]} — check that the value exists`;
525
- const notFnMatch = message.match(/(\w+) is not a function/);
526
- if (notFnMatch) return `"${notFnMatch[1]}" is not a function — check imports and exports`;
527
- if (message.includes("Element type is invalid")) return "A component resolved to undefined/null — check default exports and import paths";
528
- if (message.includes("Invalid hook call")) return "A hook was called outside of a React component render. If this is a 'use client' component, ensure the directive is at the very top of the file (before any imports) and that @vitejs/plugin-rsc is loaded correctly. Barrel re-exports from non-'use client' files do not propagate the directive.";
529
- return null;
530
- }
531
- /**
532
- * Extract stack frames that reference user code (not node_modules,
533
- * not framework internals).
534
- *
535
- * Returns at most 5 frames to keep output concise.
536
- */
537
- function extractUserFrames(stack) {
538
- const lines = stack.split("\n");
539
- const userFrames = [];
540
- for (const line of lines) {
541
- const trimmed = line.trim();
542
- if (!trimmed.startsWith("at ")) continue;
543
- if (trimmed.includes("node_modules") || trimmed.includes("<react-server-dom>") || trimmed.includes("<rsc-vendor>") || trimmed.includes("<vite-dep>") || trimmed.includes("node:internal")) continue;
544
- userFrames.push(trimmed);
545
- if (userFrames.length >= 5) break;
546
- }
547
- return userFrames;
548
- }
549
- //#endregion
550
- //#region src/server/logger.ts
551
- /**
552
- * Logger — structured logging with environment-aware formatting.
553
- *
554
- * timber.js does not ship a logger. Users export any object with
555
- * info/warn/error/debug methods from instrumentation.ts and the framework
556
- * picks it up. Silent if no logger export is present.
557
- *
558
- * See design/17-logging.md §"Production Logging"
559
- */
560
- var _logger = null;
561
- /**
562
- * Set the user-provided logger. Called by the instrumentation loader
563
- * when it finds a `logger` export in instrumentation.ts.
564
- */
565
- function setLogger(logger) {
566
- _logger = logger;
567
- }
568
- /**
569
- * Get the current logger, or null if none configured.
570
- * Framework-internal — used at framework event points to emit structured logs.
571
- */
572
- function getLogger() {
573
- return _logger;
574
- }
575
- /**
576
- * Inject trace_id and span_id into log data for log–trace correlation.
577
- * Always injects trace_id (never undefined). Injects span_id only when OTEL is active.
578
- */
579
- function withTraceContext(data) {
580
- const store = getTraceStore();
581
- const enriched = { ...data };
582
- if (store) {
583
- enriched.trace_id = store.traceId;
584
- if (store.spanId) enriched.span_id = store.spanId;
585
- }
586
- return enriched;
587
- }
588
- /** Log a completed request. Level: info. */
589
- function logRequestCompleted(data) {
590
- _logger?.info("request completed", withTraceContext(data));
591
- }
592
- /** Log request received. Level: debug. */
593
- function logRequestReceived(data) {
594
- _logger?.debug("request received", withTraceContext(data));
595
- }
596
- /** Log a slow request warning. Level: warn. */
597
- function logSlowRequest(data) {
598
- _logger?.warn("slow request exceeded threshold", withTraceContext(data));
599
- }
600
- /** Log middleware short-circuit. Level: debug. */
601
- function logMiddlewareShortCircuit(data) {
602
- _logger?.debug("middleware short-circuited", withTraceContext(data));
603
- }
604
- /** Log unhandled error in middleware phase. Level: error. */
605
- function logMiddlewareError(data) {
606
- if (_logger) _logger.error("unhandled error in middleware phase", withTraceContext(data));
607
- else if (isDebug()) console.error("[timber] middleware error", data.error);
608
- }
609
- /** Log unhandled render-phase error. Level: error. */
610
- function logRenderError(data) {
611
- if (_logger) _logger.error("unhandled render-phase error", withTraceContext(data));
612
- else if (isDebug()) console.error("[timber] render error:", formatSsrError(data.error));
613
- }
614
- /** Log proxy.ts uncaught error. Level: error. */
615
- function logProxyError(data) {
616
- if (_logger) _logger.error("proxy.ts threw uncaught error", withTraceContext(data));
617
- else if (isDebug()) console.error("[timber] proxy error", data.error);
618
- }
619
- /** Log waitUntil() adapter missing (once at startup). Level: warn. */
620
- function logWaitUntilUnsupported() {
621
- _logger?.warn("adapter does not support waitUntil()");
622
- }
623
- /** Log waitUntil() promise rejection. Level: warn. */
624
- function logWaitUntilRejected(data) {
625
- _logger?.warn("waitUntil() promise rejected", withTraceContext(data));
626
- }
627
- /** Log staleWhileRevalidate refetch failure. Level: warn. */
628
- function logSwrRefetchFailed(data) {
629
- _logger?.warn("staleWhileRevalidate refetch failed", withTraceContext(data));
630
- }
631
- /** Log cache miss. Level: debug. */
632
- function logCacheMiss(data) {
633
- _logger?.debug("timber.cache MISS", withTraceContext(data));
634
- }
635
- //#endregion
636
- //#region src/server/instrumentation.ts
637
- /**
638
- * Instrumentation — loads and runs the user's instrumentation.ts file.
639
- *
640
- * instrumentation.ts is a file convention at the project root that exports:
641
- * - register() — called once at server startup, before the first request
642
- * - onRequestError() — called for every unhandled server error
643
- * - logger — any object with info/warn/error/debug methods
644
- *
645
- * See design/17-logging.md §"instrumentation.ts — The Entry Point"
646
- */
647
- var _initialized = false;
648
- var _onRequestError = null;
649
- /**
650
- * Load and initialize the user's instrumentation.ts module.
651
- *
652
- * - Awaits register() before returning (server blocks on this).
653
- * - Picks up the logger export and wires it into the framework logger.
654
- * - Stores onRequestError for later invocation.
655
- *
656
- * @param loader - Function that dynamically imports the user's instrumentation module.
657
- * Returns null if no instrumentation.ts exists.
658
- */
659
- async function loadInstrumentation(loader) {
660
- if (_initialized) return;
661
- _initialized = true;
662
- let mod;
663
- try {
664
- mod = await loader();
665
- } catch (error) {
666
- console.error("[timber] Failed to load instrumentation.ts:", error);
667
- return;
668
- }
669
- if (!mod) return;
670
- if (mod.logger && typeof mod.logger.info === "function") setLogger(mod.logger);
671
- if (typeof mod.onRequestError === "function") _onRequestError = mod.onRequestError;
672
- if (typeof mod.register === "function") try {
673
- await mod.register();
674
- } catch (error) {
675
- console.error("[timber] instrumentation.ts register() threw:", error);
676
- throw error;
677
- }
678
- }
679
- /**
680
- * Call the user's onRequestError hook. Catches and logs any errors thrown
681
- * by the hook itself — it must not affect the response.
682
- */
683
- async function callOnRequestError(error, request, context) {
684
- if (!_onRequestError) return;
685
- try {
686
- await _onRequestError(error, request, context);
687
- } catch (hookError) {
688
- console.error("[timber] onRequestError hook threw:", hookError);
689
- }
690
- }
691
- /**
692
- * Check if onRequestError is registered.
693
- */
694
- function hasOnRequestError() {
695
- return _onRequestError !== null;
696
- }
697
- //#endregion
698
- //#region src/server/pipeline-metadata.ts
699
- /**
700
- * Metadata route helpers for the request pipeline.
701
- *
702
- * Handles serving static metadata files and serializing sitemap responses.
703
- * Extracted from pipeline.ts to keep files under 500 lines.
704
- *
705
- * See design/16-metadata.md §"Metadata Routes"
706
- */
707
- /**
708
- * Content types that are text-based and should include charset=utf-8.
709
- * Binary formats (images) should not include charset.
710
- */
711
- var TEXT_CONTENT_TYPES = new Set([
712
- "application/xml",
713
- "text/plain",
714
- "application/json",
715
- "application/manifest+json",
716
- "image/svg+xml"
717
- ]);
718
- /**
719
- * Serve a static metadata file by reading it from disk.
720
- *
721
- * Static metadata route files (.xml, .txt, .json, .png, .ico, .svg, etc.)
722
- * are served as-is with the appropriate Content-Type header.
723
- * Text files include charset=utf-8; binary files do not.
724
- *
725
- * See design/16-metadata.md §"Metadata Routes"
726
- */
727
- async function serveStaticMetadataFile(metaMatch) {
728
- const { contentType, file } = metaMatch;
729
- const isText = TEXT_CONTENT_TYPES.has(contentType);
730
- const body = await readFile(file.filePath);
731
- const headers = {
732
- "Content-Type": isText ? `${contentType}; charset=utf-8` : contentType,
733
- "Content-Length": String(body.byteLength)
734
- };
735
- return new Response(body, {
736
- status: 200,
737
- headers
738
- });
739
- }
740
- /**
741
- * Serialize a sitemap array to XML.
742
- * Follows the sitemap.org protocol: https://www.sitemaps.org/protocol.html
743
- */
744
- function serializeSitemap(entries) {
745
- return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${entries.map((e) => {
746
- let xml = ` <url>\n <loc>${escapeXml(e.url)}</loc>`;
747
- if (e.lastModified) {
748
- const date = e.lastModified instanceof Date ? e.lastModified.toISOString() : e.lastModified;
749
- xml += `\n <lastmod>${escapeXml(date)}</lastmod>`;
750
- }
751
- if (e.changeFrequency) xml += `\n <changefreq>${escapeXml(e.changeFrequency)}</changefreq>`;
752
- if (e.priority !== void 0) xml += `\n <priority>${e.priority}</priority>`;
753
- xml += "\n </url>";
754
- return xml;
755
- }).join("\n")}\n</urlset>`;
756
- }
757
- /** Escape special XML characters. */
758
- function escapeXml(str) {
759
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
760
- }
761
- //#endregion
762
- //#region src/server/pipeline-interception.ts
763
- /**
764
- * Check if an intercepting route applies for this soft navigation.
765
- *
766
- * Matches the target pathname against interception rewrites, constrained
767
- * by the source URL (X-Timber-URL header — where the user navigates FROM).
768
- *
769
- * Returns the source pathname to re-match if interception applies, or null.
770
- */
771
- function findInterceptionMatch(targetPathname, sourceUrl, rewrites) {
772
- for (const rewrite of rewrites) {
773
- if (!sourceUrl.startsWith(rewrite.interceptingPrefix)) continue;
774
- if (pathnameMatchesPattern(targetPathname, rewrite.interceptedPattern)) return { sourcePathname: rewrite.interceptingPrefix };
775
- }
776
- return null;
777
- }
778
- /**
779
- * Check if a pathname matches a URL pattern with dynamic segments.
780
- *
781
- * Supports [param] (single segment) and [...param] (one or more segments).
782
- * Static segments must match exactly.
783
- */
784
- function pathnameMatchesPattern(pathname, pattern) {
785
- const pathParts = pathname === "/" ? [] : pathname.slice(1).split("/");
786
- const patternParts = pattern === "/" ? [] : pattern.slice(1).split("/");
787
- let pi = 0;
788
- for (let i = 0; i < patternParts.length; i++) {
789
- const segment = patternParts[i];
790
- if (segment.startsWith("[...") || segment.startsWith("[[...")) return pi < pathParts.length || segment.startsWith("[[...");
791
- if (segment.startsWith("[") && segment.endsWith("]")) {
792
- if (pi >= pathParts.length) return false;
793
- pi++;
794
- continue;
795
- }
796
- if (pi >= pathParts.length || pathParts[pi] !== segment) return false;
797
- pi++;
798
- }
799
- return pi === pathParts.length;
800
- }
801
- //#endregion
802
- //#region src/server/pipeline.ts
803
- /**
804
- * Request pipeline — the central dispatch for all timber.js requests.
805
- *
806
- * Pipeline stages (in order):
807
- * proxy.ts → canonicalize → route match → 103 Early Hints → middleware.ts → render
808
- *
809
- * Each stage is a pure function or returns a Response to short-circuit.
810
- * Each request gets a trace ID, structured logging, and OTEL spans.
811
- *
812
- * See design/07-routing.md §"Request Lifecycle", design/02-rendering-pipeline.md §"Request Flow",
813
- * and design/17-logging.md §"Production Logging"
814
- */
815
- /**
816
- * Create the request handler from a pipeline configuration.
817
- *
818
- * Returns a function that processes an incoming Request through all pipeline stages
819
- * and produces a Response. This is the top-level entry point for the server.
820
- */
821
- function createPipeline(config) {
822
- const { proxy, matchRoute, render, earlyHints, stripTrailingSlash = true, slowRequestMs = 3e3, enableServerTiming = false, onPipelineError } = config;
823
- let activeRequests = 0;
824
- return async (req) => {
825
- const url = new URL(req.url);
826
- const method = req.method;
827
- const path = url.pathname;
828
- const startTime = performance.now();
829
- activeRequests++;
830
- return runWithTraceId(generateTraceId(), async () => {
831
- return runWithRequestContext(req, async () => {
832
- const runRequest = async () => {
833
- logRequestReceived({
834
- method,
835
- path
836
- });
837
- const response = await withSpan("http.server.request", {
838
- "http.request.method": method,
839
- "url.path": path
840
- }, async () => {
841
- const otelIds = await getOtelTraceId();
842
- if (otelIds) replaceTraceId(otelIds.traceId, otelIds.spanId);
843
- let result;
844
- if (proxy || config.proxyLoader) result = await runProxyPhase(req, method, path);
845
- else result = await handleRequest(req, method, path);
846
- await setSpanAttribute("http.response.status_code", result.status);
847
- if (enableServerTiming) {
848
- const serverTiming = getServerTimingHeader();
849
- if (serverTiming) {
850
- result = ensureMutableResponse(result);
851
- result.headers.set("Server-Timing", serverTiming);
852
- }
853
- } else {
854
- const totalMs = Math.round(performance.now() - startTime);
855
- result = ensureMutableResponse(result);
856
- result.headers.set("Server-Timing", `total;dur=${totalMs}`);
857
- }
858
- return result;
859
- });
860
- const durationMs = Math.round(performance.now() - startTime);
861
- const status = response.status;
862
- const concurrency = activeRequests;
863
- activeRequests--;
864
- logRequestCompleted({
865
- method,
866
- path,
867
- status,
868
- durationMs,
869
- concurrency
870
- });
871
- if (slowRequestMs > 0 && durationMs > slowRequestMs) logSlowRequest({
872
- method,
873
- path,
874
- durationMs,
875
- threshold: slowRequestMs,
876
- concurrency
877
- });
878
- return response;
879
- };
880
- return enableServerTiming ? runWithTimingCollector(runRequest) : runRequest();
881
- });
882
- });
883
- };
884
- async function runProxyPhase(req, method, path) {
885
- try {
886
- let proxyExport;
887
- if (config.proxyLoader) proxyExport = (await config.proxyLoader()).default;
888
- else proxyExport = config.proxy;
889
- const proxyFn = () => runProxy(proxyExport, req, () => handleRequest(req, method, path));
890
- return await withSpan("timber.proxy", {}, () => enableServerTiming ? withTiming("proxy", "proxy.ts", proxyFn) : proxyFn());
891
- } catch (error) {
892
- logProxyError({ error });
893
- await fireOnRequestError(error, req, "proxy");
894
- if (onPipelineError && error instanceof Error) onPipelineError(error, "proxy");
895
- return new Response(null, { status: 500 });
896
- }
897
- }
898
- async function handleRequest(req, method, path) {
899
- const result = canonicalize(new URL(req.url).pathname, stripTrailingSlash);
900
- if (!result.ok) return new Response(null, { status: result.status });
901
- const canonicalPathname = result.pathname;
902
- if (config.matchMetadataRoute) {
903
- const metaMatch = config.matchMetadataRoute(canonicalPathname);
904
- if (metaMatch) try {
905
- if (metaMatch.isStatic) return await serveStaticMetadataFile(metaMatch);
906
- const mod = await metaMatch.file.load();
907
- if (typeof mod.default !== "function") return new Response("Metadata route must export a default function", { status: 500 });
908
- const handlerResult = await mod.default();
909
- if (handlerResult instanceof Response) return handlerResult;
910
- const contentType = metaMatch.contentType;
911
- let body;
912
- if (typeof handlerResult === "string") body = handlerResult;
913
- else if (contentType === "application/xml") body = serializeSitemap(handlerResult);
914
- else if (contentType === "application/manifest+json") body = JSON.stringify(handlerResult, null, 2);
915
- else body = typeof handlerResult === "string" ? handlerResult : String(handlerResult);
916
- return new Response(body, {
917
- status: 200,
918
- headers: { "Content-Type": `${contentType}; charset=utf-8` }
919
- });
920
- } catch (error) {
921
- logRenderError({
922
- method,
923
- path,
924
- error
925
- });
926
- if (onPipelineError && error instanceof Error) onPipelineError(error, "metadata-route");
927
- return new Response(null, { status: 500 });
928
- }
929
- }
930
- let match = matchRoute(canonicalPathname);
931
- let interception;
932
- const sourceUrl = req.headers.get("X-Timber-URL");
933
- if (sourceUrl && config.interceptionRewrites?.length) {
934
- const intercepted = findInterceptionMatch(canonicalPathname, sourceUrl, config.interceptionRewrites);
935
- if (intercepted) {
936
- const sourceMatch = matchRoute(intercepted.sourcePathname);
937
- if (sourceMatch) {
938
- match = sourceMatch;
939
- interception = { targetPathname: canonicalPathname };
940
- }
941
- }
942
- }
943
- if (!match) {
944
- if (config.renderNoMatch) {
945
- const responseHeaders = new Headers();
946
- return config.renderNoMatch(req, responseHeaders);
947
- }
948
- return new Response(null, { status: 404 });
949
- }
950
- const responseHeaders = new Headers();
951
- const requestHeaderOverlay = new Headers();
952
- responseHeaders.set("Cache-Control", "private, no-cache, no-store, max-age=0, must-revalidate");
953
- if (earlyHints) try {
954
- await earlyHints(match, req, responseHeaders);
955
- } catch {}
956
- if (match.middleware) {
957
- const ctx = {
958
- req,
959
- requestHeaders: requestHeaderOverlay,
960
- headers: responseHeaders,
961
- params: match.params,
962
- searchParams: new URL(req.url).searchParams,
963
- earlyHints: (hints) => {
964
- for (const hint of hints) {
965
- let value = `<${hint.href}>; rel=${hint.rel}`;
966
- if (hint.as !== void 0) value += `; as=${hint.as}`;
967
- if (hint.crossOrigin !== void 0) value += `; crossorigin=${hint.crossOrigin}`;
968
- if (hint.fetchPriority !== void 0) value += `; fetchpriority=${hint.fetchPriority}`;
969
- responseHeaders.append("Link", value);
970
- }
971
- }
972
- };
973
- try {
974
- setMutableCookieContext(true);
975
- const middlewareFn = () => runMiddleware(match.middleware, ctx);
976
- const middlewareResponse = await withSpan("timber.middleware", {}, () => enableServerTiming ? withTiming("mw", "middleware.ts", middlewareFn) : middlewareFn());
977
- setMutableCookieContext(false);
978
- if (middlewareResponse) {
979
- const finalResponse = ensureMutableResponse(middlewareResponse);
980
- applyCookieJar(finalResponse.headers);
981
- logMiddlewareShortCircuit({
982
- method,
983
- path,
984
- status: finalResponse.status
985
- });
986
- return finalResponse;
987
- }
988
- applyRequestHeaderOverlay(requestHeaderOverlay);
989
- } catch (error) {
990
- setMutableCookieContext(false);
991
- if (error instanceof RedirectSignal) {
992
- applyCookieJar(responseHeaders);
993
- if ((req.headers.get("Accept") ?? "").includes("text/x-component")) {
994
- responseHeaders.set("X-Timber-Redirect", error.location);
995
- return new Response(null, {
996
- status: 204,
997
- headers: responseHeaders
998
- });
999
- }
1000
- responseHeaders.set("Location", error.location);
1001
- return new Response(null, {
1002
- status: error.status,
1003
- headers: responseHeaders
1004
- });
1005
- }
1006
- if (error instanceof DenySignal) return new Response(null, { status: error.status });
1007
- logMiddlewareError({
1008
- method,
1009
- path,
1010
- error
1011
- });
1012
- await fireOnRequestError(error, req, "handler");
1013
- if (onPipelineError && error instanceof Error) onPipelineError(error, "middleware");
1014
- return new Response(null, { status: 500 });
1015
- }
1016
- }
1017
- applyCookieJar(responseHeaders);
1018
- try {
1019
- const renderFn = () => render(req, match, responseHeaders, requestHeaderOverlay, interception);
1020
- const response = await withSpan("timber.render", { "http.route": canonicalPathname }, () => enableServerTiming ? withTiming("render", "RSC + SSR render", renderFn) : renderFn());
1021
- markResponseFlushed();
1022
- return response;
1023
- } catch (error) {
1024
- if (error instanceof DenySignal) return new Response(null, { status: error.status });
1025
- if (error instanceof RedirectSignal) {
1026
- if ((req.headers.get("Accept") ?? "").includes("text/x-component")) {
1027
- responseHeaders.set("X-Timber-Redirect", error.location);
1028
- return new Response(null, {
1029
- status: 204,
1030
- headers: responseHeaders
1031
- });
1032
- }
1033
- responseHeaders.set("Location", error.location);
1034
- return new Response(null, {
1035
- status: error.status,
1036
- headers: responseHeaders
1037
- });
1038
- }
1039
- logRenderError({
1040
- method,
1041
- path,
1042
- error
1043
- });
1044
- await fireOnRequestError(error, req, "render");
1045
- if (onPipelineError && error instanceof Error) onPipelineError(error, "render");
1046
- if (config.renderFallbackError) try {
1047
- return await config.renderFallbackError(error, req, responseHeaders);
1048
- } catch {}
1049
- return new Response(null, { status: 500 });
1050
- }
1051
- }
1052
- }
1053
- /**
1054
- * Fire the user's onRequestError hook with request context.
1055
- * Extracts request info from the Request object and calls the instrumentation hook.
1056
- */
1057
- async function fireOnRequestError(error, req, phase) {
1058
- const url = new URL(req.url);
1059
- const headersObj = {};
1060
- req.headers.forEach((v, k) => {
1061
- headersObj[k] = v;
1062
- });
1063
- await callOnRequestError(error, {
1064
- method: req.method,
1065
- path: url.pathname,
1066
- headers: headersObj
1067
- }, {
1068
- phase,
1069
- routePath: url.pathname,
1070
- routeType: "page",
1071
- traceId: traceId()
1072
- });
1073
- }
1074
- /**
1075
- * Apply all Set-Cookie headers from the cookie jar to a Headers object.
1076
- * Each cookie gets its own Set-Cookie header per RFC 6265 §4.1.
1077
- */
1078
- function applyCookieJar(headers) {
1079
- for (const value of getSetCookieHeaders()) headers.append("Set-Cookie", value);
1080
- }
1081
- /**
1082
- * Ensure a Response has mutable headers so the pipeline can safely append
1083
- * Set-Cookie and Server-Timing entries.
1084
- *
1085
- * `Response.redirect()` and some platform-level responses return objects
1086
- * with immutable headers. Calling `.set()` or `.append()` on them throws
1087
- * `TypeError: immutable`. This helper detects the immutable case by
1088
- * attempting a no-op write and, on failure, clones into a fresh Response
1089
- * with mutable headers.
1090
- */
1091
- function ensureMutableResponse(response) {
1092
- try {
1093
- response.headers.set("X-Timber-Probe", "1");
1094
- response.headers.delete("X-Timber-Probe");
1095
- return response;
1096
- } catch {
1097
- return new Response(response.body, {
1098
- status: response.status,
1099
- statusText: response.statusText,
1100
- headers: new Headers(response.headers)
1101
- });
1102
- }
1103
- }
1104
- //#endregion
1105
- //#region src/server/build-manifest.ts
1106
- /**
1107
- * Collect all CSS files needed for a matched route's segment chain.
1108
- *
1109
- * Walks segments root → leaf, collecting CSS for each layout and page.
1110
- * Deduplicates while preserving order (root layout CSS first).
1111
- */
1112
- function collectRouteCss(segments, manifest) {
1113
- const seen = /* @__PURE__ */ new Set();
1114
- const result = [];
1115
- for (const segment of segments) for (const file of [segment.layout, segment.page]) {
1116
- if (!file) continue;
1117
- const cssFiles = manifest.css[file.filePath];
1118
- if (!cssFiles) continue;
1119
- for (const url of cssFiles) if (!seen.has(url)) {
1120
- seen.add(url);
1121
- result.push(url);
1122
- }
1123
- }
1124
- return result;
1125
- }
1126
- /**
1127
- * Collect all font entries needed for a matched route's segment chain.
1128
- *
1129
- * Walks segments root → leaf, collecting fonts for each layout and page.
1130
- * Deduplicates by href while preserving order.
1131
- */
1132
- function collectRouteFonts(segments, manifest) {
1133
- const seen = /* @__PURE__ */ new Set();
1134
- const result = [];
1135
- for (const segment of segments) for (const file of [segment.layout, segment.page]) {
1136
- if (!file) continue;
1137
- const fonts = manifest.fonts[file.filePath];
1138
- if (!fonts) continue;
1139
- for (const entry of fonts) if (!seen.has(entry.href)) {
1140
- seen.add(entry.href);
1141
- result.push(entry);
1142
- }
1143
- }
1144
- return result;
1145
- }
1146
- /**
1147
- * Collect modulepreload URLs for a matched route's segment chain.
1148
- *
1149
- * Walks segments root → leaf, collecting transitive JS dependencies
1150
- * for each layout and page. Deduplicates across segments.
1151
- */
1152
- function collectRouteModulepreloads(segments, manifest) {
1153
- const seen = /* @__PURE__ */ new Set();
1154
- const result = [];
1155
- for (const segment of segments) for (const file of [segment.layout, segment.page]) {
1156
- if (!file) continue;
1157
- const preloads = manifest.modulepreload[file.filePath];
1158
- if (!preloads) continue;
1159
- for (const url of preloads) if (!seen.has(url)) {
1160
- seen.add(url);
1161
- result.push(url);
1162
- }
1163
- }
1164
- return result;
1165
- }
1166
- //#endregion
1167
- //#region src/server/early-hints.ts
1168
- /**
1169
- * 103 Early Hints utilities.
1170
- *
1171
- * Early Hints are sent before the final response to let the browser
1172
- * start fetching critical resources (CSS, fonts, JS) while the server
1173
- * is still rendering.
1174
- *
1175
- * The framework collects hints from two sources:
1176
- * 1. Build manifest — CSS, fonts, and JS chunks known at route-match time
1177
- * 2. ctx.earlyHints() — explicit hints added by middleware or route handlers
1178
- *
1179
- * Both are emitted as Link headers. Cloudflare CDN automatically converts
1180
- * Link headers into 103 Early Hints responses.
1181
- *
1182
- * Design docs: 02-rendering-pipeline.md §"Early Hints (103)"
1183
- */
1184
- /**
1185
- * Format a single EarlyHint as a Link header value.
1186
- *
1187
- * Examples:
1188
- * `</styles/root.css>; rel=preload; as=style`
1189
- * `</fonts/inter.woff2>; rel=preload; as=font; crossorigin=anonymous`
1190
- * `</_timber/client.js>; rel=modulepreload`
1191
- * `<https://fonts.googleapis.com>; rel=preconnect`
1192
- */
1193
- function formatLinkHeader(hint) {
1194
- let value = `<${hint.href}>; rel=${hint.rel}`;
1195
- if (hint.as !== void 0) value += `; as=${hint.as}`;
1196
- if (hint.crossOrigin !== void 0) value += `; crossorigin=${hint.crossOrigin}`;
1197
- if (hint.fetchPriority !== void 0) value += `; fetchpriority=${hint.fetchPriority}`;
1198
- return value;
1199
- }
1200
- /**
1201
- * Collect all Link header strings for a matched route's segment chain.
1202
- *
1203
- * Walks the build manifest to emit hints for:
1204
- * - CSS stylesheets (rel=preload; as=style)
1205
- * - Font assets (rel=preload; as=font; crossorigin)
1206
- * - JS modulepreload hints (rel=modulepreload) — unless skipJs is set
1207
- *
1208
- * Also emits global CSS from the `_global` manifest key. Route files
1209
- * are server components that don't appear in the client bundle, so
1210
- * per-route CSS keying doesn't work with the RSC plugin. The `_global`
1211
- * key contains all CSS assets from the client build — fine for early
1212
- * hints since they're just prefetch signals.
1213
- *
1214
- * Returns formatted Link header strings, deduplicated, root → leaf order.
1215
- * Returns an empty array in dev mode (manifest is empty).
1216
- */
1217
- function collectEarlyHintHeaders(segments, manifest, options) {
1218
- const result = [];
1219
- const seen = /* @__PURE__ */ new Set();
1220
- const add = (header) => {
1221
- if (!seen.has(header)) {
1222
- seen.add(header);
1223
- result.push(header);
1224
- }
1225
- };
1226
- for (const url of collectRouteCss(segments, manifest)) add(formatLinkHeader({
1227
- href: url,
1228
- rel: "preload",
1229
- as: "style"
1230
- }));
1231
- for (const url of manifest.css["_global"] ?? []) add(formatLinkHeader({
1232
- href: url,
1233
- rel: "preload",
1234
- as: "style"
1235
- }));
1236
- for (const font of collectRouteFonts(segments, manifest)) add(formatLinkHeader({
1237
- href: font.href,
1238
- rel: "preload",
1239
- as: "font",
1240
- crossOrigin: "anonymous"
1241
- }));
1242
- if (!options?.skipJs) for (const url of collectRouteModulepreloads(segments, manifest)) add(formatLinkHeader({
1243
- href: url,
1244
- rel: "modulepreload"
1245
- }));
1246
- return result;
1247
- }
1248
- //#endregion
1249
- //#region src/server/early-hints-sender.ts
1250
- /**
1251
- * Per-request 103 Early Hints sender — ALS bridge for platform adapters.
1252
- *
1253
- * The pipeline collects Link headers for CSS, fonts, and JS chunks at
1254
- * route-match time. On platforms that support it (Node.js v18.11+, Bun),
1255
- * the adapter can send these as a 103 Early Hints interim response before
1256
- * the final response is ready.
1257
- *
1258
- * This module provides an ALS-based bridge: the generated entry point
1259
- * (e.g., the Nitro entry) wraps the handler with `runWithEarlyHintsSender`,
1260
- * binding a per-request sender function. The pipeline calls
1261
- * `sendEarlyHints103()` to fire the 103 if a sender is available.
1262
- *
1263
- * On platforms where 103 is handled at the CDN level (e.g., Cloudflare
1264
- * converts Link headers into 103 automatically), no sender is installed
1265
- * and `sendEarlyHints103()` is a no-op.
1266
- *
1267
- * Design doc: 02-rendering-pipeline.md §"Early Hints (103)"
1268
- */
1269
- /**
1270
- * Run a function with a per-request early hints sender installed.
1271
- *
1272
- * Called by generated entry points (e.g., Nitro node-server/bun) to
1273
- * bind the platform's writeEarlyHints capability for the request duration.
1274
- */
1275
- function runWithEarlyHintsSender(sender, fn) {
1276
- return earlyHintsSenderAls.run(sender, fn);
1277
- }
1278
- /**
1279
- * Send collected Link headers as a 103 Early Hints response.
1280
- *
1281
- * No-op if no sender is installed for the current request (e.g., on
1282
- * Cloudflare where the CDN handles 103 automatically, or in dev mode).
1283
- *
1284
- * Non-fatal: errors from the sender are caught and silently ignored.
1285
- */
1286
- function sendEarlyHints103(links) {
1287
- if (!links.length) return;
1288
- const sender = earlyHintsSenderAls.getStore();
1289
- if (!sender) return;
1290
- try {
1291
- sender(links);
1292
- } catch {}
1293
- }
1294
- //#endregion
1295
- //#region src/server/tree-builder.ts
1296
- /**
1297
- * Build the unified element tree from a matched segment chain.
1298
- *
1299
- * Construction is bottom-up:
1300
- * 1. Start with the page component (leaf segment)
1301
- * 2. Wrap in status-code error boundaries (fallback chain)
1302
- * 3. Wrap in AccessGate (if segment has access.ts)
1303
- * 4. Pass as children to the segment's layout
1304
- * 5. Repeat up the segment chain to root
1305
- *
1306
- * Parallel slots are resolved at each layout level and composed as named props.
1307
- */
1308
- async function buildElementTree(config) {
1309
- const { segments, params, searchParams, loadModule, createElement, errorBoundaryComponent } = config;
1310
- if (segments.length === 0) throw new Error("[timber] buildElementTree: empty segment chain");
1311
- const leaf = segments[segments.length - 1];
1312
- if (leaf.route && !leaf.page) return {
1313
- tree: null,
1314
- isApiRoute: true
1315
- };
1316
- const PageComponent = (leaf.page ? await loadModule(leaf.page) : null)?.default;
1317
- if (!PageComponent) throw new Error(`[timber] No page component found for route at ${leaf.urlPath}. Each route must have a page.tsx or route.ts.`);
1318
- let element = createElement(PageComponent, {
1319
- params,
1320
- searchParams
1321
- });
1322
- for (let i = segments.length - 1; i >= 0; i--) {
1323
- const segment = segments[i];
1324
- element = await wrapWithErrorBoundaries(segment, element, loadModule, createElement, errorBoundaryComponent);
1325
- if (segment.access) {
1326
- const accessFn = (await loadModule(segment.access)).default;
1327
- element = createElement("timber:access-gate", {
1328
- accessFn,
1329
- params,
1330
- searchParams,
1331
- segmentName: segment.segmentName,
1332
- children: element
1333
- });
1334
- }
1335
- if (segment.layout) {
1336
- const LayoutComponent = (await loadModule(segment.layout)).default;
1337
- if (LayoutComponent) {
1338
- const slotProps = {};
1339
- if (segment.slots.size > 0) for (const [slotName, slotNode] of segment.slots) slotProps[slotName] = await buildSlotElement(slotNode, params, searchParams, loadModule, createElement, errorBoundaryComponent);
1340
- element = createElement(LayoutComponent, {
1341
- ...slotProps,
1342
- params,
1343
- searchParams,
1344
- children: element
1345
- });
1346
- }
1347
- }
1348
- }
1349
- return {
1350
- tree: element,
1351
- isApiRoute: false
1352
- };
1353
- }
1354
- /**
1355
- * Build the element tree for a parallel slot.
1356
- *
1357
- * Slots have their own access.ts (SlotAccessGate) and error boundaries.
1358
- * On access denial: denied.tsx → default.tsx → null (graceful degradation).
1359
- */
1360
- async function buildSlotElement(slotNode, params, searchParams, loadModule, createElement, errorBoundaryComponent) {
1361
- const PageComponent = (slotNode.page ? await loadModule(slotNode.page) : null)?.default;
1362
- const DefaultComponent = (slotNode.default ? await loadModule(slotNode.default) : null)?.default;
1363
- if (!PageComponent) return DefaultComponent ? createElement(DefaultComponent, {
1364
- params,
1365
- searchParams
1366
- }) : null;
1367
- let element = createElement(PageComponent, {
1368
- params,
1369
- searchParams
1370
- });
1371
- element = await wrapWithErrorBoundaries(slotNode, element, loadModule, createElement, errorBoundaryComponent);
1372
- if (slotNode.access) {
1373
- const accessFn = (await loadModule(slotNode.access)).default;
1374
- const DeniedComponent = (slotNode.denied ? await loadModule(slotNode.denied) : null)?.default;
1375
- element = createElement("timber:slot-access-gate", {
1376
- accessFn,
1377
- params,
1378
- searchParams,
1379
- deniedFallback: DeniedComponent ? createElement(DeniedComponent, {
1380
- slot: slotNode.segmentName.replace(/^@/, ""),
1381
- dangerouslyPassData: void 0
1382
- }) : null,
1383
- defaultFallback: DefaultComponent ? createElement(DefaultComponent, {
1384
- params,
1385
- searchParams
1386
- }) : null,
1387
- children: element
1388
- });
1389
- }
1390
- return element;
1391
- }
1392
- /**
1393
- * Wrap an element with error boundaries from a segment's status-code files.
1394
- *
1395
- * Wrapping order (innermost to outermost):
1396
- * 1. Specific status files (503.tsx, 429.tsx, etc.)
1397
- * 2. Category catch-alls (4xx.tsx, 5xx.tsx)
1398
- * 3. error.tsx (general error boundary)
1399
- *
1400
- * This creates the fallback chain described in design/10-error-handling.md.
1401
- */
1402
- async function wrapWithErrorBoundaries(segment, element, loadModule, createElement, errorBoundaryComponent) {
1403
- if (segment.statusFiles) {
1404
- for (const [key, file] of segment.statusFiles) if (key !== "4xx" && key !== "5xx") {
1405
- const status = parseInt(key, 10);
1406
- if (!isNaN(status)) {
1407
- const Component = (await loadModule(file)).default;
1408
- if (Component) element = createElement(errorBoundaryComponent, {
1409
- fallbackComponent: Component,
1410
- status,
1411
- children: element
1412
- });
1413
- }
1414
- }
1415
- for (const [key, file] of segment.statusFiles) if (key === "4xx" || key === "5xx") {
1416
- const Component = (await loadModule(file)).default;
1417
- if (Component) element = createElement(errorBoundaryComponent, {
1418
- fallbackComponent: Component,
1419
- status: key === "4xx" ? 400 : 500,
1420
- children: element
1421
- });
1422
- }
1423
- }
1424
- if (segment.error) {
1425
- const ErrorComponent = (await loadModule(segment.error)).default;
1426
- if (ErrorComponent) element = createElement(errorBoundaryComponent, {
1427
- fallbackComponent: ErrorComponent,
1428
- children: element
1429
- });
1430
- }
1431
- return element;
1432
- }
1433
- //#endregion
1434
- //#region src/server/access-gate.tsx
1435
- /**
1436
- * AccessGate and SlotAccessGate — framework-injected async server components.
1437
- *
1438
- * AccessGate wraps each segment's layout in the element tree. It calls the
1439
- * segment's access.ts before the layout renders. If access.ts calls deny()
1440
- * or redirect(), the signal propagates as a render-phase throw — caught by
1441
- * the flush controller to produce the correct HTTP status code.
1442
- *
1443
- * SlotAccessGate wraps parallel slot content. On denial, it renders the
1444
- * graceful degradation chain: denied.tsx → default.tsx → null. Slot denial
1445
- * does not affect the HTTP status code.
1446
- *
1447
- * See design/04-authorization.md and design/02-rendering-pipeline.md §"AccessGate"
1448
- */
1449
- /**
1450
- * Framework-injected access gate for segments.
1451
- *
1452
- * When a pre-computed `verdict` prop is provided (from the pre-render pass
1453
- * in route-element-builder.ts), AccessGate replays it synchronously — no
1454
- * async, no re-execution of access.ts, immune to Suspense timing. The OTEL
1455
- * span was already emitted during the pre-render pass.
1456
- *
1457
- * When no verdict is provided (backward compat with tree-builder.ts),
1458
- * AccessGate calls accessFn directly with OTEL instrumentation.
1459
- *
1460
- * access.ts is a pure gate — return values are discarded. The layout below
1461
- * gets the same data by calling the same cached functions (React.cache dedup).
1462
- */
1463
- function AccessGate(props) {
1464
- const { accessFn, params, searchParams, segmentName, verdict, children } = props;
1465
- if (verdict !== void 0) {
1466
- if (verdict === "pass") return children;
1467
- throw verdict;
1468
- }
1469
- return accessGateFallback(accessFn, params, searchParams, segmentName, children);
1470
- }
1471
- /**
1472
- * Async fallback for AccessGate when no pre-computed verdict is available.
1473
- * Calls accessFn with OTEL instrumentation.
1474
- */
1475
- async function accessGateFallback(accessFn, params, searchParams, segmentName, children) {
1476
- await withSpan("timber.access", { "timber.segment": segmentName ?? "unknown" }, async () => {
1477
- try {
1478
- await accessFn({
1479
- params,
1480
- searchParams
1481
- });
1482
- await setSpanAttribute("timber.result", "pass");
1483
- } catch (error) {
1484
- if (error instanceof DenySignal) {
1485
- await setSpanAttribute("timber.result", "deny");
1486
- await setSpanAttribute("timber.deny_status", error.status);
1487
- if (error.sourceFile) await setSpanAttribute("timber.deny_file", error.sourceFile);
1488
- } else if (error instanceof RedirectSignal) await setSpanAttribute("timber.result", "redirect");
1489
- throw error;
1490
- }
1491
- });
1492
- return children;
1493
- }
1494
- /**
1495
- * Framework-injected access gate for parallel slots.
1496
- *
1497
- * On denial, graceful degradation: denied.tsx → default.tsx → null.
1498
- * The HTTP status code is unaffected — slot denial is a UI concern, not
1499
- * a protocol concern. The parent layout and sibling slots still render.
1500
- *
1501
- * redirect() in slot access.ts is a dev-mode error — redirecting from a
1502
- * slot doesn't make architectural sense.
1503
- */
1504
- async function SlotAccessGate(props) {
1505
- const { accessFn, params, searchParams, deniedFallback, defaultFallback, children } = props;
1506
- try {
1507
- await accessFn({
1508
- params,
1509
- searchParams
1510
- });
1511
- } catch (error) {
1512
- if (error instanceof DenySignal) return deniedFallback ?? defaultFallback ?? null;
1513
- if (error instanceof RedirectSignal) {
1514
- if (isDebug()) console.error("[timber] redirect() is not allowed in slot access.ts. Slots use deny() for graceful degradation — denied.tsx → default.tsx → null. If you need to redirect, move the logic to the parent segment's access.ts.");
1515
- return deniedFallback ?? defaultFallback ?? null;
1516
- }
1517
- if (isDebug()) console.warn("[timber] Unhandled error in slot access.ts. Use deny() for access control, not unhandled throws.", error);
1518
- throw error;
1519
- }
1520
- return children;
1521
- }
1522
- //#endregion
1523
- //#region src/server/status-code-resolver.ts
1524
- /**
1525
- * Maps legacy file convention names to their corresponding HTTP status codes.
1526
- * Only used in the 4xx component fallback chain.
1527
- */
1528
- var LEGACY_FILE_TO_STATUS = {
1529
- "not-found": 404,
1530
- "forbidden": 403,
1531
- "unauthorized": 401
1532
- };
1533
- /**
1534
- * Resolve the status-code file to render for a given HTTP status code.
1535
- *
1536
- * Walks the segment chain from leaf to root following the fallback chain
1537
- * defined in design/10-error-handling.md. Returns null if no file is found
1538
- * (caller should render the framework default).
1539
- *
1540
- * @param status - The HTTP status code (4xx or 5xx).
1541
- * @param segments - The matched segment chain from root (index 0) to leaf (last).
1542
- * @param format - The response format family ('component' or 'json'). Defaults to 'component'.
1543
- */
1544
- function resolveStatusFile(status, segments, format = "component") {
1545
- if (status >= 400 && status <= 499) return format === "json" ? resolve4xxJson(status, segments) : resolve4xx(status, segments);
1546
- if (status >= 500 && status <= 599) return format === "json" ? resolve5xxJson(status, segments) : resolve5xx(status, segments);
1547
- return null;
1548
- }
1549
- /**
1550
- * 4xx component fallback chain (three separate passes):
1551
- * Pass 1 — status files (leaf → root): {status}.tsx → 4xx.tsx
1552
- * Pass 2 — legacy compat (leaf → root): not-found.tsx / forbidden.tsx / unauthorized.tsx
1553
- * Pass 3 — error.tsx (leaf → root)
1554
- */
1555
- function resolve4xx(status, segments) {
1556
- const statusStr = String(status);
1557
- for (let i = segments.length - 1; i >= 0; i--) {
1558
- const segment = segments[i];
1559
- if (!segment.statusFiles) continue;
1560
- const exact = segment.statusFiles.get(statusStr);
1561
- if (exact) return {
1562
- file: exact,
1563
- status,
1564
- kind: "exact",
1565
- segmentIndex: i
1566
- };
1567
- const category = segment.statusFiles.get("4xx");
1568
- if (category) return {
1569
- file: category,
1570
- status,
1571
- kind: "category",
1572
- segmentIndex: i
1573
- };
1574
- }
1575
- for (let i = segments.length - 1; i >= 0; i--) {
1576
- const segment = segments[i];
1577
- if (!segment.legacyStatusFiles) continue;
1578
- for (const [name, legacyStatus] of Object.entries(LEGACY_FILE_TO_STATUS)) if (legacyStatus === status) {
1579
- const file = segment.legacyStatusFiles.get(name);
1580
- if (file) return {
1581
- file,
1582
- status,
1583
- kind: "legacy",
1584
- segmentIndex: i
1585
- };
1586
- }
1587
- }
1588
- for (let i = segments.length - 1; i >= 0; i--) if (segments[i].error) return {
1589
- file: segments[i].error,
1590
- status,
1591
- kind: "error",
1592
- segmentIndex: i
1593
- };
1594
- return null;
1595
- }
1596
- /**
1597
- * 4xx JSON fallback chain (single pass):
1598
- * Pass 1 — json status files (leaf → root): {status}.json → 4xx.json
1599
- * No legacy compat, no error.tsx — JSON chain terminates at category catch-all.
1600
- */
1601
- function resolve4xxJson(status, segments) {
1602
- const statusStr = String(status);
1603
- for (let i = segments.length - 1; i >= 0; i--) {
1604
- const segment = segments[i];
1605
- if (!segment.jsonStatusFiles) continue;
1606
- const exact = segment.jsonStatusFiles.get(statusStr);
1607
- if (exact) return {
1608
- file: exact,
1609
- status,
1610
- kind: "exact",
1611
- segmentIndex: i
1612
- };
1613
- const category = segment.jsonStatusFiles.get("4xx");
1614
- if (category) return {
1615
- file: category,
1616
- status,
1617
- kind: "category",
1618
- segmentIndex: i
1619
- };
1620
- }
1621
- return null;
1622
- }
1623
- /**
1624
- * 5xx component fallback chain (single pass, per-segment):
1625
- * At each segment (leaf → root): {status}.tsx → 5xx.tsx → error.tsx
1626
- */
1627
- function resolve5xx(status, segments) {
1628
- const statusStr = String(status);
1629
- for (let i = segments.length - 1; i >= 0; i--) {
1630
- const segment = segments[i];
1631
- if (segment.statusFiles) {
1632
- const exact = segment.statusFiles.get(statusStr);
1633
- if (exact) return {
1634
- file: exact,
1635
- status,
1636
- kind: "exact",
1637
- segmentIndex: i
1638
- };
1639
- const category = segment.statusFiles.get("5xx");
1640
- if (category) return {
1641
- file: category,
1642
- status,
1643
- kind: "category",
1644
- segmentIndex: i
1645
- };
1646
- }
1647
- if (segment.error) return {
1648
- file: segment.error,
1649
- status,
1650
- kind: "error",
1651
- segmentIndex: i
1652
- };
1653
- }
1654
- return null;
1655
- }
1656
- /**
1657
- * 5xx JSON fallback chain (single pass):
1658
- * At each segment (leaf → root): {status}.json → 5xx.json
1659
- * No error.tsx equivalent — JSON chain terminates at category catch-all.
1660
- */
1661
- function resolve5xxJson(status, segments) {
1662
- const statusStr = String(status);
1663
- for (let i = segments.length - 1; i >= 0; i--) {
1664
- const segment = segments[i];
1665
- if (!segment.jsonStatusFiles) continue;
1666
- const exact = segment.jsonStatusFiles.get(statusStr);
1667
- if (exact) return {
1668
- file: exact,
1669
- status,
1670
- kind: "exact",
1671
- segmentIndex: i
1672
- };
1673
- const category = segment.jsonStatusFiles.get("5xx");
1674
- if (category) return {
1675
- file: category,
1676
- status,
1677
- kind: "category",
1678
- segmentIndex: i
1679
- };
1680
- }
1681
- return null;
1682
- }
1683
- /**
1684
- * Resolve the denial file for a parallel route slot.
1685
- *
1686
- * Slot denial is graceful degradation — no HTTP status on the wire.
1687
- * Fallback chain: denied.tsx → default.tsx → null.
1688
- *
1689
- * @param slotNode - The segment node for the slot (segmentType === 'slot').
1690
- */
1691
- function resolveSlotDenied(slotNode) {
1692
- const slotName = slotNode.segmentName.replace(/^@/, "");
1693
- if (slotNode.denied) return {
1694
- file: slotNode.denied,
1695
- slotName,
1696
- kind: "denied"
1697
- };
1698
- if (slotNode.default) return {
1699
- file: slotNode.default,
1700
- slotName,
1701
- kind: "default"
1702
- };
1703
- return null;
1704
- }
1705
- //#endregion
1706
- //#region src/server/flush.ts
1707
- /**
1708
- * Flush controller for timber.js rendering.
1709
- *
1710
- * Holds the response until `onShellReady` fires, then commits the HTTP status
1711
- * code and flushes the shell. Render-phase signals (deny, redirect, unhandled
1712
- * throws) caught before flush produce correct HTTP status codes.
1713
- *
1714
- * See design/02-rendering-pipeline.md §"The Flush Point" and §"The Hold Window"
1715
- */
1716
- /**
1717
- * Execute a render and hold the response until the shell is ready.
1718
- *
1719
- * The flush controller:
1720
- * 1. Calls the render function to start renderToReadableStream
1721
- * 2. Waits for shellReady (onShellReady)
1722
- * 3. If a render-phase signal was thrown (deny, redirect, error), produces
1723
- * the correct HTTP status code
1724
- * 4. If the shell rendered successfully, commits the status and streams
1725
- *
1726
- * Render-phase signals caught before flush:
1727
- * - `DenySignal` → HTTP 4xx with appropriate status code
1728
- * - `RedirectSignal` → HTTP 3xx with Location header
1729
- * - `RenderError` → HTTP status from error (default 500)
1730
- * - Unhandled error → HTTP 500
1731
- *
1732
- * @param renderFn - Function that starts the React render.
1733
- * @param options - Flush configuration.
1734
- * @returns The committed HTTP Response.
1735
- */
1736
- async function flushResponse(renderFn, options = {}) {
1737
- const { responseHeaders = new Headers(), defaultStatus = 200 } = options;
1738
- let renderResult;
1739
- try {
1740
- renderResult = await renderFn();
1741
- } catch (error) {
1742
- return handleSignal(error, responseHeaders);
1743
- }
1744
- try {
1745
- await renderResult.shellReady;
1746
- } catch (error) {
1747
- return handleSignal(error, responseHeaders);
1748
- }
1749
- responseHeaders.set("Content-Type", "text/html; charset=utf-8");
1750
- return {
1751
- response: new Response(renderResult.stream, {
1752
- status: defaultStatus,
1753
- headers: responseHeaders
1754
- }),
1755
- status: defaultStatus,
1756
- isRedirect: false,
1757
- isDenial: false
1758
- };
1759
- }
1760
- /**
1761
- * Handle a render-phase signal and produce the correct HTTP response.
1762
- */
1763
- function handleSignal(error, responseHeaders) {
1764
- if (error instanceof RedirectSignal) {
1765
- responseHeaders.set("Location", error.location);
1766
- return {
1767
- response: new Response(null, {
1768
- status: error.status,
1769
- headers: responseHeaders
1770
- }),
1771
- status: error.status,
1772
- isRedirect: true,
1773
- isDenial: false
1774
- };
1775
- }
1776
- if (error instanceof DenySignal) return {
1777
- response: new Response(null, {
1778
- status: error.status,
1779
- headers: responseHeaders
1780
- }),
1781
- status: error.status,
1782
- isRedirect: false,
1783
- isDenial: true
1784
- };
1785
- if (error instanceof RenderError) return {
1786
- response: new Response(null, {
1787
- status: error.status,
1788
- headers: responseHeaders
1789
- }),
1790
- status: error.status,
1791
- isRedirect: false,
1792
- isDenial: false
1793
- };
1794
- console.error("[timber] Unhandled render-phase error:", error);
1795
- return {
1796
- response: new Response(null, {
1797
- status: 500,
1798
- headers: responseHeaders
1799
- }),
1800
- status: 500,
1801
- isRedirect: false,
1802
- isDenial: false
1803
- };
1804
- }
1805
- //#endregion
1806
- //#region src/server/csrf.ts
1807
- /** HTTP methods that are considered safe (no mutation). */
1808
- var SAFE_METHODS = new Set([
1809
- "GET",
1810
- "HEAD",
1811
- "OPTIONS"
1812
- ]);
1813
- /**
1814
- * Validate the Origin header against the request's Host.
1815
- *
1816
- * For mutation methods (POST, PUT, PATCH, DELETE):
1817
- * - If `csrf: false`, skip validation.
1818
- * - If `allowedOrigins` is set, Origin must match one exactly (no wildcards).
1819
- * - Otherwise, Origin's host must match the request's Host header.
1820
- *
1821
- * Safe methods (GET, HEAD, OPTIONS) always pass.
1822
- */
1823
- function validateCsrf(req, config) {
1824
- if (SAFE_METHODS.has(req.method)) return { ok: true };
1825
- if (config.csrf === false) return { ok: true };
1826
- const origin = req.headers.get("Origin");
1827
- if (!origin) return {
1828
- ok: false,
1829
- status: 403
1830
- };
1831
- if (config.allowedOrigins) return config.allowedOrigins.includes(origin) ? { ok: true } : {
1832
- ok: false,
1833
- status: 403
1834
- };
1835
- const host = req.headers.get("Host");
1836
- if (!host) return {
1837
- ok: false,
1838
- status: 403
1839
- };
1840
- let originHost;
1841
- try {
1842
- originHost = new URL(origin).host;
1843
- } catch {
1844
- return {
1845
- ok: false,
1846
- status: 403
1847
- };
1848
- }
1849
- return originHost === host ? { ok: true } : {
1850
- ok: false,
1851
- status: 403
1852
- };
1853
- }
1854
- //#endregion
1855
- //#region src/server/body-limits.ts
1856
- var KB = 1024;
1857
- var MB = 1024 * KB;
1858
- var GB = 1024 * MB;
1859
- var DEFAULT_LIMITS = {
1860
- actionBodySize: 1 * MB,
1861
- uploadBodySize: 10 * MB,
1862
- maxFields: 100
1863
- };
1864
- var SIZE_PATTERN = /^(\d+(?:\.\d+)?)\s*(kb|mb|gb)?$/i;
1865
- /** Parse a human-readable size string ("1mb", "512kb", "1024") into bytes. */
1866
- function parseBodySize(size) {
1867
- const match = SIZE_PATTERN.exec(size.trim());
1868
- if (!match) throw new Error(`Invalid body size format: "${size}". Expected format like "1mb", "512kb", or "1024".`);
1869
- const value = Number.parseFloat(match[1]);
1870
- const unit = (match[2] ?? "").toLowerCase();
1871
- switch (unit) {
1872
- case "kb": return Math.floor(value * KB);
1873
- case "mb": return Math.floor(value * MB);
1874
- case "gb": return Math.floor(value * GB);
1875
- case "": return Math.floor(value);
1876
- default: throw new Error(`Unknown size unit: "${unit}"`);
1877
- }
1878
- }
1879
- /** Check whether a request body exceeds the configured size limit (stateless, no ALS). */
1880
- function enforceBodyLimits(req, kind, config) {
1881
- const contentLength = req.headers.get("Content-Length");
1882
- if (!contentLength) return {
1883
- ok: false,
1884
- status: 411
1885
- };
1886
- const bodySize = Number.parseInt(contentLength, 10);
1887
- if (Number.isNaN(bodySize)) return {
1888
- ok: false,
1889
- status: 411
1890
- };
1891
- return bodySize <= resolveLimit(kind, config) ? { ok: true } : {
1892
- ok: false,
1893
- status: 413
1894
- };
1895
- }
1896
- /**
1897
- * Resolve the byte limit for a given body kind, using config overrides or defaults.
1898
- */
1899
- function resolveLimit(kind, config) {
1900
- const userLimits = config.limits;
1901
- if (kind === "action") return userLimits?.actionBodySize ? parseBodySize(userLimits.actionBodySize) : DEFAULT_LIMITS.actionBodySize;
1902
- return userLimits?.uploadBodySize ? parseBodySize(userLimits.uploadBodySize) : DEFAULT_LIMITS.uploadBodySize;
1903
- }
1904
- //#endregion
1905
- //#region src/server/metadata-social.ts
1906
- /**
1907
- * Render Open Graph metadata into head element descriptors.
1908
- *
1909
- * Handles og:title, og:description, og:image (with dimensions/alt),
1910
- * og:video, og:audio, og:article:author, and other OG properties.
1911
- */
1912
- function renderOpenGraph(og, elements) {
1913
- const simpleProps = [
1914
- ["og:title", og.title],
1915
- ["og:description", og.description],
1916
- ["og:url", og.url],
1917
- ["og:site_name", og.siteName],
1918
- ["og:locale", og.locale],
1919
- ["og:type", og.type],
1920
- ["og:article:published_time", og.publishedTime],
1921
- ["og:article:modified_time", og.modifiedTime]
1922
- ];
1923
- for (const [property, content] of simpleProps) if (content) elements.push({
1924
- tag: "meta",
1925
- attrs: {
1926
- property,
1927
- content
1928
- }
1929
- });
1930
- if (og.images) if (typeof og.images === "string") elements.push({
1931
- tag: "meta",
1932
- attrs: {
1933
- property: "og:image",
1934
- content: og.images
1935
- }
1936
- });
1937
- else {
1938
- const imgList = Array.isArray(og.images) ? og.images : [og.images];
1939
- for (const img of imgList) {
1940
- elements.push({
1941
- tag: "meta",
1942
- attrs: {
1943
- property: "og:image",
1944
- content: img.url
1945
- }
1946
- });
1947
- if (img.width) elements.push({
1948
- tag: "meta",
1949
- attrs: {
1950
- property: "og:image:width",
1951
- content: String(img.width)
1952
- }
1953
- });
1954
- if (img.height) elements.push({
1955
- tag: "meta",
1956
- attrs: {
1957
- property: "og:image:height",
1958
- content: String(img.height)
1959
- }
1960
- });
1961
- if (img.alt) elements.push({
1962
- tag: "meta",
1963
- attrs: {
1964
- property: "og:image:alt",
1965
- content: img.alt
1966
- }
1967
- });
1968
- }
1969
- }
1970
- if (og.videos) for (const video of og.videos) elements.push({
1971
- tag: "meta",
1972
- attrs: {
1973
- property: "og:video",
1974
- content: video.url
1975
- }
1976
- });
1977
- if (og.audio) for (const audio of og.audio) elements.push({
1978
- tag: "meta",
1979
- attrs: {
1980
- property: "og:audio",
1981
- content: audio.url
1982
- }
1983
- });
1984
- if (og.authors) for (const author of og.authors) elements.push({
1985
- tag: "meta",
1986
- attrs: {
1987
- property: "og:article:author",
1988
- content: author
1989
- }
1990
- });
1991
- }
1992
- /**
1993
- * Render Twitter Card metadata into head element descriptors.
1994
- *
1995
- * Handles twitter:card, twitter:site, twitter:title, twitter:image,
1996
- * twitter:player, and twitter:app (per-platform name/id/url).
1997
- */
1998
- function renderTwitter(tw, elements) {
1999
- const simpleProps = [
2000
- ["twitter:card", tw.card],
2001
- ["twitter:site", tw.site],
2002
- ["twitter:site:id", tw.siteId],
2003
- ["twitter:title", tw.title],
2004
- ["twitter:description", tw.description],
2005
- ["twitter:creator", tw.creator],
2006
- ["twitter:creator:id", tw.creatorId]
2007
- ];
2008
- for (const [name, content] of simpleProps) if (content) elements.push({
2009
- tag: "meta",
2010
- attrs: {
2011
- name,
2012
- content
2013
- }
2014
- });
2015
- if (tw.images) if (typeof tw.images === "string") elements.push({
2016
- tag: "meta",
2017
- attrs: {
2018
- name: "twitter:image",
2019
- content: tw.images
2020
- }
2021
- });
2022
- else {
2023
- const imgList = Array.isArray(tw.images) ? tw.images : [tw.images];
2024
- for (const img of imgList) {
2025
- const url = typeof img === "string" ? img : img.url;
2026
- elements.push({
2027
- tag: "meta",
2028
- attrs: {
2029
- name: "twitter:image",
2030
- content: url
2031
- }
2032
- });
2033
- }
2034
- }
2035
- if (tw.players) for (const player of tw.players) {
2036
- elements.push({
2037
- tag: "meta",
2038
- attrs: {
2039
- name: "twitter:player",
2040
- content: player.playerUrl
2041
- }
2042
- });
2043
- if (player.width) elements.push({
2044
- tag: "meta",
2045
- attrs: {
2046
- name: "twitter:player:width",
2047
- content: String(player.width)
2048
- }
2049
- });
2050
- if (player.height) elements.push({
2051
- tag: "meta",
2052
- attrs: {
2053
- name: "twitter:player:height",
2054
- content: String(player.height)
2055
- }
2056
- });
2057
- if (player.streamUrl) elements.push({
2058
- tag: "meta",
2059
- attrs: {
2060
- name: "twitter:player:stream",
2061
- content: player.streamUrl
2062
- }
2063
- });
2064
- }
2065
- if (tw.app) {
2066
- const platforms = [
2067
- ["iPhone", "iphone"],
2068
- ["iPad", "ipad"],
2069
- ["googlePlay", "googleplay"]
2070
- ];
2071
- if (tw.app.name) {
2072
- for (const [key, tag] of platforms) if (tw.app.id?.[key]) elements.push({
2073
- tag: "meta",
2074
- attrs: {
2075
- name: `twitter:app:name:${tag}`,
2076
- content: tw.app.name
2077
- }
2078
- });
2079
- }
2080
- for (const [key, tag] of platforms) {
2081
- const id = tw.app.id?.[key];
2082
- if (id) elements.push({
2083
- tag: "meta",
2084
- attrs: {
2085
- name: `twitter:app:id:${tag}`,
2086
- content: id
2087
- }
2088
- });
2089
- }
2090
- for (const [key, tag] of platforms) {
2091
- const url = tw.app.url?.[key];
2092
- if (url) elements.push({
2093
- tag: "meta",
2094
- attrs: {
2095
- name: `twitter:app:url:${tag}`,
2096
- content: url
2097
- }
2098
- });
2099
- }
2100
- }
2101
- }
2102
- //#endregion
2103
- //#region src/server/metadata-platform.ts
2104
- /**
2105
- * Render icon link elements (favicon, shortcut, apple-touch-icon, custom).
2106
- */
2107
- function renderIcons(icons, elements) {
2108
- if (icons.icon) {
2109
- if (typeof icons.icon === "string") elements.push({
2110
- tag: "link",
2111
- attrs: {
2112
- rel: "icon",
2113
- href: icons.icon
2114
- }
2115
- });
2116
- else if (Array.isArray(icons.icon)) for (const icon of icons.icon) {
2117
- const attrs = {
2118
- rel: "icon",
2119
- href: icon.url
2120
- };
2121
- if (icon.sizes) attrs.sizes = icon.sizes;
2122
- if (icon.type) attrs.type = icon.type;
2123
- elements.push({
2124
- tag: "link",
2125
- attrs
2126
- });
2127
- }
2128
- }
2129
- if (icons.shortcut) {
2130
- const urls = Array.isArray(icons.shortcut) ? icons.shortcut : [icons.shortcut];
2131
- for (const url of urls) elements.push({
2132
- tag: "link",
2133
- attrs: {
2134
- rel: "shortcut icon",
2135
- href: url
2136
- }
2137
- });
2138
- }
2139
- if (icons.apple) {
2140
- if (typeof icons.apple === "string") elements.push({
2141
- tag: "link",
2142
- attrs: {
2143
- rel: "apple-touch-icon",
2144
- href: icons.apple
2145
- }
2146
- });
2147
- else if (Array.isArray(icons.apple)) for (const icon of icons.apple) {
2148
- const attrs = {
2149
- rel: "apple-touch-icon",
2150
- href: icon.url
2151
- };
2152
- if (icon.sizes) attrs.sizes = icon.sizes;
2153
- elements.push({
2154
- tag: "link",
2155
- attrs
2156
- });
2157
- }
2158
- }
2159
- if (icons.other) for (const icon of icons.other) {
2160
- const attrs = {
2161
- rel: icon.rel,
2162
- href: icon.url
2163
- };
2164
- if (icon.sizes) attrs.sizes = icon.sizes;
2165
- if (icon.type) attrs.type = icon.type;
2166
- elements.push({
2167
- tag: "link",
2168
- attrs
2169
- });
2170
- }
2171
- }
2172
- /**
2173
- * Render alternate link elements (canonical, hreflang, media, types).
2174
- */
2175
- function renderAlternates(alternates, elements) {
2176
- if (alternates.canonical) elements.push({
2177
- tag: "link",
2178
- attrs: {
2179
- rel: "canonical",
2180
- href: alternates.canonical
2181
- }
2182
- });
2183
- if (alternates.languages) for (const [lang, href] of Object.entries(alternates.languages)) elements.push({
2184
- tag: "link",
2185
- attrs: {
2186
- rel: "alternate",
2187
- hreflang: lang,
2188
- href
2189
- }
2190
- });
2191
- if (alternates.media) for (const [media, href] of Object.entries(alternates.media)) elements.push({
2192
- tag: "link",
2193
- attrs: {
2194
- rel: "alternate",
2195
- media,
2196
- href
2197
- }
2198
- });
2199
- if (alternates.types) for (const [type, href] of Object.entries(alternates.types)) elements.push({
2200
- tag: "link",
2201
- attrs: {
2202
- rel: "alternate",
2203
- type,
2204
- href
2205
- }
2206
- });
2207
- }
2208
- /**
2209
- * Render site verification meta tags (Google, Yahoo, Yandex, custom).
2210
- */
2211
- function renderVerification(verification, elements) {
2212
- const verificationProps = [
2213
- ["google-site-verification", verification.google],
2214
- ["y_key", verification.yahoo],
2215
- ["yandex-verification", verification.yandex]
2216
- ];
2217
- for (const [name, content] of verificationProps) if (content) elements.push({
2218
- tag: "meta",
2219
- attrs: {
2220
- name,
2221
- content
2222
- }
2223
- });
2224
- if (verification.other) for (const [name, value] of Object.entries(verification.other)) {
2225
- const content = Array.isArray(value) ? value.join(", ") : value;
2226
- elements.push({
2227
- tag: "meta",
2228
- attrs: {
2229
- name,
2230
- content
2231
- }
2232
- });
2233
- }
2234
- }
2235
- /**
2236
- * Render Apple Web App meta tags and startup image links.
2237
- */
2238
- function renderAppleWebApp(appleWebApp, elements) {
2239
- if (appleWebApp.capable) elements.push({
2240
- tag: "meta",
2241
- attrs: {
2242
- name: "apple-mobile-web-app-capable",
2243
- content: "yes"
2244
- }
2245
- });
2246
- if (appleWebApp.title) elements.push({
2247
- tag: "meta",
2248
- attrs: {
2249
- name: "apple-mobile-web-app-title",
2250
- content: appleWebApp.title
2251
- }
2252
- });
2253
- if (appleWebApp.statusBarStyle) elements.push({
2254
- tag: "meta",
2255
- attrs: {
2256
- name: "apple-mobile-web-app-status-bar-style",
2257
- content: appleWebApp.statusBarStyle
2258
- }
2259
- });
2260
- if (appleWebApp.startupImage) {
2261
- const images = Array.isArray(appleWebApp.startupImage) ? appleWebApp.startupImage : [{ url: appleWebApp.startupImage }];
2262
- for (const img of images) {
2263
- const attrs = {
2264
- rel: "apple-touch-startup-image",
2265
- href: typeof img === "string" ? img : img.url
2266
- };
2267
- if (typeof img === "object" && img.media) attrs.media = img.media;
2268
- elements.push({
2269
- tag: "link",
2270
- attrs
2271
- });
2272
- }
2273
- }
2274
- }
2275
- /**
2276
- * Render App Links (al:*) meta tags for deep linking across platforms.
2277
- */
2278
- function renderAppLinks(appLinks, elements) {
2279
- const platformEntries = [
2280
- ["ios", appLinks.ios],
2281
- ["android", appLinks.android],
2282
- ["windows", appLinks.windows],
2283
- ["windows_phone", appLinks.windowsPhone],
2284
- ["windows_universal", appLinks.windowsUniversal]
2285
- ];
2286
- for (const [platform, entries] of platformEntries) {
2287
- if (!entries) continue;
2288
- for (const entry of entries) for (const [key, value] of Object.entries(entry)) if (value !== void 0 && value !== null) elements.push({
2289
- tag: "meta",
2290
- attrs: {
2291
- property: `al:${platform}:${key}`,
2292
- content: String(value)
2293
- }
2294
- });
2295
- }
2296
- if (appLinks.web) {
2297
- if (appLinks.web.url) elements.push({
2298
- tag: "meta",
2299
- attrs: {
2300
- property: "al:web:url",
2301
- content: appLinks.web.url
2302
- }
2303
- });
2304
- if (appLinks.web.shouldFallback !== void 0) elements.push({
2305
- tag: "meta",
2306
- attrs: {
2307
- property: "al:web:should_fallback",
2308
- content: appLinks.web.shouldFallback ? "true" : "false"
2309
- }
2310
- });
2311
- }
2312
- }
2313
- /**
2314
- * Render Apple iTunes smart banner meta tag.
2315
- */
2316
- function renderItunes(itunes, elements) {
2317
- const parts = [`app-id=${itunes.appId}`];
2318
- if (itunes.affiliateData) parts.push(`affiliate-data=${itunes.affiliateData}`);
2319
- if (itunes.appArgument) parts.push(`app-argument=${itunes.appArgument}`);
2320
- elements.push({
2321
- tag: "meta",
2322
- attrs: {
2323
- name: "apple-itunes-app",
2324
- content: parts.join(", ")
2325
- }
2326
- });
2327
- }
2328
- //#endregion
2329
- //#region src/server/metadata-render.ts
2330
- /**
2331
- * Convert resolved metadata into an array of head element descriptors.
2332
- *
2333
- * Each descriptor has a `tag` ('title', 'meta', 'link') and either
2334
- * `content` (for <title>) or `attrs` (for <meta>/<link>).
2335
- *
2336
- * The framework's MetadataResolver component consumes these descriptors
2337
- * and renders them into the <head>.
2338
- */
2339
- function renderMetadataToElements(metadata) {
2340
- const elements = [];
2341
- if (typeof metadata.title === "string") elements.push({
2342
- tag: "title",
2343
- content: metadata.title
2344
- });
2345
- const simpleMetaProps = [
2346
- ["description", metadata.description],
2347
- ["generator", metadata.generator],
2348
- ["application-name", metadata.applicationName],
2349
- ["referrer", metadata.referrer],
2350
- ["category", metadata.category],
2351
- ["creator", metadata.creator],
2352
- ["publisher", metadata.publisher]
2353
- ];
2354
- for (const [name, content] of simpleMetaProps) if (content) elements.push({
2355
- tag: "meta",
2356
- attrs: {
2357
- name,
2358
- content
2359
- }
2360
- });
2361
- if (metadata.keywords) {
2362
- const content = Array.isArray(metadata.keywords) ? metadata.keywords.join(", ") : metadata.keywords;
2363
- elements.push({
2364
- tag: "meta",
2365
- attrs: {
2366
- name: "keywords",
2367
- content
2368
- }
2369
- });
2370
- }
2371
- if (metadata.robots) {
2372
- const content = typeof metadata.robots === "string" ? metadata.robots : renderRobotsObject(metadata.robots);
2373
- elements.push({
2374
- tag: "meta",
2375
- attrs: {
2376
- name: "robots",
2377
- content
2378
- }
2379
- });
2380
- if (typeof metadata.robots === "object" && metadata.robots.googleBot) {
2381
- const gbContent = typeof metadata.robots.googleBot === "string" ? metadata.robots.googleBot : renderRobotsObject(metadata.robots.googleBot);
2382
- elements.push({
2383
- tag: "meta",
2384
- attrs: {
2385
- name: "googlebot",
2386
- content: gbContent
2387
- }
2388
- });
2389
- }
2390
- }
2391
- if (metadata.openGraph) renderOpenGraph(metadata.openGraph, elements);
2392
- if (metadata.twitter) renderTwitter(metadata.twitter, elements);
2393
- if (metadata.icons) renderIcons(metadata.icons, elements);
2394
- if (metadata.manifest) elements.push({
2395
- tag: "link",
2396
- attrs: {
2397
- rel: "manifest",
2398
- href: metadata.manifest
2399
- }
2400
- });
2401
- if (metadata.alternates) renderAlternates(metadata.alternates, elements);
2402
- if (metadata.verification) renderVerification(metadata.verification, elements);
2403
- if (metadata.formatDetection) {
2404
- const parts = [];
2405
- if (metadata.formatDetection.telephone === false) parts.push("telephone=no");
2406
- if (metadata.formatDetection.email === false) parts.push("email=no");
2407
- if (metadata.formatDetection.address === false) parts.push("address=no");
2408
- if (parts.length > 0) elements.push({
2409
- tag: "meta",
2410
- attrs: {
2411
- name: "format-detection",
2412
- content: parts.join(", ")
2413
- }
2414
- });
2415
- }
2416
- if (metadata.authors) {
2417
- const authorList = Array.isArray(metadata.authors) ? metadata.authors : [metadata.authors];
2418
- for (const author of authorList) {
2419
- if (author.name) elements.push({
2420
- tag: "meta",
2421
- attrs: {
2422
- name: "author",
2423
- content: author.name
2424
- }
2425
- });
2426
- if (author.url) elements.push({
2427
- tag: "link",
2428
- attrs: {
2429
- rel: "author",
2430
- href: author.url
2431
- }
2432
- });
2433
- }
2434
- }
2435
- if (metadata.appleWebApp) renderAppleWebApp(metadata.appleWebApp, elements);
2436
- if (metadata.appLinks) renderAppLinks(metadata.appLinks, elements);
2437
- if (metadata.itunes) renderItunes(metadata.itunes, elements);
2438
- if (metadata.other) for (const [name, value] of Object.entries(metadata.other)) {
2439
- const content = Array.isArray(value) ? value.join(", ") : value;
2440
- elements.push({
2441
- tag: "meta",
2442
- attrs: {
2443
- name,
2444
- content
2445
- }
2446
- });
2447
- }
2448
- return elements;
2449
- }
2450
- function renderRobotsObject(robots) {
2451
- const parts = [];
2452
- if (robots.index === true) parts.push("index");
2453
- if (robots.index === false) parts.push("noindex");
2454
- if (robots.follow === true) parts.push("follow");
2455
- if (robots.follow === false) parts.push("nofollow");
2456
- return parts.join(", ");
2457
- }
2458
- //#endregion
2459
- //#region src/server/metadata.ts
2460
- /**
2461
- * Resolve a title value with an optional template.
2462
- *
2463
- * - string → apply template if present
2464
- * - { absolute: '...' } → use as-is, skip template
2465
- * - { default: '...' } → use as fallback (no template applied)
2466
- * - undefined → undefined
2467
- */
2468
- function resolveTitle(title, template) {
2469
- if (title === void 0 || title === null) return;
2470
- if (typeof title === "string") return template ? template.replace("%s", title) : title;
2471
- if (title.absolute !== void 0) return title.absolute;
2472
- if (title.default !== void 0) return title.default;
2473
- }
2474
- /**
2475
- * Resolve metadata from a segment chain.
2476
- *
2477
- * Processes entries from root layout to page (in segment order).
2478
- * The merge algorithm:
2479
- * 1. Shallow-merge all keys except title (later wins)
2480
- * 2. Track the most recent title template
2481
- * 3. Resolve the final title using the template
2482
- *
2483
- * In error state, the page entry is dropped and noindex is injected.
2484
- *
2485
- * See design/16-metadata.md §"Merge Algorithm"
2486
- */
2487
- function resolveMetadata(entries, options = {}) {
2488
- const { errorState = false } = options;
2489
- const merged = {};
2490
- let titleTemplate;
2491
- let lastDefault;
2492
- let rawTitle;
2493
- for (const { metadata, isPage } of entries) {
2494
- if (errorState && isPage) continue;
2495
- if (metadata.title !== void 0 && typeof metadata.title === "object") {
2496
- if (metadata.title.template !== void 0) titleTemplate = metadata.title.template;
2497
- if (metadata.title.default !== void 0) lastDefault = metadata.title.default;
2498
- }
2499
- for (const key of Object.keys(metadata)) {
2500
- if (key === "title") continue;
2501
- merged[key] = metadata[key];
2502
- }
2503
- if (metadata.title !== void 0) rawTitle = metadata.title;
2504
- }
2505
- if (errorState) {
2506
- rawTitle = lastDefault !== void 0 ? { default: lastDefault } : rawTitle;
2507
- titleTemplate = void 0;
2508
- }
2509
- const resolvedTitle = resolveTitle(rawTitle, titleTemplate);
2510
- if (resolvedTitle !== void 0) merged.title = resolvedTitle;
2511
- if (errorState) merged.robots = "noindex";
2512
- return merged;
2513
- }
2514
- /**
2515
- * Check if a string is an absolute URL.
2516
- */
2517
- function isAbsoluteUrl(url) {
2518
- return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//");
2519
- }
2520
- /**
2521
- * Resolve a relative URL against a base URL.
2522
- */
2523
- function resolveUrl(url, base) {
2524
- if (isAbsoluteUrl(url)) return url;
2525
- return new URL(url, base).toString();
2526
- }
2527
- /**
2528
- * Resolve relative URLs in metadata fields against metadataBase.
2529
- *
2530
- * Returns a new metadata object with URLs resolved. Absolute URLs are not modified.
2531
- * If metadataBase is not set, returns the metadata unchanged.
2532
- */
2533
- function resolveMetadataUrls(metadata) {
2534
- const base = metadata.metadataBase;
2535
- if (!base) return metadata;
2536
- const result = { ...metadata };
2537
- if (result.openGraph) {
2538
- result.openGraph = { ...result.openGraph };
2539
- if (typeof result.openGraph.images === "string") result.openGraph.images = resolveUrl(result.openGraph.images, base);
2540
- else if (Array.isArray(result.openGraph.images)) result.openGraph.images = result.openGraph.images.map((img) => ({
2541
- ...img,
2542
- url: resolveUrl(img.url, base)
2543
- }));
2544
- else if (result.openGraph.images) result.openGraph.images = {
2545
- ...result.openGraph.images,
2546
- url: resolveUrl(result.openGraph.images.url, base)
2547
- };
2548
- if (result.openGraph.url && !isAbsoluteUrl(result.openGraph.url)) result.openGraph.url = resolveUrl(result.openGraph.url, base);
2549
- }
2550
- if (result.twitter) {
2551
- result.twitter = { ...result.twitter };
2552
- if (typeof result.twitter.images === "string") result.twitter.images = resolveUrl(result.twitter.images, base);
2553
- else if (Array.isArray(result.twitter.images)) {
2554
- const resolved = result.twitter.images.map((img) => typeof img === "string" ? resolveUrl(img, base) : {
2555
- ...img,
2556
- url: resolveUrl(img.url, base)
2557
- });
2558
- const allStrings = resolved.every((r) => typeof r === "string");
2559
- result.twitter.images = allStrings ? resolved : resolved;
2560
- } else if (result.twitter.images) result.twitter.images = {
2561
- ...result.twitter.images,
2562
- url: resolveUrl(result.twitter.images.url, base)
2563
- };
2564
- }
2565
- if (result.alternates) {
2566
- result.alternates = { ...result.alternates };
2567
- if (result.alternates.canonical && !isAbsoluteUrl(result.alternates.canonical)) result.alternates.canonical = resolveUrl(result.alternates.canonical, base);
2568
- if (result.alternates.languages) {
2569
- const langs = {};
2570
- for (const [lang, url] of Object.entries(result.alternates.languages)) langs[lang] = isAbsoluteUrl(url) ? url : resolveUrl(url, base);
2571
- result.alternates.languages = langs;
2572
- }
2573
- }
2574
- if (result.icons) {
2575
- result.icons = { ...result.icons };
2576
- if (typeof result.icons.icon === "string") result.icons.icon = resolveUrl(result.icons.icon, base);
2577
- else if (Array.isArray(result.icons.icon)) result.icons.icon = result.icons.icon.map((i) => ({
2578
- ...i,
2579
- url: resolveUrl(i.url, base)
2580
- }));
2581
- if (typeof result.icons.apple === "string") result.icons.apple = resolveUrl(result.icons.apple, base);
2582
- else if (Array.isArray(result.icons.apple)) result.icons.apple = result.icons.apple.map((i) => ({
2583
- ...i,
2584
- url: resolveUrl(i.url, base)
2585
- }));
2586
- }
2587
- return result;
2588
- }
2589
- //#endregion
1
+ import { n as isDevMode, t as isDebug } from "../_chunks/debug-ECi_61pb.js";
2
+ import { t as formatSize } from "../_chunks/format-CYBGxKtc.js";
3
+ import { n as formFlashAls } from "../_chunks/als-registry-HS0LGUl2.js";
4
+ import { n as defineSegmentParams } from "../_chunks/define-C77ScO0m.js";
5
+ import { a as getHeaders, c as getSegmentParams, i as getHeader, n as getCookie, r as getCookies, s as getSearchParams } from "../_chunks/request-context-qMsWgy9C.js";
6
+ import { a as revalidateTag, c as RedirectType, d as redirect, f as redirectExternal, i as revalidatePath, o as DenySignal, p as waitUntil, s as RedirectSignal, u as deny } from "../_chunks/actions-Dg-ANYHb.js";
7
+ import { a as getSpanId, d as withSpan, o as getTraceId, t as addSpanEvent } from "../_chunks/tracing-CCYbKn5n.js";
2590
8
  //#region src/server/form-data.ts
2591
9
  /**
2592
10
  * FormData preprocessing — schema-agnostic conversion of FormData to typed objects.
@@ -2697,6 +115,35 @@ var coerce = {
2697
115
  } catch {
2698
116
  return;
2699
117
  }
118
+ },
119
+ date(value) {
120
+ if (value === void 0 || value === null || value === "") return void 0;
121
+ if (value instanceof Date) return value;
122
+ if (typeof value !== "string") return void 0;
123
+ const date = new Date(value);
124
+ if (Number.isNaN(date.getTime())) return void 0;
125
+ const ymdMatch = value.match(/^(\d{4})-(\d{2})-(\d{2})/);
126
+ if (ymdMatch) {
127
+ const inputYear = Number(ymdMatch[1]);
128
+ const inputMonth = Number(ymdMatch[2]);
129
+ const inputDay = Number(ymdMatch[3]);
130
+ const isUTC = value.length === 10 || value.endsWith("Z");
131
+ const parsedYear = isUTC ? date.getUTCFullYear() : date.getFullYear();
132
+ const parsedMonth = isUTC ? date.getUTCMonth() + 1 : date.getMonth() + 1;
133
+ const parsedDay = isUTC ? date.getUTCDate() : date.getDate();
134
+ if (inputYear !== parsedYear || inputMonth !== parsedMonth || inputDay !== parsedDay) return;
135
+ }
136
+ return date;
137
+ },
138
+ file(options) {
139
+ return (value) => {
140
+ if (value === void 0 || value === null || value === "") return void 0;
141
+ if (!(value instanceof File)) return void 0;
142
+ if (value.size === 0 && value.name === "") return void 0;
143
+ if (options?.maxSize !== void 0 && value.size > options.maxSize) return;
144
+ if (options?.accept !== void 0 && !options.accept.includes(value.type)) return;
145
+ return value;
146
+ };
2700
147
  }
2701
148
  };
2702
149
  //#endregion
@@ -2879,6 +326,7 @@ function createActionClient(config = {}) {
2879
326
  input
2880
327
  }) };
2881
328
  } catch (error) {
329
+ if (error instanceof RedirectSignal || error instanceof DenySignal) throw error;
2882
330
  return handleActionError(error);
2883
331
  }
2884
332
  }
@@ -2987,214 +435,6 @@ function getFormFlash() {
2987
435
  return formFlashAls.getStore() ?? null;
2988
436
  }
2989
437
  //#endregion
2990
- //#region src/server/actions.ts
2991
- /**
2992
- * Get the current revalidation state. Throws if called outside an action context.
2993
- * @internal
2994
- */
2995
- function getRevalidationState() {
2996
- const state = revalidationAls.getStore();
2997
- if (!state) throw new Error("revalidatePath/revalidateTag called outside of a server action context. These functions can only be called during action execution.");
2998
- return state;
2999
- }
3000
- /**
3001
- * Re-render the route at `path` and include the RSC flight payload in the
3002
- * action response. The client reconciles inline — no separate fetch needed.
3003
- *
3004
- * Can be called from server actions, API routes, or any server-side context.
3005
- *
3006
- * @param path - The path to re-render (e.g. '/dashboard', '/todos').
3007
- */
3008
- function revalidatePath(path) {
3009
- const state = getRevalidationState();
3010
- if (!state.paths.includes(path)) state.paths.push(path);
3011
- }
3012
- /**
3013
- * Invalidate all pre-rendered shells and 'use cache' entries tagged with `tag`.
3014
- * Does not return a payload — the next request for an invalidated route re-renders fresh.
3015
- *
3016
- * @param tag - The cache tag to invalidate (e.g. 'products', 'user:123').
3017
- */
3018
- function revalidateTag(tag) {
3019
- const state = getRevalidationState();
3020
- if (!state.tags.includes(tag)) state.tags.push(tag);
3021
- }
3022
- /**
3023
- * Execute a server action and process revalidation.
3024
- *
3025
- * 1. Sets up revalidation state
3026
- * 2. Calls the action function
3027
- * 3. Processes revalidateTag calls (invalidates cache entries)
3028
- * 4. Processes revalidatePath calls (re-renders and captures RSC payload)
3029
- * 5. Returns the action result + optional RSC payload
3030
- *
3031
- * @param actionFn - The server action function to execute.
3032
- * @param args - Arguments to pass to the action.
3033
- * @param config - Handler configuration (cache handler, renderer).
3034
- */
3035
- async function executeAction(actionFn, args, config = {}, spanMeta) {
3036
- const state = {
3037
- paths: [],
3038
- tags: []
3039
- };
3040
- let actionResult;
3041
- let redirectTo;
3042
- let redirectStatus;
3043
- await revalidationAls.run(state, async () => {
3044
- try {
3045
- actionResult = await withSpan("timber.action", {
3046
- ...spanMeta?.actionFile ? { "timber.action_file": spanMeta.actionFile } : {},
3047
- ...spanMeta?.actionName ? { "timber.action_name": spanMeta.actionName } : {}
3048
- }, () => actionFn(...args));
3049
- } catch (error) {
3050
- if (error instanceof RedirectSignal) {
3051
- redirectTo = error.location;
3052
- redirectStatus = error.status;
3053
- } else throw error;
3054
- }
3055
- });
3056
- if (state.tags.length > 0 && config.cacheHandler) await Promise.all(state.tags.map((tag) => config.cacheHandler.invalidate({ tag })));
3057
- let revalidation;
3058
- if (state.paths.length > 0 && config.renderer) {
3059
- const path = state.paths[0];
3060
- try {
3061
- revalidation = await config.renderer(path);
3062
- } catch (renderError) {
3063
- if (renderError instanceof RedirectSignal) {
3064
- redirectTo = renderError.location;
3065
- redirectStatus = renderError.status;
3066
- } else console.error("[timber] revalidatePath render failed:", renderError);
3067
- }
3068
- }
3069
- return {
3070
- actionResult,
3071
- revalidation,
3072
- ...redirectTo ? {
3073
- redirectTo,
3074
- redirectStatus
3075
- } : {}
3076
- };
3077
- }
3078
- /**
3079
- * Build an HTTP Response for a no-JS form submission.
3080
- * Standard POST → 302 redirect pattern.
3081
- *
3082
- * @param redirectPath - Where to redirect after the action executes.
3083
- */
3084
- function buildNoJsResponse(redirectPath, status = 302) {
3085
- return new Response(null, {
3086
- status,
3087
- headers: { Location: redirectPath }
3088
- });
3089
- }
3090
- /**
3091
- * Detect whether the incoming request is an RSC action request (with JS)
3092
- * or a plain HTML form POST (no JS).
3093
- *
3094
- * RSC action requests use Accept: text/x-component or Content-Type: text/x-component.
3095
- */
3096
- function isRscActionRequest(req) {
3097
- const accept = req.headers.get("Accept") ?? "";
3098
- const contentType = req.headers.get("Content-Type") ?? "";
3099
- return accept.includes("text/x-component") || contentType.includes("text/x-component");
3100
- }
3101
- //#endregion
3102
- //#region src/server/route-handler.ts
3103
- /** All recognized HTTP method export names. */
3104
- var HTTP_METHODS = [
3105
- "GET",
3106
- "POST",
3107
- "PUT",
3108
- "PATCH",
3109
- "DELETE",
3110
- "HEAD",
3111
- "OPTIONS"
3112
- ];
3113
- /**
3114
- * Resolve the full list of allowed methods for a route module.
3115
- *
3116
- * Includes:
3117
- * - All explicitly exported methods
3118
- * - HEAD (implicit when GET is exported)
3119
- * - OPTIONS (always implicit)
3120
- */
3121
- function resolveAllowedMethods(mod) {
3122
- const methods = [];
3123
- for (const method of HTTP_METHODS) {
3124
- if (method === "HEAD" || method === "OPTIONS") continue;
3125
- if (mod[method]) methods.push(method);
3126
- }
3127
- if (mod.GET && !mod.HEAD) methods.push("HEAD");
3128
- else if (mod.HEAD) methods.push("HEAD");
3129
- if (!mod.OPTIONS) methods.push("OPTIONS");
3130
- else methods.push("OPTIONS");
3131
- return methods;
3132
- }
3133
- /**
3134
- * Handle an incoming request against a route.ts module.
3135
- *
3136
- * Dispatches to the named method handler, auto-generates 405/OPTIONS,
3137
- * and merges response headers from ctx.headers.
3138
- */
3139
- async function handleRouteRequest(mod, ctx) {
3140
- const method = ctx.req.method.toUpperCase();
3141
- const allowHeader = resolveAllowedMethods(mod).join(", ");
3142
- if (method === "OPTIONS") {
3143
- if (mod.OPTIONS) return runHandler(mod.OPTIONS, ctx);
3144
- return new Response(null, {
3145
- status: 204,
3146
- headers: { Allow: allowHeader }
3147
- });
3148
- }
3149
- if (method === "HEAD") {
3150
- if (mod.HEAD) return runHandler(mod.HEAD, ctx);
3151
- if (mod.GET) {
3152
- const res = await runHandler(mod.GET, ctx);
3153
- return new Response(null, {
3154
- status: res.status,
3155
- headers: res.headers
3156
- });
3157
- }
3158
- }
3159
- const handler = mod[method];
3160
- if (!handler) return new Response(null, {
3161
- status: 405,
3162
- headers: { Allow: allowHeader }
3163
- });
3164
- return runHandler(handler, ctx);
3165
- }
3166
- /**
3167
- * Run a handler, merge ctx.headers into the response, and catch errors.
3168
- */
3169
- async function runHandler(handler, ctx) {
3170
- try {
3171
- return mergeResponseHeaders(await handler(ctx), ctx.headers);
3172
- } catch (error) {
3173
- console.error("[timber] Uncaught error in route.ts handler:", error);
3174
- return new Response(null, { status: 500 });
3175
- }
3176
- }
3177
- /**
3178
- * Merge response headers from ctx.headers into the handler's response.
3179
- * ctx.headers (set by middleware or the handler) are applied to the final response.
3180
- * Handler-set headers take precedence over ctx.headers.
3181
- */
3182
- function mergeResponseHeaders(res, ctxHeaders) {
3183
- let hasCtxHeaders = false;
3184
- ctxHeaders.forEach(() => {
3185
- hasCtxHeaders = true;
3186
- });
3187
- if (!hasCtxHeaders) return res;
3188
- const merged = new Headers();
3189
- ctxHeaders.forEach((value, key) => merged.set(key, value));
3190
- res.headers.forEach((value, key) => merged.set(key, value));
3191
- return new Response(res.body, {
3192
- status: res.status,
3193
- statusText: res.statusText,
3194
- headers: merged
3195
- });
3196
- }
3197
- //#endregion
3198
- export { AccessGate, ActionError, DEFAULT_LIMITS, DenySignal, METADATA_ROUTE_CONVENTIONS, RedirectSignal, RedirectType, RenderError, SlotAccessGate, WarningId, addSpanEvent, buildElementTree, buildNoJsResponse, callOnRequestError, canonicalize, classifyMetadataRoute, coerce, collectEarlyHintHeaders, cookies, createActionClient, createPipeline, deny, enforceBodyLimits, executeAction, flushResponse, formatLinkHeader, generateTraceId, getFormFlash, getLogger, getMetadataRouteAutoLink, getMetadataRouteServePath, getSetCookieHeaders, handleRouteRequest, hasOnRequestError, headers, isRscActionRequest, loadInstrumentation, logCacheMiss, logMiddlewareError, logMiddlewareShortCircuit, logProxyError, logRenderError, logRequestCompleted, logRequestReceived, logSlowRequest, logSwrRefetchFailed, logWaitUntilRejected, logWaitUntilUnsupported, markResponseFlushed, notFound, parseBodySize, parseFormData, permanentRedirect, redirect, redirectExternal, renderMetadataToElements, replaceTraceId, resolveAllowedMethods, resolveMetadata, resolveMetadataUrls, resolveSlotDenied, resolveStatusFile, resolveTitle, revalidatePath, revalidateTag, runMiddleware, runProxy, runWithEarlyHintsSender, runWithRequestContext, runWithTraceId, searchParams, sendEarlyHints103, setCookieSecrets, setLogger, setMutableCookieContext, setParsedSearchParams, setViteServer, spanId, traceId, validateCsrf, validated, waitUntil, warnCacheRequestProps, warnDenyAfterFlush, warnDenyInSuspense, warnDynamicApiInStaticBuild, warnRedirectInAccess, warnRedirectInSlotAccess, warnRedirectInSuspense, warnSlowSlotWithoutSuspense, warnStaticRequestApi, warnSuspenseWrappingChildren, withSpan };
438
+ export { ActionError, RedirectType, addSpanEvent, coerce, createActionClient, defineSegmentParams, deny, getCookie, getCookies, getFormFlash, getHeader, getHeaders, getSearchParams, getSegmentParams, getSpanId, getTraceId, parseFormData, redirect, redirectExternal, revalidatePath, revalidateTag, validated, waitUntil, withSpan };
3199
439
 
3200
440
  //# sourceMappingURL=index.js.map