Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cleargraph

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cleargraph - npm Package Compare versions

Comparing version 6.0.0 to 7.0.0

7

CHANGELOG.md

@@ -7,2 +7,9 @@ # Change Log

## [7.0.0] - 2020-12-21
### New
* All methods that used to return a map or nodes or edges now return arrays.
* There are corresponding methods that still return maps where the method name is suffixed with 'map', as in nodeMap or succesorMap()
* Added source and target getters for Edge
* Added return types to toposort() and findCycles()
## [6.0.0] - 2020-12-03

@@ -9,0 +16,0 @@

4

dist/algorithms/tarjan.js

@@ -19,3 +19,3 @@ "use strict";

stack.push(v);
let successors = [...g.successors(v).keys()];
let successors = [...g.successorMap(v).keys()];
successors.forEach(function (w) {

@@ -41,3 +41,3 @@ if (!lodash_1.default.has(visited, w)) {

}
[...g.nodes.keys()].forEach(function (v) {
[...g.nodeMap.keys()].forEach(function (v) {
if (!lodash_1.default.has(visited, v)) {

@@ -44,0 +44,0 @@ dfs(v);

@@ -14,2 +14,4 @@ import { NodeId } from './node';

get id(): string;
get source(): string;
get target(): string;
stringify(): string;

@@ -16,0 +18,0 @@ static fromObject(obj: {

@@ -14,2 +14,8 @@ "use strict";

}
get source() {
return this.sourceId;
}
get target() {
return this.targetId;
}
stringify() {

@@ -16,0 +22,0 @@ let attrStr = '';

@@ -42,19 +42,24 @@ import { Node, NodeId } from './index';

};
get nodes(): Map<NodeId, Node<N>>;
get edges(): Map<EdgeId, Edge<E>>;
get nodeMap(): Map<NodeId, Node<N>>;
get edgeMap(): Map<EdgeId, Edge<E>>;
get nodes(): Array<Node<N>>;
get edges(): Array<Edge<E>>;
nodeCount(): number;
edgeCount(): number;
sources(): Node<N>[];
sinks(): Node<N>[];
sources(): Array<Node<N>>;
sinks(): Array<Node<N>>;
deleteNode(id: NodeId): void;
deleteEdge(sourceId: string, targetId: string): void;
inEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
outEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
nodeEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
inEdgesMap(nodeId: NodeId): Map<EdgeId, Edge<E>>;
outEdgesMap(nodeId: NodeId): Map<EdgeId, Edge<E>>;
nodeEdgesMap(nodeId: NodeId): Map<EdgeId, Edge<E>>;
inEdges(nodeId: NodeId): Array<Edge<E>>;
outEdges(nodeId: NodeId): Array<Edge<E>>;
nodeEdges(nodeId: NodeId): Array<Edge<E>>;
_inEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
_outEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
_nodeEdges(nodeId: NodeId): Map<EdgeId, Edge<E>>;
successors(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
predecessors(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
neighbors(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
successorMap(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
predecessorMap(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
neighborMap(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;
_successors(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;

@@ -70,3 +75,3 @@ _predecessors(nodeId: NodeId, filterPredicate?: (edge: Edge<E>) => boolean): Map<NodeId, Node<N>>;

} | undefined, filterPredicate: (data: Edge<E>) => boolean): this;
successorsArray(nodeId: NodeId, filterPredicate?: (data: Edge<E>) => boolean): Node<N>[];
successors(nodeId: NodeId, filterPredicate?: (data: Edge<E>) => boolean): Array<Node<N>>;
_successorsArrayUtil(nodeId: string, successorsList?: string[], visited?: {

@@ -81,3 +86,3 @@ [key: string]: boolean;

}, filterPredicate?: (data: Edge<E>) => boolean): this;
predecessorsArray(nodeId: NodeId, filterPredicate?: (data: Edge<E>) => boolean): Node<N>[];
predecessors(nodeId: NodeId, filterPredicate?: (data: Edge<E>) => boolean): Array<Node<N>>;
_predecessorsArrayUtil(nodeId: string, predecessorsList?: string[], visited?: {

@@ -88,37 +93,7 @@ [key: string]: boolean;

private _predecessorsLayersUtil;
toposort(reverse?: boolean): Node<N>[];
toposort(reverse?: boolean): Array<Node<N>>;
_transformEdges(): string[][];
_toposort(): any[];
isCyclic(graph?: this): boolean;
findCycles(graph?: this): (number | ((...items: never[]) => number) | (() => undefined) | (() => string) | {
(...items: ConcatArray<never>[]): never[];
(...items: ConcatArray<never>[]): never[];
} | ((searchElement: never, fromIndex?: number | undefined) => number) | ((searchElement: never, fromIndex?: number | undefined) => number) | ((start?: number | undefined, end?: number | undefined) => never[]) | ((searchElement: never, fromIndex?: number | undefined) => boolean) | (() => string) | ((callbackfn: (value: never, index: number, array: never[]) => void, thisArg?: any) => void) | ((separator?: string | undefined) => string) | (() => never[]) | (() => undefined) | ((compareFn?: ((a: never, b: never) => number) | undefined) => never[]) | {
(start: number, deleteCount?: number | undefined): never[];
(start: number, deleteCount: number, ...items: never[]): never[];
} | ((...items: never[]) => number) | ((callbackfn: (value: never, index: number, array: never[]) => unknown, thisArg?: any) => boolean) | ((callbackfn: (value: never, index: number, array: never[]) => unknown, thisArg?: any) => boolean) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[]) | {
<S extends never>(callbackfn: (value: never, index: number, array: never[]) => value is S, thisArg?: any): S[];
(callbackfn: (value: never, index: number, array: never[]) => unknown, thisArg?: any): never[];
} | {
(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never;
(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never;
<U_1>(callbackfn: (previousValue: U_1, currentValue: never, currentIndex: number, array: never[]) => U_1, initialValue: U_1): U_1;
} | {
(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never;
(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never;
<U_2>(callbackfn: (previousValue: U_2, currentValue: never, currentIndex: number, array: never[]) => U_2, initialValue: U_2): U_2;
} | {
<S_1 extends never>(predicate: (this: void, value: never, index: number, obj: never[]) => value is S_1, thisArg?: any): S_1 | undefined;
(predicate: (value: never, index: number, obj: never[]) => unknown, thisArg?: any): undefined;
} | ((predicate: (value: never, index: number, obj: never[]) => unknown, thisArg?: any) => number) | ((value: never, start?: number | undefined, end?: number | undefined) => never[]) | ((target: number, start: number, end?: number | undefined) => never[]) | (() => IterableIterator<[number, never]>) | (() => IterableIterator<number>) | (() => IterableIterator<never>) | (<U_3, This = undefined>(callback: (this: This, value: never, index: number, array: never[]) => U_3 | readonly U_3[], thisArg?: This | undefined) => U_3[]) | {
<U_4>(this: U_4[][][][][][][][], depth: 7): U_4[];
<U_5>(this: U_5[][][][][][][], depth: 6): U_5[];
<U_6>(this: U_6[][][][][][], depth: 5): U_6[];
<U_7>(this: U_7[][][][][], depth: 4): U_7[];
<U_8>(this: U_8[][][][], depth: 3): U_8[];
<U_9>(this: U_9[][][], depth: 2): U_9[];
<U_10>(this: U_10[][], depth?: 1 | undefined): U_10[];
<U_11>(this: U_11[], depth: 0): U_11[];
<U_12>(depth?: number | undefined): any[];
})[];
findCycles(graph?: this): string[][];
merge(graphs: this[]): this;

@@ -125,0 +100,0 @@ allPaths(sourceId: NodeId, targetId: NodeId): NodeId[][];

@@ -123,8 +123,14 @@ "use strict";

}
get nodes() {
get nodeMap() {
return this._nodes;
}
get edges() {
get edgeMap() {
return this._edges;
}
get nodes() {
return [...this._nodes.values()];
}
get edges() {
return [...this._edges.values()];
}
nodeCount() {

@@ -169,11 +175,20 @@ return [...this._nodes.keys()].length;

}
inEdges(nodeId) {
inEdgesMap(nodeId) {
return this._inEdges(nodeId);
}
outEdges(nodeId) {
outEdgesMap(nodeId) {
return this._outEdges(nodeId);
}
nodeEdges(nodeId) {
nodeEdgesMap(nodeId) {
return this._nodeEdges(nodeId);
}
inEdges(nodeId) {
return [...this._inEdges(nodeId).values()];
}
outEdges(nodeId) {
return [...this._outEdges(nodeId).values()];
}
nodeEdges(nodeId) {
return [...this._nodeEdges(nodeId).values()];
}
_inEdges(nodeId) {

@@ -221,9 +236,9 @@ let newEdges = new Map();

}
successors(nodeId, filterPredicate = returnTrue) {
successorMap(nodeId, filterPredicate = returnTrue) {
return this._successors(nodeId, filterPredicate);
}
predecessors(nodeId, filterPredicate = returnTrue) {
predecessorMap(nodeId, filterPredicate = returnTrue) {
return this._predecessors(nodeId, filterPredicate);
}
neighbors(nodeId, filterPredicate = returnTrue) {
neighborMap(nodeId, filterPredicate = returnTrue) {
return this._neighbors(nodeId, filterPredicate);

@@ -328,3 +343,3 @@ }

}
successorsArray(nodeId, filterPredicate = returnTrue) {
successors(nodeId, filterPredicate = returnTrue) {
const successorIds = lodash_1.default.uniq(this._successorsArrayUtil(nodeId, [], {}, filterPredicate));

@@ -367,3 +382,3 @@ let successors = [];

layers[floor].forEach((successor) => {
const successors = [...this.successors(successor, filterPredicate).keys()];
const successors = [...this.successorMap(successor, filterPredicate).keys()];
layers[nextFloor] = layers[nextFloor].concat(successors);

@@ -394,3 +409,3 @@ });

}
predecessorsArray(nodeId, filterPredicate = returnTrue) {
predecessors(nodeId, filterPredicate = returnTrue) {
const predecessorIds = lodash_1.default.uniq(this._predecessorsArrayUtil(nodeId, [], {}, filterPredicate));

@@ -433,3 +448,3 @@ let predecessors = [];

layers[floor].forEach((predecessor) => {
const predecessors = [...this.predecessors(predecessor, filterPredicate).keys()];
const predecessors = [...this.predecessorMap(predecessor, filterPredicate).keys()];
layers[nextFloor] = layers[nextFloor].concat(predecessors);

@@ -516,9 +531,9 @@ });

var _a, _b;
for (let [nodeId, node] of incomingGraph.nodes) {
for (let [nodeId, node] of incomingGraph.nodeMap) {
mergedGraph.setNode(nodeId, node.attr);
}
for (let [edgeId, edge] of incomingGraph.edges) {
for (let [edgeId, edge] of incomingGraph.edgeMap) {
const sourceId = (_a = incomingGraph._edges.get(edgeId)) === null || _a === void 0 ? void 0 : _a.sourceId;
const targetId = (_b = incomingGraph._edges.get(edgeId)) === null || _b === void 0 ? void 0 : _b.targetId;
if (mergedGraph.edges.has(edgeId) && !!sourceId && !!targetId) {
if (mergedGraph.edgeMap.has(edgeId) && !!sourceId && !!targetId) {
mergedGraph.setEdge(sourceId, targetId, edge.attr);

@@ -571,3 +586,3 @@ }

let nodeArray = [];
for (let [nodeId, nodeData] of graph.nodes.entries()) {
for (let [nodeId, nodeData] of graph.nodeMap.entries()) {
const graphNode = graph.node(nodeId);

@@ -594,3 +609,3 @@ if (!!graphNode) {

let edgeArray = [];
for (let [edgeId, edgeData] of graph.edges.entries()) {
for (let [edgeId, edgeData] of graph.edgeMap.entries()) {
const graphEdge = graph._edgeById(edgeId);

@@ -597,0 +612,0 @@ if (!!graphEdge) {

@@ -103,9 +103,19 @@ "use strict";

it('should return all graph nodes as a map', () => {
const keys = [...g.nodes.keys()];
const keys = [...g.nodeMap.keys()];
chai_1.expect(keys).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
});
it('should return all graph edges as a map', () => {
const keys = [...g.edges.keys()];
const keys = [...g.edgeMap.keys()];
chai_1.expect(keys).to.deep.equal(["a->b", "a->c", "c->d", "c->e", "d->f", "e->d", "g->a"]);
});
it('should return all graph nodes as an array', () => {
const nodes = g.nodes;
chai_1.expect(nodes.length).to.equal(7);
chai_1.expect(nodes[0]).to.be.an('object');
});
it('should return all graph edges as an array', () => {
const edges = g.edges;
chai_1.expect(edges.length).to.equal(7);
chai_1.expect(edges[0]).to.be.an('object');
});
it('should return the correct node count', () => {

@@ -139,24 +149,42 @@ chai_1.expect(g.nodeCount()).to.equal(7);

});
it('should find all in edges of a given node', () => {
const keys = [...g.inEdges('d').keys()];
it('should return a map of all in edges of a given node', () => {
const keys = [...g.inEdgesMap('d').keys()];
chai_1.expect(keys).to.deep.equal(['c->d', 'e->d']);
});
it('should find all out edges of a given node', () => {
const keys = [...g.outEdges('a').keys()];
it('should return a map of all out edges of a given node', () => {
const keys = [...g.outEdgesMap('a').keys()];
chai_1.expect(keys).to.deep.equal(['a->b', 'a->c']);
});
it('should find all node edges of a given node', () => {
const keys = [...g.nodeEdges('a').keys()];
it('should return a map of all node edges of a given node', () => {
const keys = [...g.nodeEdgesMap('a').keys()];
chai_1.expect(keys).to.deep.equal(['g->a', 'a->b', 'a->c']);
});
it('should return an array of all in edges of a given node', () => {
const inEdges = g.inEdges('d');
chai_1.expect(inEdges.length).to.equal(2);
chai_1.expect(inEdges[0]).to.be.an('object');
chai_1.expect(inEdges[0].id).to.equal('c->d');
});
it('should return an array of all out edges of a given node', () => {
const outEdges = g.outEdges('a');
chai_1.expect(outEdges.length).to.equal(2);
chai_1.expect(outEdges[0]).to.be.an('object');
chai_1.expect(outEdges[0].id).to.equal('a->b');
});
it('should return an array of all node edges of a given node', () => {
const nodeEdges = g.nodeEdges('a');
chai_1.expect(nodeEdges.length).to.equal(3);
chai_1.expect(nodeEdges[0]).to.be.an('object');
chai_1.expect(nodeEdges[0].id).to.equal('g->a');
});
it('should find immediate successors of a given node', () => {
const keys = [...g.successors('c').keys()];
const keys = [...g.successorMap('c').keys()];
chai_1.expect(keys).to.deep.equal(['d', 'e']);
});
it('should find immediate predecessors of a given node', () => {
const keys = [...g.predecessors('c').keys()];
const keys = [...g.predecessorMap('c').keys()];
chai_1.expect(keys).to.deep.equal(['a']);
});
it('should find neighbors of a given node', () => {
const keys = [...g.neighbors('c').keys()];
const keys = [...g.neighborMap('c').keys()];
chai_1.expect(keys).to.deep.equal(['a', 'd', 'e']);

@@ -167,4 +195,4 @@ });

const subgraph = node ? g.successorsSubgraph(node.id) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(['c', 'd', 'f', 'e']);

@@ -177,4 +205,4 @@ chai_1.expect(edgeKeys).to.deep.equal(['c->d', 'd->f', 'c->e', 'e->d']);

const subgraph = node1 && node2 ? g.successorsSubgraph([node1.id, node2.id]) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(['a', 'b', 'c', 'd', 'f', 'e']);

@@ -189,4 +217,4 @@ chai_1.expect(edgeKeys).to.deep.equal(['a->b', 'a->c', 'c->d', 'd->f', 'c->e', 'e->d']);

const subgraph = node1 && node2 ? g.successorsSubgraph([node1.id, node2.id]) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(["b", "h", "c", "d", "f", "e"]);

@@ -200,4 +228,4 @@ chai_1.expect(edgeKeys).to.deep.equal(["b->h", "c->d", "d->f", "c->e", "e->d"]);

const subgraph = node ? g.predecessorsSubgraph(node.id) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(['d', 'c', 'a', 'g', 'e']);

@@ -210,4 +238,4 @@ chai_1.expect(edgeKeys).to.deep.equal(["c->d", "a->c", "g->a", "e->d", "c->e"]);

const subgraph = node1 && node2 ? g.predecessorsSubgraph([node1.id, node2.id]) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(["d", "c", "a", "g", "e"]);

@@ -222,4 +250,4 @@ chai_1.expect(edgeKeys).to.deep.equal(["c->d", "a->c", "g->a", "e->d", "c->e"]);

const subgraph = node1 && node2 ? g.predecessorsSubgraph([node1.id, node2.id]) : new index_1.Graph();
const nodeKeys = [...subgraph.nodes.keys()];
const edgeKeys = [...subgraph.edges.keys()];
const nodeKeys = [...subgraph.nodeMap.keys()];
const edgeKeys = [...subgraph.edgeMap.keys()];
chai_1.expect(nodeKeys).to.deep.equal(["d", "c", "a", "g", "e", "h", "b"]);

@@ -232,3 +260,3 @@ chai_1.expect(edgeKeys).to.deep.equal(["c->d", "a->c", "g->a", "e->d", "c->e", "b->h", "a->b"]);

const node = g.node('c');
const arr = !!node ? g.successorsArray(node.id).map(elem => elem.id) : [];
const arr = !!node ? g.successors(node.id).map(elem => elem.id) : [];
chai_1.expect(arr).to.deep.equal(['d', 'f', 'e']);

@@ -238,3 +266,3 @@ });

const node = g.node('d');
const arr = !!node ? g.predecessorsArray(node.id).map(elem => elem.id) : [];
const arr = !!node ? g.predecessors(node.id).map(elem => elem.id) : [];
chai_1.expect(arr).to.deep.equal(['c', 'a', 'g', 'e']);

@@ -320,5 +348,8 @@ });

it('should return all cycles in graph', () => {
g.setEdge('f', 'g', new EdgeData('dev', 2));
chai_1.expect(g.findCycles()).to.deep.equal([['e', 'g', 'f', 'd', 'c', 'a']]);
g.deleteEdge('f', 'g');
g.setEdge('c', 'g', new EdgeData('dev', 2));
g.setEdge('f', 'e', new EdgeData('dev', 2));
const cycles = g.findCycles();
chai_1.expect(cycles).to.deep.equal([["e", "f", "d"], ["g", "c", "a"]]);
g.deleteEdge('c', 'g');
g.deleteEdge('f', 'e');
});

@@ -341,4 +372,4 @@ it('should convert graph to json object', () => {

const newGraph = index_1.Graph.parse(JSON.stringify(json));
chai_1.expect([...newGraph.nodes.keys()]).to.deep.equal(['a', 'b']);
chai_1.expect([...newGraph.edges.keys()]).to.deep.equal(['a->b']);
chai_1.expect([...newGraph.nodeMap.keys()]).to.deep.equal(['a', 'b']);
chai_1.expect([...newGraph.edgeMap.keys()]).to.deep.equal(['a->b']);
});

@@ -358,5 +389,5 @@ before('creating graphs for merge', function () {

const res = g.merge([h, i]);
chai_1.expect(res.nodes.size).to.equal(10);
chai_1.expect(res.edges.size).to.equal(10);
chai_1.expect(res.edges.has('i->h')).to.be.true;
chai_1.expect(res.nodeMap.size).to.equal(10);
chai_1.expect(res.edgeMap.size).to.equal(10);
chai_1.expect(res.edgeMap.has('i->h')).to.be.true;
});

@@ -363,0 +394,0 @@ });

{
"name": "cleargraph",
"version": "6.0.0",
"version": "7.0.0",
"description": "A library for modeling and traversing graphs",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc