The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as bigquery from "@distilled.cloud/gcp/bigquery_v2"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as GCPBindings from "../GCPBindings.ts"; |
| 5 | import { grantFor } from "../HttpBinding.ts"; |
| 6 | import type { Dataset } from "./Dataset.ts"; |
| 7 | import { Query, type QueryRequest } from "./Query.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link Query}. |
| 11 | * |
| 12 | * @layer |
| 13 | * @provides GCP.BigQuery.Query |
| 14 | */ |
| 15 | export const QueryHttp = Layer.effect( |
| 16 | Query, |
| 17 | Effect.gen(function* () { |
| 18 | const bind = yield* GCPBindings.Bind; |
| 19 | const queryJobs = yield* GCPBindings.withCredentials(bigquery.queryJobs); |
| 20 | return Effect.fn(function* (dataset: Dataset) { |
| 21 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 22 | yield* bind`GCP.BigQuery.Query(${dataset})`({ |
| 23 | iam: [ |
| 24 | // bigquery.jobs.create is only grantable on the project. |
| 25 | { role: "roles/bigquery.jobUser" }, |
| 26 | // Read access on this dataset only (its access list). |
| 27 | grantFor({ role: "roles/bigquery.dataViewer", on: "bigquery.dataset" }, dataset.name), |
| 28 | ], |
| 29 | }); |
| 30 | } |
| 31 | const project = yield* dataset.project; |
| 32 | const datasetId = yield* dataset.datasetId; |
| 33 | const location = yield* dataset.location; |
| 34 | return Effect.fn(`GCP.BigQuery.Query(${dataset.LogicalId})`)(function* ( |
| 35 | request: QueryRequest, |
| 36 | ) { |
| 37 | return yield* queryJobs({ |
| 38 | projectId: yield* project, |
| 39 | body: { |
| 40 | useLegacySql: false, |
| 41 | location: yield* location, |
| 42 | ...request, |
| 43 | defaultDataset: request.defaultDataset ?? { |
| 44 | projectId: yield* project, |
| 45 | datasetId: yield* datasetId, |
| 46 | }, |
| 47 | }, |
| 48 | }); |
| 49 | }); |
| 50 | }); |
| 51 | }), |
| 52 | ); |