Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function exampleWithLoop () {
//
// f -------, b<-,
// a -- b -- c -- e `
// `------ d -'
// \
//
static async buildGraphFromScope(scope: Scope): Promise {
const graph = new Graph();
const allModelComponents: ModelComponent[] = await scope.list();
const buildGraphP = allModelComponents.map(async modelComponent => {
const buildVersionP = modelComponent.listVersions().map(async versionNum => {
const version = await modelComponent.loadVersion(versionNum, scope.objects);
if (!version) {
// a component might be in the scope with only the latest version
return;
}
const id = modelComponent.toBitId().changeVersion(versionNum);
this._addDependenciesToGraph(id, graph, version);
});
await Promise.all(buildVersionP);
});
await Promise.all(buildGraphP);
return graph;
}
export const draw = function(text, id) {
conf = getConfig().state;
parser.yy.clear();
parser.parse(text);
logger.debug('Rendering diagram ' + text);
// /// / Fetch the default direction, use TD if none was found
const diagram = d3.select(`[id='${id}']`);
insertMarkers(diagram);
// // Layout graph, Create a new directed graph
const graph = new graphlib.Graph({
multigraph: false,
compound: true,
// acyclicer: 'greedy',
rankdir: 'RL'
// ranksep: '20'
});
// // Default to assigning a new object as a label for each new edge.
graph.setDefaultEdgeLabel(function() {
return {};
});
const rootDoc = stateDb.getRootDoc();
renderDoc(rootDoc, diagram);
const padding = conf.padding;
_validateNodes(pipeline, opt) {
const options = opt || {};
const graph = new Graph();
const links = [];
pipeline.nodes.forEach((node) => {
if (graph.node(node.nodeName)) {
throw new InvalidDataError(`found duplicate node ${node.nodeName}`);
}
if (node.nodeName === 'flowInput') {
throw new InvalidDataError(`pipeline ${pipeline.name} has invalid reserved name flowInput`);
}
if (node.input) {
node.input.forEach((inp) => {
if (options.checkFlowInput) {
try {
parser.checkFlowInput({ flowInput: pipeline.flowInput, nodeInput: inp });
}
export function buildComponentsGraph(components: Component[]): AllDependenciesGraphs {
const graphDeps = new Graph();
const graphDevDeps = new Graph();
const graphCompilerDeps = new Graph();
const graphTesterDeps = new Graph();
components.forEach(component => {
_setGraphEdges(component.id, component.dependencies, graphDeps);
_setGraphEdges(component.id, component.devDependencies, graphDevDeps);
_setGraphEdges(component.id, component.compilerDependencies, graphCompilerDeps);
_setGraphEdges(component.id, component.testerDependencies, graphTesterDeps);
});
return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
export function buildComponentsGraphForComponentsAndVersion(
components: ComponentsAndVersions[]
): AllDependenciesGraphs {
const graphDeps = new Graph();
const graphDevDeps = new Graph();
const graphCompilerDeps = new Graph();
const graphTesterDeps = new Graph();
components.forEach(({ component, version, versionStr }) => {
const bitId = component.toBitId().changeVersion(versionStr);
_setGraphEdges(bitId, version.dependencies, graphDeps);
_setGraphEdges(bitId, version.devDependencies, graphDevDeps);
_setGraphEdges(bitId, version.compilerDependencies, graphCompilerDeps);
_setGraphEdges(bitId, version.testerDependencies, graphTesterDeps);
});
return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
const createGraph = installers => {
const graph = new Graph();
installers.forEach(({ plugin }) => {
graph.setNode(plugin.name, plugin);
});
installers.forEach(({ plugin: pl }) => {
if (Array.isArray(pl.dependencies)) {
pl.dependencies.forEach(dep => {
graph.setEdge(pl.name, dep);
});
}
});
validateGraph(graph);
return graph;
};
export function buildComponentsGraphForComponentsAndVersion(
components: ComponentsAndVersions[]
): AllDependenciesGraphs {
const graphDeps = new Graph();
const graphDevDeps = new Graph();
const graphCompilerDeps = new Graph();
const graphTesterDeps = new Graph();
components.forEach(({ component, version, versionStr }) => {
const bitId = component.toBitId().changeVersion(versionStr);
_setGraphEdges(bitId, version.dependencies, graphDeps);
_setGraphEdges(bitId, version.devDependencies, graphDevDeps);
_setGraphEdges(bitId, version.compilerDependencies, graphCompilerDeps);
_setGraphEdges(bitId, version.testerDependencies, graphTesterDeps);
});
return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
const getGraph = async () => {
const graph = {
nodes: new Graph(),
data: await getComponents(),
state: await readStateFile()
}
forEach((componentId) => {
graph.nodes.setNode(componentId)
}, keys(graph.data))
forEachObjIndexed((component, componentId) => {
component.dependencies = getDependencies(component.inputs)
if (not(isEmpty(component.dependencies))) {
forEach((dependencyId) => {
graph.nodes.setEdge(componentId, dependencyId)
}, component.dependencies)
}
}, graph.data)