UNPKG

asl-validator

Version:
42 lines (41 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.missingTerminalStateErrors = void 0; var types_1 = require("../types"); var get_states_1 = require("./get-states"); var missingTerminalStateErrors = function (definition) { var errorMessages = []; // find each enclosed state machine and verify that // each state machine contains at least one of the following: // - state with End: true // - state with Type: Succeed // - state with Type: Fail var terminals = {}; var fsmId = 1; (0, get_states_1.getStatesContainer)(definition).forEach(function (states) { var fsmKey = "fsm".concat(fsmId); // initialize the nested fsm to have a terminal count of zero terminals[fsmKey] = 0; // check each of its states to see if the fsm terminates Object.values(states).forEach(function (state) { var count = terminals[fsmKey]; if (["Succeed", "Fail"].indexOf(state.Type) !== -1 || state.End) { terminals[fsmKey] = count ? count + 1 : 1; } }); fsmId += 1; }); for (var _i = 0, _a = Object.entries(terminals); _i < _a.length; _i++) { var _b = _a[_i], key = _b[0], value = _b[1]; if (value === 0) { errorMessages.push({ "Error code": types_1.StateMachineErrorCode.MissingTerminalState, // better to have a line number here Message: "State machine ".concat(key, " is missing a terminal state"), }); } } return errorMessages; }; exports.missingTerminalStateErrors = missingTerminalStateErrors;