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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jbreckmckye.gitbook.io/node-ts-architecture/step-by-step/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
