Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Create basic CombineSplitInBatches Node #2564

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<INodeExecutionData[][]> {
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);

}
}
1 change: 1 addition & 0 deletions packages/nodes-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down