npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gitlive/firestore-node-persistence

v0.1.0

Published

Firestore persistent local cache for Node.js: a minimal SQLite-backed IndexedDB adapter that enables persistentLocalCache() in the stock firebase SDK at runtime.

Downloads

68

Readme

@gitlive/firestore-node-persistence

Persistent local cache for Cloud Firestore on Node.js, as a runtime add-on for the stock firebase / @firebase/firestore npm packages — no fork, no patching.

The Firestore SDK's persistence layer is built entirely on IndexedDB and its only environment gate is the presence of a working indexedDB global. This package provides a minimal IndexedDB implementation backed by the built-in node:sqlite module (Node.js ≥ 22.5), covering exactly the API surface the SDK's SimpleDb wrapper uses, and installs it as globalThis.indexedDB / globalThis.IDBKeyRange. The SDK's entire persistence stack (schema v18, migrations, LRU garbage collection, client-side indexing) then runs unchanged.

Usage

import { registerFirestoreNodePersistence } from '@gitlive/firestore-node-persistence';

// Must run before Firestore is initialized.
registerFirestoreNodePersistence({ directory: './.firestore' }); // directory is optional

import { initializeApp } from 'firebase/app';
import { initializeFirestore, persistentLocalCache } from 'firebase/firestore';

const app = initializeApp({ /* ... */ });
const db = initializeFirestore(app, {
  localCache: persistentLocalCache()
});

Documents written offline are durably staged and query results are cached in SQLite files under directory (default: .firestore in the working directory), one file per Firestore database, and survive process restarts.

registerFirestoreNodePersistence() returns false (and installs nothing) when node:sqlite is unavailable (Node < 22.5); Firestore then falls back to its memory cache exactly as it does today.

Implementation notes

  • Key encoding: IndexedDB keys (numbers, strings, binary, nested arrays) are encoded to byte strings whose memcmp order equals the IndexedDB key ordering — including UTF-16 code-unit string comparison — so SQLite BLOB primary keys reproduce IndexedDB semantics exactly. Validated by property tests against a reference implementation of the spec's comparison algorithm.
  • Values are stored with the V8 structured serializer (node:v8), the same structured-clone semantics (and on-disk format family) Chromium's own IndexedDB uses.
  • Transactions map to SQLite transactions with FIFO scheduling and IndexedDB-style auto-commit; cursors are incremental B-tree seeks, so iterate-and-mutate patterns and large scans behave correctly with bounded memory.
  • Validated against the SDK's own persistence test suites (SimpleDb, LocalStore, IndexedDbPersistence incl. primary-lease arbitration, and the spec test matrix) as well as an offline write → restart → read-from-cache end-to-end test against the published firebase package.

Caveats

  • Single tab manager only: persistentSingleTabManager (the default). Multi-tab synchronization requires LocalStorage and does not apply to Node.
  • One process per cache directory. The stock SDK has a bug on LocalStorage-less platforms (isClientZombied treats every client as zombied), so a second process pointed at the same directory would steal the primary lease instead of failing cleanly. Fixed upstream in firebase-js-sdk PR; until that lands, share nothing.
  • The SDK logs a spurious LocalStorage is unavailable warning at startup on Node; it is harmless (that concern is about browser tab refreshes).
  • Data written by a newer Node.js major version may not be readable by an older one (V8 serializer forward-compatibility); for a cache this surfaces as a clean failure and rebuild, not corruption.
  • The globals are only installed if no indexedDB global already exists (refuses to fight other polyfills such as fake-indexeddb).

License

Apache-2.0. Portions derived from firebase-js-sdk (Apache-2.0).