@timber-js/app 0.2.0-alpha.185 → 0.2.0-alpha.186

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 (418) hide show
  1. package/dist/_chunks/{actions-O_LsyCE4.js → actions-C-Rw9vPc.js} +3 -3
  2. package/dist/_chunks/{actions-O_LsyCE4.js.map → actions-C-Rw9vPc.js.map} +1 -1
  3. package/dist/_chunks/als-slots-mFweg276.js +27 -0
  4. package/dist/_chunks/als-slots-mFweg276.js.map +1 -0
  5. package/dist/_chunks/base-path-DaQrzbez.js +80 -0
  6. package/dist/_chunks/base-path-DaQrzbez.js.map +1 -0
  7. package/dist/_chunks/build-manifest-DWppEdLB.js +86 -0
  8. package/dist/_chunks/build-manifest-DWppEdLB.js.map +1 -0
  9. package/dist/_chunks/build-output-helper-C3DrfzZR.js +369 -0
  10. package/dist/_chunks/build-output-helper-C3DrfzZR.js.map +1 -0
  11. package/dist/_chunks/{cache-api-B-lhk9p4.js → cache-api-Cd0VZ_Pd.js} +3 -3
  12. package/dist/_chunks/{cache-api-B-lhk9p4.js.map → cache-api-Cd0VZ_Pd.js.map} +1 -1
  13. package/dist/_chunks/cli-schema-sync-CKgHC2MB.js +1857 -0
  14. package/dist/_chunks/cli-schema-sync-CKgHC2MB.js.map +1 -0
  15. package/dist/_chunks/{cloudflare-CnT5Lr7U.js → cloudflare-Cs0uZXea.js} +89 -12
  16. package/dist/_chunks/{cloudflare-CnT5Lr7U.js.map → cloudflare-Cs0uZXea.js.map} +1 -1
  17. package/dist/_chunks/error-boundary-DpYRI_I1.js +330 -0
  18. package/dist/_chunks/error-boundary-DpYRI_I1.js.map +1 -0
  19. package/dist/_chunks/{fast-hash-D6hIVt1Y.js → fast-hash-C-tVYrLb.js} +6 -1
  20. package/dist/_chunks/fast-hash-C-tVYrLb.js.map +1 -0
  21. package/dist/_chunks/fs-identity-D7vb6GdI.js +208 -0
  22. package/dist/_chunks/fs-identity-D7vb6GdI.js.map +1 -0
  23. package/dist/_chunks/{logger-AWfuX-KJ.js → logger-N7e5auP0.js} +9 -13
  24. package/dist/_chunks/logger-N7e5auP0.js.map +1 -0
  25. package/dist/_chunks/navigation-root-B29qg0_T.js +274 -0
  26. package/dist/_chunks/navigation-root-B29qg0_T.js.map +1 -0
  27. package/dist/_chunks/param-value-C8TNYchQ.js +66 -0
  28. package/dist/_chunks/param-value-C8TNYchQ.js.map +1 -0
  29. package/dist/_chunks/{plugin-context---kTF5v8.js → plugin-context-DEGLSJs3.js} +2 -1
  30. package/dist/_chunks/plugin-context-DEGLSJs3.js.map +1 -0
  31. package/dist/_chunks/{router-ref-CtmF-aPv.js → router-ref-DuYuV_0Q.js} +2 -2
  32. package/dist/_chunks/router-ref-DuYuV_0Q.js.map +1 -0
  33. package/dist/_chunks/rsc-cache-key-DD0fl_-s.js +243 -0
  34. package/dist/_chunks/rsc-cache-key-DD0fl_-s.js.map +1 -0
  35. package/dist/_chunks/rsc-error-envelope-tT5PJs4q.js +40 -0
  36. package/dist/_chunks/rsc-error-envelope-tT5PJs4q.js.map +1 -0
  37. package/dist/_chunks/rsc-payload-path-B_LBodc2.js +48 -0
  38. package/dist/_chunks/rsc-payload-path-B_LBodc2.js.map +1 -0
  39. package/dist/_chunks/{segment-classify-Byy425ng.js → segment-classify-C539Pa2O.js} +23 -2
  40. package/dist/_chunks/{segment-classify-Byy425ng.js.map → segment-classify-C539Pa2O.js.map} +1 -1
  41. package/dist/_chunks/{canonicalize-DQHyFClh.js → segment-keys-BawYuNFO.js} +61 -2
  42. package/dist/_chunks/segment-keys-BawYuNFO.js.map +1 -0
  43. package/dist/_chunks/slot-params-BCTmZkQB.js +76 -0
  44. package/dist/_chunks/slot-params-BCTmZkQB.js.map +1 -0
  45. package/dist/_chunks/{ssr-data-BOWsq18U.js → ssr-data-14MXm7Pj.js} +17 -2
  46. package/dist/_chunks/ssr-data-14MXm7Pj.js.map +1 -0
  47. package/dist/_chunks/use-segment-params-ClyUNq4d.js +128 -0
  48. package/dist/_chunks/use-segment-params-ClyUNq4d.js.map +1 -0
  49. package/dist/_chunks/{walkers-_6zKFlch.js → walkers-BhhwI9TD.js} +21 -87
  50. package/dist/_chunks/walkers-BhhwI9TD.js.map +1 -0
  51. package/dist/adapters/build-output-helper.d.ts +37 -0
  52. package/dist/adapters/build-output-helper.d.ts.map +1 -1
  53. package/dist/adapters/cloudflare-dev.js +1 -1
  54. package/dist/adapters/cloudflare-kv-cache.js +1 -1
  55. package/dist/adapters/cloudflare.d.ts.map +1 -1
  56. package/dist/adapters/cloudflare.js +1 -1
  57. package/dist/adapters/fs-identity.d.ts +64 -0
  58. package/dist/adapters/fs-identity.d.ts.map +1 -0
  59. package/dist/adapters/nitro.d.ts.map +1 -1
  60. package/dist/adapters/nitro.js +2 -3
  61. package/dist/adapters/nitro.js.map +1 -1
  62. package/dist/adapters/shared.d.ts +57 -1
  63. package/dist/adapters/shared.d.ts.map +1 -1
  64. package/dist/adapters/types.d.ts +13 -1
  65. package/dist/adapters/types.d.ts.map +1 -1
  66. package/dist/cache/fast-hash.d.ts +5 -0
  67. package/dist/cache/fast-hash.d.ts.map +1 -1
  68. package/dist/cache/index.js +1 -1
  69. package/dist/cli.js +2 -2
  70. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -1
  71. package/dist/client/browser-entry/hydrate.d.ts +20 -9
  72. package/dist/client/browser-entry/hydrate.d.ts.map +1 -1
  73. package/dist/client/browser-entry/post-hydration.d.ts +4 -1
  74. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -1
  75. package/dist/client/browser-entry/router-init.d.ts +3 -0
  76. package/dist/client/browser-entry/router-init.d.ts.map +1 -1
  77. package/dist/client/browser-entry/rsc-stream.d.ts +8 -0
  78. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -1
  79. package/dist/client/error-boundary.d.ts +1 -0
  80. package/dist/client/error-boundary.d.ts.map +1 -1
  81. package/dist/client/error-boundary.js +1 -162
  82. package/dist/client/history.d.ts +13 -6
  83. package/dist/client/history.d.ts.map +1 -1
  84. package/dist/client/index.js +18 -11
  85. package/dist/client/index.js.map +1 -1
  86. package/dist/client/internal.d.ts +4 -3
  87. package/dist/client/internal.d.ts.map +1 -1
  88. package/dist/client/internal.js +865 -306
  89. package/dist/client/internal.js.map +1 -1
  90. package/dist/client/link.d.ts.map +1 -1
  91. package/dist/client/navigation-api.d.ts +2 -2
  92. package/dist/client/navigation-commit.d.ts +71 -0
  93. package/dist/client/navigation-commit.d.ts.map +1 -0
  94. package/dist/client/navigation-context.d.ts +37 -20
  95. package/dist/client/navigation-context.d.ts.map +1 -1
  96. package/dist/client/navigation-root.d.ts +63 -23
  97. package/dist/client/navigation-root.d.ts.map +1 -1
  98. package/dist/client/params-context.d.ts +81 -0
  99. package/dist/client/params-context.d.ts.map +1 -0
  100. package/dist/client/router-effects.d.ts +129 -0
  101. package/dist/client/router-effects.d.ts.map +1 -0
  102. package/dist/client/router-lifecycle.d.ts +55 -0
  103. package/dist/client/router-lifecycle.d.ts.map +1 -0
  104. package/dist/client/router-pipeline.d.ts +84 -0
  105. package/dist/client/router-pipeline.d.ts.map +1 -0
  106. package/dist/client/router-ref.d.ts +1 -1
  107. package/dist/client/router-ref.d.ts.map +1 -1
  108. package/dist/client/router-skew.d.ts +21 -0
  109. package/dist/client/router-skew.d.ts.map +1 -0
  110. package/dist/client/router-types.d.ts +207 -0
  111. package/dist/client/router-types.d.ts.map +1 -0
  112. package/dist/client/router.d.ts +1 -182
  113. package/dist/client/router.d.ts.map +1 -1
  114. package/dist/client/rsc-fetch.d.ts +38 -25
  115. package/dist/client/rsc-fetch.d.ts.map +1 -1
  116. package/dist/client/segment-cache.d.ts +79 -34
  117. package/dist/client/segment-cache.d.ts.map +1 -1
  118. package/dist/client/ssr-data.d.ts +6 -0
  119. package/dist/client/ssr-data.d.ts.map +1 -1
  120. package/dist/client/stale-client.d.ts +69 -0
  121. package/dist/client/stale-client.d.ts.map +1 -0
  122. package/dist/client/state.d.ts +10 -1
  123. package/dist/client/state.d.ts.map +1 -1
  124. package/dist/client/top-loader.d.ts +2 -1
  125. package/dist/client/top-loader.d.ts.map +1 -1
  126. package/dist/client/unload-guard.d.ts +5 -0
  127. package/dist/client/unload-guard.d.ts.map +1 -1
  128. package/dist/client/use-cookie.d.ts.map +1 -1
  129. package/dist/client/use-router.d.ts +1 -1
  130. package/dist/client/use-segment-params.d.ts +18 -8
  131. package/dist/client/use-segment-params.d.ts.map +1 -1
  132. package/dist/cookies/index.js +3 -3
  133. package/dist/cookies/index.js.map +1 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +906 -321
  136. package/dist/index.js.map +1 -1
  137. package/dist/plugin-context.d.ts +31 -0
  138. package/dist/plugin-context.d.ts.map +1 -1
  139. package/dist/plugins/adapter-build.d.ts.map +1 -1
  140. package/dist/plugins/build-manifest.d.ts +1 -1
  141. package/dist/plugins/build-manifest.d.ts.map +1 -1
  142. package/dist/plugins/entries.d.ts.map +1 -1
  143. package/dist/plugins/fonts.d.ts.map +1 -1
  144. package/dist/plugins/request-dep/analysis.d.ts +106 -0
  145. package/dist/plugins/request-dep/analysis.d.ts.map +1 -0
  146. package/dist/plugins/request-dep/index.d.ts +75 -0
  147. package/dist/plugins/request-dep/index.d.ts.map +1 -0
  148. package/dist/plugins/request-dep/origin.d.ts +61 -0
  149. package/dist/plugins/request-dep/origin.d.ts.map +1 -0
  150. package/dist/plugins/routing.d.ts +9 -0
  151. package/dist/plugins/routing.d.ts.map +1 -1
  152. package/dist/plugins/static-build.d.ts +136 -8
  153. package/dist/plugins/static-build.d.ts.map +1 -1
  154. package/dist/routing/codegen-types.d.ts +18 -0
  155. package/dist/routing/codegen-types.d.ts.map +1 -1
  156. package/dist/routing/codegen.d.ts.map +1 -1
  157. package/dist/routing/collision-probe.d.ts +104 -0
  158. package/dist/routing/collision-probe.d.ts.map +1 -0
  159. package/dist/routing/collision-spaces.d.ts +26 -0
  160. package/dist/routing/collision-spaces.d.ts.map +1 -0
  161. package/dist/routing/index.js +3 -3
  162. package/dist/routing/interception.d.ts +235 -6
  163. package/dist/routing/interception.d.ts.map +1 -1
  164. package/dist/routing/manifest-codegen.d.ts.map +1 -1
  165. package/dist/routing/scanner.d.ts.map +1 -1
  166. package/dist/routing/segment-classify.d.ts +33 -0
  167. package/dist/routing/segment-classify.d.ts.map +1 -1
  168. package/dist/routing/segment-keys.d.ts +95 -0
  169. package/dist/routing/segment-keys.d.ts.map +1 -0
  170. package/dist/routing/slot-placement.d.ts +48 -0
  171. package/dist/routing/slot-placement.d.ts.map +1 -0
  172. package/dist/routing/walkers.d.ts +6 -0
  173. package/dist/routing/walkers.d.ts.map +1 -1
  174. package/dist/search-params/define.d.ts +0 -6
  175. package/dist/search-params/define.d.ts.map +1 -1
  176. package/dist/search-params/index.js +176 -2
  177. package/dist/search-params/index.js.map +1 -1
  178. package/dist/segment-params/define.d.ts +0 -6
  179. package/dist/segment-params/define.d.ts.map +1 -1
  180. package/dist/segment-params/index.js +69 -1
  181. package/dist/segment-params/index.js.map +1 -0
  182. package/dist/server/actions.d.ts +6 -3
  183. package/dist/server/actions.d.ts.map +1 -1
  184. package/dist/server/als-registry.d.ts +2 -1
  185. package/dist/server/als-registry.d.ts.map +1 -1
  186. package/dist/server/build-manifest.d.ts +13 -1
  187. package/dist/server/build-manifest.d.ts.map +1 -1
  188. package/dist/server/chain-url-parts.d.ts +82 -0
  189. package/dist/server/chain-url-parts.d.ts.map +1 -0
  190. package/dist/server/children-interception.d.ts +49 -0
  191. package/dist/server/children-interception.d.ts.map +1 -0
  192. package/dist/server/default-status-page.d.ts +45 -0
  193. package/dist/server/default-status-page.d.ts.map +1 -0
  194. package/dist/server/deny-renderer.d.ts +14 -3
  195. package/dist/server/deny-renderer.d.ts.map +1 -1
  196. package/dist/server/head-response.d.ts +35 -0
  197. package/dist/server/head-response.d.ts.map +1 -0
  198. package/dist/server/index.js +2 -2
  199. package/dist/server/internal.js +393 -212
  200. package/dist/server/internal.js.map +1 -1
  201. package/dist/server/param-coercion.d.ts +10 -1
  202. package/dist/server/param-coercion.d.ts.map +1 -1
  203. package/dist/server/pipeline-helpers.d.ts +0 -18
  204. package/dist/server/pipeline-helpers.d.ts.map +1 -1
  205. package/dist/server/pipeline-interception.d.ts +59 -9
  206. package/dist/server/pipeline-interception.d.ts.map +1 -1
  207. package/dist/server/pipeline-outcome.d.ts.map +1 -1
  208. package/dist/server/pipeline-phases.d.ts.map +1 -1
  209. package/dist/server/pipeline.d.ts +11 -0
  210. package/dist/server/pipeline.d.ts.map +1 -1
  211. package/dist/server/publish-params.d.ts +33 -0
  212. package/dist/server/publish-params.d.ts.map +1 -0
  213. package/dist/server/request-context.d.ts +48 -0
  214. package/dist/server/request-context.d.ts.map +1 -1
  215. package/dist/server/route-element-builder.d.ts +32 -2
  216. package/dist/server/route-element-builder.d.ts.map +1 -1
  217. package/dist/server/route-handler.d.ts.map +1 -1
  218. package/dist/server/route-matcher.d.ts +13 -0
  219. package/dist/server/route-matcher.d.ts.map +1 -1
  220. package/dist/server/rsc-cache-key-guard.d.ts +78 -0
  221. package/dist/server/rsc-cache-key-guard.d.ts.map +1 -0
  222. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  223. package/dist/server/rsc-entry/error-renderer.d.ts +14 -2
  224. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  225. package/dist/server/rsc-entry/helpers.d.ts +2 -10
  226. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  227. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  228. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  229. package/dist/server/rsc-entry/rsc-payload.d.ts +3 -2
  230. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  231. package/dist/server/rsc-entry/rsc-stream.d.ts +3 -2
  232. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  233. package/dist/server/rsc-entry/ssr-renderer.d.ts +2 -0
  234. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  235. package/dist/server/skippable-prefix.d.ts +23 -0
  236. package/dist/server/skippable-prefix.d.ts.map +1 -0
  237. package/dist/server/slot-interception.d.ts +80 -0
  238. package/dist/server/slot-interception.d.ts.map +1 -0
  239. package/dist/server/slot-resolver.d.ts +70 -8
  240. package/dist/server/slot-resolver.d.ts.map +1 -1
  241. package/dist/server/ssr-bridge-types.d.ts +6 -0
  242. package/dist/server/ssr-bridge-types.d.ts.map +1 -1
  243. package/dist/server/ssr-entry.d.ts.map +1 -1
  244. package/dist/server/ssr-wrappers.d.ts +24 -13
  245. package/dist/server/ssr-wrappers.d.ts.map +1 -1
  246. package/dist/server/state-tree-diff.d.ts +6 -27
  247. package/dist/server/state-tree-diff.d.ts.map +1 -1
  248. package/dist/server/static-generator.d.ts +6 -0
  249. package/dist/server/static-generator.d.ts.map +1 -1
  250. package/dist/server/static-not-found.d.ts +52 -0
  251. package/dist/server/static-not-found.d.ts.map +1 -0
  252. package/dist/shared/als-slots.d.ts +41 -0
  253. package/dist/shared/als-slots.d.ts.map +1 -0
  254. package/dist/shared/base-path.d.ts +56 -0
  255. package/dist/shared/base-path.d.ts.map +1 -0
  256. package/dist/shared/param-value.d.ts +80 -0
  257. package/dist/shared/param-value.d.ts.map +1 -0
  258. package/dist/shared/payload-root.d.ts +108 -0
  259. package/dist/shared/payload-root.d.ts.map +1 -0
  260. package/dist/shared/rsc-cache-key.d.ts +163 -0
  261. package/dist/shared/rsc-cache-key.d.ts.map +1 -0
  262. package/dist/shared/rsc-error-envelope.d.ts +25 -0
  263. package/dist/shared/rsc-error-envelope.d.ts.map +1 -0
  264. package/dist/shared/rsc-manifest.d.ts +28 -0
  265. package/dist/shared/rsc-manifest.d.ts.map +1 -0
  266. package/dist/shared/rsc-payload-path.d.ts +42 -0
  267. package/dist/shared/rsc-payload-path.d.ts.map +1 -0
  268. package/dist/shared/segment-info.d.ts +59 -0
  269. package/dist/shared/segment-info.d.ts.map +1 -0
  270. package/dist/shared/slot-params.d.ts +51 -0
  271. package/dist/shared/slot-params.d.ts.map +1 -0
  272. package/dist/shared/static-platform-files.d.ts +71 -0
  273. package/dist/shared/static-platform-files.d.ts.map +1 -0
  274. package/docs/api/31-api-client.mdx +4 -2
  275. package/docs/learn/02-pages-and-layouts.mdx +1 -1
  276. package/docs/learn/11-error-handling.mdx +2 -0
  277. package/docs/learn/12-client-navigation.mdx +2 -2
  278. package/docs/learn/14-deploying.mdx +23 -0
  279. package/docs/more/01-advanced-routing.mdx +172 -2
  280. package/docs/more/04-metadata-and-fonts.mdx +1 -1
  281. package/package.json +2 -2
  282. package/src/adapters/build-output-helper.ts +116 -3
  283. package/src/adapters/cloudflare.ts +86 -11
  284. package/src/adapters/fs-identity.ts +156 -0
  285. package/src/adapters/nitro.ts +6 -6
  286. package/src/adapters/shared.ts +196 -21
  287. package/src/adapters/types.ts +13 -1
  288. package/src/cache/fast-hash.ts +5 -0
  289. package/src/client/browser-entry/action-dispatch.ts +9 -4
  290. package/src/client/browser-entry/hydrate.ts +40 -29
  291. package/src/client/browser-entry/index.ts +15 -1
  292. package/src/client/browser-entry/post-hydration.ts +10 -9
  293. package/src/client/browser-entry/router-init.ts +104 -48
  294. package/src/client/browser-entry/rsc-stream.ts +11 -2
  295. package/src/client/error-boundary.tsx +20 -15
  296. package/src/client/history.ts +13 -6
  297. package/src/client/internal.ts +4 -3
  298. package/src/client/link.tsx +55 -8
  299. package/src/client/navigation-api.ts +3 -3
  300. package/src/client/navigation-commit.ts +174 -0
  301. package/src/client/navigation-context.ts +40 -67
  302. package/src/client/navigation-root.tsx +326 -101
  303. package/src/client/params-context.ts +192 -0
  304. package/src/client/router-effects.ts +231 -0
  305. package/src/client/router-lifecycle.ts +288 -0
  306. package/src/client/router-pipeline.ts +389 -0
  307. package/src/client/router-ref.ts +1 -1
  308. package/src/client/router-skew.ts +30 -0
  309. package/src/client/router-types.ts +230 -0
  310. package/src/client/router.ts +242 -707
  311. package/src/client/rsc-fetch.ts +169 -102
  312. package/src/client/segment-cache.ts +121 -44
  313. package/src/client/ssr-data.ts +6 -0
  314. package/src/client/stale-client.ts +191 -0
  315. package/src/client/state.ts +14 -1
  316. package/src/client/top-loader.tsx +2 -1
  317. package/src/client/unload-guard.ts +34 -2
  318. package/src/client/use-cookie.ts +9 -2
  319. package/src/client/use-router.ts +1 -1
  320. package/src/client/use-segment-params.ts +41 -18
  321. package/src/index.ts +5 -1
  322. package/src/plugin-context.ts +32 -0
  323. package/src/plugins/adapter-build.ts +4 -0
  324. package/src/plugins/build-manifest.ts +34 -13
  325. package/src/plugins/entries.ts +4 -0
  326. package/src/plugins/fonts.ts +11 -8
  327. package/src/plugins/request-dep/analysis.ts +447 -0
  328. package/src/plugins/request-dep/index.ts +376 -0
  329. package/src/plugins/request-dep/origin.ts +310 -0
  330. package/src/plugins/routing.ts +59 -2
  331. package/src/plugins/static-build.ts +315 -73
  332. package/src/routing/codegen-types.ts +18 -0
  333. package/src/routing/codegen.ts +50 -10
  334. package/src/routing/collision-probe.ts +438 -0
  335. package/src/routing/collision-spaces.ts +281 -0
  336. package/src/routing/interception.ts +896 -50
  337. package/src/routing/manifest-codegen.ts +5 -3
  338. package/src/routing/scanner.ts +114 -89
  339. package/src/routing/segment-classify.ts +57 -0
  340. package/src/routing/segment-keys.ts +146 -0
  341. package/src/routing/slot-placement.ts +97 -0
  342. package/src/routing/walkers.ts +8 -0
  343. package/src/search-params/define.ts +6 -29
  344. package/src/segment-params/define.ts +4 -27
  345. package/src/server/action-handler.ts +3 -1
  346. package/src/server/actions.ts +6 -3
  347. package/src/server/als-registry.ts +2 -1
  348. package/src/server/build-manifest.ts +14 -1
  349. package/src/server/chain-url-parts.ts +163 -0
  350. package/src/server/children-interception.ts +115 -0
  351. package/src/server/default-status-page.ts +127 -0
  352. package/src/server/deny-renderer.ts +81 -20
  353. package/src/server/head-response.ts +54 -0
  354. package/src/server/param-coercion.ts +48 -18
  355. package/src/server/pipeline-helpers.ts +0 -45
  356. package/src/server/pipeline-interception.ts +81 -32
  357. package/src/server/pipeline-outcome.ts +2 -4
  358. package/src/server/pipeline-phases.ts +68 -16
  359. package/src/server/pipeline.ts +57 -10
  360. package/src/server/prebuilt-runtime.ts +4 -4
  361. package/src/server/publish-params.ts +42 -0
  362. package/src/server/request-context.ts +97 -18
  363. package/src/server/route-element-builder.ts +89 -98
  364. package/src/server/route-handler.ts +8 -8
  365. package/src/server/route-matcher.ts +21 -9
  366. package/src/server/rsc-cache-key-guard.ts +170 -0
  367. package/src/server/rsc-entry/api-handler.ts +6 -8
  368. package/src/server/rsc-entry/error-renderer.ts +64 -25
  369. package/src/server/rsc-entry/helpers.ts +31 -16
  370. package/src/server/rsc-entry/index.ts +36 -28
  371. package/src/server/rsc-entry/render-route.ts +9 -4
  372. package/src/server/rsc-entry/revalidate-renderer.ts +1 -1
  373. package/src/server/rsc-entry/rsc-payload.ts +14 -25
  374. package/src/server/rsc-entry/rsc-stream.ts +4 -3
  375. package/src/server/rsc-entry/ssr-renderer.ts +13 -9
  376. package/src/server/skippable-prefix.ts +92 -0
  377. package/src/server/slot-interception.ts +168 -0
  378. package/src/server/slot-resolver.ts +253 -156
  379. package/src/server/ssr-bridge-types.ts +6 -0
  380. package/src/server/ssr-entry.ts +12 -4
  381. package/src/server/ssr-wrappers.tsx +33 -32
  382. package/src/server/state-tree-diff.ts +14 -55
  383. package/src/server/static-generator.ts +65 -27
  384. package/src/server/static-not-found.ts +134 -0
  385. package/src/shared/als-slots.ts +72 -0
  386. package/src/shared/base-path.ts +80 -0
  387. package/src/shared/param-value.ts +244 -0
  388. package/src/shared/payload-root.ts +151 -0
  389. package/src/shared/rsc-cache-key.ts +269 -0
  390. package/src/shared/rsc-error-envelope.ts +31 -0
  391. package/src/shared/rsc-manifest.ts +29 -0
  392. package/src/shared/rsc-payload-path.ts +45 -0
  393. package/src/shared/segment-info.ts +60 -0
  394. package/src/shared/slot-params.ts +111 -0
  395. package/src/shared/static-platform-files.ts +75 -0
  396. package/dist/_chunks/build-output-helper-DOGYFb_X.js +0 -196
  397. package/dist/_chunks/build-output-helper-DOGYFb_X.js.map +0 -1
  398. package/dist/_chunks/canonicalize-DQHyFClh.js.map +0 -1
  399. package/dist/_chunks/cli-schema-sync-BTWEKJXo.js +0 -668
  400. package/dist/_chunks/cli-schema-sync-BTWEKJXo.js.map +0 -1
  401. package/dist/_chunks/define-COtkxMRT.js +0 -191
  402. package/dist/_chunks/define-COtkxMRT.js.map +0 -1
  403. package/dist/_chunks/define-c4au4I9R.js +0 -82
  404. package/dist/_chunks/define-c4au4I9R.js.map +0 -1
  405. package/dist/_chunks/fast-hash-D6hIVt1Y.js.map +0 -1
  406. package/dist/_chunks/logger-AWfuX-KJ.js.map +0 -1
  407. package/dist/_chunks/navigation-root-bUDZLw74.js +0 -124
  408. package/dist/_chunks/navigation-root-bUDZLw74.js.map +0 -1
  409. package/dist/_chunks/plugin-context---kTF5v8.js.map +0 -1
  410. package/dist/_chunks/router-ref-CtmF-aPv.js.map +0 -1
  411. package/dist/_chunks/ssr-data-BOWsq18U.js.map +0 -1
  412. package/dist/_chunks/use-segment-params-D1CzlgBo.js +0 -151
  413. package/dist/_chunks/use-segment-params-D1CzlgBo.js.map +0 -1
  414. package/dist/_chunks/walkers-_6zKFlch.js.map +0 -1
  415. package/dist/client/error-boundary.js.map +0 -1
  416. package/dist/plugins/request-dep.d.ts +0 -32
  417. package/dist/plugins/request-dep.d.ts.map +0 -1
  418. package/src/plugins/request-dep.ts +0 -499
