vinext 0.0.30 → 0.0.31

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 (435) hide show
  1. package/README.md +12 -6
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +247 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +591 -571
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +430 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -380
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +374 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +442 -211
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +84 -113
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +82 -62
  70. package/dist/index.js +2172 -3133
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +560 -670
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +161 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +17 -14
  112. package/dist/server/dev-server.js +542 -869
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +181 -210
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +25 -22
  121. package/dist/server/instrumentation.js +110 -122
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +106 -128
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +270 -317
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +61 -61
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +31 -47
  136. package/dist/server/middleware.js +273 -404
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +38 -30
  142. package/dist/server/pages-i18n.js +112 -139
  143. package/dist/server/pages-i18n.js.map +1 -1
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +714 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +20 -45
  162. package/dist/shims/cache-runtime.js +271 -422
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +130 -121
  165. package/dist/shims/cache.js +339 -427
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +4 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -164
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +16 -14
  191. package/dist/shims/fetch-cache.js +437 -645
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +8 -13
  208. package/dist/shims/head-state.js +25 -42
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +16 -20
  211. package/dist/shims/head.js +172 -250
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -78
  214. package/dist/shims/headers.js +447 -575
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +16 -20
  217. package/dist/shims/i18n-context.js +35 -48
  218. package/dist/shims/i18n-context.js.map +1 -1
  219. package/dist/shims/i18n-state.d.ts +8 -14
  220. package/dist/shims/i18n-state.js +34 -42
  221. package/dist/shims/i18n-state.js.map +1 -1
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -46
  226. package/dist/shims/image.js +283 -308
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +6 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -37
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +255 -391
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -546
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +10 -18
  260. package/dist/shims/navigation-state.js +66 -74
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +505 -704
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -60
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -11
  274. package/dist/shims/request-state-types.js +0 -1
  275. package/dist/shims/router-state.d.ts +13 -10
  276. package/dist/shims/router-state.js +34 -43
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -85
  279. package/dist/shims/router.js +506 -628
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +175 -164
  287. package/dist/shims/server.js +462 -478
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +20 -20
  290. package/dist/shims/unified-request-context.js +81 -99
  291. package/dist/shims/unified-request-context.js.map +1 -1
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +17 -9
  305. package/dist/utils/domain-locale.js +36 -56
  306. package/dist/utils/domain-locale.js.map +1 -1
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +10 -9
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/pages-i18n.d.ts.map +0 -1
  367. package/dist/server/prod-server.d.ts.map +0 -1
  368. package/dist/server/request-log.d.ts.map +0 -1
  369. package/dist/server/request-pipeline.d.ts.map +0 -1
  370. package/dist/server/worker-utils.d.ts.map +0 -1
  371. package/dist/shims/amp.d.ts.map +0 -1
  372. package/dist/shims/app.d.ts.map +0 -1
  373. package/dist/shims/app.js.map +0 -1
  374. package/dist/shims/cache-runtime.d.ts.map +0 -1
  375. package/dist/shims/cache.d.ts.map +0 -1
  376. package/dist/shims/client-only.d.ts.map +0 -1
  377. package/dist/shims/client-only.js.map +0 -1
  378. package/dist/shims/compat-router.d.ts.map +0 -1
  379. package/dist/shims/config.d.ts.map +0 -1
  380. package/dist/shims/constants.d.ts.map +0 -1
  381. package/dist/shims/document.d.ts.map +0 -1
  382. package/dist/shims/dynamic.d.ts.map +0 -1
  383. package/dist/shims/error-boundary.d.ts.map +0 -1
  384. package/dist/shims/error.d.ts.map +0 -1
  385. package/dist/shims/fetch-cache.d.ts.map +0 -1
  386. package/dist/shims/font-google-base.d.ts.map +0 -1
  387. package/dist/shims/font-google.d.ts.map +0 -1
  388. package/dist/shims/font-google.generated.d.ts.map +0 -1
  389. package/dist/shims/font-google.js.map +0 -1
  390. package/dist/shims/font-local.d.ts.map +0 -1
  391. package/dist/shims/form.d.ts.map +0 -1
  392. package/dist/shims/head-state.d.ts.map +0 -1
  393. package/dist/shims/head.d.ts.map +0 -1
  394. package/dist/shims/headers.d.ts.map +0 -1
  395. package/dist/shims/i18n-context.d.ts.map +0 -1
  396. package/dist/shims/i18n-state.d.ts.map +0 -1
  397. package/dist/shims/image-config.d.ts.map +0 -1
  398. package/dist/shims/image.d.ts.map +0 -1
  399. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  400. package/dist/shims/internal/api-utils.js.map +0 -1
  401. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  402. package/dist/shims/internal/cookies.d.ts.map +0 -1
  403. package/dist/shims/internal/cookies.js.map +0 -1
  404. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  405. package/dist/shims/internal/router-context.d.ts.map +0 -1
  406. package/dist/shims/internal/utils.d.ts.map +0 -1
  407. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  408. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  409. package/dist/shims/legacy-image.d.ts.map +0 -1
  410. package/dist/shims/link.d.ts.map +0 -1
  411. package/dist/shims/metadata.d.ts.map +0 -1
  412. package/dist/shims/navigation-state.d.ts.map +0 -1
  413. package/dist/shims/navigation.d.ts.map +0 -1
  414. package/dist/shims/og.d.ts.map +0 -1
  415. package/dist/shims/og.js.map +0 -1
  416. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  417. package/dist/shims/request-context.d.ts.map +0 -1
  418. package/dist/shims/request-state-types.d.ts.map +0 -1
  419. package/dist/shims/request-state-types.js.map +0 -1
  420. package/dist/shims/router-state.d.ts.map +0 -1
  421. package/dist/shims/router.d.ts.map +0 -1
  422. package/dist/shims/script.d.ts.map +0 -1
  423. package/dist/shims/server-only.d.ts.map +0 -1
  424. package/dist/shims/server-only.js.map +0 -1
  425. package/dist/shims/server.d.ts.map +0 -1
  426. package/dist/shims/unified-request-context.d.ts.map +0 -1
  427. package/dist/shims/url-safety.d.ts.map +0 -1
  428. package/dist/shims/url-utils.d.ts.map +0 -1
  429. package/dist/shims/web-vitals.d.ts.map +0 -1
  430. package/dist/utils/base-path.d.ts.map +0 -1
  431. package/dist/utils/domain-locale.d.ts.map +0 -1
  432. package/dist/utils/hash.d.ts.map +0 -1
  433. package/dist/utils/manifest-paths.d.ts.map +0 -1
  434. package/dist/utils/project.d.ts.map +0 -1
  435. package/dist/utils/query.d.ts.map +0 -1
