mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 19:16:04 +08: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.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 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 ActionsVariables = operations['v1-list-action-runs']['parameters']['path']
|
|
|
|
export async function listActionRuns(params: ActionsVariables, signal?: AbortSignal) {
|
|
const { data, error } = await get(`/v1/projects/{ref}/actions`, {
|
|
params: { path: params },
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ActionsData = Awaited<ReturnType<typeof listActionRuns>>
|
|
export type ActionsError = ResponseError
|
|
|
|
export type ActionRunStep = ActionsData[number]['run_steps'][number]
|
|
export type ActionName = ActionRunStep['name']
|
|
export type ActionStatus = ActionRunStep['status']
|
|
|
|
export const useActionsQuery = <TData = ActionsData>(
|
|
{ ref }: ActionsVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<ActionsData, ActionsError, TData> = {}
|
|
) =>
|
|
useQuery<ActionsData, ActionsError, TData>({
|
|
queryKey: actionKeys.list(ref),
|
|
queryFn: ({ signal }) => listActionRuns({ ref }, signal),
|
|
enabled: enabled && Boolean(ref),
|
|
staleTime: 0,
|
|
...options,
|
|
})
|