@chix/flow
Version:
99 lines • 4.13 kB
JavaScript
;
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
var getPortsIfExists_1 = require("./getPortsIfExists");
var ValidationError_1 = require("./ValidationError");
function _checkIds(flowDefinition, nodeDefinitions) {
var e_1, _a, e_2, _b;
var knownIds = [];
var nodes = {};
if (flowDefinition.nodes.length > 0 && !nodeDefinitions) {
throw new Error('Cannot validate without nodeDefinitions');
}
try {
for (var _c = __values(flowDefinition.nodes), _d = _c.next(); !_d.done; _d = _c.next()) {
var node = _d.value;
if (!node.ns) {
throw new ValidationError_1.ValidationError("Cannot find nodeDefinition without name: " + node.name);
}
if (!nodeDefinitions[node.ns]) {
throw new ValidationError_1.ValidationError("Cannot find nodeDefinition with namespace: " + node.ns);
}
if (!nodeDefinitions[node.ns][node.name]) {
throw new ValidationError_1.ValidationError("Cannot find nodeDefinition for " + node.ns + ":" + node.name);
}
knownIds.push(node.id);
nodes[node.id] = node;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
try {
for (var _e = __values(flowDefinition.links), _f = _e.next(); !_f.done; _f = _e.next()) {
var link = _f.value;
if (!link.source) {
throw Error('source not defined');
}
if (!link.target) {
throw Error('target not defined');
}
if (knownIds.indexOf(link.source.id) === -1) {
throw new ValidationError_1.ValidationError('Source node does not exist ' + link.source.id);
}
if (knownIds.indexOf(link.target.id) === -1) {
throw new ValidationError_1.ValidationError('Target node does not exist ' + link.target.id);
}
var source = nodes[link.source.id];
var target = nodes[link.target.id];
var outputPorts = getPortsIfExists_1.getPortsIfExists('output', source, nodeDefinitions);
if (link.source.port[0] !== ':' && !outputPorts[link.source.port]) {
throw new ValidationError_1.ValidationError([
'Process',
link.source.id,
'has no output port named',
link.source.port,
'\n\n\tOutput ports available:',
'\n\n\t',
Object.keys(outputPorts).join(', '),
].join(' '));
}
var inputPorts = getPortsIfExists_1.getPortsIfExists('input', target, nodeDefinitions);
if (link.target.port[0] !== ':' && !inputPorts[link.target.port]) {
throw new ValidationError_1.ValidationError([
'Process',
link.target.id,
'has no input port named',
link.target.port,
'\n\n\tInput ports available:',
'\n\n\t',
Object.keys(inputPorts).join(', '),
].join(' '));
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
return true;
}
exports._checkIds = _checkIds;
//# sourceMappingURL=_checkIds.js.map