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

2.8 KiB

name, description
name description
sp-api-capability-events-memory Faithful in-memory CapabilityEventBusLike reference implementation (MemoryEvents) for the Suaveplan API capability system. Real per-topic pub/sub with idempotent unsubscribe and awaited delivery. The fixture that runEventsConformance measures every event-bus implementation against.

@suaveplan/api-capability-events-memory

Purpose

Faithful in-memory CapabilityEventBusLike reference implementation (MemoryEvents) for the Suaveplan API capability system. Provides real per-topic publish/subscribe with idempotent unsubscribe and awaited delivery (callers can await emit).

This is the fixture that @suaveplan/api-capability-kit's runEventsConformance harness measures every event-bus implementation against. Its conformance test also runs against both the direct implementation AND the same implementation behind @suaveplan/api-capability-proxy, proving the proxy stays transparent.

Architecture

Component Source Role
MemoryEvents src/memory-events/memory-events.ts In-memory CapabilityEventBusLike (emit/on)
EventListener src/memory-events/memory-events.ts Listener type for the bus

File Structure

src/
  index.ts              # Exports MemoryEvents, EventListener
  memory-events/
    memory-events.ts    # Implementation
    memory-events.md    # Module docs
    memory-events.test.ts # Conformance + direct tests

Entry Points

Import Exports
@suaveplan/api-capability-events-memory MemoryEvents, EventListener
@suaveplan/api-capability-events-memory/memory-events/memory-events MemoryEvents, EventListener

Patterns

Basic pub/sub

import { MemoryEvents } from "@suaveplan/api-capability-events-memory";

const bus = new MemoryEvents();
const off = bus.on("user.created", (payload) => console.log(payload));
await bus.emit("user.created", { id: "u1" });
off(); // idempotent unsubscribe

Awaited delivery

// emit awaits all listeners before resolving
await bus.emit("order.placed", { orderId: "ord_123" });
// Safe to proceed knowing all handlers have run

Constraints

  • Reference implementation — the canonical in-memory event bus; all other implementations measured against it.
  • Proxy transparency — conformance tests prove identical behaviour behind @suaveplan/api-capability-proxy.
  • Idempotent unsubscribe — calling the returned unsubscriber multiple times is safe.
  • Dependencies: @suaveplan/api-types, tslib. Dev: @suaveplan/api-capability-kit, @suaveplan/api-capability-proxy.

Checklist

  • Read src/memory-events/memory-events.ts before modifying bus behaviour
  • Preserve proxy transparency — changes must pass both direct and proxied conformance tests