feat(step-functions): support and utilize new intrinsics#468
Conversation
✅ Deploy Preview for effortless-malabi-1c3e77 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
…nto sussman/sfn_new_intrinsics
src/step-function.ts
Outdated
| * @param | ||
| */ | ||
| export const range = makeStepFunctionIntegration< | ||
| "SFN.Range", |
There was a problem hiding this comment.
Should this be States.Range? To match the intrinsic name?
There was a problem hiding this comment.
Though I am not using the full names of the intrinsics. (ArrayRange => Range) because "array" is covered by the type.
src/step-function.ts
Outdated
| >("SFN.Base64Encode", { | ||
| asl(call, context) { | ||
| const [data] = call.args; | ||
|
|
||
| if (!data) { | ||
| throw new SynthError( | ||
| ErrorCodes.Invalid_Input, | ||
| "Expected Base64 data argument to be provided." | ||
| ); | ||
| } | ||
|
|
||
| return context.evalContext(call, ({ evalExprToJsonPathOrLiteral }) => { | ||
| const dataOut = evalExprToJsonPathOrLiteral(data.expr); | ||
|
|
||
| if ( | ||
| ASLGraph.isLiteralValue(dataOut) && | ||
| typeof dataOut.value !== "string" | ||
| ) { | ||
| throw new SynthError( | ||
| ErrorCodes.Invalid_Input, | ||
| "Expected base64Encode data argument to be a string or reference." | ||
| ); | ||
| } | ||
| const temp = context.newHeapVariable(); | ||
| return { | ||
| Type: "Pass", | ||
| Parameters: { | ||
| "out.$": `States.Base64Encode(${ | ||
| ASLGraph.isJsonPath(dataOut) | ||
| ? dataOut.jsonPath | ||
| : `'${dataOut.value}'` | ||
| })`, | ||
| }, | ||
| ResultPath: temp, | ||
| Next: ASLGraph.DeferNext, | ||
| output: { | ||
| jsonPath: `${temp}.out`, | ||
| }, | ||
| }; | ||
| }); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
I wonder if there is anyway to simplify these new intrinsic. They seem to have a lot of code in common. Thoughts?
There was a problem hiding this comment.
Created a helper to assign a single parameter key and output it. Was applicable in many places.
test/localstack.ts
Outdated
| credentials: clientConfig.credentials, | ||
| }; | ||
| sdkProvider.sdkOptions = { | ||
| // @ts-ignore |
| (parent) => { | ||
| return new StepFunction(parent, "sfn", async () => { | ||
| const odd = $SFN | ||
| .range(1, 11, 2) |
There was a problem hiding this comment.
Yes. Will add more to the test.
Signed-off-by: github-actions <github-actions@github.com>
sam-goodwin
left a comment
There was a problem hiding this comment.
Oops, forgot to send these comments through lol
src/asl/synth.ts
Outdated
| ResultPath: `$.${errorVariableName}`, | ||
| }, | ||
| ASLGraph.assignJsonPathOrIntrinsic( | ||
| `States.StringToJson($.${errorVariableName}.Cause)`, |
There was a problem hiding this comment.
Should this be using one of the ASLGrapj.intrinscStringToJson calls?
There was a problem hiding this comment.
Yep! My plan was to sweep through and update the whole code base to use these helpers after this change. Tried to get all of the intrinsics added in this change, but the helpers came much later than some of the other changes. Will clean up.
There was a problem hiding this comment.
Updated most of them now
src/asl/synth.ts
Outdated
| // postfix | ||
| // assign left to heap | ||
| // mutate left | ||
| // assign left | ||
| // return heap |
There was a problem hiding this comment.
Not sure what to do with these comments.
There was a problem hiding this comment.
ha, just me trying to figure out the logic...
src/asl/synth.ts
Outdated
| if (ASLGraph.isLiteralValue(left)) { | ||
| if ( | ||
| ASLGraph.isLiteralString(left) || | ||
| ASLGraph.isLiteralNumber(left) | ||
| ) { | ||
| return ASLGraph.isLiteralValue(right) | ||
| ? { | ||
| value: | ||
| right.value && | ||
| typeof right.value === "object" && | ||
| left.value in right.value, | ||
| containsJsonPath: false, | ||
| } |
There was a problem hiding this comment.
Going to need some comments.
src/error-code.ts
Outdated
| * Step Functions Arithmetic Only Supports Integer | ||
| * | ||
| * Step Functions only supports integer addition via the `States.MathAdd`. | ||
| * | ||
| * ```ts | ||
| * new StepFunction(stack, "sfn", async (input: { a: number }) => { | ||
| * return 1.5 + input.a; | ||
| * }); | ||
| * ``` | ||
| * | ||
| * If the above machine is given input: `{ a: 0.5 }`, the result will be `1`. | ||
| * | ||
| * Effectively resulting in: `Math.floor(1.5) + Math.floor(0.5)` => `1` |
There was a problem hiding this comment.
I think this can be described more simply.
Step Functions can only add integers. When adding floating point numbers, the service will floor each of the numbers before adding them.
1.5 + 1.5 = 2
src/validate.ts
Outdated
| return [ | ||
| newError( | ||
| node, | ||
| ErrorCodes.Cannot_perform_arithmetic_or_bitwise_computations_on_variables_in_Step_Function |
There was a problem hiding this comment.
Did we update this error code with the new addition change?
There was a problem hiding this comment.
the logic, forgot about the text.
Signed-off-by: github-actions <github-actions@github.com>
…nto sussman/sfn_new_intrinsics
…ionless/functionless into sussman/sfn_new_intrinsics
Signed-off-by: github-actions <github-actions@github.com>
Signed-off-by: github-actions <github-actions@github.com>
…ionless/functionless into sussman/sfn_new_intrinsics
…functionless into sussman/build_perf
Signed-off-by: github-actions <github-actions@github.com>
|
Is this ready? Looks good to me |
|
Missed the approve and it was witting on #510, will push soon. |

Depends on #510
Closes #77 Closes #282 Closes #330 Closes #395
+=,+,-,-=,--,++Note: new intrinsics are not supported by localstack yet.