( nodeId: string, textValue: string, inputData: DumpToTSVNodeData | DBNumericAdjustmentNodeData, config?: unknown, executionContext?: FlowExecutionContext, )
| 5757 | } |
| 5758 | |
| 5759 | async function executeDumpToTSVNode( |
| 5760 | nodeId: string, |
| 5761 | textValue: string, |
| 5762 | inputData: DumpToTSVNodeData | DBNumericAdjustmentNodeData, |
| 5763 | config?: unknown, |
| 5764 | executionContext?: FlowExecutionContext, |
| 5765 | ): Promise<NodeExecutionResult> { |
| 5766 | console.log(`Dump to TSV Node ${nodeId}: Processing with input type: ${inputData?.type}`); |
| 5767 | |
| 5768 | if (!inputData || (inputData.type !== "TableSelection" && inputData.type !== "ChangedColumnSelection")) { |
| 5769 | return { success: false, error: "Invalid input: Expected TableSelection or ChangedColumnSelection data" }; |
| 5770 | } |
| 5771 | |
| 5772 | // Handle ChangedColumnSelection input - convert to a format we can dump |
| 5773 | if (inputData.type === "ChangedColumnSelection") { |
| 5774 | const changedData = inputData as DBNumericAdjustmentNodeData; |
| 5775 | const adjustedInputData = changedData.adjustedInputData; |
| 5776 | |
| 5777 | // adjustedInputData has structure: { type, columns: [{tableName, fileName, sourcePack, sourceTable, selectedColumns, data}] } |
| 5778 | // where data is array of {col, data} - each entry is one value for one row |
| 5779 | if (!adjustedInputData?.columns || adjustedInputData.columns.length === 0) { |
| 5780 | console.log(`Dump to TSV Node ${nodeId}: No columns to dump - skipping file write`); |
| 5781 | return { |
| 5782 | success: true, |
| 5783 | data: changedData, // Pass through the input |
| 5784 | }; |
| 5785 | } |
| 5786 | |
| 5787 | console.log( |
| 5788 | `Dump to TSV Node ${nodeId}: Processing ChangedColumnSelection with ${adjustedInputData.columns.length} table entries`, |
| 5789 | ); |
| 5790 | |
| 5791 | // Build TSV from ChangedColumnSelection |
| 5792 | const tsvLines: string[] = []; |
| 5793 | |
| 5794 | // Process each table entry in the columns array |
| 5795 | for (const tableEntry of adjustedInputData.columns) { |
| 5796 | const tableName = tableEntry.tableName || "unknown"; |
| 5797 | const fileName = tableEntry.fileName || ""; |
| 5798 | const columnNames = tableEntry.selectedColumns || []; |
| 5799 | const data = tableEntry.data || []; |
| 5800 | |
| 5801 | console.log( |
| 5802 | `Dump to TSV Node ${nodeId}: Table "${tableName}" has ${columnNames.length} columns and ${data.length} data entries`, |
| 5803 | ); |
| 5804 | |
| 5805 | // Header: table name, file name, then column names |
| 5806 | if (tsvLines.length === 0 && columnNames.length > 0) { |
| 5807 | const headerCols = ["_table", "_file", ...columnNames]; |
| 5808 | tsvLines.push(headerCols.join("\t")); |
| 5809 | } |
| 5810 | |
| 5811 | // data is an array where each entry is {col: columnName, data: value} |
| 5812 | // For single column selection, each entry is one row |
| 5813 | // For multiple columns, entries are interleaved: row1col1, row1col2, row2col1, row2col2, etc. |
| 5814 | const numCols = columnNames.length || 1; |
| 5815 | const numRows = Math.floor(data.length / numCols); |
| 5816 |
no test coverage detected