import {z} from 'zod' export type MtdnaCurationFields = {mt_ps2_strength?: (string | null) | undefined, mt_ps3_evidence?: (string | null) | undefined, mt_ps4_proband_count?: (number | null) | undefined, mt_ps4_haplogroup_diversity_count?: (number | null) | undefined, mt_pm6_strength?: (string | null) | undefined, mt_pp1_maternal_member_count?: (number | null) | undefined, mt_pp1_homoplasmic_in_all?: (boolean | null) | undefined, mt_pp1_heteroplasmy_correlation?: (boolean | null) | undefined, mt_pp4_etc_deficiency?: (string | null) | undefined, mt_bs2_strength?: (string | null) | undefined, mt_bs3_evidence?: (string | null) | undefined, mt_bs4_evidence?: (string | null) | undefined, mt_bp5_evidence?: (string | null) | undefined}; export type CreateApiSessionsSessionIdVariantsVariantIdxMtdnaCurationPreviewArgs = {session_id: string, variant_idx: number, body: MtdnaCurationFields}; export type CreateApiSessionsSessionIdVariantsVariantIdxMtdnaCurationPreviewOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const curationStateResponse = z.object({has_curated_flags: z.record(z.string(), z.boolean()), strength_enums: z.record(z.string(), z.string().nullable()), pp1_disqualified: z.boolean(), curated_contributed: z.boolean(), emitted_curated_criteria: z.array(z.string())}); 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 }; /** * Preview curation evaluation without saving * * POST /sessions/{session_id}/variants/{variant_idx}/mtdna-curation/preview */ export const createApiSessionsSessionIdVariantsVariantIdxMtdnaCurationPreview = async (args: CreateApiSessionsSessionIdVariantsVariantIdxMtdnaCurationPreviewArgs, options: CreateApiSessionsSessionIdVariantsVariantIdxMtdnaCurationPreviewOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/sessions/${encodeURIComponent(String(args.session_id))}/variants/${encodeURIComponent(String(args.variant_idx))}/mtdna-curation/preview${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(curationStateResponse, await res.json()) };