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 RunQuery}; project and database come from the bound database. */
9export type RunQueryRequest =
10 DatastoreDatabaseRequest<datastore.RunQueryProjectsRequest>;
11
12/**
13 * Runtime binding for Datastore `projects.runQuery`.
14 *
15 * Bind this operation to a Datastore-mode `GCP.Firestore.Database` in a Function/Action init
16 * phase. Provide {@link RunQueryHttp}. The bound database supplies the
17 * project and database id; queries 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 * ### Querying Entities
22 * **Example:** Query a kind
23 * ```typescript
24 * const database = yield* GCP.Firestore.Database("Tasks", {
25 * type: "DATASTORE_MODE",
26 * });
27 * const runQuery = yield* GCP.Datastore.RunQuery(database);
28 * const page = yield* runQuery({
29 * body: { query: { kind: [{ name: "Task" }] } },
30 * });
31 * ```
32 *
33 * @binding
34 * @category Datastore
35 */
36export interface RunQuery extends Binding.Service<
37 RunQuery,
38 "GCP.Datastore.RunQuery",
39 (
40 database: Database,
41 ) => Effect.Effect<
42 (
43 request: RunQueryRequest,
44 ) => Effect.Effect<
45 datastore.RunQueryResponse,
46 datastore.RunQueryProjectsError,
47 RuntimeContext
48 >
49 >
50> {}
51
52export const RunQuery = Binding.Service<RunQuery>("GCP.Datastore.RunQuery");