@timber-js/app 0.2.0-alpha.1 → 0.2.0-alpha.100

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 (742) hide show
  1. package/LICENSE +8 -0
  2. package/dist/_chunks/actions-CQ8Z8VGL.js +1061 -0
  3. package/dist/_chunks/actions-CQ8Z8VGL.js.map +1 -0
  4. package/dist/_chunks/build-output-helper-DXnW0qjz.js +61 -0
  5. package/dist/_chunks/build-output-helper-DXnW0qjz.js.map +1 -0
  6. package/dist/_chunks/chunk-BYIpzuS7.js +39 -0
  7. package/dist/_chunks/define-B-Q_UMOD.js +195 -0
  8. package/dist/_chunks/define-B-Q_UMOD.js.map +1 -0
  9. package/dist/_chunks/define-CfBPoJb0.js +123 -0
  10. package/dist/_chunks/define-CfBPoJb0.js.map +1 -0
  11. package/dist/_chunks/define-cookie-BjpIt4UC.js +194 -0
  12. package/dist/_chunks/define-cookie-BjpIt4UC.js.map +1 -0
  13. package/dist/_chunks/format-Bcn-Iv1x.js +14 -0
  14. package/dist/_chunks/format-Bcn-Iv1x.js.map +1 -0
  15. package/dist/_chunks/handler-store-B-lqaGyh.js +54 -0
  16. package/dist/_chunks/handler-store-B-lqaGyh.js.map +1 -0
  17. package/dist/_chunks/logger-0m8MsKdc.js +291 -0
  18. package/dist/_chunks/logger-0m8MsKdc.js.map +1 -0
  19. package/dist/_chunks/merge-search-params-BphMdht_.js +122 -0
  20. package/dist/_chunks/merge-search-params-BphMdht_.js.map +1 -0
  21. package/dist/_chunks/{metadata-routes-CQCnF4VK.js → metadata-routes-BU684ls2.js} +1 -1
  22. package/dist/_chunks/{metadata-routes-CQCnF4VK.js.map → metadata-routes-BU684ls2.js.map} +1 -1
  23. package/dist/_chunks/navigation-root-BCYczjml.js +96 -0
  24. package/dist/_chunks/navigation-root-BCYczjml.js.map +1 -0
  25. package/dist/_chunks/registry-I2ss-lvy.js +20 -0
  26. package/dist/_chunks/registry-I2ss-lvy.js.map +1 -0
  27. package/dist/_chunks/router-ref-h3-UaCQv.js +28 -0
  28. package/dist/_chunks/router-ref-h3-UaCQv.js.map +1 -0
  29. package/dist/_chunks/schema-bridge-Cxu4l-7p.js +86 -0
  30. package/dist/_chunks/schema-bridge-Cxu4l-7p.js.map +1 -0
  31. package/dist/_chunks/segment-classify-BjfuctV2.js +137 -0
  32. package/dist/_chunks/segment-classify-BjfuctV2.js.map +1 -0
  33. package/dist/_chunks/segment-context-Dx_OizxD.js +34 -0
  34. package/dist/_chunks/segment-context-Dx_OizxD.js.map +1 -0
  35. package/dist/_chunks/{ssr-data-DLnbYpj1.js → ssr-data-B4CdH7rE.js} +1 -1
  36. package/dist/_chunks/ssr-data-B4CdH7rE.js.map +1 -0
  37. package/dist/_chunks/stale-reload-Bab885FO.js +64 -0
  38. package/dist/_chunks/stale-reload-Bab885FO.js.map +1 -0
  39. package/dist/_chunks/tracing-C8V-YGsP.js +329 -0
  40. package/dist/_chunks/tracing-C8V-YGsP.js.map +1 -0
  41. package/dist/_chunks/{use-query-states-DAhgj8Gx.js → use-query-states-B2XTqxDR.js} +7 -20
  42. package/dist/_chunks/use-query-states-B2XTqxDR.js.map +1 -0
  43. package/dist/_chunks/use-segment-params-BkpKAQ7D.js +185 -0
  44. package/dist/_chunks/use-segment-params-BkpKAQ7D.js.map +1 -0
  45. package/dist/_chunks/walkers-Tg0Alwcg.js +850 -0
  46. package/dist/_chunks/walkers-Tg0Alwcg.js.map +1 -0
  47. package/dist/_chunks/{format-DNt20Kt8.js → warnings-Cg47l5sk.js} +7 -45
  48. package/dist/_chunks/warnings-Cg47l5sk.js.map +1 -0
  49. package/dist/adapters/build-output-helper.d.ts +28 -0
  50. package/dist/adapters/build-output-helper.d.ts.map +1 -0
  51. package/dist/adapters/cloudflare-dev.d.ts +109 -0
  52. package/dist/adapters/cloudflare-dev.d.ts.map +1 -0
  53. package/dist/adapters/cloudflare-dev.js +73 -0
  54. package/dist/adapters/cloudflare-dev.js.map +1 -0
  55. package/dist/adapters/cloudflare-kv-cache.d.ts +64 -0
  56. package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -0
  57. package/dist/adapters/cloudflare-kv-cache.js +95 -0
  58. package/dist/adapters/cloudflare-kv-cache.js.map +1 -0
  59. package/dist/adapters/cloudflare.d.ts +148 -12
  60. package/dist/adapters/cloudflare.d.ts.map +1 -1
  61. package/dist/adapters/cloudflare.js +142 -38
  62. package/dist/adapters/cloudflare.js.map +1 -1
  63. package/dist/adapters/compress-module.d.ts.map +1 -1
  64. package/dist/adapters/nitro.d.ts +17 -1
  65. package/dist/adapters/nitro.d.ts.map +1 -1
  66. package/dist/adapters/nitro.js +143 -45
  67. package/dist/adapters/nitro.js.map +1 -1
  68. package/dist/adapters/shared.d.ts +16 -0
  69. package/dist/adapters/shared.d.ts.map +1 -0
  70. package/dist/cache/cache-api.d.ts +24 -0
  71. package/dist/cache/cache-api.d.ts.map +1 -0
  72. package/dist/cache/fast-hash.d.ts +22 -0
  73. package/dist/cache/fast-hash.d.ts.map +1 -0
  74. package/dist/cache/handler-store.d.ts +31 -0
  75. package/dist/cache/handler-store.d.ts.map +1 -0
  76. package/dist/cache/index.d.ts +23 -7
  77. package/dist/cache/index.d.ts.map +1 -1
  78. package/dist/cache/index.js +195 -84
  79. package/dist/cache/index.js.map +1 -1
  80. package/dist/cache/singleflight.d.ts +18 -1
  81. package/dist/cache/singleflight.d.ts.map +1 -1
  82. package/dist/cache/sizeof.d.ts +22 -0
  83. package/dist/cache/sizeof.d.ts.map +1 -0
  84. package/dist/cache/timber-cache.d.ts +1 -1
  85. package/dist/cache/timber-cache.d.ts.map +1 -1
  86. package/dist/cli.d.ts +6 -1
  87. package/dist/cli.d.ts.map +1 -1
  88. package/dist/cli.js +8 -3
  89. package/dist/cli.js.map +1 -1
  90. package/dist/client/browser-dev.d.ts +34 -1
  91. package/dist/client/browser-dev.d.ts.map +1 -1
  92. package/dist/client/browser-entry/action-dispatch.d.ts +17 -0
  93. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -0
  94. package/dist/client/browser-entry/hmr.d.ts +21 -0
  95. package/dist/client/browser-entry/hmr.d.ts.map +1 -0
  96. package/dist/client/browser-entry/hydrate.d.ts +46 -0
  97. package/dist/client/browser-entry/hydrate.d.ts.map +1 -0
  98. package/dist/client/browser-entry/index.d.ts +30 -0
  99. package/dist/client/browser-entry/index.d.ts.map +1 -0
  100. package/dist/client/browser-entry/post-hydration.d.ts +26 -0
  101. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -0
  102. package/dist/client/browser-entry/router-init.d.ts +23 -0
  103. package/dist/client/browser-entry/router-init.d.ts.map +1 -0
  104. package/dist/client/browser-entry/rsc-stream.d.ts +24 -0
  105. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -0
  106. package/dist/client/browser-entry/scroll.d.ts +19 -0
  107. package/dist/client/browser-entry/scroll.d.ts.map +1 -0
  108. package/dist/client/error-boundary.d.ts +12 -5
  109. package/dist/client/error-boundary.d.ts.map +1 -1
  110. package/dist/client/error-boundary.js +26 -5
  111. package/dist/client/error-boundary.js.map +1 -1
  112. package/dist/client/error-reconstituter.d.ts +54 -0
  113. package/dist/client/error-reconstituter.d.ts.map +1 -0
  114. package/dist/client/form.d.ts +16 -27
  115. package/dist/client/form.d.ts.map +1 -1
  116. package/dist/client/history.d.ts +19 -4
  117. package/dist/client/history.d.ts.map +1 -1
  118. package/dist/client/index.d.ts +9 -24
  119. package/dist/client/index.d.ts.map +1 -1
  120. package/dist/client/index.js +312 -1109
  121. package/dist/client/index.js.map +1 -1
  122. package/dist/client/internal.d.ts +19 -0
  123. package/dist/client/internal.d.ts.map +1 -0
  124. package/dist/client/internal.js +964 -0
  125. package/dist/client/internal.js.map +1 -0
  126. package/dist/client/link-pending-store.d.ts +63 -0
  127. package/dist/client/link-pending-store.d.ts.map +1 -0
  128. package/dist/client/link.d.ts +73 -63
  129. package/dist/client/link.d.ts.map +1 -1
  130. package/dist/client/nav-link-store.d.ts +36 -0
  131. package/dist/client/nav-link-store.d.ts.map +1 -0
  132. package/dist/client/navigation-api-types.d.ts +90 -0
  133. package/dist/client/navigation-api-types.d.ts.map +1 -0
  134. package/dist/client/navigation-api.d.ts +115 -0
  135. package/dist/client/navigation-api.d.ts.map +1 -0
  136. package/dist/client/navigation-context.d.ts +22 -5
  137. package/dist/client/navigation-context.d.ts.map +1 -1
  138. package/dist/client/{transition-root.d.ts → navigation-root.d.ts} +42 -8
  139. package/dist/client/navigation-root.d.ts.map +1 -0
  140. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  141. package/dist/client/router-ref.d.ts +1 -1
  142. package/dist/client/router.d.ts +70 -4
  143. package/dist/client/router.d.ts.map +1 -1
  144. package/dist/client/rsc-fetch.d.ts +38 -3
  145. package/dist/client/rsc-fetch.d.ts.map +1 -1
  146. package/dist/client/segment-cache.d.ts +1 -1
  147. package/dist/client/segment-cache.d.ts.map +1 -1
  148. package/dist/client/segment-context.d.ts +1 -1
  149. package/dist/client/segment-context.d.ts.map +1 -1
  150. package/dist/client/segment-merger.d.ts.map +1 -1
  151. package/dist/client/segment-outlet.d.ts +63 -0
  152. package/dist/client/segment-outlet.d.ts.map +1 -0
  153. package/dist/client/ssr-data.d.ts +13 -4
  154. package/dist/client/ssr-data.d.ts.map +1 -1
  155. package/dist/client/stale-reload.d.ts +15 -0
  156. package/dist/client/stale-reload.d.ts.map +1 -1
  157. package/dist/client/state.d.ts +1 -1
  158. package/dist/client/top-loader.d.ts +5 -5
  159. package/dist/client/top-loader.d.ts.map +1 -1
  160. package/dist/client/use-cookie.d.ts +8 -0
  161. package/dist/client/use-cookie.d.ts.map +1 -1
  162. package/dist/client/use-link-status.d.ts +5 -5
  163. package/dist/client/use-link-status.d.ts.map +1 -1
  164. package/dist/client/{use-navigation-pending.d.ts → use-pending-navigation.d.ts} +4 -4
  165. package/dist/client/use-pending-navigation.d.ts.map +1 -0
  166. package/dist/client/use-query-states.d.ts +1 -1
  167. package/dist/client/use-query-states.d.ts.map +1 -1
  168. package/dist/client/use-router.d.ts +1 -1
  169. package/dist/client/{use-params.d.ts → use-segment-params.d.ts} +7 -5
  170. package/dist/client/use-segment-params.d.ts.map +1 -0
  171. package/dist/codec.d.ts +33 -0
  172. package/dist/codec.d.ts.map +1 -0
  173. package/dist/codec.js +2 -0
  174. package/dist/config-types.d.ts +294 -0
  175. package/dist/config-types.d.ts.map +1 -0
  176. package/dist/config-validation.d.ts +51 -0
  177. package/dist/config-validation.d.ts.map +1 -0
  178. package/dist/content/index.d.ts +1 -10
  179. package/dist/content/index.d.ts.map +1 -1
  180. package/dist/content/index.js +0 -2
  181. package/dist/cookies/define-cookie.d.ts +98 -25
  182. package/dist/cookies/define-cookie.d.ts.map +1 -1
  183. package/dist/cookies/index.d.ts +2 -1
  184. package/dist/cookies/index.d.ts.map +1 -1
  185. package/dist/cookies/index.js +36 -72
  186. package/dist/cookies/index.js.map +1 -1
  187. package/dist/cookies/json-cookie.d.ts +64 -0
  188. package/dist/cookies/json-cookie.d.ts.map +1 -0
  189. package/dist/cookies/validation.d.ts +46 -0
  190. package/dist/cookies/validation.d.ts.map +1 -0
  191. package/dist/dev-tools/404-page.d.ts +46 -0
  192. package/dist/dev-tools/404-page.d.ts.map +1 -0
  193. package/dist/dev-tools/browser-logs.d.ts +84 -0
  194. package/dist/dev-tools/browser-logs.d.ts.map +1 -0
  195. package/dist/dev-tools/error-page.d.ts +58 -0
  196. package/dist/dev-tools/error-page.d.ts.map +1 -0
  197. package/dist/dev-tools/holding-server.d.ts +54 -0
  198. package/dist/dev-tools/holding-server.d.ts.map +1 -0
  199. package/dist/dev-tools/index.d.ts +31 -0
  200. package/dist/dev-tools/index.d.ts.map +1 -0
  201. package/dist/{server/dev-span-processor.d.ts → dev-tools/instrumentation.d.ts} +26 -6
  202. package/dist/dev-tools/instrumentation.d.ts.map +1 -0
  203. package/dist/{server/dev-logger.d.ts → dev-tools/logger.d.ts} +1 -1
  204. package/dist/dev-tools/logger.d.ts.map +1 -0
  205. package/dist/{plugins/dev-logs.d.ts → dev-tools/logs.d.ts} +2 -2
  206. package/dist/dev-tools/logs.d.ts.map +1 -0
  207. package/dist/dev-tools/overlay.d.ts +91 -0
  208. package/dist/dev-tools/overlay.d.ts.map +1 -0
  209. package/dist/dev-tools/stack-classifier.d.ts +34 -0
  210. package/dist/dev-tools/stack-classifier.d.ts.map +1 -0
  211. package/dist/dev-tools/terminal.d.ts +28 -0
  212. package/dist/dev-tools/terminal.d.ts.map +1 -0
  213. package/dist/{server/dev-warnings.d.ts → dev-tools/warnings.d.ts} +2 -22
  214. package/dist/dev-tools/warnings.d.ts.map +1 -0
  215. package/dist/fonts/bundle.d.ts +48 -0
  216. package/dist/fonts/bundle.d.ts.map +1 -0
  217. package/dist/fonts/css.d.ts +1 -0
  218. package/dist/fonts/css.d.ts.map +1 -1
  219. package/dist/fonts/dev-middleware.d.ts +22 -0
  220. package/dist/fonts/dev-middleware.d.ts.map +1 -0
  221. package/dist/fonts/local.d.ts +4 -2
  222. package/dist/fonts/local.d.ts.map +1 -1
  223. package/dist/fonts/pipeline.d.ts +167 -0
  224. package/dist/fonts/pipeline.d.ts.map +1 -0
  225. package/dist/fonts/transform.d.ts +64 -0
  226. package/dist/fonts/transform.d.ts.map +1 -0
  227. package/dist/fonts/types.d.ts +45 -1
  228. package/dist/fonts/types.d.ts.map +1 -1
  229. package/dist/fonts/virtual-modules.d.ts +103 -0
  230. package/dist/fonts/virtual-modules.d.ts.map +1 -0
  231. package/dist/index.d.ts +46 -152
  232. package/dist/index.d.ts.map +1 -1
  233. package/dist/index.js +14702 -12350
  234. package/dist/index.js.map +1 -1
  235. package/dist/plugin-context.d.ts +107 -0
  236. package/dist/plugin-context.d.ts.map +1 -0
  237. package/dist/plugins/adapter-build.d.ts +1 -1
  238. package/dist/plugins/adapter-build.d.ts.map +1 -1
  239. package/dist/plugins/build-manifest.d.ts +2 -2
  240. package/dist/plugins/build-manifest.d.ts.map +1 -1
  241. package/dist/plugins/build-report.d.ts +16 -4
  242. package/dist/plugins/build-report.d.ts.map +1 -1
  243. package/dist/plugins/chunks.d.ts +9 -1
  244. package/dist/plugins/chunks.d.ts.map +1 -1
  245. package/dist/plugins/client-chunks.d.ts +32 -0
  246. package/dist/plugins/client-chunks.d.ts.map +1 -0
  247. package/dist/plugins/content.d.ts +1 -1
  248. package/dist/plugins/content.d.ts.map +1 -1
  249. package/dist/plugins/dev-server.d.ts +1 -1
  250. package/dist/plugins/dev-server.d.ts.map +1 -1
  251. package/dist/plugins/entries.d.ts +8 -1
  252. package/dist/plugins/entries.d.ts.map +1 -1
  253. package/dist/plugins/fonts.d.ts +17 -65
  254. package/dist/plugins/fonts.d.ts.map +1 -1
  255. package/dist/plugins/mdx.d.ts +7 -1
  256. package/dist/plugins/mdx.d.ts.map +1 -1
  257. package/dist/plugins/routing.d.ts +1 -1
  258. package/dist/plugins/routing.d.ts.map +1 -1
  259. package/dist/plugins/server-bundle.d.ts.map +1 -1
  260. package/dist/plugins/shims.d.ts +6 -5
  261. package/dist/plugins/shims.d.ts.map +1 -1
  262. package/dist/plugins/static-build.d.ts +4 -4
  263. package/dist/plugins/static-build.d.ts.map +1 -1
  264. package/dist/routing/codegen-shared.d.ts +55 -0
  265. package/dist/routing/codegen-shared.d.ts.map +1 -0
  266. package/dist/routing/codegen-types.d.ts +52 -0
  267. package/dist/routing/codegen-types.d.ts.map +1 -0
  268. package/dist/routing/codegen.d.ts +2 -2
  269. package/dist/routing/codegen.d.ts.map +1 -1
  270. package/dist/routing/convention-lint.d.ts +41 -0
  271. package/dist/routing/convention-lint.d.ts.map +1 -0
  272. package/dist/routing/index.d.ts +5 -1
  273. package/dist/routing/index.d.ts.map +1 -1
  274. package/dist/routing/index.js +3 -2
  275. package/dist/routing/link-codegen.d.ts +90 -0
  276. package/dist/routing/link-codegen.d.ts.map +1 -0
  277. package/dist/routing/scanner.d.ts +1 -10
  278. package/dist/routing/scanner.d.ts.map +1 -1
  279. package/dist/routing/segment-classify.d.ts +75 -0
  280. package/dist/routing/segment-classify.d.ts.map +1 -0
  281. package/dist/routing/status-file-lint.d.ts +2 -1
  282. package/dist/routing/status-file-lint.d.ts.map +1 -1
  283. package/dist/routing/types.d.ts +77 -25
  284. package/dist/routing/types.d.ts.map +1 -1
  285. package/dist/routing/walkers.d.ts +51 -0
  286. package/dist/routing/walkers.d.ts.map +1 -0
  287. package/dist/rsc-runtime/rsc.d.ts +1 -1
  288. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  289. package/dist/rsc-runtime/ssr.d.ts +12 -0
  290. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  291. package/dist/schema-bridge.d.ts +76 -0
  292. package/dist/schema-bridge.d.ts.map +1 -0
  293. package/dist/search-params/define.d.ts +157 -0
  294. package/dist/search-params/define.d.ts.map +1 -0
  295. package/dist/search-params/index.d.ts +4 -7
  296. package/dist/search-params/index.d.ts.map +1 -1
  297. package/dist/search-params/index.js +34 -441
  298. package/dist/search-params/index.js.map +1 -1
  299. package/dist/search-params/registry.d.ts +2 -2
  300. package/dist/search-params/registry.d.ts.map +1 -1
  301. package/dist/search-params/wrappers.d.ts +53 -0
  302. package/dist/search-params/wrappers.d.ts.map +1 -0
  303. package/dist/segment-params/define.d.ts +95 -0
  304. package/dist/segment-params/define.d.ts.map +1 -0
  305. package/dist/segment-params/index.d.ts +3 -0
  306. package/dist/segment-params/index.d.ts.map +1 -0
  307. package/dist/segment-params/index.js +2 -0
  308. package/dist/server/access-gate.d.ts +8 -3
  309. package/dist/server/access-gate.d.ts.map +1 -1
  310. package/dist/server/action-client.d.ts +41 -6
  311. package/dist/server/action-client.d.ts.map +1 -1
  312. package/dist/server/action-encryption.d.ts +76 -0
  313. package/dist/server/action-encryption.d.ts.map +1 -0
  314. package/dist/server/action-handler.d.ts +35 -1
  315. package/dist/server/action-handler.d.ts.map +1 -1
  316. package/dist/server/actions.d.ts +3 -6
  317. package/dist/server/actions.d.ts.map +1 -1
  318. package/dist/server/als-registry.d.ts +33 -5
  319. package/dist/server/als-registry.d.ts.map +1 -1
  320. package/dist/server/asset-headers.d.ts +1 -15
  321. package/dist/server/asset-headers.d.ts.map +1 -1
  322. package/dist/server/build-manifest.d.ts +2 -2
  323. package/dist/server/build-manifest.d.ts.map +1 -1
  324. package/dist/server/cookie-context.d.ts +170 -0
  325. package/dist/server/cookie-context.d.ts.map +1 -0
  326. package/dist/server/cookie-parsing.d.ts +51 -0
  327. package/dist/server/cookie-parsing.d.ts.map +1 -0
  328. package/dist/server/debug.d.ts +82 -0
  329. package/dist/server/debug.d.ts.map +1 -0
  330. package/dist/server/default-logger.d.ts +22 -0
  331. package/dist/server/default-logger.d.ts.map +1 -0
  332. package/dist/server/deny-boundary.d.ts +90 -0
  333. package/dist/server/deny-boundary.d.ts.map +1 -0
  334. package/dist/server/deny-renderer.d.ts.map +1 -1
  335. package/dist/server/dev-source-map.d.ts +22 -0
  336. package/dist/server/dev-source-map.d.ts.map +1 -0
  337. package/dist/server/early-hints-sender.d.ts.map +1 -1
  338. package/dist/server/early-hints.d.ts +13 -5
  339. package/dist/server/early-hints.d.ts.map +1 -1
  340. package/dist/server/error-boundary-wrapper.d.ts +7 -1
  341. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  342. package/dist/server/fallback-error.d.ts +12 -7
  343. package/dist/server/fallback-error.d.ts.map +1 -1
  344. package/dist/server/flight-injection-state.d.ts +66 -0
  345. package/dist/server/flight-injection-state.d.ts.map +1 -0
  346. package/dist/server/flight-scripts.d.ts +42 -0
  347. package/dist/server/flight-scripts.d.ts.map +1 -0
  348. package/dist/server/flush.d.ts.map +1 -1
  349. package/dist/server/form-data.d.ts +29 -0
  350. package/dist/server/form-data.d.ts.map +1 -1
  351. package/dist/server/html-injector-core.d.ts +212 -0
  352. package/dist/server/html-injector-core.d.ts.map +1 -0
  353. package/dist/server/html-injectors.d.ts +81 -41
  354. package/dist/server/html-injectors.d.ts.map +1 -1
  355. package/dist/server/index.d.ts +9 -46
  356. package/dist/server/index.d.ts.map +1 -1
  357. package/dist/server/index.js +158 -2899
  358. package/dist/server/index.js.map +1 -1
  359. package/dist/server/internal.d.ts +48 -0
  360. package/dist/server/internal.d.ts.map +1 -0
  361. package/dist/server/internal.js +2900 -0
  362. package/dist/server/internal.js.map +1 -0
  363. package/dist/server/logger.d.ts +39 -7
  364. package/dist/server/logger.d.ts.map +1 -1
  365. package/dist/server/middleware-runner.d.ts +36 -4
  366. package/dist/server/middleware-runner.d.ts.map +1 -1
  367. package/dist/server/node-stream-transforms.d.ts +110 -0
  368. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  369. package/dist/server/param-coercion.d.ts +26 -0
  370. package/dist/server/param-coercion.d.ts.map +1 -0
  371. package/dist/server/pipeline-helpers.d.ts +95 -0
  372. package/dist/server/pipeline-helpers.d.ts.map +1 -0
  373. package/dist/server/pipeline-interception.d.ts +1 -1
  374. package/dist/server/pipeline-interception.d.ts.map +1 -1
  375. package/dist/server/pipeline-metadata.d.ts +6 -0
  376. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  377. package/dist/server/pipeline-outcome.d.ts +49 -0
  378. package/dist/server/pipeline-outcome.d.ts.map +1 -0
  379. package/dist/server/pipeline-phases.d.ts +52 -0
  380. package/dist/server/pipeline-phases.d.ts.map +1 -0
  381. package/dist/server/pipeline.d.ts +93 -23
  382. package/dist/server/pipeline.d.ts.map +1 -1
  383. package/dist/server/port-resolution.d.ts +117 -0
  384. package/dist/server/port-resolution.d.ts.map +1 -0
  385. package/dist/server/primitives.d.ts +69 -18
  386. package/dist/server/primitives.d.ts.map +1 -1
  387. package/dist/server/render-timeout.d.ts +51 -0
  388. package/dist/server/render-timeout.d.ts.map +1 -0
  389. package/dist/server/request-context.d.ts +41 -109
  390. package/dist/server/request-context.d.ts.map +1 -1
  391. package/dist/server/route-element-builder.d.ts +27 -1
  392. package/dist/server/route-element-builder.d.ts.map +1 -1
  393. package/dist/server/route-handler.d.ts.map +1 -1
  394. package/dist/server/route-matcher.d.ts +21 -34
  395. package/dist/server/route-matcher.d.ts.map +1 -1
  396. package/dist/server/rsc-entry/action-middleware-runner.d.ts +66 -0
  397. package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -0
  398. package/dist/server/rsc-entry/api-handler.d.ts +2 -2
  399. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  400. package/dist/server/rsc-entry/error-renderer.d.ts +26 -13
  401. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  402. package/dist/server/rsc-entry/helpers.d.ts +49 -6
  403. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  404. package/dist/server/rsc-entry/index.d.ts +20 -3
  405. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  406. package/dist/server/rsc-entry/render-route.d.ts +50 -0
  407. package/dist/server/rsc-entry/render-route.d.ts.map +1 -0
  408. package/dist/server/rsc-entry/rsc-payload.d.ts +3 -3
  409. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  410. package/dist/server/rsc-entry/rsc-stream.d.ts +20 -1
  411. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  412. package/dist/server/rsc-entry/ssr-bridge.d.ts +1 -1
  413. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  414. package/dist/server/rsc-entry/ssr-renderer.d.ts +19 -4
  415. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  416. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +119 -0
  417. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -0
  418. package/dist/server/rsc-prop-warnings.d.ts.map +1 -1
  419. package/dist/server/safe-load.d.ts +46 -0
  420. package/dist/server/safe-load.d.ts.map +1 -0
  421. package/dist/server/sensitive-fields.d.ts +74 -0
  422. package/dist/server/sensitive-fields.d.ts.map +1 -0
  423. package/dist/server/sitemap-generator.d.ts +129 -0
  424. package/dist/server/sitemap-generator.d.ts.map +1 -0
  425. package/dist/server/sitemap-handler.d.ts +22 -0
  426. package/dist/server/sitemap-handler.d.ts.map +1 -0
  427. package/dist/server/slot-resolver.d.ts +1 -1
  428. package/dist/server/slot-resolver.d.ts.map +1 -1
  429. package/dist/server/ssr-entry.d.ts +23 -0
  430. package/dist/server/ssr-entry.d.ts.map +1 -1
  431. package/dist/server/ssr-render.d.ts +39 -21
  432. package/dist/server/ssr-render.d.ts.map +1 -1
  433. package/dist/server/ssr-wrappers.d.ts +50 -0
  434. package/dist/server/ssr-wrappers.d.ts.map +1 -0
  435. package/dist/server/state-tree-diff.d.ts.map +1 -1
  436. package/dist/server/status-code-resolver.d.ts +16 -11
  437. package/dist/server/status-code-resolver.d.ts.map +1 -1
  438. package/dist/server/stream-utils.d.ts +36 -0
  439. package/dist/server/stream-utils.d.ts.map +1 -0
  440. package/dist/server/tracing.d.ts +15 -5
  441. package/dist/server/tracing.d.ts.map +1 -1
  442. package/dist/server/tree-builder.d.ts +62 -30
  443. package/dist/server/tree-builder.d.ts.map +1 -1
  444. package/dist/server/types.d.ts +49 -4
  445. package/dist/server/types.d.ts.map +1 -1
  446. package/dist/server/utils/escape-html.d.ts +14 -0
  447. package/dist/server/utils/escape-html.d.ts.map +1 -0
  448. package/dist/server/version-skew.d.ts +61 -0
  449. package/dist/server/version-skew.d.ts.map +1 -0
  450. package/dist/server/waituntil-bridge.d.ts.map +1 -1
  451. package/dist/shared/merge-search-params.d.ts +22 -0
  452. package/dist/shared/merge-search-params.d.ts.map +1 -0
  453. package/dist/shims/font-google.d.ts +1 -1
  454. package/dist/shims/font-google.d.ts.map +1 -1
  455. package/dist/shims/font-google.js +42 -0
  456. package/dist/shims/font-google.js.map +1 -0
  457. package/dist/shims/font-local.d.ts +26 -0
  458. package/dist/shims/font-local.d.ts.map +1 -0
  459. package/dist/shims/font-local.js +20 -0
  460. package/dist/shims/font-local.js.map +1 -0
  461. package/dist/shims/headers.d.ts +2 -1
  462. package/dist/shims/headers.d.ts.map +1 -1
  463. package/dist/shims/navigation-client.d.ts +3 -1
  464. package/dist/shims/navigation-client.d.ts.map +1 -1
  465. package/dist/shims/navigation.d.ts +11 -5
  466. package/dist/shims/navigation.d.ts.map +1 -1
  467. package/dist/utils/directive-parser.d.ts +1 -43
  468. package/dist/utils/directive-parser.d.ts.map +1 -1
  469. package/dist/utils/state-machine.d.ts +80 -0
  470. package/dist/utils/state-machine.d.ts.map +1 -0
  471. package/package.json +56 -22
  472. package/src/adapters/build-output-helper.ts +77 -0
  473. package/src/adapters/cloudflare-dev.ts +177 -0
  474. package/src/adapters/cloudflare-kv-cache.ts +142 -0
  475. package/src/adapters/cloudflare.ts +350 -76
  476. package/src/adapters/compress-module.ts +24 -4
  477. package/src/adapters/nitro.ts +148 -60
  478. package/src/adapters/shared.ts +40 -0
  479. package/src/adapters/wrangler.d.ts +7 -0
  480. package/src/cache/cache-api.ts +38 -0
  481. package/src/cache/fast-hash.ts +34 -0
  482. package/src/cache/handler-store.ts +68 -0
  483. package/src/cache/index.ts +81 -18
  484. package/src/cache/singleflight.ts +62 -4
  485. package/src/cache/sizeof.ts +31 -0
  486. package/src/cache/timber-cache.ts +41 -29
  487. package/src/cli.ts +16 -6
  488. package/src/client/browser-dev.ts +153 -1
  489. package/src/client/browser-entry/action-dispatch.ts +116 -0
  490. package/src/client/browser-entry/hmr.ts +81 -0
  491. package/src/client/browser-entry/hydrate.ts +145 -0
  492. package/src/client/browser-entry/index.ts +143 -0
  493. package/src/client/browser-entry/post-hydration.ts +119 -0
  494. package/src/client/browser-entry/router-init.ts +193 -0
  495. package/src/client/browser-entry/rsc-stream.ts +157 -0
  496. package/src/client/browser-entry/scroll.ts +27 -0
  497. package/src/client/error-boundary.tsx +97 -20
  498. package/src/client/error-reconstituter.tsx +65 -0
  499. package/src/client/form.tsx +31 -32
  500. package/src/client/history.ts +26 -4
  501. package/src/client/index.ts +77 -43
  502. package/src/client/internal.ts +58 -0
  503. package/src/client/link-pending-store.ts +111 -0
  504. package/src/client/link.tsx +432 -140
  505. package/src/client/nav-link-store.ts +47 -0
  506. package/src/client/navigation-api-types.ts +112 -0
  507. package/src/client/navigation-api.ts +332 -0
  508. package/src/client/navigation-context.ts +83 -18
  509. package/src/client/navigation-root.tsx +342 -0
  510. package/src/client/nuqs-adapter.tsx +16 -3
  511. package/src/client/router-ref.ts +1 -1
  512. package/src/client/router.ts +303 -78
  513. package/src/client/rsc-fetch.ts +112 -8
  514. package/src/client/segment-cache.ts +1 -1
  515. package/src/client/segment-context.ts +6 -1
  516. package/src/client/segment-merger.ts +2 -8
  517. package/src/client/segment-outlet.tsx +86 -0
  518. package/src/client/ssr-data.ts +13 -5
  519. package/src/client/stale-reload.ts +74 -7
  520. package/src/client/state.ts +2 -2
  521. package/src/client/top-loader.tsx +41 -25
  522. package/src/client/use-cookie.ts +29 -0
  523. package/src/client/use-link-status.ts +7 -7
  524. package/src/client/{use-navigation-pending.ts → use-pending-navigation.ts} +6 -6
  525. package/src/client/use-query-states.ts +9 -3
  526. package/src/client/use-router.ts +1 -1
  527. package/src/client/{use-params.ts → use-segment-params.ts} +7 -5
  528. package/src/codec.ts +45 -0
  529. package/src/config-types.ts +292 -0
  530. package/src/config-validation.ts +303 -0
  531. package/src/content/index.ts +5 -13
  532. package/src/cookies/define-cookie.ts +301 -55
  533. package/src/cookies/index.ts +12 -1
  534. package/src/cookies/json-cookie.ts +105 -0
  535. package/src/cookies/validation.ts +134 -0
  536. package/src/dev-tools/404-page.ts +387 -0
  537. package/src/dev-tools/browser-logs.ts +288 -0
  538. package/src/dev-tools/error-page.ts +509 -0
  539. package/src/dev-tools/holding-server.ts +187 -0
  540. package/src/dev-tools/index.ts +90 -0
  541. package/src/dev-tools/instrumentation.ts +176 -0
  542. package/src/{plugins/dev-logs.ts → dev-tools/logs.ts} +3 -3
  543. package/src/dev-tools/overlay.ts +456 -0
  544. package/src/dev-tools/stack-classifier.ts +75 -0
  545. package/src/dev-tools/terminal.ts +183 -0
  546. package/src/{server/dev-warnings.ts → dev-tools/warnings.ts} +6 -50
  547. package/src/fonts/bundle.ts +142 -0
  548. package/src/fonts/css.ts +2 -1
  549. package/src/fonts/dev-middleware.ts +74 -0
  550. package/src/fonts/local.ts +7 -3
  551. package/src/fonts/pipeline.ts +314 -0
  552. package/src/fonts/transform.ts +406 -0
  553. package/src/fonts/types.ts +50 -1
  554. package/src/fonts/virtual-modules.ts +227 -0
  555. package/src/index.ts +376 -315
  556. package/src/plugin-context.ts +240 -0
  557. package/src/plugins/adapter-build.ts +12 -4
  558. package/src/plugins/build-manifest.ts +13 -2
  559. package/src/plugins/build-report.ts +32 -21
  560. package/src/plugins/chunks.ts +9 -1
  561. package/src/plugins/client-chunks.ts +65 -0
  562. package/src/plugins/content.ts +1 -1
  563. package/src/plugins/dev-server.ts +154 -21
  564. package/src/plugins/entries.ts +119 -12
  565. package/src/plugins/fonts.ts +177 -524
  566. package/src/plugins/mdx.ts +52 -15
  567. package/src/plugins/routing.ts +225 -41
  568. package/src/plugins/server-action-exports.ts +1 -1
  569. package/src/plugins/server-bundle.ts +36 -1
  570. package/src/plugins/shims.ts +136 -35
  571. package/src/plugins/static-build.ts +17 -11
  572. package/src/routing/codegen-shared.ts +98 -0
  573. package/src/routing/codegen-types.ts +53 -0
  574. package/src/routing/codegen.ts +143 -176
  575. package/src/routing/convention-lint.ts +357 -0
  576. package/src/routing/index.ts +5 -1
  577. package/src/routing/interception.ts +1 -1
  578. package/src/routing/link-codegen.ts +294 -0
  579. package/src/routing/scanner.ts +107 -110
  580. package/src/routing/segment-classify.ts +188 -0
  581. package/src/routing/status-file-lint.ts +10 -7
  582. package/src/routing/types.ts +78 -25
  583. package/src/routing/walkers.ts +90 -0
  584. package/src/rsc-runtime/rsc.ts +2 -0
  585. package/src/rsc-runtime/ssr.ts +50 -0
  586. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  587. package/src/{search-params/codecs.ts → schema-bridge.ts} +57 -20
  588. package/src/search-params/define.ts +538 -0
  589. package/src/search-params/index.ts +14 -20
  590. package/src/search-params/registry.ts +2 -2
  591. package/src/search-params/wrappers.ts +92 -0
  592. package/src/segment-params/define.ts +332 -0
  593. package/src/segment-params/index.ts +9 -0
  594. package/src/server/access-gate.tsx +79 -36
  595. package/src/server/action-client.ts +103 -20
  596. package/src/server/action-encryption.ts +144 -0
  597. package/src/server/action-handler.ts +112 -14
  598. package/src/server/actions.ts +10 -9
  599. package/src/server/als-registry.ts +35 -7
  600. package/src/server/asset-headers.ts +8 -34
  601. package/src/server/build-manifest.ts +10 -4
  602. package/src/server/compress.ts +25 -7
  603. package/src/server/cookie-context.ts +468 -0
  604. package/src/server/cookie-parsing.ts +135 -0
  605. package/src/server/debug.ts +137 -0
  606. package/src/server/default-logger.ts +99 -0
  607. package/src/server/deny-boundary.ts +218 -0
  608. package/src/server/deny-renderer.ts +33 -51
  609. package/src/server/dev-source-map.ts +31 -0
  610. package/src/server/early-hints-sender.ts +3 -2
  611. package/src/server/early-hints.ts +36 -15
  612. package/src/server/error-boundary-wrapper.ts +74 -22
  613. package/src/server/fallback-error.ts +74 -102
  614. package/src/server/flight-injection-state.ts +113 -0
  615. package/src/server/flight-scripts.ts +62 -0
  616. package/src/server/flush.ts +2 -1
  617. package/src/server/form-data.ts +76 -0
  618. package/src/server/html-injector-core.ts +403 -0
  619. package/src/server/html-injectors.ts +244 -223
  620. package/src/server/index.ts +31 -184
  621. package/src/server/internal.ts +176 -0
  622. package/src/server/logger.ts +67 -35
  623. package/src/server/middleware-runner.ts +75 -4
  624. package/src/server/node-stream-transforms.ts +369 -0
  625. package/src/server/param-coercion.ts +76 -0
  626. package/src/server/pipeline-helpers.ts +204 -0
  627. package/src/server/pipeline-interception.ts +17 -16
  628. package/src/server/pipeline-metadata.ts +13 -0
  629. package/src/server/pipeline-outcome.ts +167 -0
  630. package/src/server/pipeline-phases.ts +409 -0
  631. package/src/server/pipeline.ts +128 -387
  632. package/src/server/port-resolution.ts +215 -0
  633. package/src/server/primitives.ts +113 -29
  634. package/src/server/render-timeout.ts +108 -0
  635. package/src/server/request-context.ts +94 -337
  636. package/src/server/route-element-builder.ts +289 -198
  637. package/src/server/route-handler.ts +24 -4
  638. package/src/server/route-matcher.ts +44 -65
  639. package/src/server/rsc-entry/action-middleware-runner.ts +167 -0
  640. package/src/server/rsc-entry/api-handler.ts +16 -17
  641. package/src/server/rsc-entry/error-renderer.ts +305 -89
  642. package/src/server/rsc-entry/helpers.ts +136 -12
  643. package/src/server/rsc-entry/index.ts +330 -312
  644. package/src/server/rsc-entry/render-route.ts +304 -0
  645. package/src/server/rsc-entry/rsc-payload.ts +100 -18
  646. package/src/server/rsc-entry/rsc-stream.ts +90 -17
  647. package/src/server/rsc-entry/ssr-bridge.ts +14 -5
  648. package/src/server/rsc-entry/ssr-renderer.ts +177 -37
  649. package/src/server/rsc-entry/wrap-action-dispatch.ts +449 -0
  650. package/src/server/rsc-prop-warnings.ts +3 -1
  651. package/src/server/safe-load.ts +60 -0
  652. package/src/server/sensitive-fields.ts +230 -0
  653. package/src/server/sitemap-generator.ts +338 -0
  654. package/src/server/sitemap-handler.ts +126 -0
  655. package/src/server/slot-resolver.ts +245 -230
  656. package/src/server/ssr-entry.ts +215 -32
  657. package/src/server/ssr-render.ts +289 -67
  658. package/src/server/ssr-wrappers.tsx +139 -0
  659. package/src/server/state-tree-diff.ts +4 -1
  660. package/src/server/status-code-resolver.ts +112 -128
  661. package/src/server/stream-utils.ts +213 -0
  662. package/src/server/tracing.ts +44 -10
  663. package/src/server/tree-builder.ts +202 -90
  664. package/src/server/types.ts +55 -6
  665. package/src/server/utils/escape-html.ts +20 -0
  666. package/src/server/version-skew.ts +104 -0
  667. package/src/server/waituntil-bridge.ts +4 -1
  668. package/src/shared/merge-search-params.ts +55 -0
  669. package/src/shims/font-google.ts +1 -1
  670. package/src/shims/font-local.ts +34 -0
  671. package/src/shims/headers.ts +5 -1
  672. package/src/shims/navigation-client.ts +4 -3
  673. package/src/shims/navigation.ts +14 -7
  674. package/src/utils/directive-parser.ts +1 -390
  675. package/src/utils/state-machine.ts +111 -0
  676. package/dist/_chunks/als-registry-k-AtAQ9R.js +0 -41
  677. package/dist/_chunks/als-registry-k-AtAQ9R.js.map +0 -1
  678. package/dist/_chunks/format-DNt20Kt8.js.map +0 -1
  679. package/dist/_chunks/interception-DGDIjDbR.js +0 -676
  680. package/dist/_chunks/interception-DGDIjDbR.js.map +0 -1
  681. package/dist/_chunks/request-context-CRj2Zh1E.js +0 -329
  682. package/dist/_chunks/request-context-CRj2Zh1E.js.map +0 -1
  683. package/dist/_chunks/ssr-data-DLnbYpj1.js.map +0 -1
  684. package/dist/_chunks/tracing-DF0G3FB7.js +0 -173
  685. package/dist/_chunks/tracing-DF0G3FB7.js.map +0 -1
  686. package/dist/_chunks/use-cookie-dDbpCTx-.js +0 -91
  687. package/dist/_chunks/use-cookie-dDbpCTx-.js.map +0 -1
  688. package/dist/_chunks/use-query-states-DAhgj8Gx.js.map +0 -1
  689. package/dist/cache/register-cached-function.d.ts +0 -17
  690. package/dist/cache/register-cached-function.d.ts.map +0 -1
  691. package/dist/client/browser-entry.d.ts +0 -22
  692. package/dist/client/browser-entry.d.ts.map +0 -1
  693. package/dist/client/browser-links.d.ts +0 -32
  694. package/dist/client/browser-links.d.ts.map +0 -1
  695. package/dist/client/link-navigate-interceptor.d.ts +0 -28
  696. package/dist/client/link-navigate-interceptor.d.ts.map +0 -1
  697. package/dist/client/link-status-provider.d.ts +0 -11
  698. package/dist/client/link-status-provider.d.ts.map +0 -1
  699. package/dist/client/transition-root.d.ts.map +0 -1
  700. package/dist/client/use-navigation-pending.d.ts.map +0 -1
  701. package/dist/client/use-params.d.ts.map +0 -1
  702. package/dist/plugins/cache-transform.d.ts +0 -36
  703. package/dist/plugins/cache-transform.d.ts.map +0 -1
  704. package/dist/plugins/dev-error-overlay.d.ts +0 -60
  705. package/dist/plugins/dev-error-overlay.d.ts.map +0 -1
  706. package/dist/plugins/dev-logs.d.ts.map +0 -1
  707. package/dist/plugins/dynamic-transform.d.ts +0 -72
  708. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  709. package/dist/search-params/analyze.d.ts +0 -54
  710. package/dist/search-params/analyze.d.ts.map +0 -1
  711. package/dist/search-params/builtin-codecs.d.ts +0 -105
  712. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  713. package/dist/search-params/codecs.d.ts +0 -53
  714. package/dist/search-params/codecs.d.ts.map +0 -1
  715. package/dist/search-params/create.d.ts +0 -106
  716. package/dist/search-params/create.d.ts.map +0 -1
  717. package/dist/server/dev-fetch-instrumentation.d.ts +0 -22
  718. package/dist/server/dev-fetch-instrumentation.d.ts.map +0 -1
  719. package/dist/server/dev-logger.d.ts.map +0 -1
  720. package/dist/server/dev-span-processor.d.ts.map +0 -1
  721. package/dist/server/dev-warnings.d.ts.map +0 -1
  722. package/dist/server/manifest-status-resolver.d.ts +0 -58
  723. package/dist/server/manifest-status-resolver.d.ts.map +0 -1
  724. package/dist/server/prerender.d.ts +0 -77
  725. package/dist/server/prerender.d.ts.map +0 -1
  726. package/src/cache/register-cached-function.ts +0 -99
  727. package/src/client/browser-entry.ts +0 -686
  728. package/src/client/browser-links.ts +0 -90
  729. package/src/client/link-navigate-interceptor.tsx +0 -62
  730. package/src/client/link-status-provider.tsx +0 -30
  731. package/src/client/transition-root.tsx +0 -160
  732. package/src/plugins/cache-transform.ts +0 -199
  733. package/src/plugins/dev-error-overlay.ts +0 -230
  734. package/src/plugins/dynamic-transform.ts +0 -161
  735. package/src/search-params/analyze.ts +0 -192
  736. package/src/search-params/builtin-codecs.ts +0 -228
  737. package/src/search-params/create.ts +0 -321
  738. package/src/server/dev-fetch-instrumentation.ts +0 -96
  739. package/src/server/dev-span-processor.ts +0 -78
  740. package/src/server/manifest-status-resolver.ts +0 -215
  741. package/src/server/prerender.ts +0 -139
  742. /package/src/{server/dev-logger.ts → dev-tools/logger.ts} +0 -0
