@statelyai/graph 0.13.0 → 1.0.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.
Files changed (55) hide show
  1. package/README.md +3 -1
  2. package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
  3. package/dist/{algorithms-BNDQcHU3.mjs → algorithms-Ba7o7niK.mjs} +29 -25
  4. package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
  5. package/dist/algorithms.d.mts +1 -1
  6. package/dist/algorithms.mjs +1 -1
  7. package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
  8. package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
  9. package/dist/format-support.mjs +31 -2
  10. package/dist/formats/adjacency-list/index.d.mts +1 -1
  11. package/dist/formats/adjacency-list/index.mjs +1 -1
  12. package/dist/formats/converter/index.d.mts +1 -60
  13. package/dist/formats/converter/index.mjs +1 -1
  14. package/dist/formats/cytoscape/index.d.mts +1 -1
  15. package/dist/formats/cytoscape/index.mjs +3 -3
  16. package/dist/formats/d2/index.d.mts +109 -0
  17. package/dist/formats/d2/index.mjs +1086 -0
  18. package/dist/formats/d3/index.d.mts +2 -2
  19. package/dist/formats/d3/index.mjs +3 -3
  20. package/dist/formats/dot/index.d.mts +1 -1
  21. package/dist/formats/dot/index.mjs +3 -3
  22. package/dist/formats/edge-list/index.d.mts +1 -1
  23. package/dist/formats/edge-list/index.mjs +1 -1
  24. package/dist/formats/elk/index.d.mts +1 -1
  25. package/dist/formats/elk/index.mjs +2 -2
  26. package/dist/formats/gexf/index.d.mts +1 -1
  27. package/dist/formats/gexf/index.mjs +9 -3
  28. package/dist/formats/gml/index.d.mts +1 -1
  29. package/dist/formats/gml/index.mjs +3 -3
  30. package/dist/formats/graphml/index.d.mts +1 -1
  31. package/dist/formats/graphml/index.mjs +11 -4
  32. package/dist/formats/jgf/index.d.mts +1 -1
  33. package/dist/formats/jgf/index.mjs +3 -3
  34. package/dist/formats/mermaid/index.d.mts +1 -1
  35. package/dist/formats/mermaid/index.mjs +9 -9
  36. package/dist/formats/tgf/index.d.mts +1 -1
  37. package/dist/formats/tgf/index.mjs +2 -2
  38. package/dist/formats/xyflow/index.d.mts +1 -1
  39. package/dist/formats/xyflow/index.mjs +2 -2
  40. package/dist/index-CHoriXZD.d.mts +638 -0
  41. package/dist/index-D9Kj6Fe3.d.mts +61 -0
  42. package/dist/index.d.mts +6 -631
  43. package/dist/index.mjs +8 -7
  44. package/dist/mode-D8OnHFBk.mjs +15 -0
  45. package/dist/queries-BlkA1HAN.d.mts +516 -0
  46. package/dist/queries.d.mts +1 -514
  47. package/dist/queries.mjs +17 -15
  48. package/dist/schemas.d.mts +21 -10
  49. package/dist/schemas.mjs +12 -2
  50. package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
  51. package/package.json +2 -1
  52. package/schemas/edge.schema.json +11 -0
  53. package/schemas/graph.schema.json +24 -3
  54. package/schemas/node.schema.json +6 -0
  55. /package/dist/{indexing-DUl3kTqm.mjs → indexing-DR8M1vBy.mjs} +0 -0
