mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { components } from 'api-types'
|
|
|
|
import { edgeFunctionsKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type EdgeFunctionsVariables = { projectRef?: string }
|
|
|
|
export type EdgeFunctionsResponse = components['schemas']['FunctionResponse']
|
|
|
|
export async function getEdgeFunctions(
|
|
{ projectRef }: EdgeFunctionsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get(`/v1/projects/{ref}/functions`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type EdgeFunctionsData = Awaited<ReturnType<typeof getEdgeFunctions>>
|
|
export type EdgeFunctionsError = ResponseError
|
|
|
|
export const useEdgeFunctionsQuery = <TData = EdgeFunctionsData>(
|
|
{ projectRef }: EdgeFunctionsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<EdgeFunctionsData, EdgeFunctionsError, TData> = {}
|
|
) =>
|
|
useQuery<EdgeFunctionsData, EdgeFunctionsError, TData>({
|
|
queryKey: edgeFunctionsKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getEdgeFunctions({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|