import type { Pool } from 'pg'; import type { RemediationResult } from '../../src/remediation/remediation-engine'; export interface RemediationStore { read(scopeKey: string): Promise; save(scopeKey: string, result: RemediationResult): Promise; } export class MemoryRemediationStore implements RemediationStore { private readonly results = new Map(); async read(key: string) { const result = this.results.get(key); return result ? structuredClone(result) : undefined; } async save(key: string, result: RemediationResult) { this.results.set(key, structuredClone(result)); } } /** All writes belong to the separate engine schema. No Core table is read or written. */ export class PostgresRemediationStore implements RemediationStore { constructor(private readonly pool: Pool) {} async read(key: string): Promise { const response = await this.pool.query<{ data: RemediationResult }>( 'SELECT data FROM assessor_remediation.package_snapshots WHERE scope_key = $1', [key]); return response.rows[0]?.data; } async save(key: string, result: RemediationResult): Promise { await this.pool.query('INSERT INTO assessor_remediation.package_snapshots (scope_key, data) VALUES ($1, $2::jsonb) ON CONFLICT (scope_key) DO NOTHING', [key, JSON.stringify(result)]); } }