/** * Embedded Store - SQLite-based Persistence Layer (CX-007) * * Provides reliable persistent storage using SQLite with: * - ACID transactions for data integrity * - Concurrent read access without corruption * - Automatic migration from JSON files * - Optional fallback to JSON if SQLite is unavailable * * Schema: * - key_value: Generic key-value storage with namespaces * - Designed for future expansion (sessions, patterns, skills tables) */ /** * Configuration for EmbeddedStore */ export interface EmbeddedStoreConfig { /** Path to the SQLite database file */ dbPath: string; /** Whether to use JSON fallback if SQLite is unavailable */ allowJsonFallback: boolean; /** Component name for logging */ componentName: string; /** Enable WAL mode for better concurrent read performance */ walMode: boolean; } /** * Default configuration */ export declare const DEFAULT_EMBEDDED_STORE_CONFIG: EmbeddedStoreConfig; /** * Statistics about store operations */ export interface EmbeddedStoreStats { /** Whether SQLite is being used (vs JSON fallback) */ usingSqlite: boolean; /** Total read operations */ reads: number; /** Total write operations */ writes: number; /** Failed operations */ failures: number; /** Last operation timestamp */ lastOperationTime: number | null; /** Database file size in bytes (SQLite only) */ dbSizeBytes: number | null; } /** * EmbeddedStore - SQLite-based persistent storage * * Provides namespaced key-value storage with: * - Atomic operations via SQLite transactions * - Automatic JSON fallback if SQLite is unavailable * - Migration from existing JSON files */ export declare class EmbeddedStore { private config; private db; private usingSqlite; private initialized; private stats; private jsonCache; private jsonDirty; private jsonSaveTimer; constructor(config?: Partial); /** * Check if better-sqlite3 is available * * This is a static method that can be called before instantiation * to determine if SQLite will be available. */ static isAvailable(): Promise; /** * Initialize the store (must be called before use) */ initialize(): Promise; /** * Load better-sqlite3 dynamically */ private loadBetterSqlite3; /** * Create the database schema */ private createSchema; /** * Initialize JSON fallback storage */ private initJsonFallback; /** * Save JSON fallback storage (debounced) */ private scheduleJsonSave; /** * Actually save JSON fallback to disk */ private saveJsonFallback; /** * Get a value from the store */ get(namespace: string, key: string): T | null; /** * Set a value in the store */ set(namespace: string, key: string, value: T): void; /** * Delete a value from the store */ delete(namespace: string, key: string): boolean; /** * Get all keys in a namespace */ keys(namespace: string): string[]; /** * Get all entries in a namespace */ getAll(namespace: string): Map; /** * Clear all entries in a namespace */ clear(namespace: string): void; /** * Check if a key exists */ has(namespace: string, key: string): boolean; /** * Count entries in a namespace */ count(namespace: string): number; /** * Run multiple operations in a transaction (SQLite only) * Falls back to sequential running for JSON storage */ transaction(fn: () => T): T; /** * Get store statistics */ getStats(): Promise; /** * Check if using SQLite */ isUsingSqlite(): boolean; /** * Get the database path */ getDbPath(): string; /** * Flush any pending writes (for graceful shutdown) */ flush(): Promise; /** * Close the store */ close(): Promise; /** * Migrate data from a JSON file to this store */ migrateFromJson(jsonPath: string, namespace: string, transform?: (data: T) => Map): Promise<{ migrated: number; skipped: number; }>; /** * Ensure the store is initialized */ private ensureInitialized; } /** * Get the global embedded store instance */ export declare function getEmbeddedStore(config?: Partial): EmbeddedStore; /** * Initialize the global store (call once at startup) */ export declare function initializeEmbeddedStore(config?: Partial): Promise; /** * Close the global store (call at shutdown) */ export declare function closeEmbeddedStore(): Promise; /** * Create a namespaced store wrapper for a specific component * * This provides a simpler API for components that only use one namespace. */ export declare class NamespacedStore { private store; private namespace; constructor(store: EmbeddedStore, namespace: string); get(key: string): T | null; set(key: string, value: T): void; delete(key: string): boolean; has(key: string): boolean; keys(): string[]; getAll(): Map; clear(): void; count(): number; } /** * Create a new EmbeddedStore instance * * Use this factory when you need a separate store instance * (e.g., for semantic infrastructure with its own database). * For shared access, use getEmbeddedStore() instead. */ export declare function createEmbeddedStore(config?: Partial): EmbeddedStore; //# sourceMappingURL=embedded-store.d.ts.map