The export record to persist (its id is the store key).
Resolves once the write and any eviction complete.
await putExport({
id: crypto.randomUUID(), createdAt: Date.now(), filename: "chempal-export.xlsx",
query: "acetone", scope: "filtered", rowCount: 12, sizeBytes: blob.size, blob,
});
export async function putExport(record: ExportRecord): Promise<void> {
try {
const db = await getDB();
const tx = db.transaction(IDB_STORE.EXPORTS, 'readwrite');
const store = tx.objectStore(IDB_STORE.EXPORTS);
await store.put(record);
// Oldest first, so we can evict from the front while keeping the newest.
const all = (await store.getAll()).sort((a, b) => a.createdAt - b.createdAt);
let totalBytes = all.reduce((sum, entry) => sum + entry.sizeBytes, 0);
let index = 0;
while (
index < all.length - 1 &&
(all.length - index > MAX_EXPORT_ENTRIES || totalBytes > MAX_EXPORT_CACHE_BYTES)
) {
const victim = all[index];
await store.delete(victim.id);
totalBytes -= victim.sizeBytes;
index++;
}
await tx.done;
emitExportsUpdated();
} catch (error) {
logger.error('Failed to put export in IndexedDB', { error });
}
}
Stores a generated
.xlsxexport, then evicts the oldest exports until the store is within both caps: at mostmaxExportEntriesrecords and at mostmaxExportsCacheBytestotal bytes. The most recent export is always kept, even if it alone exceeds the byte budget.