UNPKG

1.02 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.validateGraph = void 0;
4const graphlib = require("../graphlib");
5const errors_1 = require("./errors");
6function assert(condition, msg) {
7 if (!condition) {
8 throw new errors_1.ValidationError(msg);
9 }
10}
11function validateGraph(graph, rootNodeId, pkgs, pkgNodes) {
12 assert((graph.predecessors(rootNodeId) || []).length === 0, `"${rootNodeId}" is not really the root`);
13 const reachableFromRoot = graphlib.alg.postorder(graph, [rootNodeId]);
14 const nodeIds = graph.nodes();
15 assert(JSON.stringify(nodeIds.sort()) === JSON.stringify(reachableFromRoot.sort()), 'not all graph nodes are reachable from root');
16 const pkgIds = Object.keys(pkgs);
17 const pkgsWithoutInstances = pkgIds.filter((pkgId) => !pkgNodes[pkgId] || pkgNodes[pkgId].size === 0);
18 assert(pkgsWithoutInstances.length === 0, 'not all pkgs have instance nodes');
19}
20exports.validateGraph = validateGraph;
21//# sourceMappingURL=validate-graph.js.map
\No newline at end of file