| 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 Lookup}; project and database come from the bound database. */ |
| 9 | export type LookupRequest = |
| 10 | DatastoreDatabaseRequest<datastore.LookupProjectsRequest>; |
| 11 | |
| 12 | /** |
| 13 | * Runtime binding for Datastore `projects.lookup`. |
| 14 | * |
| 15 | * Bind this operation to a Datastore-mode `GCP.Firestore.Database` in a Function/Action init |
| 16 | * phase. Provide {@link LookupHttp}. The bound database supplies the |
| 17 | * project and database id; lookups 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 | * ### Looking Up Entities |
| 22 | * **Example:** Lookup by key |
| 23 | * ```typescript |
| 24 | * const database = yield* GCP.Firestore.Database("Tasks", { |
| 25 | * type: "DATASTORE_MODE", |
| 26 | * }); |
| 27 | * const lookup = yield* GCP.Datastore.Lookup(database); |
| 28 | * const result = yield* lookup({ |
| 29 | * body: { |
| 30 | * keys: [{ path: [{ kind: "Task", name: "t1" }] }], |
| 31 | * }, |
| 32 | * }); |
| 33 | * ``` |
| 34 | * |
| 35 | * @binding |
| 36 | * @category Datastore |
| 37 | */ |
| 38 | export interface Lookup extends Binding.Service< |
| 39 | Lookup, |
| 40 | "GCP.Datastore.Lookup", |
| 41 | ( |
| 42 | database: Database, |
| 43 | ) => Effect.Effect< |
| 44 | ( |
| 45 | request: LookupRequest, |
| 46 | ) => Effect.Effect< |
| 47 | datastore.LookupResponse, |
| 48 | datastore.LookupProjectsError, |
| 49 | RuntimeContext |
| 50 | > |
| 51 | > |
| 52 | > {} |
| 53 | |
| 54 | export const Lookup = Binding.Service<Lookup>("GCP.Datastore.Lookup"); |