diff --git a/packages/nodes-base/nodes/CombineSplitInBatches/CombineSplitInBatches.node.ts b/packages/nodes-base/nodes/CombineSplitInBatches/CombineSplitInBatches.node.ts new file mode 100644 index 0000000000000..d5f09a9d17b77 --- /dev/null +++ b/packages/nodes-base/nodes/CombineSplitInBatches/CombineSplitInBatches.node.ts @@ -0,0 +1,70 @@ +import { IExecuteFunctions } from 'n8n-core'; +import { + INodeExecutionData, + INodeType, + INodeTypeDescription, +} from 'n8n-workflow'; + + +export class CombineSplitInBatches implements INodeType { + description: INodeTypeDescription = { + displayName: 'CombineSplitInBatches', + name: 'combineSplitInBatches', + icon: 'fa:map-signs', + group: ['transform'], + version: 1, + description: 'Combines data from SplitInBatches Node', + defaults: { + name: 'CombineSplitInBatches', + color: '#408000', + }, + inputs: ['main'], + outputs: ['main', 'main'], + outputNames: ['done', 'continue'], + properties: [ + { + displayName: 'SplitInBatches Node', + name: 'splitInBatchesNode', + type: 'string', + default: '', + placeholder: 'SplitInBatches', + required: true, + description: 'The name of the SplitInBatches Node to operate on.', + }, + ], + }; + + + async execute(this: IExecuteFunctions): Promise { + const incomingItems = this.getInputData(); + + const splitInBatchesNode = this.getNodeParameter('splitInBatchesNode', 0) as string; + + const proxy = this.getWorkflowDataProxy(0); + + const noItemsLeft = proxy.$node[splitInBatchesNode].context["noItemsLeft"]; + + if (noItemsLeft === false) { + // Output data on "continue" branch + return [[], incomingItems]; + } + + // Output data on "done" branch + const allData: INodeExecutionData[] = []; + + let counter = 0; + do { + try { + // @ts-ignore + const items = proxy.$items(this.getNode().name, 1, counter).map(item => item); + allData.push(...items); + } catch (error) { + allData.push(...incomingItems); + return [allData, []]; + } + + counter++; + } while(true); + + } +} diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 27092cca26f6f..601416ab47f96 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -364,6 +364,7 @@ "dist/nodes/Cockpit/Cockpit.node.js", "dist/nodes/Coda/Coda.node.js", "dist/nodes/CoinGecko/CoinGecko.node.js", + "dist/nodes/CombineSplitInBatches/CombineSplitInBatches.node.js", "dist/nodes/Compression/Compression.node.js", "dist/nodes/Contentful/Contentful.node.js", "dist/nodes/ConvertKit/ConvertKit.node.js",