fix(core): Missing pairedItem fixes (#8394)

This commit is contained in:
Michael Kret 2024-01-19 13:47:25 +02:00 committed by GitHub
parent 2c14371481
commit 284d965b5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 37 additions and 6 deletions

View file

@ -718,10 +718,12 @@ export class AirtableV1 implements INodeType {
const downloadFieldNames = ( const downloadFieldNames = (
this.getNodeParameter('downloadFieldNames', 0) as string this.getNodeParameter('downloadFieldNames', 0) as string
).split(','); ).split(',');
const pairedItem = generatePairedItemData(items.length);
const data = await downloadRecordAttachments.call( const data = await downloadRecordAttachments.call(
this, this,
responseData.records as IRecord[], responseData.records as IRecord[],
downloadFieldNames, downloadFieldNames,
pairedItem,
); );
return [data]; return [data];
} }

View file

@ -7,6 +7,7 @@ import type {
IPollFunctions, IPollFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
IPairedItemData,
} from 'n8n-workflow'; } from 'n8n-workflow';
interface IAttachment { interface IAttachment {
@ -100,10 +101,14 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions, this: IExecuteFunctions | IPollFunctions,
records: IRecord[], records: IRecord[],
fieldNames: string[], fieldNames: string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> { ): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = []; const elements: INodeExecutionData[] = [];
for (const record of records) { for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} }; const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = record as unknown as IDataObject; element.json = record as unknown as IDataObject;
for (const fieldName of fieldNames) { for (const fieldName of fieldNames) {
if (record.fields[fieldName] !== undefined) { if (record.fields[fieldName] !== undefined) {

View file

@ -194,10 +194,12 @@ export async function execute(
returnData = responseData.records as INodeExecutionData[]; returnData = responseData.records as INodeExecutionData[];
if (options.downloadFields) { if (options.downloadFields) {
const pairedItem = generatePairedItemData(items.length);
return await downloadRecordAttachments.call( return await downloadRecordAttachments.call(
this, this,
responseData.records as IRecord[], responseData.records as IRecord[],
options.downloadFields as string[], options.downloadFields as string[],
pairedItem,
); );
} }

View file

@ -7,6 +7,7 @@ import type {
IPollFunctions, IPollFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
IPairedItemData,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { ApplicationError } from 'n8n-workflow'; import { ApplicationError } from 'n8n-workflow';
import type { IAttachment, IRecord } from '../helpers/interfaces'; import type { IAttachment, IRecord } from '../helpers/interfaces';
@ -87,6 +88,7 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions, this: IExecuteFunctions | IPollFunctions,
records: IRecord[], records: IRecord[],
fieldNames: string | string[], fieldNames: string | string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> { ): Promise<INodeExecutionData[]> {
if (typeof fieldNames === 'string') { if (typeof fieldNames === 'string') {
fieldNames = fieldNames.split(',').map((item) => item.trim()); fieldNames = fieldNames.split(',').map((item) => item.trim());
@ -99,6 +101,9 @@ export async function downloadRecordAttachments(
const elements: INodeExecutionData[] = []; const elements: INodeExecutionData[] = [];
for (const record of records) { for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} }; const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = flattenOutput(record as unknown as IDataObject); element.json = flattenOutput(record as unknown as IDataObject);
for (const fieldName of fieldNames) { for (const fieldName of fieldNames) {
if (record.fields[fieldName] !== undefined) { if (record.fields[fieldName] !== undefined) {

View file

@ -13,6 +13,7 @@ import type {
import { deepCopy } from 'n8n-workflow'; import { deepCopy } from 'n8n-workflow';
import { oldVersionNotice } from '@utils/descriptions'; import { oldVersionNotice } from '@utils/descriptions';
import { generatePairedItemData } from '../../../utils/utilities';
const versionDescription: INodeTypeDescription = { const versionDescription: INodeTypeDescription = {
displayName: 'Merge', displayName: 'Merge',
@ -477,7 +478,8 @@ export class MergeV1 implements INodeType {
returnData.push.apply(returnData, this.getInputData(1)); returnData.push.apply(returnData, this.getInputData(1));
} }
} else if (mode === 'wait') { } else if (mode === 'wait') {
returnData.push({ json: {} }); const pairedItem = generatePairedItemData(this.getInputData(0).length);
returnData.push({ json: {}, pairedItem });
} }
return [returnData]; return [returnData];

View file

@ -29,6 +29,7 @@ import {
} from './GenericFunctions'; } from './GenericFunctions';
import { optionsDescription } from './OptionsDescription'; import { optionsDescription } from './OptionsDescription';
import { generatePairedItemData } from '../../../utils/utilities';
const versionDescription: INodeTypeDescription = { const versionDescription: INodeTypeDescription = {
displayName: 'Merge', displayName: 'Merge',
@ -599,7 +600,8 @@ export class MergeV2 implements INodeType {
returnData.push.apply(returnData, this.getInputData(1)); returnData.push.apply(returnData, this.getInputData(1));
} }
if (output === 'empty') { if (output === 'empty') {
returnData.push({ json: {} }); const itemData = generatePairedItemData(this.getInputData(0).length);
returnData.push({ json: {}, pairedItem: itemData });
} }
} }
} }

View file

@ -7,6 +7,7 @@ import type {
IHookFunctions, IHookFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
IPairedItemData,
IPollFunctions, IPollFunctions,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { jsonParse, NodeOperationError } from 'n8n-workflow'; import { jsonParse, NodeOperationError } from 'n8n-workflow';
@ -106,11 +107,15 @@ export async function downloadRecordAttachments(
this: IExecuteFunctions | IPollFunctions, this: IExecuteFunctions | IPollFunctions,
records: IDataObject[], records: IDataObject[],
fieldNames: string[], fieldNames: string[],
pairedItem?: IPairedItemData[],
): Promise<INodeExecutionData[]> { ): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = []; const elements: INodeExecutionData[] = [];
for (const record of records) { for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} }; const element: INodeExecutionData = { json: {}, binary: {} };
if (pairedItem) {
element.pairedItem = pairedItem;
}
element.json = record as unknown as IDataObject; element.json = record as unknown as IDataObject;
for (const fieldName of fieldNames) { for (const fieldName of fieldNames) {
let attachments = record[fieldName] as IAttachment[]; let attachments = record[fieldName] as IAttachment[];

View file

@ -521,6 +521,7 @@ export class NocoDB implements INodeType {
this, this,
responseData as IDataObject[], responseData as IDataObject[],
downloadFieldNames, downloadFieldNames,
[{ item: i }],
); );
data.push(...response); data.push(...response);
} }
@ -584,6 +585,7 @@ export class NocoDB implements INodeType {
this, this,
[responseData as IDataObject], [responseData as IDataObject],
downloadFieldNames, downloadFieldNames,
[{ item: i }],
); );
const newItem = { const newItem = {
binary: data[0].binary, binary: data[0].binary,

View file

@ -9,6 +9,7 @@ import type {
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeProperties, INodeProperties,
IPairedItemData,
IPollFunctions, IPollFunctions,
JsonObject, JsonObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -860,12 +861,15 @@ export type FileRecord = {
}; };
}; };
// prettier-ignore // prettier-ignore
export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: FileRecord[]): Promise<INodeExecutionData[]> { export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: FileRecord[], pairedItem?: IPairedItemData[]): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = []; const elements: INodeExecutionData[] = [];
for (const record of records) { for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} }; const element: INodeExecutionData = { json: {}, binary: {} };
element.json = record as unknown as IDataObject; element.json = record as unknown as IDataObject;
if (pairedItem) {
element.pairedItems = pairedItem;
}
for (const key of Object.keys(record.properties)) { for (const key of Object.keys(record.properties)) {
if (record.properties[key].type === 'files') { if (record.properties[key].type === 'files') {
if (record.properties[key].files.length) { if (record.properties[key].files.length) {

View file

@ -591,7 +591,9 @@ export class NotionV2 implements INodeType {
responseData = responseData.results; responseData = responseData.results;
} }
if (download) { if (download) {
responseData = await downloadFiles.call(this, responseData as FileRecord[]); responseData = await downloadFiles.call(this, responseData as FileRecord[], [
{ item: i },
]);
} }
if (simple) { if (simple) {
responseData = simplifyObjects(responseData, download); responseData = simplifyObjects(responseData, download);

View file

@ -530,7 +530,7 @@ export class Redis implements INodeType {
let item: INodeExecutionData; let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
item = { json: {} }; item = { json: {}, pairedItem: { item: itemIndex } };
if (operation === 'delete') { if (operation === 'delete') {
const keyDelete = this.getNodeParameter('key', itemIndex) as string; const keyDelete = this.getNodeParameter('key', itemIndex) as string;

View file

@ -150,7 +150,7 @@ export class SetV1 implements INodeType {
const nodeVersion = this.getNode().typeVersion; const nodeVersion = this.getNode().typeVersion;
if (items.length === 0) { if (items.length === 0) {
items.push({ json: {} }); items.push({ json: {}, pairedItem: { item: 0 } });
} }
const returnData: INodeExecutionData[] = []; const returnData: INodeExecutionData[] = [];