import {z} from 'zod' export type GetApiRegistriesRegistryNamePackageNamesArgs = {registryName: string, page?: number | undefined, per_page?: number | undefined, created_after?: string | undefined, updated_after?: string | undefined, created_before?: string | undefined, updated_before?: string | undefined, sort?: ('updated_at' | 'created_at' | 'name' | 'downloads' | 'dependent_repos_count' | 'dependent_packages_count' | 'latest_release_published_at' | 'versions_count' | 'maintainers_count' | 'docker_downloads_count' | 'docker_dependents_count' | 'stargazers_count' | 'forks_count') | undefined, order?: string | undefined, critical?: boolean | undefined, funding?: boolean | undefined, prefix?: string | undefined, postfix?: string | undefined}; export type GetApiRegistriesRegistryNamePackageNamesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiRegistriesRegistryNamePackageNamesResponse = z.array(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 }; /** * get a list of package names from a registry * * GET /registries/{registryName}/package_names */ export const getApiRegistriesRegistryNamePackageNames = async (args: GetApiRegistriesRegistryNamePackageNamesArgs, options?: GetApiRegistriesRegistryNamePackageNamesOptions) => { const {baseUrl = "https://packages.ecosyste.ms/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (args.critical != null) query.append("critical", String(args.critical)) if (args.funding != null) query.append("funding", String(args.funding)) if (args.prefix != null) query.append("prefix", String(args.prefix)) if (args.postfix != null) query.append("postfix", String(args.postfix)) const url = `${baseUrl.replace(/\/+$/, '')}/registries/${encodeURIComponent(String(args.registryName))}/package_names${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(getApiRegistriesRegistryNamePackageNamesResponse, await res.json()) };