@@ -21,9 +21,10 @@
21
21
  */
22
22
 
23
23
  import { AsyncLocalStorage } from 'node:async_hooks';
24
+ import type { DebugComponentEntry } from './rsc-entry/helpers.js';
24
25
 
25
26
  // ─── Request Context ──────────────────────────────────────────────────────
26
- // Used by: request-context.ts (headers(), cookies(), searchParams())
27
+ // Used by: request-context.ts (getHeaders(), getCookies(), getSearchParams())
27
28
  // Design doc: design/04-authorization.md
28
29
 
29
30
  /** @internal — import via request-context.ts public API */
@@ -39,28 +40,55 @@ export interface RequestContextStore {
39
40
  /** Original (pre-overlay) frozen headers, kept for overlay merging. */
40
41
  originalHeaders: Headers;
41
42
  /**
42
- * Promise resolving to the route's typed search params (when search-params.ts
43
- * exists) or to the raw URLSearchParams. Stored as a Promise so the framework
44
- * can later support partial pre-rendering where param resolution is deferred.
43
+ * Raw URLSearchParams for the current request.
44
+ * To get typed parsed params, import a search params definition and
45
+ * call `.parse(searchParams())`.
45
46
  */
46
- searchParamsPromise: Promise<URLSearchParams | Record<string, unknown>>;
47
+ searchParams: URLSearchParams;
48
+ /**
49
+ * Raw search string from the request URL (e.g. "?foo=bar&baz=1").
50
+ * Available synchronously for use in `redirect()` with `preserveSearchParams`.
51
+ */
52
+ searchString: string;
53
+ /**
54
+ * Coerced segment params for the current request.
55
+ * Set by the pipeline after route matching and param coercion, before
56
+ * middleware and rendering. Pages and layouts read params via
57
+ * `getSegmentParams()` instead of receiving them as a prop.
58
+ *
59
+ * See design/07-routing.md §"params.ts — Convention File for Typed Params"
60
+ */
61
+ segmentParams?: Record<string, string | string[]>;
47
62
  /** Outgoing Set-Cookie entries (name → serialized value + options). Last write wins. */
48
63
  cookieJar: Map<string, CookieEntry>;
49
64
  /** Whether the response has flushed (headers committed). */
50
65
  flushed: boolean;
51
66
  /** Whether the current context allows cookie mutation. */
52
67
  mutableContext: boolean;
68
+ /**
69
+ * Set by AccessGate or PageDenyBoundary when a DenySignal is caught
70
+ * server-side (inside the React tree, before React Flight sees it).
71
+ * The pipeline reads this after render to set the HTTP status code.
72
+ * See TIM-666.
73
+ */
74
+ denyStatus?: number;
75
+ /**
76
+ * Dev-only: getter for the current request's RSC debug components.
77
+ * Set by renderRoute() so onPipelineError can include component tree
78
+ * context for render-phase errors without module-level shared state.
79
+ */
80
+ debugComponentsGetter?: () => DebugComponentEntry[];
53
81
  }
