@swell/apps-sdk 1.0.161 → 1.0.162

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.
@@ -1,8 +1,9 @@
1
1
  import type { KVNamespace } from '@cloudflare/workers-types';
2
- import { HtmlCache } from './html-cache';
2
+ import { HtmlCache, type CacheRules } from './html-cache';
3
3
  export type HtmlCacheEnv = {
4
4
  NAMESPACE?: KVNamespace;
5
5
  HTML_CACHE_EPOCH?: string;
6
6
  HTML_CACHE_BACKEND?: 'kv' | 'worker';
7
+ HTML_CACHE_RULES?: CacheRules;
7
8
  };
8
- export declare function getHtmlCache(env?: HtmlCacheEnv): HtmlCache | null;
9
+ export declare function getHtmlCache(env?: HtmlCacheEnv, cacheRules?: CacheRules): HtmlCache | null;
@@ -1,5 +1,33 @@
1
1
  import type { CacheBackend, CachedEntry } from './html-cache-backend';
2
- type DeploymentMode = 'live' | 'preview' | 'editor';
2
+ /**
3
+ * Configuration for path-specific cache behavior.
4
+ * Paths support wildcards:
5
+ * - * matches any characters except /
6
+ * - ** matches any characters including /
7
+ * Examples: '/account/*', '/api/**', '*.json'
8
+ * First matching rule wins.
9
+ */
10
+ export interface PathRule {
11
+ path: string;
12
+ ttl?: number;
13
+ swr?: number;
14
+ skip?: boolean;
15
+ }
16
+ export interface CacheRules {
17
+ defaults?: {
18
+ live?: {
19
+ ttl: number;
20
+ swr: number;
21
+ };
22
+ preview?: {
23
+ ttl: number;
24
+ swr: number;
25
+ };
26
+ };
27
+ pathRules?: PathRule[];
28
+ }
29
+ export declare const DEFAULT_CACHE_RULES: CacheRules;
30
+ type DeploymentMode = 'live' | 'preview';
3
31
  export interface CacheResult {
4
32
  found: boolean;
5
33
  stale?: boolean;
@@ -18,13 +46,14 @@ export interface CacheResult {
18
46
  export declare class HtmlCache {
19
47
  protected epoch: string;
20
48
  protected backend: CacheBackend;
21
- constructor(epoch: string, backend: CacheBackend);
49
+ protected cacheRules: CacheRules;
50
+ constructor(epoch: string, backend: CacheBackend, cacheRules?: CacheRules);
22
51
  get(request: Request): Promise<CacheResult | null>;
23
52
  getWithConditionals(request: Request): Promise<CacheResult | null>;
24
53
  put(request: Request, response: Response): Promise<void>;
25
54
  delete(requestOrKey: Request | string): Promise<void>;
26
- isReadCacheCandidate(request: Request): boolean;
27
- isWriteCacheCandidate(request: Request, response: Response): boolean;
55
+ canReadFromCache(request: Request): boolean;
56
+ canWriteToCache(request: Request, response: Response): boolean;
28
57
  createRevalidationRequest(request: Request): Request;
29
58
  protected buildClientResponse(entry: CachedEntry, isStale: boolean, age: number): Response;
30
59
  protected buildCacheKey(request: Request): string;
@@ -34,12 +63,19 @@ export declare class HtmlCache {
34
63
  protected sanitizeClientHeaders(headers: Headers): void;
35
64
  protected generateVersionHash(headers: Headers): string;
36
65
  protected extractSwellData(headers: Headers): Record<string, unknown>;
37
- protected isCacheable(request: Request): boolean;
66
+ protected isRequestCacheable(request: Request): boolean;
38
67
  protected isResponseCacheable(response: Response): boolean;
39
68
  protected getDeploymentMode(headers: Headers): DeploymentMode;
40
69
  protected getTTLForRequest(request: Request): number;
41
70
  protected getSWRForRequest(request: Request): number;
42
71
  protected getEntryAge(entry: CachedEntry): number;
72
+ /**
73
+ * Converts wildcard pattern to regex and tests against path.
74
+ * - * matches any characters except /
75
+ * - ** matches any characters including /
76
+ */
77
+ protected pathMatches(pattern: string, path: string): boolean;
78
+ protected normalizeHeaders(headers: Headers): Record<string, string>;
43
79
  protected normalizeSearchParams(searchParams: URLSearchParams): string;
44
80
  }
45
81
  export {};
@@ -1,4 +1,4 @@
1
- export type { CacheResult } from './html-cache';
2
- export { HtmlCache } from './html-cache';
1
+ export type { CacheResult, CacheRules, PathRule } from './html-cache';
2
+ export { HtmlCache, DEFAULT_CACHE_RULES } from './html-cache';
3
3
  export { getHtmlCache } from './html-cache-factory';
4
4
  export type { HtmlCacheEnv } from './html-cache-factory';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@swell/apps-sdk",
3
3
  "type": "module",
4
- "version": "1.0.161",
4
+ "version": "1.0.162",
5
5
  "description": "Swell SDK for building isomorphic apps.",
6
6
  "author": "Swell",
7
7
  "license": "MIT",