@timber-js/app 0.2.0-alpha.16 → 0.2.0-alpha.160

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 (985) hide show
  1. package/LICENSE +8 -0
  2. package/agent-skill.md +344 -0
  3. package/dist/_chunks/actions-C9yAuoX3.js +314 -0
  4. package/dist/_chunks/actions-C9yAuoX3.js.map +1 -0
  5. package/dist/_chunks/build-output-helper-DF5uScqS.js +158 -0
  6. package/dist/_chunks/build-output-helper-DF5uScqS.js.map +1 -0
  7. package/dist/_chunks/cache-api-swbefQ6F.js +1125 -0
  8. package/dist/_chunks/cache-api-swbefQ6F.js.map +1 -0
  9. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → canonicalize-P41GR6tY.js} +94 -18
  10. package/dist/_chunks/canonicalize-P41GR6tY.js.map +1 -0
  11. package/dist/_chunks/cli-schema-sync-BhYDz_-x.js +638 -0
  12. package/dist/_chunks/cli-schema-sync-BhYDz_-x.js.map +1 -0
  13. package/dist/_chunks/codec-registry-oOUxugz3.js +21 -0
  14. package/dist/_chunks/codec-registry-oOUxugz3.js.map +1 -0
  15. package/dist/_chunks/define-Bssfp6ot.js +82 -0
  16. package/dist/_chunks/define-Bssfp6ot.js.map +1 -0
  17. package/dist/_chunks/define-CFmvb4Bt.js +203 -0
  18. package/dist/_chunks/define-CFmvb4Bt.js.map +1 -0
  19. package/dist/_chunks/dist-BA3u1z3W.js +423 -0
  20. package/dist/_chunks/dist-BA3u1z3W.js.map +1 -0
  21. package/dist/_chunks/fast-hash-D6hIVt1Y.js +36 -0
  22. package/dist/_chunks/fast-hash-D6hIVt1Y.js.map +1 -0
  23. package/dist/_chunks/format-CfwjgPz9.js +14 -0
  24. package/dist/_chunks/format-CfwjgPz9.js.map +1 -0
  25. package/dist/_chunks/href-validation-CMc5JRls.js +141 -0
  26. package/dist/_chunks/href-validation-CMc5JRls.js.map +1 -0
  27. package/dist/_chunks/logger-CPoQkGK6.js +1523 -0
  28. package/dist/_chunks/logger-CPoQkGK6.js.map +1 -0
  29. package/dist/_chunks/navigation-root-bUDZLw74.js +124 -0
  30. package/dist/_chunks/navigation-root-bUDZLw74.js.map +1 -0
  31. package/dist/_chunks/plugin-context-DeAxFRMq.js +280 -0
  32. package/dist/_chunks/plugin-context-DeAxFRMq.js.map +1 -0
  33. package/dist/_chunks/registry-DbJPKoBp.js +20 -0
  34. package/dist/_chunks/registry-DbJPKoBp.js.map +1 -0
  35. package/dist/_chunks/resolve-schema-3iUvBV5T.js +50 -0
  36. package/dist/_chunks/resolve-schema-3iUvBV5T.js.map +1 -0
  37. package/dist/_chunks/router-ref-CtmF-aPv.js +28 -0
  38. package/dist/_chunks/router-ref-CtmF-aPv.js.map +1 -0
  39. package/dist/_chunks/schema-bridge-BY3QLBL7.js +119 -0
  40. package/dist/_chunks/schema-bridge-BY3QLBL7.js.map +1 -0
  41. package/dist/_chunks/segment-classify-CDDRVKs7.js +137 -0
  42. package/dist/_chunks/segment-classify-CDDRVKs7.js.map +1 -0
  43. package/dist/_chunks/segment-context-ZDnXDkbz.js +34 -0
  44. package/dist/_chunks/segment-context-ZDnXDkbz.js.map +1 -0
  45. package/dist/_chunks/sizeof-lXffQ1Vr.js +35 -0
  46. package/dist/_chunks/sizeof-lXffQ1Vr.js.map +1 -0
  47. package/dist/_chunks/{ssr-data-MjmprTmO.js → ssr-data-BOWsq18U.js} +1 -1
  48. package/dist/_chunks/ssr-data-BOWsq18U.js.map +1 -0
  49. package/dist/_chunks/tree-match-D2l830j2.js +102 -0
  50. package/dist/_chunks/tree-match-D2l830j2.js.map +1 -0
  51. package/dist/_chunks/{use-query-states-D5KaffOK.js → use-query-states-CbeQmext.js} +7 -20
  52. package/dist/_chunks/use-query-states-CbeQmext.js.map +1 -0
  53. package/dist/_chunks/use-segment-params-D1CzlgBo.js +151 -0
  54. package/dist/_chunks/use-segment-params-D1CzlgBo.js.map +1 -0
  55. package/dist/_chunks/walkers-c8aReVgo.js +988 -0
  56. package/dist/_chunks/walkers-c8aReVgo.js.map +1 -0
  57. package/dist/adapters/build-output-helper.d.ts +29 -0
  58. package/dist/adapters/build-output-helper.d.ts.map +1 -0
  59. package/dist/adapters/cloudflare-dev.d.ts +109 -0
  60. package/dist/adapters/cloudflare-dev.d.ts.map +1 -0
  61. package/dist/adapters/cloudflare-dev.js +73 -0
  62. package/dist/adapters/cloudflare-dev.js.map +1 -0
  63. package/dist/adapters/cloudflare-kv-cache.d.ts +64 -0
  64. package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -0
  65. package/dist/adapters/cloudflare-kv-cache.js +117 -0
  66. package/dist/adapters/cloudflare-kv-cache.js.map +1 -0
  67. package/dist/adapters/cloudflare.d.ts +177 -20
  68. package/dist/adapters/cloudflare.d.ts.map +1 -1
  69. package/dist/adapters/cloudflare.js +342 -67
  70. package/dist/adapters/cloudflare.js.map +1 -1
  71. package/dist/adapters/compress-module.d.ts +5 -4
  72. package/dist/adapters/compress-module.d.ts.map +1 -1
  73. package/dist/adapters/nitro.d.ts +1 -3
  74. package/dist/adapters/nitro.d.ts.map +1 -1
  75. package/dist/adapters/nitro.js +143 -144
  76. package/dist/adapters/nitro.js.map +1 -1
  77. package/dist/adapters/shared.d.ts +6 -0
  78. package/dist/adapters/shared.d.ts.map +1 -0
  79. package/dist/cache/cache-api.d.ts +26 -0
  80. package/dist/cache/cache-api.d.ts.map +1 -0
  81. package/dist/cache/handler-store.d.ts +33 -0
  82. package/dist/cache/handler-store.d.ts.map +1 -0
  83. package/dist/cache/index.d.ts +27 -7
  84. package/dist/cache/index.d.ts.map +1 -1
  85. package/dist/cache/index.js +3 -326
  86. package/dist/cache/invalidation-epoch.d.ts +43 -0
  87. package/dist/cache/invalidation-epoch.d.ts.map +1 -0
  88. package/dist/cache/redis-handler.d.ts +97 -8
  89. package/dist/cache/redis-handler.d.ts.map +1 -1
  90. package/dist/cache/singleflight.d.ts +19 -2
  91. package/dist/cache/singleflight.d.ts.map +1 -1
  92. package/dist/cache/sizeof.d.ts +22 -0
  93. package/dist/cache/sizeof.d.ts.map +1 -0
  94. package/dist/cache/stable-stringify.d.ts +9 -0
  95. package/dist/cache/stable-stringify.d.ts.map +1 -1
  96. package/dist/cache/store.d.ts +53 -0
  97. package/dist/cache/store.d.ts.map +1 -0
  98. package/dist/cache/stores/cloudflare-kv.d.ts +38 -0
  99. package/dist/cache/stores/cloudflare-kv.d.ts.map +1 -0
  100. package/dist/cache/stores/cloudflare-kv.js +29 -0
  101. package/dist/cache/stores/cloudflare-kv.js.map +1 -0
  102. package/dist/cache/stores/memory.d.ts +42 -0
  103. package/dist/cache/stores/memory.d.ts.map +1 -0
  104. package/dist/cache/stores/memory.js +90 -0
  105. package/dist/cache/stores/memory.js.map +1 -0
  106. package/dist/cache/stores/redis.d.ts +69 -0
  107. package/dist/cache/stores/redis.d.ts.map +1 -0
  108. package/dist/cache/stores/redis.js +35 -0
  109. package/dist/cache/stores/redis.js.map +1 -0
  110. package/dist/cache/stores/vercel.d.ts +36 -0
  111. package/dist/cache/stores/vercel.d.ts.map +1 -0
  112. package/dist/cache/stores/vercel.js +33 -0
  113. package/dist/cache/stores/vercel.js.map +1 -0
  114. package/dist/cache/tag-aware-handler.d.ts +51 -0
  115. package/dist/cache/tag-aware-handler.d.ts.map +1 -0
  116. package/dist/cache/timber-cache.d.ts +20 -10
  117. package/dist/cache/timber-cache.d.ts.map +1 -1
  118. package/dist/cdn/cloudflare-purge.d.ts +23 -0
  119. package/dist/cdn/cloudflare-purge.d.ts.map +1 -0
  120. package/dist/cdn/fastly-purge.d.ts +25 -0
  121. package/dist/cdn/fastly-purge.d.ts.map +1 -0
  122. package/dist/cdn/headers.d.ts +97 -0
  123. package/dist/cdn/headers.d.ts.map +1 -0
  124. package/dist/cdn/index.d.ts +5 -0
  125. package/dist/cdn/index.d.ts.map +1 -0
  126. package/dist/cdn/purge-store.d.ts +23 -0
  127. package/dist/cdn/purge-store.d.ts.map +1 -0
  128. package/dist/cdn/workers-cache-purge.d.ts +16 -0
  129. package/dist/cdn/workers-cache-purge.d.ts.map +1 -0
  130. package/dist/cli-schema-sync.d.ts +59 -0
  131. package/dist/cli-schema-sync.d.ts.map +1 -0
  132. package/dist/cli.d.ts +34 -2
  133. package/dist/cli.d.ts.map +1 -1
  134. package/dist/cli.js +107 -33
  135. package/dist/cli.js.map +1 -1
  136. package/dist/client/browser-dev.d.ts +37 -1
  137. package/dist/client/browser-dev.d.ts.map +1 -1
  138. package/dist/client/browser-entry/action-dispatch.d.ts +17 -0
  139. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -0
  140. package/dist/client/browser-entry/hmr.d.ts +21 -0
  141. package/dist/client/browser-entry/hmr.d.ts.map +1 -0
  142. package/dist/client/browser-entry/hydrate.d.ts +46 -0
  143. package/dist/client/browser-entry/hydrate.d.ts.map +1 -0
  144. package/dist/client/browser-entry/index.d.ts +29 -0
  145. package/dist/client/browser-entry/index.d.ts.map +1 -0
  146. package/dist/client/browser-entry/post-hydration.d.ts +26 -0
  147. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -0
  148. package/dist/client/browser-entry/router-init.d.ts +26 -0
  149. package/dist/client/browser-entry/router-init.d.ts.map +1 -0
  150. package/dist/client/browser-entry/rsc-stream.d.ts +24 -0
  151. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -0
  152. package/dist/client/browser-entry/scroll.d.ts +28 -0
  153. package/dist/client/browser-entry/scroll.d.ts.map +1 -0
  154. package/dist/client/error-boundary.d.ts +12 -5
  155. package/dist/client/error-boundary.d.ts.map +1 -1
  156. package/dist/client/error-boundary.js +47 -10
  157. package/dist/client/error-boundary.js.map +1 -1
  158. package/dist/client/error-reconstituter.d.ts +61 -0
  159. package/dist/client/error-reconstituter.d.ts.map +1 -0
  160. package/dist/client/form.d.ts +16 -27
  161. package/dist/client/form.d.ts.map +1 -1
  162. package/dist/client/history.d.ts +11 -6
  163. package/dist/client/history.d.ts.map +1 -1
  164. package/dist/client/index.d.ts +10 -24
  165. package/dist/client/index.d.ts.map +1 -1
  166. package/dist/client/index.js +182 -1134
  167. package/dist/client/index.js.map +1 -1
  168. package/dist/client/internal.d.ts +19 -0
  169. package/dist/client/internal.d.ts.map +1 -0
  170. package/dist/client/internal.js +825 -0
  171. package/dist/client/internal.js.map +1 -0
  172. package/dist/client/link.d.ts +69 -60
  173. package/dist/client/link.d.ts.map +1 -1
  174. package/dist/client/navigation-api.d.ts +120 -0
  175. package/dist/client/navigation-api.d.ts.map +1 -0
  176. package/dist/client/navigation-context.d.ts +3 -2
  177. package/dist/client/navigation-context.d.ts.map +1 -1
  178. package/dist/client/navigation-root.d.ts +119 -0
  179. package/dist/client/navigation-root.d.ts.map +1 -0
  180. package/dist/client/nuqs-adapter.d.ts +1 -1
  181. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  182. package/dist/client/router-ref.d.ts +1 -1
  183. package/dist/client/router.d.ts +87 -14
  184. package/dist/client/router.d.ts.map +1 -1
  185. package/dist/client/rsc-fetch.d.ts +47 -14
  186. package/dist/client/rsc-fetch.d.ts.map +1 -1
  187. package/dist/client/segment-cache.d.ts +4 -4
  188. package/dist/client/segment-cache.d.ts.map +1 -1
  189. package/dist/client/segment-outlet.d.ts +49 -0
  190. package/dist/client/segment-outlet.d.ts.map +1 -0
  191. package/dist/client/segment-update-context.d.ts +21 -0
  192. package/dist/client/segment-update-context.d.ts.map +1 -0
  193. package/dist/client/shallow-url.d.ts +10 -0
  194. package/dist/client/shallow-url.d.ts.map +1 -0
  195. package/dist/client/ssr-data.d.ts +13 -4
  196. package/dist/client/ssr-data.d.ts.map +1 -1
  197. package/dist/client/state.d.ts +1 -1
  198. package/dist/client/top-loader.d.ts +5 -5
  199. package/dist/client/top-loader.d.ts.map +1 -1
  200. package/dist/client/use-cookie.d.ts +12 -0
  201. package/dist/client/use-cookie.d.ts.map +1 -1
  202. package/dist/client/use-link-status.d.ts +5 -5
  203. package/dist/client/use-link-status.d.ts.map +1 -1
  204. package/dist/client/use-pathname.d.ts.map +1 -1
  205. package/dist/client/use-pending-navigation.d.ts +23 -0
  206. package/dist/client/use-pending-navigation.d.ts.map +1 -0
  207. package/dist/client/use-query-states.d.ts +1 -1
  208. package/dist/client/use-query-states.d.ts.map +1 -1
  209. package/dist/client/use-router.d.ts +1 -1
  210. package/dist/client/use-router.d.ts.map +1 -1
  211. package/dist/client/use-search-params.d.ts +12 -5
  212. package/dist/client/use-search-params.d.ts.map +1 -1
  213. package/dist/client/{use-params.d.ts → use-segment-params.d.ts} +8 -6
  214. package/dist/client/use-segment-params.d.ts.map +1 -0
  215. package/dist/codec.d.ts +69 -0
  216. package/dist/codec.d.ts.map +1 -0
  217. package/dist/codec.js +75 -0
  218. package/dist/codec.js.map +1 -0
  219. package/dist/config-types.d.ts +304 -0
  220. package/dist/config-types.d.ts.map +1 -0
  221. package/dist/config-validation.d.ts +51 -0
  222. package/dist/config-validation.d.ts.map +1 -0
  223. package/dist/content/index.d.ts +1 -10
  224. package/dist/content/index.d.ts.map +1 -1
  225. package/dist/content/index.js +0 -2
  226. package/dist/cookies/define-cookie.d.ts +58 -25
  227. package/dist/cookies/define-cookie.d.ts.map +1 -1
  228. package/dist/cookies/index.d.ts +2 -1
  229. package/dist/cookies/index.d.ts.map +1 -1
  230. package/dist/cookies/index.js +253 -36
  231. package/dist/cookies/index.js.map +1 -1
  232. package/dist/cookies/json-cookie.d.ts +64 -0
  233. package/dist/cookies/json-cookie.d.ts.map +1 -0
  234. package/dist/cookies/validation.d.ts +34 -0
  235. package/dist/cookies/validation.d.ts.map +1 -0
  236. package/dist/dev-tools/404-page.d.ts +50 -0
  237. package/dist/dev-tools/404-page.d.ts.map +1 -0
  238. package/dist/dev-tools/browser-logs.d.ts +40 -0
  239. package/dist/dev-tools/browser-logs.d.ts.map +1 -0
  240. package/dist/dev-tools/dev-page-shell.d.ts +78 -0
  241. package/dist/dev-tools/dev-page-shell.d.ts.map +1 -0
  242. package/dist/dev-tools/error-page.d.ts +32 -0
  243. package/dist/dev-tools/error-page.d.ts.map +1 -0
  244. package/dist/dev-tools/holding-server.d.ts +54 -0
  245. package/dist/dev-tools/holding-server.d.ts.map +1 -0
  246. package/dist/dev-tools/hydration-overlay.d.ts +11 -0
  247. package/dist/dev-tools/hydration-overlay.d.ts.map +1 -0
  248. package/dist/dev-tools/index.d.ts +31 -0
  249. package/dist/dev-tools/index.d.ts.map +1 -0
  250. package/dist/dev-tools/instrumentation.d.ts +59 -0
  251. package/dist/dev-tools/instrumentation.d.ts.map +1 -0
  252. package/dist/{server/dev-logger.d.ts → dev-tools/logger.d.ts} +1 -1
  253. package/dist/dev-tools/logger.d.ts.map +1 -0
  254. package/dist/{plugins/dev-logs.d.ts → dev-tools/logs.d.ts} +2 -2
  255. package/dist/dev-tools/logs.d.ts.map +1 -0
  256. package/dist/dev-tools/overlay.d.ts +91 -0
  257. package/dist/dev-tools/overlay.d.ts.map +1 -0
  258. package/dist/dev-tools/stack-classifier.d.ts +34 -0
  259. package/dist/dev-tools/stack-classifier.d.ts.map +1 -0
  260. package/dist/dev-tools/terminal.d.ts +28 -0
  261. package/dist/dev-tools/terminal.d.ts.map +1 -0
  262. package/dist/fonts/ast-walk.d.ts +68 -0
  263. package/dist/fonts/ast-walk.d.ts.map +1 -0
  264. package/dist/fonts/ast.d.ts +110 -6
  265. package/dist/fonts/ast.d.ts.map +1 -1
  266. package/dist/fonts/bundle.d.ts +50 -0
  267. package/dist/fonts/bundle.d.ts.map +1 -0
  268. package/dist/fonts/dev-middleware.d.ts +22 -0
  269. package/dist/fonts/dev-middleware.d.ts.map +1 -0
  270. package/dist/fonts/fallbacks.d.ts +0 -7
  271. package/dist/fonts/fallbacks.d.ts.map +1 -1
  272. package/dist/fonts/google.d.ts +4 -2
  273. package/dist/fonts/google.d.ts.map +1 -1
  274. package/dist/fonts/local.d.ts +4 -4
  275. package/dist/fonts/local.d.ts.map +1 -1
  276. package/dist/fonts/paths.d.ts +43 -0
  277. package/dist/fonts/paths.d.ts.map +1 -0
  278. package/dist/fonts/pipeline.d.ts +158 -0
  279. package/dist/fonts/pipeline.d.ts.map +1 -0
  280. package/dist/fonts/transform.d.ts +82 -0
  281. package/dist/fonts/transform.d.ts.map +1 -0
  282. package/dist/fonts/types.d.ts +47 -1
  283. package/dist/fonts/types.d.ts.map +1 -1
  284. package/dist/fonts/virtual-modules.d.ts +77 -0
  285. package/dist/fonts/virtual-modules.d.ts.map +1 -0
  286. package/dist/index.d.ts +46 -180
  287. package/dist/index.d.ts.map +1 -1
  288. package/dist/index.js +7807 -13691
  289. package/dist/index.js.map +1 -1
  290. package/dist/params/codec-registry.d.ts +26 -0
  291. package/dist/params/codec-registry.d.ts.map +1 -0
  292. package/dist/params/define-schema.d.ts +81 -0
  293. package/dist/params/define-schema.d.ts.map +1 -0
  294. package/dist/params/index.d.ts +5 -0
  295. package/dist/params/index.d.ts.map +1 -0
  296. package/dist/params/index.js +34 -0
  297. package/dist/params/index.js.map +1 -0
  298. package/dist/params/resolve-schema.d.ts +34 -0
  299. package/dist/params/resolve-schema.d.ts.map +1 -0
  300. package/dist/plugin-context.d.ts +190 -0
  301. package/dist/plugin-context.d.ts.map +1 -0
  302. package/dist/plugins/adapter-build.d.ts +20 -1
  303. package/dist/plugins/adapter-build.d.ts.map +1 -1
  304. package/dist/plugins/build-manifest.d.ts +7 -3
  305. package/dist/plugins/build-manifest.d.ts.map +1 -1
  306. package/dist/plugins/build-report.d.ts +43 -7
  307. package/dist/plugins/build-report.d.ts.map +1 -1
  308. package/dist/plugins/cache.d.ts +64 -0
  309. package/dist/plugins/cache.d.ts.map +1 -0
  310. package/dist/plugins/callsite-ast.d.ts +95 -0
  311. package/dist/plugins/callsite-ast.d.ts.map +1 -0
  312. package/dist/plugins/callsite-jsx.d.ts +35 -0
  313. package/dist/plugins/callsite-jsx.d.ts.map +1 -0
  314. package/dist/plugins/chunks.d.ts +11 -4
  315. package/dist/plugins/chunks.d.ts.map +1 -1
  316. package/dist/plugins/client-chunks.d.ts +40 -0
  317. package/dist/plugins/client-chunks.d.ts.map +1 -0
  318. package/dist/plugins/cloudflare-wasm.d.ts +21 -0
  319. package/dist/plugins/cloudflare-wasm.d.ts.map +1 -0
  320. package/dist/plugins/content.d.ts +1 -1
  321. package/dist/plugins/content.d.ts.map +1 -1
  322. package/dist/plugins/dev-server.d.ts +17 -1
  323. package/dist/plugins/dev-server.d.ts.map +1 -1
  324. package/dist/plugins/entries.d.ts +1 -1
  325. package/dist/plugins/entries.d.ts.map +1 -1
  326. package/dist/plugins/fonts.d.ts +16 -73
  327. package/dist/plugins/fonts.d.ts.map +1 -1
  328. package/dist/plugins/mdx.d.ts +1 -1
  329. package/dist/plugins/mdx.d.ts.map +1 -1
  330. package/dist/plugins/prebuilt-capture.d.ts +60 -0
  331. package/dist/plugins/prebuilt-capture.d.ts.map +1 -0
  332. package/dist/plugins/prebuilt.d.ts +82 -0
  333. package/dist/plugins/prebuilt.d.ts.map +1 -0
  334. package/dist/plugins/prerender-sugar.d.ts +42 -0
  335. package/dist/plugins/prerender-sugar.d.ts.map +1 -0
  336. package/dist/plugins/routing.d.ts +1 -1
  337. package/dist/plugins/routing.d.ts.map +1 -1
  338. package/dist/plugins/server-bundle.d.ts.map +1 -1
  339. package/dist/plugins/shims.d.ts +29 -5
  340. package/dist/plugins/shims.d.ts.map +1 -1
  341. package/dist/plugins/static-build.d.ts +5 -26
  342. package/dist/plugins/static-build.d.ts.map +1 -1
  343. package/dist/routing/codegen-shared.d.ts +67 -0
  344. package/dist/routing/codegen-shared.d.ts.map +1 -0
  345. package/dist/routing/codegen-types.d.ts +64 -0
  346. package/dist/routing/codegen-types.d.ts.map +1 -0
  347. package/dist/routing/codegen.d.ts +7 -2
  348. package/dist/routing/codegen.d.ts.map +1 -1
  349. package/dist/routing/convention-lint.d.ts +41 -0
  350. package/dist/routing/convention-lint.d.ts.map +1 -0
  351. package/dist/routing/export-detect.d.ts +56 -0
  352. package/dist/routing/export-detect.d.ts.map +1 -0
  353. package/dist/routing/file-cache.d.ts +8 -0
  354. package/dist/routing/file-cache.d.ts.map +1 -0
  355. package/dist/routing/index.d.ts +7 -1
  356. package/dist/routing/index.d.ts.map +1 -1
  357. package/dist/routing/index.js +4 -2
  358. package/dist/routing/interception.d.ts +0 -5
  359. package/dist/routing/interception.d.ts.map +1 -1
  360. package/dist/routing/link-codegen.d.ts +90 -0
  361. package/dist/routing/link-codegen.d.ts.map +1 -0
  362. package/dist/routing/manifest-codegen.d.ts +32 -0
  363. package/dist/routing/manifest-codegen.d.ts.map +1 -0
  364. package/dist/routing/scanner.d.ts +1 -10
  365. package/dist/routing/scanner.d.ts.map +1 -1
  366. package/dist/routing/schema-validation.d.ts +35 -0
  367. package/dist/routing/schema-validation.d.ts.map +1 -0
  368. package/dist/routing/segment-classify.d.ts +75 -0
  369. package/dist/routing/segment-classify.d.ts.map +1 -0
  370. package/dist/routing/segment-codegen.d.ts +38 -0
  371. package/dist/routing/segment-codegen.d.ts.map +1 -0
  372. package/dist/routing/types.d.ts +77 -25
  373. package/dist/routing/types.d.ts.map +1 -1
  374. package/dist/routing/walkers.d.ts +51 -0
  375. package/dist/routing/walkers.d.ts.map +1 -0
  376. package/dist/rsc-runtime/rsc.d.ts +1 -1
  377. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  378. package/dist/rsc-runtime/ssr.d.ts +12 -0
  379. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  380. package/dist/schema-bridge.d.ts +91 -0
  381. package/dist/schema-bridge.d.ts.map +1 -0
  382. package/dist/search-params/define.d.ts +157 -0
  383. package/dist/search-params/define.d.ts.map +1 -0
  384. package/dist/search-params/index.d.ts +4 -7
  385. package/dist/search-params/index.d.ts.map +1 -1
  386. package/dist/search-params/index.js +37 -440
  387. package/dist/search-params/index.js.map +1 -1
  388. package/dist/search-params/registry.d.ts +2 -2
  389. package/dist/search-params/registry.d.ts.map +1 -1
  390. package/dist/search-params/wrappers.d.ts +53 -0
  391. package/dist/search-params/wrappers.d.ts.map +1 -0
  392. package/dist/segment-params/define.d.ts +89 -0
  393. package/dist/segment-params/define.d.ts.map +1 -0
  394. package/dist/segment-params/index.d.ts +3 -0
  395. package/dist/segment-params/index.d.ts.map +1 -0
  396. package/dist/segment-params/index.js +2 -0
  397. package/dist/server/access-gate.d.ts +8 -3
  398. package/dist/server/access-gate.d.ts.map +1 -1
  399. package/dist/server/action-client.d.ts +41 -6
  400. package/dist/server/action-client.d.ts.map +1 -1
  401. package/dist/server/action-encryption.d.ts +76 -0
  402. package/dist/server/action-encryption.d.ts.map +1 -0
  403. package/dist/server/action-handler.d.ts +35 -1
  404. package/dist/server/action-handler.d.ts.map +1 -1
  405. package/dist/server/actions.d.ts +6 -30
  406. package/dist/server/actions.d.ts.map +1 -1
  407. package/dist/server/als-registry.d.ts +85 -11
  408. package/dist/server/als-registry.d.ts.map +1 -1
  409. package/dist/server/asset-headers.d.ts +8 -18
  410. package/dist/server/asset-headers.d.ts.map +1 -1
  411. package/dist/server/body-limits.d.ts.map +1 -1
  412. package/dist/server/build-manifest.d.ts +6 -29
  413. package/dist/server/build-manifest.d.ts.map +1 -1
  414. package/dist/server/canonicalize.d.ts +10 -0
  415. package/dist/server/canonicalize.d.ts.map +1 -1
  416. package/dist/server/coalesce-tick.d.ts +40 -0
  417. package/dist/server/coalesce-tick.d.ts.map +1 -0
  418. package/dist/server/cookie-context.d.ts +170 -0
  419. package/dist/server/cookie-context.d.ts.map +1 -0
  420. package/dist/server/cookie-parsing.d.ts +65 -0
  421. package/dist/server/cookie-parsing.d.ts.map +1 -0
  422. package/dist/server/csrf.d.ts +3 -2
  423. package/dist/server/csrf.d.ts.map +1 -1
  424. package/dist/server/default-logger.d.ts +22 -0
  425. package/dist/server/default-logger.d.ts.map +1 -0
  426. package/dist/server/deny-boundary.d.ts +115 -0
  427. package/dist/server/deny-boundary.d.ts.map +1 -0
  428. package/dist/server/deny-renderer.d.ts +2 -2
  429. package/dist/server/deny-renderer.d.ts.map +1 -1
  430. package/dist/server/dev-source-map.d.ts +22 -0
  431. package/dist/server/dev-source-map.d.ts.map +1 -0
  432. package/dist/server/early-hints-sender.d.ts.map +1 -1
  433. package/dist/server/early-hints.d.ts +13 -11
  434. package/dist/server/early-hints.d.ts.map +1 -1
  435. package/dist/server/error-boundary-wrapper.d.ts +7 -1
  436. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  437. package/dist/server/fallback-error.d.ts +12 -7
  438. package/dist/server/fallback-error.d.ts.map +1 -1
  439. package/dist/server/flight-injection-state.d.ts +66 -0
  440. package/dist/server/flight-injection-state.d.ts.map +1 -0
  441. package/dist/server/flight-scripts.d.ts +42 -0
  442. package/dist/server/flight-scripts.d.ts.map +1 -0
  443. package/dist/server/form-data.d.ts +41 -0
  444. package/dist/server/form-data.d.ts.map +1 -1
  445. package/dist/server/html-injector-core.d.ts +221 -0
  446. package/dist/server/html-injector-core.d.ts.map +1 -0
  447. package/dist/server/html-injectors.d.ts +82 -41
  448. package/dist/server/html-injectors.d.ts.map +1 -1
  449. package/dist/server/index.d.ts +10 -46
  450. package/dist/server/index.d.ts.map +1 -1
  451. package/dist/server/index.js +170 -2911
  452. package/dist/server/index.js.map +1 -1
  453. package/dist/server/internal.d.ts +49 -0
  454. package/dist/server/internal.d.ts.map +1 -0
  455. package/dist/server/internal.js +3577 -0
  456. package/dist/server/internal.js.map +1 -0
  457. package/dist/server/logger.d.ts +39 -7
  458. package/dist/server/logger.d.ts.map +1 -1
  459. package/dist/server/metadata-routes.d.ts +23 -7
  460. package/dist/server/metadata-routes.d.ts.map +1 -1
  461. package/dist/server/middleware-runner.d.ts +36 -4
  462. package/dist/server/middleware-runner.d.ts.map +1 -1
  463. package/dist/server/node-stream-transforms.d.ts +119 -0
  464. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  465. package/dist/server/param-coercion.d.ts +54 -0
  466. package/dist/server/param-coercion.d.ts.map +1 -0
  467. package/dist/server/pipeline-helpers.d.ts +95 -0
  468. package/dist/server/pipeline-helpers.d.ts.map +1 -0
  469. package/dist/server/pipeline-interception.d.ts +1 -1
  470. package/dist/server/pipeline-interception.d.ts.map +1 -1
  471. package/dist/server/pipeline-metadata.d.ts +6 -0
  472. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  473. package/dist/server/pipeline-outcome.d.ts +49 -0
  474. package/dist/server/pipeline-outcome.d.ts.map +1 -0
  475. package/dist/server/pipeline-phases.d.ts +56 -0
  476. package/dist/server/pipeline-phases.d.ts.map +1 -0
  477. package/dist/server/pipeline.d.ts +122 -19
  478. package/dist/server/pipeline.d.ts.map +1 -1
  479. package/dist/server/port-resolution.d.ts +117 -0
  480. package/dist/server/port-resolution.d.ts.map +1 -0
  481. package/dist/server/prebuilt/cache-key.d.ts +58 -0
  482. package/dist/server/prebuilt/cache-key.d.ts.map +1 -0
  483. package/dist/server/prebuilt/capture-state.d.ts +57 -0
  484. package/dist/server/prebuilt/capture-state.d.ts.map +1 -0
  485. package/dist/server/prebuilt/manifest-tag-index.d.ts +27 -0
  486. package/dist/server/prebuilt/manifest-tag-index.d.ts.map +1 -0
  487. package/dist/server/prebuilt/overlay.d.ts +100 -0
  488. package/dist/server/prebuilt/overlay.d.ts.map +1 -0
  489. package/dist/server/prebuilt/payload-source.d.ts +78 -0
  490. package/dist/server/prebuilt/payload-source.d.ts.map +1 -0
  491. package/dist/server/prebuilt/synthetic-store.d.ts +66 -0
  492. package/dist/server/prebuilt/synthetic-store.d.ts.map +1 -0
  493. package/dist/server/prebuilt-builder.d.ts +120 -0
  494. package/dist/server/prebuilt-builder.d.ts.map +1 -0
  495. package/dist/server/prebuilt-runtime.d.ts +101 -0
  496. package/dist/server/prebuilt-runtime.d.ts.map +1 -0
  497. package/dist/server/primitives.d.ts +83 -31
  498. package/dist/server/primitives.d.ts.map +1 -1
  499. package/dist/server/render-timeout.d.ts +51 -0
  500. package/dist/server/render-timeout.d.ts.map +1 -0
  501. package/dist/server/render-utils.d.ts +25 -0
  502. package/dist/server/render-utils.d.ts.map +1 -0
  503. package/dist/server/request-context.d.ts +62 -107
  504. package/dist/server/request-context.d.ts.map +1 -1
  505. package/dist/server/route-element-builder.d.ts +39 -25
  506. package/dist/server/route-element-builder.d.ts.map +1 -1
  507. package/dist/server/route-handler.d.ts.map +1 -1
  508. package/dist/server/route-matcher.d.ts +25 -36
  509. package/dist/server/route-matcher.d.ts.map +1 -1
  510. package/dist/server/rsc-entry/action-middleware-runner.d.ts +66 -0
  511. package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -0
  512. package/dist/server/rsc-entry/api-handler.d.ts +12 -3
  513. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  514. package/dist/server/rsc-entry/error-renderer.d.ts +26 -13
  515. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  516. package/dist/server/rsc-entry/helpers.d.ts +51 -28
  517. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  518. package/dist/server/rsc-entry/index.d.ts +30 -8
  519. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  520. package/dist/server/rsc-entry/render-route.d.ts +50 -0
  521. package/dist/server/rsc-entry/render-route.d.ts.map +1 -0
  522. package/dist/server/rsc-entry/revalidate-renderer.d.ts +108 -0
  523. package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -0
  524. package/dist/server/rsc-entry/rsc-payload.d.ts +5 -6
  525. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  526. package/dist/server/rsc-entry/rsc-stream.d.ts +17 -1
  527. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  528. package/dist/server/rsc-entry/ssr-bridge.d.ts +5 -1
  529. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  530. package/dist/server/rsc-entry/ssr-renderer.d.ts +34 -4
  531. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  532. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +119 -0
  533. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -0
  534. package/dist/server/safe-load.d.ts +46 -0
  535. package/dist/server/safe-load.d.ts.map +1 -0
  536. package/dist/server/sensitive-fields.d.ts +74 -0
  537. package/dist/server/sensitive-fields.d.ts.map +1 -0
  538. package/dist/server/sitemap-generator.d.ts +129 -0
  539. package/dist/server/sitemap-generator.d.ts.map +1 -0
  540. package/dist/server/sitemap-handler.d.ts +22 -0
  541. package/dist/server/sitemap-handler.d.ts.map +1 -0
  542. package/dist/server/slot-resolver.d.ts +7 -5
  543. package/dist/server/slot-resolver.d.ts.map +1 -1
  544. package/dist/server/ssr-bridge-types.d.ts +121 -0
  545. package/dist/server/ssr-bridge-types.d.ts.map +1 -0
  546. package/dist/server/ssr-entry.d.ts +2 -43
  547. package/dist/server/ssr-entry.d.ts.map +1 -1
  548. package/dist/server/ssr-render.d.ts +64 -21
  549. package/dist/server/ssr-render.d.ts.map +1 -1
  550. package/dist/server/ssr-wrappers.d.ts +50 -0
  551. package/dist/server/ssr-wrappers.d.ts.map +1 -0
  552. package/dist/server/state-tree-diff.d.ts +12 -5
  553. package/dist/server/state-tree-diff.d.ts.map +1 -1
  554. package/dist/server/status-code-resolver.d.ts +22 -11
  555. package/dist/server/status-code-resolver.d.ts.map +1 -1
  556. package/dist/server/stream-utils.d.ts +47 -0
  557. package/dist/server/stream-utils.d.ts.map +1 -0
  558. package/dist/server/tracing.d.ts +44 -9
  559. package/dist/server/tracing.d.ts.map +1 -1
  560. package/dist/server/tree-builder.d.ts +62 -30
  561. package/dist/server/tree-builder.d.ts.map +1 -1
  562. package/dist/server/tree-match.d.ts +49 -0
  563. package/dist/server/tree-match.d.ts.map +1 -0
  564. package/dist/server/types.d.ts +71 -6
  565. package/dist/server/types.d.ts.map +1 -1
  566. package/dist/server/utils/escape-html.d.ts +14 -0
  567. package/dist/server/utils/escape-html.d.ts.map +1 -0
  568. package/dist/server/utils/mdx-file.d.ts +15 -0
  569. package/dist/server/utils/mdx-file.d.ts.map +1 -0
  570. package/dist/server/version-skew.d.ts +61 -0
  571. package/dist/server/version-skew.d.ts.map +1 -0
  572. package/dist/server/workers-cache-bridge.d.ts +26 -0
  573. package/dist/server/workers-cache-bridge.d.ts.map +1 -0
  574. package/dist/shared/href-validation.d.ts +49 -0
  575. package/dist/shared/href-validation.d.ts.map +1 -0
  576. package/dist/shared/merge-search-params.d.ts +22 -0
  577. package/dist/shared/merge-search-params.d.ts.map +1 -0
  578. package/dist/shared/redirect-type.d.ts +17 -0
  579. package/dist/shared/redirect-type.d.ts.map +1 -0
  580. package/dist/shims/font-google.d.ts +1 -1
  581. package/dist/shims/font-google.d.ts.map +1 -1
  582. package/dist/shims/font-google.js +42 -0
  583. package/dist/shims/font-google.js.map +1 -0
  584. package/dist/shims/font-local.d.ts +26 -0
  585. package/dist/shims/font-local.d.ts.map +1 -0
  586. package/dist/shims/font-local.js +20 -0
  587. package/dist/shims/font-local.js.map +1 -0
  588. package/dist/shims/headers.d.ts +53 -1
  589. package/dist/shims/headers.d.ts.map +1 -1
  590. package/dist/shims/image.d.ts +16 -16
  591. package/dist/shims/navigation-client.d.ts +35 -11
  592. package/dist/shims/navigation-client.d.ts.map +1 -1
  593. package/dist/shims/navigation.d.ts +11 -5
  594. package/dist/shims/navigation.d.ts.map +1 -1
  595. package/dist/utils/state-machine.d.ts +80 -0
  596. package/dist/utils/state-machine.d.ts.map +1 -0
  597. package/docs/api/30-api-server.mdx +233 -0
  598. package/docs/api/31-api-client.mdx +161 -0
  599. package/docs/api/32-api-cache.mdx +199 -0
  600. package/docs/api/33-api-search-params.mdx +141 -0
  601. package/docs/api/34-api-config.mdx +189 -0
  602. package/docs/api/35-api-typescript.mdx +170 -0
  603. package/docs/api/36-cli.mdx +143 -0
  604. package/docs/learn/00-introduction.mdx +76 -0
  605. package/docs/learn/01-quick-start.mdx +94 -0
  606. package/docs/learn/02-pages-and-layouts.mdx +147 -0
  607. package/docs/learn/03-fetching-data.mdx +211 -0
  608. package/docs/learn/03b-access-control.mdx +130 -0
  609. package/docs/learn/04-loading-states.mdx +67 -0
  610. package/docs/learn/04b-the-flush-point.mdx +115 -0
  611. package/docs/learn/05-typed-params.mdx +275 -0
  612. package/docs/learn/06-forms-and-actions.mdx +146 -0
  613. package/docs/learn/07-typed-routes.mdx +127 -0
  614. package/docs/learn/08-streaming.mdx +146 -0
  615. package/docs/learn/09-caching.mdx +136 -0
  616. package/docs/learn/10-middleware.mdx +157 -0
  617. package/docs/learn/11-error-handling.mdx +156 -0
  618. package/docs/learn/12-client-navigation.mdx +168 -0
  619. package/docs/learn/13-configuration.mdx +145 -0
  620. package/docs/learn/14-deploying.mdx +264 -0
  621. package/docs/more/01-advanced-routing.mdx +139 -0
  622. package/docs/more/02-advanced-forms.mdx +137 -0
  623. package/docs/more/03-coming-from-nextjs.mdx +186 -0
  624. package/docs/more/04-metadata-and-fonts.mdx +193 -0
  625. package/docs/more/04b-mdx.mdx +209 -0
  626. package/docs/more/05-content-collections.mdx +90 -0
  627. package/docs/more/06-instrumentation.mdx +214 -0
  628. package/docs/more/07-security.mdx +129 -0
  629. package/docs/more/08-developer-experience.mdx +134 -0
  630. package/docs/more/40-why-timber.mdx +50 -0
  631. package/docs/more/41-timber-vs-nextjs.mdx +81 -0
  632. package/docs/more/42-timber-vs-others.mdx +68 -0
  633. package/docs/more/50-ai-agent-instructions.mdx +169 -0
  634. package/llms.txt +55 -0
  635. package/package.json +102 -26
  636. package/src/adapters/build-output-helper.ts +199 -0
  637. package/src/adapters/cloudflare-dev.ts +177 -0
  638. package/src/adapters/cloudflare-kv-cache.ts +179 -0
  639. package/src/adapters/cloudflare.ts +594 -119
  640. package/src/adapters/compress-module.ts +27 -92
  641. package/src/adapters/nitro.ts +131 -96
  642. package/src/adapters/raw-imports.d.ts +5 -0
  643. package/src/adapters/shared.ts +68 -0
  644. package/src/adapters/wrangler.d.ts +7 -0
  645. package/src/cache/cache-api.ts +107 -0
  646. package/src/cache/handler-store.ts +76 -0
  647. package/src/cache/index.ts +88 -18
  648. package/src/cache/invalidation-epoch.ts +93 -0
  649. package/src/cache/redis-handler.ts +122 -15
  650. package/src/cache/singleflight.ts +64 -6
  651. package/src/cache/sizeof.ts +33 -0
  652. package/src/cache/stable-stringify.ts +65 -2
  653. package/src/cache/store.ts +71 -0
  654. package/src/cache/stores/cloudflare-kv.ts +52 -0
  655. package/src/cache/stores/memory.ts +125 -0
  656. package/src/cache/stores/redis.ts +97 -0
  657. package/src/cache/stores/vercel.ts +59 -0
  658. package/src/cache/tag-aware-handler.ts +233 -0
  659. package/src/cache/timber-cache.ts +142 -36
  660. package/src/cdn/cloudflare-purge.ts +50 -0
  661. package/src/cdn/fastly-purge.ts +63 -0
  662. package/src/cdn/headers.ts +153 -0
  663. package/src/cdn/index.ts +17 -0
  664. package/src/cdn/purge-store.ts +34 -0
  665. package/src/cdn/workers-cache-purge.ts +30 -0
  666. package/src/cli-schema-sync.ts +388 -0
  667. package/src/cli.ts +157 -34
  668. package/src/client/browser-dev.ts +156 -1
  669. package/src/client/browser-entry/action-dispatch.ts +124 -0
  670. package/src/client/browser-entry/hmr.ts +70 -0
  671. package/src/client/browser-entry/hydrate.ts +187 -0
  672. package/src/client/browser-entry/index.ts +111 -0
  673. package/src/client/browser-entry/post-hydration.ts +103 -0
  674. package/src/client/browser-entry/router-init.ts +287 -0
  675. package/src/client/browser-entry/rsc-stream.ts +157 -0
  676. package/src/client/browser-entry/scroll.ts +50 -0
  677. package/src/client/error-boundary.tsx +127 -22
  678. package/src/client/error-reconstituter.tsx +79 -0
  679. package/src/client/form.tsx +31 -32
  680. package/src/client/history.ts +11 -7
  681. package/src/client/index.ts +67 -45
  682. package/src/client/internal.ts +58 -0
  683. package/src/client/link.tsx +346 -150
  684. package/src/client/navigation-api.ts +341 -0
  685. package/src/client/navigation-context.ts +15 -7
  686. package/src/client/navigation-root.tsx +355 -0
  687. package/src/client/nuqs-adapter.tsx +16 -3
  688. package/src/client/router-ref.ts +1 -1
  689. package/src/client/router.ts +482 -166
  690. package/src/client/rsc-fetch.ts +214 -33
  691. package/src/client/segment-cache.ts +7 -7
  692. package/src/client/segment-outlet.tsx +77 -0
  693. package/src/client/segment-update-context.ts +42 -0
  694. package/src/client/shallow-url.ts +22 -0
  695. package/src/client/ssr-data.ts +13 -5
  696. package/src/client/state.ts +2 -2
  697. package/src/client/top-loader.tsx +11 -9
  698. package/src/client/use-cookie.ts +49 -14
  699. package/src/client/use-link-status.ts +7 -7
  700. package/src/client/use-pathname.ts +1 -0
  701. package/src/client/use-pending-navigation.ts +40 -0
  702. package/src/client/use-query-states.ts +9 -3
  703. package/src/client/use-router.ts +4 -1
  704. package/src/client/use-search-params.ts +31 -44
  705. package/src/client/{use-params.ts → use-segment-params.ts} +9 -6
  706. package/src/codec.ts +147 -0
  707. package/src/config-types.ts +302 -0
  708. package/src/config-validation.ts +328 -0
  709. package/src/content/index.ts +5 -13
  710. package/src/cookies/define-cookie.ts +217 -53
  711. package/src/cookies/index.ts +12 -1
  712. package/src/cookies/json-cookie.ts +105 -0
  713. package/src/cookies/validation.ts +192 -0
  714. package/src/dev-tools/404-page.ts +286 -0
  715. package/src/dev-tools/browser-logs.ts +55 -0
  716. package/src/dev-tools/dev-page-shell.ts +260 -0
  717. package/src/dev-tools/error-page.ts +331 -0
  718. package/src/dev-tools/holding-server.ts +187 -0
  719. package/src/dev-tools/hydration-overlay.ts +158 -0
  720. package/src/dev-tools/index.ts +83 -0
  721. package/src/dev-tools/instrumentation.ts +213 -0
  722. package/src/{server/dev-logger.ts → dev-tools/logger.ts} +33 -51
  723. package/src/{plugins/dev-logs.ts → dev-tools/logs.ts} +9 -5
  724. package/src/dev-tools/overlay.ts +469 -0
  725. package/src/dev-tools/stack-classifier.ts +75 -0
  726. package/src/dev-tools/terminal.ts +182 -0
  727. package/src/fonts/ast-walk.ts +235 -0
  728. package/src/fonts/ast.ts +477 -126
  729. package/src/fonts/bundle.ts +138 -0
  730. package/src/fonts/dev-middleware.ts +85 -0
  731. package/src/fonts/fallbacks.ts +0 -23
  732. package/src/fonts/google.ts +63 -8
  733. package/src/fonts/local.ts +9 -8
  734. package/src/fonts/paths.ts +58 -0
  735. package/src/fonts/pipeline.ts +316 -0
  736. package/src/fonts/transform.ts +305 -0
  737. package/src/fonts/types.ts +52 -1
  738. package/src/fonts/virtual-modules.ts +179 -0
  739. package/src/index.ts +431 -352
  740. package/src/params/codec-registry.ts +34 -0
  741. package/src/params/define-schema.ts +115 -0
  742. package/src/params/index.ts +17 -0
  743. package/src/params/resolve-schema.ts +84 -0
  744. package/src/plugin-context.ts +378 -0
  745. package/src/plugins/adapter-build.ts +98 -4
  746. package/src/plugins/build-manifest.ts +168 -23
  747. package/src/plugins/build-report.ts +253 -35
  748. package/src/plugins/cache.ts +186 -0
  749. package/src/plugins/callsite-ast.ts +167 -0
  750. package/src/plugins/callsite-jsx.ts +243 -0
  751. package/src/plugins/chunks.ts +74 -5
  752. package/src/plugins/client-chunks.ts +144 -0
  753. package/src/plugins/cloudflare-wasm.ts +141 -0
  754. package/src/plugins/content.ts +1 -1
  755. package/src/plugins/dev-server.ts +293 -46
  756. package/src/plugins/entries.ts +129 -8
  757. package/src/plugins/fonts.ts +191 -664
  758. package/src/plugins/mdx.ts +47 -10
  759. package/src/plugins/prebuilt-capture.ts +210 -0
  760. package/src/plugins/prebuilt.ts +700 -0
  761. package/src/plugins/prerender-sugar.ts +329 -0
  762. package/src/plugins/routing.ts +237 -241
  763. package/src/plugins/server-bundle.ts +97 -12
  764. package/src/plugins/shims.ts +217 -64
  765. package/src/plugins/static-build.ts +15 -90
  766. package/src/routing/codegen-shared.ts +115 -0
  767. package/src/routing/codegen-types.ts +65 -0
  768. package/src/routing/codegen.ts +360 -178
  769. package/src/routing/convention-lint.ts +394 -0
  770. package/src/routing/export-detect.ts +304 -0
  771. package/src/routing/file-cache.ts +23 -0
  772. package/src/routing/index.ts +10 -1
  773. package/src/routing/interception.ts +3 -22
  774. package/src/routing/link-codegen.ts +310 -0
  775. package/src/routing/manifest-codegen.ts +281 -0
  776. package/src/routing/scanner.ts +248 -188
  777. package/src/routing/schema-validation.ts +149 -0
  778. package/src/routing/segment-classify.ts +188 -0
  779. package/src/routing/segment-codegen.ts +98 -0
  780. package/src/routing/types.ts +78 -25
  781. package/src/routing/walkers.ts +90 -0
  782. package/src/rsc-runtime/rsc.ts +9 -0
  783. package/src/rsc-runtime/ssr.ts +50 -0
  784. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  785. package/src/schema-bridge.ts +252 -0
  786. package/src/search-params/define.ts +570 -0
  787. package/src/search-params/index.ts +14 -20
  788. package/src/search-params/registry.ts +2 -2
  789. package/src/search-params/wrappers.ts +110 -0
  790. package/src/segment-params/define.ts +249 -0
  791. package/src/segment-params/index.ts +9 -0
  792. package/src/server/access-gate.tsx +84 -34
  793. package/src/server/action-client.ts +119 -28
  794. package/src/server/action-encryption.ts +144 -0
  795. package/src/server/action-handler.ts +123 -33
  796. package/src/server/actions.ts +39 -54
  797. package/src/server/als-registry.ts +129 -20
  798. package/src/server/asset-headers.ts +15 -37
  799. package/src/server/body-limits.ts +10 -2
  800. package/src/server/build-manifest.ts +13 -56
  801. package/src/server/canonicalize.ts +6 -3
  802. package/src/server/coalesce-tick.ts +75 -0
  803. package/src/server/compress.ts +34 -7
  804. package/src/server/cookie-context.ts +484 -0
  805. package/src/server/cookie-parsing.ts +163 -0
  806. package/src/server/csrf.ts +39 -6
  807. package/src/server/default-logger.ts +99 -0
  808. package/src/server/deny-boundary.ts +311 -0
  809. package/src/server/deny-renderer.ts +85 -77
  810. package/src/server/dev-source-map.ts +31 -0
  811. package/src/server/early-hints-sender.ts +3 -2
  812. package/src/server/early-hints.ts +37 -27
  813. package/src/server/error-boundary-wrapper.ts +61 -22
  814. package/src/server/fallback-error.ts +79 -102
  815. package/src/server/flight-injection-state.ts +113 -0
  816. package/src/server/flight-scripts.ts +62 -0
  817. package/src/server/form-data.ts +124 -12
  818. package/src/server/html-injector-core.ts +437 -0
  819. package/src/server/html-injectors.ts +267 -254
  820. package/src/server/index.ts +29 -183
  821. package/src/server/internal.ts +181 -0
  822. package/src/server/logger.ts +72 -36
  823. package/src/server/metadata-routes.ts +44 -19
  824. package/src/server/middleware-runner.ts +75 -4
  825. package/src/server/node-stream-transforms.ts +331 -0
  826. package/src/server/param-coercion.ts +206 -0
  827. package/src/server/pipeline-helpers.ts +204 -0
  828. package/src/server/pipeline-interception.ts +32 -18
  829. package/src/server/pipeline-metadata.ts +14 -0
  830. package/src/server/pipeline-outcome.ts +197 -0
  831. package/src/server/pipeline-phases.ts +538 -0
  832. package/src/server/pipeline.ts +226 -382
  833. package/src/server/port-resolution.ts +215 -0
  834. package/src/server/prebuilt/cache-key.ts +224 -0
  835. package/src/server/prebuilt/capture-state.ts +89 -0
  836. package/src/server/prebuilt/manifest-tag-index.ts +46 -0
  837. package/src/server/prebuilt/overlay.ts +256 -0
  838. package/src/server/prebuilt/payload-source.ts +201 -0
  839. package/src/server/prebuilt/synthetic-store.ts +121 -0
  840. package/src/server/prebuilt-builder.ts +696 -0
  841. package/src/server/prebuilt-runtime.ts +708 -0
  842. package/src/server/primitives.ts +155 -63
  843. package/src/server/render-timeout.ts +108 -0
  844. package/src/server/render-utils.ts +31 -0
  845. package/src/server/request-context.ts +168 -337
  846. package/src/server/route-element-builder.ts +523 -233
  847. package/src/server/route-handler.ts +31 -4
  848. package/src/server/route-matcher.ts +144 -277
  849. package/src/server/rsc-entry/action-middleware-runner.ts +167 -0
  850. package/src/server/rsc-entry/api-handler.ts +69 -32
  851. package/src/server/rsc-entry/error-renderer.ts +306 -89
  852. package/src/server/rsc-entry/helpers.ts +160 -76
  853. package/src/server/rsc-entry/index.ts +393 -329
  854. package/src/server/rsc-entry/render-route.ts +284 -0
  855. package/src/server/rsc-entry/revalidate-renderer.ts +349 -0
  856. package/src/server/rsc-entry/rsc-payload.ts +72 -33
  857. package/src/server/rsc-entry/rsc-stream.ts +85 -13
  858. package/src/server/rsc-entry/ssr-bridge.ts +18 -5
  859. package/src/server/rsc-entry/ssr-renderer.ts +273 -43
  860. package/src/server/rsc-entry/wrap-action-dispatch.ts +449 -0
  861. package/src/server/safe-load.ts +60 -0
  862. package/src/server/sensitive-fields.ts +230 -0
  863. package/src/server/sitemap-generator.ts +344 -0
  864. package/src/server/sitemap-handler.ts +157 -0
  865. package/src/server/slot-resolver.ts +258 -257
  866. package/src/server/ssr-bridge-types.ts +124 -0
  867. package/src/server/ssr-entry.ts +206 -78
  868. package/src/server/ssr-render.ts +345 -82
  869. package/src/server/ssr-wrappers.tsx +141 -0
  870. package/src/server/state-tree-diff.ts +30 -23
  871. package/src/server/status-code-resolver.ts +115 -130
  872. package/src/server/stream-utils.ts +286 -0
  873. package/src/server/tracing.ts +126 -14
  874. package/src/server/tree-builder.ts +204 -90
  875. package/src/server/tree-match.ts +220 -0
  876. package/src/server/types.ts +78 -9
  877. package/src/server/utils/escape-html.ts +20 -0
  878. package/src/server/utils/mdx-file.ts +22 -0
  879. package/src/server/version-skew.ts +104 -0
  880. package/src/server/workers-cache-bridge.ts +33 -0
  881. package/src/shared/href-validation.ts +159 -0
  882. package/src/shared/merge-search-params.ts +55 -0
  883. package/src/shared/redirect-type.ts +17 -0
  884. package/src/shims/font-google.ts +1 -1
  885. package/src/shims/font-local.ts +34 -0
  886. package/src/shims/headers.ts +122 -1
  887. package/src/shims/navigation-client.ts +51 -29
  888. package/src/shims/navigation.ts +14 -7
  889. package/src/utils/state-machine.ts +111 -0
  890. package/dist/_chunks/als-registry-B7DbZ2hS.js +0 -41
  891. package/dist/_chunks/als-registry-B7DbZ2hS.js.map +0 -1
  892. package/dist/_chunks/debug-B3Gypr3D.js +0 -108
  893. package/dist/_chunks/debug-B3Gypr3D.js.map +0 -1
  894. package/dist/_chunks/format-RyoGQL74.js +0 -164
  895. package/dist/_chunks/format-RyoGQL74.js.map +0 -1
  896. package/dist/_chunks/interception-BOoWmLUA.js +0 -676
  897. package/dist/_chunks/interception-BOoWmLUA.js.map +0 -1
  898. package/dist/_chunks/metadata-routes-Cjmvi3rQ.js.map +0 -1
  899. package/dist/_chunks/request-context-BQUC8PHn.js +0 -330
  900. package/dist/_chunks/request-context-BQUC8PHn.js.map +0 -1
  901. package/dist/_chunks/ssr-data-MjmprTmO.js.map +0 -1
  902. package/dist/_chunks/tracing-CemImE6h.js +0 -187
  903. package/dist/_chunks/tracing-CemImE6h.js.map +0 -1
  904. package/dist/_chunks/use-cookie-DX-l1_5E.js +0 -91
  905. package/dist/_chunks/use-cookie-DX-l1_5E.js.map +0 -1
  906. package/dist/_chunks/use-query-states-D5KaffOK.js.map +0 -1
  907. package/dist/cache/index.js.map +0 -1
  908. package/dist/cache/register-cached-function.d.ts +0 -17
  909. package/dist/cache/register-cached-function.d.ts.map +0 -1
  910. package/dist/client/browser-entry.d.ts +0 -21
  911. package/dist/client/browser-entry.d.ts.map +0 -1
  912. package/dist/client/head.d.ts +0 -16
  913. package/dist/client/head.d.ts.map +0 -1
  914. package/dist/client/link-status-provider.d.ts +0 -11
  915. package/dist/client/link-status-provider.d.ts.map +0 -1
  916. package/dist/client/segment-merger.d.ts +0 -119
  917. package/dist/client/segment-merger.d.ts.map +0 -1
  918. package/dist/client/stale-reload.d.ts +0 -44
  919. package/dist/client/stale-reload.d.ts.map +0 -1
  920. package/dist/client/transition-root.d.ts +0 -74
  921. package/dist/client/transition-root.d.ts.map +0 -1
  922. package/dist/client/use-navigation-pending.d.ts +0 -26
  923. package/dist/client/use-navigation-pending.d.ts.map +0 -1
  924. package/dist/client/use-params.d.ts.map +0 -1
  925. package/dist/plugins/cache-transform.d.ts +0 -36
  926. package/dist/plugins/cache-transform.d.ts.map +0 -1
  927. package/dist/plugins/dev-error-overlay.d.ts +0 -60
  928. package/dist/plugins/dev-error-overlay.d.ts.map +0 -1
  929. package/dist/plugins/dev-logs.d.ts.map +0 -1
  930. package/dist/plugins/dynamic-transform.d.ts +0 -72
  931. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  932. package/dist/plugins/server-action-exports.d.ts +0 -26
  933. package/dist/plugins/server-action-exports.d.ts.map +0 -1
  934. package/dist/routing/status-file-lint.d.ts +0 -33
  935. package/dist/routing/status-file-lint.d.ts.map +0 -1
  936. package/dist/search-params/analyze.d.ts +0 -54
  937. package/dist/search-params/analyze.d.ts.map +0 -1
  938. package/dist/search-params/builtin-codecs.d.ts +0 -105
  939. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  940. package/dist/search-params/codecs.d.ts +0 -53
  941. package/dist/search-params/codecs.d.ts.map +0 -1
  942. package/dist/search-params/create.d.ts +0 -106
  943. package/dist/search-params/create.d.ts.map +0 -1
  944. package/dist/server/client-module-map.d.ts +0 -47
  945. package/dist/server/client-module-map.d.ts.map +0 -1
  946. package/dist/server/dev-fetch-instrumentation.d.ts +0 -22
  947. package/dist/server/dev-fetch-instrumentation.d.ts.map +0 -1
  948. package/dist/server/dev-logger.d.ts.map +0 -1
  949. package/dist/server/dev-span-processor.d.ts +0 -29
  950. package/dist/server/dev-span-processor.d.ts.map +0 -1
  951. package/dist/server/dev-warnings.d.ts +0 -129
  952. package/dist/server/dev-warnings.d.ts.map +0 -1
  953. package/dist/server/flush.d.ts +0 -74
  954. package/dist/server/flush.d.ts.map +0 -1
  955. package/dist/server/manifest-status-resolver.d.ts +0 -58
  956. package/dist/server/manifest-status-resolver.d.ts.map +0 -1
  957. package/dist/server/prerender.d.ts +0 -77
  958. package/dist/server/prerender.d.ts.map +0 -1
  959. package/dist/utils/directive-parser.d.ts +0 -70
  960. package/dist/utils/directive-parser.d.ts.map +0 -1
  961. package/src/cache/register-cached-function.ts +0 -103
  962. package/src/client/browser-entry.ts +0 -678
  963. package/src/client/head.ts +0 -61
  964. package/src/client/link-status-provider.tsx +0 -30
  965. package/src/client/segment-merger.ts +0 -339
  966. package/src/client/stale-reload.ts +0 -87
  967. package/src/client/transition-root.tsx +0 -166
  968. package/src/client/use-navigation-pending.ts +0 -38
  969. package/src/plugins/cache-transform.ts +0 -199
  970. package/src/plugins/dev-error-overlay.ts +0 -230
  971. package/src/plugins/dynamic-transform.ts +0 -161
  972. package/src/plugins/server-action-exports.ts +0 -220
  973. package/src/routing/status-file-lint.ts +0 -112
  974. package/src/search-params/analyze.ts +0 -192
  975. package/src/search-params/builtin-codecs.ts +0 -228
  976. package/src/search-params/codecs.ts +0 -153
  977. package/src/search-params/create.ts +0 -321
  978. package/src/server/client-module-map.ts +0 -58
  979. package/src/server/dev-fetch-instrumentation.ts +0 -96
  980. package/src/server/dev-span-processor.ts +0 -78
  981. package/src/server/dev-warnings.ts +0 -283
  982. package/src/server/flush.ts +0 -182
  983. package/src/server/manifest-status-resolver.ts +0 -215
  984. package/src/server/prerender.ts +0 -139
  985. package/src/utils/directive-parser.ts +0 -529
