@nwire/messages
v0.7.1
Published
Nwire — typed command and event contracts. defineCommand, defineEvent with public/internal visibility. Zod-validated; shareable across the backend, frontends, BFFs.
Readme
@nwire/messages
Command + event primitives —
defineCommand/defineEventand the message-envelope types.
What it is
Typed message primitives for the CQRS surface: defineCommand for intent (one handler, one response) and defineEvent for facts (many subscribers, fan-out). Includes the visibility/scope/outcome enums and zod-binding types every Nwire transport, bus, and store agrees on.
Install
pnpm add @nwire/messagesWithin nwire-app
For developers using this package as part of the Nwire stack. @nwire/forge's defineEvent wraps this one with extra hooks (bus republish, projection fan-out). Touch @nwire/messages directly when you need just the contracts — typically in shared kits a foreign service imports.
import { defineEvent } from "@nwire/forge"; // adds bus + projection wiring
const StudentWasEnrolled = defineEvent("StudentWasEnrolled", {
schema: z.object({ studentId: z.string(), courseId: z.string() }),
}).public();API
defineCommand(name, { schema })— intent contract; one handler, one response.defineEvent(name, { schema, scope?, visibility?, outcome? })— fact contract; many subscribers.CommandDefinition,EventDefinition,EventMessageOf,CommandPayload,EventPayload— inferred types.EventVisibility/EventScope/EventOutcome— enums (public/internal,domain/integration, success/failure tags).ServiceBootedEvent,NoopCommand— built-in baseline contracts.
