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

Function withGeneratedColumnIds

apps/sim/lib/table/column-keys.ts:61–91  ·  view source on GitHub ↗
(schema: TableSchema)

Source from the content-addressed store, hash-verified

59 * already carry an id.
60 */
61export function withGeneratedColumnIds(schema: TableSchema): TableSchema {
62 const idByName = new Map<string, string>()
63 const columns = schema.columns.map((col) => {
64 if (col.id) {
65 idByName.set(col.name, col.id)
66 return col
67 }
68 const id = generateColumnId()
69 idByName.set(col.name, id)
70 return { ...col, id }
71 })
72
73 const remap = (ref: string) => idByName.get(ref) ?? ref
74 const workflowGroups = schema.workflowGroups?.map((group) => ({
75 ...group,
76 outputs: group.outputs.map((o) => ({ ...o, columnName: remap(o.columnName) })),
77 ...(group.dependencies?.columns
78 ? { dependencies: { columns: group.dependencies.columns.map(remap) } }
79 : {}),
80 ...(group.inputMappings
81 ? {
82 inputMappings: group.inputMappings.map((m) => ({
83 ...m,
84 columnName: remap(m.columnName),
85 })),
86 }
87 : {}),
88 }))
89
90 return { ...schema, columns, ...(workflowGroups ? { workflowGroups } : {}) }
91}
92
93/**
94 * Rewrites a workflow group's column references (output `columnName`,

Callers 3

resolveSetupFunction · 0.90
createTableFunction · 0.90

Calls 3

generateColumnIdFunction · 0.85
remapFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected