mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 03:15:06 +03:00
Follows the API team's flow: mint an upload slot, PUT a gzipped tar of the starter source to the presigned URL, then deploy with the context upload id.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { queryOptions } from '@tanstack/react-query'
|
|
|
|
import { workersKeys } from './keys'
|
|
import { parseWorker } from './workers.utils'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import type { ResponseError } from '@/types'
|
|
|
|
export type WorkersVariables = { projectRef?: string }
|
|
export type WorkersError = ResponseError
|
|
|
|
async function getWorkers({ projectRef }: WorkersVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/v2/projects/{ref}/workers', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) return handleError(error)
|
|
return data.data.map(parseWorker)
|
|
}
|
|
|
|
export type WorkersData = Awaited<ReturnType<typeof getWorkers>>
|
|
|
|
export const workersQueryOptions = ({ projectRef }: WorkersVariables) =>
|
|
queryOptions({
|
|
queryKey: workersKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getWorkers({ projectRef }, signal),
|
|
enabled: IS_PLATFORM && typeof projectRef !== 'undefined',
|
|
// Builds finish asynchronously, so keep polling until nothing is mid-build.
|
|
refetchInterval: (query) =>
|
|
query.state.data?.some((worker) => worker.buildState === 'building') ? 5_000 : false,
|
|
})
|