Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/__tests__/definitions/invalid-map-items.asl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"QueryLanguage": "JSONata",
"Comment": "Items and ItemsPath are mutually exclusive in Map state.",
"StartAt": "SetupAnimals",
"States": {
"SetupAnimals": {
"Type": "Pass",
"Output": {
"animals": ["Lion", "Cheetah", "Elephant"]
},
"Next": "ProcessAnimals"
},
"ProcessAnimals": {
"Type": "Map",
"Items": "{% $states.input.animals %}",
"ItemsPath": "$.foo",
"ItemSelector": {
"animalName": "{% $states.context.Map.Item.Value %}"
},
"ItemProcessor": {
"StartAt": "NoOp",
"States": {
"NoOp": {
"Type": "Pass",
"End": true
}
}
},
"Output": {
"processResults": "{% $states.result %}"
},
"End": true
}
}
}
34 changes: 34 additions & 0 deletions src/__tests__/definitions/valid-map-items.asl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"QueryLanguage": "JSONata",
"Comment": "A test for valid map items in JSONata",
"StartAt": "SetupAnimals",
"States": {
"SetupAnimals": {
"Type": "Pass",
"Output": {
"animals": ["Lion", "Cheetah", "Elephant"]
},
"Next": "ProcessAnimals"
},
"ProcessAnimals": {
"Type": "Map",
"Items": "{% $states.input.animals %}",
"ItemSelector": {
"animalName": "{% $states.context.Map.Item.Value %}"
},
"ItemProcessor": {
"StartAt": "NoOp",
"States": {
"NoOp": {
"Type": "Pass",
"End": true
}
}
},
"Output": {
"processResults": "{% $states.result %}"
},
"End": true
}
}
}
16 changes: 16 additions & 0 deletions src/__tests__/definitions/valid-wait-jsonata.asl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"QueryLanguage": "JSONata",
"StartAt": "SetupWait",
"States": {
"SetupWait": {
"Type": "Pass",
"Next": "DoWait",
"Output": { "waitTime": "{% $round($random() * 10) %}" }
},
"DoWait": {
"Type": "Wait",
"Seconds": "{% $states.input.waitTime %}",
"End": true
}
}
}
3 changes: 3 additions & 0 deletions src/schemas/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"ResultPath": {
"$ref": "paths.json#/definitions/asl_result_path"
},
"Items": {
"type": ["array", "string"]
},
"ItemsPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
},
Expand Down
11 changes: 9 additions & 2 deletions src/schemas/wait.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
"$ref": "paths.json#/definitions/asl_path"
},
"Seconds": {
"type": "number",
"minimum": 0
"oneOf": [
{
"type": "number",
"minimum": 0
},
{
"type": "string"
}
]
},
"Timestamp": {
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum StateMachineErrorCode {
WaitDurationError = "WAIT_DURATION",
TaskTimeoutError = "TASK_TIMEOUT",
TaskHeartbeatError = "TASK_HEARTBEAT",
MapItemsError = "MAP_ITEMS_ERROR",
MapItemProcessorError = "MAP_ITEM_PROCESSOR",
MapItemSelectorError = "MAP_ITEM_SELECTOR",
MapItemBatcherError = "MAP_ITEM_BATCHER",
Expand Down
7 changes: 7 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ export = function validator(
errorCode: StateMachineErrorCode.MapMaxConcurrencyError,
}),
},
{
filter: IsMap,
checker: AtMostOne({
props: ["Items", "ItemsPath"],
errorCode: StateMachineErrorCode.MapItemsError,
}),
},
{
filter: IsMap,
checker: AtMostOne({
Expand Down