feat(core)!: Change data processing for multi-input-nodes (#4238)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Jan Oberhauser
2023-06-23 12:07:52 +02:00
committed by GitHub
parent 9194d8bb0e
commit b8458a53f6
13 changed files with 7032 additions and 67 deletions

View File

@@ -20,6 +20,7 @@ export class Merge extends VersionedNodeType {
1: new MergeV1(baseDescription),
2: new MergeV2(baseDescription),
2.1: new MergeV2(baseDescription),
2.2: new MergeV2(baseDescription),
};
super(nodeVersions, baseDescription);

View File

@@ -30,6 +30,7 @@ const versionDescription: INodeTypeDescription = {
inputs: ['main', 'main'],
outputs: ['main'],
inputNames: ['Input 1', 'Input 2'],
forceInputNodeExecution: true,
properties: [
oldVersionNotice,
{

View File

@@ -35,7 +35,7 @@ const versionDescription: INodeTypeDescription = {
name: 'merge',
icon: 'fa:code-branch',
group: ['transform'],
version: [2, 2.1],
version: [2, 2.1, 2.2],
subtitle: '={{$parameter["mode"]}}',
description: 'Merges data of multiple streams once data from both is available',
defaults: {
@@ -46,6 +46,11 @@ const versionDescription: INodeTypeDescription = {
inputs: ['main', 'main'],
outputs: ['main'],
inputNames: ['Input 1', 'Input 2'],
// If the node is of version 2.2 or if mode is chooseBranch data from both branches is required
// to continue, else data from any input suffices
requiredInputs:
'={{ $version < 2.2 ? undefined : ($parameter["mode"] === "chooseBranch" ? [0, 1] : 1) }}',
forceInputNodeExecution: '={{ $version < 2.2 }}',
properties: [
{
displayName: 'Mode',
@@ -374,6 +379,12 @@ export class MergeV2 implements INodeType {
let input1 = this.getInputData(0);
let input2 = this.getInputData(1);
if (input1.length === 0 || input2.length === 0) {
// If data of any input is missing, return the data of
// the input that contains data
return [[...input1, ...input2]];
}
if (clashHandling.resolveClash === 'preferInput1') {
[input1, input2] = [input2, input1];
}
@@ -454,6 +465,7 @@ export class MergeV2 implements INodeType {
let input1 = this.getInputData(0);
let input2 = this.getInputData(1);
if (nodeVersion < 2.1) {
input1 = checkInput(
this.getInputData(0),
@@ -473,6 +485,24 @@ export class MergeV2 implements INodeType {
if (!input1) return [returnData];
}
if (input1.length === 0 || input2.length === 0) {
if (joinMode === 'keepMatches') {
// Stop the execution
return [[]];
} else if (joinMode === 'enrichInput1' && input1.length === 0) {
// No data to enrich so stop
return [[]];
} else if (joinMode === 'enrichInput2' && input2.length === 0) {
// No data to enrich so stop
return [[]];
} else {
// Return the data of any of the inputs that contains data
return [[...input1, ...input2]];
}
}
if (!input1) return [returnData];
if (!input2 || !matchFields.length) {
if (
joinMode === 'keepMatches' ||