@statelyai/graph 0.13.0 → 2.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 (57) hide show
  1. package/README.md +57 -26
  2. package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-GeL1Cu-L.mjs} +5 -3
  3. package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-CsGNehct.d.mts} +137 -2
  4. package/dist/{algorithms-BNDQcHU3.mjs → algorithms-DF1pSQGv.mjs} +1494 -357
  5. package/dist/algorithms.d.mts +2 -2
  6. package/dist/algorithms.mjs +2 -2
  7. package/dist/{converter-Dspillnn.mjs → converter-DyCJJfTe.mjs} +2 -2
  8. package/dist/{edge-list-gKe8-iRa.mjs → edge-list-BcZ0h6zz.mjs} +1 -1
  9. package/dist/format-support.mjs +67 -11
  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 +5 -3
  16. package/dist/formats/d2/index.d.mts +109 -0
  17. package/dist/formats/d2/index.mjs +1100 -0
  18. package/dist/formats/d3/index.d.mts +2 -2
  19. package/dist/formats/d3/index.mjs +5 -3
  20. package/dist/formats/dot/index.d.mts +1 -1
  21. package/dist/formats/dot/index.mjs +24 -8
  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 +23 -16
  26. package/dist/formats/gexf/index.d.mts +1 -1
  27. package/dist/formats/gexf/index.mjs +30 -17
  28. package/dist/formats/gml/index.d.mts +1 -1
  29. package/dist/formats/gml/index.mjs +22 -13
  30. package/dist/formats/graphml/index.d.mts +1 -1
  31. package/dist/formats/graphml/index.mjs +83 -25
  32. package/dist/formats/jgf/index.d.mts +1 -1
  33. package/dist/formats/jgf/index.mjs +6 -3
  34. package/dist/formats/mermaid/index.d.mts +1 -1
  35. package/dist/formats/mermaid/index.mjs +57 -20
  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 +33 -6
  40. package/dist/index-D51lJnt2.d.mts +61 -0
  41. package/dist/index-DWmo1mIp.d.mts +697 -0
  42. package/dist/index.d.mts +6 -631
  43. package/dist/index.mjs +144 -295
  44. package/dist/mode-D8OnHFBk.mjs +15 -0
  45. package/dist/queries-BfXeTXRf.d.mts +547 -0
  46. package/dist/queries-KirMDR7e.mjs +980 -0
  47. package/dist/queries.d.mts +1 -514
  48. package/dist/queries.mjs +1 -766
  49. package/dist/schemas.d.mts +21 -10
  50. package/dist/schemas.mjs +35 -86
  51. package/dist/{types-CnZ01raw.d.mts → types-DNYdIU21.d.mts} +83 -11
  52. package/dist/validate-TtH-x3JV.mjs +190 -0
  53. package/package.json +14 -3
  54. package/schemas/edge.schema.json +11 -0
  55. package/schemas/graph.schema.json +24 -3
  56. package/schemas/node.schema.json +6 -0
  57. package/dist/indexing-DUl3kTqm.mjs +0 -137
