import { BindingName, CallExpr, Expr, FunctionlessNode, FunctionLike, ParameterDecl, PropAccessExpr, Stmt, VariableDecl } from "@functionless/ast"; import { aws_iam } from "aws-cdk-lib"; import { Construct } from "constructs"; import { ASLGraph } from "./asl-graph"; import { States, CommonFields, StateMachine, Pass, Choice, Fail, Succeed, Wait, Parameters, Condition, State } from "./states"; /** * Handler used by {@link ASL.evalExpr}* functions. * * @param output - the {@link ASLGraph.Output} generated by the output by the expression. * @param context - some helper functions specific to the evaluation context. * @returns a state with output or output to be merged into the other states generated during evaluation. */ declare type EvalExprHandler = (output: Output, context: EvalExprContext) => Result; export interface EvalExprContext { /** * Callback provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ addState: (state: ASLGraph.NodeState | ASLGraph.SubState) => void; /** * Returns a {@link ASLGraph.JsonPath} which points to the output value of the evaluated expression. * Any states required are added to the graph in order. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a json path. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ normalizeOutputToJsonPath(): ASLGraph.JsonPath; /** * Returns a {@link ASLGraph.JsonPath} or {@link ASLGraph.LiteralValue} which points to the output value of the evaluated expression. * Any states required are added to the graph in order. * * * If the output was a {@link ASLGraph.LiteralValue}, the output is returned. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ normalizeOutputToJsonPathOrLiteral(): ASLGraph.JsonPath | ASLGraph.LiteralValue; } /** * Handler used by {@link ASL.evalContext} functions. * * @param context - some helper functions specific to the evaluation context. * @returns a state with output or output to be merged into the other states generated during evaluation. */ declare type EvalContextHandler = (context: EvalContextContext) => T; export interface EvalContextContext { /** * Callback provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ addState: (state: ASLGraph.NodeState | ASLGraph.SubState) => void; /** * Evaluates a single expression and returns the {@link ASLGraph.Output}. * * Any generated states will be merged in with the output. * * This method is the same as {@link ASL.evalExpr}, but it adds any generated states to the current {@link ASL.evalContext}. */ evalExpr: (expr: Expr, allowUndefined?: boolean) => ASLGraph.Output; /** * Evaluates a single expression and returns the {@link ASLGraph.Output}. * * Any generated states will be merged in with the output. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a {@link ASL.JsonPath}. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * * This method is the same as {@link ASL.evalExprToJsonPath}, but it adds any generated states to the current {@link ASL.evalContext}. */ evalExprToJsonPath: (expr: Expr, allowUndefined?: boolean) => ASLGraph.JsonPath; /** * Evaluates a single expression and returns the {@link ASLGraph.JsonPath} or {@link ASLGraph.LiteralValue}. * * Any generated states will be merged in with the output. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. * * This method is the same as {@link ASL.evalExprToJsonPathOrLiteral}, but it adds any generated states to the current {@link ASL.evalContext}. */ evalExprToJsonPathOrLiteral: (expr: Expr, allowUndefined?: boolean) => ASLGraph.JsonPath | ASLGraph.LiteralValue; /** * Returns a {@link ASLGraph.JsonPath} which points to the value of the given output. * Any states required are added to the graph in order. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a json path. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ normalizeOutputToJsonPath(output: ASLGraph.Output): ASLGraph.JsonPath; /** * Returns a {@link ASLGraph.JsonPath} which points to the value of the given output. * Any states required are added to the graph in order. * * * If the output was a {@link ASLGraph.LiteralValue}, the output is returned. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ normalizeOutputToJsonPathOrLiteral(output: ASLGraph.Output): ASLGraph.JsonPath | ASLGraph.LiteralValue; /** * Assigns an {@link ASLGraph.Output} to a jsonPath variable. * * If the {@link value} is a {@link ASLGraph.ConditionOutput}, states are added to turn * the condition into a boolean value. * * Any states required to assign the value are added to the graph in order. */ assignValue(value: ASLGraph.Output, targetJsonPath?: string): ASLGraph.JsonPath; } /** * Amazon States Language (ASL) Generator. */ export declare class ASL { readonly scope: Construct; readonly role: aws_iam.IRole; /** * A friendly name to identify the Functionless Context. */ static readonly ContextName = "Amazon States Language"; /** * Tag this instance with its Functionless Context ({@link this.ContextName}) */ readonly kind = "Amazon States Language"; /** * The Amazon States Language (ASL) State Machine Definition synthesized fro the {@link decl}. */ readonly definition: StateMachine; /** * The {@link FunctionLike} AST representation of the State Machine. */ readonly decl: FunctionLike; private readonly stateNamesGenerator; private readonly variableNamesGenerator; private readonly variableNamesMap; private readonly generatedNames; /** * A pointer to the state used to continue. * * For and While loops should implement this state. */ private static readonly ContinueNext; /** * A pointer to the nearest break point. * * For and While loops should implement this state. */ private static readonly BreakNext; /** * A pointer to the nearest catch state. */ private static readonly CatchState; private readonly contextParameter; constructor(scope: Construct, role: aws_iam.IRole, decl: FunctionLike); /** * Access Functionless context variables in the machine state like the input to the machine. * * The Functionless context is only added to the machine when needed. * Using this property anywhere in a machine will add the context Pass state to the start of the machine. */ context: { null: string; }; /** * Returns a unique name for a declaration. * * The first time we see a declaration, the name will be the same as the identifier name. * * All future unique declarations with the same name will see an incremented number suffixed to the identifier. * * ```ts * const a; * const a; // a__1 * const a; // a__2 * for(let a in []) // a__3 * ``` */ private getDeclarationName; /** * Returns the unique variable name which has been registered for this identifier. * * Expects an {@link Identifier} which has a discoverable declaration. * * @see getDeclarationName */ private getIdentifierName; /** * Generates a valid, unique state name for the ASL machine. * * * Truncates the name to 75 characters * * If the name is already used, suffix with a unique number * * Cache both the truncated name and the suffixed name to prevent future collisions. */ private createUniqueStateName; /** * Flattens a {@link ASLGraph.SubState} graph or {@link ASLGraph.NodeState} into a {@link States} collection. * * Provides a node naming strategy. (see `stmtName`). * * @param stmtName - The name to use to start the graph. When a SubState is given, the first state of the collection * with use the `stmtName`. All subsequent states either use the name of the `node` given or their local name * prefixed onto the parent name. * When a NodeState is given, the `stmtName` is used. */ aslGraphToStates(state: ASLGraph.NodeState | ASLGraph.SubState, overrideStateName?: string): StateMachine; /** * Evaluate a single {@link Stmt} into a collection of named states. * * @param returnPass partial Pass state which will be given the return value as input using {@link ASLGraph.passWithInput}. * provide the rest to determine the behavior of the returnStmt. */ evalStmt(stmt: Stmt, returnPass: Omit & CommonFields): ASLGraph.SubState | ASLGraph.NodeState | undefined; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * @param expr - Expression to evaluate. * @param handler - A handler callback which receives the {@link ASLGraph.Output} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExpr(expr: Expr, handler: EvalExprHandler): Result; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * @param expr - Expression to evaluate. * @param contextNode - Node to associate with the output state. This node may be used to name the resulting state. * Otherwise expr is used. * @param handler - A handler callback which receives the {@link ASLGraph.Output} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExpr(expr: Expr, contextNode: FunctionlessNode, handler: EvalExprHandler): Result; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * If the {@link ASLGraph.Output} of the expression is not a {@link ASLGraph.JsonPath}, it will be normalized into one. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a json path. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. * * @param expr - Expression to evaluate. * @param handler - A handler callback which receives the {@link ASLGraph.JsonPath} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExprToJsonPath(expr: Expr, handler: EvalExprHandler): ASLGraph.NodeResults; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * If the {@link ASLGraph.Output} of the expression is not a {@link ASLGraph.JsonPath}, it will be normalized into one. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a json path. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. * * @param expr - Expression to evaluate. * @param contextNode - Optional node to associate with the output state. This node may be used to name the resulting state. * Otherwise expr is used. * @param handler - A handler callback which receives the {@link ASLGraph.JsonPath} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExprToJsonPath(expr: Expr, contextNode: FunctionlessNode, handler: EvalExprHandler): ASLGraph.NodeResults; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * If the {@link ASLGraph.Output} of the expression is not a {@link ASLGraph.JsonPath} or {@link ASLGraph.LiteralValue}, it will be normalized into one. * * * If the output is a {@link ASLGraph.LiteralValue}, the output is returned as is. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned as is. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. * * @param expr - Expression to evaluate. * @param handler - A handler callback which received the {@link ASLGraph.Output} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExprToJsonPathOrLiteral(expr: Expr, handler: EvalExprHandler): ASLGraph.NodeResults; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * * Any states generated from the original expression or contextual helper functions in {@link handler} * will be merged into a single {@link ASLGraph.NodeResults} object at the end. * * If the {@link ASLGraph.Output} of the expression is not a {@link ASLGraph.JsonPath} or {@link ASLGraph.LiteralValue}, it will be normalized into one. * * * If the output is a {@link ASLGraph.LiteralValue}, the output is returned as is. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned as is. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. * * @param expr - Expression to evaluate. * @param contextNode - Optional node to associate with the output state. This node may be used to name the resulting state. * Otherwise expr is used. * @param handler - A handler callback which received the {@link ASLGraph.Output} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. * An `addState` callback is also provided to inject additional states into the graph. * The state will be joined (@see ASLGraph.joinSubStates ) with the previous and next states in the order received. */ evalExprToJsonPathOrLiteral(expr: Expr, contextNode: FunctionlessNode, handler: EvalExprHandler): ASLGraph.NodeResults; /** * Recursively evaluate a single expression, building a single {@link ASLGraph.NodeResults} object. * All SubStates generated during evaluation will be merged into a {@link ASLGraph.SubState}. * * @param expr - Expression to evaluate. * @param handler - A handler callback which receives the {@link ASLGraph.Output} resolved from the expression. * This output will represent the constant or variable representing the output of the expression. */ private evalExprToSubState; /** * evalExpr* functions provide a stateful closure that simplifies the evaluation * of an expression into {@link ASLGraph} states and {@link ASLGraph.Output}s. * * Unlike {@link eval} which requires manually joining of states, evalExpr* methods * maintain an array of that that we joined together at the end. They reduce control, * but reduce the work to generate valid ASLGraphs. */ private evalExprBase; /** * Returns the states required to normalize any {@link ASLGraph.Output} into a {@link ASLGraph.JsonPath}. * * * If the output was a {@link ASLGraph.LiteralValue}, a new state will be added that turns the literal into a json path. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ private normalizeOutputToJsonPath; /** * returns the states required to normalize a {@link ASLGraph.Output} into a {@link ASLGraph.JsonPath} or {@link ASLGraph.LiteralValue}. * * * If the output is a {@link ASLGraph.LiteralValue}, the output is returned as is. * * If the output was a {@link ASLGraph.JsonPath}, the output is returned as is. * * If the output was a {@link ASLGraph.ConditionOutput}, a new {@link Choice} state will turn the conditional into a boolean * and return a {@link ASLGraph.JsonPath}. */ private normalizeOutputToJsonPathOrLiteralValue; /** * Provides a contextual `evalExpr` and `evalCondition` functions to the handler provided. * Any SubStates generated using the provided functions will be joined into a single {@link ASLGraph.OutputSubState} * with the output of the handler. * * All SubStates generated during evaluation will be merged into a {@link ASLGraph.OutputSubState} along with the output * of the handler callback. * * @param expr - Expression to evaluate. * @param contextNode - Optional node to associate with the output state. This node may be used to name the resulting state. * Otherwise expr is used. * @param handler - A handler callback which receives the contextual `evalExpr` function. The out of this handler will be * joined with any SubStates created from the `evalExpr` function. */ evalContext(contextNode: FunctionlessNode | undefined, handler: EvalContextHandler): T; /** * Internal method similar to {@link evalContext}. * * Unlike {@link evalContext}, this method does not return an output with the State or SubState. * * Used by the {@link evalStmt} cases which do not need an output (the output is determined by the stmt). * * @see evalContext for more details. */ private evalContextToSubState; /** * Base logic shared by {@link evalContext} and {@link evalContextToSubState}. * * @see evalContext for more details. */ private evalContextBase; /** * Evaluate an {@link Expr} to a single {@link State}. * * Method is private. External consumers should use use {@link evalContext} or {@link evalExpr}. * * @param expr the {@link Expr} to evaluate. * @param allowUndefined - when true, does not fail on undefined values. The resulting output literal may contain `value: undefined`. * @returns the {@link ASLGraph.Output} generated by an expression or an {@link ASLGraph.OutputSubState} with additional states and outputs. */ private eval; /** * Returns an object containing Pass/Task parameters values to clone the current lexical scope into * another scope, like a Map state. * * ```ts * { * 'a.$': '$.a' * } * ``` */ cloneLexicalScopeParameters(node: FunctionlessNode): Record; /** * Evaluates any expression to a string. * * https://262.ecma-international.org/5.1/#sec-9.8 */ evalToString(expr?: Expr): ASLGraph.NodeResults; /** * Implements the logic of unary `-` on an expression. * * First the value is converted to a number and then it is negated. */ negateExpr(expr: Expr): ASLGraph.LiteralValue | (ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }); /** * Invert the numeric value of a reference. * * Assumes that a jsonPath is a number or null. */ negateJsonPathOrLiteralValue(output: ASLGraph.JsonPath | ASLGraph.LiteralValue, node?: FunctionlessNode): ASLGraph.LiteralValue | (ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }); /** * Evaluates any jsonPath value to a string. * * https://262.ecma-international.org/5.1/#sec-9.8 * * @returns jsonPath: {resultPath}.str * * Caveat: Unlike the ECMA spec, objects and arrays will be stringified with JsonToString. * 1. To avoid the complexity of a recursive array join for arrays. * 2. It is impossible to tell an empty object from an empty array. */ jsonPathValueToString(jsonPath: ASLGraph.JsonPath, resultPath?: string): ASLGraph.OutputSubState; /** * Evaluates any expression to a number. When the number cannot be converted, returns `null`. * * https://262.ecma-international.org/5.1/#sec-9.3 */ evalToNumber(expr?: Expr): (ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }) | ASLGraph.LiteralValue; /** * Evaluates any jsonPath value to a number. * * https://262.ecma-international.org/5.1/#sec-9.3 * * @returns jsonPath: {resultPath}.num */ jsonPathValueToNumber(jsonPath: ASLGraph.JsonPath, resultPath?: string): ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }; plus(leftOut: ASLGraph.JsonPath | ASLGraph.LiteralValue, rightOut: ASLGraph.JsonPath | ASLGraph.LiteralValue, node?: FunctionlessNode): ASLGraph.NodeResults; minus(leftOut: ASLGraph.JsonPath | ASLGraph.LiteralValue, rightOut: ASLGraph.JsonPath | ASLGraph.LiteralValue): ASLGraph.LiteralValue | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: Parameters | undefined; } & { node?: FunctionlessNode | undefined; } & { output: ASLGraph.JsonPath; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: Parameters | undefined; } & { node?: FunctionlessNode | undefined; } & { output: ASLGraph.JsonPath; }) | (ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }); /** * Performs addition on any two value, coercing to a number as needed. */ numericAdd(leftOut: ASLGraph.JsonPath | ASLGraph.LiteralValue, rightOut: ASLGraph.JsonPath | ASLGraph.LiteralValue): ASLGraph.NodeResults; /** * Preforms a string concat on any two values, coercing to a string as needed. */ stringConcat(leftOut: ASLGraph.JsonPath | ASLGraph.LiteralValue, rightOut: ASLGraph.JsonPath | ASLGraph.LiteralValue): ASLGraph.NodeResults; /** * Helper that generates an {@link ASLGraph.OutputState} which returns null. */ stateWithVoidOutput(state: State | ASLGraph.SubState): ASLGraph.OutputSubState | ASLGraph.OutputState; /** * Helper that generates an {@link ASLGraph.OutputState} which returns a value to a temporary location. */ stateWithHeapOutput(state: Exclude, node?: FunctionlessNode): ASLGraph.NodeState & { output: ASLGraph.JsonPath; }; /** * Helper that generates a {@link Pass} state to assign a single jsonPath or intrinsic to * an output location. * * ```ts * assignJsonPathOrIntrinsic("out", "States.Array(1,2,3)"); * ``` * * => * * ```ts * { * "Type": "Pass", * "Parameters": { * "out.$": "State.Array(1,2,3)" * }, * "Next": ASLGraph.DeferNext, * "ResultPath": "$.someTempLocation", * "output": { "jsonPath": "$.someTempLocation.out" } * } * ``` * * @param jsonPathOrIntrinsic - json path (ex: $.var) or instrinsic function (ex: States.Array) to place into the output. */ assignJsonPathOrIntrinsic(jsonPathOrIntrinsic: ASLGraph.IntrinsicFunction | ASLGraph.JsonPath, propertyName?: string, next?: string, node?: FunctionlessNode): ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { Next: string; End?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: Parameters | undefined; } & { node?: FunctionlessNode | undefined; } & { output: ASLGraph.JsonPath; }) | ({ Comment?: string | undefined; InputPath?: string | undefined; OutputPath?: string | undefined; } & { End: true; Next?: undefined; } & { Comment?: string | undefined; Type: "Pass"; Result?: any; ResultPath?: string | null | undefined; Parameters?: Parameters | undefined; } & { node?: FunctionlessNode | undefined; } & { output: ASLGraph.JsonPath; }) | (ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }); /** * When the condition is true, executes the true states and assigns the left output to a temp variable. * When the condition is false, executes the true states and assigns the right out to a temp variable. * * @param trueState - states to execute when the condition is true. Default: returns true * @param falseState - states to execute when the condition is false. Default: returns false * * @returns a {@link ASLGraph.OutputSubState} that executes true when the value is true and false when the value is false. */ conditionState(node: FunctionlessNode | undefined, cond: Condition, trueState?: ASLGraph.NodeResults, falseState?: ASLGraph.NodeResults, outputJsonPath?: string): ASLGraph.OutputSubState & { output: ASLGraph.JsonPath; }; /** * Mutable heap counter. */ private heapCounter; /** * returns an in order unique memory location in the form `$.heap[id]` * TODO: make this contextual - https://github.com/functionless/functionless/issues/321 */ newHeapVariable(): string; /** * returns an in order unique memory location in the form `heap[id]` * TODO: make this contextual - https://github.com/functionless/functionless/issues/321 */ newHeapVariableName(): string; /** * Find the transition edge from this {@link node} to the State which will handle * the error. * * @param node * @returns `undefined` if the error is terminal, otherwise a Next, ResultPath */ throw(node: FunctionlessNode): { /** * Name of the state to transition to. */ Next: string; /** * JSON Path to store the the error payload. */ ResultPath: string | null; } | undefined; /** * Process a `array.slice()` expression and output the jsonPath or constant value. */ private sliceToStateOutput; /** * Turns a call to `.join` on an array into a {@link ASLGraph.SubState}. * * If both the array and the separator argument are constant, just run .join and return the results. * * Otherwise, create a state machine that iterates over all elements of the array at runtime and creates a new * string with the separator between elements. */ private joinToStateOutput; private filterToStateOutput; /** * Attempt to compile filter to JSONPath. If possible, this is the most efficient way to filter. * * When not possible, undefined is returned. */ private filterToJsonPath; /** * filter an array using ASLGraph. Should support any logic that returns a boolean already supported by Functionless Step Functions. * * Note: If possible, try to use {@link filterToJsonPath} as it introduces no new state transitions. */ private filterToASLGraph; private includesToASLGraph; /** * Provides a method to sub-array given any combination of reference or literal. * Step functions/ASL does not allow sub-arraying with dynamic keys, but allows * Static slices (jsonPath) and */ private subArray; private mapToStateOutput; private forEachToStateOutput; /** * Generic, plugable helper for array methods likes map, forEach, and filter. * * Expects a function in the form arr.(item, index, array) => {}; * * `workingSpace` - a state location used by the array method machine. We'll write over this location with the result after. * * 1. init - initializes a working copy of the array, used to tail the array in the `workingSpace` (workingSpace.arr) * 1. [optional] - user provided parameter values to initialize the `workingSpace` * 2. check - check if the tailed array (`workingSpace.arr`) has more items. * 1. If yes, go to next, else go to `end` state. * 3. assignParameters - setup the current item, index, and array parameters, including handling any binding. Only if the parameter is defined by the program. * 4. body - execute the body of the function, with any return values going to the `iterationResultJsonPath` * 5. handle result - optional - optionally handle the result and customize the tail operation. Often the tail and handle logic can be joined together into one state. * 6. tail - if tail was not bypassed in the handle result step, update the `workingSpace.arr` to the tail of the array `workingSpace.arr[1:]`. * 7. check - return to the check state * 8. end - once the array is empty, execute the end state provided by the caller. Generally writing the result to the `workingSpace` location. */ private iterateArrayMethod; /** * We're indexing the array we're iterating over with the key. For this special case, we know that * the value points to `$$.Map.Item.Value`. * * In the below example: * 1. the value of `$$.Map.Item.Index` is stashed in `$.i` (as expected) * 2. the value of `$$.Map.Item.Value` is stashed in `$.0_i`. Special `0_` prefix is impossible * to produce with TypeScript syntax and is therefore safe to use a prefix to store the hidden value. * * ```ts * for (const i in items) { * const a = items[i] * { * Type: Pass * ResultPath: $.a * InputPath: "$.0_i" * } * } * ``` */ private elementAccessExprToJsonPath; /** * Attempts to access the length property on an array or a reference that maybe an array, * returns undefined when it cannot do so. */ private accessLengthProperty; private arrayLength; /** * Provides states that attempt to disambiguate an array and object at runtime. * * is array of length 1 => arr * has prop hint => obj * stringify * is [] => arr * => obj * * @param propertyHint - a property that is expected to exist if the value is an object. * @param arrayOrObjectReference - a json path that may be an array or object * @param whenArray - the state(s) to execute when we think the value is an array * @param whenObject - the state(s) to execute when we think the value is an object * @param resultPath - the json path both `whenObject` and `whenArray` output to. * @param canAssignResultPath - when true, the machine may assign a temporary value to the result path * Do not set to `true` this if the result path may need to be used by the array/object states * or the result path is not assigned over later. */ private disambiguateArrayObject; /** * Asserts that an {@link ASLGraph.Output} is a constant and is a number or string. * * Element access in StepFunctions must be constant because dynamic object is not supported. */ private getElementAccessConstant; /** * In some cases, variable can be batch declared as state parameters. * This method is an alternative to {@link evalDecl} which can evaluate multiple {@link ParameterDecl}s * with initial values into a parameter object and any state to be run after (which setup any bound variables.) * * Parameter with identifier names become State Parameter keys * * `(input) => {}` * -> * ```ts * { * Type: "Pass", // or Task, Name, etc * Parameters: { * "input.$": jsonPath * } * } * ``` * * `({ value }) => {}` * -> * ```ts * { * Type: "Pass", * InputPath: jsonPath, * ResultPath: "$.value" * } * ``` * * A Parameter object will be more efficient as multiple values can be bound in a single State rather than multiple passes. * * However: * 1. a State Parameter object can only override the entire state, it cannot update or add a subset of all variable names. * 2. a State Parameter object only supports json path computation. Complex situations like invoking an {@link Integration} or * default value support for binding patterns would not be supported. * * @returns a tuple of * 1. a {@link Parameters} object intended to be used in the Parameters or ResultSelector of a state. * Contains the initialized parameter names. Could be empty. * 2. a state or sub-state used to generate the bound names. May be undefined. */ evalParameterDeclForStateParameter(node: FunctionlessNode, ...parameters: ASL.EvalParameterDeclEntry[]): [ Record, ASLGraph.NodeState | ASLGraph.SubState | undefined ]; evalDecl(decl: VariableDecl | ParameterDecl, initialValue?: ASLGraph.Output): ASLGraph.SubState | ASLGraph.NodeState | undefined; /** * Generic handler for any type of assignment with either an identifier or a binding pattern (deconstruction). * * Nested BindPatterns are handled recursively. * * const x = 1; * => * const x = 1; * * const { x } = y; * => * const x = y.x; * * const { x } = { x: 1 }; * => * const x = 1; * * const { x = 1 } = y; * => * const x = y.x === undefined ? 1 : y.x; * * const { x = 1 } = {}; * => * const x = 1; * * const { x: { z } } = y; * => * const z = y.x.z; * * const { x, ...rest } = y; * => * INVALID - rest is unsupported in objects because ASL doesn't support object manipulation (ex: delete) or field enumeration (ex: keySet). * * const [x] = arr; * => * const x = arr[0]; * * const [,x] = arr; * => * const x = arr[1]; * * const [x,...rest] = arr; * => * const x = arr[0]; * const rest = arr.slice(1); */ private evalAssignment; /** * Assigns an {@link ASLGraph.Output} to a jsonPath variable. * * If the {@link value} is a {@link ASLGraph.ConditionOutput}, states are added to turn * the condition into a boolean value. */ private assignValue; /** * Given an output value (json path, literal, or condition) and an expression to compute a default value, * return a possibly updated output value which will contain the default value if the initial value is undefined. * * `return value === undefined ? defaultValue : value;` */ private applyDefaultValue; /** * Zip an array with it's index. * * In ASL, it is not possible to do arithmetic or get the length of an array, but * the map state does give us the index. * * @param formatIndex allows the optional formatting of the index number, for example, turning it into a string. * @returns a partial map state that results in an array of { index: number, item: arrayElement[index] }. */ private zipArray; } export declare function isForEach(expr: CallExpr): expr is CallExpr & { expr: PropAccessExpr; }; export declare function isMap(expr: CallExpr): expr is CallExpr & { expr: PropAccessExpr; }; export declare namespace ASL { interface EvalParameterDeclEntry { parameter: (ParameterDecl & { name: Name; }) | undefined; valuePath: ASLGraph.JsonPath; /** * When true and the parameter requires states outside of the Parameter object, * a new name will created in the Parameter object and assigned the valuePath. * * This is useful for Map states where the $$.Map.Item.* values * are not present inside of the map states. */ reassignBoundParameters?: boolean; } function isTruthy(v: string): Condition; function and(...cond: (Condition | undefined)[]): Condition; function or(...cond: (Condition | undefined)[]): Condition; function not(cond: Condition): Condition; function isPresent(Variable: string): Condition; function isNotPresent(Variable: string): Condition; function isNull(Variable: string): Condition; function isNotNull(Variable: string): Condition; function isBoolean(Variable: string): Condition; function isString(Variable: string): Condition; function isNumeric(Variable: string): Condition; function isPresentAndNotNull(Variable: string): Condition; function stringEqualsPath(Variable: string, path: string): Condition; function stringEquals(Variable: string, string: string): Condition; function numericEqualsPath(Variable: string, path: string): Condition; function numericEquals(Variable: string, number: number): Condition; function numericLessThan(Variable: string, number: number): Condition; function numericLessThanPath(Variable: string, path: string): Condition; function numericGreaterThanEquals(Variable: string, number: number): Condition; function booleanEqualsPath(Variable: string, path: string): Condition; function booleanEquals(Variable: string, value: boolean): Condition; /** * Supported comparison operators. * * Note: !== and != can be achieved by using {@link ASL.not}. */ type ValueComparisonOperators = "===" | "==" | ">" | ">=" | "<=" | "<" | "!=" | "!=="; const VALUE_COMPARISONS: Record>; function compareValueOfType(Variable: string, operation: keyof typeof VALUE_COMPARISONS, value: string | number | boolean): Condition; function comparePathOfType(Variable: string, operation: keyof typeof VALUE_COMPARISONS, path: string, type: "string" | "number" | "boolean"): Condition; function falseCondition(): Condition; function trueCondition(): Condition; } export declare const deploymentOnlyModule = true; export {}; //# sourceMappingURL=synth.d.ts.map