import {z} from 'zod' export type Arch = 'x86_64' | 'i686' | 'aarch64' | 'armv7' | 'armv6' | 'riscv64' | 'loongarch64' | 'powerpc64' | 's390x' | 'wasm32' | 'universal' | 'unknown'; export type Kind = 'binary' | 'installer' | 'library' | 'source' | 'sbom' | 'other'; export type Libc = 'gnu' | 'musl' | 'msvc' | 'mingw' | 'bionic' | 'unknown'; export type Os = 'linux' | 'windows' | 'macos' | 'freebsd' | 'openbsd' | 'netbsd' | 'android' | 'ios' | 'unknown'; export type CreateAssetRequest = {arch?: (Arch | null) | undefined, kind?: (Kind | null) | undefined, libc?: (Libc | null) | undefined, name: string, os?: (Os | null) | undefined, size: number}; export type CreateApiApiReposNamespaceRepositoryReleasesReleaseIdAssetsArgs = {namespace: string, repository: string, release_id: string, body: CreateAssetRequest}; export type CreateApiApiReposNamespaceRepositoryReleasesReleaseIdAssetsOptions = {baseUrl: string, cookieAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createAssetResponse = z.object({assetId: z.string(), uploadUrl: z.string()}); 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 Release Asset * * POST /api/repos/{namespace}/{repository}/releases/{release_id}/assets */ export const createApiApiReposNamespaceRepositoryReleasesReleaseIdAssets = async (args: CreateApiApiReposNamespaceRepositoryReleasesReleaseIdAssetsArgs, options: CreateApiApiReposNamespaceRepositoryReleasesReleaseIdAssetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, cookieAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (cookieAuth !== undefined) cookies.push("gitarena-session=" + encodeURIComponent(cookieAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/api/repos/${encodeURIComponent(String(args.namespace))}/${encodeURIComponent(String(args.repository))}/releases/${encodeURIComponent(String(args.release_id))}/assets${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(createAssetResponse, await res.json()) };