# event-sourcerer-client

> event-sourcerer client

Latest version **0.1.1** (published 2019-07-02) · 0 weekly downloads

## Install

```sh
npm install event-sourcerer-client
pnpm add event-sourcerer-client
yarn add event-sourcerer-client
bun add event-sourcerer-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2019-07-02 |
| First published | 2019-06-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | circle-pager |
| Keywords | event sourcing |

## Links

- npm: https://www.npmjs.com/package/event-sourcerer-client
- npm.io page: https://npm.io/package/event-sourcerer-client

## Dependencies (3)

- [@hapi/joi](https://npm.io/package/@hapi/joi.md) 15.x.x
- [@pager/logger](https://npm.io/package/@pager/logger.md) 5.x.x
- [@pager/jackrabbit](https://npm.io/package/@pager/jackrabbit.md) 4.x.x

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2019-07-02
- 0.1.0 — 2019-06-20

## README

# event-sourcerer-client
Event Sourcing client

This client would be in charge of handling publishing of events to the event sourcing service. 

The intent is for this client to be an abstraction over whatever protocol/transport/service we decide to use for event publishing and consumption.

## Usage Example

- Require and Initialize
```javascript
const Jackrabbit = require('jackrabbit');
const EventSourcerer = require('@pager/event-sourcerer-client');
const Client = EventSourcerer.Client;
const SingleKeyRabbitTransport = EventSourcerer.transports.SingleKeyRabbit;

const rabbit = Jackrabbit('amqp://localhost')
const transport = new SingleKeyRabbit(rabbit, { exchangeName: 'pager' })
const client = new Client(transport)
```

- Just use it to publish
```javascript
const stream = 'chats'
const streamId = '123456'
const eventType = 'created'
const data = { 'name': 'my chat' }

client.publish(stream, streamId, eventType, data)
```

## API Reference

### Client

#### `Client(transport)`

- `transport` - an instance of an object with a publish function that implements actual publishing of messages.

#### `publish(stream, streamId, eventType, data)`

- `stream` - Name identifying the type of the stream, the stream is the category name to which we publish messages, analog to a model/entity name.
- `streamId` - Identifier for a particular instance of the stream
- `eventType` - Name of the event.
- `data` - An object with fields and values for the event

### Transports

#### SingleKeyRabbitTransport

This transport can be used to publish messages to a RabbitMQ instance, under a single key by stream. The key being `events.{stream}.created`.

##### `SingleKeyRabbitTransport(rabbitConnection, options)`

- `rabbit` - Configured connection to rabbit, as the one returned by `@pager/jackrabbit` or a compatible one.
- `options` - settings:
    - `exchangeName` - name of the RabbitMQ exchange. Required.
    - `exchangeType` - Type of exchange. Optional. Possible values: `topic`, `default`. Defaults to `topic`

#### MultiKeyRabbitTransport

This transport can be used to publish messages to a RabbitMQ instance, where every event is published to it's own key. The key being `{stream}.{eventType}`.

##### `MultiKeyRabbitTransport(rabbitConnection, options)`

- `rabbit` - Configured connection to rabbit, as the one returned by `@pager/jackrabbit` or a compatible one.
- `options` - settings:
    - `exchangeName` - name of the RabbitMQ exchange. Required.
    - `exchangeType` - Type of exchange. Optional. Possible values: `topic`, `default`. Defaults to `topic`

#### MultiTransport

This transport can be used to publish messages to a RabbitMQ instance, under a single key by stream. The key being `events.{stream}.created`.

##### `SingleKeyRabbitTransport(rabbitConnection, options)`

- `rabbit` - Configured connection to rabbit, as the one returned by `@pager/jackrabbit` or a compatible one.

---
_Source: https://npm.io/package/event-sourcerer-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
