How to use the graphlib.alg.isAcyclic function in graphlib

To help you get started, we’ve selected a few graphlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ConsenSys / ethql / packages / plugin / src / bootstrap.ts View on Github external
// Add an implicit dependency on core, if core is not explicitly listed.
    if (coreLoaded && name !== 'core' && ![...after, ...before].includes('core')) {
      after.push('core');
    }

    // Add the edges.
    before.forEach(b => graph.setEdge(name, b));
    after.forEach(a => graph.setEdge(a, name));
  }

  // Sort plugins topologically.
  const orderedPlugins = alg.topsort(graph).map(node => graph.node(node) as EthqlPlugin);

  const sources = graph.sources();
  if (sources.length === 0 || !alg.isAcyclic(graph)) {
    throw new Error(ERR_MSG_NO_ROOT);
  } else if (sources.length > 1) {
    throw new Error(ERR_MSG_MANY_ROOTS(sources));
  }

  console.log(`⚒   Bootstrapping with plugins: ${orderedPlugins.map(p => p.name).join(', ')}.`);

  // Merge schemas, resolvers, serviceDefinitions from all plugins.
  let merged: MergeResult = { config: runtimeConfig, schema: [], resolvers: {}, serviceDefinitions: {} };
  for (let plugin of orderedPlugins) {
    if (typeof plugin.resolvers === 'function') {
      plugin.resolvers = plugin.resolvers(merged.resolvers);
    }
    merged = deepmerge.all([merged, plugin]) as MergeResult;
  }
github unboundedsystems / adapt / core / src / deploy / execution_plan.ts View on Github external
if (!succIds) throw new InternalError(`id '${id}' not found`);
            const deps = succIds.map((sId) => {
                const isHard = hardSet.delete(sId);
                return { id: sId, type: isHard ? "hard" : "soft" };
            });
            if (hardSet.size !== 0) {
                throw new InternalError(`Internal consistency check failed: ` +
                    `not all hardDeps are successors`);
            }
            const entry: EPDependencies[string] = { detail: detail(node), deps };
            if (node.element) entry.elementId = node.element.id;
            return entry;
        };

        const ret: EPDependencies = {};
        const ids = alg.isAcyclic(this.graph) ?
            alg.topsort(this.graph) : this.graph.nodes();

        // Insert starting with leaves for a more human-readable ordering
        for (let i = ids.length - 1; i >= 0; i--) {
            const id = ids[i];
            const node = this.getNode(id);
            ret[id] = getDeps(node, id);
        }
        return ret;
    }
github serverless / components / src / core / declarative / utils / createGraph.js View on Github external
// create a `root` node and add all nodes which are not dependent on other nodes
  // this `root` node will be used to walk the graph later on
  dag.setNode(ROOT_NODE_NAME)
  dag = reduce(
    (accum, instanceId) => {
      if (instanceId !== ROOT_NODE_NAME) {
        accum.setEdge(instanceId, ROOT_NODE_NAME)
      }
      return accum
    },
    dag,
    dag.sinks()
  )

  // checking for circular dependencies
  const isAcyclic = alg.isAcyclic(dag)
  if (!isAcyclic) {
    const cycles = alg.findCycles(dag)
    let msg = ['Your serverless.yml file has circular dependencies:']
    cycles.forEach((cycle, index) => {
      let fromAToB = cycle.join(' --> ')
      fromAToB = `${(index += 1)}. ${fromAToB}`
      const fromBToA = cycle.reverse().join(' <-- ')
      const padLength = fromAToB.length + 4
      msg.push(fromAToB.padStart(padLength))
      msg.push(fromBToA.padStart(padLength))
    }, cycles)
    msg = msg.join('\n')
    throw new Error(msg)
  }

  return dag
github ezolenko / rollup-plugin-typescript2 / dist / rollup-plugin-typescript2.es.js View on Github external
TsCache.prototype.walkTree = function (cb) {
        var acyclic = alg.isAcyclic(this.dependencyTree);
        if (acyclic) {
            each(alg.topsort(this.dependencyTree), function (id) { return cb(id); });
            return;
        }
        this.context.info(yellow("import tree has cycles"));
        each(this.dependencyTree.nodes(), function (id) { return cb(id); });
    };
    TsCache.prototype.done = function () {
github kube-HPC / hkube / core / api-server / lib / validation / api-validator.js View on Github external
links.push({ source: nd.nodeName, target: node.nodeName });
                        }
                        else {
                            throw new InvalidDataError(`node ${node.nodeName} is depend on ${n.nodeName} which is not exists`);
                        }
                    });
                });
            }
            graph.setNode(node.nodeName, node);
        });

        links.forEach((link) => {
            graph.setEdge(link.source, link.target);
        });

        if (!alg.isAcyclic(graph)) {
            throw new InvalidDataError(`pipeline ${pipeline.name} has cyclic nodes`);
        }
    }
github webiny / webiny-js / packages / cli / sls / template / utils.js View on Github external
const validateGraph = graph => {
    const isAcyclic = alg.isAcyclic(graph);
    if (!isAcyclic) {
        const cycles = alg.findCycles(graph);
        let msg = ["Your template has circular dependencies:"];
        cycles.forEach((cycle, index) => {
            let fromAToB = cycle.join(" --> ");
            fromAToB = `${(index += 1)}. ${fromAToB}`;
            const fromBToA = cycle.reverse().join(" <-- ");
            const padLength = fromAToB.length + 4;
            msg.push(fromAToB.padStart(padLength));
            msg.push(fromBToA.padStart(padLength));
        }, cycles);
        msg = msg.join("\n");
        throw new Error(msg);
    }
};
github webiny / webiny-js / packages / app-admin / src / components / Install / useInstaller.js View on Github external
const validateGraph = graph => {
        const isAcyclic = alg.isAcyclic(graph);
        if (!isAcyclic) {
            const cycles = alg.findCycles(graph);
            let msg = ["Your installers have circular dependencies:"];
            cycles.forEach((cycle, index) => {
                let fromAToB = cycle.join(" --> ");
                fromAToB = `${index + 1}. ${fromAToB}`;
                const fromBToA = cycle.reverse().join(" <-- ");
                const padLength = fromAToB.length + 4;
                msg.push(fromAToB.padStart(padLength));
                msg.push(fromBToA.padStart(padLength));
            }, cycles);
            msg = msg.join("\n");
            throw new Error(msg);
        }
    };
github webiny / webiny-js / packages / app-admin / src / components / Install / Install.js View on Github external
const validateGraph = graph => {
    const isAcyclic = alg.isAcyclic(graph);
    if (!isAcyclic) {
        const cycles = alg.findCycles(graph);
        let msg = ["Your installers have circular dependencies:"];
        cycles.forEach((cycle, index) => {
            let fromAToB = cycle.join(" --> ");
            fromAToB = `${(index += 1)}. ${fromAToB}`;
            const fromBToA = cycle.reverse().join(" <-- ");
            const padLength = fromAToB.length + 4;
            msg.push(fromAToB.padStart(padLength));
            msg.push(fromBToA.padStart(padLength));
        }, cycles);
        msg = msg.join("\n");
        throw new Error(msg);
    }
};