( nodeId: string, textValue: string, inputData: DBTablesNodeData, config?: unknown, executionContext?: FlowExecutionContext, )
| 1537 | } |
| 1538 | |
| 1539 | async function executeReverseReferenceLookupNode( |
| 1540 | nodeId: string, |
| 1541 | textValue: string, |
| 1542 | inputData: DBTablesNodeData, |
| 1543 | config?: unknown, |
| 1544 | executionContext?: FlowExecutionContext, |
| 1545 | ): Promise<NodeExecutionResult> { |
| 1546 | console.log(`Reverse Reference Lookup Node ${nodeId}: Processing with input tables:`, { |
| 1547 | tableCount: inputData?.tables?.length, |
| 1548 | tableNames: inputData?.tables?.map((t) => t.name), |
| 1549 | }); |
| 1550 | |
| 1551 | if (!inputData || inputData.type !== "TableSelection") { |
| 1552 | return { success: false, error: "Invalid input: Expected TableSelection data" }; |
| 1553 | } |
| 1554 | |
| 1555 | // Parse selected reverse table and includeBaseGame from textValue |
| 1556 | const parsed = getNodeConfig<{ selectedReverseTable?: string; includeBaseGame?: boolean }>(config, textValue); |
| 1557 | if (!parsed) { |
| 1558 | return { success: false, error: "Invalid node configuration" }; |
| 1559 | } |
| 1560 | let selectedReverseTable = parsed.selectedReverseTable || ""; |
| 1561 | const includeBaseGame = parsed.includeBaseGame !== false; |
| 1562 | |
| 1563 | // Build source files list, potentially including base game |
| 1564 | const sourceFiles = [...(inputData.sourceFiles || [])]; |
| 1565 | |
| 1566 | if (includeBaseGame) { |
| 1567 | const baseGamePackName = gameToPackWithDBTablesName[appData.currentGame]; |
| 1568 | if (baseGamePackName) { |
| 1569 | const baseGameFolder = appData.gamesToGameFolderPaths[appData.currentGame].dataFolder; |
| 1570 | if (baseGameFolder) { |
| 1571 | const baseGamePackPath = path.join(baseGameFolder, baseGamePackName); |
| 1572 | // Check if base game pack is not already in sourceFiles |
| 1573 | if (!sourceFiles.some((sf) => sf.path === baseGamePackPath)) { |
| 1574 | if (fs.existsSync(baseGamePackPath)) { |
| 1575 | sourceFiles.push({ |
| 1576 | name: baseGamePackName, |
| 1577 | path: baseGamePackPath, |
| 1578 | loaded: true, |
| 1579 | }); |
| 1580 | console.log( |
| 1581 | `Reverse Reference Lookup Node ${nodeId}: Added base game pack from ${baseGamePackPath}`, |
| 1582 | ); |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | // Get the input table name to find reverse references |
| 1590 | let inputTableName = ""; |
| 1591 | if (inputData.tables.length > 0) { |
| 1592 | inputTableName = inputData.tables[0].name.replace(/^db\\/, "").replace(/\\.*$/, ""); |
| 1593 | } |
| 1594 | |
| 1595 | // If no reverse table is selected, try to auto-select if there's only one option |
| 1596 | if ((!selectedReverseTable || selectedReverseTable.trim() === "") && inputTableName) { |
no test coverage detected