mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* ref(etl): Rename ETL Replication to Replication and update docs * Fix * Fix * Fix * Fix * Fix
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import type { components } from 'api-types'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { replicationKeys } from './keys'
|
|
|
|
type ReplicationDestinationByIdParams = { projectRef?: string; destinationId?: number }
|
|
|
|
async function fetchReplicationDestinationById(
|
|
{ projectRef, destinationId }: ReplicationDestinationByIdParams,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
if (!destinationId) throw new Error('destinationId is required')
|
|
const { data, error } = await get('/platform/replication/{ref}/destinations/{destination_id}', {
|
|
params: { path: { ref: projectRef, destination_id: destinationId } },
|
|
signal,
|
|
})
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type ReplicationDestinationByIdData = components['schemas']['ReplicationDestinationResponse']
|
|
|
|
export const useReplicationDestinationByIdQuery = <TData = ReplicationDestinationByIdData>(
|
|
{ projectRef, destinationId }: ReplicationDestinationByIdParams,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationDestinationByIdData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationDestinationByIdData, ResponseError, TData>({
|
|
queryKey: replicationKeys.destinationById(projectRef, destinationId),
|
|
queryFn: ({ signal }) => fetchReplicationDestinationById({ projectRef, destinationId }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof destinationId !== 'undefined',
|
|
...options,
|
|
})
|