1.0.0 • Published 7 days ago

eventive v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 days ago

Eventive

npm.io npm.io npm.io npm.io npm.io

Event Sourcing Framework in MongoDB

Getting Started

$ yarn add mongodb eventive

Setup

1. Define Domain Model

type MyDomainEvent =
  | BaseDomainEvent<
      "init",
      {
        // ...
      }
    >
  | BaseDomainEvent<
      "update",
      {
        // ...
      }
    >;

2. Define my state

type MyState = {
  // ...
};

3. Implement my business logic clearly in reducer

import { BaseReducer } from "eventive";

const reducer: BaseReducer<MyDomainEvent, MyState> = (prevState, event) => {
  // ...

  return nextState;
};

4. Maps older revision events to newer event interfaces for backwards compatibility

import { BaseMapper } from "eventive";

const mapper: BaseMapper<MyDomainEvent> = (event) => {
  // ...

  return currentRevisionEvent;
};

5. Then, eventive automatically make common repository interface

import { eventive } from "eventive";
import { MongoClient } from "mongodb";

const mongoClient = new MongoClient();
const db = mongoClient.db("my_database");

const myRepository = eventive({
  db,
  entityName: "MyModel",
  reducer,
  mapper,
  dbCollectionName: "events", // optional
});

Usage

all()

/**
 * Scan all entities
 */
myRepository.all();

findOne()

/**
 * Find one entity with `entityId`
 */
myRepository.findOne({
  entityId: "...",
});

batchGet()

/**
 * Find many entities with `entityIds`
 */
myRepository.batchGet({
  entityIds: ["...", "..."],
});

create()

/**
 * Create entity with initial DomainEvent
 */
const { commit } = myRepository.create({
  eventName: "init",
  eventBody: {
    // ...
  },
});

dispatch()

/**
 * Dispatch DomainEvent to entity
 */
const { commit } = myRepository.dispatch({
  entity,
  eventName: "edit",
  eventBody: {
    // ...
  },
});
1.0.0

7 days ago

0.13.0

22 days ago

0.12.0

1 month ago

0.11.0

1 month ago

0.10.0

4 months ago

0.9.0

6 months ago

0.8.0

7 months ago

0.7.0

7 months ago

0.6.0

7 months ago

0.5.0

7 months ago

0.4.0

9 months ago

0.3.0

1 year ago

0.2.3

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago