( nodeId: string, textValue: string, inputData: DBTablesNodeData, config?: unknown, )
| 3291 | } |
| 3292 | |
| 3293 | async function executeIndexTableNode( |
| 3294 | nodeId: string, |
| 3295 | textValue: string, |
| 3296 | inputData: DBTablesNodeData, |
| 3297 | config?: unknown, |
| 3298 | ): Promise<NodeExecutionResult> { |
| 3299 | console.log(`Index Table Node ${nodeId}: Processing ${inputData?.tables?.length || 0} table(s)`); |
| 3300 | |
| 3301 | if (!inputData || inputData.type !== "TableSelection") { |
| 3302 | return { success: false, error: "Invalid input: Expected TableSelection data" }; |
| 3303 | } |
| 3304 | |
| 3305 | // Parse index columns from textValue |
| 3306 | const parsed = getNodeConfig<{ indexColumns?: string[] }>(config, textValue); |
| 3307 | if (!parsed) { |
| 3308 | return { success: false, error: "Invalid index configuration" }; |
| 3309 | } |
| 3310 | const indexColumns = parsed.indexColumns || []; |
| 3311 | |
| 3312 | if (indexColumns.length === 0) { |
| 3313 | return { success: false, error: "No index columns specified" }; |
| 3314 | } |
| 3315 | |
| 3316 | console.log(`Index Table Node ${nodeId}: Indexing by columns: ${indexColumns.join(", ")}`); |
| 3317 | |
| 3318 | // Combine rows from all tables |
| 3319 | if (inputData.tables.length === 0) { |
| 3320 | return { success: false, error: "No tables in input data" }; |
| 3321 | } |
| 3322 | |
| 3323 | const allRows: AmendedSchemaField[][] = []; |
| 3324 | const sourceTable = inputData.tables[0]; // Keep first for metadata |
| 3325 | |
| 3326 | for (const table of inputData.tables) { |
| 3327 | if (!table.table.schemaFields || !table.table.tableSchema) { |
| 3328 | console.warn(`Index Table Node ${nodeId}: Skipping table without schema data`); |
| 3329 | continue; |
| 3330 | } |
| 3331 | |
| 3332 | const rows = getRowsForPackedFile(table.table); |
| 3333 | |
| 3334 | allRows.push(...rows); |
| 3335 | } |
| 3336 | |
| 3337 | const rows = allRows; |
| 3338 | console.log( |
| 3339 | `Index Table Node ${nodeId}: Indexing ${rows.length} rows from ${inputData.tables.length} pack file(s)`, |
| 3340 | ); |
| 3341 | |
| 3342 | // Build the index map |
| 3343 | const indexMap = new Map<string, any[]>(); |
| 3344 | |
| 3345 | for (const row of rows) { |
| 3346 | // Extract values for the index columns |
| 3347 | const keyParts: string[] = []; |
| 3348 | let allColumnsFound = true; |
| 3349 | |
| 3350 | for (const columnName of indexColumns) { |
no test coverage detected