Files
supabase/apps/studio/data/replication/pipeline-replication-status-query.ts
Charis df742bdb3b refactor(studio): rename ResponseError to StudioError (#52707)
## What

Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.

## Why

Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.

## Notes for reviewers

- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
2026-11-03 11:09:30 -05:00

86 lines
2.8 KiB
TypeScript

import { queryOptions, useQuery } from '@tanstack/react-query'
import { components } from 'api-types'
import { replicationKeys } from './keys'
import { pipelineIdSchema } from './pipeline-id'
import { replicationPollingOptions } from './polling'
import { get, handleError } from '@/data/fetchers'
import type { StudioError } from '@/lib/errors/studio-errors'
import type { UseCustomQueryOptions } from '@/types'
export type ReplicationPipelineReplicationStatusVariables = {
projectRef?: string
pipelineId?: string
}
export type ReplicationPipelineReplicationStatusError = StudioError
export type ReplicationPipelineTableStatus =
components['schemas']['PipelineReplicationStatusResponse_Output']['table_statuses'][number]
async function fetchReplicationPipelineReplicationStatus(
{ projectRef, pipelineId }: ReplicationPipelineReplicationStatusVariables,
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, pipeline_id: pipelineIdSchema.parse(data.pipeline_id) }
}
export type ReplicationPipelineReplicationStatusData = Awaited<
ReturnType<typeof fetchReplicationPipelineReplicationStatus>
>
export const replicationPipelineReplicationStatusQueryOptions = <
TData = ReplicationPipelineReplicationStatusData,
>({
projectRef,
pipelineId,
}: ReplicationPipelineReplicationStatusVariables) =>
queryOptions<
ReplicationPipelineReplicationStatusData,
ReplicationPipelineReplicationStatusError,
TData
>({
queryKey: replicationKeys.pipelinesReplicationStatus(projectRef, pipelineId),
queryFn: ({ signal }) =>
fetchReplicationPipelineReplicationStatus({ projectRef, pipelineId }, signal),
...replicationPollingOptions,
enabled: typeof projectRef !== 'undefined' && typeof pipelineId !== 'undefined',
})
export const useReplicationPipelineReplicationStatusQuery = <
TData = ReplicationPipelineReplicationStatusData,
>(
variables: ReplicationPipelineReplicationStatusVariables,
options: UseCustomQueryOptions<
ReplicationPipelineReplicationStatusData,
ReplicationPipelineReplicationStatusError,
TData
> = {}
) =>
useQuery<
ReplicationPipelineReplicationStatusData,
ReplicationPipelineReplicationStatusError,
TData
>({
...replicationPipelineReplicationStatusQueryOptions<TData>(variables),
...options,
enabled:
options.enabled !== false &&
typeof variables.projectRef !== 'undefined' &&
typeof variables.pipelineId !== 'undefined',
})