import { Result } from "../common/result"; import { DomainEvent } from "../domain/domain-event"; import { EventStore } from "./event-store"; export declare enum SnapshotStrategy { INTERVAL = "interval", EVENT_COUNT = "event_count", TIME_THRESHOLD = "time_threshold", MANUAL = "manual", STATE_CHANGE = "state_change" } export interface Snapshot { readonly snapshotId: string; readonly aggregateId: string; readonly aggregateType: string; readonly version: number; readonly data: Record; readonly metadata: SnapshotMetadata; readonly createdAt: Date; readonly active: boolean; } export interface SnapshotMetadata { readonly strategy: SnapshotStrategy; readonly eventsSinceLastSnapshot: number; readonly timeSinceLastSnapshot: number; readonly sizeInBytes: number; readonly compressionRatio?: number; readonly checksum: string; readonly customData?: Record; } export interface SnapshotConfiguration { readonly strategy: SnapshotStrategy; readonly eventCountThreshold?: number; readonly timeThreshold?: number; readonly interval?: number; readonly compress?: boolean; readonly compressionAlgorithm?: CompressionAlgorithm; readonly encrypt?: boolean; readonly encryptionAlgorithm?: EncryptionAlgorithm; readonly maxSnapshots?: number; readonly autoCleanup?: boolean; } export declare enum CompressionAlgorithm { GZIP = "gzip", DEFLATE = "deflate", BROTLI = "brotli", LZ4 = "lz4" } export declare enum EncryptionAlgorithm { AES256 = "aes256", AES128 = "aes128", CHACHA20 = "chacha20" } export interface SnapshotStore { saveSnapshot(snapshot: Snapshot): Promise>; getLatestSnapshot(aggregateId: string): Promise>; getSnapshot(snapshotId: string): Promise>; getSnapshots(aggregateId: string): Promise>; getSnapshotsInRange(aggregateId: string, fromVersion: number, toVersion: number): Promise>; deleteSnapshot(snapshotId: string): Promise>; deleteOldSnapshots(aggregateId: string, keepCount: number): Promise>; getSnapshotStatistics(): Promise>; } export interface SnapshotStatistics { readonly totalSnapshots: number; readonly totalSizeInBytes: number; readonly averageSizeInBytes: number; readonly snapshotsByStrategy: Record; readonly snapshotsByAggregateType: Record; readonly compressionStats: { compressedSnapshots: number; averageCompressionRatio: number; totalSpaceSaved: number; }; } export interface SnapshotManager { createSnapshot(aggregateId: string, aggregateType: string, aggregateState: Record, version: number, configuration?: SnapshotConfiguration): Promise>; restoreAggregate(aggregateId: string, targetVersion?: number): Promise; }>>; getBestSnapshot(aggregateId: string, targetVersion: number): Promise>; shouldCreateSnapshot(aggregateId: string, currentVersion: number, configuration: SnapshotConfiguration): Promise>; cleanupSnapshots(aggregateId: string, configuration: SnapshotConfiguration): Promise>; getSnapshotConfiguration(aggregateType: string): Promise>; setSnapshotConfiguration(aggregateType: string, configuration: SnapshotConfiguration): Promise>; } export declare class BaseSnapshotManager implements SnapshotManager { private snapshotStore; private eventStore; private serializer?; private compressor?; private encryptor?; private configurations; private lastSnapshotVersions; private lastSnapshotTimes; constructor(snapshotStore: SnapshotStore, eventStore: EventStore, serializer?: SnapshotSerializer, compressor?: SnapshotCompressor, encryptor?: SnapshotEncryptor); createSnapshot(aggregateId: string, aggregateType: string, aggregateState: Record, version: number, configuration?: SnapshotConfiguration): Promise>; restoreAggregate(aggregateId: string, targetVersion?: number): Promise; }>>; getBestSnapshot(aggregateId: string, targetVersion: number): Promise>; shouldCreateSnapshot(aggregateId: string, currentVersion: number, configuration: SnapshotConfiguration): Promise>; cleanupSnapshots(aggregateId: string, configuration: SnapshotConfiguration): Promise>; getSnapshotConfiguration(aggregateType: string): Promise>; setSnapshotConfiguration(aggregateType: string, configuration: SnapshotConfiguration): Promise>; private deserializeSnapshot; private applyEventToState; private calculateChecksum; private generateSnapshotId; private setDefaultConfigurations; } export interface SnapshotSerializer { serialize(data: Record): Promise>; deserialize(serializedData: string): Promise>>; } export interface SnapshotCompressor { compress(data: string, algorithm?: CompressionAlgorithm): Promise>; decompress(compressedData: string): Promise>; } export interface SnapshotEncryptor { encrypt(data: string, algorithm?: EncryptionAlgorithm): Promise>; decrypt(encryptedData: string): Promise>; } export declare class SnapshotConfigurationBuilder { private aggregateType; private configuration; constructor(aggregateType: string); strategy(strategy: SnapshotStrategy): SnapshotConfigurationBuilder; eventCountThreshold(threshold: number): SnapshotConfigurationBuilder; timeThreshold(threshold: number): SnapshotConfigurationBuilder; interval(interval: number): SnapshotConfigurationBuilder; compress(compress?: boolean): SnapshotConfigurationBuilder; compressionAlgorithm(algorithm: CompressionAlgorithm): SnapshotConfigurationBuilder; encrypt(encrypt?: boolean): SnapshotConfigurationBuilder; encryptionAlgorithm(algorithm: EncryptionAlgorithm): SnapshotConfigurationBuilder; maxSnapshots(maxSnapshots: number): SnapshotConfigurationBuilder; autoCleanup(autoCleanup?: boolean): SnapshotConfigurationBuilder; build(): SnapshotConfiguration; } export declare function createSnapshotConfiguration(aggregateType: string): SnapshotConfigurationBuilder;