( tableId: string, rows: RowData[], table: TableDefinition, workspaceId: string, context?: ServerToolContext )
| 304 | } |
| 305 | |
| 306 | async function batchInsertAll( |
| 307 | tableId: string, |
| 308 | rows: RowData[], |
| 309 | table: TableDefinition, |
| 310 | workspaceId: string, |
| 311 | context?: ServerToolContext |
| 312 | ): Promise<number> { |
| 313 | let inserted = 0 |
| 314 | const userId = context?.userId |
| 315 | for (let i = 0; i < rows.length; i += MAX_BATCH_SIZE) { |
| 316 | assertServerToolNotAborted(context, 'Request aborted before table mutation could be applied.') |
| 317 | const batch = rows.slice(i, i + MAX_BATCH_SIZE) |
| 318 | const requestId = generateId().slice(0, 8) |
| 319 | const result = await batchInsertRows( |
| 320 | { tableId, rows: batch, workspaceId, userId }, |
| 321 | // Pass the running total so each batch's capacity check sees cumulative rows, |
| 322 | // not the same pre-loop snapshot (which would let a multi-batch insert overshoot). |
| 323 | { ...table, rowCount: table.rowCount + inserted }, |
| 324 | requestId |
| 325 | ) |
| 326 | inserted += result.length |
| 327 | } |
| 328 | return inserted |
| 329 | } |
| 330 | |
| 331 | export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult> = { |
| 332 | name: UserTable.id, |
no test coverage detected