/** * Filesystem Storage Adapter * * File-based storage implementation for Node.js environments. * Each key is stored as a separate JSON file in a directory. * * **Node.js only** - throws an error if used in browser environments. * * @example * ```typescript * const adapter = new FileSystemStorageAdapter({ * baseDir: '.frontmcp/storage', * }); * * await adapter.connect(); * await adapter.set('user:123', JSON.stringify({ name: 'John' })); * const value = await adapter.get('user:123'); * await adapter.disconnect(); * ``` */ import { BaseStorageAdapter } from './base'; import type { SetOptions } from '../types'; /** * Options for FileSystemStorageAdapter. */ export interface FileSystemAdapterOptions { /** * Base directory for storage (absolute or relative to cwd). * Each key is stored as a file in this directory. */ baseDir: string; /** * File extension for stored files. * @default '.json' */ extension?: string; /** * Directory permissions (Unix mode). * @default 0o700 */ dirMode?: number; /** * File permissions (Unix mode). * @default 0o600 */ fileMode?: number; } /** * Filesystem-based storage adapter. * * Features: * - Persists data to individual JSON files * - Atomic writes using temp file + rename * - Restricted file permissions (0o600) * - TTL support with lazy expiration * * Limitations: * - No pub/sub support * - TTL not enforced with background sweeper * - Not suitable for high-throughput scenarios * * @example * ```typescript * import { FileSystemStorageAdapter } from '@frontmcp/utils'; * * const adapter = new FileSystemStorageAdapter({ * baseDir: '.frontmcp/keys', * extension: '.json', * }); * * await adapter.connect(); * * // Store data * await adapter.set('my-key', 'my-value'); * * // Retrieve data * const value = await adapter.get('my-key'); * * // List all keys * const keys = await adapter.keys(); * * await adapter.disconnect(); * ``` */ export declare class FileSystemStorageAdapter extends BaseStorageAdapter { protected readonly backendName = "filesystem"; private readonly baseDir; private readonly extension; private readonly dirMode; private readonly fileMode; constructor(options: FileSystemAdapterOptions); connect(): Promise; disconnect(): Promise; ping(): Promise; get(key: string): Promise; protected doSet(key: string, value: string, options?: SetOptions): Promise; delete(key: string): Promise; exists(key: string): Promise; expire(key: string, ttlSeconds: number): Promise; ttl(key: string): Promise; keys(pattern?: string): Promise; incr(key: string): Promise; decr(key: string): Promise; incrBy(key: string, amount: number): Promise; /** * Convert a storage key to a file path. * Sanitizes the key to be filesystem-safe. */ private keyToPath; /** * Convert a filename back to a storage key. */ private pathToKey; /** * Encode a key to be filesystem-safe. * Uses URL encoding to handle special characters. */ private encodeKey; /** * Decode a filesystem-safe key back to original. */ private decodeKey; /** * Read an entry from a file. */ private readEntry; /** * Check if an entry is expired. */ private isExpired; /** * Delete a file, returning true if it existed. */ private deleteFile; /** * Atomic write: write to temp file then rename. * This ensures we don't corrupt the file if write is interrupted. */ private atomicWrite; /** * Get suggestion message for pub/sub not supported error. */ protected getPubSubSuggestion(): string; }