@@ -1,468 +1,317 @@
1
- /**
2
- * "use cache" runtime
3
- *
4
- * This module provides the runtime for "use cache" directive support.
5
- * Functions marked with "use cache" are transformed by the vinext:use-cache
6
- * Vite plugin to wrap them with `registerCachedFunction()`.
7
- *
8
- * The runtime:
9
- * 1. Generates a cache key from function identity + serialized arguments
10
- * 2. Checks the CacheHandler for a cached value
11
- * 3. On HIT: returns the cached value (deserialized via RSC stream)
12
- * 4. On MISS: creates an AsyncLocalStorage context for cacheLife/cacheTag,
13
- * calls the original function, serializes the result via RSC stream,
14
- * collects metadata, stores the result
15
- *
16
- * Serialization uses the RSC protocol (renderToReadableStream /
17
- * createFromReadableStream / encodeReply) from @vitejs/plugin-rsc.
18
- * This correctly handles React elements, client references, Promises,
19
- * and all RSC-serializable types — unlike JSON.stringify which silently
20
- * drops $$typeof Symbols and function values.
21
- *
22
- * When RSC APIs are unavailable (e.g. in unit tests), falls back to
23
- * JSON.stringify/parse with the same stableStringify cache key generation.
24
- *
25
- * Cache variants:
26
- * - "use cache" — shared cache (default profile)
27
- * - "use cache: remote" — shared cache (explicit)
28
- * - "use cache: private" — per-request cache (not shared across requests)
29
- */
1
+ import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
2
+ import { _registerCacheContextAccessor, cacheLifeProfiles, getCacheHandler } from "./cache.js";
30
3
  import { AsyncLocalStorage } from "node:async_hooks";
31
- import { getCacheHandler, cacheLifeProfiles, _registerCacheContextAccessor, } from "./cache.js";
32
- import { isInsideUnifiedScope, getRequestContext, runWithUnifiedStateMutation, } from "./unified-request-context.js";
33
- // Store on globalThis via Symbol so headers.ts can detect "use cache" scope
34
- // without a direct import (avoiding circular dependencies).
4
+ //#region src/shims/cache-runtime.ts
5
+ /**
6
+ * "use cache" runtime
7
+ *
8
+ * This module provides the runtime for "use cache" directive support.
9
+ * Functions marked with "use cache" are transformed by the vinext:use-cache
10
+ * Vite plugin to wrap them with `registerCachedFunction()`.
11
+ *
12
+ * The runtime:
13
+ * 1. Generates a cache key from function identity + serialized arguments
14
+ * 2. Checks the CacheHandler for a cached value
15
+ * 3. On HIT: returns the cached value (deserialized via RSC stream)
16
+ * 4. On MISS: creates an AsyncLocalStorage context for cacheLife/cacheTag,
17
+ * calls the original function, serializes the result via RSC stream,
18
+ * collects metadata, stores the result
19
+ *
20
+ * Serialization uses the RSC protocol (renderToReadableStream /
21
+ * createFromReadableStream / encodeReply) from @vitejs/plugin-rsc.
22
+ * This correctly handles React elements, client references, Promises,
23
+ * and all RSC-serializable types — unlike JSON.stringify which silently
24
+ * drops $$typeof Symbols and function values.
25
+ *
26
+ * When RSC APIs are unavailable (e.g. in unit tests), falls back to
27
+ * JSON.stringify/parse with the same stableStringify cache key generation.
28
+ *
29
+ * Cache variants:
30
+ * - "use cache" — shared cache (default profile)
31
+ * - "use cache: remote" — shared cache (explicit)
32
+ * - "use cache: private" — per-request cache (not shared across requests)
33
+ */
35
34
  const _CONTEXT_ALS_KEY = Symbol.for("vinext.cacheRuntime.contextAls");
