ruvector/studio/data/analytics/project-log-stats-query.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
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>
2025-12-06 23:04:48 +00:00

79 lines
2.2 KiB
TypeScript

import { QueryClient, useQuery } from '@tanstack/react-query'
import { operations } from 'api-types'
import { get, handleError } from 'data/fetchers'
import { analyticsKeys } from './keys'
import { UseCustomQueryOptions } from 'types'
export type ProjectLogStatsVariables = {
projectRef?: string
interval?: NonNullable<
operations['UsageApiController_getApiCounts']['parameters']['query']
>['interval']
}
export type ProjectLogStatsResponse = {
result: UsageApiCounts[]
}
export interface UsageApiCounts {
total_auth_requests: number
total_storage_requests: number
total_rest_requests: number
total_realtime_requests: number
timestamp: string
}
export async function getProjectLogStats(
{ projectRef, interval }: ProjectLogStatsVariables,
signal?: AbortSignal
) {
if (!projectRef) {
throw new Error('projectRef is required')
}
if (!interval) {
throw new Error('interval is required')
}
const { data, error } = await get(
'/platform/projects/{ref}/analytics/endpoints/usage.api-counts',
{
params: {
path: { ref: projectRef },
query: {
interval,
},
},
signal,
}
)
if (error) handleError(error)
return data as unknown as ProjectLogStatsResponse
}
export type ProjectLogStatsData = Awaited<ReturnType<typeof getProjectLogStats>>
export type ProjectLogStatsError = unknown
export const useProjectLogStatsQuery = <TData = ProjectLogStatsData>(
{ projectRef, interval }: ProjectLogStatsVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<ProjectLogStatsData, ProjectLogStatsError, TData> = {}
) =>
useQuery<ProjectLogStatsData, ProjectLogStatsError, TData>({
queryKey: analyticsKeys.usageApiCounts(projectRef, interval),
queryFn: ({ signal }) => getProjectLogStats({ projectRef, interval }, signal),
enabled: enabled && typeof projectRef !== 'undefined' && typeof interval !== 'undefined',
...options,
})
export function prefetchProjectLogStats(
client: QueryClient,
{ projectRef, interval }: ProjectLogStatsVariables
) {
return client.fetchQuery({
queryKey: analyticsKeys.usageApiCounts(projectRef, interval),
queryFn: ({ signal }) => getProjectLogStats({ projectRef, interval }, signal),
})
}