1import type * as firestore from "@distilled.cloud/gcp/firestore_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { Database } from "./Database.ts";
6
7export interface PatchDocumentRequest extends Omit<
8 firestore.PatchProjectsDatabasesDocumentsRequest,
9 "name"
10> {
11 /**
12 * Document path relative to the database, e.g. `users/alice`. Creates
13 * the document if it does not exist unless `currentDocument.exists` is
14 * set.
15 */
16 documentPath: string;
17}
18
19/**
20 * Runtime binding for Firestore `documents.patch`.
21 *
22 * Bind this operation to a {@link Database} in a Function/Action init
23 * phase. Provide {@link PatchDocumentHttp}. Patch upserts unless a
24 * current-document precondition is set.
25 *
26 * ### Writing Documents
27 * **Example:** Upsert a document
28 * ```typescript
29 * const patchDocument = yield* GCP.Firestore.PatchDocument(database);
30 * yield* patchDocument({
31 * documentPath: "users/alice",
32 * body: { fields: { name: { stringValue: "Alice" } } },
33 * });
34 * ```
35 *
36 * @binding
37 * @category Firestore
38 */
39export interface PatchDocument extends Binding.Service<
40 PatchDocument,
41 "GCP.Firestore.PatchDocument",
42 (
43 database: Database,
44 ) => Effect.Effect<
45 (
46 request: PatchDocumentRequest,
47 ) => Effect.Effect<
48 firestore.Document,
49 firestore.PatchProjectsDatabasesDocumentsError,
50 RuntimeContext
51 >
52 >
53> {}
54
55export const PatchDocument = Binding.Service<PatchDocument>(
56 "GCP.Firestore.PatchDocument",
57);