mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 12:14:26 +08:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
import { databaseKeys } from './keys'
|
|
|
|
export type PoolingConfigurationVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export type PoolingConfiguration = components['schemas']['SupavisorConfigResponse']
|
|
|
|
export async function getPoolingConfiguration(
|
|
{ projectRef }: PoolingConfigurationVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/projects/{ref}/config/supavisor`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type PoolingConfigurationData = Awaited<ReturnType<typeof getPoolingConfiguration>>
|
|
export type PoolingConfigurationError = ResponseError
|
|
|
|
export const usePoolingConfigurationQuery = <TData = PoolingConfigurationData>(
|
|
{ projectRef }: PoolingConfigurationVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<PoolingConfigurationData, PoolingConfigurationError, TData> = {}
|
|
) =>
|
|
useQuery<PoolingConfigurationData, PoolingConfigurationError, TData>(
|
|
databaseKeys.poolingConfiguration(projectRef),
|
|
({ signal }) => getPoolingConfiguration({ projectRef }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|