Skip to content

Commit

Permalink
feat: Do not assign all paired items (no-changelog) (#11716)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Feb 6, 2025
1 parent 2eabca5 commit 4c2546d
Show file tree
Hide file tree
Showing 33 changed files with 55 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,20 @@ describe('Test AirtableV2, base => getMany', () => {
name: 'base 1',
permissionLevel: 'create',
},
pairedItem: [
{
item: 0,
},
],
},
{
json: {
id: 'appYYY',
name: 'base 2',
permissionLevel: 'edit',
},
pairedItem: [
{
item: 0,
},
],
},
{
json: {
id: 'appZZZ',
name: 'base 3',
permissionLevel: 'create',
},
pairedItem: [
{
item: 0,
},
],
},
]);
});
Expand All @@ -101,11 +86,6 @@ describe('Test AirtableV2, base => getMany', () => {
name: 'base 2',
permissionLevel: 'edit',
},
pairedItem: [
{
item: 0,
},
],
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ 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: [],
});
});

Expand Down Expand Up @@ -142,11 +138,7 @@ 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: [],
});
});
});
13 changes: 2 additions & 11 deletions packages/nodes-base/nodes/Airtable/v1/AirtableV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
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 @@ -737,24 +736,16 @@ export class AirtableV1 implements INodeType {
const downloadFieldNames = (
this.getNodeParameter('downloadFieldNames', 0) as string
).split(',');
const pairedItem = generatePairedItemData(items.length);

const data = await downloadRecordAttachments.call(
this,
responseData.records as IRecord[],
downloadFieldNames,
pairedItem,
);
return [data];
}

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

return [
this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(returnData), {
itemData,
}),
];
return [this.helpers.returnJsonArray(returnData)];
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import type {
IExecuteFunctions,
} from 'n8n-workflow';

import {
generatePairedItemData,
updateDisplayOptions,
wrapData,
} from '../../../../../utils/utilities';
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
import { apiRequest } from '../../transport';

const properties: INodeProperties[] = [
Expand Down Expand Up @@ -112,11 +108,7 @@ 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,
});
const returnData = wrapData(bases);

return returnData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
IExecuteFunctions,
} from 'n8n-workflow';

import { generatePairedItemData, updateDisplayOptions } from '../../../../../utils/utilities';
import { updateDisplayOptions } from '../../../../../utils/utilities';
import type { IRecord } from '../../helpers/interfaces';
import { flattenOutput } from '../../helpers/utils';
import { apiRequest, apiRequestAllItems, downloadRecordAttachments } from '../../transport';
Expand Down Expand Up @@ -156,12 +156,9 @@ export async function execute(
const endpoint = `${base}/${table}`;

let itemsLength = items.length ? 1 : 0;
let fallbackPairedItems;

if (nodeVersion >= 2.1) {
itemsLength = items.length;
} else {
fallbackPairedItems = generatePairedItemData(items.length);
}

for (let i = 0; i < itemsLength; i++) {
Expand Down Expand Up @@ -208,7 +205,7 @@ export async function execute(
this,
responseData.records as IRecord[],
options.downloadFields as string[],
fallbackPairedItems || [{ item: i }],
nodeVersion >= 2.1 ? [{ item: i }] : undefined,
);
returnData.push(...itemWithAttachments);
continue;
Expand All @@ -220,7 +217,7 @@ export async function execute(
json: flattenOutput(record),
})) as INodeExecutionData[];

const itemData = fallbackPairedItems || [{ item: i }];
const itemData = nodeVersion >= 2.1 ? [{ item: i }] : [];

