1import * as workflowexecutions from "@distilled.cloud/gcp/workflowexecutions_v1";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import {
5 CreateExecution,
6 type CreateExecutionRequest,
7} from "./CreateExecution.ts";
8import type { Workflow } from "./Workflow.ts";
9import { bindGcpHost } from "../Host.ts";
10
11/**
12 * HTTP implementation of {@link CreateExecution}.
13 *
14 * @layer
15 * @provides GCP.Workflows.CreateExecution
16 */
17export const CreateExecutionHttp = Layer.effect(
18 CreateExecution,
19 Effect.gen(function* () {
20 const createExecution =
21 yield* workflowexecutions.createProjectsLocationsWorkflowsExecutions;
22 return Effect.fn(function* (workflow: Workflow) {
23 yield* bindGcpHost({
24 tag: "GCP.Workflows.CreateExecution",
25 resource: workflow,
26 // Workflows has no resource-level IAM; invoker is granted on the project.
27 iam: [{ role: "roles/workflows.invoker" }],
28 });
29 const name = yield* workflow.name;
30 return Effect.fn(`GCP.Workflows.CreateExecution(${workflow.LogicalId})`)(
31 function* (request?: CreateExecutionRequest) {
32 const parent = yield* name;
33 return yield* createExecution({ ...request, parent });
34 },
35 );
36 });
37 }),
38);