@statelyai/graph 0.6.0 → 0.7.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.
@@ -1,7 +1,16 @@
1
1
  import { a as indexUpdateEdgeEndpoints, i as indexReparentNode, n as indexAddEdge, o as invalidateIndex, r as indexAddNode, t as getIndex } from "./indexing-DyfgLuzw.mjs";
2
2
 
3
3
  //#region src/graph.ts
4
- function resolveNode(config) {
4
+ /**
5
+ * Create a resolved graph node from a config. Fills in defaults.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const node = createGraphNode({ id: 'a', data: { label: 'hi' } });
10
+ * // { type: 'node', id: 'a', label: '', data: { label: 'hi' } }
11
+ * ```
12
+ */
13
+ function createGraphNode(config) {
5
14
  if (!config.id) throw new Error("Node id must be a non-empty string");
6
15
  if (config.parentId === "") throw new Error("Node parentId must be a non-empty string");
7
16
  const node = {
@@ -21,7 +30,16 @@ function resolveNode(config) {
21
30
  if (config.style !== void 0) node.style = config.style;
22
31
  return node;
23
32
  }
24
- function resolveEdge(config) {
33
+ /**
34
+ * Create a resolved graph edge from a config. Fills in defaults.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const edge = createGraphEdge({ id: 'e1', sourceId: 'a', targetId: 'b' });
39
+ * // { type: 'edge', id: 'e1', sourceId: 'a', targetId: 'b', label: null, data: undefined }
40
+ * ```
41
+ */
42
+ function createGraphEdge(config) {
25
43
  if (!config.id) throw new Error("Edge id must be a non-empty string");
26
44
  if (!config.sourceId) throw new Error("Edge sourceId must be a non-empty string");
27
45
  if (!config.targetId) throw new Error("Edge targetId must be a non-empty string");
@@ -58,8 +76,8 @@ function createGraph(config) {
58
76
  id: config?.id ?? "",
59
77
  type: config?.type ?? "directed",
60
78
  initialNodeId: config?.initialNodeId ?? null,
61
- nodes: (config?.nodes ?? []).map(resolveNode),
62
- edges: (config?.edges ?? []).map(resolveEdge),
79
+ nodes: (config?.nodes ?? []).map(createGraphNode),
80
+ edges: (config?.edges ?? []).map(createGraphEdge),
63
81
  data: config?.data ?? void 0
64
82
  };
65
83
  if (config?.direction !== void 0) graph.direction = config.direction;
@@ -257,7 +275,7 @@ function hasEdge(graph, id) {
257
275
  * ```
258
276
  */
259
277
  function addNode(graph, config) {
260
- const node = resolveNode(config);
278
+ const node = createGraphNode(config);
261
279
  const idx = getIndex(graph);
262
280
  if (idx.nodeById.has(config.id)) throw new Error(`Node "${config.id}" already exists`);
263
281
  if (config.parentId && !idx.nodeById.has(config.parentId)) throw new Error(`Parent node "${config.parentId}" does not exist`);
@@ -276,7 +294,7 @@ function addNode(graph, config) {
276
294
  * ```
277
295
  */
278
296
  function addEdge(graph, config) {
279
- const edge = resolveEdge(config);
297
+ const edge = createGraphEdge(config);
280
298
  const idx = getIndex(graph);
281
299
  if (idx.edgeById.has(config.id)) throw new Error(`Edge "${config.id}" already exists`);
282
300
  if (!idx.nodeById.has(config.sourceId)) throw new Error(`Source node "${config.sourceId}" does not exist`);
@@ -2121,4 +2139,4 @@ function joinPaths(headPath, tailPath) {
2121
2139
  }
2122
2140
 
2123
2141
  //#endregion
2124
- export { addEntities as A, hasEdge as B, hasPath as C, joinPaths as D, isTree as E, deleteEdge as F, updateEdge as H, deleteEntities as I, deleteNode as L, createGraph as M, createGraphFromTransition as N, GraphInstance as O, createVisualGraph as P, getEdge as R, getTopologicalSort as S, isConnected as T, updateEntities as U, hasNode as V, updateNode as W, getShortestPath as _, genPreorders as a, getSimplePaths as b, getAStarPath as c, getCycles as d, getMinimumSpanningTree as f, getPreorders as g, getPreorder as h, genPostorders as i, addNode as j, addEdge as k, getAllPairsShortestPaths as l, getPostorders as m, dfs as n, genShortestPaths as o, getPostorder as p, genCycles as r, genSimplePaths as s, bfs as t, getConnectedComponents as u, getShortestPaths as v, isAcyclic as w, getStronglyConnectedComponents as x, getSimplePath as y, getNode as z };
2142
+ export { addEntities as A, getEdge as B, hasPath as C, joinPaths as D, isTree as E, createGraphNode as F, updateEntities as G, hasEdge as H, createVisualGraph as I, updateNode as K, deleteEdge as L, createGraph as M, createGraphEdge as N, GraphInstance as O, createGraphFromTransition as P, deleteEntities as R, getTopologicalSort as S, isConnected as T, hasNode as U, getNode as V, updateEdge as W, getShortestPath as _, genPreorders as a, getSimplePaths as b, getAStarPath as c, getCycles as d, getMinimumSpanningTree as f, getPreorders as g, getPreorder as h, genPostorders as i, addNode as j, addEdge as k, getAllPairsShortestPaths as l, getPostorders as m, dfs as n, genShortestPaths as o, getPostorder as p, genCycles as r, genSimplePaths as s, bfs as t, getConnectedComponents as u, getShortestPaths as v, isAcyclic as w, getStronglyConnectedComponents as x, getSimplePath as y, deleteNode as z };
@@ -1,4 +1,4 @@
1
- import { C as SinglePathOptions, S as PathOptions, T as TraversalOptions, _ as GraphPath, h as GraphNode, n as AllPairsShortestPathsOptions, t as AStarOptions, u as Graph, y as MSTOptions } from "./types-DF-HNw50.mjs";
1
+ import { C as SinglePathOptions, S as PathOptions, T as TraversalOptions, _ as GraphPath, h as GraphNode, n as AllPairsShortestPathsOptions, t as AStarOptions, u as Graph, y as MSTOptions } from "./types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/algorithms.d.ts
4
4
 
@@ -1,3 +1,3 @@
1
- import { C as hasPath, D as joinPaths, E as isTree, S as getTopologicalSort, T as isConnected, _ 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, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath } from "./algorithms-oVD9PYil.mjs";
1
+ import { C as hasPath, D as joinPaths, E as isTree, S as getTopologicalSort, T as isConnected, _ 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, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath } from "./algorithms-Dw5jEwDK.mjs";
2
2
 
3
3
  export { 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 };
@@ -1,4 +1,4 @@
1
- import { u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/adjacency-list/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/converter/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/cytoscape/index.d.ts
4
4
  interface CytoscapeNode {
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/d3/index.d.ts
4
4
  interface D3Node {
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/dot/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/edge-list/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { D as VisualGraph, k as VisualGraphFormatConverter } from "../../types-DF-HNw50.mjs";
1
+ import { D as VisualGraph, k as VisualGraphFormatConverter } from "../../types-DkKjaQW3.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 { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/gexf/index.d.ts
4
4
  declare function toGEXF(graph: Graph): string;
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/gml/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/graphml/index.d.ts
4
4
  declare function toGraphML(graph: Graph): string;
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/jgf/index.d.ts
4
4
  interface JGFNode {
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/mermaid/sequence.d.ts
4
4
  interface SequenceNodeData {
@@ -1836,7 +1836,10 @@ function fromMermaidClass(input) {
1836
1836
  if (classBlockMatch) {
1837
1837
  currentClass = classBlockMatch[1];
1838
1838
  const node = ensureNode(currentClass);
1839
- if (classBlockMatch[2]) node.data.genericType = classBlockMatch[2];
1839
+ if (classBlockMatch[2]) {
1840
+ node.data ??= {};
1841
+ node.data.genericType = classBlockMatch[2];
1842
+ }
1840
1843
  inClassBlock = true;
1841
1844
  braceDepth = 1;
1842
1845
  continue;
@@ -1852,10 +1855,13 @@ function fromMermaidClass(input) {
1852
1855
  }
1853
1856
  const annotMatch = line.match(/^<<(.+)>>$/);
1854
1857
  if (annotMatch) {
1855
- nodeMap.get(currentClass).data.annotation = annotMatch[1];
1858
+ const node$1 = nodeMap.get(currentClass);
1859
+ node$1.data ??= {};
1860
+ node$1.data.annotation = annotMatch[1];
1856
1861
  continue;
1857
1862
  }
1858
1863
  const node = nodeMap.get(currentClass);
1864
+ node.data ??= {};
1859
1865
  if (!node.data.members) node.data.members = [];
1860
1866
  node.data.members.push(parseMember(line));
1861
1867
  continue;
@@ -1863,12 +1869,16 @@ function fromMermaidClass(input) {
1863
1869
  const classInlineMatch = line.match(/^class\s+(\S+?)(?:~(.+?)~)?\s*$/);
1864
1870
  if (classInlineMatch) {
1865
1871
  const node = ensureNode(classInlineMatch[1]);
1866
- if (classInlineMatch[2]) node.data.genericType = classInlineMatch[2];
1872
+ if (classInlineMatch[2]) {
1873
+ node.data ??= {};
1874
+ node.data.genericType = classInlineMatch[2];
1875
+ }
1867
1876
  continue;
1868
1877
  }
1869
1878
  const annotLineMatch = line.match(/^<<(.+)>>\s+(\S+)\s*$/);
1870
1879
  if (annotLineMatch) {
1871
1880
  const node = ensureNode(annotLineMatch[2]);
1881
+ node.data ??= {};
1872
1882
  node.data.annotation = annotLineMatch[1];
1873
1883
  continue;
1874
1884
  }
@@ -1876,6 +1886,7 @@ function fromMermaidClass(input) {
1876
1886
  if (inlineMemberMatch) {
1877
1887
  if (!parseRelationship(line)) {
1878
1888
  const node = ensureNode(inlineMemberMatch[1]);
1889
+ node.data ??= {};
1879
1890
  if (!node.data.members) node.data.members = [];
1880
1891
  node.data.members.push(parseMember(inlineMemberMatch[2]));
1881
1892
  continue;
@@ -2067,7 +2078,10 @@ function fromMermaidER(input) {
2067
2078
  const attrMatch = line.match(/^(\S+)\s+(\S+)(?:\s+(PK|FK|UK))?(?:\s+"([^"]*)")?$/);
2068
2079
  if (attrMatch) {
2069
2080
  const node = nodeMap.get(currentEntity);
2070
- if (!node.data.attributes) node.data.attributes = [];
2081
+ if (!node.data?.attributes) {
2082
+ if (!node.data) node.data = {};
2083
+ node.data.attributes = [];
2084
+ }
2071
2085
  node.data.attributes.push({
2072
2086
  type: attrMatch[1],
2073
2087
  name: attrMatch[2],
@@ -2289,7 +2303,7 @@ function toMermaidMindmap(graph) {
2289
2303
  const indent = " ".repeat(depth + 1);
2290
2304
  const shape = child.shape;
2291
2305
  const brackets = shape ? SHAPE_TO_BRACKETS[shape] : void 0;
2292
- const label = escapeMermaidLabel(child.label);
2306
+ const label = escapeMermaidLabel(child.label ?? child.id);
2293
2307
  const text = brackets ? `${brackets[0]}${label}${brackets[1]}` : label;
2294
2308
  let extra = "";
2295
2309
  if (child.data?.icon) extra = `\n${" ".repeat(depth + 2)}::icon(${child.data.icon})`;
@@ -2442,7 +2456,7 @@ function fromMermaidBlock(input) {
2442
2456
  const label = spanMatch[2] ?? id;
2443
2457
  const span = parseInt(spanMatch[3], 10);
2444
2458
  const node = ensureNode(id, label);
2445
- node.data.span = span;
2459
+ if (node.data) node.data.span = span;
2446
2460
  continue;
2447
2461
  }
2448
2462
  const parts = line.split(/\s+/);
@@ -1,4 +1,4 @@
1
- import { m as GraphFormatConverter, u as Graph } from "../../types-DF-HNw50.mjs";
1
+ import { m as GraphFormatConverter, u as Graph } from "../../types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/formats/tgf/index.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { D as VisualGraph, k as VisualGraphFormatConverter } from "../../types-DF-HNw50.mjs";
1
+ import { D as VisualGraph, k as VisualGraphFormatConverter } from "../../types-DkKjaQW3.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,10 +1,30 @@
1
- import { A as VisualNode, C as SinglePathOptions, D as VisualGraph, E as VisualEdge, M as WalkOptions, N as WeightedWalkOptions, O as VisualGraphConfig, S as PathOptions, T as TraversalOptions, _ as GraphPath, a as EdgeChange, b as NodeChange, c as EntitiesUpdate, d as GraphConfig, f as GraphDiff, g as GraphPatch, h as GraphNode, i as DeleteNodeOptions, j as WalkContext, l as EntityRect, m as GraphFormatConverter, n as AllPairsShortestPathsOptions, o as EdgeConfig, p as GraphEdge, r as CoverageStats, s as EntitiesConfig, t as AStarOptions, u as Graph, v as GraphStep, w as TransitionOptions, x as NodeConfig, y as MSTOptions } from "./types-DF-HNw50.mjs";
1
+ import { A as VisualNode, C as SinglePathOptions, D as VisualGraph, E as VisualEdge, M as WalkOptions, N as WeightedWalkOptions, O as VisualGraphConfig, S as PathOptions, T as TraversalOptions, _ as GraphPath, a as EdgeChange, b as NodeChange, c as EntitiesUpdate, d as GraphConfig, f as GraphDiff, g as GraphPatch, h as GraphNode, i as DeleteNodeOptions, j as WalkContext, l as EntityRect, m as GraphFormatConverter, n as AllPairsShortestPathsOptions, o as EdgeConfig, p as GraphEdge, r as CoverageStats, s as EntitiesConfig, t as AStarOptions, u as Graph, v as GraphStep, w as TransitionOptions, x as NodeConfig, y as MSTOptions } from "./types-DkKjaQW3.mjs";
2
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";
3
3
  import { createFormatConverter } from "./formats/converter/index.mjs";
4
4
  import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgeBetween, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
5
5
 
6
6
  //#region src/graph.d.ts
7
7
 
8
+ /**
9
+ * Create a resolved graph node from a config. Fills in defaults.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const node = createGraphNode({ id: 'a', data: { label: 'hi' } });
14
+ * // { type: 'node', id: 'a', label: '', data: { label: 'hi' } }
15
+ * ```
16
+ */
17
+ declare function createGraphNode<T = any>(config: NodeConfig<T>): GraphNode<T>;
18
+ /**
19
+ * Create a resolved graph edge from a config. Fills in defaults.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const edge = createGraphEdge({ id: 'e1', sourceId: 'a', targetId: 'b' });
24
+ * // { type: 'edge', id: 'e1', sourceId: 'a', targetId: 'b', label: null, data: undefined }
25
+ * ```
26
+ */
27
+ declare function createGraphEdge<T = any>(config: EdgeConfig<T>): GraphEdge<T>;
8
28
  /**
9
29
  * Create a graph from a config. Resolves defaults for all fields.
10
30
  *
@@ -547,4 +567,4 @@ declare function getCoverage<N, E>(graph: Graph<N, E>, steps: GraphStep<N, E>[],
547
567
  from?: string;
548
568
  }): CoverageStats;
549
569
  //#endregion
550
- 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 GraphFormatConverter, GraphInstance, type GraphNode, type GraphPatch, type GraphPath, type GraphStep, type MSTOptions, type NodeChange, type NodeConfig, type PathOptions, type EntityRect as Positioned, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualNode, type WalkContext, type WalkOptions, type WeightedWalkOptions, addEdge, addEntities, addNode, applyPatches, bfs, createFormatConverter, createGraph, createGraphFromTransition, 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, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, getParent, getPatches, 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 };
570
+ 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 GraphFormatConverter, GraphInstance, type GraphNode, type GraphPatch, type GraphPath, type GraphStep, type MSTOptions, type NodeChange, type NodeConfig, type PathOptions, type EntityRect as Positioned, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualNode, type WalkContext, type WalkOptions, type WeightedWalkOptions, addEdge, addEntities, addNode, applyPatches, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, 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, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, getParent, getPatches, 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 };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { o as invalidateIndex, t as getIndex } from "./indexing-DyfgLuzw.mjs";
2
- import { A as addEntities, B as hasEdge, C as hasPath, D as joinPaths, E as isTree, F as deleteEdge, H as updateEdge, I as deleteEntities, L as deleteNode, M as createGraph, N as createGraphFromTransition, O as GraphInstance, P as createVisualGraph, R as getEdge, S as getTopologicalSort, T as isConnected, U as updateEntities, V as hasNode, W as updateNode, _ 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, 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 getNode } from "./algorithms-oVD9PYil.mjs";
2
+ import { A as addEntities, B as getEdge, C as hasPath, D as joinPaths, E as isTree, F as createGraphNode, G as updateEntities, H as hasEdge, I as createVisualGraph, K as updateNode, L as deleteEdge, M as createGraph, N as createGraphEdge, O as GraphInstance, P as createGraphFromTransition, R as deleteEntities, S as getTopologicalSort, T as isConnected, U as hasNode, V as getNode, W as updateEdge, _ 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, 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 deleteNode } from "./algorithms-Dw5jEwDK.mjs";
3
3
  import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgeBetween, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, 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
 
@@ -813,4 +813,4 @@ function getCoverage(graph, steps, options) {
813
813
  }
814
814
 
815
815
  //#endregion
816
- export { GraphInstance, addEdge, addEntities, addNode, applyPatches, bfs, createFormatConverter, createGraph, createGraphFromTransition, 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, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, getParent, getPatches, 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 };
816
+ export { GraphInstance, addEdge, addEntities, addNode, applyPatches, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, 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, getEdgesOf, getInDegree, getInEdges, getLCA, getMinimumSpanningTree, getNeighbors, getNode, getOutDegree, getOutEdges, getParent, getPatches, 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 };
@@ -1,4 +1,4 @@
1
- import { h as GraphNode, p as GraphEdge, u as Graph } from "./types-DF-HNw50.mjs";
1
+ import { h as GraphNode, p as GraphEdge, u as Graph } from "./types-DkKjaQW3.mjs";
2
2
 
3
3
  //#region src/queries.d.ts
4
4
 
package/dist/queries.mjs CHANGED
@@ -565,7 +565,7 @@ function getRelativeDistanceMap(graph, parentId) {
565
565
  if (parentId !== null) {
566
566
  const pi = idx.nodeById.get(parentId);
567
567
  if (pi !== void 0) sourceId = graph.nodes[pi].initialNodeId ?? null;
568
- } else sourceId = graph.initialNodeId;
568
+ } else sourceId = graph.initialNodeId ?? null;
569
569
  if (!sourceId) return {};
570
570
  const siblingSet = new Set(idx.childNodes.get(parentId) ?? []);
571
571
  if (!siblingSet.has(sourceId)) return {};
@@ -6,7 +6,7 @@ declare const NodeSchema: z.ZodObject<{
6
6
  id: z.ZodString;
7
7
  parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
8
  initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
- label: z.ZodString;
9
+ label: z.ZodOptional<z.ZodString>;
10
10
  data: z.ZodAny;
11
11
  x: z.ZodOptional<z.ZodNumber>;
12
12
  y: z.ZodOptional<z.ZodNumber>;
@@ -21,7 +21,7 @@ declare const EdgeSchema: z.ZodObject<{
21
21
  id: z.ZodString;
22
22
  sourceId: z.ZodString;
23
23
  targetId: z.ZodString;
24
- label: z.ZodString;
24
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
25
25
  weight: z.ZodOptional<z.ZodNumber>;
26
26
  data: z.ZodAny;
27
27
  x: z.ZodOptional<z.ZodNumber>;
@@ -37,13 +37,13 @@ declare const GraphSchema: z.ZodObject<{
37
37
  directed: "directed";
38
38
  undirected: "undirected";
39
39
  }>;
40
- initialNodeId: z.ZodNullable<z.ZodString>;
40
+ initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
41
  nodes: z.ZodArray<z.ZodObject<{
42
42
  type: z.ZodLiteral<"node">;
43
43
  id: z.ZodString;
44
44
  parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
45
  initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
- label: z.ZodString;
46
+ label: z.ZodOptional<z.ZodString>;
47
47
  data: z.ZodAny;
48
48
  x: z.ZodOptional<z.ZodNumber>;
49
49
  y: z.ZodOptional<z.ZodNumber>;
@@ -58,7 +58,7 @@ declare const GraphSchema: z.ZodObject<{
58
58
  id: z.ZodString;
59
59
  sourceId: z.ZodString;
60
60
  targetId: z.ZodString;
61
- label: z.ZodString;
61
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
62
  weight: z.ZodOptional<z.ZodNumber>;
63
63
  data: z.ZodAny;
64
64
  x: z.ZodOptional<z.ZodNumber>;
package/dist/schemas.mjs CHANGED
@@ -7,7 +7,7 @@ const NodeSchema = z.object({
7
7
  id: z.string(),
8
8
  parentId: z.string().nullable().optional(),
9
9
  initialNodeId: z.string().nullable().optional(),
10
- label: z.string(),
10
+ label: z.string().optional(),
11
11
  data: z.any(),
12
12
  x: z.number().optional(),
13
13
  y: z.number().optional(),
@@ -22,7 +22,7 @@ const EdgeSchema = z.object({
22
22
  id: z.string(),
23
23
  sourceId: z.string(),
24
24
  targetId: z.string(),
25
- label: z.string(),
25
+ label: z.string().nullable().optional(),
26
26
  weight: z.number().optional(),
27
27
  data: z.any(),
28
28
  x: z.number().optional(),
@@ -35,7 +35,7 @@ const EdgeSchema = z.object({
35
35
  const GraphSchema = z.object({
36
36
  id: z.string(),
37
37
  type: z.enum(["directed", "undirected"]),
38
- initialNodeId: z.string().nullable(),
38
+ initialNodeId: z.string().nullable().optional(),
39
39
  nodes: z.array(NodeSchema),
40
40
  edges: z.array(EdgeSchema),
41
41
  data: z.any(),
@@ -63,7 +63,7 @@ interface EdgeConfig<TEdgeData = any> {
63
63
  interface Graph<TNodeData = any, TEdgeData = any, TGraphData = any> {
64
64
  id: string;
65
65
  type: 'directed' | 'undirected';
66
- initialNodeId: string | null;
66
+ initialNodeId?: string | null;
67
67
  nodes: GraphNode<TNodeData>[];
68
68
  edges: GraphEdge<TEdgeData>[];
69
69
  data: TGraphData;
@@ -75,7 +75,7 @@ interface GraphNode<TNodeData = any> {
75
75
  id: string;
76
76
  parentId?: string | null;
77
77
  initialNodeId?: string | null;
78
- label: string;
78
+ label?: string;
79
79
  data: TNodeData;
80
80
  x?: number;
81
81
  y?: number;
@@ -90,7 +90,7 @@ interface GraphEdge<TEdgeData = any> {
90
90
  id: string;
91
91
  sourceId: string;
92
92
  targetId: string;
93
- label: string | null;
93
+ label?: string | null;
94
94
  /**
95
95
  * Optional numeric weight for the edge.
96
96
  * Used by pathfinding, MST, and other weighted algorithms.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statelyai/graph",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.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",