| 1 | import type * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../../Binding.ts"; |
| 3 | import type { Database } from "./Database.ts"; |
| 4 | import type { ReadDatabaseClient } from "./ReadDatabase.ts"; |
| 5 | import type { WriteDatabaseClient } from "./WriteDatabase.ts"; |
| 6 | |
| 7 | export interface ReadWriteDatabaseClient |
| 8 | extends ReadDatabaseClient, WriteDatabaseClient {} |
| 9 | |
| 10 | /** |
| 11 | * Read and write access to a Firestore {@link Database}. Grants |
| 12 | * `roles/datastore.user` on the project under an IAM Condition naming |
| 13 | * this database (Firestore databases have no resource-level IAM policy). |
| 14 | * |
| 15 | * ### Reading and writing |
| 16 | * **Example:** Increment a counter |
| 17 | * ```typescript |
| 18 | * const db = yield* GCP.Firestore.ReadWriteDatabase(database); |
| 19 | * const doc = yield* db.get("counters/visits"); |
| 20 | * const count = typeof doc?.fields.count === "number" ? doc.fields.count : 0; |
| 21 | * yield* db.set("counters/visits", { count: count + 1 }); |
| 22 | * // …provided with Effect.provide(GCP.Firestore.ReadWriteDatabaseHttp) |
| 23 | * ``` |
| 24 | * |
| 25 | * @binding |
| 26 | * @category Firestore |
| 27 | */ |
| 28 | export interface ReadWriteDatabase extends Binding.Service< |
| 29 | ReadWriteDatabase, |
| 30 | "GCP.Firestore.ReadWriteDatabase", |
| 31 | (database: Database) => Effect.Effect<ReadWriteDatabaseClient> |
| 32 | > {} |
| 33 | |
| 34 | export const ReadWriteDatabase = Binding.Service<ReadWriteDatabase>( |
| 35 | "GCP.Firestore.ReadWriteDatabase", |
| 36 | ); |