asl-validator
Version:
Amazon States Language validator
34 lines (33 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.missingTransitionTargetErrors = void 0;
var jsonpath_plus_1 = require("jsonpath-plus");
var types_1 = require("../types");
var missingTransitionTargetErrors = function (definition) {
// retrieve all states
var machineStates = [];
(0, jsonpath_plus_1.JSONPath)({ json: definition, path: "$..States" }).forEach(function (s) {
machineStates = machineStates.concat(Object.keys(s));
});
// retrieve all reachable states
var reachableStates = (0, jsonpath_plus_1.JSONPath)({
json: definition,
path: "$..[StartAt,Next,Default]",
}).filter(function (path, pos, array) { return array.indexOf(path) === pos; });
// check if all states are reachable
var unreachable = machineStates
.filter(function (state) { return reachableStates.indexOf(state) === -1; })
.map(function (state) { return ({
"Error code": types_1.StateMachineErrorCode.MissingTransitionTarget,
Message: "State ".concat(state, " is not reachable"),
}); });
// check if all 'Next', 'StartAt' and 'Default' states exist
var inexistant = reachableStates
.filter(function (state) { return machineStates.indexOf(state) === -1; })
.map(function (state) { return ({
"Error code": types_1.StateMachineErrorCode.MissingTransitionTarget,
Message: "Missing 'StartAt'|'Next'|'Default' target: ".concat(state),
}); });
return unreachable.concat(inexistant);
};
exports.missingTransitionTargetErrors = missingTransitionTargetErrors;