* Replaces a table's rows with wire rows keyed by column name. Translates the * keys to stable column ids (unknown keys are dropped, matching every other * name-translating boundary) and delegates to `replaceTableRows`, which owns * locking, validation, plan row limits, batching, and rowCount mai
( table: TableDefinition, rows: Array<Record<string, unknown>>, context: ExecutionContext )
| 26 | * locking, validation, plan row limits, batching, and rowCount maintenance. |
| 27 | */ |
| 28 | async function replaceTableRowsFromWire( |
| 29 | table: TableDefinition, |
| 30 | rows: Array<Record<string, unknown>>, |
| 31 | context: ExecutionContext |
| 32 | ): Promise<{ error?: string }> { |
| 33 | const idByName = buildIdByName(table.schema) |
| 34 | const idKeyedRows = rows.map((row) => rowDataNameToId(row as RowData, idByName)) |
| 35 | const emptyIndex = idKeyedRows.findIndex((row) => Object.keys(row).length === 0) |
| 36 | if (emptyIndex !== -1) { |
| 37 | return { |
| 38 | error: `Row ${emptyIndex + 1} has no keys matching columns on table "${table.name}" (columns: ${table.schema.columns.map((c) => c.name).join(', ')})`, |
| 39 | } |
| 40 | } |
| 41 | await replaceTableRows( |
| 42 | { |
| 43 | tableId: table.id, |
| 44 | rows: idKeyedRows, |
| 45 | workspaceId: table.workspaceId, |
| 46 | userId: context.userId, |
| 47 | }, |
| 48 | table, |
| 49 | generateId().slice(0, 8) |
| 50 | ) |
| 51 | return {} |
| 52 | } |
| 53 | |
| 54 | export async function maybeWriteOutputToTable( |
| 55 | toolName: string, |
no test coverage detected