import { dashboardApi } from './dashboard-api' export interface DashboardQueryLog { id: number | string query: string normalizedQuery: string type: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'OTHER' duration: number connection: string status: 'completed' | 'failed' | 'slow' error: string executedAt: string model: string method: string rowsAffected: number | null memoryUsage: number | null tags: string[] affectedTables: string[] indexesUsed: string[] missingIndexes: string[] suggestions: string[] } export interface DashboardQueryCounts { total: number reads: number writes: number slow: number failed: number averageDuration: number } /** One page of the query log, chosen by the server (stacksjs/stacks#3204). */ export interface DashboardQueryResponse { enabled: boolean slowThreshold: number queries: DashboardQueryLog[] total: number page: number perPage: number counts: DashboardQueryCounts connections: string[] error?: string } export interface DashboardQueryFilters { range: 'hour' | 'day' | 'week' status: DashboardQueryLog['status'] | 'all' type: DashboardQueryLog['type'] | 'all' connection: string page: number perPage: number } export interface DashboardQueryShowResponse { query: DashboardQueryLog | null } /** * One page of the query log. `query` is what the Queries page's useServerList * sends: the range, status, type and connection (each left out when it is * "all", which the server reads the same), page and per_page. */ export async function fetchDashboardQueries(query: URLSearchParams): Promise { return dashboardApi(`/api/dashboard/queries?${query}`) } export async function fetchDashboardQuery(id: string): Promise { const response = await dashboardApi(`/api/dashboard/queries/${encodeURIComponent(id)}`) return response.query }