# Events

{% hint style="warning" %}
This project and documentation are work in progress
{% endhint %}

{% hint style="info" %}
Example code: [src/lib/events](https://github.com/jbreckmckye/node-typescript-architecture/tree/master/src/lib/events)
{% endhint %}

Events are an optional part of the lib, used the represent the types sent over any kind of event / message bus. These event buses are passed into operations via means of the context. If your app doesn't use events, feel free to skip this folder.

Examples of event systems include a distributed message queue like AmazonMQ, or a JavaScript program that consumes your library attaching its own JS event handler functions. The lib doesn't care - all it needs to know is what events to send.

In the community library app, one such event is `BookAdded`. This will be used to tell an analytics system that the library has registered a book under a ID, and will be used to make sense of subsequent events referencing that ID.

```typescript
import { UUID } from 'io-ts-types/lib/UUID'

export type BookAdded = {
  bookId: UUID,
  name: string
}
```

Because Events aren't inputs to the system, you don't need to write IO-TS codecs for them. Plain TS types are sufficient.

You'll want to create an **index.ts** with your events imported, for further export with the lib. This allows the context adapter for your event bus to operate in a type-safe manner.
