A collection of helper methods for storing nostr events in an IndexedDB
https://hzrd149.github.io/nostr-idb/ β HEALTH ? 84 / Healthy
A collection of helper methods for storing nostr events in an IndexedDB
https://hzrd149.github.io/nostr-idb/ β// readme
A TypeScript library for storing and querying Nostr events locally in the browser with IndexedDB. It provides a NIP-DB-compatible API, in-memory caching, batched writes, live subscriptions, NIP-91 AND-tag filters, and app-defined event sidecar metadata.
pnpm add nostr-idb
JavaScript-style pseudocode (event comes from your app or a relay):
import { NostrIDB } from "nostr-idb";
const db = new NostrIDB();
await db.add(event);
const notes = await db.query({ kinds: [1], limit: 20 });
const savedEvent = await db.event(event.id);
// Stream stored and newly added notes; break when finished.
for await (const note of db.subscribe({ kinds: [1] })) {
display(note);
if (done) break;
}
await db.stop();
import { configureDiagnostics } from "nostr-idb";
configureDiagnostics({ debug: true, timing: true });
configureDiagnostics({ timing: false }); // Leave debug logging enabled
Both flags default to false and apply to all instances in this loaded copy of
the library, including standalone helpers. The same function and its
DiagnosticsOptions type are exported fromβ¦