/** * Snapshot Manager Service * * Manages database snapshots for save/restore functionality. * Creates compressed archives of database state for rollback capability. */ import type { DatabaseClient } from '../db/client.js'; /** * Snapshot metadata */ export interface SnapshotMetadata { /** Unique snapshot ID */ id: string; /** Snapshot name/title */ name: string; /** Snapshot description */ description?: string; /** When snapshot was created */ createdAt: string; /** Snapshot size in bytes (compressed) */ size: number; /** Number of context items in snapshot */ itemCount: number; /** k0ntext version that created this snapshot */ k0ntextVersion: string; /** Git commit SHA if available */ gitCommit?: string; /** Tags for categorization */ tags?: string[]; /** Whether snapshot is automatic (true) or manual (false) */ automatic: boolean; } /** * Snapshot create options */ export interface SnapshotCreateOptions { /** Snapshot name */ name: string; /** Snapshot description */ description?: string; /** Tags for categorization */ tags?: string[]; /** Create without writing to disk (dry run) */ dryRun?: boolean; /** Include git commit in metadata */ includeGitCommit?: boolean; /** Compress snapshot (default: true) */ compress?: boolean; /** Whether snapshot is automatic (default: false) */ automatic?: boolean; } /** * Snapshot restore options */ export interface SnapshotRestoreOptions { /** Path to snapshot file */ snapshotPath: string; /** Restore without confirmation */ force?: boolean; /** Create backup before restoring */ backupBeforeRestore?: boolean; /** Verify database after restore */ verify?: boolean; } /** * Snapshot list entry */ export interface SnapshotListEntry { /** Snapshot ID */ id: string; /** Snapshot name */ name: string; /** Snapshot description */ description?: string; /** When snapshot was created */ createdAt: string; /** Snapshot size in bytes */ size: number; /** Number of items */ itemCount: number; /** Tags */ tags?: string[]; /** Snapshot file path */ path: string; } /** * Snapshot diff result */ export interface SnapshotDiffResult { /** Snapshot A ID */ snapshotA: string; /** Snapshot B ID */ snapshotB: string; /** Items only in A */ onlyInA: string[]; /** Items only in B */ onlyInB: string[]; /** Items in both (with differences) */ differences: Array<{ id: string; type: string; name: string; changeType: 'added' | 'removed' | 'modified' | 'same'; }>; } /** * Snapshot Manager * * Manages database snapshots with compression and verification. */ export declare class SnapshotManager { private db; private projectRoot; private snapshotsDir; private k0ntextVersion; constructor(db: DatabaseClient, projectRoot: string | undefined, k0ntextVersion: string); /** * Ensure snapshots directory exists */ private ensureSnapshotsDir; /** * Generate snapshot ID */ private generateSnapshotId; /** * Get snapshot file path */ private getSnapshotPath; /** * Get compressed snapshot file path */ private getCompressedSnapshotPath; /** * Get git commit SHA if in git repository */ private getGitCommit; /** * Create a snapshot * * @param options - Snapshot creation options * @returns Snapshot metadata */ createSnapshot(options: SnapshotCreateOptions): Promise; /** * Export current database to file */ private exportDatabase; /** * Compress a file using gzip */ private compressFile; /** * List all snapshots * * @returns Array of snapshot entries */ listSnapshots(): Promise; /** * Restore a snapshot * * @param options - Snapshot restore options * @returns True if restored successfully */ restoreSnapshot(options: SnapshotRestoreOptions): Promise; /** * Create backup before restoring */ private createBackupBeforeRestore; /** * Decompress a gzip file */ private decompressFile; /** * Verify restored database */ private verifyRestore; /** * Delete a snapshot * * @param snapshotId - Snapshot ID to delete * @returns True if deleted successfully */ deleteSnapshot(snapshotId: string): Promise; /** * Diff two snapshots * * @param snapshotA - First snapshot ID or path * @param snapshotB - Second snapshot ID or path * @returns Diff result */ diffSnapshots(snapshotA: string, snapshotB: string): Promise; /** * Load a snapshot database for reading */ private loadSnapshotDatabase; /** * Check if file exists */ private fileExists; /** * Get all context items from database */ private getAllContextItems; /** * Check if two context items differ */ private itemsDiffer; /** * Save snapshot metadata */ private saveSnapshotMetadata; /** * Get snapshot metadata path */ private getMetadataPath; /** * Load snapshot metadata */ private loadSnapshotMetadata; /** * Delete snapshot metadata */ private deleteSnapshotMetadata; /** * Create automatic snapshot (before risky operations) * * @param operation - Operation being performed * @returns Snapshot metadata */ createAutoSnapshot(operation: string): Promise; /** * Get storage usage information * * @returns Storage statistics */ getStorageUsage(): Promise<{ totalSnapshots: number; totalSize: number; oldestSnapshot?: string; newestSnapshot?: string; }>; /** * Clean up old snapshots * * @param daysOld - Remove snapshots older than this many days * @param keepMinimum - Always keep at least this many snapshots * @returns Number of snapshots removed */ cleanupOldSnapshots(daysOld?: number, keepMinimum?: number): Promise; } //# sourceMappingURL=snapshot-manager.d.ts.map