import { UseQueryOptions, useQuery } from '@tanstack/react-query' import { get, handleError } from 'data/fetchers' import { ResponseError } from 'types' import { replicationKeys } from './keys' type ReplicationSourcesParams = { projectRef?: string } async function fetchReplicationSources( { projectRef }: ReplicationSourcesParams, signal?: AbortSignal ) { if (!projectRef) throw new Error('projectRef is required') const { data, error } = await get('/platform/replication/{ref}/sources', { params: { path: { ref: projectRef } }, signal, }) if (error) { handleError(error) } return data } export type ReplicationSourcesData = Awaited> export const useReplicationSourcesQuery = ( { projectRef }: ReplicationSourcesParams, { enabled = true, ...options }: UseQueryOptions = {} ) => useQuery( replicationKeys.sources(projectRef), ({ signal }) => fetchReplicationSources({ projectRef }, signal), { enabled: enabled && typeof projectRef !== 'undefined', ...options } )