mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(Split In Batches Node): Fix issue with pairedItem (#4873)
fix(SplitInBatches Node): Fix issue with pairedItem
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
import {
|
||||
deepCopy,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IPairedItemData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class SplitInBatches implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -69,18 +75,56 @@ export class SplitInBatches implements INodeType {
|
||||
if (nodeContext.items === undefined || options.reset === true) {
|
||||
// Is the first time the node runs
|
||||
|
||||
const sourceData = this.getInputSourceData();
|
||||
|
||||
nodeContext.currentRunIndex = 0;
|
||||
nodeContext.maxRunIndex = Math.ceil(items.length / batchSize);
|
||||
nodeContext.sourceData = deepCopy(sourceData);
|
||||
|
||||
// Get the items which should be returned
|
||||
returnItems.push.apply(returnItems, items.splice(0, batchSize));
|
||||
|
||||
// Set the other items to be saved in the context to return at later runs
|
||||
nodeContext.items = items;
|
||||
nodeContext.items = [...items];
|
||||
} else {
|
||||
// The node has been called before. So return the next batch of items.
|
||||
nodeContext.currentRunIndex += 1;
|
||||
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
||||
|
||||
const addSourceOverwrite = (pairedItem: IPairedItemData | number): IPairedItemData => {
|
||||
if (typeof pairedItem === 'number') {
|
||||
return {
|
||||
item: pairedItem,
|
||||
sourceOverwrite: nodeContext.sourceData,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...pairedItem,
|
||||
sourceOverwrite: nodeContext.sourceData,
|
||||
};
|
||||
};
|
||||
|
||||
function getPairedItemInformation(
|
||||
item: INodeExecutionData,
|
||||
): IPairedItemData | IPairedItemData[] {
|
||||
if (item.pairedItem === undefined) {
|
||||
return {
|
||||
item: 0,
|
||||
sourceOverwrite: nodeContext.sourceData,
|
||||
};
|
||||
}
|
||||
|
||||
if (Array.isArray(item.pairedItem)) {
|
||||
return item.pairedItem.map(addSourceOverwrite);
|
||||
}
|
||||
|
||||
return addSourceOverwrite(item.pairedItem);
|
||||
}
|
||||
|
||||
returnItems.map((item) => {
|
||||
item.pairedItem = getPairedItemInformation(item);
|
||||
});
|
||||
}
|
||||
|
||||
nodeContext.noItemsLeft = nodeContext.items.length === 0;
|
||||
@@ -90,12 +134,6 @@ export class SplitInBatches implements INodeType {
|
||||
return null;
|
||||
}
|
||||
|
||||
returnItems.map((item, index) => {
|
||||
item.pairedItem = {
|
||||
item: index,
|
||||
};
|
||||
});
|
||||
|
||||
return this.prepareOutputData(returnItems);
|
||||
return [returnItems];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user