vinext 0.0.0 → 0.0.2

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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/build/static-export.d.ts +78 -0
  4. package/dist/build/static-export.d.ts.map +1 -0
  5. package/dist/build/static-export.js +553 -0
  6. package/dist/build/static-export.js.map +1 -0
  7. package/dist/check.d.ts +52 -0
  8. package/dist/check.d.ts.map +1 -0
  9. package/dist/check.js +483 -0
  10. package/dist/check.js.map +1 -0
  11. package/dist/cli.d.ts +15 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +565 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/client/entry.d.ts +2 -0
  16. package/dist/client/entry.d.ts.map +1 -0
  17. package/dist/client/entry.js +85 -0
  18. package/dist/client/entry.js.map +1 -0
  19. package/dist/cloudflare/index.d.ts +8 -0
  20. package/dist/cloudflare/index.d.ts.map +1 -0
  21. package/dist/cloudflare/index.js +8 -0
  22. package/dist/cloudflare/index.js.map +1 -0
  23. package/dist/cloudflare/kv-cache-handler.d.ts +68 -0
  24. package/dist/cloudflare/kv-cache-handler.d.ts.map +1 -0
  25. package/dist/cloudflare/kv-cache-handler.js +304 -0
  26. package/dist/cloudflare/kv-cache-handler.js.map +1 -0
  27. package/dist/cloudflare/tpr.d.ts +78 -0
  28. package/dist/cloudflare/tpr.d.ts.map +1 -0
  29. package/dist/cloudflare/tpr.js +672 -0
  30. package/dist/cloudflare/tpr.js.map +1 -0
  31. package/dist/config/config-matchers.d.ts +106 -0
  32. package/dist/config/config-matchers.d.ts.map +1 -0
  33. package/dist/config/config-matchers.js +499 -0
  34. package/dist/config/config-matchers.js.map +1 -0
  35. package/dist/config/next-config.d.ts +153 -0
  36. package/dist/config/next-config.d.ts.map +1 -0
  37. package/dist/config/next-config.js +274 -0
  38. package/dist/config/next-config.js.map +1 -0
  39. package/dist/deploy.d.ts +87 -0
  40. package/dist/deploy.d.ts.map +1 -0
  41. package/dist/deploy.js +644 -0
  42. package/dist/deploy.js.map +1 -0
  43. package/dist/index.d.ts +156 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +3296 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/init.d.ts +55 -0
  48. package/dist/init.d.ts.map +1 -0
  49. package/dist/init.js +201 -0
  50. package/dist/init.js.map +1 -0
  51. package/dist/routing/app-router.d.ts +96 -0
  52. package/dist/routing/app-router.d.ts.map +1 -0
  53. package/dist/routing/app-router.js +815 -0
  54. package/dist/routing/app-router.js.map +1 -0
  55. package/dist/routing/pages-router.d.ts +52 -0
  56. package/dist/routing/pages-router.d.ts.map +1 -0
  57. package/dist/routing/pages-router.js +239 -0
  58. package/dist/routing/pages-router.js.map +1 -0
  59. package/dist/server/api-handler.d.ts +18 -0
  60. package/dist/server/api-handler.d.ts.map +1 -0
  61. package/dist/server/api-handler.js +169 -0
  62. package/dist/server/api-handler.js.map +1 -0
  63. package/dist/server/app-dev-server.d.ts +42 -0
  64. package/dist/server/app-dev-server.d.ts.map +1 -0
  65. package/dist/server/app-dev-server.js +2718 -0
  66. package/dist/server/app-dev-server.js.map +1 -0
  67. package/dist/server/app-router-entry.d.ts +18 -0
  68. package/dist/server/app-router-entry.d.ts.map +1 -0
  69. package/dist/server/app-router-entry.js +34 -0
  70. package/dist/server/app-router-entry.js.map +1 -0
  71. package/dist/server/dev-server.d.ts +40 -0
  72. package/dist/server/dev-server.d.ts.map +1 -0
  73. package/dist/server/dev-server.js +758 -0
  74. package/dist/server/dev-server.js.map +1 -0
  75. package/dist/server/html.d.ts +22 -0
  76. package/dist/server/html.d.ts.map +1 -0
  77. package/dist/server/html.js +29 -0
  78. package/dist/server/html.js.map +1 -0
  79. package/dist/server/image-optimization.d.ts +56 -0
  80. package/dist/server/image-optimization.d.ts.map +1 -0
  81. package/dist/server/image-optimization.js +103 -0
  82. package/dist/server/image-optimization.js.map +1 -0
  83. package/dist/server/instrumentation.d.ts +68 -0
  84. package/dist/server/instrumentation.d.ts.map +1 -0
  85. package/dist/server/instrumentation.js +90 -0
  86. package/dist/server/instrumentation.js.map +1 -0
  87. package/dist/server/isr-cache.d.ts +61 -0
  88. package/dist/server/isr-cache.d.ts.map +1 -0
  89. package/dist/server/isr-cache.js +134 -0
  90. package/dist/server/isr-cache.js.map +1 -0
  91. package/dist/server/metadata-routes.d.ts +103 -0
  92. package/dist/server/metadata-routes.d.ts.map +1 -0
  93. package/dist/server/metadata-routes.js +270 -0
  94. package/dist/server/metadata-routes.js.map +1 -0
  95. package/dist/server/middleware.d.ts +77 -0
  96. package/dist/server/middleware.d.ts.map +1 -0
  97. package/dist/server/middleware.js +228 -0
  98. package/dist/server/middleware.js.map +1 -0
  99. package/dist/server/prod-server.d.ts +78 -0
  100. package/dist/server/prod-server.d.ts.map +1 -0
  101. package/dist/server/prod-server.js +712 -0
  102. package/dist/server/prod-server.js.map +1 -0
  103. package/dist/shims/amp.d.ts +17 -0
  104. package/dist/shims/amp.d.ts.map +1 -0
  105. package/dist/shims/amp.js +21 -0
  106. package/dist/shims/amp.js.map +1 -0
  107. package/dist/shims/app.d.ts +12 -0
  108. package/dist/shims/app.d.ts.map +1 -0
  109. package/dist/shims/app.js +2 -0
  110. package/dist/shims/app.js.map +1 -0
  111. package/dist/shims/cache-runtime.d.ts +68 -0
  112. package/dist/shims/cache-runtime.d.ts.map +1 -0
  113. package/dist/shims/cache-runtime.js +437 -0
  114. package/dist/shims/cache-runtime.js.map +1 -0
  115. package/dist/shims/cache.d.ts +243 -0
  116. package/dist/shims/cache.d.ts.map +1 -0
  117. package/dist/shims/cache.js +415 -0
  118. package/dist/shims/cache.js.map +1 -0
  119. package/dist/shims/client-only.d.ts +18 -0
  120. package/dist/shims/client-only.d.ts.map +1 -0
  121. package/dist/shims/client-only.js +18 -0
  122. package/dist/shims/client-only.js.map +1 -0
  123. package/dist/shims/config.d.ts +27 -0
  124. package/dist/shims/config.d.ts.map +1 -0
  125. package/dist/shims/config.js +30 -0
  126. package/dist/shims/config.js.map +1 -0
  127. package/dist/shims/constants.d.ts +13 -0
  128. package/dist/shims/constants.d.ts.map +1 -0
  129. package/dist/shims/constants.js +13 -0
  130. package/dist/shims/constants.js.map +1 -0
  131. package/dist/shims/document.d.ts +33 -0
  132. package/dist/shims/document.d.ts.map +1 -0
  133. package/dist/shims/document.js +32 -0
  134. package/dist/shims/document.js.map +1 -0
  135. package/dist/shims/dynamic.d.ts +33 -0
  136. package/dist/shims/dynamic.d.ts.map +1 -0
  137. package/dist/shims/dynamic.js +149 -0
  138. package/dist/shims/dynamic.js.map +1 -0
  139. package/dist/shims/error-boundary.d.ts +33 -0
  140. package/dist/shims/error-boundary.d.ts.map +1 -0
  141. package/dist/shims/error-boundary.js +88 -0
  142. package/dist/shims/error-boundary.js.map +1 -0
  143. package/dist/shims/error.d.ts +16 -0
  144. package/dist/shims/error.d.ts.map +1 -0
  145. package/dist/shims/error.js +45 -0
  146. package/dist/shims/error.js.map +1 -0
  147. package/dist/shims/fetch-cache.d.ts +61 -0
  148. package/dist/shims/fetch-cache.d.ts.map +1 -0
  149. package/dist/shims/fetch-cache.js +307 -0
  150. package/dist/shims/fetch-cache.js.map +1 -0
  151. package/dist/shims/font-google.d.ts +122 -0
  152. package/dist/shims/font-google.d.ts.map +1 -0
  153. package/dist/shims/font-google.js +387 -0
  154. package/dist/shims/font-google.js.map +1 -0
  155. package/dist/shims/font-local.d.ts +61 -0
  156. package/dist/shims/font-local.d.ts.map +1 -0
  157. package/dist/shims/font-local.js +303 -0
  158. package/dist/shims/font-local.js.map +1 -0
  159. package/dist/shims/form.d.ts +30 -0
  160. package/dist/shims/form.d.ts.map +1 -0
  161. package/dist/shims/form.js +78 -0
  162. package/dist/shims/form.js.map +1 -0
  163. package/dist/shims/head-state.d.ts +11 -0
  164. package/dist/shims/head-state.d.ts.map +1 -0
  165. package/dist/shims/head-state.js +47 -0
  166. package/dist/shims/head-state.js.map +1 -0
  167. package/dist/shims/head.d.ts +28 -0
  168. package/dist/shims/head.d.ts.map +1 -0
  169. package/dist/shims/head.js +148 -0
  170. package/dist/shims/head.js.map +1 -0
  171. package/dist/shims/headers.d.ts +150 -0
  172. package/dist/shims/headers.d.ts.map +1 -0
  173. package/dist/shims/headers.js +412 -0
  174. package/dist/shims/headers.js.map +1 -0
  175. package/dist/shims/image-config.d.ts +30 -0
  176. package/dist/shims/image-config.d.ts.map +1 -0
  177. package/dist/shims/image-config.js +91 -0
  178. package/dist/shims/image-config.js.map +1 -0
  179. package/dist/shims/image.d.ts +63 -0
  180. package/dist/shims/image.d.ts.map +1 -0
  181. package/dist/shims/image.js +284 -0
  182. package/dist/shims/image.js.map +1 -0
  183. package/dist/shims/internal/api-utils.d.ts +12 -0
  184. package/dist/shims/internal/api-utils.d.ts.map +1 -0
  185. package/dist/shims/internal/api-utils.js +7 -0
  186. package/dist/shims/internal/api-utils.js.map +1 -0
  187. package/dist/shims/internal/app-router-context.d.ts +21 -0
  188. package/dist/shims/internal/app-router-context.d.ts.map +1 -0
  189. package/dist/shims/internal/app-router-context.js +15 -0
  190. package/dist/shims/internal/app-router-context.js.map +1 -0
  191. package/dist/shims/internal/cookies.d.ts +9 -0
  192. package/dist/shims/internal/cookies.d.ts.map +1 -0
  193. package/dist/shims/internal/cookies.js +9 -0
  194. package/dist/shims/internal/cookies.js.map +1 -0
  195. package/dist/shims/internal/router-context.d.ts +2 -0
  196. package/dist/shims/internal/router-context.d.ts.map +1 -0
  197. package/dist/shims/internal/router-context.js +9 -0
  198. package/dist/shims/internal/router-context.js.map +1 -0
  199. package/dist/shims/internal/utils.d.ts +48 -0
  200. package/dist/shims/internal/utils.d.ts.map +1 -0
  201. package/dist/shims/internal/utils.js +35 -0
  202. package/dist/shims/internal/utils.js.map +1 -0
  203. package/dist/shims/internal/work-unit-async-storage.d.ts +12 -0
  204. package/dist/shims/internal/work-unit-async-storage.d.ts.map +1 -0
  205. package/dist/shims/internal/work-unit-async-storage.js +13 -0
  206. package/dist/shims/internal/work-unit-async-storage.js.map +1 -0
  207. package/dist/shims/layout-segment-context.d.ts +21 -0
  208. package/dist/shims/layout-segment-context.d.ts.map +1 -0
  209. package/dist/shims/layout-segment-context.js +27 -0
  210. package/dist/shims/layout-segment-context.js.map +1 -0
  211. package/dist/shims/legacy-image.d.ts +52 -0
  212. package/dist/shims/legacy-image.d.ts.map +1 -0
  213. package/dist/shims/legacy-image.js +46 -0
  214. package/dist/shims/legacy-image.js.map +1 -0
  215. package/dist/shims/link.d.ts +48 -0
  216. package/dist/shims/link.d.ts.map +1 -0
  217. package/dist/shims/link.js +395 -0
  218. package/dist/shims/link.js.map +1 -0
  219. package/dist/shims/metadata.d.ts +184 -0
  220. package/dist/shims/metadata.d.ts.map +1 -0
  221. package/dist/shims/metadata.js +472 -0
  222. package/dist/shims/metadata.js.map +1 -0
  223. package/dist/shims/navigation-state.d.ts +14 -0
  224. package/dist/shims/navigation-state.d.ts.map +1 -0
  225. package/dist/shims/navigation-state.js +77 -0
  226. package/dist/shims/navigation-state.js.map +1 -0
  227. package/dist/shims/navigation.d.ts +201 -0
  228. package/dist/shims/navigation.d.ts.map +1 -0
  229. package/dist/shims/navigation.js +672 -0
  230. package/dist/shims/navigation.js.map +1 -0
  231. package/dist/shims/og.d.ts +20 -0
  232. package/dist/shims/og.d.ts.map +1 -0
  233. package/dist/shims/og.js +19 -0
  234. package/dist/shims/og.js.map +1 -0
  235. package/dist/shims/router-state.d.ts +11 -0
  236. package/dist/shims/router-state.d.ts.map +1 -0
  237. package/dist/shims/router-state.js +56 -0
  238. package/dist/shims/router-state.js.map +1 -0
  239. package/dist/shims/router.d.ts +103 -0
  240. package/dist/shims/router.d.ts.map +1 -0
  241. package/dist/shims/router.js +536 -0
  242. package/dist/shims/router.js.map +1 -0
  243. package/dist/shims/script.d.ts +58 -0
  244. package/dist/shims/script.d.ts.map +1 -0
  245. package/dist/shims/script.js +163 -0
  246. package/dist/shims/script.js.map +1 -0
  247. package/dist/shims/server-only.d.ts +19 -0
  248. package/dist/shims/server-only.d.ts.map +1 -0
  249. package/dist/shims/server-only.js +19 -0
  250. package/dist/shims/server-only.js.map +1 -0
  251. package/dist/shims/server.d.ts +178 -0
  252. package/dist/shims/server.d.ts.map +1 -0
  253. package/dist/shims/server.js +377 -0
  254. package/dist/shims/server.js.map +1 -0
  255. package/dist/shims/web-vitals.d.ts +24 -0
  256. package/dist/shims/web-vitals.d.ts.map +1 -0
  257. package/dist/shims/web-vitals.js +17 -0
  258. package/dist/shims/web-vitals.js.map +1 -0
  259. package/dist/utils/hash.d.ts +6 -0
  260. package/dist/utils/hash.d.ts.map +1 -0
  261. package/dist/utils/hash.js +20 -0
  262. package/dist/utils/hash.js.map +1 -0
  263. package/dist/utils/project.d.ts +36 -0
  264. package/dist/utils/project.d.ts.map +1 -0
  265. package/dist/utils/project.js +112 -0
  266. package/dist/utils/project.js.map +1 -0
  267. package/dist/utils/query.d.ts +10 -0
  268. package/dist/utils/query.d.ts.map +1 -0
  269. package/dist/utils/query.js +27 -0
  270. package/dist/utils/query.js.map +1 -0
  271. package/package.json +65 -7
  272. package/index.js +0 -1
