import {z} from 'zod' export type GetApiSnapshotsSnapshotIdRefactoringOpportunitiesArgs = {snapshot_id: string, refactoring_type?: (string | null) | undefined, status?: string | undefined, confidence?: (string | null) | undefined, effort?: (string | null) | undefined, file_path?: (string | null) | undefined, search?: (string | null) | undefined, mechanical?: boolean | undefined, view?: string | undefined, order?: (string | null) | undefined, step_preview?: number | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiSnapshotsSnapshotIdRefactoringOpportunitiesOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSnapshotsSnapshotIdRefactoringOpportunitiesResponse = z.record(z.string(), z.unknown()); 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 }; /** * Refactoring Opportunities * * GET /snapshots/{snapshot_id}/refactoring/opportunities */ export const getApiSnapshotsSnapshotIdRefactoringOpportunities = async (args: GetApiSnapshotsSnapshotIdRefactoringOpportunitiesArgs, options: GetApiSnapshotsSnapshotIdRefactoringOpportunitiesOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.refactoring_type != null) query.append("refactoring_type", String(args.refactoring_type)) if (args.status != null) query.append("status", String(args.status)) if (args.confidence != null) query.append("confidence", String(args.confidence)) if (args.effort != null) query.append("effort", String(args.effort)) if (args.file_path != null) query.append("file_path", String(args.file_path)) if (args.search != null) query.append("search", String(args.search)) if (args.mechanical != null) query.append("mechanical", String(args.mechanical)) if (args.view != null) query.append("view", String(args.view)) if (args.order != null) query.append("order", String(args.order)) if (args.step_preview != null) query.append("step_preview", String(args.step_preview)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/refactoring/opportunities${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(getApiSnapshotsSnapshotIdRefactoringOpportunitiesResponse, await res.json()) };