# @nwire/messages

> Command + event primitives — `defineCommand` / `defineEvent` and 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

```bash
pnpm add @nwire/messages
```

## Within 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.

```ts
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.
