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

Commit d03ce46

Browse files
authored
Merge pull request #363 from cloudant/nano8
Nano8
2 parents 764d50b + a19cbfe commit d03ce46

File tree

7 files changed

+125
-62
lines changed

7 files changed

+125
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
node_modules/
55
coverage/
66
/.env
7+
test/typescript/cloudant.js

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# UNRELEASED
22
- [NEW] Added option for client to authenticate with IAM token server.
33
- [FIXED] Case where `.resume()` was called on an undefined response.
4+
- [BREAKING CHANGE] Nano 7 accepted a callback to the `*AsStream` functions, but
5+
the correct behaviour when using the `request` object from `*AsStream`
6+
functions is to use event handlers. Users of the `*AsStream` functions should
7+
ensure they are using event handlers not callbacks before moving to this
8+
version.
9+
- [UPGRADED] Apache CouchDB Nano to a minimum of version 8 for `*AsStream`
10+
function fixes.
411

512
# 3.0.2 (2019-01-07)
613
- [FIXED] Remove unnecessary `@types/nano` dependancy.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,25 @@ getpandarev('4-2e6cdc4c7e26b745c2881a24e0eeece2', function(err, body) {
980980
})
981981
~~~
982982
983+
### Pipes
984+
985+
When using the `*AsStream` functions instead of a `Promise` a `request` object
986+
is returned that may be piped as a stream. For example:
987+
988+
```js
989+
cloudant.db.listAsStream()
990+
.on('error', function(error) {
991+
console.log('ERROR');
992+
})
993+
.on('end', function(error) {
994+
console.log('DONE');
995+
})
996+
.pipe(process.stdout);
997+
```
998+
999+
Note that there are no callbacks when using these streams and event listeners
1000+
must be used instead.
1001+
9831002
## Development and Contribution
9841003
9851004
This is an open-source library, published under the Apache 2.0 license. We very

api-migration.md

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,65 @@ has breaking API changes. Each section covers migrating from one major version
55
to another. The section titles state the versions between which the change was
66
made.
77

8+
## 3.x → 4.x
9+
10+
[Apache CouchDB Nano](https://www.npmjs.com/package/nano) version 7 used in
11+
`nodejs-cloudant` 3.x had an API error that allowed specifying a callback when
12+
using `*AsStream` functions. Using a callback with the `request` object caused a
13+
`Buffer` allocation attempt for the entire response size, which would fail for
14+
large streams. The correct approach is to use event listeners on the response
15+
stream.
16+
17+
To prevent incorrect usage the option of providing a callback was removed from
18+
the Apache CouchDB Nano API in version 8 and consequently nodejs-cloudant 4.x.
19+
Consumers of the `*AsStream` functions using callbacks need to adapt their code
20+
to use event listeners instead. For example:
21+
22+
```js
23+
cloudant.db.listAsStream(function(error, response, body) {
24+
if (error) {
25+
console.log('ERROR');
26+
} else {
27+
console.log('DONE');
28+
}
29+
}).pipe(process.stdout);
30+
```
31+
32+
may be replaced with:
33+
34+
```js
35+
cloudant.db.listAsStream()
36+
.on('error', function(error) {
37+
console.log('ERROR');
38+
})
39+
.on('end', function(error) {
40+
console.log('DONE');
41+
})
42+
.pipe(process.stdout);
43+
```
44+
45+
## 2.x → 3.x
46+
47+
We've upgraded our [nano](https://www.npmjs.com/package/nano) dependency. This
48+
means all return types are now a `Promise` (except for the `...AsStream`
49+
functions). The `promise` plugin is no longer required. It is silently ignored
50+
when specified in the client configuration.
51+
52+
Example:
53+
```js
54+
var cloudant = new Cloudant({ url: myUrl, plugins: [ 'retry' ] });
55+
56+
// Lists all the databases.
57+
cloudant.db.list().then((dbs) => {
58+
dbs.forEach((db) => {
59+
console.log(db);
60+
});
61+
}).catch((err) => { console.log(err); });
62+
```
63+
64+
Nano is responsible for resolving or rejecting all promises. Any errors thrown
65+
are created from within Nano. The old `CloudantError` type no longer exists.
66+
867
## 1.x → 2.x
968

1069
This change introduces multiple plugin support by using a request interceptor
@@ -49,25 +108,3 @@ var cloudant = new Cloudant({ url: myUrl, plugins: [] });
49108

50109
Finally, the `promise` plugin now throws a `CloudantError` (extended from
51110
`Error`) rather than a `string` which was considered bad practice.
52-
53-
## 2.x → 3.x
54-
55-
We've upgraded our [nano](https://www.npmjs.com/package/nano) dependency. This
56-
means all return types are now a `Promise` (except for the `...AsStream`
57-
functions). The `promise` plugin is no longer required. It is silently ignored
58-
when specified in the client configuration.
59-
60-
Example:
61-
```js
62-
var cloudant = new Cloudant({ url: myUrl, plugins: [ 'retry' ] });
63-
64-
// Lists all the databases.
65-
cloudant.db.list().then((dbs) => {
66-
dbs.forEach((db) => {
67-
console.log(db);
68-
});
69-
}).catch((err) => { console.log(err); });
70-
```
71-
72-
Nano is responsible for resolving or rejecting all promises. Any errors thrown
73-
are created from within Nano. The old `CloudantError` type no longer exists.

package-lock.json

Lines changed: 33 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"concat-stream": "^1.6.0",
2929
"debug": "^3.1.0",
3030
"lockfile": "1.0.3",
31-
"nano": "^7.1.1",
31+
"nano": "^8.0.0",
3232
"request": "^2.81.0",
3333
"tmp": "0.0.33"
3434
},

test/legacy/plugin.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ describe('retry-on-429 plugin #db', function() {
113113
setTimeout(done, 1000);
114114
});
115115

116-
it('should return a stream', function(done) {
116+
it.only('should return a stream', function(done) {
117117
var mocks = nock(SERVER)
118-
.get('/' + dbName).reply(200, { ok: true });
118+
.get('/_all_dbs').reply(200, ['_replicator','_users']);
119119
var cloudant = Cloudant({plugins: 'retry', url: SERVER, username: ME, password: PASSWORD});
120-
var dbs = cloudant.db.listAsStream(function() {
121-
done();
120+
var dbs = cloudant.db.listAsStream()
121+
.once('end', function() {
122+
done()
122123
});
123124
assert.equal(dbs instanceof PassThroughDuplex, true);
124125
});

0 commit comments

Comments
 (0)