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