mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-08-05 11:28:36 +02:00
36 lines
912 B
TypeScript
36 lines
912 B
TypeScript
import type { INode, IRunData } from 'n8n-workflow';
|
|
|
|
import type { DirectedGraph } from './directed-graph';
|
|
|
|
/**
|
|
* Returns new run data that does not contain data for any node that is a child
|
|
* of any start node.
|
|
* This does not mutate the `runData` being passed in.
|
|
*/
|
|
export function cleanRunData(
|
|
runData: IRunData,
|
|
graph: DirectedGraph,
|
|
startNodes: Set<INode>,
|
|
): IRunData {
|
|
const newRunData: IRunData = { ...runData };
|
|
|
|
for (const startNode of startNodes) {
|
|
delete newRunData[startNode.name];
|
|
const children = graph.getChildren(startNode);
|
|
|
|
for (const child of children) {
|
|
delete newRunData[child.name];
|
|
}
|
|
}
|
|
|
|
// Remove run data for all nodes that are not part of the subgraph
|
|
for (const nodeName of Object.keys(newRunData)) {
|
|
if (!graph.hasNode(nodeName)) {
|
|
// remove run data for node that is not part of the graph
|
|
delete newRunData[nodeName];
|
|
}
|
|
}
|
|
|
|
return newRunData;
|
|
}
|