// readme

nostr-idb

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.

Install

pnpm add nostr-idb

Usage

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();

API overview

Diagnostics

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…