Files
supabase/apps/studio/data/replication/sources-query.ts
T
Alaister YoungandJoshen Lim 8855d05803 chore(studio): swap react-query to object syntax (#39842)
* chore(studio): swap react-query to object syntax

* Fix small issues found

* Fix realtime settings

* Nit

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-10-27 09:38:27 +01:00

38 lines
1.2 KiB
TypeScript

import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
import { replicationKeys } from './keys'
type ReplicationSourcesParams = { projectRef?: string }
async function fetchReplicationSources(
{ projectRef }: ReplicationSourcesParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/replication/{ref}/sources', {
params: { path: { ref: projectRef } },
signal,
})
if (error) {
handleError(error)
}
return data
}
export type ReplicationSourcesData = Awaited<ReturnType<typeof fetchReplicationSources>>
export const useReplicationSourcesQuery = <TData = ReplicationSourcesData>(
{ projectRef }: ReplicationSourcesParams,
{ enabled = true, ...options }: UseQueryOptions<ReplicationSourcesData, ResponseError, TData> = {}
) =>
useQuery<ReplicationSourcesData, ResponseError, TData>({
queryKey: replicationKeys.sources(projectRef),
queryFn: ({ signal }) => fetchReplicationSources({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})