import {z} from 'zod' export type GetApiPreprocessingVepCacheStatsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const vepCacheDistributionEntry = z.object({label: z.string(), count: z.number().int(), pct: z.number().optional()}); export const vepCacheChromosomeEntry = z.object({chromosome: z.string(), positive: z.number().int(), negative: z.number().int()}); export const vepCacheStatsResponse = z.object({file_exists: z.boolean(), file_size_bytes: z.number().int().optional(), file_size_human: z.string().optional(), vep_version: z.string().nullable().optional(), positive_count: z.number().int().optional(), negative_count: z.number().int().optional(), total_count: z.number().int().optional(), oldest_entry: z.string().nullable().optional(), newest_entry: z.string().nullable().optional(), dedup_cutoff: z.string().nullable().optional(), impact_distribution: z.array(vepCacheDistributionEntry).optional(), consequence_distribution: z.array(vepCacheDistributionEntry).optional(), biotype_distribution: z.array(vepCacheDistributionEntry).optional(), chromosome_distribution: z.array(vepCacheChromosomeEntry).optional(), sample_positive: z.array(z.record(z.string(), z.unknown())).optional(), sample_negative: z.array(z.record(z.string(), z.unknown())).optional(), query_time_ms: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Vep Cache Stats * * GET /preprocessing/vep-cache/stats */ export const getApiPreprocessingVepCacheStats = async (options: GetApiPreprocessingVepCacheStatsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/preprocessing/vep-cache/stats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(vepCacheStatsResponse, await res.json()) };