@revealui/cache 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +52 -18
- package/package.json +4 -12
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ Optional peer dependency: `next` (>=14.0.0) - required for ISR helpers.
|
|
|
75
75
|
|--------|------|---------|
|
|
76
76
|
| `configureCacheLogger` | Function | Set custom logger (defaults to console) |
|
|
77
77
|
|
|
78
|
-
##
|
|
78
|
+
## Design Principles
|
|
79
79
|
|
|
80
80
|
- **Adaptive**: ISR presets scale from real-time (10s) to immutable (1y) based on content volatility
|
|
81
81
|
- **Unified**: Cache tags follow the same taxonomy as CMS collections - invalidation is automatic
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { C as CacheStore } from './types-CmU1eRbl.js';
|
|
2
2
|
export { a as CacheEntry } from './types-CmU1eRbl.js';
|
|
3
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* CDN Configuration and Cache Management
|
|
@@ -160,14 +159,47 @@ declare function getCacheTTL(headers: Headers): number;
|
|
|
160
159
|
/**
|
|
161
160
|
* Edge Caching and ISR (Incremental Static Regeneration)
|
|
162
161
|
*
|
|
163
|
-
*
|
|
162
|
+
* Framework-agnostic helpers for edge caching, ISR-style revalidation, edge
|
|
163
|
+
* rate limiting, geolocation, A/B testing, personalization, and CDN cache
|
|
164
|
+
* headers. Works in any runtime that exposes Web-standard `Request` /
|
|
165
|
+
* `Response` — NextRequest/NextResponse pass via structural typing, Hono's
|
|
166
|
+
* `c.req.raw` / `c.res` pass directly, Cloudflare Workers Request/Response
|
|
167
|
+
* pass directly, etc. The package no longer carries a `next` peer dep.
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* Framework-agnostic request shape for edge-cache helpers — compatible with
|
|
171
|
+
* NextRequest, Hono `c.req.raw`, Cloudflare Workers Request, and any other
|
|
172
|
+
* Web-standard `Request` subclass that exposes a NextRequest-style `cookies`
|
|
173
|
+
* map. Narrowed to the read-only subset we actually consume.
|
|
174
|
+
*
|
|
175
|
+
* Consumers using a bare Web `Request` (no `cookies` field — e.g., plain
|
|
176
|
+
* `fetch` requests) must wrap it before calling helpers that read cookies
|
|
177
|
+
* (`getABTestVariant`, `getPersonalizationConfig`). Helpers that only read
|
|
178
|
+
* headers (`getGeoLocation`, `EdgeRateLimiter.check` with default key) work
|
|
179
|
+
* with bare `Request` directly via subtype compatibility.
|
|
180
|
+
*/
|
|
181
|
+
interface CacheRequest extends Request {
|
|
182
|
+
readonly cookies: {
|
|
183
|
+
get(name: string): {
|
|
184
|
+
readonly value: string;
|
|
185
|
+
} | undefined;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Framework-agnostic response shape for edge-cache helpers — compatible with
|
|
190
|
+
* NextResponse, Hono `c.res`, Cloudflare Workers Response, and any other
|
|
191
|
+
* Web-standard `Response` subclass. Helpers in this file only consume the
|
|
192
|
+
* standard `headers.set()` surface.
|
|
164
193
|
*/
|
|
165
|
-
|
|
194
|
+
type CacheResponse = Response;
|
|
166
195
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
196
|
+
* Framework-agnostic ISR-style fetch options. Extends Web-standard
|
|
197
|
+
* `RequestInit` with a `next` property that mirrors Next.js's ISR
|
|
198
|
+
* revalidation + cache-tag shape. Runtimes that don't honor the `next`
|
|
199
|
+
* field (anything outside Next.js) ignore it silently — the helper still
|
|
200
|
+
* works as a plain `fetch` wrapper.
|
|
169
201
|
*/
|
|
170
|
-
interface
|
|
202
|
+
interface CachedFetchRequestInit extends RequestInit {
|
|
171
203
|
next?: {
|
|
172
204
|
revalidate?: number | false;
|
|
173
205
|
tags?: string[];
|
|
@@ -254,9 +286,11 @@ interface EdgeCacheConfig {
|
|
|
254
286
|
/**
|
|
255
287
|
* Create edge cached fetch
|
|
256
288
|
*/
|
|
257
|
-
declare function createEdgeCachedFetch(config?: EdgeCacheConfig): <T>(url: string, options?:
|
|
289
|
+
declare function createEdgeCachedFetch(config?: EdgeCacheConfig): <T>(url: string, options?: CachedFetchRequestInit) => Promise<T>;
|
|
258
290
|
/**
|
|
259
|
-
*
|
|
291
|
+
* Memoizing cache wrapper for any async function. TTL-based eviction.
|
|
292
|
+
* Framework-agnostic — does NOT use Next.js's `unstable_cache`; this is
|
|
293
|
+
* a plain in-memory wrapper that works in any runtime.
|
|
260
294
|
*/
|
|
261
295
|
declare function createCachedFunction<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, options?: {
|
|
262
296
|
tags?: string[];
|
|
@@ -268,7 +302,7 @@ declare function createCachedFunction<TArgs extends unknown[], TReturn>(fn: (...
|
|
|
268
302
|
interface EdgeRateLimitConfig {
|
|
269
303
|
limit: number;
|
|
270
304
|
window: number;
|
|
271
|
-
key?: (request:
|
|
305
|
+
key?: (request: CacheRequest) => string;
|
|
272
306
|
}
|
|
273
307
|
declare class EdgeRateLimiter {
|
|
274
308
|
private config;
|
|
@@ -277,7 +311,7 @@ declare class EdgeRateLimiter {
|
|
|
277
311
|
/**
|
|
278
312
|
* Check rate limit
|
|
279
313
|
*/
|
|
280
|
-
check(request:
|
|
314
|
+
check(request: CacheRequest): {
|
|
281
315
|
allowed: boolean;
|
|
282
316
|
limit: number;
|
|
283
317
|
remaining: number;
|
|
@@ -298,11 +332,11 @@ interface GeoLocation {
|
|
|
298
332
|
latitude?: number;
|
|
299
333
|
longitude?: number;
|
|
300
334
|
}
|
|
301
|
-
declare function getGeoLocation(request:
|
|
335
|
+
declare function getGeoLocation(request: CacheRequest): GeoLocation | null;
|
|
302
336
|
/**
|
|
303
337
|
* Edge A/B testing with cache
|
|
304
338
|
*/
|
|
305
|
-
declare function getABTestVariant(request:
|
|
339
|
+
declare function getABTestVariant(request: CacheRequest, testName: string, variants: string[]): string;
|
|
306
340
|
/**
|
|
307
341
|
* Edge personalization cache
|
|
308
342
|
*/
|
|
@@ -313,25 +347,25 @@ interface PersonalizationConfig {
|
|
|
313
347
|
device?: 'mobile' | 'tablet' | 'desktop';
|
|
314
348
|
variant?: string;
|
|
315
349
|
}
|
|
316
|
-
declare function getPersonalizationConfig(request:
|
|
350
|
+
declare function getPersonalizationConfig(request: CacheRequest): PersonalizationConfig;
|
|
317
351
|
/**
|
|
318
352
|
* Edge cache headers helper
|
|
319
353
|
*/
|
|
320
|
-
declare function setEdgeCacheHeaders(response:
|
|
354
|
+
declare function setEdgeCacheHeaders(response: CacheResponse, config: {
|
|
321
355
|
maxAge?: number;
|
|
322
356
|
sMaxAge?: number;
|
|
323
357
|
staleWhileRevalidate?: number;
|
|
324
358
|
tags?: string[];
|
|
325
|
-
}):
|
|
359
|
+
}): CacheResponse;
|
|
326
360
|
/**
|
|
327
361
|
* Preload links for critical resources
|
|
328
362
|
*/
|
|
329
|
-
declare function addPreloadLinks(response:
|
|
363
|
+
declare function addPreloadLinks(response: CacheResponse, resources: Array<{
|
|
330
364
|
href: string;
|
|
331
365
|
as: string;
|
|
332
366
|
type?: string;
|
|
333
367
|
crossorigin?: boolean;
|
|
334
|
-
}>):
|
|
368
|
+
}>): CacheResponse;
|
|
335
369
|
/**
|
|
336
370
|
* Cache warming for ISR pages
|
|
337
371
|
*/
|
|
@@ -445,4 +479,4 @@ declare function configureCacheLogger(logger: CacheLogger): void;
|
|
|
445
479
|
*/
|
|
446
480
|
declare function getCacheLogger(): CacheLogger;
|
|
447
481
|
|
|
448
|
-
export { type CDNCacheConfig, type CDNPurgeConfig, CDN_CACHE_PRESETS, CacheInvalidationChannel, type CacheLogger, CacheStore, DEFAULT_CDN_CONFIG, type EdgeCacheConfig, type EdgeRateLimitConfig, EdgeRateLimiter, type GeoLocation, type ISRConfig, ISR_PRESETS, type InvalidationChannelOptions, type InvalidationEvent, type InvalidationEventType, type PersonalizationConfig, addPreloadLinks, configureCacheLogger, createCachedFunction, createEdgeCachedFetch, generateCacheControl, generateCacheTags, generateCloudflareConfig, generateStaticParams, generateVercelCacheConfig, getABTestVariant, getCacheLogger, getCacheTTL, getGeoLocation, getPersonalizationConfig, purgeAllCache, purgeCDNCache, purgeCacheByTag, revalidatePath, revalidatePaths, revalidateTag, revalidateTags, setEdgeCacheHeaders, shouldCacheResponse, warmCDNCache, warmISRCache };
|
|
482
|
+
export { type CDNCacheConfig, type CDNPurgeConfig, CDN_CACHE_PRESETS, CacheInvalidationChannel, type CacheLogger, type CacheRequest, type CacheResponse, CacheStore, DEFAULT_CDN_CONFIG, type EdgeCacheConfig, type EdgeRateLimitConfig, EdgeRateLimiter, type GeoLocation, type ISRConfig, ISR_PRESETS, type InvalidationChannelOptions, type InvalidationEvent, type InvalidationEventType, type PersonalizationConfig, addPreloadLinks, configureCacheLogger, createCachedFunction, createEdgeCachedFetch, generateCacheControl, generateCacheTags, generateCloudflareConfig, generateStaticParams, generateVercelCacheConfig, getABTestVariant, getCacheLogger, getCacheTTL, getGeoLocation, getPersonalizationConfig, purgeAllCache, purgeCDNCache, purgeCacheByTag, revalidatePath, revalidatePaths, revalidateTag, revalidateTags, setEdgeCacheHeaders, shouldCacheResponse, warmCDNCache, warmISRCache };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revealui/cache",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "CDN config, edge cache, ISR presets, and revalidation helpers
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Framework-agnostic CDN config, edge cache, ISR-style presets, and revalidation helpers. Compatible with NextRequest/NextResponse, Hono, and Cloudflare Workers via structural typing — no `next` peer dep.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@revealui/security": "0.
|
|
7
|
+
"@revealui/security": "0.4.0"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@electric-sql/pglite": "^0.4.
|
|
10
|
+
"@electric-sql/pglite": "^0.4.5",
|
|
11
11
|
"@types/node": "^25.6.0",
|
|
12
12
|
"tsup": "^8.5.1",
|
|
13
13
|
"typescript": "^6.0.3",
|
|
@@ -31,14 +31,6 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"main": "./dist/index.js",
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"next": "^14.0.0 || ^15.5.10 || ^16.2.3"
|
|
36
|
-
},
|
|
37
|
-
"peerDependenciesMeta": {
|
|
38
|
-
"next": {
|
|
39
|
-
"optional": true
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
34
|
"publishConfig": {
|
|
43
35
|
"access": "public",
|
|
44
36
|
"registry": "https://registry.npmjs.org"
|