import {z} from 'zod' export type GetApiSynapseBioAntibodySearchArgs = {antigen_name: string, page?: number | undefined, rows?: number | undefined}; export type GetApiSynapseBioAntibodySearchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b065AntibodySearchAntibodyPatentInfo = z.object({source_type: z.string().optional(), antibody_patent_id: z.string().optional(), antibody_patent_number: z.string().optional(), heavy_chain_sequence_id: z.string().optional(), light_chain_sequence_id: z.string().optional()}); export const b065AntibodySearchAntibodyUniport = z.object({uniprot_id: z.string().optional(), uniprot_id_seq: z.string().optional()}); export const b065AntibodySearchAntibodySequenceInfo = z.object({antibody_heavy_chain: z.string().optional(), antibody_light_chain: z.string().optional(), heavy_chain_sequence_number: z.number().int().optional(), light_chain_sequence_number: z.number().int().optional()}); export const b065AntibodySearchAntibodyDetail = z.object({source: b065AntibodySearchAntibodyPatentInfo.optional(), affinity_id: z.string().optional(), antigen_name: z.string().optional(), antibody_name: z.array(z.unknown()).optional(), antigen_species: z.string().optional(), antigen_uniport: z.array(b065AntibodySearchAntibodyUniport).optional(), antigen_sequence: z.string().optional(), antibody_sequence: b065AntibodySearchAntibodySequenceInfo.optional()}); export const b065AntibodySearchAntibodyResponse = z.object({page: z.number().int().optional(), rows: z.number().int().optional(), items: z.array(b065AntibodySearchAntibodyDetail).optional(), total: z.number().int().optional()}); export const b065AntibodySearchResponse = z.object({data: b065AntibodySearchAntibodyResponse.optional(), status: z.boolean(), error_msg: z.string().optional(), error_code: z.number().int()}); 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 }; /** * B065 Antigen-Antibody Pairing Search * * GET /synapse/bio/antibody/search */ export const getApiSynapseBioAntibodySearch = async (args: GetApiSynapseBioAntibodySearchArgs, options?: GetApiSynapseBioAntibodySearchOptions) => { const {baseUrl = "https://connect.patsnap.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.antigen_name != null) query.append("antigen_name", String(args.antigen_name)) if (args.page != null) query.append("page", String(args.page)) if (args.rows != null) query.append("rows", String(args.rows)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/synapse/bio/antibody/search${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(b065AntibodySearchResponse, await res.json()) };