1import type * as datastore from "@distilled.cloud/gcp/datastore_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { Database } from "../Firestore/Database.ts";
6import type { DatastoreDatabaseRequest } from "./BindingHttp.ts";
7
8/** Request for {@link Commit}; project and database come from the bound database. */
9export 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 */
46export 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
62export const Commit = Binding.Service<Commit>("GCP.Datastore.Commit");