@@ -0,0 +1,243 @@
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
+ interface CacheContextLike {
20
+ tags: string[];
21
+ lifeConfigs: import("./cache-runtime.js").CacheContext["lifeConfigs"];
22
+ variant: string;
23
+ }
24
+ /**
25
+ * Register the cache context accessor. Called by cache-runtime.ts on load.
26
+ * @internal
27
+ */
28
+ export declare function _registerCacheContextAccessor(fn: () => CacheContextLike | null): void;
29
+ export interface CacheHandlerValue {
30
+ lastModified: number;
31
+ age?: number;
32
+ cacheState?: string;
33
+ value: IncrementalCacheValue | null;
34
+ }
35
+ /** Discriminated union of cache value types. */
36
+ export type IncrementalCacheValue = CachedFetchValue | CachedAppPageValue | CachedPagesValue | CachedRouteValue | CachedRedirectValue | CachedImageValue;
37
+ export interface CachedFetchValue {
38
+ kind: "FETCH";
39
+ data: {
40
+ headers: Record<string, string>;
41
+ body: string;
42
+ url: string;
43
+ status?: number;
44
+ };
45
+ tags?: string[];
46
+ revalidate: number;
47
+ }
48
+ export interface CachedAppPageValue {
49
+ kind: "APP_PAGE";
50
+ html: string;
51
+ rscData: ArrayBuffer | undefined;
52
+ headers: Record<string, string | string[]> | undefined;
53
+ postponed: string | undefined;
54
+ status: number | undefined;
55
+ }
56
+ export interface CachedPagesValue {
57
+ kind: "PAGES";
58
+ html: string;
59
+ pageData: object;
60
+ headers: Record<string, string | string[]> | undefined;
61
+ status: number | undefined;
62
+ }
63
+ export interface CachedRouteValue {
64
+ kind: "APP_ROUTE";
65
+ body: ArrayBuffer;
66
+ status: number;
67
+ headers: Record<string, string | string[]>;
68
+ }
69
+ export interface CachedRedirectValue {
70
+ kind: "REDIRECT";
71
+ props: object;
72
+ }
73
+ export interface CachedImageValue {
74
+ kind: "IMAGE";
75
+ etag: string;
76
+ buffer: ArrayBuffer;
77
+ extension: string;
78
+ revalidate?: number;
79
+ }
80
+ export interface CacheHandlerContext {
81
+ dev?: boolean;
82
+ maxMemoryCacheSize?: number;
83
+ revalidatedTags?: string[];
84
+ [key: string]: unknown;
85
+ }
86
+ export interface CacheHandler {
87
+ get(key: string, ctx?: Record<string, unknown>): Promise<CacheHandlerValue | null>;
88
+ set(key: string, data: IncrementalCacheValue | null, ctx?: Record<string, unknown>): Promise<void>;
89
+ revalidateTag(tags: string | string[], durations?: {
90
+ expire?: number;
91
+ }): Promise<void>;
92
+ resetRequestCache?(): void;
93
+ }
94
+ export declare class MemoryCacheHandler implements CacheHandler {
95
+ private store;
96
+ private tagRevalidatedAt;
97
+ get(key: string, _ctx?: Record<string, unknown>): Promise<CacheHandlerValue | null>;
98
+ set(key: string, data: IncrementalCacheValue | null, ctx?: Record<string, unknown>): Promise<void>;
99
+ revalidateTag(tags: string | string[], _durations?: {
100
+ expire?: number;
101
+ }): Promise<void>;
102
+ resetRequestCache(): void;
103
+ }
104
+ /**
105
+ * Set a custom CacheHandler. Call this during server startup to
106
+ * plug in Cloudflare KV, Redis, DynamoDB, or any other backend.
107
+ *
108
+ * The handler must implement the CacheHandler interface (same shape
109
+ * as Next.js 16's CacheHandler class).
110
+ */
111
+ export declare function setCacheHandler(handler: CacheHandler): void;
112
+ /**
113
+ * Get the active CacheHandler (for internal use or testing).
114
+ */
115
+ export declare function getCacheHandler(): CacheHandler;
116
+ /**
117
+ * Revalidate cached data associated with a specific cache tag.
118
+ *
119
+ * Works with both `fetch(..., { next: { tags: ['myTag'] } })` and
120
+ * `unstable_cache(fn, keys, { tags: ['myTag'] })`.
121
+ */
122
+ /**
123
+ * Revalidate cached data associated with a specific cache tag.
124
+ *
125
+ * Next.js 16 updated signature: requires a cacheLife profile as second argument
126
+ * for stale-while-revalidate (SWR) behavior. The single-argument form is
127
+ * deprecated but still supported for backward compatibility.
128
+ *
129
+ * @param tag - Cache tag to revalidate
130
+ * @param profile - cacheLife profile name (e.g. 'max', 'hours') or inline { expire: number }
131
+ */
132
+ export declare function revalidateTag(tag: string, profile?: string | {
133
+ expire?: number;
134
+ }): Promise<void>;
135
+ /**
136
+ * Revalidate cached data associated with a specific path.
137
+ *
138
+ * Under the hood, Next.js converts paths to internal tags.
139
+ * We use a `_N_T_/path` prefix convention for path-based tags.
140
+ */
141
+ export declare function revalidatePath(path: string, _type?: "page" | "layout"): Promise<void>;
142
+ /**
143
+ * Expire and immediately refresh cached data for a tag (Next.js 16).
144
+ *
145
+ * Server Actions-only API that provides read-your-writes semantics:
146
+ * the cache entry is expired and fresh data is read within the same request,
147
+ * so the user immediately sees their changes.
148
+ *
149
+ * Use this for interactive features (forms, user settings) where users
150
+ * expect to see their updates instantly.
151
+ *
152
+ * @param tag - Cache tag to expire and refresh
153
+ */
154
+ export declare function updateTag(tag: string): Promise<void>;
155
+ /**
156
+ * Refresh uncached data on the page (Next.js 16).
157
+ *
158
+ * Server Actions-only API that signals the client to re-fetch dynamic
159
+ * (uncached) data without touching the cache. Complementary to the
160
+ * client-side router.refresh().
161
+ *
162
+ * Use this when you need to refresh data like notification counts,
163
+ * live metrics, or status indicators after performing a server action.
164
+ */
165
+ export declare function refresh(): void;
166
+ /**
167
+ * Opt out of static rendering and indicate a particular component should not be cached.
168
+ *
169
+ * In Next.js, calling noStore() inside a Server Component ensures the component
170
+ * is dynamically rendered. In our implementation, this is a no-op since we don't
171
+ * have the same static/dynamic rendering split — all server rendering is on-demand.
172
+ * It's provided for API compatibility so apps importing it don't break.
173
+ */
174
+ export declare function unstable_noStore(): void;
175
+ export { unstable_noStore as noStore };
176
+ /**
177
+ * Initialize cache ALS for a new request. Call at request entry.
178
+ * @internal
179
+ */
180
+ export declare function _initRequestScopedCacheState(): void;
181
+ /**
182
+ * Set a request-scoped cache life config. Called by cacheLife() when outside
183
+ * a "use cache" function context.
184
+ * @internal
185
+ */
186
+ export declare function _setRequestScopedCacheLife(config: CacheLifeConfig): void;
187
+ /**
188
+ * Consume and reset the request-scoped cache life. Returns null if none was set.
189
+ * @internal
190
+ */
191
+ export declare function _consumeRequestScopedCacheLife(): CacheLifeConfig | null;
192
+ /**
193
+ * Cache life configuration. Controls stale-while-revalidate behavior.
194
+ */
195
+ export interface CacheLifeConfig {
196
+ /** How long (seconds) the client can cache without checking the server */
197
+ stale?: number;
198
+ /** How frequently (seconds) the server cache refreshes */
199
+ revalidate?: number;
200
+ /** Max staleness (seconds) before deoptimizing to dynamic */
201
+ expire?: number;
202
+ }
203
+ /**
204
+ * Built-in cache life profiles matching Next.js 16.
205
+ */
206
+ export declare const cacheLifeProfiles: Record<string, CacheLifeConfig>;
207
+ /**
208
+ * Set the cache lifetime for a "use cache" function.
209
+ *
210
+ * Accepts either a built-in profile name (e.g., "hours", "days") or a custom
211
+ * configuration object. In Next.js, this only works inside "use cache" functions.
212
+ *
213
+ * When called inside a "use cache" function, this sets the cache TTL.
214
+ * The "minimum-wins" rule applies: if called multiple times, the shortest
215
+ * duration for each field wins.
216
+ *
217
+ * When called outside a "use cache" context, this is a validated no-op.
218
+ */
219
+ export declare function cacheLife(profile: string | CacheLifeConfig): void;
220
+ /**
221
+ * Tag a "use cache" function's cached result for on-demand revalidation.
222
+ *
223
+ * Tags set here can be invalidated via revalidateTag(). In Next.js, this only
224
+ * works inside "use cache" functions.
225
+ *
226
+ * When called inside a "use cache" function, tags are attached to the cached
227
+ * entry. They can later be invalidated via revalidateTag().
228
+ *
229
+ * When called outside a "use cache" context, this is a no-op.
230
+ */
231
+ export declare function cacheTag(...tags: string[]): void;
232
+ interface UnstableCacheOptions {
233
+ revalidate?: number | false;
234
+ tags?: string[];
235
+ }
236
+ /**
237
+ * Wrap an async function with caching.
238
+ *
239
+ * Returns a new function that caches results. The cache key is derived
240
+ * from keyParts + serialized arguments.
241
+ */
242
+ export declare function unstable_cache<T extends (...args: any[]) => Promise<any>>(fn: T, keyParts?: string[], options?: UnstableCacheOptions): T;
243
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/shims/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,OAAO,oBAAoB,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC;IACtE,OAA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/**
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";
21
+ import { fnv1a64 } from "../utils/hash.js";
22
+ /** @internal Set by cache-runtime.ts on import to avoid circular dependency */
23
+ let _getCacheContextFn = null;
24
+ /**
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
+ }
97
+ }
98
+ // ---------------------------------------------------------------------------
99
+ // Active cache handler — the singleton used by next/cache API functions.
100
+ // Defaults to MemoryCacheHandler, can be swapped at runtime.
101
+ // ---------------------------------------------------------------------------
102
+ let activeHandler = new MemoryCacheHandler();
103
+ /**
104
+ * Set a custom CacheHandler. Call this during server startup to
105
+ * plug in Cloudflare KV, Redis, DynamoDB, or any other backend.
106
+ *
107
+ * The handler must implement the CacheHandler interface (same shape
108
+ * as Next.js 16's CacheHandler class).
109
+ */
110
+ export function setCacheHandler(handler) {
111
+ activeHandler = handler;
112
+ }
113
+ /**
114
+ * Get the active CacheHandler (for internal use or testing).
115
+ */
116
+ export function getCacheHandler() {
117
+ return activeHandler;
118
+ }
119
+ // ---------------------------------------------------------------------------
120
+ // Public API — what app code imports from 'next/cache'
121
+ // ---------------------------------------------------------------------------
122
+ /**
123
+ * Revalidate cached data associated with a specific cache tag.
124
+ *
125
+ * Works with both `fetch(..., { next: { tags: ['myTag'] } })` and
126
+ * `unstable_cache(fn, keys, { tags: ['myTag'] })`.
127
+ */
128
+ /**
129
+ * Revalidate cached data associated with a specific cache tag.
130
+ *
131
+ * Next.js 16 updated signature: requires a cacheLife profile as second argument
132
+ * for stale-while-revalidate (SWR) behavior. The single-argument form is
133
+ * deprecated but still supported for backward compatibility.
134
+ *
135
+ * @param tag - Cache tag to revalidate
136
+ * @param profile - cacheLife profile name (e.g. 'max', 'hours') or inline { expire: number }
137
+ */
138
+ export async function revalidateTag(tag, profile) {
139
+ // Resolve the profile to durations for the handler
140
+ let durations;
141
+ if (typeof profile === "string") {
142
+ const resolved = cacheLifeProfiles[profile];
143
+ if (resolved) {
144
+ durations = { expire: resolved.expire };
145
+ }
146
+ }
147
+ else if (profile && typeof profile === "object") {
148
+ durations = profile;
149
+ }
150
+ await activeHandler.revalidateTag(tag, durations);
151
+ }
152
+ /**
153
+ * Revalidate cached data associated with a specific path.
154
+ *
155
+ * Under the hood, Next.js converts paths to internal tags.
156
+ * We use a `_N_T_/path` prefix convention for path-based tags.
157
+ */
158
+ export async function revalidatePath(path, _type) {
159
+ // Next.js internally converts paths to tags with a prefix
160
+ const pathTag = `_N_T_${path}`;
161
+ await activeHandler.revalidateTag([path, pathTag]);
162
+ }
163
+ /**
164
+ * Expire and immediately refresh cached data for a tag (Next.js 16).
165
+ *
166
+ * Server Actions-only API that provides read-your-writes semantics:
167
+ * the cache entry is expired and fresh data is read within the same request,
168
+ * so the user immediately sees their changes.
169
+ *
170
+ * Use this for interactive features (forms, user settings) where users
171
+ * expect to see their updates instantly.
172
+ *
173
+ * @param tag - Cache tag to expire and refresh
174
+ */
175
+ export async function updateTag(tag) {
176
+ // Expire the tag immediately (same as revalidateTag without SWR)
177
+ await activeHandler.revalidateTag(tag);
178
+ }
179
+ /**
180
+ * Refresh uncached data on the page (Next.js 16).
181
+ *
182
+ * Server Actions-only API that signals the client to re-fetch dynamic
183
+ * (uncached) data without touching the cache. Complementary to the
184
+ * client-side router.refresh().
185
+ *
186
+ * Use this when you need to refresh data like notification counts,
187
+ * live metrics, or status indicators after performing a server action.
188
+ */
189
+ export function refresh() {
190
+ // In our implementation, this is a signal that the client should
191
+ // refresh dynamic data. The actual refresh happens on the client side
192
+ // via the RSC protocol — the server action response triggers a
193
+ // client-side navigation refresh.
194
+ // For now, this is a no-op on the server; the Server Action response
195
+ // mechanism already handles re-rendering the affected RSC tree.
196
+ }
197
+ /**
198
+ * Opt out of static rendering and indicate a particular component should not be cached.
199
+ *
200
+ * In Next.js, calling noStore() inside a Server Component ensures the component
201
+ * is dynamically rendered. In our implementation, this is a no-op since we don't
202
+ * have the same static/dynamic rendering split — all server rendering is on-demand.
203
+ * It's provided for API compatibility so apps importing it don't break.
204
+ */
205
+ export function unstable_noStore() {
206
+ // Signal dynamic usage so ISR-configured routes bypass the cache
207
+ _markDynamic();
208
+ }
209
+ // Also export as `noStore` (Next.js 15+ naming)
210
+ export { unstable_noStore as noStore };
211
+ const _ALS_KEY = Symbol.for("vinext.cache.als");
212
+ const _FALLBACK_KEY = Symbol.for("vinext.cache.fallback");
213
+ const _g = globalThis;
214
+ const _cacheAls = (_g[_ALS_KEY] ??= new AsyncLocalStorage());
215
+ const _cacheFallbackState = (_g[_FALLBACK_KEY] ??= {
216
+ requestScopedCacheLife: null,
217
+ });
218
+ function _cacheEnterWith(state) {
219
+ const enterWith = _cacheAls.enterWith;
220
+ if (typeof enterWith === "function") {
221
+ try {
222
+ enterWith.call(_cacheAls, state);
223
+ return;
224
+ }
225
+ catch {
226
+ // Fall through to best-effort fallback.
227
+ }
228
+ }
229
+ _cacheFallbackState.requestScopedCacheLife = state.requestScopedCacheLife;
230
+ }
231
+ function _getCacheState() {
232
+ return _cacheAls.getStore() ?? _cacheFallbackState;
233
+ }
234
+ /**
235
+ * Initialize cache ALS for a new request. Call at request entry.
236
+ * @internal
237
+ */
238
+ export function _initRequestScopedCacheState() {
239
+ _cacheEnterWith({ requestScopedCacheLife: null });
240
+ _cacheFallbackState.requestScopedCacheLife = null;
241
+ }
242
+ /**
243
+ * Set a request-scoped cache life config. Called by cacheLife() when outside
244
+ * a "use cache" function context.
245
+ * @internal
246
+ */
247
+ export function _setRequestScopedCacheLife(config) {
248
+ const state = _getCacheState();
249
+ if (state.requestScopedCacheLife === null) {
250
+ state.requestScopedCacheLife = { ...config };
251
+ }
252
+ else {
253
+ // Minimum-wins rule
254
+ if (config.stale !== undefined) {
255
+ state.requestScopedCacheLife.stale = state.requestScopedCacheLife.stale !== undefined
256
+ ? Math.min(state.requestScopedCacheLife.stale, config.stale)
257
+ : config.stale;
258
+ }
259
+ if (config.revalidate !== undefined) {
260
+ state.requestScopedCacheLife.revalidate = state.requestScopedCacheLife.revalidate !== undefined
261
+ ? Math.min(state.requestScopedCacheLife.revalidate, config.revalidate)
262
+ : config.revalidate;
263
+ }
264
+ if (config.expire !== undefined) {
265
+ state.requestScopedCacheLife.expire = state.requestScopedCacheLife.expire !== undefined
266
+ ? Math.min(state.requestScopedCacheLife.expire, config.expire)
267
+ : config.expire;
268
+ }
269
+ }
270
+ }
271
+ /**
272
+ * Consume and reset the request-scoped cache life. Returns null if none was set.
273
+ * @internal
274
+ */
275
+ export function _consumeRequestScopedCacheLife() {
276
+ const state = _getCacheState();
277
+ const config = state.requestScopedCacheLife;
278
+ state.requestScopedCacheLife = null;
279
+ return config;
280
+ }
281
+ /**
282
+ * Built-in cache life profiles matching Next.js 16.
283
+ */
284
+ export const cacheLifeProfiles = {
285
+ default: { revalidate: 900, expire: 4294967294 },
286
+ seconds: { stale: 30, revalidate: 1, expire: 60 },
287
+ minutes: { stale: 300, revalidate: 60, expire: 3600 },
288
+ hours: { stale: 300, revalidate: 3600, expire: 86400 },
289
+ days: { stale: 300, revalidate: 86400, expire: 604800 },
290
+ weeks: { stale: 300, revalidate: 604800, expire: 2592000 },
291
+ max: { stale: 300, revalidate: 2592000, expire: 31536000 },
292
+ };
293
+ /**
294
+ * Set the cache lifetime for a "use cache" function.
295
+ *
296
+ * Accepts either a built-in profile name (e.g., "hours", "days") or a custom
297
+ * configuration object. In Next.js, this only works inside "use cache" functions.
298
+ *
299
+ * When called inside a "use cache" function, this sets the cache TTL.
300
+ * The "minimum-wins" rule applies: if called multiple times, the shortest
301
+ * duration for each field wins.
302
+ *
303
+ * When called outside a "use cache" context, this is a validated no-op.
304
+ */
305
+ export function cacheLife(profile) {
306
+ let resolvedConfig;
307
+ if (typeof profile === "string") {
308
+ // Validate the profile name exists
309
+ if (!cacheLifeProfiles[profile]) {
310
+ console.warn(`[vinext] cacheLife: unknown profile "${profile}". ` +
311
+ `Available profiles: ${Object.keys(cacheLifeProfiles).join(", ")}`);
312
+ return;
313
+ }
314
+ resolvedConfig = { ...cacheLifeProfiles[profile] };
315
+ }
316
+ else if (typeof profile === "object" && profile !== null) {
317
+ // Validate the config shape
318
+ if (profile.expire !== undefined &&
319
+ profile.revalidate !== undefined &&
320
+ profile.expire < profile.revalidate) {
321
+ console.warn("[vinext] cacheLife: expire must be >= revalidate");
322
+ }
323
+ resolvedConfig = { ...profile };
324
+ }
325
+ else {
326
+ return;
327
+ }
328
+ // If we're inside a "use cache" context, push the config
329
+ try {
330
+ const ctx = _getCacheContextFn?.();
331
+ if (ctx) {
332
+ ctx.lifeConfigs.push(resolvedConfig);
333
+ return;
334
+ }
335
+ }
336
+ catch {
337
+ // Fall through to request-scoped
338
+ }
339
+ // Outside a "use cache" context (e.g., page component with file-level "use cache"):
340
+ // store as request-scoped so the server can read it after rendering.
341
+ _setRequestScopedCacheLife(resolvedConfig);
342
+ }
343
+ /**
344
+ * Tag a "use cache" function's cached result for on-demand revalidation.
345
+ *
346
+ * Tags set here can be invalidated via revalidateTag(). In Next.js, this only
347
+ * works inside "use cache" functions.
348
+ *
349
+ * When called inside a "use cache" function, tags are attached to the cached
350
+ * entry. They can later be invalidated via revalidateTag().
351
+ *
352
+ * When called outside a "use cache" context, this is a no-op.
353
+ */
354
+ export function cacheTag(...tags) {
355
+ try {
356
+ const ctx = _getCacheContextFn?.();
357
+ if (ctx) {
358
+ ctx.tags.push(...tags);
359
+ }
360
+ }
361
+ catch {
362
+ // Not in a cache context — no-op
363
+ }
364
+ }
365
+ /**
366
+ * Wrap an async function with caching.
367
+ *
368
+ * Returns a new function that caches results. The cache key is derived
369
+ * from keyParts + serialized arguments.
370
+ */
371
+ export function unstable_cache(fn, keyParts, options) {
372
+ const baseKey = keyParts
373
+ ? keyParts.join(":")
374
+ : fnv1a64(fn.toString());
375
+ const tags = options?.tags ?? [];
376
+ const revalidateSeconds = options?.revalidate;
377
+ const cachedFn = async (...args) => {
378
+ const argsKey = JSON.stringify(args);
379
+ const cacheKey = `unstable_cache:${baseKey}:${argsKey}`;
380
+ // Try to get from cache
381
+ const existing = await activeHandler.get(cacheKey, {
382
+ kind: "FETCH",
383
+ tags,
384
+ });
385
+ if (existing?.value && existing.value.kind === "FETCH") {
386
+ try {
387
+ return JSON.parse(existing.value.data.body);
388
+ }
389
+ catch {
390
+ // Corrupted entry, fall through to re-fetch
391
+ }
392
+ }
393
+ // Cache miss — call the function
394
+ const result = await fn(...args);
395
+ // Store in cache using the FETCH kind
396
+ const cacheValue = {
397
+ kind: "FETCH",
398
+ data: {
399
+ headers: {},
400
+ body: JSON.stringify(result),
401
+ url: cacheKey,
402
+ },
403
+ tags,
404
+ revalidate: typeof revalidateSeconds === "number" ? revalidateSeconds : 0,
405
+ };
406
+ await activeHandler.set(cacheKey, cacheValue, {
407
+ fetchCache: true,
408
+ tags,
409
+ revalidate: revalidateSeconds,
410
+ });
411
+ return result;
412
+ };
413
+ return cachedFn;
414
+ }
415
+ //# sourceMappingURL=cache.js.map