36
35
  const _gCacheRuntime = globalThis;
37
- export const cacheContextStorage = (_gCacheRuntime[_CONTEXT_ALS_KEY] ??=
38
- new AsyncLocalStorage());
39
- // Register the context accessor so cacheLife()/cacheTag() in cache.ts can
40
- // access the context without a circular import.
36
+ const cacheContextStorage = _gCacheRuntime[_CONTEXT_ALS_KEY] ??= new AsyncLocalStorage();
41
37
  _registerCacheContextAccessor(() => cacheContextStorage.getStore() ?? null);
42
38
  /**
43
- * Get the current cache context. Returns null if not inside a "use cache" function.
44
- */
45
- export function getCacheContext() {
46
- return cacheContextStorage.getStore() ?? null;
39
+ * Get the current cache context. Returns null if not inside a "use cache" function.
40
+ */
41
+ function getCacheContext() {
42
+ return cacheContextStorage.getStore() ?? null;
47
43
  }
48
44
  const NOT_LOADED = Symbol("not-loaded");
49
45
  let _rscModule = NOT_LOADED;
50
46
  async function getRscModule() {
51
- if (_rscModule !== NOT_LOADED)
52
- return _rscModule;
53
- try {
54
- _rscModule = (await import("@vitejs/plugin-rsc/react/rsc"));
55
- }
56
- catch {
57
- _rscModule = null;
58
- }
59
- return _rscModule;
47
+ if (_rscModule !== NOT_LOADED) return _rscModule;
48
+ try {
49
+ _rscModule = await import("@vitejs/plugin-rsc/react/rsc");
50
+ } catch {
51
+ _rscModule = null;
52
+ }
53
+ return _rscModule;
60
54
  }
61
- // ---------------------------------------------------------------------------
62
- // RSC stream helpers
63
- // ---------------------------------------------------------------------------
64
55
  /** Collect a ReadableStream<Uint8Array> into a single Uint8Array. */
65
56
  async function collectStream(stream) {
66
- const reader = stream.getReader();
67
- const chunks = [];
68
- let totalLength = 0;
69
- for (;;) {
70
- const { done, value } = await reader.read();
71
- if (done)
72
- break;
73
- chunks.push(value);
74
- totalLength += value.length;
75
- }
76
- if (chunks.length === 1)
77
- return chunks[0];
78
- const result = new Uint8Array(totalLength);
79
- let offset = 0;
80
- for (const chunk of chunks) {
81
- result.set(chunk, offset);
82
- offset += chunk.length;
83
- }
84
- return result;
57
+ const reader = stream.getReader();
58
+ const chunks = [];
59
+ let totalLength = 0;
60
+ for (;;) {
61
+ const { done, value } = await reader.read();
62
+ if (done) break;
63
+ chunks.push(value);
64
+ totalLength += value.length;
65
+ }
66
+ if (chunks.length === 1) return chunks[0];
67
+ const result = new Uint8Array(totalLength);
68
+ let offset = 0;
69
+ for (const chunk of chunks) {
70
+ result.set(chunk, offset);
71
+ offset += chunk.length;
72
+ }
73
+ return result;
85
74
  }
86
75
  /** Encode a Uint8Array as a base64 string for storage. Uses Node Buffer. */
87
76
  function uint8ToBase64(bytes) {
88
- return Buffer.from(bytes).toString("base64");
77
+ return Buffer.from(bytes).toString("base64");
89
78
  }
90
79
  /** Decode a base64 string back to Uint8Array. Uses Node Buffer. */
91
80
  function base64ToUint8(base64) {
92
- return new Uint8Array(Buffer.from(base64, "base64"));
81
+ return new Uint8Array(Buffer.from(base64, "base64"));
93
82
  }
94
83
  /** Create a ReadableStream from a Uint8Array. */
95
84
  function uint8ToStream(bytes) {
96
- return new ReadableStream({
97
- start(controller) {
98
- controller.enqueue(bytes);
99
- controller.close();
100
- },
101
- });
85
+ return new ReadableStream({ start(controller) {
86
+ controller.enqueue(bytes);
87
+ controller.close();
88
+ } });
102
89
  }
103
90
  /**
104
- * Convert an encodeReply result (string | FormData) to a cache key string.
105
- * For FormData (binary args), produces a deterministic SHA-256 hash over
106
- * the sorted entries. We can't hash `new Response(formData).arrayBuffer()`
107
- * because multipart boundaries are non-deterministic across serializations.
108
- *
109
- * Exported for testing.
110
- */
111
- export async function replyToCacheKey(reply) {
112
- if (typeof reply === "string")
113
- return reply;
114
- // Collect entries in stable order (sorted by name, then by value for
115
- // entries with the same name) so the hash is deterministic.
116
- const entries = [...reply.entries()];
117
- const valStr = (v) => (typeof v === "string" ? v : v.name);
118
- entries.sort((a, b) => a[0].localeCompare(b[0]) || valStr(a[1]).localeCompare(valStr(b[1])));
119
- const parts = [];
120
- for (const [name, value] of entries) {
121
- if (typeof value === "string") {
122
- parts.push(`${name}=s:${value}`);
123
- }
124
- else {
125
- // Blob/File: include type, size, and content bytes
126
- const bytes = new Uint8Array(await value.arrayBuffer());
127
- parts.push(`${name}=b:${value.type}:${value.size}:${Buffer.from(bytes).toString("base64")}`);
128
- }
129
- }
130
- const payload = new TextEncoder().encode(parts.join("\0"));
131
- const hashBuffer = await crypto.subtle.digest("SHA-256", payload);
132
- return Buffer.from(new Uint8Array(hashBuffer)).toString("base64url");
91
+ * Convert an encodeReply result (string | FormData) to a cache key string.
92
+ * For FormData (binary args), produces a deterministic SHA-256 hash over
93
+ * the sorted entries. We can't hash `new Response(formData).arrayBuffer()`
94
+ * because multipart boundaries are non-deterministic across serializations.
95
+ *
96
+ * Exported for testing.
97
+ */
98
+ async function replyToCacheKey(reply) {
99
+ if (typeof reply === "string") return reply;
100
+ const entries = [...reply.entries()];
101
+ const valStr = (v) => typeof v === "string" ? v : v.name;
102
+ entries.sort((a, b) => a[0].localeCompare(b[0]) || valStr(a[1]).localeCompare(valStr(b[1])));
103
+ const parts = [];
104
+ for (const [name, value] of entries) if (typeof value === "string") parts.push(`${name}=s:${value}`);
105
+ else {
106
+ const bytes = new Uint8Array(await value.arrayBuffer());
107
+ parts.push(`${name}=b:${value.type}:${value.size}:${Buffer.from(bytes).toString("base64")}`);
108
+ }
109
+ const payload = new TextEncoder().encode(parts.join("\0"));
110
+ const hashBuffer = await crypto.subtle.digest("SHA-256", payload);
111
+ return Buffer.from(new Uint8Array(hashBuffer)).toString("base64url");
133
112
  }
134
- // ---------------------------------------------------------------------------
135
- // Minimum-wins resolution for cacheLife
136
- // ---------------------------------------------------------------------------
137
113
  /**
138
- * Resolve collected cacheLife configs into a single effective config.
139
- * The "minimum-wins" rule: if multiple cacheLife() calls are made,
140
- * each field takes the smallest value across all calls.
141
- */
114
+ * Resolve collected cacheLife configs into a single effective config.
115
+ * The "minimum-wins" rule: if multiple cacheLife() calls are made,
116
+ * each field takes the smallest value across all calls.
117
+ */
142
118
  function resolveCacheLife(configs) {
143
- if (configs.length === 0) {
144
- // Default profile
145
- return { ...cacheLifeProfiles.default };
146
- }
147
- if (configs.length === 1) {
148
- return { ...configs[0] };
149
- }
150
- // Minimum-wins across all fields
151
- const result = {};
152
- for (const config of configs) {
153
- if (config.stale !== undefined) {
154
- result.stale =
155
- result.stale !== undefined ? Math.min(result.stale, config.stale) : config.stale;
156
- }
157
- if (config.revalidate !== undefined) {
158
- result.revalidate =
159
- result.revalidate !== undefined
160
- ? Math.min(result.revalidate, config.revalidate)
161
- : config.revalidate;
162
- }
163
- if (config.expire !== undefined) {
164
- result.expire =
165
- result.expire !== undefined ? Math.min(result.expire, config.expire) : config.expire;
166
- }
167
- }
168
- return result;
119
+ if (configs.length === 0) return { ...cacheLifeProfiles.default };
120
+ if (configs.length === 1) return { ...configs[0] };
121
+ const result = {};
122
+ for (const config of configs) {
123
+ if (config.stale !== void 0) result.stale = result.stale !== void 0 ? Math.min(result.stale, config.stale) : config.stale;
124
+ if (config.revalidate !== void 0) result.revalidate = result.revalidate !== void 0 ? Math.min(result.revalidate, config.revalidate) : config.revalidate;
125
+ if (config.expire !== void 0) result.expire = result.expire !== void 0 ? Math.min(result.expire, config.expire) : config.expire;
126
+ }
127
+ return result;
169
128
  }
170
129
  const _PRIVATE_ALS_KEY = Symbol.for("vinext.cacheRuntime.privateAls");
171
130
  const _PRIVATE_FALLBACK_KEY = Symbol.for("vinext.cacheRuntime.privateFallback");
172
131
  const _g = globalThis;
173
- const _privateAls = (_g[_PRIVATE_ALS_KEY] ??=
174
- new AsyncLocalStorage());
175
- const _privateFallbackState = (_g[_PRIVATE_FALLBACK_KEY] ??= {
176
- _privateCache: new Map(),
177
- });
132
+ const _privateAls = _g[_PRIVATE_ALS_KEY] ??= new AsyncLocalStorage();
133
+ const _privateFallbackState = _g[_PRIVATE_FALLBACK_KEY] ??= { _privateCache: /* @__PURE__ */ new Map() };
178
134
  function _getPrivateState() {
179
- if (isInsideUnifiedScope()) {
180
- const ctx = getRequestContext();
181
- if (ctx._privateCache === null) {
182
- ctx._privateCache = new Map();
183
- }
184
- return ctx;
185
- }
186
- return _privateAls.getStore() ?? _privateFallbackState;
135
+ if (isInsideUnifiedScope()) {
136
+ const ctx = getRequestContext();
137
+ if (ctx._privateCache === null) ctx._privateCache = /* @__PURE__ */ new Map();
138
+ return ctx;
139
+ }
140
+ return _privateAls.getStore() ?? _privateFallbackState;
187
141
  }
188
142
  /**
189
- * Run a function within a private cache ALS scope.
190
- * Ensures per-request isolation for "use cache: private" entries
191
- * on concurrent runtimes.
192
- */
193
- export function runWithPrivateCache(fn) {
194
- if (isInsideUnifiedScope()) {
195
- return runWithUnifiedStateMutation((uCtx) => {
196
- uCtx._privateCache = new Map();
197
- }, fn);
198
- }
199
- const state = {
200
- _privateCache: new Map(),
201
- };
202
- return _privateAls.run(state, fn);
143
+ * Run a function within a private cache ALS scope.
144
+ * Ensures per-request isolation for "use cache: private" entries
145
+ * on concurrent runtimes.
146
+ */
147
+ function runWithPrivateCache(fn) {
148
+ if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
149
+ uCtx._privateCache = /* @__PURE__ */ new Map();
150
+ }, fn);
151
+ const state = { _privateCache: /* @__PURE__ */ new Map() };
152
+ return _privateAls.run(state, fn);
203
153
  }
204
154
  /**
205
- * Clear the private per-request cache. Should be called at the start of each request.
206
- * Only needed when not using runWithPrivateCache() (legacy path).
207
- */
208
- export function clearPrivateCache() {
209
- if (isInsideUnifiedScope()) {
210
- getRequestContext()._privateCache = new Map();
211
- return;
212
- }
213
- const state = _privateAls.getStore();
214
- if (state) {
215
- state._privateCache = new Map();
216
- }
217
- else {
218
- _privateFallbackState._privateCache = new Map();
219
- }
155
+ * Clear the private per-request cache. Should be called at the start of each request.
156
+ * Only needed when not using runWithPrivateCache() (legacy path).
157
+ */
158
+ function clearPrivateCache() {
159
+ if (isInsideUnifiedScope()) {
160
+ getRequestContext()._privateCache = /* @__PURE__ */ new Map();
161
+ return;
162
+ }
163
+ const state = _privateAls.getStore();
164
+ if (state) state._privateCache = /* @__PURE__ */ new Map();
165
+ else _privateFallbackState._privateCache = /* @__PURE__ */ new Map();
220
166
  }
221
- // ---------------------------------------------------------------------------
222
- // Core runtime: registerCachedFunction
223
- // ---------------------------------------------------------------------------
224
167
  /**
225
- * Register a function as a cached function. This is called by the Vite
226
- * transform for each "use cache" function.
227
- *
228
- * @param fn - The original async function
229
- * @param id - A stable identifier for the function (module path + export name)
230
- * @param variant - Cache variant: "" (default/shared), "remote", "private"
231
- * @returns A wrapper function that checks cache before calling the original
232
- */
233
- export function registerCachedFunction(fn, id, variant) {
234
- const cacheVariant = variant ?? "";
235
- // In dev mode, skip the shared cache so code changes are immediately
236
- // visible after HMR. Without this, the MemoryCacheHandler returns stale
237
- // results because the cache key (module path + export name) doesn't
238
- // change when the file is edited — only the function body changes.
239
- // Per-request ("use cache: private") caching still works in dev since
240
- // it's scoped to a single request and doesn't persist across HMR.
241
- const isDev = typeof process !== "undefined" && process.env.NODE_ENV === "development";
242
- const cachedFn = async (...args) => {
243
- const rsc = await getRscModule();
244
- // Build the cache key. Use encodeReply (RSC protocol) when available —
245
- // it correctly handles React elements as temporary references (excluded
246
- // from key). Falls back to stableStringify when RSC is unavailable.
247
- let cacheKey;
248
- try {
249
- if (rsc && args.length > 0) {
250
- // Temporary references let encodeReply handle non-serializable values
251
- // (like React elements in args) by excluding them from the key.
252
- const tempRefs = rsc.createClientTemporaryReferenceSet();
253
- // Unwrap Promise-augmented objects before encoding.
254
- // Next.js 16 params/searchParams are created via
255
- // Object.assign(Promise.resolve(obj), obj) — a Promise with own
256
- // enumerable properties. encodeReply treats Promises as temporary
257
- // references (excluded from the key), which means different param
258
- // values (e.g., section:"sports" vs section:"electronics") produce
259
- // identical cache keys. We must extract the plain data so the actual
260
- // values are included in the cache key.
261
- const processedArgs = unwrapThenableObjects(args);
262
- const encoded = await rsc.encodeReply(processedArgs, {
263
- temporaryReferences: tempRefs,
264
- });
265
- const argsKey = await replyToCacheKey(encoded);
266
- cacheKey = `use-cache:${id}:${argsKey}`;
267
- }
268
- else {
269
- const argsKey = args.length > 0 ? ":" + stableStringify(args) : "";
270
- cacheKey = `use-cache:${id}${argsKey}`;
271
- }
272
- }
273
- catch {
274
- // Non-serializable arguments — run without caching
275
- return fn(...args);
276
- }
277
- // "use cache: private" uses per-request in-memory cache
278
- if (cacheVariant === "private") {
279
- const privateCache = _getPrivateState()._privateCache;
280
- const privateHit = privateCache.get(cacheKey);
281
- if (privateHit !== undefined) {
282
- return privateHit;
283
- }
284
- const result = await executeWithContext(fn, args, cacheVariant);
285
- privateCache.set(cacheKey, result);
286
- return result;
287
- }
288
- // In dev mode, always execute fresh — skip shared cache lookup/storage.
289
- // This ensures HMR changes are reflected immediately.
290
- if (isDev) {
291
- return cacheContextStorage.run({ tags: [], lifeConfigs: [], variant: cacheVariant || "default" }, () => fn(...args));
292
- }
293
- // Shared cache ("use cache" / "use cache: remote")
294
- const handler = getCacheHandler();
295
- // Check cache — deserialize via RSC stream when available, JSON otherwise
296
- const existing = await handler.get(cacheKey, { kind: "FETCH" });
297
- if (existing?.value && existing.value.kind === "FETCH" && existing.cacheState !== "stale") {
298
- try {
299
- if (rsc && existing.value.data.headers["x-vinext-rsc"] === "1") {
300
- // RSC-serialized entry: base64 → bytes → stream → deserialize
301
- const bytes = base64ToUint8(existing.value.data.body);
302
- const stream = uint8ToStream(bytes);
303
- return await rsc.createFromReadableStream(stream);
304
- }
305
- // JSON-serialized entry (legacy or no RSC available)
306
- return JSON.parse(existing.value.data.body);
307
- }
308
- catch {
309
- // Corrupted entry, fall through to re-execute
310
- }
311
- }
312
- // Cache miss (or stale) — execute with context
313
- const ctx = {
314
- tags: [],
315
- lifeConfigs: [],
316
- variant: cacheVariant || "default",
317
- };
318
- const result = await cacheContextStorage.run(ctx, () => fn(...args));
319
- // Resolve effective cache life from collected configs
320
- const effectiveLife = resolveCacheLife(ctx.lifeConfigs);
321
- const revalidateSeconds = effectiveLife.revalidate ?? cacheLifeProfiles.default.revalidate ?? 900;
322
- // Store in cache — use RSC stream serialization when available (handles
323
- // React elements, client refs, Promises, etc.), JSON otherwise.
324
- try {
325
- let body;
326
- const headers = {};
327
- if (rsc) {
328
- // RSC serialization: result → stream → bytes → base64.
329
- // No temporaryReferences — cached values must be self-contained
330
- // since they're persisted across requests.
331
- const stream = rsc.renderToReadableStream(result);
332
- const bytes = await collectStream(stream);
333
- body = uint8ToBase64(bytes);
334
- headers["x-vinext-rsc"] = "1";
335
- }
336
- else {
337
- // JSON fallback
338
- body = JSON.stringify(result);
339
- if (body === undefined)
340
- return result;
341
- }
342
- const cacheValue = {
343
- kind: "FETCH",
344
- data: {
345
- headers,
346
- body,
347
- url: cacheKey,
348
- },
349
- tags: ctx.tags,
350
- revalidate: revalidateSeconds,
351
- };
352
- await handler.set(cacheKey, cacheValue, {
353
- fetchCache: true,
354
- tags: ctx.tags,
355
- revalidate: revalidateSeconds,
356
- });
357
- }
358
- catch {
359
- // Result not serializable — skip caching, still return the result
360
- }
361
- return result;
362
- };
363
- return cachedFn;
168
+ * Register a function as a cached function. This is called by the Vite
169
+ * transform for each "use cache" function.
170
+ *
171
+ * @param fn - The original async function
172
+ * @param id - A stable identifier for the function (module path + export name)
173
+ * @param variant - Cache variant: "" (default/shared), "remote", "private"
174
+ * @returns A wrapper function that checks cache before calling the original
175
+ */
176
+ function registerCachedFunction(fn, id, variant) {
177
+ const cacheVariant = variant ?? "";
178
+ const isDev = typeof process !== "undefined" && process.env.NODE_ENV === "development";
179
+ const cachedFn = async (...args) => {
180
+ const rsc = await getRscModule();
181
+ let cacheKey;
182
+ try {
183
+ if (rsc && args.length > 0) {
184
+ const tempRefs = rsc.createClientTemporaryReferenceSet();
185
+ const processedArgs = unwrapThenableObjects(args);
186
+ cacheKey = `use-cache:${id}:${await replyToCacheKey(await rsc.encodeReply(processedArgs, { temporaryReferences: tempRefs }))}`;
187
+ } else cacheKey = `use-cache:${id}${args.length > 0 ? ":" + stableStringify(args) : ""}`;
188
+ } catch {
189
+ return fn(...args);
190
+ }
191
+ if (cacheVariant === "private") {
192
+ const privateCache = _getPrivateState()._privateCache;
193
+ const privateHit = privateCache.get(cacheKey);
194
+ if (privateHit !== void 0) return privateHit;
195
+ const result = await executeWithContext(fn, args, cacheVariant);
196
+ privateCache.set(cacheKey, result);
197
+ return result;
198
+ }
199
+ if (isDev) return cacheContextStorage.run({
200
+ tags: [],
201
+ lifeConfigs: [],
202
+ variant: cacheVariant || "default"
203
+ }, () => fn(...args));
204
+ const handler = getCacheHandler();
205
+ const existing = await handler.get(cacheKey, { kind: "FETCH" });
206
+ if (existing?.value && existing.value.kind === "FETCH" && existing.cacheState !== "stale") try {
207
+ if (rsc && existing.value.data.headers["x-vinext-rsc"] === "1") {
208
+ const stream = uint8ToStream(base64ToUint8(existing.value.data.body));
209
+ return await rsc.createFromReadableStream(stream);
210
+ }
211
+ return JSON.parse(existing.value.data.body);
212
+ } catch {}
213
+ const ctx = {
214
+ tags: [],
215
+ lifeConfigs: [],
216
+ variant: cacheVariant || "default"
217
+ };
218
+ const result = await cacheContextStorage.run(ctx, () => fn(...args));
219
+ const revalidateSeconds = resolveCacheLife(ctx.lifeConfigs).revalidate ?? cacheLifeProfiles.default.revalidate ?? 900;
220
+ try {
221
+ let body;
222
+ const headers = {};
223
+ if (rsc) {
224
+ body = uint8ToBase64(await collectStream(rsc.renderToReadableStream(result)));
225
+ headers["x-vinext-rsc"] = "1";
226
+ } else {
227
+ body = JSON.stringify(result);
228
+ if (body === void 0) return result;
229
+ }
230
+ const cacheValue = {
231
+ kind: "FETCH",
232
+ data: {
233
+ headers,
234
+ body,
235
+ url: cacheKey
236
+ },
237
+ tags: ctx.tags,
238
+ revalidate: revalidateSeconds
239
+ };
240
+ await handler.set(cacheKey, cacheValue, {
241
+ fetchCache: true,
242
+ tags: ctx.tags,
243
+ revalidate: revalidateSeconds
244
+ });
245
+ } catch {}
246
+ return result;
247
+ };
248
+ return cachedFn;
364
249
  }
365
- // ---------------------------------------------------------------------------
366
- // Helper: execute function within cache context
367
- // ---------------------------------------------------------------------------
368
250
  async function executeWithContext(fn, args, variant) {
369
- const ctx = {
370
- tags: [],
371
- lifeConfigs: [],
372
- variant: variant || "default",
373
- };
374
- return cacheContextStorage.run(ctx, () => fn(...args));
251
+ const ctx = {
252
+ tags: [],
253
+ lifeConfigs: [],
254
+ variant: variant || "default"
255
+ };
256
+ return cacheContextStorage.run(ctx, () => fn(...args));
375
257
  }
376
- // ---------------------------------------------------------------------------
377
- // Unwrap Promise-augmented objects for cache key generation
378
- // ---------------------------------------------------------------------------
379
258
  /**
380
- * Recursively unwrap "thenable objects" — values created by
381
- * `Object.assign(Promise.resolve(obj), obj)` — into plain objects.
382
- *
383
- * Next.js 16 params and searchParams are passed as Promise-augmented objects
384
- * that work both as `await params` and `params.key`. When these are fed to
385
- * `encodeReply` with `temporaryReferences`, the Promise is treated as a
386
- * temporary reference and its actual values are **excluded** from the
387
- * serialized output. This means different param values (e.g.,
388
- * `section:"sports"` vs `section:"electronics"`) produce identical cache keys.
389
- *
390
- * This function extracts the own enumerable properties into plain objects
391
- * so `encodeReply` can serialize the actual values into the cache key.
392
- * Only used for cache key generation — the original Promise-augmented
393
- * objects are still passed to the actual function on cache miss.
394
- */
259
+ * Recursively unwrap "thenable objects" — values created by
260
+ * `Object.assign(Promise.resolve(obj), obj)` — into plain objects.
261
+ *
262
+ * Next.js 16 params and searchParams are passed as Promise-augmented objects
263
+ * that work both as `await params` and `params.key`. When these are fed to
264
+ * `encodeReply` with `temporaryReferences`, the Promise is treated as a
265
+ * temporary reference and its actual values are **excluded** from the
266
+ * serialized output. This means different param values (e.g.,
267
+ * `section:"sports"` vs `section:"electronics"`) produce identical cache keys.
268
+ *
269
+ * This function extracts the own enumerable properties into plain objects
270
+ * so `encodeReply` can serialize the actual values into the cache key.
271
+ * Only used for cache key generation — the original Promise-augmented
272
+ * objects are still passed to the actual function on cache miss.
273
+ */
395
274
  function unwrapThenableObjects(value) {
396
- if (value === null || value === undefined || typeof value !== "object") {
397
- return value;
398
- }
399
- if (Array.isArray(value)) {
400
- return value.map(unwrapThenableObjects);
401
- }
402
- // Detect thenable (Promise-like) with own enumerable properties —
403
- // this is the Object.assign(Promise.resolve(obj), obj) pattern.
404
- if (typeof value.then === "function") {
405
- const keys = Object.keys(value);
406
- if (keys.length > 0) {
407
- const plain = {};
408
- for (const key of keys) {
409
- plain[key] = unwrapThenableObjects(value[key]);
410
- }
411
- return plain;
412
- }
413
- // Pure Promise with no own properties — leave as-is
414
- return value;
415
- }
416
- // Regular object — recurse into values
417
- const result = {};
418
- for (const key of Object.keys(value)) {
419
- result[key] = unwrapThenableObjects(value[key]);
420
- }
421
- return result;
275
+ if (value === null || value === void 0 || typeof value !== "object") return value;
276
+ if (Array.isArray(value)) return value.map(unwrapThenableObjects);
277
+ if (typeof value.then === "function") {
278
+ const keys = Object.keys(value);
279
+ if (keys.length > 0) {
280
+ const plain = {};
281
+ for (const key of keys) plain[key] = unwrapThenableObjects(value[key]);
282
+ return plain;
283
+ }
284
+ return value;
285
+ }
286
+ const result = {};
287
+ for (const key of Object.keys(value)) result[key] = unwrapThenableObjects(value[key]);
288
+ return result;
422
289
  }
423
- // ---------------------------------------------------------------------------
424
- // Fallback: stable JSON serialization for cache keys (when RSC unavailable)
425
- // ---------------------------------------------------------------------------
426
290
  function stableStringify(value, seen) {
427
- if (value === undefined)
428
- return "undefined";
429
- if (value === null)
430
- return "null";
431
- // Bail on non-serializable primitives so the caller can skip caching
432
- if (typeof value === "function")
433
- throw new Error("Cannot serialize function");
434
- if (typeof value === "symbol")
435
- throw new Error("Cannot serialize symbol");
436
- if (Array.isArray(value)) {
437
- // Circular reference detection
438
- if (!seen)
439
- seen = new Set();
440
- if (seen.has(value))
441
- throw new Error("Circular reference");
442
- seen.add(value);
443
- const result = "[" + value.map((v) => stableStringify(v, seen)).join(",") + "]";
444
- seen.delete(value);
445
- return result;
446
- }
447
- if (typeof value === "object" && value !== null) {
448
- if (value instanceof Date) {
449
- return `Date(${value.getTime()})`;
450
- }
451
- // Circular reference detection
452
- if (!seen)
453
- seen = new Set();
454
- if (seen.has(value))
455
- throw new Error("Circular reference");
456
- seen.add(value);
457
- const keys = Object.keys(value).sort();
458
- const result = "{" +
459
- keys
460
- .map((k) => `${JSON.stringify(k)}:${stableStringify(value[k], seen)}`)
461
- .join(",") +
462
- "}";
463
- seen.delete(value);
464
- return result;
465
- }
466
- return JSON.stringify(value);
291
+ if (value === void 0) return "undefined";
292
+ if (value === null) return "null";
293
+ if (typeof value === "function") throw new Error("Cannot serialize function");
294
+ if (typeof value === "symbol") throw new Error("Cannot serialize symbol");
295
+ if (Array.isArray(value)) {
296
+ if (!seen) seen = /* @__PURE__ */ new Set();
297
+ if (seen.has(value)) throw new Error("Circular reference");
298
+ seen.add(value);
299
+ const result = "[" + value.map((v) => stableStringify(v, seen)).join(",") + "]";
300
+ seen.delete(value);
301
+ return result;
302
+ }
303
+ if (typeof value === "object" && value !== null) {
304
+ if (value instanceof Date) return `Date(${value.getTime()})`;
305
+ if (!seen) seen = /* @__PURE__ */ new Set();
306
+ if (seen.has(value)) throw new Error("Circular reference");
307
+ seen.add(value);
308
+ const result = "{" + Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stableStringify(value[k], seen)}`).join(",") + "}";
309
+ seen.delete(value);
310
+ return result;
311
+ }
312
+ return JSON.stringify(value);
467
313
  }
314
+ //#endregion
315
+ export { cacheContextStorage, clearPrivateCache, getCacheContext, registerCachedFunction, replyToCacheKey, runWithPrivateCache };
316
+
468
317
  //# sourceMappingURL=cache-runtime.js.map