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

Function applyColumnOrderToSchema

apps/sim/lib/table/service.ts:88–107  ·  view source on GitHub ↗

* Returns `schema` with `columns` sorted by `metadata.columnOrder` (the user- * editable visible order). Columns missing from `columnOrder` are appended at * the end in their original (schema-creation) order — covers tables created * before `columnOrder` existed and any drift from out-of-band col

(
  schema: TableSchema,
  metadata: TableMetadata | null
)

Source from the content-addressed store, hash-verified

86 * consumer (grid, sidebar, copilot, mothership) gets the same ordered list.
87 */
88function applyColumnOrderToSchema(
89 schema: TableSchema,
90 metadata: TableMetadata | null
91): TableSchema {
92 const order = metadata?.columnOrder
93 if (!order || order.length === 0) return schema
94 // `columnOrder` holds stable column ids (legacy entries equal the name == id).
95 const byId = new Map<string, TableSchema['columns'][number]>()
96 for (const c of schema.columns) byId.set(getColumnId(c), c)
97 const ordered: TableSchema['columns'] = []
98 for (const id of order) {
99 const c = byId.get(id)
100 if (c) {
101 ordered.push(c)
102 byId.delete(id)
103 }
104 }
105 for (const c of byId.values()) ordered.push(c)
106 return { ...schema, columns: ordered }
107}
108
109/**
110 * Gets a table by ID with full details.

Callers 2

getTableByIdFunction · 0.85
listTablesFunction · 0.85

Calls 5

getColumnIdFunction · 0.90
setMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected