@timber-js/app 0.2.0-alpha.4 → 0.2.0-alpha.40

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 (336) hide show
  1. package/LICENSE +8 -0
  2. package/dist/_chunks/{als-registry-B7DbZ2hS.js → als-registry-Ba7URUIn.js} +1 -1
  3. package/dist/_chunks/als-registry-Ba7URUIn.js.map +1 -0
  4. package/dist/_chunks/chunk-DYhsFzuS.js +33 -0
  5. package/dist/_chunks/debug-ECi_61pb.js +108 -0
  6. package/dist/_chunks/debug-ECi_61pb.js.map +1 -0
  7. package/dist/_chunks/define-cookie-BmKbSyp0.js +93 -0
  8. package/dist/_chunks/define-cookie-BmKbSyp0.js.map +1 -0
  9. package/dist/_chunks/error-boundary-BAN3751q.js +211 -0
  10. package/dist/_chunks/error-boundary-BAN3751q.js.map +1 -0
  11. package/dist/_chunks/{format-CwdaB0_2.js → format-cX7wzEp2.js} +2 -2
  12. package/dist/_chunks/{format-CwdaB0_2.js.map → format-cX7wzEp2.js.map} +1 -1
  13. package/dist/_chunks/{interception-BOoWmLUA.js → interception-D2djYaIm.js} +112 -77
  14. package/dist/_chunks/interception-D2djYaIm.js.map +1 -0
  15. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → metadata-routes-BU684ls2.js} +1 -1
  16. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js.map → metadata-routes-BU684ls2.js.map} +1 -1
  17. package/dist/_chunks/{request-context-CZJi4CuK.js → request-context-BxYIJM24.js} +93 -69
  18. package/dist/_chunks/request-context-BxYIJM24.js.map +1 -0
  19. package/dist/_chunks/segment-context-C6byCyZU.js +69 -0
  20. package/dist/_chunks/segment-context-C6byCyZU.js.map +1 -0
  21. package/dist/_chunks/stale-reload-C0ValzG7.js +47 -0
  22. package/dist/_chunks/stale-reload-C0ValzG7.js.map +1 -0
  23. package/dist/_chunks/{tracing-Cwn7697K.js → tracing-CuXiCP5p.js} +17 -3
  24. package/dist/_chunks/{tracing-Cwn7697K.js.map → tracing-CuXiCP5p.js.map} +1 -1
  25. package/dist/_chunks/{use-query-states-D5KaffOK.js → use-query-states-BvW0TKDn.js} +1 -1
  26. package/dist/_chunks/{use-query-states-D5KaffOK.js.map → use-query-states-BvW0TKDn.js.map} +1 -1
  27. package/dist/_chunks/wrappers-C6J0nNji.js +331 -0
  28. package/dist/_chunks/wrappers-C6J0nNji.js.map +1 -0
  29. package/dist/adapters/compress-module.d.ts.map +1 -1
  30. package/dist/adapters/nitro.d.ts +17 -1
  31. package/dist/adapters/nitro.d.ts.map +1 -1
  32. package/dist/adapters/nitro.js +56 -13
  33. package/dist/adapters/nitro.js.map +1 -1
  34. package/dist/cache/fast-hash.d.ts +22 -0
  35. package/dist/cache/fast-hash.d.ts.map +1 -0
  36. package/dist/cache/index.d.ts +5 -2
  37. package/dist/cache/index.d.ts.map +1 -1
  38. package/dist/cache/index.js +88 -18
  39. package/dist/cache/index.js.map +1 -1
  40. package/dist/cache/register-cached-function.d.ts.map +1 -1
  41. package/dist/cache/singleflight.d.ts +18 -1
  42. package/dist/cache/singleflight.d.ts.map +1 -1
  43. package/dist/cache/timber-cache.d.ts.map +1 -1
  44. package/dist/client/error-boundary.d.ts +10 -1
  45. package/dist/client/error-boundary.d.ts.map +1 -1
  46. package/dist/client/error-boundary.js +1 -125
  47. package/dist/client/index.d.ts +3 -2
  48. package/dist/client/index.d.ts.map +1 -1
  49. package/dist/client/index.js +213 -93
  50. package/dist/client/index.js.map +1 -1
  51. package/dist/client/link.d.ts +22 -8
  52. package/dist/client/link.d.ts.map +1 -1
  53. package/dist/client/navigation-context.d.ts +2 -2
  54. package/dist/client/router.d.ts +25 -3
  55. package/dist/client/router.d.ts.map +1 -1
  56. package/dist/client/rsc-fetch.d.ts +23 -2
  57. package/dist/client/rsc-fetch.d.ts.map +1 -1
  58. package/dist/client/segment-cache.d.ts +1 -1
  59. package/dist/client/segment-cache.d.ts.map +1 -1
  60. package/dist/client/segment-context.d.ts +1 -1
  61. package/dist/client/segment-context.d.ts.map +1 -1
  62. package/dist/client/segment-merger.d.ts.map +1 -1
  63. package/dist/client/stale-reload.d.ts +15 -0
  64. package/dist/client/stale-reload.d.ts.map +1 -1
  65. package/dist/client/top-loader.d.ts +1 -1
  66. package/dist/client/top-loader.d.ts.map +1 -1
  67. package/dist/client/transition-root.d.ts +1 -1
  68. package/dist/client/transition-root.d.ts.map +1 -1
  69. package/dist/client/use-params.d.ts +2 -2
  70. package/dist/client/use-params.d.ts.map +1 -1
  71. package/dist/client/use-query-states.d.ts +1 -1
  72. package/dist/codec.d.ts +21 -0
  73. package/dist/codec.d.ts.map +1 -0
  74. package/dist/cookies/define-cookie.d.ts +33 -12
  75. package/dist/cookies/define-cookie.d.ts.map +1 -1
  76. package/dist/cookies/index.js +1 -83
  77. package/dist/fonts/css.d.ts +1 -0
  78. package/dist/fonts/css.d.ts.map +1 -1
  79. package/dist/fonts/local.d.ts +4 -2
  80. package/dist/fonts/local.d.ts.map +1 -1
  81. package/dist/index.d.ts +112 -35
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +635 -233
  84. package/dist/index.js.map +1 -1
  85. package/dist/params/define.d.ts +76 -0
  86. package/dist/params/define.d.ts.map +1 -0
  87. package/dist/params/index.d.ts +8 -0
  88. package/dist/params/index.d.ts.map +1 -0
  89. package/dist/params/index.js +104 -0
  90. package/dist/params/index.js.map +1 -0
  91. package/dist/plugins/adapter-build.d.ts.map +1 -1
  92. package/dist/plugins/build-manifest.d.ts.map +1 -1
  93. package/dist/plugins/client-chunks.d.ts +32 -0
  94. package/dist/plugins/client-chunks.d.ts.map +1 -0
  95. package/dist/plugins/dev-error-overlay.d.ts +26 -1
  96. package/dist/plugins/dev-error-overlay.d.ts.map +1 -1
  97. package/dist/plugins/entries.d.ts +7 -0
  98. package/dist/plugins/entries.d.ts.map +1 -1
  99. package/dist/plugins/fonts.d.ts +9 -1
  100. package/dist/plugins/fonts.d.ts.map +1 -1
  101. package/dist/plugins/mdx.d.ts +6 -0
  102. package/dist/plugins/mdx.d.ts.map +1 -1
  103. package/dist/plugins/routing.d.ts.map +1 -1
  104. package/dist/plugins/server-bundle.d.ts.map +1 -1
  105. package/dist/plugins/static-build.d.ts.map +1 -1
  106. package/dist/routing/codegen.d.ts +2 -2
  107. package/dist/routing/codegen.d.ts.map +1 -1
  108. package/dist/routing/index.js +1 -1
  109. package/dist/routing/scanner.d.ts.map +1 -1
  110. package/dist/routing/status-file-lint.d.ts +2 -1
  111. package/dist/routing/status-file-lint.d.ts.map +1 -1
  112. package/dist/routing/types.d.ts +6 -4
  113. package/dist/routing/types.d.ts.map +1 -1
  114. package/dist/rsc-runtime/rsc.d.ts +1 -1
  115. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  116. package/dist/rsc-runtime/ssr.d.ts +12 -0
  117. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  118. package/dist/search-params/codecs.d.ts +1 -1
  119. package/dist/search-params/define.d.ts +153 -0
  120. package/dist/search-params/define.d.ts.map +1 -0
  121. package/dist/search-params/index.d.ts +4 -5
  122. package/dist/search-params/index.d.ts.map +1 -1
  123. package/dist/search-params/index.js +3 -474
  124. package/dist/search-params/registry.d.ts +1 -1
  125. package/dist/search-params/wrappers.d.ts +53 -0
  126. package/dist/search-params/wrappers.d.ts.map +1 -0
  127. package/dist/server/access-gate.d.ts +4 -0
  128. package/dist/server/access-gate.d.ts.map +1 -1
  129. package/dist/server/action-client.d.ts.map +1 -1
  130. package/dist/server/action-encryption.d.ts +76 -0
  131. package/dist/server/action-encryption.d.ts.map +1 -0
  132. package/dist/server/action-handler.d.ts.map +1 -1
  133. package/dist/server/als-registry.d.ts +18 -4
  134. package/dist/server/als-registry.d.ts.map +1 -1
  135. package/dist/server/build-manifest.d.ts +2 -2
  136. package/dist/server/debug.d.ts +46 -15
  137. package/dist/server/debug.d.ts.map +1 -1
  138. package/dist/server/default-logger.d.ts +22 -0
  139. package/dist/server/default-logger.d.ts.map +1 -0
  140. package/dist/server/deny-renderer.d.ts.map +1 -1
  141. package/dist/server/early-hints.d.ts +13 -5
  142. package/dist/server/early-hints.d.ts.map +1 -1
  143. package/dist/server/error-boundary-wrapper.d.ts +4 -0
  144. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  145. package/dist/server/flight-injection-state.d.ts +78 -0
  146. package/dist/server/flight-injection-state.d.ts.map +1 -0
  147. package/dist/server/flight-scripts.d.ts +39 -0
  148. package/dist/server/flight-scripts.d.ts.map +1 -0
  149. package/dist/server/flush.d.ts.map +1 -1
  150. package/dist/server/form-data.d.ts +29 -0
  151. package/dist/server/form-data.d.ts.map +1 -1
  152. package/dist/server/html-injectors.d.ts +5 -11
  153. package/dist/server/html-injectors.d.ts.map +1 -1
  154. package/dist/server/index.d.ts +4 -2
  155. package/dist/server/index.d.ts.map +1 -1
  156. package/dist/server/index.js +1975 -1649
  157. package/dist/server/index.js.map +1 -1
  158. package/dist/server/logger.d.ts +24 -7
  159. package/dist/server/logger.d.ts.map +1 -1
  160. package/dist/server/node-stream-transforms.d.ts +77 -0
  161. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  162. package/dist/server/pipeline.d.ts +7 -4
  163. package/dist/server/pipeline.d.ts.map +1 -1
  164. package/dist/server/primitives.d.ts +30 -3
  165. package/dist/server/primitives.d.ts.map +1 -1
  166. package/dist/server/render-timeout.d.ts +51 -0
  167. package/dist/server/render-timeout.d.ts.map +1 -0
  168. package/dist/server/request-context.d.ts +65 -38
  169. package/dist/server/request-context.d.ts.map +1 -1
  170. package/dist/server/route-element-builder.d.ts +7 -0
  171. package/dist/server/route-element-builder.d.ts.map +1 -1
  172. package/dist/server/route-handler.d.ts.map +1 -1
  173. package/dist/server/route-matcher.d.ts +2 -2
  174. package/dist/server/route-matcher.d.ts.map +1 -1
  175. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  176. package/dist/server/rsc-entry/helpers.d.ts +46 -3
  177. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  178. package/dist/server/rsc-entry/index.d.ts +6 -1
  179. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  180. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  181. package/dist/server/rsc-entry/rsc-stream.d.ts +9 -0
  182. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  183. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  184. package/dist/server/slot-resolver.d.ts +1 -1
  185. package/dist/server/slot-resolver.d.ts.map +1 -1
  186. package/dist/server/ssr-entry.d.ts +22 -0
  187. package/dist/server/ssr-entry.d.ts.map +1 -1
  188. package/dist/server/ssr-render.d.ts +39 -21
  189. package/dist/server/ssr-render.d.ts.map +1 -1
  190. package/dist/server/tracing.d.ts +10 -0
  191. package/dist/server/tracing.d.ts.map +1 -1
  192. package/dist/server/tree-builder.d.ts +19 -12
  193. package/dist/server/tree-builder.d.ts.map +1 -1
  194. package/dist/server/types.d.ts +1 -3
  195. package/dist/server/types.d.ts.map +1 -1
  196. package/dist/server/version-skew.d.ts +61 -0
  197. package/dist/server/version-skew.d.ts.map +1 -0
  198. package/dist/server/waituntil-bridge.d.ts.map +1 -1
  199. package/dist/shared/merge-search-params.d.ts +22 -0
  200. package/dist/shared/merge-search-params.d.ts.map +1 -0
  201. package/dist/shims/navigation-client.d.ts +1 -1
  202. package/dist/shims/navigation-client.d.ts.map +1 -1
  203. package/dist/shims/navigation.d.ts +1 -1
  204. package/dist/shims/navigation.d.ts.map +1 -1
  205. package/dist/utils/state-machine.d.ts +80 -0
  206. package/dist/utils/state-machine.d.ts.map +1 -0
  207. package/package.json +17 -14
  208. package/src/adapters/compress-module.ts +24 -4
  209. package/src/adapters/nitro.ts +58 -9
  210. package/src/cache/fast-hash.ts +34 -0
  211. package/src/cache/index.ts +5 -2
  212. package/src/cache/register-cached-function.ts +7 -3
  213. package/src/cache/singleflight.ts +62 -4
  214. package/src/cache/timber-cache.ts +34 -26
  215. package/src/cli.ts +0 -0
  216. package/src/client/browser-entry.ts +94 -90
  217. package/src/client/error-boundary.tsx +18 -1
  218. package/src/client/index.ts +10 -1
  219. package/src/client/link.tsx +78 -19
  220. package/src/client/navigation-context.ts +2 -2
  221. package/src/client/router.ts +105 -60
  222. package/src/client/rsc-fetch.ts +63 -2
  223. package/src/client/segment-cache.ts +1 -1
  224. package/src/client/segment-context.ts +6 -1
  225. package/src/client/segment-merger.ts +2 -8
  226. package/src/client/stale-reload.ts +32 -6
  227. package/src/client/top-loader.tsx +10 -9
  228. package/src/client/transition-root.tsx +7 -1
  229. package/src/client/use-params.ts +3 -3
  230. package/src/client/use-query-states.ts +1 -1
  231. package/src/codec.ts +21 -0
  232. package/src/cookies/define-cookie.ts +69 -18
  233. package/src/fonts/css.ts +2 -1
  234. package/src/fonts/local.ts +7 -3
  235. package/src/index.ts +280 -85
  236. package/src/params/define.ts +260 -0
  237. package/src/params/index.ts +28 -0
  238. package/src/plugins/adapter-build.ts +6 -0
  239. package/src/plugins/build-manifest.ts +11 -0
  240. package/src/plugins/client-chunks.ts +65 -0
  241. package/src/plugins/dev-error-overlay.ts +70 -1
  242. package/src/plugins/dev-server.ts +38 -4
  243. package/src/plugins/entries.ts +12 -11
  244. package/src/plugins/fonts.ts +171 -19
  245. package/src/plugins/mdx.ts +9 -5
  246. package/src/plugins/routing.ts +40 -14
  247. package/src/plugins/server-bundle.ts +32 -1
  248. package/src/plugins/shims.ts +1 -1
  249. package/src/plugins/static-build.ts +8 -4
  250. package/src/routing/codegen.ts +109 -88
  251. package/src/routing/scanner.ts +55 -6
  252. package/src/routing/status-file-lint.ts +2 -1
  253. package/src/routing/types.ts +7 -4
  254. package/src/rsc-runtime/rsc.ts +2 -0
  255. package/src/rsc-runtime/ssr.ts +50 -0
  256. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  257. package/src/search-params/codecs.ts +1 -1
  258. package/src/search-params/define.ts +504 -0
  259. package/src/search-params/index.ts +12 -18
  260. package/src/search-params/registry.ts +1 -1
  261. package/src/search-params/wrappers.ts +85 -0
  262. package/src/server/access-gate.tsx +40 -9
  263. package/src/server/action-client.ts +14 -5
  264. package/src/server/action-encryption.ts +144 -0
  265. package/src/server/action-handler.ts +19 -2
  266. package/src/server/als-registry.ts +18 -4
  267. package/src/server/build-manifest.ts +4 -4
  268. package/src/server/compress.ts +25 -7
  269. package/src/server/debug.ts +55 -17
  270. package/src/server/default-logger.ts +98 -0
  271. package/src/server/deny-renderer.ts +2 -1
  272. package/src/server/early-hints.ts +36 -15
  273. package/src/server/error-boundary-wrapper.ts +57 -14
  274. package/src/server/flight-injection-state.ts +152 -0
  275. package/src/server/flight-scripts.ts +59 -0
  276. package/src/server/flush.ts +2 -1
  277. package/src/server/form-data.ts +76 -0
  278. package/src/server/html-injectors.ts +103 -66
  279. package/src/server/index.ts +9 -4
  280. package/src/server/logger.ts +38 -35
  281. package/src/server/node-stream-transforms.ts +381 -0
  282. package/src/server/pipeline.ts +131 -39
  283. package/src/server/primitives.ts +47 -5
  284. package/src/server/render-timeout.ts +108 -0
  285. package/src/server/request-context.ts +112 -119
  286. package/src/server/route-element-builder.ts +106 -114
  287. package/src/server/route-handler.ts +2 -1
  288. package/src/server/route-matcher.ts +2 -2
  289. package/src/server/rsc-entry/error-renderer.ts +5 -3
  290. package/src/server/rsc-entry/helpers.ts +122 -3
  291. package/src/server/rsc-entry/index.ts +125 -49
  292. package/src/server/rsc-entry/rsc-payload.ts +52 -12
  293. package/src/server/rsc-entry/rsc-stream.ts +33 -8
  294. package/src/server/rsc-entry/ssr-renderer.ts +40 -13
  295. package/src/server/slot-resolver.ts +199 -210
  296. package/src/server/ssr-entry.ts +169 -17
  297. package/src/server/ssr-render.ts +266 -67
  298. package/src/server/tracing.ts +23 -0
  299. package/src/server/tree-builder.ts +91 -57
  300. package/src/server/types.ts +1 -3
  301. package/src/server/version-skew.ts +104 -0
  302. package/src/server/waituntil-bridge.ts +4 -1
  303. package/src/shared/merge-search-params.ts +48 -0
  304. package/src/shims/navigation-client.ts +1 -1
  305. package/src/shims/navigation.ts +1 -1
  306. package/src/utils/state-machine.ts +111 -0
  307. package/dist/_chunks/als-registry-B7DbZ2hS.js.map +0 -1
  308. package/dist/_chunks/debug-B4WUeqJ-.js +0 -75
  309. package/dist/_chunks/debug-B4WUeqJ-.js.map +0 -1
  310. package/dist/_chunks/interception-BOoWmLUA.js.map +0 -1
  311. package/dist/_chunks/request-context-CZJi4CuK.js.map +0 -1
  312. package/dist/_chunks/ssr-data-MjmprTmO.js +0 -88
  313. package/dist/_chunks/ssr-data-MjmprTmO.js.map +0 -1
  314. package/dist/_chunks/use-cookie-DX-l1_5E.js +0 -91
  315. package/dist/_chunks/use-cookie-DX-l1_5E.js.map +0 -1
  316. package/dist/client/error-boundary.js.map +0 -1
  317. package/dist/cookies/index.js.map +0 -1
  318. package/dist/plugins/dynamic-transform.d.ts +0 -72
  319. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  320. package/dist/search-params/analyze.d.ts +0 -54
  321. package/dist/search-params/analyze.d.ts.map +0 -1
  322. package/dist/search-params/builtin-codecs.d.ts +0 -105
  323. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  324. package/dist/search-params/create.d.ts +0 -106
  325. package/dist/search-params/create.d.ts.map +0 -1
  326. package/dist/search-params/index.js.map +0 -1
  327. package/dist/server/prerender.d.ts +0 -77
  328. package/dist/server/prerender.d.ts.map +0 -1
  329. package/dist/server/response-cache.d.ts +0 -53
  330. package/dist/server/response-cache.d.ts.map +0 -1
  331. package/src/plugins/dynamic-transform.ts +0 -161
  332. package/src/search-params/analyze.ts +0 -192
  333. package/src/search-params/builtin-codecs.ts +0 -228
  334. package/src/search-params/create.ts +0 -321
  335. package/src/server/prerender.ts +0 -139
  336. package/src/server/response-cache.ts +0 -277
