Files
2026-06-09 21:06:27 +01:00

5.1 KiB

@suaveplan/api-router-in-memory — in-memory router adapter for the @suaveplan/api plugin system. Implements both the abstract Router contract from @suaveplan/api-router AND the PipelineRouter contract from @suaveplan/api-router on a single InMemoryRouter class. Production-grade in-memory adapter — keeps state in process, dispatches without binding a socket. Passes runRouterConformance + runPipelineRouterConformance.

Stage-5 in-memory router adapter for @suaveplan/api. Implements both the abstract Router contract from @suaveplan/api-router AND the PipelineRouter contract from @suaveplan/api-router on a single InMemoryRouter class. Production-grade in-memory adapter — not a test double.

Documentation tree

  • adapter — InMemoryRouter is the Stage-5 in-memory router adapter for @suaveplan/api. It implements both…
    • adapter — InMemoryRouter is the Stage-5 in-memory router adapter for @suaveplan/api. It implements both…
  • blue-green-slot — InMemoryBlueGreenSlot is the BlueGreenSlot implementation paired with InMemoryRouter. It is a thin extension of `…
    • blue-green-slot — InMemoryBlueGreenSlot is the BlueGreenSlot implementation paired with InMemoryRouter. It is a thin extension of `…
  • error-codes — Defines the stable ROUTER_IN_MEMORY.* error-code namespace used by every production path in `@suaveplan/api-router-in…
    • error-codes — Defines the stable ROUTER_IN_MEMORY.* error-code namespace used by every production path in `@suaveplan/api-router-in…
  • pipeline — PipelineRouteTable is the in-memory metadata store that backs InMemoryRouter's pipeline facet. It stores per-route…
    • pipeline — PipelineRouteTable is the in-memory metadata store that backs InMemoryRouter's pipeline facet. It stores per-route…
  • testing — createInMemoryRouterHarness() is the canonical "spin up an in-memory router for a test" entry point. It bundles a fre…
    • testing — createInMemoryRouterHarness() is the canonical "spin up an in-memory router for a test" entry point. It bundles a fre…

What it ships

  • InMemoryRouter / createInMemoryRouter() — concrete Router adapter that subclasses the abstract base AND exposes the pipeline facet (registerPipelineRoute, matchPipeline, listPipelineRoutes, unregisterPipelineRoute, unregisterPipelinePlugin).
  • InMemoryBlueGreenSlot / createInMemoryBlueGreenSlot — hot-reload primitive paired with the router. Thin extension of @suaveplan/api-router's reference InMemoryBlueGreenSlot.
  • PipelineRouteTable — the in-memory metadata store backing the pipeline facet, exported for advanced use cases that need to share a table across routers.
  • createInMemoryRouterHarness() — downstream test helper that bundles a router + slot factory pair, replacing the hand-rolled router shims that have grown across the foundation + plugin tests.
  • ROUTER_IN_MEMORY_CODES / RouterInMemoryError — stable error-code registry (ROUTER_IN_MEMORY.ROUTE_COLLISION, ROUTER_IN_MEMORY.INVALID_PREFIX).

Conformance

The package passes BOTH foundation conformance suites:

  • runRouterConformance from @suaveplan/api-router/testing — see tests/conformance/api-router.test.ts.
  • runPipelineRouterConformance from @suaveplan/api-router/testing/pipeline-router-conformance — see tests/conformance/pipeline-router.test.ts.

Adding new behaviours requires re-running both harnesses.

Modules

Usage

import {
    createInMemoryRouter,
    InMemoryBlueGreenSlot,
} from "@suaveplan/api-router-in-memory";

const router = createInMemoryRouter({ plugin: "billing" });
router.get("/invoices/:id", () => null);

router.registerPipelineRoute({
    plugin: "billing",
    method: "POST",
    path: "/invoices",
    handler: async () => ({ ok: true }),
});

const slot = new InMemoryBlueGreenSlot("billing", () => "v1");
slot.setShadow(() => "v2");
const draining = slot.flip();
await slot.dispose(draining.slotId, { timeoutMs: 100 });

When to use

  • Foundation tests that need a real Router/PipelineRouter without a Hono peer.
  • Plugin tests that previously hand-rolled their own router shim (api-router-hono carries the Hono peer-dep cost).
  • The default router: "in-memory" slot in the Stage-5 @suaveplan/api-host/testing adapter table.