1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validateGraph = void 0;
|
4 | const graphlib = require("../graphlib");
|
5 | const errors_1 = require("./errors");
|
6 | function assert(condition, msg) {
|
7 | if (!condition) {
|
8 | throw new errors_1.ValidationError(msg);
|
9 | }
|
10 | }
|
11 | function 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 | }
|
20 | exports.validateGraph = validateGraph;
|
21 |
|
\ | No newline at end of file |