/** * @file esm-cache.ts * @description Cache manager for downloaded ESM bundles. * * Supports two modes: * - **Node.js**: File-based cache with `.mjs`/`.cjs` bundles and metadata JSON * - **Browser**: In-memory cache (no file system access) * * The mode is auto-detected. In-memory cache is always used as a fast first-level cache, * with disk persistence as a second level in Node.js environments. */ /** * Metadata stored alongside each cached ESM bundle. */ export interface EsmCacheEntry { /** Full package URL used to fetch */ packageUrl: string; /** Full package name (e.g., '@acme/mcp-tools') */ packageName: string; /** Concrete resolved version */ resolvedVersion: string; /** Timestamp when cached */ cachedAt: number; /** Path to the cached bundle file (.mjs for ESM, .cjs for bridged CJS; empty in browser) */ bundlePath: string; /** HTTP ETag for conditional requests */ etag?: string; /** In-memory bundle content (used in browser mode and as fast cache in Node.js) */ bundleContent?: string; } /** * Options for the ESM cache manager. */ export interface EsmCacheOptions { /** * Root cache directory for disk persistence. Environment-aware default: * - **Browser**: empty string (disk cache disabled, in-memory only) * - **Node.js server** (project has `node_modules/`): `{cwd}/node_modules/.cache/frontmcp-esm/` * - **CLI binary** (no `node_modules/`): `~/.frontmcp/esm-cache/` */ cacheDir?: string; /** Maximum age of cached entries in milliseconds. Defaults to 24 hours. */ maxAgeMs?: number; /** * Maximum number of bundles kept in the in-memory cache. When exceeded, the * oldest entries are evicted (FIFO). Bounds heap growth on a long-running * server that loads/reloads many package versions over its lifetime — TTL * alone doesn't cap the count within the age window. Defaults to 100. */ maxEntries?: number; } /** * Cache manager for ESM bundles. * * **Node.js mode**: File-based disk cache with in-memory first-level cache. * ``` * {cacheDir}/{hash}/ * bundle.mjs|cjs - Native ESM or bridged CJS bundle code * meta.json - Cache metadata (version, timestamp, etag) * ``` * * **Browser mode**: In-memory Map only (no file system). */ export declare class EsmCacheManager { private readonly cacheDir; private readonly maxAgeMs; private readonly maxEntries; private readonly memoryStore; constructor(options?: EsmCacheOptions); /** Evict oldest in-memory entries (FIFO via Map insertion order) past the cap. */ private evictIfNeeded; /** * Get a cached ESM bundle entry if it exists and is not expired. */ get(packageName: string, version: string): Promise; /** * Store an ESM bundle in the cache. */ put(packageName: string, version: string, bundleContent: string, packageUrl: string, etag?: string): Promise; /** * Invalidate all cached versions for a package. */ invalidate(packageName: string): Promise; /** * Remove expired cache entries. */ cleanup(maxAgeMs?: number): Promise; /** * Read the cached bundle content from a cache entry. */ readBundle(entry: EsmCacheEntry): Promise; /** * Get the cache directory for a specific package+version combination. */ private getEntryDir; } //# sourceMappingURL=esm-cache.d.ts.map