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

Function snapshotAndMutateRows

apps/sim/hooks/queries/tables.ts:1897–1948  ·  view source on GitHub ↗
(
  queryClient: ReturnType<typeof useQueryClient>,
  tableId: string,
  transform: (row: TableRow) => TableRow | null,
  options?: {
    cancelInFlight?: boolean
    /** Restrict the walk to one exact cached query (e.g. the active filtered
     *  view) when the mutation's server effect doesn't cover other views. */
    onlyKey?: readonly unknown[]
  }
)

Source from the content-addressed store, hash-verified

1895 * list of [queryKey, prior data] entries so optimistic-update callers can
1896 * roll back. SSE patchers can ignore the return value. */
1897export async function snapshotAndMutateRows(
1898 queryClient: ReturnType<typeof useQueryClient>,
1899 tableId: string,
1900 transform: (row: TableRow) => TableRow | null,
1901 options?: {
1902 cancelInFlight?: boolean
1903 /** Restrict the walk to one exact cached query (e.g. the active filtered
1904 * view) when the mutation's server effect doesn't cover other views. */
1905 onlyKey?: readonly unknown[]
1906 }
1907): Promise<RowsCacheSnapshots> {
1908 const scope = options?.onlyKey
1909 ? ({ queryKey: options.onlyKey, exact: true } as const)
1910 : ({ queryKey: tableKeys.rowsRoot(tableId) } as const)
1911 if (options?.cancelInFlight !== false) {
1912 await queryClient.cancelQueries(scope)
1913 }
1914 const matching = queryClient.getQueriesData<RowsCacheEntry>(scope)
1915 const snapshots: RowsCacheSnapshots = []
1916 for (const [key, data] of matching) {
1917 if (!data) continue
1918 if (isInfiniteRowsCache(data)) {
1919 let touched = false
1920 const nextPages = data.pages.map((page) => {
1921 let pageTouched = false
1922 const nextRows = page.rows.map((r) => {
1923 const next = transform(r)
1924 if (!next) return r
1925 pageTouched = true
1926 touched = true
1927 return next
1928 })
1929 return pageTouched ? { ...page, rows: nextRows } : page
1930 })
1931 if (!touched) continue
1932 snapshots.push([key, data])
1933 queryClient.setQueryData<InfiniteRowsCache>(key, { ...data, pages: nextPages })
1934 continue
1935 }
1936 let touched = false
1937 const nextRows = data.rows.map((r) => {
1938 const next = transform(r)
1939 if (!next) return r
1940 touched = true
1941 return next
1942 })
1943 if (!touched) continue
1944 snapshots.push([key, data])
1945 queryClient.setQueryData<TableRowsResponse>(key, { ...data, rows: nextRows })
1946 }
1947 return snapshots
1948}
1949
1950export function restoreCachedWorkflowCells(
1951 queryClient: ReturnType<typeof useQueryClient>,

Callers 4

applyCellFunction · 0.90
useCancelTableRunsFunction · 0.85
useDeleteColumnFunction · 0.85
useRunColumnFunction · 0.85

Calls 3

isInfiniteRowsCacheFunction · 0.85
transformFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected