| 1 | import type * as firestore from "@distilled.cloud/gcp/firestore_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 "./Database.ts"; |
| 6 | |
| 7 | export interface GetDocumentRequest extends Omit< |
| 8 | firestore.GetProjectsDatabasesDocumentsRequest, |
| 9 | "name" |
| 10 | > { |
| 11 | /** |
| 12 | * Document path relative to the database, e.g. `users/alice`. |
| 13 | */ |
| 14 | documentPath: string; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Runtime binding for Firestore `documents.get`. |
| 19 | * |
| 20 | * Bind this operation to a {@link Database} in a Function/Action init |
| 21 | * phase. Provide {@link GetDocumentHttp}. |
| 22 | * |
| 23 | * ### Reading Documents |
| 24 | * **Example:** Get a document |
| 25 | * ```typescript |
| 26 | * const getDocument = yield* GCP.Firestore.GetDocument(database); |
| 27 | * const doc = yield* getDocument({ documentPath: "users/alice" }); |
| 28 | * ``` |
| 29 | * |
| 30 | * @binding |
| 31 | * @category Firestore |
| 32 | */ |
| 33 | export interface GetDocument extends Binding.Service< |
| 34 | GetDocument, |
| 35 | "GCP.Firestore.GetDocument", |
| 36 | ( |
| 37 | database: Database, |
| 38 | ) => Effect.Effect< |
| 39 | ( |
| 40 | request: GetDocumentRequest, |
| 41 | ) => Effect.Effect< |
| 42 | firestore.Document, |
| 43 | firestore.GetProjectsDatabasesDocumentsError, |
| 44 | RuntimeContext |
| 45 | > |
| 46 | > |
| 47 | > {} |
| 48 | |
| 49 | export const GetDocument = Binding.Service<GetDocument>( |
| 50 | "GCP.Firestore.GetDocument", |
| 51 | ); |