mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* Add custom types for queries, mutations and infinite queries. * Migrate all queries to use the new type. * Migrate all infinite queries to useCustomInfiniteQueryOptions. * Migrate all mutations to use useCustomMutationOptions. * Add type to all imports in `types` folder.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import type { operations } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { actionKeys } from './keys'
|
|
|
|
export type ActionRunVariables = operations['v1-get-action-run']['parameters']['path']
|
|
|
|
export async function getActionRun(params: ActionRunVariables, signal?: AbortSignal) {
|
|
const { data, error } = await get('/v1/projects/{ref}/actions/{run_id}', {
|
|
params: { path: params },
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ActionRunData = Awaited<ReturnType<typeof getActionRun>>
|
|
export type ActionRunError = ResponseError
|
|
|
|
export const useActionRunQuery = <TData = ActionRunData>(
|
|
{ ref, run_id }: ActionRunVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<ActionRunData, ActionRunError, TData> = {}
|
|
) =>
|
|
useQuery<ActionRunData, ActionRunError, TData>({
|
|
queryKey: actionKeys.detail(ref, run_id),
|
|
queryFn: ({ signal }) => getActionRun({ ref, run_id }, signal),
|
|
enabled: enabled && Boolean(ref) && Boolean(run_id),
|
|
staleTime: 0,
|
|
...options,
|
|
})
|