From 68fb1c64dca99fb603fe6d52fd50c4749a2ca898 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 16 Jul 2022 08:33:48 +0200 Subject: [PATCH] feat(core): Autofix pairedItem information if inputItems(n) === outputItems(n) --- packages/core/src/WorkflowExecute.ts | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 3f67e11334..ca2b0ecb75 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -945,21 +945,33 @@ export class WorkflowExecute { if (outputData === null) { continue; } - for (const item of outputData) { + for (const [index, item] of outputData.entries()) { if (!item.pairedItem) { - // The pairedItem is missing so check if it can get automatically fixed + // The pairedItem data is missing, so check if it can get automatically fixed if ( - executionData.data.main.length !== 1 || - executionData.data.main[0]?.length !== 1 + executionData.data.main.length === 1 && + executionData.data.main[0]?.length === 1 ) { - // Automatically fixing is only possible if there is only one - // input and one input item + // The node has one input and one incoming item, so we know + // that all items must originate from that single + item.pairedItem = { + item: 0, + }; + } else if ( + nodeSuccessData.length === 1 && + executionData.data.main.length === 1 && + executionData.data.main[0]?.length === nodeSuccessData[0].length + ) { + // The node has one input and one output. The number of items on both is + // identical so we can make the resonable asumption that each of the input + // items is the origin of the corresponding output items + item.pairedItem = { + item: index, + }; + } else { + // In all other cases is autofixing not possible break checkOutputData; } - - item.pairedItem = { - item: 0, - }; } } }