Added multiplex mode to merge

Even though it theoretically supports multiple inputs and outputs, more
common use case is with one of the inputs having single item similar to
an iterative set node.
This commit is contained in:
Subhash Chandra 2020-01-15 17:45:26 +05:30
parent 974013640d
commit 21de89608e

View file

@ -51,6 +51,11 @@ export class Merge implements INodeType {
value: 'mergeByKey', value: 'mergeByKey',
description: 'Merges data of both inputs. The output will contain items of input 1 merged with data of input 2. Merge happens depending on a defined key.', description: 'Merges data of both inputs. The output will contain items of input 1 merged with data of input 2. Merge happens depending on a defined key.',
}, },
{
name: 'Multiplex',
value: 'mux',
description: 'Merges each value of one input with each value of the other input. The output will contain (m * n) items where (m) and (n) are lengths of the inputs.'
},
{ {
name: 'Pass-through', name: 'Pass-through',
value: 'passThrough', value: 'passThrough',
@ -254,6 +259,23 @@ export class Merge implements INodeType {
returnData.push(newItem); returnData.push(newItem);
} }
} else if (mode === 'mux') {
const dataInput1 = this.getInputData(0);
const dataInput2 = this.getInputData(1);
if (!dataInput1 || !dataInput2) {
return [returnData];
}
let entry1: INodeExecutionData;
let entry2: INodeExecutionData;
for (entry1 of dataInput1) {
for (entry2 of dataInput2) {
returnData.push({json: {...(entry1.json), ...(entry2.json)}});
}
}
return [returnData];
} else if (['keepKeyMatches', 'mergeByKey', 'removeKeyMatches'].includes(mode)) { } else if (['keepKeyMatches', 'mergeByKey', 'removeKeyMatches'].includes(mode)) {
const dataInput1 = this.getInputData(0); const dataInput1 = this.getInputData(0);
if (!dataInput1) { if (!dataInput1) {