Skip to content

GCP.Firestore reference

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.

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",
});
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" });

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" },
});

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" },
],
},
);

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).

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,
});

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.

const deleteDocument = yield* GCP.Firestore.DeleteDocument(database);
yield* deleteDocument({ documentPath: "users/alice" });

Source: src/GCP/Firestore/DeleteDocumentHttp.ts Kind: Layer · Provides: GCP.Firestore.DeleteDocument

HTTP implementation of DeleteDocument.

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.

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" } },
});

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.

const getDocument = yield* GCP.Firestore.GetDocument(database);
const doc = yield* getDocument({ documentPath: "users/alice" });

Source: src/GCP/Firestore/GetDocumentHttp.ts Kind: Layer · Provides: GCP.Firestore.GetDocument

HTTP implementation of GetDocument.

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.

const patchDocument = yield* GCP.Firestore.PatchDocument(database);
yield* patchDocument({
documentPath: "users/alice",
body: { fields: { name: { stringValue: "Alice" } } },
});

Source: src/GCP/Firestore/PatchDocumentHttp.ts Kind: Layer · Provides: GCP.Firestore.PatchDocument

HTTP implementation of PatchDocument.

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).

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)
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" },
},
},
});

Source: src/GCP/Firestore/ReadDatabaseHttp.ts Kind: Layer · Provides: GCP.Firestore.ReadDatabase

HTTP implementation of ReadDatabase over the Firestore REST API.

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).

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)

Source: src/GCP/Firestore/ReadWriteDatabaseHttp.ts Kind: Layer · Provides: GCP.Firestore.ReadWriteDatabase

HTTP implementation of ReadWriteDatabase over the Firestore REST API.

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).

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)

Source: src/GCP/Firestore/WriteDatabaseHttp.ts Kind: Layer · Provides: GCP.Firestore.WriteDatabase

HTTP implementation of WriteDatabase over the Firestore REST API.