mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
54 lines
1.9 KiB
TypeScript
54 lines
1.9 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 ReplicationPipelineReplicationStatusParams = { projectRef?: string; pipelineId?: number }
|
|
|
|
export type ReplicationPipelineTableStatus =
|
|
components['schemas']['ReplicationPipelineReplicationStatusResponse']['table_statuses'][number]
|
|
|
|
async function fetchReplicationPipelineReplicationStatus(
|
|
{ projectRef, pipelineId }: ReplicationPipelineReplicationStatusParams,
|
|
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}/replication-status',
|
|
{
|
|
params: { path: { ref: projectRef, pipeline_id: pipelineId } },
|
|
signal,
|
|
}
|
|
)
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type ReplicationPipelineReplicationStatusData = Awaited<
|
|
ReturnType<typeof fetchReplicationPipelineReplicationStatus>
|
|
>
|
|
|
|
export const useReplicationPipelineReplicationStatusQuery = <
|
|
TData = ReplicationPipelineReplicationStatusData,
|
|
>(
|
|
{ projectRef, pipelineId }: ReplicationPipelineReplicationStatusParams,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationPipelineReplicationStatusData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationPipelineReplicationStatusData, ResponseError, TData>({
|
|
queryKey: replicationKeys.pipelinesReplicationStatus(projectRef, pipelineId),
|
|
queryFn: ({ signal }) =>
|
|
fetchReplicationPipelineReplicationStatus({ projectRef, pipelineId }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof pipelineId !== 'undefined',
|
|
...options,
|
|
})
|