mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 21:05:06 +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.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { workflowRunKeys } from './keys'
|
|
|
|
export type WorkflowRunLogsVariables = {
|
|
workflowRunId?: string
|
|
}
|
|
|
|
export async function getWorkflowRunLogs(
|
|
{ workflowRunId }: WorkflowRunLogsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!workflowRunId) throw new Error('workflowRunId is required')
|
|
|
|
const { data, error } = await get(`/platform/workflow-runs/{workflow_run_id}/logs`, {
|
|
params: {
|
|
path: {
|
|
workflow_run_id: workflowRunId,
|
|
},
|
|
},
|
|
parseAs: 'text',
|
|
headers: {
|
|
Accept: 'text/plain',
|
|
},
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
.split('\n')
|
|
.flatMap((line) => line.split('\r'))
|
|
.join('\n')
|
|
.trim()
|
|
}
|
|
|
|
export type WorkflowRunLogsData = Awaited<ReturnType<typeof getWorkflowRunLogs>>
|
|
export type WorkflowRunLogsError = ResponseError
|
|
|
|
export const useWorkflowRunLogsQuery = <TData = WorkflowRunLogsData>(
|
|
{ workflowRunId }: WorkflowRunLogsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<WorkflowRunLogsData, WorkflowRunLogsError, TData> = {}
|
|
) =>
|
|
useQuery<WorkflowRunLogsData, WorkflowRunLogsError, TData>({
|
|
queryKey: workflowRunKeys.list(workflowRunId),
|
|
queryFn: ({ signal }) => getWorkflowRunLogs({ workflowRunId }, signal),
|
|
enabled: enabled && typeof workflowRunId !== 'undefined',
|
|
staleTime: 0,
|
|
...options,
|
|
})
|