| 1 | import type * as sfn from "@distilled.cloud/aws/sfn"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { StateMachine } from "./StateMachine.ts"; |
| 5 | |
| 6 | export interface StartExecutionRequest extends Omit< |
| 7 | sfn.StartExecutionInput, |
| 8 | "stateMachineArn" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `states:StartExecution`. |
| 13 | * |
| 14 | * Bind this operation to a {@link StateMachine} inside a function runtime to |
| 15 | * get a callable that starts asynchronous executions with the state machine |
| 16 | * ARN injected automatically. |
| 17 | * ### Starting Executions |
| 18 | * **Example:** Start a workflow execution |
| 19 | * ```typescript |
| 20 | * const startExecution = yield* StepFunctions.StartExecution(machine); |
| 21 | * |
| 22 | * const execution = yield* startExecution({ |
| 23 | * input: JSON.stringify({ orderId: "123" }), |
| 24 | * }); |
| 25 | * // execution.executionArn identifies the running workflow |
| 26 | * ``` |
| 27 | * |
| 28 | * **Example:** Idempotent start via execution name |
| 29 | * ```typescript |
| 30 | * const execution = yield* startExecution({ |
| 31 | * name: `order-${orderId}`, |
| 32 | * input: JSON.stringify({ orderId }), |
| 33 | * }); |
| 34 | * ``` |
| 35 | * |
| 36 | * @binding |
| 37 | */ |
| 38 | export interface StartExecution extends Binding.Service< |
| 39 | StartExecution, |
| 40 | "AWS.StepFunctions.StartExecution", |
| 41 | ( |
| 42 | stateMachine: StateMachine, |
| 43 | ) => Effect.Effect< |
| 44 | ( |
| 45 | request?: StartExecutionRequest, |
| 46 | ) => Effect.Effect<sfn.StartExecutionOutput, sfn.StartExecutionError> |
| 47 | > |
| 48 | > {} |
| 49 | export const StartExecution = Binding.Service<StartExecution>( |
| 50 | "AWS.StepFunctions.StartExecution", |
| 51 | ); |