import {z} from 'zod' export type B016SequenceInfoRequest = Record; export type CreateApiBioSequenceInfoArgs = {sequence_id?: number | undefined, body: B016SequenceInfoRequest}; export type CreateApiBioSequenceInfoOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b016SequenceInfoBioSequenceInfoCdr = z.object({hc_cdr1: z.string().optional(), hc_cdr2: z.string().optional(), hc_cdr3: z.string().optional()}); export const b016SequenceInfoBioSequenceInfoCdrs = z.object({abm: z.array(b016SequenceInfoBioSequenceInfoCdr).optional(), imgt: z.array(b016SequenceInfoBioSequenceInfoCdr).optional(), kabat: z.array(b016SequenceInfoBioSequenceInfoCdr).optional(), chothia: z.array(b016SequenceInfoBioSequenceInfoCdr).optional(), contact: z.array(b016SequenceInfoBioSequenceInfoCdr).optional()}); export const b016SequenceInfoCommonName = z.object({lang: z.string().optional(), name: z.string().optional()}); export const b016SequenceInfoBioDrugInfo = z.object({drug_id: z.string().optional(), display_name: z.array(b016SequenceInfoCommonName).optional()}); export const b016SequenceInfoBioGeneInfo = z.object({name: z.string().optional(), gene_id: z.string().optional()}); export const b016SequenceInfoBioSequenceInfoClaim = z.object({pn: z.string().optional(), pbdt: z.number().int().optional(), positions: z.array(z.unknown()).optional()}); export const b016SequenceInfoBioSequenceInfoResponse = z.object({cdrs: b016SequenceInfoBioSequenceInfoCdrs.optional(), type: z.string().optional(), drugs: z.array(b016SequenceInfoBioDrugInfo).optional(), genes: z.array(b016SequenceInfoBioGeneInfo).optional(), length: z.string().optional(), organism: z.array(z.unknown()).optional(), sequence: z.string().optional(), description: z.string().optional(), is_antibody: z.boolean().optional(), seq_position: z.array(b016SequenceInfoBioSequenceInfoClaim).optional(), sequence_code: z.number().int().optional(), sequence_name: z.array(z.unknown()).optional(), sequence_label: z.array(z.unknown()).optional(), claimed_in_patents: z.boolean().optional(), chemically_modified: z.boolean().optional()}); export const b016SequenceInfoResponse = z.object({data: b016SequenceInfoBioSequenceInfoResponse.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 }; /** * B016 Sequence Infomation * * POST /bio/sequence/info */ export const createApiBioSequenceInfo = async (args: CreateApiBioSequenceInfoArgs, options?: CreateApiBioSequenceInfoOptions) => { const {baseUrl = "https://connect.patsnap.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.sequence_id != null) query.append("sequence_id", String(args.sequence_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/bio/sequence/info${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(b016SequenceInfoResponse, await res.json()) };