feat: nest API under /api/v1, structured error envelope, paged lists

Move every handler from /api/* to /api/v1/*. /api/* is now reserved for
future versioning.

Standardise the error response shape across the API as
{"error": {"code": "snake_case", "message": "..."}}. AppError gains a
`code()` whose top-level variants are matched exhaustively without a
wildcard — new variants are a compile error until coded. 500-class
responses always emit the fixed "internal error" string and log the
real cause via tracing only.

Lock in the list pagination envelope as {"items": [...], "page": {
"limit", "offset", "total"}} and apply it to GET /api/v1/mangas. `total`
serialises as null until feat/list-search-polish lands an indexed count.

The frontend client parses the envelope into ApiError.code with an
http_error fallback for non-JSON bodies. listMangas now returns the
paged shape; the root route consumes .items. New client.test.ts covers
envelope parsing and the fallback paths.

Lockstep version bump to 0.2.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-05-16 21:41:20 +02:00
parent 6c1d04aaf4
commit ce9a01793f
18 changed files with 6121 additions and 67 deletions

View File

@@ -1,18 +1,20 @@
import { test, expect } from '@playwright/test';
// These E2E tests run against the dev server (vite on :5173) which proxies
// /api to the backend. Set E2E_BASE_URL to point at a different deployment.
// These E2E tests run against the SvelteKit dev server, which proxies /api
// to the backend. Playwright starts vite via `webServer` (see
// playwright.config.ts) unless E2E_BASE_URL points at a different deployment.
//
// A live backend (and Postgres) must be reachable. Routes mock the network
// where possible to keep journeys deterministic.
// Routes are mocked at the page level so the journeys are deterministic and
// don't require a live backend.
const emptyPage = { items: [], page: { limit: 50, offset: 0, total: null } };
test('home page renders the Mangalord heading and search input', async ({ page }) => {
// Mock the list endpoint so the test doesn't depend on DB state.
await page.route('**/api/mangas*', async (route) => {
await page.route('**/api/v1/mangas*', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([])
body: JSON.stringify(emptyPage)
});
});
@@ -24,10 +26,10 @@ test('home page renders the Mangalord heading and search input', async ({ page }
test('search updates the manga list', async ({ page }) => {
let lastSearch: string | null = null;
await page.route('**/api/mangas*', async (route) => {
await page.route('**/api/v1/mangas*', async (route) => {
const url = new URL(route.request().url());
lastSearch = url.searchParams.get('search');
const body =
const items =
lastSearch === 'berserk'
? [
{
@@ -44,7 +46,7 @@ test('search updates the manga list', async ({ page }) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(body)
body: JSON.stringify({ items, page: { limit: 50, offset: 0, total: null } })
});
});