@revealui/cache 0.1.3 → 0.1.5

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.
@@ -0,0 +1,90 @@
1
+ RevealUI Studio — Commercial Licensing for Pro Packages
2
+
3
+ This file is an explainer for the dual-license structure of this repository.
4
+ It is NOT a standalone license document; the canonical license terms for
5
+ each Pro package live in that package's own LICENSE file.
6
+
7
+ ## Repository Licensing Overview
8
+
9
+ Most of this repository (the OSS packages, apps, scripts, docs, and tooling)
10
+ is licensed under the MIT License. See LICENSE in the repository root for
11
+ those terms.
12
+
13
+ A small number of "Pro" packages are licensed under the Functional Source
14
+ License v1.1 with MIT Future License (FSL-1.1-MIT) instead of MIT. Those
15
+ packages each carry their own LICENSE file containing the canonical FSL
16
+ terms; this file documents which packages are covered and what FSL-1.1-MIT
17
+ permits and restricts.
18
+
19
+ ## Pro Packages Covered
20
+
21
+ The following packages distributed in this repository are licensed under
22
+ FSL-1.1-MIT, not MIT:
23
+
24
+ - @revealui/ai (see packages/ai/LICENSE)
25
+ - @revealui/harnesses (see packages/harnesses/LICENSE)
26
+
27
+ Additional Pro packages may be added in future. The presence of a LICENSE
28
+ file inside a package directory containing the FSL-1.1-MIT text is the
29
+ authoritative signal that the package is governed by FSL terms rather than
30
+ the root MIT LICENSE.
31
+
32
+ ## What FSL-1.1-MIT Permits
33
+
34
+ Source code for Pro packages is publicly available. You may:
35
+
36
+ - Use the package internally for any purpose, including commercial use
37
+ - Modify the package and distribute derivative works under the same terms
38
+ - Inspect, audit, and debug the source
39
+ - Depend on the package from your own software
40
+
41
+ ## What FSL-1.1-MIT Restricts
42
+
43
+ You may NOT make the functionality of a Pro package available to third
44
+ parties as a service that competes with RevealUI Studio's commercial
45
+ offerings. The full restriction text in each per-package LICENSE controls;
46
+ in plain language, prohibited uses include:
47
+
48
+ - Hosting the package as part of a SaaS that primarily delivers the
49
+ package's functionality
50
+ - Offering a service whose value derives entirely or primarily from the
51
+ package
52
+ - Repackaging the functionality for redistribution as a competing service
53
+
54
+ If you are unsure whether your intended use is restricted, contact
55
+ founder@revealui.com before relying on the package.
56
+
57
+ ## Change Date and MIT Conversion
58
+
59
+ Each Pro package's LICENSE file specifies a Change Date. On the earlier of
60
+ that date or the fourth anniversary of the first publicly-available
61
+ distribution of a specific version of the package under FSL, the package
62
+ automatically converts to the MIT License (the "Change License"). After
63
+ conversion, all FSL restrictions are removed for the version in question
64
+ and going forward.
65
+
66
+ This means every Pro package in this repository will eventually become MIT;
67
+ FSL-1.1-MIT is a time-limited restriction, not a permanent one.
68
+
69
+ ## Commercial Licensing Alternatives
70
+
71
+ If FSL-1.1-MIT terms do not fit your use case (for example, you are
72
+ building a service that the FSL would prohibit, or you need contractual
73
+ guarantees beyond what an open license provides), commercial licensing is
74
+ available.
75
+
76
+ Contact: founder@revealui.com
77
+
78
+ ## Canonical FSL-1.1-MIT Text
79
+
80
+ The Functional Source License v1.1 with MIT Future License is published at:
81
+
82
+ https://fsl.software/FSL-1.1-MIT.template.md
83
+
84
+ The full canonical text is reproduced verbatim in each Pro package's
85
+ LICENSE file. If there is any conflict between this explainer and a
86
+ per-package LICENSE file, the per-package LICENSE file controls.
87
+
88
+ ---
89
+
90
+ Copyright (c) 2025-2026 RevealUI Studio
package/README.md CHANGED
@@ -10,7 +10,7 @@ Caching infrastructure for RevealUI applications. Provides CDN cache configurati
10
10
  - You want edge-level rate limiting or A/B test variant assignment
11
11
  - You need cache warming for static paths
12
12
 
13
- If you're caching in-memory data within a single request, use standard `Map` or LRUthis package is for HTTP-layer and CDN caching.
13
+ If you're caching in-memory data within a single request, use standard `Map` or LRU - this package is for HTTP-layer and CDN caching.
14
14
 
15
15
  ## Installation
16
16
 
@@ -18,7 +18,7 @@ If you're caching in-memory data within a single request, use standard `Map` or
18
18
  pnpm add @revealui/cache
