Code coverage report for lib/replicate/index.js

Statements: 100% (25 / 25)      Branches: 100% (12 / 12)      Functions: 100% (2 / 2)      Lines: 100% (25 / 25)      Ignored: none     

All files » lib/replicate/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40    1 1 1   1 2330 2330 266   2064       1 1035 151 151   1035 357   1035 1035 1035 1035   1035 1035 1035 1035 1035 1035     1      
'use strict';
 
var utils = require('../utils');
var replicate = require('./replicate');
var Replication = require('./replication');
 
function toPouch(db, opts) {
  var PouchConstructor = opts.PouchConstructor;
  if (typeof db === 'string') {
    return new PouchConstructor(db, opts);
  } else {
    return db;
  }
}
 
function replicateWrapper(src, target, opts, callback) {
  if (typeof opts === 'function') {
    callback = opts;
    opts = {};
  }
  if (typeof opts === 'undefined') {
    opts = {};
  }
  opts.complete = callback;
  opts = utils.clone(opts);
  opts.continuous = opts.continuous || opts.live;
  opts.retry = ('retry' in opts) ? opts.retry : false;
  /*jshint validthis:true */
  opts.PouchConstructor = opts.PouchConstructor || this;
  var replicateRet = new Replication(opts);
  var srcPouch = toPouch(src, opts);
  var targetPouch = toPouch(target, opts);
  replicate(srcPouch, targetPouch, opts, replicateRet);
  return replicateRet;
}
 
module.exports = {
  replicate : replicateWrapper,
  toPouch: toPouch
};