diff --git a/.flowconfig b/.flowconfig index 7b7b4bb..34e5c77 100644 --- a/.flowconfig +++ b/.flowconfig @@ -2,6 +2,7 @@ .*/radium/.* .*/standard-changelog/.* .*/conventional-changelog-core/.* +.*/node_modules/.* [include] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..dd38849 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,27 @@ +version: "{build}" + +environment: + matrix: + - nodejs_version: "6" + +matrix: + fast_finish: true + +install: + # Install Node.js + - ps: Install-Product node $env:nodejs_version + + # Upgrade npm + - npm install -g npm + + # Output our current versions for debugging + - node --version + - npm --version + + # Install our package dependencies + - npm install + +test_script: + - npm run test:node + +build: off \ No newline at end of file diff --git a/package.json b/package.json index 78f98ce..47bd147 100644 --- a/package.json +++ b/package.json @@ -54,4 +54,4 @@ "David Dias ", "Friedel Ziegelmayer " ] -} \ No newline at end of file +} diff --git a/src/sharding.js b/src/sharding.js index ff4f164..a4337bf 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -3,7 +3,6 @@ const waterfall = require('async/waterfall') const parallel = require('async/parallel') -const pull = require('pull-stream') const Key = require('interface-datastore').Key const sh = require('./shard') @@ -129,51 +128,44 @@ class ShardingDatastore { query (q /* : Query */) /* : QueryResult */ { const tq/* : Query */ = { - keysOnly: q.keysOnly + keysOnly: q.keysOnly, + offset: q.offset, + limit: q.limit, + filters: [ + (e, cb) => cb(null, e.key.toString() !== shardKey.toString()), + (e, cb) => cb(null, e.key.toString() !== shardReadmeKey.toString()) + ] } if (q.prefix != null) { - // TODO: transform - tq.prefix = q.prefix + tq.filters.push((e, cb) => { + cb(null, this._invertKey(e.key).toString().startsWith(q.prefix)) + }) } if (q.filters != null) { - tq.filters = q.filters.map((f) => (e, cb) => { + const filters = q.filters.map((f) => (e, cb) => { f(Object.assign({}, e, { key: this._invertKey(e.key) }), cb) }) + tq.filters = tq.filters.concat(filters) } if (q.orders != null) { tq.orders = q.orders.map((o) => (res, cb) => { - const m = res.map((e) => { - return Object.assign({}, e, { - key: this._invertKey(e.key) - }) + res.forEach((e) => { e.key = this._invertKey(e.key) }) + o(res, (err, ordered) => { + if (err) { + return cb(err) + } + ordered.forEach((e) => { e.key = this._convertKey(e.key) }) + cb(null, ordered) }) - o(m, cb) }) } - if (q.offset != null) { - tq.offset = q.offset + 2 - } - - if (q.limit != null) { - tq.limit = q.limit + 2 - } - - return pull( - this.child.query(tq), - pull.filter((e) => { - if (e.key.toString() === shardKey.toString() || - e.key.toString() === shardReadmeKey.toString()) { - return false - } - return true - }) - ) + return this.child.query(tq) } close (callback /* : Callback */) /* : void */ { diff --git a/test/sharding.spec.js b/test/sharding.spec.js index 8168c45..3c6598a 100644 --- a/test/sharding.spec.js +++ b/test/sharding.spec.js @@ -84,8 +84,7 @@ describe('ShardingStore', () => { }) }) - // TODO: fix query prefix and orders - describe.skip('interface-datastore', () => { + describe('interface-datastore', () => { require('interface-datastore/src/tests')({ setup (callback) { const shard = new sh.NextToLast(2)