| 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 | |
| 5 | export interface TestStateRequest extends sfn.TestStateInput {} |
| 6 | |
| 7 | /** |
| 8 | * Runtime binding for `states:TestState` — execute a *single* ASL state |
| 9 | * (Task, Pass, Wait, Choice, Succeed, Fail) without creating a state |
| 10 | * machine, optionally with mocked service integrations. |
| 11 | * |
| 12 | * Service-scoped (no resource argument). States that call other services |
| 13 | * (e.g. `lambda:invoke`) need a `roleArn` the caller can `iam:PassRole` — |
| 14 | * intrinsic states (Pass/Choice/Succeed/Fail) run without one. |
| 15 | * ### Testing States |
| 16 | * **Example:** Test a Pass state's output processing |
| 17 | * ```typescript |
| 18 | * const testState = yield* StepFunctions.TestState(); |
| 19 | * |
| 20 | * const result = yield* testState({ |
| 21 | * definition: JSON.stringify({ |
| 22 | * Type: "Pass", |
| 23 | * QueryLanguage: "JSONata", |
| 24 | * Output: "{% $states.input.value * 2 %}", |
| 25 | * End: true, |
| 26 | * }), |
| 27 | * input: JSON.stringify({ value: 21 }), |
| 28 | * }); |
| 29 | * // result.status === "SUCCEEDED", result.output === "42" |
| 30 | * ``` |
| 31 | * |
| 32 | * @binding |
| 33 | */ |
| 34 | export interface TestState extends Binding.Service< |
| 35 | TestState, |
| 36 | "AWS.StepFunctions.TestState", |
| 37 | () => Effect.Effect< |
| 38 | ( |
| 39 | request: TestStateRequest, |
| 40 | ) => Effect.Effect<sfn.TestStateOutput, sfn.TestStateError> |
| 41 | > |
| 42 | > {} |
| 43 | export const TestState = Binding.Service<TestState>( |
| 44 | "AWS.StepFunctions.TestState", |
| 45 | ); |