Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Refactor datastore core to use async/await instead of callbacks #17

Merged
merged 2 commits into from
May 29, 2019
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
23 changes: 0 additions & 23 deletions .appveyor.yml

This file was deleted.

68 changes: 39 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
sudo: false
language: node_js
cache: npm
stages:
- check
- test
- cov

matrix:
node_js:
- '10'

os:
- linux
- osx

script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
include:
- node_js: 6
env: CXX=g++-4.8
- node_js: 8
env: CXX=g++-4.8
# - node_js: stable
# env: CXX=g++-4.8

script:
- npm run lint
- npm run test
- npm run coverage

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- os: windows
cache: false

- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint

- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser -t webworker

- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless

notifications:
email: false
29 changes: 0 additions & 29 deletions appveyor.yml

This file was deleted.

2 changes: 0 additions & 2 deletions ci/Jenkinsfile

This file was deleted.

15 changes: 0 additions & 15 deletions circle.yml

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
},
"homepage": "https://github.com/ipfs/js-datastore-core#readme",
"devDependencies": {
"aegir": "^15.3.1",
"aegir": "^v18.2.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"flow-bin": "~0.83.0"
"flow-bin": "~0.83.0",
"highlight.js": "https://github.com/highlightjs/highlight.js/tarball/9.15.4/highlight.js.tar.gz"
},
"dependencies": {
"async": "^2.6.1",
"interface-datastore": "~0.6.0",
"interface-datastore": "git://github.com/ipfs/interface-datastore.git#refactor/async-iterators",
"left-pad": "^1.3.0",
"pull-many": "^1.0.8",
"pull-stream": "^3.6.9"
Expand Down
44 changes: 21 additions & 23 deletions src/keytransform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* @flow */
'use strict'

const pull = require('pull-stream')
const utils = require('interface-datastore').utils
const map = utils.map

/* ::
import type {Key, Datastore, Batch, Query, QueryResult, Callback} from 'interface-datastore'
Expand Down Expand Up @@ -38,24 +39,24 @@ class KeyTransformDatastore /* :: <Value> */ {
this.transform = transform
}

open (callback /* : Callback<void> */) /* : void */ {
this.child.open(callback)
open () /* : Promise<void> */ {
return this.child.open()
}

put (key /* : Key */, val /* : Value */, callback /* : Callback<void> */) /* : void */ {
this.child.put(this.transform.convert(key), val, callback)
async put (key /* : Key */, val /* : Value */) /* : Promise<void> */ {
return this.child.put(this.transform.convert(key), val)
}

get (key /* : Key */, callback /* : Callback<Value> */) /* : void */ {
this.child.get(this.transform.convert(key), callback)
async get (key /* : Key */) /* : Promise<Value> */ {
return this.child.get(this.transform.convert(key))
}

has (key /* : Key */, callback /* : Callback<bool> */) /* : void */ {
this.child.has(this.transform.convert(key), callback)
async has (key /* : Key */) /* : Promise<bool> */ {
return this.child.has(this.transform.convert(key))
}

delete (key /* : Key */, callback /* : Callback<void> */) /* : void */ {
this.child.delete(this.transform.convert(key), callback)
async delete (key /* : Key */) /* : Promise<void> */ {
return this.child.delete(this.transform.convert(key))
}

batch () /* : Batch<Value> */ {
Expand All @@ -67,24 +68,21 @@ class KeyTransformDatastore /* :: <Value> */ {
delete: (key /* : Key */) /* : void */ => {
b.delete(this.transform.convert(key))
},
commit: (callback /* : Callback<void> */) /* : void */ => {
b.commit(callback)
commit: async () /* : Promise<void> */ => {
return b.commit()
}
}
}

query (q /* : Query<Value> */) /* : QueryResult<Value> */ {
return pull(
this.child.query(q),
pull.map(e => {
e.key = this.transform.invert(e.key)
return e
})
)
query (q /* : Query<Value> */) /* : Iterator */ {
return map(this.child.query(q), e => {
e.key = this.transform.invert(e.key)
return e
})
}

close (callback /* : Callback<void> */) /* : void */ {
this.child.close(callback)
async close () /* : Promise<void> */ {
return this.child.close()
}
}

Expand Down
Loading