nusm axolotlnusm
Storage Adapters

IndexedDB

Persist asynchronous browser state in a dedicated database and object store.

import { createIndexDbAdapter, createNusmStore } from "nusm";

const activity = createNusmStore(
  { entries: [] as Array<{ id: string; message: string }> },
  {
    adapter: createIndexDbAdapter({
      dbName: "acme-app",
      storeName: "state",
    }),
    persist: { strategy: "entire" },
    storeId: "activity",
  },
);

await activity.ready;

Options

interface IndexDbAdapterOptions {
  dbName?: string;
  storeName?: string;
  version?: number;
  serialize?: (value: unknown) => string;
  deserialize?: (raw: string) => unknown;
  pacer?: NusmPacerConfig;
}
OptionDefaultPurpose
dbName"nusm"IndexedDB database name
storeName"nusm"Object store used for persistence units
versionReserved; runtime currently opens version 1Public option retained for compatibility
serializesuperjson.stringifyEncode values before storing them
deserializesuperjson.parseDecode stored strings
pacertrailing, 100 msControl asynchronous write scheduling

Behavior

The adapter creates its object store during the database upgrade event when needed. Reads, writes, removes, key enumeration, and clear operations run through IndexedDB transactions.

Physical keys follow the standard nusm layout:

nusm:<storeId>:entire
nusm:<storeId>:slice:<sliceKey>

When to choose it

IndexedDB is a good fit when state is too substantial for synchronous Web Storage, writes are naturally asynchronous, or you want a dedicated object store boundary.

Configure Authenticated synchronization with an HMAC source to share IndexedDB-backed state. Remote values pass the receiving store validator before being written into its IndexedDB store.

Browser boundary

createIndexDbAdapter requires the global indexedDB API and throws outside a compatible browser environment. Construct it on the client. Tests can provide an IndexedDB-compatible global such as fake-indexeddb before adapter creation.

On this page