MCPcopy Index your code
hub / github.com/simstudioai/sim / replaceTableRowsFromWire

Function replaceTableRowsFromWire

apps/sim/lib/copilot/request/tools/tables.ts:28–52  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

26 * locking, validation, plan row limits, batching, and rowCount maintenance.
27 */
28async 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
54export async function maybeWriteOutputToTable(
55 toolName: string,

Callers 2

maybeWriteOutputToTableFunction · 0.85
maybeWriteReadCsvToTableFunction · 0.85

Calls 5

buildIdByNameFunction · 0.90
rowDataNameToIdFunction · 0.90
replaceTableRowsFunction · 0.90
generateIdFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected