mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 13:59:37 +08:00
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get } from 'data/fetchers'
|
|
import { analyticsKeys } from './keys'
|
|
import type { ResponseError } from 'types'
|
|
|
|
export type ProjectLogRequestsCountVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export async function getProjectLogRequestsCountStats(
|
|
{ projectRef }: ProjectLogRequestsCountVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) {
|
|
throw new Error('projectRef is required')
|
|
}
|
|
|
|
const { data, error } = await get(
|
|
'/platform/projects/{ref}/analytics/endpoints/usage.api-requests-count',
|
|
{
|
|
params: {
|
|
path: {
|
|
ref: projectRef,
|
|
},
|
|
},
|
|
signal,
|
|
}
|
|
)
|
|
|
|
if (error) {
|
|
throw error
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
export type ProjectLogRequestsCountData = Awaited<
|
|
ReturnType<typeof getProjectLogRequestsCountStats>
|
|
>
|
|
export type ProjectLogRequestsCountError = ResponseError
|
|
|
|
export const useProjectLogRequestsCountQuery = <TData = ProjectLogRequestsCountData>(
|
|
{ projectRef }: ProjectLogRequestsCountVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData> = {}
|
|
) =>
|
|
useQuery<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData>(
|
|
analyticsKeys.usageApiRequestsCount(projectRef),
|
|
({ signal }) => getProjectLogRequestsCountStats({ projectRef }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|