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

eventsourced

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventsourced

Event sourcing JavaScript entity class

  • 1.0.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

eventsourced

Build Status Coverage Status Dependency Status npm version

Event sourcing JavaScript entity class

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.

Documentation

Auto-generated API Documentation.

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. Note: 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 {
  /**
   * 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();

/**
 * Sets name to Daniel,
 * changes state, emits
 * renamed event.
 */
a.rename('Daniel');

/**
 * Sets foo to bar, changes
 * state, emits saved event.
 */
a.save();

/**
 * Does nothing, does not
 * emit event.
 */
a.touch();

Scripts

  • npm test to run one-off tests.
  • npm start to continuously run tests on every change.
  • npm run cov to see test coverage report.

Keywords

FAQs

Package last updated on 13 Sep 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