Remove executeSingle from FunctionItem node

This commit is contained in:
dali 2021-02-17 08:51:02 +01:00
parent 735a7e6812
commit 81f33b4c04

View file

@ -1,4 +1,4 @@
import { IExecuteSingleFunctions } from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IBinaryKeyData,
IDataObject,
@ -40,8 +40,16 @@ export class FunctionItem implements INodeType {
],
};
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
let item = this.getInputData();
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length as unknown as number;
let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
item = items[itemIndex];
// Copy the items as they may get changed in the functions
item = JSON.parse(JSON.stringify(item));
@ -61,7 +69,7 @@ export class FunctionItem implements INodeType {
};
// Make it possible to access data via $node, $parameter, ...
const dataProxy = this.getWorkflowDataProxy();
const dataProxy = this.getWorkflowDataProxy(itemIndex);
Object.assign(sandbox, dataProxy);
const options = {
@ -84,7 +92,7 @@ export class FunctionItem implements INodeType {
const vm = new NodeVM(options);
// Get the code to execute
const functionCode = this.getNodeParameter('functionCode') as string;
const functionCode = this.getNodeParameter('functionCode', itemIndex) as string;
let jsonData: IDataObject;
@ -108,6 +116,8 @@ export class FunctionItem implements INodeType {
returnItem.binary = item.binary;
}
return returnItem;
returnData.push(returnItem);
}
return this.prepareOutputData(returnData);
}
}