@statelyai/graph 0.8.0 → 0.9.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as TraversalOptions, B as WeightedWalkOptions, C as NodeChange, D as PortDirection, E as PortConfig, I as VisualNode, L as VisualPort, M as VisualGraph, N as VisualGraphConfig, O as SinglePathOptions, P as VisualGraphEntity, R as WalkContext, S as MSTOptions, T as PathOptions, _ as GraphNode, a as EdgeChange, b as GraphPort, c as EntitiesUpdate, d as GraphConfig, f as GraphDiff, g as GraphFormatConverter, h as GraphEntityConfig, i as DeleteNodeOptions, j as VisualEdge, k as TransitionOptions, 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 GraphPatch, w as NodeConfig, x as GraphStep, y as GraphPath, z as WalkOptions } from "./types-BzckPChi.mjs";
2
- import { bfs, dfs, genCycles, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getConnectedComponents, getCycles, getMinimumSpanningTree, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isTree, joinPaths } from "./algorithms.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-g2uWmPrb.mjs";
3
3
  import { createFormatConverter } from "./formats/converter/index.mjs";
4
4
  import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgeBetween, 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
 
@@ -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 GraphEntityConfig, type GraphFormatConverter, GraphInstance, type GraphNode, type GraphPatch, type GraphPath, type GraphPort, type GraphStep, type MSTOptions, type NodeChange, type NodeConfig, type PathOptions, type PortConfig, type PortDirection, type EntityRect as Positioned, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualGraphEntity, type VisualNode, type VisualPort, type WalkContext, type WalkOptions, type WeightedWalkOptions, 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, getEdgeBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, 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, isLeaf, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
631
+ export { type AStarOptions, type AllPairsShortestPathsOptions, type CoverageStats, type DeleteNodeOptions, type EdgeChange, type EdgeConfig, type EntitiesConfig, type EntitiesUpdate, type GirvanNewmanOptions, type Graph, type GraphConfig, type GraphDiff, type GraphEdge, type GraphEntity, type GraphEntityConfig, 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 EntityRect as Positioned, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualGraphEntity, 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, getEdgeBetween, 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 addEntities, B as deleteNode, C as hasPath, D as joinPaths, E as isTree, F as createGraphNode, G as updateEdge, H as getNode, I as createGraphPort, K as updateEntities, L as createVisualGraph, M as createGraph, N as createGraphEdge, O as GraphInstance, P as createGraphFromTransition, R as deleteEdge, S as getTopologicalSort, T as isConnected, U as hasEdge, V as getEdge, W as hasNode, _ 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 addNode, k as addEdge, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as updateNode, 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 deleteEntities } from "./algorithms-Pbj9dJB1.mjs";
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-3xvCxHzo.mjs";
3
3
  import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgeBetween, 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, getEdgeBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, 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, isLeaf, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
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, getEdgeBetween, 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statelyai/graph",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.9.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",