fix(Merge Node): Do not error if expected key is missing

This commit is contained in:
Michael Kret
2023-04-28 19:46:59 +03:00
committed by GitHub
parent c0b1cddc91
commit d219af75cf
11 changed files with 1257 additions and 74 deletions

View File

@@ -68,7 +68,7 @@ export class ItemListsV2 implements INodeType {
constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
version: 2,
version: [2, 2.1],
defaults: {
name: 'Item Lists',
},
@@ -803,6 +803,8 @@ return 0;`,
const returnData: INodeExecutionData[] = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const nodeVersion = this.getNode().typeVersion;
if (resource === 'itemList') {
if (operation === 'splitOutItems') {
for (let i = 0; i < length; i++) {
@@ -827,21 +829,25 @@ return 0;`,
}
if (arrayToSplit === undefined) {
if (fieldToSplitOut.includes('.') && disableDotNotation) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToSplitOut}' in the input data`,
{
description:
"If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options",
},
);
if (nodeVersion < 2.1) {
if (fieldToSplitOut.includes('.') && disableDotNotation) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToSplitOut}' in the input data`,
{
description:
"If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options",
},
);
} else {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToSplitOut}' in the input data`,
{ itemIndex: i },
);
}
} else {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToSplitOut}' in the input data`,
{ itemIndex: i },
);
arrayToSplit = [];
}
}
@@ -950,36 +956,39 @@ return 0;`,
description: 'Please add a field to aggregate',
});
}
for (const { fieldToAggregate } of fieldsToAggregate) {
let found = false;
for (const item of items) {
if (fieldToAggregate === '') {
throw new NodeOperationError(this.getNode(), 'Field to aggregate is blank', {
description: 'Please add a field to aggregate',
});
}
if (!disableDotNotation) {
if (get(item.json, fieldToAggregate) !== undefined) {
if (nodeVersion < 2.1) {
for (const { fieldToAggregate } of fieldsToAggregate) {
let found = false;
for (const item of items) {
if (fieldToAggregate === '') {
throw new NodeOperationError(this.getNode(), 'Field to aggregate is blank', {
description: 'Please add a field to aggregate',
});
}
if (!disableDotNotation) {
if (get(item.json, fieldToAggregate) !== undefined) {
found = true;
}
} else if (item.json.hasOwnProperty(fieldToAggregate)) {
found = true;
}
} else if (item.json.hasOwnProperty(fieldToAggregate)) {
found = true;
}
}
if (!found && disableDotNotation && fieldToAggregate.includes('.')) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToAggregate}' in the input data`,
{
description:
"If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options",
},
);
} else if (!found && !keepMissing) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToAggregate}' in the input data`,
);
if (!found && disableDotNotation && fieldToAggregate.includes('.')) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToAggregate}' in the input data`,
{
description:
"If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options",
},
);
} else if (!found && !keepMissing) {
throw new NodeOperationError(
this.getNode(),
`Couldn't find the field '${fieldToAggregate}' in the input data`,
);
}
}
}

View File

@@ -571,7 +571,11 @@ export async function execute(
const getValue = fieldValueGetter(options.disableDotNotation);
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
const nodeVersion = this.getNode().typeVersion;
if (nodeVersion < 2.1) {
checkIfFieldExists.call(this, newItems, fieldsToSummarize, getValue);
}
const aggregationResult = splitData(
fieldsToSplitBy,