feat(ui): add getNodes method to Graph

This commit is contained in:
psychedelicious
2025-06-29 12:02:31 +10:00
parent 6fa7c8c2ee
commit bf4016b4bc
2 changed files with 23 additions and 0 deletions

View File

@@ -138,6 +138,21 @@ describe('Graph', () => {
});
});
describe('getNodes', () => {
it('should return all nodes in the graph', () => {
const g = new Graph();
const n1 = g.addNode({
id: 'n1',
type: 'add',
});
const n2 = g.addNode({
id: 'n2',
type: 'sub',
});
expect(g.getNodes()).toEqual([n1, n2]);
});
});
describe('addEdge', () => {
const add: Invocation<'add'> = {
id: 'from-node',

View File

@@ -128,6 +128,14 @@ export class Graph {
return node;
}
/**
* Gets all nodes in the graph.
* @returns An array of all nodes in the graph.
*/
getNodes(): AnyInvocation[] {
return Object.values(this._graph.nodes);
}
/**
* Get the immediate incomers of a node.
* @param node The node to get the incomers of.