@nwire/app
v0.7.1
Published
Nwire — managed Container with plugin lifecycle, framework events, and DI hooks. The 'app' in the sealed architecture: composes modules + plugins, boots in order, exposes a Container, fires framework events at every lifecycle transition. Phase 69 extracti
Readme
@nwire/app
Container + plugin lifecycle + envelope.
What it does
Composes modules and plugins into a managed Container, fires typed framework events at every lifecycle transition, and propagates correlation / tracing / tenant via the envelope. definePlugin is the single extension primitive; the bus carries App* events (AppRegistering, AppBooting, AppBooted, AppReady, AppShuttingDown, AppShutdown) plus any plugins declare themselves.
Install
pnpm add @nwire/appQuick start
import { FrameworkEventBus, AppBooted, defineFrameworkEvent } from "@nwire/app";
import { NoopLogger } from "@nwire/logger";
const bus = new FrameworkEventBus(new NoopLogger());
bus.on(AppBooted, async ({ appName, bootedAt }) => {
console.log(`${appName} booted at ${bootedAt}`);
});
const TenantSwitched = defineFrameworkEvent<{ tenantId: string }>(
"app.tenant-switched",
"parallel",
);
bus.on(TenantSwitched, ({ tenantId }) => console.log(`switched to ${tenantId}`));
await bus.fire(TenantSwitched, { tenantId: "acme" });API surface
defineFrameworkEvent<TPayload>(name, mode)— declare a typed lifecycle event.FrameworkEventBus— typed dispatcher; one per app instance.AppRegistering/AppBooting/AppBooted/AppReady/AppShuttingDown/AppShutdown— built-in lifecycle events.definePlugin(name, setup)— closure-form plugin withbind/provide/on/before/after/middleware/boot/shutdown.- Dispatch modes —
parallel(*-ed, fire-and-forget),series(sequential await),series-bail(*-ing, vetoable).
When to use
The composition root for any non-trivial Nwire app. Standalone: use framework events as a generic typed pub/sub for any lifecycle. Full-stack: pair with @nwire/forge and the bus carries ActionDispatching / ActionCompleted / ActionFailed alongside lifecycle events.
