event-store
Event sourcing made easy.
Instalation
$ npm install event-store
Usage
order.js
; const id = 0; { super; thisid = id || ++id; thisamountDue = 0; thisamountPaid = 0; thisbalance = 0; } { thisamountDue = dataamountDue; this; this; } { thisamountPaid += dataamountPaid; this; this; return this; } { return thisamountDue - thisamountPaid; }
order-store.js
; { superOrder; thiscache = {}; } // We extend the get method to support // getting and storing entities to cache. { // Try to get entity from cache let order = thiscacheid; if order return ; // Call our parent get method. super; } { order; order; }
index.js
;; // creating instancesconst orderStore = Order;const order = 'abc123'; // Initialize orderorder; // Pay orderorder; // persist our order entity to the storeorderStore; // later in your code:// get order entity by id with events appliedorderStore;
API
For API usage please check event-store-entity and event-store-mongo readme files.
Run tests
$ make test
Credits
This library was inspired by the sourced project.
License
(The MIT License)
Copyright (c) 2016 Jonathan Brumley <cayasso@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.