@statelyai/graph 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -1
- package/dist/{algorithms-Pbj9dJB1.mjs → algorithms-C-S7u40k.mjs} +813 -7
- package/dist/algorithms-DdjFO-ft.d.mts +787 -0
- package/dist/algorithms.d.mts +2 -647
- package/dist/algorithms.mjs +2 -2
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/converter/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/d3/index.d.mts +1 -1
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/xyflow/index.d.mts +1 -1
- package/dist/index.d.mts +58 -7
- package/dist/index.mjs +95 -3
- package/dist/queries.d.mts +14 -14
- package/dist/queries.mjs +16 -9
- package/dist/{types-BzckPChi.d.mts → types-F3j-sr2X.d.mts} +31 -16
- package/package.json +4 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as VisualGraphFormatConverter, j as VisualGraph } from "../../types-F3j-sr2X.mjs";
|
|
2
2
|
import { ElkEdge, ElkEdgeSection, ElkExtendedEdge, ElkGraphElement, ElkLabel, ElkNode, ElkNode as ElkNode$1, ElkPoint, ElkPort, ElkPrimitiveEdge, ElkShape, LayoutOptions } from "elkjs/lib/elk-api";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/elk/index.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as VisualGraphFormatConverter, j as VisualGraph } from "../../types-F3j-sr2X.mjs";
|
|
2
2
|
import { EdgeBase, NodeBase } from "@xyflow/system";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/xyflow/index.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
1
|
+
import { A as VisualEdge, C as NodeConfig, D as SinglePathOptions, E as PortDirection, F as VisualNode, I as VisualPort, L as WalkContext, M as VisualGraphConfig, N as VisualGraphEntity, O as TransitionOptions, P as VisualGraphFormatConverter, R as WalkOptions, S as NodeChange, T as PortConfig, _ as GraphPatch, a as EdgeChange, b as GraphStep, c as EntitiesUpdate, d as GraphConfig, f as GraphDiff, g as GraphNode, h as GraphFormatConverter, i as DeleteNodeOptions, j as VisualGraph, k as TraversalOptions, l as EntityRect, m as GraphEntity, n as AllPairsShortestPathsOptions, o as EdgeConfig, p as GraphEdge, r as CoverageStats, s as EntitiesConfig, t as AStarOptions, u as Graph, v as GraphPath, w as PathOptions, x as MSTOptions, y as GraphPort, z as WeightedWalkOptions } from "./types-F3j-sr2X.mjs";
|
|
2
|
+
import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-DdjFO-ft.mjs";
|
|
3
3
|
import { createFormatConverter } from "./formats/converter/index.mjs";
|
|
4
|
-
import { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
4
|
+
import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/graph.d.ts
|
|
7
7
|
|
|
@@ -112,7 +112,7 @@ declare function getNode<N>(graph: Graph<N>, id: string): GraphNode<N> | undefin
|
|
|
112
112
|
* const missing = getEdge(graph, 'z'); // undefined
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
|
-
declare function getEdge<E>(graph: Graph<
|
|
115
|
+
declare function getEdge<N, E>(graph: Graph<N, E>, id: string): GraphEdge<E> | undefined;
|
|
116
116
|
/**
|
|
117
117
|
* Check if a node exists in the graph.
|
|
118
118
|
*
|
|
@@ -161,7 +161,7 @@ declare function addNode<N, P = any>(graph: Graph<N, any, any, P>, config: NodeC
|
|
|
161
161
|
* // graph.edges.length === 1
|
|
162
162
|
* ```
|
|
163
163
|
*/
|
|
164
|
-
declare function addEdge<E>(graph: Graph<
|
|
164
|
+
declare function addEdge<N, E>(graph: Graph<N, E>, config: EdgeConfig<E>): GraphEdge<E>;
|
|
165
165
|
/**
|
|
166
166
|
* **Mutable.** Delete a node and its connected edges. Mutates `graph.nodes`
|
|
167
167
|
* and `graph.edges` in place.
|
|
@@ -220,7 +220,7 @@ declare function updateNode<N, P = any>(graph: Graph<N, any, any, P>, id: string
|
|
|
220
220
|
* // updated.label === 'new'
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
declare function updateEdge<E>(graph: Graph<
|
|
223
|
+
declare function updateEdge<N, E>(graph: Graph<N, E>, id: string, update: Partial<Omit<EdgeConfig<E>, 'id'>>): GraphEdge<E>;
|
|
224
224
|
/**
|
|
225
225
|
* **Mutable.** Add multiple nodes and edges to the graph.
|
|
226
226
|
* Nodes are added first, then edges (so edges can reference new nodes).
|
|
@@ -334,6 +334,57 @@ declare class GraphInstance<N = any, E = any, G = any, P = any> {
|
|
|
334
334
|
*/
|
|
335
335
|
declare function invalidateIndex(graph: Graph): void;
|
|
336
336
|
//#endregion
|
|
337
|
+
//#region src/equivalence.d.ts
|
|
338
|
+
declare const LAYOUT_KEYS: {
|
|
339
|
+
node: readonly ["x", "y", "width", "height", "style", "color", "shape"];
|
|
340
|
+
edge: readonly ["x", "y", "width", "height", "style", "color"];
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Compare two entities on a given set of keys.
|
|
344
|
+
* If `keys` is omitted or empty, compares all own keys of `a`.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* import { createGraphNode, areEntitiesEqual, LAYOUT_KEYS } from '@statelyai/graph';
|
|
349
|
+
*
|
|
350
|
+
* const a = createGraphNode({ id: 'n1', label: 'hello', x: 0 });
|
|
351
|
+
* const b = createGraphNode({ id: 'n1', label: 'hello', x: 100 });
|
|
352
|
+
*
|
|
353
|
+
* areEntitiesEqual(a, b, LAYOUT_KEYS.node); // false (x differs)
|
|
354
|
+
* areEntitiesEqual(a, b, NON_LAYOUT_KEYS.node); // true
|
|
355
|
+
* areEntitiesEqual(a, b); // false (compares all keys)
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function areEntitiesEqual<T extends GraphNode | GraphEdge>(a: T, b: T, keys?: readonly (keyof T)[]): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Compare two entities on layout keys only (position, size, style, color, shape).
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* import { createGraphNode, isLayoutEqual } from '@statelyai/graph';
|
|
365
|
+
*
|
|
366
|
+
* const a = createGraphNode({ id: 'n1', x: 0, y: 0 });
|
|
367
|
+
* const b = createGraphNode({ id: 'n1', x: 100, y: 200 });
|
|
368
|
+
*
|
|
369
|
+
* isLayoutEqual(a, b); // false
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
declare function isLayoutEqual<T extends GraphNode | GraphEdge>(a: T, b: T): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Compare two entities on non-layout keys only (id, data, connections, labels, etc.).
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* import { createGraphNode, isNonLayoutEqual } from '@statelyai/graph';
|
|
379
|
+
*
|
|
380
|
+
* const a = createGraphNode({ id: 'n1', label: 'hello', x: 0 });
|
|
381
|
+
* const b = createGraphNode({ id: 'n1', label: 'hello', x: 100 });
|
|
382
|
+
*
|
|
383
|
+
* isNonLayoutEqual(a, b); // true (layout changed, but non-layout didn't)
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
declare function isNonLayoutEqual<T extends GraphNode | GraphEdge>(a: T, b: T): boolean;
|
|
387
|
+
//#endregion
|
|
337
388
|
//#region src/diff.d.ts
|
|
338
389
|
/**
|
|
339
390
|
* Compute a structured diff from graph `a` to graph `b` by matching IDs.
|
|
@@ -577,4 +628,4 @@ declare function getCoverage<N, E>(graph: Graph<N, E>, steps: GraphStep<N, E>[],
|
|
|
577
628
|
from?: string;
|
|
578
629
|
}): CoverageStats;
|
|
579
630
|
//#endregion
|
|
580
|
-
export { type AStarOptions, type AllPairsShortestPathsOptions, type CoverageStats, type DeleteNodeOptions, type EdgeChange, type EdgeConfig, type EntitiesConfig, type EntitiesUpdate, type Graph, type GraphConfig, type GraphDiff, type GraphEdge, type GraphEntity, type
|
|
631
|
+
export { type AStarOptions, type AllPairsShortestPathsOptions, type CoverageStats, type DeleteNodeOptions, type EdgeChange, type EdgeConfig, type EntitiesConfig, type EntitiesUpdate, type EntityRect, type GirvanNewmanOptions, type Graph, type GraphConfig, type GraphDiff, type GraphEdge, type GraphEntity, type GraphFormatConverter, GraphInstance, type GraphNode, type GraphPatch, type GraphPath, type GraphPort, type GraphStep, type HITSResult, type IsomorphismOptions, type IterativeCentralityOptions, LAYOUT_KEYS, type LabelPropagationOptions, type MSTOptions, type NodeChange, type NodeConfig, type PathOptions, type PortConfig, type PortDirection, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualGraphEntity, type VisualGraphFormatConverter, type VisualNode, type VisualPort, type WalkContext, type WalkOptions, type WeightedWalkOptions, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,100 @@
|
|
|
1
1
|
import { o as invalidateIndex, t as getIndex } from "./indexing-DyfgLuzw.mjs";
|
|
2
|
-
import { A as
|
|
3
|
-
import { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
2
|
+
import { $ as createGraphPort, A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, G as GraphInstance, H as getInDegreeCentrality, I as getModularity, J as addNode, K as addEdge, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, Q as createGraphNode, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, X as createGraphEdge, Y as createGraph, Z as createGraphFromTransition, _ as getShortestPath, a as genPreorders, at as getNode, b as getSimplePaths, c as getAStarPath, ct as updateEdge, d as getCycles, et as createVisualGraph, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, it as getEdge, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, lt as updateEntities, m as getPostorders, n as dfs, nt as deleteEntities, o as genShortestPaths, ot as hasEdge, p as getPostorder, q as addEntities, r as genCycles, rt as deleteNode, s as genSimplePaths, st as hasNode, t as bfs, tt as deleteEdge, u as getConnectedComponents, ut as updateNode, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-C-S7u40k.mjs";
|
|
3
|
+
import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
|
|
4
4
|
import { n as createFormatConverter } from "./converter-B5CUD0r9.mjs";
|
|
5
5
|
|
|
6
|
+
//#region src/equivalence.ts
|
|
7
|
+
/** Shallow-compare two values, returning true if they differ. */
|
|
8
|
+
function differs$1(a, b) {
|
|
9
|
+
if (a === b) return false;
|
|
10
|
+
if (a == null || b == null) return a !== b;
|
|
11
|
+
if (typeof a === "object" && typeof b === "object") return JSON.stringify(a) !== JSON.stringify(b);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
const LAYOUT_KEYS = {
|
|
15
|
+
node: [
|
|
16
|
+
"x",
|
|
17
|
+
"y",
|
|
18
|
+
"width",
|
|
19
|
+
"height",
|
|
20
|
+
"style",
|
|
21
|
+
"color",
|
|
22
|
+
"shape"
|
|
23
|
+
],
|
|
24
|
+
edge: [
|
|
25
|
+
"x",
|
|
26
|
+
"y",
|
|
27
|
+
"width",
|
|
28
|
+
"height",
|
|
29
|
+
"style",
|
|
30
|
+
"color"
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
const LAYOUT_KEY_SET = {
|
|
34
|
+
node: new Set(LAYOUT_KEYS.node),
|
|
35
|
+
edge: new Set(LAYOUT_KEYS.edge)
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Compare two entities on a given set of keys.
|
|
39
|
+
* If `keys` is omitted or empty, compares all own keys of `a`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { createGraphNode, areEntitiesEqual, LAYOUT_KEYS } from '@statelyai/graph';
|
|
44
|
+
*
|
|
45
|
+
* const a = createGraphNode({ id: 'n1', label: 'hello', x: 0 });
|
|
46
|
+
* const b = createGraphNode({ id: 'n1', label: 'hello', x: 100 });
|
|
47
|
+
*
|
|
48
|
+
* areEntitiesEqual(a, b, LAYOUT_KEYS.node); // false (x differs)
|
|
49
|
+
* areEntitiesEqual(a, b, NON_LAYOUT_KEYS.node); // true
|
|
50
|
+
* areEntitiesEqual(a, b); // false (compares all keys)
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function areEntitiesEqual(a, b, keys) {
|
|
54
|
+
const compareKeys = keys && keys.length > 0 ? keys : Object.keys(a);
|
|
55
|
+
for (const key of compareKeys) if (differs$1(a[key], b[key])) return false;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Compare two entities on layout keys only (position, size, style, color, shape).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { createGraphNode, isLayoutEqual } from '@statelyai/graph';
|
|
64
|
+
*
|
|
65
|
+
* const a = createGraphNode({ id: 'n1', x: 0, y: 0 });
|
|
66
|
+
* const b = createGraphNode({ id: 'n1', x: 100, y: 200 });
|
|
67
|
+
*
|
|
68
|
+
* isLayoutEqual(a, b); // false
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function isLayoutEqual(a, b) {
|
|
72
|
+
return areEntitiesEqual(a, b, LAYOUT_KEYS[a.type]);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Compare two entities on non-layout keys only (id, data, connections, labels, etc.).
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { createGraphNode, isNonLayoutEqual } from '@statelyai/graph';
|
|
80
|
+
*
|
|
81
|
+
* const a = createGraphNode({ id: 'n1', label: 'hello', x: 0 });
|
|
82
|
+
* const b = createGraphNode({ id: 'n1', label: 'hello', x: 100 });
|
|
83
|
+
*
|
|
84
|
+
* isNonLayoutEqual(a, b); // true (layout changed, but non-layout didn't)
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function isNonLayoutEqual(a, b) {
|
|
88
|
+
const skip = LAYOUT_KEY_SET[a.type];
|
|
89
|
+
const keys = Object.keys(a);
|
|
90
|
+
for (let i = 0; i < keys.length; i++) {
|
|
91
|
+
if (skip.has(keys[i])) continue;
|
|
92
|
+
if (differs$1(a[keys[i]], b[keys[i]])) return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
6
98
|
//#region src/diff.ts
|
|
7
99
|
function nodeToConfig$1(node) {
|
|
8
100
|
const config = { id: node.id };
|
|
@@ -813,4 +905,4 @@ function getCoverage(graph, steps, options) {
|
|
|
813
905
|
}
|
|
814
906
|
|
|
815
907
|
//#endregion
|
|
816
|
-
export { GraphInstance, addEdge, addEntities, addNode, applyPatches, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getChildren, getConnectedComponents, getCoverage, getCycles, getDegree, getDepth, getDescendants, getDiff, getEdge,
|
|
908
|
+
export { GraphInstance, LAYOUT_KEYS, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
|
package/dist/queries.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as GraphNode, p as GraphEdge, u as Graph, y as GraphPort } from "./types-F3j-sr2X.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/queries.d.ts
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ import { _ as GraphNode, b as GraphPort, p as GraphEdge, u as Graph } from "./ty
|
|
|
18
18
|
* // => [edge e1, edge e2]
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
declare function getEdgesOf<E>(graph: Graph<
|
|
21
|
+
declare function getEdgesOf<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
22
22
|
/**
|
|
23
23
|
* Returns incoming edges to a node.
|
|
24
24
|
*
|
|
@@ -34,7 +34,7 @@ declare function getEdgesOf<E>(graph: Graph<any, E>, nodeId: string): GraphEdge<
|
|
|
34
34
|
* // => []
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
declare function getInEdges<E>(graph: Graph<
|
|
37
|
+
declare function getInEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
38
38
|
/**
|
|
39
39
|
* Returns outgoing edges from a node.
|
|
40
40
|
*
|
|
@@ -50,9 +50,9 @@ declare function getInEdges<E>(graph: Graph<any, E>, nodeId: string): GraphEdge<
|
|
|
50
50
|
* // => []
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
declare function getOutEdges<E>(graph: Graph<
|
|
53
|
+
declare function getOutEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
54
54
|
/**
|
|
55
|
-
* Returns
|
|
55
|
+
* Returns all edges from `sourceId` to `targetId`.
|
|
56
56
|
* For undirected graphs, checks both directions.
|
|
57
57
|
*
|
|
58
58
|
* @example
|
|
@@ -61,13 +61,13 @@ declare function getOutEdges<E>(graph: Graph<any, E>, nodeId: string): GraphEdge
|
|
|
61
61
|
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
62
62
|
* edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
|
|
63
63
|
* });
|
|
64
|
-
*
|
|
65
|
-
* // => edge e1
|
|
66
|
-
*
|
|
67
|
-
* // =>
|
|
64
|
+
* getEdgesBetween(graph, 'a', 'b');
|
|
65
|
+
* // => [edge e1]
|
|
66
|
+
* getEdgesBetween(graph, 'b', 'a');
|
|
67
|
+
* // => [] (directed graph)
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
|
-
declare function
|
|
70
|
+
declare function getEdgesBetween<N, E>(graph: Graph<N, E>, sourceId: string, targetId: string): GraphEdge<E>[];
|
|
71
71
|
/**
|
|
72
72
|
* Returns direct successor nodes (targets of outgoing edges).
|
|
73
73
|
*
|
|
@@ -469,7 +469,7 @@ declare function getSinks<N>(graph: Graph<N>): GraphNode<N>[];
|
|
|
469
469
|
* getPort(graph, 'a', 'missing'); // => undefined
|
|
470
470
|
* ```
|
|
471
471
|
*/
|
|
472
|
-
declare function getPort<
|
|
472
|
+
declare function getPort<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string, portName: string): GraphPort<P> | undefined;
|
|
473
473
|
/**
|
|
474
474
|
* Get all ports on a node. Returns `[]` if the node has no ports or doesn't exist.
|
|
475
475
|
*
|
|
@@ -487,7 +487,7 @@ declare function getPort<P = any>(graph: Graph<any, any, any, P>, nodeId: string
|
|
|
487
487
|
* getPorts(graph, 'a'); // => [port in, port out]
|
|
488
488
|
* ```
|
|
489
489
|
*/
|
|
490
|
-
declare function getPorts<
|
|
490
|
+
declare function getPorts<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string): GraphPort<P>[];
|
|
491
491
|
/**
|
|
492
492
|
* Get all edges connected to a specific port on a node.
|
|
493
493
|
*
|
|
@@ -510,6 +510,6 @@ declare function getPorts<P = any>(graph: Graph<any, any, any, P>, nodeId: strin
|
|
|
510
510
|
* getEdgesByPort(graph, 'a', 'out'); // => [edge e1]
|
|
511
511
|
* ```
|
|
512
512
|
*/
|
|
513
|
-
declare function getEdgesByPort<E
|
|
513
|
+
declare function getEdgesByPort<N, E>(graph: Graph<N, E>, nodeId: string, portName: string): GraphEdge<E>[];
|
|
514
514
|
//#endregion
|
|
515
|
-
export { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
515
|
+
export { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf };
|
package/dist/queries.mjs
CHANGED
|
@@ -73,7 +73,7 @@ function getOutEdges(graph, nodeId) {
|
|
|
73
73
|
return (idx.outEdges.get(nodeId) ?? []).map((eid) => graph.edges[idx.edgeById.get(eid)]);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Returns
|
|
76
|
+
* Returns all edges from `sourceId` to `targetId`.
|
|
77
77
|
* For undirected graphs, checks both directions.
|
|
78
78
|
*
|
|
79
79
|
* @example
|
|
@@ -82,28 +82,35 @@ function getOutEdges(graph, nodeId) {
|
|
|
82
82
|
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
83
83
|
* edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
|
|
84
84
|
* });
|
|
85
|
-
*
|
|
86
|
-
* // => edge e1
|
|
87
|
-
*
|
|
88
|
-
* // =>
|
|
85
|
+
* getEdgesBetween(graph, 'a', 'b');
|
|
86
|
+
* // => [edge e1]
|
|
87
|
+
* getEdgesBetween(graph, 'b', 'a');
|
|
88
|
+
* // => [] (directed graph)
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
function
|
|
91
|
+
function getEdgesBetween(graph, sourceId, targetId) {
|
|
92
92
|
const idx = getIndex(graph);
|
|
93
|
+
const result = [];
|
|
94
|
+
const seen = /* @__PURE__ */ new Set();
|
|
93
95
|
const outIds = idx.outEdges.get(sourceId) ?? [];
|
|
94
96
|
for (const eid of outIds) {
|
|
95
97
|
const ai = idx.edgeById.get(eid);
|
|
96
98
|
const e = graph.edges[ai];
|
|
97
|
-
if (e.targetId === targetId)
|
|
99
|
+
if (e.targetId === targetId) {
|
|
100
|
+
seen.add(eid);
|
|
101
|
+
result.push(e);
|
|
102
|
+
}
|
|
98
103
|
}
|
|
99
104
|
if (graph.type === "undirected") {
|
|
100
105
|
const outIds2 = idx.outEdges.get(targetId) ?? [];
|
|
101
106
|
for (const eid of outIds2) {
|
|
107
|
+
if (seen.has(eid)) continue;
|
|
102
108
|
const ai = idx.edgeById.get(eid);
|
|
103
109
|
const e = graph.edges[ai];
|
|
104
|
-
if (e.targetId === sourceId)
|
|
110
|
+
if (e.targetId === sourceId) result.push(e);
|
|
105
111
|
}
|
|
106
112
|
}
|
|
113
|
+
return result;
|
|
107
114
|
}
|
|
108
115
|
/**
|
|
109
116
|
* Returns direct successor nodes (targets of outgoing edges).
|
|
@@ -758,4 +765,4 @@ function getEdgesByPort(graph, nodeId, portName) {
|
|
|
758
765
|
}
|
|
759
766
|
|
|
760
767
|
//#endregion
|
|
761
|
-
export { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
768
|
+
export { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf };
|
|
@@ -5,16 +5,14 @@ interface EntityRect {
|
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
interface
|
|
8
|
+
/** Shared optional visual/style props for nodes, edges, ports. */
|
|
9
|
+
interface GraphEntity {
|
|
10
10
|
x?: number;
|
|
11
11
|
y?: number;
|
|
12
12
|
width?: number;
|
|
13
13
|
height?: number;
|
|
14
14
|
style?: Record<string, string | number>;
|
|
15
15
|
}
|
|
16
|
-
/** Resolved entity base — optional visual props (non-visual graphs may omit). */
|
|
17
|
-
interface GraphEntity extends GraphEntityConfig {}
|
|
18
16
|
/** Visual entity base — required position/size. */
|
|
19
17
|
interface VisualGraphEntity {
|
|
20
18
|
x: number;
|
|
@@ -24,7 +22,7 @@ interface VisualGraphEntity {
|
|
|
24
22
|
style?: Record<string, string | number>;
|
|
25
23
|
}
|
|
26
24
|
type PortDirection = 'in' | 'out' | 'inout';
|
|
27
|
-
interface PortConfig<TPortData = any> extends
|
|
25
|
+
interface PortConfig<TPortData = any> extends GraphEntity {
|
|
28
26
|
name: string;
|
|
29
27
|
direction?: PortDirection;
|
|
30
28
|
label?: string;
|
|
@@ -36,7 +34,12 @@ interface GraphPort<TPortData = any> extends GraphEntity {
|
|
|
36
34
|
label?: string;
|
|
37
35
|
data: TPortData;
|
|
38
36
|
}
|
|
39
|
-
interface VisualPort<TPortData = any> extends
|
|
37
|
+
interface VisualPort<TPortData = any> extends GraphPort<TPortData> {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
}
|
|
40
43
|
interface GraphConfig<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> {
|
|
41
44
|
id?: string;
|
|
42
45
|
type?: 'directed' | 'undirected';
|
|
@@ -47,17 +50,17 @@ interface GraphConfig<TNodeData = any, TEdgeData = any, TGraphData = any, TPortD
|
|
|
47
50
|
direction?: 'up' | 'down' | 'left' | 'right';
|
|
48
51
|
style?: Record<string, string | number>;
|
|
49
52
|
}
|
|
50
|
-
interface NodeConfig<TNodeData = any, TPortData = any> extends
|
|
53
|
+
interface NodeConfig<TNodeData = any, TPortData = any> extends GraphEntity {
|
|
51
54
|
id: string;
|
|
52
55
|
parentId?: string | null;
|
|
53
56
|
initialNodeId?: string;
|
|
54
|
-
label?: string;
|
|
57
|
+
label?: string | null;
|
|
55
58
|
data?: TNodeData;
|
|
56
59
|
ports?: PortConfig<TPortData>[];
|
|
57
60
|
shape?: string;
|
|
58
61
|
color?: string;
|
|
59
62
|
}
|
|
60
|
-
interface EdgeConfig<TEdgeData = any> extends
|
|
63
|
+
interface EdgeConfig<TEdgeData = any> extends GraphEntity {
|
|
61
64
|
/**
|
|
62
65
|
* The id of the edge.
|
|
63
66
|
*/
|
|
@@ -102,7 +105,7 @@ interface GraphNode<TNodeData = any, TPortData = any> extends GraphEntity {
|
|
|
102
105
|
id: string;
|
|
103
106
|
parentId?: string | null;
|
|
104
107
|
initialNodeId?: string | null;
|
|
105
|
-
label?: string;
|
|
108
|
+
label?: string | null;
|
|
106
109
|
data: TNodeData;
|
|
107
110
|
ports?: GraphPort<TPortData>[];
|
|
108
111
|
shape?: string;
|
|
@@ -127,11 +130,19 @@ interface GraphEdge<TEdgeData = any> extends GraphEntity {
|
|
|
127
130
|
data: TEdgeData;
|
|
128
131
|
color?: string;
|
|
129
132
|
}
|
|
130
|
-
interface VisualNode<TNodeData = any, TPortData = any> extends
|
|
131
|
-
|
|
133
|
+
interface VisualNode<TNodeData = any, TPortData = any> extends GraphNode<TNodeData, TPortData> {
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
width: number;
|
|
137
|
+
height: number;
|
|
132
138
|
ports?: VisualPort<TPortData>[];
|
|
133
139
|
}
|
|
134
|
-
interface VisualEdge<TEdgeData = any> extends
|
|
140
|
+
interface VisualEdge<TEdgeData = any> extends GraphEdge<TEdgeData> {
|
|
141
|
+
x: number;
|
|
142
|
+
y: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}
|
|
135
146
|
interface VisualGraph<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> extends Omit<Graph<TNodeData, TEdgeData, TGraphData, TPortData>, 'nodes' | 'edges'> {
|
|
136
147
|
nodes: VisualNode<TNodeData, TPortData>[];
|
|
137
148
|
edges: VisualEdge<TEdgeData>[];
|
|
@@ -176,6 +187,8 @@ interface PathOptions<TEdgeData = any> {
|
|
|
176
187
|
to?: string;
|
|
177
188
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
178
189
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
190
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
191
|
+
algorithm?: 'dijkstra' | 'bellman-ford';
|
|
179
192
|
}
|
|
180
193
|
interface SinglePathOptions<TEdgeData = any> {
|
|
181
194
|
/** Source node ID. Default: graph.initialNodeId, else sole inDegree-0 node */
|
|
@@ -184,6 +197,8 @@ interface SinglePathOptions<TEdgeData = any> {
|
|
|
184
197
|
to: string;
|
|
185
198
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
186
199
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
200
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
201
|
+
algorithm?: 'dijkstra' | 'bellman-ford';
|
|
187
202
|
}
|
|
188
203
|
interface AStarOptions<TEdgeData = any> {
|
|
189
204
|
/** Source node ID. */
|
|
@@ -209,8 +224,8 @@ interface MSTOptions<TEdgeData = any> {
|
|
|
209
224
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
210
225
|
}
|
|
211
226
|
interface AllPairsShortestPathsOptions<TEdgeData = any> {
|
|
212
|
-
/** Algorithm to use. Default: 'dijkstra'. */
|
|
213
|
-
algorithm?: 'floyd-warshall' | 'dijkstra';
|
|
227
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
228
|
+
algorithm?: 'floyd-warshall' | 'dijkstra' | 'bellman-ford';
|
|
214
229
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
215
230
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
216
231
|
}
|
|
@@ -337,4 +352,4 @@ interface TransitionOptions<TState, TEvent> {
|
|
|
337
352
|
id?: string;
|
|
338
353
|
}
|
|
339
354
|
//#endregion
|
|
340
|
-
export {
|
|
355
|
+
export { VisualEdge as A, NodeConfig as C, SinglePathOptions as D, PortDirection as E, VisualNode as F, VisualPort as I, WalkContext as L, VisualGraphConfig as M, VisualGraphEntity as N, TransitionOptions as O, VisualGraphFormatConverter as P, WalkOptions as R, NodeChange as S, PortConfig as T, GraphPatch as _, EdgeChange as a, GraphStep as b, EntitiesUpdate as c, GraphConfig as d, GraphDiff as f, GraphNode as g, GraphFormatConverter as h, DeleteNodeOptions as i, VisualGraph as j, TraversalOptions as k, EntityRect as l, GraphEntity as m, AllPairsShortestPathsOptions as n, EdgeConfig as o, GraphEdge as p, CoverageStats as r, EntitiesConfig as s, AStarOptions as t, Graph as u, GraphPath as v, PathOptions as w, MSTOptions as x, GraphPort as y, WeightedWalkOptions as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/graph",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "A TypeScript-first graph library with plain JSON-serializable objects",
|
|
6
6
|
"author": "David Khourshid <david@stately.ai>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"schemas"
|
|
51
51
|
],
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"publint": "^0.3.15",
|
|
53
54
|
"@changesets/changelog-github": "^0.5.2",
|
|
54
55
|
"@changesets/cli": "^2.29.8",
|
|
55
56
|
"@types/d3-array": "^3.2.2",
|
|
@@ -103,6 +104,8 @@
|
|
|
103
104
|
"dev": "tsdown --watch",
|
|
104
105
|
"test": "vitest",
|
|
105
106
|
"typecheck": "tsc --noEmit",
|
|
107
|
+
"verify": "pnpm typecheck && pnpm test -- --run && pnpm build && pnpm validate:package",
|
|
108
|
+
"validate:package": "publint && tsx scripts/smoke-package.ts",
|
|
106
109
|
"generate-schema": "tsx scripts/generate-json-schema.ts",
|
|
107
110
|
"changeset": "changeset",
|
|
108
111
|
"version": "changeset version",
|