54
82
 
55
83
  /** A single outgoing cookie entry in the cookie jar. */
56
84
  export interface CookieEntry {
57
85
  name: string;
58
86
  value: string;
59
- options: import('./request-context.js').CookieOptions;
87
+ options: import('./cookie-context.js').CookieOptions;
60
88
  }
61
89
 
62
90
  // ─── Tracing ──────────────────────────────────────────────────────────────
63
- // Used by: tracing.ts (traceId(), spanId())
91
+ // Used by: tracing.ts (getTraceId(), getSpanId())
64
92
  // Design doc: design/17-logging.md
65
93
 
66
94
  export interface TraceStore {
@@ -15,6 +15,14 @@
15
15
  * Design docs: 18-build-system.md, 06-caching.md
16
16
  */
17
17
 
18
+ import { IMMUTABLE_CACHE, STATIC_CACHE } from '../adapters/shared.js';
19
+
20
+ // Re-export cache constants and generateHeadersFile from the shared adapter
21
+ // module. The canonical definitions live in adapters/shared.ts because
22
+ // adapters are loaded by Node before Vite's resolver is available — they
23
+ // can only import from within their own directory.
24
+ export { IMMUTABLE_CACHE, STATIC_CACHE, generateHeadersFile } from '../adapters/shared.js';
25
+
18
26
  /**
19
27
  * Regex matching Vite-hashed asset filenames.
20
28
  *
@@ -30,18 +38,6 @@
30
38
  */
31
39
  const HASHED_ASSET_RE = /[-.][\da-f]{8,}\.\w+$/;
32
40
 
33
- /** One year in seconds (365 days). */
34
- const ONE_YEAR = 31_536_000;
35
-
36
- /** One hour in seconds. */
37
- const ONE_HOUR = 3_600;
38
-
39
- /** Cache-Control value for hashed (immutable) assets. */
40
- export const IMMUTABLE_CACHE = `public, max-age=${ONE_YEAR}, immutable`;
41
-
42
- /** Cache-Control value for unhashed static assets. */
43
- export const STATIC_CACHE = `public, max-age=${ONE_HOUR}, must-revalidate`;
44
-
45
41
  /**
46
42
  * Check if a URL path looks like a hashed asset.
47
43
  */
@@ -57,25 +53,3 @@ export function isHashedAsset(pathname: string): boolean {
57
53
  export function getAssetCacheControl(pathname: string): string {
58
54
  return isHashedAsset(pathname) ? IMMUTABLE_CACHE : STATIC_CACHE;
59
55
  }
60
-
61
- /**
62
- * Generate a `_headers` file for static asset cache control.
63
- *
64
- * The `_headers` file is a platform convention supported by Cloudflare Workers
65
- * Static Assets, Cloudflare Pages, and Netlify. It maps URL patterns to
66
- * HTTP response headers.
67
- *
68
- * Vite places all hashed chunks under `/assets/` — these get immutable caching.
69
- * Everything else (favicon.ico, robots.txt, etc.) gets a shorter cache.
70
- */
71
- export function generateHeadersFile(): string {
72
- return `# Auto-generated by @timber-js/app — static asset cache headers.
73
- # See design/25-production-deployments.md §"CDN / Edge Cache"
74
-
75
- /assets/*
76
- Cache-Control: ${IMMUTABLE_CACHE}
77
-
78
- /*
79
- Cache-Control: ${STATIC_CACHE}
80
- `;
81
- }
@@ -85,6 +85,12 @@ export function collectRouteCss(segments: SegmentWithFiles[], manifest: BuildMan
85
85
  * via injectHead() before </head>.
86
86
  */
87
87
  export function buildCssLinkTags(cssUrls: string[]): string {
88
+ // Emit <link rel="stylesheet"> tags as a fallback for platforms where
89
+ // React's Float system (via @vitejs/plugin-rsc preinit with
90
+ // data-precedence) doesn't handle CSS injection. In practice, Float
91
+ // deduplicates and these may be dropped. No preload hints — Float
92
+ // already starts the fetch via preinit(), and redundant preloads
93
+ // cause "ignored due to unknown as/type" browser warnings.
88
94
  return cssUrls.map((url) => `<link rel="stylesheet" href="${url}">`).join('');
89
95
  }
90
96
 
@@ -95,10 +101,10 @@ export function buildCssLinkTags(cssUrls: string[]): string {
95
101
  * into 103 Early Hints responses. This avoids platform-specific 103
96
102
  * sending code.
97
103
  *
98
- * Example output: `</assets/root.css>; rel=preload; as=style, </assets/page.css>; rel=preload; as=style`
104
+ * Example output: `</assets/root.css>; as=style; rel=preload, </assets/page.css>; as=style; rel=preload`
99
105
  */
100
106
  export function buildLinkHeaders(cssUrls: string[]): string {
101
- return cssUrls.map((url) => `<${url}>; rel=preload; as=style`).join(', ');
107
+ return cssUrls.map((url) => `<${url}>; as=style; rel=preload`).join(', ');
102
108
  }
103
109
 
104
110
  // ─── Font utilities ──────────────────────────────────────────────────────
@@ -153,10 +159,10 @@ export function buildFontPreloadTags(fonts: ManifestFontEntry[]): string {
153
159
  *
154
160
  * Cloudflare CDN converts Link headers with rel=preload into 103 Early Hints.
155
161
  *
156
- * Example: `</fonts/inter.woff2>; rel=preload; as=font; crossorigin`
162
+ * Example: `</fonts/inter.woff2>; as=font; rel=preload; crossorigin`
157
163
  */
158
164
  export function buildFontLinkHeaders(fonts: ManifestFontEntry[]): string {
159
- return fonts.map((f) => `<${f.href}>; rel=preload; as=font; crossorigin`).join(', ');
165
+ return fonts.map((f) => `<${f.href}>; as=font; rel=preload; crossorigin`).join(', ');
160
166
  }
161
167
 
162
168
  // ─── JS chunk utilities ──────────────────────────────────────────────────
@@ -160,15 +160,33 @@ export function compressResponse(request: Request, response: Response): Response
160
160
  });
161
161
  }
162
162
 
163
- // ─── Gzip (CompressionStream API) ────────────────────────────────────────
163
+ // ─── Gzip (node:zlib with Z_SYNC_FLUSH) ──────────────────────────────────
164
+ //
165
+ // Uses node:zlib's createGzip with Z_SYNC_FLUSH so each chunk is flushed
166
+ // to the output immediately. The Web Platform CompressionStream API buffers
167
+ // internally and does NOT flush per-chunk — this kills streaming because
168
+ // the browser doesn't receive the HTML shell until the gzip stream closes
169
+ // (i.e. after all Suspense boundaries resolve).
170
+ //
171
+ // Z_SYNC_FLUSH adds ~2–5% size overhead vs Z_NO_FLUSH but preserves
172
+ // correct streaming behavior: the shell renders instantly, Suspense
173
+ // fallbacks are visible immediately, and streamed content appears
174
+ // progressively.
175
+
176
+ import { createGzip, constants } from 'node:zlib';
177
+ import { Readable } from 'node:stream';
164
178
 
165
179
  /**
166
- * Compress a ReadableStream with gzip using the Web Platform CompressionStream API.
167
- * Available in Node 18+, Bun, and Deno — no npm dependency needed.
180
+ * Compress a ReadableStream with gzip, flushing each chunk immediately.
181
+ *
182
+ * Uses node:zlib's createGzip with Z_SYNC_FLUSH to ensure each HTML chunk
183
+ * (shell, Suspense resolution, RSC payload) is delivered to the browser
184
+ * as soon as it's available — preserving streaming semantics.
168
185
  */
169
186
  function compressWithGzip(body: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {
170
- const compressionStream = new CompressionStream('gzip');
171
- // Cast needed: CompressionStream's WritableStream<BufferSource> type is wider
172
- // than ReadableStream's Uint8Array, but Uint8Array is a valid BufferSource.
173
- return body.pipeThrough(compressionStream as unknown as TransformStream<Uint8Array, Uint8Array>);
187
+ const gzip = createGzip({ flush: constants.Z_SYNC_FLUSH });
188
+ const nodeInput = Readable.fromWeb(body as import('stream/web').ReadableStream);
189
+ nodeInput.pipe(gzip);
190
+
191
+ return Readable.toWeb(gzip) as ReadableStream<Uint8Array>;
174
192
  }
@@ -0,0 +1,468 @@
1
+ /**
2
+ * Cookie Context — per-request cookie API and on-the-wire helpers.
3
+ *
4
+ * Split out of `request-context.ts` (TIM-853) so the cookie subsystem
5
+ * — encoding contract, options grammar, parser, serializer, RYW map,
6
+ * and rerender seed — lives in one file. The headers/scope/params APIs
7
+ * stay in `request-context.ts` and call into this module via the
8
+ * exported helpers.
9
+ *
10
+ * See design/29-cookies.md for the encoding contract and read-your-own-
11
+ * writes semantics. See ONGOING_SECURITY.md H-3 (TIM-868) for the
12
+ * smuggling primitive that the encoding contract closes.
13
+ */
14
+
15
+ import { requestContextAls, type RequestContextStore } from './als-registry.js';
16
+ import { isDebug } from './debug.js';
17
+ import { assertValidCookieName, assertValidCookieValue } from '../cookies/validation.js';
18
+ import {
19
+ parseCookieHeader,
20
+ parseSetCookie,
21
+ safeDecodeCookieValue,
22
+ serializeCookieEntry,
23
+ } from './cookie-parsing.js';
24
+
25
+ // Re-export the validators so framework-internal consumers and tests can
26
+ // import the canonical implementation from the same module that hosts
27
+ // `getCookies()`. The pure shared module lives in `cookies/validation.ts`
28
+ // so the client `useCookie` hook can use the same checks without pulling
29
+ // in the server ALS code.
30
+ export { assertValidCookieName, assertValidCookieValue };
31
+
32
+ // ─── Public API ───────────────────────────────────────────────────────────
33
+
34
+ /**
35
+ * Returns a cookie accessor for the current request.
36
+ *
37
+ * Available in middleware, access checks, server components, and server actions.
38
+ * Throws if called outside a request context (security principle #2: no global fallback).
39
+ *
40
+ * Read methods (.get, .has, .getAll) are always available and reflect
41
+ * read-your-own-writes from .set() calls in the same request.
42
+ *
43
+ * Mutation methods (.set, .delete, .clear) are only available in mutable
44
+ * contexts (middleware.ts, server actions, route.ts handlers). Calling them
45
+ * in read-only contexts (access.ts, server components) throws.
46
+ *
47
+ * This is the escape hatch for direct cookie jar operations. For typed
48
+ * cookie access, use `defineCookie()` instead.
49
+ *
50
+ * See design/29-cookies.md
51
+ */
52
+ export function getCookieJar(): RequestCookies {
53
+ const store = requestContextAls.getStore();
54
+ if (!store) {
55
+ throw new Error(
56
+ '[timber] getCookieJar() called outside of a request context. ' +
57
+ 'It can only be used in middleware, access checks, server components, and server actions.'
58
+ );
59
+ }
60
+
61
+ // Parse cookies lazily on first access
62
+ if (!store.parsedCookies) {
63
+ store.parsedCookies = parseCookieHeader(store.cookieHeader);
64
+ }
65
+
66
+ const map = store.parsedCookies;
67
+ return {
68
+ get(name: string): string | undefined {
69
+ return map.get(name);
70
+ },
71
+ has(name: string): boolean {
72
+ return map.has(name);
73
+ },
74
+ getAll(): Array<{ name: string; value: string }> {
75
+ return Array.from(map.entries()).map(([name, value]) => ({ name, value }));
76
+ },
77
+ get size(): number {
78
+ return map.size;
79
+ },
80
+
81
+ set(name: string, value: string, options?: SetCookieOptions): void {
82
+ assertMutable(store, 'set');
83
+ // Validate the name first — names cannot be URL-encoded (RFC 7230
84
+ // token grammar is strict), so a bad name is always a bug.
85
+ assertValidCookieName(name);
86
+ // Type guard with a guiding error. The single most common mistake
87
+ // is passing a non-string (object, number, Date) and expecting the
88
+ // framework to JSON-encode. Point developers at jsonCookieCodec.
89
+ if (typeof value !== 'string') {
90
+ throw new Error(
91
+ `[timber] getCookieJar().set(${JSON.stringify(name)}, …): value must be a string, got ${typeof value}.\n` +
92
+ ` To store a JSON-serializable value, use defineCookie + jsonCookieCodec:\n` +
93
+ `\n` +
94
+ ` import { defineCookie, jsonCookieCodec } from '@timber-js/app/cookies';\n` +
95
+ `\n` +
96
+ ` export const ${name}Cookie = defineCookie(${JSON.stringify(name)}, {\n` +
97
+ ` codec: jsonCookieCodec(),\n` +
98
+ ` });\n` +
99
+ `\n` +
100
+ ` ${name}Cookie.set(value);\n` +
101
+ `\n` +
102
+ ` See design/29-cookies.md §"Typed Cookies with Schema Validation".`
103
+ );
104
+ }
105
+ // Encode the value so the on-the-wire bytes always satisfy
106
+ // RFC 6265 §4.1.1 cookie-octet. encodeURIComponent's output is a
107
+ // strict subset of cookie-octet (only `A-Z a-z 0-9 ! ' ( ) * - . _
108
+ // ~ %`), so the encoded form can never carry the H-3 smuggling
109
+ // primitive — `;` becomes `%3B`, CR/LF become `%0D`/`%0A`, etc.
110
+ // The round-trip is lossless: parseCookieHeader auto-decodes on
111
+ // read, so `cookies().get(name)` returns exactly `value`. See
112
+ // ONGOING_SECURITY.md H-3 (TIM-868) and design/29-cookies.md
113
+ // §"Encoding Contract".
114
+ //
115
+ // The `{ raw: true }` opt-out skips the encoder for callers who
116
+ // need exact byte control (e.g. forwarding pre-encoded cookies
117
+ // from an upstream service). The opt-out goes through the strict
118
+ // cookie-octet validator instead — the smuggling primitive cannot
119
+ // sneak in via the escape hatch.
120
+ const raw = options?.raw === true;
121
+ const wireValue = raw ? value : encodeURIComponent(value);
122
+ if (raw) {
123
+ assertValidCookieValue(name, wireValue);
124
+ }
125
+ if (store.flushed) {
126
+ if (isDebug()) {
127
+ console.warn(
128
+ `[timber] warn: getCookieJar().set('${name}') called after response headers were committed.\n` +
129
+ ` The cookie will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n` +
130
+ ` or a route.ts handler.`
131
+ );
132
+ }
133
+ return;
134
+ }
135
+ // Strip the framework-only `raw` flag before persisting — it is
136
+ // not an HTTP cookie attribute and must not leak into the jar.
137
+ const { raw: _raw, ...attributeOptions } = options ?? {};
138
+ void _raw;
139
+ const opts = { ...DEFAULT_COOKIE_OPTIONS, ...attributeOptions };
140
+ store.cookieJar.set(name, { name, value: wireValue, options: opts });
141
+ // Read-your-own-writes: store the DECODED logical value so that
142
+ // subsequent `cookies().get(name)` in the same request returns
143
+ // exactly what the developer wrote — never the encoded form.
144
+ // For `{ raw: true }`, the wire form IS the logical form.
145
+ map.set(name, raw ? wireValue : value);
146
+ },
147
+
148
+ setFromHeaders(headers: Headers): void {
149
+ assertMutable(store, 'setFromHeaders');
150
+ if (store.flushed) {
151
+ console.warn(
152
+ `[timber] warn: getCookieJar().setFromHeaders() called after response headers were committed.\n` +
153
+ ` The cookies will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n` +
154
+ ` or a route.ts handler.`
155
+ );
156
+ return;
157
+ }
158
+ // Headers.getSetCookie() returns individual Set-Cookie strings,
159
+ // avoiding the fragile comma-splitting that raw .get() requires.
160
+ for (const raw of headers.getSetCookie()) {
161
+ const parsed = parseSetCookie(raw);
162
+ if (parsed) {
163
+ // Use setRaw to preserve the original header's attributes without
164
+ // merging DEFAULT_COOKIE_OPTIONS (parseSetCookie intentionally
165
+ // does not apply defaults — see its doc comment).
166
+ setRaw(store, map, parsed.name, parsed.value, parsed.options);
167
+ }
168
+ }
169
+ },
170
+
171
+ delete(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void {
172
+ assertMutable(store, 'delete');
173
+ // Validate the name even though delete writes an empty value — a
174
+ // smuggled name (`;` or CR/LF) would corrupt the Set-Cookie header
175
+ // we emit. See ONGOING_SECURITY.md H-3 (TIM-868).
176
+ assertValidCookieName(name);
177
+ if (store.flushed) {
178
+ if (isDebug()) {
179
+ console.warn(
180
+ `[timber] warn: getCookieJar().delete('${name}') called after response headers were committed.\n` +
181
+ ` The cookie will NOT be deleted. Move cookie mutations to middleware.ts, a server action,\n` +
182
+ ` or a route.ts handler.`
183
+ );
184
+ }
185
+ return;
186
+ }
187
+ const opts: CookieOptions = {
188
+ ...DEFAULT_COOKIE_OPTIONS,
189
+ ...options,
190
+ maxAge: 0,
191
+ expires: new Date(0),
192
+ };
193
+ store.cookieJar.set(name, { name, value: '', options: opts });
194
+ // Remove from read view
195
+ map.delete(name);
196
+ },
197
+
198
+ clear(): void {
199
+ assertMutable(store, 'clear');
200
+ if (store.flushed) return;
201
+ // Delete every incoming cookie
202
+ for (const name of Array.from(map.keys())) {
203
+ store.cookieJar.set(name, {
204
+ name,
205
+ value: '',
206
+ options: { ...DEFAULT_COOKIE_OPTIONS, maxAge: 0, expires: new Date(0) },
207
+ });
208
+ }
209
+ map.clear();
210
+ },
211
+
212
+ toString(): string {
213
+ // Re-encode values when serializing as a Cookie header — the
214
+ // RYW map holds decoded logical values, but a Cookie header has
215
+ // to satisfy `cookie-octet`. Mirror the auto-encode contract on
216
+ // `set()` so toString() round-trips losslessly with parseCookieHeader.
217
+ return Array.from(map.entries())
218
+ .map(([name, value]) => `${name}=${encodeURIComponent(value)}`)
219
+ .join('; ');
220
+ },
221
+ };
222
+ }
223
+
224
+ /**
225
+ * Returns the value of a single cookie, or undefined if absent.
226
+ *
227
+ * @internal — not part of the public API. Use `defineCookie().get()` or `getCookieJar().get()` instead.
228
+ */
229
+ export function getCookie(name: string): string | undefined {
230
+ const jar = getCookieJar();
231
+ return jar.get(name);
232
+ }
233
+
234
+ // ─── Types ────────────────────────────────────────────────────────────────
235
+
236
+ /**
237
+ * Per-call options for `getCookies().set()`. Extends the persistent
238
+ * `CookieOptions` (HTTP cookie attributes) with framework-only flags
239
+ * that are NOT serialized into the Set-Cookie header.
240
+ *
241
+ * The `raw` flag is the escape hatch for the auto-encoding contract.
242
+ * See design/29-cookies.md §"Encoding Contract".
243
+ */
244
+ export interface SetCookieOptions extends CookieOptions {
245
+ /**
246
+ * Skip the framework's `encodeURIComponent` pass and store the value
247
+ * verbatim. The value is then validated against the strict RFC 6265
248
+ * §4.1.1 `cookie-octet` grammar — the H-3 smuggling primitive cannot
249
+ * sneak in via this opt-out.
250
+ *
251
+ * Use this when forwarding a cookie value that is already in its
252
+ * intended on-the-wire form (e.g. mirroring an upstream service's
253
+ * Set-Cookie). Default: `false` (auto-encode).
254
+ */
255
+ raw?: boolean;
256
+ }
257
+
258
+ /** Options for setting a cookie. See design/29-cookies.md. */
259
+ export interface CookieOptions {
260
+ /** Domain scope. Default: omitted (current domain only). */
261
+ domain?: string;
262
+ /** URL path scope. Default: '/'. */
263
+ path?: string;
264
+ /** Expiration date. Mutually exclusive with maxAge. */
265
+ expires?: Date;
266
+ /** Max age in seconds. Mutually exclusive with expires. */
267
+ maxAge?: number;
268
+ /** Prevent client-side JS access. Default: true. */
269
+ httpOnly?: boolean;
270
+ /** Only send over HTTPS. Default: true. */
271
+ secure?: boolean;
272
+ /** Cross-site request policy. Default: 'lax'. */
273
+ sameSite?: 'strict' | 'lax' | 'none';
274
+ /** Partitioned (CHIPS) — isolate cookie per top-level site. Default: false. */
275
+ partitioned?: boolean;
276
+ }
277
+
278
+ /**
279
+ * Cookie accessor returned by `getCookies()`.
280
+ *
281
+ * Read methods are always available. Mutation methods throw in read-only
282
+ * contexts (access.ts, server components).
283
+ */
284
+ export interface RequestCookies {
285
+ /** Get a cookie value by name. Returns undefined if not present. */
286
+ get(name: string): string | undefined;
287
+ /** Check if a cookie exists. */
288
+ has(name: string): boolean;
289
+ /** Get all cookies as an array of { name, value } pairs. */
290
+ getAll(): Array<{ name: string; value: string }>;
291
+ /** Number of cookies. */
292
+ readonly size: number;
293
+ /**
294
+ * Set a cookie. Only available in mutable contexts (middleware, actions,
295
+ * route handlers).
296
+ *
297
+ * The value is auto-encoded with `encodeURIComponent` so the on-the-wire
298
+ * bytes always satisfy RFC 6265 §4.1.1 cookie-octet — `cookies().get()`
299
+ * returns the same logical value the developer wrote. Pass `{ raw: true }`
300
+ * to skip the encoder; the raw path validates against the strict
301
+ * cookie-octet grammar instead. See design/29-cookies.md §"Encoding
302
+ * Contract" and ONGOING_SECURITY.md H-3 (TIM-868).
303
+ */
304
+ set(name: string, value: string, options?: SetCookieOptions): void;
305
+ /**
306
+ * Copy all `Set-Cookie` headers from a `Headers` object.
307
+ * Parses each header and forwards name, value, and all attributes
308
+ * (path, domain, max-age, expires, sameSite, secure, httpOnly, partitioned).
309
+ *
310
+ * Useful when forwarding cookies from an internal `fetch()` or auth handler:
311
+ * ```ts
312
+ * const response = await auth.handler(req);
313
+ * getCookies().then(c => c.setFromHeaders(response.headers));
314
+ * ```
315
+ */
316
+ setFromHeaders(headers: Headers): void;
317
+ /** Delete a cookie. Only available in mutable contexts. */
318
+ delete(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
319
+ /** Delete all cookies. Only available in mutable contexts. */
320
+ clear(): void;
321
+ /** Serialize cookies as a Cookie header string. */
322
+ toString(): string;
323
+ }
324
+
325
+ const DEFAULT_COOKIE_OPTIONS: CookieOptions = {
326
+ path: '/',
327
+ httpOnly: true,
328
+ secure: true,
329
+ sameSite: 'lax',
330
+ };
331
+
332
+ // ─── Framework-Internal Helpers ───────────────────────────────────────────
333
+
334
+ /**
335
+ * Per-request seed map of cookie name → value, registered out-of-band so the
336
+ * pipeline's `runWithRequestContext` call can pick it up without changing
337
+ * the function's calling convention. Stored in a WeakMap keyed by the
338
+ * synthetic Request object built for the rerender path, so the seed lives
339
+ * exactly as long as the request and is collected with it.
340
+ *
341
+ * The seed exists to eliminate the parse/serialize round-trip on the no-JS
342
+ * form-rerender path — see ONGOING_SECURITY.md H-3 (TIM-868). The action's
343
+ * post-mutation RYW snapshot is threaded directly into the rerender scope's
344
+ * `parsedCookies` map, bypassing `parseCookieHeader` entirely.
345
+ */
346
+ const seededRequestCookies = new WeakMap<Request, Map<string, string>>();
347
+
348
+ /**
349
+ * Register a pre-parsed cookie map to use as the request context seed for
350
+ * the next `runWithRequestContext(req, …)` call with this exact `req`.
351
+ *
352
+ * Used by the no-JS form-rerender dispatcher in
353
+ * `rsc-entry/wrap-action-dispatch.ts` to thread the action's post-mutation
354
+ * cookie state into the rerender scope without serializing back through a
355
+ * `Cookie:` header. See TIM-868 / TIM-837.
356
+ *
357
+ * @internal — framework use only.
358
+ */
359
+ export function seedRequestCookies(req: Request, cookies: Map<string, string>): void {
360
+ // Defensive copy: callers must not be able to mutate the rerender scope's
361
+ // map after seeding, and the rerender scope must not mutate the snapshot
362
+ // we hand back to other observers.
363
+ seededRequestCookies.set(req, new Map(cookies));
364
+ }
365
+
366
+ /**
367
+ * Pop the seed (if any) for `req` and return it. Called from
368
+ * `runWithRequestContext` exactly once per request — the seed is consumed
369
+ * eagerly so it cannot leak into a hypothetical future re-use of the same
370
+ * Request reference.
371
+ *
372
+ * @internal — framework use only.
373
+ */
374
+ export function consumeSeededCookies(req: Request): Map<string, string> | undefined {
375
+ const seed = seededRequestCookies.get(req);
376
+ if (seed) seededRequestCookies.delete(req);
377
+ return seed;
378
+ }
379
+
380
+ /**
381
+ * Build a Map of cookie name → value reflecting the current request's
382
+ * read-your-own-writes state. Includes incoming cookies plus any
383
+ * mutations from getCookies().set() / getCookies().delete() in the same request.
384
+ *
385
+ * Used by SSR renderers to populate NavContext.cookies so that
386
+ * useCookie()'s server snapshot matches the actual response state.
387
+ *
388
+ * See design/29-cookies.md §"Read-Your-Own-Writes"
389
+ * See design/triage/TIM-441-cookie-api-triage.md §4
390
+ */
391
+ export function getCookiesForSsr(): Map<string, string> {
392
+ const store = requestContextAls.getStore();
393
+ if (!store) {
394
+ throw new Error('[timber] getCookiesForSsr() called outside of a request context.');
395
+ }
396
+
397
+ // Trigger lazy parsing if not yet done
398
+ if (!store.parsedCookies) {
399
+ store.parsedCookies = parseCookieHeader(store.cookieHeader);
400
+ }
401
+
402
+ // The parsedCookies map already reflects read-your-own-writes:
403
+ // - getCookies().set() updates the map via map.set(name, value)
404
+ // - getCookies().delete() removes from the map via map.delete(name)
405
+ // Return a copy so callers can't mutate the internal map.
406
+ return new Map(store.parsedCookies);
407
+ }
408
+
409
+ /**
410
+ * Collect all Set-Cookie headers from the cookie jar.
411
+ * Called by the framework at flush time to apply cookies to the response.
412
+ *
413
+ * Returns an array of serialized Set-Cookie header values.
414
+ */
415
+ export function getSetCookieHeaders(): string[] {
416
+ const store = requestContextAls.getStore();
417
+ if (!store) return [];
418
+ return Array.from(store.cookieJar.values()).map(serializeCookieEntry);
419
+ }
420
+
421
+ // ─── Cookie Helpers ───────────────────────────────────────────────────────
422
+
423
+ /** Throw if cookie mutation is attempted in a read-only context. */
424
+ function assertMutable(store: RequestContextStore, method: string): void {
425
+ if (!store.mutableContext) {
426
+ throw new Error(
427
+ `[timber] getCookieJar().${method}() cannot be called in this context.\n` +
428
+ ` Set cookies in middleware.ts, server actions, or route.ts handlers.`
429
+ );
430
+ }
431
+ }
432
+
433
+ /**
434
+ * Write a cookie to the jar WITHOUT merging DEFAULT_COOKIE_OPTIONS.
435
+ * Used by setFromHeaders to preserve the original header's attributes exactly.
436
+ *
437
+ * For deletion cookies (maxAge=0), the jar entry is still created so the
438
+ * Set-Cookie header is emitted, but the cookie is NOT added to the read map
439
+ * (it would be misleading — the cookie is being deleted).
440
+ */
441
+ function setRaw(
442
+ store: RequestContextStore,
443
+ readMap: Map<string, string>,
444
+ name: string,
445
+ value: string,
446
+ options: CookieOptions
447
+ ): void {
448
+ // setRaw is the forwarding path for upstream Set-Cookie headers
449
+ // (`getCookies().setFromHeaders(response.headers)`). The value comes
450
+ // out of `parseSetCookie` in its on-the-wire form — already encoded
451
+ // by whoever produced it — so we re-emit it verbatim into our jar.
452
+ // We DO validate against the strict cookie-octet grammar, both as
453
+ // defense-in-depth against a malicious upstream and to keep the
454
+ // ONGOING_SECURITY.md H-3 invariant intact at every entry point into
455
+ // the cookie jar / RYW map.
456
+ assertValidCookieName(name);
457
+ assertValidCookieValue(name, value);
458
+ store.cookieJar.set(name, { name, value, options });
459
+ // Deletion cookies (Max-Age=0) should not appear in the read map.
460
+ if (options.maxAge === 0) {
461
+ readMap.delete(name);
462
+ } else {
463
+ // Decode for the RYW map so consumers see the same logical bytes
464
+ // they would see if the upstream cookie had arrived on the next
465
+ // request. Mirrors `parseCookieHeader`'s auto-decode.
466
+ readMap.set(name, safeDecodeCookieValue(value));
467
+ }
468
+ }