You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2019/07/03 15:26:31 UTC
[GitHub] [couchdb-nano] madbence opened a new issue #170: Inconsistent
Promise interface
madbence opened a new issue #170: Inconsistent Promise interface
URL: https://github.com/apache/couchdb-nano/issues/170
## Expected Behavior
`db.attachment.get` should have a consistent return value (ie. resolved promise value and callback value)
## Current Behavior
when `db.attachment.get` is called without a `callback` param, the result is decoded into a string.
when `db.attachment.get` is called with a `callback` param, the result is not decoded, it'll be a `Buffer` object.
## Possible Solution
In case the `callback` is missing, the `accept` header is removed from the request:
https://github.com/apache/couchdb-nano/blob/4fed1e50488479596e4b2e440d96040c2dc72e36/lib/nano.js#L228-L233
`encoding` is always `null`, but it's compared against `undefined`: https://github.com/apache/couchdb-nano/blob/4fed1e50488479596e4b2e440d96040c2dc72e36/lib/nano.js#L814-L824
I'm not sure what would be the right behavior, I'd probably expect a `Buffer`.
## Steps to Reproduce (for bugs)
```js
const nano = require('nano');
const db = nano('http://localhost:5984');
(async () => {
const d = db.use('test');
await db.db.create('test').catch(() => {});
await d.insert({foo: 'bar'}, 'foo').catch(() => {});
const rev = (await d.get('foo'))._rev;
await d.attachment.insert('foo', 'bar', JSON.stringify({foo: 'bar'}), 'application/json', {rev}).catch(() => {})
await d.attachment.get('foo', 'bar').then((data) => console.log('promise', typeof data, data));
d.attachment.get('foo', 'bar', (err, data) => console.log('callback', typeof data, data));
})().catch(err => console.log(err));
// promise string {"foo":"bar"}
// callback object <Buffer 7b 22 66 6f 6f 22 3a 22 62 61 72 22 7d>
```
## Context
We're trying to migrate away from the callback-based API, and use promises.
## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* CouchDB: `2.3.1`
* Nano: `8.1.0`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services