@teyik0/furin 0.1.0-alpha.11 → 0.1.0-alpha.13

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,3 +1,5 @@
1
+ import { type Cache, type RevalidateType } from "./route-cache.ts";
2
+ export type { Cache, CacheInvalidationResult, RevalidateType } from "./route-cache.ts";
1
3
  export interface ISRCacheEntry {
2
4
  generatedAt: number;
3
5
  html: string;
@@ -66,11 +68,23 @@ type CachePurger = (paths: string[]) => Promise<void>;
66
68
  export declare function setCachePurger(fn: CachePurger): void;
67
69
  /** @internal */
68
70
  export declare function callCachePurger(paths: string[]): void;
71
+ export type CacheInvalidator = Pick<Cache<unknown>, "invalidatePath" | "name">;
72
+ /**
73
+ * Register a cache invalidator that participates in `revalidatePath()`.
74
+ *
75
+ * Internal extension point for render caches that are not backed by the
76
+ * production HTML maps. The returned function unregisters the same instance.
77
+ *
78
+ * @internal
79
+ */
80
+ export declare function registerCacheInvalidator(invalidator: CacheInvalidator): () => void;
69
81
  /**
70
82
  * Programmatically invalidate the server-side cache for a given path.
71
83
  *
72
- * - `type: 'page'` (default): exact URL match.
73
- * - `type: 'layout'`: the path itself plus all nested children (prefix match).
84
+ * - `type: 'page'` — exact URL match.
85
+ * - `type: 'layout'` — the path itself plus all nested children (prefix match).
86
+ *
87
+ * The `type` parameter is required and must be provided by callers.
74
88
  *
75
89
  * Works for ISR and SSG routes. SSR routes are always fresh (no server-side
76
90
  * cache), but calling this still queues a client-side prefetch invalidation
@@ -86,11 +100,10 @@ export declare function callCachePurger(paths: string[]): void;
86
100
  * // In an API route or webhook handler:
87
101
  * import { revalidatePath } from "@teyik0/furin";
88
102
  *
89
- * revalidatePath("/blog/my-post"); // invalidate a single page
103
+ * revalidatePath("/blog/my-post", "page"); // invalidate a single page
90
104
  * revalidatePath("/blog", "layout"); // invalidate /blog + all children
91
105
  * ```
92
106
  */
93
- export declare function revalidatePath(path: string, type?: "page" | "layout"): boolean;
107
+ export declare function revalidatePath(path: string, type: RevalidateType): boolean;
94
108
  /** @internal — resets all module state between tests */
95
109
  export declare function __resetCacheState(): void;
96
- export {};
@@ -15,6 +15,7 @@
15
15
  * Two separate Maps for ISR and SSG keep the type pure and let the inspector
16
16
  * surface both modes uniformly without union juggling.
17
17
  */
18
+ import { type RevalidateType } from "./route-cache.ts";
18
19
  export interface DevLoaderCacheEntry {
19
20
  /**
20
21
  * Source files this entry depends on (absolute paths). Editing any of
@@ -45,6 +46,34 @@ export interface InvalidateOutcome {
45
46
  isr: number;
46
47
  ssg: number;
47
48
  }
49
+ /**
50
+ * Extracts the URL path part from a dev cache key.
51
+ *
52
+ * Cache keys have the format `${rootPath}:${urlPath}` where `urlPath` always
53
+ * starts with `/` (it's a route pattern). Filesystem `rootPath` may contain
54
+ * `:` on Windows (e.g. `C:/Users/...`), so we use `lastIndexOf(":/")` to find
55
+ * the boundary — the URL part is always the trailing `/...` segment.
56
+ *
57
+ * Returns `null` if the key doesn't match the expected shape (defensive — all
58
+ * keys produced by `renderDevISRWithLoaderCache` are well-formed, but a
59
+ * future caller could violate the invariant).
60
+ *
61
+ * @internal Exported for unit testing only.
62
+ */
63
+ export declare function urlPathFromCacheKey(key: string): string | null;
64
+ /**
65
+ * Drops every dev cache entry whose URL path matches `path` according to the
66
+ * same rules as `revalidatePath`:
67
+ *
68
+ * - `type: "page"` — exact match
69
+ * - `type: "layout"` — prefix match (the path itself + any descendant)
70
+ *
71
+ * Called from `cache.ts:revalidatePath` so a single API works for both prod
72
+ * (HTML caches `isrCache` / `ssgCache`) and dev (loader-data caches
73
+ * `devISRLoaderCache` / `devSSGLoaderCache`). Without this, dev users see
74
+ * stale loader data after mutations until the revalidate window expires.
75
+ */
76
+ export declare function invalidateDevLoaderCacheByPath(path: string, type: RevalidateType): InvalidateOutcome;
48
77
  /**
49
78
  * Drops every dev cache entry whose dependency chain includes `filePath`.
50
79
  * Safe to call for files that were never registered — returns an empty