1- import { Edge , FlowGraph , Node } from "@tokens-studio/graph-engine" ;
1+ import { Edge , Graph , Node } from "@tokens-studio/graph-engine" ;
22
33/**
44 * Finds all nodes of a specified type in the graph
55 * @param graph
66 * @param type
77 * @returns
88 */
9- export const findNodesOfType = ( graph : FlowGraph , type : string ) =>
10- graph . nodes . filter ( ( node ) => node . type === type ) ;
9+ export const findNodesOfType = ( graph : Graph , type : string ) =>
10+ Object . values ( graph . nodes ) . filter ( ( node ) => node . factory . type === type ) ;
1111
12- export const findOutEdges = ( graph : FlowGraph , id : string ) =>
13- graph . edges . filter ( ( edge ) => edge . source === id ) ;
12+ export const findOutEdges = ( graph : Graph , id : string ) =>
13+ Object . values ( graph . edges ) . filter ( ( edge ) => edge . source === id ) ;
1414
1515/**
1616 * Converts the array of nodes in the graph to a lookup for O(1) performance
1717 * @param graph
1818 * @returns
1919 */
20- export const toNodeLookup = ( graph : FlowGraph ) : Record < string , Node > =>
21- graph . nodes . reduce ( ( acc , node ) => {
20+ export const toNodeLookup = ( graph : Graph ) : Record < string , Node > =>
21+ Object . values ( graph . nodes ) . reduce ( ( acc , node ) => {
2222 acc [ node . id ] = node ;
2323 return acc ;
2424 } , { } ) ;
@@ -28,8 +28,8 @@ export const toNodeLookup = (graph: FlowGraph): Record<string, Node> =>
2828 * @param graph
2929 * @returns
3030 */
31- export const toEdgeLookup = ( graph : FlowGraph ) : Record < string , Edge > =>
32- graph . edges . reduce ( ( acc , edge ) => {
31+ export const toEdgeLookup = ( graph : Graph ) : Record < string , Edge > =>
32+ Object . values ( graph . edges ) . reduce ( ( acc , edge ) => {
3333 acc [ edge . id ] = edge ;
3434 return acc ;
3535 } , { } ) ;
@@ -48,19 +48,19 @@ export type SourceToTarget = {
4848 * @returns
4949 */
5050export const findSourceToTargetOfType = (
51- graph : FlowGraph ,
51+ graph : Graph ,
5252 sourceType : string ,
5353 targetType : string
5454) : SourceToTarget [ ] => {
5555 const nodeLookup = toNodeLookup ( graph ) ;
5656
57- return graph . nodes
58- . filter ( ( node ) => node . type === sourceType )
57+ return Object . values ( graph . nodes )
58+ . filter ( ( node ) => node . factory . type === sourceType )
5959 . reduce ( ( acc , node ) => {
6060 const edges = findOutEdges ( graph , node . id ) ;
6161
6262 const foundTargets = edges
63- . filter ( ( edge ) => nodeLookup [ edge . target ] . type === targetType )
63+ . filter ( ( edge ) => nodeLookup [ edge . target ] . factory . type === targetType )
6464 . map ( ( edge ) => {
6565 return {
6666 source : node ,
0 commit comments