import type { StoredMessage, StoredSignature, StoredKey, } from '../types/message.js'; import type { DatabaseStorageService } from './database.js'; import type { StorageServiceInterface } from './storageInterface.js'; /** * Adapter to make DatabaseStorageService compatible with StorageServiceInterface. * This allows existing code to work with the new database implementation. */ export class StorageAdapter implements StorageServiceInterface { constructor(private db: DatabaseStorageService) {} hasSeenHash(hash: string): boolean { return this.db.hasSeenHash(hash); } markHashSeen(hash: string): void { this.db.markHashSeen(hash); } storeMessage(msg: StoredMessage): void { this.db.storeMessage(msg); } getMessage(hash: string): StoredMessage | undefined { return this.db.getMessage(hash); } getMessages( start: number, end: number, serviceUuid?: string, ): StoredMessage[] { return this.db.getMessages(start, end, serviceUuid); } storeSignature(sig: StoredSignature): void { this.db.storeSignature(sig); } getSignatures(hash: string): StoredSignature[] { return this.db.getSignatures(hash); } storeKey(key: StoredKey): void { this.db.storeKey(key); } getKeys(hash: string): StoredKey[] { return this.db.getKeys(hash); } getKeysInWindow(start: number, end: number): StoredKey[] { return this.db.getKeysInWindow(start, end); } getSeenHashCount(): number { return this.db.getSeenHashCount(); } getSeenHashes(): string[] { return this.db.getSeenHashes(); } getSignatureCount(): number { return this.db.getSignatureCount(); } getKeyCount(): number { return this.db.getKeyCount(); } /** * No-op for compatibility (database handles persistence automatically). */ async saveToDisk(): Promise { // Database is already persistent, no need to save } /** * No-op for compatibility. */ async initialize(): Promise { // Already initialized in database service } }