Socket
Socket
Sign inDemoInstall

eventive

Package Overview
Dependencies
221
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eventive

![](https://img.shields.io/npm/v/eventive) ![](https://img.shields.io/npm/l/eventive) ![](https://img.shields.io/npm/dt/eventive) ![](https://img.shields.io/github/contributors/tonyfromundefined/eventive) ![](https://img.shields.io/github/last-commit/tony


Version published
Weekly downloads
17
decreased by-75%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Eventive

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: {
    // ...
  },
});

FAQs

Last updated on 25 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc