55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
// investigation-storage — application-facing persistence boundary
|
|
// Owns the canonical identity contract: snapshot.id is the sole save identity.
|
|
// Delegates to the concrete localStorage provider internally.
|
|
|
|
import { loadInvestigation as _load, saveInvestigation as _save, clearInvestigation as _clear, listInvestigations as _list, restartInvestigation as _restart } from "./providers/local-storage.js";
|
|
|
|
/**
|
|
* Canonical save contract: snapshot.id is the sole identity authority.
|
|
* When snapshot carries an id — persist under that id key (identity-aware).
|
|
* When snapshot has no id — fall back to legacy singleton compatibility path.
|
|
*/
|
|
export function saveInvestigation(snapshot, explicitId) {
|
|
if (snapshot && typeof snapshot === "object" && snapshot.id != null) {
|
|
return _save(snapshot, snapshot.id);
|
|
}
|
|
// Legacy unidentified snapshot — singleton fallback for unmigrated callers
|
|
return _save(snapshot, explicitId);
|
|
}
|
|
|
|
/**
|
|
* Canonical load contract: select by durable id when supplied;
|
|
* fall back to legacy singleton path otherwise.
|
|
*/
|
|
export function loadInvestigation(id) {
|
|
return _load(id != null ? id : undefined);
|
|
}
|
|
|
|
/**
|
|
* Canonical clear contract: remove by identity-aware key when supplied;
|
|
* fall back to legacy singleton keys otherwise.
|
|
*/
|
|
export function clearInvestigation(id) {
|
|
return _clear(id ?? undefined);
|
|
}
|
|
|
|
/**
|
|
* Lists all durable-ID Investigation records as lightweight summaries.
|
|
* Excludes legacy singleton, sessionStorage state, unrelated storage, malformed entries.
|
|
*/
|
|
export function listInvestigations() {
|
|
return _list();
|
|
}
|
|
|
|
/**
|
|
* Semantic restart: reset reasoning/report state within the Investigation container.
|
|
*
|
|
* The Investigation is NOT deleted or replaced. Its durable `id` and `scenario` (container)
|
|
* are preserved. All reasoning-state fields are cleared so a new clean pass can begin.
|
|
*
|
|
* Missing/invalid id → silently no-op (does NOT fall back to legacy singleton).
|
|
*/
|
|
export function restartInvestigation(id) {
|
|
return _restart(id);
|
|
}
|