npm.io
0.15.1 • Published 3d ago

@nwire/bus

Licence
MIT
Version
0.15.1
Deps
2
Size
8 kB
Vulns
0
Weekly
2.7K

@nwire/bus

Cross-service event bus contract — pub/sub for events that leave one service and reach another.

What it does

Defines EventBus, the publish-subscribe contract used to fan domain events across deployable services. Within one service the runtime fans events to in-process actors/projections/reactions; across services those same events flow through this bus (NATS in production, in-memory in tests). Ships InMemoryEventBus for dev/tests; swap in @nwire/nats (or any other adapter) by config.

Install

pnpm add @nwire/bus

Quick start

import { InMemoryEventBus } from "@nwire/bus";
import { learnflowApp } from "@amit/learnflow";

const bus = new InMemoryEventBus();
const app = learnflowApp.create({ bus, publishToBus: true });
await app.start();
// Cross-service subscribers can now react to `learnflow.StudentWasEnrolled` etc.

API surface

  • EventBuspublish(message) + subscribe(eventName, handler) => unsubscribe.
  • InMemoryEventBus — in-process default for tests / single-service deployments.
  • BusEventMessage / BusSubscriber — wire types.

When to use

When the system is deployed as more than one process (split services, microservices).

Within nwire-app

For developers using this package as part of the Nwire stack — register it via app.use(...) or it auto-wires when you compose createApp({ modules }).

import { createApp } from "@nwire/forge";

const app = createApp({
  /* ...config... */
});
// Adapter/plugin wiring happens here when applicable.

Keywords