import { Node , NodeImpl , ScalarNode } from './NodeDefs' ; export abstract class AbstractGraph { protected nodesMap : Map < string , Node > = new Map < string , Node > ( ) ; public abstract getEdges ( node ) ; public get nodes ( ) { return this . nodesMap . values ( ) ; } public get nodeNames ( ) : IterableIterator < string > { return this . nodesMap . keys ( ) ; } public addEdge ( src , dst ) { ( src as NodeImpl ) . addEdge ( dst ) ; } public getNode ( name ) { return this . nodesMap . get ( name ) ; } public getOrAddNode ( name , details ) { let n = this . nodesMap . get ( name ) ; if ( n ) { return n ; } n = new ScalarNode ( name , details ) ; this . nodesMap . set ( name , n ) ; return n ; } protected getNodeFromName ( name ) { let found ; Array . from ( this . nodes ) . forEach ( node => { if ( ( node . details . get ( 'name' ) as String ) . startsWith ( name ) && ( node . details . get ( 'type' ) as String ) === 'CustomObject' ) { found = node ; } } ) ; return found ; } protected getNodeShortId ( name ) { let found ; Array . from ( this . nodes ) . forEach ( node => { if ( node . name . startsWith ( name ) ) { found = node ; } } ) ; return found ; } }