Files
supabase/apps/studio/data/replication/tables-query.ts
T
Joshen Lim 64e3e047eb Final final cleaning up barrel files (#40018)
* Final final cleaning up barrel files

* Fix merge conflict
2025-10-31 14:02:59 +08:00

39 lines
1.4 KiB
TypeScript

import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { replicationKeys } from './keys'
type ReplicationTablesParams = { projectRef?: string; sourceId?: number }
async function fetchReplicationTables(
{ projectRef, sourceId }: ReplicationTablesParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
if (!sourceId) throw new Error('sourceId is required')
const { data, error } = await get('/platform/replication/{ref}/sources/{source_id}/tables', {
params: { path: { ref: projectRef, source_id: sourceId } },
signal,
})
if (error) {
handleError(error)
}
return data
}
export type ReplicationTablesData = Awaited<ReturnType<typeof fetchReplicationTables>>
export const useReplicationTablesQuery = <TData = ReplicationTablesData>(
{ projectRef, sourceId }: ReplicationTablesParams,
{ enabled = true, ...options }: UseQueryOptions<ReplicationTablesData, ResponseError, TData> = {}
) =>
useQuery<ReplicationTablesData, ResponseError, TData>({
queryKey: replicationKeys.tables(projectRef, sourceId),
queryFn: ({ signal }) => fetchReplicationTables({ projectRef, sourceId }, signal),
enabled: enabled && typeof projectRef !== 'undefined' && typeof sourceId !== 'undefined',
...options,
})