You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2018/07/18 13:58:30 UTC

[couchdb-nano] branch issue98 updated (e537418 -> abab887)

This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a change to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git.


    from e537418  migration guide
     new dc7687d  swap out var for const/let in the core code and tests
     new 6eac47d  refactor responseHandler to make parameter names more readable
     new 2e84992  add default parameter value in responseHandler
     new 2d3b22c  return headers for headDoc on an error
     new 11c6168  added central getCallback function to remove code duplication
     new 214a0da  var--->const in the README
     new 166c23c  modernise JS in migration guide
     new abab887  jshint fixes

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                        |  58 ++--
 lib/logger.js                                    |   8 +-
 lib/nano.js                                      | 379 ++++++++++-------------
 migration_6_to_7.md                              |  11 +-
 tests/helpers/index.js                           |  16 +-
 tests/helpers/integration.js                     |  58 ++--
 tests/helpers/unit.js                            |  24 +-
 tests/integration/attachment/destroy.js          |  12 +-
 tests/integration/attachment/get.js              |  12 +-
 tests/integration/attachment/insert.js           |  10 +-
 tests/integration/attachment/pipe.js             |  28 +-
 tests/integration/attachment/update.js           |  17 +-
 tests/integration/database/changes.js            |  14 +-
 tests/integration/database/compact.js            |  12 +-
 tests/integration/database/create-and-destroy.js |  12 +-
 tests/integration/database/follow.js             |  12 +-
 tests/integration/database/get.js                |  14 +-
 tests/integration/database/list.js               |  12 +-
 tests/integration/database/replicate.js          |  20 +-
 tests/integration/database/replicator.js         |  18 +-
 tests/integration/design/atomic.js               |  20 +-
 tests/integration/design/compact.js              |  36 +--
 tests/integration/design/list.js                 |  10 +-
 tests/integration/design/multiple.js             |  14 +-
 tests/integration/design/query.js                |  14 +-
 tests/integration/design/search.js               |  14 +-
 tests/integration/design/show.js                 |  12 +-
 tests/integration/document/bulk.js               |  10 +-
 tests/integration/document/copy.js               |  14 +-
 tests/integration/document/create_index.js       |  10 +-
 tests/integration/document/destroy.js            |  14 +-
 tests/integration/document/fetch.js              |  14 +-
 tests/integration/document/fetch_revs.js         |  14 +-
 tests/integration/document/find.js               |  12 +-
 tests/integration/document/get.js                |  10 +-
 tests/integration/document/head.js               |  10 +-
 tests/integration/document/insert.js             |  18 +-
 tests/integration/document/list.js               |  24 +-
 tests/integration/document/update.js             |  15 +-
 tests/integration/multipart/get.js               |  16 +-
 tests/integration/multipart/insert.js            |  20 +-
 tests/integration/shared/config.js               |  30 +-
 tests/integration/shared/cookie.js               |  18 +-
 tests/integration/shared/error.js                |  14 +-
 tests/integration/shared/headers.js              |  10 +-
 tests/integration/shared/log.js                  |  11 +-
 tests/integration/util/uuid.js                   |  12 +-
 tests/intercept/design/search.js                 |  40 +--
 tests/unit/attachment/destroy.js                 |   2 +-
 tests/unit/attachment/get.js                     |   2 +-
 tests/unit/attachment/insert.js                  |   6 +-
 tests/unit/database/changes.js                   |   2 +-
 tests/unit/database/compact.js                   |   2 +-
 tests/unit/database/create.js                    |   2 +-
 tests/unit/database/destroy.js                   |   2 +-
 tests/unit/database/follow.js                    |   2 +-
 tests/unit/database/get.js                       |   2 +-
 tests/unit/database/list.js                      |   2 +-
 tests/unit/database/replicate.js                 |   2 +-
 tests/unit/database/replicator.js                |   2 +-
 tests/unit/database/updates.js                   |   2 +-
 tests/unit/design/atomic.js                      |   2 +-
 tests/unit/design/compact.js                     |   2 +-
 tests/unit/design/find.js                        |   2 +-
 tests/unit/design/list.js                        |   2 +-
 tests/unit/design/search.js                      |   2 +-
 tests/unit/design/show.js                        |   2 +-
 tests/unit/design/spatial.js                     |   2 +-
 tests/unit/design/view.js                        |   2 +-
 tests/unit/document/bulk.js                      |   2 +-
 tests/unit/document/copy.js                      |   4 +-
 tests/unit/document/get.js                       |  10 +-
 tests/unit/multipart/get.js                      |   2 +-
 tests/unit/multipart/insert.js                   |   2 +-
 tests/unit/shared/error.js                       |  16 +-
 tests/unit/shared/follow-updates.js              |   2 +-
 tests/unit/shared/jar.js                         |   8 +-
 77 files changed, 599 insertions(+), 696 deletions(-)


[couchdb-nano] 08/08: jshint fixes

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit abab8879abcebbee6f22dd87d50831c1dc299442
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 14:58:22 2018 +0100

    jshint fixes
