Skip to content

A bit of Event Sourcing with just a sprinkle of Blockchain

License

Notifications You must be signed in to change notification settings

ryanbonial/event-chain

Repository files navigation

🕰️⛓️ Event Chain ⛓️🕰️

Event Chain is a JS library for storing sequential events and validating them using a hash.

Usage

Create an Event Chain

var EventChain = require('./EventChain');
const eventChain = new EventChain();

Add events

eventChain.AddEvent("MOVIE_CREATE", { id: 1, title: 'Hackers', released: '1995' });

eventChain.AddEvent("MOVIE_UPDATE_RATING", { id: 1, mpaaRating: 'PG-13' });

Example Event Chain

[
  {
     "eventType": "MOVIE_CREATE",
     "data": {
        "id": 1,
        "title": "Hackers",
        "released": "1995"
     },
     "metaData": {
        "createdBy": "Ryan",
        "createdDate": "2020-03-25T20:44:19.556Z",
        "previousHash": "0"
     },
     "id": "208a6a89-0ea5-435c-8a75-cffcb06f0101",
     "hash": "043sZA57xXKoJPC6vyMSk1DA9Uyv07kvqxeqATWIR1Q="
  },
  {
     "eventType": "MOVIE_UPDATE_RATING",
     "data": {
        "id": 1,
        "mpaaRating": "PG-13"
     },
     "metaData": {
        "createdBy": "Ryan",
        "createdDate": "2020-03-25T20:44:19.568Z",
        "previousHash": "043sZA57xXKoJPC6vyMSk1DA9Uyv07kvqxeqATWIR1Q="
     },
     "id": "edbf81c3-d135-4098-8e78-57a2267148e0",
     "hash": "B3GCqf1W7PTOv00IaJL6mDHtkI0BJdm6uKtse+E8al8="
  }
]

Get an object projection

eventChain.GetProjection('MOVIE', 1) // { id: 1, title: 'Hackers', released: '1995', mpaaRating: 'PG-13' }

More on Event Sourcing

Martin Fowler - https://martinfowler.com/eaaDev/EventSourcing.html

GOTO 2014 • Event Sourcing • Greg Young - https://www.youtube.com/watch?v=8JKjvY4etTY

About

A bit of Event Sourcing with just a sprinkle of Blockchain

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published