Files
2026-05-27 23:47:53 +01:00

8.0 KiB

@suaveplan/storage-browser-indexeddb - Browser IndexedDB AbstractStorage adapter for @suaveplan/storage: structured-clone key-value storage via globalThis.indexedDB, AbortSignal everywhere, strict key sanitisation, TTL via expiresAt index, metadata storage, partial reads, DOMException → typed IndexedDbError mapping, full OTel surface.

Browser-tier AbstractStorage adapter backed by the W3C IndexedDB API (globalThis.indexedDB). Provides persistent, origin-scoped key-value storage for browser consumers — vault snapshots, drive chunk caches, in-app i18n catalogues, password manager records — with full AbstractStorage conformance, TTL via an expiresAt index, AbortSignal threading, strict key sanitisation, Zod-validated options, structured IndexedDbError boundary, DOMException → typed-code mapping, and a complete OpenTelemetry surface.

Documentation tree

Install

bun add @suaveplan/storage-browser-indexeddb

Quick start

import {
 createIndexedDbStorage,
 isIndexedDbAvailable,
} from "@suaveplan/storage-browser-indexeddb";

if (!isIndexedDbAvailable()) {
 throw new Error("This browser does not support IndexedDB");
}

const storage = createIndexedDbStorage({ dbName: "myapp" });
await storage.set("user/42", new TextEncoder().encode("hello"));
const back = await storage.get("user/42");

Factory integration

import { registerIndexedDbProvider } from "@suaveplan/storage-browser-indexeddb/registry";
import { createStorage } from "@suaveplan/storage/factory";

registerIndexedDbProvider();
const storage = createStorage({ type: "indexeddb", config: { dbName: "myapp" } });

The package does NOT self-register at module-evaluation time — call registerIndexedDbProvider() explicitly so sideEffects: false bundlers can tree-shake the factory path when not used.

Capabilities

Capability Value Notes
partialReads true Via Uint8Array.subarray(...) on the in-memory copy of the stored row.
partialWrites false IndexedDB has no random-access put; setPartial uses the AbstractStorage read-modify-write fallback.
nativeStreams false IndexedDB has no native streaming surface; createReadStream / createWriteStream use the buffered fallback.
atomicWrites true Each objectStore.put is a single-transaction commit.
contentAddressable false Keys are caller-supplied strings.

Modules

License

MIT.