Skip to content

Commit

Permalink
feat: add check for map with parameters and itemselector (#128)
Browse files Browse the repository at this point in the history
refactor: replace map one of with checker
  • Loading branch information
massfords authored Feb 17, 2023
1 parent 28f5065 commit 3400275
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/__tests__/error-reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ describe("tests with definitions containing errors to see what's reported", () =
const definition = JSON.parse(fs.readFileSync(path.join(__dirname, 'definitions', input.file), "utf-8")) as StateMachine;
const {isValid, errors} = validator(definition);
expect(isValid).toBe(false);
expect(errors).toHaveLength(input.expected_errors.length);
expect(errors).toStrictEqual(input.expected_errors)
expect(errors.splice(0,1)).toStrictEqual(input.expected_errors)
});

});
25 changes: 25 additions & 0 deletions src/checks/mapChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {AslChecker, StateMachineErrorCode} from "../types";
import {checkPropertyWorkflow} from "./checkProperty";

export const mapChecks: AslChecker = (definition) => {
return [
...checkPropertyWorkflow({
definition,
filter: ({state}) => {
return state.Type === 'Map'
},
propCheck: 'exactlyOne',
props: ["ItemProcessor", "Iterator"],
errorCode: StateMachineErrorCode.MapItemProcessorError,
}),
...checkPropertyWorkflow({
definition,
filter: ({state}) => {
return state.Type === 'Map'
},
propCheck: 'atMostOne',
props: ["ItemSelector", "Parameters"],
errorCode: StateMachineErrorCode.MapItemSelectorError,
}),
]
}
12 changes: 0 additions & 12 deletions src/schemas/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@
}
}
},
"oneOf": [
{
"required": [
"ItemProcessor"
]
},
{
"required": [
"Iterator"
]
}
],
"required": ["Type"],
"additionalProperties": false
}
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export enum StateMachineErrorCode {
WaitDurationError = 'WAIT_DURATION',
TaskTimeoutError = 'TASK_TIMEOUT',
TaskHeartbeatError = 'TASK_HEARTBEAT',
MapItemProcessorError = 'MAP_ITEM_PROCESSOR',
MapItemSelectorError = 'MAP_ITEM_SELECTOR'
}
export type StateMachineError = {
'Error code': StateMachineErrorCode;
Expand Down
2 changes: 2 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {mustNotHaveDuplicateFieldNamesAfterEvaluation} from "./checks/duplicate-
import {terminalStateWithNext} from "./checks/terminalStateWithNext";
import {waitDuration} from "./checks/waitDuration";
import {taskChecks} from "./checks/taskChecks";
import {mapChecks} from "./checks/mapChecks";

const DefaultOptions: ValidationOptions = {
checkPaths: true,
Expand All @@ -32,6 +33,7 @@ export = function validator(definition: StateMachine, opts?: ValidationOptions):
errors.push(...terminalStateWithNext(definition, options));
errors.push(...waitDuration(definition, options));
errors.push(...taskChecks(definition, options));
errors.push(...mapChecks(definition, options));
}

return {
Expand Down

0 comments on commit 3400275

Please sign in to comment.