Skip to content

Update to support demux-js 1.0.2 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"typescript": "^2.9.2"
},
"dependencies": {
"demux-js": "0.0.1-docs",
"demux-js": "^1.0.2",
"massive": "^5.2.0",
"pg-promise": "^8.4.5",
"request": "^2.87.0",
"request-promise-native": "^1.0.5"
},
"peerDependencies": {
"demux-js": "0.0.1-docs"
"demux-js": "^1.0.2"
},
"scripts": {
"release": "release-it",
Expand Down
6 changes: 2 additions & 4 deletions src/MassiveActionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Block, Effect, handlers, IndexState, Updater } from "demux-js"

export const { AbstractActionHandler } = handlers
import { AbstractActionHandler, Block, Effect, IndexState, Updater } from "demux-js"

/**
* Connects to a Postgres database using [MassiveJS](https://github.com/dmfay/massive-js). This expects that
Expand Down Expand Up @@ -39,7 +37,7 @@ export class MassiveActionHandler extends AbstractActionHandler {
}

protected async updateIndexState(state: any, block: Block, isReplay: boolean) {
const { actions, ...blockInfo } = block
const { blockInfo } = block
state._index_state.save({
id: 0,
block_number: blockInfo.blockNumber,
Expand Down
15 changes: 7 additions & 8 deletions src/testHelpers/JsonActionReader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Block, readers } from "demux-js"
import { AbstractActionReader, Block } from "demux-js"
import request from "request-promise-native"

export const { AbstractActionReader } = readers

/**
* Reads from an array of `Block` objects, useful for testing.
*/
Expand All @@ -19,19 +17,20 @@ export class JsonActionReader extends AbstractActionReader {

public async getHeadBlockNumber(): Promise<number> {
const block = this.blockchain.slice(-1)[0]
if (this.blockchain.length !== block.blockNumber) {
throw Error(`Block at position ${this.blockchain.length} indicates position ${block.blockNumber} incorrectly.`)
const { blockInfo: { blockNumber } } = block
if (this.blockchain.length !== blockNumber) {
throw Error(`Block at position ${this.blockchain.length} indicates position ${blockNumber} incorrectly.`)
}
return block.blockNumber
return blockNumber
}

public async getBlock(blockNumber: number): Promise<Block> {
const block = this.blockchain[blockNumber - 1]
if (!block) {
throw Error(`Block at position ${blockNumber} does not exist.`)
}
if (block.blockNumber !== blockNumber) {
throw Error(`Block at position ${blockNumber} indicates position ${block.blockNumber} incorrectly.`)
if (block.blockInfo.blockNumber !== blockNumber) {
throw Error(`Block at position ${blockNumber} indicates position ${block.blockInfo.blockNumber} incorrectly.`)
}
return block
}
Expand Down
24 changes: 15 additions & 9 deletions src/testHelpers/blockchain.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[
{
"blockNumber": 1,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000000",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000000",
"blockInfo": {
"blockNumber": 1,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000000",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000000"
},
"actions": [
{
"type": "add_todo",
Expand All @@ -21,9 +23,11 @@
]
},
{
"blockNumber": 2,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000001",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000000",
"blockInfo": {
"blockNumber": 2,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000001",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000000"
},
"actions": [
{
"type": "add_tasks",
Expand Down Expand Up @@ -53,9 +57,11 @@
]
},
{
"blockNumber": 3,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000002",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000001",
"blockInfo": {
"blockNumber": 3,
"blockHash": "0000000000000000000000000000000000000000000000000000000000000002",
"previousBlockHash": "0000000000000000000000000000000000000000000000000000000000000001"
},
"actions": [
{
"type": "update_task",
Expand Down
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1629,14 +1629,9 @@ delegates@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"

demux-js@0.0.1-docs:
version "0.0.1-docs"
resolved "https://registry.yarnpkg.com/demux-js/-/demux-js-0.0.1-docs.tgz#5ce14f04c146326f8ab222ff2c30e9796c560948"
dependencies:
massive "^5.1.3"
pg-promise "^8.4.5"
request "^2.87.0"
request-promise-native "^1.0.5"
demux-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/demux-js/-/demux-js-1.0.2.tgz#60852a597ecf11eb41b6b4483f496b626ed4f966"

detect-indent@5.0.0:
version "5.0.0"
Expand Down Expand Up @@ -3588,7 +3583,7 @@ marked@^0.3.17:
version "0.3.19"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.19.tgz#5d47f709c4c9fc3c216b6d46127280f40b39d790"

massive@^5.1.3, massive@^5.2.0:
massive@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/massive/-/massive-5.2.0.tgz#7b734c54c2230db37f161737d1339f3d9e4f879f"
dependencies:
Expand Down