@@ -8,8 +8,8 @@
8
8
  * No runtime overhead — purely static type generation.
9
9
  */
10
10
 
11
- import { existsSync } from 'node:fs';
12
- import { join, relative, posix } from 'node:path';
11
+ import { existsSync, readFileSync } from 'node:fs';
12
+ import { relative, posix } from 'node:path';
13
13
  import type { RouteTree, SegmentNode } from './types.js';
14
14
 
15
15
  /** A single route entry extracted from the segment tree. */
@@ -18,10 +18,10 @@ interface RouteEntry {
18
18
  urlPath: string;
19
19
  /** Accumulated params from all ancestor dynamic segments */
20
20
  params: ParamEntry[];
21
- /** Whether this route has a co-located search-params.ts */
21
+ /** Whether the page.tsx exports searchParams */
22
22
  hasSearchParams: boolean;
23
- /** Absolute path to search-params.ts (for computing relative import paths) */
24
- searchParamsAbsPath?: string;
23
+ /** Absolute path to the page file that exports searchParams (for import paths) */
24
+ searchParamsPagePath?: string;
25
25
  /** Whether this is an API route (route.ts) vs page route */
26
26
  isApiRoute: boolean;
27
27
  }
@@ -29,15 +29,17 @@ interface RouteEntry {
29
29
  interface ParamEntry {
30
30
  name: string;
31
31
  type: 'string' | 'string[]' | 'string[] | undefined';
32
+ /** When a layout/page exports defineParams, the absolute path to that file. */
33
+ codecFilePath?: string;
32
34
  }
33
35
 
34
36
  /** Options for route map generation. */
35
37
  export interface CodegenOptions {
36
- /** Absolute path to the app/ directory. Required for search-params.ts detection. */
38
+ /** Absolute path to the app/ directory. Required for page searchParams detection. */
37
39
  appDir?: string;
38
40
  /**
39
41
  * Absolute path to the directory where the .d.ts file will be written.
40
- * Used to compute correct relative import paths for search-params.ts files.
42
+ * Used to compute correct relative import paths for page files.
41
43
  * Defaults to appDir when not provided (preserves backward compat for tests).
42
44
  */
43
45
  outputDir?: string;
@@ -51,7 +53,7 @@ export interface CodegenOptions {
51
53
  */
52
54
  export function generateRouteMap(tree: RouteTree, options: CodegenOptions = {}): string {
53
55
  const routes: RouteEntry[] = [];
54
- collectRoutes(tree.root, [], options.appDir, routes);
56
+ collectRoutes(tree.root, [], routes);
55
57
 
56
58
  // Sort routes alphabetically for deterministic output
57
59
  routes.sort((a, b) => a.urlPath.localeCompare(b.urlPath));
@@ -71,15 +73,17 @@ export function generateRouteMap(tree: RouteTree, options: CodegenOptions = {}):
71
73
  function collectRoutes(
72
74
  node: SegmentNode,
73
75
  ancestorParams: ParamEntry[],
74
- appDir: string | undefined,
75
76
  routes: RouteEntry[]
76
77
  ): void {
77
78
  // Accumulate params from this segment
78
79
  const params = [...ancestorParams];
79
80
  if (node.paramName) {
81
+ // Check if layout or page exports a params codec for this segment
82
+ const codecFile = findParamsExport(node);
80
83
  params.push({
81
84
  name: node.paramName,
82
85
  type: paramTypeForSegment(node.segmentType),
86
+ codecFilePath: codecFile,
83
87
  });
84
88
  }
85
89
 
@@ -95,13 +99,14 @@ function collectRoutes(
95
99
  isApiRoute,
96
100
  };
97
101
 
98
- // Detect co-located search-params.ts
99
- if (appDir && isPage) {
100
- const segmentDir = resolveSegmentDir(appDir, node);
101
- const searchParamsFile = findSearchParamsFile(segmentDir);
102
- if (searchParamsFile) {
102
+ // Detect searchParams export from params.ts (primary) or page.tsx (fallback)
103
+ if (isPage) {
104
+ if (node.params && fileHasExport(node.params.filePath, 'searchParams')) {
103
105
  entry.hasSearchParams = true;
104
- entry.searchParamsAbsPath = searchParamsFile;
106
+ entry.searchParamsPagePath = node.params.filePath;
107
+ } else if (node.page && fileHasExport(node.page.filePath, 'searchParams')) {
108
+ entry.hasSearchParams = true;
109
+ entry.searchParamsPagePath = node.page.filePath;
105
110
  }
106
111
  }
107
112
 
@@ -110,12 +115,12 @@ function collectRoutes(
110
115
 
111
116
  // Recurse into children
112
117
  for (const child of node.children) {
113
- collectRoutes(child, params, appDir, routes);
118
+ collectRoutes(child, params, routes);
114
119
  }
115
120
 
116
121
  // Recurse into slots (they share the parent's URL path, but may have their own pages)
117
122
  for (const [, slot] of node.slots) {
118
- collectRoutes(slot, params, appDir, routes);
123
+ collectRoutes(slot, params, routes);
119
124
  }
120
125
  }
121
126
 
@@ -134,33 +139,43 @@ function paramTypeForSegment(segmentType: string): ParamEntry['type'] {
134
139
  }
135
140
 
136
141
  /**
137
- * Resolve the absolute directory path for a segment node.
142
+ * Check if a file exports a specific named export.
138
143
  *
139
- * Reconstructs the filesystem path by walking from appDir through
140
- * the segment names encoded in the urlPath, accounting for groups and slots.
144
+ * Uses a lightweight regex check not full AST parsing. The actual type
145
+ * extraction happens via the TypeScript compiler in the generated .d.ts.
141
146
  */
142
- function resolveSegmentDir(appDir: string, node: SegmentNode): string {
143
- // The node's page/route file path gives us the actual directory
144
- const file = node.page ?? node.route;
145
- if (file) {
146
- // The file is in the segment directory — go up one level
147
- const parts = file.filePath.split('/');
148
- parts.pop(); // remove filename
149
- return parts.join('/');
147
+ function fileHasExport(filePath: string, exportName: string): boolean {
148
+ if (!existsSync(filePath)) return false;
149
+ try {
150
+ const content = readFileSync(filePath, 'utf-8');
151
+ const e = exportName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
152
+ return (
153
+ new RegExp(`export\\s+(const|let|var)\\s+${e}\\b`).test(content) ||
154
+ new RegExp(`export\\s*\\{[^}]*\\b${e}\\b[^}]*\\}`).test(content)
155
+ );
156
+ } catch {
157
+ return false;
150
158
  }
151
- // Fallback: construct from urlPath (imprecise for groups, but acceptable)
152
- return appDir;
153
159
  }
154
160
 
155
161
  /**
156
- * Find a search-params.ts file in a directory.
162
+ * Find which file exports `segmentParams` for a dynamic segment.
163
+ *
164
+ * Priority: params.ts (convention file) > layout > page.
165
+ * params.ts is the canonical location (TIM-508). Layout/page fallback
166
+ * exists for backward compat during migration.
157
167
  */
158
- function findSearchParamsFile(dirPath: string): string | undefined {
159
- for (const ext of ['ts', 'tsx']) {
160
- const candidate = join(dirPath, `search-params.${ext}`);
161
- if (existsSync(candidate)) {
162
- return candidate;
163
- }
168
+ function findParamsExport(node: SegmentNode): string | undefined {
169
+ // params.ts convention file primary location
170
+ if (node.params && fileHasExport(node.params.filePath, 'segmentParams')) {
171
+ return node.params.filePath;
172
+ }
173
+ // Fallback: layout or page export (legacy, will be removed)
174
+ if (node.layout && fileHasExport(node.layout.filePath, 'segmentParams')) {
175
+ return node.layout.filePath;
176
+ }
177
+ if (node.page && fileHasExport(node.page.filePath, 'segmentParams')) {
178
+ return node.page.filePath;
164
179
  }
165
180
  return undefined;
166
181
  }
@@ -184,7 +199,7 @@ function formatDeclarationFile(routes: RouteEntry[], importBase?: string): strin
184
199
  lines.push(' interface Routes {');
185
200
 
186
201
  for (const route of routes) {
187
- const paramsType = formatParamsType(route.params);
202
+ const paramsType = formatParamsType(route.params, importBase);
188
203
  const searchParamsType = formatSearchParamsType(route, importBase);
189
204
 
190
205
  lines.push(` '${route.urlPath}': {`);
@@ -200,15 +215,9 @@ function formatDeclarationFile(routes: RouteEntry[], importBase?: string): strin
200
215
  // Generate @timber-js/app/server augmentation — typed searchParams() generic
201
216
  const pageRoutes = routes.filter((r) => !r.isApiRoute);
202
217
 
203
- if (pageRoutes.length > 0) {
204
- lines.push("declare module '@timber-js/app/server' {");
205
- lines.push(" import type { Routes } from '@timber-js/app'");
206
- lines.push(
207
- " export function searchParams<R extends keyof Routes>(): Promise<Routes[R]['searchParams']>"
208
- );
209
- lines.push('}');
210
- lines.push('');
211
- }
218
+ // Note: searchParams() always returns Promise<URLSearchParams>.
219
+ // Typed parsing is done via definition.parse(searchParams()).
220
+ // No module augmentation needed for @timber-js/app/server.
212
221
 
213
222
  // Generate overloads for @timber-js/app/client
214
223
  const dynamicRoutes = routes.filter((r) => r.params.length > 0);
@@ -223,10 +232,10 @@ function formatDeclarationFile(routes: RouteEntry[], importBase?: string): strin
223
232
  // useParams overloads
224
233
  if (dynamicRoutes.length > 0) {
225
234
  for (const route of dynamicRoutes) {
226
- const paramsType = formatParamsType(route.params);
227
- lines.push(` export function useParams(route: '${route.urlPath}'): ${paramsType}`);
235
+ const paramsType = formatParamsType(route.params, importBase);
236
+ lines.push(` export function useSegmentParams(route: '${route.urlPath}'): ${paramsType}`);
228
237
  }
229
- lines.push(' export function useParams(): Record<string, string | string[]>');
238
+ lines.push(' export function useSegmentParams(): Record<string, string | string[]>');
230
239
  lines.push('');
231
240
  }
232
241
 
@@ -252,12 +261,27 @@ function formatDeclarationFile(routes: RouteEntry[], importBase?: string): strin
252
261
  /**
253
262
  * Format the params type for a route entry.
254
263
  */
255
- function formatParamsType(params: ParamEntry[]): string {
264
+ function formatParamsType(params: ParamEntry[], importBase?: string): string {
256
265
  if (params.length === 0) {
257
266
  return '{}';
258
267
  }
259
268
 
260
- const fields = params.map((p) => `${p.name}: ${p.type}`);
269
+ const fields = params.map((p) => {
270
+ if (p.codecFilePath) {
271
+ // Use the codec's inferred type from the layout/page file
272
+ const absPath = p.codecFilePath.replace(/\.(ts|tsx)$/, '');
273
+ let importPath: string;
274
+ if (importBase) {
275
+ importPath = './' + relative(importBase, absPath).replace(/\\/g, '/');
276
+ } else {
277
+ importPath = './' + posix.basename(absPath);
278
+ }
279
+ // Extract T from the 'segmentParams' named export's ParamsDefinition<T>
280
+ const codecType = `(typeof import('${importPath}'))['segmentParams'] extends import('@timber-js/app/params').ParamsDefinition<infer T> ? T[${JSON.stringify(p.name)}] : ${p.type}`;
281
+ return `${p.name}: ${codecType}`;
282
+ }
283
+ return `${p.name}: ${p.type}`;
284
+ });
261
285
  return `{ ${fields.join('; ')} }`;
262
286
  }
263
287
 
@@ -270,12 +294,24 @@ function formatParamsType(params: ParamEntry[]): string {
270
294
  *
271
295
  * See design/07-routing.md §"Typed params and searchParams on <Link>"
272
296
  */
273
- function formatLinkParamsType(params: ParamEntry[]): string {
297
+ function formatLinkParamsType(params: ParamEntry[], importBase?: string): string {
274
298
  if (params.length === 0) {
275
299
  return '{}';
276
300
  }
277
301
 
278
302
  const fields = params.map((p) => {
303
+ if (p.codecFilePath) {
304
+ // With a codec, Link params use the codec's output type
305
+ const absPath = p.codecFilePath.replace(/\.(ts|tsx)$/, '');
306
+ let importPath: string;
307
+ if (importBase) {
308
+ importPath = './' + relative(importBase, absPath).replace(/\\/g, '/');
309
+ } else {
310
+ importPath = './' + posix.basename(absPath);
311
+ }
312
+ const codecType = `(typeof import('${importPath}'))['segmentParams'] extends import('@timber-js/app/params').ParamsDefinition<infer T> ? T[${JSON.stringify(p.name)}] : ${p.type}`;
313
+ return `${p.name}: ${codecType}`;
314
+ }
279
315
  // Single dynamic segments accept string | number for convenience
280
316
  const type = p.type === 'string' ? 'string | number' : p.type;
281
317
  return `${p.name}: ${type}`;
@@ -286,13 +322,13 @@ function formatLinkParamsType(params: ParamEntry[]): string {
286
322
  /**
287
323
  * Format the searchParams type for a route entry.
288
324
  *
289
- * When a search-params.ts exists, we reference its inferred type via an import type.
325
+ * When a page.tsx exports searchParams, we reference its inferred type via an import type.
290
326
  * The import path is relative to `importBase` (the directory where the .d.ts will be
291
327
  * written). When importBase is undefined, falls back to a bare relative path.
292
328
  */
293
329
  function formatSearchParamsType(route: RouteEntry, importBase?: string): string {
294
- if (route.hasSearchParams && route.searchParamsAbsPath) {
295
- const absPath = route.searchParamsAbsPath.replace(/\.(ts|tsx)$/, '');
330
+ if (route.hasSearchParams && route.searchParamsPagePath) {
331
+ const absPath = route.searchParamsPagePath.replace(/\.(ts|tsx)$/, '');
296
332
  let importPath: string;
297
333
  if (importBase) {
298
334
  // Make the path relative to the output directory, converted to posix separators
@@ -300,10 +336,8 @@ function formatSearchParamsType(route: RouteEntry, importBase?: string): string
300
336
  } else {
301
337
  importPath = './' + posix.basename(absPath);
302
338
  }
303
- // Use (typeof import('...'))[' default'] instead of import('...').default
304
- // because with moduleResolution:"bundler", import('...').default is treated as
305
- // a namespace member access which doesn't work for default exports.
306
- return `(typeof import('${importPath}'))['default'] extends import('@timber-js/app/search-params').SearchParamsDefinition<infer T> ? T : never`;
339
+ // Extract the type from the named 'searchParams' export of the page module.
340
+ return `(typeof import('${importPath}'))['searchParams'] extends import('@timber-js/app/search-params').SearchParamsDefinition<infer T> ? T : never`;
307
341
  }
308
342
  return '{}';
309
343
  }
@@ -353,38 +387,25 @@ function formatTypedLinkOverloads(routes: RouteEntry[], importBase?: string): st
353
387
 
354
388
  for (const route of routes) {
355
389
  const hasDynamicParams = route.params.length > 0;
356
- const paramsType = formatLinkParamsType(route.params);
390
+ const paramsProp = hasDynamicParams
391
+ ? `segmentParams: ${formatLinkParamsType(route.params, importBase)}`
392
+ : 'segmentParams?: never';
393
+
357
394
  const searchParamsType = route.hasSearchParams
358
395
  ? formatSearchParamsType(route, importBase)
359
396
  : null;
397
+ const searchParamsProp = searchParamsType
398
+ ? `searchParams?: { definition: SearchParamsDefinition<${searchParamsType}>; values: Partial<${searchParamsType}> }`
399
+ : 'searchParams?: never';
360
400
 
361
- if (hasDynamicParams) {
362
- // Route with dynamic segments params prop required
363
- const spProp = searchParamsType
364
- ? `searchParams?: { definition: SearchParamsDefinition<${searchParamsType}>; values: Partial<${searchParamsType}> }`
365
- : `searchParams?: never`;
366
- lines.push(
367
- ` export function Link(props: Omit<import('react').AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {`
368
- );
369
- lines.push(` href: '${route.urlPath}'`);
370
- lines.push(` params: ${paramsType}`);
371
- lines.push(` ${spProp}`);
372
- lines.push(` prefetch?: boolean; scroll?: boolean; children?: import('react').ReactNode`);
373
- lines.push(` }): import('react').JSX.Element`);
374
- } else {
375
- // Static route — no params needed
376
- const spProp = searchParamsType
377
- ? `searchParams?: { definition: SearchParamsDefinition<${searchParamsType}>; values: Partial<${searchParamsType}> }`
378
- : `searchParams?: never`;
379
- lines.push(
380
- ` export function Link(props: Omit<import('react').AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {`
381
- );
382
- lines.push(` href: '${route.urlPath}'`);
383
- lines.push(` params?: never`);
384
- lines.push(` ${spProp}`);
385
- lines.push(` prefetch?: boolean; scroll?: boolean; children?: import('react').ReactNode`);
386
- lines.push(` }): import('react').JSX.Element`);
387
- }
401
+ lines.push(
402
+ ` export function Link(props: Omit<import('react').AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {`
403
+ );
404
+ lines.push(` href: '${route.urlPath}'`);
405
+ lines.push(` ${paramsProp}`);
406
+ lines.push(` ${searchParamsProp}`);
407
+ lines.push(` prefetch?: boolean; scroll?: boolean; children?: import('react').ReactNode`);
408
+ lines.push(` }): import('react').JSX.Element`);
388
409
  }
389
410
 
390
411
  // Fallback overload for arbitrary string hrefs (escape hatch)
@@ -53,7 +53,7 @@ const LEGACY_STATUS_FILES: Record<string, number> = {
53
53
  /**
54
54
  * File convention names that are always .ts/.tsx (never .mdx etc.)
55
55
  */
56
- const FIXED_CONVENTIONS = new Set(['middleware', 'access', 'route', 'prerender', 'search-params']);
56
+ const FIXED_CONVENTIONS = new Set(['middleware', 'access', 'route', 'params']);
57
57
 
58
58
  /**
59
59
  * Status-code file patterns:
@@ -92,6 +92,10 @@ export function scanRoutes(appDir: string, config: ScannerConfig = {}): RouteTre
92
92
  // Validate: detect route group collisions (different groups producing pages at the same URL)
93
93
  validateRouteGroupCollisions(tree.root);
94
94
 
95
+ // Validate: detect duplicate param names in nested dynamic segments
96
+ // e.g., /[id]/items/[id] — same param name in ancestor and descendant
97
+ validateDuplicateParamNames(tree.root);
98
+
95
99
  return tree;
96
100
  }
97
101
 
@@ -278,11 +282,8 @@ function scanSegmentFiles(dirPath: string, node: SegmentNode, extSet: Set<string
278
282
  case 'route':
279
283
  node.route = file;
280
284
  break;
281
- case 'prerender':
282
- node.prerender = file;
283
- break;
284
- case 'search-params':
285
- node.searchParams = file;
285
+ case 'params':
286
+ node.params = file;
286
287
  break;
287
288
  }
288
289
  continue;
@@ -482,6 +483,54 @@ function collectRoutableLeaves(
482
483
  }
483
484
  }
484
485
 
486
+ /**
487
+ * Validate that no route chain contains duplicate dynamic param names.
488
+ *
489
+ * Example violation:
490
+ * app/[id]/items/[id]/page.tsx — 'id' appears twice in the ancestor chain.
491
+ *
492
+ * Route groups are transparent — params accumulate through them.
493
+ * Slots are independent — duplicate detection does NOT cross slot boundaries.
494
+ *
495
+ * See design/07-routing.md §"Duplicate Param Name Detection"
496
+ */
497
+ function validateDuplicateParamNames(root: SegmentNode): void {
498
+ walkForDuplicateParams(root, new Map());
499
+ }
500
+
501
+ /**
502
+ * Recursively walk the segment tree, tracking seen param names → segment paths.
503
+ * Throws on the first duplicate found.
504
+ */
505
+ function walkForDuplicateParams(node: SegmentNode, seen: Map<string, string>): void {
506
+ // If this node introduces a param name, check for duplicates
507
+ if (node.paramName) {
508
+ const existing = seen.get(node.paramName);
509
+ if (existing) {
510
+ throw new Error(
511
+ `[timber] Duplicate param name '${node.paramName}' in route chain.\n` +
512
+ ` First defined at: ${existing}\n` +
513
+ ` Duplicate at: ${node.urlPath || '/'}\n` +
514
+ ` Rename one of the segments to avoid ambiguity.`
515
+ );
516
+ }
517
+ // Add to seen for descendants (use a new Map to avoid polluting siblings)
518
+ seen = new Map(seen);
519
+ seen.set(node.paramName, node.urlPath || '/');
520
+ }
521
+
522
+ // Recurse into children (they inherit the accumulated params)
523
+ for (const child of node.children) {
524
+ walkForDuplicateParams(child, seen);
525
+ }
526
+
527
+ // Slots are independent parallel routes — start fresh param tracking
528
+ // (a slot's params don't conflict with the main route's params)
529
+ for (const [, slotNode] of node.slots) {
530
+ walkForDuplicateParams(slotNode, new Map(seen));
531
+ }
532
+ }
533
+
485
534
  /**
486
535
  * Find a fixed-extension file (proxy.ts) in a directory.
487
536
  */
@@ -31,7 +31,8 @@ export interface StatusFileLintWarning {
31
31
  * that are missing it.
32
32
  *
33
33
  * MDX and JSON status files are excluded — MDX files are server components
34
- * by design, and JSON files are data, not components.
34
+ * by design (pre-rendered as elements via fallbackElement, see TIM-503),
35
+ * and JSON files are data, not components.
35
36
  */
36
37
  export function lintStatusFileDirectives(tree: RouteTree): StatusFileLintWarning[] {
37
38
  const warnings: StatusFileLintWarning[] = [];
@@ -59,6 +59,12 @@ export interface SegmentNode {
59
59
  middleware?: RouteFile;
60
60
  access?: RouteFile;
61
61
  route?: RouteFile;
62
+ /**
63
+ * params.ts — isomorphic convention file exporting segmentParams and/or searchParams.
64
+ * Discovered by the scanner like middleware.ts and access.ts.
65
+ * See design/07-routing.md §"params.ts Convention File"
66
+ */
67
+ params?: RouteFile;
62
68
  error?: RouteFile;
63
69
  default?: RouteFile;
64
70
  /** Status-code files: 4xx.tsx, 5xx.tsx, {status}.tsx (component format) */
@@ -69,10 +75,7 @@ export interface SegmentNode {
69
75
  denied?: RouteFile;
70
76
  /** Legacy compat: not-found.tsx (maps to 404), forbidden.tsx (403), unauthorized.tsx (401) */
71
77
  legacyStatusFiles?: Map<string, RouteFile>;
72
- /** prerender.ts — signals build-time pre-rendering for this segment's shell */
73
- prerender?: RouteFile;
74
- /** search-params.ts — typed search params definition for this route */
75
- searchParams?: RouteFile;
78
+
76
79
  /** Metadata route files (sitemap.ts, robots.ts, icon.tsx, etc.) keyed by base name */
77
80
  metadataRoutes?: Map<string, RouteFile>;
78
81
 
@@ -16,4 +16,6 @@ export {
16
16
  loadServerAction,
17
17
  decodeReply,
18
18
  decodeAction,
19
+ encryptActionBoundArgs,
20
+ decryptActionBoundArgs,
19
21
  } from '@vitejs/plugin-rsc/rsc';
@@ -11,3 +11,53 @@
11
11
  */
12
12
 
13
13
  export { createFromReadableStream } from '@vitejs/plugin-rsc/ssr';
14
+
15
+ // ─── Node.js Stream Path ─────────────────────────────────────────────────────
16
+ //
17
+ // On Node.js, createFromNodeStream reads RSC Flight data from a Node.js
18
+ // Readable (C++ backed) instead of a Web ReadableStream (JS reimplementation).
19
+ // Eliminates Promise-per-chunk overhead on the SSR decode path.
20
+ //
21
+ // The plugin only exports createFromReadableStream (via client.edge.js).
22
+ // createFromNodeStream lives in the vendored client.node.js. We import it
23
+ // directly and wire up the same serverConsumerManifest the plugin uses.
24
+
25
+ import { createServerConsumerManifest } from '@vitejs/plugin-rsc/ssr';
26
+
27
+ type CreateFromNodeStreamFn = (
28
+ stream: import('node:stream').Readable,
29
+ manifest: ReturnType<typeof createServerConsumerManifest>,
30
+ options?: Record<string, unknown>
31
+ ) => React.ReactNode;
32
+
33
+ let _createFromNodeStream: CreateFromNodeStreamFn | null = null;
34
+
35
+ try {
36
+ if (typeof process !== 'undefined' && process.release?.name === 'node') {
37
+ const clientNode = await import('@vitejs/plugin-rsc/vendor/react-server-dom/client.node');
38
+ if (typeof clientNode.createFromNodeStream === 'function') {
39
+ _createFromNodeStream = clientNode.createFromNodeStream;
40
+ }
41
+ }
42
+ } catch {
43
+ // Not available — fall back to createFromReadableStream
44
+ }
45
+
46
+ /**
47
+ * Decode an RSC Flight stream from a Node.js Readable.
48
+ *
49
+ * Uses the vendored createFromNodeStream which reads via Node.js native
50
+ * streams (C++ libuv) instead of Web ReadableStream (JS Promise per chunk).
51
+ *
52
+ * Returns null if createFromNodeStream isn't available (CF Workers, etc),
53
+ * signaling the caller to use createFromReadableStream instead.
54
+ */
55
+ export function createFromNodeStream(
56
+ stream: import('node:stream').Readable
57
+ ): React.ReactNode | null {
58
+ if (!_createFromNodeStream) return null;
59
+ return _createFromNodeStream(stream, createServerConsumerManifest());
60
+ }
61
+
62
+ /** Whether the Node.js stream RSC decode path is available. */
63
+ export const hasNodeStreamDecode = _createFromNodeStream !== null;
@@ -0,0 +1,7 @@
1
+ declare module '@vitejs/plugin-rsc/vendor/react-server-dom/client.node' {
2
+ export function createFromNodeStream(
3
+ stream: import('node:stream').Readable,
4
+ manifest: unknown,
5
+ options?: Record<string, unknown>
6
+ ): React.ReactNode;
7
+ }
@@ -5,7 +5,7 @@
5
5
  * Design doc: design/09-typescript.md §"The SearchParamCodec Protocol"
6
6
  */
7
7
 
8
- import type { SearchParamCodec } from './create.js';
8
+ import type { SearchParamCodec } from './define.js';
9
9
 
10
10
  // ---------------------------------------------------------------------------
11
11
  // Standard Schema interface (subset)