Comparing version 3.1.4-431ae7e.0 to 3.1.4-4e25e05.0
@@ -1,3 +0,3 @@ | ||
import * as Logger from "bunyan"; | ||
import { Block, HandlerInfo, HandlerVersion, IndexState, NextBlock, VersionedAction } from "./interfaces"; | ||
import * as Logger from 'bunyan'; | ||
import { Block, HandlerInfo, HandlerVersion, IndexState, NextBlock, VersionedAction } from './interfaces'; | ||
/** | ||
@@ -15,2 +15,3 @@ * Takes `block`s output from implementations of `AbstractActionReader` and processes their actions through the | ||
protected log: Logger; | ||
protected initialized: boolean; | ||
private deferredEffects; | ||
@@ -32,2 +33,6 @@ private handlerVersionMap; | ||
/** | ||
* Performs all required initialization for the handler. | ||
*/ | ||
initialize(): Promise<void>; | ||
/** | ||
* Updates the `lastProcessedBlockNumber` and `lastProcessedBlockHash` meta state, coinciding with the block | ||
@@ -51,2 +56,6 @@ * that has just been processed. These are the same values read by `updateIndexState()`. | ||
/** | ||
* Idempotently performs any required setup. | ||
*/ | ||
protected abstract setup(): Promise<void>; | ||
/** | ||
* This method is used when matching the types of incoming actions against the types the `Updater`s and `Effect`s are | ||
@@ -83,2 +92,3 @@ * subscribed to. When this returns true, their corresponding functions will run. | ||
protected handleActions(state: any, context: any, nextBlock: NextBlock, isReplay: boolean): Promise<void>; | ||
private handleRollback; | ||
private range; | ||
@@ -88,2 +98,3 @@ private runOrDeferEffect; | ||
private getNextDeferredBlockNumber; | ||
private rollbackDeferredEffects; | ||
private initHandlerVersions; | ||
@@ -90,0 +101,0 @@ private refreshIndexState; |
@@ -19,2 +19,3 @@ "use strict"; | ||
const Logger = __importStar(require("bunyan")); | ||
const errors_1 = require("./errors"); | ||
/** | ||
@@ -34,8 +35,9 @@ * Takes `block`s output from implementations of `AbstractActionReader` and processes their actions through the | ||
this.lastProcessedBlockNumber = 0; | ||
this.lastProcessedBlockHash = ""; | ||
this.handlerVersionName = "v1"; | ||
this.lastProcessedBlockHash = ''; | ||
this.handlerVersionName = 'v1'; | ||
this.initialized = false; | ||
this.deferredEffects = {}; | ||
this.handlerVersionMap = {}; | ||
this.initHandlerVersions(handlerVersions); | ||
this.log = Logger.createLogger({ name: "demux" }); | ||
this.log = Logger.createLogger({ name: 'demux' }); | ||
} | ||
@@ -50,12 +52,7 @@ /** | ||
const { isRollback, isEarliestBlock } = blockMeta; | ||
if (isRollback || (isReplay && isEarliestBlock)) { | ||
const rollbackBlockNumber = blockInfo.blockNumber - 1; | ||
const rollbackCount = this.lastProcessedBlockNumber - rollbackBlockNumber; | ||
this.log.info(`Rolling back ${rollbackCount} blocks to block ${rollbackBlockNumber}...`); | ||
yield this.rollbackTo(rollbackBlockNumber); | ||
yield this.refreshIndexState(); | ||
if (!this.initialized) { | ||
yield this.initialize(); | ||
this.initialized = true; | ||
} | ||
else if (this.lastProcessedBlockNumber === 0 && this.lastProcessedBlockHash === "") { | ||
yield this.refreshIndexState(); | ||
} | ||
yield this.handleRollback(isRollback, blockInfo.blockNumber, isReplay, isEarliestBlock); | ||
const nextBlockNeeded = this.lastProcessedBlockNumber + 1; | ||
@@ -78,3 +75,4 @@ // Just processed this block; skip | ||
if (blockInfo.previousBlockHash !== this.lastProcessedBlockHash) { | ||
throw Error("Block hashes do not match; block not part of current chain."); | ||
const err = new errors_1.MismatchedBlockHashError(); | ||
throw err; | ||
} | ||
@@ -100,2 +98,11 @@ } | ||
/** | ||
* Performs all required initialization for the handler. | ||
*/ | ||
initialize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.setup(); | ||
yield this.refreshIndexState(); | ||
}); | ||
} | ||
/** | ||
* This method is used when matching the types of incoming actions against the types the `Updater`s and `Effect`s are | ||
@@ -179,2 +186,17 @@ * subscribed to. When this returns true, their corresponding functions will run. | ||
} | ||
handleRollback(isRollback, blockNumber, isReplay, isEarliestBlock) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (isRollback || (isReplay && isEarliestBlock)) { | ||
const rollbackBlockNumber = blockNumber - 1; | ||
const rollbackCount = this.lastProcessedBlockNumber - rollbackBlockNumber; | ||
this.log.info(`Rolling back ${rollbackCount} blocks to block ${rollbackBlockNumber}...`); | ||
yield this.rollbackTo(rollbackBlockNumber); | ||
this.rollbackDeferredEffects(blockNumber); | ||
yield this.refreshIndexState(); | ||
} | ||
else if (this.lastProcessedBlockNumber === 0 && this.lastProcessedBlockHash === '') { | ||
yield this.refreshIndexState(); | ||
} | ||
}); | ||
} | ||
range(start, end) { | ||
@@ -185,2 +207,3 @@ return Array(end - start).fill(0).map((_, i) => i + start); | ||
const { block, lastIrreversibleBlockNumber } = nextBlock; | ||
const { blockNumber } = block.blockInfo; | ||
const shouldRunImmediately = (!effect.deferUntilIrreversible || block.blockInfo.blockNumber <= lastIrreversibleBlockNumber); | ||
@@ -190,7 +213,7 @@ if (shouldRunImmediately) { | ||
} | ||
else if (!this.deferredEffects[block.blockInfo.blockNumber]) { | ||
this.deferredEffects[block.blockInfo.blockNumber] = [() => effect.run(payload, block, context)]; | ||
} | ||
else { | ||
this.deferredEffects[block.blockInfo.blockNumber].push(() => effect.run(payload, block, context)); | ||
if (!this.deferredEffects[blockNumber]) { | ||
this.deferredEffects[blockNumber] = []; | ||
} | ||
this.deferredEffects[blockNumber].push(() => effect.run(payload, block, context)); | ||
} | ||
@@ -205,3 +228,4 @@ } | ||
if (this.deferredEffects[blockNumber]) { | ||
for (const deferredEffect of this.deferredEffects[blockNumber]) { | ||
const effects = this.deferredEffects[blockNumber]; | ||
for (const deferredEffect of effects) { | ||
deferredEffect(); | ||
@@ -220,10 +244,16 @@ } | ||
} | ||
rollbackDeferredEffects(rollbackTo) { | ||
const blockNumbers = Object.keys(this.deferredEffects).map((num) => parseInt(num, 10)); | ||
const toRollBack = blockNumbers.filter((bn) => bn >= rollbackTo); | ||
for (const blockNumber of toRollBack) { | ||
delete this.deferredEffects[blockNumber]; | ||
} | ||
} | ||
initHandlerVersions(handlerVersions) { | ||
if (handlerVersions.length === 0) { | ||
throw new Error("Must have at least one handler version."); | ||
throw new errors_1.MissingHandlerVersionError(); | ||
} | ||
for (const handlerVersion of handlerVersions) { | ||
if (this.handlerVersionMap.hasOwnProperty(handlerVersion.versionName)) { | ||
throw new Error(`Handler version name '${handlerVersion.versionName}' already exists. ` + | ||
"Handler versions must have unique names."); | ||
throw new errors_1.DuplicateHandlerVersionError(handlerVersion.versionName); | ||
} | ||
@@ -236,3 +266,3 @@ this.handlerVersionMap[handlerVersion.versionName] = handlerVersion; | ||
} | ||
else if (handlerVersions[0].versionName !== "v1") { | ||
else if (handlerVersions[0].versionName !== 'v1') { | ||
this.warnIncorrectFirstHandler(handlerVersions[0].versionName); | ||
@@ -272,1 +302,2 @@ } | ||
exports.AbstractActionHandler = AbstractActionHandler; | ||
//# sourceMappingURL=AbstractActionHandler.js.map |
@@ -1,3 +0,3 @@ | ||
import * as Logger from "bunyan"; | ||
import { ActionReaderOptions, Block, NextBlock, ReaderInfo } from "./interfaces"; | ||
import * as Logger from 'bunyan'; | ||
import { ActionReaderOptions, Block, NextBlock, ReaderInfo } from './interfaces'; | ||
/** | ||
@@ -15,3 +15,3 @@ * Reads blocks from a blockchain, outputting normalized `Block` objects. | ||
protected log: Logger; | ||
private initialized; | ||
protected initialized: boolean; | ||
constructor(options?: ActionReaderOptions); | ||
@@ -41,2 +41,6 @@ /** | ||
/** | ||
* Performs all required initialization for the reader. | ||
*/ | ||
initialize(): Promise<void>; | ||
/** | ||
* Changes the state of the `AbstractActionReader` instance to have just processed the block at the given block | ||
@@ -54,2 +58,6 @@ * number. If the block exists in its temporary block history, it will use this, otherwise it will fetch the block | ||
/** | ||
* Idempotently performs any required setup. | ||
*/ | ||
protected abstract setup(): Promise<void>; | ||
/** | ||
* Incrementally rolls back reader state one block at a time, comparing the blockHistory with | ||
@@ -56,0 +64,0 @@ * newly fetched blocks. Fork resolution is finished when either the current block's previous hash |
@@ -19,7 +19,8 @@ "use strict"; | ||
const Logger = __importStar(require("bunyan")); | ||
const errors_1 = require("./errors"); | ||
const defaultBlock = { | ||
blockInfo: { | ||
blockNumber: 0, | ||
blockHash: "", | ||
previousBlockHash: "", | ||
blockHash: '', | ||
previousBlockHash: '', | ||
timestamp: new Date(0), | ||
@@ -43,3 +44,3 @@ }, | ||
this.onlyIrreversible = optionsWithDefaults.onlyIrreversible; | ||
this.log = Logger.createLogger({ name: "demux" }); | ||
this.log = Logger.createLogger({ name: 'demux' }); | ||
} | ||
@@ -60,6 +61,5 @@ /** | ||
}; | ||
// TODO: Should this only be called when updating headBlockNumber? | ||
this.lastIrreversibleBlockNumber = yield this.getLastIrreversibleBlockNumber(); | ||
if (!this.initialized) { | ||
yield this.initBlockState(); | ||
yield this.initialize(); | ||
} | ||
@@ -97,2 +97,12 @@ if (this.currentBlockNumber === this.headBlockNumber) { | ||
/** | ||
* Performs all required initialization for the reader. | ||
*/ | ||
initialize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.setup(); | ||
yield this.initBlockState(); | ||
this.initialized = true; | ||
}); | ||
} | ||
/** | ||
* Changes the state of the `AbstractActionReader` instance to have just processed the block at the given block | ||
@@ -108,6 +118,6 @@ * number. If the block exists in its temporary block history, it will use this, otherwise it will fetch the block | ||
if (blockNumber < this.startAtBlock) { | ||
throw new Error("Cannot seek to block before configured `startAtBlock` number."); | ||
throw new errors_1.ImproperStartAtBlockError(); | ||
} | ||
if (blockNumber > this.headBlockNumber) { | ||
throw new Error(`Cannot seek to block number ${blockNumber} as it does not exist yet.`); | ||
throw new errors_1.ImproperSeekToBlockError(blockNumber); | ||
} | ||
@@ -166,2 +176,3 @@ this.currentBlockNumber = blockNumber - 1; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.lastIrreversibleBlockNumber = yield this.getLastIrreversibleBlockNumber(); | ||
this.headBlockNumber = yield this.getLatestNeededBlockNumber(); | ||
@@ -173,3 +184,2 @@ if (this.currentBlockNumber < 0) { | ||
yield this.reloadHistory(); | ||
this.initialized = true; | ||
}); | ||
@@ -251,3 +261,3 @@ } | ||
if (tryCount === maxTries) { | ||
throw new Error("Could not reload history."); | ||
throw new errors_1.ReloadHistoryError(); | ||
} | ||
@@ -261,3 +271,3 @@ } | ||
if (this.currentBlockData.blockInfo.blockNumber < this.lastIrreversibleBlockNumber && checkIrreversiblility) { | ||
throw new Error("Last irreversible block has been passed without resolving fork"); | ||
throw new errors_1.UnresolvedForkError(); | ||
} | ||
@@ -268,3 +278,3 @@ this.blockHistory.push(yield this.getBlock(this.currentBlockData.blockInfo.blockNumber - 1)); | ||
logForkDetected(unvalidatedBlockData, expectedHash, actualHash) { | ||
this.log.info("!! FORK DETECTED !!"); | ||
this.log.info('!! FORK DETECTED !!'); | ||
this.log.info(` MISMATCH:`); | ||
@@ -275,9 +285,9 @@ this.log.info(` ✓ NEW Block ${unvalidatedBlockData.blockInfo.blockNumber} previous: ${actualHash}`); | ||
logForkResolved(currentBlockInfo, previousBlockInfo) { | ||
this.log.info(" MATCH:"); | ||
this.log.info(' MATCH:'); | ||
this.log.info(` ✓ NEW Block ${currentBlockInfo.blockNumber} previous: ${currentBlockInfo.previousBlockHash}`); // tslint:disable-line | ||
this.log.info(` ✓ OLD Block ${previousBlockInfo.blockNumber} id: ${previousBlockInfo.blockHash}`); | ||
this.log.info("!! FORK RESOLVED !!"); | ||
this.log.info('!! FORK RESOLVED !!'); | ||
} | ||
logForkMismatch(currentBlockInfo, previousBlockInfo) { | ||
this.log.info(" MISMATCH:"); | ||
this.log.info(' MISMATCH:'); | ||
this.log.info(` ✓ NEW Block ${currentBlockInfo.blockNumber} previous: ${currentBlockInfo.previousBlockHash}`); | ||
@@ -288,1 +298,2 @@ this.log.info(` ✕ OLD Block ${previousBlockInfo.blockNumber} id: ${previousBlockInfo.blockHash}`); | ||
exports.AbstractActionReader = AbstractActionReader; | ||
//# sourceMappingURL=AbstractActionReader.js.map |
@@ -1,5 +0,5 @@ | ||
import * as Logger from "bunyan"; | ||
import { AbstractActionHandler } from "./AbstractActionHandler"; | ||
import { AbstractActionReader } from "./AbstractActionReader"; | ||
import { DemuxInfo } from "./interfaces"; | ||
import * as Logger from 'bunyan'; | ||
import { AbstractActionHandler } from './AbstractActionHandler'; | ||
import { AbstractActionReader } from './AbstractActionReader'; | ||
import { DemuxInfo } from './interfaces'; | ||
/** | ||
@@ -22,2 +22,3 @@ * Coordinates implementations of `AbstractActionReader`s and `AbstractActionHandler`s in | ||
private error; | ||
private clean; | ||
constructor(actionReader: AbstractActionReader, actionHandler: AbstractActionHandler, pollInterval: number); | ||
@@ -52,2 +53,3 @@ /** | ||
protected checkForBlocks(isReplay?: boolean): Promise<void>; | ||
private readonly status; | ||
} |
@@ -19,2 +19,3 @@ "use strict"; | ||
const Logger = __importStar(require("bunyan")); | ||
const interfaces_1 = require("./interfaces"); | ||
/** | ||
@@ -32,3 +33,4 @@ * Coordinates implementations of `AbstractActionReader`s and `AbstractActionHandler`s in | ||
this.error = null; | ||
this.log = Logger.createLogger({ name: "demux" }); | ||
this.clean = true; | ||
this.log = Logger.createLogger({ name: 'demux' }); | ||
} | ||
@@ -53,5 +55,6 @@ /** | ||
this.shouldPause = false; | ||
this.log.info("Indexing paused."); | ||
this.log.info('Indexing paused.'); | ||
return; | ||
} | ||
this.clean = false; | ||
this.running = true; | ||
@@ -68,3 +71,3 @@ this.error = null; | ||
this.error = err; | ||
this.log.info("Indexing unexpectedly paused due to an error."); | ||
this.log.info('Indexing unexpectedly paused due to an error.'); | ||
return; | ||
@@ -86,6 +89,7 @@ } | ||
if (this.running) { | ||
this.log.info("Cannot start; already indexing."); | ||
this.log.info('Cannot start; already indexing.'); | ||
return false; | ||
} | ||
this.log.info("Starting indexing."); | ||
this.log.info('Starting indexing.'); | ||
// tslint:disable-next-line:no-floating-promises | ||
this.watch(); | ||
@@ -99,6 +103,6 @@ return true; | ||
if (!this.running) { | ||
this.log.info("Cannot pause; not currently indexing."); | ||
this.log.info('Cannot pause; not currently indexing.'); | ||
return false; | ||
} | ||
this.log.info("Pausing indexing."); | ||
this.log.info('Pausing indexing.'); | ||
this.shouldPause = true; | ||
@@ -111,16 +115,6 @@ return true; | ||
get info() { | ||
let status; | ||
if (this.running && !this.shouldPause) { | ||
status = "indexing"; | ||
} | ||
else if (this.running && this.shouldPause) { | ||
status = "pausing"; | ||
} | ||
else { | ||
status = "paused"; | ||
} | ||
const info = { | ||
handler: this.actionHandler.info, | ||
reader: this.actionReader.info, | ||
status, | ||
indexingStatus: this.status, | ||
}; | ||
@@ -150,3 +144,3 @@ if (this.error) { | ||
if (nextBlockNumberNeeded) { | ||
yield this.actionReader.seekToBlock(nextBlockNumberNeeded - 1); | ||
yield this.actionReader.seekToBlock(nextBlockNumberNeeded); | ||
} | ||
@@ -157,3 +151,19 @@ headBlockNumber = this.actionReader.headBlockNumber; | ||
} | ||
get status() { | ||
if (this.clean) { | ||
return interfaces_1.IndexingStatus.Initial; | ||
} | ||
if (this.running && !this.shouldPause) { | ||
return interfaces_1.IndexingStatus.Indexing; | ||
} | ||
if (this.running && this.shouldPause) { | ||
return interfaces_1.IndexingStatus.Pausing; | ||
} | ||
if (this.error) { | ||
return interfaces_1.IndexingStatus.Stopped; | ||
} | ||
return interfaces_1.IndexingStatus.Paused; | ||
} | ||
} | ||
exports.BaseActionWatcher = BaseActionWatcher; | ||
//# sourceMappingURL=BaseActionWatcher.js.map |
@@ -1,4 +0,4 @@ | ||
import { AbstractActionHandler } from "./AbstractActionHandler"; | ||
import { AbstractActionReader } from "./AbstractActionReader"; | ||
import { BaseActionWatcher } from "./BaseActionWatcher"; | ||
import { AbstractActionHandler } from './AbstractActionHandler'; | ||
import { AbstractActionReader } from './AbstractActionReader'; | ||
import { BaseActionWatcher } from './BaseActionWatcher'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Exposes the BaseActionWatcher's API methods through a simple REST interface using Express |
@@ -31,9 +31,9 @@ "use strict"; | ||
this.server = null; | ||
this.express.get("/info", (_, res) => { | ||
this.express.get('/info', (_, res) => { | ||
res.json(this.info); | ||
}); | ||
this.express.post("/start", (_, res) => { | ||
this.express.post('/start', (_, res) => { | ||
res.json({ success: this.start() }); | ||
}); | ||
this.express.post("/pause", (_, res) => { | ||
this.express.post('/pause', (_, res) => { | ||
res.json({ success: this.pause() }); | ||
@@ -73,1 +73,2 @@ }); | ||
exports.ExpressActionWatcher = ExpressActionWatcher; | ||
//# sourceMappingURL=ExpressActionWatcher.js.map |
@@ -1,5 +0,6 @@ | ||
export { Action, Block, BlockInfo, Effect, HandlerVersion, IndexState, Updater } from "./interfaces"; | ||
export { AbstractActionHandler } from "./AbstractActionHandler"; | ||
export { AbstractActionReader } from "./AbstractActionReader"; | ||
export { BaseActionWatcher } from "./BaseActionWatcher"; | ||
export { ExpressActionWatcher } from "./ExpressActionWatcher"; | ||
export { AbstractActionHandler } from './AbstractActionHandler'; | ||
export { AbstractActionReader } from './AbstractActionReader'; | ||
export { BaseActionWatcher } from './BaseActionWatcher'; | ||
export { ExpressActionWatcher } from './ExpressActionWatcher'; | ||
export * from './interfaces'; | ||
export * from './errors'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -11,1 +14,4 @@ var AbstractActionHandler_1 = require("./AbstractActionHandler"); | ||
exports.ExpressActionWatcher = ExpressActionWatcher_1.ExpressActionWatcher; | ||
__export(require("./interfaces")); | ||
__export(require("./errors")); | ||
//# sourceMappingURL=index.js.map |
@@ -15,7 +15,2 @@ export interface ActionReaderOptions { | ||
onlyIrreversible?: boolean; | ||
/** | ||
* This determines how many blocks in the past are cached. This is used for determining | ||
* block validity during both normal operation and when rolling back. | ||
*/ | ||
maxHistoryLength?: number; | ||
} | ||
@@ -91,4 +86,11 @@ export interface Block { | ||
} | ||
export declare enum IndexingStatus { | ||
Initial = "initial", | ||
Indexing = "indexing", | ||
Pausing = "pausing", | ||
Paused = "paused", | ||
Stopped = "stopped" | ||
} | ||
export interface DemuxInfo { | ||
status: string; | ||
indexingStatus: IndexingStatus; | ||
error?: Error; | ||
@@ -95,0 +97,0 @@ handler: HandlerInfo; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var IndexingStatus; | ||
(function (IndexingStatus) { | ||
IndexingStatus["Initial"] = "initial"; | ||
IndexingStatus["Indexing"] = "indexing"; | ||
IndexingStatus["Pausing"] = "pausing"; | ||
IndexingStatus["Paused"] = "paused"; | ||
IndexingStatus["Stopped"] = "stopped"; | ||
})(IndexingStatus = exports.IndexingStatus || (exports.IndexingStatus = {})); | ||
//# sourceMappingURL=interfaces.js.map |
{ | ||
"name": "demux", | ||
"version": "3.1.4-431ae7e.0", | ||
"version": "3.1.4-4e25e05.0", | ||
"author": { | ||
@@ -14,6 +14,9 @@ "name": "Julien Heller", | ||
"devDependencies": { | ||
"@blockone/tslint-config-blockone": "^2.0.0", | ||
"@types/bunyan": "^1.8.5", | ||
"@types/express": "^4.16.0", | ||
"@types/jest": "^23.1.4", | ||
"@types/node": "^10.5.1", | ||
"@types/request-promise-native": "^1.0.15", | ||
"@types/supertest": "^2.0.7", | ||
"eslint": "^4.9.0", | ||
@@ -35,6 +38,6 @@ "eslint-config-airbnb-base": "12.1.0", | ||
"watch": "tsc -w", | ||
"example": "./run-example.sh", | ||
"example": "./scripts/run-example.sh", | ||
"lint": "tslint -c tslint.json -p tsconfig.json", | ||
"test": "jest --detectOpenHandles --maxWorkers=2", | ||
"build-docs": "./build-docs.sh", | ||
"build-docs": "./scripts/build-docs.sh", | ||
"current-version": "echo $npm_package_version" | ||
@@ -60,7 +63,5 @@ }, | ||
"dependencies": { | ||
"@types/express": "^4.16.0", | ||
"@types/supertest": "^2.0.7", | ||
"bunyan": "^1.8.12", | ||
"express": "^4.16.4" | ||
"bunyan": "1.8.12", | ||
"express": "4.16.4" | ||
} | ||
} |
@@ -86,2 +86,4 @@ # demux-js [![Build Status](https://travis-ci.org/EOSIO/demux-js.svg?branch=develop)](https://travis-ci.org/EOSIO/demux-js) | ||
* [**`ExpressActionWatcher`**](https://eosio.github.io/demux-js/classes/expressactionwatcher.html): Exposes the API methods from the BaseActionWatcher through an Express server | ||
In order to process actions, we need the following things: | ||
@@ -95,9 +97,46 @@ | ||
- Instantiate the implemented `AbstractActionReader` with any needed configuration | ||
- Instantiate the implemented `AbstractActionHandler`, passing in the `HandlerVersion` and any other needed configuration | ||
- Instantiate the implemented `AbstractActionReader` with any needed configuration | ||
- Instantiate a `BaseActionWatcher`, passing in the above Handler and Reader instances | ||
- Call `watch()` on the Watcher | ||
- Instantiate the `BaseActionWatcher` (or a subclass), passing in the Action Handler and Action Watcher instances | ||
- Start indexing via the Action Watcher's `watch()` method (by either calling it directly or otherwise) | ||
#### Example | ||
```javascript | ||
const { BaseActionWatcher, ExpressActionWatcher } = require("demux") | ||
const { MyActionReader } = require("./MyActionReader") | ||
const { MyActionHandler } = require("./MyActionHandler") | ||
const { handlerVersions } = require("./handlerVersions") | ||
const { readerConfig, handlerConfig, pollInterval, portNumber } = require("./config") | ||
const actionReader = new MyActionReader(readerConfig) | ||
const actioHandler = new MyActionHandler(handlerVersions, handlerConfig) | ||
``` | ||
Then, either | ||
```javascript | ||
const watcher = new BaseActionWatcher( | ||
actionReader, | ||
actionHandler, | ||
pollInterval, | ||
) | ||
watcher.watch() | ||
``` | ||
Or, | ||
```javascript | ||
const expressWatcher = new ExpressActionWatcher( | ||
actionReader, | ||
actionHandler, | ||
pollInterval, | ||
portNumber, | ||
) | ||
expressWatcher.listen() | ||
// You can then make a POST request to `/start` on your configured endpoint | ||
``` | ||
### [**API documentation**](https://eosio.github.io/demux-js/) | ||
### [Learn from a full example](examples/eos-transfers) |
2
24
1306
141
89198
18
+ Addedbody-parser@1.18.3(transitive)
+ Addedbunyan@1.8.12(transitive)
+ Addedbytes@3.0.0(transitive)
+ Addedcontent-disposition@0.5.2(transitive)
+ Addedcookie@0.3.1(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addeddestroy@1.0.4(transitive)
+ Addedexpress@4.16.4(transitive)
+ Addedfinalhandler@1.1.1(transitive)
+ Addedhttp-errors@1.6.3(transitive)
+ Addediconv-lite@0.4.23(transitive)
+ Addedinherits@2.0.3(transitive)
+ Addedmerge-descriptors@1.0.1(transitive)
+ Addedmime@1.4.1(transitive)
+ Addedon-finished@2.3.0(transitive)
+ Addedpath-to-regexp@0.1.7(transitive)
+ Addedqs@6.5.2(transitive)
+ Addedraw-body@2.3.3(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsend@0.16.2(transitive)
+ Addedserve-static@1.13.2(transitive)
+ Addedsetprototypeof@1.1.0(transitive)
+ Addedstatuses@1.4.0(transitive)
- Removed@types/express@^4.16.0
- Removed@types/supertest@^2.0.7
- Removed@types/body-parser@1.19.5(transitive)
- Removed@types/connect@3.4.38(transitive)
- Removed@types/cookiejar@2.1.5(transitive)
- Removed@types/express@4.17.21(transitive)
- Removed@types/express-serve-static-core@4.19.6(transitive)
- Removed@types/http-errors@2.0.4(transitive)
- Removed@types/methods@1.1.4(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removed@types/node@22.13.4(transitive)
- Removed@types/qs@6.9.18(transitive)
- Removed@types/range-parser@1.2.7(transitive)
- Removed@types/send@0.17.4(transitive)
- Removed@types/serve-static@1.15.7(transitive)
- Removed@types/superagent@8.1.9(transitive)
- Removed@types/supertest@2.0.16(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbunyan@1.8.15(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcookie@0.7.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedencodeurl@2.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedexpress@4.21.2(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedform-data@4.0.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmime@1.6.0(transitive)
- Removedms@2.1.3(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedpath-to-regexp@0.1.12(transitive)
- Removedqs@6.13.0(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedundici-types@6.20.0(transitive)
Updatedbunyan@1.8.12
Updatedexpress@4.16.4