New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stepfunctions): add intrinsic functions #22431
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5a2a405
refactor
gkkachi 09421ac
Add missing intrinsic functions
gkkachi 1b16891
Update readme
gkkachi ab29124
Add integration test
gkkachi 926c938
Remove unnecessary comments
gkkachi d32fbf3
Add test for `renderInExpression`
gkkachi d2ff6e1
Add an assertion for the integ test
gkkachi ea3e9f1
Merge remote-tracking branch 'upstream/main'
gkkachi 452e251
Fix lint errors
gkkachi 27a909b
Merge branch 'main' into main
TheRealAmazonKendra 8d337cf
Merge branch 'main' into main
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,17 +312,22 @@ function pathFromToken(token: IResolvable | undefined) { | |
} | ||
|
||
/** | ||
* Render the string in a valid JSON Path expression. | ||
* Render the string or number value in a valid JSON Path expression. | ||
* | ||
* If the string is a Tokenized JSON path reference -- return the JSON path reference inside it. | ||
* Otherwise, single-quote it. | ||
* If the value is a Tokenized JSON path reference -- return the JSON path reference inside it. | ||
* If the value is a number -- convert it to string. | ||
* If the value is a string -- single-quote it. | ||
* Otherwise, throw errors. | ||
* | ||
* Call this function whenever you're building compound JSONPath expressions, in | ||
* order to avoid having tokens-in-tokens-in-tokens which become very hard to parse. | ||
*/ | ||
export function renderInExpression(x: string) { | ||
const path = jsonPathString(x); | ||
return path ?? singleQuotestring(x); | ||
export function renderInExpression(x: any) { | ||
const path = jsonPathFromAny(x); | ||
if (path) return path; | ||
if (typeof x === 'number') return x.toString(10); | ||
if (typeof x === 'string') return singleQuotestring(x); | ||
throw new Error('Unxexpected value.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra x in unexpected |
||
} | ||
|
||
function singleQuotestring(x: string) { | ||
|
@@ -341,4 +346,4 @@ function singleQuotestring(x: string) { | |
} | ||
ret.push("'"); | ||
return ret.join(''); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than throwing an error here for other types and accepting any, x should be typed to the specific valid types:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderInExpression
can receivestring[]
here, so it should at least acceptstring[]
. (Note thatlistAt
returnsstring[]
. )We could restrict the input type by creating another function like
renderListInExpression
, but I think it is not necessary because the function is a "private" function.https://github.com/gkkachi/aws-cdk/blob/ab29124d26cf8a21a1399b0193122c7b8419d00d/packages/%40aws-cdk/aws-stepfunctions/lib/fields.ts#L113-L115
https://github.com/gkkachi/aws-cdk/blob/ab29124d26cf8a21a1399b0193122c7b8419d00d/packages/%40aws-cdk/aws-stepfunctions/test/fields.test.ts#L241
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it can accept string[], the logic isn't quite right, then. You throw an error if it's not string or number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please write tests against the various input types you'd expect here and at least one failure case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote tests for
renderInExpression
. d32fbf3