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