Skip to content

Commit

Permalink
fix(core): Missing pairing info (n8n-io#7326)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):
  • Loading branch information
michael-radency authored Oct 10, 2023
1 parent 6479eb1 commit e2c3c7a
Show file tree
Hide file tree
Showing 52 changed files with 363 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,35 @@ describe('Test AirtableV2, base => getMany', () => {
name: 'base 1',
permissionLevel: 'create',
},
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
},
{
json: {
id: 'appYYY',
name: 'base 2',
permissionLevel: 'edit',
},
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
},
{
json: {
id: 'appZZZ',
name: 'base 3',
permissionLevel: 'create',
},
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
},
]);
});
Expand All @@ -107,9 +113,11 @@ describe('Test AirtableV2, base => getMany', () => {
name: 'base 2',
permissionLevel: 'edit',
},
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
},
]);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/nodes-base/nodes/Airtable/test/v2/node/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const node: INode = {

export const createMockExecuteFunction = (nodeParameters: IDataObject) => {
const fakeExecuteFunction = {
getInputData() {
return [{ json: {} }];
},
getNodeParameter(
parameterName: string,
_itemIndex: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ describe('Test AirtableV2, search operation', () => {
expect(result).toHaveLength(2);
expect(result[0]).toEqual({
json: { id: 'recYYY', foo: 'foo 2', bar: 'bar 2' },
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
});
});

Expand Down Expand Up @@ -152,9 +154,11 @@ describe('Test AirtableV2, search operation', () => {
expect(result).toHaveLength(1);
expect(result[0]).toEqual({
json: { id: 'recYYY', foo: 'foo 2', bar: 'bar 2' },
pairedItem: {
item: 0,
},
pairedItem: [
{
item: 0,
},
],
});
});
});
5 changes: 4 additions & 1 deletion packages/nodes-base/nodes/Airtable/v1/AirtableV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { IRecord } from './GenericFunctions';
import { apiRequest, apiRequestAllItems, downloadRecordAttachments } from './GenericFunctions';

import { oldVersionNotice } from '../../../utils/descriptions';
import { generatePairedItemData } from '../../../utils/utilities';

const versionDescription: INodeTypeDescription = {
displayName: 'Airtable',
Expand Down Expand Up @@ -727,9 +728,11 @@ export class AirtableV1 implements INodeType {
}

// We can return from here
const itemData = generatePairedItemData(items.length);

return [
this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(returnData), {
itemData: { item: 0 },
itemData,
}),
];
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type {
INodeProperties,
IExecuteFunctions,
} from 'n8n-workflow';
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
import {
generatePairedItemData,
updateDisplayOptions,
wrapData,
} from '../../../../../utils/utilities';
import { apiRequest } from '../../transport';

const properties: INodeProperties[] = [
Expand Down Expand Up @@ -107,8 +111,10 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
bases = bases.filter((base) => permissionLevel.includes(base.permissionLevel as string));
}

const itemData = generatePairedItemData(this.getInputData().length);

const returnData = this.helpers.constructExecutionMetaData(wrapData(bases), {
itemData: { item: 0 },
itemData,
});

return returnData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
INodeProperties,
IExecuteFunctions,
} from 'n8n-workflow';
import { updateDisplayOptions } from '../../../../../utils/utilities';
import { generatePairedItemData, updateDisplayOptions } from '../../../../../utils/utilities';
import { apiRequest, apiRequestAllItems, downloadRecordAttachments } from '../../transport';
import type { IRecord } from '../../helpers/interfaces';
import { flattenOutput } from '../../helpers/utils';
Expand Down Expand Up @@ -205,8 +205,10 @@ export async function execute(
json: flattenOutput(record as IDataObject),
}));

const itemData = generatePairedItemData(items.length);

