UNPKG

asl-validator

Version:
27 lines (26 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.duplicateStateNames = void 0; var jsonpath_plus_1 = require("jsonpath-plus"); var types_1 = require("../types"); var duplicateStateNames = function (definition) { var errorMessages = []; var names = {}; (0, jsonpath_plus_1.JSONPath)({ json: definition, path: "$..['States']" }).forEach(function (states) { Object.keys(states).forEach(function (stateName) { var current = names[stateName]; names[stateName] = current ? current + 1 : 1; }); }); for (var _i = 0, _a = Object.entries(names); _i < _a.length; _i++) { var _b = _a[_i], key = _b[0], value = _b[1]; if (value > 1) { errorMessages.push({ "Error code": types_1.StateMachineErrorCode.DuplicateStateNames, Message: "A state with this name already exists: ".concat(key), }); } } return errorMessages; }; exports.duplicateStateNames = duplicateStateNames;