import { CallExpr } from "@functionless/ast"; import { aws_events_targets, aws_stepfunctions } from "aws-cdk-lib"; import { IPrincipal } from "aws-cdk-lib/aws-iam"; import { StepFunctions } from "aws-sdk"; import { Construct } from "constructs"; import { ApiGatewayVtlIntegration } from "./api"; import { AppSyncVtlIntegration } from "./appsync"; import { ASL, ASLGraph, Retry, StateMachine, States, Task } from "./asl"; import { Rule } from "./event-bridge"; import { Event } from "./event-bridge/types"; import { NativeIntegration } from "./function"; import { Integration, IntegrationCall } from "./integration"; export declare type AnyStepFunction = ExpressStepFunction | StepFunction; /** * Machine and Execution context available during runtime. * * @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html * * To access this data, use the second parameter in a new {@link StepFunction}'s callback. * * ```ts * new StepFunction(stack, 'sfn', (input, context) => { * return context.Execution.Name; * }) * ``` * * > Note: missing fields (ex: `$$.State.Name`) are abstracted away from {@link StepFunction}. * > Note: `$$.Execution.Input` is available as the first parameter of the closure `(input) => {}`. */ export interface SfnContext { /** * Data associated with the current execution of the state machine which is available during execution. */ readonly Execution: { /** * Unique name of the current execution of the {@link StateMachine}. * * @example - executionName */ readonly Name: string; /** * Arn of the current execution of the {@link StateMachine}. * * @example - arn:aws:states:us-east-1:123456789012:execution:stateMachineName:executionName */ readonly Id: string; /** * Time the current execution started. * * Format: ISO 8601 * * @example - 2019-03-26T20:14:13.192Z */ readonly StartTime: string; /** * Execution role ARN * * @example - arn:aws:iam::123456789012:role */ readonly RoleArn: string; }; /** * Data associated with the state machine which is available during execution. */ readonly StateMachine: { /** * Unique name of the {@link StateMachine}. * * @example - stateMachineName */ readonly Name: string; /** * Arn of the {@link StateMachine}. * * @example arn:aws:states:us-east-1:123456789012:stateMachine:stateMachineName */ readonly Id: string; }; readonly Task: { /** * Task token to be used with {@link $SFN.task} and the `waitForTaskToken` integration pattern. * * https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html */ readonly Token: string; }; } export declare type StepFunctionClosure | undefined, Out> = (arg: Payload, context: SfnContext) => Promise | Out; declare type ParallelFunction = () => Promise | T; declare type ParallelFunctionReturnType> = T extends ParallelFunction ? P : never; export interface $SFN { /** * Wait for a specific number of {@link seconds}. * * ```ts * new ExpressStepFunction(this, "F", (seconds: number) => $SFN.waitFor(seconds)) * ``` * * @see https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html */ waitFor(seconds: number): void; /** * Wait until a {@link timestamp}. * * ```ts * new ExpressStepFunction(this, "F", (timestamp: string) => $SFN.waitUntil(timestamp)) * ``` * * @see https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html */ waitUntil(timestamp: string): void; /** * Process each item in an {@link array} in parallel and run with the default maxConcurrency. * * Example: * ```ts * new ExpressStepFunction(this, "F", async (items: string[]) => { * await $SFN.forEach(items, { maxConcurrency: 2 }, item => task(item)); * }); * ``` * * @param array the list of items to process * @param callbackfn function to process each item */ forEach(array: T[], callbackfn: (item: T, index: number, array: T[]) => void): Promise; /** * Process each item in an {@link array} in parallel and run with the default maxConcurrency. * * Example: * ```ts * new ExpressStepFunction(this, "F", async (items: string[]) => { * await $SFN.forEach(items, { maxConcurrency: 2 }, item => task(item)); * }); * ``` * * @param array the list of items to process * @param props configure the maxConcurrency * @param callbackfn function to process each item */ forEach(array: T[], props: { maxConcurrency: number; }, callbackfn: (item: T, index: number, array: T[]) => void): Promise; /** * Map over each item in an {@link array} in parallel and run with the default maxConcurrency. * * Example: * ```ts * new ExpressStepFunction(this, "F", (items: string[]) => { * return $SFN.map(items, item => task(item)) * }); * ``` * * @param array the list of items to map over * @param callbackfn function to process each item * @returns an array containing the result of each mapped item */ map(array: T[], callbackfn: (item: T, index: number, array: T[]) => U | Promise): Promise; /** * Map over each item in an {@link array} in parallel and run with the default maxConcurrency. * * Example: * ```ts * new ExpressStepFunction(this, "F", (items: string[]) => { * return $SFN.map(items, item => task(item)) * }); * ``` * * @param array the list of items to map over * @param props configure the maxConcurrency * @param callbackfn function to process each item * @returns an array containing the result of each mapped item */ map(array: T[], props: { maxConcurrency: number; }, callbackfn: (item: T, index: number, array: T[]) => U | Promise): Promise; /** * Run 1 or more workflows in parallel. * * ```ts * new ExpressStepFunction(this, "F", (id: string) => { * const results = $SFN.parallel( * () => task1(id) * () => task2(id) * ) * }) * ``` */ parallel[]>(...paths: Paths): Promise<{ [i in keyof Paths]: i extends `${number}` ? ParallelFunctionReturnType : Paths[i]; }>; /** * Apply Step Function's built in Retry logic to a function. * * ```ts * new ExpressStepFunction(this, "F", (id: string) => { * const results = $SFN.retry( * async () => { await task1(id) } * ) * }) * ``` * * By default, all errors (`States.ALL`) will be caught and retried with the default backoff strategy: * MaxAttempts: 3 * IntervalSeconds: 1 * BackoffRate: 2.0 * * Optionally provide specific error codes and backoff strategies. * * ```ts * new ExpressStepFunction(this, "F", (id: string) => { * const results = $SFN.retry( * [{ ErrorEquals: ["Lambda.ToManyRequestsException"], BackoffRate: 2.5, IntervalSeconds: 2, MaxAttempts: 4 }], * async () => { await task1(id) } * ) * }) * ``` * * Caveat: `$SFN.retry` does not maintain the state of mutated variables within the callback. * * ```ts * let a = 1; * await $SFN.retry(() => { a = 2; return a * 4; }) * return a; * ``` * * The return value will be `1`. * */ retry>(retry: Retry[], callback: Func): ReturnType; retry>(callback: Func): ReturnType; /** * Use the States.ArrayPartition intrinsic function to partition a large array. * You can also use this intrinsic to slice the data and then send the payload in smaller chunks. * * ```ts * SFN.Partition([1,2,3,4,5], 3); // [[1,2,3], [4,5]] * ``` * * @param arr - an array to partition, cannot exceed the payload size limit of 256KB. * @param size - the desired chunk size, must be non-zero, positive integer. */ partition(arr: T[], size: number): T[][]; /** * Use the States.ArrayRange intrinsic function to create a new array containing a specific range of elements. * The new array can contain up to 1000 elements. * * ```ts * SFN.range(1, 10, 3); // [1, 4, 7, 10] * ``` * * @param start - first element in the new array * @param end - final element of the new array (inclusive) * @param step - optional step parameter (default: 1) */ range(start: number, end: number, step?: Exclude): number[]; /** * The States.ArrayUnique intrinsic function removes duplicate values from an array and returns an array containing only unique elements. * This function takes an array, which can be unsorted, as its sole argument. * * ```ts * SFN.unique([1,2,3,3,4,4,5,5]); // [1,2,3,4,5] * ``` * * @param arr - array of values to return unique values of. */ unique(arr: T[]): T[]; /** * States.ArrayGetItem returns a specified index's value of an array. * * ```ts * SFN.getItem([1,2,3,3,4,4,5,5], 0); // 1 * ``` * * @param arr - array of values to access. * @param index - array index to retrieve. */ getItem(arr: T[], index: number): T; /** * Use the `base64Encode` intrinsic function to encode data based on MIME Base64 encoding scheme. * You can use this function to pass data to other AWS services without using an AWS Lambda function. * * @param data - String to encode as base64. Up to 10000 characters. */ base64Encode(data: string): string; /** * Use the base64Decode intrinsic function to decode data based on MIME Base64 decoding scheme. * You can use this function to pass data to other AWS services without using a Lambda function. * * @param base64 - Base64 string to decode. Up to 10000 characters. */ base64Decode(base64: string): string; /** * Use the `hash` intrinsic function to calculate the hash value of a given input. * You can use this function to pass data to other AWS services without using a Lambda function. * * @param data - data to hash. * @param algorithm - algorithm to use. */ hash(data: any, algorithm: ASLGraph.HashAlgorithm): string; /** * Use the States.MathRandom intrinsic function to return a random number between the specified start and end number. * For example, you can use this function to distribute a specific task between two or more resources. * * @param start - starting number, must be an integer. * @param end - ending number, must be an integer. * @param seed - optional seed value to determine when generating the random value. */ random(start: number, end: number, seed?: number): number; /** * Invoke any {@link StepFunction task}. Return type will be whatever the task would return in StepFunctions. * * https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html * * @param definition.Resource - Resource to invoke - must be a string literal. * @param definition.Retry - an array of {@link Retry}, must only contain literal values. * @param definition.Comment - a comment added to the state machine - must be a string literal. * @param definition.Parameters - values to pass to the task. * @param definition.TimeoutSeconds - time to wait for the task to complete. * @param definition.HeartbeatSeconds - time to wait for the task to complete. * * Note: If Parameters is a reference, TimeoutSeconds and Heartbeat cannot be references. */ task(definition: Pick): Result; } export declare const $SFN: { waitFor: IntegrationCall<"$SFN.waitFor", (seconds: number) => void>; waitUntil: IntegrationCall<"$SFN.waitUntil", (timestamp: string) => void>; forEach: IntegrationCall<"$SFN.forEach", { (array: T[], callbackfn: (item: T, index: number, array: T[]) => void): Promise; (array: T_1[], props: { maxConcurrency: number; }, callbackfn: (item: T_1, index: number, array: T_1[]) => void): Promise; }>; map: IntegrationCall<"$SFN.map", { (array: T_2[], callbackfn: (item: T_2, index: number, array: T_2[]) => U | Promise): Promise; (array: T_3[], props: { maxConcurrency: number; }, callbackfn: (item: T_3, index: number, array: T_3[]) => U_1 | Promise): Promise; }>; parallel: IntegrationCall<"$SFN.parallel", []>(...paths: Paths) => Promise<{ [i in keyof Paths]: i extends `${number}` ? ParallelFunctionReturnType : Paths[i]; }>>; retry: IntegrationCall<"$SFN.$SFN.retry", { >(retry: Retry[], callback: Func): ReturnType; >(callback: Func_1): ReturnType; }>; partition: IntegrationCall<"$SFN.States.Partition", (arr: T_4[], size: number) => T_4[][]>; range: IntegrationCall<"$SFN.States.Range", (start: number, end: number, step?: Exclude) => number[]>; unique: IntegrationCall<"$SFN.States.Unique", (arr: T_5[]) => T_5[]>; getItem: IntegrationCall<"$SFN.States.GetItem", (arr: T_6[], index: number) => T_6>; base64Encode: IntegrationCall<"$SFN.States.Base64Encode", (data: string) => string>; base64Decode: IntegrationCall<"$SFN.States.Base64Decode", (base64: string) => string>; hash: IntegrationCall<"$SFN.States.Hash", (data: any, algorithm: ASLGraph.HashAlgorithm) => string>; random: IntegrationCall<"$SFN.States.Random", (start: number, end: number, seed?: number) => number>; /** * Invoke any {@link StepFunction task}. Return type will be whatever the task would return in StepFunctions. * * https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html */ task: IntegrationCall<"$SFN.SFN.task", (definition: Pick) => Result>; }; /** * Data types allowed as a Step Function Cause. */ export declare type StepFunctionCause = null | boolean | number | string | StepFunctionCause[] | { [prop: string]: StepFunctionCause; }; /** * An Error that can be thrown from within a {@link StepFunction} or {@link ExpressStepFunction}. * * It encodes a `Fail` state in ASL. * ```json * { * "Type": "Fail", * "Error": , * "Cause": JSON.stringify() * } * ``` * * For example: * ```ts * throw new StepFunctionError("MyError", { "key": "value"}); * ``` * * Produces the following Fail state: * ```json * { * "Type": "Fail", * "Error": "MyError", * "Cause": "{\"key\":\"value\""}" * } * ``` */ export declare class StepFunctionError extends Error { /** * The name of the Error to place in the Fail state. */ readonly error: string; readonly cause: StepFunctionCause; static readonly kind = "StepFunctionError"; static isConstructor(a: any): a is typeof StepFunctionError; constructor( /** * The name of the Error to place in the Fail state. */ error: string, cause: StepFunctionCause); } export declare function isStepFunction

