sailfork / t3code-github / .repos/ alchemy-effect/ packages/ aws/ src/ StepFunctions/ StartExecution.ts

import type * as sfn from "@distilled.cloud/aws/sfn";
import * as Binding from "alchemy/Binding";
import type * as Effect from "effect/Effect";
import type { StateMachine } from "./StateMachine.ts";

export interface StartExecutionRequest extends Omit<sfn.StartExecutionInput, "stateMachineArn"> {}

/**
 * Runtime binding for `states:StartExecution`.
 *
 * Bind this operation to a {@link StateMachine} inside a function runtime to
 * get a callable that starts asynchronous executions with the state machine
 * ARN injected automatically.
 * ### Starting Executions
 * **Example:** Start a workflow execution
 * ```typescript
 * const startExecution = yield* StepFunctions.StartExecution(machine);
 *
 * const execution = yield* startExecution({
 *   input: JSON.stringify({ orderId: "123" }),
 * });
 * // execution.executionArn identifies the running workflow
 * ```
 *
 * **Example:** Idempotent start via execution name
 * ```typescript
 * const execution = yield* startExecution({
 *   name: `order-${orderId}`,
 *   input: JSON.stringify({ orderId }),
 * });
 * ```
 *
 * @binding
 */
export interface StartExecution extends Binding.Service<
  StartExecution,
  "AWS.StepFunctions.StartExecution",
  (
    stateMachine: StateMachine,
  ) => Effect.Effect<
    (
      request?: StartExecutionRequest,
    ) => Effect.Effect<sfn.StartExecutionOutput, sfn.StartExecutionError>
  >
> {}
export const StartExecution = Binding.Service<StartExecution>("AWS.StepFunctions.StartExecution");