@rangojs/router 0.4.3 → 0.5.1

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 (420) hide show
  1. package/dist/types/browser/prefetch/cache.d.ts +31 -2
  2. package/dist/types/cache/cf/cf-cache-store.d.ts +2 -0
  3. package/dist/types/cache/types.d.ts +39 -6
  4. package/dist/types/route-definition/helpers-types.d.ts +5 -4
  5. package/dist/types/rsc/capture-queue.d.ts +19 -3
  6. package/dist/types/rsc/shell-build-manifest.d.ts +2 -2
  7. package/dist/types/rsc/shell-capture.d.ts +22 -2
  8. package/dist/types/rsc/shell-serve.d.ts +18 -12
  9. package/dist/types/static-handler.d.ts +15 -1
  10. package/dist/types/urls/path-helper-types.d.ts +6 -7
  11. package/dist/types.backup/__internal.d.ts +127 -0
  12. package/dist/types.backup/bin/rango.d.ts +1 -0
  13. package/dist/types.backup/browser/action-coordinator.d.ts +57 -0
  14. package/dist/types.backup/browser/action-fence.d.ts +33 -0
  15. package/dist/types.backup/browser/app-shell.d.ts +34 -0
  16. package/dist/types.backup/browser/app-version.d.ts +6 -0
  17. package/dist/types.backup/browser/connection-warmup.d.ts +31 -0
  18. package/dist/types.backup/browser/cookie-name.d.ts +66 -0
  19. package/dist/types.backup/browser/event-controller.d.ts +221 -0
  20. package/dist/types.backup/browser/history-state.d.ts +26 -0
  21. package/dist/types.backup/browser/index.d.ts +1 -0
  22. package/dist/types.backup/browser/intercept-utils.d.ts +30 -0
  23. package/dist/types.backup/browser/invalidate-client-cache.d.ts +17 -0
  24. package/dist/types.backup/browser/link-interceptor.d.ts +43 -0
  25. package/dist/types.backup/browser/logging.d.ts +33 -0
  26. package/dist/types.backup/browser/merge-segment-loaders.d.ts +38 -0
  27. package/dist/types.backup/browser/navigation-bridge.d.ts +27 -0
  28. package/dist/types.backup/browser/navigation-client.d.ts +17 -0
  29. package/dist/types.backup/browser/navigation-store-handle.d.ts +25 -0
  30. package/dist/types.backup/browser/navigation-store.d.ts +95 -0
  31. package/dist/types.backup/browser/navigation-transaction.d.ts +75 -0
  32. package/dist/types.backup/browser/network-error-handler.d.ts +35 -0
  33. package/dist/types.backup/browser/partial-update.d.ts +61 -0
  34. package/dist/types.backup/browser/prefetch/cache.d.ts +183 -0
  35. package/dist/types.backup/browser/prefetch/fetch.d.ts +52 -0
  36. package/dist/types.backup/browser/prefetch/observer.d.ts +27 -0
  37. package/dist/types.backup/browser/prefetch/policy.d.ts +13 -0
  38. package/dist/types.backup/browser/prefetch/queue.d.ts +48 -0
  39. package/dist/types.backup/browser/prefetch/resource-ready.d.ts +28 -0
  40. package/dist/types.backup/browser/rango-state.d.ts +52 -0
  41. package/dist/types.backup/browser/react/Link.d.ts +140 -0
  42. package/dist/types.backup/browser/react/NavigationProvider.d.ts +88 -0
  43. package/dist/types.backup/browser/react/ScrollRestoration.d.ts +78 -0
  44. package/dist/types.backup/browser/react/context.d.ts +54 -0
  45. package/dist/types.backup/browser/react/filter-segment-order.d.ts +35 -0
  46. package/dist/types.backup/browser/react/index.d.ts +1 -0
  47. package/dist/types.backup/browser/react/location-state-shared.d.ts +162 -0
  48. package/dist/types.backup/browser/react/location-state.d.ts +29 -0
  49. package/dist/types.backup/browser/react/mount-context.d.ts +23 -0
  50. package/dist/types.backup/browser/react/nonce-context.d.ts +14 -0
  51. package/dist/types.backup/browser/react/shallow-equal.d.ts +5 -0
  52. package/dist/types.backup/browser/react/use-action.d.ts +61 -0
  53. package/dist/types.backup/browser/react/use-handle.d.ts +21 -0
  54. package/dist/types.backup/browser/react/use-href.d.ts +32 -0
  55. package/dist/types.backup/browser/react/use-link-status.d.ts +36 -0
  56. package/dist/types.backup/browser/react/use-mount.d.ts +24 -0
  57. package/dist/types.backup/browser/react/use-navigation.d.ts +15 -0
  58. package/dist/types.backup/browser/react/use-params.d.ts +21 -0
  59. package/dist/types.backup/browser/react/use-pathname.d.ts +13 -0
  60. package/dist/types.backup/browser/react/use-reverse.d.ts +40 -0
  61. package/dist/types.backup/browser/react/use-router.d.ts +23 -0
  62. package/dist/types.backup/browser/react/use-search-params.d.ts +19 -0
  63. package/dist/types.backup/browser/react/use-segments.d.ts +29 -0
  64. package/dist/types.backup/browser/response-adapter.d.ts +58 -0
  65. package/dist/types.backup/browser/rsc-router.d.ts +141 -0
  66. package/dist/types.backup/browser/scroll-restoration.d.ts +103 -0
  67. package/dist/types.backup/browser/segment-reconciler.d.ts +74 -0
  68. package/dist/types.backup/browser/segment-structure-assert.d.ts +16 -0
  69. package/dist/types.backup/browser/server-action-bridge.d.ts +29 -0
  70. package/dist/types.backup/browser/types.d.ts +530 -0
  71. package/dist/types.backup/browser/validate-redirect-origin.d.ts +28 -0
  72. package/dist/types.backup/build/collect-fallback-refs.d.ts +5 -0
  73. package/dist/types.backup/build/generate-manifest.d.ts +100 -0
  74. package/dist/types.backup/build/generate-route-types.d.ts +8 -0
  75. package/dist/types.backup/build/index.d.ts +21 -0
  76. package/dist/types.backup/build/prefix-tree-utils.d.ts +56 -0
  77. package/dist/types.backup/build/route-trie.d.ts +89 -0
  78. package/dist/types.backup/build/route-types/ast-helpers.d.ts +3 -0
  79. package/dist/types.backup/build/route-types/ast-route-extraction.d.ts +13 -0
  80. package/dist/types.backup/build/route-types/codegen.d.ts +16 -0
  81. package/dist/types.backup/build/route-types/include-resolution.d.ts +74 -0
  82. package/dist/types.backup/build/route-types/param-extraction.d.ts +13 -0
  83. package/dist/types.backup/build/route-types/per-module-writer.d.ts +18 -0
  84. package/dist/types.backup/build/route-types/router-processing.d.ts +82 -0
  85. package/dist/types.backup/build/route-types/scan-filter.d.ts +17 -0
  86. package/dist/types.backup/build/route-types/source-scan.d.ts +13 -0
  87. package/dist/types.backup/build/runtime-discovery.d.ts +24 -0
  88. package/dist/types.backup/cache/background-task.d.ts +21 -0
  89. package/dist/types.backup/cache/cache-error.d.ts +71 -0
  90. package/dist/types.backup/cache/cache-key-utils.d.ts +35 -0
  91. package/dist/types.backup/cache/cache-policy.d.ts +59 -0
  92. package/dist/types.backup/cache/cache-runtime.d.ts +51 -0
  93. package/dist/types.backup/cache/cache-scope.d.ts +134 -0
  94. package/dist/types.backup/cache/cache-tag.d.ts +79 -0
  95. package/dist/types.backup/cache/cf/cf-base64.d.ts +4 -0
  96. package/dist/types.backup/cache/cf/cf-cache-constants.d.ts +105 -0
  97. package/dist/types.backup/cache/cf/cf-cache-store.d.ts +481 -0
  98. package/dist/types.backup/cache/cf/cf-cache-types.d.ts +300 -0
  99. package/dist/types.backup/cache/cf/cf-kv-utils.d.ts +22 -0
  100. package/dist/types.backup/cache/cf/cf-tag-marker-memo.d.ts +15 -0
  101. package/dist/types.backup/cache/cf/index.d.ts +3 -0
  102. package/dist/types.backup/cache/document-cache.d.ts +69 -0
  103. package/dist/types.backup/cache/handle-capture.d.ts +23 -0
  104. package/dist/types.backup/cache/handle-snapshot.d.ts +39 -0
  105. package/dist/types.backup/cache/index.d.ts +7 -0
  106. package/dist/types.backup/cache/memory-segment-store.d.ts +163 -0
  107. package/dist/types.backup/cache/profile-registry.d.ts +40 -0
  108. package/dist/types.backup/cache/read-through-swr.d.ts +60 -0
  109. package/dist/types.backup/cache/segment-codec.d.ts +78 -0
  110. package/dist/types.backup/cache/shell-snapshot.d.ts +162 -0
  111. package/dist/types.backup/cache/tag-invalidation.d.ts +74 -0
  112. package/dist/types.backup/cache/taint.d.ts +71 -0
  113. package/dist/types.backup/cache/types.d.ts +407 -0
  114. package/dist/types.backup/cache/vercel/index.d.ts +1 -0
  115. package/dist/types.backup/cache/vercel/vercel-cache-store.d.ts +267 -0
  116. package/dist/types.backup/client.d.ts +184 -0
  117. package/dist/types.backup/client.rsc.d.ts +39 -0
  118. package/dist/types.backup/cloudflare/index.d.ts +7 -0
  119. package/dist/types.backup/cloudflare/tracing.d.ts +53 -0
  120. package/dist/types.backup/component-utils.d.ts +46 -0
  121. package/dist/types.backup/components/DefaultDocument.d.ts +13 -0
  122. package/dist/types.backup/context-var.d.ts +84 -0
  123. package/dist/types.backup/debug.d.ts +57 -0
  124. package/dist/types.backup/decode-loader-results.d.ts +5 -0
  125. package/dist/types.backup/default-error-boundary.d.ts +10 -0
  126. package/dist/types.backup/defer.d.ts +89 -0
  127. package/dist/types.backup/deps/browser.d.ts +1 -0
  128. package/dist/types.backup/deps/html-stream-client.d.ts +1 -0
  129. package/dist/types.backup/deps/html-stream-server.d.ts +1 -0
  130. package/dist/types.backup/deps/rsc.d.ts +1 -0
  131. package/dist/types.backup/deps/ssr.d.ts +1 -0
  132. package/dist/types.backup/encode-kv.d.ts +35 -0
  133. package/dist/types.backup/errors.d.ts +226 -0
  134. package/dist/types.backup/escape-script.d.ts +44 -0
  135. package/dist/types.backup/handle.d.ts +93 -0
  136. package/dist/types.backup/handles/MetaTags.d.ts +17 -0
  137. package/dist/types.backup/handles/Scripts.d.ts +38 -0
  138. package/dist/types.backup/handles/breadcrumbs.d.ts +43 -0
  139. package/dist/types.backup/handles/deferred-resolution.d.ts +53 -0
  140. package/dist/types.backup/handles/is-thenable.d.ts +12 -0
  141. package/dist/types.backup/handles/meta.d.ts +43 -0
  142. package/dist/types.backup/handles/script.d.ts +139 -0
  143. package/dist/types.backup/host/cookie-handler.d.ts +8 -0
  144. package/dist/types.backup/host/errors.d.ts +40 -0
  145. package/dist/types.backup/host/index.d.ts +33 -0
  146. package/dist/types.backup/host/pattern-matcher.d.ts +30 -0
  147. package/dist/types.backup/host/router.d.ts +12 -0
  148. package/dist/types.backup/host/testing.d.ts +41 -0
  149. package/dist/types.backup/host/types.d.ts +148 -0
  150. package/dist/types.backup/host/utils.d.ts +20 -0
  151. package/dist/types.backup/href-client.d.ts +214 -0
  152. package/dist/types.backup/index.d.ts +112 -0
  153. package/dist/types.backup/index.rsc.d.ts +51 -0
  154. package/dist/types.backup/internal-debug.d.ts +1 -0
  155. package/dist/types.backup/loader-store.d.ts +193 -0
  156. package/dist/types.backup/loader.d.ts +18 -0
  157. package/dist/types.backup/loader.rsc.d.ts +18 -0
  158. package/dist/types.backup/missing-id-error.d.ts +1 -0
  159. package/dist/types.backup/outlet-context.d.ts +12 -0
  160. package/dist/types.backup/outlet-provider.d.ts +12 -0
  161. package/dist/types.backup/prerender/build-shell-capture.d.ts +104 -0
  162. package/dist/types.backup/prerender/param-hash.d.ts +6 -0
  163. package/dist/types.backup/prerender/shell-manifest-key.d.ts +18 -0
  164. package/dist/types.backup/prerender/store.d.ts +62 -0
  165. package/dist/types.backup/prerender.d.ts +292 -0
  166. package/dist/types.backup/redirect-origin.d.ts +55 -0
  167. package/dist/types.backup/regex-escape.d.ts +6 -0
  168. package/dist/types.backup/render-error-thrower.d.ts +13 -0
  169. package/dist/types.backup/response-utils.d.ts +35 -0
  170. package/dist/types.backup/reverse.d.ts +206 -0
  171. package/dist/types.backup/root-error-boundary.d.ts +32 -0
  172. package/dist/types.backup/route-content-wrapper.d.ts +40 -0
  173. package/dist/types.backup/route-definition/dsl-helpers.d.ts +130 -0
  174. package/dist/types.backup/route-definition/helper-factories.d.ts +22 -0
  175. package/dist/types.backup/route-definition/helpers-types.d.ts +392 -0
  176. package/dist/types.backup/route-definition/index.d.ts +7 -0
  177. package/dist/types.backup/route-definition/redirect.d.ts +48 -0
  178. package/dist/types.backup/route-definition/resolve-handler-use.d.ts +19 -0
  179. package/dist/types.backup/route-definition/use-item-types.d.ts +1 -0
  180. package/dist/types.backup/route-definition.d.ts +1 -0
  181. package/dist/types.backup/route-map-builder.d.ts +127 -0
  182. package/dist/types.backup/route-name.d.ts +27 -0
  183. package/dist/types.backup/route-types.d.ts +172 -0
  184. package/dist/types.backup/router/basename.d.ts +10 -0
  185. package/dist/types.backup/router/content-negotiation.d.ts +91 -0
  186. package/dist/types.backup/router/debug-manifest.d.ts +7 -0
  187. package/dist/types.backup/router/error-handling.d.ts +76 -0
  188. package/dist/types.backup/router/find-match.d.ts +19 -0
  189. package/dist/types.backup/router/handler-context.d.ts +41 -0
  190. package/dist/types.backup/router/instrument.d.ts +161 -0
  191. package/dist/types.backup/router/intercept-resolution.d.ts +79 -0
  192. package/dist/types.backup/router/lazy-includes.d.ts +26 -0
  193. package/dist/types.backup/router/loader-resolution.d.ts +63 -0
  194. package/dist/types.backup/router/logging.d.ts +41 -0
  195. package/dist/types.backup/router/manifest.d.ts +8 -0
  196. package/dist/types.backup/router/match-api.d.ts +19 -0
  197. package/dist/types.backup/router/match-context.d.ts +184 -0
  198. package/dist/types.backup/router/match-handlers.d.ts +49 -0
  199. package/dist/types.backup/router/match-middleware/background-revalidation.d.ts +113 -0
  200. package/dist/types.backup/router/match-middleware/cache-lookup.d.ts +113 -0
  201. package/dist/types.backup/router/match-middleware/cache-store.d.ts +112 -0
  202. package/dist/types.backup/router/match-middleware/index.d.ts +80 -0
  203. package/dist/types.backup/router/match-middleware/intercept-resolution.d.ts +116 -0
  204. package/dist/types.backup/router/match-middleware/segment-resolution.d.ts +94 -0
  205. package/dist/types.backup/router/match-pipelines.d.ts +103 -0
  206. package/dist/types.backup/router/match-result.d.ts +114 -0
  207. package/dist/types.backup/router/metrics.d.ts +6 -0
  208. package/dist/types.backup/router/middleware-types.d.ts +74 -0
  209. package/dist/types.backup/router/middleware.d.ts +116 -0
  210. package/dist/types.backup/router/navigation-snapshot.d.ts +22 -0
  211. package/dist/types.backup/router/params-util.d.ts +8 -0
  212. package/dist/types.backup/router/parse-pattern.d.ts +38 -0
  213. package/dist/types.backup/router/pattern-matching.d.ts +169 -0
  214. package/dist/types.backup/router/prefetch-cache-ttl.d.ts +27 -0
  215. package/dist/types.backup/router/prefetch-limits.d.ts +20 -0
  216. package/dist/types.backup/router/prerender-match.d.ts +50 -0
  217. package/dist/types.backup/router/preview-match.d.ts +22 -0
  218. package/dist/types.backup/router/request-classification.d.ts +104 -0
  219. package/dist/types.backup/router/revalidation.d.ts +57 -0
  220. package/dist/types.backup/router/route-snapshot.d.ts +112 -0
  221. package/dist/types.backup/router/router-context.d.ts +137 -0
  222. package/dist/types.backup/router/router-interfaces.d.ts +432 -0
  223. package/dist/types.backup/router/router-options.d.ts +738 -0
  224. package/dist/types.backup/router/router-registry.d.ts +15 -0
  225. package/dist/types.backup/router/segment-resolution/fresh.d.ts +55 -0
  226. package/dist/types.backup/router/segment-resolution/helpers.d.ts +93 -0
  227. package/dist/types.backup/router/segment-resolution/loader-cache.d.ts +33 -0
  228. package/dist/types.backup/router/segment-resolution/loader-mask.d.ts +44 -0
  229. package/dist/types.backup/router/segment-resolution/loader-snapshot.d.ts +90 -0
  230. package/dist/types.backup/router/segment-resolution/mask-nested.d.ts +53 -0
  231. package/dist/types.backup/router/segment-resolution/revalidation.d.ts +85 -0
  232. package/dist/types.backup/router/segment-resolution/static-store.d.ts +17 -0
  233. package/dist/types.backup/router/segment-resolution/streamed-handler-telemetry.d.ts +16 -0
  234. package/dist/types.backup/router/segment-resolution/view-transition-default.d.ts +28 -0
  235. package/dist/types.backup/router/segment-resolution.d.ts +3 -0
  236. package/dist/types.backup/router/segment-wrappers.d.ts +53 -0
  237. package/dist/types.backup/router/state-cookie-name.d.ts +1 -0
  238. package/dist/types.backup/router/substitute-pattern-params.d.ts +23 -0
  239. package/dist/types.backup/router/telemetry-otel.d.ts +113 -0
  240. package/dist/types.backup/router/telemetry.d.ts +215 -0
  241. package/dist/types.backup/router/timeout.d.ts +68 -0
  242. package/dist/types.backup/router/tracing.d.ts +125 -0
  243. package/dist/types.backup/router/trie-matching.d.ts +32 -0
  244. package/dist/types.backup/router/types.d.ts +98 -0
  245. package/dist/types.backup/router/url-params.d.ts +26 -0
  246. package/dist/types.backup/router.d.ts +7 -0
  247. package/dist/types.backup/rsc/capture-queue.d.ts +6 -0
  248. package/dist/types.backup/rsc/full-payload.d.ts +22 -0
  249. package/dist/types.backup/rsc/handler-context.d.ts +31 -0
  250. package/dist/types.backup/rsc/handler.d.ts +9 -0
  251. package/dist/types.backup/rsc/helpers.d.ts +213 -0
  252. package/dist/types.backup/rsc/index.d.ts +17 -0
  253. package/dist/types.backup/rsc/json-route-result.d.ts +20 -0
  254. package/dist/types.backup/rsc/loader-fetch.d.ts +14 -0
  255. package/dist/types.backup/rsc/manifest-init.d.ts +18 -0
  256. package/dist/types.backup/rsc/nonce.d.ts +28 -0
  257. package/dist/types.backup/rsc/origin-guard.d.ts +50 -0
  258. package/dist/types.backup/rsc/progressive-enhancement.d.ts +19 -0
  259. package/dist/types.backup/rsc/redirect-guard.d.ts +35 -0
  260. package/dist/types.backup/rsc/response-cache-serve.d.ts +46 -0
  261. package/dist/types.backup/rsc/response-error.d.ts +19 -0
  262. package/dist/types.backup/rsc/response-route-handler.d.ts +29 -0
  263. package/dist/types.backup/rsc/rsc-rendering.d.ts +23 -0
  264. package/dist/types.backup/rsc/runtime-warnings.d.ts +22 -0
  265. package/dist/types.backup/rsc/server-action.d.ts +68 -0
  266. package/dist/types.backup/rsc/shell-build-manifest.d.ts +84 -0
  267. package/dist/types.backup/rsc/shell-capture-constants.d.ts +27 -0
  268. package/dist/types.backup/rsc/shell-capture.d.ts +374 -0
  269. package/dist/types.backup/rsc/shell-serve.d.ts +136 -0
  270. package/dist/types.backup/rsc/ssr-setup.d.ts +48 -0
  271. package/dist/types.backup/rsc/transition-gate.d.ts +27 -0
  272. package/dist/types.backup/rsc/types.d.ts +290 -0
  273. package/dist/types.backup/runtime-env.d.ts +1 -0
  274. package/dist/types.backup/search-params.d.ts +125 -0
  275. package/dist/types.backup/segment-content-promise.d.ts +13 -0
  276. package/dist/types.backup/segment-fragments.d.ts +56 -0
  277. package/dist/types.backup/segment-loader-promise.d.ts +22 -0
  278. package/dist/types.backup/segment-system.d.ts +84 -0
  279. package/dist/types.backup/serialize.d.ts +164 -0
  280. package/dist/types.backup/server/context.d.ts +494 -0
  281. package/dist/types.backup/server/cookie-parse.d.ts +10 -0
  282. package/dist/types.backup/server/cookie-store.d.ts +107 -0
  283. package/dist/types.backup/server/fetchable-loader-store.d.ts +20 -0
  284. package/dist/types.backup/server/handle-store.d.ts +100 -0
  285. package/dist/types.backup/server/loader-registry.d.ts +32 -0
  286. package/dist/types.backup/server/request-context.d.ts +596 -0
  287. package/dist/types.backup/server/root-layout.d.ts +3 -0
  288. package/dist/types.backup/server.d.ts +15 -0
  289. package/dist/types.backup/ssr/index.d.ts +233 -0
  290. package/dist/types.backup/ssr/inject-rsc-eager.d.ts +3 -0
  291. package/dist/types.backup/ssr/preinit-client-references.d.ts +71 -0
  292. package/dist/types.backup/ssr/ssr-root.d.ts +69 -0
  293. package/dist/types.backup/static-handler.d.ts +57 -0
  294. package/dist/types.backup/testing/cache-status.d.ts +63 -0
  295. package/dist/types.backup/testing/collect-handle.d.ts +20 -0
  296. package/dist/types.backup/testing/dispatch.d.ts +123 -0
  297. package/dist/types.backup/testing/dom.entry.d.ts +15 -0
  298. package/dist/types.backup/testing/e2e/fixture.d.ts +37 -0
  299. package/dist/types.backup/testing/e2e/index.d.ts +30 -0
  300. package/dist/types.backup/testing/e2e/matchers.d.ts +17 -0
  301. package/dist/types.backup/testing/e2e/page-helpers.d.ts +62 -0
  302. package/dist/types.backup/testing/e2e/parity.d.ts +111 -0
  303. package/dist/types.backup/testing/e2e/server.d.ts +35 -0
  304. package/dist/types.backup/testing/flight-matchers.d.ts +55 -0
  305. package/dist/types.backup/testing/flight-normalize.d.ts +1 -0
  306. package/dist/types.backup/testing/flight-tree.d.ts +192 -0
  307. package/dist/types.backup/testing/flight.d.ts +115 -0
  308. package/dist/types.backup/testing/flight.entry.d.ts +27 -0
  309. package/dist/types.backup/testing/generated-routes.d.ts +66 -0
  310. package/dist/types.backup/testing/index.d.ts +52 -0
  311. package/dist/types.backup/testing/internal/context.d.ts +225 -0
  312. package/dist/types.backup/testing/internal/flight-client-globals.d.ts +1 -0
  313. package/dist/types.backup/testing/internal/seed-vars.d.ts +30 -0
  314. package/dist/types.backup/testing/render-handler.d.ts +160 -0
  315. package/dist/types.backup/testing/render-route.d.ts +246 -0
  316. package/dist/types.backup/testing/run-loader.d.ts +186 -0
  317. package/dist/types.backup/testing/run-middleware.d.ts +132 -0
  318. package/dist/types.backup/testing/run-transition-when.d.ts +77 -0
  319. package/dist/types.backup/testing/vitest-stubs/cloudflare-email.d.ts +6 -0
  320. package/dist/types.backup/testing/vitest-stubs/cloudflare-workers.d.ts +13 -0
  321. package/dist/types.backup/testing/vitest-stubs/plugin-rsc.d.ts +7 -0
  322. package/dist/types.backup/testing/vitest-stubs/version.d.ts +1 -0
  323. package/dist/types.backup/testing/vitest.d.ts +205 -0
  324. package/dist/types.backup/theme/ThemeProvider.d.ts +13 -0
  325. package/dist/types.backup/theme/ThemeScript.d.ts +45 -0
  326. package/dist/types.backup/theme/constants.d.ts +39 -0
  327. package/dist/types.backup/theme/index.d.ts +29 -0
  328. package/dist/types.backup/theme/theme-context.d.ts +21 -0
  329. package/dist/types.backup/theme/theme-script.d.ts +26 -0
  330. package/dist/types.backup/theme/types.d.ts +162 -0
  331. package/dist/types.backup/theme/use-theme.d.ts +8 -0
  332. package/dist/types.backup/types/boundaries.d.ts +93 -0
  333. package/dist/types.backup/types/cache-types.d.ts +191 -0
  334. package/dist/types.backup/types/error-types.d.ts +114 -0
  335. package/dist/types.backup/types/global-namespace.d.ts +90 -0
  336. package/dist/types.backup/types/handler-context.d.ts +658 -0
  337. package/dist/types.backup/types/index.d.ts +11 -0
  338. package/dist/types.backup/types/loader-types.d.ts +182 -0
  339. package/dist/types.backup/types/request-scope.d.ts +93 -0
  340. package/dist/types.backup/types/route-config.d.ts +105 -0
  341. package/dist/types.backup/types/route-entry.d.ts +95 -0
  342. package/dist/types.backup/types/segments.d.ts +234 -0
  343. package/dist/types.backup/types.d.ts +1 -0
  344. package/dist/types.backup/urls/include-helper.d.ts +17 -0
  345. package/dist/types.backup/urls/include-provider.d.ts +27 -0
  346. package/dist/types.backup/urls/index.d.ts +6 -0
  347. package/dist/types.backup/urls/path-helper-types.d.ts +197 -0
  348. package/dist/types.backup/urls/path-helper.d.ts +12 -0
  349. package/dist/types.backup/urls/pattern-types.d.ts +166 -0
  350. package/dist/types.backup/urls/response-types.d.ts +67 -0
  351. package/dist/types.backup/urls/type-extraction.d.ts +157 -0
  352. package/dist/types.backup/urls/urls-function.d.ts +24 -0
  353. package/dist/types.backup/urls.d.ts +1 -0
  354. package/dist/types.backup/use-loader.d.ts +150 -0
  355. package/dist/types.backup/vercel/index.d.ts +10 -0
  356. package/dist/types.backup/vercel/tracing.d.ts +70 -0
  357. package/dist/types.backup/vite/debug.d.ts +80 -0
  358. package/dist/types.backup/vite/discovery/bundle-postprocess.d.ts +12 -0
  359. package/dist/types.backup/vite/discovery/dev-prerender-cache.d.ts +65 -0
  360. package/dist/types.backup/vite/discovery/discover-routers.d.ts +17 -0
  361. package/dist/types.backup/vite/discovery/discovery-errors.d.ts +113 -0
  362. package/dist/types.backup/vite/discovery/gate-state.d.ts +79 -0
  363. package/dist/types.backup/vite/discovery/prerender-collection.d.ts +24 -0
  364. package/dist/types.backup/vite/discovery/route-types-writer.d.ts +32 -0
  365. package/dist/types.backup/vite/discovery/self-gen-tracking.d.ts +22 -0
  366. package/dist/types.backup/vite/discovery/shell-prerender-phase.d.ts +40 -0
  367. package/dist/types.backup/vite/discovery/state.d.ts +162 -0
  368. package/dist/types.backup/vite/discovery/virtual-module-codegen.d.ts +15 -0
  369. package/dist/types.backup/vite/index.d.ts +11 -0
  370. package/dist/types.backup/vite/inject-client-debug.d.ts +56 -0
  371. package/dist/types.backup/vite/plugin-types.d.ts +298 -0
  372. package/dist/types.backup/vite/plugins/cjs-to-esm.d.ts +6 -0
  373. package/dist/types.backup/vite/plugins/client-ref-dedup.d.ts +40 -0
  374. package/dist/types.backup/vite/plugins/client-ref-hashing.d.ts +35 -0
  375. package/dist/types.backup/vite/plugins/cloudflare-protocol-stub.d.ts +64 -0
  376. package/dist/types.backup/vite/plugins/expose-action-id.d.ts +18 -0
  377. package/dist/types.backup/vite/plugins/expose-id-utils.d.ts +37 -0
  378. package/dist/types.backup/vite/plugins/expose-ids/export-analysis.d.ts +19 -0
  379. package/dist/types.backup/vite/plugins/expose-ids/handler-transform.d.ts +10 -0
  380. package/dist/types.backup/vite/plugins/expose-ids/loader-transform.d.ts +8 -0
  381. package/dist/types.backup/vite/plugins/expose-ids/router-transform.d.ts +13 -0
  382. package/dist/types.backup/vite/plugins/expose-ids/types.d.ts +29 -0
  383. package/dist/types.backup/vite/plugins/expose-internal-ids.d.ts +6 -0
  384. package/dist/types.backup/vite/plugins/performance-tracks.d.ts +25 -0
  385. package/dist/types.backup/vite/plugins/refresh-cmd.d.ts +20 -0
  386. package/dist/types.backup/vite/plugins/use-cache-transform.d.ts +20 -0
  387. package/dist/types.backup/vite/plugins/vercel-output.d.ts +85 -0
  388. package/dist/types.backup/vite/plugins/version-injector.d.ts +21 -0
  389. package/dist/types.backup/vite/plugins/version-plugin.d.ts +19 -0
  390. package/dist/types.backup/vite/plugins/virtual-entries.d.ts +36 -0
  391. package/dist/types.backup/vite/plugins/virtual-stub-plugin.d.ts +7 -0
  392. package/dist/types.backup/vite/rango.d.ts +29 -0
  393. package/dist/types.backup/vite/router-discovery.d.ts +23 -0
  394. package/dist/types.backup/vite/utils/ast-handler-extract.d.ts +64 -0
  395. package/dist/types.backup/vite/utils/banner.d.ts +2 -0
  396. package/dist/types.backup/vite/utils/bundle-analysis.d.ts +28 -0
  397. package/dist/types.backup/vite/utils/client-chunks.d.ts +55 -0
  398. package/dist/types.backup/vite/utils/directive-prologue.d.ts +16 -0
  399. package/dist/types.backup/vite/utils/forward-user-plugins.d.ts +37 -0
  400. package/dist/types.backup/vite/utils/manifest-utils.d.ts +7 -0
  401. package/dist/types.backup/vite/utils/package-resolution.d.ts +6 -0
  402. package/dist/types.backup/vite/utils/prerender-utils.d.ts +32 -0
  403. package/dist/types.backup/vite/utils/shared-utils.d.ts +55 -0
  404. package/dist/vite/index.js +1 -1
  405. package/package.json +1 -1
  406. package/skills/parallel/SKILL.md +1 -1
  407. package/skills/ppr/SKILL.md +44 -3
  408. package/src/browser/prefetch/cache.ts +53 -9
  409. package/src/browser/prefetch/fetch.ts +83 -2
  410. package/src/cache/cf/cf-cache-store.ts +27 -8
  411. package/src/cache/types.ts +41 -6
  412. package/src/cache/vercel/vercel-cache-store.ts +24 -10
  413. package/src/route-definition/helpers-types.ts +5 -3
  414. package/src/rsc/capture-queue.ts +120 -47
  415. package/src/rsc/rsc-rendering.ts +11 -3
  416. package/src/rsc/shell-build-manifest.ts +20 -7
  417. package/src/rsc/shell-capture.ts +164 -12
  418. package/src/rsc/shell-serve.ts +27 -12
  419. package/src/static-handler.ts +18 -2
  420. package/src/urls/path-helper-types.ts +9 -10
