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,470 +1,391 @@
1
- /**
2
- * next/cache shim
3
- *
4
- * Provides the Next.js caching API surface: revalidateTag, revalidatePath,
5
- * unstable_cache. Backed by a pluggable CacheHandler that defaults to
6
- * in-memory but can be swapped for Cloudflare KV, Redis, DynamoDB, etc.
7
- *
8
- * The CacheHandler interface matches Next.js 16's CacheHandler class, so
9
- * existing community adapters (@neshca/cache-handler, @opennextjs/aws, etc.)
10
- * can be used directly.
11
- *
12
- * Configuration (in vite.config.ts or next.config.js):
13
- * vinext({ cacheHandler: './my-cache-handler.ts' })
14
- *
15
- * Or set at runtime:
16
- * import { setCacheHandler } from 'next/cache';
17
- * setCacheHandler(new MyCacheHandler());
18
- */
19
- import { markDynamicUsage as _markDynamic } from "./headers.js";
20
- import { AsyncLocalStorage } from "node:async_hooks";
1
+ import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
2
+ import { getRequestExecutionContext, runWithExecutionContext } from "./request-context.js";
3
+ import { markDynamicUsage } from "./headers.js";
21
4
  import { fnv1a64 } from "../utils/hash.js";
5
+ import { AsyncLocalStorage } from "node:async_hooks";
6
+ //#region src/shims/cache.ts
7
+ /**
8
+ * next/cache shim
9
+ *
10
+ * Provides the Next.js caching API surface: revalidateTag, revalidatePath,
11
+ * unstable_cache. Backed by a pluggable CacheHandler that defaults to
12
+ * in-memory but can be swapped for Cloudflare KV, Redis, DynamoDB, etc.
13
+ *
14
+ * The CacheHandler interface matches Next.js 16's CacheHandler class, so
15
+ * existing community adapters (@neshca/cache-handler, @opennextjs/aws, etc.)
16
+ * can be used directly.
17
+ *
18
+ * Configuration (in vite.config.ts or next.config.js):
19
+ * vinext({ cacheHandler: './my-cache-handler.ts' })
20
+ *
21
+ * Or set at runtime:
22
+ * import { setCacheHandler } from 'next/cache';
23
+ * setCacheHandler(new MyCacheHandler());
24
+ */
22
25
  /** @internal Set by cache-runtime.ts on import to avoid circular dependency */
23
26
  let _getCacheContextFn = null;
