/** * Corpus metadata store. * * node:sqlite is used rather than better-sqlite3 or DuckDB: it is built into Node 24, so there is * no native build step and no lockfile that can stop working in two years. The corpus is a few * hundred thousand rows of small metadata, which is well within its comfortable range. * * node:sqlite arrived in Node 22.5, but the extraction library itself runs on Node 20. Loading it * lazily keeps that promise: requiring the package never touches this module, so a Node 20 host can * use analyze() and extract() while only the corpus tooling needs the newer runtime. * * The store holds derived metadata only. Raw messages stay on disk, referenced by path, and are * never copied. See docs/threat-model.md for what the derived data can still reveal. */ import { type MessageRecord } from './analyze'; export type FileStatus = 'ok' | 'failed' | 'skipped' | 'oversize' | 'timeout'; export interface FileRecord { path: string; size: number; mtime: number; sha256: string | null; status: FileStatus; errorCode: string | null; errorDetail: string | null; durationMs: number | null; } export interface ScanRow { file: FileRecord; message: MessageRecord | null; } export interface RunOptions { root: string; [key: string]: unknown; } /** * Lifecycle of a scan run. * * `running` also covers a process that died without ever updating its row, which is why release * gates must select on `completed` rather than on the newest row. An interrupted run's partial * output is not a baseline, and reading it as one silently approves a release against a fraction of * the corpus. */ export type RunStatus = 'running' | 'completed' | 'failed' | 'aborted'; export declare class CorpusStore { private readonly db; private readonly insertFileStmt; private readonly insertMessageStmt; private readonly seenStmt; /** Per database salt for privacy preserving hashes. Created on first open. */ readonly salt: string; constructor(file: string); private migrate; private readOrCreateSalt; getMeta(key: string): string | null; setMeta(key: string, value: string): void; startRun(options: RunOptions): number; finishRun(runId: number, status: RunStatus, counts: { seen: number; processed: number; failed: number; skipped: number; }): void; /** * The most recent run that finished cleanly. * * Every consumer that reads corpus results goes through this rather than taking the newest row. * A run that crashed, was interrupted, or is still going has partial output, and treating it as * a baseline approves a release against whatever fraction of the corpus happened to finish. */ latestCompletedRun(): { id: number; root: string; } | null; /** * True when this exact file has already been processed by the current processing version. * Resume relies on size and mtime rather than a hash, because hashing every file would mean * reading the whole corpus again just to decide what to skip. */ isProcessed(relPath: string, size: number, mtime: number): boolean; /** * Write a batch inside a single transaction, retrying briefly on lock contention. * * All or nothing on purpose. A half written batch would leave files recorded as processed whose * message rows never landed, and a resumed run would skip them, so the corpus would be quietly * short of exactly the messages that were in flight when the write failed. */ writeBatch(rows: readonly ScanRow[], runId: number): void; private writeBatchOnce; /** Execute a statement. Returns the driver result, including lastInsertRowid. */ run(sql: string, ...params: (string | number | null)[]): import("node:sqlite").StatementResultingChanges; /** Run a function inside a transaction, rolling back on any throw. */ transaction(fn: () => void): void; /** Run an arbitrary read only query. Used by the stats and sampling commands. */ query>(sql: string, ...params: (string | number | null)[]): T[]; queryOne>(sql: string, ...params: (string | number | null)[]): T | null; close(): void; } //# sourceMappingURL=store.d.ts.map