| undefined, O = any>(a: any): a is StepFunction | ExpressStepFunction; /** * {@see https://docs.aws.amazon.com/step-functions/latest/dg/cw-events.html} */ interface StepFunctionDetail { executionArn: string; stateMachineArn: string; name: string; status: "SUCCEEDED" | "RUNNING" | "FAILED" | "TIMED_OUT" | "ABORTED"; startDate: number; stopDate: number | null; input: string; inputDetails: { included: boolean; }; output: null | string; outputDetails: null | { included: boolean; }; } export interface StepFunctionStatusChangedEvent extends Event { } interface StepFunctionEventBusTargetProps extends Omit { } declare abstract class BaseStepFunction | undefined, CallIn, CallOut> implements Integration<"StepFunction", (input: CallIn) => Promise> { readonly resource: aws_stepfunctions.StateMachine; readonly kind = "StepFunction"; readonly functionlessKind = "StepFunction"; readonly appSyncVtl: AppSyncVtlIntegration; readonly __functionBrand: (input: CallIn) => Promise; constructor(resource: aws_stepfunctions.StateMachine); readonly apiGWVtl: ApiGatewayVtlIntegration; appSyncIntegration(integration: Pick, grant: (resource: aws_stepfunctions.StateMachine, principal: IPrincipal) => void): AppSyncVtlIntegration; asl(call: CallExpr, context: ASL): ASLGraph.NodeState & { output: ASLGraph.JsonPath; }; readonly eventBus: import("./event-bridge").EventBusTargetIntegration; private statusChangeEventDocument; onSucceeded(scope: Construct, id: string): Rule; onFailed(scope: Construct, id: string): Rule; onStarted(scope: Construct, id: string): Rule; onTimedOut(scope: Construct, id: string): Rule; onAborted(scope: Construct, id: string): Rule; /** * Create event bus rule that matches any status change on this machine. */ onStatusChanged(scope: Construct, id: string): Rule; } export interface StepFunctionProps extends Omit { } /** * An {@link ExpressStepFunction} is a callable Function which executes on the managed * AWS Step Function infrastructure. Like a Lambda Function, it runs within memory of * a single machine, except unlike Lambda, the entire environment is managed and operated * by AWS. Meaning, there is no Operating System, Memory, CPU, Credentials or API Clients * to manage. The entire workflow is configured at build-time via the Amazon State Language (ASL). * * With Functionless, the ASL is derived from type-safe TypeScript code instead of JSON. * * ```ts * import * as f from "@functionless/aws-constructs"; * * const table = new f.Table(this, "Table", { ... }); * * const getItem = new ExpressStepFunction(this, "F", () => { * return f.$AWS.DynamoDB.GetItem({ * Table: table, * Key: { * .. * } * }); * }); * ``` */ export interface IExpressStepFunction | undefined, Out> { (input: StepFunctionRequest): SyncExecutionResult; } declare class BaseExpressStepFunction | undefined, Out> extends BaseStepFunction, SyncExecutionResult> implements IExpressStepFunction { /** * This static property identifies this class as an ExpressStepFunction to the TypeScript plugin. */ static readonly FunctionlessType = "ExpressStepFunction"; readonly native: NativeIntegration<(input: StepFunctionRequest) => Promise>>; constructor(machine: aws_stepfunctions.StateMachine); } interface BaseExpressStepFunction | undefined, Out> { (input: StepFunctionRequest): SyncExecutionResult; } /** * An {@link ExpressStepFunction} is a callable Function which executes on the managed * AWS Step Function infrastructure. Like a Lambda Function, it runs within memory of * a single machine, except unlike Lambda, the entire environment is managed and operated * by AWS. Meaning, there is no Operating System, Memory, CPU, Credentials or API Clients * to manage. The entire workflow is configured at build-time via the Amazon State Language (ASL). * * With Functionless, the ASL is derived from type-safe TypeScript code instead of JSON. * * ```ts * import * as f from "@functionless/aws-constructs"; * * const table = new f.Table(this, "Table", { ... }); * * const getItem = new ExpressStepFunction(this, "F", () => { * return f.$AWS.DynamoDB.GetItem({ * Table: table, * Key: { * .. * } * }); * }); * ``` */ export declare class ExpressStepFunction | undefined, Out> extends BaseExpressStepFunction { readonly definition: StateMachine; /** * Wrap a {@link aws_stepfunctions.StateMachine} with Functionless. * * A wrapped {@link StepFunction} provides common integrations like execute (`machine()`) and `describeExecution`. * * {@link ExpressStepFunction} should only be used to wrap a Express Step Function. * Express Step Functions should use {@link StepFunction}. * * ```ts * ExpressStepFunction.fromStateMachine(new aws_stepfunctions.StateMachine(this, "F", { * stateMachineType: aws_stepfunctions.StateMachineType.EXPRESS, * ... * })); * ``` */ static fromStateMachine | undefined, Out>(machine: aws_stepfunctions.StateMachine): IExpressStepFunction; constructor(scope: Construct, id: string, props: StepFunctionProps, func: StepFunctionClosure); constructor(scope: Construct, id: string, func: StepFunctionClosure); } interface BaseSyncExecutionResult { billingDetails?: { billedDurationInMilliseconds: number; billedMemoryUsedInMB: number; }; executionArn: string; input: string; inputDetails: { included: boolean; }; name: string; outputDetails: { included: boolean; }; startDate: number; stateMachineArn: string; status: "SUCCEEDED" | "FAILED" | "TIMED_OUT"; stopDate: number; traceHeader: string; } export interface SyncExecutionFailedResult extends BaseSyncExecutionResult { cause: string; error: string; status: "FAILED" | "TIMED_OUT"; } export interface SyncExecutionSuccessResult extends BaseSyncExecutionResult { output: T; status: "SUCCEEDED"; } export declare type SyncExecutionResult = SyncExecutionFailedResult | SyncExecutionSuccessResult; export declare type StepFunctionRequest

