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 - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

60

lib/entity/entity.spec.js
const Entity = require('.');
const tap = require('tap');
const fixtures = {
a: {
name: 'Luis',
email: 'l@example.com',
},
b: {
name: 'Daniel',
email: 'd@example.com',
},
};
const testname = 'Luis';
let state = null;

@@ -33,40 +25,42 @@ class TestEntity extends Entity {

const instance = new TestEntity();
const i = new TestEntity();
tap.equals(Entity.inspect(instance).version, 0, 'Version should be 0.');
tap.equals(Entity.inspect(i).version, 0, 'Version should be 0.');
instance.on('renamed', () => {
i.on('renamed', () => {
state = Entity.inspect(i);
tap.pass('Should emit "renamed" event');
tap.equals(Entity.inspect(instance).version, 1, 'Version should be 1.');
tap.equals(instance.name, fixtures.b.name, `Name should be ${fixtures.b.name}.`);
tap.equals(state.version, 1, 'Version should be 1.');
tap.equals(i.name, testname, `Name should be ${testname}.`);
});
instance.rename(fixtures.b.name);
i.rename(testname);
instance.save();
tap.equals(Entity.inspect(instance).version, 2, 'Version should be 2.');
tap.equals(Entity.inspect(instance).history.length, 2, 'History should contain 2 entries.');
i.save();
state = Entity.inspect(i);
tap.equals(state.version, 2, 'Version should be 2.');
tap.equals(state.history.length, 2, 'History should contain 2 entries.');
instance.touch();
tap.equals(Entity.inspect(instance).version, 2, 'Version should be 2.');
tap.equals(Entity.inspect(instance).history.length, 2, 'History should contain 2 entries.');
i.touch();
state = Entity.inspect(i);
tap.equals(state.version, 2, 'Version should be 2.');
tap.equals(state.history.length, 2, 'History should contain 2 entries.');
tap.same(Entity.snapshot(instance), {
name: fixtures.b.name,
foo: 'bar',
}, 'Snapshot should contain expected data.');
const snapshot = Entity.snapshot(i);
const expected = { name: testname, foo: 'bar' };
tap.same(snapshot, expected, 'Snapshot should contain expected data.');
tap.test('Manually registering a command', t => {
Entity.registerCommand(instance, 'fix', function cmd() {
Entity.registerCommand(i, 'fix', function cmd() {
this.fixed = true;
});
const cmdInRegistry = (Entity.getRegisteredCommandsOf(instance).indexOf('fix') > -1);
const cmdInRegistry = (Entity.getRegisteredCommandsOf(i).indexOf('fix') > -1);
t.ok(cmdInRegistry, 'Successfully registers a command.');
instance.on('fixed', () => {
i.on('fixed', () => {
state = Entity.inspect(i);
t.pass('Command fires expected event.');
t.equals(Entity.inspect(instance).version, 3, 'Command increases version.');
t.equals(instance.fixed, true, 'Command changes state.');
t.equals(state.version, 3, 'Command increases version.');
t.equals(i.fixed, true, 'Command changes state.');
t.end();
});
instance.fix();
i.fix();
});
{
"name": "eventsourced",
"version": "1.0.7",
"description": "An Event Sourcing library for Node",
"version": "1.0.8",
"description": "An Event Sourcing library for Node using ES6, Immutable, NLP and some CQRS.",
"main": "index.js",

@@ -6,0 +6,0 @@ "directories": {

@@ -28,3 +28,3 @@ # Event Sourced

* 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 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.

@@ -40,3 +40,4 @@ * We use JS Symbols to hide internal functionality. To inspect an instance use `Entity.inspect(<instance>);`.

/**
* Commands change state and return undefined or null.
* Commands change state
* and return undefined or null.
*/

@@ -51,4 +52,6 @@ rename(name) {

/**
* 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.
* 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.
*/

@@ -58,3 +61,5 @@ touch() {

/**
* A query method does return something but does not change state.
* A query method does return
* something but does not change
* state.
*/

@@ -72,5 +77,20 @@ myQuery() {

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.
/**
* 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();
```

@@ -77,0 +97,0 @@

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