GCP.Firestore reference
Database
Section titled “Database”Source:
src/GCP/Firestore/Database.ts
A Cloud Firestore database.
Firestore databases have no labels field and Alchemy writes no data
into them: read reports a database it finds without prior state as
unowned (adopt it with --adopt). Changing databaseId, location, databaseEdition, CMEK, or
Realtime Updates mode replaces the database.
Create, update, and delete are long-running operations — provisioning a named database typically takes tens of seconds.
Database: Creating a Database
Section titled “Database: Creating a Database”Generated name
const database = yield* GCP.Firestore.Database("App", {});Explicit id, location, and concurrency
const database = yield* GCP.Firestore.Database("App", { databaseId: "app-data", location: "us-central1", type: "FIRESTORE_NATIVE", concurrencyMode: "OPTIMISTIC",});Database: Reading and Writing Documents
Section titled “Database: Reading and Writing Documents”const patchDocument = yield* GCP.Firestore.PatchDocument(database);yield* patchDocument({ documentPath: "users/alice", body: { fields: { name: { stringValue: "Alice" } } },});const getDocument = yield* GCP.Firestore.GetDocument(database);const doc = yield* getDocument({ documentPath: "users/alice" });DatabasesBackupSchedule
Section titled “DatabasesBackupSchedule”Source:
src/GCP/Firestore/DatabasesBackupSchedule.ts
A scheduled backup for a Cloud Firestore database.
At most one daily and one weekly schedule can exist per database.
The schedule id is assigned by the API. Retention updates in place;
switching daily vs weekly or moving to another database replaces the
schedule. Backup schedules have no labels field: read reports a
schedule it finds without prior state as unowned (adopt it with
--adopt).
DatabasesBackupSchedule: Creating a Backup Schedule
Section titled “DatabasesBackupSchedule: Creating a Backup Schedule”Daily backups retained for 7 days
const database = yield* GCP.Firestore.Database("App", { location: "us-central1",});const schedule = yield* GCP.Firestore.DatabasesBackupSchedule("Nightly", { database: database.name, retention: "604800s", dailyRecurrence: true,});Weekly backups
const schedule = yield* GCP.Firestore.DatabasesBackupSchedule("Weekly", { database: database.name, retention: "1209600s", weeklyRecurrence: { day: "SUNDAY" },});DatabasesCollectionGroupsIndex
Section titled “DatabasesCollectionGroupsIndex”Source:
src/GCP/Firestore/DatabasesCollectionGroupsIndex.ts
A composite Firestore index on a collection group.
The index id is assigned by the API. Indexes are immutable — changing
fields, scope, density, uniqueness, or the parent collection replaces
the index. Indexes have no labels field: read reports an index it
finds without prior state as unowned (adopt it with --adopt).
DatabasesCollectionGroupsIndex: Creating an Index
Section titled “DatabasesCollectionGroupsIndex: Creating an Index”const database = yield* GCP.Firestore.Database("App", { location: "us-central1",});const index = yield* GCP.Firestore.DatabasesCollectionGroupsIndex( "UsersByName", { database: database.name, collectionGroup: "users", queryScope: "COLLECTION", fields: [ { fieldPath: "name", order: "ASCENDING" }, { fieldPath: "created", order: "DESCENDING" }, ], },);DatabasesUserCred
Section titled “DatabasesUserCred”Source:
src/GCP/Firestore/DatabasesUserCred.ts
User credentials for a Cloud Firestore database with MongoDB compatibility.
User creds are owned by the parent database and require Enterprise
edition with the MongoDB-compatible API enabled. The plaintext
password is returned only on create (and password reset); later
reads keep the last known value from state. Enable/disable updates
in place. Changing userCredsId or database replaces the creds.
User creds have no labels field: read reports creds it finds without
prior state as unowned (adopt them with --adopt).
DatabasesUserCred: Creating User Creds
Section titled “DatabasesUserCred: Creating User Creds”Enabled creds on an Enterprise database
const database = yield* GCP.Firestore.Database("App", { location: "us-central1", databaseEdition: "ENTERPRISE", mongodbCompatibleDataAccessMode: "DATA_ACCESS_MODE_ENABLED",});const creds = yield* GCP.Firestore.DatabasesUserCred("AppUser", { database: database.name,});Disabled creds
const creds = yield* GCP.Firestore.DatabasesUserCred("AppUser", { database: database.name, disabled: true,});DeleteDocument
Section titled “DeleteDocument”Source:
src/GCP/Firestore/DeleteDocument.ts
Runtime binding for Firestore documents.delete.
Bind this operation to a Database in a Function/Action init
phase. Provide DeleteDocumentHttp.
DeleteDocument: Deleting Documents
Section titled “DeleteDocument: Deleting Documents”const deleteDocument = yield* GCP.Firestore.DeleteDocument(database);yield* deleteDocument({ documentPath: "users/alice" });DeleteDocumentHttp
Section titled “DeleteDocumentHttp”Source:
src/GCP/Firestore/DeleteDocumentHttp.tsKind: Layer · Provides:GCP.Firestore.DeleteDocument
HTTP implementation of DeleteDocument.
Document
Section titled “Document”Source:
src/GCP/Firestore/Document.ts
A Cloud Firestore document.
Documents have no labels field and Alchemy writes nothing but the given
fields: read reports a document it finds without prior state as
unowned (adopt it with --adopt). Changing
database, collectionId, parentPath, or documentId replaces
the document. User fields update in place via documents.patch.
Runtime get/patch/delete of arbitrary documents still goes through
GetDocument / PatchDocument / DeleteDocument.
Document: Creating a Document
Section titled “Document: Creating a Document”Generated id in _alchemy
const doc = yield* GCP.Firestore.Document("Flag", { fields: { env: { stringValue: "test" } },});Named document
const doc = yield* GCP.Firestore.Document("Alice", { database: "(default)", collectionId: "users", documentId: "alice", fields: { name: { stringValue: "Alice" } },});GetDocument
Section titled “GetDocument”Source:
src/GCP/Firestore/GetDocument.ts
Runtime binding for Firestore documents.get.
Bind this operation to a Database in a Function/Action init
phase. Provide GetDocumentHttp.
GetDocument: Reading Documents
Section titled “GetDocument: Reading Documents”const getDocument = yield* GCP.Firestore.GetDocument(database);const doc = yield* getDocument({ documentPath: "users/alice" });GetDocumentHttp
Section titled “GetDocumentHttp”Source:
src/GCP/Firestore/GetDocumentHttp.tsKind: Layer · Provides:GCP.Firestore.GetDocument
HTTP implementation of GetDocument.
PatchDocument
Section titled “PatchDocument”Source:
src/GCP/Firestore/PatchDocument.ts
Runtime binding for Firestore documents.patch.
Bind this operation to a Database in a Function/Action init
phase. Provide PatchDocumentHttp. Patch upserts unless a
current-document precondition is set.
PatchDocument: Writing Documents
Section titled “PatchDocument: Writing Documents”const patchDocument = yield* GCP.Firestore.PatchDocument(database);yield* patchDocument({ documentPath: "users/alice", body: { fields: { name: { stringValue: "Alice" } } },});PatchDocumentHttp
Section titled “PatchDocumentHttp”Source:
src/GCP/Firestore/PatchDocumentHttp.tsKind: Layer · Provides:GCP.Firestore.PatchDocument
HTTP implementation of PatchDocument.
ReadDatabase
Section titled “ReadDatabase”Source:
src/GCP/Firestore/ReadDatabase.ts
Read access to a Firestore Database: get, list, query.
Grants roles/datastore.viewer on the project under an IAM Condition
naming this database (Firestore databases have no resource-level IAM
policy).
ReadDatabase: Reading documents
Section titled “ReadDatabase: Reading documents”const db = yield* GCP.Firestore.ReadDatabase(database);const alice = yield* db.get("users/alice");const { documents } = yield* db.list("users", { pageSize: 20 });// …provided with Effect.provide(GCP.Firestore.ReadDatabaseHttp)ReadDatabase: Querying
Section titled “ReadDatabase: Querying”const db = yield* GCP.Firestore.ReadDatabase(database);const admins = yield* db.query({ from: [{ collectionId: "users" }], where: { fieldFilter: { field: { fieldPath: "role" }, op: "EQUAL", value: { stringValue: "admin" }, }, },});ReadDatabaseHttp
Section titled “ReadDatabaseHttp”Source:
src/GCP/Firestore/ReadDatabaseHttp.tsKind: Layer · Provides:GCP.Firestore.ReadDatabase
HTTP implementation of ReadDatabase over the Firestore REST API.
ReadWriteDatabase
Section titled “ReadWriteDatabase”Source:
src/GCP/Firestore/ReadWriteDatabase.ts
Read and write access to a Firestore Database. Grants
roles/datastore.user on the project under an IAM Condition naming
this database (Firestore databases have no resource-level IAM policy).
ReadWriteDatabase: Reading and writing
Section titled “ReadWriteDatabase: Reading and writing”const db = yield* GCP.Firestore.ReadWriteDatabase(database);const doc = yield* db.get("counters/visits");const count = typeof doc?.fields.count === "number" ? doc.fields.count : 0;yield* db.set("counters/visits", { count: count + 1 });// …provided with Effect.provide(GCP.Firestore.ReadWriteDatabaseHttp)ReadWriteDatabaseHttp
Section titled “ReadWriteDatabaseHttp”Source:
src/GCP/Firestore/ReadWriteDatabaseHttp.tsKind: Layer · Provides:GCP.Firestore.ReadWriteDatabase
HTTP implementation of ReadWriteDatabase over the Firestore REST API.
WriteDatabase
Section titled “WriteDatabase”Source:
src/GCP/Firestore/WriteDatabase.ts
Write access to a Firestore Database: set, update, delete,
create. Grants roles/datastore.user on the project under an IAM
Condition naming this database (Firestore databases have no
resource-level IAM policy).
WriteDatabase: Writing documents
Section titled “WriteDatabase: Writing documents”const db = yield* GCP.Firestore.WriteDatabase(database);yield* db.create("users/alice", { name: "Alice", visits: 0 }).pipe( Effect.catchTag("GCP.Firestore.DocumentAlreadyExists", () => Effect.void),);yield* db.update("users/alice", { visits: 1, lastSeen: new Date() });yield* db.delete("users/bob");// …provided with Effect.provide(GCP.Firestore.WriteDatabaseHttp)WriteDatabaseHttp
Section titled “WriteDatabaseHttp”Source:
src/GCP/Firestore/WriteDatabaseHttp.tsKind: Layer · Provides:GCP.Firestore.WriteDatabase
HTTP implementation of WriteDatabase over the Firestore REST API.