import { type Signal } from "../helpers/index.js"; import { type FetchConfig, type Paths, getFetcher } from "./client/index.js"; import { hoistApiError } from "./errors.js"; /** * ValueOf represents only the values of a given keyed interface. */ export type ValueOf = T[keyof T]; /** * TableFormat represents a object with rows and columns. */ export interface TableFormat { rows: Array>; columns: Array<{ name: string }>; } /** * ObjectsFormat represents an array of rows as key/value objects. */ export type ObjectsFormat = T[]; export type BaseParams = Paths["/query"]["get"]["parameters"]["query"]; export type Format = BaseParams["format"]; export type Params = BaseParams & { format?: T }; export async function getQuery( config: FetchConfig, params: Params<"objects" | undefined>, signal?: Signal ): Promise>; export async function getQuery( config: FetchConfig, params: Params<"table">, signal?: Signal ): Promise>; export async function getQuery( config: FetchConfig, params: Params, signal?: Signal ): Promise | TableFormat> { const queryByStatement = getFetcher(config) .path("/query") .method("get") .create(); const { data } = await queryByStatement(params, signal).catch(hoistApiError); switch (params.format) { case "table": return data as any; default: return data as any; } }