@@ -1,515 +1,2 @@
1
- import { g as GraphNode, p as GraphEdge, u as Graph, y as GraphPort } from "./types-CnZ01raw.mjs";
2
-
3
- //#region src/queries.d.ts
4
-
5
- /**
6
- * Returns all edges (incoming + outgoing) connected to a node.
7
- *
8
- * @example
9
- * ```ts
10
- * const graph = createGraph({
11
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
12
- * edges: [
13
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
14
- * { id: 'e2', sourceId: 'c', targetId: 'b' },
15
- * ],
16
- * });
17
- * getEdgesOf(graph, 'b');
18
- * // => [edge e1, edge e2]
19
- * ```
20
- */
21
- declare function getEdgesOf<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
22
- /**
23
- * Returns incoming edges to a node.
24
- *
25
- * @example
26
- * ```ts
27
- * const graph = createGraph({
28
- * nodes: [{ id: 'a' }, { id: 'b' }],
29
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
30
- * });
31
- * getInEdges(graph, 'b');
32
- * // => [edge e1]
33
- * getInEdges(graph, 'a');
34
- * // => []
35
- * ```
36
- */
37
- declare function getInEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
38
- /**
39
- * Returns outgoing edges from a node.
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
- * getOutEdges(graph, 'a');
48
- * // => [edge e1]
49
- * getOutEdges(graph, 'b');
50
- * // => []
51
- * ```
52
- */
53
- declare function getOutEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
54
- /**
55
- * Returns all edges from `sourceId` to `targetId`.
56
- * For undirected graphs, checks both directions.
57
- *
58
- * @example
59
- * ```ts
60
- * const graph = createGraph({
61
- * nodes: [{ id: 'a' }, { id: 'b' }],
62
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
63
- * });
64
- * getEdgesBetween(graph, 'a', 'b');
65
- * // => [edge e1]
66
- * getEdgesBetween(graph, 'b', 'a');
67
- * // => [] (directed graph)
68
- * ```
69
- */
70
- declare function getEdgesBetween<N, E>(graph: Graph<N, E>, sourceId: string, targetId: string): GraphEdge<E>[];
71
- /**
72
- * Returns direct successor nodes (targets of outgoing edges).
73
- *
74
- * @example
75
- * ```ts
76
- * const graph = createGraph({
77
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
78
- * edges: [
79
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
80
- * { id: 'e2', sourceId: 'a', targetId: 'c' },
81
- * ],
82
- * });
83
- * getSuccessors(graph, 'a');
84
- * // => [node b, node c]
85
- * ```
86
- */
87
- declare function getSuccessors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
88
- /**
89
- * Returns direct predecessor nodes (sources of incoming edges).
90
- *
91
- * @example
92
- * ```ts
93
- * const graph = createGraph({
94
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
95
- * edges: [
96
- * { id: 'e1', sourceId: 'a', targetId: 'c' },
97
- * { id: 'e2', sourceId: 'b', targetId: 'c' },
98
- * ],
99
- * });
100
- * getPredecessors(graph, 'c');
101
- * // => [node a, node b]
102
- * ```
103
- */
104
- declare function getPredecessors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
105
- /**
106
- * Returns all neighbor nodes (successors + predecessors).
107
- *
108
- * @example
109
- * ```ts
110
- * const graph = createGraph({
111
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
112
- * edges: [
113
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
114
- * { id: 'e2', sourceId: 'c', targetId: 'b' },
115
- * ],
116
- * });
117
- * getNeighbors(graph, 'b');
118
- * // => [node a, node c]
119
- * ```
120
- */
121
- declare function getNeighbors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
122
- /**
123
- * Returns the total degree of a node (inDegree + outDegree).
124
- * For undirected graphs, each edge is counted once.
125
- *
126
- * @example
127
- * ```ts
128
- * const graph = createGraph({
129
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
130
- * edges: [
131
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
132
- * { id: 'e2', sourceId: 'c', targetId: 'b' },
133
- * ],
134
- * });
135
- * getDegree(graph, 'b'); // => 2
136
- * getDegree(graph, 'a'); // => 1
137
- * ```
138
- */
139
- declare function getDegree(graph: Graph, nodeId: string): number;
140
- /**
141
- * Returns the in-degree of a node (number of incoming edges).
142
- *
143
- * @example
144
- * ```ts
145
- * const graph = createGraph({
146
- * nodes: [{ id: 'a' }, { id: 'b' }],
147
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
148
- * });
149
- * getInDegree(graph, 'b'); // => 1
150
- * getInDegree(graph, 'a'); // => 0
151
- * ```
152
- */
153
- declare function getInDegree(graph: Graph, nodeId: string): number;
154
- /**
155
- * Returns the out-degree of a node (number of outgoing edges).
156
- *
157
- * @example
158
- * ```ts
159
- * const graph = createGraph({
160
- * nodes: [{ id: 'a' }, { id: 'b' }],
161
- * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
162
- * });
163
- * getOutDegree(graph, 'a'); // => 1
164
- * getOutDegree(graph, 'b'); // => 0
165
- * ```
166
- */
167
- declare function getOutDegree(graph: Graph, nodeId: string): number;
168
- /**
169
- * Returns direct children of a node in the hierarchy.
170
- * Pass `null` to get root-level nodes.
171
- *
172
- * @example
173
- * ```ts
174
- * const graph = createGraph({
175
- * nodes: [
176
- * { id: 'parent' },
177
- * { id: 'child1', parentId: 'parent' },
178
- * { id: 'child2', parentId: 'parent' },
179
- * ],
180
- * });
181
- * getChildren(graph, 'parent');
182
- * // => [node child1, node child2]
183
- * getChildren(graph, null);
184
- * // => [node parent]
185
- * ```
186
- */
187
- declare function getChildren<N>(graph: Graph<N>, nodeId: string | null): GraphNode<N>[];
188
- /**
189
- * Returns the parent node in the hierarchy, or `undefined` if root-level.
190
- *
191
- * @example
192
- * ```ts
193
- * const graph = createGraph({
194
- * nodes: [
195
- * { id: 'parent' },
196
- * { id: 'child', parentId: 'parent' },
197
- * ],
198
- * });
199
- * getParent(graph, 'child');
200
- * // => node parent
201
- * getParent(graph, 'parent');
202
- * // => undefined
203
- * ```
204
- */
205
- declare function getParent<N>(graph: Graph<N>, nodeId: string): GraphNode<N> | undefined;
206
- /**
207
- * Returns all ancestors from the node up to the root (nearest parent first).
208
- *
209
- * @example
210
- * ```ts
211
- * const graph = createGraph({
212
- * nodes: [
213
- * { id: 'root' },
214
- * { id: 'mid', parentId: 'root' },
215
- * { id: 'leaf', parentId: 'mid' },
216
- * ],
217
- * });
218
- * getAncestors(graph, 'leaf');
219
- * // => [node mid, node root]
220
- * ```
221
- */
222
- declare function getAncestors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
223
- /**
224
- * Returns all descendants recursively (depth-first).
225
- *
226
- * @example
227
- * ```ts
228
- * const graph = createGraph({
229
- * nodes: [
230
- * { id: 'root' },
231
- * { id: 'child', parentId: 'root' },
232
- * { id: 'grandchild', parentId: 'child' },
233
- * ],
234
- * });
235
- * getDescendants(graph, 'root');
236
- * // => [node child, node grandchild]
237
- * ```
238
- */
239
- declare function getDescendants<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
240
- /**
241
- * Returns all root nodes (nodes with no parent).
242
- *
243
- * @example
244
- * ```ts
245
- * const graph = createGraph({
246
- * nodes: [
247
- * { id: 'root1' },
248
- * { id: 'root2' },
249
- * { id: 'child', parentId: 'root1' },
250
- * ],
251
- * });
252
- * getRoots(graph);
253
- * // => [node root1, node root2]
254
- * ```
255
- */
256
- declare function getRoots<N>(graph: Graph<N>): GraphNode<N>[];
257
- /**
258
- * Whether a node has children (is a compound/group node).
259
- *
260
- * @example
261
- * ```ts
262
- * const graph = createGraph({
263
- * nodes: [
264
- * { id: 'parent' },
265
- * { id: 'child', parentId: 'parent' },
266
- * ],
267
- * });
268
- * isCompound(graph, 'parent'); // => true
269
- * isCompound(graph, 'child'); // => false
270
- * ```
271
- */
272
- declare function isCompound(graph: Graph, nodeId: string): boolean;
273
- /**
274
- * Whether a node has no children (is a leaf/atomic node).
275
- *
276
- * @example
277
- * ```ts
278
- * const graph = createGraph({
279
- * nodes: [
280
- * { id: 'parent' },
281
- * { id: 'child', parentId: 'parent' },
282
- * ],
283
- * });
284
- * isLeaf(graph, 'child'); // => true
285
- * isLeaf(graph, 'parent'); // => false
286
- * ```
287
- */
288
- declare function isLeaf(graph: Graph, nodeId: string): boolean;
289
- /**
290
- * Depth of a node in the hierarchy (root = 0).
291
- * Returns -1 if the node is not found.
292
- *
293
- * @example
294
- * ```ts
295
- * const graph = createGraph({
296
- * nodes: [
297
- * { id: 'root' },
298
- * { id: 'child', parentId: 'root' },
299
- * { id: 'grandchild', parentId: 'child' },
300
- * ],
301
- * });
302
- * getDepth(graph, 'root'); // => 0
303
- * getDepth(graph, 'child'); // => 1
304
- * getDepth(graph, 'grandchild'); // => 2
305
- * ```
306
- */
307
- declare function getDepth(graph: Graph, nodeId: string): number;
308
- /**
309
- * Sibling nodes (same parentId, excluding the node itself).
310
- *
311
- * @example
312
- * ```ts
313
- * const graph = createGraph({
314
- * nodes: [
315
- * { id: 'parent' },
316
- * { id: 'a', parentId: 'parent' },
317
- * { id: 'b', parentId: 'parent' },
318
- * { id: 'c', parentId: 'parent' },
319
- * ],
320
- * });
321
- * getSiblings(graph, 'a');
322
- * // => [node b, node c]
323
- * ```
324
- */
325
- declare function getSiblings<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
326
- /**
327
- * Least Common Ancestor -- deepest proper ancestor of all given nodes.
328
- * A proper ancestor excludes the input nodes themselves.
329
- *
330
- * @example
331
- * ```ts
332
- * const graph = createGraph({
333
- * nodes: [
334
- * { id: 'root' },
335
- * { id: 'a', parentId: 'root' },
336
- * { id: 'b', parentId: 'root' },
337
- * { id: 'a1', parentId: 'a' },
338
- * ],
339
- * });
340
- * getLCA(graph, 'a1', 'b');
341
- * // => node root
342
- * getLCA(graph, 'a', 'b');
343
- * // => node root
344
- * ```
345
- */
346
- declare function getLCA<N>(graph: Graph<N>, ...nodeIds: string[]): GraphNode<N> | undefined;
347
- /**
348
- * Returns a map of nodeId → shortest-path distance for all sibling nodes
349
- * (same parentId). Distance is measured from the parent's `initialNodeId`
350
- * (or `graph.initialNodeId` for root-level nodes).
351
- *
352
- * Only follows edges between siblings. Unreachable siblings are omitted.
353
- *
354
- * @example Root-level nodes (uses `graph.initialNodeId`):
355
- * ```ts
356
- * const graph = createGraph({
357
- * initialNodeId: 'a',
358
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
359
- * edges: [
360
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
361
- * { id: 'e2', sourceId: 'b', targetId: 'c' },
362
- * ],
363
- * });
364
- * getRelativeDistanceMap(graph, null);
365
- * // => { a: 0, b: 1, c: 2 }
366
- * ```
367
- *
368
- * @example Nested nodes (uses parent's `initialNodeId`):
369
- * ```ts
370
- * const graph = createGraph({
371
- * nodes: [
372
- * { id: 'parent', initialNodeId: 's1' },
373
- * { id: 's1', parentId: 'parent' },
374
- * { id: 's2', parentId: 'parent' },
375
- * { id: 's3', parentId: 'parent' },
376
- * ],
377
- * edges: [
378
- * { id: 'e1', sourceId: 's1', targetId: 's2' },
379
- * { id: 'e2', sourceId: 's2', targetId: 's3' },
380
- * ],
381
- * });
382
- * getRelativeDistanceMap(graph, 'parent');
383
- * // => { s1: 0, s2: 1, s3: 2 }
384
- * ```
385
- */
386
- declare function getRelativeDistanceMap(graph: Graph, parentId: string | null): Record<string, number>;
387
- /**
388
- * Returns the shortest-path distance of a node from its parent's initial node.
389
- * Automatically scopes to the node's sibling group (same `parentId`).
390
- *
391
- * Returns `undefined` if the node is not found or unreachable.
392
- *
393
- * @example
394
- * ```ts
395
- * const graph = createGraph({
396
- * initialNodeId: 'a',
397
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
398
- * edges: [
399
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
400
- * { id: 'e2', sourceId: 'b', targetId: 'c' },
401
- * ],
402
- * });
403
- * getRelativeDistance(graph, 'a'); // => 0
404
- * getRelativeDistance(graph, 'b'); // => 1
405
- * getRelativeDistance(graph, 'c'); // => 2
406
- * ```
407
- *
408
- * @example Nested nodes:
409
- * ```ts
410
- * const graph = createGraph({
411
- * nodes: [
412
- * { id: 'parent', initialNodeId: 's1' },
413
- * { id: 's1', parentId: 'parent' },
414
- * { id: 's2', parentId: 'parent' },
415
- * ],
416
- * edges: [{ id: 'e1', sourceId: 's1', targetId: 's2' }],
417
- * });
418
- * getRelativeDistance(graph, 's1'); // => 0
419
- * getRelativeDistance(graph, 's2'); // => 1
420
- * ```
421
- */
422
- declare function getRelativeDistance(graph: Graph, nodeId: string): number | undefined;
423
- /**
424
- * Nodes with no incoming edges (inDegree 0).
425
- *
426
- * @example
427
- * ```ts
428
- * const graph = createGraph({
429
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
430
- * edges: [
431
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
432
- * { id: 'e2', sourceId: 'b', targetId: 'c' },
433
- * ],
434
- * });
435
- * getSources(graph);
436
- * // => [node a]
437
- * ```
438
- */
439
- declare function getSources<N>(graph: Graph<N>): GraphNode<N>[];
440
- /**
441
- * Nodes with no outgoing edges (outDegree 0).
442
- *
443
- * @example
444
- * ```ts
445
- * const graph = createGraph({
446
- * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
447
- * edges: [
448
- * { id: 'e1', sourceId: 'a', targetId: 'b' },
449
- * { id: 'e2', sourceId: 'b', targetId: 'c' },
450
- * ],
451
- * });
452
- * getSinks(graph);
453
- * // => [node c]
454
- * ```
455
- */
456
- declare function getSinks<N>(graph: Graph<N>): GraphNode<N>[];
457
- /**
458
- * Get a port by name on a node, or `undefined` if not found.
459
- *
460
- * @example
461
- * ```ts
462
- * const graph = createGraph({
463
- * nodes: [{
464
- * id: 'a',
465
- * ports: [{ name: 'out', direction: 'out' }],
466
- * }],
467
- * });
468
- * getPort(graph, 'a', 'out'); // => { name: 'out', direction: 'out', ... }
469
- * getPort(graph, 'a', 'missing'); // => undefined
470
- * ```
471
- */
472
- declare function getPort<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string, portName: string): GraphPort<P> | undefined;
473
- /**
474
- * Get all ports on a node. Returns `[]` if the node has no ports or doesn't exist.
475
- *
476
- * @example
477
- * ```ts
478
- * const graph = createGraph({
479
- * nodes: [{
480
- * id: 'a',
481
- * ports: [
482
- * { name: 'in', direction: 'in' },
483
- * { name: 'out', direction: 'out' },
484
- * ],
485
- * }],
486
- * });
487
- * getPorts(graph, 'a'); // => [port in, port out]
488
- * ```
489
- */
490
- declare function getPorts<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string): GraphPort<P>[];
491
- /**
492
- * Get all edges connected to a specific port on a node.
493
- *
494
- * Returns edges where:
495
- * - `sourceId === nodeId && sourcePort === portName`, or
496
- * - `targetId === nodeId && targetPort === portName`
497
- *
498
- * @example
499
- * ```ts
500
- * const graph = createGraph({
501
- * nodes: [
502
- * { id: 'a', ports: [{ name: 'out', direction: 'out' }] },
503
- * { id: 'b', ports: [{ name: 'in', direction: 'in' }] },
504
- * ],
505
- * edges: [{
506
- * id: 'e1', sourceId: 'a', targetId: 'b',
507
- * sourcePort: 'out', targetPort: 'in',
508
- * }],
509
- * });
510
- * getEdgesByPort(graph, 'a', 'out'); // => [edge e1]
511
- * ```
512
- */
513
- declare function getEdgesByPort<N, E>(graph: Graph<N, E>, nodeId: string, portName: string): GraphEdge<E>[];
514
- //#endregion
1
+ 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-BfXeTXRf.mjs";
515
2
  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 };