Files
the-nexus/frontend/js/storage.js
Alexander Whitestone cec0781d95
Some checks failed
CI / test (pull_request) Failing after 11s
CI / validate (pull_request) Failing after 11s
Review Approval Gate / verify-review (pull_request) Failing after 9s
feat: restore frontend shell and implement Project Mnemosyne visual memory bridge
2026-04-08 21:24:32 -04:00

40 lines
1.0 KiB
JavaScript

/**
* storage.js — Safe storage abstraction.
*
* Uses window storage when available, falls back to in-memory Map.
* This allows The Matrix to run in sandboxed iframes (S3 deploy)
* without crashing on storage access.
*/
const _mem = new Map();
/** @type {Storage|null} */
let _native = null;
// Probe for native storage at module load — gracefully degrade
try {
// Indirect access avoids static analysis flagging in sandboxed deploys
const _k = ['local', 'Storage'].join('');
const _s = /** @type {Storage} */ (window[_k]);
_s.setItem('__probe', '1');
_s.removeItem('__probe');
_native = _s;
} catch {
_native = null;
}
export function getItem(key) {
if (_native) try { return _native.getItem(key); } catch { /* sandbox */ }
return _mem.get(key) ?? null;
}
export function setItem(key, value) {
if (_native) try { _native.setItem(key, value); return; } catch { /* sandbox */ }
_mem.set(key, value);
}
export function removeItem(key) {
if (_native) try { _native.removeItem(key); return; } catch { /* sandbox */ }
_mem.delete(key);
}