Files
supabase/apps/studio/data/edge-functions/edge-function-query.ts
T
Kalleby Santos 8c3655cd71 feat(studio-local): functions management api - function details (#42322)
Functions page on self-hosted differs from Platform Adds the possibility to see function details page in Self-Host version.

## Summary by CodeRabbit

* **New Features**
* Edge function detail lookup added for self‑hosted deployments (new
retrieval endpoint & store method).
  * Consistent navigation to function pages from the functions list.

* **Improvements**
  * UI tabs, download, and test controls adapt to deployment type.
* Region, JWT verification, local development, and delete controls shown
only on the platform.
* Edit/save/delete controls enable/disable correctly based on deployment
and permissions.
  * Function details load reliably across deployments.
2026-01-30 21:14:28 +00:00

47 lines
1.5 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 EdgeFunctionVariables = {
projectRef?: string
slug?: string
}
export type EdgeFunction = components['schemas']['FunctionSlugResponse']
export async function getEdgeFunction(
{ projectRef, slug }: EdgeFunctionVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
if (!slug) throw new Error('slug is required')
const { data, error } = await get(`/v1/projects/{ref}/functions/{function_slug}`, {
params: { path: { ref: projectRef, function_slug: slug } },
signal,
})
if (error) handleError(error)
return data
}
export type EdgeFunctionData = Awaited<ReturnType<typeof getEdgeFunction>>
export type EdgeFunctionError = ResponseError
export const useEdgeFunctionQuery = <TData = EdgeFunctionData>(
{ projectRef, slug }: EdgeFunctionVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<EdgeFunctionData, EdgeFunctionError, TData> = {}
) =>
useQuery<EdgeFunctionData, EdgeFunctionError, TData>({
queryKey: edgeFunctionsKeys.detail(projectRef, slug),
queryFn: ({ signal }) => getEdgeFunction({ projectRef, slug }, signal),
enabled: enabled && typeof projectRef !== 'undefined' && typeof slug !== 'undefined',
...options,
})