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

Function buildAutoMapping

apps/sim/lib/table/import.ts:367–398  ·  view source on GitHub ↗
(csvHeaders: string[], tableSchema: TableSchema)

Source from the content-addressed store, hash-verified

365 * comparison. Unmapped headers are set to `null`.
366 */
367export function buildAutoMapping(csvHeaders: string[], tableSchema: TableSchema): CsvHeaderMapping {
368 const mapping: CsvHeaderMapping = {}
369 const columns = tableSchema.columns
370
371 const exactByName = new Map(columns.map((c) => [c.name, c.name]))
372 const loose = new Map<string, string>()
373 for (const col of columns) {
374 loose.set(col.name.toLowerCase().replace(/[^a-z0-9]/g, ''), col.name)
375 }
376
377 const usedTargets = new Set<string>()
378
379 for (const header of csvHeaders) {
380 const sanitized = sanitizeName(header)
381 const exact = exactByName.get(sanitized)
382 if (exact && !usedTargets.has(exact)) {
383 mapping[header] = exact
384 usedTargets.add(exact)
385 continue
386 }
387 const key = header.toLowerCase().replace(/[^a-z0-9]/g, '')
388 const fuzzy = loose.get(key)
389 if (fuzzy && !usedTargets.has(fuzzy)) {
390 mapping[header] = fuzzy
391 usedTargets.add(fuzzy)
392 continue
393 }
394 mapping[header] = null
395 }
396
397 return mapping
398}
399
400/**
401 * Coerces parsed CSV rows into `RowData` objects keyed by the target column's

Callers 5

executeFunction · 0.90
resolveSetupFunction · 0.90
import.test.tsFile · 0.90
handleFileSelectedFunction · 0.90
route.tsFile · 0.90

Calls 5

sanitizeNameFunction · 0.70
setMethod · 0.65
replaceMethod · 0.65
getMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected