-
Notifications
You must be signed in to change notification settings - Fork 30
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: support new fields for variables #162
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Comment": "QueryLanguage is JSONata but has JSONPath fields", | ||
"StartAt": "EmptyState", | ||
"QueryLanguage": "JSONata", | ||
"States": { | ||
"EmptyState": { | ||
"Type": "Pass", | ||
"Parameters": ["abc"], | ||
"ResultPath": "$.emptyState", | ||
"End": true | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/__tests__/definitions/invalid-jsonata-path-fields.asl.json
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"Comment": "Incorrectly has JSONPath fields on JSONata states", | ||
"StartAt": "Verification", | ||
"States": { | ||
"Verification": { | ||
"Type": "Parallel", | ||
"QueryLanguage": "JSONata", | ||
"Branches": [ | ||
{ | ||
"StartAt": "Check Identity", | ||
"States": { | ||
"Check Identity": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"OutputPath": "$.foo" | ||
} | ||
} | ||
}, | ||
{ | ||
"StartAt": "Check Address", | ||
"States": { | ||
"Check Address": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isAddressValid": "{% $not(null in $each($states.input.data.address, function($v) { $length($trim($v)) > 0 ? $v : null })) %}" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"Assign": { | ||
"inputPayload": "{% $states.context.Execution.Input %}", | ||
"isCustomerValid": "{% $states.result.isIdentityValid and $states.result.isAddressValid %}" | ||
}, | ||
"Next": "Approve or Deny?" | ||
}, | ||
"Approve or Deny?": { | ||
"Type": "Choice", | ||
"QueryLanguage": "JSONata", | ||
"Choices": [ | ||
{ | ||
"Next": "Add Account", | ||
"Condition": "{% $isCustomerValid %}" | ||
} | ||
], | ||
"Default": "Deny Message" | ||
}, | ||
"Add Account": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::dynamodb:putItem", | ||
"Arguments": { | ||
"TableName": "${AccountsTable}", | ||
"Item": { | ||
"PK": { | ||
"S": "{% $uuid() %}" | ||
}, | ||
"email": { | ||
"S": "{% $inputPayload.data.identity.email %}" | ||
}, | ||
"name": { | ||
"S": "{% $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname %}" | ||
}, | ||
"address": { | ||
"S": "{% $join($each($inputPayload.data.address, function($v) { $v }), ', ') %}" | ||
}, | ||
"timestamp": { | ||
"S": "{% $now() %}" | ||
} | ||
} | ||
}, | ||
"Next": "Home Insurance Interests" | ||
}, | ||
"Home Insurance Interests": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::sqs:sendMessage", | ||
"Arguments": { | ||
"QueueUrl": "${HomeInsuranceInterestQueueArn}", | ||
"MessageBody": "{% ($e := $inputPayload.data.identity.email; $n := $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname; $inputPayload.data.interests[category = 'home']{'customer': $n, 'email': $e, 'totalAssetValue': $sum(estimatedValue), category: {type: yearBuilt}}) %}" | ||
}, | ||
"Next": "Approved Message" | ||
}, | ||
"Approved Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "arn:aws:sns:us-east-1:123456789012:CustomerNotifications", | ||
"Message.$": "States.Format('Hello {}, your application has been approved.', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
}, | ||
"Deny Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "${SendCustomerNotificationSNSTopicArn}", | ||
"Message.$": "States.Format('Hello {}, your application has been denied because validation of provided data failed', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/__tests__/definitions/invalid-variable-result-path.json
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Comment": "ResultPath cannot contain a variable", | ||
"StartAt": "StepOne", | ||
"States": { | ||
"StepOne": { | ||
"Type": "Pass", | ||
"Assign": { | ||
"foo": "bar" | ||
}, | ||
"Next": "Fin" | ||
}, | ||
"Fin": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:lambda:region-1:1234567890:function:InvalidResultPath", | ||
"ResultPath": "$foo", | ||
"End": true | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"Comment": "This is a state machine for account application service", | ||
"StartAt": "Verification", | ||
"States": { | ||
"Verification": { | ||
"Type": "Parallel", | ||
"QueryLanguage": "JSONata", | ||
"Branches": [ | ||
{ | ||
"StartAt": "Check Identity", | ||
"States": { | ||
"Check Identity": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isIdentityValid": "{% $match($states.input.data.identity.email, /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/) and $match($states.input.data.identity.ssn, /^(\\d{3}-?\\d{2}-?\\d{4}|XXX-XX-XXXX)$/) %}" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"StartAt": "Check Address", | ||
"States": { | ||
"Check Address": { | ||
"Type": "Pass", | ||
"QueryLanguage": "JSONata", | ||
"End": true, | ||
"Output": { | ||
"isAddressValid": "{% $not(null in $each($states.input.data.address, function($v) { $length($trim($v)) > 0 ? $v : null })) %}" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"Assign": { | ||
"inputPayload": "{% $states.context.Execution.Input %}", | ||
"isCustomerValid": "{% $states.result.isIdentityValid and $states.result.isAddressValid %}" | ||
}, | ||
"Next": "Approve or Deny?" | ||
}, | ||
"Approve or Deny?": { | ||
"Type": "Choice", | ||
"QueryLanguage": "JSONata", | ||
"Choices": [ | ||
{ | ||
"Next": "Add Account", | ||
"Condition": "{% $isCustomerValid %}" | ||
} | ||
], | ||
"Default": "Deny Message" | ||
}, | ||
"Add Account": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::dynamodb:putItem", | ||
"Arguments": { | ||
"TableName": "${AccountsTable}", | ||
"Item": { | ||
"PK": { | ||
"S": "{% $uuid() %}" | ||
}, | ||
"email": { | ||
"S": "{% $inputPayload.data.identity.email %}" | ||
}, | ||
"name": { | ||
"S": "{% $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname %}" | ||
}, | ||
"address": { | ||
"S": "{% $join($each($inputPayload.data.address, function($v) { $v }), ', ') %}" | ||
}, | ||
"timestamp": { | ||
"S": "{% $now() %}" | ||
} | ||
} | ||
}, | ||
"Next": "Home Insurance Interests" | ||
}, | ||
"Home Insurance Interests": { | ||
"Type": "Task", | ||
"QueryLanguage": "JSONata", | ||
"Resource": "arn:aws:states:::sqs:sendMessage", | ||
"Arguments": { | ||
"QueueUrl": "${HomeInsuranceInterestQueueArn}", | ||
"MessageBody": "{% ($e := $inputPayload.data.identity.email; $n := $inputPayload.data.firstname & ' ' & $inputPayload.data.lastname; $inputPayload.data.interests[category = 'home']{'customer': $n, 'email': $e, 'totalAssetValue': $sum(estimatedValue), category: {type: yearBuilt}}) %}" | ||
}, | ||
"Next": "Approved Message" | ||
}, | ||
"Approved Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "arn:aws:sns:us-east-1:123456789012:CustomerNotifications", | ||
"Message.$": "States.Format('Hello {}, your application has been approved.', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
}, | ||
"Deny Message": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"TopicArn": "${SendCustomerNotificationSNSTopicArn}", | ||
"Message.$": "States.Format('Hello {}, your application has been denied because validation of provided data failed', $inputPayload.data.firstname)" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
new version supports variables in JSONPath expressions and also adds a new format type for
ResultPath
fields which areReferencePath
expressions but cannot contain variables.