diff --git a/packages/nodes-base/nodes/Aws/DynamoDB/AwsDynamoDB.node.ts b/packages/nodes-base/nodes/Aws/DynamoDB/AwsDynamoDB.node.ts index d6f882a3cb845..87e8d6d9e6fe1 100644 --- a/packages/nodes-base/nodes/Aws/DynamoDB/AwsDynamoDB.node.ts +++ b/packages/nodes-base/nodes/Aws/DynamoDB/AwsDynamoDB.node.ts @@ -91,7 +91,7 @@ export class AwsDynamoDB implements INodeType { const operation = this.getNodeParameter('operation', 0); let responseData; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; for (let i = 0; i < items.length; i++) { try { @@ -391,14 +391,19 @@ export class AwsDynamoDB implements INodeType { responseData = responseData.map(simplify); } } - - Array.isArray(responseData) - ? returnData.push(...responseData) - : returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } @@ -406,6 +411,6 @@ export class AwsDynamoDB implements INodeType { } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts index 712ba806271c9..04838794ba51d 100644 --- a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts +++ b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts @@ -12,7 +12,6 @@ import type { INodeExecutionData, INodeType, INodeTypeDescription, - JsonObject, } from 'n8n-workflow'; import { NodeOperationError } from 'n8n-workflow'; @@ -84,7 +83,7 @@ export class AwsS3 implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const qs: IDataObject = {}; let responseData; const resource = this.getNodeParameter('resource', 0); @@ -150,8 +149,11 @@ export class AwsS3 implements INodeType { qs, headers, ); - - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucket.html @@ -167,7 +169,11 @@ export class AwsS3 implements INodeType { {}, headers, ); - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html @@ -194,7 +200,11 @@ export class AwsS3 implements INodeType { ); responseData = responseData.slice(0, qs.limit); } - returnData.push.apply(returnData, responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html @@ -263,11 +273,11 @@ export class AwsS3 implements INodeType { ); responseData = responseData.ListBucketResult.Contents; } - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData); - } else { - returnData.push(responseData); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } if (resource === 'folder') { @@ -306,7 +316,11 @@ export class AwsS3 implements INodeType { {}, region, ); - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html if (operation === 'delete') { @@ -386,7 +400,11 @@ export class AwsS3 implements INodeType { responseData = { deleted: responseData.DeleteResult.Deleted }; } - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html if (operation === 'getAll') { @@ -446,7 +464,11 @@ export class AwsS3 implements INodeType { if (qs.limit) { responseData = responseData.splice(0, qs.limit as number); } - returnData.push.apply(returnData, responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } } @@ -554,7 +576,11 @@ export class AwsS3 implements INodeType { {}, region, ); - returnData.push(responseData.CopyObjectResult); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData.CopyObjectResult), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html if (operation === 'download') { @@ -647,8 +673,11 @@ export class AwsS3 implements INodeType { {}, region, ); - - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html if (operation === 'getAll') { @@ -710,7 +739,11 @@ export class AwsS3 implements INodeType { if (qs.limit) { responseData = responseData.splice(0, qs.limit as number); } - returnData.push.apply(returnData, responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } //https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html @@ -863,12 +896,20 @@ export class AwsS3 implements INodeType { region, ); } - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: (error as JsonObject).message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -878,7 +919,7 @@ export class AwsS3 implements INodeType { // For file downloads the files get attached to the existing items return this.prepareOutputData(items); } else { - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } } diff --git a/packages/nodes-base/nodes/Aws/SES/AwsSes.node.ts b/packages/nodes-base/nodes/Aws/SES/AwsSes.node.ts index 79b24ed03a65b..6cbe0158f6082 100644 --- a/packages/nodes-base/nodes/Aws/SES/AwsSes.node.ts +++ b/packages/nodes-base/nodes/Aws/SES/AwsSes.node.ts @@ -817,7 +817,7 @@ export class AwsSes implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; let responseData; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); @@ -1281,23 +1281,24 @@ export class AwsSes implements INodeType { responseData = responseData.UpdateTemplateResponse; } } - - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else { - if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Dropcontact/Dropcontact.node.ts b/packages/nodes-base/nodes/Dropcontact/Dropcontact.node.ts index a53356b93231f..84d6ac5493ba4 100644 --- a/packages/nodes-base/nodes/Dropcontact/Dropcontact.node.ts +++ b/packages/nodes-base/nodes/Dropcontact/Dropcontact.node.ts @@ -8,7 +8,7 @@ import type { } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow'; -import { dropcontactApiRequest } from './GenericFunction'; +import { dropcontactApiRequest, mapPairedItemsFrom } from './GenericFunction'; export class Dropcontact implements INodeType { description: INodeTypeDescription = { @@ -246,7 +246,7 @@ export class Dropcontact implements INodeType { const operation = this.getNodeParameter('operation', 0); let responseData: any; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; if (resource === 'contact') { if (operation === 'enrich') { @@ -278,7 +278,13 @@ export class Dropcontact implements INodeType { if (!responseData.success) { if (this.continueOnFail()) { - returnData.push({ error: responseData.reason || 'invalid request' }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: responseData.reason || 'invalid request' }), + { + itemData: mapPairedItemsFrom(entryData), + }, + ); + returnData.push(...executionData); } else { throw new NodeApiError(this.getNode(), { error: responseData.reason || 'invalid request', @@ -300,7 +306,13 @@ export class Dropcontact implements INodeType { ); if (!responseData.success) { if (this.continueOnFail()) { - responseData.push({ error: responseData.reason }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: responseData.reason }), + { + itemData: mapPairedItemsFrom(entryData), + }, + ); + returnData.push(...executionData); } else { throw new NodeApiError(this.getNode(), { error: responseData.reason, @@ -308,10 +320,22 @@ export class Dropcontact implements INodeType { }); } } else { - returnData.push(...responseData.data); + responseData.data.forEach((d: IDataObject, index: number) => { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(d), + { itemData: { item: index } }, + ); + returnData.push(...executionData); + }); } } else { - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { + itemData: mapPairedItemsFrom(entryData), + }, + ); + returnData.push(...executionData); } } @@ -327,18 +351,26 @@ export class Dropcontact implements INodeType { )) as { request_id: string; error: string; success: boolean }; if (!responseData.success) { if (this.continueOnFail()) { - responseData.push({ error: responseData.reason || 'invalid request' }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: responseData.reason || 'invalid request' }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } else { throw new NodeApiError(this.getNode(), { error: responseData.reason || 'invalid request', }); } } - returnData.push(...responseData.data); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData.data), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Dropcontact/GenericFunction.ts b/packages/nodes-base/nodes/Dropcontact/GenericFunction.ts index bd140a958f731..271ebf6c7cc63 100644 --- a/packages/nodes-base/nodes/Dropcontact/GenericFunction.ts +++ b/packages/nodes-base/nodes/Dropcontact/GenericFunction.ts @@ -1,6 +1,6 @@ import type { IExecuteFunctions, IHookFunctions } from 'n8n-core'; -import type { IDataObject, ILoadOptionsFunctions } from 'n8n-workflow'; +import type { IDataObject, ILoadOptionsFunctions, IPairedItemData } from 'n8n-workflow'; import type { OptionsWithUri } from 'request'; @@ -32,3 +32,11 @@ export async function dropcontactApiRequest( return this.helpers.requestWithAuthentication.call(this, 'dropcontactApi', options); } + +export function mapPairedItemsFrom(iterable: Iterable | ArrayLike): IPairedItemData[] { + return Array.from(iterable, (_, i) => i).map((index) => { + return { + item: index, + }; + }); +} diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index 35f97207d4aa9..b6c04851bee33 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -543,17 +543,19 @@ export class Ftp implements INodeType { if (recursive) { responseData = await callRecursiveList(path, sftp!, normalizeSFtpItem); - returnItems.push.apply( - returnItems, + const executionData = this.helpers.constructExecutionMetaData( this.helpers.returnJsonArray(responseData as unknown as IDataObject[]), + { itemData: { item: i } }, ); + returnItems.push.apply(returnItems, executionData); } else { responseData = await sftp!.list(path); responseData.forEach((item) => normalizeSFtpItem(item, path)); - returnItems.push.apply( - returnItems, + const executionData = this.helpers.constructExecutionMetaData( this.helpers.returnJsonArray(responseData as unknown as IDataObject[]), + { itemData: { item: i } }, ); + returnItems.push.apply(returnItems, executionData); } } @@ -566,8 +568,11 @@ export class Ftp implements INodeType { } else { responseData = await sftp!.delete(path); } - - returnItems.push({ json: { success: true } }); + const executionData = this.helpers.constructExecutionMetaData( + [{ json: { success: true } }], + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } if (operation === 'rename') { @@ -582,8 +587,11 @@ export class Ftp implements INodeType { } responseData = await sftp!.rename(oldPath, newPath); - - returnItems.push({ json: { success: true } }); + const executionData = this.helpers.constructExecutionMetaData( + [{ json: { success: true } }], + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } if (operation === 'download') { @@ -600,7 +608,11 @@ export class Ftp implements INodeType { filePathDownload, ); - returnItems.push(items[i]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(items[i]), + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } finally { await binaryFile.cleanup(); } @@ -643,7 +655,11 @@ export class Ftp implements INodeType { await sftp!.put(buffer, remotePath); } - returnItems.push(items[i]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(items[i]), + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } } @@ -655,19 +671,21 @@ export class Ftp implements INodeType { if (recursive) { responseData = await callRecursiveList(path, ftp!, normalizeFtpItem); - returnItems.push.apply( - returnItems, + const executionData = this.helpers.constructExecutionMetaData( this.helpers.returnJsonArray(responseData as unknown as IDataObject[]), + { itemData: { item: i } }, ); + returnItems.push.apply(returnItems, executionData); } else { responseData = await ftp!.list(path); responseData.forEach((item) => normalizeFtpItem(item as ftpClient.ListingElement, path), ); - returnItems.push.apply( - returnItems, + const executionData = this.helpers.constructExecutionMetaData( this.helpers.returnJsonArray(responseData as unknown as IDataObject[]), + { itemData: { item: i } }, ); + returnItems.push.apply(returnItems, executionData); } } @@ -680,8 +698,11 @@ export class Ftp implements INodeType { } else { responseData = await ftp!.delete(path); } - - returnItems.push({ json: { success: true } }); + const executionData = this.helpers.constructExecutionMetaData( + [{ json: { success: true } }], + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } if (operation === 'download') { @@ -699,7 +720,11 @@ export class Ftp implements INodeType { filePathDownload, ); - returnItems.push(items[i]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(items[i]), + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } finally { await binaryFile.cleanup(); } @@ -711,8 +736,11 @@ export class Ftp implements INodeType { const newPath = this.getNodeParameter('newPath', i) as string; responseData = await ftp!.rename(oldPath, newPath); - - returnItems.push({ json: { success: true } }); + const executionData = this.helpers.constructExecutionMetaData( + [{ json: { success: true } }], + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } if (operation === 'upload') { @@ -773,7 +801,11 @@ export class Ftp implements INodeType { } } } - returnItems.push(items[i]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(items[i]), + { itemData: { item: i } }, + ); + returnItems.push(...executionData); } } } diff --git a/packages/nodes-base/nodes/Grist/Grist.node.ts b/packages/nodes-base/nodes/Grist/Grist.node.ts index 21d136458de9d..c529165f1749c 100644 --- a/packages/nodes-base/nodes/Grist/Grist.node.ts +++ b/packages/nodes-base/nodes/Grist/Grist.node.ts @@ -116,7 +116,7 @@ export class Grist implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); let responseData; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const operation = this.getNodeParameter('operation', 0); @@ -247,17 +247,23 @@ export class Grist implements INodeType { } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + continue; } throw error; } - - Array.isArray(responseData) - ? returnData.push(...responseData) - : returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts b/packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts index 2e03f9e42bbf1..ddc69e1e53da8 100644 --- a/packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts +++ b/packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts @@ -180,7 +180,7 @@ export class HomeAssistant implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); @@ -442,22 +442,27 @@ export class HomeAssistant implements INodeType { if (resource === 'cameraProxy' && operation === 'get') { items[i].json = { error: error.message }; } else { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } continue; } throw error; } - - Array.isArray(responseData) - ? returnData.push(...responseData) - : returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } if (resource === 'cameraProxy' && operation === 'getScreenshot') { return this.prepareOutputData(items); } else { - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } } diff --git a/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts b/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts index bd2e8308439e6..07ae1ba6d6d57 100644 --- a/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts +++ b/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts @@ -1,6 +1,5 @@ import type { IExecuteFunctions } from 'n8n-core'; import type { - IDataObject, ILoadOptionsFunctions, INodeExecutionData, INodePropertyOptions, @@ -70,7 +69,7 @@ export class LinkedIn implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; let responseData; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); @@ -256,21 +255,24 @@ export class LinkedIn implements INodeType { responseData = await linkedInApiRequest.call(this, 'POST', endpoint, body); } } - - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Matrix/Matrix.node.ts b/packages/nodes-base/nodes/Matrix/Matrix.node.ts index f89ac3a1e2ca3..46edec80f1143 100644 --- a/packages/nodes-base/nodes/Matrix/Matrix.node.ts +++ b/packages/nodes-base/nodes/Matrix/Matrix.node.ts @@ -138,27 +138,30 @@ export class Matrix implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData() as IDataObject[]; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { const responseData = await handleMatrixCall.call(this, items[i], i, resource, operation); - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/MicrosoftOutlook.node.ts b/packages/nodes-base/nodes/Microsoft/Outlook/MicrosoftOutlook.node.ts index 85955898c497b..a99cc502fb460 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/MicrosoftOutlook.node.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/MicrosoftOutlook.node.ts @@ -131,7 +131,7 @@ export class MicrosoftOutlook implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const qs: IDataObject = {}; let responseData; @@ -145,11 +145,18 @@ export class MicrosoftOutlook implements INodeType { try { const messageId = this.getNodeParameter('messageId', i) as string; responseData = await microsoftApiRequest.call(this, 'DELETE', `/messages/${messageId}`); - - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -182,17 +189,29 @@ export class MicrosoftOutlook implements INodeType { if (additionalFields.dataPropertyAttachmentsPrefixName) { const prefix = additionalFields.dataPropertyAttachmentsPrefixName as string; const data = await downloadAttachments.call(this, responseData, prefix); - returnData.push.apply(returnData, data as unknown as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(data), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } else { - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } if (additionalFields.dataPropertyAttachmentsPrefixName) { - return [returnData as INodeExecutionData[]]; + return [returnData]; } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -217,10 +236,18 @@ export class MicrosoftOutlook implements INodeType { body, {}, ); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -256,10 +283,18 @@ export class MicrosoftOutlook implements INodeType { responseData = await microsoftApiRequest.call(this, 'POST', '/messages', body, {}); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -289,11 +324,18 @@ export class MicrosoftOutlook implements INodeType { 'POST', `/messages/${messageId}/send`, ); - - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -354,10 +396,18 @@ export class MicrosoftOutlook implements INodeType { await microsoftApiRequest.call(this, 'POST', `/messages/${responseData.id}/send`); } - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -452,13 +502,25 @@ export class MicrosoftOutlook implements INodeType { if (additionalFields.dataPropertyAttachmentsPrefixName) { const prefix = additionalFields.dataPropertyAttachmentsPrefixName as string; const data = await downloadAttachments.call(this, responseData, prefix); - returnData.push.apply(returnData, data as unknown as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(data), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } else { - returnData.push.apply(returnData, responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -466,7 +528,7 @@ export class MicrosoftOutlook implements INodeType { } if (additionalFields.dataPropertyAttachmentsPrefixName) { - return [returnData as INodeExecutionData[]]; + return [returnData]; } } @@ -485,10 +547,18 @@ export class MicrosoftOutlook implements INodeType { `/messages/${messageId}/move`, body, ); - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -536,10 +606,18 @@ export class MicrosoftOutlook implements INodeType { }; responseData = await microsoftApiRequest.call(this, 'POST', '/sendMail', body, {}); - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -647,10 +725,18 @@ export class MicrosoftOutlook implements INodeType { {}, ); } - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -740,10 +826,18 @@ export class MicrosoftOutlook implements INodeType { undefined, qs, ); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -783,10 +877,18 @@ export class MicrosoftOutlook implements INodeType { responseData = await microsoftApiRequest.call(this, 'GET', endpoint, undefined, qs); responseData = responseData.value; } - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -821,10 +923,18 @@ export class MicrosoftOutlook implements INodeType { } responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -841,10 +951,18 @@ export class MicrosoftOutlook implements INodeType { 'DELETE', `/mailFolders/${folderId}`, ); - returnData.push({ success: true }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: true }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -872,10 +990,18 @@ export class MicrosoftOutlook implements INodeType { {}, qs, ); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -911,10 +1037,18 @@ export class MicrosoftOutlook implements INodeType { responseData = await microsoftApiRequest.call(this, 'GET', '/mailFolders', {}, qs); responseData = responseData.value; } - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -956,10 +1090,18 @@ export class MicrosoftOutlook implements INodeType { ); responseData = responseData.value; } - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -983,10 +1125,18 @@ export class MicrosoftOutlook implements INodeType { `/mailFolders/${folderId}`, body, ); - returnData.push(responseData); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -1025,11 +1175,19 @@ export class MicrosoftOutlook implements INodeType { responseData = await microsoftApiRequest.call(this, 'GET', endpoint, undefined, qs); responseData = responseData.value; } - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; @@ -1043,7 +1201,7 @@ export class MicrosoftOutlook implements INodeType { ) { return this.prepareOutputData(items); } else { - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } } diff --git a/packages/nodes-base/nodes/N8nTrainingCustomerDatastore/N8nTrainingCustomerDatastore.node.ts b/packages/nodes-base/nodes/N8nTrainingCustomerDatastore/N8nTrainingCustomerDatastore.node.ts index aa5742831bb65..bb2cf787a7071 100644 --- a/packages/nodes-base/nodes/N8nTrainingCustomerDatastore/N8nTrainingCustomerDatastore.node.ts +++ b/packages/nodes-base/nodes/N8nTrainingCustomerDatastore/N8nTrainingCustomerDatastore.node.ts @@ -1,11 +1,6 @@ import type { IExecuteFunctions } from 'n8n-core'; -import type { - IDataObject, - INodeExecutionData, - INodeType, - INodeTypeDescription, -} from 'n8n-workflow'; +import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow'; const data = [ { @@ -116,7 +111,7 @@ export class N8nTrainingCustomerDatastore implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const operation = this.getNodeParameter('operation', 0); let responseData; @@ -138,11 +133,15 @@ export class N8nTrainingCustomerDatastore implements INodeType { } if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push.apply(returnData, executionData); } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); + returnData.push({ json: responseData }); } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/N8nTrainingCustomerMessenger/N8nTrainingCustomerMessenger.node.ts b/packages/nodes-base/nodes/N8nTrainingCustomerMessenger/N8nTrainingCustomerMessenger.node.ts index 1c13a24e0fd0a..fc53cd38b9e86 100644 --- a/packages/nodes-base/nodes/N8nTrainingCustomerMessenger/N8nTrainingCustomerMessenger.node.ts +++ b/packages/nodes-base/nodes/N8nTrainingCustomerMessenger/N8nTrainingCustomerMessenger.node.ts @@ -1,11 +1,6 @@ import type { IExecuteFunctions } from 'n8n-core'; -import type { - IDataObject, - INodeExecutionData, - INodeType, - INodeTypeDescription, -} from 'n8n-workflow'; +import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow'; export class N8nTrainingCustomerMessenger implements INodeType { description: INodeTypeDescription = { @@ -43,7 +38,7 @@ export class N8nTrainingCustomerMessenger implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; let responseData; @@ -53,9 +48,13 @@ export class N8nTrainingCustomerMessenger implements INodeType { const message = this.getNodeParameter('message', i) as string; responseData = { output: `Sent message to customer ${customerId}: ${message}` }; + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); - returnData.push(responseData); + returnData.push(...executionData); } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Odoo/Odoo.node.ts b/packages/nodes-base/nodes/Odoo/Odoo.node.ts index 84dec321c1bd8..4425f32b8a5f6 100644 --- a/packages/nodes-base/nodes/Odoo/Odoo.node.ts +++ b/packages/nodes-base/nodes/Odoo/Odoo.node.ts @@ -11,7 +11,6 @@ import type { INodePropertyOptions, INodeType, INodeTypeDescription, - JsonObject, } from 'n8n-workflow'; import { deepCopy } from 'n8n-workflow'; @@ -298,7 +297,7 @@ export class Odoo implements INodeType { async execute(this: IExecuteFunctions): Promise { let items = this.getInputData(); items = deepCopy(items); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; let responseData; const resource = this.getNodeParameter('resource', 0); @@ -745,21 +744,27 @@ export class Odoo implements INodeType { ); } } - - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData); - } else if (responseData !== undefined) { - returnData.push(responseData); + if (responseData !== undefined) { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: (error as JsonObject).message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts b/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts index 6bee0891854f4..791f258f8d081 100644 --- a/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts +++ b/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts @@ -102,7 +102,7 @@ export class Phantombuster implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const qs: IDataObject = {}; let responseData; @@ -247,20 +247,23 @@ export class Phantombuster implements INodeType { } } } - - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts index b00e2abadfcba..75b6a3d75d9fe 100644 --- a/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts +++ b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts @@ -1,7 +1,6 @@ import type { IExecuteFunctions } from 'n8n-core'; import type { - IDataObject, ILoadOptionsFunctions, INodeExecutionData, INodePropertyOptions, @@ -88,7 +87,7 @@ export class PhilipsHue implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; let responseData; const resource = this.getNodeParameter('resource', 0); @@ -176,12 +175,12 @@ export class PhilipsHue implements INodeType { ); } } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Pushover/Pushover.node.ts b/packages/nodes-base/nodes/Pushover/Pushover.node.ts index 980238c1e53bf..e68d546060fb0 100644 --- a/packages/nodes-base/nodes/Pushover/Pushover.node.ts +++ b/packages/nodes-base/nodes/Pushover/Pushover.node.ts @@ -298,7 +298,7 @@ export class Pushover implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; let responseData; const resource = this.getNodeParameter('resource', 0); @@ -372,21 +372,25 @@ export class Pushover implements INodeType { } responseData = await pushoverApiRequest.call(this, 'POST', '/messages.json', body); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Rocketchat/Rocketchat.node.ts b/packages/nodes-base/nodes/Rocketchat/Rocketchat.node.ts index 18f41491ee77f..842fb9250543e 100644 --- a/packages/nodes-base/nodes/Rocketchat/Rocketchat.node.ts +++ b/packages/nodes-base/nodes/Rocketchat/Rocketchat.node.ts @@ -372,7 +372,7 @@ export class Rocketchat implements INodeType { const items = this.getInputData(); const length = items.length; let responseData; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < length; i++) { @@ -478,20 +478,24 @@ export class Rocketchat implements INodeType { ); } } - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Snowflake/Snowflake.node.ts b/packages/nodes-base/nodes/Snowflake/Snowflake.node.ts index ea53aa36e99ea..ab0ee55f0a9d3 100644 --- a/packages/nodes-base/nodes/Snowflake/Snowflake.node.ts +++ b/packages/nodes-base/nodes/Snowflake/Snowflake.node.ts @@ -160,7 +160,7 @@ export class Snowflake implements INodeType { const credentials = (await this.getCredentials( 'snowflake', )) as unknown as snowflake.ConnectionOptions; - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; let responseData; const connection = snowflake.createConnection(credentials); @@ -178,7 +178,11 @@ export class Snowflake implements INodeType { for (let i = 0; i < items.length; i++) { const query = this.getNodeParameter('query', i) as string; responseData = await execute(connection, query, []); - returnData.push.apply(returnData, responseData as IDataObject[]); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData as IDataObject[]), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } @@ -196,7 +200,13 @@ export class Snowflake implements INodeType { const data = copyInputItems(items, columns); const binds = data.map((element) => Object.values(element)); await execute(connection, query, binds as unknown as snowflake.InsertBinds); - returnData.push.apply(returnData, data); + data.forEach((d, i) => { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(d), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + }); } if (operation === 'update') { @@ -221,11 +231,16 @@ export class Snowflake implements INodeType { for (let i = 0; i < binds.length; i++) { await execute(connection, query, binds[i] as unknown as snowflake.InsertBinds); } - returnData.push.apply(returnData, data); + data.forEach((d, i) => { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(d), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + }); } await destroy(connection); - - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Supabase/GenericFunctions.ts b/packages/nodes-base/nodes/Supabase/GenericFunctions.ts index 35ffacc422d35..c90b775c142a5 100644 --- a/packages/nodes-base/nodes/Supabase/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Supabase/GenericFunctions.ts @@ -13,6 +13,7 @@ import type { ICredentialTestFunctions, IDataObject, INodeProperties, + IPairedItemData, } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow'; @@ -322,3 +323,11 @@ export async function validateCredentials( return this.helpers.request(options); } + +export function mapPairedItemsFrom(iterable: Iterable | ArrayLike): IPairedItemData[] { + return Array.from(iterable, (_, i) => i).map((index) => { + return { + item: index, + }; + }); +} diff --git a/packages/nodes-base/nodes/Supabase/Supabase.node.ts b/packages/nodes-base/nodes/Supabase/Supabase.node.ts index 3e5a7197d1a0e..2129ead358ebf 100644 --- a/packages/nodes-base/nodes/Supabase/Supabase.node.ts +++ b/packages/nodes-base/nodes/Supabase/Supabase.node.ts @@ -18,6 +18,7 @@ import { buildGetQuery, buildOrQuery, buildQuery, + mapPairedItemsFrom, supabaseApiRequest, validateCredentials, } from './GenericFunctions'; @@ -121,7 +122,7 @@ export class Supabase implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const qs: IDataObject = {}; const resource = this.getNodeParameter('resource', 0); @@ -155,14 +156,28 @@ export class Supabase implements INodeType { records.push(record); } const endpoint = `/${tableId}`; - let createdRow; try { - createdRow = await supabaseApiRequest.call(this, 'POST', endpoint, records); - returnData.push(...createdRow); + const createdRows: IDataObject[] = await supabaseApiRequest.call( + this, + 'POST', + endpoint, + records, + ); + createdRows.forEach((row, i) => { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(row), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + }); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.description }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.description }), + { itemData: mapPairedItemsFrom(records) }, + ); + returnData.push(...executionData); } else { throw error; } @@ -207,11 +222,21 @@ export class Supabase implements INodeType { rows = await supabaseApiRequest.call(this, 'DELETE', endpoint, {}, qs); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.description }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.description }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + continue; } + throw error; } - returnData.push(...rows); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(rows), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } @@ -237,11 +262,21 @@ export class Supabase implements INodeType { rows = await supabaseApiRequest.call(this, 'GET', endpoint, {}, qs); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.description }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + continue; } + throw error; } - returnData.push(...rows); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(rows), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } @@ -280,13 +315,23 @@ export class Supabase implements INodeType { try { rows = await supabaseApiRequest.call(this, 'GET', endpoint, {}, qs); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(rows), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.description }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.description }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); + continue; } + throw error; } - returnData.push(...rows); } } @@ -346,16 +391,25 @@ export class Supabase implements INodeType { try { updatedRow = await supabaseApiRequest.call(this, 'PATCH', endpoint, record, qs); - returnData.push(...updatedRow); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(updatedRow), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.description }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.description }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } + throw error; } } } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/TheHive/TheHive.node.ts b/packages/nodes-base/nodes/TheHive/TheHive.node.ts index f750f67186246..5df283dbbb278 100644 --- a/packages/nodes-base/nodes/TheHive/TheHive.node.ts +++ b/packages/nodes-base/nodes/TheHive/TheHive.node.ts @@ -313,7 +313,7 @@ export class TheHive implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const qs: IDataObject = {}; let responseData; @@ -1954,19 +1954,23 @@ export class TheHive implements INodeType { } } - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else if (responseData !== undefined) { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts b/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts index fd67bbfc13ed3..a8b6e25bbf91c 100644 --- a/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts +++ b/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts @@ -697,7 +697,7 @@ export class TodoistV2 implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; const service = new TodoistService(); let responseData; @@ -712,23 +712,40 @@ export class TodoistV2 implements INodeType { i, ); } - if (Array.isArray(responseData?.data)) { - returnData.push.apply(returnData, responseData?.data as IDataObject[]); + + if (responseData !== undefined && Array.isArray(responseData?.data)) { + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData.data as IDataObject[]), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } else { if (responseData?.hasOwnProperty('success')) { - returnData.push({ success: responseData.success }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ success: responseData.success }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } else { - returnData.push(responseData?.data as IDataObject); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData?.data as IDataObject), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } } } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } } diff --git a/packages/nodes-base/nodes/Zulip/Zulip.node.ts b/packages/nodes-base/nodes/Zulip/Zulip.node.ts index c50c37fa7feaa..f2840bdc40b96 100644 --- a/packages/nodes-base/nodes/Zulip/Zulip.node.ts +++ b/packages/nodes-base/nodes/Zulip/Zulip.node.ts @@ -126,7 +126,7 @@ export class Zulip implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const returnData: IDataObject[] = []; + const returnData: INodeExecutionData[] = []; const length = items.length; let responseData; const resource = this.getNodeParameter('resource', 0); @@ -464,20 +464,23 @@ export class Zulip implements INodeType { responseData = await zulipApiRequest.call(this, 'DELETE', `/users/${userId}`, body); } } - - if (Array.isArray(responseData)) { - returnData.push.apply(returnData, responseData as IDataObject[]); - } else { - returnData.push(responseData as IDataObject); - } + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray(responseData), + { itemData: { item: i } }, + ); + returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { - returnData.push({ error: error.message }); + const executionData = this.helpers.constructExecutionMetaData( + this.helpers.returnJsonArray({ error: error.message }), + { itemData: { item: i } }, + ); + returnData.push(...executionData); continue; } throw error; } } - return [this.helpers.returnJsonArray(returnData)]; + return this.prepareOutputData(returnData); } }