import {z} from 'zod' export type GetApiSnapshotsSnapshotIdHealthCoverageArgs = {snapshot_id: string, offset?: number | undefined, limit?: number | undefined, module_limit?: number | undefined, include_inferred?: boolean | undefined}; export type GetApiSnapshotsSnapshotIdHealthCoverageOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const coverageReportPaths = z.object({total: z.number().int(), matched: z.number().int(), unmatched: z.number().int(), ambiguous: z.number().int(), unmatched_sample: z.array(z.string())}); export const coverageSummaryFreshness = z.object({status: z.enum(["current", "stale", "unknown"]), indexed_commit: z.string().nullable()}); export const coverageHistoryPoint = z.object({ingested_at: z.string(), ingested_commit_sha: z.string().nullable(), line_coverage_pct: z.number(), branch_coverage_pct: z.number().nullable()}); export const coverageFileRow = z.object({file_path: z.string(), source_format: z.string(), line_coverage_pct: z.number(), branch_coverage_pct: z.number().nullable().optional(), total_coverable_lines: z.number().int().optional(), ingested_at: z.string().nullable().optional(), ingested_commit_sha: z.string().nullable().optional(), health_score: z.number().nullable().optional(), nloc: z.number().int().nullable().optional()}); export const coverageModuleRow = z.object({module: z.string(), files: z.number().int(), covered_lines: z.number().int(), total_lines: z.number().int(), line_coverage_pct: z.number()}); export const reachedFileRow = z.object({file_path: z.string(), reached: z.boolean(), health_score: z.number().nullable().optional(), nloc: z.number().int().nullable().optional()}); export const inferredTestMap = z.object({files: z.array(reachedFileRow).optional(), files_total: z.number().int().optional(), files_reached: z.number().int().optional(), files_not_reached: z.number().int().optional(), test_file_count: z.number().int().optional()}); export const healthCoverageResponse = z.object({overall_line_coverage_pct: z.number().nullable().optional(), overall_branch_coverage_pct: z.number().nullable().optional(), file_count_with_coverage: z.number().int().optional(), source_format: z.string().nullable().optional(), ingested_at: z.string().nullable().optional(), ingested_commit_sha: z.string().nullable().optional(), source_formats: z.array(z.string()).optional(), mapping_partial: z.boolean().nullable().optional(), report_paths: coverageReportPaths.nullable().optional(), freshness: coverageSummaryFreshness.nullable().optional(), history: z.array(coverageHistoryPoint).nullable().optional(), files: z.array(coverageFileRow).optional(), modules: z.array(coverageModuleRow).optional(), modules_total: z.number().int().optional(), total: z.number().int().optional(), basis: z.string().nullable().optional(), inferred: inferredTestMap.nullable().optional(), state: z.string().optional(), reason: z.string().nullable().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 }; /** * Health Coverage * * GET /snapshots/{snapshot_id}/health/coverage */ export const getApiSnapshotsSnapshotIdHealthCoverage = async (args: GetApiSnapshotsSnapshotIdHealthCoverageArgs, options: GetApiSnapshotsSnapshotIdHealthCoverageOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.module_limit != null) query.append("module_limit", String(args.module_limit)) if (args.include_inferred != null) query.append("include_inferred", String(args.include_inferred)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/health/coverage${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(healthCoverageResponse, await res.json()) };