Skip to content

Commit

Permalink
Move index to row for consistency with bulk().
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Mar 26, 2016
1 parent 64dd8ca commit ca7562c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/iteratorCaller.js
Expand Up @@ -17,10 +17,12 @@ class IteratorCallerStream extends SwiftTransformStream {
// -------------------------------------------------

_transform(data, encoding, callback) {
data.index = this._count++; // eslint-disable-line no-plusplus

// Execute the iterator
// Note that the iterator can throw synchronously as well as return non-promise values
return Promise.resolve()
.then(() => this._iterator(data, this._count++)) // eslint-disable-line no-plusplus
.then(() => this._iterator(data))
.then(() => callback(null, data), (err) => callback(err))
// Equivalent to .done()
.catch((err) => {
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Expand Up @@ -22,11 +22,11 @@ describe('couchdbIterator()', () => {
it('should iterate all rows', () => {
let count = 0;

return couchdbIterator(prepared.couchdbAddr, (row, index) => {
expect(index).to.equal(count);
return couchdbIterator(prepared.couchdbAddr, (row) => {
expect(row.index).to.equal(count);
count += 1;

expect(row).to.have.all.keys('id', 'key', 'value');
expect(row).to.have.all.keys('index', 'id', 'key', 'value');
expect(row.id).to.be.a('string');
expect(row.key).to.be.a('string');
expect(row.value).to.be.an('object');
Expand All @@ -41,11 +41,11 @@ describe('couchdbIterator()', () => {
it('should iterate all rows from a view', () => {
let count = 0;

return couchdbIterator(prepared.couchdbAddr, 'test/view-1', (row, index) => {
expect(index).to.equal(count);
return couchdbIterator(prepared.couchdbAddr, 'test/view-1', (row) => {
expect(row.index).to.equal(count);
count += 1;

expect(row).to.have.all.keys('id', 'key', 'value');
expect(row).to.have.all.keys('index', 'id', 'key', 'value');
expect(row.id).to.be.a('string');
expect(row.key).to.be.a('array');
expect(row.value).to.be.an('object');
Expand Down

0 comments on commit ca7562c

Please sign in to comment.