Files
supabase/apps/studio/data/edge-functions/edge-functions-query.ts
T
1862b71745 feat(studio-local): functions management api - list functions (#40690)
## What is the current behaviour?

Functions page on self-hosted differs from Platform

## What is the new behaviour?

Adds the possibility to see a list of edge-functions in Self-Host
version.

## Summary by CodeRabbit

* **New Features**
* Added self-hosted edge functions support with filesystem-based
artifact listing and a new API endpoint to list local functions.
* Improved functions UI: unified view, enhanced search and adjacent sort
controls, and clearer local-hosting guidance.

* **Chores**
* Added environment configuration and docker volume for edge functions
management.
* Updated build/task config to pass through edge functions env and
include contentlayer outputs.

Co-authored-by: Ali Waseem <waseema393@gmail.com>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
Co-authored-by: Terry Sutton <saltcod@gmail.com>
2026-01-30 08:00:21 +08:00

43 lines
1.4 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { components } from 'api-types'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { edgeFunctionsKeys } from './keys'
export type EdgeFunctionsVariables = { projectRef?: string }
export type EdgeFunctionsResponse = components['schemas']['FunctionResponse']
export async function getEdgeFunctions(
{ projectRef }: EdgeFunctionsVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get(`/v1/projects/{ref}/functions`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type EdgeFunctionsData = Awaited<ReturnType<typeof getEdgeFunctions>>
export type EdgeFunctionsError = ResponseError
export const useEdgeFunctionsQuery = <TData = EdgeFunctionsData>(
{ projectRef }: EdgeFunctionsVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<EdgeFunctionsData, EdgeFunctionsError, TData> = {}
) =>
useQuery<EdgeFunctionsData, EdgeFunctionsError, TData>({
queryKey: edgeFunctionsKeys.list(projectRef),
queryFn: ({ signal }) => getEdgeFunctions({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})