( trx: DbOrTx, rowIds: Iterable<string> )
| 24 | * `Map<rowId, RowExecutions>` suitable for plugging into `TableRow.executions`. |
| 25 | */ |
| 26 | export async function loadExecutionsByRow( |
| 27 | trx: DbOrTx, |
| 28 | rowIds: Iterable<string> |
| 29 | ): Promise<Map<string, RowExecutions>> { |
| 30 | const ids = Array.from(new Set(rowIds)) |
| 31 | const result = new Map<string, RowExecutions>() |
| 32 | if (ids.length === 0) return result |
| 33 | // Explicit column list, never `select()` — `enrichmentDetails` is large and |
| 34 | // must stay off the hot grid read path (fetched on demand via |
| 35 | // `loadEnrichmentDetail`). |
| 36 | const rows = await trx |
| 37 | .select({ |
| 38 | rowId: tableRowExecutions.rowId, |
| 39 | groupId: tableRowExecutions.groupId, |
| 40 | status: tableRowExecutions.status, |
| 41 | executionId: tableRowExecutions.executionId, |
| 42 | jobId: tableRowExecutions.jobId, |
| 43 | workflowId: tableRowExecutions.workflowId, |
| 44 | error: tableRowExecutions.error, |
| 45 | runningBlockIds: tableRowExecutions.runningBlockIds, |
| 46 | blockErrors: tableRowExecutions.blockErrors, |
| 47 | cancelledAt: tableRowExecutions.cancelledAt, |
| 48 | }) |
| 49 | .from(tableRowExecutions) |
| 50 | .where(inArray(tableRowExecutions.rowId, ids)) |
| 51 | for (const r of rows) { |
| 52 | const existing = result.get(r.rowId) ?? {} |
| 53 | const meta: RowExecutionMetadata = { |
| 54 | status: r.status as RowExecutionMetadata['status'], |
| 55 | executionId: r.executionId ?? null, |
| 56 | jobId: r.jobId ?? null, |
| 57 | workflowId: r.workflowId, |
| 58 | error: r.error ?? null, |
| 59 | ...(r.runningBlockIds && r.runningBlockIds.length > 0 |
| 60 | ? { runningBlockIds: r.runningBlockIds } |
| 61 | : {}), |
| 62 | ...(r.blockErrors && Object.keys(r.blockErrors as Record<string, string>).length > 0 |
| 63 | ? { blockErrors: r.blockErrors as Record<string, string> } |
| 64 | : {}), |
| 65 | ...(r.cancelledAt ? { cancelledAt: r.cancelledAt.toISOString() } : {}), |
| 66 | } |
| 67 | existing[r.groupId] = meta |
| 68 | result.set(r.rowId, existing) |
| 69 | } |
| 70 | return result |
| 71 | } |
| 72 | |
| 73 | /** Convenience: load executions for one row, returning `{}` when missing. */ |
| 74 | export async function loadExecutionsForRow(trx: DbOrTx, rowId: string): Promise<RowExecutions> { |
no test coverage detected