@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.
- package/README.md +3 -1
- package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
- package/dist/{algorithms-BNDQcHU3.mjs → algorithms-Ba7o7niK.mjs} +29 -25
- package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
- package/dist/algorithms.d.mts +1 -1
- package/dist/algorithms.mjs +1 -1
- package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
- package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
- package/dist/format-support.mjs +31 -2
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +1 -60
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.mjs +3 -3
- package/dist/formats/d2/index.d.mts +109 -0
- package/dist/formats/d2/index.mjs +1086 -0
- package/dist/formats/d3/index.d.mts +2 -2
- package/dist/formats/d3/index.mjs +3 -3
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +3 -3
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/elk/index.mjs +2 -2
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +9 -3
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/gml/index.mjs +3 -3
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +11 -4
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/jgf/index.mjs +3 -3
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/mermaid/index.mjs +9 -9
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/tgf/index.mjs +2 -2
- package/dist/formats/xyflow/index.d.mts +1 -1
- package/dist/formats/xyflow/index.mjs +2 -2
- package/dist/index-CHoriXZD.d.mts +638 -0
- package/dist/index-D9Kj6Fe3.d.mts +61 -0
- package/dist/index.d.mts +6 -631
- package/dist/index.mjs +8 -7
- package/dist/mode-D8OnHFBk.mjs +15 -0
- package/dist/queries-BlkA1HAN.d.mts +516 -0
- package/dist/queries.d.mts +1 -514
- package/dist/queries.mjs +17 -15
- package/dist/schemas.d.mts +21 -10
- package/dist/schemas.mjs +12 -2
- package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
- package/package.json +2 -1
- package/schemas/edge.schema.json +11 -0
- package/schemas/graph.schema.json +24 -3
- package/schemas/node.schema.json +6 -0
- /package/dist/{indexing-DUl3kTqm.mjs → indexing-DR8M1vBy.mjs} +0 -0
package/dist/queries.d.mts
CHANGED
|
@@ -1,515 +1,2 @@
|
|
|
1
|
-
import { g as
|
|
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-BlkA1HAN.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 };
|
package/dist/queries.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as getIndex } from "./indexing-
|
|
1
|
+
import { t as getIndex } from "./indexing-DR8M1vBy.mjs";
|
|
2
|
+
import { t as getEdgeMode } from "./mode-D8OnHFBk.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/queries.ts
|
|
4
5
|
/**
|
|
@@ -74,7 +75,7 @@ function getOutEdges(graph, nodeId) {
|
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Returns all edges from `sourceId` to `targetId`.
|
|
77
|
-
*
|
|
78
|
+
* Edges whose effective mode is not `'directed'` are matched both ways.
|
|
78
79
|
*
|
|
79
80
|
* @example
|
|
80
81
|
* ```ts
|
|
@@ -85,7 +86,7 @@ function getOutEdges(graph, nodeId) {
|
|
|
85
86
|
* getEdgesBetween(graph, 'a', 'b');
|
|
86
87
|
* // => [edge e1]
|
|
87
88
|
* getEdgesBetween(graph, 'b', 'a');
|
|
88
|
-
* // => [] (directed
|
|
89
|
+
* // => [] (directed edge)
|
|
89
90
|
* ```
|
|
90
91
|
*/
|
|
91
92
|
function getEdgesBetween(graph, sourceId, targetId) {
|
|
@@ -101,14 +102,12 @@ function getEdgesBetween(graph, sourceId, targetId) {
|
|
|
101
102
|
result.push(e);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (e.targetId === sourceId) result.push(e);
|
|
111
|
-
}
|
|
105
|
+
const outIds2 = idx.outEdges.get(targetId) ?? [];
|
|
106
|
+
for (const eid of outIds2) {
|
|
107
|
+
if (seen.has(eid)) continue;
|
|
108
|
+
const ai = idx.edgeById.get(eid);
|
|
109
|
+
const e = graph.edges[ai];
|
|
110
|
+
if (e.targetId === sourceId && getEdgeMode(graph, e) !== "directed") result.push(e);
|
|
112
111
|
}
|
|
113
112
|
return result;
|
|
114
113
|
}
|
|
@@ -199,7 +198,8 @@ function getNeighbors(graph, nodeId) {
|
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
200
|
* Returns the total degree of a node (inDegree + outDegree).
|
|
202
|
-
* For
|
|
201
|
+
* For graphs whose default mode is not `'directed'`, each incident edge is
|
|
202
|
+
* counted once.
|
|
203
203
|
*
|
|
204
204
|
* @example
|
|
205
205
|
* ```ts
|
|
@@ -216,7 +216,7 @@ function getNeighbors(graph, nodeId) {
|
|
|
216
216
|
*/
|
|
217
217
|
function getDegree(graph, nodeId) {
|
|
218
218
|
const idx = getIndex(graph);
|
|
219
|
-
if (graph.
|
|
219
|
+
if (graph.mode !== "directed") {
|
|
220
220
|
const out = idx.outEdges.get(nodeId) ?? [];
|
|
221
221
|
const inE = idx.inEdges.get(nodeId) ?? [];
|
|
222
222
|
return new Set([...out, ...inE]).size;
|
|
@@ -591,10 +591,12 @@ function getRelativeDistanceMap(graph, parentId) {
|
|
|
591
591
|
queue.push(neighborId);
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
|
-
|
|
594
|
+
for (const eid of idx.inEdges.get(id) ?? []) {
|
|
595
595
|
const ai = idx.edgeById.get(eid);
|
|
596
596
|
if (ai === void 0) continue;
|
|
597
|
-
const
|
|
597
|
+
const edge = graph.edges[ai];
|
|
598
|
+
if (getEdgeMode(graph, edge) === "directed") continue;
|
|
599
|
+
const neighborId = edge.sourceId;
|
|
598
600
|
if (siblingSet.has(neighborId) && !dist.has(neighborId)) {
|
|
599
601
|
dist.set(neighborId, d + 1);
|
|
600
602
|
queue.push(neighborId);
|
package/dist/schemas.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as GraphNode, b as GraphPort, p as GraphEdge, u as Graph } from "./types-3-FS9NV2.mjs";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/schemas.d.ts
|
|
@@ -15,7 +15,7 @@ declare const PortSchema: z.ZodObject<{
|
|
|
15
15
|
y: z.ZodOptional<z.ZodNumber>;
|
|
16
16
|
width: z.ZodOptional<z.ZodNumber>;
|
|
17
17
|
height: z.ZodOptional<z.ZodNumber>;
|
|
18
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
18
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
19
19
|
}, z.core.$strip>;
|
|
20
20
|
declare const NodeSchema: z.ZodObject<{
|
|
21
21
|
type: z.ZodLiteral<"node">;
|
|
@@ -30,7 +30,7 @@ declare const NodeSchema: z.ZodObject<{
|
|
|
30
30
|
height: z.ZodOptional<z.ZodNumber>;
|
|
31
31
|
shape: z.ZodOptional<z.ZodString>;
|
|
32
32
|
color: z.ZodOptional<z.ZodString>;
|
|
33
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
33
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
34
34
|
ports: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
35
35
|
name: z.ZodString;
|
|
36
36
|
direction: z.ZodEnum<{
|
|
@@ -44,7 +44,7 @@ declare const NodeSchema: z.ZodObject<{
|
|
|
44
44
|
y: z.ZodOptional<z.ZodNumber>;
|
|
45
45
|
width: z.ZodOptional<z.ZodNumber>;
|
|
46
46
|
height: z.ZodOptional<z.ZodNumber>;
|
|
47
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
47
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
48
48
|
}, z.core.$strip>>>;
|
|
49
49
|
}, z.core.$strip>;
|
|
50
50
|
declare const EdgeSchema: z.ZodObject<{
|
|
@@ -56,19 +56,25 @@ declare const EdgeSchema: z.ZodObject<{
|
|
|
56
56
|
weight: z.ZodOptional<z.ZodNumber>;
|
|
57
57
|
sourcePort: z.ZodOptional<z.ZodString>;
|
|
58
58
|
targetPort: z.ZodOptional<z.ZodString>;
|
|
59
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
60
|
+
directed: "directed";
|
|
61
|
+
undirected: "undirected";
|
|
62
|
+
bidirectional: "bidirectional";
|
|
63
|
+
}>>;
|
|
59
64
|
data: z.ZodAny;
|
|
60
65
|
x: z.ZodOptional<z.ZodNumber>;
|
|
61
66
|
y: z.ZodOptional<z.ZodNumber>;
|
|
62
67
|
width: z.ZodOptional<z.ZodNumber>;
|
|
63
68
|
height: z.ZodOptional<z.ZodNumber>;
|
|
64
69
|
color: z.ZodOptional<z.ZodString>;
|
|
65
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
70
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
66
71
|
}, z.core.$strip>;
|
|
67
72
|
declare const GraphSchema: z.ZodObject<{
|
|
68
73
|
id: z.ZodString;
|
|
69
|
-
|
|
74
|
+
mode: z.ZodEnum<{
|
|
70
75
|
directed: "directed";
|
|
71
76
|
undirected: "undirected";
|
|
77
|
+
bidirectional: "bidirectional";
|
|
72
78
|
}>;
|
|
73
79
|
initialNodeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
74
80
|
nodes: z.ZodArray<z.ZodObject<{
|
|
@@ -84,7 +90,7 @@ declare const GraphSchema: z.ZodObject<{
|
|
|
84
90
|
height: z.ZodOptional<z.ZodNumber>;
|
|
85
91
|
shape: z.ZodOptional<z.ZodString>;
|
|
86
92
|
color: z.ZodOptional<z.ZodString>;
|
|
87
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
93
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
88
94
|
ports: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
89
95
|
name: z.ZodString;
|
|
90
96
|
direction: z.ZodEnum<{
|
|
@@ -98,7 +104,7 @@ declare const GraphSchema: z.ZodObject<{
|
|
|
98
104
|
y: z.ZodOptional<z.ZodNumber>;
|
|
99
105
|
width: z.ZodOptional<z.ZodNumber>;
|
|
100
106
|
height: z.ZodOptional<z.ZodNumber>;
|
|
101
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
107
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
102
108
|
}, z.core.$strip>>>;
|
|
103
109
|
}, z.core.$strip>>;
|
|
104
110
|
edges: z.ZodArray<z.ZodObject<{
|
|
@@ -110,13 +116,18 @@ declare const GraphSchema: z.ZodObject<{
|
|
|
110
116
|
weight: z.ZodOptional<z.ZodNumber>;
|
|
111
117
|
sourcePort: z.ZodOptional<z.ZodString>;
|
|
112
118
|
targetPort: z.ZodOptional<z.ZodString>;
|
|
119
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
120
|
+
directed: "directed";
|
|
121
|
+
undirected: "undirected";
|
|
122
|
+
bidirectional: "bidirectional";
|
|
123
|
+
}>>;
|
|
113
124
|
data: z.ZodAny;
|
|
114
125
|
x: z.ZodOptional<z.ZodNumber>;
|
|
115
126
|
y: z.ZodOptional<z.ZodNumber>;
|
|
116
127
|
width: z.ZodOptional<z.ZodNumber>;
|
|
117
128
|
height: z.ZodOptional<z.ZodNumber>;
|
|
118
129
|
color: z.ZodOptional<z.ZodString>;
|
|
119
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
130
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
120
131
|
}, z.core.$strip>>;
|
|
121
132
|
data: z.ZodAny;
|
|
122
133
|
direction: z.ZodOptional<z.ZodEnum<{
|
|
@@ -125,7 +136,7 @@ declare const GraphSchema: z.ZodObject<{
|
|
|
125
136
|
left: "left";
|
|
126
137
|
right: "right";
|
|
127
138
|
}>>;
|
|
128
|
-
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
139
|
+
style: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
129
140
|
}, z.core.$strip>;
|
|
130
141
|
interface GraphValidationIssue {
|
|
131
142
|
code: string;
|