import {z} from 'zod' export type GetApiPartstudiosDDidWvmWvmidEEidFstableArgs = {did: string, wvm: string, wvmid: string, eid: string, configuration?: string | undefined, tableNamespace?: string | undefined, tableType: string, tableParameters?: string | undefined, partId?: string | undefined, linkDocumentId?: string | undefined}; export type GetApiPartstudiosDDidWvmWvmidEEidFstableOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const gBTTableTextAlignment = z.enum(["LEFT", "CENTER", "RIGHT", "UNKNOWN"]); export const bTApiTableColumn3141 = z.object({btType: z.string().optional(), header: z.string().optional(), id: z.string().optional(), textAlignment: gBTTableTextAlignment.optional()}); export const bTApiTableRow2915 = z.object({btType: z.string().optional(), callout: z.string().optional(), columnIdToValue: z.record(z.string(), z.string()).optional(), entityIds: z.array(z.string()).optional()}); export const bTApiTable2300 = z.object({btType: z.string().optional(), columns: z.array(bTApiTableColumn3141).optional(), entityIds: z.array(z.string()).optional(), id: z.string().optional(), rows: z.array(bTApiTableRow2915).optional(), title: z.string().optional()}); export const bTApiTableList1223 = z.object({btType: z.string().optional(), tables: z.array(bTApiTable2300).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 }; /** * Compute and return a FeatureScript table for a Part Studio. * * GET /partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/fstable */ export const getApiPartstudiosDDidWvmWvmidEEidFstable = async (args: GetApiPartstudiosDDidWvmWvmidEEidFstableArgs, options?: GetApiPartstudiosDDidWvmWvmidEEidFstableOptions) => { const {baseUrl = "https://api.onshape.com/api/v17", fetch: fetchFn = fetch, OAuth2, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;charset=UTF-8; qs=0.09") if (args.configuration != null) query.append("configuration", String(args.configuration)) if (args.tableNamespace != null) query.append("tableNamespace", String(args.tableNamespace)) if (args.tableType != null) query.append("tableType", String(args.tableType)) if (args.tableParameters != null) query.append("tableParameters", String(args.tableParameters)) if (args.partId != null) query.append("partId", String(args.partId)) if (args.linkDocumentId != null) query.append("linkDocumentId", String(args.linkDocumentId)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/partstudios/d/${encodeURIComponent(String(args.did))}/${encodeURIComponent(String(args.wvm))}/${encodeURIComponent(String(args.wvmid))}/e/${encodeURIComponent(String(args.eid))}/fstable${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(bTApiTableList1223, await res.json()) };