fix(core)!: $(...).[last,first,all]() defaulting to the first output instead of the output that connects the nodes (#9760)

This commit is contained in:
Danny Martini
2024-06-19 15:10:30 +02:00
committed by GitHub
parent 77bf16667b
commit 4ac9266820
5 changed files with 244 additions and 14 deletions

View File

@@ -619,18 +619,9 @@ export class WorkflowDataProxy {
getDataProxy(): IWorkflowDataProxyData {
const that = this;
const getNodeOutput = (nodeName?: string, branchIndex?: number, runIndex?: number) => {
let executionData: INodeExecutionData[];
if (nodeName === undefined) {
executionData = that.connectionInputData;
} else {
branchIndex = branchIndex || 0;
runIndex = runIndex === undefined ? -1 : runIndex;
executionData = that.getNodeExecutionData(nodeName, false, branchIndex, runIndex);
}
return executionData;
const getNodeOutput = (nodeName: string, branchIndex: number, runIndex?: number) => {
runIndex = runIndex === undefined ? -1 : runIndex;
return that.getNodeExecutionData(nodeName, false, branchIndex, runIndex);
};
// replacing proxies with the actual data.
@@ -1073,6 +1064,12 @@ export class WorkflowDataProxy {
if (property === 'first') {
ensureNodeExecutionData();
return (branchIndex?: number, runIndex?: number) => {
branchIndex =
branchIndex ??
// default to the output the active node is connected to
that.workflow.getNodeConnectionIndexes(that.activeNodeName, nodeName)
?.sourceIndex ??
0;
const executionData = getNodeOutput(nodeName, branchIndex, runIndex);
if (executionData[0]) return executionData[0];
return undefined;
@@ -1081,6 +1078,12 @@ export class WorkflowDataProxy {
if (property === 'last') {
ensureNodeExecutionData();
return (branchIndex?: number, runIndex?: number) => {
branchIndex =
branchIndex ??
// default to the output the active node is connected to
that.workflow.getNodeConnectionIndexes(that.activeNodeName, nodeName)
?.sourceIndex ??
0;
const executionData = getNodeOutput(nodeName, branchIndex, runIndex);
if (!executionData.length) return undefined;
if (executionData[executionData.length - 1]) {
@@ -1091,8 +1094,15 @@ export class WorkflowDataProxy {
}
if (property === 'all') {
ensureNodeExecutionData();
return (branchIndex?: number, runIndex?: number) =>
getNodeOutput(nodeName, branchIndex, runIndex);
return (branchIndex?: number, runIndex?: number) => {
branchIndex =
branchIndex ??
// default to the output the active node is connected to
that.workflow.getNodeConnectionIndexes(that.activeNodeName, nodeName)
?.sourceIndex ??
0;
return getNodeOutput(nodeName, branchIndex, runIndex);
};
}
if (property === 'context') {
return that.nodeContextGetter(nodeName);