---
 lib/nano.js | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index 1bf2d17..6db083d 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -80,7 +80,7 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
   const responseHandler = function(req, opts, resolve, reject, callback) {
     
-    return function(err, response = { statusCode: 500 }, body) {
+    return function(err, response = { statusCode: 500 }, body = '') {
       let parsed;
       const responseHeaders = Object.assign({
         uri: req.uri,
@@ -422,13 +422,19 @@ module.exports = exports = nano = function dbScope(cfg) {
   // http://guide.couchdb.org/draft/replication.html
   function queryReplication(id, opts0, callback0) {
     const {opts, callback} = getCallback(opts0, callback0);
-    return relax({db: '_replicator', method: 'GET', path: id}, callback);
+    return relax({db: '_replicator', method: 'GET', path: id, qs: opts}, callback);
   }
 
   // http://guide.couchdb.org/draft/replication.html
   function disableReplication(id, rev, opts0, callback0) {
     const {opts, callback} = getCallback(opts0, callback0);
-    return relax({db: '_replicator', method: 'DELETE', path: id, qs: {rev: rev}}, callback);
+    const req = {
+      db: '_replicator', 
+      method: 'DELETE', 
+      path: id, 
+      qs: Object.assign(opts, {rev: rev})
+    };
+    return relax(req, callback);
   }
 
   function docModule(dbName) {
@@ -509,7 +515,7 @@ module.exports = exports = nano = function dbScope(cfg) {
           if (err) {
             reject(err);
           } else {
-            resolve(headers)
+            resolve(headers);
           }
         });
       });


[couchdb-nano] 04/08: return headers for headDoc on an error

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 2d3b22c6a55b748d8dd58054144479880f24deb8
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 13:36:24 2018 +0100

    return headers for headDoc on an error
---
 lib/nano.js | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index f911b6f..4e41a5f 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -77,16 +77,16 @@ module.exports = exports = nano = function dbScope(cfg) {
       }, response.headers);
       if (err) {
         log({err: 'socket', body: body, headers: responseHeaders});
-        const ret_e = errs.merge(err, {
+        const returnError = errs.merge(err, {
           message: 'error happened in your connection',
           scope: 'socket',
           errid: 'request'
         });
         if (reject) {
-          reject(ret_e);
+          reject(returnError);
         } 
         if (callback) {
-          callback(ret_e);
+          callback(returnError);
         }
         return ;
       }
@@ -524,16 +524,14 @@ module.exports = exports = nano = function dbScope(cfg) {
           method: 'HEAD',
           qs: {}
         }, function(err, body, headers) {
-          if (err) {
-            if (callback) {
-              callback(err);
-            }
-            return reject(err);
-          }
           if (callback) {
             callback(err, body, headers);
+          } 
+          if (err) {
+            reject(err);
+          } else {
+            resolve(headers)
           }
-          resolve(headers);
         });
       });
     }


[couchdb-nano] 02/08: refactor responseHandler to make parameter names more readable

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 6eac47d3882361e81ee973c322176cb8eb93f1c9
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 13:22:54 2018 +0100

    refactor responseHandler to make parameter names more readable
---
 lib/nano.js | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index fe72b73..e0384cb 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -69,14 +69,15 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
   const responseHandler = function(req, opts, resolve, reject, callback) {
     
-    return function(e, h, b) {
+    return function(err, response, body) {
       let parsed;
-      const rh = h && h.headers || {};
-      rh.statusCode = h && h.statusCode || 500;
-      rh.uri = req.uri;
-      if (e) {
-        log({err: 'socket', body: b, headers: rh});
-        const ret_e = errs.merge(e, {
+      const responseHeaders = Object.assign({
+        uri: req.uri,
+        statusCode: response ? response.statusCode : 500
+      }, response ? response.headers : {});
+      if (err) {
+        log({err: 'socket', body: body, headers: responseHeaders});
+        const ret_e = errs.merge(err, {
           message: 'error happened in your connection',
           scope: 'socket',
           errid: 'request'
@@ -90,27 +91,27 @@ module.exports = exports = nano = function dbScope(cfg) {
         return ;
       }
 
-      delete rh.server;
-      delete rh['content-length'];
+      delete responseHeaders.server;
+      delete responseHeaders['content-length'];
 
       if (opts.dontParse) {
-        parsed = b;
+        parsed = body;
       } else {
-        try { parsed = JSON.parse(b); } catch (err) { parsed = b; }
+        try { parsed = JSON.parse(body); } catch (err) { parsed = body; }
       }
 
-      if (rh.statusCode >= 200 && rh.statusCode < 400) {
-        log({err: null, body: parsed, headers: rh});
+      if (responseHeaders.statusCode >= 200 && responseHeaders.statusCode < 400) {
+        log({err: null, body: parsed, headers: responseHeaders});
         if (resolve) {
           resolve(parsed);
         } 
         if (callback) {
-          callback(null, parsed, rh);
+          callback(null, parsed, responseHeaders);
         }
         return;
       }
 
-      log({err: 'couch', body: parsed, headers: rh});
+      log({err: 'couch', body: parsed, headers: responseHeaders});
 
       // cloudant stacktrace
       if (typeof parsed === 'string') {
@@ -126,17 +127,17 @@ module.exports = exports = nano = function dbScope(cfg) {
 
       // scrub credentials
       req.uri = scrub(req.uri);
-      rh.uri = scrub(rh.uri);
+      responseHeaders.uri = scrub(responseHeaders.uri);
       if (req.headers.cookie) {
         req.headers.cookie = "XXXXXXX";
       }
 
       let errors = errs.merge({
-        message: 'couch returned ' + rh.statusCode,
+        message: 'couch returned ' + responseHeaders.statusCode,
         scope: 'couch',
-        statusCode: rh.statusCode,
+        statusCode: responseHeaders.statusCode,
         request: req,
-        headers: rh,
+        headers: responseHeaders,
         errid: 'non_200'
       }, errs.create(parsed));
 


[couchdb-nano] 01/08: swap out var for const/let in the core code and tests

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit dc7687db32e25d97811813182e1549ccfbff72dc
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 11:28:09 2018 +0100

    swap out var for const/let in the core code and tests
---
 lib/logger.js                                    |  8 +--
 lib/nano.js                                      | 78 ++++++++++++------------
 tests/helpers/index.js                           | 16 ++---
 tests/helpers/integration.js                     | 58 +++++++++---------
 tests/helpers/unit.js                            | 24 ++++----
 tests/integration/attachment/destroy.js          | 12 ++--
 tests/integration/attachment/get.js              | 12 ++--
 tests/integration/attachment/insert.js           | 10 +--
 tests/integration/attachment/pipe.js             | 28 ++++-----
 tests/integration/attachment/update.js           | 17 +++---
 tests/integration/database/changes.js            | 14 ++---
 tests/integration/database/compact.js            | 12 ++--
 tests/integration/database/create-and-destroy.js | 12 ++--
 tests/integration/database/follow.js             | 12 ++--
 tests/integration/database/get.js                | 14 ++---
 tests/integration/database/list.js               | 12 ++--
 tests/integration/database/replicate.js          | 20 +++---
 tests/integration/database/replicator.js         | 18 +++---
 tests/integration/design/atomic.js               | 20 +++---
 tests/integration/design/compact.js              | 36 ++---------
 tests/integration/design/list.js                 | 10 +--
 tests/integration/design/multiple.js             | 14 ++---
 tests/integration/design/query.js                | 14 ++---
 tests/integration/design/search.js               | 14 ++---
 tests/integration/design/show.js                 | 12 ++--
 tests/integration/document/bulk.js               | 10 +--
 tests/integration/document/copy.js               | 14 ++---
 tests/integration/document/create_index.js       | 10 +--
 tests/integration/document/destroy.js            | 14 ++---
 tests/integration/document/fetch.js              | 14 ++---
 tests/integration/document/fetch_revs.js         | 14 ++---
 tests/integration/document/find.js               | 12 ++--
 tests/integration/document/get.js                | 10 +--
 tests/integration/document/head.js               | 10 +--
 tests/integration/document/insert.js             | 18 +++---
 tests/integration/document/list.js               | 24 ++++----
 tests/integration/document/update.js             | 15 ++---
 tests/integration/multipart/get.js               | 16 ++---
 tests/integration/multipart/insert.js            | 20 +++---
 tests/integration/shared/config.js               | 30 ++++-----
 tests/integration/shared/cookie.js               | 18 +++---
 tests/integration/shared/error.js                | 14 ++---
 tests/integration/shared/headers.js              | 10 +--
 tests/integration/shared/log.js                  | 11 ++--
 tests/integration/util/uuid.js                   | 12 ++--
 tests/intercept/design/search.js                 | 40 ++++++------
 tests/unit/attachment/destroy.js                 |  2 +-
 tests/unit/attachment/get.js                     |  2 +-
 tests/unit/attachment/insert.js                  |  6 +-
 tests/unit/database/changes.js                   |  2 +-
 tests/unit/database/compact.js                   |  2 +-
 tests/unit/database/create.js                    |  2 +-
 tests/unit/database/destroy.js                   |  2 +-
 tests/unit/database/follow.js                    |  2 +-
 tests/unit/database/get.js                       |  2 +-
 tests/unit/database/list.js                      |  2 +-
 tests/unit/database/replicate.js                 |  2 +-
 tests/unit/database/replicator.js                |  2 +-
 tests/unit/database/updates.js                   |  2 +-
 tests/unit/design/atomic.js                      |  2 +-
 tests/unit/design/compact.js                     |  2 +-
 tests/unit/design/find.js                        |  2 +-
 tests/unit/design/list.js                        |  2 +-
 tests/unit/design/search.js                      |  2 +-
 tests/unit/design/show.js                        |  2 +-
 tests/unit/design/spatial.js                     |  2 +-
 tests/unit/design/view.js                        |  2 +-
 tests/unit/document/bulk.js                      |  2 +-
 tests/unit/document/copy.js                      |  4 +-
 tests/unit/document/get.js                       | 10 +--
 tests/unit/multipart/get.js                      |  2 +-
 tests/unit/multipart/insert.js                   |  2 +-
 tests/unit/shared/error.js                       | 16 ++---
 tests/unit/shared/follow-updates.js              |  2 +-
 tests/unit/shared/jar.js                         |  8 +--
 75 files changed, 446 insertions(+), 479 deletions(-)

diff --git a/lib/logger.js b/lib/logger.js
index 4d02fc3..8d74bb0 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -12,14 +12,14 @@
 
 'use strict';
 
-var debug = require('debug')('nano/logger');
+const debug = require('debug')('nano/logger');
 
 module.exports = function logging(cfg) {
-  var log = cfg && cfg.log;
-  var logStrategy = typeof log === 'function' ? log : debug;
+  const log = cfg && cfg.log;
+  const logStrategy = typeof log === 'function' ? log : debug;
 
   return function logEvent(prefix) {
-    var eventId = (prefix ? prefix + '-' : '') +
+    const eventId = (prefix ? prefix + '-' : '') +
       (~~(Math.random() * 1e9)).toString(36);
     return function log() {
       logStrategy.call(this, eventId, [].slice.call(arguments, 0));
diff --git a/lib/nano.js b/lib/nano.js
index 6f54aa3..fe72b73 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -12,19 +12,19 @@
 
 'use strict';
 
-var u = require('url');
-var assert = require('assert');
-var querystring = require('querystring');
-var request = require('request');
-var errs = require('errs');
-var isEmpty = require('lodash.isempty');
-var follow = require('cloudant-follow');
-var logger = require('./logger');
+const u = require('url');
+const assert = require('assert');
+const querystring = require('querystring');
+const request = require('request');
+const errs = require('errs');
+const isEmpty = require('lodash.isempty');
+const follow = require('cloudant-follow');
+const logger = require('./logger');
 
-var nano;
+let nano;
 
 module.exports = exports = nano = function dbScope(cfg) {
-  var serverScope = {};
+  let serverScope = {};
 
   if (typeof cfg === 'string') {
     cfg = {url: cfg};
@@ -39,21 +39,21 @@ module.exports = exports = nano = function dbScope(cfg) {
   serverScope.config = cfg;
   cfg.requestDefaults = cfg.requestDefaults || {jar: false};
 
-  var httpAgent = (typeof cfg.request === 'function') ? cfg.request :
+  const httpAgent = (typeof cfg.request === 'function') ? cfg.request :
     request.defaults(cfg.requestDefaults);
-  var followAgent = (typeof cfg.follow === 'function') ? cfg.follow : follow;
-  var log = typeof cfg.log === 'function' ? cfg.log : logger(cfg);
-  var parseUrl = 'parseUrl' in cfg ? cfg.parseUrl : true;
+  const followAgent = (typeof cfg.follow === 'function') ? cfg.follow : follow;
+  const log = typeof cfg.log === 'function' ? cfg.log : logger(cfg);
+  const parseUrl = 'parseUrl' in cfg ? cfg.parseUrl : true;
 
   function maybeExtractDatabaseComponent() {
     if (!parseUrl) {
       return;
     }
 
-    var path = u.parse(cfg.url);
-    var pathArray = path.pathname.split('/').filter(function(e) { return e; });
-    var db = pathArray.pop();
-    var rootPath = path.pathname.replace(/\/?$/, '/..');
+    const path = u.parse(cfg.url);
+    let pathArray = path.pathname.split('/').filter(function(e) { return e; });
+    const db = pathArray.pop();
+    const rootPath = path.pathname.replace(/\/?$/, '/..');
 
     if (db) {
       cfg.url = urlResolveFix(cfg.url, rootPath).replace(/\/?$/, '');
@@ -67,16 +67,16 @@ module.exports = exports = nano = function dbScope(cfg) {
     }
     return str;
   }
-  var responseHandler = function(req, opts, resolve, reject, callback) {
+  const responseHandler = function(req, opts, resolve, reject, callback) {
     
     return function(e, h, b) {
-      var parsed;
-      var rh = h && h.headers || {};
+      let parsed;
+      const rh = h && h.headers || {};
       rh.statusCode = h && h.statusCode || 500;
       rh.uri = req.uri;
       if (e) {
         log({err: 'socket', body: b, headers: rh});
-        var ret_e = errs.merge(e, {
+        const ret_e = errs.merge(e, {
           message: 'error happened in your connection',
           scope: 'socket',
           errid: 'request'
@@ -131,7 +131,7 @@ module.exports = exports = nano = function dbScope(cfg) {
         req.headers.cookie = "XXXXXXX";
       }
 
-      var errors = errs.merge({
+      let errors = errs.merge({
         message: 'couch returned ' + rh.statusCode,
         scope: 'couch',
         statusCode: rh.statusCode,
@@ -166,21 +166,21 @@ module.exports = exports = nano = function dbScope(cfg) {
       callback = null;
     }
 
-    var qs = Object.assign({}, opts.qs);
+    const qs = Object.assign({}, opts.qs);
 
-    var headers = {
+    const headers = {
       'content-type': 'application/json',
       accept: 'application/json'
     };
 
-    var req = {
+    const req = {
       method: (opts.method || 'GET'),
       headers: headers,
       uri: cfg.url
     };
 
     // https://github.com/mikeal/request#requestjar
-    var isJar = opts.jar || cfg.jar;
+    const isJar = opts.jar || cfg.jar;
 
     if (isJar) {
       req.jar = isJar;
@@ -446,13 +446,13 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
 
   function docModule(dbName) {
-    var docScope = {};
+    let docScope = {};
     dbName = decodeURIComponent(dbName);
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#put--db-docid
     // http://docs.couchdb.org/en/latest/api/database/common.html#post--db
     function insertDoc(doc, qs, callback) {
-      var opts = {db: dbName, body: doc, method: 'POST'};
+      const opts = {db: dbName, body: doc, method: 'POST'};
 
       if (typeof qs === 'function') {
         callback = qs;
@@ -479,7 +479,7 @@ module.exports = exports = nano = function dbScope(cfg) {
     function destroyDoc(docName, rev, callback) {
       if(!docName) {
         if(callback) {
-          var msg = "Invalid doc id";
+          const msg = 'Invalid doc id';
           callback(msg, null);
           return new Promise(function(resolve, reject) {
             reject(msg);
@@ -544,7 +544,7 @@ module.exports = exports = nano = function dbScope(cfg) {
         opts = {};
       }
 
-      var qs = {
+      const qs = {
         db: dbName,
         doc: docSrc,
         method: 'COPY',
@@ -631,13 +631,13 @@ module.exports = exports = nano = function dbScope(cfg) {
       }
 
       // prevent mutation of the client qs object by using a clone
-      var qs1 = Object.assign({}, qs);
+      const qs1 = Object.assign({}, qs);
 
-      var viewPath = '_design/' + ddoc + '/_' + meta.type + '/'  + viewName;
+      const viewPath = '_design/' + ddoc + '/_' + meta.type + '/'  + viewName;
 
       // Several search parameters must be JSON-encoded; but since this is an
       // object API, several parameters need JSON endoding.
-      var paramsToEncode = ['counts', 'drilldown', 'group_sort', 'ranges', 'sort'];
+      const paramsToEncode = ['counts', 'drilldown', 'group_sort', 'ranges', 'sort'];
       paramsToEncode.forEach(function(param) {
         if (param in qs1) {
           if (typeof qs1[param] !== 'string') {
@@ -656,7 +656,7 @@ module.exports = exports = nano = function dbScope(cfg) {
 
 
       if (qs1 && qs1.keys) {
-        var body = {keys: qs1.keys};
+        const body = {keys: qs1.keys};
         delete qs1.keys;
         return relax({
           db: dbName,
@@ -667,7 +667,7 @@ module.exports = exports = nano = function dbScope(cfg) {
           stream: meta.stream
         }, callback);
       } else {
-        var req = {
+        const req = {
           db: dbName,
           method: meta.method || 'GET',
           path: viewPath,
@@ -756,12 +756,12 @@ module.exports = exports = nano = function dbScope(cfg) {
       }
       qs = qs || {};
 
-      var docName = qs.docName;
+      const docName = qs.docName;
       delete qs.docName;
 
       doc = Object.assign({_attachments: {}}, doc);
 
-      var multipart = [];
+      const multipart = [];
 
       attachments.forEach(function(att) {
         doc._attachments[att.name] = {
@@ -1026,7 +1026,7 @@ module.exports = exports = nano = function dbScope(cfg) {
     uuids: uuids
   });
 
-  var db = maybeExtractDatabaseComponent();
+  const db = maybeExtractDatabaseComponent();
 
   return db ? docModule(db) : serverScope;
 };
diff --git a/tests/helpers/index.js b/tests/helpers/index.js
index eb6a5d0..8cbebdc 100644
--- a/tests/helpers/index.js
+++ b/tests/helpers/index.js
@@ -12,14 +12,14 @@
 
 'use strict';
 
-var path = require('path');
-var fs = require('fs');
-var url = require('url');
-var nano = require('../../lib/nano');
+const path = require('path');
+const fs = require('fs');
+const url = require('url');
+const nano = require('../../lib/nano');
 
-var helpers = exports;
-var cfg = helpers.cfg = require('../fixtures/cfg');
-var auth = url.parse(cfg.admin).auth.split(':');
+const helpers = exports;
+const cfg = helpers.cfg = require('../fixtures/cfg');
+const auth = url.parse(cfg.admin).auth.split(':');
 
 helpers.noopTest = function(t){ t.end(); };
 helpers.timeout = cfg.timeout;
@@ -34,7 +34,7 @@ helpers.username = auth[0];
 helpers.password = auth[1];
 
 helpers.loadFixture = function helpersLoadFixture(filename, json) {
-  var contents = fs.readFileSync(
+  const contents = fs.readFileSync(
     path.join(__dirname, '..', 'fixtures', filename), (json ? 'ascii' : null));
   return json ? JSON.parse(contents) : contents;
 };
diff --git a/tests/helpers/integration.js b/tests/helpers/integration.js
index d146e71..340c72f 100644
--- a/tests/helpers/integration.js
+++ b/tests/helpers/integration.js
@@ -12,18 +12,18 @@
 
 'use strict';
 
-var async = require('async');
-var debug = require('debug');
-var path = require('path');
-var harness = require('tape-it');
-var endsWith = require('endswith');
-var cfg = require('../fixtures/cfg');
-var nano = require('../../lib/nano');
-var helpers = require('./');
+const async = require('async');
+const debug = require('debug');
+const path = require('path');
+const harness = require('tape-it');
+const endsWith = require('endswith');
+const cfg = require('../fixtures/cfg');
+const nano = require('../../lib/nano');
+const helpers = require('./');
 
 helpers.setup = function() {
-  var self = this;
-  var args = Array.prototype.slice.call(arguments);
+  const self = this;
+  const args = Array.prototype.slice.call(arguments);
 
   return function(assert) {
     args.push(function(err) {
@@ -36,8 +36,8 @@ helpers.setup = function() {
 };
 
 helpers.teardown = function() {
-  var self = this;
-  var args = Array.prototype.slice.call(arguments);
+  const self = this;
+  const args = Array.prototype.slice.call(arguments);
 
   return function(assert) {
     args.push(function(err) {
@@ -51,21 +51,21 @@ helpers.teardown = function() {
 };
 
 helpers.harness = function(name, setup, teardown) {
-  var parent = name || module.parent.filename;
-  var fileName = path.basename(parent).split('.')[0];
-  var parentDir = path.dirname(parent)
+  const parent = name || module.parent.filename;
+  const fileName = path.basename(parent).split('.')[0];
+  const parentDir = path.dirname(parent)
     .split(path.sep).reverse()[0];
-  var shortPath = path.join(parentDir, fileName);
-  var log = debug(path.join('nano', 'tests', 'integration', shortPath));
-  var dbName = shortPath.replace('/', '_');
-  var nanoLog = nano({
+  const shortPath = path.join(parentDir, fileName);
+  const log = debug(path.join('nano', 'tests', 'integration', shortPath));
+  const dbName = shortPath.replace('/', '_');
+  const nanoLog = nano({
     url: cfg.couch,
     log: log
   });
 
-  var mock = helpers.nock(helpers.couch, shortPath, log);
-  var db   = nanoLog.use(dbName);
-  var locals = {
+  const mock = helpers.nock(helpers.couch, shortPath, log);
+  const db   = nanoLog.use(dbName);
+  const locals = {
     mock: mock,
     db: db,
     nano: nanoLog
@@ -82,15 +82,15 @@ helpers.harness = function(name, setup, teardown) {
 };
 
 helpers.nock = function helpersNock(url, fixture, log) {
-  var nock = require('nock');
-  var nockDefs = require('../fixtures/' + fixture + '.json');
+  const nock = require('nock');
+  const nockDefs = require('../fixtures/' + fixture + '.json');
 
   nockDefs.forEach(function(n) {
-    var headers = n.headers || {};
-    var response = n.buffer ? endsWith(n.buffer, '.png') ?
+    let headers = n.headers || {};
+    const response = n.buffer ? endsWith(n.buffer, '.png') ?
         helpers.loadFixture(n.buffer) : new Buffer(n.buffer, 'base64') :
         n.response || '';
-    var body = n.base64 ? new Buffer(n.base64, 'base64').toString() :
+        const body = n.base64 ? new Buffer(n.base64, 'base64').toString() :
         n.body || '';
 
     if (typeof headers === 'string' && endsWith(headers, '.json')) {
@@ -166,7 +166,7 @@ helpers.viewDerek = function viewDerek(db, assert, opts, next, method) {
 };
 
 helpers.insertOne = function insertThree(assert) {
-  var db = this.db;
+  const db = this.db;
   db.insert({'foo': 'baz'}, 'foobaz', function(err) {
     assert.equal(err, null, 'should store docs');
     assert.end();
@@ -174,7 +174,7 @@ helpers.insertOne = function insertThree(assert) {
 };
 
 helpers.insertThree = function insertThree(assert) {
-  var db = this.db;
+  const db = this.db;
   async.parallel([
     function(cb) { db.insert({'foo': 'bar'}, 'foobar', cb); },
     function(cb) { db.insert({'bar': 'foo'}, 'barfoo', cb); },
diff --git a/tests/helpers/unit.js b/tests/helpers/unit.js
index 52cd7e6..a15dfc6 100644
--- a/tests/helpers/unit.js
+++ b/tests/helpers/unit.js
@@ -12,20 +12,20 @@
 
 'use strict';
 
-var helpers = require('./');
-var Client = require('../../lib/nano');
-var test  = require('tape');
-var _ = require('underscore');
+const helpers = require('./');
+const Client = require('../../lib/nano');
+const test  = require('tape');
+const _ = require('underscore');
 
 helpers.unit = function(method, error) {
-  var unitName = 'nano/tests/unit/' + method.join('/');
-  var debug = require('debug')(unitName);
+  const unitName = 'nano/tests/unit/' + method.join('/');
+  const debug = require('debug')(unitName);
 
   function log(data) {
     debug({ got: data.body });
   }
 
-  var cli = helpers.mockClientOk(log, error);
+  let cli = helpers.mockClientOk(log, error);
 
   //
   // allow database creation and other server stuff
@@ -40,15 +40,15 @@ helpers.unit = function(method, error) {
     cli.server = helpers.mockClientDb(log, error);
   }
 
-  var testNr = 1;
+  let testNr = 1;
 
   return function() {
-    var args = Array.prototype.slice.call(arguments);
-    var stub = args.pop();
+    const args = Array.prototype.slice.call(arguments);
+    const stub = args.pop();
 
     test(unitName + ':' + testNr++,
     function(assert) {
-      var f;
+      let f;
       assert.ok(typeof stub, 'object');
 
       //
@@ -101,7 +101,7 @@ helpers.unit = function(method, error) {
 function mockClient(code, path, extra) {
   return function(debug, error) {
     extra = extra || {};
-    var opts = _.extend(extra, {
+    const opts = _.extend(extra, {
       url: helpers.couch + path,
       log: debug,
       request: function(req, cb) {
diff --git a/tests/integration/attachment/destroy.js b/tests/integration/attachment/destroy.js
index 9b5b7e6..cae9552 100644
--- a/tests/integration/attachment/destroy.js
+++ b/tests/integration/attachment/destroy.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should be able to insert a new plain text attachment', function(assert) {
-  var p = db.attachment.insert('new',
+  const p = db.attachment.insert('new',
   'att', 'Hello World!', 'text/plain', function(error, att) {
     assert.equal(error, null, 'store the attachment');
     assert.equal(att.ok, true, 'response ok');
@@ -42,7 +42,7 @@ it('should be able to insert a new plain text attachment', function(assert) {
 });
 
 it('should fail destroying with a bad filename', function(assert) {
-  var p = db.attachment.destroy('new', false, true, function(error, response) {
+  const p = db.attachment.destroy('new', false, true, function(error, response) {
     assert.equal(response, undefined, 'no response should be given');
   });
   assert.ok(helpers.isPromise(p), 'returns Promise');
diff --git a/tests/integration/attachment/get.js b/tests/integration/attachment/get.js
index ad180d8..12c20ba 100644
--- a/tests/integration/attachment/get.js
+++ b/tests/integration/attachment/get.js
@@ -12,10 +12,10 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should be able to fetch an attachment', function(assert) {
   db.attachment.insert('new_string', 'att', 'Hello', 'text/plain',
@@ -23,7 +23,7 @@ it('should be able to fetch an attachment', function(assert) {
     assert.equal(error, null, 'should store `hello`');
     assert.equal(hello.ok, true, 'response ok');
     assert.ok(hello.rev, 'should have a revision number');
-    var p = db.attachment.get('new_string', 'att',
+    const p = db.attachment.get('new_string', 'att',
     function(error, helloWorld) {
       assert.equal(error, null, 'should get `hello`');
       assert.equal('Hello', helloWorld.toString(), 'string is reflexive');
@@ -45,7 +45,7 @@ it('should insert and fetch a binary file', function(assert) {
     assert.equal(error, null, 'should store `123`');
     assert.equal(hello.ok, true, 'response ok');
     assert.ok(hello.rev, 'should have a revision number');
-    var p = db.attachment.get('new_binary', 'att',
+    const p = db.attachment.get('new_binary', 'att',
     function(error, binaryData) {
       assert.equal(error, null, 'should get the binary data');
       assert.equal('123', binaryData.toString(), 'binary data is reflexive');
diff --git a/tests/integration/attachment/insert.js b/tests/integration/attachment/insert.js
index 821fb40..6389592 100644
--- a/tests/integration/attachment/insert.js
+++ b/tests/integration/attachment/insert.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should be able to insert a simple attachment', function(assert) {
-  var p = db.attachment.insert('new', 'att', 'Hello World!', 'text/plain',
+  const p = db.attachment.insert('new', 'att', 'Hello World!', 'text/plain',
   function(error, att) {
     assert.equal(error, null, 'should store the attachment');
     assert.equal(att.ok, true, 'response ok');
diff --git a/tests/integration/attachment/pipe.js b/tests/integration/attachment/pipe.js
index 3470c61..e81ff08 100644
--- a/tests/integration/attachment/pipe.js
+++ b/tests/integration/attachment/pipe.js
@@ -12,18 +12,18 @@
 
 'use strict';
 
-var fs = require('fs');
-var path = require('path');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
-var pixel = helpers.pixel;
+const fs = require('fs');
+const path = require('path');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
+const pixel = helpers.pixel;
 
 it('should be able to pipe to a writeStream', function(assert) {
-  var buffer = new Buffer(pixel, 'base64');
-  var filename = path.join(__dirname, '.temp.bmp');
-  var ws = fs.createWriteStream(filename);
+  const buffer = new Buffer(pixel, 'base64');
+  const filename = path.join(__dirname, '.temp.bmp');
+  const ws = fs.createWriteStream(filename);
 
   ws.on('close', function() {
     assert.equal(fs.readFileSync(filename).toString('base64'), pixel);
@@ -39,7 +39,7 @@ it('should be able to pipe to a writeStream', function(assert) {
 });
 
 it('should be able to pipe to a writeStream', function(assert) {
-  var ws = fs.createWriteStream('/dev/null');
+  const ws = fs.createWriteStream('/dev/null');
   db.attachment.getAsStream('new', 'att', function() {})
     .pipe(ws)
     .on('end', function() {
@@ -48,9 +48,9 @@ it('should be able to pipe to a writeStream', function(assert) {
 });
 
 it('should be able to pipe from a readStream', function(assert) {
-  var logo = path.join(__dirname, '..', '..', 'fixtures', 'logo.png');
-  var rs = fs.createReadStream(logo);
-  var is = db.attachment.insertAsStream('nodejs', 'logo.png', null, 'image/png', function() {
+  const logo = path.join(__dirname, '..', '..', 'fixtures', 'logo.png');
+  const rs = fs.createReadStream(logo);
+  const is = db.attachment.insertAsStream('nodejs', 'logo.png', null, 'image/png', function() {
   });
 
   is.on('end', function() {
diff --git a/tests/integration/attachment/update.js b/tests/integration/attachment/update.js
index 11d1b22..7d3bae8 100644
--- a/tests/integration/attachment/update.js
+++ b/tests/integration/attachment/update.js
@@ -12,21 +12,22 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var pixel = helpers.pixel;
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
-var rev;
+const helpers = require('../../helpers/integration');
+const pixel = helpers.pixel;
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
+
+let rev;
 
 it('should be able to insert and update attachments', function(assert) {
-  var buffer = new Buffer(pixel, 'base64');
+  const buffer = new Buffer(pixel, 'base64');
   db.attachment.insert('new', 'att', 'Hello', 'text/plain',
   function(error, hello) {
     assert.equal(error, null, 'should store hello');
     assert.equal(hello.ok, true, 'response ok');
     assert.ok(hello.rev, 'should have a revision');
-    var p = db.attachment.insert('new', 'att', buffer, 'image/bmp',
+    const p = db.attachment.insert('new', 'att', buffer, 'image/bmp',
     {rev: hello.rev}, function(error, bmp) {
       assert.equal(error, null, 'should store the pixel');
       assert.ok(bmp.rev, 'should store a revision');
diff --git a/tests/integration/database/changes.js b/tests/integration/database/changes.js
index d13493d..b223f9b 100644
--- a/tests/integration/database/changes.js
+++ b/tests/integration/database/changes.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should be able to insert three documents', helpers.insertThree);
 
 it('should be able to receive changes since seq:0', function(assert) {
-  var p = db.changes({since:0}, function(error, response) {
+  const p = db.changes({since:0}, function(error, response) {
     assert.equal(error, null, 'gets response from changes');
     assert.equal(response.results.length, 3, 'gets three results');
   });
@@ -35,7 +35,7 @@ it('should be able to receive changes since seq:0', function(assert) {
 });
 
 it('should be able to receive changes since seq:0 as stream', function(assert) {
-  var p = db.changesAsStream({since:0}, function(error, response) {
+  const p = db.changesAsStream({since:0}, function(error, response) {
     assert.equal(error, null, 'gets response from changes');
     assert.equal(response.results.length, 3, 'gets three results');
     assert.end();
@@ -45,7 +45,7 @@ it('should be able to receive changes since seq:0 as stream', function(assert) {
 });
 
 it('should be able to receive changes - no params - stream', function(assert) {
-  var p = db.changesAsStream(function(error) {
+  const p = db.changesAsStream(function(error) {
     assert.equal(error, null, 'gets response from changes');
     assert.end();
   });
diff --git a/tests/integration/database/compact.js b/tests/integration/database/compact.js
index 50ed454..ef6137f 100644
--- a/tests/integration/database/compact.js
+++ b/tests/integration/database/compact.js
@@ -12,10 +12,10 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should store and delete `goofy`', function(assert) {
   db.insert({'foo': 'baz'}, 'goofy', function(error, foo) {
@@ -30,7 +30,7 @@ it('should store and delete `goofy`', function(assert) {
 });
 
 it('should have run the compaction', function(assert) {
-  var p = db.compact(function(error) {
+  const p = db.compact(function(error) {
     assert.equal(error, null, 'compact should respond');
     db.info(function(error, info) {
       assert.equal(error, null, 'info should respond');
@@ -64,5 +64,5 @@ it('should finish compaction before ending', function(assert) {
     });
   }
 
-  var task = setInterval(nextWhenFinished, 100);
+  const task = setInterval(nextWhenFinished, 100);
 });
diff --git a/tests/integration/database/create-and-destroy.js b/tests/integration/database/create-and-destroy.js
index 94d082b..af8259c 100644
--- a/tests/integration/database/create-and-destroy.js
+++ b/tests/integration/database/create-and-destroy.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var nano = harness.locals.nano;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const nano = harness.locals.nano;
 
 it('should be able to create `az09_$()+-/` database', function(assert) {
   nano.db.create('az09_$()+-/', function(err) {
@@ -27,7 +27,7 @@ it('should be able to create `az09_$()+-/` database', function(assert) {
 
 it('should be able to use config from a nano object to create a db',
 function(assert) {
-  var config = helpers.Nano(
+  const config = helpers.Nano(
     helpers.couch + '/' + encodeURIComponent('with/slash')).config;
   helpers.Nano(config.url).db.create(config.db, function(err) {
     assert.equal(err, null, 'should create database');
diff --git a/tests/integration/database/follow.js b/tests/integration/database/follow.js
index e66749c..42ce686 100644
--- a/tests/integration/database/follow.js
+++ b/tests/integration/database/follow.js
@@ -12,18 +12,18 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 if (helpers.unmocked) {
   it('should insert a bunch of items', helpers.insertThree);
 
-  var feed1;
+  let feed1;
 
   it('should be able to get the changes feed', function(assert) {
-    var i = 3;
+    let i = 3;
 
     feed1 = db.follow({since: '0'});
 
diff --git a/tests/integration/database/get.js b/tests/integration/database/get.js
index ce1e61c..a01ece8 100644
--- a/tests/integration/database/get.js
+++ b/tests/integration/database/get.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var nano = harness.locals.nano;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const nano = harness.locals.nano;
 
 it('should be able to fetch the database', function(assert) {
-  var p = nano.db.get('database_get', function(error, response) {
+  const p = nano.db.get('database_get', function(error, response) {
     assert.equal(error, null, 'should get the db');
     assert.equal(response['doc_count'], 0, 'should be empty');
     assert.equal(response['db_name'], 'database_get', 'name');
@@ -35,9 +35,9 @@ it('should be able to fetch the database', function(assert) {
 });
 
 it('resolves db URL correctly for http://app.com/_couchdb', function(assert) {
-  var nano = require('../../../lib/nano');
+  const nano = require('../../../lib/nano');
 
-  var couch = nano({
+  const couch = nano({
     url: 'http://app.com/_couchdb/',
     parseUrl: false,
     request: function(options) {
diff --git a/tests/integration/database/list.js b/tests/integration/database/list.js
index f689681..aa35a47 100644
--- a/tests/integration/database/list.js
+++ b/tests/integration/database/list.js
@@ -12,10 +12,10 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var nano = harness.locals.nano;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const nano = harness.locals.nano;
 
 it('should ensure _replicator and _users are created', function(assert) {
   nano.db.create('_replicator', function() {
@@ -28,9 +28,9 @@ it('should ensure _replicator and _users are created', function(assert) {
 });
 
 it('should list the correct databases', function(assert) {
-  var p = nano.db.list(function(error, list) {
+  const p = nano.db.list(function(error, list) {
     assert.equal(error, null, 'should list databases');
-    var filtered = list.filter(function(e) {
+    const filtered = list.filter(function(e) {
       return e === 'database_list' || e === '_replicator' || e === '_users';
     });
     assert.equal(filtered.length, 3, 'should have exactly 3 dbs');
diff --git a/tests/integration/database/replicate.js b/tests/integration/database/replicate.js
index 1212d0a..5ca95aa 100644
--- a/tests/integration/database/replicate.js
+++ b/tests/integration/database/replicate.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
-var nano = harness.locals.nano;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
+const nano = harness.locals.nano;
 
-var replica;
-var replica2;
+let replica;
+let replica2;
 
 it('should insert a bunch of items', helpers.insertThree);
 
@@ -35,7 +35,7 @@ it('creates a bunch of database replicas', function(assert) {
 it('should be able to replicate three docs', function(assert) {
   replica = nano.use('database_replica');
 
-  var p = db.replicate('database_replica', function(error) {
+  const p = db.replicate('database_replica', function(error) {
     assert.equal(error, null, 'replication should work');
     replica.list(function(error, list) {
       assert.equal(error, null, 'should be able to invoke list');
@@ -66,7 +66,7 @@ it('should be able to replicate to a `nano` object', function(assert) {
 });
 
 it('should be able to replicate with params', function(assert) {
-  var p = db.replicate('database_replica', {}, function(error) {
+  const p = db.replicate('database_replica', {}, function(error) {
     assert.equal(error, null, 'replication should work');
   });
   assert.ok(helpers.isPromise(p), 'returns Promise');
diff --git a/tests/integration/database/replicator.js b/tests/integration/database/replicator.js
index 46db4c6..0585292 100644
--- a/tests/integration/database/replicator.js
+++ b/tests/integration/database/replicator.js
@@ -12,16 +12,16 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
-var nano = harness.locals.nano;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
+const nano = harness.locals.nano;
 
-var replica;
-var replica2;
-var replica3;
+let replica;
+let replica2;
+let replica3;
 
 it('should insert a bunch of items', helpers.insertThree);
 
diff --git a/tests/integration/design/atomic.js b/tests/integration/design/atomic.js
index b9d46ea..2c18848 100644
--- a/tests/integration/design/atomic.js
+++ b/tests/integration/design/atomic.js
@@ -12,18 +12,18 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
-var rev;
+let rev;
 
 it('should be able to insert an atomic design doc', function(assert) {
-  var p = db.insert({
+  const p = db.insert({
     updates: {
       inplace: function(doc, req) {
-        var body = JSON.parse(req.body);
+        const body = JSON.parse(req.body);
         doc[body.field] = body.value;
         return [doc, JSON.stringify(doc)];
       },
@@ -46,7 +46,7 @@ it('should be able to insert an atomic design doc', function(assert) {
 });
 
 it('should be able to insert atomically', function(assert) {
-  var p = db.atomic('update', 'inplace', 'foobar', {
+  const p = db.atomic('update', 'inplace', 'foobar', {
     field: 'foo',
     value: 'bar'
   }, function(error, response) {
@@ -58,7 +58,7 @@ it('should be able to insert atomically', function(assert) {
 });
 
 it('should be able to update atomically without a body', function (assert) {
-  var p = db.insert({}, 'baz', function () {
+  const p = db.insert({}, 'baz', function () {
     db.atomic('update', 'addbaz', 'baz', function (error, response) {
       assert.equal(error, null, 'should be able to update');
       assert.equal(response.baz, 'biz', 'and the new field is present');
@@ -69,7 +69,7 @@ it('should be able to update atomically without a body', function (assert) {
 });
 
 it('should be able to update with slashes on the id', function(assert) {
-  var p = db.insert({'wat': 'wat'}, 'wat/wat', function(error, foo) {
+  const p = db.insert({'wat': 'wat'}, 'wat/wat', function(error, foo) {
     assert.equal(error, null, 'stores `wat`');
     assert.equal(foo.ok, true, 'response ok');
     db.atomic('update', 'inplace', 'wat/wat', {
diff --git a/tests/integration/design/compact.js b/tests/integration/design/compact.js
index 9628dba..fbcdfe4 100644
--- a/tests/integration/design/compact.js
+++ b/tests/integration/design/compact.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should insert `alice` the design doc', function(assert) {
   async.waterfall([
@@ -40,29 +40,3 @@ it('should insert `alice` the design doc', function(assert) {
     assert.end();
   });
 });
-
-/*it('should be able to compact a view', function(assert) {
-  async.waterfall([
-    function(next) {
-      db.view.compact('alice', next);
-    },
-    function(response, _, next) {
-      function dbInfo() {
-        db.info(function(err, info) {
-          if (!info['compact_running']) {
-            clearInterval(task);
-            next();
-          }
-        });
-      }
-      var task = setInterval(dbInfo, 50);
-    },
-    function(next) {
-      db.view('alice', 'by_id', next);
-    }
-  ], function(err, view) {
-    assert.equal(err, null, 'should be able to call the view');
-    assert.equal(view['total_rows'], 0, 'and see stuff got deleted');
-    assert.end();
-  });
-});*/
diff --git a/tests/integration/design/list.js b/tests/integration/design/list.js
index 7dcdf1a..514638c 100644
--- a/tests/integration/design/list.js
+++ b/tests/integration/design/list.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should create a ddoc and insert some docs', helpers.prepareAView);
 
 it('should get the people by running the ddoc', function(assert) {
-  var p = db.viewWithList('people', 'by_name_and_city', 'my_list', {
+  const p = db.viewWithList('people', 'by_name_and_city', 'my_list', {
     key: [
       'Derek',
       'San Francisco'
diff --git a/tests/integration/design/multiple.js b/tests/integration/design/multiple.js
index 8868be2..6205638 100644
--- a/tests/integration/design/multiple.js
+++ b/tests/integration/design/multiple.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should be able to insert docs and design doc', function(assert) {
-  var p = db.insert({
+  const p = db.insert({
     views: {
       'by_id': {
         map: 'function(doc) { emit(doc._id, doc); }'
@@ -41,7 +41,7 @@ it('should be able to insert docs and design doc', function(assert) {
 it('should insert a bunch of items', helpers.insertThree);
 
 it('get multiple docs with a composed key', function(assert) {
-  var p = db.view('alice', 'by_id', {
+  const p = db.view('alice', 'by_id', {
     keys: ['foobar', 'barfoo'],
     'include_docs': true
   }, function(err, view) {
@@ -63,7 +63,7 @@ it('get multiple docs with a composed key', function(assert) {
 });
 
 it('get multiple docs with a composed key as a stream', function(assert) {
-  var p = db.viewAsStream('alice', 'by_id', {
+  const p = db.viewAsStream('alice', 'by_id', {
     keys: ['foobar', 'barfoo'],
     'include_docs': true
   }, function(err, view) {
diff --git a/tests/integration/design/query.js b/tests/integration/design/query.js
index c2b2022..0d49a65 100644
--- a/tests/integration/design/query.js
+++ b/tests/integration/design/query.js
@@ -12,14 +12,14 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
-var viewDerek = helpers.viewDerek;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
+const viewDerek = helpers.viewDerek;
 
-var opts = {key: ['Derek', 'San Francisco']};
+const opts = {key: ['Derek', 'San Francisco']};
 
 it('should create a ddoc and insert some docs', helpers.prepareAView);
 
diff --git a/tests/integration/design/search.js b/tests/integration/design/search.js
index ce7a439..94c37a5 100644
--- a/tests/integration/design/search.js
+++ b/tests/integration/design/search.js
@@ -12,19 +12,19 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
-var viewDerek = helpers.viewDerek;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
+const viewDerek = helpers.viewDerek;
 
 //
 // these are cloudant only
 // tests do no run without mocks
 //
 if (helpers.mocked) {
-  var opts = {key: ['Derek', 'San Francisco']};
+  const opts = {key: ['Derek', 'San Francisco']};
 
   it('should create a ddoc and insert some docs', function(assert) {
     helpers.prepareAView(assert, '/_search', db);
diff --git a/tests/integration/design/show.js b/tests/integration/design/show.js
index f22a8e5..174339f 100644
--- a/tests/integration/design/show.js
+++ b/tests/integration/design/show.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var async = require('async');
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const async = require('async');
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should insert a show ddoc', function(assert) {
   db.insert({
@@ -73,7 +73,7 @@ it('should insert a show ddoc', function(assert) {
 });
 
 it('should show the amazing clemens in json', function(assert) {
-  var p = db.show('people', 'singleDoc', 'p_clemens', function(error, doc, rh) {
+  const p = db.show('people', 'singleDoc', 'p_clemens', function(error, doc, rh) {
     assert.equal(error, null, 'its alive');
     assert.equal(rh['content-type'], 'application/json');
     assert.equal(doc.name, 'Clemens');
diff --git a/tests/integration/document/bulk.js b/tests/integration/document/bulk.js
index 61b156f..65dac59 100644
--- a/tests/integration/document/bulk.js
+++ b/tests/integration/document/bulk.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('should be able to bulk insert two docs', function(assert) {
-  var p = db.bulk({
+  const p = db.bulk({
     'docs': [
       {'key':'baz', 'name':'bazzel'},
       {'key':'bar', 'name':'barry'}
diff --git a/tests/integration/document/copy.js b/tests/integration/document/copy.js
index a49769f..3353b42 100644
--- a/tests/integration/document/copy.js
+++ b/tests/integration/document/copy.js
@@ -12,10 +12,10 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
 it('must insert two docs before the tests start', function(assert) {
   db.insert({'foo': 'baz'}, 'foo_src', function(error, src) {
@@ -32,7 +32,7 @@ it('must insert two docs before the tests start', function(assert) {
 });
 
 it('should be able to copy and overwrite a document', function(assert) {
-  var p = db.copy('foo_src', 'foo_dest', {overwrite: true},
+  const p = db.copy('foo_src', 'foo_dest', {overwrite: true},
   function(error, response, headers) {
     assert.equal(error, null,
       'should have copied and overwritten foo_src to foo_dest');
@@ -49,7 +49,7 @@ it('should be able to copy and overwrite a document', function(assert) {
 
 it('copy without overwrite should return conflict for exists docs',
 function(assert) {
-  var p = db.copy('foo_src', 'foo_dest', function(error) {
+  const p = db.copy('foo_src', 'foo_dest', function(error) {
     assert.equal(error.error, 'conflict', 'should be a conflict');
   });
   assert.ok(helpers.isPromise(p), 'returns Promise');
@@ -62,7 +62,7 @@ function(assert) {
 });
 
 it('copy to a new destination should work', function(assert) {
-  var p = db.copy('foo_src', 'baz_dest', function(error, response, headers) {
+  const p = db.copy('foo_src', 'baz_dest', function(error, response, headers) {
     assert.equal(error, null, 'copies into new document');
     assert.equal(headers['statusCode'], 201, 'Status code should be 201');
   });
diff --git a/tests/integration/document/create_index.js b/tests/integration/document/create_index.js
index 2a2570c..6f8ce3f 100644
--- a/tests/integration/document/create_index.js
+++ b/tests/integration/document/create_index.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a one item', helpers.insertOne);
 
 it ('Should create one simple index', function(assert) {
-  var p = db.createIndex({
+  const p = db.createIndex({
     name: 'fooindex',
     index: { fields: ['foo'] }
   }, function(error, foo) {
diff --git a/tests/integration/document/destroy.js b/tests/integration/document/destroy.js
index 4bea37a..b8e3f28 100644
--- a/tests/integration/document/destroy.js
+++ b/tests/integration/document/destroy.js
@@ -12,12 +12,12 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
-var db = harness.locals.db;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
+const db = harness.locals.db;
 
-var rev;
+let rev;
 
 it('should insert a document', function(assert) {
   db.insert({'foo': 'baz'}, 'foobaz', function(error, foo) {
@@ -30,7 +30,7 @@ it('should insert a document', function(assert) {
 });
 
 it('should not delete a db', function(assert) {
-  var p = db.destroy(undefined, undefined, function(error, response) {
+  const p = db.destroy(undefined, undefined, function(error, response) {
     assert.equal(error, 'Invalid doc id', 'validated delete parameters');
     assert.equal(response, null, 'ok!');
   });
@@ -44,7 +44,7 @@ it('should not delete a db', function(assert) {
 });
 
 it('should delete a document', function(assert) {
-  var p = db.destroy('foobaz', rev, function(error, response) {
+  const p = db.destroy('foobaz', rev, function(error, response) {
     assert.equal(error, null, 'deleted foo');
     assert.equal(response.ok, true, 'ok!');
   });
diff --git a/tests/integration/document/fetch.js b/tests/integration/document/fetch.js
index becf6a3..eaf68a8 100644
--- a/tests/integration/document/fetch.js
+++ b/tests/integration/document/fetch.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a bunch of items', helpers.insertThree);
 
 it('should be able to fetch with one key', function(assert) {
-  var p = db.fetch({keys:['foobar']}, function(error, docs) {
+  const p = db.fetch({keys:['foobar']}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.equal(docs.rows.length, 1, 'and get one row');
     assert.equal(docs['total_rows'], 3, 'out of 3');
@@ -37,7 +37,7 @@ it('should be able to fetch with one key', function(assert) {
 });
 
 it('should be able to fetch with multiple keys', function(assert) {
-  var p = db.fetch({keys:['foobar', 'barfoo']}, function(error, docs) {
+  const p = db.fetch({keys:['foobar', 'barfoo']}, function(error, docs) {
     assert.equal(error, null, 'no errors');
     assert.equal(docs.rows.length, 2, 'two rows');
     assert.equal(docs['total_rows'], 3, 'out of 3');
@@ -54,7 +54,7 @@ it('should be able to fetch with multiple keys', function(assert) {
 });
 
 it('should be able to fetch with params', function(assert) {
-  var p = db.fetch({keys:['foobar']}, {not: 'important'}, function(error, docs) {
+  const p = db.fetch({keys:['foobar']}, {not: 'important'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.equal(docs.rows.length, 1, 'and get one row');
     assert.equal(docs['total_rows'], 3, 'out of 3');
diff --git a/tests/integration/document/fetch_revs.js b/tests/integration/document/fetch_revs.js
index d30cddc..f19ba0e 100644
--- a/tests/integration/document/fetch_revs.js
+++ b/tests/integration/document/fetch_revs.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a bunch of items', helpers.insertThree);
 
 it('should be able to fetch with one key', function(assert) {
-  var p = db.fetchRevs({keys:['foobar']}, function(error, docs) {
+  const p = db.fetchRevs({keys:['foobar']}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.equal(docs.rows.length, 1, 'and get one row');
     assert.equal(docs['total_rows'], 3, 'out of 3');
@@ -39,7 +39,7 @@ it('should be able to fetch with one key', function(assert) {
 });
 
 it('should be able to fetch with multiple keys', function(assert) {
-  var p = db.fetchRevs({keys:['foobar', 'barfoo']}, function(error, docs) {
+  const p = db.fetchRevs({keys:['foobar', 'barfoo']}, function(error, docs) {
     assert.equal(error, null, 'it works');
     assert.equal(docs.rows.length, 2, 'two rows');
     assert.equal(docs['total_rows'], 3, 'out of 3');
@@ -60,7 +60,7 @@ it('should be able to fetch with multiple keys', function(assert) {
 });
 
 it('should be able to fetch with params', function(assert) {
-  var p = db.fetchRevs({keys:['foobar']}, {still: 'no'}, function(error, docs) {
+  const p = db.fetchRevs({keys:['foobar']}, {still: 'no'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.equal(docs.rows.length, 1, 'and get one row');
     assert.equal(docs['total_rows'], 3, 'out of 3');
diff --git a/tests/integration/document/find.js b/tests/integration/document/find.js
index 28d504a..4959469 100644
--- a/tests/integration/document/find.js
+++ b/tests/integration/document/find.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a bunch of items', helpers.insertThree);
 
 it('should be to do a mango query', function(assert) {
-  var p = db.find({ selector: { foo: 'baz'}}, function(error, response) {
+  const p = db.find({ selector: { foo: 'baz'}}, function(error, response) {
     assert.equal(error, null, 'should work');
     assert.equal(response.docs.length, 1, 'and get one row');
   });
@@ -35,7 +35,7 @@ it('should be to do a mango query', function(assert) {
 });
 
 it('should be to do a mango query with streams', function(assert) {
-  var p = db.findAsStream({ selector: { foo: 'baz'}}, function(error, response) {
+  const p = db.findAsStream({ selector: { foo: 'baz'}}, function(error, response) {
     assert.equal(error, null, 'should work');
     assert.equal(response.docs.length, 1, 'and get one row');
     assert.end();
diff --git a/tests/integration/document/get.js b/tests/integration/document/get.js
index ed6814f..b6223a4 100644
--- a/tests/integration/document/get.js
+++ b/tests/integration/document/get.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a one item', helpers.insertOne);
 
 it('should get the document', function(assert) {
-  var p = db.get('foobaz', {'revs_info': true}, function(error, foobaz) {
+  const p = db.get('foobaz', {'revs_info': true}, function(error, foobaz) {
     assert.equal(error, null, 'should get foobaz');
     assert.ok(foobaz['_revs_info'], 'got revs info');
     assert.equal(foobaz._id, 'foobaz', 'id is food');
diff --git a/tests/integration/document/head.js b/tests/integration/document/head.js
index 1b98f81..4ab2647 100644
--- a/tests/integration/document/head.js
+++ b/tests/integration/document/head.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should insert a one item', helpers.insertOne);
 
 it('should get a status code when you do head', function(assert) {
-  var p = db.head('foobaz', function(error, body, headers) {
+  const p = db.head('foobaz', function(error, body, headers) {
     assert.equal(error, null, 'should get the head of foobaz');
     assert.equal(headers['statusCode'], 200, 'and is ok');
   });
diff --git a/tests/integration/document/insert.js b/tests/integration/document/insert.js
index fa05d37..d38ed12 100644
--- a/tests/integration/document/insert.js
+++ b/tests/integration/document/insert.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
-var rev;
+let rev;
 
 it('should insert one simple document', function(assert) {
-  var p = db.insert({'foo': 'baz'}, 'foobaz', function(error, foo) {
+  const p = db.insert({'foo': 'baz'}, 'foobaz', function(error, foo) {
     rev = foo.rev;
     assert.equal(error, null, 'should have stored foo');
     assert.equal(foo.ok, true, 'response should be ok');
@@ -38,7 +38,7 @@ it('should insert one simple document', function(assert) {
 });
 
 it('should fail to insert again since it already exists', function(assert) {
-  var p = db.insert({}, 'foobaz', function(error) {
+  const p = db.insert({}, 'foobaz', function(error) {
     assert.equal(error['statusCode'], 409, 'should be conflict');
     assert.equal(error.scope, 'couch', 'scope is couch');
     assert.equal(error.error, 'conflict', 'type is conflict');
@@ -55,7 +55,7 @@ it('should fail to insert again since it already exists', function(assert) {
 });
 
 it('should be able to use custom params in insert', function(assert) {
-  var p = db.insert({
+  const p = db.insert({
     foo: 'baz',
     _rev: rev
   }, {
@@ -78,7 +78,7 @@ it('should be able to use custom params in insert', function(assert) {
 });
 
 it('should be able to insert functions in docs', function(assert) {
-  var p = db.insert({
+  const p = db.insert({
     fn: function() { return true; },
     fn2: 'function () { return true; }'
   }, function(error, fns) {
diff --git a/tests/integration/document/list.js b/tests/integration/document/list.js
index 9b336bd..1bd580a 100644
--- a/tests/integration/document/list.js
+++ b/tests/integration/document/list.js
@@ -12,16 +12,16 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var nano = harness.locals.nano;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const nano = harness.locals.nano;
+const it = harness.it;
 
 it('should insert a bunch of items', helpers.insertThree);
 
 it('should list the three documents', function(assert) {
-  var p = db.list(function(error, docs) {
+  const p = db.list(function(error, docs) {
     assert.equal(error, null, 'should get list');
     assert.equal(docs['total_rows'], 3, 'with total three rows');
     assert.ok(docs.rows, 'and the rows themselves');
@@ -53,7 +53,7 @@ it('should be able to list using the `relax` function', function(assert) {
 });
 
 it('should be able to list with a start_key', function(assert) {
-  var p = db.list({start_key: 'c'}, function(error, docs) {
+  const p = db.list({start_key: 'c'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.ok(docs.rows, 'get the rows');
     assert.equal(docs.rows.length, 2, 'starts in row two');
@@ -74,7 +74,7 @@ it('should be able to list with a start_key', function(assert) {
 });
 
 it('should be able to list with a startkey', function(assert) {
-  var p = db.list({startkey: 'c'}, function(error, docs) {
+  const p = db.list({startkey: 'c'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.ok(docs.rows, 'get the rows');
     assert.equal(docs.rows.length, 2, 'starts in row two');
@@ -95,7 +95,7 @@ it('should be able to list with a startkey', function(assert) {
 });
 
 it('should be able to list with a endkey', function(assert) {
-  var p = db.list({endkey: 's'}, function(error, docs) {
+  const p = db.list({endkey: 's'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.ok(docs.rows, 'get the rows');
     assert.equal(docs.rows.length, 2, 'starts in row two');
@@ -116,7 +116,7 @@ it('should be able to list with a endkey', function(assert) {
 });
 
 it('should be able to list with a end_key', function(assert) {
-  var p = db.list({end_key: 's'}, function(error, docs) {
+  const p = db.list({end_key: 's'}, function(error, docs) {
     assert.equal(error, null, 'should work');
     assert.ok(docs.rows, 'get the rows');
     assert.equal(docs.rows.length, 2, 'starts in row two');
@@ -137,7 +137,7 @@ it('should be able to list with a end_key', function(assert) {
 });
 
 it('should be able to list as a stream', function(assert) {
-  var p = db.listAsStream(function(error) {
+  const p = db.listAsStream(function(error) {
     assert.equal(error, null, 'should work');
   });
   assert.ok(!helpers.isPromise(p), 'does not return Promise');
@@ -145,7 +145,7 @@ it('should be able to list as a stream', function(assert) {
 });
 
 it('should be able to list with params as a stream', function(assert) {
-  var p = db.listAsStream({end_key: 's'}, function(error) {
+  const p = db.listAsStream({end_key: 's'}, function(error) {
     assert.equal(error, null, 'should work');
   });
   assert.ok(!helpers.isPromise(p), 'does not return Promise');
diff --git a/tests/integration/document/update.js b/tests/integration/document/update.js
index 38630bd..7853ca0 100644
--- a/tests/integration/document/update.js
+++ b/tests/integration/document/update.js
@@ -12,14 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
-var rev;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
+
+let rev;
 
 it('should insert one doc', function(assert) {
-  var p = db.insert({'foo': 'baz'}, 'foobar', function(error, foo) {
+  const p = db.insert({'foo': 'baz'}, 'foobar', function(error, foo) {
     assert.equal(error, null, 'stored foo');
     assert.equal(foo.ok, true, 'response ok');
     assert.ok(foo.rev, 'withs rev');
@@ -37,7 +38,7 @@ it('should insert one doc', function(assert) {
 });
 
 it('should update the document', function(assert) {
-  var p = db.insert({foo: 'bar', '_rev': rev}, 'foobar', function(error, response) {
+  const p = db.insert({foo: 'bar', '_rev': rev}, 'foobar', function(error, response) {
     assert.equal(error, null, 'should have deleted foo');
     assert.equal(response.ok, true, 'response should be ok');
   });
diff --git a/tests/integration/multipart/get.js b/tests/integration/multipart/get.js
index 370014f..3da281e 100644
--- a/tests/integration/multipart/get.js
+++ b/tests/integration/multipart/get.js
@@ -12,21 +12,21 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
-var rev;
+let rev;
 
 it('should be able to insert a doc with att', function(assert) {
-  var att = {
+  const att = {
     name: 'att',
     data: 'Hello World!',
     'content_type': 'text/plain'
   };
 
-  var p = db.multipart.insert({'foo': 'baz'}, [att], 'foobaz', function(error, foo) {
+  const p = db.multipart.insert({'foo': 'baz'}, [att], 'foobaz', function(error, foo) {
     assert.equal(error, null, 'should have stored foobaz');
     assert.equal(foo.ok, true, 'response should be ok');
     assert.equal(foo.id, 'foobaz', 'id is foobaz');
@@ -46,7 +46,7 @@ it('should be able to insert a doc with att', function(assert) {
 });
 
 it('should be able to get the document with the attachment', function(assert) {
-  var p = db.multipart.get('foobaz', function(error, foobaz, headers) {
+  const p = db.multipart.get('foobaz', function(error, foobaz, headers) {
     assert.equal(error, null, 'should get foobaz');
     if (helpers.unmocked) {
       assert.ok(headers['content-type'], 'should have content type');
diff --git a/tests/integration/multipart/insert.js b/tests/integration/multipart/insert.js
index 44aac9d..f80d26c 100644
--- a/tests/integration/multipart/insert.js
+++ b/tests/integration/multipart/insert.js
@@ -12,18 +12,18 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should handle crazy encodings', function(assert) {
-  var att = {
+  const att = {
     name: 'att',
     data: 'काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥',
     'content_type': 'text/plain'
   };
-  var p = db.multipart.insert({'foo': 'bar'}, [att], 'foobar', function(error, foo) {
+  const p = db.multipart.insert({'foo': 'bar'}, [att], 'foobar', function(error, foo) {
     assert.equal(error, null, 'should have stored foo and attachment');
     assert.equal(foo.ok, true, 'response should be ok');
     assert.ok(foo.rev, 'response should have rev');
@@ -40,13 +40,13 @@ it('should handle crazy encodings', function(assert) {
 });
 
 it('should test with presence of attachment', function(assert) {
-  var att = {
+  const att = {
     name: 'two',
     data: 'Hello World!',
     'content_type': 'text/plain'
   };
 
-  var p = db.attachment.insert('mydoc', 'one', 'Hello World!', 'text/plain',
+  const p = db.attachment.insert('mydoc', 'one', 'Hello World!', 'text/plain',
   function(err) {
     assert.equal(err, null, 'should have stored the thingy');
     db.get('mydoc', function(_, doc) {
@@ -64,12 +64,12 @@ it('should test with presence of attachment', function(assert) {
 });
 
 it('should work with attachment as a buffer', function(assert) {
-  var att = {
+  const att = {
     name: 'att',
     data: new Buffer('foo'),
     'content_type': 'text/plain'
   };
-  var p = db.multipart.insert({'foo': 'bar'}, [att], 'otherdoc', function(error, foo) {
+  const p = db.multipart.insert({'foo': 'bar'}, [att], 'otherdoc', function(error, foo) {
     assert.equal(error, null, 'Should have stored foo and attachment');
     assert.equal(foo.ok, true, 'Response should be ok');
     assert.ok(foo.rev, 'Response should have rev');
diff --git a/tests/integration/shared/config.js b/tests/integration/shared/config.js
index 1575b65..e5d78d2 100644
--- a/tests/integration/shared/config.js
+++ b/tests/integration/shared/config.js
@@ -12,15 +12,15 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var nano = harness.locals.nano;
-var Nano = helpers.Nano;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const nano = harness.locals.nano;
+const Nano = helpers.Nano;
 
-var it = harness.it;
+const it = harness.it;
 
 it('should serve the root when no path is specified', function(assert) {
-  var p = nano.dinosaur('', function(err, response) {
+  const p = nano.dinosaur('', function(err, response) {
     assert.equal(err, null, 'failed to get root');
     assert.ok(response.version, 'version is defined');
     nano.relax(function(err, response) {
@@ -39,7 +39,7 @@ it('should serve the root when no path is specified', function(assert) {
 });
 
 it('should be able to parse urls', function(assert) {
-  var baseUrl = 'http://someurl.com';
+  const baseUrl = 'http://someurl.com';
   assert.equal(
     Nano(baseUrl).config.url,
     baseUrl,
@@ -55,14 +55,6 @@ it('should be able to parse urls', function(assert) {
     'http://a:b@someurl.com:5984',
     'with authentication');
 
-  //var withDb = Nano({
-  //  url: 'http://a:b@someurl.com:5984',
-  //  db: 'foo'
-  //})
-
-  //assert.equal(withDb.config.db, 'foo', 'should create url with db');
-  //assert.ok(withDb.attachment, 'should have an attachment');
-
   assert.equal(
     Nano('http://a:b%20c%3F@someurl.com:5984/mydb').config.url,
     'http://a:b%20c%3F@someurl.com:5984',
@@ -97,7 +89,7 @@ it('should be able to parse urls', function(assert) {
 });
 
 it('should not parse urls when parseURL flag set to false', function(assert) {
-  var url = 'http://someurl.com/path';
+  const url = 'http://someurl.com/path';
 
   assert.equal(
     Nano({
@@ -111,7 +103,7 @@ it('should not parse urls when parseURL flag set to false', function(assert) {
 });
 
 it('should accept and handle customer http headers', function(assert) {
-  var nanoWithDefaultHeaders = Nano({
+  const nanoWithDefaultHeaders = Nano({
     url: helpers.couch,
     defaultHeaders: {
       'x-custom-header': 'custom',
@@ -119,7 +111,7 @@ it('should accept and handle customer http headers', function(assert) {
     }
   });
 
-  var req = nanoWithDefaultHeaders.db.listAsStream(function(err) {
+  const req = nanoWithDefaultHeaders.db.listAsStream(function(err) {
     assert.equal(err, null, 'should list');
     assert.end();
   });
@@ -136,7 +128,7 @@ it('should accept and handle customer http headers', function(assert) {
 });
 
 it('should prevent shallow object copies', function(assert) {
-  var config = {
+  const config = {
     url: 'http://someurl.com'
   };
 
diff --git a/tests/integration/shared/cookie.js b/tests/integration/shared/cookie.js
index 6690264..15c2bac 100644
--- a/tests/integration/shared/cookie.js
+++ b/tests/integration/shared/cookie.js
@@ -12,14 +12,14 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var nano = harness.locals.nano;
-var Nano = helpers.Nano;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const nano = harness.locals.nano;
+const Nano = helpers.Nano;
+const it = harness.it;
 
-var cookie;
-var server;
+let cookie;
+let server;
 
 it('should be able to create a user', function(assert) {
   nano.relax({
@@ -51,9 +51,9 @@ it('should be able to insert with a cookie', function(assert) {
     url: helpers.couch,
     cookie: cookie
   });
-  var db = server.use('shared_cookie');
+  const db = server.use('shared_cookie');
 
-  var p = db.insert({'foo': 'baz'}, null, function(error, response) {
+  const p = db.insert({'foo': 'baz'}, null, function(error, response) {
     assert.equal(error, null, 'should have stored value');
     assert.equal(response.ok, true, 'response should be ok');
     assert.ok(response.rev, 'response should have rev');
diff --git a/tests/integration/shared/error.js b/tests/integration/shared/error.js
index b74628e..d9a1a87 100644
--- a/tests/integration/shared/error.js
+++ b/tests/integration/shared/error.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var nano = harness.locals.nano;
-var Nano = helpers.Nano;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const nano = harness.locals.nano;
+const Nano = helpers.Nano;
+const it = harness.it;
 
 it('should throw when initialize fails', function(assert) {
   try {
@@ -35,7 +35,7 @@ it('should throw when initialize fails', function(assert) {
 });
 
 it('should be able to stream the simplest request', function(assert) {
-  var root = nano.request({stream: true});
+  const root = nano.request({stream: true});
   root.on('end', function() {
     assert.pass('request worked');
     assert.end();
@@ -43,7 +43,7 @@ it('should be able to stream the simplest request', function(assert) {
 });
 
 it('should error when destroying a db that does not exist', function(assert) {
-  var p = nano.db.destroy('say_wat_wat', function(error) {
+  const p = nano.db.destroy('say_wat_wat', function(error) {
     assert.ok(error, 'an error');
     assert.ok(error.message, 'a note');
     assert.equal(error.message, 'Database does not exist.', 'is missing');
diff --git a/tests/integration/shared/headers.js b/tests/integration/shared/headers.js
index b4af027..1a9880c 100644
--- a/tests/integration/shared/headers.js
+++ b/tests/integration/shared/headers.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var nano = harness.locals.nano;
-var db = harness.locals.db;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const nano = harness.locals.nano;
+const db = harness.locals.db;
+const it = harness.it;
 
 it('should get headers', function(assert) {
   db.attachment.insert('new', 'att', 'Hello', 'text/plain',
diff --git a/tests/integration/shared/log.js b/tests/integration/shared/log.js
index f94e1a1..f1d07f7 100644
--- a/tests/integration/shared/log.js
+++ b/tests/integration/shared/log.js
@@ -12,14 +12,13 @@
 
 'use strict';
 
-var logger = require('../../../lib/logger');
-
-var helpers = require('../../helpers');
-var harness = helpers.harness(__filename);
-var it = harness.it;
+const logger = require('../../../lib/logger');
+const helpers = require('../../helpers');
+const harness = helpers.harness(__filename);
+const it = harness.it;
 
 it('should be able to instantiate a log', function(assert) {
-  var log = logger({
+  const log = logger({
     log: function(id, msg) {
       assert.equal(typeof id, 'string', 'id is set `' + id + '`');
       assert.equal(msg[0], 'testing 1234');
diff --git a/tests/integration/util/uuid.js b/tests/integration/util/uuid.js
index 2969090..0aca172 100644
--- a/tests/integration/util/uuid.js
+++ b/tests/integration/util/uuid.js
@@ -12,13 +12,13 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var nano = helpers.nano;
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const nano = helpers.nano;
+const it = harness.it;
 
 it('should generate three uuids', function(assert) {
-  var p = nano.uuids(3, function(error, data) {
+  const p = nano.uuids(3, function(error, data) {
     assert.equal(error, null, 'should generate uuids');
     assert.ok(data, 'got response');
     assert.ok(data.uuids, 'got uuids');
@@ -37,7 +37,7 @@ it('should generate three uuids', function(assert) {
 });
 
 it('should generate one uuid', function(assert) {
-  var p = nano.uuids(function(error, data) {
+  const p = nano.uuids(function(error, data) {
     assert.equal(error, null, 'should generate uuids');
     assert.ok(data, 'got response');
     assert.ok(data.uuids, 'got uuid');
diff --git a/tests/intercept/design/search.js b/tests/intercept/design/search.js
index 3456780..f853b48 100644
--- a/tests/intercept/design/search.js
+++ b/tests/intercept/design/search.js
@@ -12,21 +12,21 @@
 
 'use strict';
 
-var helpers = require('../../helpers/integration');
-var harness = helpers.harness(__filename);
-var it = harness.it;
+const helpers = require('../../helpers/integration');
+const harness = helpers.harness(__filename);
+const it = harness.it;
 
-var nano = require('../../../lib/nano.js');
-var fakeRequest = function(r, callback) {
+const nano = require('../../../lib/nano.js');
+const fakeRequest = function(r, callback) {
   callback(null, { statusCode: 200 }, r);
 };
 // by passing in a fake Request object, we can intercept the request
 // and see how Nano is pre-processing the parameters
-var n = nano({url: 'http://localhost:5984', request: fakeRequest});
-var db = n.db.use('fake');
+const n = nano({url: 'http://localhost:5984', request: fakeRequest});
+const db = n.db.use('fake');
 
 it('should allow custom request object to be supplied', function(assert) {
-  var p = db.info(function(err, data) {
+  const p = db.info(function(err, data) {
       assert.equal(err, null);
       assert.equal(data.method, 'GET');
       assert.equal(typeof data.headers, 'object');
@@ -43,7 +43,7 @@ it('should allow custom request object to be supplied', function(assert) {
 });
 
 it('should encode array counts parameter', function(assert) {
-  var p = db.search('fake', 'fake', { counts: ['brand','colour'] }, function(err, data) {
+  const p = db.search('fake', 'fake', { counts: ['brand','colour'] }, function(err, data) {
       assert.equal(err, null);
       assert.equal(data.method, 'GET');
       assert.equal(typeof data.headers, 'object');
@@ -62,7 +62,7 @@ it('should encode array counts parameter', function(assert) {
 });
 
 it('should not encode string counts parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { counts: JSON.stringify(['brand','colour']) }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -84,7 +84,7 @@ it('should not encode string counts parameter', function(assert) {
 });
 
 it('should encode array drilldown parameter', function(assert) {
-  var p = db.search('fake', 'fake', { drilldown: ['colour','red'] }, function(err, data) {
+  const p = db.search('fake', 'fake', { drilldown: ['colour','red'] }, function(err, data) {
       assert.equal(err, null);
       assert.equal(data.method, 'GET');
       assert.equal(typeof data.headers, 'object');
@@ -104,7 +104,7 @@ it('should encode array drilldown parameter', function(assert) {
 });
 
 it('should not encode string drilldown parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { drilldown: JSON.stringify(['colour','red']) }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -126,7 +126,7 @@ it('should not encode string drilldown parameter', function(assert) {
 });
 
 it('should encode array group_sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { group_sort: ['-foo<number>','bar<string>'] }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -148,7 +148,7 @@ it('should encode array group_sort parameter', function(assert) {
 });
 
 it('should not encode string group_sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { group_sort: JSON.stringify(['-foo<number>','bar<string>']) }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -170,7 +170,7 @@ it('should not encode string group_sort parameter', function(assert) {
 });
 
 it('should encode object ranges parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { ranges: {'price':'[0 TO 10]'} }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -192,7 +192,7 @@ it('should encode object ranges parameter', function(assert) {
 });
 
 it('should not encode string ranges parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { ranges: JSON.stringify({'price':'[0 TO 10]'}) }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -214,7 +214,7 @@ it('should not encode string ranges parameter', function(assert) {
 });
 
 it('should encode array sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { sort: ['-foo<number>','bar<string>'] }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -236,7 +236,7 @@ it('should encode array sort parameter', function(assert) {
 });
 
 it('should not encode string sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { sort: JSON.stringify(['-foo<number>','bar<string>']) }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -258,7 +258,7 @@ it('should not encode string sort parameter', function(assert) {
 });
 
 it('should encode unencoded sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { sort: '-foo<number>' }, 
                     function(err, data) {
       assert.equal(err, null);
@@ -280,7 +280,7 @@ it('should encode unencoded sort parameter', function(assert) {
 });
 
 it('should not encode encoded string sort parameter', function(assert) {
-  var p = db.search('fake', 'fake', 
+  const p = db.search('fake', 'fake', 
                     { sort: JSON.stringify('-foo<number>') }, 
                     function(err, data) {
       assert.equal(err, null);
diff --git a/tests/unit/attachment/destroy.js b/tests/unit/attachment/destroy.js
index e25a772..084950f 100644
--- a/tests/unit/attachment/destroy.js
+++ b/tests/unit/attachment/destroy.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var destroyAttachment = require('../../helpers/unit').unit([
+const destroyAttachment = require('../../helpers/unit').unit([
   'attachment',
   'destroy'
 ]);
diff --git a/tests/unit/attachment/get.js b/tests/unit/attachment/get.js
index 2e23a25..1972363 100644
--- a/tests/unit/attachment/get.js
+++ b/tests/unit/attachment/get.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var getAttachment = require('../../helpers/unit').unit([
+const getAttachment = require('../../helpers/unit').unit([
   'attachment',
   'get'
 ]);
diff --git a/tests/unit/attachment/insert.js b/tests/unit/attachment/insert.js
index 0416b89..0ed455f 100644
--- a/tests/unit/attachment/insert.js
+++ b/tests/unit/attachment/insert.js
@@ -12,10 +12,10 @@
 
 'use strict';
 
-var helpers = require('../../helpers/unit');
-var insertAttachment = helpers.unit(['attachment', 'insert']);
+const helpers = require('../../helpers/unit');
+const insertAttachment = helpers.unit(['attachment', 'insert']);
 
-var buffer = new Buffer(helpers.pixel, 'base64');
+const buffer = new Buffer(helpers.pixel, 'base64');
 
 insertAttachment('pixels', 'pixel.bmp', buffer, 'image/bmp', {
   body: buffer,
diff --git a/tests/unit/database/changes.js b/tests/unit/database/changes.js
index 778d0cc..8b017eb 100644
--- a/tests/unit/database/changes.js
+++ b/tests/unit/database/changes.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var changesDatabase = require('../../helpers/unit').unit([
+const changesDatabase = require('../../helpers/unit').unit([
   'database',
   'changes'
 ]);
diff --git a/tests/unit/database/compact.js b/tests/unit/database/compact.js
index ca6711e..0f36ba8 100644
--- a/tests/unit/database/compact.js
+++ b/tests/unit/database/compact.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var compactDatabase = require('../../helpers/unit').unit([
+const compactDatabase = require('../../helpers/unit').unit([
   'database',
   'compact'
 ]);
diff --git a/tests/unit/database/create.js b/tests/unit/database/create.js
index 53b5994..674f702 100644
--- a/tests/unit/database/create.js
+++ b/tests/unit/database/create.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var createDatabase = require('../../helpers/unit').unit([
+const createDatabase = require('../../helpers/unit').unit([
   'database',
   'create'
 ]);
diff --git a/tests/unit/database/destroy.js b/tests/unit/database/destroy.js
index b2c4f0e..6378d8b 100644
--- a/tests/unit/database/destroy.js
+++ b/tests/unit/database/destroy.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var destroyDatabase = require('../../helpers/unit').unit([
+const destroyDatabase = require('../../helpers/unit').unit([
   'database',
   'destroy'
 ]);
diff --git a/tests/unit/database/follow.js b/tests/unit/database/follow.js
index 99bab1b..92d5cb1 100644
--- a/tests/unit/database/follow.js
+++ b/tests/unit/database/follow.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var followDatabase = require('../../helpers/unit').unit([
+const followDatabase = require('../../helpers/unit').unit([
   'database',
   'follow'
 ]);
diff --git a/tests/unit/database/get.js b/tests/unit/database/get.js
index 2cdd2cc..3cbae19 100644
--- a/tests/unit/database/get.js
+++ b/tests/unit/database/get.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var getDatabase = require('../../helpers/unit').unit([
+const getDatabase = require('../../helpers/unit').unit([
   'database',
   'get'
 ]);
diff --git a/tests/unit/database/list.js b/tests/unit/database/list.js
index 1367d8a..2d4e928 100644
--- a/tests/unit/database/list.js
+++ b/tests/unit/database/list.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var listDatabases = require('../../helpers/unit').unit([
+const listDatabases = require('../../helpers/unit').unit([
   'database',
   'list'
 ]);
diff --git a/tests/unit/database/replicate.js b/tests/unit/database/replicate.js
index 21120f3..a55c08d 100644
--- a/tests/unit/database/replicate.js
+++ b/tests/unit/database/replicate.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var replicateDatabase = require('../../helpers/unit').unit([
+const replicateDatabase = require('../../helpers/unit').unit([
   'database',
   'replicate'
 ]);
diff --git a/tests/unit/database/replicator.js b/tests/unit/database/replicator.js
index dd4abbe..126df42 100644
--- a/tests/unit/database/replicator.js
+++ b/tests/unit/database/replicator.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var replicator = require('../../helpers/unit').unit([
+const replicator = require('../../helpers/unit').unit([
   'database',
   'replicator'
 ]);
diff --git a/tests/unit/database/updates.js b/tests/unit/database/updates.js
index 31f27ce..6690018 100644
--- a/tests/unit/database/updates.js
+++ b/tests/unit/database/updates.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var updatesDatabase = require('../../helpers/unit').unit([
+const updatesDatabase = require('../../helpers/unit').unit([
   'database',
   'updates'
 ]);
diff --git a/tests/unit/design/atomic.js b/tests/unit/design/atomic.js
index 04b1bfc..a52d98e 100644
--- a/tests/unit/design/atomic.js
+++ b/tests/unit/design/atomic.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var atomicDesign = require('../../helpers/unit').unit([
+const atomicDesign = require('../../helpers/unit').unit([
   'view',
   'atomic'
 ]);
diff --git a/tests/unit/design/compact.js b/tests/unit/design/compact.js
index dafc8f0..1239193 100644
--- a/tests/unit/design/compact.js
+++ b/tests/unit/design/compact.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var compactDesign = require('../../helpers/unit').unit([
+const compactDesign = require('../../helpers/unit').unit([
   'view',
   'compact'
 ]);
diff --git a/tests/unit/design/find.js b/tests/unit/design/find.js
index 41a4026..b8c6767 100644
--- a/tests/unit/design/find.js
+++ b/tests/unit/design/find.js
@@ -11,7 +11,7 @@
 // the License.
 
 'use strict';
-var findDesign = require('../../helpers/unit').unit([
+const findDesign = require('../../helpers/unit').unit([
   'find',
   'find'
 ]);
diff --git a/tests/unit/design/list.js b/tests/unit/design/list.js
index d2bd430..e37fdfa 100644
--- a/tests/unit/design/list.js
+++ b/tests/unit/design/list.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var listDesign = require('../../helpers/unit').unit([
+const listDesign = require('../../helpers/unit').unit([
   'view',
   'viewWithList'
 ]);
diff --git a/tests/unit/design/search.js b/tests/unit/design/search.js
index 4fee871..a7b6336 100644
--- a/tests/unit/design/search.js
+++ b/tests/unit/design/search.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var searchDesign = require('../../helpers/unit').unit([
+const searchDesign = require('../../helpers/unit').unit([
   'view',
   'search'
 ]);
diff --git a/tests/unit/design/show.js b/tests/unit/design/show.js
index 1a98ff5..9b99dee 100644
--- a/tests/unit/design/show.js
+++ b/tests/unit/design/show.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var showDesign = require('../../helpers/unit').unit([
+const showDesign = require('../../helpers/unit').unit([
   'view',
   'show'
 ]);
diff --git a/tests/unit/design/spatial.js b/tests/unit/design/spatial.js
index b3aa400..d3ce830 100644
--- a/tests/unit/design/spatial.js
+++ b/tests/unit/design/spatial.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var geoDesign = require('../../helpers/unit').unit([
+const geoDesign = require('../../helpers/unit').unit([
   'view',
   'spatial'
 ]);
diff --git a/tests/unit/design/view.js b/tests/unit/design/view.js
index df441e3..a9c8c14 100644
--- a/tests/unit/design/view.js
+++ b/tests/unit/design/view.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var viewDesign = require('../../helpers/unit').unit([
+const viewDesign = require('../../helpers/unit').unit([
   'view',
   'view'
 ]);
diff --git a/tests/unit/document/bulk.js b/tests/unit/document/bulk.js
index 20db29f..9f874b7 100644
--- a/tests/unit/document/bulk.js
+++ b/tests/unit/document/bulk.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var bulkDocument = require('../../helpers/unit').unit([
+const bulkDocument = require('../../helpers/unit').unit([
   'document',
   'bulk'
 ]);
diff --git a/tests/unit/document/copy.js b/tests/unit/document/copy.js
index 5b34c8b..3722d13 100644
--- a/tests/unit/document/copy.js
+++ b/tests/unit/document/copy.js
@@ -12,12 +12,12 @@
 
 'use strict';
 
-var copyDocument = require('../../helpers/unit').unit([
+const copyDocument = require('../../helpers/unit').unit([
   'document',
   'copy'
 ]);
 
-var copyDocumentFail = require('../../helpers/unit').unit([
+const copyDocumentFail = require('../../helpers/unit').unit([
   'document',
   'copy'
 ], new Error('OMG This sucks'));
diff --git a/tests/unit/document/get.js b/tests/unit/document/get.js
index b0d490e..cccb5bf 100644
--- a/tests/unit/document/get.js
+++ b/tests/unit/document/get.js
@@ -12,12 +12,12 @@
 
 'use strict';
 
-var helpers = require('../../helpers/unit');
-var test  = require('tape');
-var debug = require('debug')('nano/tests/unit/shared/error');
+const helpers = require('../../helpers/unit');
+const test  = require('tape');
+const debug = require('debug')('nano/tests/unit/shared/error');
 
-var cli = helpers.mockClientDb(debug);
-var db = cli.use('foo');
+const cli = helpers.mockClientDb(debug);
+const db = cli.use('foo');
 
 test('it should not return db info if docName undefined', function(assert) {
   db.get(undefined, function(err) {
diff --git a/tests/unit/multipart/get.js b/tests/unit/multipart/get.js
index 23755ea..ea9b6a7 100644
--- a/tests/unit/multipart/get.js
+++ b/tests/unit/multipart/get.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var getMultipart = require('../../helpers/unit').unit([
+const getMultipart = require('../../helpers/unit').unit([
   'multipart',
   'get'
 ]);
diff --git a/tests/unit/multipart/insert.js b/tests/unit/multipart/insert.js
index 642c88d..a3cccb4 100644
--- a/tests/unit/multipart/insert.js
+++ b/tests/unit/multipart/insert.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var insertMultipart = require('../../helpers/unit').unit([
+const insertMultipart = require('../../helpers/unit').unit([
   'multipart',
   'insert'
 ]);
diff --git a/tests/unit/shared/error.js b/tests/unit/shared/error.js
index 8809abd..ff1dc8c 100644
--- a/tests/unit/shared/error.js
+++ b/tests/unit/shared/error.js
@@ -12,17 +12,17 @@
 
 'use strict';
 
-var helpers = require('../../helpers/unit');
-var test  = require('tape');
-var debug = require('debug')('nano/tests/unit/shared/error');
+const helpers = require('../../helpers/unit');
+const test  = require('tape');
+const debug = require('debug')('nano/tests/unit/shared/error');
 
-var cli = helpers.mockClientFail(debug);
-var cli2 = helpers.mockClientUnparsedError(debug);
-var cli3 = helpers.mockClientUnparsedError(debug, JSON.stringify({
+const cli = helpers.mockClientFail(debug);
+const cli2 = helpers.mockClientUnparsedError(debug);
+const cli3 = helpers.mockClientUnparsedError(debug, JSON.stringify({
   error: 'not a reason'
 }));
 
-var cli4 = helpers.mockClientUnparsedError(debug, JSON.stringify({
+const cli4 = helpers.mockClientUnparsedError(debug, JSON.stringify({
   stack: new Error('foo').stack
 }));
 
@@ -49,7 +49,7 @@ test('should be capable of using `error`', function(assert) {
 
 test('should remove cloudant stacktraces', function(assert) {
   cli4.relax({}, function(err) {
-    var msg = err.stack.split('\n')[0];
+    const msg = err.stack.split('\n')[0];
     assert.notEqual(msg, 'Error: foo');
     assert.equal(msg, 'Error: Unspecified error');
     assert.end();
diff --git a/tests/unit/shared/follow-updates.js b/tests/unit/shared/follow-updates.js
index bf06bce..78bc537 100644
--- a/tests/unit/shared/follow-updates.js
+++ b/tests/unit/shared/follow-updates.js
@@ -12,7 +12,7 @@
 
 'use strict';
 
-var followUpdates = require('../../helpers/unit').unit([
+const followUpdates = require('../../helpers/unit').unit([
   'server',
   'followUpdates'
 ]);
diff --git a/tests/unit/shared/jar.js b/tests/unit/shared/jar.js
index c46d62c..aa901bf 100644
--- a/tests/unit/shared/jar.js
+++ b/tests/unit/shared/jar.js
@@ -12,11 +12,11 @@
 
 'use strict';
 
-var helpers = require('../../helpers/unit');
-var test  = require('tape');
-var debug = require('debug')('nano/tests/unit/shared/jar');
+const helpers = require('../../helpers/unit');
+const test  = require('tape');
+const debug = require('debug')('nano/tests/unit/shared/jar');
 
-var cli = helpers.mockClientJar(debug);
+const cli = helpers.mockClientJar(debug);
 
 test('it should be able to set a jar box', function(assert) {
   assert.equal(cli.config.jar, 'is set');


[couchdb-nano] 05/08: added central getCallback function to remove code duplication

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 11c616831ebe75bbff3342e9fc167f493845fb0a
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 14:43:35 2018 +0100

    added central getCallback function to remove code duplication
---
 lib/nano.js | 242 ++++++++++++++++++++++--------------------------------------
 1 file changed, 87 insertions(+), 155 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index 4e41a5f..1bf2d17 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -23,6 +23,17 @@ const logger = require('./logger');
 
 let nano;
 
+function getCallback (opts, callback) {
+  if (typeof opts === 'function') {
+    callback = opts;
+    opts = {};
+  }
+  return {
+    opts,
+    callback
+  };
+}
+
 module.exports = exports = nano = function dbScope(cfg) {
   let serverScope = {};
 
@@ -297,14 +308,11 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
 
   // http://docs.couchdb.org/en/latest/api/server/common.html#get--_db_updates
-  function updates(qs, callback) {
-    if (typeof qs === 'function') {
-      callback = qs;
-      qs = {};
-    }
+  function updates(qs0, callback0) {
+    const {opts, callback} = getCallback(qs0, callback0);
     return relax({
       db: '_db_updates',
-      qs: qs
+      qs: opts
     }, callback);
   }
 
@@ -352,35 +360,23 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
 
   // http://docs.couchdb.org/en/latest/api/database/changes.html#get--db-_changes
-  function changesDb(dbName, qs, callback) {
-    if (typeof qs === 'function') {
-      callback = qs;
-      qs = {};
-    }
-    return relax({db: dbName, path: '_changes', qs: qs}, callback);
+  function changesDb(dbName, qs0, callback0) {
+    const {opts, callback} = getCallback(qs0, callback0);
+    return relax({db: dbName, path: '_changes', qs: opts}, callback);
   }
 
-  function changesDbAsStream(dbName, qs, callback) {
-    if (typeof qs === 'function') {
-      callback = qs;
-      qs = {};
-    }
-    return relax({db: dbName, path: '_changes', stream: true, qs: qs}, callback);
+  function changesDbAsStream(dbName, qs0, callback0) {
+    const {opts, callback} = getCallback(qs0, callback0);
+    return relax({db: dbName, path: '_changes', stream: true, qs: opts}, callback);
   }
 
-  function followDb(dbName, qs, callback) {
-    if (typeof qs === 'function') {
-      callback = qs;
-      qs = {};
-    }
-
-    qs = qs || {};
-    qs.db = urlResolveFix(cfg.url, encodeURIComponent(dbName));
-
+  function followDb(dbName, qs0, callback0) {
+    const {opts, callback} = getCallback(qs0, callback0);
+    opts.db = urlResolveFix(cfg.url, encodeURIComponent(dbName));
     if (typeof callback === 'function') {
-      return followAgent(qs, callback);
+      return followAgent(opts, callback);
     } else {
-      return new followAgent.Feed(qs);
+      return new followAgent.Feed(opts);
     }
   }
 
@@ -393,11 +389,9 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
 
   // http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate
-  function replicateDb(source, target, opts, callback) {
-    if (typeof opts === 'function') {
-      callback = opts;
-      opts = {};
-    }
+  function replicateDb(source, target, opts0, callback0) {
+    const {opts, callback} = getCallback(opts0, callback0);
+
     // _replicate
     opts.source = _serializeAsUrl(source);
     opts.target = _serializeAsUrl(target);
@@ -411,16 +405,13 @@ module.exports = exports = nano = function dbScope(cfg) {
       callback = count;
       count = 1;
     }
-
     return relax({ method: 'GET', path: '_uuids', qs: {count: count}}, callback);
   }
 
   // http://guide.couchdb.org/draft/replication.html
-  function enableReplication(source, target, opts, callback) {
-    if (typeof opts === 'function') {
-      callback = opts;
-      opts = {};
-    }
+  function enableReplication(source, target, opts0, callback0) {
+    const {opts, callback} = getCallback(opts0, callback0);
+
     // _replicator
     opts.source = _serializeAsUrl(source);
     opts.target = _serializeAsUrl(target);
@@ -429,20 +420,14 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
 
   // http://guide.couchdb.org/draft/replication.html
-  function queryReplication(id, opts, callback) {
-    if (typeof opts === 'function') {
-      callback = opts;
-      opts = {};
-    }
+  function queryReplication(id, opts0, callback0) {
+    const {opts, callback} = getCallback(opts0, callback0);
     return relax({db: '_replicator', method: 'GET', path: id}, callback);
   }
 
   // http://guide.couchdb.org/draft/replication.html
-  function disableReplication(id, rev, opts, callback) {
-    if (typeof opts === 'function') {
-      callback = opts;
-      opts = {};
-    }
+  function disableReplication(id, rev, opts0, callback0) {
+    const {opts, callback} = getCallback(opts0, callback0);
     return relax({db: '_replicator', method: 'DELETE', path: id, qs: {rev: rev}}, callback);
   }
 
@@ -452,28 +437,25 @@ module.exports = exports = nano = function dbScope(cfg) {
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#put--db-docid
     // http://docs.couchdb.org/en/latest/api/database/common.html#post--db
-    function insertDoc(doc, qs, callback) {
-      const opts = {db: dbName, body: doc, method: 'POST'};
+    function insertDoc(doc, qs0, callback0) {
+      const req = {db: dbName, body: doc, method: 'POST'};
 
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
+      let {opts, callback} = getCallback(qs0, callback0);
 
-      if (typeof qs === 'string') {
-        qs = {docName: qs};
+      if (typeof opts === 'string') {
+        opts = {docName: opts};
       }
 
-      if (qs) {
-        if (qs.docName) {
-          opts.doc = qs.docName;
-          opts.method = 'PUT';
-          delete qs.docName;
+      if (opts) {
+        if (opts.docName) {
+          req.doc = opts.docName;
+          req.method = 'PUT';
+          delete opts.docName;
         }
-        opts.qs = qs;
+        req.qs = opts;
       }
 
-      return relax(opts, callback);
+      return relax(req, callback);
     }
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
@@ -498,18 +480,15 @@ module.exports = exports = nano = function dbScope(cfg) {
     }
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#get--db-docid
-    function getDoc(docName, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
+    function getDoc(docName, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
 
       if(!docName) {
         if(callback)
           callback("Invalid doc id", null);
       }
       else {
-        return relax({db: dbName, doc: docName, qs: qs}, callback);
+        return relax({db: dbName, doc: docName, qs: opts}, callback);
       }
     }
 
@@ -537,11 +516,8 @@ module.exports = exports = nano = function dbScope(cfg) {
     }
 
     // http://docs.couchdb.org/en/latest/api/document/common.html#copy--db-docid
-    function copyDoc(docSrc, docDest, opts, callback) {
-      if (typeof opts === 'function') {
-        callback = opts;
-        opts = {};
-      }
+    function copyDoc(docSrc, docDest, opts0, callback0) {
+      const {opts, callback} = getCallback(opts0, callback0);
 
       const qs = {
         db: dbName,
@@ -567,70 +543,51 @@ module.exports = exports = nano = function dbScope(cfg) {
     }
 
     // http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
-    function listDoc(qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
-      return relax({db: dbName, path: '_all_docs', qs: qs}, callback);
+    function listDoc(qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
+      return relax({db: dbName, path: '_all_docs', qs: opts}, callback);
     }
 
     // http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docs
-    function listDocAsStream(qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
-      return relax({db: dbName, path: '_all_docs', qs: qs, stream: true}, callback);
+    function listDocAsStream(qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
+      return relax({db: dbName, path: '_all_docs', qs: opts, stream: true}, callback);
     }
 
     // http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs
-    function fetchDocs(docNames, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
-      qs = qs || {};
-      qs['include_docs'] = true;
+    function fetchDocs(docNames, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
+      opts['include_docs'] = true;
 
       return relax({
         db: dbName,
         path: '_all_docs',
         method: 'POST',
-        qs: qs,
+        qs: opts,
         body: docNames
       }, callback);
     }
 
-    function fetchRevs(docNames, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
+    function fetchRevs(docNames, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         path: '_all_docs',
         method: 'POST',
-        qs: qs,
+        qs: opts,
         body: docNames
       }, callback);
     }
 
-    function view(ddoc, viewName, meta, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
+    function view(ddoc, viewName, meta, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
 
       if (typeof meta.stream !== 'boolean') {
         meta.stream = false;
       }
 
       // prevent mutation of the client qs object by using a clone
-      const qs1 = Object.assign({}, qs);
+      const qs1 = Object.assign({}, opts);
 
       const viewPath = '_design/' + ddoc + '/_' + meta.type + '/'  + viewName;
 
@@ -733,18 +690,14 @@ module.exports = exports = nano = function dbScope(cfg) {
     }
 
     // http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_bulksDoc
-    function bulksDoc(docs, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
+    function bulksDoc(docs, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         path: '_bulk_docs',
         body: docs,
         method: 'POST',
-        qs: qs
+        qs: opts
       }, callback);
     }
 
@@ -788,88 +741,67 @@ module.exports = exports = nano = function dbScope(cfg) {
       }, callback);
     }
 
-    function getMultipart(docName, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-      qs = qs || {};
-
-      qs.attachments = true;
+    function getMultipart(docName, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
+      opts.attachments = true;
 
       return relax({
         db: dbName,
         doc: docName,
         encoding: null,
         accept: 'multipart/related',
-        qs: qs
+        qs: opts
       }, callback);
     }
 
-    function insertAtt(docName, attName, att, contentType, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
+    function insertAtt(docName, attName, att, contentType, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         att: attName,
         method: 'PUT',
         contentType: contentType,
         doc: docName,
-        qs: qs,
+        qs: opts,
         body: att,
         dontStringify: true
       }, callback);
     }
 
-    function insertAttAsStream(docName, attName, att, contentType, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
+    function insertAttAsStream(docName, attName, att, contentType, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         att: attName,
         method: 'PUT',
         contentType: contentType,
         doc: docName,
-        qs: qs,
+        qs: opts,
         body: att,
         stream: true,
         dontStringify: true
       }, callback);
     }
 
-    function getAtt(docName, attName, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
+    function getAtt(docName, attName, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         att: attName,
         doc: docName,
-        qs: qs,
+        qs: opts,
         encoding: null,
         dontParse: true
       }, callback);
     }
 
-    function getAttAsStream(docName, attName, qs, callback) {
-      if (typeof qs === 'function') {
-        callback = qs;
-        qs = {};
-      }
-
+    function getAttAsStream(docName, attName, qs0, callback0) {
+      const {opts, callback} = getCallback(qs0, callback0);
       return relax({
         db: dbName,
         att: attName,
         doc: docName,
-        qs: qs,
+        qs: opts,
         stream: true,
         encoding: null,
         dontParse: true


[couchdb-nano] 03/08: add default parameter value in responseHandler

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 2e849923b4b0380e3ed74c0311340abf5acfd451
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 13:26:48 2018 +0100

    add default parameter value in responseHandler
---
 lib/nano.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/nano.js b/lib/nano.js
index e0384cb..f911b6f 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -69,12 +69,12 @@ module.exports = exports = nano = function dbScope(cfg) {
   }
   const responseHandler = function(req, opts, resolve, reject, callback) {
     
-    return function(err, response, body) {
+    return function(err, response = { statusCode: 500 }, body) {
       let parsed;
       const responseHeaders = Object.assign({
         uri: req.uri,
-        statusCode: response ? response.statusCode : 500
-      }, response ? response.headers : {});
+        statusCode: response.statusCode
+      }, response.headers);
       if (err) {
         log({err: 'socket', body: body, headers: responseHeaders});
         const ret_e = errs.merge(err, {


[couchdb-nano] 06/08: var--->const in the README

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 214a0dab13f9c10ffc1dc3118119659b376cd6a1
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 14:49:53 2018 +0100

    var--->const in the README
---
 README.md | 58 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/README.md b/README.md
index 7fe061a..7cc8d41 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ See [Migration Guide for switching from Nano 6.x to 7.x](migration_6_to_7.md).
 To use `nano` you need to connect it to your CouchDB install, to do that:
 
 ```js
-var nano = require('nano')('http://localhost:5984');
+const nano = require('nano')('http://localhost:5984');
 ```
 
 The URL you supply may also contain authenication credentials e.g. `http://admin:mypassword@localhost:5984`.
@@ -109,7 +109,7 @@ nano.db.create('alice');
 and to use an existing database:
 
 ```js
-var alice = nano.db.use('alice');
+const alice = nano.db.use('alice');
 ```
 
 Under-the-hood, calls like `nano.db.create` are making HTTP API calls to the CouchDB service. Such operations are *asynchronous*. There are two ways to recieve the asynchronous data back from the library
@@ -147,8 +147,8 @@ The documentation will now follow the *Promises* style.
 A simple but complete example is:
 
 ```js
-var nano = require('nano')('http://localhost:5984');
-var alice = null;
+const nano = require('nano')('http://localhost:5984');
+let alice;
 
 nano.db.destory('alice').then((response) => {
   return nano.db.create('alice')
@@ -190,29 +190,29 @@ You can also see your document in [futon](http://localhost:5984/_utils).
 Configuring nano to use your database server is as simple as:
 
 ```js
-var nano = require('nano')('http://localhost:5984'),
-  db = nano.use('foo');
+const nano = require('nano')('http://localhost:5984')
+const db = nano.use('foo');
 ```
 
 If you don't need to instrument database objects you can simply:
 
 ```js
 // nano parses the URL and knows this is a database
-var db = require('nano')('http://localhost:5984/foo');
+const db = require('nano')('http://localhost:5984/foo');
 ```
 
 You can also pass options to the require to specify further configuration options you can pass an object literal instead:
 
 ```js
 // nano parses the URL and knows this is a database
-var opts = {
+const opts = {
   url: "http://localhost:5984/foo",
   requestDefaults: { "proxy" : "http://someproxy" },
   log: (id, args) => {
     console.log(id, args);
   }
 };
-var db = require('nano')(opts);
+const db = require('nano')(opts);
 ```
 
 Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc.
@@ -222,11 +222,11 @@ You can tell nano to not parse the URL (maybe the server is behind a proxy, is a
 ```js
 // nano does not parse the URL and return the server api
 // "http://localhost:5984/prefix" is the CouchDB server root
-var couch = require('nano')(
+const couch = require('nano')(
   { url : "http://localhost:5984/prefix"
     parseUrl : false
   });
-var db = couch.use('foo');
+const db = couch.use('foo');
 ```
 
 ### Pool size and open sockets
@@ -242,14 +242,14 @@ You can also increase the size in your calling context using `requestDefaults` i
 Here's an example explicitly using the keep alive agent (installed using `npm install agentkeepalive`), especially useful to limit your open sockets when doing high-volume access to CouchDB on localhost:
 
 ```js
-var agentkeepalive = require('agentkeepalive');
-var myagent = new agentkeepalive({
+const agentkeepalive = require('agentkeepalive');
+const myagent = new agentkeepalive({
   maxSockets: 50,
   maxKeepAliveRequests: 0,
   maxKeepAliveTime: 30000
 });
 
-var db = require('nano')(
+const db = require('nano')(
   { url: "http://localhost:5984/foo",
     requestDefaults : { "agent" : myagent }
   });
@@ -433,7 +433,7 @@ nano.db.changes('alice').pipe(process.stdout);
 Uses [Follow] to create a solid changes feed. Please consult `follow` documentation for more information as this is a very complete API on it's own:
 
 ```js
-var feed = db.follow({since: "now"});
+const feed = db.follow({since: "now"});
 feed.on('change', (change) => {
   console.log("change: ", change);
 });
@@ -458,7 +458,7 @@ nano.db.info().then((body) => {
 Returns a database object that allows you to perform operations against that database:
 
 ```js
-var alice = nano.use('alice');
+const alice = nano.use('alice');
 alice.insert({ happy: true }, 'rabbit').then((body) => {
   // do something
 });
@@ -526,7 +526,7 @@ Use [Follow] to create a solid
 Please consult follow documentation for more information as this is a very complete api on it's own
 
 ```js
-var feed = nano.followUpdates({since: "now"});
+const feed = nano.followUpdates({since: "now"});
 feed.on('change', (change) => {
   console.log("change: ", change);
 });
@@ -543,7 +543,7 @@ process.nextTick( () => {
 Inserts `doc` in the database with optional `params`. If params is a string, it's assumed it is the intended document `_id`. If params is an object, it's passed as query string parameters and `docName` is checked for defining the document `_id`:
 
 ```js
-var alice = nano.use('alice');
+const alice = nano.use('alice');
 alice.insert({ happy: true }, 'rabbit').then((body) => {
   console.log(body);
 });
@@ -552,7 +552,7 @@ alice.insert({ happy: true }, 'rabbit').then((body) => {
 The `insert` function can also be used with the method signature `db.insert(doc,[callback])`, where the `doc` contains the `_id` field e.g.
 
 ```js
-var alice = nano.use('alice')
+const alice = nano.use('alice')
 alice.insert({ _id: 'myid', happy: true }).then((body) => {
   console.log(body)
 })
@@ -561,7 +561,7 @@ alice.insert({ _id: 'myid', happy: true }).then((body) => {
 and also used to update an existing document, by including the `_rev` token in the document being saved:
 
 ```js
-var alice = nano.use('alice')
+const alice = nano.use('alice')
 alice.insert({ _id: 'myid', _rev: '1-23202479633c2b380f79507a776743d5', happy: false }).then((body) => {
   console.log(body)
 })
@@ -624,7 +624,7 @@ Bulk operations(update/delete/insert) on the database, refer to the
 [CouchDB doc](http://docs.couchdb.org/en/2.1.1/api/database/bulk-api.html#db-bulk-docs) e.g:
 
 ```js
-var documents = [
+const documents = [
   { a:1, b:2 },
   { _id: 'tiger', striped: true}
 ];
@@ -672,7 +672,7 @@ additional query string `params` can be specified, `include_docs` is always set
 to `true`.
 
 ```js
-var keys = ['tiger', 'zebra', 'donkey'];
+const keys = ['tiger', 'zebra', 'donkey'];
 alice.fetch({keys: keys}).then((data) => {
   console.log(data);
 });
@@ -693,7 +693,7 @@ Create index on database fields, as specified in
 [CouchDB doc](http://docs.couchdb.org/en/latest/api/database/find.html#db-index).
 
 ```js
-var indexDef = {
+const indexDef = {
   index: { fields: ['foo'] },
   name: 'fooindex'
 };
@@ -898,7 +898,7 @@ An example update handler follows:
   "in-place" : "function(doc, req) {
       var field = req.form.field;
       var value = req.form.value;
-      var message = 'set '+field+' to '+value;
+      var message = 'set ' + field + ' to ' + value;
       doc[field] = value;
       return [doc, message];
   }"
@@ -931,7 +931,7 @@ Perform a ["Mango" query](http://docs.couchdb.org/en/2.1.1/api/database/find.htm
 
 ```js
 // find documents where the name = "Brian" and age > 25.
-var q = { 
+const q = { 
   selector: {
     name: { "$eq": "Brian"},
     age : { "$gt": 25 }
@@ -950,7 +950,7 @@ Perform a ["Mango" query](http://docs.couchdb.org/en/2.1.1/api/database/find.htm
 
 ```js
 // find documents where the name = "Brian" and age > 25.
-var q = { 
+const q = { 
   selector: {
     name: { "$eq": "Brian"},
     age : { "$gt": 25 }
@@ -1035,9 +1035,9 @@ getrabbitrev('4-2e6cdc4c7e26b745c2881a24e0eeece2').then((body) => {
 You can pipe the return values of certain nano functions like other stream. For example if our `rabbit` document has an attachment with name `picture.png` you can pipe it to a `writable stream`:
 
 ```js
-var fs = require('fs'),
-    nano = require('nano')('http://127.0.0.1:5984/');
-var alice = nano.use('alice');
+const fs = require('fs');
+const nano = require('nano')('http://127.0.0.1:5984/');
+const alice = nano.use('alice');
 alice.attachment.getAsStream('rabbit', 'picture.png').pipe(fs.createWriteStream('/tmp/rabbit.png'));
 ```
 


[couchdb-nano] 07/08: modernise JS in migration guide

Posted by gl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

glynnbird pushed a commit to branch issue98
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git

commit 166c23c252048da4d4e8b7c76156698d2049db13
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Wed Jul 18 14:50:10 2018 +0100

    modernise JS in migration guide
---
 migration_6_to_7.md | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/migration_6_to_7.md b/migration_6_to_7.md
index 84aaee7..33d1f92 100644
--- a/migration_6_to_7.md
+++ b/migration_6_to_7.md
@@ -16,9 +16,8 @@ In Nano 7:
 
 ```js
 // Nano 7
-var db = nano.db.use('mydb')
-var x = db.get('mydoc') 
-// x is a Promise
+const db = nano.db.use('mydb')
+const x = await db.get('mydoc') 
 ```
 
 If you are not using the streaming properties of Nano 6's return value, you may not need to change any code at all. This document outlines the areas that have changed and what you need to do to your code.
@@ -53,7 +52,7 @@ If you have code in the *callback* style, then Nano 7 will still work:
 
 ```js
 // Nano 7
-db.get('mydoc', function(err, data)  {
+db.get('mydoc', (err, data) => {
   console.log(err, data)
 })
 ```
@@ -84,9 +83,9 @@ db.get('mydoc').then((doc) => {
 In a JavaScript [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function), the code becomes even neater with the [await operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await):
 
 ```js
-var doc = await db.get('mydoc')
+let doc = await db.get('mydoc')
 doc.last_updated = new Date().getTime()
-var response = await db.insert(doc)
+let response = await db.insert(doc)
 ```
 
 You may find that using the Promise style of coding helps you create neater, simpler code, but pre-existing code that uses the callback style should still work.