24
27
  /**
25
- * Register the cache context accessor. Called by cache-runtime.ts on load.
26
- * @internal
27
- */
28
- export function _registerCacheContextAccessor(fn) {
29
- _getCacheContextFn = fn;
30
- }
31
- export class MemoryCacheHandler {
32
- store = new Map();
33
- tagRevalidatedAt = new Map();
34
- async get(key, _ctx) {
35
- const entry = this.store.get(key);
36
- if (!entry)
37
- return null;
38
- // Check tag-based invalidation first — if tag was invalidated, treat as hard miss
39
- for (const tag of entry.tags) {
40
- const revalidatedAt = this.tagRevalidatedAt.get(tag);
41
- if (revalidatedAt && revalidatedAt >= entry.lastModified) {
42
- this.store.delete(key);
43
- return null;
44
- }
45
- }
46
- // Check time-based expiry — return stale entry with cacheState="stale"
47
- // instead of deleting, so ISR can serve stale-while-revalidate
48
- if (entry.revalidateAt !== null && Date.now() > entry.revalidateAt) {
49
- return {
50
- lastModified: entry.lastModified,
51
- value: entry.value,
52
- cacheState: "stale",
53
- };
54
- }
55
- return {
56
- lastModified: entry.lastModified,
57
- value: entry.value,
58
- };
59
- }
60
- async set(key, data, ctx) {
61
- const tags = [];
62
- if (data && "tags" in data && Array.isArray(data.tags)) {
63
- tags.push(...data.tags);
64
- }
65
- if (ctx && "tags" in ctx && Array.isArray(ctx.tags)) {
66
- tags.push(...ctx.tags);
67
- }
68
- let revalidateAt = null;
69
- if (ctx) {
70
- // Handle both old-style { revalidate } and new-style { cacheControl: { revalidate } }
71
- const revalidate = ctx.cacheControl?.revalidate ?? ctx.revalidate;
72
- if (typeof revalidate === "number" && revalidate > 0) {
73
- revalidateAt = Date.now() + revalidate * 1000;
74
- }
75
- }
76
- if (data && "revalidate" in data && typeof data.revalidate === "number") {
77
- revalidateAt = Date.now() + data.revalidate * 1000;
78
- }
79
- this.store.set(key, {
80
- value: data,
81
- tags,
82
- lastModified: Date.now(),
83
- revalidateAt,
84
- });
85
- }
86
- async revalidateTag(tags, _durations) {
87
- const tagList = Array.isArray(tags) ? tags : [tags];
88
- const now = Date.now();
89
- for (const tag of tagList) {
90
- this.tagRevalidatedAt.set(tag, now);
91
- }
92
- }
93
- resetRequestCache() {
94
- // No-op for the simple memory cache. In a production adapter,
95
- // this would clear per-request caches (e.g., dedup fetch calls).
96
- }
28
+ * Register the cache context accessor. Called by cache-runtime.ts on load.
29
+ * @internal
30
+ */
31
+ function _registerCacheContextAccessor(fn) {
32
+ _getCacheContextFn = fn;
97
33
  }
98
- export { runWithExecutionContext, getRequestExecutionContext } from "./request-context.js";
99
- // ---------------------------------------------------------------------------
100
- // Active cache handler — the singleton used by next/cache API functions.
101
- // Defaults to MemoryCacheHandler, can be swapped at runtime.
102
- //
103
- // Stored on globalThis via Symbol.for so that setCacheHandler() called in the
104
- // Cloudflare Worker environment (worker/index.ts) is visible to getCacheHandler()
105
- // called in the RSC environment (generated RSC entry). Without this, the two
106
- // environments load separate module instances and operate on different
107
- // `activeHandler` variables setCacheHandler sets KVCacheHandler in one copy,
108
- // but getCacheHandler returns MemoryCacheHandler from the other copy.
109
- // ---------------------------------------------------------------------------
34
+ var NoOpCacheHandler = class {
35
+ async get(_key, _ctx) {
36
+ return null;
37
+ }
38
+ async set(_key, _data, _ctx) {}
39
+ async revalidateTag(_tags, _durations) {}
40
+ };
41
+ var MemoryCacheHandler = class {
42
+ store = /* @__PURE__ */ new Map();
43
+ tagRevalidatedAt = /* @__PURE__ */ new Map();
44
+ async get(key, _ctx) {
45
+ const entry = this.store.get(key);
46
+ if (!entry) return null;
47
+ for (const tag of entry.tags) {
48
+ const revalidatedAt = this.tagRevalidatedAt.get(tag);
49
+ if (revalidatedAt && revalidatedAt >= entry.lastModified) {
50
+ this.store.delete(key);
51
+ return null;
52
+ }
53
+ }
54
+ if (entry.revalidateAt !== null && Date.now() > entry.revalidateAt) return {
55
+ lastModified: entry.lastModified,
56
+ value: entry.value,
57
+ cacheState: "stale"
58
+ };
59
+ return {
60
+ lastModified: entry.lastModified,
61
+ value: entry.value
62
+ };
63
+ }
64
+ async set(key, data, ctx) {
65
+ const typedCtx = ctx;
66
+ const tagSet = /* @__PURE__ */ new Set();
67
+ if (data && "tags" in data && Array.isArray(data.tags)) for (const t of data.tags) tagSet.add(t);
68
+ if (typedCtx && Array.isArray(typedCtx.tags)) for (const t of typedCtx.tags) tagSet.add(t);
69
+ const tags = [...tagSet];
70
+ let effectiveRevalidate;
71
+ if (typedCtx) {
72
+ const revalidate = typedCtx.cacheControl?.revalidate ?? typedCtx.revalidate;
73
+ if (typeof revalidate === "number") effectiveRevalidate = revalidate;
74
+ }
75
+ if (data && "revalidate" in data && typeof data.revalidate === "number") effectiveRevalidate = data.revalidate;
76
+ if (effectiveRevalidate === 0) return;
77
+ const revalidateAt = typeof effectiveRevalidate === "number" && effectiveRevalidate > 0 ? Date.now() + effectiveRevalidate * 1e3 : null;
78
+ this.store.set(key, {
79
+ value: data,
80
+ tags,
81
+ lastModified: Date.now(),
82
+ revalidateAt
83
+ });
84
+ }
85
+ async revalidateTag(tags, _durations) {
86
+ const tagList = Array.isArray(tags) ? tags : [tags];
87
+ const now = Date.now();
88
+ for (const tag of tagList) this.tagRevalidatedAt.set(tag, now);
89
+ }
90
+ resetRequestCache() {}
91
+ };
110
92
  const _HANDLER_KEY = Symbol.for("vinext.cacheHandler");
111
93
  const _gHandler = globalThis;
112
94
  function _getActiveHandler() {
113
- return _gHandler[_HANDLER_KEY] ?? (_gHandler[_HANDLER_KEY] = new MemoryCacheHandler());
95
+ return _gHandler[_HANDLER_KEY] ?? (_gHandler[_HANDLER_KEY] = new MemoryCacheHandler());
114
96
  }
115
97
  /**
116
- * Set a custom CacheHandler. Call this during server startup to
117
- * plug in Cloudflare KV, Redis, DynamoDB, or any other backend.
118
- *
119
- * The handler must implement the CacheHandler interface (same shape
120
- * as Next.js 16's CacheHandler class).
121
- */
122
- export function setCacheHandler(handler) {
123
- _gHandler[_HANDLER_KEY] = handler;
98
+ * Set a custom CacheHandler. Call this during server startup to
99
+ * plug in Cloudflare KV, Redis, DynamoDB, or any other backend.
100
+ *
101
+ * The handler must implement the CacheHandler interface (same shape
102
+ * as Next.js 16's CacheHandler class).
103
+ */
104
+ function setCacheHandler(handler) {
105
+ _gHandler[_HANDLER_KEY] = handler;
124
106
  }
125
107
  /**
126
- * Get the active CacheHandler (for internal use or testing).
127
- */
128
- export function getCacheHandler() {
129
- return _getActiveHandler();
108
+ * Get the active CacheHandler (for internal use or testing).
109
+ */
110
+ function getCacheHandler() {
111
+ return _getActiveHandler();
130
112
  }
131
- // ---------------------------------------------------------------------------
132
- // Public API — what app code imports from 'next/cache'
133
- // ---------------------------------------------------------------------------
134
113
  /**
135
- * Revalidate cached data associated with a specific cache tag.
136
- *
137
- * Works with both `fetch(..., { next: { tags: ['myTag'] } })` and
138
- * `unstable_cache(fn, keys, { tags: ['myTag'] })`.
139
- */
140
- /**
141
- * Revalidate cached data associated with a specific cache tag.
142
- *
143
- * Next.js 16 updated signature: requires a cacheLife profile as second argument
144
- * for stale-while-revalidate (SWR) behavior. The single-argument form is
145
- * deprecated but still supported for backward compatibility.
146
- *
147
- * @param tag - Cache tag to revalidate
148
- * @param profile - cacheLife profile name (e.g. 'max', 'hours') or inline { expire: number }
149
- */
150
- export async function revalidateTag(tag, profile) {
151
- // Resolve the profile to durations for the handler
152
- let durations;
153
- if (typeof profile === "string") {
154
- const resolved = cacheLifeProfiles[profile];
155
- if (resolved) {
156
- durations = { expire: resolved.expire };
157
- }
158
- }
159
- else if (profile && typeof profile === "object") {
160
- durations = profile;
161
- }
162
- await _getActiveHandler().revalidateTag(tag, durations);
114
+ * Revalidate cached data associated with a specific cache tag.
115
+ *
116
+ * Works with both `fetch(..., { next: { tags: ['myTag'] } })` and
117
+ * `unstable_cache(fn, keys, { tags: ['myTag'] })`.
118
+ *
119
+ * Next.js 16 updated signature: accepts a cacheLife profile as second argument
120
+ * for stale-while-revalidate (SWR) behavior. The single-argument form is
121
+ * deprecated but still supported for backward compatibility.
122
+ *
123
+ * @param tag - Cache tag to revalidate
124
+ * @param profile - cacheLife profile name (e.g. 'max', 'hours') or inline { expire: number }
125
+ */
126
+ async function revalidateTag(tag, profile) {
127
+ let durations;
128
+ if (typeof profile === "string") {
129
+ const resolved = cacheLifeProfiles[profile];
130
+ if (resolved) durations = { expire: resolved.expire };
131
+ } else if (profile && typeof profile === "object") durations = profile;
132
+ await _getActiveHandler().revalidateTag(tag, durations);
163
133
  }
164
134
  /**
165
- * Revalidate cached data associated with a specific path.
166
- *
167
- * Under the hood, Next.js converts paths to internal tags.
168
- * We use a `_N_T_/path` prefix convention for path-based tags.
169
- */
170
- export async function revalidatePath(path, _type) {
171
- // Next.js internally converts paths to tags with a prefix
172
- const pathTag = `_N_T_${path}`;
173
- await _getActiveHandler().revalidateTag([path, pathTag]);
135
+ * Revalidate cached data associated with a specific path.
136
+ *
137
+ * Invalidation works through implicit tags generated at render time by
138
+ * `__pageCacheTags` (in app-rsc-entry.ts), matching Next.js's getDerivedTags:
139
+ *
140
+ * - `type: "layout"` → invalidates `_N_T_<path>/layout`, cascading to all
141
+ * descendant pages (they carry ancestor layout tags from render time).
142
+ * - `type: "page"` → invalidates `_N_T_<path>/page`, targeting only the
143
+ * exact route's page component.
144
+ * - No type → invalidates `_N_T_<path>` (broader, exact path).
145
+ *
146
+ * The `type` parameter is App Router only — Pages Router does not generate
147
+ * layout/page hierarchy tags, so only no-type invalidation applies there.
148
+ */
149
+ async function revalidatePath(path, type) {
150
+ const stem = path.endsWith("/") ? path.slice(0, -1) : path;
151
+ const tag = type ? `_N_T_${stem}/${type}` : `_N_T_${stem || "/"}`;
152
+ await _getActiveHandler().revalidateTag(tag);
174
153
  }
175
154
  /**
176
- * Expire and immediately refresh cached data for a tag (Next.js 16).
177
- *
178
- * Server Actions-only API that provides read-your-writes semantics:
179
- * the cache entry is expired and fresh data is read within the same request,
180
- * so the user immediately sees their changes.
181
- *
182
- * Use this for interactive features (forms, user settings) where users
183
- * expect to see their updates instantly.
184
- *
185
- * @param tag - Cache tag to expire and refresh
186
- */
187
- export async function updateTag(tag) {
188
- // Expire the tag immediately (same as revalidateTag without SWR)
189
- await _getActiveHandler().revalidateTag(tag);
190
- }
155
+ * No-op shim for API compatibility.
156
+ *
157
+ * In Next.js, calling `refresh()` inside a Server Action triggers a
158
+ * client-side router refresh so the user immediately sees updated data.
159
+ * vinext does not yet implement the Server Actions refresh protocol,
160
+ * so this function has no effect.
161
+ */
162
+ function refresh() {}
191
163
  /**
192
- * Refresh uncached data on the page (Next.js 16).
193
- *
194
- * Server Actions-only API that signals the client to re-fetch dynamic
195
- * (uncached) data without touching the cache. Complementary to the
196
- * client-side router.refresh().
197
- *
198
- * Use this when you need to refresh data like notification counts,
199
- * live metrics, or status indicators after performing a server action.
200
- */
201
- export function refresh() {
202
- // In our implementation, this is a signal that the client should
203
- // refresh dynamic data. The actual refresh happens on the client side
204
- // via the RSC protocol — the server action response triggers a
205
- // client-side navigation refresh.
206
- // For now, this is a no-op on the server; the Server Action response
207
- // mechanism already handles re-rendering the affected RSC tree.
164
+ * Expire a cache tag immediately (Next.js 16).
165
+ *
166
+ * Server Actions-only API that expires a tag so the next request
167
+ * fetches fresh data. Unlike `revalidateTag`, which uses stale-while-revalidate,
168
+ * `updateTag` invalidates synchronously within the same request context.
169
+ */
170
+ async function updateTag(tag) {
171
+ await _getActiveHandler().revalidateTag(tag);
208
172
  }
209
173
  /**
210
- * Opt out of static rendering and indicate a particular component should not be cached.
211
- *
212
- * In Next.js, calling noStore() inside a Server Component ensures the component
213
- * is dynamically rendered. In our implementation, this is a no-op since we don't
214
- * have the same static/dynamic rendering split — all server rendering is on-demand.
215
- * It's provided for API compatibility so apps importing it don't break.
216
- */
217
- export function unstable_noStore() {
218
- // Signal dynamic usage so ISR-configured routes bypass the cache
219
- _markDynamic();
174
+ * Opt out of static rendering and indicate a particular component should not be cached.
175
+ *
176
+ * In Next.js, calling noStore() inside a Server Component ensures the component
177
+ * is dynamically rendered. In our implementation, this is a no-op since we don't
178
+ * have the same static/dynamic rendering split — all server rendering is on-demand.
179
+ * It's provided for API compatibility so apps importing it don't break.
180
+ */
181
+ function unstable_noStore() {
182
+ markDynamicUsage();
220
183
  }
221
- // Also export as `noStore` (Next.js 15+ naming)
222
- export { unstable_noStore as noStore };
223
184
  const _ALS_KEY = Symbol.for("vinext.cache.als");
224
185
  const _FALLBACK_KEY = Symbol.for("vinext.cache.fallback");
225
186
  const _g = globalThis;
226
- const _cacheAls = (_g[_ALS_KEY] ??=
227
- new AsyncLocalStorage());
228
- const _cacheFallbackState = (_g[_FALLBACK_KEY] ??= {
229
- requestScopedCacheLife: null,
230
- });
187
+ const _cacheAls = _g[_ALS_KEY] ??= new AsyncLocalStorage();
188
+ const _cacheFallbackState = _g[_FALLBACK_KEY] ??= { requestScopedCacheLife: null };
231
189
  function _getCacheState() {
232
- return _cacheAls.getStore() ?? _cacheFallbackState;
190
+ if (isInsideUnifiedScope()) return getRequestContext();
191
+ return _cacheAls.getStore() ?? _cacheFallbackState;
233
192
  }
234
193
  /**
235
- * Run a function within a cache state ALS scope.
236
- * Ensures per-request isolation for request-scoped cacheLife config
237
- * on concurrent runtimes.
238
- * @internal
239
- */
240
- export function _runWithCacheState(fn) {
241
- const state = {
242
- requestScopedCacheLife: null,
243
- };
244
- return _cacheAls.run(state, fn);
194
+ * Run a function within a cache state ALS scope.
195
+ * Ensures per-request isolation for request-scoped cacheLife config
196
+ * on concurrent runtimes.
197
+ * @internal
198
+ */
199
+ function _runWithCacheState(fn) {
200
+ if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
201
+ uCtx.requestScopedCacheLife = null;
202
+ }, fn);
203
+ return _cacheAls.run({ requestScopedCacheLife: null }, fn);
245
204
  }
246
205
  /**
247
- * Initialize cache ALS for a new request. Call at request entry.
248
- * Only needed when not using _runWithCacheState() (legacy path).
249
- * @internal
250
- */
251
- export function _initRequestScopedCacheState() {
252
- const state = _cacheAls.getStore();
253
- if (state) {
254
- state.requestScopedCacheLife = null;
255
- }
256
- else {
257
- _cacheFallbackState.requestScopedCacheLife = null;
258
- }
206
+ * Initialize cache ALS for a new request. Call at request entry.
207
+ * Only needed when not using _runWithCacheState() (legacy path).
208
+ * @internal
209
+ */
210
+ function _initRequestScopedCacheState() {
211
+ _getCacheState().requestScopedCacheLife = null;
259
212
  }
260
213
  /**
261
- * Set a request-scoped cache life config. Called by cacheLife() when outside
262
- * a "use cache" function context.
263
- * @internal
264
- */
265
- export function _setRequestScopedCacheLife(config) {
266
- const state = _getCacheState();
267
- if (state.requestScopedCacheLife === null) {
268
- state.requestScopedCacheLife = { ...config };
269
- }
270
- else {
271
- // Minimum-wins rule
272
- if (config.stale !== undefined) {
273
- state.requestScopedCacheLife.stale =
274
- state.requestScopedCacheLife.stale !== undefined
275
- ? Math.min(state.requestScopedCacheLife.stale, config.stale)
276
- : config.stale;
277
- }
278
- if (config.revalidate !== undefined) {
279
- state.requestScopedCacheLife.revalidate =
280
- state.requestScopedCacheLife.revalidate !== undefined
281
- ? Math.min(state.requestScopedCacheLife.revalidate, config.revalidate)
282
- : config.revalidate;
283
- }
284
- if (config.expire !== undefined) {
285
- state.requestScopedCacheLife.expire =
286
- state.requestScopedCacheLife.expire !== undefined
287
- ? Math.min(state.requestScopedCacheLife.expire, config.expire)
288
- : config.expire;
289
- }
290
- }
214
+ * Set a request-scoped cache life config. Called by cacheLife() when outside
215
+ * a "use cache" function context.
216
+ * @internal
217
+ */
218
+ function _setRequestScopedCacheLife(config) {
219
+ const state = _getCacheState();
220
+ if (state.requestScopedCacheLife === null) state.requestScopedCacheLife = { ...config };
221
+ else {
222
+ if (config.stale !== void 0) state.requestScopedCacheLife.stale = state.requestScopedCacheLife.stale !== void 0 ? Math.min(state.requestScopedCacheLife.stale, config.stale) : config.stale;
223
+ if (config.revalidate !== void 0) state.requestScopedCacheLife.revalidate = state.requestScopedCacheLife.revalidate !== void 0 ? Math.min(state.requestScopedCacheLife.revalidate, config.revalidate) : config.revalidate;
224
+ if (config.expire !== void 0) state.requestScopedCacheLife.expire = state.requestScopedCacheLife.expire !== void 0 ? Math.min(state.requestScopedCacheLife.expire, config.expire) : config.expire;
225
+ }
291
226
  }
292
227
  /**
293
- * Consume and reset the request-scoped cache life. Returns null if none was set.
294
- * @internal
295
- */
296
- export function _consumeRequestScopedCacheLife() {
297
- const state = _getCacheState();
298
- const config = state.requestScopedCacheLife;
299
- state.requestScopedCacheLife = null;
300
- return config;
228
+ * Consume and reset the request-scoped cache life. Returns null if none was set.
229
+ * @internal
230
+ */
231
+ function _consumeRequestScopedCacheLife() {
232
+ const state = _getCacheState();
233
+ const config = state.requestScopedCacheLife;
234
+ state.requestScopedCacheLife = null;
235
+ return config;
301
236
  }
302
237
  /**
303
- * Built-in cache life profiles matching Next.js 16.
304
- */
305
- export const cacheLifeProfiles = {
306
- default: { revalidate: 900, expire: 4294967294 },
307
- seconds: { stale: 30, revalidate: 1, expire: 60 },
308
- minutes: { stale: 300, revalidate: 60, expire: 3600 },
309
- hours: { stale: 300, revalidate: 3600, expire: 86400 },
310
- days: { stale: 300, revalidate: 86400, expire: 604800 },
311
- weeks: { stale: 300, revalidate: 604800, expire: 2592000 },
312
- max: { stale: 300, revalidate: 2592000, expire: 31536000 },
238
+ * Built-in cache life profiles matching Next.js 16.
239
+ */
240
+ const cacheLifeProfiles = {
241
+ default: {
242
+ revalidate: 900,
243
+ expire: 4294967294
244
+ },
245
+ seconds: {
246
+ stale: 30,
247
+ revalidate: 1,
248
+ expire: 60
249
+ },
250
+ minutes: {
251
+ stale: 300,
252
+ revalidate: 60,
253
+ expire: 3600
254
+ },
255
+ hours: {
256
+ stale: 300,
257
+ revalidate: 3600,
258
+ expire: 86400
259
+ },
260
+ days: {
261
+ stale: 300,
262
+ revalidate: 86400,
263
+ expire: 604800
264
+ },
265
+ weeks: {
266
+ stale: 300,
267
+ revalidate: 604800,
268
+ expire: 2592e3
269
+ },
270
+ max: {
271
+ stale: 300,
272
+ revalidate: 2592e3,
273
+ expire: 31536e3
274
+ }
313
275
  };
314
276
  /**
315
- * Set the cache lifetime for a "use cache" function.
316
- *
317
- * Accepts either a built-in profile name (e.g., "hours", "days") or a custom
318
- * configuration object. In Next.js, this only works inside "use cache" functions.
319
- *
320
- * When called inside a "use cache" function, this sets the cache TTL.
321
- * The "minimum-wins" rule applies: if called multiple times, the shortest
322
- * duration for each field wins.
323
- *
324
- * When called outside a "use cache" context, this is a validated no-op.
325
- */
326
- export function cacheLife(profile) {
327
- let resolvedConfig;
328
- if (typeof profile === "string") {
329
- // Validate the profile name exists
330
- if (!cacheLifeProfiles[profile]) {
331
- console.warn(`[vinext] cacheLife: unknown profile "${profile}". ` +
332
- `Available profiles: ${Object.keys(cacheLifeProfiles).join(", ")}`);
333
- return;
334
- }
335
- resolvedConfig = { ...cacheLifeProfiles[profile] };
336
- }
337
- else if (typeof profile === "object" && profile !== null) {
338
- // Validate the config shape
339
- if (profile.expire !== undefined &&
340
- profile.revalidate !== undefined &&
341
- profile.expire < profile.revalidate) {
342
- console.warn("[vinext] cacheLife: expire must be >= revalidate");
343
- }
344
- resolvedConfig = { ...profile };
345
- }
346
- else {
347
- return;
348
- }
349
- // If we're inside a "use cache" context, push the config
350
- try {
351
- const ctx = _getCacheContextFn?.();
352
- if (ctx) {
353
- ctx.lifeConfigs.push(resolvedConfig);
354
- return;
355
- }
356
- }
357
- catch {
358
- // Fall through to request-scoped
359
- }
360
- // Outside a "use cache" context (e.g., page component with file-level "use cache"):
361
- // store as request-scoped so the server can read it after rendering.
362
- _setRequestScopedCacheLife(resolvedConfig);
277
+ * Set the cache lifetime for a "use cache" function.
278
+ *
279
+ * Accepts either a built-in profile name (e.g., "hours", "days") or a custom
280
+ * configuration object. In Next.js, this only works inside "use cache" functions.
281
+ *
282
+ * When called inside a "use cache" function, this sets the cache TTL.
283
+ * The "minimum-wins" rule applies: if called multiple times, the shortest
284
+ * duration for each field wins.
285
+ *
286
+ * When called outside a "use cache" context, this is a validated no-op.
287
+ */
288
+ function cacheLife(profile) {
289
+ let resolvedConfig;
290
+ if (typeof profile === "string") {
291
+ if (!cacheLifeProfiles[profile]) {
292
+ console.warn(`[vinext] cacheLife: unknown profile "${profile}". Available profiles: ${Object.keys(cacheLifeProfiles).join(", ")}`);
293
+ return;
294
+ }
295
+ resolvedConfig = { ...cacheLifeProfiles[profile] };
296
+ } else if (typeof profile === "object" && profile !== null) {
297
+ if (profile.expire !== void 0 && profile.revalidate !== void 0 && profile.expire < profile.revalidate) console.warn("[vinext] cacheLife: expire must be >= revalidate");
298
+ resolvedConfig = { ...profile };
299
+ } else return;
300
+ try {
301
+ const ctx = _getCacheContextFn?.();
302
+ if (ctx) {
303
+ ctx.lifeConfigs.push(resolvedConfig);
304
+ return;
305
+ }
306
+ } catch {}
307
+ _setRequestScopedCacheLife(resolvedConfig);
363
308
  }
364
309
  /**
365
- * Tag a "use cache" function's cached result for on-demand revalidation.
366
- *
367
- * Tags set here can be invalidated via revalidateTag(). In Next.js, this only
368
- * works inside "use cache" functions.
369
- *
370
- * When called inside a "use cache" function, tags are attached to the cached
371
- * entry. They can later be invalidated via revalidateTag().
372
- *
373
- * When called outside a "use cache" context, this is a no-op.
374
- */
375
- export function cacheTag(...tags) {
376
- try {
377
- const ctx = _getCacheContextFn?.();
378
- if (ctx) {
379
- ctx.tags.push(...tags);
380
- }
381
- }
382
- catch {
383
- // Not in a cache context — no-op
384
- }
310
+ * Tag a "use cache" function's cached result for on-demand revalidation.
311
+ *
312
+ * Tags set here can be invalidated via revalidateTag(). In Next.js, this only
313
+ * works inside "use cache" functions.
314
+ *
315
+ * When called inside a "use cache" function, tags are attached to the cached
316
+ * entry. They can later be invalidated via revalidateTag().
317
+ *
318
+ * When called outside a "use cache" context, this is a no-op.
319
+ */
320
+ function cacheTag(...tags) {
321
+ try {
322
+ const ctx = _getCacheContextFn?.();
323
+ if (ctx) ctx.tags.push(...tags);
324
+ } catch {}
385
325
  }
386
- // ---------------------------------------------------------------------------
387
- // unstable_cache — the older caching API
388
- // ---------------------------------------------------------------------------
389
326
  /**
390
- * AsyncLocalStorage to track whether we're inside an unstable_cache() callback.
391
- * Stored on globalThis via Symbol so headers.ts can detect the scope without
392
- * a direct import (avoiding circular dependencies).
393
- */
327
+ * AsyncLocalStorage to track whether we're inside an unstable_cache() callback.
328
+ * Stored on globalThis via Symbol so headers.ts can detect the scope without
329
+ * a direct import (avoiding circular dependencies).
330
+ */
394
331
  const _UNSTABLE_CACHE_ALS_KEY = Symbol.for("vinext.unstableCache.als");
395
- const _unstableCacheAls = (_g[_UNSTABLE_CACHE_ALS_KEY] ??=
396
- new AsyncLocalStorage());
397
- const UNSTABLE_CACHE_UNDEFINED_SENTINEL = "__vinext_unstable_cache_undefined__";
332
+ const _unstableCacheAls = _g[_UNSTABLE_CACHE_ALS_KEY] ??= new AsyncLocalStorage();
398
333
  function serializeUnstableCacheResult(value) {
399
- return value === undefined ? UNSTABLE_CACHE_UNDEFINED_SENTINEL : JSON.stringify(value);
334
+ const wrapper = value === void 0 ? { undef: true } : { v: value };
335
+ return JSON.stringify(wrapper);
400
336
  }
401
337
  function deserializeUnstableCacheResult(body) {
402
- if (body === UNSTABLE_CACHE_UNDEFINED_SENTINEL) {
403
- return undefined;
404
- }
405
- return JSON.parse(body);
338
+ const wrapper = JSON.parse(body);
339
+ return "undef" in wrapper ? void 0 : wrapper.v;
406
340
  }
407
341
  /**
408
- * Check if the current execution context is inside an unstable_cache() callback.
409
- * Used by headers(), cookies(), and connection() to throw errors when
410
- * dynamic request APIs are called inside a cache scope.
411
- */
412
- export function isInsideUnstableCacheScope() {
413
- return _unstableCacheAls.getStore() === true;
342
+ * Check if the current execution context is inside an unstable_cache() callback.
343
+ * Used by headers(), cookies(), and connection() to throw errors when
344
+ * dynamic request APIs are called inside a cache scope.
345
+ */
346
+ function isInsideUnstableCacheScope() {
347
+ return _unstableCacheAls.getStore() === true;
414
348
  }
415
349
  /**
416
- * Wrap an async function with caching.
417
- *
418
- * Returns a new function that caches results. The cache key is derived
419
- * from keyParts + serialized arguments.
420
- */
421
- export function unstable_cache(fn, keyParts, options) {
422
- const baseKey = keyParts ? keyParts.join(":") : fnv1a64(fn.toString());
423
- const tags = options?.tags ?? [];
424
- const revalidateSeconds = options?.revalidate;
425
- const cachedFn = async (...args) => {
426
- const argsKey = JSON.stringify(args);
427
- const cacheKey = `unstable_cache:${baseKey}:${argsKey}`;
428
- // Try to get from cache. Check cacheState so time-expired entries
429
- // trigger a re-fetch instead of being served indefinitely.
430
- const existing = await _getActiveHandler().get(cacheKey, {
431
- kind: "FETCH",
432
- tags,
433
- });
434
- if (existing?.value && existing.value.kind === "FETCH" && existing.cacheState !== "stale") {
435
- try {
436
- return deserializeUnstableCacheResult(existing.value.data.body);
437
- }
438
- catch {
439
- // Corrupted entry, fall through to re-fetch
440
- }
441
- }
442
- // Cache miss — call the function inside the unstable_cache ALS scope
443
- // so that headers()/cookies()/connection() can detect they're in a
444
- // cache scope and throw an appropriate error.
445
- const result = await _unstableCacheAls.run(true, () => fn(...args));
446
- // Store in cache using the FETCH kind
447
- const cacheValue = {
448
- kind: "FETCH",
449
- data: {
450
- headers: {},
451
- body: serializeUnstableCacheResult(result),
452
- url: cacheKey,
453
- },
454
- tags,
455
- // revalidate: false means "cache indefinitely" (no time-based expiry).
456
- // A positive number means time-based revalidation in seconds.
457
- // When unset (undefined), default to false (indefinite) matching
458
- // Next.js behavior for unstable_cache without explicit revalidate.
459
- revalidate: typeof revalidateSeconds === "number" ? revalidateSeconds : false,
460
- };
461
- await _getActiveHandler().set(cacheKey, cacheValue, {
462
- fetchCache: true,
463
- tags,
464
- revalidate: revalidateSeconds,
465
- });
466
- return result;
467
- };
468
- return cachedFn;
350
+ * Wrap an async function with caching.
351
+ *
352
+ * Returns a new function that caches results. The cache key is derived
353
+ * from keyParts + serialized arguments.
354
+ */
355
+ function unstable_cache(fn, keyParts, options) {
356
+ const baseKey = keyParts ? keyParts.join(":") : fnv1a64(fn.toString());
357
+ const tags = options?.tags ?? [];
358
+ const revalidateSeconds = options?.revalidate;
359
+ const cachedFn = async (...args) => {
360
+ const cacheKey = `unstable_cache:${baseKey}:${JSON.stringify(args)}`;
361
+ const existing = await _getActiveHandler().get(cacheKey, {
362
+ kind: "FETCH",
363
+ tags
364
+ });
365
+ if (existing?.value && existing.value.kind === "FETCH" && existing.cacheState !== "stale") try {
366
+ return deserializeUnstableCacheResult(existing.value.data.body);
367
+ } catch {}
368
+ const result = await _unstableCacheAls.run(true, () => fn(...args));
369
+ const cacheValue = {
370
+ kind: "FETCH",
371
+ data: {
372
+ headers: {},
373
+ body: serializeUnstableCacheResult(result),
374
+ url: cacheKey
375
+ },
376
+ tags,
377
+ revalidate: typeof revalidateSeconds === "number" ? revalidateSeconds : false
378
+ };
379
+ await _getActiveHandler().set(cacheKey, cacheValue, {
380
+ fetchCache: true,
381
+ tags,
382
+ revalidate: revalidateSeconds
383
+ });
384
+ return result;
385
+ };
386
+ return cachedFn;
469
387
  }
388
+ //#endregion
389
+ export { MemoryCacheHandler, NoOpCacheHandler, _consumeRequestScopedCacheLife, _initRequestScopedCacheState, _registerCacheContextAccessor, _runWithCacheState, _setRequestScopedCacheLife, cacheLife, cacheLifeProfiles, cacheTag, getCacheHandler, getRequestExecutionContext, isInsideUnstableCacheScope, unstable_noStore as noStore, unstable_noStore, refresh, revalidatePath, revalidateTag, runWithExecutionContext, setCacheHandler, unstable_cache, updateTag };
390
+
470
391
  //# sourceMappingURL=cache.js.map