@@ -0,0 +1,407 @@
1
+ /**
2
+ * Cache Store Types
3
+ *
4
+ * Generic caching interface supporting multiple value types.
5
+ * Designed to be implemented by different backends:
6
+ * - MemoryCacheStore (dev/testing)
7
+ * - Cloudflare Cache API adapter
8
+ * - Cloudflare KV adapter
9
+ * - Redis adapter
10
+ */
11
+ import type { ResolvedSegment } from "../types.js";
12
+ import type { RequestContext } from "../server/request-context.js";
13
+ /**
14
+ * Result from cache get() including data and revalidation status
15
+ */
16
+ export interface CacheGetResult {
17
+ /** The cached entry data */
18
+ data: CachedEntryData;
19
+ /**
20
+ * Whether the caller should trigger background revalidation.
21
+ * True when entry is stale AND not already being revalidated.
22
+ * The store atomically marks the entry as REVALIDATING when returning true.
23
+ */
24
+ shouldRevalidate: boolean;
25
+ }
26
+ /**
27
+ * Low-level segment cache store interface.
28
+ *
29
+ * Implementations handle the actual storage (memory, KV, Redis, etc.).
30
+ * The store deals with serialized data - RSC serialization is handled
31
+ * by the cache provider layer.
32
+ *
33
+ * @typeParam TEnv - Platform bindings type (e.g., Cloudflare env)
34
+ */
35
+ export interface SegmentCacheStore<TEnv = unknown> {
36
+ /**
37
+ * Default cache options for this store.
38
+ * Used by cache() boundaries when ttl/swr are not explicitly specified.
39
+ */
40
+ readonly defaults?: CacheDefaults;
41
+ /**
42
+ * Custom key generator applied to all cache operations using this store.
43
+ * Receives the full RequestContext and the default-generated key.
44
+ * Return value becomes the final cache key (unless route overrides with `key` option).
45
+ *
46
+ * Resolution priority:
47
+ * 1. Route-level `key` function (full override)
48
+ * 2. Store-level `keyGenerator` (modifies default key)
49
+ * 3. Default key generation (prefix:pathname:params)
50
+ *
51
+ * @example Using headers for cache segmentation
52
+ * ```typescript
53
+ * keyGenerator: (ctx, defaultKey) => {
54
+ * const segment = ctx.request.headers.get('x-user-segment') || 'default';
55
+ * return `${segment}:${defaultKey}`;
56
+ * }
57
+ * ```
58
+ *
59
+ * @example Using env bindings (Cloudflare)
60
+ * ```typescript
61
+ * keyGenerator: (ctx, defaultKey) => {
62
+ * const region = ctx.env.REGION || 'us';
63
+ * return `${region}:${defaultKey}`;
64
+ * }
65
+ * ```
66
+ *
67
+ * @example Using cookies for locale
68
+ * ```typescript
69
+ * keyGenerator: (ctx, defaultKey) => {
70
+ * const locale = cookies().get('locale')?.value || 'en';
71
+ * return `${locale}:${defaultKey}`;
72
+ * }
73
+ * ```
74
+ */
75
+ readonly keyGenerator?: (ctx: RequestContext<TEnv>, defaultKey: string) => string | Promise<string>;
76
+ /**
77
+ * Get cached entry data by key
78
+ * @returns Cache result with data and staleness, or null if not found/expired
79
+ */
80
+ get(key: string): Promise<CacheGetResult | null>;
81
+ /**
82
+ * Store entry data with TTL
83
+ * @param key - Cache key
84
+ * @param data - Serialized entry data
85
+ * @param ttl - Time-to-live in seconds
86
+ * @param swr - Optional stale-while-revalidate window in seconds
87
+ */
88
+ set(key: string, data: CachedEntryData, ttl: number, swr?: number): Promise<void>;
89
+ /**
90
+ * Delete a cached entry
91
+ * @returns true if deleted, false if not found
92
+ */
93
+ delete(key: string): Promise<boolean>;
94
+ /**
95
+ * Clear all cached entries (optional, for testing)
96
+ */
97
+ clear?(): Promise<void>;
98
+ /**
99
+ * Get a cached Response by key.
100
+ * Returns the response and whether it should be revalidated (SWR).
101
+ */
102
+ getResponse?(key: string): Promise<{
103
+ response: Response;
104
+ shouldRevalidate: boolean;
105
+ } | null>;
106
+ /**
107
+ * Store a Response with TTL and optional SWR window.
108
+ * @param key - Cache key
109
+ * @param response - Response to cache (will be cloned)
110
+ * @param ttl - Time-to-live in seconds
111
+ * @param swr - Optional stale-while-revalidate window in seconds
112
+ * @param tags - Optional cache tags for invalidation
113
+ */
114
+ putResponse?(key: string, response: Response, ttl: number, swr?: number, tags?: string[]): Promise<void>;
115
+ /**
116
+ * Get a cached PPR shell entry by key.
117
+ * Returns the stored prelude/postponed pair (see ShellCacheEntry) and whether
118
+ * it should be revalidated (SWR). Used by the shell-cache middleware to serve
119
+ * a cached HTML shell and resume fizz for just the live holes.
120
+ *
121
+ * Optional: a store that does not implement the shell family disables the
122
+ * shell-cache middleware (it fails open to the normal HTML render path).
123
+ */
124
+ getShell?(key: string): Promise<{
125
+ entry: ShellCacheEntry;
126
+ shouldRevalidate?: boolean;
127
+ } | null>;
128
+ /**
129
+ * Store a PPR shell entry with TTL and optional SWR window.
130
+ * The prelude bytes and postponed state are version- and generation-coupled
131
+ * and travel together in a single entry (they must never mix across a React
132
+ * upgrade — the reactVersion field on the entry gates that at read time).
133
+ * @param key - Cache key
134
+ * @param entry - The shell prelude/postponed/version/createdAt bundle
135
+ * @param ttlSeconds - Time-to-live in seconds
136
+ * @param swrSeconds - Optional stale-while-revalidate window in seconds
137
+ * @param tags - Optional cache tags for invalidation (participates in
138
+ * invalidateTags via the same tag machinery as the item family)
139
+ */
140
+ putShell?(key: string, entry: ShellCacheEntry, ttlSeconds?: number, swrSeconds?: number, tags?: string[]): Promise<void>;
141
+ /**
142
+ * Get a cached function result by key.
143
+ * Returns the serialized value, optional handle data, and staleness flag.
144
+ */
145
+ getItem?(key: string): Promise<CacheItemResult | null>;
146
+ /**
147
+ * Store a function result with TTL and optional SWR window.
148
+ * @param key - Cache key (format: use-cache:{functionId}:{serializedArgs})
149
+ * @param value - RSC-serialized return value
150
+ * @param options - TTL, SWR, handle data, and tags
151
+ */
152
+ setItem?(key: string, value: string, options?: CacheItemOptions): Promise<void>;
153
+ /**
154
+ * Invalidate every cache entry (segment, response, item) tagged with any of
155
+ * `tags`. Store-level primitive that the public updateTag()/revalidateTag()
156
+ * APIs delegate to. Receives ALL of one invalidation call's tags at once so
157
+ * stores can batch their work (e.g. a single CDN purge request rather than
158
+ * one per tag). Stores that do not support tags simply omit this method.
159
+ * @param tags - The cache tags to invalidate
160
+ */
161
+ invalidateTags?(tags: string[]): Promise<void>;
162
+ /**
163
+ * True when ANY of `tags` was invalidated (invalidateTags/updateTag) at or
164
+ * after `sinceMs` (>= so a same-millisecond invalidation wins, favouring
165
+ * freshness). Consulted by the build-time shell read-through
166
+ * (rsc/shell-build-manifest.ts): a baked shell entry is immutable in the
167
+ * build manifest, so "was it evicted" is answered by the store's tag
168
+ * markers against the entry's createdAt rather than by deleting anything.
169
+ * Optional: without it, TAGGED build entries are not served (untagged ones
170
+ * are unaffected — they are evictable only by deploy/buildVersion anyway).
171
+ * Fail open to `false` on marker-read errors: a transient store fault must
172
+ * degrade to "still valid", the same posture as the envelope tag checks.
173
+ */
174
+ isTagsInvalidatedSince?(tags: string[], sinceMs: number): Promise<boolean>;
175
+ }
176
+ /**
177
+ * Result from getItem() for function-level caching ("use cache").
178
+ */
179
+ export interface CacheItemResult {
180
+ /** RSC-serialized return value */
181
+ value: string;
182
+ /** RSC-encoded handle data captured during execution (breadcrumbs, metadata,
183
+ * etc.). Encoded via the Flight codec so Promise/ReactNode handle values
184
+ * survive JSON-serializing stores — see handle-snapshot.ts encodeHandles. */
185
+ handles?: string;
186
+ /** Whether the entry is stale and should be revalidated */
187
+ shouldRevalidate: boolean;
188
+ /**
189
+ * The entry's cache tags (including runtime cacheTag() tags), surfaced on read
190
+ * so a "use cache" HIT can still contribute its tags to the request-scoped tag
191
+ * set used by document-level caching. On a hit the cached function is not
192
+ * re-run, so its runtime tags are only available here, not from re-execution.
193
+ */
194
+ tags?: string[];
195
+ }
196
+ /**
197
+ * A cached PPR (Partial Pre-rendering) shell entry.
198
+ *
199
+ * One entry carries BOTH artifacts a resume needs — the rendered HTML prelude
200
+ * and React's postponed state — because the pair is version- and
201
+ * generation-coupled and must never be mixed across a React upgrade or a build
202
+ * change. The reactVersion and buildVersion fields are the read-time gates that
203
+ * enforce both halves: isValidShellHit (rsc/shell-serve.ts) treats an entry
204
+ * whose reactVersion differs from the running React, or whose buildVersion
205
+ * differs from the running build, as a miss (the postponed blob encodes hole
206
+ * positions against one exact tree; resuming it against a different React or a
207
+ * different app build tree-mismatches inside resume(), AFTER the 200 + prelude
208
+ * are committed — an unrecoverable broken serve).
209
+ */
210
+ export interface ShellCacheEntry {
211
+ /** Rendered HTML prelude bytes, base64-encoded (stores are JSON-serializing). */
212
+ prelude: string;
213
+ /**
214
+ * JSON.stringify of React's postponed state, or null when the shell settled
215
+ * with no holes (the DATA variant — served without a fizz resume).
216
+ */
217
+ postponed: string | null;
218
+ /** React.version captured at prerender time; the read-time invalidation gate. */
219
+ reactVersion: string;
220
+ /**
221
+ * Build version captured at prerender time (the RSC handler's `version` —
222
+ * the `@rangojs/router:version` build stamp by default, bumped per build and
223
+ * on dev RSC-module edits). The second read-time gate: a persistent shared
224
+ * store (KV/runtime-cache) survives deploys, and an app-code change that
225
+ * keeps the same React version would otherwise leave a stale-build
226
+ * prelude+postponed live under the same key. Optional only for entries
227
+ * stored before the field existed — those are treated as a miss and the
228
+ * recapture re-stamps them (pre-release, no compat shim).
229
+ */
230
+ buildVersion?: string;
231
+ /**
232
+ * The initialTheme the CAPTURE render was built with (the derived context's
233
+ * reqCtx.theme). The resume tail must render ThemeProvider with the SAME
234
+ * initialTheme the frozen prelude was rendered with: React resume requires the
235
+ * tree above the holes to match the prerendered tree, and initialTheme is
236
+ * per-request METADATA, not part of the cached segments — a visitor whose
237
+ * theme differs from the capturer's would otherwise produce a divergent resume
238
+ * tree (broken stitching/hydration). The visitor's real theme is applied
239
+ * pre-paint by the FOUC script and re-synced from the cookie post-mount by
240
+ * ThemeProvider.
241
+ */
242
+ initialTheme?: string;
243
+ /**
244
+ * The CAPTURE DATA SNAPSHOT: every cache-store read-hit and write the capture
245
+ * render performed, in stored/serialized form. Replaying these on a HIT (via
246
+ * the SeededShellStore overlay, for the tail render only) reproduces the
247
+ * shell's cached content byte-identically, so the freshly rendered hydration
248
+ * payload matches the frozen prelude even after the underlying cache entries
249
+ * have drifted (expired, been recomputed, or been tag-invalidated).
250
+ *
251
+ * Optional: an entry captured before this field existed simply has no
252
+ * snapshot and keeps the pre-snapshot behavior (the tail reads live, so any
253
+ * shell-baked cached value that drifted mismatches the prelude). Recapture
254
+ * heals it. See docs/design/ppr-shell-resume.md ("the capture data snapshot").
255
+ */
256
+ snapshot?: ShellSnapshotRecord[];
257
+ /**
258
+ * True when the capture's HANDLER layer declared per-request liveness: a
259
+ * handle pushed OUTSIDE a DSL loader scope carried a nested thenable (the
260
+ * capture mask turns it into a never-filling hole), such a push was still
261
+ * pending when the entry was written, or a handler-invoked loader
262
+ * (ctx.use(loader) from a handler body — the consumption lane, #672)
263
+ * executed during the capture. The serve tail then must NOT take the
264
+ * handler-free fast path (the implicit doc-cache hit): only a handler
265
+ * re-run can mint that hole's live promise or refresh that consumed value.
266
+ * DSL-loader pushes never set this — loaders re-run fresh on every HIT, so
267
+ * their holes always fill.
268
+ */
269
+ handlerLiveHoles?: boolean;
270
+ /** Epoch ms when the shell was captured. */
271
+ createdAt: number;
272
+ }
273
+ /**
274
+ * The families a shell snapshot pins. The item/segment/response families are
275
+ * cache-store reads/writes (recorded by RecordingShellStore); the loader family
276
+ * pins the settled CONTAINER of a bake-lane loader (a loader on an entry with
277
+ * no renderable loading(), executed during capture — see
278
+ * docs/design/loader-container-bake.md). Excludes the shell family itself
279
+ * (getShell/putShell) — the snapshot rides INSIDE a shell entry, so recording
280
+ * it would be self-referential.
281
+ */
282
+ export type ShellSnapshotFamily = "item" | "segment" | "response" | "loader";
283
+ /**
284
+ * The stored form of a loader-family snapshot value: the bake-lane loader's
285
+ * settled container, Flight-serialized AFTER eliding every still-pending nested
286
+ * promise to a hole marker (the marker paths are holes, not shell material; on
287
+ * a HIT the overlay re-slots the fresh run's promises there). Flight (not JSON)
288
+ * so typed values (Date/Map) survive the round trip.
289
+ */
290
+ export interface ShellSnapshotLoaderValue {
291
+ /** RSC-serialized elided container (see loader-snapshot.ts). */
292
+ value: string;
293
+ }
294
+ /** A serialized cached Response for the response family of a shell snapshot. */
295
+ export interface ShellSnapshotResponseValue {
296
+ status: number;
297
+ /** Client-facing header pairs (per-client signal headers excluded at record). */
298
+ headers: [string, string][];
299
+ /** base64-encoded response body (binary-safe, JSON-serializable). */
300
+ body: string;
301
+ }
302
+ /** The stored form of an item-family (use cache / loader cache) snapshot value. */
303
+ export interface ShellSnapshotItemValue {
304
+ /** RSC-serialized return value. */
305
+ value: string;
306
+ /** RSC-encoded handle data, if any. */
307
+ handles?: string;
308
+ /** The entry's cache tags. */
309
+ tags?: string[];
310
+ }
311
+ /**
312
+ * One recorded cache-store read-hit or write from the capture render. `value`
313
+ * carries the entry in its stored/serialized shape so it round-trips through a
314
+ * JSON-serializing store (KV, CF, Vercel) with the rest of the ShellCacheEntry:
315
+ * - `item` -> {@link ShellSnapshotItemValue}
316
+ * - `segment` -> {@link CachedEntryData} (already JSON-able)
317
+ * - `response`-> {@link ShellSnapshotResponseValue}
318
+ */
319
+ export interface ShellSnapshotRecord {
320
+ family: ShellSnapshotFamily;
321
+ key: string;
322
+ value: ShellSnapshotItemValue | CachedEntryData | ShellSnapshotResponseValue | ShellSnapshotLoaderValue;
323
+ }
324
+ /**
325
+ * Options for setItem() for function-level caching ("use cache").
326
+ */
327
+ export interface CacheItemOptions {
328
+ /** RSC-encoded handle data to store alongside the value (see encodeHandles). */
329
+ handles?: string;
330
+ /** Time-to-live in seconds */
331
+ ttl?: number;
332
+ /** Stale-while-revalidate window in seconds */
333
+ swr?: number;
334
+ /** Cache tags for invalidation */
335
+ tags?: string[];
336
+ }
337
+ /**
338
+ * Serialized segment data stored in cache
339
+ * Note: loading is preserved to ensure consistent tree structure between cached and fresh renders
340
+ *
341
+ * @internal This type is an implementation detail and may change without notice.
342
+ */
343
+ export interface SerializedSegmentData {
344
+ /** RSC-encoded component string */
345
+ encoded: string;
346
+ /** RSC-encoded layout string (if present) */
347
+ encodedLayout?: string;
348
+ /** RSC-encoded loading skeleton string (if present), or "null" for explicit null */
349
+ encodedLoading?: string;
350
+ /** RSC-encoded loaderData (if present) */
351
+ encodedLoaderData?: string;
352
+ /** RSC-encoded loaderDataPromise (if present) */
353
+ encodedLoaderDataPromise?: string;
354
+ /** Segment metadata (everything except component, layout, loading, and loader data) */
355
+ metadata: Omit<ResolvedSegment, "component" | "layout" | "loading" | "loaderData" | "loaderDataPromise">;
356
+ }
357
+ /**
358
+ * Raw data stored in cache for an entry
359
+ *
360
+ * @internal This type is an implementation detail and may change without notice.
361
+ */
362
+ export interface CachedEntryData {
363
+ /** Serialized segments for this entry */
364
+ segments: SerializedSegmentData[];
365
+ /** RSC-encoded handle data keyed by segment ID. Encoded via the Flight codec
366
+ * (see handle-snapshot.ts encodeHandles) so Promise/ReactNode handle values
367
+ * round-trip through JSON-serializing stores instead of being flattened. */
368
+ handles: string;
369
+ /** Expiration timestamp (ms since epoch) */
370
+ expiresAt: number;
371
+ /** Cache tags for invalidation */
372
+ tags?: string[];
373
+ /** Timestamp (ms since epoch) when tags were attached, for distributed invalidation */
374
+ taggedAt?: number;
375
+ }
376
+ /**
377
+ * Default cache options applied to all cache() boundaries.
378
+ * Individual cache() calls can override any of these values.
379
+ *
380
+ * @example
381
+ * ```ts
382
+ * const store = new CFCacheStore({
383
+ * defaults: { ttl: 60, swr: 300 }
384
+ * });
385
+ * ```
386
+ */
387
+ export interface CacheDefaults {
388
+ /**
389
+ * Default time-to-live in seconds.
390
+ * After TTL expires, cached entry is considered stale.
391
+ * Must be a finite, non-negative number; an invalid value (NaN/Infinity/
392
+ * negative) falls back to the default at read time.
393
+ */
394
+ ttl?: number;
395
+ /**
396
+ * Default stale-while-revalidate window in seconds.
397
+ * During SWR window, stale content is served while revalidating in background.
398
+ * Must be a finite, non-negative number; an invalid value (NaN/Infinity/
399
+ * negative) falls back to the default at read time.
400
+ */
401
+ swr?: number;
402
+ }
403
+ /**
404
+ * Handle data for a single segment
405
+ * Structure: { handleName: [values...] }
406
+ */
407
+ export type SegmentHandleData = Record<string, unknown[]>;
@@ -0,0 +1 @@
1
+ export { VercelCacheStore, type VercelCacheStoreOptions, type VercelRuntimeCache, type VercelCacheDebug, type VercelCacheReadDebugEvent, type VercelCacheReadOutcome, VERCEL_MAX_ITEM_BYTES, VERCEL_MAX_TAGS_PER_ITEM, VERCEL_MAX_TAG_BYTES, } from "./vercel-cache-store.js";
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Vercel Runtime Cache Store
3
+ *
4
+ * A SegmentCacheStore backed by Vercel's Runtime Cache (`getCache()` from
5
+ * `@vercel/functions`). It is the production store analogue to CFCacheStore, but
6
+ * far smaller: Vercel's Runtime Cache already IS a distributed, tag-aware cache
7
+ * (regional storage, global tag-expire within ~300ms), so none of CFCacheStore's
8
+ * L1/L2 tiering, KV tag-marker comparison, marker memoization, or per-tier
9
+ * timeout budgets are needed here - the platform does that work. What this store
10
+ * adds on top of the raw primitive is the parts Vercel does NOT give us:
11
+ *
12
+ * 1. Stale-while-revalidate. `getCache` has no stale-but-serve: a TTL'd entry
13
+ * simply becomes a miss. We store our own {staleAt, expiresAt} envelope and
14
+ * set the Vercel ttl to (ttl + swr) so the entry survives its SWR window,
15
+ * computing staleness ourselves via the shared cache-policy helpers.
16
+ * 2. A single-keyspace family split. `getCache` is one flat keyspace, whereas
17
+ * the interface has three value families (segments, "use cache" items, full
18
+ * responses). The memory store keeps three separate Maps; here they must be
19
+ * namespaced by a prefix or a set() of a response would clobber a segment
20
+ * cached under the same router key.
21
+ * 3. The platform guardrails: the 2 MB per-item ceiling (oversized writes
22
+ * silently no-op on Vercel, so we skip + report), the per-item tag cap, and
23
+ * cross-deploy non-reconciliation (TTL/tag updates are not reconciled across
24
+ * deployments - bake a build id into `version` or the getCache namespace).
25
+ *
26
+ * Dependency stance: this module imports NOTHING from `@vercel/functions`. The
27
+ * runtime cache handle (and `waitUntil`) are injected through the constructor and
28
+ * typed against the local VercelRuntimeCache shape below, exactly as CFCacheStore
29
+ * takes its `kv`/`ctx` bindings by injection. The consumer passes the real
30
+ * `getCache(...)` result, which satisfies the shape structurally. That keeps the
31
+ * router free of a hard Vercel dependency.
32
+ */
33
+ import type { SegmentCacheStore, CachedEntryData, CacheDefaults, CacheGetResult, CacheItemResult, CacheItemOptions, ShellCacheEntry } from "../types.js";
34
+ import type { RequestContext } from "../../server/request-context.js";
35
+ /**
36
+ * Minimal structural shape of the Vercel Runtime Cache returned by `getCache()`
37
+ * from `@vercel/functions`. Declared locally so @rangojs/router carries no hard
38
+ * dependency on `@vercel/functions`; the real handle satisfies it structurally.
39
+ *
40
+ * @see https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#getcache
41
+ */
42
+ export interface VercelRuntimeCache {
43
+ /** Returns the stored value, or a nullish value on miss. Never throws on miss. */
44
+ get(key: string): Promise<unknown>;
45
+ /** Stores a value with optional TTL (seconds), tags, and observability name. */
46
+ set(key: string, value: unknown, options?: {
47
+ ttl?: number;
48
+ tags?: string[];
49
+ name?: string;
50
+ }): Promise<void>;
51
+ /** Removes a value by key. */
52
+ delete(key: string): Promise<void>;
53
+ /** Expires every entry tagged with any of `tag`. Global, ~300ms propagation. */
54
+ expireTag(tag: string | string[]): Promise<void>;
55
+ }
56
+ /**
57
+ * Vercel Runtime Cache hard per-item ceiling: 2 MB. Writes above this silently
58
+ * no-op on the platform, so the store measures the serialized envelope and skips
59
+ * (fail-open) entries at or above this size.
60
+ */
61
+ export declare const VERCEL_MAX_ITEM_BYTES: number;
62
+ /**
63
+ * Per-item tag ceiling. Vercel's getCache API reference lists 128 tags per item
64
+ * (https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#getcache).
65
+ * Tags beyond this are dropped with a warning at write time. Does NOT cap
66
+ * invalidateTags() - an invalidation must reach every requested tag.
67
+ */
68
+ export declare const VERCEL_MAX_TAGS_PER_ITEM: number;
69
+ /** Max tag length in UTF-8 bytes accepted by Vercel; longer tags are skipped. */
70
+ export declare const VERCEL_MAX_TAG_BYTES: number;
71
+ /** Read-path outcome for the debug sink. */
72
+ export type VercelCacheReadOutcome = "miss" | "fresh" | "stale-revalidate" | "expired" | "corrupt" | "error";
73
+ /** Diagnostic event emitted on every read when `debug` is set. */
74
+ export interface VercelCacheReadDebugEvent {
75
+ op: "get" | "getItem" | "getResponse" | "getShell";
76
+ key: string;
77
+ outcome: VercelCacheReadOutcome;
78
+ staleAt?: number;
79
+ expiresAt?: number;
80
+ shouldRevalidate?: boolean;
81
+ /** Wall-clock ms spent in the backing cache.get(). */
82
+ readMs?: number;
83
+ }
84
+ /** `true` logs each read outcome; a function receives the structured event. */
85
+ export type VercelCacheDebug = boolean | ((event: VercelCacheReadDebugEvent) => void);
86
+ /**
87
+ * Options for VercelCacheStore.
88
+ */
89
+ export interface VercelCacheStoreOptions<TEnv = unknown> {
90
+ /**
91
+ * The Vercel Runtime Cache handle - `getCache()` from `@vercel/functions`.
92
+ * Required. Construct it with a build-hash namespace to bust stale-shaped
93
+ * entries across deployments, since Vercel does not reconcile TTL/tags between
94
+ * deploys:
95
+ *
96
+ * ```ts
97
+ * import { getCache } from "@vercel/functions";
98
+ * new VercelCacheStore({ cache: getCache({ namespace: BUILD_ID }) });
99
+ * ```
100
+ */
101
+ cache: VercelRuntimeCache;
102
+ /**
103
+ * `waitUntil` from `@vercel/functions`. Used only to run the stale-read lock
104
+ * write (herd dampening) off the response path - the router already
105
+ * backgrounds the actual writes. When omitted, the lock write runs detached
106
+ * (fire-and-forget) instead.
107
+ */
108
+ waitUntil?: (promise: Promise<unknown>) => void;
109
+ /**
110
+ * Default ttl/swr for cache() boundaries when not explicitly specified.
111
+ */
112
+ defaults?: CacheDefaults;
113
+ /**
114
+ * Custom key generator applied to all cache operations (region/locale/user
115
+ * segmentation). Receives the request context and the default key.
116
+ */
117
+ keyGenerator?: (ctx: RequestContext<TEnv>, defaultKey: string) => string | Promise<string>;
118
+ /**
119
+ * Build/version id folded into every stored key as `v/{version}/...`. A second
120
+ * cross-deploy busting layer in addition to (or instead of) the getCache
121
+ * namespace. Changing it invalidates everything this store wrote previously.
122
+ */
123
+ version?: string;
124
+ /**
125
+ * Max serialized entry size in bytes before a write is skipped. Defaults to
126
+ * VERCEL_MAX_ITEM_BYTES (2 MB - the platform's hard cap).
127
+ */
128
+ maxItemBytes?: number;
129
+ /**
130
+ * Human-readable label passed as the Vercel `set({ name })` option for
131
+ * observability in the Vercel dashboard.
132
+ */
133
+ name?: string;
134
+ /**
135
+ * Read diagnostics. `true` logs each read outcome to the console; a function
136
+ * receives the structured VercelCacheReadDebugEvent.
137
+ */
138
+ debug?: VercelCacheDebug;
139
+ }
140
+ /**
141
+ * Vercel Runtime Cache-backed segment cache store.
142
+ *
143
+ * Suitable for production deployments on Vercel Functions (Node runtime). The
144
+ * store is best-effort: every read failure degrades to a miss and every write
145
+ * failure to a no-op (reported, never thrown) - the sole exception is
146
+ * invalidateTags(), which rejects when the injected cache's expireTag() rejects
147
+ * so an awaited updateTag() can surface the failure.
148
+ *
149
+ * Read-your-own-writes caveat: this honesty is only as strong as the cache
150
+ * handle. The official `@vercel/functions` cache (`BuildCache.expireTag`)
151
+ * CATCHES backend failures and resolves, so with the official client a failed
152
+ * expireTag is invisible here and an awaited updateTag() can report success that
153
+ * did not happen. Treat tag invalidation on the official Vercel client as
154
+ * best-effort, not a hard read-your-own-writes guarantee. (A custom cache handle
155
+ * that propagates expireTag rejections does get the strict guarantee, which is
156
+ * what the unit suite exercises.)
157
+ *
158
+ * Key hashing / family isolation. The store namespaces its three value tiers as
159
+ * `rg:{s|i|r}:{key}` so segment, `"use cache"`, and response entries occupy
160
+ * disjoint keyspaces. That separation is only as strong as the cache's
161
+ * `keyHashFunction`: `getCache`'s default is djb2, which folds every key to 32
162
+ * bits (8 hex chars), so at a large live-key count a collision can let one
163
+ * entry's body be served for another key (same-family) or be misread as corrupt
164
+ * (cross-family). For deployments with many cached keys, pass a wider hash so
165
+ * the family split is real isolation, e.g. `getCache({ keyHashFunction })` with
166
+ * a sha256-based function.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import { getCache, waitUntil } from "@vercel/functions";
171
+ * import { VercelCacheStore } from "@rangojs/router/cache";
172
+ *
173
+ * export const router = createRouter({
174
+ * cache: () => ({
175
+ * store: new VercelCacheStore({
176
+ * // `process.env` (not `import.meta.env`, which needs a VITE_ prefix and
177
+ * // would be undefined here) so cross-deploy busting via `version` works.
178
+ * cache: getCache({ namespace: process.env.VERCEL_DEPLOYMENT_ID }),
179
+ * waitUntil,
180
+ * defaults: { ttl: 60, swr: 300 },
181
+ * }),
182
+ * }),
183
+ * });
184
+ * ```
185
+ */
186
+ export declare class VercelCacheStore<TEnv = unknown> implements SegmentCacheStore<TEnv> {
187
+ readonly defaults?: CacheDefaults;
188
+ readonly keyGenerator?: (ctx: RequestContext<TEnv>, defaultKey: string) => string | Promise<string>;
189
+ private readonly cache;
190
+ private readonly waitUntil?;
191
+ private readonly version?;
192
+ private readonly maxItemBytes;
193
+ private readonly name?;
194
+ private readonly debug?;
195
+ constructor(options: VercelCacheStoreOptions<TEnv>);
196
+ get(key: string): Promise<CacheGetResult | null>;
197
+ set(key: string, data: CachedEntryData, ttl: number, swr?: number): Promise<void>;
198
+ delete(key: string): Promise<boolean>;
199
+ getResponse(key: string): Promise<{
200
+ response: Response;
201
+ shouldRevalidate: boolean;
202
+ } | null>;
203
+ putResponse(key: string, response: Response, ttl: number, swr?: number, tags?: string[]): Promise<void>;
204
+ getItem(key: string): Promise<CacheItemResult | null>;
205
+ setItem(key: string, value: string, options?: CacheItemOptions): Promise<void>;
206
+ getShell(key: string): Promise<{
207
+ entry: ShellCacheEntry;
208
+ shouldRevalidate?: boolean;
209
+ } | null>;
210
+ putShell(key: string, entry: ShellCacheEntry, ttlSeconds?: number, swrSeconds?: number, tags?: string[]): Promise<void>;
211
+ /**
212
+ * Build-shell read-through gate (SegmentCacheStore.isTagsInvalidatedSince).
213
+ * The platform's expireTag() DELETES tagged entries and keeps no queryable
214
+ * history, so invalidateTags() below writes its own "tm" marker entries and
215
+ * this compares them against the baked entry's build-time createdAt
216
+ * (>= so a same-millisecond invalidation wins). Fails open to `false` on
217
+ * read errors — the same posture as the CF marker check.
218
+ */
219
+ isTagsInvalidatedSince(tags: string[], sinceMs: number): Promise<boolean>;
220
+ invalidateTags(tags: string[]): Promise<void>;
221
+ private toStoreKey;
222
+ private write;
223
+ /**
224
+ * Normalize a value read back from the cache. Entries written by this store
225
+ * are pre-serialized JSON strings (see write()); legacy entries (written
226
+ * before that change, or by a client that deserializes for us) come back as
227
+ * objects. Parse strings, pass objects through, and treat a non-JSON string
228
+ * as corrupt (returns undefined, so the caller reports + evicts).
229
+ */
230
+ private decodeRaw;
231
+ /**
232
+ * Stale-read herd dampening via a tiny companion lock key. On a stale read,
233
+ * check `{storeKey}:lock`; if absent, claim it (write a short-TTL marker) and
234
+ * return true so THIS reader triggers revalidation. If present, another
235
+ * same-region reader already claimed it, so return false and serve the stale
236
+ * entry as fresh without piling on. Best-effort and non-blocking; never throws.
237
+ *
238
+ * Only the STALE path pays the extra lock read; the fresh-hit path takes no
239
+ * lock round trip. Unlike the prior whole-envelope re-stamp, a stale read now
240
+ * writes only the tiny lock, never the (potentially large) payload.
241
+ *
242
+ * Non-atomic (getCache has no compare-and-set): two readers can both find no
243
+ * lock and both revalidate. The window is REVALIDATION_LOCK_MS wide, after
244
+ * which the lock expires and the entry is re-claimed (or a fresh write has
245
+ * superseded it). A read-compare would not close the race without CAS.
246
+ */
247
+ private claimRevalidation;
248
+ /** Measure a pre-serialized entry against the per-item size cap (see write). */
249
+ private withinSizeLimit;
250
+ /**
251
+ * Drop tags Vercel cannot round-trip: over-length tags, and tags carrying a
252
+ * URL metacharacter the `@vercel/functions` client does not encode (see
253
+ * VERCEL_UNSAFE_TAG_CHARS). Runs on BOTH paths - the write path
254
+ * (clampTagsForWrite) and invalidateTags - so a tag that would silently fail
255
+ * invalidation is never stored in the first place. `category` reports the
256
+ * drop under the caller's real operation (write vs invalidate).
257
+ */
258
+ private validateTags;
259
+ /** validateTags + the per-item tag cap. Used on the write path. */
260
+ private clampTagsForWrite;
261
+ private safeDelete;
262
+ private emitDebug;
263
+ private asSegmentEnvelope;
264
+ private asItemEnvelope;
265
+ private asShellEnvelope;
266
+ private asResponseEnvelope;
267
+ }