Skip to content

feat(api): library read endpoints — GET /libraries, GET /libraries/:id/specs#227

Merged
thewrz merged 1 commit into
mainfrom
feat/api-library-read
Jun 19, 2026
Merged

feat(api): library read endpoints — GET /libraries, GET /libraries/:id/specs#227
thewrz merged 1 commit into
mainfrom
feat/api-library-read

Conversation

@thewrz

@thewrz thewrz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Why

The examples/web_ui_demo board cannot bootstrap on main: creating its default project requires a source library id (POST /projects mandates sourceLibraryIds ≥1 by design, #94), and seeded library UUIDs are only discoverable by listing them. The DB layer already had listLibraries(); these were just never exposed over REST. First of the roadmap-first backend gaps that unblock the demo (spec: docs/superpowers/specs/2026-06-19-demo-backend-conformance.md).

What

Two read endpoints, mirroring the existing GET /conventions list pattern and ADR-015 D1 (libraries are first-class):

  • GET /librariesApiResponse<Library[]>, ordered by tier then name (reuses listLibraries()).
  • GET /libraries/:id/specsApiResponse<LibrarySpec[]> with each spec's paragraph nodeCount; 404 on unknown library, 400 on malformed id. New listLibrarySpecs query.

openapi.yaml documents both with Library/LibrarySpec schemas; the contract gate response-covers them.

Testing

  • Unit/integration: src/api/libraries.integration.test.ts (list returns seeded built-ins ordered; specs list returns nodeCount; 404 + 400) — 5/5 pass
  • Contract gate green (route↔spec coverage + response-schema validation)
  • pnpm lint clean (eslint + tsc + prettier)
  • CI green

⚠️ Note: src/parser/docx/cpi.integration.test.ts fails on origin/main independently of this PR (CPI source-inference regression) — not introduced here.

🤖 Co-authored by Claude Opus 4.8. Closes #226.

Summary by CodeRabbit

New Features

  • Added endpoints to list all available libraries, organized by tier and name
  • New ability to retrieve all specs within a library, including section, title, and node count information
  • Improved error handling for invalid library identifiers and missing resources

…d/specs

The web UI demo cannot bootstrap on main without listing libraries: creating
its default project needs a source library id (POST /projects mandates
sourceLibraryIds, #94), and seeded library UUIDs are only discoverable by
listing. These reads existed in the DB layer but weren't exposed.

- GET /libraries → Library[] (tier, name order), reusing listLibraries().
- GET /libraries/:id/specs → LibrarySpec[] with paragraph node counts; 404 on
  unknown library. New listLibrarySpecs query (specs ⋈ paragraphs).
- openapi.yaml documents both; contract gate response-covers them.

Closes #226

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds GET /libraries and GET /libraries/{id}/specs REST endpoints. A new listLibrarySpecs DB query joins specs to paragraphs to compute nodeCount. Two Express handlers with UUID validation and 400/404/500 error handling are wired into the router. OpenAPI schemas and endpoint definitions are added, and integration tests cover ordering, nodeCount, and error cases.

Changes

Library Read Endpoints

Layer / File(s) Summary
LibrarySpec type and listLibrarySpecs query
src/db/queries/libraries.ts, src/db/index.ts
Adds the LibrarySpec interface and listLibrarySpecs function that joins specs to paragraphs, computes nodeCount via COUNT, orders by section, and re-exports both from the DB index.
Express handlers and router wiring
src/api/libraries.ts, src/api/router.ts
Adds parseLibraryId (zod UUID validation), listLibrariesHandler, and listLibrarySpecsHandler with 400/404/500 error handling. Registers /libraries and /libraries/:id/specs GET routes.
OpenAPI contract
openapi.yaml
Documents both GET operations with SuccessResponse envelopes and error responses. Adds Library and LibrarySpec component schemas including nullable owner/parentLibraryId and nodeCount.
Integration tests
src/api/libraries.integration.test.ts, src/api/contract.integration.test.ts
New test suite covers GET /libraries (tier presence, sort order) and GET /libraries/:id/specs (nodeCount, empty case, 404, 400). Contract test's response-covered set and schema-validation tests are extended for both endpoints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wrzonance/SpecR#212: Introduced the contract/route↔spec gate infrastructure in src/api/contract.integration.test.ts that this PR extends by registering the new /libraries and /libraries/{id}/specs operations as response-covered endpoints.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding two new library read endpoints (GET /libraries and GET /libraries/:id/specs) to the API.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #226: both endpoints are added with correct signatures, responses are documented in openapi.yaml, integration tests verify listed libraries and node counts, and no linting violations are introduced.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the stated objectives: API endpoints, database queries, OpenAPI schemas, integration tests, and router registration are all necessary for implementing the two library read operations.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-library-read

Comment @coderabbitai help to get the list of available commands and usage tips.

@thewrz thewrz marked this pull request as ready for review June 19, 2026 18:45
@thewrz thewrz merged commit 9dceb3f into main Jun 19, 2026
5 checks passed
@thewrz thewrz deleted the feat/api-library-read branch June 19, 2026 18:46
thewrz added a commit that referenced this pull request Jun 21, 2026
With GET /libraries (#227) and GET /projects (#229) on main, the demo now
bootstraps. This conforms the rest of it to main's actual API:

- features.js capability map: panels check a flag and degrade to a clear
  "not available in this build" state instead of calling endpoints that 404.
  libraries/projectsList on (landed); library writes, project settings/sources,
  coordination/required-sections, and hard-delete stay off.
- Repoint getSpecTree -> GET /specs/:id (the single-spec read already returns
  the tree). Drop the explicit deleteReference call — references are derived
  from paragraph text, so the paragraph PATCH re-derives them.
- Restore the reference-web arcs by fetching project-scoped outbound references
  (GET /projects/:id/specs/:specId/references, ADR-024) per loaded spec.

Verified end-to-end with Playwright: clean boot, default project auto-created,
all bootstrap calls 200/201, zero console 404s, gated endpoints never hit.

Closes #230

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api): library read endpoints — GET /libraries, GET /libraries/:id/specs

1 participant