New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

reventor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reventor

An event-driven persistence layer for the server inspired by redux.

latest
Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

Stupid-simple event sourcing.

REVENTOR

npm version GitHub license

An event-driven persistence for the application layer inspired by Redux.

Note: this currently provides an in-memory implementation, not suitable for production

createStore

const { createStore, adapters: { InMemory } } = require('reventor')

// Just like Redux, a reducer takes the previous state and a
// current event to produce the next state. This reducer will be used
// to map over a set of events for a given aggregate
function reducer (previousState = {}, event) {
  const { eventType, data } = event

  switch (eventType) {
  case 'acct:created':
    return { ...data, balance: 0 }
  case 'acct:deposit':
    return {
       ...previousState,
       balance: previousState.balance + data.amount
    }
  case 'acct:withdrawal':
    return {
       ...previousState,
       balance: previousState.balance - data.amount
    }
  }
  default:
    return previousState
  }
}

const adapter = new InMemory()
const { dispatch, getState } = createStore(adapter, reducer)

module.exports = { dispatch, getState }

dispatch

A function for dispatching events which takes a single event, or array of event objects.

dispatch({
  eventType: 'account:create'
  aggregateId: 'account:1234',
  aggregateVersion: 0,
  data: {
    owner: {
      email: 'owner@example.com',
      phone: {
        type: 'cell'
        number: '+15628675309'
      }
    }
    createdAt: Date.now(),
  }
})

getState

Get the state of an aggreaget.

getState('account:1234')

TODOs

  • Add couchdb adpater
  • Add subscribe / unsubscribe methods to store
  • Add postgres adapter
  • Implement snapshots
  • More examples
  • Monitoring / management UI

FAQs

Package last updated on 17 Apr 2019

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