mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 09:50:33 -04:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { replicationKeys } from './keys'
|
|
import { checkReplicationFeatureFlagRetry } from './utils'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
type ReplicationDestinationsParams = { projectRef?: string }
|
|
|
|
async function fetchReplicationDestinations(
|
|
{ projectRef }: ReplicationDestinationsParams,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/platform/replication/{ref}/destinations', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type ReplicationDestinationsData = Awaited<ReturnType<typeof fetchReplicationDestinations>>
|
|
|
|
export const useReplicationDestinationsQuery = <TData = ReplicationDestinationsData>(
|
|
{ projectRef }: ReplicationDestinationsParams,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationDestinationsData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationDestinationsData, ResponseError, TData>({
|
|
queryKey: replicationKeys.destinations(projectRef),
|
|
queryFn: ({ signal }) => fetchReplicationDestinations({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
refetchOnMount: false,
|
|
refetchOnWindowFocus: false,
|
|
retry: checkReplicationFeatureFlagRetry,
|
|
...options,
|
|
})
|