Skip to content

Commit

Permalink
feat(stepfunctions): add support JSONata and variables (#32343)
Browse files Browse the repository at this point in the history
### Issue #32262 

Closes #32262.

### Reason for this change


For to use JSONata and variables of Step Function feature on AWS CDK. JSONata is new query language of Step Function, It is simple and powerful language. JSONata and variables is recommend for new state machine.

### Description of changes

#### JSONata support
Add `jsonPath()` and `jsonata()` factory methods to state constructs.  For example,

```ts
// For JSONPath
sfn.Pass.jsonPath(stack, "JSONPathPass", {
    outputPath: sfn.JsonPath.stringAt('$foo'),
});

// For JSONata
sfn.Pass.jsonata(stack, "JSONataPass", {
    outputs: {
        count: "{% $states.input.count + 1 %}"
    },
});
```

One option would be to simply add JSONata-specific properties to the Props of the existing State construct, but in this case, the JSONata-specific properties will be displayed to the JSONPath user. Conversely, it was thought that the development experience would deteriorate if JSONata users were shown JSONPath-specific properties. As a countermeasure, we decomposed the existing Props into JSONPath-specific properties and created `jsonPath()` and `jsonata()` factory methods to separate type suggestions for JSONPath users and JSONata users.

The existing initialization method, the constructor, is backward compatible because it accepts `JSONPath` and `JSONata `properties. However, to use this interface directly is a lot of noise. This noise is a source of confusion for SFn beginners, and I thought it was necessary to solve this problem.
![image](https://github.com/user-attachments/assets/ac7ffade-e601-44c7-a76c-064f3dce5e9e)

Therefore, we use the factory methods for each query language.  
※ The `output` property is used in the image example, but it is actually `outputs`. Check out [this comment](#32343 (comment)) for the reasons for this decision.

`jsonPath()` does not have a JSONata-specific property `outputs`.
![image](https://github.com/user-attachments/assets/d3ee9ff1-9a7e-4c9d-bb85-ffd9e1b4a7f1)

`jsonata()` does not have JSONPath-specific properties such as `xxxPath`.
![image](https://github.com/user-attachments/assets/f466ba1a-9bef-4d4f-944c-cdf544b1965b)

#### Variables

Add `assign` to state constructs.  `assign` can be used from either `JSONata` or `JSONPath`.


For example,

```ts
sfn.Pass.jsonata(this, 'AssignExamplePass', {
  assign: {
     count: "{% $states.input.count + 1 %}"
  },
});
```

### Description of how you validated changes

Added unit test. Integration tests are not yet.


### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
WinterYukky authored Feb 1, 2025
1 parent 9ae1d34 commit 0bb3d6f
Show file tree
Hide file tree
Showing 180 changed files with 167,849 additions and 897 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0bb3d6f

Please sign in to comment.