Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "demux-js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Julien Heller", |
121
README.md
@@ -1,120 +0,3 @@ | ||
# demux-js [![Build Status](https://travis-ci.org/EOSIO/demux-js.svg?branch=develop)](https://travis-ci.org/EOSIO/demux-js) | ||
# DEPRECATED | ||
Demux is a backend infrastructure pattern for sourcing blockchain events to deterministically update queryable datastores and trigger side effects. This library serves as a reference implementation of that pattern for use with Node applications. | ||
## Installation | ||
```bash | ||
# Using yarn | ||
yarn add demux-js | ||
# Using npm | ||
npm install demux-js --save | ||
``` | ||
## Overview | ||
Taking inspiration from the [Flux Architecture](https://facebook.github.io/flux/docs/in-depth-overview.html#content) pattern and [Redux](https://github.com/reduxjs/redux/), Demux was born out of the following qualifications: | ||
1. A separation of concerns between how state exists on the blockchain and how it is queried by the client front-end | ||
1. Client front-end not solely responsible for determining derived, reduced, and/or accumulated state | ||
1. Ability for blockchain events to trigger new transactions, as well as other side effects outside of the blockchain | ||
1. The blockchain as the single source of truth for all application state | ||
### Separated Persistence Layer | ||
Storing data in indexed state on blockchains can be useful for three reasons: decentralized consensus of computation results, usage of state from within other blockchain computations, and for retrieval of state for use in client front-ends. When building more complicated front-ends, you run into a few problems when retrieving directly from indexed blockchain state: | ||
* The query interface used to retrieve the indexed data is limited. Complex data requirements can mean you either have to make an excess number of queries and process the data on the client, or you must store additional derivative data on the blockchain itself. | ||
* Scaling your query load means creating more blockchain endpoint nodes, which can be very expensive. | ||
Demux solves these problems by off-loading queries to any persistence layer that you want. As blockchain events happen, your chosen persistence layer is updated by `updater` functions, which deterministically process an array of `Action` objects. The persistence layer can then be queried by your front-end through a suitable API (for example, REST or GraphQL). | ||
This means that we can separate our concerns: for data that needs decentralized consensus of computation or access from other blockchain events, we can still store the data in indexed blockchain state, without having to worry about tailoring to front-end queries. For data required by our front-end, we can pre-process and index data in a way that makes it easy for it to be queried, in a horizontally scalable persistence layer of our choice. The end result is that both systems can serve their purpose more effectively. | ||
### Side Effects | ||
Since we have a system for acting upon specific blockchain events deterministically, we can utilize this system to manage non-deterministic events as well. These `effect` functions work almost exactly the same as `updater` functions, except they run asynchronously, are not run during replays, and modifying the deterministic datastore is off-limits. Examples include: signing and broadcasting a transaction, sending an email, and initiating a traditional fiat payment. | ||
### Single Source of Truth | ||
There are other solutions to the above problems that involve legacy persistence layers that are their own sources of truth. By deriving all state from the blockchain, however, we gain the following benefits: | ||
* If the accumulated datastore is lost or deleted, it may be regenerated by replaying blockchain actions | ||
* As long as application code is open source, and the blockchain is public, all application state can be audited | ||
* No need to maintain multiple ways of updating state (submitting transactions is the sole way) | ||
## Data Flow | ||
<img src='https://i.imgur.com/MFfGOe3.png' height='492' alt='Demux Logo' /> | ||
1. Client sends transaction to blockchain | ||
1. Action Watcher invokes Action Reader to check for new blocks | ||
1. Action Reader sees transaction in new block, parses actions | ||
1. Action Watcher sends actions to Action Handler | ||
1. Action Handler processes actions through Updaters and Effects | ||
1. Actions run their corresponding Updaters, updating the state of the Datastore | ||
1. Actions run their corresponding Effects, triggering external events | ||
1. Client queries API for updated data | ||
## Usage | ||
This library provides the following classes: | ||
* [**`AbstractActionReader`**](https://eosio.github.io/demux-js/classes/abstractactionreader.html): Abstract class used for implementing your own Action Readers | ||
* [**`AbstractActionHandler`**](https://eosio.github.io/demux-js/classes/abstractactionhandler.html): Abstract class used for implementing your own Action Handlers | ||
* [**`BaseActionWatcher`**](https://eosio.github.io/demux-js/classes/baseactionwatcher.html): Base class that implements a ready-to-use Action Watcher | ||
#### [**View full API documentation here.**](https://eosio.github.io/demux-js/) | ||
## Class Implementations | ||
Repository | Description | ||
---|--- | ||
[EOSIO / demux-js-eos](https://github.com/EOSIO/demux-js-eos) * | Action Reader implementations for EOSIO blockchains | ||
[EOSIO / demux-js-postgres](https://github.com/EOSIO/demux-js-postgres) * | Action Handler implementation for Postgres databases | ||
*\* Officially supported by Block.one* | ||
To get your project listed, add it here and submit a PR! | ||
## Example | ||
```js | ||
// Let's read from an EOS node | ||
const { NodeosActionReader } = require("demux-eos") | ||
// Assuming you've created your own subclass of AbstractActionHandler | ||
const MyActionHandler = require("./MyActionHandler") | ||
// Ties everything together in a polling loop | ||
const { BaseActionWatcher } = require("demux-js") | ||
// Import Updaters and Effects, which are arrays of objects: | ||
// [ { actionType: string, (updater|effect): function }, ... ] | ||
const updaters = require("./updaters") | ||
const effects = require("./effects") | ||
const actionReader = new NodeosActionReader( | ||
"http://some-nodeos-endpoint:8888", // Locally hosted node needed for reasonable indexing speed | ||
12345678, // First actions relevant to this dapp happen at this block | ||
) | ||
const actionHandler = new MyActionHandler( | ||
updaters, | ||
effects, | ||
) | ||
const actionWatcher = new BaseActionWatcher( | ||
actionReader, | ||
actionHandler, | ||
250, // Poll at twice the block interval for less latency | ||
) | ||
actionWatcher.watch() // Start watch loop | ||
``` | ||
For more complete examples, [see the examples directory](examples/). | ||
This project has been renamed to `demux`. Install using `demux` instead. |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
1
453778
32
563
4