mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { components } from 'api-types'
|
|
|
|
import { replicationKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
type ReplicationPipelineVersionParams = { projectRef?: string; pipelineId?: number }
|
|
type ReplicationPipelineVersionResponse =
|
|
components['schemas']['ReplicationPipelineVersionResponse']
|
|
|
|
export async function fetchReplicationPipelineVersion(
|
|
{ projectRef, pipelineId }: ReplicationPipelineVersionParams,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
if (!pipelineId) throw new Error('pipelineId is required')
|
|
|
|
const { data, error } = await get('/platform/replication/{ref}/pipelines/{pipeline_id}/version', {
|
|
params: { path: { ref: projectRef, pipeline_id: pipelineId } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type ReplicationPipelineVersionData = ReplicationPipelineVersionResponse
|
|
|
|
export const useReplicationPipelineVersionQuery = <TData = ReplicationPipelineVersionData>(
|
|
{ projectRef, pipelineId }: ReplicationPipelineVersionParams,
|
|
{
|
|
enabled = true,
|
|
staleTime = Infinity,
|
|
refetchOnMount = false,
|
|
refetchOnWindowFocus = false,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationPipelineVersionData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationPipelineVersionData, ResponseError, TData>({
|
|
queryKey: replicationKeys.pipelinesVersion(projectRef, pipelineId),
|
|
queryFn: ({ signal }) => fetchReplicationPipelineVersion({ projectRef, pipelineId }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof pipelineId !== 'undefined',
|
|
staleTime,
|
|
refetchOnMount,
|
|
refetchOnWindowFocus,
|
|
...options,
|
|
})
|