vinext 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/build/prerender.d.ts +188 -0
- package/dist/build/prerender.js +675 -0
- package/dist/build/prerender.js.map +1 -0
- package/dist/build/report.d.ts +45 -46
- package/dist/build/report.js +247 -276
- package/dist/build/report.js.map +1 -1
- package/dist/build/run-prerender.d.ts +62 -0
- package/dist/build/run-prerender.js +183 -0
- package/dist/build/run-prerender.js.map +1 -0
- package/dist/build/server-manifest.d.ts +19 -0
- package/dist/build/server-manifest.js +29 -0
- package/dist/build/server-manifest.js.map +1 -0
- package/dist/build/static-export.d.ts +51 -66
- package/dist/build/static-export.js +51 -545
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.d.ts +26 -24
- package/dist/check.js +591 -571
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +1 -15
- package/dist/cli.js +430 -491
- package/dist/cli.js.map +1 -1
- package/dist/client/entry.d.ts +1 -2
- package/dist/client/entry.js +49 -62
- package/dist/client/entry.js.map +1 -1
- package/dist/client/validate-module-path.d.ts +4 -1
- package/dist/client/validate-module-path.js +23 -28
- package/dist/client/validate-module-path.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +15 -20
- package/dist/client/vinext-next-data.js +0 -1
- package/dist/cloudflare/index.d.ts +3 -8
- package/dist/cloudflare/index.js +3 -8
- package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
- package/dist/cloudflare/kv-cache-handler.js +354 -380
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +36 -34
- package/dist/cloudflare/tpr.js +460 -603
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +31 -40
- package/dist/config/config-matchers.js +727 -936
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/dotenv.d.ts +18 -11
- package/dist/config/dotenv.js +79 -84
- package/dist/config/dotenv.js.map +1 -1
- package/dist/config/next-config.d.ts +156 -146
- package/dist/config/next-config.js +374 -464
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +87 -96
- package/dist/deploy.js +490 -628
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +4 -1
- package/dist/entries/app-browser-entry.js +12 -8
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +33 -20
- package/dist/entries/app-rsc-entry.js +442 -211
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +9 -1
- package/dist/entries/app-ssr-entry.js +61 -28
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.d.ts +6 -2
- package/dist/entries/pages-client-entry.js +30 -33
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-entry-helpers.d.ts +5 -1
- package/dist/entries/pages-entry-helpers.js +17 -14
- package/dist/entries/pages-entry-helpers.js.map +1 -1
- package/dist/entries/pages-server-entry.d.ts +6 -2
- package/dist/entries/pages-server-entry.js +84 -113
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.d.ts +82 -62
- package/dist/index.js +2172 -3133
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +40 -37
- package/dist/init.js +201 -258
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +7 -3
- package/dist/plugins/async-hooks-stub.js +39 -42
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/client-reference-dedup.d.ts +7 -3
- package/dist/plugins/client-reference-dedup.js +63 -88
- package/dist/plugins/client-reference-dedup.js.map +1 -1
- package/dist/routing/app-router.d.ts +100 -96
- package/dist/routing/app-router.js +560 -670
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +18 -15
- package/dist/routing/file-matcher.js +65 -65
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.d.ts +23 -24
- package/dist/routing/pages-router.js +147 -172
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.d.ts +23 -20
- package/dist/routing/route-trie.js +131 -151
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.d.ts +5 -2
- package/dist/routing/route-validation.js +98 -130
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +10 -7
- package/dist/routing/utils.js +75 -111
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts +8 -13
- package/dist/server/api-handler.js +161 -193
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-router-entry.d.ts +6 -16
- package/dist/server/app-router-entry.js +26 -54
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +11 -64
- package/dist/server/dev-module-runner.js +89 -101
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/dev-origin-check.d.ts +12 -10
- package/dist/server/dev-origin-check.js +98 -108
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.d.ts +17 -14
- package/dist/server/dev-server.js +542 -869
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/html.d.ts +4 -1
- package/dist/server/html.js +25 -26
- package/dist/server/html.js.map +1 -1
- package/dist/server/image-optimization.d.ts +31 -28
- package/dist/server/image-optimization.js +181 -210
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation.d.ts +25 -22
- package/dist/server/instrumentation.js +110 -122
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts +16 -26
- package/dist/server/isr-cache.js +106 -128
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +85 -88
- package/dist/server/metadata-routes.js +270 -317
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +7 -4
- package/dist/server/middleware-codegen.js +61 -61
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +8 -6
- package/dist/server/middleware-request-headers.js +47 -65
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +31 -47
- package/dist/server/middleware.js +273 -404
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/normalize-path.d.ts +4 -1
- package/dist/server/normalize-path.js +33 -47
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +38 -30
- package/dist/server/pages-i18n.js +112 -139
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/prod-server.d.ts +19 -31
- package/dist/server/prod-server.js +714 -945
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-log.d.ts +18 -12
- package/dist/server/request-log.js +45 -52
- package/dist/server/request-log.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +9 -17
- package/dist/server/request-pipeline.js +133 -184
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/worker-utils.d.ts +4 -1
- package/dist/server/worker-utils.js +31 -37
- package/dist/server/worker-utils.js.map +1 -1
- package/dist/shims/amp.d.ts +5 -2
- package/dist/shims/amp.js +19 -15
- package/dist/shims/amp.js.map +1 -1
- package/dist/shims/app.d.ts +8 -10
- package/dist/shims/app.js +0 -1
- package/dist/shims/cache-runtime.d.ts +20 -45
- package/dist/shims/cache-runtime.js +271 -422
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +130 -121
- package/dist/shims/cache.js +339 -427
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/client-only.d.ts +1 -18
- package/dist/shims/client-only.js +0 -17
- package/dist/shims/compat-router.d.ts +4 -1
- package/dist/shims/compat-router.js +23 -19
- package/dist/shims/compat-router.js.map +1 -1
- package/dist/shims/config.d.ts +7 -5
- package/dist/shims/config.js +16 -23
- package/dist/shims/config.js.map +1 -1
- package/dist/shims/constants.d.ts +119 -118
- package/dist/shims/constants.js +159 -164
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/document.d.ts +20 -16
- package/dist/shims/document.js +41 -22
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/dynamic.d.ts +13 -22
- package/dist/shims/dynamic.js +122 -136
- package/dist/shims/dynamic.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +22 -15
- package/dist/shims/error-boundary.js +81 -79
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/error.d.ts +11 -12
- package/dist/shims/error.js +35 -39
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +16 -14
- package/dist/shims/fetch-cache.js +437 -645
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +28 -26
- package/dist/shims/font-google-base.js +238 -325
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/font-google.d.ts +3 -3
- package/dist/shims/font-google.generated.d.ts +1928 -1924
- package/dist/shims/font-google.generated.js +1928 -2133
- package/dist/shims/font-google.generated.js.map +1 -1
- package/dist/shims/font-google.js +3 -3
- package/dist/shims/font-local.d.ts +28 -26
- package/dist/shims/font-local.js +204 -260
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.d.ts +13 -27
- package/dist/shims/form.js +128 -180
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head-state.d.ts +8 -13
- package/dist/shims/head-state.js +25 -42
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/head.d.ts +16 -20
- package/dist/shims/head.js +172 -250
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +84 -78
- package/dist/shims/headers.js +447 -575
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-context.d.ts +16 -20
- package/dist/shims/i18n-context.js +35 -48
- package/dist/shims/i18n-context.js.map +1 -1
- package/dist/shims/i18n-state.d.ts +8 -14
- package/dist/shims/i18n-state.js +34 -42
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/image-config.d.ts +11 -8
- package/dist/shims/image-config.js +50 -83
- package/dist/shims/image-config.js.map +1 -1
- package/dist/shims/image.d.ts +37 -46
- package/dist/shims/image.js +283 -308
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/api-utils.d.ts +7 -4
- package/dist/shims/internal/api-utils.js +0 -6
- package/dist/shims/internal/app-router-context.d.ts +22 -17
- package/dist/shims/internal/app-router-context.js +17 -13
- package/dist/shims/internal/app-router-context.js.map +1 -1
- package/dist/shims/internal/cookies.d.ts +2 -9
- package/dist/shims/internal/cookies.js +2 -9
- package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
- package/dist/shims/internal/parse-cookie-header.js +29 -29
- package/dist/shims/internal/parse-cookie-header.js.map +1 -1
- package/dist/shims/internal/router-context.d.ts +6 -1
- package/dist/shims/internal/router-context.js +11 -7
- package/dist/shims/internal/router-context.js.map +1 -1
- package/dist/shims/internal/utils.d.ts +40 -37
- package/dist/shims/internal/utils.js +24 -30
- package/dist/shims/internal/utils.js.map +1 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
- package/dist/shims/internal/work-unit-async-storage.js +14 -11
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
- package/dist/shims/layout-segment-context.d.ts +11 -14
- package/dist/shims/layout-segment-context.js +24 -23
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/legacy-image.d.ts +39 -46
- package/dist/shims/legacy-image.js +47 -42
- package/dist/shims/legacy-image.js.map +1 -1
- package/dist/shims/link.d.ts +32 -36
- package/dist/shims/link.js +255 -391
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +210 -202
- package/dist/shims/metadata.js +545 -546
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.d.ts +10 -18
- package/dist/shims/navigation-state.js +66 -74
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +59 -63
- package/dist/shims/navigation.js +505 -704
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +2 -20
- package/dist/shims/og.js +2 -19
- package/dist/shims/readonly-url-search-params.d.ts +8 -5
- package/dist/shims/readonly-url-search-params.js +26 -22
- package/dist/shims/readonly-url-search-params.js.map +1 -1
- package/dist/shims/request-context.d.ts +8 -5
- package/dist/shims/request-context.js +50 -60
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +11 -11
- package/dist/shims/request-state-types.js +0 -1
- package/dist/shims/router-state.d.ts +13 -10
- package/dist/shims/router-state.js +34 -43
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +81 -85
- package/dist/shims/router.js +506 -628
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.d.ts +39 -48
- package/dist/shims/script.js +107 -160
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server-only.d.ts +1 -19
- package/dist/shims/server-only.js +0 -18
- package/dist/shims/server.d.ts +175 -164
- package/dist/shims/server.js +462 -478
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +20 -20
- package/dist/shims/unified-request-context.js +81 -99
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/url-safety.d.ts +4 -1
- package/dist/shims/url-safety.js +15 -11
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +8 -5
- package/dist/shims/url-utils.js +62 -93
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/shims/web-vitals.d.ts +10 -8
- package/dist/shims/web-vitals.js +9 -15
- package/dist/shims/web-vitals.js.map +1 -1
- package/dist/utils/base-path.d.ts +5 -2
- package/dist/utils/base-path.js +21 -19
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +17 -9
- package/dist/utils/domain-locale.js +36 -56
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/hash.d.ts +4 -1
- package/dist/utils/hash.js +19 -17
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/manifest-paths.d.ts +6 -3
- package/dist/utils/manifest-paths.js +15 -16
- package/dist/utils/manifest-paths.js.map +1 -1
- package/dist/utils/project.d.ts +13 -11
- package/dist/utils/project.js +169 -216
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/query.d.ts +8 -6
- package/dist/utils/query.js +57 -67
- package/dist/utils/query.js.map +1 -1
- package/package.json +10 -9
- package/dist/build/report.d.ts.map +0 -1
- package/dist/build/static-export.d.ts.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client/entry.d.ts.map +0 -1
- package/dist/client/validate-module-path.d.ts.map +0 -1
- package/dist/client/vinext-next-data.d.ts.map +0 -1
- package/dist/client/vinext-next-data.js.map +0 -1
- package/dist/cloudflare/index.d.ts.map +0 -1
- package/dist/cloudflare/index.js.map +0 -1
- package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
- package/dist/cloudflare/tpr.d.ts.map +0 -1
- package/dist/config/config-matchers.d.ts.map +0 -1
- package/dist/config/dotenv.d.ts.map +0 -1
- package/dist/config/next-config.d.ts.map +0 -1
- package/dist/deploy.d.ts.map +0 -1
- package/dist/entries/app-browser-entry.d.ts.map +0 -1
- package/dist/entries/app-rsc-entry.d.ts.map +0 -1
- package/dist/entries/app-ssr-entry.d.ts.map +0 -1
- package/dist/entries/pages-client-entry.d.ts.map +0 -1
- package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
- package/dist/entries/pages-server-entry.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
- package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
- package/dist/routing/app-router.d.ts.map +0 -1
- package/dist/routing/file-matcher.d.ts.map +0 -1
- package/dist/routing/pages-router.d.ts.map +0 -1
- package/dist/routing/route-trie.d.ts.map +0 -1
- package/dist/routing/route-validation.d.ts.map +0 -1
- package/dist/routing/utils.d.ts.map +0 -1
- package/dist/server/api-handler.d.ts.map +0 -1
- package/dist/server/app-router-entry.d.ts.map +0 -1
- package/dist/server/dev-module-runner.d.ts.map +0 -1
- package/dist/server/dev-origin-check.d.ts.map +0 -1
- package/dist/server/dev-server.d.ts.map +0 -1
- package/dist/server/html.d.ts.map +0 -1
- package/dist/server/image-optimization.d.ts.map +0 -1
- package/dist/server/instrumentation.d.ts.map +0 -1
- package/dist/server/isr-cache.d.ts.map +0 -1
- package/dist/server/metadata-routes.d.ts.map +0 -1
- package/dist/server/middleware-codegen.d.ts.map +0 -1
- package/dist/server/middleware-request-headers.d.ts.map +0 -1
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/normalize-path.d.ts.map +0 -1
- package/dist/server/pages-i18n.d.ts.map +0 -1
- package/dist/server/prod-server.d.ts.map +0 -1
- package/dist/server/request-log.d.ts.map +0 -1
- package/dist/server/request-pipeline.d.ts.map +0 -1
- package/dist/server/worker-utils.d.ts.map +0 -1
- package/dist/shims/amp.d.ts.map +0 -1
- package/dist/shims/app.d.ts.map +0 -1
- package/dist/shims/app.js.map +0 -1
- package/dist/shims/cache-runtime.d.ts.map +0 -1
- package/dist/shims/cache.d.ts.map +0 -1
- package/dist/shims/client-only.d.ts.map +0 -1
- package/dist/shims/client-only.js.map +0 -1
- package/dist/shims/compat-router.d.ts.map +0 -1
- package/dist/shims/config.d.ts.map +0 -1
- package/dist/shims/constants.d.ts.map +0 -1
- package/dist/shims/document.d.ts.map +0 -1
- package/dist/shims/dynamic.d.ts.map +0 -1
- package/dist/shims/error-boundary.d.ts.map +0 -1
- package/dist/shims/error.d.ts.map +0 -1
- package/dist/shims/fetch-cache.d.ts.map +0 -1
- package/dist/shims/font-google-base.d.ts.map +0 -1
- package/dist/shims/font-google.d.ts.map +0 -1
- package/dist/shims/font-google.generated.d.ts.map +0 -1
- package/dist/shims/font-google.js.map +0 -1
- package/dist/shims/font-local.d.ts.map +0 -1
- package/dist/shims/form.d.ts.map +0 -1
- package/dist/shims/head-state.d.ts.map +0 -1
- package/dist/shims/head.d.ts.map +0 -1
- package/dist/shims/headers.d.ts.map +0 -1
- package/dist/shims/i18n-context.d.ts.map +0 -1
- package/dist/shims/i18n-state.d.ts.map +0 -1
- package/dist/shims/image-config.d.ts.map +0 -1
- package/dist/shims/image.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.js.map +0 -1
- package/dist/shims/internal/app-router-context.d.ts.map +0 -1
- package/dist/shims/internal/cookies.d.ts.map +0 -1
- package/dist/shims/internal/cookies.js.map +0 -1
- package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
- package/dist/shims/internal/router-context.d.ts.map +0 -1
- package/dist/shims/internal/utils.d.ts.map +0 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
- package/dist/shims/layout-segment-context.d.ts.map +0 -1
- package/dist/shims/legacy-image.d.ts.map +0 -1
- package/dist/shims/link.d.ts.map +0 -1
- package/dist/shims/metadata.d.ts.map +0 -1
- package/dist/shims/navigation-state.d.ts.map +0 -1
- package/dist/shims/navigation.d.ts.map +0 -1
- package/dist/shims/og.d.ts.map +0 -1
- package/dist/shims/og.js.map +0 -1
- package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
- package/dist/shims/request-context.d.ts.map +0 -1
- package/dist/shims/request-state-types.d.ts.map +0 -1
- package/dist/shims/request-state-types.js.map +0 -1
- package/dist/shims/router-state.d.ts.map +0 -1
- package/dist/shims/router.d.ts.map +0 -1
- package/dist/shims/script.d.ts.map +0 -1
- package/dist/shims/server-only.d.ts.map +0 -1
- package/dist/shims/server-only.js.map +0 -1
- package/dist/shims/server.d.ts.map +0 -1
- package/dist/shims/unified-request-context.d.ts.map +0 -1
- package/dist/shims/url-safety.d.ts.map +0 -1
- package/dist/shims/url-utils.d.ts.map +0 -1
- package/dist/shims/web-vitals.d.ts.map +0 -1
- package/dist/utils/base-path.d.ts.map +0 -1
- package/dist/utils/domain-locale.d.ts.map +0 -1
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/manifest-paths.d.ts.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/query.d.ts.map +0 -1
package/dist/shims/cache.js
CHANGED
|
@@ -1,479 +1,391 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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";
|
|
22
|
-
import {
|
|
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
|
+
*/
|
|
23
25
|
/** @internal Set by cache-runtime.ts on import to avoid circular dependency */
|
|
24
26
|
let _getCacheContextFn = null;
|
|
25
27
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
export class MemoryCacheHandler {
|
|
33
|
-
store = new Map();
|
|
34
|
-
tagRevalidatedAt = new Map();
|
|
35
|
-
async get(key, _ctx) {
|
|
36
|
-
const entry = this.store.get(key);
|
|
37
|
-
if (!entry)
|
|
38
|
-
return null;
|
|
39
|
-
// Check tag-based invalidation first — if tag was invalidated, treat as hard miss
|
|
40
|
-
for (const tag of entry.tags) {
|
|
41
|
-
const revalidatedAt = this.tagRevalidatedAt.get(tag);
|
|
42
|
-
if (revalidatedAt && revalidatedAt >= entry.lastModified) {
|
|
43
|
-
this.store.delete(key);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Check time-based expiry — return stale entry with cacheState="stale"
|
|
48
|
-
// instead of deleting, so ISR can serve stale-while-revalidate
|
|
49
|
-
if (entry.revalidateAt !== null && Date.now() > entry.revalidateAt) {
|
|
50
|
-
return {
|
|
51
|
-
lastModified: entry.lastModified,
|
|
52
|
-
value: entry.value,
|
|
53
|
-
cacheState: "stale",
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
lastModified: entry.lastModified,
|
|
58
|
-
value: entry.value,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async set(key, data, ctx) {
|
|
62
|
-
const tags = [];
|
|
63
|
-
if (data && "tags" in data && Array.isArray(data.tags)) {
|
|
64
|
-
tags.push(...data.tags);
|
|
65
|
-
}
|
|
66
|
-
if (ctx && "tags" in ctx && Array.isArray(ctx.tags)) {
|
|
67
|
-
tags.push(...ctx.tags);
|
|
68
|
-
}
|
|
69
|
-
// Resolve effective revalidate — data overrides ctx.
|
|
70
|
-
// revalidate: 0 means "don't cache", so skip storage entirely.
|
|
71
|
-
let effectiveRevalidate;
|
|
72
|
-
if (ctx) {
|
|
73
|
-
const revalidate = ctx.cacheControl?.revalidate ?? ctx.revalidate;
|
|
74
|
-
if (typeof revalidate === "number") {
|
|
75
|
-
effectiveRevalidate = revalidate;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (data && "revalidate" in data && typeof data.revalidate === "number") {
|
|
79
|
-
effectiveRevalidate = data.revalidate;
|
|
80
|
-
}
|
|
81
|
-
if (effectiveRevalidate === 0)
|
|
82
|
-
return;
|
|
83
|
-
const revalidateAt = typeof effectiveRevalidate === "number" && effectiveRevalidate > 0
|
|
84
|
-
? Date.now() + effectiveRevalidate * 1000
|
|
85
|
-
: null;
|
|
86
|
-
this.store.set(key, {
|
|
87
|
-
value: data,
|
|
88
|
-
tags,
|
|
89
|
-
lastModified: Date.now(),
|
|
90
|
-
revalidateAt,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
async revalidateTag(tags, _durations) {
|
|
94
|
-
const tagList = Array.isArray(tags) ? tags : [tags];
|
|
95
|
-
const now = Date.now();
|
|
96
|
-
for (const tag of tagList) {
|
|
97
|
-
this.tagRevalidatedAt.set(tag, now);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
resetRequestCache() {
|
|
101
|
-
// No-op for the simple memory cache. In a production adapter,
|
|
102
|
-
// this would clear per-request caches (e.g., dedup fetch calls).
|
|
103
|
-
}
|
|
28
|
+
* Register the cache context accessor. Called by cache-runtime.ts on load.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function _registerCacheContextAccessor(fn) {
|
|
32
|
+
_getCacheContextFn = fn;
|
|
104
33
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
};
|
|
117
92
|
const _HANDLER_KEY = Symbol.for("vinext.cacheHandler");
|
|
118
93
|
const _gHandler = globalThis;
|
|
119
94
|
function _getActiveHandler() {
|
|
120
|
-
|
|
95
|
+
return _gHandler[_HANDLER_KEY] ?? (_gHandler[_HANDLER_KEY] = new MemoryCacheHandler());
|
|
121
96
|
}
|
|
122
97
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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;
|
|
131
106
|
}
|
|
132
107
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
108
|
+
* Get the active CacheHandler (for internal use or testing).
|
|
109
|
+
*/
|
|
110
|
+
function getCacheHandler() {
|
|
111
|
+
return _getActiveHandler();
|
|
137
112
|
}
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
// Public API — what app code imports from 'next/cache'
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
113
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const resolved = cacheLifeProfiles[profile];
|
|
162
|
-
if (resolved) {
|
|
163
|
-
durations = { expire: resolved.expire };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else if (profile && typeof profile === "object") {
|
|
167
|
-
durations = profile;
|
|
168
|
-
}
|
|
169
|
-
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);
|
|
170
133
|
}
|
|
171
134
|
/**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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);
|
|
181
153
|
}
|
|
182
154
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
*
|
|
192
|
-
* @param tag - Cache tag to expire and refresh
|
|
193
|
-
*/
|
|
194
|
-
export async function updateTag(tag) {
|
|
195
|
-
// Expire the tag immediately (same as revalidateTag without SWR)
|
|
196
|
-
await _getActiveHandler().revalidateTag(tag);
|
|
197
|
-
}
|
|
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() {}
|
|
198
163
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*/
|
|
208
|
-
export function refresh() {
|
|
209
|
-
// In our implementation, this is a signal that the client should
|
|
210
|
-
// refresh dynamic data. The actual refresh happens on the client side
|
|
211
|
-
// via the RSC protocol — the server action response triggers a
|
|
212
|
-
// client-side navigation refresh.
|
|
213
|
-
// For now, this is a no-op on the server; the Server Action response
|
|
214
|
-
// 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);
|
|
215
172
|
}
|
|
216
173
|
/**
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
_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();
|
|
227
183
|
}
|
|
228
|
-
// Also export as `noStore` (Next.js 15+ naming)
|
|
229
|
-
export { unstable_noStore as noStore };
|
|
230
184
|
const _ALS_KEY = Symbol.for("vinext.cache.als");
|
|
231
185
|
const _FALLBACK_KEY = Symbol.for("vinext.cache.fallback");
|
|
232
186
|
const _g = globalThis;
|
|
233
|
-
const _cacheAls =
|
|
234
|
-
|
|
235
|
-
const _cacheFallbackState = (_g[_FALLBACK_KEY] ??= {
|
|
236
|
-
requestScopedCacheLife: null,
|
|
237
|
-
});
|
|
187
|
+
const _cacheAls = _g[_ALS_KEY] ??= new AsyncLocalStorage();
|
|
188
|
+
const _cacheFallbackState = _g[_FALLBACK_KEY] ??= { requestScopedCacheLife: null };
|
|
238
189
|
function _getCacheState() {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
return _cacheAls.getStore() ?? _cacheFallbackState;
|
|
190
|
+
if (isInsideUnifiedScope()) return getRequestContext();
|
|
191
|
+
return _cacheAls.getStore() ?? _cacheFallbackState;
|
|
243
192
|
}
|
|
244
193
|
/**
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
const state = {
|
|
257
|
-
requestScopedCacheLife: null,
|
|
258
|
-
};
|
|
259
|
-
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);
|
|
260
204
|
}
|
|
261
205
|
/**
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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;
|
|
268
212
|
}
|
|
269
213
|
/**
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
state.requestScopedCacheLife.stale =
|
|
283
|
-
state.requestScopedCacheLife.stale !== undefined
|
|
284
|
-
? Math.min(state.requestScopedCacheLife.stale, config.stale)
|
|
285
|
-
: config.stale;
|
|
286
|
-
}
|
|
287
|
-
if (config.revalidate !== undefined) {
|
|
288
|
-
state.requestScopedCacheLife.revalidate =
|
|
289
|
-
state.requestScopedCacheLife.revalidate !== undefined
|
|
290
|
-
? Math.min(state.requestScopedCacheLife.revalidate, config.revalidate)
|
|
291
|
-
: config.revalidate;
|
|
292
|
-
}
|
|
293
|
-
if (config.expire !== undefined) {
|
|
294
|
-
state.requestScopedCacheLife.expire =
|
|
295
|
-
state.requestScopedCacheLife.expire !== undefined
|
|
296
|
-
? Math.min(state.requestScopedCacheLife.expire, config.expire)
|
|
297
|
-
: config.expire;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
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
|
+
}
|
|
300
226
|
}
|
|
301
227
|
/**
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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;
|
|
310
236
|
}
|
|
311
237
|
/**
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
+
}
|
|
322
275
|
};
|
|
323
276
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
else {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
// If we're inside a "use cache" context, push the config
|
|
359
|
-
try {
|
|
360
|
-
const ctx = _getCacheContextFn?.();
|
|
361
|
-
if (ctx) {
|
|
362
|
-
ctx.lifeConfigs.push(resolvedConfig);
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
catch {
|
|
367
|
-
// Fall through to request-scoped
|
|
368
|
-
}
|
|
369
|
-
// Outside a "use cache" context (e.g., page component with file-level "use cache"):
|
|
370
|
-
// store as request-scoped so the server can read it after rendering.
|
|
371
|
-
_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);
|
|
372
308
|
}
|
|
373
309
|
/**
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
catch {
|
|
392
|
-
// Not in a cache context — no-op
|
|
393
|
-
}
|
|
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 {}
|
|
394
325
|
}
|
|
395
|
-
// ---------------------------------------------------------------------------
|
|
396
|
-
// unstable_cache — the older caching API
|
|
397
|
-
// ---------------------------------------------------------------------------
|
|
398
326
|
/**
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
+
*/
|
|
403
331
|
const _UNSTABLE_CACHE_ALS_KEY = Symbol.for("vinext.unstableCache.als");
|
|
404
|
-
const _unstableCacheAls =
|
|
405
|
-
new AsyncLocalStorage());
|
|
406
|
-
const UNSTABLE_CACHE_UNDEFINED_SENTINEL = "__vinext_unstable_cache_undefined__";
|
|
332
|
+
const _unstableCacheAls = _g[_UNSTABLE_CACHE_ALS_KEY] ??= new AsyncLocalStorage();
|
|
407
333
|
function serializeUnstableCacheResult(value) {
|
|
408
|
-
|
|
334
|
+
const wrapper = value === void 0 ? { undef: true } : { v: value };
|
|
335
|
+
return JSON.stringify(wrapper);
|
|
409
336
|
}
|
|
410
337
|
function deserializeUnstableCacheResult(body) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
return JSON.parse(body);
|
|
338
|
+
const wrapper = JSON.parse(body);
|
|
339
|
+
return "undef" in wrapper ? void 0 : wrapper.v;
|
|
415
340
|
}
|
|
416
341
|
/**
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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;
|
|
423
348
|
}
|
|
424
349
|
/**
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
},
|
|
463
|
-
tags,
|
|
464
|
-
// revalidate: false means "cache indefinitely" (no time-based expiry).
|
|
465
|
-
// A positive number means time-based revalidation in seconds.
|
|
466
|
-
// When unset (undefined), default to false (indefinite) matching
|
|
467
|
-
// Next.js behavior for unstable_cache without explicit revalidate.
|
|
468
|
-
revalidate: typeof revalidateSeconds === "number" ? revalidateSeconds : false,
|
|
469
|
-
};
|
|
470
|
-
await _getActiveHandler().set(cacheKey, cacheValue, {
|
|
471
|
-
fetchCache: true,
|
|
472
|
-
tags,
|
|
473
|
-
revalidate: revalidateSeconds,
|
|
474
|
-
});
|
|
475
|
-
return result;
|
|
476
|
-
};
|
|
477
|
-
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;
|
|
478
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
|
+
|
|
479
391
|
//# sourceMappingURL=cache.js.map
|