19
19
  ```
20
20
 
21
- Optional peer dependency: `next` (>=14.0.0)required for ISR helpers.
21
+ Optional peer dependency: `next` (>=14.0.0) - required for ISR helpers.
22
22
 
23
23
  ## API Reference
24
24
 
@@ -78,11 +78,11 @@ Optional peer dependency: `next` (>=14.0.0) — required for ISR helpers.
78
78
  ## JOSHUA Alignment
79
79
 
80
80
  - **Adaptive**: ISR presets scale from real-time (10s) to immutable (1y) based on content volatility
81
- - **Unified**: Cache tags follow the same taxonomy as CMS collectionsinvalidation is automatic
82
- - **Orthogonal**: Caching is a separate concern from content servingswap CDN providers without changing business logic
81
+ - **Unified**: Cache tags follow the same taxonomy as CMS collections - invalidation is automatic
82
+ - **Orthogonal**: Caching is a separate concern from content serving - swap CDN providers without changing business logic
83
83
 
84
84
  ## Related Packages
85
85
 
86
- - `apps/api`Applies cache headers to REST responses
87
- - `apps/marketing`Uses ISR presets for marketing pages
88
- - `@revealui/core`Triggers cache invalidation on content changes
86
+ - `apps/server` - Applies cache headers to REST responses
87
+ - `apps/marketing` - Uses ISR presets for marketing pages
88
+ - `@revealui/core` - Triggers cache invalidation on content changes
@@ -1,6 +1,38 @@
1
1
  import { C as CacheStore } from '../types-CmU1eRbl.js';
2
2
  export { a as CacheEntry } from '../types-CmU1eRbl.js';
3
3
 
4
+ /**
5
+ * Browser PGlite Cache Store
6
+ *
7
+ * Creates a PGlite WASM instance in the browser backed by IndexedDB,
8
+ * then wraps it with PGliteCacheStore for SQL-powered client-side caching.
9
+ *
10
+ * Benefits over localStorage:
11
+ * - SQL queries for filtering cached data
12
+ * - Tag-based and prefix-based invalidation
13
+ * - IndexedDB storage (much larger than localStorage's ~5MB)
14
+ * - Shared CacheStore interface with server-side cache
15
+ *
16
+ * Usage:
17
+ * const cache = await createBrowserCache();
18
+ * await cache.set('posts:123', postData, 3600, ['posts']);
19
+ * const data = await cache.get('posts:123');
20
+ * await cache.close(); // on unmount
21
+ */
22
+
23
+ interface BrowserCacheOptions {
24
+ /** IndexedDB database name for persistence (default: 'revealui-cache') */
25
+ dbName?: string;
26
+ }
27
+ /**
28
+ * Create a browser-compatible PGlite cache store.
29
+ *
30
+ * Dynamically imports @electric-sql/pglite (WASM) to avoid bundling
31
+ * it in server builds. The PGlite instance uses IndexedDB for persistence
32
+ * so cached data survives page reloads.
33
+ */
34
+ declare function createBrowserCache(options?: BrowserCacheOptions): Promise<CacheStore>;
35
+
4
36
  /**
5
37
  * In-Memory Cache Store
6
38
  *
@@ -30,13 +62,13 @@ declare class InMemoryCacheStore implements CacheStore {
30
62
  *
31
63
  * PostgreSQL-compatible cache store backed by PGlite (in-memory or file-based).
32
64
  * Provides the same CacheStore interface as InMemoryCacheStore but uses SQL
33
- * for persistence and queryingenabling distributed invalidation via
65
+ * for persistence and querying - enabling distributed invalidation via
34
66
  * ElectricSQL shape subscriptions in Phase 5.10C.
35
67
  *
36
68
  * Table schema is auto-created on first use (no external migrations needed).
37
69
  */
38
70
 
39
- /** Minimal PGlite interfaceavoids importing the full @electric-sql/pglite package. */
71
+ /** Minimal PGlite interface - avoids importing the full @electric-sql/pglite package. */
40
72
  interface PGliteInstance {
41
73
  exec(query: string): Promise<unknown>;
42
74
  query<T = Record<string, unknown>>(query: string, params?: unknown[]): Promise<{
@@ -69,4 +101,26 @@ declare class PGliteCacheStore implements CacheStore {
69
101
  close(): Promise<void>;
70
102
  }
71
103
 
72
- export { CacheStore, InMemoryCacheStore, PGliteCacheStore };
104
+ interface UseBrowserCacheResult {
105
+ /** The PGlite-backed CacheStore instance. Null while initializing. */
106
+ cache: CacheStore | null;
107
+ /** Whether the cache is still being initialized. */
108
+ loading: boolean;
109
+ /** Initialization error, if any. */
110
+ error: Error | null;
111
+ }
112
+ /**
113
+ * Access the browser-side PGlite cache store.
114
+ *
115
+ * Returns a shared singleton CacheStore. Multiple components can
116
+ * use this hook without creating duplicate PGlite instances.
117
+ *
118
+ * Example:
119
+ * const { cache, loading } = useBrowserCache();
120
+ * if (!loading && cache) {
121
+ * const data = await cache.get('posts:recent');
122
+ * }
123
+ */
124
+ declare function useBrowserCache(): UseBrowserCacheResult;
125
+
126
+ export { CacheStore, InMemoryCacheStore, PGliteCacheStore, createBrowserCache, useBrowserCache };
@@ -1,3 +1,8 @@
1
+ import {
2
+ PGliteCacheStore,
3
+ createBrowserCache
4
+ } from "../chunk-EPAGOXMX.js";
5
+
1
6
  // src/adapters/memory.ts
2
7
  var InMemoryCacheStore = class {
3
8
  store = /* @__PURE__ */ new Map();
@@ -82,114 +87,58 @@ var InMemoryCacheStore = class {
82
87
  }
83
88
  };
84
89
 
85
- // src/adapters/pglite.ts
86
- var CREATE_TABLE_SQL = `
87
- CREATE TABLE IF NOT EXISTS _cache_entries (
88
- key TEXT PRIMARY KEY,
89
- value TEXT NOT NULL,
90
- expires_at BIGINT NOT NULL,
91
- tags TEXT[] NOT NULL DEFAULT '{}'
92
- );
93
- CREATE INDEX IF NOT EXISTS _cache_entries_expires_idx ON _cache_entries (expires_at);
94
- `;
95
- var PGliteCacheStore = class {
96
- db;
97
- ready;
98
- closeOnDestroy;
99
- constructor(options) {
100
- this.db = options.db;
101
- this.closeOnDestroy = options.closeOnDestroy ?? false;
102
- this.ready = this.init();
103
- }
104
- async init() {
105
- await this.db.exec(CREATE_TABLE_SQL);
106
- }
107
- async get(key) {
108
- await this.ready;
109
- const now = Date.now();
110
- const result = await this.db.query(
111
- "SELECT value FROM _cache_entries WHERE key = $1 AND expires_at > $2",
112
- [key, now]
113
- );
114
- const row = result.rows[0];
115
- if (!row) return null;
116
- return JSON.parse(row.value);
117
- }
118
- async set(key, value, ttlSeconds, tags) {
119
- await this.ready;
120
- const expiresAt = Date.now() + ttlSeconds * 1e3;
121
- const serialized = JSON.stringify(value);
122
- const tagArray = tags ?? [];
123
- await this.db.query(
124
- `INSERT INTO _cache_entries (key, value, expires_at, tags)
125
- VALUES ($1, $2, $3, $4)
126
- ON CONFLICT (key) DO UPDATE
127
- SET value = EXCLUDED.value, expires_at = EXCLUDED.expires_at, tags = EXCLUDED.tags`,
128
- [key, serialized, expiresAt, tagArray]
129
- );
130
- }
131
- async delete(...keys) {
132
- await this.ready;
133
- if (keys.length === 0) return 0;
134
- const placeholders = keys.map((_, i) => `$${i + 1}`).join(", ");
135
- const result = await this.db.query(
136
- `WITH deleted AS (DELETE FROM _cache_entries WHERE key IN (${placeholders}) RETURNING 1)
137
- SELECT count(*)::text AS count FROM deleted`,
138
- keys
139
- );
140
- return Number.parseInt(result.rows[0]?.count ?? "0", 10);
141
- }
142
- async deleteByPrefix(prefix) {
143
- await this.ready;
144
- const escaped = prefix.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
145
- const result = await this.db.query(
146
- `WITH deleted AS (DELETE FROM _cache_entries WHERE key LIKE $1 ESCAPE '\\' RETURNING 1)
147
- SELECT count(*)::text AS count FROM deleted`,
148
- [`${escaped}%`]
149
- );
150
- return Number.parseInt(result.rows[0]?.count ?? "0", 10);
151
- }
152
- async deleteByTags(tags) {
153
- await this.ready;
154
- if (tags.length === 0) return 0;
155
- const result = await this.db.query(
156
- `WITH deleted AS (DELETE FROM _cache_entries WHERE tags && $1 RETURNING 1)
157
- SELECT count(*)::text AS count FROM deleted`,
158
- [tags]
159
- );
160
- return Number.parseInt(result.rows[0]?.count ?? "0", 10);
161
- }
162
- async clear() {
163
- await this.ready;
164
- await this.db.exec("DELETE FROM _cache_entries");
165
- }
166
- async size() {
167
- await this.ready;
168
- const now = Date.now();
169
- const result = await this.db.query(
170
- "SELECT count(*)::text AS count FROM _cache_entries WHERE expires_at > $1",
171
- [now]
172
- );
173
- return Number.parseInt(result.rows[0]?.count ?? "0", 10);
174
- }
175
- async prune() {
176
- await this.ready;
177
- const now = Date.now();
178
- const result = await this.db.query(
179
- `WITH deleted AS (DELETE FROM _cache_entries WHERE expires_at <= $1 RETURNING 1)
180
- SELECT count(*)::text AS count FROM deleted`,
181
- [now]
182
- );
183
- return Number.parseInt(result.rows[0]?.count ?? "0", 10);
184
- }
185
- async close() {
186
- if (this.closeOnDestroy) {
187
- await this.db.close();
90
+ // src/adapters/use-browser-cache.ts
91
+ import { useEffect, useRef, useState } from "react";
92
+ var sharedCache = null;
93
+ var initPromise = null;
94
+ var refCount = 0;
95
+ async function getOrCreateCache() {
96
+ if (sharedCache) return sharedCache;
97
+ if (initPromise) return initPromise;
98
+ initPromise = import("../browser-7BTPENLH.js").then(async (mod) => {
99
+ const cache = await mod.createBrowserCache();
100
+ sharedCache = cache;
101
+ return cache;
102
+ });
103
+ return initPromise;
104
+ }
105
+ function useBrowserCache() {
106
+ const [cache, setCache] = useState(sharedCache);
107
+ const [loading, setLoading] = useState(!sharedCache);
108
+ const [error, setError] = useState(null);
109
+ const mounted = useRef(true);
110
+ useEffect(() => {
111
+ mounted.current = true;
112
+ refCount++;
113
+ if (!sharedCache) {
114
+ getOrCreateCache().then((c) => {
115
+ if (mounted.current) {
116
+ setCache(c);
117
+ setLoading(false);
118
+ }
119
+ }).catch((err) => {
120
+ if (mounted.current) {
121
+ setError(err instanceof Error ? err : new Error(String(err)));
122
+ setLoading(false);
123
+ }
124
+ });
188
125
  }
189
- }
190
- };
126
+ return () => {
127
+ mounted.current = false;
128
+ refCount--;
129
+ if (refCount === 0 && sharedCache) {
130
+ sharedCache.close().catch(() => {
131
+ });
132
+ sharedCache = null;
133
+ initPromise = null;
134
+ }
135
+ };
136
+ }, []);
137
+ return { cache, loading, error };
138
+ }
191
139
  export {
192
140
  InMemoryCacheStore,
193
- PGliteCacheStore
141
+ PGliteCacheStore,
142
+ createBrowserCache,
143
+ useBrowserCache
194
144
  };
195
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ import {
2
+ createBrowserCache
3
+ } from "./chunk-EPAGOXMX.js";
4
+ export {
5
+ createBrowserCache
6
+ };
@@ -0,0 +1,123 @@
1
+ // src/adapters/pglite.ts
2
+ var CREATE_TABLE_SQL = `
3
+ CREATE TABLE IF NOT EXISTS _cache_entries (
4
+ key TEXT PRIMARY KEY,
5
+ value TEXT NOT NULL,
6
+ expires_at BIGINT NOT NULL,
7
+ tags TEXT[] NOT NULL DEFAULT '{}'
8
+ );
9
+ CREATE INDEX IF NOT EXISTS _cache_entries_expires_idx ON _cache_entries (expires_at);
10
+ `;
11
+ var PGliteCacheStore = class {
12
+ db;
13
+ ready;
14
+ closeOnDestroy;
15
+ constructor(options) {
16
+ this.db = options.db;
17
+ this.closeOnDestroy = options.closeOnDestroy ?? false;
18
+ this.ready = this.init();
19
+ }
20
+ async init() {
21
+ await this.db.exec(CREATE_TABLE_SQL);
22
+ }
23
+ async get(key) {
24
+ await this.ready;
25
+ const now = Date.now();
26
+ const result = await this.db.query(
27
+ "SELECT value FROM _cache_entries WHERE key = $1 AND expires_at > $2",
28
+ [key, now]
29
+ );
30
+ const row = result.rows[0];
31
+ if (!row) return null;
32
+ return JSON.parse(row.value);
33
+ }
34
+ async set(key, value, ttlSeconds, tags) {
35
+ await this.ready;
36
+ const expiresAt = Date.now() + ttlSeconds * 1e3;
37
+ const serialized = JSON.stringify(value);
38
+ const tagArray = tags ?? [];
39
+ await this.db.query(
40
+ `INSERT INTO _cache_entries (key, value, expires_at, tags)
41
+ VALUES ($1, $2, $3, $4)
42
+ ON CONFLICT (key) DO UPDATE
43
+ SET value = EXCLUDED.value, expires_at = EXCLUDED.expires_at, tags = EXCLUDED.tags`,
44
+ [key, serialized, expiresAt, tagArray]
45
+ );
46
+ }
47
+ async delete(...keys) {
48
+ await this.ready;
49
+ if (keys.length === 0) return 0;
50
+ const placeholders = keys.map((_, i) => `$${i + 1}`).join(", ");
51
+ const result = await this.db.query(
52
+ `WITH deleted AS (DELETE FROM _cache_entries WHERE key IN (${placeholders}) RETURNING 1)
53
+ SELECT count(*)::text AS count FROM deleted`,
54
+ keys
55
+ );
56
+ return Number.parseInt(result.rows[0]?.count ?? "0", 10);
57
+ }
58
+ async deleteByPrefix(prefix) {
59
+ await this.ready;
60
+ const escaped = prefix.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
61
+ const result = await this.db.query(
62
+ `WITH deleted AS (DELETE FROM _cache_entries WHERE key LIKE $1 ESCAPE '\\' RETURNING 1)
63
+ SELECT count(*)::text AS count FROM deleted`,
64
+ [`${escaped}%`]
65
+ );
66
+ return Number.parseInt(result.rows[0]?.count ?? "0", 10);
67
+ }
68
+ async deleteByTags(tags) {
69
+ await this.ready;
70
+ if (tags.length === 0) return 0;
71
+ const result = await this.db.query(
72
+ `WITH deleted AS (DELETE FROM _cache_entries WHERE tags && $1 RETURNING 1)
73
+ SELECT count(*)::text AS count FROM deleted`,
74
+ [tags]
75
+ );
76
+ return Number.parseInt(result.rows[0]?.count ?? "0", 10);
77
+ }
78
+ async clear() {
79
+ await this.ready;
80
+ await this.db.exec("DELETE FROM _cache_entries");
81
+ }
82
+ async size() {
83
+ await this.ready;
84
+ const now = Date.now();
85
+ const result = await this.db.query(
86
+ "SELECT count(*)::text AS count FROM _cache_entries WHERE expires_at > $1",
87
+ [now]
88
+ );
89
+ return Number.parseInt(result.rows[0]?.count ?? "0", 10);
90
+ }
91
+ async prune() {
92
+ await this.ready;
93
+ const now = Date.now();
94
+ const result = await this.db.query(
95
+ `WITH deleted AS (DELETE FROM _cache_entries WHERE expires_at <= $1 RETURNING 1)
96
+ SELECT count(*)::text AS count FROM deleted`,
97
+ [now]
98
+ );
99
+ return Number.parseInt(result.rows[0]?.count ?? "0", 10);
100
+ }
101
+ async close() {
102
+ if (this.closeOnDestroy) {
103
+ await this.db.close();
104
+ }
105
+ }
106
+ };
107
+
108
+ // src/adapters/browser.ts
109
+ async function createBrowserCache(options) {
110
+ const dbName = options?.dbName ?? "revealui-cache";
111
+ const { PGlite } = await import("@electric-sql/pglite");
112
+ const db = new PGlite(`idb://${dbName}`);
113
+ await db.waitReady;
114
+ return new PGliteCacheStore({
115
+ db,
116
+ closeOnDestroy: true
117
+ });
118
+ }
119
+
120
+ export {
121
+ PGliteCacheStore,
122
+ createBrowserCache
123
+ };
package/dist/index.d.ts CHANGED
@@ -379,7 +379,7 @@ interface InvalidationChannelOptions {
379
379
  instanceId: string;
380
380
  /** Poll interval in milliseconds (default: 5000). */
381
381
  pollIntervalMs?: number;
382
- /** Event TTL in secondsevents older than this are pruned (default: 60). */
382
+ /** Event TTL in seconds - events older than this are pruned (default: 60). */
383
383
  eventTtlSeconds?: number;
384
384
  }