@@ -1,668 +0,0 @@
1
- import { o as __exportAll } from "./dist-BA3u1z3W.js";
2
- import { a as classifyMetadataRoute, c as isDynamicMetadataExtension, n as NULL_BYTE_RE, t as ENCODED_SEPARATOR_RE } from "./canonicalize-DQHyFClh.js";
3
- import { r as DEFAULT_PAGE_EXTENSIONS, t as classifySegment } from "./segment-classify-Byy425ng.js";
4
- import { h as swallow } from "./logger-AWfuX-KJ.js";
5
- import { a as resolveAppDir } from "./plugin-context---kTF5v8.js";
6
- import { basename, extname, join } from "node:path";
7
- import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
8
- //#region src/routing/scanner.ts
9
- /**
10
- * Route discovery scanner.
11
- *
12
- * Pure function: (appDir, config) → RouteTree
13
- *
14
- * Scans the app/ directory and builds a segment tree recognizing all
15
- * timber.js file conventions. Does NOT handle request matching — this
16
- * is discovery only.
17
- */
18
- /**
19
- * File convention names that use pageExtensions (can be .tsx, .ts, .jsx, .js, .mdx, etc.)
20
- */
21
- var PAGE_EXT_CONVENTIONS = /* @__PURE__ */ new Set([
22
- "page",
23
- "layout",
24
- "error",
25
- "default",
26
- "denied"
27
- ]);
28
- /**
29
- * File convention names that are always .ts/.tsx (never .mdx etc.)
30
- */
31
- var FIXED_CONVENTIONS = /* @__PURE__ */ new Set([
32
- "middleware",
33
- "access",
34
- "route",
35
- "params"
36
- ]);
37
- /**
38
- * Status-code file patterns:
39
- * - Exact 3-digit codes: 401.tsx, 429.tsx, 503.tsx
40
- * - Category catch-alls: 4xx.tsx, 5xx.tsx
41
- */
42
- var STATUS_CODE_PATTERN = /^(\d{3}|[45]xx)$/;
43
- /**
44
- * Scan the app/ directory and build the route tree.
45
- *
46
- * @param appDir - Absolute path to the app/ directory
47
- * @param config - Scanner configuration
48
- * @returns The complete route tree
49
- */
50
- function scanRoutes(appDir, config = {}) {
51
- const pageExtensions = config.pageExtensions ?? DEFAULT_PAGE_EXTENSIONS;
52
- const extSet = new Set(pageExtensions);
53
- const tree = { root: createSegmentNode("", "static", "/") };
54
- const proxyFile = findFixedFile(appDir, "proxy");
55
- if (proxyFile) tree.proxy = proxyFile;
56
- const globalErrorFile = findPageExtFile(appDir, "global-error", extSet);
57
- if (globalErrorFile) tree.globalError = globalErrorFile;
58
- scanSegmentFiles(appDir, tree.root, extSet);
59
- scanChildren(appDir, tree.root, extSet);
60
- validateRouteGroupCollisions(tree.root);
61
- validateDuplicateParamNames(tree.root);
62
- validateUniqueBracketForms(tree.root);
63
- validateAffixedSiblingConflicts(tree.root);
64
- return tree;
65
- }
66
- /**
67
- * Create an empty segment node.
68
- */
69
- function createSegmentNode(segmentName, segmentType, urlPath, paramName, interceptionMarker, interceptedSegmentName, paramPrefix, paramSuffix) {
70
- return {
71
- segmentName,
72
- segmentType,
73
- urlPath,
74
- paramName,
75
- paramPrefix,
76
- paramSuffix,
77
- interceptionMarker,
78
- interceptedSegmentName,
79
- children: [],
80
- slots: {}
81
- };
82
- }
83
- /**
84
- * Compute the URL path for a child segment given its parent's URL path.
85
- * Route groups, slots, and intercepting routes do NOT add URL depth.
86
- */
87
- function computeUrlPath(parentUrlPath, dirName, segmentType) {
88
- if (segmentType === "group" || segmentType === "slot" || segmentType === "intercepting") return parentUrlPath;
89
- return `${parentUrlPath === "/" ? "" : parentUrlPath}/${dirName}`;
90
- }
91
- /**
92
- * Scan a directory for file conventions and populate the segment node.
93
- */
94
- function scanSegmentFiles(dirPath, node, extSet) {
95
- let entries;
96
- try {
97
- entries = readdirSync(dirPath);
98
- } catch (err) {
99
- swallow(err, `scanSegmentFiles: unreadable directory ${dirPath}`, { level: "warn" });
100
- return;
101
- }
102
- for (const entry of entries) {
103
- const fullPath = join(dirPath, entry);
104
- try {
105
- if (statSync(fullPath).isDirectory()) continue;
106
- } catch {
107
- continue;
108
- }
109
- const ext = extname(entry).slice(1);
110
- const name = basename(entry, `.${ext}`);
111
- if (PAGE_EXT_CONVENTIONS.has(name) && extSet.has(ext)) {
112
- const key = name;
113
- const existing = node[key];
114
- if (existing) throwDuplicateConvention(name, existing.filePath, fullPath);
115
- node[key] = {
116
- filePath: fullPath,
117
- extension: ext
118
- };
119
- continue;
120
- }
121
- if (FIXED_CONVENTIONS.has(name) && /^[jt]sx?$/.test(ext)) {
122
- const key = name;
123
- const existing = node[key];
124
- if (existing) throwDuplicateConvention(name, existing.filePath, fullPath);
125
- node[key] = {
126
- filePath: fullPath,
127
- extension: ext
128
- };
129
- continue;
130
- }
131
- if (STATUS_CODE_PATTERN.test(name) && ext === "json") {
132
- if (!node.jsonStatusFiles) node.jsonStatusFiles = {};
133
- node.jsonStatusFiles[name] = {
134
- filePath: fullPath,
135
- extension: ext
136
- };
137
- continue;
138
- }
139
- if (STATUS_CODE_PATTERN.test(name) && extSet.has(ext)) {
140
- if (!node.statusFiles) node.statusFiles = {};
141
- const existing = node.statusFiles[name];
142
- if (existing) throwDuplicateConvention(name, existing.filePath, fullPath);
143
- node.statusFiles[name] = {
144
- filePath: fullPath,
145
- extension: ext
146
- };
147
- continue;
148
- }
149
- const metaInfo = classifyMetadataRoute(entry);
150
- if (metaInfo) {
151
- if (!metaInfo.nestable && node.segmentName !== "") throw new Error(`Build error: '${name}' is a root-only metadata convention and must be in the app root directory.\n File: ${fullPath}\n Move this file to the app root (not a route group or nested segment).`);
152
- if (!node.metadataRoutes) node.metadataRoutes = {};
153
- const existing = node.metadataRoutes[name];
154
- if (existing) {
155
- const existingIsDynamic = isDynamicMetadataExtension(name, existing.extension);
156
- const newIsDynamic = isDynamicMetadataExtension(name, ext);
157
- if (existingIsDynamic === newIsDynamic) throwDuplicateConvention(name, existing.filePath, fullPath);
158
- if (newIsDynamic) node.metadataRoutes[name] = {
159
- filePath: fullPath,
160
- extension: ext
161
- };
162
- } else node.metadataRoutes[name] = {
163
- filePath: fullPath,
164
- extension: ext
165
- };
166
- }
167
- }
168
- if (node.route && node.page) throw new Error(`Build error: route.ts and page.* cannot coexist in the same segment.\n route.ts: ${node.route.filePath}\n page: ${node.page.filePath}\nA URL is either an API endpoint or a rendered page, not both.`);
169
- }
170
- /**
171
- * Throw a build error for two files claiming the same convention slot in
172
- * one segment (e.g. page.tsx + page.jsx). Which file readdir returns first
173
- * is platform-dependent (APFS sorts entries, ext4 does not) — silently
174
- * picking one would let macOS dev and Linux CI serve different
175
- * implementations of the same route.
176
- */
177
- function throwDuplicateConvention(convention, firstPath, secondPath) {
178
- throw new Error(`Build error: duplicate '${convention}' files in the same route segment.\n File 1: ${firstPath}\n File 2: ${secondPath}\nEach segment may define '${convention}' at most once. Remove one of the files.`);
179
- }
180
- /**
181
- * Recursively scan child directories and build the segment tree.
182
- */
183
- function scanChildren(dirPath, parentNode, extSet) {
184
- let entries;
185
- try {
186
- entries = readdirSync(dirPath);
187
- } catch (err) {
188
- swallow(err, `scanChildren: unreadable directory ${dirPath}`, { level: "warn" });
189
- return;
190
- }
191
- for (const entry of entries) {
192
- const fullPath = join(dirPath, entry);
193
- try {
194
- if (!statSync(fullPath).isDirectory()) continue;
195
- } catch {
196
- continue;
197
- }
198
- if (ENCODED_SEPARATOR_RE.test(entry)) throw new Error(`Build error: directory name contains an encoded path delimiter (%2F or %5C).\n Directory: ${fullPath}\nEncoded separators in directory names cause route collisions when decoded. Rename the directory to remove the encoded delimiter.`);
199
- if (NULL_BYTE_RE.test(entry)) throw new Error(`Build error: directory name contains an encoded null byte (%00).\n Directory: ${fullPath}\nEncoded null bytes in directory names are not allowed. Rename the directory to remove the null byte encoding.`);
200
- const { type, paramName, paramPrefix, paramSuffix, interceptionMarker, interceptedSegmentName } = classifySegment(entry);
201
- if (type === "private") continue;
202
- const childNode = createSegmentNode(entry, type, computeUrlPath(parentNode.urlPath, entry, type), paramName, interceptionMarker, interceptedSegmentName, paramPrefix, paramSuffix);
203
- scanSegmentFiles(fullPath, childNode, extSet);
204
- scanChildren(fullPath, childNode, extSet);
205
- if (type === "slot") {
206
- const slotName = entry.slice(1);
207
- parentNode.slots[slotName] = childNode;
208
- } else parentNode.children.push(childNode);
209
- }
210
- }
211
- /**
212
- * Validate that route groups don't produce conflicting pages/routes at the same URL path.
213
- *
214
- * Two route groups like (auth)/login/page.tsx and (marketing)/login/page.tsx both claim
215
- * /login — the scanner must detect and reject this at build time.
216
- *
217
- * Each parallel slot is validated as its OWN collision space: a slot's pages
218
- * intentionally share URL paths with the parent tree (that's the point of
219
- * parallel routes), but two route groups INSIDE one slot claiming the same
220
- * URL — e.g. @side/(a)/x/page.tsx + @side/(b)/x/page.tsx — still collide.
221
- */
222
- function validateRouteGroupCollisions(root) {
223
- collectRoutableLeaves(root, /* @__PURE__ */ new Map(), "");
224
- }
225
- /**
226
- * Walk the segment tree and collect all routable leaves (page or route files),
227
- * throwing on collision. Each slot recurses with a FRESH collision map —
228
- * slots are parallel routes that intentionally share URL paths with their
229
- * parent tree, but collisions within a single slot are real errors.
230
- */
231
- function collectRoutableLeaves(node, seen, segmentPath) {
232
- if (node.segmentType === "intercepting") return;
233
- const currentPath = segmentPath ? `${segmentPath}/${node.segmentName}` : node.segmentName || "(root)";
234
- const routableFile = node.page ?? node.route;
235
- if (routableFile) {
236
- const existing = seen.get(node.urlPath);
237
- if (existing) throw new Error(`Build error: route collision — multiple route groups produce a page/route at the same URL path.\n URL path: ${node.urlPath}\n File 1: ${existing.filePath} (via ${existing.segmentPath})\n File 2: ${routableFile.filePath} (via ${currentPath})\nEach URL path must map to exactly one page or route handler. Rename or move one of the conflicting files.`);
238
- seen.set(node.urlPath, {
239
- filePath: routableFile.filePath,
240
- segmentPath: currentPath
241
- });
242
- }
243
- for (const child of node.children) collectRoutableLeaves(child, seen, currentPath);
244
- for (const slotNode of Object.values(node.slots)) collectRoutableLeaves(slotNode, /* @__PURE__ */ new Map(), currentPath);
245
- }
246
- /**
247
- * Validate that no route chain contains duplicate dynamic param names.
248
- *
249
- * Example violation:
250
- * app/[id]/items/[id]/page.tsx — 'id' appears twice in the ancestor chain.
251
- *
252
- * Route groups are transparent — params accumulate through them.
253
- * Slots are independent — duplicate detection does NOT cross slot boundaries.
254
- *
255
- * See design/07-routing.md §"Duplicate Param Name Detection"
256
- */
257
- function validateDuplicateParamNames(root) {
258
- walkForDuplicateParams(root, /* @__PURE__ */ new Map());
259
- }
260
- /**
261
- * Recursively walk the segment tree, tracking seen param names → segment paths.
262
- * Throws on the first duplicate found.
263
- */
264
- function walkForDuplicateParams(node, seen) {
265
- if (node.paramName) {
266
- const existing = seen.get(node.paramName);
267
- if (existing) throw new Error(`[timber] Duplicate param name '${node.paramName}' in route chain.\n First defined at: ${existing}\n Duplicate at: ${node.urlPath || "/"}\n Rename one of the segments to avoid ambiguity.`);
268
- seen = new Map(seen);
269
- seen.set(node.paramName, node.urlPath || "/");
270
- }
271
- for (const child of node.children) walkForDuplicateParams(child, seen);
272
- for (const slotNode of Object.values(node.slots)) walkForDuplicateParams(slotNode, new Map(seen));
273
- }
274
- /**
275
- * Validate that each param name uses a single bracket form across the entire route tree.
276
- *
277
- * Different bracket forms produce different types:
278
- * [id] → string
279
- * [...id] → string[]
280
- * [[...id]] → string[] | undefined
281
- *
282
- * If the same param name appears with multiple forms, the no-argument
283
- * getSegmentParams() / useSegmentParams() return type becomes ambiguous.
284
- *
285
- * Same name + same form across different routes is fine and expected.
286
- */
287
- function validateUniqueBracketForms(root) {
288
- collectBracketForms(root, /* @__PURE__ */ new Map());
289
- }
290
- function collectBracketForms(node, forms) {
291
- if (node.paramName && node.segmentType !== "static" && node.segmentType !== "group") {
292
- const existing = forms.get(node.paramName);
293
- if (existing && existing.segmentType !== node.segmentType) {
294
- const bracketExamples = {
295
- "dynamic": `[${node.paramName}]`,
296
- "catch-all": `[...${node.paramName}]`,
297
- "optional-catch-all": `[[...${node.paramName}]]`
298
- };
299
- throw new Error(`[timber] Param name '${node.paramName}' uses multiple bracket forms.\n ${bracketExamples[existing.segmentType] ?? existing.segmentType} at: ${existing.urlPath}\n ${bracketExamples[node.segmentType] ?? node.segmentType} at: ${node.urlPath || "/"}\n Each param name must use a single bracket form across all routes.\n Rename one of the segments to fix this (e.g., [${node.paramName}] → [${node.paramName}Id]).`);
300
- }
301
- if (!existing) forms.set(node.paramName, {
302
- segmentType: node.segmentType,
303
- urlPath: node.urlPath || "/"
304
- });
305
- }
306
- for (const child of node.children) collectBracketForms(child, forms);
307
- for (const slotNode of Object.values(node.slots)) collectBracketForms(slotNode, forms);
308
- }
309
- /**
310
- * Validate that no sibling affixed dynamic segments have equal specificity.
311
- *
312
- * Among affixed siblings, longer combined prefix+suffix length wins. When two
313
- * siblings tie (same total affix length), the router would fall back to
314
- * filesystem scan order — which is platform-dependent. This is a build error.
315
- *
316
- * Route groups are URL-transparent, so affixed segments inside different groups
317
- * at the same level still conflict with each other.
318
- *
319
- * See design/07-routing.md §"Priority"
320
- */
321
- function validateAffixedSiblingConflicts(node) {
322
- const affixed = collectEffectiveAffixed(node);
323
- if (affixed.length >= 2) {
324
- const byLength = /* @__PURE__ */ new Map();
325
- for (const child of affixed) {
326
- const len = (child.paramPrefix?.length ?? 0) + (child.paramSuffix?.length ?? 0);
327
- const group = byLength.get(len);
328
- if (group) group.push(child);
329
- else byLength.set(len, [child]);
330
- }
331
- for (const [, group] of byLength) if (group.length >= 2) throw new Error(`Build error: ambiguous affixed dynamic siblings with equal specificity.\n Parent: ${node.urlPath || "/"}\n Segments: ${group.map((s) => s.segmentName).join(", ")}\n Combined prefix+suffix length: ${(group[0].paramPrefix?.length ?? 0) + (group[0].paramSuffix?.length ?? 0)}\nThe router cannot deterministically choose between these — filesystem scan order is platform-dependent.\nRename one segment to give it a longer or shorter combined affix.`);
332
- }
333
- for (const child of node.children) validateAffixedSiblingConflicts(child);
334
- for (const slotNode of Object.values(node.slots)) validateAffixedSiblingConflicts(slotNode);
335
- }
336
- /**
337
- * Collect affixed dynamic segments that are effective children of a node.
338
- * Route groups are URL-transparent, so we look through them recursively.
339
- */
340
- function collectEffectiveAffixed(node) {
341
- const result = [];
342
- for (const child of node.children) if (child.segmentType === "dynamic" && (child.paramPrefix || child.paramSuffix)) result.push(child);
343
- else if (child.segmentType === "group") result.push(...collectEffectiveAffixed(child));
344
- return result;
345
- }
346
- /**
347
- * Find a fixed-extension file (proxy.ts) in a directory.
348
- */
349
- function findFixedFile(dirPath, name) {
350
- for (const ext of ["ts", "tsx"]) {
351
- const fullPath = join(dirPath, `${name}.${ext}`);
352
- try {
353
- if (statSync(fullPath).isFile()) return {
354
- filePath: fullPath,
355
- extension: ext
356
- };
357
- } catch {}
358
- }
359
- }
360
- /**
361
- * Find a file using the configured page extensions (tsx, ts, jsx, js, mdx, etc.).
362
- * Used for app-root conventions like global-error that aren't per-segment.
363
- */
364
- function findPageExtFile(dirPath, name, extSet) {
365
- for (const ext of extSet) {
366
- const fullPath = join(dirPath, `${name}.${ext}`);
367
- try {
368
- if (statSync(fullPath).isFile()) return {
369
- filePath: fullPath,
370
- extension: ext
371
- };
372
- } catch {}
373
- }
374
- }
375
- //#endregion
376
- //#region src/cli-schema-sync.ts
377
- /**
378
- * `timber schema sync` — scan filesystem for dynamic segments, append
379
- * missing entries with `codec.string` defaults, and remove stale entries
380
- * whose segments no longer exist in the filesystem.
381
- *
382
- * Design doc: design/41-global-params.md §Auto-Scaffolding
383
- */
384
- var cli_schema_sync_exports = /* @__PURE__ */ __exportAll({
385
- collectDynamicSegments: () => collectDynamicSegments,
386
- defaultCodecForSegment: () => defaultCodecForSegment,
387
- findSchemaFile: () => findSchemaFile,
388
- findSegmentParamsBlock: () => findSegmentParamsBlock,
389
- parseExistingSchemaKeys: () => parseExistingSchemaKeys,
390
- runSchemaSync: () => runSchemaSync
391
- });
392
- function toBracketKey(node) {
393
- if (node.paramPrefix || node.paramSuffix) return `[${node.paramName}]`;
394
- switch (node.segmentType) {
395
- case "catch-all": return `[...${node.paramName}]`;
396
- case "optional-catch-all": return `[[...${node.paramName}]]`;
397
- default: return `[${node.paramName}]`;
398
- }
399
- }
400
- /**
401
- * Collect all unique bracket-keyed dynamic segment names from the route tree.
402
- * Returns entries like '[artistSlug]', '[...slug]', '[[...topic]]'.
403
- */
404
- function collectDynamicSegments(appDir) {
405
- const tree = scanRoutes(appDir);
406
- const segments = /* @__PURE__ */ new Set();
407
- walkSegments(tree.root, segments);
408
- return [...segments].sort();
409
- }
410
- function walkSegments(node, segments) {
411
- if (node.paramName) segments.add(toBracketKey(node));
412
- for (const child of node.children) walkSegments(child, segments);
413
- for (const slot of Object.values(node.slots)) walkSegments(slot, segments);
414
- }
415
- /**
416
- * Replace comment bodies (and optionally string contents) with spaces,
417
- * preserving length and newlines so every index maps 1:1 to the original.
418
- * Lets the structural scanning below ignore `segmentParams` mentions and
419
- * braces inside comments/strings without a TS parser (fine pre-alpha,
420
- * see TIM-1066).
421
- *
422
- * With `maskStrings`, string contents are blanked too — except literal
423
- * 'segmentParams' strings, kept so a quoted property key stays findable.
424
- */
425
- function maskSource(content, maskStrings) {
426
- const out = content.split("");
427
- const n = content.length;
428
- let i = 0;
429
- const blank = (from, to) => {
430
- for (let j = from; j < to; j++) if (content[j] !== "\n") out[j] = " ";
431
- };
432
- while (i < n) {
433
- const ch = content[i];
434
- const next = content[i + 1];
435
- if (ch === "/" && next === "/") {
436
- const start = i;
437
- while (i < n && content[i] !== "\n") i++;
438
- blank(start, i);
439
- } else if (ch === "/" && next === "*") {
440
- const start = i;
441
- i += 2;
442
- while (i < n && !(content[i] === "*" && content[i + 1] === "/")) i++;
443
- i = Math.min(i + 2, n);
444
- blank(start, i);
445
- } else if (ch === "\"" || ch === "'" || ch === "`") {
446
- const start = i;
447
- i++;
448
- while (i < n && content[i] !== ch) {
449
- if (content[i] === "\\") i++;
450
- i++;
451
- }
452
- const end = i;
453
- if (maskStrings && content.slice(start + 1, end) !== "segmentParams") blank(start + 1, end);
454
- i++;
455
- } else i++;
456
- }
457
- return out.join("");
458
- }
459
- /**
460
- * Locate the `segmentParams: { ... }` block in a schema file.
461
- * Returns the indices of the opening and matching closing brace, or null
462
- * if no segmentParams property is found. Comments and strings are masked
463
- * first, so a JSDoc example mentioning `segmentParams: { ... }` above the
464
- * real defineSchema call is not mistaken for the block, and braces inside
465
- * comments/strings don't skew the depth count. The search is anchored to
466
- * the `defineSchema(` call when present, so helper objects with their own
467
- * segmentParams property earlier in the file are skipped.
468
- */
469
- function findSegmentParamsBlock(content) {
470
- const masked = maskSource(content, true);
471
- const defineCall = /\bdefineSchema\s*\(/.exec(masked);
472
- const keyRe = /(['"]?)segmentParams\1\s*:\s*\{/g;
473
- keyRe.lastIndex = defineCall ? defineCall.index + defineCall[0].length : 0;
474
- const keyMatch = keyRe.exec(masked);
475
- if (!keyMatch) return null;
476
- const openBrace = keyMatch.index + keyMatch[0].length - 1;
477
- let depth = 1;
478
- let i = openBrace + 1;
479
- while (i < masked.length && depth > 0) {
480
- if (masked[i] === "{") depth++;
481
- else if (masked[i] === "}") depth--;
482
- i++;
483
- }
484
- if (depth > 0) return null;
485
- return {
486
- openBrace,
487
- closeBrace: i - 1
488
- };
489
- }
490
- /**
491
- * Parse existing bracket keys from an app/schema.ts file.
492
- * Scoped to the segmentParams: { ... } block — bracket keys elsewhere in
493
- * the file (unrelated objects, comments above defineSchema) are ignored.
494
- * Comments inside the block are masked, so a commented-out entry does not
495
- * count as registered.
496
- *
497
- * The key charset matches the route classifier (segment-classify.ts):
498
- * any character except `]`, so hyphenated params like '[my-param]' parse.
499
- */
500
- function parseExistingSchemaKeys(content) {
501
- const block = findSegmentParamsBlock(content);
502
- if (!block) return [];
503
- const blockContent = maskSource(content, false).slice(block.openBrace, block.closeBrace);
504
- const keys = [];
505
- const re = /['"](\[{1,2}(?:\.{3})?[^\]]+\]{1,2})['"]\s*:/g;
506
- let m;
507
- while ((m = re.exec(blockContent)) !== null) keys.push(m[1]);
508
- return keys;
509
- }
510
- /** Schema file extensions to check. */
511
- var SCHEMA_EXTENSIONS = [
512
- ".ts",
513
- ".tsx",
514
- ".js",
515
- ".jsx"
516
- ];
517
- /**
518
- * Find the schema file path if it exists.
519
- */
520
- function findSchemaFile(appDir) {
521
- for (const ext of SCHEMA_EXTENSIONS) {
522
- const p = join(appDir, `schema${ext}`);
523
- if (existsSync(p)) return p;
524
- }
525
- }
526
- function defaultCodecForSegment(seg) {
527
- if (seg.startsWith("[[...")) return "codec.optionalCatchAll(codec.string)";
528
- if (seg.startsWith("[...")) return "codec.stringArray";
529
- return "codec.string";
530
- }
531
- /**
532
- * Generate the content for a new app/schema.ts with the given segment keys.
533
- */
534
- function generateNewSchema(segments) {
535
- const lines = [];
536
- lines.push("import { defineSchema } from '@timber-js/app/params';");
537
- lines.push("import { codec } from '@timber-js/app/codec';");
538
- lines.push("");
539
- lines.push("export default defineSchema({");
540
- lines.push(" segmentParams: {");
541
- for (const seg of segments) lines.push(` '${seg}': ${defaultCodecForSegment(seg)},`);
542
- lines.push(" },");
543
- lines.push("});");
544
- lines.push("");
545
- return lines.join("\n");
546
- }
547
- /**
548
- * Append missing segment entries to an existing schema file.
549
- * Inserts new entries before the closing `}` of segmentParams.
550
- */
551
- var CODEC_IMPORT = "import { codec } from '@timber-js/app/codec';";
552
- function hasCodecImport(content) {
553
- return /import\s+\{[^}]*\bcodec\b[^}]*\}\s+from\s+['"]@timber-js\/app\/codec['"]/.test(content);
554
- }
555
- function ensureCodecImport(content) {
556
- if (hasCodecImport(content)) return content;
557
- const lines = content.split("\n");
558
- let lastImportIndex = -1;
559
- for (let i = 0; i < lines.length; i++) if (/^\s*import\s/.test(lines[i])) lastImportIndex = i;
560
- if (lastImportIndex === -1) return "import { codec } from '@timber-js/app/codec';\n" + content;
561
- lines.splice(lastImportIndex + 1, 0, CODEC_IMPORT);
562
- return lines.join("\n");
563
- }
564
- function appendToSchema(content, newSegments) {
565
- content = ensureCodecImport(content);
566
- const block = findSegmentParamsBlock(content);
567
- if (!block) throw new Error("[timber] Could not find segmentParams in schema file. Expected a defineSchema({ segmentParams: { ... } }) call.");
568
- const { openBrace, closeBrace } = block;
569
- const existingLine = content.slice(openBrace, closeBrace).match(/^(\s+)['"]\[/m);
570
- const indent = existingLine ? existingLine[1] : " ";
571
- const insertion = newSegments.map((seg) => `${indent}'${seg}': ${defaultCodecForSegment(seg)},`).join("\n");
572
- const before = content.slice(0, closeBrace);
573
- const after = content.slice(closeBrace);
574
- return before + (before.trimEnd().endsWith(",") ? "\n" : "\n") + insertion + "\n" + after;
575
- }
576
- /**
577
- * Remove entries from the segmentParams block whose keys match `staleSegments`.
578
- * Removes the entire entry including trailing comma/whitespace. Scoped to
579
- * the segmentParams block — identical keys in unrelated objects elsewhere
580
- * in the file are left untouched.
581
- */
582
- function removeFromSchema(content, staleSegments) {
583
- const block = findSegmentParamsBlock(content);
584
- if (!block) return content;
585
- let blockContent = content.slice(block.openBrace, block.closeBrace);
586
- let blockMasked = maskSource(blockContent, false);
587
- for (const seg of staleSegments) {
588
- const escaped = seg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
589
- const keyRe = new RegExp(`^[ \t]*['"]${escaped}['"][ \t]*:`, "gm");
590
- let m;
591
- while ((m = keyRe.exec(blockMasked)) !== null) {
592
- const start = m.index;
593
- let i = m.index + m[0].length;
594
- let depth = 0;
595
- let inString = null;
596
- while (i < blockMasked.length) {
597
- const ch = blockMasked[i];
598
- if (inString) {
599
- if (ch === "\\") i++;
600
- else if (ch === inString) inString = null;
601
- } else if (ch === "\"" || ch === "'" || ch === "`") inString = ch;
602
- else if (ch === "(" || ch === "{" || ch === "[") depth++;
603
- else if (ch === ")" || ch === "}" || ch === "]") depth--;
604
- else if (depth === 0 && ch === ",") {
605
- i++;
606
- break;
607
- } else if (depth === 0 && (ch === "\n" || ch === "}")) break;
608
- i++;
609
- }
610
- if (i < blockMasked.length && blockMasked[i] === "\n") i++;
611
- blockContent = blockContent.slice(0, start) + blockContent.slice(i);
612
- blockMasked = blockMasked.slice(0, start) + blockMasked.slice(i);
613
- keyRe.lastIndex = start;
614
- }
615
- }
616
- return content.slice(0, block.openBrace) + blockContent + content.slice(block.closeBrace);
617
- }
618
- /**
619
- * Run the schema sync: scan filesystem, diff against schema, append missing.
620
- */
621
- function runSchemaSync(projectRoot) {
622
- const appDir = resolveAppDir(projectRoot);
623
- const filesystemSegments = collectDynamicSegments(appDir);
624
- const schemaPath = findSchemaFile(appDir);
625
- if (filesystemSegments.length === 0 && !schemaPath) return {
626
- filesystemSegments: [],
627
- existingSegments: [],
628
- addedSegments: [],
629
- removedSegments: [],
630
- created: false
631
- };
632
- if (!schemaPath) {
633
- writeFileSync(join(appDir, "schema.ts"), generateNewSchema(filesystemSegments), "utf-8");
634
- return {
635
- filesystemSegments,
636
- existingSegments: [],
637
- addedSegments: filesystemSegments,
638
- removedSegments: [],
639
- created: true
640
- };
641
- }
642
- const content = readFileSync(schemaPath, "utf-8");
643
- const existingSegments = parseExistingSchemaKeys(content);
644
- const missing = filesystemSegments.filter((seg) => !existingSegments.includes(seg));
645
- const stale = existingSegments.filter((seg) => !filesystemSegments.includes(seg));
646
- if (missing.length === 0 && stale.length === 0) return {
647
- filesystemSegments,
648
- existingSegments,
649
- addedSegments: [],
650
- removedSegments: [],
651
- created: false
652
- };
653
- let updated = content;
654
- if (stale.length > 0) updated = removeFromSchema(updated, stale);
655
- if (missing.length > 0) updated = appendToSchema(updated, missing);
656
- writeFileSync(schemaPath, updated, "utf-8");
657
- return {
658
- filesystemSegments,
659
- existingSegments,
660
- addedSegments: missing,
661
- removedSegments: stale,
662
- created: false
663
- };
664
- }
665
- //#endregion
666
- export { scanRoutes as i, findSchemaFile as n, parseExistingSchemaKeys as r, cli_schema_sync_exports as t };
667
-
668
- //# sourceMappingURL=cli-schema-sync-BTWEKJXo.js.map