import {z} from 'zod' export type GetApiApiProjectsProjectIdCommitsCommitIdDiffArgs = {content?: ('true' | 'false' | 'True' | 'False' | 'TRUE' | 'FALSE' | boolean) | undefined, projectId: string, commitId: string}; export type GetApiApiProjectsProjectIdCommitsCommitIdDiffOptions = {baseUrl: string, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiProjectsProjectIdCommitsCommitIdDiffResponse = z.object({id: z.string(), message: z.string().nullable(), branchId: z.string(), projectId: z.string(), createdById: z.string().nullable(), createdBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), createdAt: z.string(), files: z.array(z.unknown()).optional(), branch: z.object({id: z.string(), name: z.string(), default: z.boolean(), projectId: z.string(), baseCommitId: z.string().nullable(), createdById: z.string().nullable(), createdBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), createdAt: z.string(), updatedAt: z.string(), changeRequests: z.array(z.object({id: z.string(), status: z.string(), type: z.string(), branchId: z.string().nullable(), projectId: z.string(), createdAt: z.string()})).optional()}), previousCommit: z.object({id: z.string(), message: z.string().nullable(), branchId: z.string(), projectId: z.string(), createdById: z.string().nullable(), createdBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), createdAt: z.string(), files: z.array(z.unknown()).optional()}).nullable().optional(), changes: z.array(z.object({type: z.enum(["added", "deleted", "modified", "renamed"]), file: z.unknown(), from: z.unknown(), to: z.unknown()})).nullable(), stats: z.object({filesAdded: z.number(), filesDeleted: z.number(), filesModified: z.number(), filesRenamed: z.number().optional(), totalChanges: z.number()})}); 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 }; /** * Get commit diff * * GET /api/projects/{projectId}/commits/{commitId}/diff * * Also accepts auth: internalAuth */ export const getApiApiProjectsProjectIdCommitsCommitIdDiff = async (args: GetApiApiProjectsProjectIdCommitsCommitIdDiffArgs, options: GetApiApiProjectsProjectIdCommitsCommitIdDiffOptions) => { const {baseUrl, fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.content != null) query.append("content", String(args.content)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.projectId))}/commits/${encodeURIComponent(String(args.commitId))}/diff${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(getApiApiProjectsProjectIdCommitsCommitIdDiffResponse, await res.json()) };