const executionData = this.helpers.constructExecutionMetaData(records, {
itemData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {

import { getWorkflowInfo } from './GenericFunctions';
import { localResourceMapping } from './methods';
import { generatePairedItemData } from '../../../utils/utilities';
import { getCurrentWorkflowInputData } from '../../../utils/workflowInputsResourceMapping/GenericFunctions';
export class ExecuteWorkflow implements INodeType {
description: INodeTypeDescription = {
Expand Down Expand Up @@ -422,8 +421,6 @@ export class ExecuteWorkflow implements INodeType {

const workflowResult = executionResult.data as INodeExecutionData[][];

const fallbackPairedItemData = generatePairedItemData(items.length);

for (const output of workflowResult) {
const sameLength = output.length === items.length;

Expand All @@ -432,17 +429,14 @@ export class ExecuteWorkflow implements INodeType {

if (sameLength) {
item.pairedItem = { item: itemIndex };
} else {
item.pairedItem = fallbackPairedItemData;
}
}
}

return workflowResult;
} catch (error) {
const pairedItem = generatePairedItemData(items.length);
if (this.continueOnFail()) {
return [[{ json: { error: error.message }, pairedItem }]];
return [[{ json: { error: error.message } }]];
}
throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

import type { JsonToSpreadsheetBinaryOptions, JsonToSpreadsheetBinaryFormat } from '@utils/binary';
import { convertJsonToSpreadsheetBinary } from '@utils/binary';
import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
import { updateDisplayOptions } from '@utils/utilities';

export const operations = ['csv', 'html', 'rtf', 'ods', 'xls', 'xlsx'];

Expand Down Expand Up @@ -98,7 +98,6 @@ export async function execute(
) {
let returnData: INodeExecutionData[] = [];

const pairedItem = generatePairedItemData(items.length);
try {
const options = this.getNodeParameter('options', 0, {}) as JsonToSpreadsheetBinaryOptions;
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0, 'data');
Expand All @@ -116,7 +115,6 @@ export async function execute(
binary: {
[binaryPropertyName]: binaryData,
},
pairedItem,
};

returnData = [newItem];
Expand All @@ -126,7 +124,6 @@ export async function execute(
json: {
error: error.message,
},
pairedItem,
});
} else {
throw new NodeOperationError(this.getNode(), error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NodeOperationError } from 'n8n-workflow';

import { createBinaryFromJson } from '@utils/binary';
import { encodeDecodeOptions } from '@utils/descriptions';
import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
import { updateDisplayOptions } from '@utils/utilities';

export const properties: INodeProperties[] = [
{
Expand Down Expand Up @@ -92,7 +92,6 @@ export async function execute(this: IExecuteFunctions, items: INodeExecutionData

const mode = this.getNodeParameter('mode', 0, 'once') as string;
if (mode === 'once') {
const pairedItem = generatePairedItemData(items.length);
try {
const options = this.getNodeParameter('options', 0, {});
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0, 'data');
Expand All @@ -114,7 +113,6 @@ export async function execute(this: IExecuteFunctions, items: INodeExecutionData
binary: {
[binaryPropertyName]: binaryData,
},
pairedItem,
};

returnData = [newItem];
Expand All @@ -124,7 +122,6 @@ export async function execute(this: IExecuteFunctions, items: INodeExecutionData
json: {
error: error.message,
},
pairedItem,
});
}
throw new NodeOperationError(this.getNode(), error);
Expand Down
6 changes: 2 additions & 4 deletions packages/nodes-base/nodes/Ftp/Ftp.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Readable } from 'stream';
import { pipeline } from 'stream/promises';
import { file as tmpFile } from 'tmp-promise';

import { formatPrivateKey, generatePairedItemData } from '@utils/utilities';
import { formatPrivateKey } from '@utils/utilities';

interface ReturnFtpItem {
type: string;
Expand Down Expand Up @@ -550,9 +550,7 @@ export class Ftp implements INodeType {
}
} catch (error) {
if (this.continueOnFail()) {
const pairedItem = generatePairedItemData(items.length);

return [[{ json: { error: error.message }, pairedItem }]];
return [[{ json: { error: error.message } }]];
}
throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { oldVersionNotice } from '@utils/descriptions';

import { googleApiRequest, googleApiRequestAllItems, simplify } from './GenericFunctions';
import { recordFields, recordOperations } from './RecordDescription';
import { generatePairedItemData } from '../../../../utils/utilities';

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

body.rows = rows;

const itemData = generatePairedItemData(items.length);

try {
responseData = await googleApiRequest.call(
this,
Expand All @@ -205,17 +202,11 @@ export class GoogleBigQueryV1 implements INodeType {
body,
);

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData },
);
const executionData = this.helpers.returnJsonArray(responseData as IDataObject[]);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData },
);
const executionErrorData = this.helpers.returnJsonArray({ error: error.message });
returnData.push(...executionErrorData);
}
throw new NodeApiError(this.getNode(), error as JsonObject, { itemIndex: 0 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import { NodeOperationError } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';

import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
import { updateDisplayOptions } from '@utils/utilities';

import type { TableSchema } from '../../helpers/interfaces';
import { checkSchema, wrapData } from '../../helpers/utils';
Expand Down Expand Up @@ -227,7 +227,6 @@ 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 @@ -281,10 +280,7 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
});
}

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

returnData.push(...executionData);
}
Expand Down
Loading

0 comments on commit 4c2546d

Please sign in to comment.