New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eventsourced

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventsourced

An Event Sourcing library for Node

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Event Sourced

Build Status Coverage Status

An Event Sourcing library for Node using ES6, Immutable, NLP and some CQRS.

Combining Event Sourcing and CQRS concepts in one Entity class for node using ES6 Symbols, Proxies, Immutable and Event Emitter. One of the main goals with the Entity class is to create instances that are as clean as possible and allow users to set and get attributes as they normally would in JavaScript while automatically maintaining state, event history, etc.

Warning

Only available for Node 6. We will be adding distributions for older versions but haven't gotten around to it yet. Stay tunned.

This is very much a work in progress and not ready for use. For now, see lib/entity/entity.spec.js to get an idea of what it does.

Installation

npm i eventsourced

Notes

  • Commands change state and return undefined or null.
  • Queries return query results and do not change state.
  • When a command is executed, if it changes state and returns null or undefined, it triggers emission of its corresponding event.
  • Events are immutable.
  • Event names are in past tense.
  • This library uses NLP to compute the past tense of a command. We are considering allowing overrides to command<->event mappings.
  • This library automatically registers defined methods and emits the appropriate event (in past tense) for the command.
  • We use JS Symbols to hide internal functionality. To inspect an instance use Entity.inspect(<instance>);.

Usage

var Entity = require('eventsourced');

class MyEntity extends Entity {
  /**
   * The constructor is required now but will be removed because it makes no
   * sense in an event sourced entity.
   */
  constructor(events, options) {
    super(events, options);
    this.name = 'Luis';
    this.email = 'lgomez@example.com';
  }
  /**
   * Commands change state and return undefined or null.
   */
  rename(name) {
    this.name = name;
  }
  save() {
    this.foo = 'bar';
    return null;
  }
  /**
   * A command that does not change state does not cause an event to be emitted.
   * It is considered to be a query and not a command.
   */
  touch() {
  }
  /**
   * A query method does return something but does not change state.
   */
  myQuery() {
    return {
      type: 'query response',
      name: this.name,
      email: this.email,
    };
  }
}

const entity = new MyEntity();

a.rename('Daniel'); // Sets name to Daniel, changes state, emits renamed event.
a.save(); // Sets foo to bar, changes state, emits saved event.
a.touch(); // Does nothing, does not emit event.

Testing

One-off tests can be run as usual:

npm test

Or you can use npm start to continuously run tests on every change.

npm start

Keywords

FAQs

Package last updated on 18 May 2016

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