@suaveplan/api-router — contract package for the Suaveplan API plugin system. Defines the abstract Router interface (verb methods + use + mount + match), Request / Response host-side shapes, Zod-validated RouteOptions schema, Middleware composition helpers with insertion-point guard, RouteMatch shape, BlueGreenSlot interface for hot-reload, the frozen ROUTER_CODES registry, and the runRouterConformance harness every concrete adapter must pass.
Stage-1 contract package for the Suaveplan API plugin system.
This package defines the abstract Router interface, the host-side
Request / Response shapes, the Zod-validated RouteOptions schema, the
Middleware composition contract with insertion-point guard, the
RouteMatch shape, the BlueGreenSlot interface backing hot reload, the
frozen ROUTER_CODES registry, and the runRouterConformance harness
every concrete adapter must pass.
The reference in-memory Router and InMemoryBlueGreenSlot implementations
ship here so the conformance harness is self-checking and Stage-1 consumers
have a working router before any concrete adapter lands.
Documentation tree
- error-codes — The
error-codesmodule is the single source of truth for every failure class this package surfaces. It exports the fr…- error-codes — The
error-codesmodule is the single source of truth for every failure class this package surfaces. It exports the fr…
- error-codes — The
- middleware — The
middlewaremodule defines the onion-modelMiddlewarecontract and thecomposeMiddlewarebuilder. Every adapte…- insertion-point — The
insertion-pointmodule enforces the security invariant from design doc §6: plugin-supplied middleware is allowed… - middleware — The
middlewaremodule defines the onion-modelMiddlewarecontract and thecomposeMiddlewarebuilder. Every adapte…
- insertion-point — The
- request — The
requestmodule defines the host-sideRouterRequestshape — the post-parse, post-validation view that route hand…- request — The
requestmodule defines the host-sideRouterRequestshape — the post-parse, post-validation view that route hand…
- request — The
- response — The
responsemodule provides the host-sideRouterResponseshape and a fluentResponseBuilderthat adapters serial…- response — The
responsemodule provides the host-sideRouterResponseshape and a fluentResponseBuilderthat adapters serial…
- response — The
- route-match — The
route-matchmodule definesRouteMatch, the shape every concrete adapter yields after resolving an incoming `(me…- route-match — The
route-matchmodule definesRouteMatch, the shape every concrete adapter yields after resolving an incoming `(me…
- route-match — The
- route-options — The
route-optionsmodule is the Zod-validated boundary for every per-route configuration block. It widens the minimal…- route-options — The
route-optionsmodule is the Zod-validated boundary for every per-route configuration block. It widens the minimal…
- route-options — The
- router — The
routermodule defines the abstractRouter— the verb-method surface (get/post/put/patch/ `delete…- router — The
routermodule defines the abstractRouter— the verb-method surface (get/post/put/patch/ `delete…
- router — The
- slot — The
slotmodule definesBlueGreenSlot— the per-plugin atomic mount point that backs hot-reload. It exposes three p…- slot — The
slotmodule definesBlueGreenSlot— the per-plugin atomic mount point that backs hot-reload. It exposes three p…
- slot — The
- testing — The
testing/conformancemodule exportsrunRouterConformance(factory)— the canonical conformance harness every conc…- pipeline-router-conformance —
runPipelineRouterConformance(factory)is the canonical contract suite every concretePipelineRouteradapter MUST pa…- pipeline-router-conformance —
runPipelineRouterConformance(factory)is the canonical contract suite every concretePipelineRouteradapter MUST pa…
- pipeline-router-conformance —
- conformance — The
testing/conformancemodule exportsrunRouterConformance(factory)— the canonical conformance harness every conc…
- pipeline-router-conformance —
Status
- Version:
0.1.0 - Stage: 1 (Contracts) — see umbrella design.
- Dependents: none yet (host wires this in).
Install
bun add @suaveplan/api-router
Modules
router— abstractRouter+ reference in-memory implementation.request— host-sideRouterRequest+MapHeaders.response—RouterResponse+ fluent builder.route-options— Zod-validatedRouteOptions.middleware— onion-modelMiddleware+composeMiddleware.middleware/insertion-point— pipeline-step guard.route-match—RouteMatchshape + factory.slot—BlueGreenSlotinterface + in-memory reference impl.error-codes—ROUTER_CODES+RouterError.testing/conformance—runRouterConformanceadapter harness.
Error codes
The five frozen codes (every one thrown by a production path):
ROUTER.ROUTE_COLLISIONROUTER.INVALID_PREFIXROUTER.MIDDLEWARE_INSERTION_DENIEDROUTER.SLOT_FLIP_FAILEDROUTER.SLOT_DISPOSE_TIMEOUT
Subpath exports
Every module has its own subpath export so consumers tree-shake to exactly what they import:
import { Router } from "@suaveplan/api-router/router";
import { composeMiddleware } from "@suaveplan/api-router/middleware";
import { parseRouteOptions } from "@suaveplan/api-router/route-options";
import { runRouterConformance } from "@suaveplan/api-router/testing";
Verification
bunx turbo lint typecheck test --filter=@suaveplan/api-router— green.bunx turbo test:coverage --filter=@suaveplan/api-router— 100/100/100/100.bunx turbo build --filter=@suaveplan/api-router— green.
License
MIT