385
385
  interface PGliteInstance {
package/dist/index.js CHANGED
@@ -368,6 +368,9 @@ function getCacheTTL(headers) {
368
368
  return 0;
369
369
  }
370
370
 
371
+ // src/edge-cache.ts
372
+ import { getClientIp } from "@revealui/security";
373
+
371
374
  // src/logger.ts
372
375
  var cacheLogger = console;
373
376
  function configureCacheLogger(logger) {
@@ -564,12 +567,13 @@ var EdgeRateLimiter = class {
564
567
  constructor(config) {
565
568
  this.config = config;
566
569
  }
570
+ config;
567
571
  cache = /* @__PURE__ */ new Map();
568
572
  /**
569
573
  * Check rate limit
570
574
  */
571
575
  check(request) {
572
- const key = this.config.key ? this.config.key(request) : request.headers.get("x-forwarded-for") || "unknown";
576
+ const key = this.config.key ? this.config.key(request) : getClientIp(request);
573
577
  const now = Date.now();
574
578
  let entry = this.cache.get(key);
575
579
  if (!entry || now > entry.resetTime) {
@@ -630,7 +634,7 @@ function getABTestVariant(request, testName, variants) {
630
634
  if (cookieVariant && variants.includes(cookieVariant)) {
631
635
  return cookieVariant;
632
636
  }
633
- const ip = request.headers.get("x-forwarded-for") || "unknown";
637
+ const ip = getClientIp(request);
634
638
  const hash = simpleHash(ip + testName);
635
639
  const variantIndex = hash % variants.length;
636
640
  const variant = variants[variantIndex];
@@ -923,4 +927,3 @@ export {
923
927
  warmCDNCache,
924
928
  warmISRCache
925
929
  };
926
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@revealui/cache",
3
- "version": "0.1.3",
4
- "description": "Caching infrastructure for RevealUI - CDN config, edge cache, ISR presets, revalidation",
3
+ "version": "0.1.5",
4
+ "description": "CDN config, edge cache, ISR presets, and revalidation helpers for Vercel and Hono. Ships with RevealUI.",
5
5
  "license": "MIT",
6
- "dependencies": {},
6
+ "dependencies": {
7
+ "@revealui/security": "0.3.1"
8
+ },
7
9
  "devDependencies": {
8
- "@electric-sql/pglite": "^0.4.2",
9
- "@types/node": "^25.5.0",
10
+ "@electric-sql/pglite": "^0.4.4",
11
+ "@types/node": "^25.6.0",
10
12
  "tsup": "^8.5.1",
11
- "typescript": "^6.0.2",
12
- "vitest": "^4.1.0",
13
- "dev": "0.0.1"
13
+ "typescript": "^6.0.3",
14
+ "vitest": "^4.1.5",
15
+ "@revealui/dev": "0.1.0"
14
16
  },
15
17
  "engines": {
16
18
  "node": ">=24.13.0"
@@ -30,7 +32,7 @@
30
32
  ],
31
33
  "main": "./dist/index.js",
32
34
  "peerDependencies": {
33
- "next": "^14.0.0 || ^15.0.0 || ^16.1.7"
35
+ "next": "^14.0.0 || ^15.5.10 || ^16.2.3"
34
36
  },
35
37
  "peerDependenciesMeta": {
36
38
  "next": {
@@ -48,6 +50,19 @@
48
50
  "url": "https://github.com/RevealUIStudio/revealui.git",
49
51
  "directory": "packages/cache"
50
52
  },
53
+ "homepage": "https://revealui.com",
54
+ "author": "RevealUI Studio <founder@revealui.com>",
55
+ "bugs": {
56
+ "url": "https://github.com/RevealUIStudio/revealui/issues"
57
+ },
58
+ "keywords": [
59
+ "revealui",
60
+ "cache",
61
+ "cdn",
62
+ "edge-cache",
63
+ "isr",
64
+ "revalidation"
65
+ ],
51
66
  "scripts": {
52
67
  "build": "tsup",
53
68
  "clean": "rm -rf dist",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/adapters/memory.ts","../../src/adapters/pglite.ts"],"sourcesContent":["/**\n * In-Memory Cache Store\n *\n * Map-backed cache store. Fast, zero-dependency, single-instance only.\n * Use for development, testing, or when distributed state isn't needed.\n */\n\nimport type { CacheStore } from './types.js';\n\ninterface MemoryEntry {\n value: string; // JSON-serialized\n expiresAt: number;\n tags: string[];\n}\n\nexport class InMemoryCacheStore implements CacheStore {\n private store = new Map<string, MemoryEntry>();\n private maxEntries: number;\n\n constructor(options?: { maxEntries?: number }) {\n this.maxEntries = options?.maxEntries ?? 10_000;\n }\n\n async get<T = unknown>(key: string): Promise<T | null> {\n const entry = this.store.get(key);\n if (!entry) return null;\n\n if (Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return null;\n }\n\n return JSON.parse(entry.value) as T;\n }\n\n async set<T = unknown>(\n key: string,\n value: T,\n ttlSeconds: number,\n tags?: string[],\n ): Promise<void> {\n // Evict oldest if at capacity\n if (this.store.size >= this.maxEntries && !this.store.has(key)) {\n const firstKey = this.store.keys().next().value;\n if (firstKey !== undefined) {\n this.store.delete(firstKey);\n }\n }\n\n this.store.set(key, {\n value: JSON.stringify(value),\n expiresAt: Date.now() + ttlSeconds * 1000,\n tags: tags ?? [],\n });\n }\n\n async delete(...keys: string[]): Promise<number> {\n let count = 0;\n for (const key of keys) {\n if (this.store.delete(key)) count++;\n }\n return count;\n }\n\n async deleteByPrefix(prefix: string): Promise<number> {\n let count = 0;\n for (const key of this.store.keys()) {\n if (key.startsWith(prefix)) {\n this.store.delete(key);\n count++;\n }\n }\n return count;\n }\n\n async deleteByTags(tags: string[]): Promise<number> {\n const tagSet = new Set(tags);\n let count = 0;\n for (const [key, entry] of this.store.entries()) {\n if (entry.tags.some((t) => tagSet.has(t))) {\n this.store.delete(key);\n count++;\n }\n }\n return count;\n }\n\n async clear(): Promise<void> {\n this.store.clear();\n }\n\n async size(): Promise<number> {\n // Count only non-expired entries\n const now = Date.now();\n let count = 0;\n for (const entry of this.store.values()) {\n if (entry.expiresAt > now) count++;\n }\n return count;\n }\n\n async prune(): Promise<number> {\n const now = Date.now();\n let pruned = 0;\n for (const [key, entry] of this.store.entries()) {\n if (entry.expiresAt <= now) {\n this.store.delete(key);\n pruned++;\n }\n }\n return pruned;\n }\n\n async close(): Promise<void> {\n this.store.clear();\n }\n}\n","/**\n * PGlite Cache Store\n *\n * PostgreSQL-compatible cache store backed by PGlite (in-memory or file-based).\n * Provides the same CacheStore interface as InMemoryCacheStore but uses SQL\n * for persistence and querying — enabling distributed invalidation via\n * ElectricSQL shape subscriptions in Phase 5.10C.\n *\n * Table schema is auto-created on first use (no external migrations needed).\n */\n\nimport type { CacheStore } from './types.js';\n\n/** Minimal PGlite interface — avoids importing the full @electric-sql/pglite package. */\ninterface PGliteInstance {\n exec(query: string): Promise<unknown>;\n query<T = Record<string, unknown>>(query: string, params?: unknown[]): Promise<{ rows: T[] }>;\n close(): Promise<void>;\n}\n\nconst CREATE_TABLE_SQL = `\n CREATE TABLE IF NOT EXISTS _cache_entries (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL,\n expires_at BIGINT NOT NULL,\n tags TEXT[] NOT NULL DEFAULT '{}'\n );\n CREATE INDEX IF NOT EXISTS _cache_entries_expires_idx ON _cache_entries (expires_at);\n`;\n\ninterface PGliteCacheStoreOptions {\n /** PGlite instance (caller owns lifecycle unless closeOnDestroy is true). */\n db: PGliteInstance;\n /** Table name prefix to avoid collisions (default: none). */\n tablePrefix?: string;\n /** Close the PGlite instance when close() is called (default: false). */\n closeOnDestroy?: boolean;\n}\n\nexport class PGliteCacheStore implements CacheStore {\n private db: PGliteInstance;\n private ready: Promise<void>;\n private closeOnDestroy: boolean;\n\n constructor(options: PGliteCacheStoreOptions) {\n this.db = options.db;\n this.closeOnDestroy = options.closeOnDestroy ?? false;\n this.ready = this.init();\n }\n\n private async init(): Promise<void> {\n await this.db.exec(CREATE_TABLE_SQL);\n }\n\n async get<T = unknown>(key: string): Promise<T | null> {\n await this.ready;\n const now = Date.now();\n\n const result = await this.db.query<{ value: string }>(\n 'SELECT value FROM _cache_entries WHERE key = $1 AND expires_at > $2',\n [key, now],\n );\n\n const row = result.rows[0];\n if (!row) return null;\n\n return JSON.parse(row.value) as T;\n }\n\n async set<T = unknown>(\n key: string,\n value: T,\n ttlSeconds: number,\n tags?: string[],\n ): Promise<void> {\n await this.ready;\n const expiresAt = Date.now() + ttlSeconds * 1000;\n const serialized = JSON.stringify(value);\n const tagArray = tags ?? [];\n\n await this.db.query(\n `INSERT INTO _cache_entries (key, value, expires_at, tags)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (key) DO UPDATE\n SET value = EXCLUDED.value, expires_at = EXCLUDED.expires_at, tags = EXCLUDED.tags`,\n [key, serialized, expiresAt, tagArray],\n );\n }\n\n async delete(...keys: string[]): Promise<number> {\n await this.ready;\n if (keys.length === 0) return 0;\n\n // Build parameterized IN clause\n const placeholders = keys.map((_, i) => `$${i + 1}`).join(', ');\n const result = await this.db.query<{ count: string }>(\n `WITH deleted AS (DELETE FROM _cache_entries WHERE key IN (${placeholders}) RETURNING 1)\n SELECT count(*)::text AS count FROM deleted`,\n keys,\n );\n\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n async deleteByPrefix(prefix: string): Promise<number> {\n await this.ready;\n // Escape LIKE metacharacters — backslash first, then % and _\n const escaped = prefix.replaceAll('\\\\', '\\\\\\\\').replaceAll('%', '\\\\%').replaceAll('_', '\\\\_');\n\n const result = await this.db.query<{ count: string }>(\n `WITH deleted AS (DELETE FROM _cache_entries WHERE key LIKE $1 ESCAPE '\\\\' RETURNING 1)\n SELECT count(*)::text AS count FROM deleted`,\n [`${escaped}%`],\n );\n\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n async deleteByTags(tags: string[]): Promise<number> {\n await this.ready;\n if (tags.length === 0) return 0;\n\n const result = await this.db.query<{ count: string }>(\n `WITH deleted AS (DELETE FROM _cache_entries WHERE tags && $1 RETURNING 1)\n SELECT count(*)::text AS count FROM deleted`,\n [tags],\n );\n\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n async clear(): Promise<void> {\n await this.ready;\n await this.db.exec('DELETE FROM _cache_entries');\n }\n\n async size(): Promise<number> {\n await this.ready;\n const now = Date.now();\n const result = await this.db.query<{ count: string }>(\n 'SELECT count(*)::text AS count FROM _cache_entries WHERE expires_at > $1',\n [now],\n );\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n async prune(): Promise<number> {\n await this.ready;\n const now = Date.now();\n const result = await this.db.query<{ count: string }>(\n `WITH deleted AS (DELETE FROM _cache_entries WHERE expires_at <= $1 RETURNING 1)\n SELECT count(*)::text AS count FROM deleted`,\n [now],\n );\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n async close(): Promise<void> {\n if (this.closeOnDestroy) {\n await this.db.close();\n }\n }\n}\n"],"mappings":";AAeO,IAAM,qBAAN,MAA+C;AAAA,EAC5C,QAAQ,oBAAI,IAAyB;AAAA,EACrC;AAAA,EAER,YAAY,SAAmC;AAC7C,SAAK,aAAa,SAAS,cAAc;AAAA,EAC3C;AAAA,EAEA,MAAM,IAAiB,KAAgC;AACrD,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAChC,QAAI,CAAC,MAAO,QAAO;AAEnB,QAAI,KAAK,IAAI,IAAI,MAAM,WAAW;AAChC,WAAK,MAAM,OAAO,GAAG;AACrB,aAAO;AAAA,IACT;AAEA,WAAO,KAAK,MAAM,MAAM,KAAK;AAAA,EAC/B;AAAA,EAEA,MAAM,IACJ,KACA,OACA,YACA,MACe;AAEf,QAAI,KAAK,MAAM,QAAQ,KAAK,cAAc,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AAC9D,YAAM,WAAW,KAAK,MAAM,KAAK,EAAE,KAAK,EAAE;AAC1C,UAAI,aAAa,QAAW;AAC1B,aAAK,MAAM,OAAO,QAAQ;AAAA,MAC5B;AAAA,IACF;AAEA,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB,OAAO,KAAK,UAAU,KAAK;AAAA,MAC3B,WAAW,KAAK,IAAI,IAAI,aAAa;AAAA,MACrC,MAAM,QAAQ,CAAC;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,UAAU,MAAiC;AAC/C,QAAI,QAAQ;AACZ,eAAW,OAAO,MAAM;AACtB,UAAI,KAAK,MAAM,OAAO,GAAG,EAAG;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;AAAA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K,KAAK;AAE5F,UAAM,SAAS,MAAM,KAAK,GAAG;AAAA,MAC3B;AAAA;AAAA,MAEA,CAAC,GAAG,OAAO,GAAG;AAAA,IAChB;AAEA,WAAO,OAAO,SAAS,OAAO,KAAK,CAAC,GAAG,SAAS,KAAK,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,aAAa,MAAiC;AAClD,UAAM,KAAK;AACX,QAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,UAAM,SAAS,MAAM,KAAK,GAAG;AAAA,MAC3B;AAAA;AAAA,MAEA,CAAC,IAAI;AAAA,IACP;AAEA,WAAO,OAAO,SAAS,OAAO,KAAK,CAAC,GAAG,SAAS,KAAK,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK;AACX,UAAM,KAAK,GAAG,KAAK,4BAA4B;AAAA,EACjD;AAAA,EAEA,MAAM,OAAwB;AAC5B,UAAM,KAAK;AACX,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,SAAS,MAAM,KAAK,GAAG;AAAA,MAC3B;AAAA,MACA,CAAC,GAAG;AAAA,IACN;AACA,WAAO,OAAO,SAAS,OAAO,KAAK,CAAC,GAAG,SAAS,KAAK,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,QAAyB;AAC7B,UAAM,KAAK;AACX,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,SAAS,MAAM,KAAK,GAAG;AAAA,MAC3B;AAAA;AAAA,MAEA,CAAC,GAAG;AAAA,IACN;AACA,WAAO,OAAO,SAAS,OAAO,KAAK,CAAC,GAAG,SAAS,KAAK,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,QAAuB;AAC3B,QAAI,KAAK,gBAAgB;AACvB,YAAM,KAAK,GAAG,MAAM;AAAA,IACtB;AAAA,EACF;AACF;","names":[]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cdn-config.ts","../src/logger.ts","../src/edge-cache.ts","../src/invalidation-channel.ts"],"sourcesContent":["/**\n * CDN Configuration and Cache Management\n *\n * Utilities for CDN caching, edge caching, and cache invalidation\n */\n\n/**\n * CDN Cache Configuration\n */\nexport interface CDNCacheConfig {\n provider?: 'cloudflare' | 'vercel' | 'fastly' | 'custom';\n zones?: string[];\n ttl?: number;\n staleWhileRevalidate?: number;\n staleIfError?: number;\n bypassCache?: boolean;\n cacheKey?: string[];\n varyHeaders?: string[];\n}\n\nexport const DEFAULT_CDN_CONFIG: CDNCacheConfig = {\n provider: 'vercel',\n ttl: 31536000, // 1 year for static assets\n staleWhileRevalidate: 86400, // 1 day\n staleIfError: 604800, // 1 week\n bypassCache: false,\n cacheKey: ['url', 'headers.accept', 'headers.accept-encoding'],\n varyHeaders: ['Accept', 'Accept-Encoding'],\n};\n\n/**\n * Generate Cache-Control header\n */\nexport function generateCacheControl(config: {\n maxAge?: number;\n sMaxAge?: number;\n staleWhileRevalidate?: number;\n staleIfError?: number;\n public?: boolean;\n private?: boolean;\n immutable?: boolean;\n noCache?: boolean;\n noStore?: boolean;\n}): string {\n const directives: string[] = [];\n\n // Visibility\n if (config.noStore) {\n directives.push('no-store');\n return directives.join(', ');\n }\n\n if (config.noCache) {\n directives.push('no-cache');\n return directives.join(', ');\n }\n\n if (config.public) {\n directives.push('public');\n } else if (config.private) {\n directives.push('private');\n }\n\n // Max age\n if (config.maxAge !== undefined) {\n directives.push(`max-age=${config.maxAge}`);\n }\n\n // Shared max age (CDN)\n if (config.sMaxAge !== undefined) {\n directives.push(`s-maxage=${config.sMaxAge}`);\n }\n\n // Stale-while-revalidate\n if (config.staleWhileRevalidate !== undefined) {\n directives.push(`stale-while-revalidate=${config.staleWhileRevalidate}`);\n }\n\n // Stale-if-error\n if (config.staleIfError !== undefined) {\n directives.push(`stale-if-error=${config.staleIfError}`);\n }\n\n // Immutable\n if (config.immutable) {\n directives.push('immutable');\n }\n\n return directives.join(', ');\n}\n\n/**\n * Cache presets for different asset types\n */\nexport const CDN_CACHE_PRESETS = {\n // Static assets with hashed filenames (immutable)\n immutable: {\n maxAge: 31536000, // 1 year\n sMaxAge: 31536000,\n public: true,\n immutable: true,\n },\n\n // Static assets (images, fonts)\n static: {\n maxAge: 2592000, // 30 days\n sMaxAge: 31536000, // 1 year on CDN\n staleWhileRevalidate: 86400, // 1 day\n public: true,\n },\n\n // API responses (short-lived)\n api: {\n maxAge: 0,\n sMaxAge: 60, // 1 minute on CDN\n staleWhileRevalidate: 30,\n public: true,\n },\n\n // HTML pages (dynamic)\n page: {\n maxAge: 0,\n sMaxAge: 300, // 5 minutes on CDN\n staleWhileRevalidate: 60,\n public: true,\n },\n\n // User-specific data\n private: {\n maxAge: 300, // 5 minutes\n private: true,\n staleWhileRevalidate: 60,\n },\n\n // No caching\n noCache: {\n noStore: true,\n },\n\n // Revalidate every request\n revalidate: {\n maxAge: 0,\n sMaxAge: 0,\n noCache: true,\n },\n} as const;\n\n/**\n * CDN Purge Configuration\n */\nexport interface CDNPurgeConfig {\n provider: 'cloudflare' | 'vercel' | 'fastly';\n apiKey?: string;\n apiSecret?: string;\n zoneId?: string;\n distributionId?: string;\n}\n\n/**\n * Purge CDN cache\n */\nexport async function purgeCDNCache(\n urls: string[],\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; purged: number; errors?: string[] }> {\n const { provider } = config;\n\n switch (provider) {\n case 'cloudflare':\n return purgeCloudflare(urls, config);\n case 'vercel':\n return purgeVercel(urls, config);\n case 'fastly':\n return purgeFastly(urls, config);\n default:\n throw new Error(`Unsupported CDN provider: ${provider}`);\n }\n}\n\n/**\n * Purge Cloudflare cache\n */\nasync function purgeCloudflare(\n urls: string[],\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; purged: number; errors?: string[] }> {\n const { apiKey, zoneId } = config;\n\n if (!(apiKey && zoneId)) {\n throw new Error('Cloudflare API key and zone ID required');\n }\n\n try {\n const response = await fetch(\n `https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache`,\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ files: urls }),\n },\n );\n\n const data = await response.json();\n\n return {\n success: data.success,\n purged: urls.length,\n errors: data.errors,\n };\n } catch (error) {\n return {\n success: false,\n purged: 0,\n errors: [error instanceof Error ? error.message : 'Unknown error'],\n };\n }\n}\n\n/**\n * Purge Vercel cache\n */\nasync function purgeVercel(\n urls: string[],\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; purged: number; errors?: string[] }> {\n const { apiKey } = config;\n\n if (!apiKey) {\n throw new Error('Vercel API token required');\n }\n\n try {\n const response = await fetch('https://api.vercel.com/v1/purge', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ urls }),\n });\n\n const data = await response.json();\n\n return {\n success: response.ok,\n purged: urls.length,\n errors: data.error ? [data.error.message] : undefined,\n };\n } catch (error) {\n return {\n success: false,\n purged: 0,\n errors: [error instanceof Error ? error.message : 'Unknown error'],\n };\n }\n}\n\n/**\n * Purge Fastly cache\n */\nasync function purgeFastly(\n urls: string[],\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; purged: number; errors?: string[] }> {\n const { apiKey } = config;\n\n if (!apiKey) {\n throw new Error('Fastly API key required');\n }\n\n try {\n const results = await Promise.all(\n urls.map(async (url) => {\n const response = await fetch(url, {\n method: 'PURGE',\n headers: {\n 'Fastly-Key': apiKey,\n },\n });\n\n return response.ok;\n }),\n );\n\n const purged = results.filter(Boolean).length;\n\n return {\n success: purged === urls.length,\n purged,\n };\n } catch (error) {\n return {\n success: false,\n purged: 0,\n errors: [error instanceof Error ? error.message : 'Unknown error'],\n };\n }\n}\n\n/**\n * Purge by cache tag\n */\nexport async function purgeCacheByTag(\n tags: string[],\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; purged: number; errors?: string[] }> {\n const { provider, apiKey, zoneId } = config;\n\n if (provider === 'cloudflare') {\n if (!(apiKey && zoneId)) {\n throw new Error('Cloudflare API key and zone ID required');\n }\n\n try {\n const response = await fetch(\n `https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache`,\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ tags }),\n },\n );\n\n const data = await response.json();\n\n return {\n success: data.success,\n purged: tags.length,\n errors: data.errors,\n };\n } catch (error) {\n return {\n success: false,\n purged: 0,\n errors: [error instanceof Error ? error.message : 'Unknown error'],\n };\n }\n }\n\n throw new Error(`Cache tag purging not supported for ${provider}`);\n}\n\n/**\n * Purge everything\n */\nexport async function purgeAllCache(\n config: CDNPurgeConfig,\n): Promise<{ success: boolean; errors?: string[] }> {\n const { provider, apiKey, zoneId } = config;\n\n if (provider === 'cloudflare') {\n if (!(apiKey && zoneId)) {\n throw new Error('Cloudflare API key and zone ID required');\n }\n\n try {\n const response = await fetch(\n `https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache`,\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ purge_everything: true }),\n },\n );\n\n const data = await response.json();\n\n return {\n success: data.success,\n errors: data.errors,\n };\n } catch (error) {\n return {\n success: false,\n errors: [error instanceof Error ? error.message : 'Unknown error'],\n };\n }\n }\n\n throw new Error(`Purge all not supported for ${provider}`);\n}\n\n/**\n * CDN cache warming\n */\nexport async function warmCDNCache(\n urls: string[],\n options: {\n concurrency?: number;\n headers?: Record<string, string>;\n } = {},\n): Promise<{ warmed: number; failed: number; errors: string[] }> {\n const { concurrency = 5, headers = {} } = options;\n\n const results: { success: boolean; error?: string }[] = [];\n const chunks: string[][] = [];\n\n // Split into chunks\n for (let i = 0; i < urls.length; i += concurrency) {\n chunks.push(urls.slice(i, i + concurrency));\n }\n\n // Warm cache in chunks\n for (const chunk of chunks) {\n const chunkResults = await Promise.all(\n chunk.map(async (url) => {\n try {\n const response = await fetch(url, { headers });\n return {\n success: response.ok,\n error: response.ok ? undefined : `${response.status} ${response.statusText}`,\n };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }),\n );\n\n results.push(...chunkResults);\n }\n\n const warmed = results.filter((r) => r.success).length;\n const failed = results.filter((r) => !r.success).length;\n const errors = results.flatMap((r) => (r.error ? [r.error] : []));\n\n return { warmed, failed, errors };\n}\n\n/**\n * Generate cache tags\n */\nexport function generateCacheTags(resource: {\n type: string;\n id?: string | number;\n related?: string[];\n}): string[] {\n const tags: string[] = [];\n\n // Type tag\n tags.push(resource.type);\n\n // ID tag\n if (resource.id) {\n tags.push(`${resource.type}:${resource.id}`);\n }\n\n // Related tags\n if (resource.related) {\n tags.push(...resource.related);\n }\n\n return tags;\n}\n\n/**\n * Edge cache configuration for Vercel\n */\nexport function generateVercelCacheConfig(preset: keyof typeof CDN_CACHE_PRESETS) {\n const config = CDN_CACHE_PRESETS[preset];\n const cacheControl = generateCacheControl(config);\n\n return {\n headers: {\n 'Cache-Control': cacheControl,\n 'CDN-Cache-Control': cacheControl,\n 'Vercel-CDN-Cache-Control': cacheControl,\n },\n };\n}\n\n/**\n * Edge cache configuration for Cloudflare\n */\nexport function generateCloudflareConfig(\n preset: keyof typeof CDN_CACHE_PRESETS,\n options: {\n cacheTags?: string[];\n bypassOnCookie?: string;\n } = {},\n) {\n const config = CDN_CACHE_PRESETS[preset];\n const cacheControl = generateCacheControl(config);\n\n const headers: Record<string, string> = {\n 'Cache-Control': cacheControl,\n };\n\n // Cache tags\n if (options.cacheTags && options.cacheTags.length > 0) {\n headers['Cache-Tag'] = options.cacheTags.join(',');\n }\n\n // Bypass on cookie\n if (options.bypassOnCookie) {\n headers['Cache-Control'] = `${cacheControl}, bypass=${options.bypassOnCookie}`;\n }\n\n return { headers };\n}\n\n/**\n * Check if response should be cached\n */\nexport function shouldCacheResponse(status: number, headers: Headers): boolean {\n // Don't cache errors\n if (status >= 400) {\n return false;\n }\n\n // Check Cache-Control header\n const cacheControl = headers.get('cache-control') || '';\n if (\n cacheControl.includes('no-store') ||\n cacheControl.includes('no-cache') ||\n cacheControl.includes('private')\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Calculate cache TTL from headers\n */\nexport function getCacheTTL(headers: Headers): number {\n const cacheControl = headers.get('cache-control') || '';\n\n // Check s-maxage first (CDN), then max-age\n for (const directive of cacheControl.split(',')) {\n const trimmed = directive.trim();\n if (trimmed.startsWith('s-maxage=')) {\n const val = trimmed.slice('s-maxage='.length);\n const num = Number.parseInt(val, 10);\n if (!Number.isNaN(num)) return num;\n }\n }\n for (const directive of cacheControl.split(',')) {\n const trimmed = directive.trim();\n if (trimmed.startsWith('max-age=')) {\n const val = trimmed.slice('max-age='.length);\n const num = Number.parseInt(val, 10);\n if (!Number.isNaN(num)) return num;\n }\n }\n\n // Check Expires header\n const expires = headers.get('expires');\n if (expires) {\n const expiresDate = new Date(expires);\n const now = new Date();\n return Math.max(0, Math.floor((expiresDate.getTime() - now.getTime()) / 1000));\n }\n\n return 0;\n}\n","/**\n * Internal logger for @revealui/cache.\n *\n * Defaults to `console`. Consumers should call `configureCacheLogger()`\n * to supply a structured logger (e.g. from `@revealui/utils/logger`).\n */\n\nexport interface CacheLogger {\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n debug(message: string, ...args: unknown[]): void;\n}\n\nlet cacheLogger: CacheLogger = console;\n\n/**\n * Replace the default console logger with a structured logger.\n */\nexport function configureCacheLogger(logger: CacheLogger): void {\n cacheLogger = logger;\n}\n\n/**\n * Get the current cache logger instance.\n */\nexport function getCacheLogger(): CacheLogger {\n return cacheLogger;\n}\n","/**\n * Edge Caching and ISR (Incremental Static Regeneration)\n *\n * Utilities for Next.js edge caching, ISR, and on-demand revalidation\n */\n\nimport type { NextRequest, NextResponse } from 'next/server';\nimport { getCacheLogger } from './logger.js';\n\n/**\n * Next.js extends the standard RequestInit with a `next` property\n * for ISR revalidation and cache tags.\n */\ninterface NextFetchRequestInit extends RequestInit {\n next?: {\n revalidate?: number | false;\n tags?: string[];\n };\n}\n\n/**\n * ISR Configuration\n */\nexport interface ISRConfig {\n revalidate?: number | false;\n tags?: string[];\n dynamicParams?: boolean;\n}\n\nexport const ISR_PRESETS = {\n // Revalidate every request\n always: {\n revalidate: 0,\n },\n\n // Revalidate every minute\n minute: {\n revalidate: 60,\n },\n\n // Revalidate every 5 minutes\n fiveMinutes: {\n revalidate: 300,\n },\n\n // Revalidate every hour\n hourly: {\n revalidate: 3600,\n },\n\n // Revalidate daily\n daily: {\n revalidate: 86400,\n },\n\n // Never revalidate (static)\n never: {\n revalidate: false,\n },\n} as const;\n\n/**\n * Generate static params for ISR\n */\nexport async function generateStaticParams<T>(\n fetchFn: () => Promise<T[]>,\n mapFn: (item: T) => Record<string, string>,\n): Promise<Array<Record<string, string>>> {\n try {\n const items = await fetchFn();\n return items.map(mapFn);\n } catch (error) {\n getCacheLogger().error(\n 'Failed to generate static params',\n error instanceof Error ? error : new Error(String(error)),\n );\n return [];\n }\n}\n\n/**\n * Revalidate tag\n */\nexport async function revalidateTag(\n tag: string,\n secret?: string,\n): Promise<{ revalidated: boolean; error?: string }> {\n const baseUrl = process.env.NEXT_PUBLIC_URL;\n if (!baseUrl) {\n getCacheLogger().warn('revalidateTag skipped: NEXT_PUBLIC_URL is not configured', { tag });\n return { revalidated: false, error: 'NEXT_PUBLIC_URL is not configured' };\n }\n\n try {\n const url = new URL('/api/revalidate', baseUrl);\n\n const headers: HeadersInit = { 'Content-Type': 'application/json' };\n if (secret) {\n headers['x-revalidate-secret'] = secret;\n }\n\n const response = await fetch(url.toString(), {\n method: 'POST',\n headers,\n body: JSON.stringify({ tag }),\n });\n\n const data = await response.json();\n\n if (!response.ok) {\n getCacheLogger().warn('revalidateTag failed', {\n tag,\n status: response.status,\n error: data.error,\n });\n }\n\n return {\n revalidated: response.ok,\n error: data.error,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n getCacheLogger().warn('revalidateTag error', { tag, error: message });\n return {\n revalidated: false,\n error: message,\n };\n }\n}\n\n/**\n * Revalidate path\n */\nexport async function revalidatePath(\n path: string,\n secret?: string,\n): Promise<{ revalidated: boolean; error?: string }> {\n const baseUrl = process.env.NEXT_PUBLIC_URL;\n if (!baseUrl) {\n getCacheLogger().warn('revalidatePath skipped: NEXT_PUBLIC_URL is not configured', { path });\n return { revalidated: false, error: 'NEXT_PUBLIC_URL is not configured' };\n }\n\n try {\n const url = new URL('/api/revalidate', baseUrl);\n\n const headers: HeadersInit = { 'Content-Type': 'application/json' };\n if (secret) {\n headers['x-revalidate-secret'] = secret;\n }\n\n const response = await fetch(url.toString(), {\n method: 'POST',\n headers,\n body: JSON.stringify({ path }),\n });\n\n const data = await response.json();\n\n return {\n revalidated: response.ok,\n error: data.error,\n };\n } catch (error) {\n return {\n revalidated: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n}\n\n/**\n * Revalidate multiple paths\n */\nexport async function revalidatePaths(\n paths: string[],\n secret?: string,\n): Promise<{\n revalidated: number;\n failed: number;\n errors: Array<{ path: string; error: string }>;\n}> {\n const results = await Promise.allSettled(paths.map((path) => revalidatePath(path, secret)));\n\n let revalidated = 0;\n let failed = 0;\n const errors: Array<{ path: string; error: string }> = [];\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n const path = paths[i];\n\n if (!(result && path)) {\n continue;\n }\n\n if (result.status === 'fulfilled' && result.value.revalidated) {\n revalidated++;\n } else {\n failed++;\n const error =\n result.status === 'fulfilled'\n ? result.value.error || 'Unknown error'\n : String(result.reason) || 'Unknown error';\n\n errors.push({ path, error });\n }\n }\n\n return { revalidated, failed, errors };\n}\n\n/**\n * Revalidate multiple tags\n */\nexport async function revalidateTags(\n tags: string[],\n secret?: string,\n): Promise<{\n revalidated: number;\n failed: number;\n errors: Array<{ tag: string; error: string }>;\n}> {\n const results = await Promise.allSettled(tags.map((tag) => revalidateTag(tag, secret)));\n\n let revalidated = 0;\n let failed = 0;\n const errors: Array<{ tag: string; error: string }> = [];\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n const tag = tags[i];\n\n if (!(result && tag)) {\n continue;\n }\n\n if (result.status === 'fulfilled' && result.value.revalidated) {\n revalidated++;\n } else {\n failed++;\n const error =\n result.status === 'fulfilled'\n ? result.value.error || 'Unknown error'\n : String(result.reason) || 'Unknown error';\n\n errors.push({ tag, error });\n }\n }\n\n return { revalidated, failed, errors };\n}\n\n/**\n * Edge middleware cache configuration\n */\nexport interface EdgeCacheConfig {\n cache?: 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached';\n next?: {\n revalidate?: number | false;\n tags?: string[];\n };\n}\n\n/**\n * Create edge cached fetch\n */\nexport function createEdgeCachedFetch(config: EdgeCacheConfig = {}) {\n return async <T>(url: string, options?: NextFetchRequestInit): Promise<T> => {\n const fetchOptions: NextFetchRequestInit = {\n ...options,\n ...config,\n next: {\n ...options?.next,\n ...config.next,\n },\n };\n\n const response = await fetch(url, fetchOptions);\n\n if (!response.ok) {\n throw new Error(`Fetch failed: ${response.statusText}`);\n }\n\n return response.json();\n };\n}\n\n/**\n * Unstable cache wrapper (Next.js 14+)\n */\nexport function createCachedFunction<TArgs extends unknown[], TReturn>(\n fn: (...args: TArgs) => Promise<TReturn>,\n options: {\n tags?: string[];\n revalidate?: number | false;\n } = {},\n): (...args: TArgs) => Promise<TReturn> {\n // If revalidation is disabled, bypass cache entirely\n if (options.revalidate === false) {\n return fn;\n }\n\n const ttlMs = (options.revalidate ?? 60) * 1000;\n const cache = new Map<string, { value: TReturn; expiresAt: number }>();\n\n return async (...args: TArgs): Promise<TReturn> => {\n const key = JSON.stringify(args);\n const now = Date.now();\n const cached = cache.get(key);\n\n if (cached && now < cached.expiresAt) {\n return cached.value;\n }\n\n const value = await fn(...args);\n cache.set(key, { value, expiresAt: now + ttlMs });\n return value;\n };\n}\n\n/**\n * Edge rate limiting with cache\n */\nexport interface EdgeRateLimitConfig {\n limit: number;\n window: number;\n key?: (request: NextRequest) => string;\n}\n\nexport class EdgeRateLimiter {\n private cache: Map<string, { count: number; resetTime: number }> = new Map();\n\n constructor(private config: EdgeRateLimitConfig) {}\n\n /**\n * Check rate limit\n */\n check(request: NextRequest): {\n allowed: boolean;\n limit: number;\n remaining: number;\n reset: number;\n } {\n const key = this.config.key\n ? this.config.key(request)\n : request.headers.get('x-forwarded-for') || 'unknown';\n\n const now = Date.now();\n let entry = this.cache.get(key);\n\n // Reset if window expired\n if (!entry || now > entry.resetTime) {\n entry = {\n count: 0,\n resetTime: now + this.config.window,\n };\n this.cache.set(key, entry);\n }\n\n // Increment count\n entry.count++;\n\n const allowed = entry.count <= this.config.limit;\n const remaining = Math.max(0, this.config.limit - entry.count);\n\n return {\n allowed,\n limit: this.config.limit,\n remaining,\n reset: entry.resetTime,\n };\n }\n\n /**\n * Clean up expired entries\n */\n cleanup(): void {\n const now = Date.now();\n for (const [key, entry] of this.cache.entries()) {\n if (now > entry.resetTime) {\n this.cache.delete(key);\n }\n }\n }\n}\n\n/**\n * Edge geolocation caching\n */\nexport interface GeoLocation {\n country?: string;\n region?: string;\n city?: string;\n latitude?: number;\n longitude?: number;\n}\n\nexport function getGeoLocation(request: NextRequest): GeoLocation | null {\n // Vercel edge headers\n const country = request.headers.get('x-vercel-ip-country');\n const region = request.headers.get('x-vercel-ip-country-region');\n const city = request.headers.get('x-vercel-ip-city');\n const latitude = request.headers.get('x-vercel-ip-latitude');\n const longitude = request.headers.get('x-vercel-ip-longitude');\n\n if (!country) {\n // Cloudflare headers\n const cfCountry = request.headers.get('cf-ipcountry');\n if (cfCountry) {\n return {\n country: cfCountry,\n };\n }\n\n return null;\n }\n\n return {\n country: country || undefined,\n region: region || undefined,\n city: city ? decodeURIComponent(city) : undefined,\n latitude: latitude ? parseFloat(latitude) : undefined,\n longitude: longitude ? parseFloat(longitude) : undefined,\n };\n}\n\n/**\n * Edge A/B testing with cache\n */\nexport function getABTestVariant(\n request: NextRequest,\n testName: string,\n variants: string[],\n): string {\n // Check cookie first\n const cookieName = `ab-test-${testName}`;\n const cookieVariant = request.cookies.get(cookieName)?.value;\n\n if (cookieVariant && variants.includes(cookieVariant)) {\n return cookieVariant;\n }\n\n // Assign variant based on IP hash\n const ip = request.headers.get('x-forwarded-for') || 'unknown';\n const hash = simpleHash(ip + testName);\n const variantIndex = hash % variants.length;\n const variant = variants[variantIndex];\n\n if (!variant) {\n throw new Error('No variant found for A/B test');\n }\n\n return variant;\n}\n\n/**\n * Simple hash function\n */\nfunction simpleHash(str: string): number {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash;\n }\n return Math.abs(hash);\n}\n\n/**\n * Edge personalization cache\n */\nexport interface PersonalizationConfig {\n userId?: string;\n preferences?: Record<string, unknown>;\n location?: GeoLocation;\n device?: 'mobile' | 'tablet' | 'desktop';\n variant?: string;\n}\n\nexport function getPersonalizationConfig(request: NextRequest): PersonalizationConfig {\n const userAgent = request.headers.get('user-agent') || '';\n const device = getDeviceType(userAgent);\n const location = getGeoLocation(request);\n\n return {\n userId: request.cookies.get('user-id')?.value,\n location: location || undefined,\n device,\n };\n}\n\n/**\n * Detect device type\n */\nfunction getDeviceType(userAgent: string): 'mobile' | 'tablet' | 'desktop' {\n const ua = userAgent.toLowerCase();\n const isTablet = ua.includes('tablet') || ua.includes('ipad');\n if (isTablet) return 'tablet';\n if (ua.includes('mobile')) return 'mobile';\n return 'desktop';\n}\n\n/**\n * Edge cache headers helper\n */\nexport function setEdgeCacheHeaders(\n response: NextResponse,\n config: {\n maxAge?: number;\n sMaxAge?: number;\n staleWhileRevalidate?: number;\n tags?: string[];\n },\n): NextResponse {\n const cacheControl: string[] = [];\n\n if (config.maxAge !== undefined) {\n cacheControl.push(`max-age=${config.maxAge}`);\n }\n\n if (config.sMaxAge !== undefined) {\n cacheControl.push(`s-maxage=${config.sMaxAge}`);\n }\n\n if (config.staleWhileRevalidate !== undefined) {\n cacheControl.push(`stale-while-revalidate=${config.staleWhileRevalidate}`);\n }\n\n if (cacheControl.length > 0) {\n response.headers.set('Cache-Control', cacheControl.join(', '));\n }\n\n if (config.tags && config.tags.length > 0) {\n response.headers.set('Cache-Tag', config.tags.join(','));\n }\n\n return response;\n}\n\n/**\n * Preload links for critical resources\n */\nexport function addPreloadLinks(\n response: NextResponse,\n resources: Array<{\n href: string;\n as: string;\n type?: string;\n crossorigin?: boolean;\n }>,\n): NextResponse {\n const links = resources.map((resource) => {\n const attrs = [`<${resource.href}>`, `rel=\"preload\"`, `as=\"${resource.as}\"`];\n\n if (resource.type) {\n attrs.push(`type=\"${resource.type}\"`);\n }\n\n if (resource.crossorigin) {\n attrs.push('crossorigin');\n }\n\n return attrs.join('; ');\n });\n\n if (links.length > 0) {\n response.headers.set('Link', links.join(', '));\n }\n\n return response;\n}\n\n/**\n * Cache warming for ISR pages\n */\nexport async function warmISRCache(\n paths: string[],\n baseURL: string = process.env.NEXT_PUBLIC_URL || 'http://localhost:3000',\n): Promise<{\n warmed: number;\n failed: number;\n errors: Array<{ path: string; error: string }>;\n}> {\n const results = await Promise.allSettled(\n paths.map(async (path) => {\n const url = new URL(path, baseURL);\n const response = await fetch(url.toString());\n\n if (!response.ok) {\n throw new Error(`${response.status} ${response.statusText}`);\n }\n\n return true;\n }),\n );\n\n let warmed = 0;\n let failed = 0;\n const errors: Array<{ path: string; error: string }> = [];\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n const path = paths[i];\n\n if (!(result && path)) {\n continue;\n }\n\n if (result.status === 'fulfilled') {\n warmed++;\n } else {\n failed++;\n errors.push({\n path,\n error:\n result.reason instanceof Error\n ? result.reason.message\n : String(result.reason) || 'Unknown error',\n });\n }\n }\n\n return { warmed, failed, errors };\n}\n","/**\n * Cache Invalidation Channel\n *\n * Coordinates cache invalidation across instances using a shared database table.\n * Events are written to `_cache_invalidation_events` and consumed by polling.\n *\n * Architecture:\n * - Publisher: writes invalidation event to shared PGlite/PostgreSQL table\n * - Subscriber: polls the table for new events and forwards to local CacheStore\n * - Events auto-expire after TTL to prevent unbounded table growth\n *\n * Future: Replace polling with ElectricSQL shape subscriptions or LISTEN/NOTIFY\n * for real-time push-based invalidation (Phase 5.10C/E).\n */\n\nimport type { CacheStore } from './adapters/types.js';\nimport { getCacheLogger } from './logger.js';\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type InvalidationEventType = 'delete' | 'delete-prefix' | 'delete-tags' | 'clear';\n\nexport interface InvalidationEvent {\n id: string;\n type: InvalidationEventType;\n /** Cache keys to delete (for 'delete' type). */\n keys?: string[];\n /** Prefix to match (for 'delete-prefix' type). */\n prefix?: string;\n /** Tags to match (for 'delete-tags' type). */\n tags?: string[];\n /** Instance ID that published the event (for deduplication). */\n sourceInstance: string;\n /** Timestamp when the event was created. */\n createdAt: number;\n}\n\nexport interface InvalidationChannelOptions {\n /** Unique instance identifier (used to skip self-published events). */\n instanceId: string;\n /** Poll interval in milliseconds (default: 5000). */\n pollIntervalMs?: number;\n /** Event TTL in seconds — events older than this are pruned (default: 60). */\n eventTtlSeconds?: number;\n}\n\n// =============================================================================\n// PGlite interface\n// =============================================================================\n\ninterface PGliteInstance {\n exec(query: string): Promise<unknown>;\n query<T = Record<string, unknown>>(query: string, params?: unknown[]): Promise<{ rows: T[] }>;\n close(): Promise<void>;\n}\n\nconst CREATE_EVENTS_TABLE_SQL = `\n CREATE TABLE IF NOT EXISTS _cache_invalidation_events (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n keys TEXT[],\n prefix TEXT,\n tags TEXT[],\n source_instance TEXT NOT NULL,\n created_at BIGINT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS _cache_inv_created_idx ON _cache_invalidation_events (created_at);\n`;\n\n// =============================================================================\n// Invalidation Channel\n// =============================================================================\n\nexport class CacheInvalidationChannel {\n private db: PGliteInstance;\n private store: CacheStore;\n private instanceId: string;\n private pollIntervalMs: number;\n private eventTtlSeconds: number;\n private lastSeenTimestamp: number;\n /** IDs processed at exactly lastSeenTimestamp (prevents re-processing on >= query). */\n private processedAtBoundary: Set<string> = new Set();\n private pollTimer: ReturnType<typeof setInterval> | null = null;\n private ready: Promise<void>;\n\n constructor(db: PGliteInstance, store: CacheStore, options: InvalidationChannelOptions) {\n this.db = db;\n this.store = store;\n this.instanceId = options.instanceId;\n this.pollIntervalMs = options.pollIntervalMs ?? 5000;\n this.eventTtlSeconds = options.eventTtlSeconds ?? 60;\n this.lastSeenTimestamp = Date.now() - 1;\n this.ready = this.init();\n }\n\n private async init(): Promise<void> {\n await this.db.exec(CREATE_EVENTS_TABLE_SQL);\n }\n\n /** Start polling for invalidation events. */\n async start(): Promise<void> {\n await this.ready;\n if (this.pollTimer) return;\n\n this.pollTimer = setInterval(() => {\n void this.poll();\n }, this.pollIntervalMs);\n if (this.pollTimer.unref) this.pollTimer.unref();\n }\n\n /** Stop polling. */\n stop(): void {\n if (this.pollTimer) {\n clearInterval(this.pollTimer);\n this.pollTimer = null;\n }\n }\n\n // ─── Publishing ─────────────────────────────────────────────────────\n\n /** Publish a key deletion event. */\n async publishDelete(...keys: string[]): Promise<void> {\n await this.publish({ type: 'delete', keys });\n }\n\n /** Publish a prefix deletion event. */\n async publishDeletePrefix(prefix: string): Promise<void> {\n await this.publish({ type: 'delete-prefix', prefix });\n }\n\n /** Publish a tag-based deletion event. */\n async publishDeleteTags(tags: string[]): Promise<void> {\n await this.publish({ type: 'delete-tags', tags });\n }\n\n /** Publish a clear-all event. */\n async publishClear(): Promise<void> {\n await this.publish({ type: 'clear' });\n }\n\n private async publish(\n event: Pick<InvalidationEvent, 'type' | 'keys' | 'prefix' | 'tags'>,\n ): Promise<void> {\n await this.ready;\n const id = crypto.randomUUID();\n const now = Date.now();\n\n await this.db.query(\n `INSERT INTO _cache_invalidation_events (id, type, keys, prefix, tags, source_instance, created_at)\n VALUES ($1, $2, $3, $4, $5, $6, $7)`,\n [\n id,\n event.type,\n event.keys ?? null,\n event.prefix ?? null,\n event.tags ?? null,\n this.instanceId,\n now,\n ],\n );\n }\n\n // ─── Polling ────────────────────────────────────────────────────────\n\n /** Poll for new events and apply them to the local cache store. */\n async poll(): Promise<number> {\n await this.ready;\n const logger = getCacheLogger();\n\n // Use >= to avoid missing events with the same millisecond timestamp.\n // Deduplication via processedAtBoundary prevents re-processing.\n const result = await this.db.query<{\n id: string;\n type: string;\n keys: string[] | null;\n prefix: string | null;\n tags: string[] | null;\n source_instance: string;\n created_at: string;\n }>(\n `SELECT id, type, keys, prefix, tags, source_instance, created_at\n FROM _cache_invalidation_events\n WHERE created_at >= $1 AND source_instance != $2\n ORDER BY created_at ASC`,\n [this.lastSeenTimestamp, this.instanceId],\n );\n\n let applied = 0;\n\n for (const row of result.rows) {\n // Skip events we already processed at the boundary timestamp\n if (this.processedAtBoundary.has(row.id)) continue;\n\n const createdAt = Number(row.created_at);\n if (createdAt > this.lastSeenTimestamp) {\n // Timestamp advanced — clear the old boundary set\n this.lastSeenTimestamp = createdAt;\n this.processedAtBoundary.clear();\n }\n this.processedAtBoundary.add(row.id);\n\n try {\n await this.applyEvent(row.type as InvalidationEventType, row);\n applied++;\n } catch (error) {\n logger.error(\n 'Failed to apply invalidation event',\n error instanceof Error ? error : new Error(String(error)),\n );\n }\n }\n\n // Prune old events\n await this.prune();\n\n return applied;\n }\n\n private async applyEvent(\n type: InvalidationEventType,\n row: { keys: string[] | null; prefix: string | null; tags: string[] | null },\n ): Promise<void> {\n switch (type) {\n case 'delete':\n if (row.keys && row.keys.length > 0) {\n await this.store.delete(...row.keys);\n }\n break;\n case 'delete-prefix':\n if (row.prefix) {\n await this.store.deleteByPrefix(row.prefix);\n }\n break;\n case 'delete-tags':\n if (row.tags && row.tags.length > 0) {\n await this.store.deleteByTags(row.tags);\n }\n break;\n case 'clear':\n await this.store.clear();\n break;\n }\n }\n\n /** Remove events older than the TTL. */\n private async prune(): Promise<number> {\n const cutoff = Date.now() - this.eventTtlSeconds * 1000;\n const result = await this.db.query<{ count: string }>(\n `WITH deleted AS (DELETE FROM _cache_invalidation_events WHERE created_at < $1 RETURNING 1)\n SELECT count(*)::text AS count FROM deleted`,\n [cutoff],\n );\n return Number.parseInt(result.rows[0]?.count ?? '0', 10);\n }\n\n /** Release resources. */\n async close(): Promise<void> {\n this.stop();\n }\n}\n"],"mappings":";AAoBO,IAAM,qBAAqC;AAAA,EAChD,UAAU;AAAA,EACV,KAAK;AAAA;AAAA,EACL,sBAAsB;AAAA;AAAA,EACtB,cAAc;AAAA;AAAA,EACd,aAAa;AAAA,EACb,UAAU,CAAC,OAAO,kBAAkB,yBAAyB;AAAA,EAC7D,aAAa,CAAC,UAAU,iBAAiB;AAC3C;AAKO,SAAS,qBAAqB,QAU1B;AACT,QAAM,aAAuB,CAAC;AAG9B,MAAI,OAAO,SAAS;AAClB,eAAW,KAAK,UAAU;AAC1B,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AAEA,MAAI,OAAO,SAAS;AAClB,eAAW,KAAK,UAAU;AAC1B,WAAO,WAAW,KAAK,IAAI;AAAA,EAC7B;AAEA,MAAI,OAAO,QAAQ;AACjB,eAAW,KAAK,QAAQ;AAAA,EAC1B,WAAW,OAAO,SAAS;AACzB,eAAW,KAAK,SAAS;AAAA,EAC3B;AAGA,MAAI,OAAO,WAAW,QAAW;AAC/B,eAAW,KAAK,WAAW,OAAO,MAAM,EAAE;AAAA,EAC5C;AAGA,MAAI,OAAO,YAAY,QAAW;AAChC,eAAW,KAAK,YAAY,OAAO,OAAO,EAAE;AAAA,EAC9C;AAGA,MAAI,OAAO,yBAAyB,QAAW;AAC7C,eAAW,KAAK,0BAA0B,OAAO,oBAAoB,EAAE;AAAA,EACzE;AAGA,MAAI,OAAO,iBAAiB,QAAW;AACrC,eAAW,KAAK,kBAAkB,OAAO,YAAY,EAAE;AAAA,EACzD;AAGA,MAAI,OAAO,WAAW;AACpB,eAAW,KAAK,WAAW;AAAA,EA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