import {z} from 'zod' export type B004SequenceJobOpenAPiNumberRangeParameter = {end?: number | undefined, start?: number | undefined}; export type B004SequenceJobOpenApiFilterParameter = {perc_identity?: B004SequenceJobOpenAPiNumberRangeParameter | undefined, q_perc_identity?: B004SequenceJobOpenAPiNumberRangeParameter | undefined, qcov_hsp_perc?: B004SequenceJobOpenAPiNumberRangeParameter | undefined, s_perc_identity?: B004SequenceJobOpenAPiNumberRangeParameter | undefined, scov_hsp_perc?: B004SequenceJobOpenAPiNumberRangeParameter | undefined, subject_length?: B004SequenceJobOpenAPiNumberRangeParameter | undefined}; export type B004SequenceJobOpenApiBlastParameter = {algorithm: string, evalue?: number | undefined, filter?: B004SequenceJobOpenApiFilterParameter | undefined, with_gaps?: boolean | undefined, word_size?: number | undefined}; export type B004SequenceJobOpenApiRequestSequenceInfo = {label?: string | undefined, sequence?: string | undefined}; export type B004SequenceJobRequest = {database?: Array | undefined, limit: number, params: B004SequenceJobOpenApiBlastParameter, query_type: string, sequence_list: Array, sequence_type: string}; export type CreateApiBioOpenapiSequenceJobArgs = {body: B004SequenceJobRequest}; export type CreateApiBioOpenapiSequenceJobOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const b004SequenceJobOpenApiResponseSequenceInfo = z.object({label: z.string().optional(), job_id: z.string().optional(), sequence: z.string().optional()}); export const b004SequenceJobResponse = z.object({data: z.array(b004SequenceJobOpenApiResponseSequenceInfo).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 }; /** * B004 Normal Sequence Search * * POST /bio-openapi/sequence/job */ export const createApiBioOpenapiSequenceJob = async (args: CreateApiBioOpenapiSequenceJobArgs, options?: CreateApiBioOpenapiSequenceJobOptions) => { 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;charset=UTF-8") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/bio-openapi/sequence/job${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(b004SequenceJobResponse, await res.json()) };