Something went wrong. Try again.
Beautiful changelogs and releases for everything
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// Server-side read-plane access. The web UI consumes only the public// read plane (parity by construction, design D22): these calls hit// the same XRPC endpoints any third-party client uses.import { env } from '$env/dynamic/private'import { error } from '@sveltejs/kit'import type { TownDistGetChangelog, TownDistGetProject, TownDistListChangelogs, TownDistListProjects, TownDistListRecentReleases, TownDistResolveRelease,} from '@dist-town/client'
const appviewURL = () => env.APPVIEW_URL ?? 'http://127.0.0.1:8480'
async function xrpc<T>(fetchFn: typeof fetch, method: string, params: Record<string, string>): Promise<T> { const url = new URL(`/xrpc/${method}`, appviewURL()) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v) const resp = await fetchFn(url) if (!resp.ok) { const body = await resp.json().catch(() => ({ message: resp.statusText })) // 400 covers unresolvable identifiers: a not-found for the visitor. // 410 travels intact: a retracted version is an answer the // publisher wrote, and routes render it rather than erroring. const status = resp.status === 404 || resp.status === 400 ? 404 : resp.status === 410 ? 410 : 502 error(status, body.message ?? body.error ?? 'read plane error') } return resp.json() as Promise<T>}
export function getProject(fetchFn: typeof fetch, repo: string, project: string) { return xrpc<TownDistGetProject.OutputSchema>(fetchFn, 'town.dist.getProject', { repo, project })}
export function resolveRelease(fetchFn: typeof fetch, repo: string, project: string, selector: string) { return xrpc<TownDistResolveRelease.OutputSchema>(fetchFn, 'town.dist.resolveRelease', { repo, project, selector, })}
export function listChangelogs(fetchFn: typeof fetch, repo: string, project: string) { return xrpc<TownDistListChangelogs.OutputSchema>(fetchFn, 'town.dist.listChangelogs', { repo, project, })}
export function getChangelog(fetchFn: typeof fetch, repo: string, project: string, rkey: string) { return xrpc<TownDistGetChangelog.OutputSchema>(fetchFn, 'town.dist.getChangelog', { repo, project, rkey, })}
export function listRecentReleases( fetchFn: typeof fetch, limit: number, scope?: { repo: string; project?: string },) { const params: Record<string, string> = { limit: String(limit) } if (scope) { params.repo = scope.repo if (scope.project) params.project = scope.project } return xrpc<TownDistListRecentReleases.OutputSchema>( fetchFn, 'town.dist.listRecentReleases', params, )}
export function listProjects(fetchFn: typeof fetch, repo: string) { return xrpc<TownDistListProjects.OutputSchema>(fetchFn, 'town.dist.listProjects', { repo })}