| undefined> = (P extends undefined ? { input?: P; } : { input: P; }) & ({ name: string; traceHeader: string; } | { name: string; } | { traceHeader: string; } | {}); export interface ExpressStepFunction | undefined, Out> { (input: StepFunctionRequest): Promise>; } /** * A {@link StepFunction} is a callable Function which executes on the managed * AWS Step Function infrastructure. Like a Lambda Function, it runs within memory of * a single machine, except unlike Lambda, the entire environment is managed and operated * by AWS. Meaning, there is no Operating System, Memory, CPU, Credentials or API Clients * to manage. The entire workflow is configured at build-time via the Amazon State Language (ASL). * * With Functionless, the ASL is derived from type-safe TypeScript code instead of JSON. * * ```ts * import * as f from "@functionless/aws-constructs"; * * const table = new f.Table(this, "Table", { ... }); * * const getItem = new StepFunction(this, "F", () => { * return f.$AWS.DynamoDB.GetItem({ * Table: table, * Key: { * .. * } * }); * }); * ``` * * @typeParam Payload - the object payload to the step function. * @typeParam Out - the type of object the step function outputs. * currently not used: https://github.com/functionless/functionless/issues/129 */ export interface IStepFunction | undefined, _Out> extends Integration<"StepFunction", (input: StepFunctionRequest) => Promise> { (input: StepFunctionRequest): Promise; } declare class BaseStandardStepFunction | undefined, Out> extends BaseStepFunction, AWS.StepFunctions.StartExecutionOutput> implements IStepFunction { /** * This static property identifies this class as an StepFunction to the TypeScript plugin. */ static readonly FunctionlessType = "StepFunction"; readonly native: NativeIntegration<(input: StepFunctionRequest) => Promise>; constructor(resource: aws_stepfunctions.StateMachine); describeExecution: IntegrationCall<"StepFunction.describeExecution", (executionArn: string) => Promise>; sendTaskSuccess: IntegrationCall<"StepFunction.sendTaskSuccess", (taskToken: AWS.StepFunctions.TaskToken, output: Payload_1) => Promise>; sendTaskFailure: IntegrationCall<"StepFunction.sendTaskFailure", (taskToken: AWS.StepFunctions.TaskToken, error?: string, cause?: string) => Promise>; sendTaskHeartbeat: IntegrationCall<"StepFunction.sendTaskHeartbeat", (taskToken: AWS.StepFunctions.TaskToken) => Promise>; } interface BaseStandardStepFunction | undefined, Out> { (input: StepFunctionRequest): Promise; describeExecution: IntegrationCall<"StepFunction.describeExecution", (executionArn: string) => Promise>; sendTaskSuccess: IntegrationCall<"StepFunction.sendTaskSuccess", (taskToken: AWS.StepFunctions.TaskToken, output: Payload) => Promise>; sendTaskFailure: IntegrationCall<"StepFunction.sendTaskFailure", (taskToken: AWS.StepFunctions.TaskToken, error?: string, cause?: string) => Promise>; sendTaskHeartbeat: IntegrationCall<"StepFunction.sendTaskHeartbeat", (taskToken: AWS.StepFunctions.TaskToken) => Promise>; } /** * A {@link StepFunction} is a callable Function which executes on the managed * AWS Step Function infrastructure. Like a Lambda Function, it runs within memory of * a single machine, except unlike Lambda, the entire environment is managed and operated * by AWS. Meaning, there is no Operating System, Memory, CPU, Credentials or API Clients * to manage. The entire workflow is configured at build-time via the Amazon State Language (ASL). * * With Functionless, the ASL is derived from type-safe TypeScript code instead of JSON. * * ```ts * import * as f from "@functionless/aws-constructs"; * * const table = new f.Table(this, "Table", { ... }); * * const getItem = new StepFunction(this, "F", () => { * return f.$AWS.DynamoDB.GetItem({ * Table: table, * Key: { * .. * } * }); * }); * ``` * * @typeParam Payload - the object payload to the step function. * @typeParam Out - the type of object the step function outputs. * currently not used: https://github.com/functionless/functionless/issues/129 */ export declare class StepFunction | undefined, Out> extends BaseStandardStepFunction implements IStepFunction { readonly definition: StateMachine; /** * Wrap a {@link aws_stepfunctions.StateMachine} with Functionless. * * A wrapped {@link StepFunction} provides common integrations like execute (`machine()`) and `describeExecution`. * * {@link StepFunction} should only be used to wrap a Standard Step Function. * Express Step Functions should use {@link ExpressStepFunction}. * * ```ts * StepFunction.fromStateMachine(new aws_stepfunctions.StateMachine(this, "F", { * ... * })); * ``` */ static fromStateMachine | undefined, Out>(machine: aws_stepfunctions.StateMachine): IStepFunction; constructor(scope: Construct, id: string, props: StepFunctionProps, func: StepFunctionClosure); constructor(scope: Construct, id: string, func: StepFunctionClosure); } export declare const deploymentOnlyModule = true; export {}; //# sourceMappingURL=step-function.d.ts.map