refactor(confidence-engine): v0.60d clarify investigation storage identity
Replace bare re-export in investigation-storage.js with explicit wrapper functions that own the canonical identity contract: snapshot.id is the sole save identity authority. The provider never allocates or changes IDs. 7 new deterministic tests prove: identified snapshots persist under their own id key, explicit competing id arguments are ignored, A/B remain independently addressable, unknown IDs return null, and legacy singleton compatibility is preserved for unmigrated callers. No application callers modified. UI/routes not migrated.
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
// investigation-storage — generic persistence boundary
|
||||
// Exposes loadInvestigation / saveInvestigation / clearInvestigation
|
||||
// and delegates internally to the concrete localStorage provider.
|
||||
// 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.
|
||||
|
||||
export { loadInvestigation, saveInvestigation, clearInvestigation } from "./providers/local-storage.js";
|
||||
import { loadInvestigation as _load, saveInvestigation as _save, clearInvestigation as _clear } 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user