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

Function coerceRowsForTable

apps/sim/lib/table/import.ts:407–426  ·  view source on GitHub ↗
(
  rows: Record<string, unknown>[],
  tableSchema: TableSchema,
  headerToColumn: Map<string, string>
)

Source from the content-addressed store, hash-verified

405 * acceptable). Pass the schema returned by `createTable` so ids are resolved.
406 */
407export function coerceRowsForTable(
408 rows: Record<string, unknown>[],
409 tableSchema: TableSchema,
410 headerToColumn: Map<string, string>
411): RowData[] {
412 const colByName = new Map(tableSchema.columns.map((c) => [c.name, c]))
413
414 return rows.map((row) => {
415 const coerced: RowData = {}
416 for (const [header, value] of Object.entries(row)) {
417 const colName = headerToColumn.get(header)
418 if (!colName) continue
419 const col = colByName.get(colName)
420 if (!col) continue
421 const colType = (col.type as CsvColumnType) ?? 'string'
422 coerced[getColumnId(col)] = coerceValue(value, colType) as RowData[string]
423 }
424 return coerced
425 })
426}
427
428/**
429 * Sanitizes raw JSON keys so they conform to the same column-name rules as CSV

Callers 5

executeFunction · 0.90
flushFunction · 0.90
import.test.tsFile · 0.90
route.tsFile · 0.90
insertRowsFunction · 0.90

Calls 3

getColumnIdFunction · 0.90
coerceValueFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected