@embrace-io/web-sdk
Version:
49 lines • 1.86 kB
TypeScript
import { DiagLogger } from "@opentelemetry/api";
//#region src/utils/NamespacedStorage/NamespacedStorage.d.ts
interface NamespacedStorageArgs {
storage: Storage;
namespace?: string;
diag?: DiagLogger;
}
/**
* `Storage`-shaped wrapper that isolates the SDK from storage errors and
* optionally namespaces keys with a prefix. Mutation methods return `true`
* on success and `false` when the call failed or writes have been disabled.
*
* Read failures (`getItem`, `key`, `length`) log at warn level and degrade
* to `null`/empty results.
*
* The first `setItem` failure flips a sticky `_writeDisabled` flag and
* emits one error; subsequent `setItem` calls silently return `false`
* without attempting the underlying write, so a one-time quota error or
* revoked permission does not keep throwing on every attempt. Reads,
* removes, and clears continue to work.
*
* An empty namespace skips the key prefix; the wrapper then exposes the
* underlying storage's full keyspace with only the safety layer applied.
*/
declare class NamespacedStorage {
private readonly _diag;
private readonly _keyPrefix;
private readonly _storage;
private _writeDisabled;
constructor({ namespace, storage, diag: diagParam }: NamespacedStorageArgs);
/**
* Logical keys when namespaced; raw underlying keys otherwise (may include
* foreign keys sharing the origin's storage). Best-effort: indices that
* throw are skipped, returns empty on bulk failure.
*/
keys(): string[];
get length(): number;
clear(): boolean;
getItem(key: string): string | null;
key(index: number): string | null;
removeItem(key: string): boolean;
setItem(key: string, value: string): boolean;
private _keyName;
private _safeRemove;
private _disableWrites;
}
//#endregion
export { NamespacedStorage };
//# sourceMappingURL=NamespacedStorage.d.ts.map