import { ExternalWriterId } from './external-writer-types' ; import { isWriteToExternalAction , isWriteTopicAction } from './pipeline-stage-unit-action/pipeline-stage-unit-action-utils' ; import { Pipeline } from './pipeline-types' ; import { Topic } from './topic-types' ; export const findPipelinesWriteToTopic = ( pipelines , topic ) : Array < Pipeline > => { return pipelines . filter ( ( { stages } ) => { return stages . some ( ( { units } ) => { return units . some ( ( { do : actions } ) => { return actions . some ( action => { if ( ! isWriteTopicAction ( action ) ) { return false ; } return action . topicId == topic . topicId ; } ) ; } ) ; } ) ; } ) ; } ; export const findPipelinesTriggerByTopic = ( pipelines , topic ) : Array < Pipeline > => { return pipelines . filter ( pipeline => pipeline . topicId == topic . topicId ) ; } ; export const findExternalWriterIds = ( pipelines , topic ) : Array < ExternalWriterId > => { const externalWriterIds = [ ] ; findPipelinesTriggerByTopic ( pipelines , topic ) . forEach ( ( { stages } ) => { stages . forEach ( ( { units } ) => { units . forEach ( ( { do : actions } ) => { return actions . forEach ( action => { if ( isWriteToExternalAction ( action ) ) { externalWriterIds . push ( action . externalWriterId ) ; } } ) ; } ) ; } ) ; } ) ; return [ ... new Set ( externalWriterIds ) ] ; } ;