MCPcopy
hub / github.com/simstudioai/sim / fetchTableColumns

Function fetchTableColumns

apps/sim/triggers/table/poller.ts:11–36  ·  view source on GitHub ↗
(blockId: string)

Source from the content-addressed store, hash-verified

9import type { TriggerConfig } from '@/triggers/types'
10
11async function fetchTableColumns(blockId: string): Promise<Array<{ label: string; id: string }>> {
12 const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
13 const workspaceId = useWorkflowRegistry.getState().hydration.workspaceId
14 if (!activeWorkflowId || !workspaceId) return []
15
16 const blockValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]?.[blockId]
17 const tableId = (blockValues?.tableSelector as string) || (blockValues?.manualTableId as string)
18 if (!tableId) return []
19
20 const tables = await getQueryClient().fetchQuery({
21 queryKey: tableKeys.list(workspaceId),
22 queryFn: async ({ signal }): Promise<TableDefinition[]> => {
23 const response = await requestJson(listTablesContract, {
24 query: { workspaceId, scope: 'active' },
25 signal,
26 })
27 return (response.data.tables ?? []) as TableDefinition[]
28 },
29 staleTime: 60 * 1000,
30 })
31
32 const table = tables.find((t: TableDefinition) => t.id === tableId)
33 if (!table?.schema?.columns) return []
34
35 return table.schema.columns.map((col) => ({ id: col.name, label: col.name }))
36}
37
38export const tableNewRowTrigger: TriggerConfig = {
39 id: 'table_new_row',

Callers

nothing calls this directly

Calls 2

getQueryClientFunction · 0.90
requestJsonFunction · 0.90

Tested by

no test coverage detected