| 1 | import * as bqdt from "@distilled.cloud/gcp/bigquerydatatransfer_v1"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { |
| 5 | StartManualRuns, |
| 6 | type StartManualRunsRequest, |
| 7 | } from "./StartManualRuns.ts"; |
| 8 | import type { TransferConfig } from "./TransferConfig.ts"; |
| 9 | import { bindGcpHost } from "../Host.ts"; |
| 10 | |
| 11 | /** |
| 12 | * HTTP implementation of {@link StartManualRuns}. |
| 13 | * |
| 14 | * @layer |
| 15 | * @provides GCP.BigQueryDataTransfer.StartManualRuns |
| 16 | */ |
| 17 | export const StartManualRunsHttp = Layer.effect( |
| 18 | StartManualRuns, |
| 19 | Effect.gen(function* () { |
| 20 | const startManualRunsProjectsLocationsTransferConfigs = |
| 21 | yield* bqdt.startManualRunsProjectsLocationsTransferConfigs; |
| 22 | return Effect.fn(function* (config: TransferConfig) { |
| 23 | yield* bindGcpHost({ |
| 24 | tag: "GCP.BigQueryDataTransfer.StartManualRuns", |
| 25 | resource: config, |
| 26 | // bigquery.transfers.update is in no narrower predefined role, and |
| 27 | // transfer configs have no resource-level IAM, so this is a project |
| 28 | // grant (see StartManualRuns JSDoc). |
| 29 | iam: [{ role: "roles/bigquery.admin" }], |
| 30 | }); |
| 31 | const name = yield* config.name; |
| 32 | return Effect.fn( |
| 33 | `GCP.BigQueryDataTransfer.StartManualRuns(${config.LogicalId})`, |
| 34 | )(function* (request?: StartManualRunsRequest) { |
| 35 | return yield* startManualRunsProjectsLocationsTransferConfigs({ |
| 36 | ...request, |
| 37 | parent: yield* name, |
| 38 | }); |
| 39 | }); |
| 40 | }); |
| 41 | }), |
| 42 | ); |