@@ -0,0 +1,1523 @@
1
+ import { i as assertValidCookieValue, n as assertValidCookieName, r as assertValidCookieOptions, t as require_dist } from "./dist-BA3u1z3W.js";
2
+ import { t as _setGetSearchParamsFn } from "./define-CFmvb4Bt.js";
3
+ import { t as _setGetSegmentParamsFn } from "./define-Bssfp6ot.js";
4
+ import { a as mergePreservedSearchParams, r as validateExternalRedirectUrl, t as assertRelativeRedirectPath } from "./href-validation-CMc5JRls.js";
5
+ import { randomUUID } from "node:crypto";
6
+ import { AsyncLocalStorage } from "node:async_hooks";
7
+ //#region src/server/als-registry.ts
8
+ /**
9
+ * Centralized AsyncLocalStorage registry for server-side per-request state.
10
+ *
11
+ * ALL ALS instances used by the server framework live here. Individual
12
+ * modules (request-context.ts, tracing.ts, actions.ts, etc.) import from
13
+ * this registry and re-export public accessor functions.
14
+ *
15
+ * Why: ALS instances require singleton semantics — if two copies of the
16
+ * same ALS exist (one from a relative import, one from a barrel import,
17
+ * or the same file re-evaluated by Vite after an HMR invalidation), one
18
+ * module writes to its copy and another reads from an empty copy.
19
+ * Centralizing ALS creation in a single module + anchoring each instance
20
+ * on `globalThis` under a `Symbol.for(...)` key eliminates this class of
21
+ * bug, including the Vite-dev case where module instance split would
22
+ * otherwise hand two copies of this file out of a single evaluation cycle.
23
+ *
24
+ * The `timber-shims` plugin remaps `@timber-js/app/server` to src/ in
25
+ * RSC and SSR environments so import-specifier paths converge here, and
26
+ * the `globalThis[SYMBOL_FOR]` anchor below closes the remaining gap: any
27
+ * second evaluation of this module picks up the ALS the first evaluation
28
+ * already stored rather than instantiating a fresh one. Same pattern the
29
+ * Cloudflare bindings ALS uses in `adapters/cloudflare.ts`.
30
+ *
31
+ * DO NOT create ALS instances outside this file. If you need a new ALS,
32
+ * add it here and import from `./als-registry.js` in the consuming module.
33
+ * Inside this file, always route through `getOrCreateAls(symbol)` — a raw
34
+ * `new AsyncLocalStorage()` reintroduces the instance-split hazard.
35
+ *
36
+ * See design/18-build-system.md §"Module Singleton Strategy" and
37
+ * §"Singleton State Registry". Regression test:
38
+ * `tests/als-registry-singleton.test.ts`.
39
+ */
40
+ /**
41
+ * Return a process-wide singleton `AsyncLocalStorage` keyed by `symbol`.
42
+ *
43
+ * `Symbol.for(...)` keys live in the cross-realm symbol registry, and
44
+ * `globalThis` is shared across every module evaluation inside the same
45
+ * Node.js process. Together they give a stable anchor that survives
46
+ * re-evaluation of this file — the second evaluation observes the
47
+ * `globalThis[symbol]` slot already populated by the first and hands
48
+ * back the identical ALS instance.
49
+ */
50
+ function getOrCreateAls(symbol) {
51
+ const g = globalThis;
52
+ const existing = g[symbol];
53
+ if (existing instanceof AsyncLocalStorage) return existing;
54
+ const created = new AsyncLocalStorage();
55
+ g[symbol] = created;
56
+ return created;
57
+ }
58
+ /** @internal — import via request-context.ts public API */
59
+ var requestContextAls = getOrCreateAls(Symbol.for("timber:request-context-als"));
60
+ /** @internal — import via tracing.ts public API */
61
+ var traceAls = getOrCreateAls(Symbol.for("timber:trace-als"));
62
+ /** @internal — import via server-timing.ts public API */
63
+ var timingAls = getOrCreateAls(Symbol.for("timber:timing-als"));
64
+ /** @internal — import via actions.ts public API */
65
+ var revalidationAls = getOrCreateAls(Symbol.for("timber:revalidation-als"));
66
+ /** @internal — import via form-flash.ts public API */
67
+ var formFlashAls = getOrCreateAls(Symbol.for("timber:form-flash-als"));
68
+ /** @internal — import via early-hints-sender.ts public API */
69
+ var earlyHintsSenderAls = getOrCreateAls(Symbol.for("timber:early-hints-sender-als"));
70
+ /** @internal — import via waituntil-bridge.ts public API */
71
+ var waitUntilAls = getOrCreateAls(Symbol.for("timber:wait-until-als"));
72
+ getOrCreateAls(Symbol.for("timber:workers-cache-purge-als"));
73
+ //#endregion
74
+ //#region src/server/tracing.ts
75
+ /**
76
+ * Tracing — per-request trace ID via AsyncLocalStorage, OTEL span helpers.
77
+ *
78
+ * getTraceId() is always available in server code (middleware, access, components, actions).
79
+ * Returns a 32-char lowercase hex string — the OTEL trace ID when an SDK is active,
80
+ * or a crypto.randomUUID()-derived fallback otherwise.
81
+ *
82
+ * See design/17-logging.md §"trace_id is Always Set"
83
+ */
84
+ /**
85
+ * Returns the current request's trace ID — always a 32-char lowercase hex string.
86
+ *
87
+ * With OTEL: the real OTEL trace ID (matches Jaeger/Honeycomb/Datadog).
88
+ * Without OTEL: crypto.randomUUID() with hyphens stripped.
89
+ *
90
+ * Throws if called outside a request context (no ALS store).
91
+ */
92
+ function getTraceId() {
93
+ const store = traceAls.getStore();
94
+ if (!store) throw new Error("[timber] getTraceId() called outside of a request context. It can only be used in middleware, access checks, server components, and server actions.");
95
+ return store.traceId;
96
+ }
97
+ /**
98
+ * Returns the current OTEL span ID if available, undefined otherwise.
99
+ */
100
+ function getSpanId() {
101
+ return traceAls.getStore()?.spanId;
102
+ }
103
+ /**
104
+ * Generate a 32-char lowercase hex ID from crypto.randomUUID().
105
+ * Same format as OTEL trace IDs — zero-friction upgrade path.
106
+ */
107
+ function generateTraceId() {
108
+ return randomUUID().replace(/-/g, "");
109
+ }
110
+ /**
111
+ * Run a callback within a trace context. Used by the pipeline to establish
112
+ * per-request ALS scope.
113
+ */
114
+ function runWithTraceId(id, fn) {
115
+ return traceAls.run({ traceId: id }, fn);
116
+ }
117
+ /**
118
+ * Replace the trace ID in the current ALS store. Used when OTEL creates
119
+ * a root span and we want to switch from the UUID fallback to the real
120
+ * OTEL trace ID.
121
+ */
122
+ function replaceTraceId(newTraceId, newSpanId) {
123
+ const store = traceAls.getStore();
124
+ if (store) {
125
+ store.traceId = newTraceId;
126
+ store.spanId = newSpanId;
127
+ }
128
+ }
129
+ /**
130
+ * Update the span ID in the current ALS store. Used when entering a new
131
+ * OTEL span to keep log–trace correlation accurate.
132
+ */
133
+ function updateSpanId(newSpanId) {
134
+ const store = traceAls.getStore();
135
+ if (store) store.spanId = newSpanId;
136
+ }
137
+ /**
138
+ * Get the current trace store, or undefined if outside a request context.
139
+ * Framework-internal — use getTraceId()/getSpanId() in user code.
140
+ */
141
+ function getTraceStore() {
142
+ return traceAls.getStore();
143
+ }
144
+ var PLATFORM_TRACER_KEY = Symbol.for("timber:platform-tracer");
145
+ /** The registered native platform tracer, if any. */
146
+ function getPlatformTracer() {
147
+ return globalThis[PLATFORM_TRACER_KEY];
148
+ }
149
+ /**
150
+ * Attempt to get the @opentelemetry/api tracer. Returns undefined if the
151
+ * package is not installed or no SDK is registered.
152
+ *
153
+ * timber.js depends on @opentelemetry/api as the vendor-neutral interface.
154
+ * The API is a no-op by default — spans are only emitted when the developer
155
+ * initializes an SDK in register().
156
+ */
157
+ var _otelApi;
158
+ async function getOtelApi() {
159
+ if (_otelApi === void 0) try {
160
+ _otelApi = await import("@opentelemetry/api");
161
+ } catch {
162
+ _otelApi = null;
163
+ }
164
+ return _otelApi;
165
+ }
166
+ /** OTEL tracer instance, lazily created. */
167
+ var _tracer;
168
+ /**
169
+ * Get the timber.js OTEL tracer. Returns null if @opentelemetry/api is not available.
170
+ */
171
+ async function getTracer() {
172
+ if (_tracer === void 0) {
173
+ const api = await getOtelApi();
174
+ if (api) _tracer = api.trace.getTracer("timber.js");
175
+ else _tracer = null;
176
+ }
177
+ return _tracer;
178
+ }
179
+ /**
180
+ * Run a function within a framework span. Composes two emission channels:
181
+ *
182
+ * - **Native platform span** — when an adapter registered a PlatformTracer
183
+ * (Cloudflare Workers), the fn is wrapped in platformTracer.enterSpan()
184
+ * so it appears in the platform's native trace view.
185
+ * - **OTEL span** — when an OTEL SDK is active, the fn also runs inside an
186
+ * OTEL span (dual emission). No SDK and no platform tracer = zero overhead.
187
+ *
188
+ * Automatically:
189
+ * - Creates the span as a child of the current context
190
+ * - Updates the ALS span ID for log–trace correlation
191
+ * - Ends the span when the function completes
192
+ * - Records exceptions on error (OTEL channel)
193
+ */
194
+ async function withSpan(name, attributes, fn) {
195
+ const platformTracer = getPlatformTracer();
196
+ if (!platformTracer) return runOtelSpan(name, attributes, fn);
197
+ return platformTracer.enterSpan(name, async (span) => {
198
+ for (const key of Object.keys(attributes)) span.setAttribute(key, attributes[key]);
199
+ const store = traceAls.getStore();
200
+ const prevPlatformSpan = store?.platformSpan;
201
+ if (store) store.platformSpan = span;
202
+ try {
203
+ return await runOtelSpan(name, attributes, fn);
204
+ } finally {
205
+ if (store) store.platformSpan = prevPlatformSpan;
206
+ }
207
+ });
208
+ }
209
+ /** The OTEL half of withSpan() — no-op passthrough when no SDK is active. */
210
+ async function runOtelSpan(name, attributes, fn) {
211
+ const tracer = await getTracer();
212
+ if (!tracer) return fn();
213
+ const api = await getOtelApi();
214
+ return tracer.startActiveSpan(name, { attributes }, async (span) => {
215
+ const prevSpanId = getSpanId();
216
+ updateSpanId(span.spanContext().spanId);
217
+ try {
218
+ const result = await fn();
219
+ span.setStatus({ code: api.SpanStatusCode.OK });
220
+ return result;
221
+ } catch (error) {
222
+ span.setStatus({ code: api.SpanStatusCode.ERROR });
223
+ if (error instanceof Error) span.recordException(error);
224
+ throw error;
225
+ } finally {
226
+ span.end();
227
+ updateSpanId(prevSpanId);
228
+ }
229
+ });
230
+ }
231
+ /**
232
+ * Set an attribute on the current active span (if any).
233
+ * Used for setting span attributes after span creation (e.g. timber.result on access spans).
234
+ */
235
+ async function setSpanAttribute(key, value) {
236
+ const platformSpan = traceAls.getStore()?.platformSpan;
237
+ if (platformSpan) platformSpan.setAttribute(key, value);
238
+ const api = await getOtelApi();
239
+ if (!api) return;
240
+ const activeSpan = api.trace.getActiveSpan();
241
+ if (activeSpan) activeSpan.setAttribute(key, value);
242
+ }
243
+ /**
244
+ * Add a span event to the current active span (if any).
245
+ * Used for timber.cache HIT/MISS events — recorded as span events, not child spans.
246
+ */
247
+ async function addSpanEvent(name, attributes) {
248
+ const api = await getOtelApi();
249
+ if (!api) return;
250
+ const activeSpan = api.trace.getActiveSpan();
251
+ if (activeSpan) activeSpan.addEvent(name, attributes);
252
+ }
253
+ /**
254
+ * Fire-and-forget span event — no await, no microtask overhead.
255
+ *
256
+ * Used on the cache hot path where awaiting addSpanEvent creates an
257
+ * unnecessary microtask per cache operation. If OTEL is not loaded yet,
258
+ * the event is silently dropped (acceptable for diagnostics).
259
+ *
260
+ * See TIM-370 for perf motivation.
261
+ */
262
+ function addSpanEventSync(name, attributes) {
263
+ if (!_otelApi) return;
264
+ const activeSpan = _otelApi.trace.getActiveSpan();
265
+ if (activeSpan) activeSpan.addEvent(name, attributes);
266
+ }
267
+ /**
268
+ * Try to extract the OTEL trace ID from the current active span context.
269
+ * Returns undefined if OTEL is not active or no span exists.
270
+ */
271
+ async function getOtelTraceId() {
272
+ const api = await getOtelApi();
273
+ if (!api) return void 0;
274
+ const activeSpan = api.trace.getActiveSpan();
275
+ if (!activeSpan) return void 0;
276
+ const ctx = activeSpan.spanContext();
277
+ if (!ctx.traceId || ctx.traceId === "00000000000000000000000000000000") return;
278
+ return {
279
+ traceId: ctx.traceId,
280
+ spanId: ctx.spanId
281
+ };
282
+ }
283
+ //#endregion
284
+ //#region src/server/debug.ts
285
+ /**
286
+ * Runtime debug flag for timber.js.
287
+ *
288
+ * Two distinct functions for two distinct security levels:
289
+ *
290
+ * ## `isDebug()` — server-side logging only
291
+ *
292
+ * Returns true when timber's debug/warning messages should be written to
293
+ * stderr / the server console. This NEVER affects what is sent to the
294
+ * client (no error details, no timing headers, no stack traces).
295
+ *
296
+ * Active when any of:
297
+ * - `NODE_ENV !== 'production'` (standard dev mode)
298
+ * - `TIMBER_DEBUG` env var is set to a truthy value at runtime
299
+ * - `timber.config.ts` has `debug: true`
300
+ *
301
+ * ## `isDevMode()` — client-visible dev behavior
302
+ *
303
+ * Returns true ONLY when `NODE_ENV !== 'production'`. This gates anything
304
+ * that changes what clients can observe:
305
+ * - Dev error pages with stack traces (fallback-error.ts)
306
+ * - Detailed Server-Timing headers (pipeline.ts)
307
+ * - Error messages in action INTERNAL_ERROR payloads (action-client.ts)
308
+ * - Pipeline error handler wiring (Vite overlay)
309
+ *
310
+ * `isDevMode()` is statically replaced in production builds → the guarded
311
+ * code is tree-shaken to zero bytes. TIMBER_DEBUG cannot enable it.
312
+ *
313
+ * Usage:
314
+ * In Cloudflare Workers wrangler.toml:
315
+ * [vars]
316
+ * TIMBER_DEBUG = "1"
317
+ *
318
+ * In Node.js:
319
+ * TIMBER_DEBUG=1 node server.js
320
+ *
321
+ * In timber.config.ts:
322
+ * export default { debug: true }
323
+ *
324
+ * See design/13-security.md for the security taxonomy.
325
+ * See design/18-build-system.md for build pipeline details.
326
+ */
327
+ /**
328
+ * Check if the application is running in development mode.
329
+ *
330
+ * This is the ONLY function that should gate client-visible dev behavior:
331
+ * - Dev error pages with stack traces
332
+ * - Server-Timing mode default (`'detailed'` in dev, `'total'` in prod)
333
+ * - Error messages in action `INTERNAL_ERROR` payloads
334
+ * - Pipeline error handler wiring (Vite overlay)
335
+ *
336
+ * Returns `process.env.NODE_ENV !== 'production'`, which is statically
337
+ * replaced by the bundler in production builds. Code guarded by this
338
+ * function is tree-shaken to zero bytes in production.
339
+ *
340
+ * TIMBER_DEBUG does NOT enable this — that would leak server internals
341
+ * to clients. Use `isDebug()` for server-side-only logging.
342
+ */
343
+ function isDevMode() {
344
+ return process.env.NODE_ENV !== "production";
345
+ }
346
+ /**
347
+ * Config-level debug override. Set via `setDebugFromConfig()` during
348
+ * initialization when timber.config.ts has `debug: true`.
349
+ */
350
+ var _configDebug = false;
351
+ /**
352
+ * Check if timber debug logging is active (server-side only).
353
+ *
354
+ * Returns true if ANY of these conditions hold:
355
+ * - NODE_ENV is not 'production' (standard dev mode)
356
+ * - TIMBER_DEBUG environment variable is set to a truthy value at runtime
357
+ * - timber.config.ts has `debug: true`
358
+ *
359
+ * This function controls ONLY server-side logging — messages written to
360
+ * stderr or the server console. It NEVER affects client-visible behavior
361
+ * (error pages, response headers, action payloads). For client-visible
362
+ * behavior, use `isDevMode()`.
363
+ *
364
+ * The TIMBER_DEBUG check is deliberately written as a dynamic property
365
+ * access so bundlers cannot statically replace it.
366
+ */
367
+ function isDebug() {
368
+ if (process.env.NODE_ENV !== "production") return true;
369
+ if (_configDebug) return true;
370
+ return _readTimberDebugEnv();
371
+ }
372
+ /**
373
+ * Read TIMBER_DEBUG from the environment at runtime.
374
+ *
375
+ * Extracted to a separate function to:
376
+ * 1. Prevent bundler inlining (cross-module function calls are not inlined)
377
+ * 2. Handle platforms where `process` may not exist (Cloudflare Workers)
378
+ * 3. Support globalThis.__TIMBER_DEBUG for programmatic control
379
+ */
380
+ function _readTimberDebugEnv() {
381
+ if (globalThis.__TIMBER_DEBUG) return true;
382
+ try {
383
+ const val = typeof process !== "undefined" && process.env ? process.env["TIMBER_DEBUG"] : void 0;
384
+ if (val && val !== "0" && val !== "false") return true;
385
+ } catch {}
386
+ return false;
387
+ }
388
+ //#endregion
389
+ //#region src/server/error-formatter.ts
390
+ /**
391
+ * Error Formatter — rewrites SSR/RSC error messages to surface user code.
392
+ *
393
+ * When React or Vite throw errors during SSR, stack traces reference
394
+ * vendored dependency paths (e.g. `.vite/deps_ssr/@vitejs_plugin-rsc_vendor_...`)
395
+ * and mangled export names (`__vite_ssr_export_default__`). This module
396
+ * rewrites error messages and stack traces to point at user code instead.
397
+ *
398
+ * Dev-only — in production, errors go through the structured logger
399
+ * without formatting.
400
+ */
401
+ /**
402
+ * Patterns that identify internal Vite/RSC vendor paths in stack traces.
403
+ * These are replaced with human-readable labels.
404
+ */
405
+ var VENDOR_PATH_PATTERNS = [
406
+ {
407
+ pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor_react-server-dom[^\s)]+/g,
408
+ replacement: "<react-server-dom>"
409
+ },
410
+ {
411
+ pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor[^\s)]+/g,
412
+ replacement: "<rsc-vendor>"
413
+ },
414
+ {
415
+ pattern: /node_modules\/\.vite\/deps_ssr\/[^\s)]+/g,
416
+ replacement: "<vite-dep>"
417
+ },
418
+ {
419
+ pattern: /node_modules\/\.vite\/deps\/[^\s)]+/g,
420
+ replacement: "<vite-dep>"
421
+ }
422
+ ];
423
+ /**
424
+ * Patterns that identify Vite-mangled export names in error messages.
425
+ */
426
+ var MANGLED_NAME_PATTERNS = [{
427
+ pattern: /__vite_ssr_export_default__/g,
428
+ replacement: "<default export>"
429
+ }, {
430
+ pattern: /__vite_ssr_export_(\w+)__/g,
431
+ replacement: "<export $1>"
432
+ }];
433
+ /**
434
+ * Rewrite an error's message and stack to replace internal Vite paths
435
+ * and mangled names with human-readable labels.
436
+ */
437
+ function formatSsrError(error) {
438
+ if (!(error instanceof Error)) return String(error);
439
+ let message = error.message;
440
+ let stack = error.stack ?? "";
441
+ for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) message = message.replace(pattern, replacement);
442
+ for (const { pattern, replacement } of VENDOR_PATH_PATTERNS) stack = stack.replace(pattern, replacement);
443
+ for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) stack = stack.replace(pattern, replacement);
444
+ const hint = extractErrorHint(error.message);
445
+ const parts = [];
446
+ parts.push(message);
447
+ if (hint) parts.push(` → ${hint}`);
448
+ const userFrames = extractUserFrames(stack);
449
+ if (userFrames.length > 0) {
450
+ parts.push("");
451
+ parts.push(" User code in stack:");
452
+ for (const frame of userFrames) parts.push(` ${frame}`);
453
+ }
454
+ return parts.join("\n");
455
+ }
456
+ /**
457
+ * Extract a human-readable hint from common React/RSC error messages.
458
+ *
459
+ * React error messages contain useful information but the surrounding
460
+ * context (vendor paths, mangled names) obscures it. This extracts the
461
+ * actionable part as a one-line hint.
462
+ */
463
+ function extractErrorHint(message) {
464
+ if (message.match(/Functions cannot be passed directly to Client Components/)) {
465
+ const propMatch = message.match(/<[^>]*?\s(\w+)=\{function/);
466
+ if (propMatch) return `Prop "${propMatch[1]}" is a function — mark it "use server" or call it before passing`;
467
+ return "A function prop was passed to a Client Component — mark it \"use server\" or call it before passing";
468
+ }
469
+ 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";
470
+ const nullRefMatch = message.match(/Cannot read propert(?:y|ies) of (undefined|null) \(reading '(\w+)'\)/);
471
+ if (nullRefMatch) return `Accessed .${nullRefMatch[2]} on ${nullRefMatch[1]} — check that the value exists`;
472
+ const notFnMatch = message.match(/(\w+) is not a function/);
473
+ if (notFnMatch) return `"${notFnMatch[1]}" is not a function — check imports and exports`;
474
+ if (message.includes("Element type is invalid")) return "A component resolved to undefined/null — check default exports and import paths";
475
+ 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.";
476
+ return null;
477
+ }
478
+ /**
479
+ * Extract stack frames that reference user code (not node_modules,
480
+ * not framework internals).
481
+ *
482
+ * Returns at most 5 frames to keep output concise.
483
+ */
484
+ function extractUserFrames(stack) {
485
+ const lines = stack.split("\n");
486
+ const userFrames = [];
487
+ for (const line of lines) {
488
+ const trimmed = line.trim();
489
+ if (!trimmed.startsWith("at ")) continue;
490
+ if (trimmed.includes("node_modules") || trimmed.includes("<react-server-dom>") || trimmed.includes("<rsc-vendor>") || trimmed.includes("<vite-dep>") || trimmed.includes("node:internal")) continue;
491
+ userFrames.push(trimmed);
492
+ if (userFrames.length >= 5) break;
493
+ }
494
+ return userFrames;
495
+ }
496
+ //#endregion
497
+ //#region src/server/default-logger.ts
498
+ /**
499
+ * DefaultLogger — human-readable stderr logging when no custom logger is configured.
500
+ *
501
+ * Ships as the fallback so production deployments always have error visibility,
502
+ * even without an `instrumentation.ts` logger export. Output is one line per
503
+ * event, designed for `fly logs`, `kubectl logs`, Cloudflare dashboard tails, etc.
504
+ *
505
+ * Format:
506
+ * [timber] ERROR message key=value key=value trace_id=4bf92f35
507
+ * [timber] WARN message key=value key=value trace_id=4bf92f35
508
+ * [timber] INFO message method=GET path=/dashboard status=200 durationMs=43 trace_id=4bf92f35
509
+ *
510
+ * Behavior:
511
+ * - Suppressed entirely in dev mode (dev logging handles all output)
512
+ * - `debug` suppressed unless TIMBER_DEBUG is set
513
+ * - Replaced entirely when a custom logger is set via `setLogger()`
514
+ *
515
+ * See design/17-logging.md §"DefaultLogger"
516
+ */
517
+ /**
518
+ * Format data fields as `key=value` pairs for human-readable output.
519
+ * - `error` key is serialized via formatSsrError for stack trace cleanup
520
+ * - `trace_id` is truncated to 8 chars for readability (full ID in OTEL)
521
+ * - Other values are stringified inline
522
+ */
523
+ function formatDataFields(data) {
524
+ if (!data) return "";
525
+ const parts = [];
526
+ let traceId;
527
+ for (const [key, value] of Object.entries(data)) {
528
+ if (key === "trace_id") {
529
+ traceId = typeof value === "string" ? value : String(value);
530
+ continue;
531
+ }
532
+ if (key === "error") {
533
+ parts.push(`error=${formatSsrError(value)}`);
534
+ continue;
535
+ }
536
+ if (value === void 0 || value === null) continue;
537
+ parts.push(`${key}=${value}`);
538
+ }
539
+ if (traceId) parts.push(`trace_id=${traceId.slice(0, 8)}`);
540
+ return parts.length > 0 ? " " + parts.join(" ") : "";
541
+ }
542
+ /** Pad level string to fixed width for alignment. */
543
+ function padLevel(level) {
544
+ return level.padEnd(5);
545
+ }
546
+ function createDefaultLogger() {
547
+ return {
548
+ error(msg, data) {
549
+ const fields = formatDataFields(data);
550
+ process.stderr.write(`[timber] ${padLevel("ERROR")} ${msg}${fields}\n`);
551
+ },
552
+ warn(msg, data) {
553
+ const fields = formatDataFields(data);
554
+ process.stderr.write(`[timber] ${padLevel("WARN")} ${msg}${fields}\n`);
555
+ },
556
+ info(msg, data) {
557
+ if (isDevMode()) return;
558
+ if (!isDebug()) return;
559
+ const fields = formatDataFields(data);
560
+ process.stderr.write(`[timber] ${padLevel("INFO")} ${msg}${fields}\n`);
561
+ },
562
+ debug(msg, data) {
563
+ if (isDevMode()) return;
564
+ if (!isDebug()) return;
565
+ const fields = formatDataFields(data);
566
+ process.stderr.write(`[timber] ${padLevel("DEBUG")} ${msg}${fields}\n`);
567
+ }
568
+ };
569
+ }
570
+ //#endregion
571
+ //#region src/server/waituntil-bridge.ts
572
+ /**
573
+ * Per-request waitUntil bridge — ALS bridge for platform adapters.
574
+ *
575
+ * The generated entry point (Nitro, Cloudflare) wraps the handler with
576
+ * `runWithWaitUntil`, binding the platform's lifecycle extension function
577
+ * (e.g., h3's `event.waitUntil()` or CF's `ctx.waitUntil()`) for the
578
+ * request duration. The `waitUntil()` primitive reads from this ALS to
579
+ * dispatch background work to the correct platform API.
580
+ *
581
+ * Design doc: design/11-platform.md §"waitUntil()"
582
+ */
583
+ /**
584
+ * Get the current request's waitUntil function, if available.
585
+ *
586
+ * Returns undefined when no platform adapter has installed a waitUntil
587
+ * handler for the current request (e.g., on platforms that don't support
588
+ * lifecycle extension, or outside a request context).
589
+ */
590
+ function getWaitUntil() {
591
+ return waitUntilAls.getStore();
592
+ }
593
+ //#endregion
594
+ //#region src/server/cookie-parsing.ts
595
+ var import_dist = require_dist();
596
+ /**
597
+ * Parse a Cookie header string into a Map of name → value pairs.
598
+ * Follows RFC 6265 §4.2.1: cookies are semicolon-separated key=value pairs.
599
+ *
600
+ * Values are auto-decoded with `decodeURIComponent` so they round-trip
601
+ * losslessly with `getCookies().set()` (which auto-encodes). Malformed
602
+ * `%`-escapes from third-party cookies fall back to the raw byte sequence
603
+ * — the parser must be total over arbitrary inbound headers, including
604
+ * non-conforming values from other servers, browser extensions, etc.
605
+ */
606
+ function parseCookieHeader(header) {
607
+ const map = /* @__PURE__ */ new Map();
608
+ if (!header) return map;
609
+ const parsed = (0, import_dist.parseCookie)(header);
610
+ for (const name in parsed) {
611
+ const value = parsed[name];
612
+ if (value !== void 0) map.set(name, value);
613
+ }
614
+ return map;
615
+ }
616
+ /**
617
+ * Decode a single cookie value with `decodeURIComponent`, falling back to
618
+ * the raw byte sequence if the input contains a malformed `%`-escape.
619
+ *
620
+ * Used by both `parseCookieHeader` (incoming Cookie: header) and the
621
+ * `setRaw` forwarding path (outgoing Set-Cookie from upstream services).
622
+ * Total — never throws.
623
+ *
624
+ * cookie's internal decode has identical semantics but is not exported,
625
+ * so we keep this standalone helper.
626
+ */
627
+ function safeDecodeCookieValue(raw) {
628
+ try {
629
+ return decodeURIComponent(raw);
630
+ } catch {
631
+ return raw;
632
+ }
633
+ }
634
+ /**
635
+ * Serialize a CookieEntry into a Set-Cookie header value.
636
+ *
637
+ * Total — never throws. If the cookie package's serializer rejects
638
+ * the input (e.g. non-integer maxAge, forbidden chars in name/value),
639
+ * falls back to a minimal hand-rolled serialization so the response
640
+ * path is never interrupted by a codec error.
641
+ */
642
+ function serializeCookieEntry(entry) {
643
+ try {
644
+ return (0, import_dist.stringifySetCookie)({
645
+ name: entry.name,
646
+ value: entry.value,
647
+ domain: entry.options.domain,
648
+ path: entry.options.path,
649
+ expires: entry.options.expires,
650
+ maxAge: entry.options.maxAge,
651
+ httpOnly: entry.options.httpOnly,
652
+ secure: entry.options.secure,
653
+ sameSite: entry.options.sameSite,
654
+ partitioned: entry.options.partitioned
655
+ }, { encode: (v) => v });
656
+ } catch {
657
+ return serializeCookieEntryFallback(entry);
658
+ }
659
+ }
660
+ function serializeCookieEntryFallback(entry) {
661
+ const parts = [`${entry.name}=${entry.value}`];
662
+ const opts = entry.options;
663
+ if (opts.domain) parts.push(`Domain=${opts.domain}`);
664
+ if (opts.path) parts.push(`Path=${opts.path}`);
665
+ if (opts.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);
666
+ if (opts.maxAge !== void 0) parts.push(`Max-Age=${opts.maxAge}`);
667
+ if (opts.httpOnly) parts.push("HttpOnly");
668
+ if (opts.secure) parts.push("Secure");
669
+ if (opts.sameSite) parts.push(`SameSite=${opts.sameSite.charAt(0).toUpperCase()}${opts.sameSite.slice(1)}`);
670
+ if (opts.partitioned) parts.push("Partitioned");
671
+ return parts.join("; ");
672
+ }
673
+ /**
674
+ * Parse a raw `Set-Cookie` header string into name, value, and options.
675
+ * Handles all standard attributes: Path, Domain, Max-Age, Expires,
676
+ * SameSite, Secure, HttpOnly, Partitioned.
677
+ *
678
+ * Does NOT apply DEFAULT_COOKIE_OPTIONS — the caller decides whether
679
+ * to merge defaults (e.g. `set()` does, but `setRaw()` should preserve
680
+ * the original header's intent).
681
+ */
682
+ function parseSetCookie(header) {
683
+ const parsed = (0, import_dist.parseSetCookie)(header, { decode: (v) => v });
684
+ if (!parsed.name) return null;
685
+ const options = {};
686
+ if (parsed.path !== void 0) options.path = parsed.path || "/";
687
+ if (parsed.domain !== void 0) options.domain = parsed.domain;
688
+ if (parsed.maxAge !== void 0 && Number.isFinite(parsed.maxAge)) options.maxAge = parsed.maxAge;
689
+ if (parsed.expires !== void 0) options.expires = parsed.expires;
690
+ if (parsed.sameSite !== void 0 && parsed.sameSite !== true) {
691
+ const sameSite = parsed.sameSite.toLowerCase();
692
+ if (sameSite === "strict" || sameSite === "lax" || sameSite === "none") options.sameSite = sameSite;
693
+ }
694
+ if (parsed.secure) options.secure = true;
695
+ if (parsed.httpOnly) options.httpOnly = true;
696
+ if (parsed.partitioned) options.partitioned = true;
697
+ return {
698
+ name: parsed.name,
699
+ value: parsed.value ?? "",
700
+ options
701
+ };
702
+ }
703
+ //#endregion
704
+ //#region src/server/cookie-context.ts
705
+ /**
706
+ * Cookie Context — per-request cookie API and on-the-wire helpers.
707
+ *
708
+ * Split out of `request-context.ts` (TIM-853) so the cookie subsystem
709
+ * — encoding contract, options grammar, parser, serializer, RYW map,
710
+ * and rerender seed — lives in one file. The headers/scope/params APIs
711
+ * stay in `request-context.ts` and call into this module via the
712
+ * exported helpers.
713
+ *
714
+ * See design/29-cookies.md for the encoding contract and read-your-own-
715
+ * writes semantics. See ONGOING_SECURITY.md H-3 (TIM-868) for the
716
+ * smuggling primitive that the encoding contract closes.
717
+ */
718
+ /**
719
+ * Returns a cookie accessor for the current request.
720
+ *
721
+ * Available in middleware, access checks, server components, and server actions.
722
+ * Throws if called outside a request context (security principle #2: no global fallback).
723
+ *
724
+ * Read methods (.get, .has, .getAll) are always available and reflect
725
+ * read-your-own-writes from .set() calls in the same request.
726
+ *
727
+ * Mutation methods (.set, .delete, .clear) are only available in mutable
728
+ * contexts (middleware.ts, server actions, route.ts handlers). Calling them
729
+ * in read-only contexts (access.ts, server components) throws.
730
+ *
731
+ * This is the escape hatch for direct cookie jar operations. For typed
732
+ * cookie access, use `defineCookie()` instead.
733
+ *
734
+ * See design/29-cookies.md
735
+ */
736
+ function getCookieJar() {
737
+ const store = requestContextAls.getStore();
738
+ if (!store) throw new Error("[timber] getCookieJar() called outside of a request context. It can only be used in middleware, access checks, server components, and server actions.");
739
+ if (!store.parsedCookies) store.parsedCookies = parseCookieHeader(store.cookieHeader);
740
+ const map = store.parsedCookies;
741
+ return {
742
+ get(name) {
743
+ return map.get(name);
744
+ },
745
+ has(name) {
746
+ return map.has(name);
747
+ },
748
+ getAll() {
749
+ return Array.from(map.entries()).map(([name, value]) => ({
750
+ name,
751
+ value
752
+ }));
753
+ },
754
+ get size() {
755
+ return map.size;
756
+ },
757
+ set(name, value, options) {
758
+ assertMutable(store, "set");
759
+ assertValidCookieName(name);
760
+ if (typeof value !== "string") throw new Error(`[timber] getCookieJar().set(${JSON.stringify(name)}, …): value must be a string, got ${typeof value}.\n To store a JSON-serializable value, use defineCookie + jsonCookieCodec:\n\n import { defineCookie, jsonCookieCodec } from '@timber-js/app/cookies';\n\n export const ${name}Cookie = defineCookie(${JSON.stringify(name)}, {\n codec: jsonCookieCodec(),\n });\n\n ${name}Cookie.set(value);\n\n See design/29-cookies.md §"Typed Cookies with Schema Validation".`);
761
+ const raw = options?.raw === true;
762
+ const wireValue = raw ? value : encodeURIComponent(value);
763
+ if (raw) assertValidCookieValue(name, wireValue);
764
+ if (store.flushed) {
765
+ if (isDebug()) console.warn(`[timber] warn: getCookieJar().set('${name}') called after response headers were committed.\n The cookie will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n or a route.ts handler.`);
766
+ return;
767
+ }
768
+ const { raw: _raw, ...attributeOptions } = options ?? {};
769
+ const opts = {
770
+ ...DEFAULT_COOKIE_OPTIONS,
771
+ ...attributeOptions
772
+ };
773
+ assertValidCookieOptions(opts);
774
+ store.cookieJar.set(name, {
775
+ name,
776
+ value: wireValue,
777
+ options: opts
778
+ });
779
+ map.set(name, raw ? wireValue : value);
780
+ },
781
+ setFromHeaders(headers) {
782
+ assertMutable(store, "setFromHeaders");
783
+ if (store.flushed) {
784
+ console.warn("[timber] warn: getCookieJar().setFromHeaders() called after response headers were committed.\n The cookies will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n or a route.ts handler.");
785
+ return;
786
+ }
787
+ for (const raw of headers.getSetCookie()) {
788
+ const parsed = parseSetCookie(raw);
789
+ if (parsed) setRaw(store, map, parsed.name, parsed.value, parsed.options);
790
+ }
791
+ },
792
+ delete(name, options) {
793
+ assertMutable(store, "delete");
794
+ assertValidCookieName(name);
795
+ if (store.flushed) {
796
+ if (isDebug()) console.warn(`[timber] warn: getCookieJar().delete('${name}') called after response headers were committed.\n The cookie will NOT be deleted. Move cookie mutations to middleware.ts, a server action,\n or a route.ts handler.`);
797
+ return;
798
+ }
799
+ const opts = {
800
+ ...DEFAULT_COOKIE_OPTIONS,
801
+ ...options,
802
+ maxAge: 0,
803
+ expires: /* @__PURE__ */ new Date(0)
804
+ };
805
+ assertValidCookieOptions(opts);
806
+ store.cookieJar.set(name, {
807
+ name,
808
+ value: "",
809
+ options: opts
810
+ });
811
+ map.delete(name);
812
+ },
813
+ clear() {
814
+ assertMutable(store, "clear");
815
+ if (store.flushed) return;
816
+ for (const name of Array.from(map.keys())) store.cookieJar.set(name, {
817
+ name,
818
+ value: "",
819
+ options: {
820
+ ...DEFAULT_COOKIE_OPTIONS,
821
+ maxAge: 0,
822
+ expires: /* @__PURE__ */ new Date(0)
823
+ }
824
+ });
825
+ map.clear();
826
+ },
827
+ toString() {
828
+ return Array.from(map.entries()).map(([name, value]) => `${name}=${encodeURIComponent(value)}`).join("; ");
829
+ }
830
+ };
831
+ }
832
+ /**
833
+ * Returns the value of a single cookie, or undefined if absent.
834
+ *
835
+ * @internal — not part of the public API. Use `defineCookie().get()` or `getCookieJar().get()` instead.
836
+ */
837
+ function getCookie(name) {
838
+ return getCookieJar().get(name);
839
+ }
840
+ var DEFAULT_COOKIE_OPTIONS = {
841
+ path: "/",
842
+ httpOnly: true,
843
+ secure: true,
844
+ sameSite: "lax"
845
+ };
846
+ /**
847
+ * Per-request seed map of cookie name → value, registered out-of-band so the
848
+ * pipeline's `runWithRequestContext` call can pick it up without changing
849
+ * the function's calling convention. Stored in a WeakMap keyed by the
850
+ * synthetic Request object built for the rerender path, so the seed lives
851
+ * exactly as long as the request and is collected with it.
852
+ *
853
+ * The seed exists to eliminate the parse/serialize round-trip on the no-JS
854
+ * form-rerender path — see ONGOING_SECURITY.md H-3 (TIM-868). The action's
855
+ * post-mutation RYW snapshot is threaded directly into the rerender scope's
856
+ * `parsedCookies` map, bypassing `parseCookieHeader` entirely.
857
+ */
858
+ var seededRequestCookies = /* @__PURE__ */ new WeakMap();
859
+ /**
860
+ * Pop the seed (if any) for `req` and return it. Called from
861
+ * `runWithRequestContext` exactly once per request — the seed is consumed
862
+ * eagerly so it cannot leak into a hypothetical future re-use of the same
863
+ * Request reference.
864
+ *
865
+ * @internal — framework use only.
866
+ */
867
+ function consumeSeededCookies(req) {
868
+ const seed = seededRequestCookies.get(req);
869
+ if (seed) seededRequestCookies.delete(req);
870
+ return seed;
871
+ }
872
+ /**
873
+ * Collect all Set-Cookie headers from the cookie jar.
874
+ * Called by the framework at flush time to apply cookies to the response.
875
+ *
876
+ * Returns an array of serialized Set-Cookie header values.
877
+ */
878
+ function getSetCookieHeaders() {
879
+ const store = requestContextAls.getStore();
880
+ if (!store) return [];
881
+ return Array.from(store.cookieJar.values()).map(serializeCookieEntry);
882
+ }
883
+ /** Throw if cookie mutation is attempted in a read-only context. */
884
+ function assertMutable(store, method) {
885
+ if (!store.mutableContext) throw new Error(`[timber] getCookieJar().${method}() cannot be called in this context.\n Set cookies in middleware.ts, server actions, or route.ts handlers.`);
886
+ }
887
+ /**
888
+ * Write a cookie to the jar WITHOUT merging DEFAULT_COOKIE_OPTIONS.
889
+ * Used by setFromHeaders to preserve the original header's attributes exactly.
890
+ *
891
+ * For deletion cookies (maxAge=0), the jar entry is still created so the
892
+ * Set-Cookie header is emitted, but the cookie is NOT added to the read map
893
+ * (it would be misleading — the cookie is being deleted).
894
+ */
895
+ function setRaw(store, readMap, name, value, options) {
896
+ assertValidCookieName(name);
897
+ assertValidCookieValue(name, value);
898
+ assertValidCookieOptions(options);
899
+ store.cookieJar.set(name, {
900
+ name,
901
+ value,
902
+ options
903
+ });
904
+ if (options.maxAge === 0) readMap.delete(name);
905
+ else readMap.set(name, safeDecodeCookieValue(value));
906
+ }
907
+ //#endregion
908
+ //#region src/server/request-context.ts
909
+ /**
910
+ * Request Context — per-request ALS store for headers, search params,
911
+ * segment params, and request scope lifecycle.
912
+ *
913
+ * Follows the same pattern as tracing.ts: a module-level AsyncLocalStorage
914
+ * instance, public accessor functions that throw outside request scope,
915
+ * and a framework-internal `runWithRequestContext()` to establish scope.
916
+ *
917
+ * Cookie state lives in `cookie-context.ts` (split out in TIM-853). The
918
+ * scope set up here owns the cookie jar / parsedCookies fields on the
919
+ * store, but the cookie API and helpers are in the cookie module.
920
+ *
921
+ * See design/04-authorization.md §"AccessContext does not include cookies or headers"
922
+ * and design/11-platform.md §"AsyncLocalStorage".
923
+ */
924
+ /**
925
+ * Returns a read-only view of the current request's headers.
926
+ *
927
+ * Available in middleware, access checks, server components, and server actions.
928
+ * Throws if called outside a request context (security principle #2: no global fallback).
929
+ */
930
+ function getHeaders() {
931
+ const store = requestContextAls.getStore();
932
+ if (!store) throw new Error("[timber] getHeaders() called outside of a request context. It can only be used in middleware, access checks, server components, and server actions.");
933
+ return store.headers;
934
+ }
935
+ /**
936
+ * Returns the value of a single request header, or undefined if absent.
937
+ *
938
+ * Thin wrapper over `getHeaders().get(name)` for the common case where
939
+ * you need exactly one header.
940
+ *
941
+ * @internal — not part of the public API. Use `getHeaders().get(name)` instead.
942
+ */
943
+ function getHeader(name) {
944
+ return getHeaders().get(name) ?? void 0;
945
+ }
946
+ /**
947
+ * Returns the current request's raw URLSearchParams.
948
+ *
949
+ * @internal — not part of the public API. Use `defineSearchParams().get()` instead.
950
+ */
951
+ function getSearchParams() {
952
+ const store = requestContextAls.getStore();
953
+ if (!store) throw new Error("[timber] getSearchParams() called outside of a request context. It can only be used in middleware, access checks, server components, and server actions.");
954
+ return store.searchParams;
955
+ }
956
+ _setGetSearchParamsFn(getSearchParams);
957
+ _setGetSegmentParamsFn(getSegmentParams);
958
+ /**
959
+ * Returns the current request's coerced segment params.
960
+ *
961
+ * The optional `segmentPath` argument exists only for TypeScript narrowing —
962
+ * it does not affect the runtime return value. Pass a segment path
963
+ * (e.g. `'/(browse)/[artistSlug]/[year]'`) to narrow the return type to the
964
+ * exact params shape for that segment.
965
+ *
966
+ * Without an argument, returns all coerced params with optional types.
967
+ *
968
+ * See design/41-global-params.md §Function Signatures
969
+ */
970
+ function getSegmentParams(segmentPath) {
971
+ const store = requestContextAls.getStore();
972
+ if (!store) throw new Error("[timber] getSegmentParams() called outside of a request context. It can only be used in middleware, access checks, server components, and server actions.");
973
+ if (!store.segmentParams) throw new Error("[timber] getSegmentParams() called before route matching completed. Segment params are not available until after the route is matched.");
974
+ if (segmentPath && store.slotParamsMap?.has(segmentPath)) {
975
+ const slotParams = store.slotParamsMap.get(segmentPath);
976
+ return {
977
+ ...store.segmentParams,
978
+ ...slotParams
979
+ };
980
+ }
981
+ if (segmentPath && isDebug() && store.matchedSegmentPath) {
982
+ const expected = extractDynamicSegments(segmentPath);
983
+ const actual = extractDynamicSegments(store.matchedSegmentPath);
984
+ const missing = expected.filter((s) => !actual.includes(s));
985
+ if (missing.length > 0) console.warn(`[timber] getSegmentParams('${segmentPath}') called but current segment is '${store.matchedSegmentPath}'\n Missing params: ${missing.join(", ")}\n These will be undefined at runtime despite the type annotation.`);
986
+ }
987
+ return store.segmentParams;
988
+ }
989
+ /**
990
+ * Set the segment params on the current request context.
991
+ * Called by the pipeline after route matching and param coercion.
992
+ *
993
+ * @internal — framework use only
994
+ */
995
+ function setSegmentParams(params) {
996
+ const store = requestContextAls.getStore();
997
+ if (!store) throw new Error("[timber] setSegmentParams() called outside of a request context.");
998
+ store.segmentParams = params;
999
+ }
1000
+ /**
1001
+ * Store the matched segment path (e.g. '/(browse)/[artistSlug]/[year]') for
1002
+ * dev-mode validation in getSegmentParams().
1003
+ *
1004
+ * @internal — framework use only
1005
+ */
1006
+ function setMatchedSegmentPath(segmentPath) {
1007
+ const store = requestContextAls.getStore();
1008
+ if (!store) return;
1009
+ store.matchedSegmentPath = segmentPath;
1010
+ }
1011
+ /**
1012
+ * Extract dynamic segment names from a route pattern.
1013
+ * '/[artistSlug]/[year]' → ['artistSlug', 'year']
1014
+ * '/docs/[...slug]' → ['slug']
1015
+ */
1016
+ function extractDynamicSegments(route) {
1017
+ const segments = [];
1018
+ const re = /\[{1,2}\.{0,3}(\w+)\]{1,2}/g;
1019
+ let m;
1020
+ while ((m = re.exec(route)) !== null) segments.push(m[1]);
1021
+ return segments;
1022
+ }
1023
+ /**
1024
+ * Returns the raw search string from the current request URL (e.g. "?foo=bar").
1025
+ * Synchronous — safe for use in `redirect()` which throws synchronously.
1026
+ *
1027
+ * Returns empty string if called outside a request context (non-throwing for
1028
+ * use in redirect's optional preserveSearchParams path).
1029
+ *
1030
+ * @internal — used by redirect() for preserveSearchParams support.
1031
+ */
1032
+ function getRequestSearchString() {
1033
+ return requestContextAls.getStore()?.searchString ?? "";
1034
+ }
1035
+ /**
1036
+ * Run a callback within a request context. Used by the pipeline to establish
1037
+ * per-request ALS scope so that `getHeaders()` and `getCookies()` work.
1038
+ *
1039
+ * If the request was previously registered via `seedRequestCookies`, the
1040
+ * resulting context's `parsedCookies` map is initialized from the seed and
1041
+ * the raw `cookieHeader` is left empty — `parseCookieHeader` is never called
1042
+ * for that request. This is the no-JS form-rerender path. See TIM-868.
1043
+ *
1044
+ * @param req - The incoming Request object.
1045
+ * @param fn - The function to run within the request context.
1046
+ */
1047
+ function runWithRequestContext(req, fn) {
1048
+ const originalCopy = new Headers(req.headers);
1049
+ const parsedUrl = new URL(req.url);
1050
+ const seed = consumeSeededCookies(req);
1051
+ const store = {
1052
+ headers: freezeHeaders(req.headers),
1053
+ originalHeaders: originalCopy,
1054
+ cookieHeader: seed ? "" : req.headers.get("cookie") ?? "",
1055
+ parsedCookies: seed,
1056
+ searchParams: parsedUrl.searchParams,
1057
+ searchString: parsedUrl.search,
1058
+ cookieJar: /* @__PURE__ */ new Map(),
1059
+ flushed: false,
1060
+ mutableContext: false
1061
+ };
1062
+ return requestContextAls.run(store, fn);
1063
+ }
1064
+ /**
1065
+ * Enable cookie mutation for the current context. Called by the framework
1066
+ * when entering middleware.ts, server actions, or route.ts handlers.
1067
+ *
1068
+ * See design/29-cookies.md §"Context Tracking"
1069
+ */
1070
+ function setMutableCookieContext(mutable) {
1071
+ const store = requestContextAls.getStore();
1072
+ if (store) store.mutableContext = mutable;
1073
+ }
1074
+ /**
1075
+ * Mark the response as flushed (headers committed). After this point,
1076
+ * cookie mutations log a warning instead of throwing.
1077
+ *
1078
+ * See design/29-cookies.md §"Streaming Constraint: Post-Flush Cookie Warning"
1079
+ */
1080
+ function markResponseFlushed() {
1081
+ const store = requestContextAls.getStore();
1082
+ if (store) store.flushed = true;
1083
+ }
1084
+ /**
1085
+ * Apply middleware-injected request headers to the current request context.
1086
+ *
1087
+ * Called by the pipeline after middleware.ts runs. Merges overlay headers
1088
+ * on top of the original request headers so downstream code (access.ts,
1089
+ * server components, server actions) sees them via `getHeaders()`.
1090
+ *
1091
+ * The original request headers are never mutated — a new frozen Headers
1092
+ * object is created with the overlay applied on top.
1093
+ *
1094
+ * See design/07-routing.md §"Request Header Injection"
1095
+ */
1096
+ function applyRequestHeaderOverlay(overlay) {
1097
+ const store = requestContextAls.getStore();
1098
+ if (!store) throw new Error("[timber] applyRequestHeaderOverlay() called outside of a request context.");
1099
+ let hasOverlay = false;
1100
+ overlay.forEach(() => {
1101
+ hasOverlay = true;
1102
+ });
1103
+ if (!hasOverlay) return;
1104
+ const merged = new Headers(store.originalHeaders);
1105
+ overlay.forEach((value, key) => {
1106
+ merged.set(key, value);
1107
+ });
1108
+ store.headers = freezeHeaders(merged);
1109
+ }
1110
+ var MUTATING_METHODS = /* @__PURE__ */ new Set([
1111
+ "set",
1112
+ "append",
1113
+ "delete"
1114
+ ]);
1115
+ /**
1116
+ * Wrap a Headers object in a Proxy that throws on mutating methods.
1117
+ * Object.freeze doesn't work on Headers (native internal slots), so we
1118
+ * intercept property access and reject set/append/delete at runtime.
1119
+ *
1120
+ * Read methods (get, has, entries, etc.) must be bound to the underlying
1121
+ * Headers instance because they access private #headersList slots.
1122
+ */
1123
+ function freezeHeaders(source) {
1124
+ const copy = new Headers(source);
1125
+ return new Proxy(copy, { get(target, prop) {
1126
+ if (typeof prop === "string" && MUTATING_METHODS.has(prop)) return () => {
1127
+ throw new Error(`[timber] getHeaders() returns a read-only Headers object. Calling .${prop}() is not allowed. Use ctx.requestHeaders in middleware to inject headers for downstream components.`);
1128
+ };
1129
+ const value = Reflect.get(target, prop);
1130
+ if (typeof value === "function") return value.bind(target);
1131
+ return value;
1132
+ } });
1133
+ }
1134
+ //#endregion
1135
+ //#region src/shared/redirect-type.ts
1136
+ /**
1137
+ * Next.js redirect type discriminator.
1138
+ *
1139
+ * Provided for API compatibility with libraries that import `RedirectType`
1140
+ * from `next/navigation`. In timber, `redirect()` always uses `replace`
1141
+ * semantics (no history entry for the redirect itself).
1142
+ *
1143
+ * Lives in shared/ (isomorphic) so both the server primitives and the
1144
+ * client-only next/navigation shim export the same definition without the
1145
+ * client shim pulling in server code.
1146
+ */
1147
+ var RedirectType = {
1148
+ push: "push",
1149
+ replace: "replace"
1150
+ };
1151
+ //#endregion
1152
+ //#region src/server/primitives.ts
1153
+ /**
1154
+ * Check if a value is JSON-serializable without data loss.
1155
+ * Returns a description of the first non-serializable value found, or null if OK.
1156
+ *
1157
+ * @internal Exported for testing only.
1158
+ */
1159
+ function findNonSerializable(value, path = "data") {
1160
+ if (value === null || value === void 0) return null;
1161
+ switch (typeof value) {
1162
+ case "string":
1163
+ case "number":
1164
+ case "boolean": return null;
1165
+ case "bigint": return `${path} contains a BigInt — BigInt throws in JSON.stringify`;
1166
+ case "function": return `${path} is a function — functions are not JSON-serializable`;
1167
+ case "symbol": return `${path} is a symbol — symbols are not JSON-serializable`;
1168
+ case "object": break;
1169
+ default: return `${path} has unsupported type "${typeof value}"`;
1170
+ }
1171
+ if (value instanceof Date) return `${path} is a Date — Dates silently coerce to strings in JSON.stringify`;
1172
+ if (value instanceof Map) return `${path} is a Map — Maps serialize as {} in JSON.stringify (data loss)`;
1173
+ if (value instanceof Set) return `${path} is a Set — Sets serialize as {} in JSON.stringify (data loss)`;
1174
+ if (value instanceof RegExp) return `${path} is a RegExp — RegExps serialize as {} in JSON.stringify`;
1175
+ if (value instanceof Error) return `${path} is an Error — Errors serialize as {} in JSON.stringify`;
1176
+ if (Array.isArray(value)) {
1177
+ for (let i = 0; i < value.length; i++) {
1178
+ const result = findNonSerializable(value[i], `${path}[${i}]`);
1179
+ if (result) return result;
1180
+ }
1181
+ return null;
1182
+ }
1183
+ const proto = Object.getPrototypeOf(value);
1184
+ if (proto === null) return `${path} is a null-prototype object — React Flight rejects null prototypes`;
1185
+ if (proto !== Object.prototype) return `${path} is a ${value.constructor?.name ?? "unknown"} instance — class instances may lose data in JSON.stringify`;
1186
+ for (const key of Object.keys(value)) {
1187
+ const result = findNonSerializable(value[key], `${path}.${key}`);
1188
+ if (result) return result;
1189
+ }
1190
+ return null;
1191
+ }
1192
+ /**
1193
+ * Emit a dev-mode warning if data is not JSON-serializable.
1194
+ * No-op in production.
1195
+ */
1196
+ function warnIfNotSerializable(data, callerName) {
1197
+ if (!isDebug()) return;
1198
+ if (data === void 0) return;
1199
+ const issue = findNonSerializable(data);
1200
+ 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.`);
1201
+ }
1202
+ /**
1203
+ * Render-phase signal thrown by `deny()`. Caught by the framework to produce
1204
+ * the correct HTTP status code (segment context) or graceful degradation (slot context).
1205
+ */
1206
+ var DenySignal = class extends Error {
1207
+ status;
1208
+ data;
1209
+ constructor(status, data) {
1210
+ super(`Access denied with status ${status}`);
1211
+ this.name = "DenySignal";
1212
+ this.status = status;
1213
+ this.data = data;
1214
+ }
1215
+ /**
1216
+ * Extract the file that called deny() from the stack trace.
1217
+ * Returns a short path (e.g. "app/auth/access.ts") or undefined if
1218
+ * the stack can't be parsed. Dev-only — used for dev log output.
1219
+ */
1220
+ get sourceFile() {
1221
+ if (!this.stack) return void 0;
1222
+ const frames = this.stack.split("\n");
1223
+ for (let i = 2; i < frames.length; i++) {
1224
+ const frame = frames[i];
1225
+ if (!frame) continue;
1226
+ if (frame.includes("primitives.ts") || frame.includes("node_modules")) continue;
1227
+ const match = frame.match(/\(([^)]+?)(?::\d+:\d+)\)/) ?? frame.match(/at\s+([^\s]+?)(?::\d+:\d+)/);
1228
+ if (match?.[1]) {
1229
+ const full = match[1];
1230
+ const appIdx = full.indexOf("/app/");
1231
+ return appIdx >= 0 ? full.slice(appIdx + 1) : full;
1232
+ }
1233
+ }
1234
+ }
1235
+ };
1236
+ /**
1237
+ * Universal denial/error primitive. Throws a `DenySignal` that the framework catches.
1238
+ *
1239
+ * - In segment context (outside Suspense): produces HTTP status code
1240
+ * - In slot context: graceful degradation → denied.tsx → default.tsx → null
1241
+ * - Inside Suspense (hold window): promoted to pre-flush behavior
1242
+ * - Inside Suspense (after flush): error boundary + noindex meta
1243
+ *
1244
+ * Supports both positional and object signatures:
1245
+ * ```ts
1246
+ * deny() // 403 (default)
1247
+ * deny(404) // 404
1248
+ * deny(503, { retry: true }) // 503 with data
1249
+ * deny({ status: 503, message: 'Maintenance' }) // object form
1250
+ * ```
1251
+ *
1252
+ * Accepts any 4xx or 5xx status code. This replaces the need for
1253
+ * `throw new RenderError(...)` in user code — RenderError is now an
1254
+ * internal pipeline detail.
1255
+ *
1256
+ * @param statusOrOptions - Status code (number) or options object. Default: 403.
1257
+ * @param data - Optional JSON-serializable data (positional form only).
1258
+ */
1259
+ function deny(statusOrOptions, data) {
1260
+ let status;
1261
+ let resolvedData;
1262
+ if (typeof statusOrOptions === "object" && statusOrOptions !== null) {
1263
+ status = statusOrOptions.status ?? 403;
1264
+ resolvedData = statusOrOptions.data;
1265
+ } else {
1266
+ status = statusOrOptions ?? 403;
1267
+ resolvedData = data;
1268
+ }
1269
+ if (status < 400 || status > 599) throw new Error(`deny() requires a 4xx or 5xx status code, got ${status}.`);
1270
+ warnIfNotSerializable(resolvedData, "deny()");
1271
+ throw new DenySignal(status, resolvedData);
1272
+ }
1273
+ /**
1274
+ * Render-phase signal thrown by `redirect()` and `redirectExternal()`.
1275
+ * Caught by the framework to produce a 3xx response or client-side navigation.
1276
+ */
1277
+ var RedirectSignal = class extends Error {
1278
+ location;
1279
+ status;
1280
+ constructor(location, status) {
1281
+ super(`Redirect to ${location}`);
1282
+ this.name = "RedirectSignal";
1283
+ this.location = location;
1284
+ this.status = status;
1285
+ }
1286
+ };
1287
+ /**
1288
+ * Returns true if the error is a framework control-flow signal (RedirectSignal
1289
+ * or DenySignal) rather than a genuine application error. Works both for direct
1290
+ * instances (RSC-side) and deserialized digest errors (SSR cross-boundary).
1291
+ *
1292
+ * See also: isFrameworkSignalError() in client/browser-dev.ts (client-only).
1293
+ */
1294
+ function isControlFlowSignal(error) {
1295
+ if (error instanceof DenySignal || error instanceof RedirectSignal) return true;
1296
+ if (error && typeof error === "object") {
1297
+ const digest = error.digest;
1298
+ if (typeof digest === "string") try {
1299
+ const parsed = JSON.parse(digest);
1300
+ if (parsed && typeof parsed === "object") return parsed.type === "redirect" || parsed.type === "deny";
1301
+ } catch {}
1302
+ }
1303
+ return false;
1304
+ }
1305
+ /**
1306
+ * Redirect to a relative path. Rejects absolute and protocol-relative URLs.
1307
+ * Use `redirectExternal()` for external redirects with an allow-list.
1308
+ *
1309
+ * @param path - Relative path (e.g. '/login', 'settings', '/login?returnTo=/dash')
1310
+ * @param statusOrOptions - HTTP status code (3xx, default 302) or options object.
1311
+ *
1312
+ * @example
1313
+ * // Simple redirect
1314
+ * redirect('/login');
1315
+ *
1316
+ * // With status code
1317
+ * redirect('/login', 301);
1318
+ *
1319
+ * // With preserved search params
1320
+ * redirect(`/docs/${version}/${slug}`, { preserveSearchParams: ['foo'] });
1321
+ */
1322
+ function redirect(path, statusOrOptions) {
1323
+ let status;
1324
+ let preserveSearchParams;
1325
+ if (typeof statusOrOptions === "number") status = statusOrOptions;
1326
+ else if (statusOrOptions) {
1327
+ status = statusOrOptions.status ?? (statusOrOptions.permanent ? 308 : 302);
1328
+ preserveSearchParams = statusOrOptions.preserveSearchParams;
1329
+ } else status = 302;
1330
+ if (status < 300 || status > 399) throw new Error(`redirect() requires a 3xx status code, got ${status}.`);
1331
+ assertRelativeRedirectPath(path);
1332
+ let resolvedPath = path;
1333
+ if (preserveSearchParams) resolvedPath = mergePreservedSearchParams(path, getRequestSearchString(), preserveSearchParams);
1334
+ throw new RedirectSignal(resolvedPath, status);
1335
+ }
1336
+ /**
1337
+ * Redirect to an external URL. The origin must be in the provided allow-list.
1338
+ *
1339
+ * Only http: and https: schemes are permitted. The allow-list is matched
1340
+ * against full origins (scheme + host + port), not bare hostnames.
1341
+ *
1342
+ * @param url - Absolute URL to redirect to.
1343
+ * @param allowList - Array of allowed origins (e.g. ['https://example.com', 'https://auth.example.com']).
1344
+ * @param status - HTTP redirect status code (3xx). Defaults to 302.
1345
+ */
1346
+ function redirectExternal(url, allowList, status = 302) {
1347
+ if (status < 300 || status > 399) throw new Error(`redirectExternal() requires a 3xx status code, got ${status}.`);
1348
+ throw new RedirectSignal(validateExternalRedirectUrl(url, allowList), status);
1349
+ }
1350
+ /**
1351
+ * Typed throw for render-phase errors that carry structured context to error boundaries.
1352
+ *
1353
+ * The `digest` (code + data) is serialized into the RSC stream separately from the
1354
+ * Error instance — only the digest crosses the RSC → client boundary.
1355
+ *
1356
+ * @example
1357
+ * ```ts
1358
+ * throw new RenderError('PRODUCT_NOT_FOUND', {
1359
+ * title: 'Product not found',
1360
+ * resourceId: params.id,
1361
+ * })
1362
+ * ```
1363
+ */
1364
+ var RenderError = class extends Error {
1365
+ code;
1366
+ digest;
1367
+ status;
1368
+ constructor(code, data, options) {
1369
+ super(`RenderError: ${code}`);
1370
+ this.name = "RenderError";
1371
+ this.code = code;
1372
+ this.digest = {
1373
+ code,
1374
+ data
1375
+ };
1376
+ warnIfNotSerializable(data, "RenderError");
1377
+ const status = options?.status ?? 500;
1378
+ if (status < 400 || status > 599) throw new Error(`RenderError status must be 4xx or 5xx, got ${status}.`);
1379
+ this.status = status;
1380
+ }
1381
+ };
1382
+ var _waitUntilWarned = false;
1383
+ /**
1384
+ * Register a promise to be kept alive after the response is sent.
1385
+ * Maps to `ctx.waitUntil()` on Cloudflare Workers and similar platforms.
1386
+ *
1387
+ * In production, the platform adapter installs a per-request waitUntil
1388
+ * function via ALS (see waituntil-bridge.ts). This function checks the
1389
+ * ALS bridge first, then falls back to the legacy adapter argument.
1390
+ *
1391
+ * If neither is available, a warning is logged once and the promise is
1392
+ * left to resolve (or reject) without being tracked.
1393
+ *
1394
+ * @param promise - The background work to keep alive.
1395
+ * @param adapter - Optional legacy adapter (prefer ALS bridge in production).
1396
+ */
1397
+ function waitUntil(promise, adapter) {
1398
+ const alsFn = getWaitUntil();
1399
+ if (alsFn) {
1400
+ alsFn(promise);
1401
+ return;
1402
+ }
1403
+ if (adapter && typeof adapter.waitUntil === "function") {
1404
+ adapter.waitUntil(promise);
1405
+ return;
1406
+ }
1407
+ if (!_waitUntilWarned) {
1408
+ _waitUntilWarned = true;
1409
+ console.warn("[timber] waitUntil() is not supported by the current adapter. Background work will not be tracked. This warning is shown once.");
1410
+ }
1411
+ }
1412
+ //#endregion
1413
+ //#region src/server/logger.ts
1414
+ /**
1415
+ * Logger — structured logging with environment-aware formatting.
1416
+ *
1417
+ * timber.js ships a DefaultLogger that writes human-readable lines to stderr
1418
+ * in production. Users can export a custom logger from instrumentation.ts to
1419
+ * replace it with pino, winston, or any TimberLogger-compatible object.
1420
+ *
1421
+ * See design/17-logging.md §"Production Logging"
1422
+ */
1423
+ var _logger = createDefaultLogger();
1424
+ /**
1425
+ * Set the user-provided logger. Called by the instrumentation loader
1426
+ * when it finds a `logger` export in instrumentation.ts. Replaces
1427
+ * the DefaultLogger entirely.
1428
+ */
1429
+ function setLogger(logger) {
1430
+ _logger = logger;
1431
+ }
1432
+ /**
1433
+ * Get the current logger. Always non-null — returns DefaultLogger when
1434
+ * no custom logger is configured.
1435
+ */
1436
+ function getLogger() {
1437
+ return _logger;
1438
+ }
1439
+ /**
1440
+ * Inject trace_id and span_id into log data for log–trace correlation.
1441
+ * Always injects trace_id (never undefined). Injects span_id only when OTEL is active.
1442
+ */
1443
+ function withTraceContext(data) {
1444
+ const store = getTraceStore();
1445
+ const enriched = { ...data };
1446
+ if (store) {
1447
+ enriched.trace_id = store.traceId;
1448
+ if (store.spanId) enriched.span_id = store.spanId;
1449
+ }
1450
+ return enriched;
1451
+ }
1452
+ /** Log a completed request. Level: info. */
1453
+ function logRequestCompleted(data) {
1454
+ _logger.info("request completed", withTraceContext(data));
1455
+ }
1456
+ /** Log request received. Level: debug. */
1457
+ function logRequestReceived(data) {
1458
+ _logger.debug("request received", withTraceContext(data));
1459
+ }
1460
+ /** Log a slow request warning. Level: warn. */
1461
+ function logSlowRequest(data) {
1462
+ _logger.warn("slow request exceeded threshold", withTraceContext(data));
1463
+ }
1464
+ /** Log middleware short-circuit. Level: debug. */
1465
+ function logMiddlewareShortCircuit(data) {
1466
+ _logger.debug("middleware short-circuited", withTraceContext(data));
1467
+ }
1468
+ /** Log unhandled error in middleware phase. Level: error. */
1469
+ function logMiddlewareError(data) {
1470
+ if (isControlFlowSignal(data.error)) return;
1471
+ _logger.error("unhandled error in middleware phase", withTraceContext(data));
1472
+ }
1473
+ /** Log unhandled render-phase error. Level: error. */
1474
+ function logRenderError(data) {
1475
+ if (isControlFlowSignal(data.error)) return;
1476
+ _logger.error("unhandled render-phase error", withTraceContext(data));
1477
+ }
1478
+ /** Log proxy.ts uncaught error. Level: error. */
1479
+ function logProxyError(data) {
1480
+ _logger.error("proxy.ts threw uncaught error", withTraceContext(data));
1481
+ }
1482
+ /** Log unhandled error in route handler. Level: error. */
1483
+ function logRouteError(data) {
1484
+ if (isControlFlowSignal(data.error)) return;
1485
+ _logger.error("unhandled route handler error", withTraceContext(data));
1486
+ }
1487
+ /** Log waitUntil() adapter missing (once at startup). Level: warn. */
1488
+ function logWaitUntilUnsupported() {
1489
+ _logger.warn("adapter does not support waitUntil()");
1490
+ }
1491
+ /** Log waitUntil() promise rejection. Level: warn. */
1492
+ function logWaitUntilRejected(data) {
1493
+ _logger.warn("waitUntil() promise rejected", withTraceContext(data));
1494
+ }
1495
+ /** Log staleWhileRevalidate refetch failure. Level: warn. */
1496
+ function logSwrRefetchFailed(data) {
1497
+ _logger.warn("staleWhileRevalidate refetch failed", withTraceContext(data));
1498
+ }
1499
+ /** Log cache miss. Level: debug. */
1500
+ function logCacheMiss(data) {
1501
+ _logger.debug("timber.cache MISS", withTraceContext(data));
1502
+ }
1503
+ /**
1504
+ * Log an intentionally swallowed error. Provides observability into catch
1505
+ * blocks that are deliberately empty — the error is consumed, never rethrown.
1506
+ *
1507
+ * Default level: `warn` in dev (so the overlay surfaces patterns), `debug`
1508
+ * in production (low noise unless TIMBER_DEBUG is set). Pass `opts.level`
1509
+ * to override.
1510
+ *
1511
+ * **Infallible** — swallow() itself never throws, even if the logger is
1512
+ * broken. A thrown swallow would turn a benign catch into a crash.
1513
+ */
1514
+ function swallow(err, reason, opts) {
1515
+ try {
1516
+ const level = opts?.level ?? (isDevMode() ? "warn" : "debug");
1517
+ _logger[level](`swallowed: ${reason}`, withTraceContext({ error: err }));
1518
+ } catch {}
1519
+ }
1520
+ //#endregion
1521
+ export { revalidationAls as $, runWithRequestContext as A, addSpanEvent as B, RedirectType as C, getSearchParams as D, getHeaders as E, getCookieJar as F, getTraceId as G, generateTraceId as H, getSetCookieHeaders as I, setSpanAttribute as J, replaceTraceId as K, getWaitUntil as L, setMutableCookieContext as M, setSegmentParams as N, getSegmentParams as O, getCookie as P, requestContextAls as Q, isDebug as R, waitUntil as S, getHeader as T, getOtelTraceId as U, addSpanEventSync as V, getSpanId as W, earlyHintsSenderAls as X, withSpan as Y, formFlashAls as Z, RedirectSignal as _, logProxyError as a, redirect as b, logRequestReceived as c, logSwrRefetchFailed as d, timingAls as et, logWaitUntilRejected as f, DenySignal as g, swallow as h, logMiddlewareShortCircuit as i, setMatchedSegmentPath as j, markResponseFlushed as k, logRouteError as l, setLogger as m, logCacheMiss as n, logRenderError as o, logWaitUntilUnsupported as p, runWithTraceId as q, logMiddlewareError as r, logRequestCompleted as s, getLogger as t, logSlowRequest as u, RenderError as v, applyRequestHeaderOverlay as w, redirectExternal as x, deny as y, isDevMode as z };
1522
+
1523
+ //# sourceMappingURL=logger-CPoQkGK6.js.map