MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / executeMergeChangesNode

Function executeMergeChangesNode

src/nodeExecutor.ts:2528–2640  ·  view source on GitHub ↗
(
  nodeId: string,
  inputData: DBNumericAdjustmentNodeData | DBNumericAdjustmentNodeData[],
  executionContext?: FlowExecutionContext,
)

Source from the content-addressed store, hash-verified

2526}
2527
2528async function executeMergeChangesNode(
2529 nodeId: string,
2530 inputData: DBNumericAdjustmentNodeData | DBNumericAdjustmentNodeData[],
2531 executionContext?: FlowExecutionContext,
2532): Promise<NodeExecutionResult> {
2533 console.log(`MergeChanges Node ${nodeId}: Merging multiple ChangedColumnSelection inputs`);
2534
2535 // Convert single input to array for uniform handling
2536 const inputs = Array.isArray(inputData) ? inputData : [inputData];
2537
2538 // Validate all inputs are ChangedColumnSelection
2539 for (let i = 0; i < inputs.length; i++) {
2540 if (!inputs[i] || inputs[i].type !== "ChangedColumnSelection") {
2541 return {
2542 success: false,
2543 error: `Invalid input at index ${i}: Expected ChangedColumnSelection data`,
2544 };
2545 }
2546 }
2547
2548 if (inputs.length === 0) {
2549 return {
2550 success: false,
2551 error: "No inputs to merge. Connect at least one ChangedColumnSelection node.",
2552 };
2553 }
2554
2555 // Start with a deep clone of the first input as the base
2556 const mergedData = structuredClone(inputs[0].adjustedInputData);
2557
2558 // Merge all subsequent inputs
2559 for (let i = 1; i < inputs.length; i++) {
2560 const currentInput = inputs[i].adjustedInputData;
2561
2562 // For each table in the current input, merge with the corresponding table in mergedData
2563 for (const currentColumn of currentInput.columns) {
2564 // Find if this table already exists in mergedData
2565 const existingColumn = mergedData.columns.find(
2566 (col) => col.tableName === currentColumn.tableName && col.fileName === currentColumn.fileName,
2567 );
2568
2569 if (existingColumn) {
2570 // Merge the changes from currentColumn into existingColumn
2571 // Update the schemaFields to reflect the changes from the current input
2572 if (
2573 currentColumn.sourceTable.schemaFields &&
2574 existingColumn.sourceTable.schemaFields &&
2575 currentColumn.sourceTable.tableSchema &&
2576 existingColumn.sourceTable.tableSchema
2577 ) {
2578 // Merge schemaFields row by row
2579 const currentRows = getRowsForPackedFile(currentColumn.sourceTable, executionContext);
2580 const existingRows = getRowsForPackedFile(existingColumn.sourceTable, executionContext);
2581
2582 // Use Set for O(1) lookup
2583 const currentSelectedSet = new Set(currentColumn.selectedColumns);
2584
2585 // Update cells in existingRows with values from currentRows if they were changed

Callers 1

executeNodeActionFunction · 0.85

Calls 3

getRowsForPackedFileFunction · 0.70
addMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected