/** * S3 Snapshot Store - Full database snapshots for faster restore. * * Stores periodic full snapshots to S3 at: * /snapshots/_.json.gz * * Snapshots are triggered by: * - Time interval (e.g., every 5 minutes) * - Change volume threshold (e.g., every 1000 changes) */ import { type S3Client } from '@aws-sdk/client-s3'; import { type S3StorageConfig, type StoragePathResolver } from './s3-config.js'; import type { SyncManager, SnapshotChunk } from '@quereus/sync'; /** * Snapshot metadata stored alongside the snapshot. */ export interface SnapshotMetadata { /** Unique snapshot identifier */ snapshotId: string; /** Database ID this snapshot belongs to */ databaseId: string; /** Timestamp when snapshot was created */ timestamp: string; /** Total number of rows in the snapshot */ totalRows: number; /** Total number of tables in the snapshot */ totalTables: number; /** Compressed size in bytes */ compressedSizeBytes: number; /** HLC timestamp of latest change in snapshot */ hlcTimestamp?: string; } /** * Configuration for periodic snapshots. */ export interface SnapshotScheduleConfig { /** Interval in milliseconds between snapshots (default: 5 minutes) */ intervalMs: number; /** Change count threshold to trigger snapshot (default: 1000) */ changeThreshold: number; /** Maximum number of snapshots to retain per database (default: 5) */ maxRetained: number; } /** * Tracker for pending snapshot operations. */ interface DatabaseSnapshotState { lastSnapshotAt: number; changesSinceSnapshot: number; snapshotInProgress: boolean; } /** * S3 Snapshot Store for full database snapshots. */ export declare class S3SnapshotStore { private readonly client; private readonly config; private readonly scheduleConfig; private readonly resolveStoragePath; private readonly databaseStates; private checkTimer; constructor(client: S3Client, config: S3StorageConfig, scheduleConfig?: Partial, resolveStoragePath?: StoragePathResolver); /** * Start periodic snapshot checks. */ start(): void; /** * Stop periodic snapshot checks. */ stop(): void; /** * Record that changes have been applied to a database. */ recordChanges(databaseId: string, changeCount: number): void; /** * Check if a database needs a snapshot based on time or change volume. */ needsSnapshot(databaseId: string): boolean; /** * Check all tracked databases for scheduled snapshots. */ private checkScheduledSnapshots; /** * Create and store a full snapshot for a database. */ createSnapshot(databaseId: string, syncManager: SyncManager): Promise; /** * Type guard to check if a chunk is a column-versions chunk. */ private isColumnVersionsChunk; /** * Check if a snapshot exists for a database. */ hasSnapshot(databaseId: string): Promise; /** * Download and deserialize the latest snapshot for a database. * Returns null if no snapshots exist. */ downloadLatestSnapshot(databaseId: string): Promise<{ chunks: SnapshotChunk[]; metadata: { snapshotId: string; timestamp: string; }; } | null>; /** * Compress data using gzip. */ private compressData; /** * Decompress gzipped data. */ private decompressData; /** * Get databases that need snapshots (for external scheduling). */ getDatabasesNeedingSnapshot(): string[]; /** * Force a snapshot for a database (ignoring schedule). */ forceSnapshot(databaseId: string, syncManager: SyncManager): Promise; /** * Get snapshot state for a database. */ getState(databaseId: string): DatabaseSnapshotState | undefined; } /** * Create an S3 snapshot store from configuration. */ export declare function createS3SnapshotStore(client: S3Client, config: S3StorageConfig, scheduleConfig?: Partial, resolveStoragePath?: StoragePathResolver): S3SnapshotStore; export {}; //# sourceMappingURL=s3-snapshot-store.d.ts.map