Comparing version 8.0.0 to 8.0.1
@@ -20,6 +20,9 @@ // Licensed under the Apache License, Version 2.0 (the 'License'); you may not | ||
const errs = require('errs') | ||
const isEmpty = require('lodash.isempty') | ||
const follow = require('cloudant-follow') | ||
const logger = require('./logger') | ||
function isEmpty (val) { | ||
return val == null || !(Object.keys(val) || val).length | ||
} | ||
function getCallback (opts, callback) { | ||
@@ -279,2 +282,6 @@ if (typeof opts === 'function') { | ||
// ask request to render query string arrays as repeated values e.g. | ||
// ?drilldown=["author","Dickens"]&drilldown=["publisher","Penguin"] | ||
req.qsStringifyOptions = { arrayFormat: 'repeat' } | ||
log(req) | ||
@@ -626,3 +633,3 @@ | ||
// object API, several parameters need JSON endoding. | ||
const paramsToEncode = ['counts', 'drilldown', 'group_sort', 'ranges', 'sort'] | ||
const paramsToEncode = ['counts', 'group_sort', 'ranges', 'sort'] | ||
paramsToEncode.forEach(function (param) { | ||
@@ -643,2 +650,21 @@ if (param in qs1) { | ||
// the drilldown parameter needs special treatment. It can either be: | ||
// - a single array of strings e.g. ['author', 'Dickens'] | ||
// - an array of arrays e.g. [['author','Dickens']['publisher','Penguin']] | ||
// The former should be JSON.stringified the latter should be an array of | ||
// JSON.stringified arrays(!). | ||
if (qs1['drilldown']) { | ||
// if this is an array of arrays | ||
if (Array.isArray(qs1['drilldown']) && | ||
qs1['drilldown'].length > 0 && | ||
Array.isArray(qs1['drilldown'][0])) { | ||
// JSON stringify each element of the array | ||
qs1['drilldown'] = qs1['drilldown'].map(function (val) { | ||
return JSON.stringify(val) | ||
}) | ||
} else if (Array.isArray(qs1['drilldown'])) { | ||
qs1['drilldown'] = JSON.stringify(qs1['drilldown']) | ||
} | ||
} | ||
if (qs1 && qs1.keys) { | ||
@@ -645,0 +671,0 @@ const body = {keys: qs1.keys} |
@@ -7,3 +7,3 @@ { | ||
"repository": "http://github.com/apache/couchdb-nano", | ||
"version": "8.0.0", | ||
"version": "8.0.1", | ||
"author": "Apache CouchDB <dev@couchdb.apache.org> (http://couchdb.apache.org)", | ||
@@ -25,3 +25,2 @@ "keywords": [ | ||
"errs": "^0.3.2", | ||
"lodash.isempty": "^4.4.0", | ||
"request": "^2.85.0" | ||
@@ -37,2 +36,3 @@ }, | ||
"scripts": { | ||
"standard": "standard --fix", | ||
"test": "standard && npm run mocha", | ||
@@ -39,0 +39,0 @@ "mocha": "NOCK_OFF=true istanbul cover tape tests/*/*/*.js", |
@@ -180,3 +180,3 @@ [![Build Status](https://travis-ci.org/apache/couchdb-nano.svg?branch=master)](https://travis-ci.org/apache/couchdb-nano)![Coverage](https://img.shields.io/badge/coverage-100%-ff69b4.svg)[![dependencies Status](https://david-dm.org/apache/couchdb-nano/status.svg)](https://david-dm.org/apache/couchdb-nano)[![NPM](http://img.shields.io/npm/v/nano.svg?style=flat-square)](https://www.npmjs.com/package/nano) | ||
``` | ||
you have inserted a document with an _id of rabbitt. | ||
you have inserted a document with an _id of rabbit. | ||
{ ok: true, | ||
@@ -287,3 +287,3 @@ id: 'rabbit', | ||
processAPIResponse(response: nano.DocumentInsertResponse) { | ||
processAPIResponse(response: Nano.DocumentInsertResponse) { | ||
if (response.ok === true) { | ||
@@ -923,2 +923,11 @@ this._id = response.id | ||
or | ||
```js | ||
const drilldown = [['author', 'Dickens']['publisher','Penguin']] | ||
alice.search('inventory', 'books', { q: '*:*', drilldown: drilldown }).then((doc) => { | ||
console.log(doc); | ||
}); | ||
``` | ||
Check out the tests for a fully functioning example. | ||
@@ -945,3 +954,3 @@ | ||
}, | ||
fields: [ "name", "age", "tags", "url" ] | ||
fields: [ "name", "age", "tags", "url" ], | ||
limit:50 | ||
@@ -965,3 +974,3 @@ }; | ||
}, | ||
fields: [ "name", "age", "tags", "url" ] | ||
fields: [ "name", "age", "tags", "url" ], | ||
limit:50 | ||
@@ -968,0 +977,0 @@ }; |
@@ -97,2 +97,5 @@ // Licensed under the Apache License, Version 2.0 (the 'License'); you may not | ||
// ignore qsStringifyOptions in object comparison | ||
delete req.qsStringifyOptions | ||
assert.deepEqual(req, stub) | ||
@@ -99,0 +102,0 @@ assert.end() |
@@ -102,2 +102,17 @@ // Licensed under the Apache License, Version 2.0 (the 'License'); you may not | ||
it('should encode array of arrays drilldown parameter', function (assert) { | ||
const p = db.search('fake', 'fake', { drilldown: [['colour', 'red'], ['category', 'cake']] }) | ||
assert.ok(helpers.isPromise(p), 'returns Promise') | ||
p.then(function (data) { | ||
assert.ok(true, 'Promise is resolved') | ||
assert.equal(data.method, 'GET') | ||
assert.equal(typeof data.headers, 'object') | ||
console.log(data.headers) | ||
assert.equal(typeof data.qs, 'object') | ||
assert.end() | ||
}).catch(function () { | ||
assert.ok(true, 'Promise is rejected') | ||
}) | ||
}) | ||
it('should encode array group_sort parameter', function (assert) { | ||
@@ -104,0 +119,0 @@ const p = db.search('fake', 'fake', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
333511
5
7358
1130
- Removedlodash.isempty@^4.4.0
- Removedlodash.isempty@4.4.0(transitive)