returnData = this.helpers.constructExecutionMetaData(returnData, {
itemData: { item: 0 },
itemData,
});
} catch (error) {
if (this.continueOnFail()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import unset from 'lodash/unset';
import { cloneDeep } from 'lodash';
import set from 'lodash/set';
import union from 'lodash/union';
import { fuzzyCompare } from '@utils/utilities';
import { fuzzyCompare, preparePairedItemDataArray } from '@utils/utilities';

type PairToMatch = {
field1: string;
Expand Down Expand Up @@ -141,6 +141,10 @@ function compareItems(

return {
json: { keys, same, different, ...(!isEmpty(skipped) && { skipped }) },
pairedItem: [
...preparePairedItemDataArray(item1.pairedItem),
...preparePairedItemDataArray(item2.pairedItem),
],
} as INodeExecutionData;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/nodes-base/nodes/Filter/Filter.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export class Filter implements INodeType {
value2,
);

if (item.pairedItem === undefined) {
item.pairedItem = [{ item: itemIndex }];
}

// If the operation is "OR" it means the item did match one condition no ned to check further
if (compareResult && combineConditions === 'OR') {
returnDataTrue.push(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { recordFields, recordOperations } from './RecordDescription';
import { v4 as uuid } from 'uuid';

import { oldVersionNotice } from '@utils/descriptions';
import { generatePairedItemData } from '../../../../utils/utilities';

const versionDescription: INodeTypeDescription = {
displayName: 'Google BigQuery',
Expand Down Expand Up @@ -198,6 +199,8 @@ export class GoogleBigQueryV1 implements INodeType {

body.rows = rows;

const itemData = generatePairedItemData(items.length);

try {
responseData = await googleApiRequest.call(
this,
Expand All @@ -208,14 +211,14 @@ export class GoogleBigQueryV1 implements INodeType {

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: 0 } },
{ itemData },
);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: 0 } },
{ itemData },
);
returnData.push(...executionErrorData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';
import { updateDisplayOptions } from '@utils/utilities';
import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
import type { TableSchema } from '../../helpers/interfaces';
import { checkSchema, wrapData } from '../../helpers/utils';
import { googleApiRequest } from '../../transport';
Expand Down Expand Up @@ -225,6 +225,7 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
}
}

const itemData = generatePairedItemData(items.length);
for (let i = 0; i < rows.length; i += batchSize) {
const batch = rows.slice(i, i + batchSize);
body.rows = batch;
Expand Down Expand Up @@ -279,7 +280,7 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa

const executionData = this.helpers.constructExecutionMetaData(
wrapData(responseData as IDataObject[]),
{ itemData: { item: 0 } },
{ itemData },
);

returnData.push(...executionData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { collectionFields, collectionOperations } from './CollectionDescription';

import { documentFields, documentOperations } from './DocumentDescription';
import { generatePairedItemData } from '../../../../utils/utilities';

export class GoogleFirebaseCloudFirestore implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -90,6 +91,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const itemData = generatePairedItemData(items.length);
const returnData: INodeExecutionData[] = [];
let responseData;
const resource = this.getNodeParameter('resource', 0);
Expand Down Expand Up @@ -130,7 +132,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: 0 } },
{ itemData },
);

returnData.push(...executionData);
Expand Down Expand Up @@ -213,7 +215,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: 0 } },
{ itemData },
);

returnData.push(...executionData);
Expand Down Expand Up @@ -395,7 +397,7 @@ export class GoogleFirebaseCloudFirestore implements INodeType {

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: 0 } },
{ itemData },
);

returnData.push(...executionData);
Expand Down
12 changes: 11 additions & 1 deletion packages/nodes-base/nodes/Google/Sheet/v1/GoogleSheetsV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { googleApiRequest, hexToRgb } from './GenericFunctions';

import { versionDescription } from './versionDescription';
import { getGoogleAccessToken } from '../../GenericFunctions';
import { generatePairedItemData } from '../../../../utils/utilities';

export class GoogleSheetsV1 implements INodeType {
description: INodeTypeDescription;
Expand Down Expand Up @@ -295,7 +296,16 @@ export class GoogleSheetsV1 implements INodeType {
returnData = [];
}

return [this.helpers.returnJsonArray(returnData)];
const pairedItem = generatePairedItemData(items.length);

const lookupOutput = returnData.map((item) => {
return {
json: item,
pairedItem,
};
});

return [lookupOutput];
} catch (error) {
if (this.continueOnFail()) {
return [this.helpers.returnJsonArray({ error: error.message })];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ export async function execute(
if (nodeVersion < 4 || dataMode === 'autoMapInputData') {
return items;
} else {
return this.helpers.returnJsonArray(setData);
const returnData: INodeExecutionData[] = [];
for (const [index, entry] of setData.entries()) {
returnData.push({
json: entry,
pairedItems: { item: index },
});
}
return returnData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ export async function execute(
if (nodeVersion < 4 || dataMode === 'autoMapInputData') {
return items;
} else {
return this.helpers.returnJsonArray(mappedValues);
const returnData: INodeExecutionData[] = [];
for (const [index, entry] of mappedValues.entries()) {
returnData.push({
json: entry,
pairedItems: { item: index },
});
}
return returnData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SheetProperties } from '../../helpers/GoogleSheets.types';
import { apiRequest } from '../../transport';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import { getExistingSheetNames, hexToRgb } from '../../helpers/GoogleSheets.utils';
import { wrapData } from '../../../../../../utils/utilities';

export const description: SheetProperties = [
{
Expand Down Expand Up @@ -78,7 +79,7 @@ export async function execute(
sheetName: string,
): Promise<INodeExecutionData[]> {
let responseData;
const returnData: IDataObject[] = [];
const returnData: INodeExecutionData[] = [];
const items = this.getInputData();

const existingSheetNames = await getExistingSheetNames(sheet);
Expand Down Expand Up @@ -120,7 +121,12 @@ export async function execute(

existingSheetNames.push(sheetTitle);

returnData.push(responseData as IDataObject);
const executionData = this.helpers.constructExecutionMetaData(
wrapData(responseData as IDataObject[]),
{ itemData: { item: i } },
);

returnData.push(...executionData);
}
return this.helpers.returnJsonArray(returnData);
return returnData;
}
Loading

0 comments on commit e2c3c7a

Please sign in to comment.