shelving/firestore/clientmodule

FirestoreClientProvider for the full Firebase JS SDK (firebase/firestore). Use this in browser apps or any environment where you need offline persistence or realtime subscriptions.

When to use this

Choose shelving/firestore/client when your code runs in the browser and you want to receive live updates as documents change. If you do not need realtime and want a smaller bundle, use shelving/firestore/lite instead. For server-side Node.js code, use shelving/firestore/server.

Install

sh
npm install firebase shelving

Setup

Initialize a Firebase app, get a Firestore instance, and pass it to the provider:

ts
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { FirestoreClientProvider } from "shelving/firestore/client";

const app = initializeApp({
  apiKey: "...",
  authDomain: "...",
  projectId: "...",
});

const db = getFirestore(app);
const provider = new FirestoreClientProvider(db);

The provider takes a single Firestore argument. It delegates all app initialization and authentication to the Firebase SDK — configure those through the Firebase SDK directly.

Realtime subscriptions

DBProvider.getItemSequence() and DBProvider.getQuerySequence() return AsyncIterable backed by Firestore's onSnapshot listener. Each new value from Firestore resolves the next iteration:

ts
for await (const post of provider.getItemSequence(POSTS, id)) {
  console.log(post); // emits whenever the document changes
}

The subscription opens lazily on first for await iteration and closes when the iterator is garbage-collected or the loop exits.

Bulk query mutations

DBProvider.setQuery(), DBProvider.updateQuery(), and DBProvider.deleteQuery() fetch matching documents with getDocs and then issue parallel Promise.all writes. For large result sets, prefer shelving/firestore/server which uses BulkWriter.

Classes

Go

FirestoreClientProviderclass

Cloud Firestore database provider backed by the full Firebase JS SDK, implementing the DBProvider abstraction.

new FirestoreClientProvider<I, T>(firestore: Firestore)