import { isReadRowsAction } from '@/services/data/tuples/pipeline-stage-unit-action/pipeline-stage-unit-action-utils' ; import { computeJoint } from '../../compute/condition-compute' ; import { ActionRuntimeContext , InternalUnitRuntimeContext , PipelineRuntimeContext } from '../../types' ; import { prepareBy , prepareTopic , prepareVariable } from './utils' ; export const runReadRows = async ( options ) => { const { pipelineContext , internalUnitContext , context , logWrite } = options ; const { action } = context ; if ( ! isReadRowsAction ( action ) ) { throw new Error ( `Not a read rows action[${ action }].` ) ; } const variableName = prepareVariable ( action ) ; const topic = prepareTopic ( action , pipelineContext ) ; const by = prepareBy ( action ) ; const rows = ( pipelineContext . runtimeData [ topic . topicId ] || [ ] ) . filter ( fakeTriggerData => { return computeJoint ( { joint : by , pipelineContext , internalUnitContext , alternativeTriggerData : fakeTriggerData } ) ; } ) ; let found = rows . length !== 0 ; pipelineContext . variables [ variableName ] = rows ; if ( found ) { await logWrite ( `Rows[value=${ JSON . stringify ( rows ) }] found.` ) ; } else { await logWrite ( 'Rows not found by given condition.' ) ; } } ;