mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-29 19:33:34 +00:00
Major additions: - Complete Next.js studio application with 1600+ components - Docker support (Dockerfile.combined, docker-compose.yml) - GCP deployment documentation and benchmarks - SQL benchmark scripts for performance testing - Sentry integration for monitoring - Comprehensive test suite and mocks Studio features: - Dashboard and admin interfaces - Data visualization components - Authentication and user management - API integration with RuVector backend - Static data and public assets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { getMultipartBoundary, parseMultipartStream } from '@mjackson/multipart-parser'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { EdgeFunctionFile } from 'components/interfaces/EdgeFunctions/EdgeFunction.types'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { edgeFunctionsKeys } from './keys'
|
|
|
|
type EdgeFunctionBodyVariables = {
|
|
projectRef?: string
|
|
slug?: string
|
|
}
|
|
|
|
export async function getEdgeFunctionBody(
|
|
{ projectRef, slug }: EdgeFunctionBodyVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
if (!slug) throw new Error('slug is required')
|
|
|
|
const { data, response, error } = await get('/v1/projects/{ref}/functions/{function_slug}/body', {
|
|
params: { path: { ref: projectRef, function_slug: slug } },
|
|
headers: { Accept: 'multipart/form-data' },
|
|
parseAs: 'stream',
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
|
|
const contentTypeHeader = response.headers.get('content-type') ?? ''
|
|
const boundary = getMultipartBoundary(contentTypeHeader)
|
|
const files = []
|
|
|
|
if (!data || !boundary) return { files: [] }
|
|
|
|
for await (let part of parseMultipartStream(data, {
|
|
boundary,
|
|
maxFileSize: 20 * 1024 * 1024,
|
|
})) {
|
|
if (part.isFile) {
|
|
files.push({
|
|
name: part.filename,
|
|
content: part.text,
|
|
})
|
|
}
|
|
}
|
|
|
|
return { files: files as Omit<EdgeFunctionFile, 'id' | 'selected'>[] }
|
|
}
|
|
|
|
export type EdgeFunctionBodyData = Awaited<ReturnType<typeof getEdgeFunctionBody>>
|
|
export type EdgeFunctionBodyError = ResponseError
|
|
|
|
export const useEdgeFunctionBodyQuery = <TData = EdgeFunctionBodyData>(
|
|
{ projectRef, slug }: EdgeFunctionBodyVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<EdgeFunctionBodyData, EdgeFunctionBodyError, TData> = {}
|
|
) =>
|
|
useQuery<EdgeFunctionBodyData, EdgeFunctionBodyError, TData>({
|
|
queryKey: edgeFunctionsKeys.body(projectRef, slug),
|
|
queryFn: ({ signal }) => getEdgeFunctionBody({ projectRef, slug }, signal),
|
|
enabled:
|
|
IS_PLATFORM && enabled && typeof projectRef !== 'undefined' && typeof slug !== 'undefined',
|
|
...options,
|
|
})
|