package/dist/index.d.mts CHANGED
@@ -1,631 +1,6 @@
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-CnZ01raw.mjs";
2
- import { A as genCycles, B as getStronglyConnectedComponents, C as getMinimumSpanningTree, D as getPostorders, E as getPostorder, F as getCycles, G as getTopologicalSort, H as bfs, I as getShortestPath, J as isConnected, K as hasPath, L as getShortestPaths, M as genSimplePaths, N as getAStarPath, O as getPreorder, P as getAllPairsShortestPaths, R as getSimplePath, S as getPageRank, T as genPreorders, U as dfs, V as joinPaths, W as getConnectedComponents, Y as isTree, _ as getDegreeCentrality, a as getBridges, b as getInDegreeCentrality, c as genGirvanNewmanCommunities, d as getLabelPropagationCommunities, f as getModularity, g as getClosenessCentrality, h as getBetweennessCentrality, i as getBiconnectedComponents, j as genShortestPaths, k as getPreorders, l as getGirvanNewmanCommunities, m as IterativeCentralityOptions, n as isIsomorphic, o as GirvanNewmanOptions, p as HITSResult, q as isAcyclic, r as getArticulationPoints, s as LabelPropagationOptions, t as IsomorphismOptions, u as getGreedyModularityCommunities, v as getEigenvectorCentrality, w as genPostorders, x as getOutDegreeCentrality, y as getHITS, z as getSimplePaths } from "./algorithms-BlM-qoJb.mjs";
3
- import { createFormatConverter } from "./formats/converter/index.mjs";
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
-
6
- //#region src/graph.d.ts
7
-
8
- /**
9
- * Create a resolved graph port from a config. Fills in defaults.
10
- *
11
- * @example
12
- * ```ts
13
- * const port = createGraphPort({ name: 'output', direction: 'out' });
14
- * // { name: 'output', direction: 'out', data: null }
15
- * ```
16
- */
17
- declare function createGraphPort<P = any>(config: PortConfig<P>): GraphPort<P>;
18
- /**
19
- * Create a resolved graph node from a config. Fills in defaults.
20
- *
21
- * @example
22
- * ```ts
23
- * const node = createGraphNode({ id: 'a', data: { label: 'hi' } });
24
- * // { type: 'node', id: 'a', label: '', data: { label: 'hi' } }
25
- * ```
26
- */
27
- declare function createGraphNode<N = any, P = any>(config: NodeConfig<N, P>): GraphNode<N, P>;
28
- /**
29
- * Create a resolved graph edge from a config. Fills in defaults.
30
- *
31
- * @example
32
- * ```ts
33
- * const edge = createGraphEdge({ id: 'e1', sourceId: 'a', targetId: 'b' });
34
- * // { type: 'edge', id: 'e1', sourceId: 'a', targetId: 'b', label: null, data: null }
35
- * ```
36
- */
37
- declare function createGraphEdge<T = any>(config: EdgeConfig<T>): GraphEdge<T>;
38
- /**
39
- * Create a graph from a config. Resolves defaults for all fields.
40
- *
41
- * @example
42
- * ```ts
43
- * const graph = createGraph({
44
- * nodes: [{ id: 'a' }, { id: 'b' }],
45
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
46
- * });
47
- * ```
48
- */
49
- declare function createGraph<N = any, E = any, G = any, P = any>(config?: GraphConfig<N, E, G, P>): Graph<N, E, G, P>;
50
- /**
51
- * Create a visual graph with required position/size on all nodes and edges.
52
- *
53
- * @example
54
- * ```ts
55
- * const graph = createVisualGraph({
56
- * nodes: [{ id: 'a', x: 0, y: 0, width: 100, height: 50 }],
57
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'a', x: 0, y: 0, width: 0, height: 0 }],
58
- * });
59
- * // graph.nodes[0].x === 0
60
- * ```
61
- */
62
- declare function createVisualGraph<N = any, E = any, G = any, P = any>(config?: VisualGraphConfig<N, E, G, P>): VisualGraph<N, E, G, P>;
63
- /**
64
- * Create a graph by BFS exploration of a transition function.
65
- * Each unique state becomes a node; each (state, event) -> nextState becomes an edge.
66
- *
67
- * - Node IDs are determined by `serializeState` (default: `JSON.stringify`).
68
- * - Edge IDs use the format `sourceId|serializedEvent|targetId` for uniqueness
69
- * and debuggability. Edge labels are just the serialized event string.
70
- *
71
- * @example
72
- * ```ts
73
- * const graph = createGraphFromTransition(
74
- * (state, event) => {
75
- * if (state === 'green' && event === 'TIMER') return 'yellow';
76
- * if (state === 'yellow' && event === 'TIMER') return 'red';
77
- * if (state === 'red' && event === 'TIMER') return 'green';
78
- * return state;
79
- * },
80
- * {
81
- * initialState: 'green',
82
- * events: ['TIMER'],
83
- * serializeState: (s) => s,
84
- * serializeEvent: (e) => e,
85
- * },
86
- * );
87
- * // graph.nodes.length === 3
88
- * ```
89
- */
90
- declare function createGraphFromTransition<TState, TEvent>(transition: (state: TState, event: TEvent) => TState, options: TransitionOptions<TState, TEvent>): Graph<TState, TEvent>;
91
- /**
92
- * Get a node by id, or `undefined` if not found.
93
- *
94
- * @example
95
- * ```ts
96
- * const graph = createGraph({ nodes: [{ id: 'a' }] });
97
- * const node = getNode(graph, 'a'); // GraphNode
98
- * const missing = getNode(graph, 'z'); // undefined
99
- * ```
100
- */
101
- declare function getNode<N>(graph: Graph<N>, id: string): GraphNode<N> | undefined;
102
- /**
103
- * Get an edge by id, or `undefined` if not found.
104
- *
105
- * @example
106
- * ```ts
107
- * const graph = createGraph({
108
- * nodes: [{ id: 'a' }, { id: 'b' }],
109
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
110
- * });
111
- * const edge = getEdge(graph, 'e1'); // GraphEdge
112
- * const missing = getEdge(graph, 'z'); // undefined
113
- * ```
114
- */
115
- declare function getEdge<N, E>(graph: Graph<N, E>, id: string): GraphEdge<E> | undefined;
116
- /**
117
- * Check if a node exists in the graph.
118
- *
119
- * @example
120
- * ```ts
121
- * const graph = createGraph({ nodes: [{ id: 'a' }] });
122
- * hasNode(graph, 'a'); // true
123
- * hasNode(graph, 'z'); // false
124
- * ```
125
- */
126
- declare function hasNode(graph: Graph, id: string): boolean;
127
- /**
128
- * Check if an edge exists in the graph.
129
- *
130
- * @example
131
- * ```ts
132
- * const graph = createGraph({
133
- * nodes: [{ id: 'a' }, { id: 'b' }],
134
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
135
- * });
136
- * hasEdge(graph, 'e1'); // true
137
- * hasEdge(graph, 'z'); // false
138
- * ```
139
- */
140
- declare function hasEdge(graph: Graph, id: string): boolean;
141
- /**
142
- * **Mutable.** Add a node to the graph. Mutates `graph.nodes` in place.
143
- * @returns The resolved node that was added.
144
- *
145
- * @example
146
- * ```ts
147
- * const graph = createGraph();
148
- * const node = addNode(graph, { id: 'a', label: 'Node A' });
149
- * // graph.nodes.length === 1
150
- * ```
151
- */
152
- declare function addNode<N, P = any>(graph: Graph<N, any, any, P>, config: NodeConfig<N, P>): GraphNode<N, P>;
153
- /**
154
- * **Mutable.** Add an edge to the graph. Mutates `graph.edges` in place.
155
- * @returns The resolved edge that was added.
156
- *
157
- * @example
158
- * ```ts
159
- * const graph = createGraph({ nodes: [{ id: 'a' }, { id: 'b' }] });
160
- * const edge = addEdge(graph, { id: 'e1', sourceId: 'a', targetId: 'b' });
161
- * // graph.edges.length === 1
162
- * ```
163
- */
164
- declare function addEdge<N, E>(graph: Graph<N, E>, config: EdgeConfig<E>): GraphEdge<E>;
165
- /**
166
- * **Mutable.** Delete a node and its connected edges. Mutates `graph.nodes`
167
- * and `graph.edges` in place.
168
- *
169
- * By default, children are deleted recursively.
170
- * With `{ reparent: true }`, children are re-parented to the deleted node's parent.
171
- *
172
- * @example
173
- * ```ts
174
- * const graph = createGraph({
175
- * nodes: [{ id: 'a' }, { id: 'b' }],
176
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
177
- * });
178
- * deleteNode(graph, 'a');
179
- * // graph.nodes.length === 1, edge e1 also removed
180
- * ```
181
- */
182
- declare function deleteNode(graph: Graph, id: string, opts?: DeleteNodeOptions): void;
183
- /**
184
- * **Mutable.** Delete an edge. Mutates `graph.edges` in place.
185
- *
186
- * @example
187
- * ```ts
188
- * const graph = createGraph({
189
- * nodes: [{ id: 'a' }, { id: 'b' }],
190
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
191
- * });
192
- * deleteEdge(graph, 'e1');
193
- * // graph.edges.length === 0
194
- * ```
195
- */
196
- declare function deleteEdge(graph: Graph, id: string): void;
197
- /**
198
- * **Mutable.** Update a node in place.
199
- * @returns The updated node.
200
- *
201
- * @example
202
- * ```ts
203
- * const graph = createGraph({ nodes: [{ id: 'a', label: 'old' }] });
204
- * const updated = updateNode(graph, 'a', { label: 'new' });
205
- * // updated.label === 'new'
206
- * ```
207
- */
208
- declare function updateNode<N, P = any>(graph: Graph<N, any, any, P>, id: string, update: Partial<Omit<NodeConfig<N, P>, 'id'>>): GraphNode<N, P>;
209
- /**
210
- * **Mutable.** Update an edge in place.
211
- * @returns The updated edge.
212
- *
213
- * @example
214
- * ```ts
215
- * const graph = createGraph({
216
- * nodes: [{ id: 'a' }, { id: 'b' }],
217
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b', label: 'old' }],
218
- * });
219
- * const updated = updateEdge(graph, 'e1', { label: 'new' });
220
- * // updated.label === 'new'
221
- * ```
222
- */
223
- declare function updateEdge<N, E>(graph: Graph<N, E>, id: string, update: Partial<Omit<EdgeConfig<E>, 'id'>>): GraphEdge<E>;
224
- /**
225
- * **Mutable.** Add multiple nodes and edges to the graph.
226
- * Nodes are added first, then edges (so edges can reference new nodes).
227
- *
228
- * @example
229
- * ```ts
230
- * const graph = createGraph();
231
- * addEntities(graph, {
232
- * nodes: [{ id: 'a' }, { id: 'b' }],
233
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
234
- * });
235
- * // graph.nodes.length === 2, graph.edges.length === 1
236
- * ```
237
- */
238
- declare function addEntities<N, E>(graph: Graph<N, E>, entities: EntitiesConfig<N, E>): void;
239
- /**
240
- * **Mutable.** Delete entities by id(s). Automatically detects whether each id
241
- * is a node or edge. Node deletions cascade to children and connected edges.
242
- *
243
- * @example
244
- * ```ts
245
- * const graph = createGraph({
246
- * nodes: [{ id: 'a' }, { id: 'b' }],
247
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
248
- * });
249
- * deleteEntities(graph, ['a', 'e1']);
250
- * // graph.nodes.length === 1, graph.edges.length === 0
251
- * ```
252
- */
253
- declare function deleteEntities(graph: Graph, ids: string | string[], opts?: DeleteNodeOptions): void;
254
- /**
255
- * **Mutable.** Update multiple nodes and edges in place.
256
- * Each entry must include an `id` to identify which entity to update.
257
- *
258
- * @example
259
- * ```ts
260
- * const graph = createGraph({
261
- * nodes: [{ id: 'a', label: 'old' }],
262
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'a', label: 'old' }],
263
- * });
264
- * updateEntities(graph, {
265
- * nodes: [{ id: 'a', label: 'new' }],
266
- * edges: [{ id: 'e1', label: 'new' }],
267
- * });
268
- * ```
269
- */
270
- declare function updateEntities<N, E>(graph: Graph<N, E>, updates: EntitiesUpdate<N, E>): void;
271
- /**
272
- * OOP wrapper around a plain `Graph` object.
273
- * Delegates to the standalone mutable functions.
274
- *
275
- * @example
276
- * ```ts
277
- * const instance = new GraphInstance({
278
- * nodes: [{ id: 'a' }, { id: 'b' }],
279
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
280
- * });
281
- * instance.addNode({ id: 'c' });
282
- * instance.hasNode('c'); // true
283
- * instance.toJSON(); // plain Graph object
284
- * ```
285
- */
286
- declare class GraphInstance<N = any, E = any, G = any, P = any> {
287
- graph: Graph<N, E, G, P>;
288
- constructor(config?: GraphConfig<N, E, G, P>);
289
- /**
290
- * Wrap an existing plain graph object.
291
- *
292
- * @example
293
- * ```ts
294
- * const graph = createGraph({ nodes: [{ id: 'a' }] });
295
- * const instance = GraphInstance.from(graph);
296
- * instance.hasNode('a'); // true
297
- * ```
298
- */
299
- static from<N = any, E = any, G = any, P = any>(graph: Graph<N, E, G, P>): GraphInstance<N, E, G, P>;
300
- get id(): string;
301
- get type(): "directed" | "undirected";
302
- get nodes(): GraphNode<N, P>[];
303
- get edges(): GraphEdge<E>[];
304
- get data(): G;
305
- getNode(id: string): GraphNode<N, any> | undefined;
306
- getEdge(id: string): GraphEdge<E> | undefined;
307
- hasNode(id: string): boolean;
308
- hasEdge(id: string): boolean;
309
- addNode(config: NodeConfig<N, P>): GraphNode<N, P>;
310
- addEdge(config: EdgeConfig<E>): GraphEdge<E>;
311
- deleteNode(id: string, opts?: DeleteNodeOptions): void;
312
- deleteEdge(id: string): void;
313
- updateNode(id: string, update: Partial<Omit<NodeConfig<N, P>, 'id'>>): GraphNode<N, P>;
314
- updateEdge(id: string, update: Partial<Omit<EdgeConfig<E>, 'id'>>): GraphEdge<E>;
315
- addEntities(entities: EntitiesConfig<N, E, P>): void;
316
- deleteEntities(ids: string | string[], opts?: DeleteNodeOptions): void;
317
- updateEntities(updates: EntitiesUpdate<N, E, P>): void;
318
- toJSON(): Graph<N, E, G, P>;
319
- }
320
- //#endregion
321
- //#region src/indexing.d.ts
322
- /**
323
- * Clear the cached index. Call this if you mutate graph.nodes/edges directly.
324
- *
325
- * @example
326
- * ```ts
327
- * import { createGraph, invalidateIndex, getIndex } from '@statelyai/graph';
328
- *
329
- * const graph = createGraph({ nodes: [{ id: 'a' }], edges: [] });
330
- * // manually mutate nodes array
331
- * graph.nodes.push({ type: 'node', id: 'b', parentId: null, initialNodeId: null, label: '', data: undefined });
332
- * invalidateIndex(graph); // forces rebuild on next getIndex()
333
- * ```
334
- */
335
- declare function invalidateIndex(graph: Graph): void;
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
388
- //#region src/diff.d.ts
389
- /**
390
- * Compute a structured diff from graph `a` to graph `b` by matching IDs.
391
- *
392
- * @example
393
- * ```ts
394
- * import { createGraph, getDiff } from '@statelyai/graph';
395
- *
396
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
397
- * const b = createGraph({ nodes: [{ id: 'n1', label: 'hello' }, { id: 'n2' }], edges: [] });
398
- *
399
- * const diff = getDiff(a, b);
400
- * // diff.nodes.added → [{ id: 'n2' }]
401
- * // diff.nodes.updated → [{ id: 'n1', old: { label: '' }, new: { label: 'hello' } }]
402
- * ```
403
- */
404
- declare function getDiff<N, E>(a: Graph<N, E>, b: Graph<N, E>): GraphDiff<N, E>;
405
- /**
406
- * Check if a diff has zero changes.
407
- *
408
- * @example
409
- * ```ts
410
- * import { createGraph, getDiff, isEmptyDiff } from '@statelyai/graph';
411
- *
412
- * const g = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
413
- * const diff = getDiff(g, g);
414
- * isEmptyDiff(diff); // true
415
- * ```
416
- */
417
- declare function isEmptyDiff(diff: GraphDiff): boolean;
418
- /**
419
- * Invert a diff: swap added/removed, swap old/new in updates.
420
- *
421
- * @example
422
- * ```ts
423
- * import { createGraph, getDiff, invertDiff } from '@statelyai/graph';
424
- *
425
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
426
- * const b = createGraph({ nodes: [{ id: 'n2' }], edges: [] });
427
- *
428
- * const diff = getDiff(a, b);
429
- * const inv = invertDiff(diff);
430
- * // inv.nodes.added contains n1 (was removed)
431
- * // inv.nodes.removed contains n2 (was added)
432
- * ```
433
- */
434
- declare function invertDiff<N, E>(diff: GraphDiff<N, E>): GraphDiff<N, E>;
435
- /**
436
- * Compute an ordered patch list from graph `a` to graph `b`.
437
- * Order: delete edges → delete nodes → add nodes → add edges → update nodes → update edges.
438
- *
439
- * @example
440
- * ```ts
441
- * import { createGraph, getPatches } from '@statelyai/graph';
442
- *
443
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
444
- * const b = createGraph({ nodes: [{ id: 'n1' }, { id: 'n2' }], edges: [] });
445
- *
446
- * const patches = getPatches(a, b);
447
- * // patches → [{ op: 'addNode', node: { id: 'n2' } }]
448
- * ```
449
- */
450
- declare function getPatches<N, E>(a: Graph<N, E>, b: Graph<N, E>): GraphPatch<N, E>[];
451
- /**
452
- * **Mutable.** Apply patches to a graph in order.
453
- * Delegates to addNode/deleteNode/updateNode/addEdge/deleteEdge/updateEdge.
454
- *
455
- * @example
456
- * ```ts
457
- * import { createGraph, getPatches, applyPatches } from '@statelyai/graph';
458
- *
459
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
460
- * const b = createGraph({ nodes: [{ id: 'n1' }, { id: 'n2' }], edges: [] });
461
- *
462
- * const patches = getPatches(a, b);
463
- * applyPatches(a, patches);
464
- * // a now contains both n1 and n2
465
- * ```
466
- */
467
- declare function applyPatches<N, E>(graph: Graph<N, E>, patches: GraphPatch<N, E>[]): void;
468
- /**
469
- * Flatten a structured diff into an ordered patch list.
470
- * Order: add nodes → update edges → delete edges → delete nodes → add edges → update nodes.
471
- * This avoids cascading deletes removing edges that are being updated,
472
- * and ensures new nodes exist before edges reference them.
473
- *
474
- * @example
475
- * ```ts
476
- * import { createGraph, getDiff, toPatches } from '@statelyai/graph';
477
- *
478
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
479
- * const b = createGraph({ nodes: [{ id: 'n2' }], edges: [] });
480
- *
481
- * const diff = getDiff(a, b);
482
- * const patches = toPatches(diff);
483
- * // patches → [{ op: 'addNode', ... }, { op: 'deleteNode', ... }]
484
- * ```
485
- */
486
- declare function toPatches<N, E>(diff: GraphDiff<N, E>): GraphPatch<N, E>[];
487
- /**
488
- * Group a patch list into a structured diff.
489
- *
490
- * @example
491
- * ```ts
492
- * import { createGraph, getPatches, toDiff } from '@statelyai/graph';
493
- *
494
- * const a = createGraph({ nodes: [{ id: 'n1' }], edges: [] });
495
- * const b = createGraph({ nodes: [{ id: 'n1' }, { id: 'n2' }], edges: [] });
496
- *
497
- * const patches = getPatches(a, b);
498
- * const diff = toDiff(patches);
499
- * // diff.nodes.added → [{ id: 'n2' }]
500
- * ```
501
- */
502
- declare function toDiff<N, E>(patches: GraphPatch<N, E>[]): GraphDiff<N, E>;
503
- //#endregion
504
- //#region src/transforms.d.ts
505
- /**
506
- * Flattens a hierarchical graph into a flat graph with only leaf nodes.
507
- *
508
- * - Edges targeting a compound node resolve to its initial child (recursively).
509
- * - Edges originating from a compound node expand to all leaf descendants.
510
- * - Only leaf nodes (nodes with no children) appear in the result.
511
- * - Duplicate edges (same source + target) are deduplicated.
512
- *
513
- * @example
514
- * ```ts
515
- * import { createGraph, flatten } from '@statelyai/graph';
516
- *
517
- * const graph = createGraph({
518
- * nodes: [
519
- * { id: 'parent', initialNodeId: 'child1' },
520
- * { id: 'child1', parentId: 'parent' },
521
- * { id: 'child2', parentId: 'parent' },
522
- * { id: 'other' },
523
- * ],
524
- * edges: [{ id: 'e1', sourceId: 'other', targetId: 'parent' }],
525
- * });
526
- *
527
- * const flat = flatten(graph);
528
- * // flat.nodes → [child1, child2, other] (leaf nodes only)
529
- * // flat.edges → edge from 'other' → 'child1' (resolved via initialNodeId)
530
- * ```
531
- */
532
- declare function flatten<N, E, G>(graph: Graph<N, E, G>): Graph<N, E, G>;
533
- /**
534
- * Returns the induced subgraph containing only the given node IDs
535
- * and edges whose endpoints are both in the set.
536
- *
537
- * Parent references to nodes outside the set are removed.
538
- *
539
- * @example
540
- * ```ts
541
- * import { createGraph, getSubgraph } from '@statelyai/graph';
542
- *
543
- * const graph = createGraph({
544
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
545
- * edges: [
546
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
547
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
548
- * ],
549
- * });
550
- *
551
- * const sub = getSubgraph(graph, ['a', 'b']);
552
- * // sub.nodes: [a, b], sub.edges: [ab]
553
- * ```
554
- */
555
- declare function getSubgraph<N, E, G>(graph: Graph<N, E, G>, nodeIds: string[]): Graph<N, E, G>;
556
- /**
557
- * Returns a new graph with all edge directions flipped (source ↔ target).
558
- * Optionally filters which edges to include.
559
- *
560
- * @example
561
- * ```ts
562
- * import { createGraph, reverseGraph } from '@statelyai/graph';
563
- *
564
- * const graph = createGraph({
565
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
566
- * edges: [
567
- * { id: 'ab', sourceId: 'a', targetId: 'b' },
568
- * { id: 'bc', sourceId: 'b', targetId: 'c' },
569
- * ],
570
- * });
571
- *
572
- * const rev = reverseGraph(graph);
573
- * // rev edges: b→a, c→b
574
- *
575
- * const filtered = reverseGraph(graph, (e) => e.id !== 'bc');
576
- * // filtered edges: b→a (only ab reversed, bc excluded)
577
- * ```
578
- */
579
- declare function reverseGraph<N, E, G>(graph: Graph<N, E, G>, filterEdge?: (edge: GraphEdge<E>) => boolean): Graph<N, E, G>;
580
- //#endregion
581
- //#region src/walks.d.ts
582
- /**
583
- * Random walk. At each node, picks a uniformly random outgoing edge.
584
- * Yields steps indefinitely (may revisit nodes) until a sink node is reached.
585
- */
586
- declare function genRandomWalk<N, E>(graph: Graph<N, E>, options?: WalkOptions<E>): Generator<GraphStep<N, E>>;
587
- /**
588
- * Weighted random walk. Edge selection probability proportional to weight.
589
- */
590
- declare function genWeightedRandomWalk<N, E>(graph: Graph<N, E>, options?: WeightedWalkOptions<E>): Generator<GraphStep<N, E>>;
591
- /**
592
- * Quick random walk targeting unvisited edges.
593
- * If unvisited outgoing edges exist, picks one randomly.
594
- * Otherwise, finds shortest path to a node with unvisited outgoing edges.
595
- */
596
- declare function genQuickRandomWalk<N, E>(graph: Graph<N, E>, options?: WalkOptions<E>): Generator<GraphStep<N, E>>;
597
- /**
598
- * Walk a predefined sequence of edge IDs.
599
- * Validates each edge exists and connects from the current position.
600
- */
601
- declare function genPredefinedWalk<N, E>(graph: Graph<N, E>, edgeIds: string[], options?: Pick<WalkOptions<E>, 'from'>): Generator<GraphStep<N, E>>;
602
- /**
603
- * Yield at most `n` steps from the source generator.
604
- */
605
- declare function takeSteps<N, E>(gen: Generator<GraphStep<N, E>>, n: number): Generator<GraphStep<N, E>>;
606
- /**
607
- * Yield steps until a specific node is reached.
608
- */
609
- declare function takeUntilNode<N, E>(gen: Generator<GraphStep<N, E>>, nodeId: string): Generator<GraphStep<N, E>>;
610
- /**
611
- * Yield steps until a specific edge is traversed.
612
- */
613
- declare function takeUntilEdge<N, E>(gen: Generator<GraphStep<N, E>>, edgeId: string): Generator<GraphStep<N, E>>;
614
- /**
615
- * Yield steps until node coverage reaches the target (0–1).
616
- */
617
- declare function takeUntilNodeCoverage<N, E>(gen: Generator<GraphStep<N, E>>, graph: Graph<N, E>, coverage: number, options?: {
618
- from?: string;
619
- }): Generator<GraphStep<N, E>>;
620
- /**
621
- * Yield steps until edge coverage reaches the target (0–1).
622
- */
623
- declare function takeUntilEdgeCoverage<N, E>(gen: Generator<GraphStep<N, E>>, graph: Graph<N, E>, coverage: number): Generator<GraphStep<N, E>>;
624
- /**
625
- * Compute coverage statistics for a completed walk.
626
- */
627
- declare function getCoverage<N, E>(graph: Graph<N, E>, steps: GraphStep<N, E>[], options?: {
628
- from?: string;
629
- }): CoverageStats;
630
- //#endregion
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 };
1
+ import { A as TraversalOptions, B as WeightedWalkOptions, C as NodeChange, D as PortDirection, E as PortConfig, F as VisualGraphFormatConverter, 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 GraphMode, h as GraphFormatConverter, 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-3-FS9NV2.mjs";
2
+ import { A as genCycles, B as getStronglyConnectedComponents, C as getMinimumSpanningTree, D as getPostorders, E as getPostorder, F as getCycles, G as getTopologicalSort, H as bfs, I as getShortestPath, J as isConnected, K as hasPath, L as getShortestPaths, M as genSimplePaths, N as getAStarPath, O as getPreorder, P as getAllPairsShortestPaths, R as getSimplePath, S as getPageRank, T as genPreorders, U as dfs, V as joinPaths, W as getConnectedComponents, Y as isTree, _ as getDegreeCentrality, a as getBridges, b as getInDegreeCentrality, c as genGirvanNewmanCommunities, d as getLabelPropagationCommunities, f as getModularity, g as getClosenessCentrality, h as getBetweennessCentrality, i as getBiconnectedComponents, j as genShortestPaths, k as getPreorders, l as getGirvanNewmanCommunities, m as IterativeCentralityOptions, n as isIsomorphic, o as GirvanNewmanOptions, p as HITSResult, q as isAcyclic, r as getArticulationPoints, s as LabelPropagationOptions, t as IsomorphismOptions, u as getGreedyModularityCommunities, v as getEigenvectorCentrality, w as genPostorders, x as getOutDegreeCentrality, y as getHITS, z as getSimplePaths } from "./algorithms-fTqmvhzP.mjs";
3
+ import { n as createFormatConverter } from "./index-D9Kj6Fe3.mjs";
4
+ import { A as addEntities, B as deleteNode, C as isLayoutEqual, D as isEdgeDirected, E as getEdgeMode, 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 areEntitiesEqual, T as invalidateIndex, U as hasEdge, V as getEdge, W as hasNode, _ as invertDiff, a as getCoverage, b as toPatches, c as takeUntilEdgeCoverage, d as flatten, f as getSubgraph, g as getPatches, h as getDiff, i as genWeightedRandomWalk, j as addNode, k as addEdge, l as takeUntilNode, m as applyPatches, n as genQuickRandomWalk, o as takeSteps, p as reverseGraph, q as updateNode, r as genRandomWalk, s as takeUntilEdge, t as genPredefinedWalk, u as takeUntilNodeCoverage, v as isEmptyDiff, w as isNonLayoutEqual, x as LAYOUT_KEYS, y as toDiff, z as deleteEntities } from "./index-CHoriXZD.mjs";
5
+ import { C as getSinks, D as isLeaf, E as isCompound, S as getSiblings, T as getSuccessors, _ as getPorts, a as getDescendants, b as getRelativeDistanceMap, c as getEdgesOf, d as getLCA, f as getNeighbors, g as getPort, h as getParent, i as getDepth, l as getInDegree, m as getOutEdges, n as getChildren, o as getEdgesBetween, p as getOutDegree, r as getDegree, s as getEdgesByPort, t as getAncestors, u as getInEdges, v as getPredecessors, w as getSources, x as getRoots, y as getRelativeDistance } from "./queries-BlkA1HAN.mjs";
6
+ export { AStarOptions, AllPairsShortestPathsOptions, CoverageStats, DeleteNodeOptions, EdgeChange, EdgeConfig, EntitiesConfig, EntitiesUpdate, EntityRect, GirvanNewmanOptions, Graph, GraphConfig, GraphDiff, GraphEdge, GraphEntity, GraphFormatConverter, GraphInstance, GraphMode, GraphNode, GraphPatch, GraphPath, GraphPort, GraphStep, HITSResult, IsomorphismOptions, IterativeCentralityOptions, LAYOUT_KEYS, LabelPropagationOptions, MSTOptions, NodeChange, NodeConfig, PathOptions, PortConfig, PortDirection, SinglePathOptions, TransitionOptions, TraversalOptions, VisualEdge, VisualGraph, VisualGraphConfig, VisualGraphEntity, VisualGraphFormatConverter, VisualNode, VisualPort, WalkContext, WalkOptions, 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, getEdgeMode, 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, isEdgeDirected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };