FirestoreProviderclass
new FirestoreProvider<I, T>(options: FirestoreProviderOptions)
| Param | Type | |
|---|---|---|
options | FirestoreProviderOptions | Options for FirestoreProvider. required |
.project | string | Google Cloud project id. required readonly |
.database | string | Firestore database id. Defaults to "(default)" readonly |
.host | string | Base URL of the Firestore API, e.g. "http://127.0.0.1:8080" for the Firestore emulator. Defaults to "https://firestore.googleapis.com" readonly |
.token | (() => stringPromiseLike<string>) | Return an OAuth2 access token for each request, e.g. from google-auth-library or a hand-rolled service-account JWT exchange.- Omit to send no Authorization header (correct for the Firestore emulator). readonly |
.fetch | ((input: string, init: RequestInit) => Promise<Response>) | Fetch implementation to use for requests (defaults to the global fetch). readonly |
| Return | |
|---|---|
FirestoreProvider<I, T> | Cloud Firestore database provider that talks to the Firestore REST API using fetch, implementing the DBProvider abstraction. |
Cloud Firestore database provider that talks to the Firestore REST API using fetch, implementing the DBProvider abstraction.
- Zero dependencies, so it runs anywhere
fetchruns: Node.js, Bun, Cloudflare Workers, Deno, and other edge runtimes. - Supports transactions via
transact()— reads see a consistent snapshot, writes buffer and commit atomically, and contended commits retry. - Does not support realtime subscriptions:
getItemSequence()andgetQuerySequence()throwUnsupportedError(the:listenendpoint requires a streaming session the plain REST API cannot provide). - Data read from Firestore is unvalidated — wrap in
ValidationDBProviderto guarantee types.
Examples
const provider = new FirestoreProvider({ project: "my-project", token: () => auth.getAccessToken() });
const id = await provider.addItem(users, { name: "Dave" });