import {z} from 'zod' export type GetApiWorkspaceWorkspaceIdRelationshipsVcsArgs = {'filter[vcs]'?: string | undefined, 'page[number]'?: number | undefined, 'page[size]'?: number | undefined, 'page[offset]'?: number | undefined, 'page[limit]'?: number | undefined, 'page[totals]'?: string | undefined}; export type GetApiWorkspaceWorkspaceIdRelationshipsVcsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiWorkspaceWorkspaceIdRelationshipsVcsResponse = z.object({data: z.object({id: z.string().optional(), type: z.literal("vcs").optional()}).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 }; /** * Returns the relationship identifiers for vcs * * GET /workspace/{workspaceId}/relationships/vcs */ export const getApiWorkspaceWorkspaceIdRelationshipsVcs = async (args: GetApiWorkspaceWorkspaceIdRelationshipsVcsArgs, options: GetApiWorkspaceWorkspaceIdRelationshipsVcsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args['filter[vcs]'] != null) query.append("filter[vcs]", String(args['filter[vcs]'])) if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[offset]'] != null) query.append("page[offset]", String(args['page[offset]'])) if (args['page[limit]'] != null) query.append("page[limit]", String(args['page[limit]'])) if (args['page[totals]'] != null) query.append("page[totals]", String(args['page[totals]'])) const url = `${baseUrl.replace(/\/+$/, '')}/workspace/${encodeURIComponent(String(args.workspaceId))}/relationships/vcs${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(getApiWorkspaceWorkspaceIdRelationshipsVcsResponse, await res.json()) };