mirror of
https://github.com/supabase/supabase.git
synced 2026-05-26 13:42:56 +08:00
* feat(docs): fetch conn string Add option to ProjectConfigVariables to fetch the Supavisor session mode connection string, for setting up MCP server * docs(mcp): reminder to replace password placeholder in connection string * fix: display helpful message if project paused --------- Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import type { ResponseError } from '~/types/fetch'
|
|
import { get } from './fetchWrappers'
|
|
import { type ReadonlyRecursive } from '~/types/utils'
|
|
|
|
const projectKeys = {
|
|
list: () => ['all-projects'] as const,
|
|
}
|
|
|
|
export async function getProjects(signal?: AbortSignal) {
|
|
const { data, error } = await get('/platform/projects', { signal })
|
|
if (error) throw error
|
|
return data
|
|
}
|
|
|
|
export type ProjectsData = Awaited<ReturnType<typeof getProjects>>
|
|
type ProjectsError = ResponseError
|
|
|
|
export function useProjectsQuery<TData = ProjectsData>({
|
|
enabled = true,
|
|
...options
|
|
}: Omit<UseQueryOptions<ProjectsData, ProjectsError, TData>, 'queryKey'> = {}) {
|
|
return useQuery<ProjectsData, ProjectsError, TData>({
|
|
queryKey: projectKeys.list(),
|
|
queryFn: ({ signal }) => getProjects(signal),
|
|
enabled,
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export function isProjectPaused(
|
|
project: ReadonlyRecursive<ProjectsData[number]> | null
|
|
): boolean | undefined {
|
|
return !project ? undefined : project.status === 'INACTIVE'
|
|
}
|