| 1 | import type * as datastore from "@distilled.cloud/gcp/datastore_v1"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 5 | import type { Database } from "../Firestore/Database.ts"; |
| 6 | import type { DatastoreDatabaseRequest } from "./BindingHttp.ts"; |
| 7 | |
| 8 | /** Request for {@link Commit}; project and database come from the bound database. */ |
| 9 | export type CommitRequest = |
| 10 | DatastoreDatabaseRequest<datastore.CommitProjectsRequest>; |
| 11 | |
| 12 | /** |
| 13 | * Runtime binding for Datastore `projects.commit`. |
| 14 | * |
| 15 | * Bind this operation to a Datastore-mode `GCP.Firestore.Database` in a Function/Action init |
| 16 | * phase. Provide {@link CommitHttp}. The bound database supplies the |
| 17 | * project and database id; mutations run against that database only. |
| 18 | * The host is granted the role on the project under an IAM Condition |
| 19 | * matching the database. |
| 20 | * |
| 21 | * ### Committing Mutations |
| 22 | * **Example:** Upsert an entity |
| 23 | * ```typescript |
| 24 | * const database = yield* GCP.Firestore.Database("Tasks", { |
| 25 | * type: "DATASTORE_MODE", |
| 26 | * }); |
| 27 | * const commit = yield* GCP.Datastore.Commit(database); |
| 28 | * const result = yield* commit({ |
| 29 | * body: { |
| 30 | * mode: "NON_TRANSACTIONAL", |
| 31 | * mutations: [ |
| 32 | * { |
| 33 | * upsert: { |
| 34 | * key: { path: [{ kind: "Task", name: "t1" }] }, |
| 35 | * properties: { title: { stringValue: "Ship" } }, |
| 36 | * }, |
| 37 | * }, |
| 38 | * ], |
| 39 | * }, |
| 40 | * }); |
| 41 | * ``` |
| 42 | * |
| 43 | * @binding |
| 44 | * @category Datastore |
| 45 | */ |
| 46 | export interface Commit extends Binding.Service< |
| 47 | Commit, |
| 48 | "GCP.Datastore.Commit", |
| 49 | ( |
| 50 | database: Database, |
| 51 | ) => Effect.Effect< |
| 52 | ( |
| 53 | request: CommitRequest, |
| 54 | ) => Effect.Effect< |
| 55 | datastore.CommitResponse, |
| 56 | datastore.CommitProjectsError, |
| 57 | RuntimeContext |
| 58 | > |
| 59 | > |
| 60 | > {} |
| 61 | |
| 62 | export const Commit = Binding.Service<Commit>("GCP.Datastore.Commit"); |