Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ddd-es-node

Package Overview
Dependencies
Maintainers
1
Versions
211
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ddd-es-node

DDD and Event Sourcing primitives for nodejs

  • 0.3.18
  • npm
  • Socket score

Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

ddd-es-node

DDD and Event Sourcing primitives for nodejs

build status npm version npm downloads

Install

npm install ddd-es-node --save

Usage

Define events.

import { EntityEvent } from "ddd-es-node";

export class OrderCancelledEvent extends EntityEvent {
}

Create domain entities.

import { Entity } from "ddd-es-node";
import { OrderCancelledEvent } from "./events";

export class Order extends Entity {
  private cancelled : boolean;
  constructor(id) {
    super(id, (self, event) => {
      if(event instanceof OrderCancelledEvent) {
        this.cancelled = true;
      }
    });
  }
  public cancel() {
    if(this.cancelled) {
      throw new Error('Order already cancelled');
    } else {
      this.dispatch(new OrderCancelledEvent());
    }
  }
}

Load entities and execute commands.

import { entityRepository } from "ddd-es-node";
import { Order } from "./orders";

export const cancelOrder = (id) : void => {
  return entityRepository
      .load(Order, id)
      .then((order : Order) => order.cancel());
};

Add event subscribers.

import { eventBus, EntityEvent } from "ddd-es-node";
import { OrderCancelledEvent } from "./events";

eventBus.subscribe((event : EntityEvent) => {
  if (event instanceof OrderCancelledEvent) {
    // do something
  }
}, { replay: true });

License

MIT

FAQs

Package last updated on 11 Sep 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc