import {z} from 'zod' export type V1Time = {nanos?: number | undefined, seconds?: unknown | undefined}; export type V1alpha1ConnectionState = {attemptedAt?: V1Time | undefined, message?: string | undefined, status?: string | undefined}; export type V1alpha1Repository = {connectionState?: V1alpha1ConnectionState | undefined, enableLfs?: boolean | undefined, insecure?: boolean | undefined, insecureIgnoreHostKey?: boolean | undefined, password?: string | undefined, repo?: string | undefined, sshPrivateKey?: string | undefined, tlsClientCertData?: string | undefined, tlsClientCertKey?: string | undefined, username?: string | undefined}; export type CreateApiApiV1RepositoriesArgs = {body: V1alpha1Repository}; export type CreateApiApiV1RepositoriesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v1Time = z.object({nanos: z.number().int().optional(), seconds: z.string().optional()}); export const v1alpha1ConnectionState = z.object({attemptedAt: v1Time.optional(), message: z.string().optional(), status: z.string().optional()}); export const v1alpha1Repository = z.object({connectionState: v1alpha1ConnectionState.optional(), enableLfs: z.boolean().optional(), insecure: z.boolean().optional(), insecureIgnoreHostKey: z.boolean().optional(), password: z.string().optional(), repo: z.string().optional(), sshPrivateKey: z.string().optional(), tlsClientCertData: z.string().optional(), tlsClientCertKey: z.string().optional(), username: z.string().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 }; /** * Create creates a repo * * POST /api/v1/repositories */ export const createApiApiV1Repositories = async (args: CreateApiApiV1RepositoriesArgs, options: CreateApiApiV1RepositoriesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/repositories${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(v1alpha1Repository, await res.json()) };