type relationships = { nodes : any [ ] ; links : any [ ] ; } ; type caches = { [ key ] : any ; } ; const makeRelationshipLinks = ( obj ) => { const relationships = { nodes : [ ] , links : [ ] } ; if ( ! obj ) return relationships ; const nodeCache = { } ; const sourceTargetCache = { } ; relationships . nodes = Object . keys ( obj ) . map ( ( nodeKey , index ) => { nodeCache [ nodeKey ] = index ; const objToReturn = { name : obj [ nodeKey ] . type === 'RecoilState' ? 'Atom' : 'Selector' , label : nodeKey , id : index , } ; if ( objToReturn . name === 'Atom' ) { if ( obj [ nodeKey ] . nodeDeps . length ) { objToReturn . name = 'Selector' ; } } return objToReturn ; } ) ; Object . keys ( obj ) . forEach ( ( nodeKey , _index ) => { obj [ nodeKey ] . nodeToNodeSubscriptions . forEach ( ( nodeToNodeSubscription ) => { const targetSource = `${ nodeCache [ nodeKey ] }${ nodeCache [ nodeToNodeSubscription ] }` ; if ( nodeCache [ nodeToNodeSubscription ] && ! sourceTargetCache [ targetSource ] ) { sourceTargetCache [ targetSource ] = true ; relationships . links . push ( { source : nodeCache [ nodeKey ] , target : nodeCache [ nodeToNodeSubscription ] , } ) ; } } ) ; obj [ nodeKey ] . nodeDeps . forEach ( ( nodeDeps ) => { const targetSource = `${ nodeCache [ nodeDeps ] }${ nodeCache [ nodeKey ] }` ; if ( nodeCache [ nodeDeps ] && ! sourceTargetCache [ targetSource ] ) { sourceTargetCache [ targetSource ] = true ; relationships . links . push ( { source : nodeCache [ nodeDeps ] , target : nodeCache [ nodeKey ] , } ) ; } } ) ; } ) ; return relationships ; } ; export default makeRelationshipLinks ;