Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pouchdb-replication

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pouchdb-replication - npm Package Compare versions

Comparing version 5.4.5 to 6.0.0

87

lib/index.js

@@ -233,3 +233,2 @@ 'use strict';

var checkpointer;
var allErrors = [];
var changedDocs = [];

@@ -268,3 +267,4 @@ // Like couchdb, every replication gets a unique session id

var docs = currentBatch.docs;
return target.bulkDocs({docs: docs, new_edits: false}).then(function (res) {
var bulkOpts = {timeout: opts.timeout};
return target.bulkDocs({docs: docs, new_edits: false}, bulkOpts).then(function (res) {
/* istanbul ignore if */

@@ -275,21 +275,25 @@ if (returnValue.cancelled) {

}
var errors = [];
var errorsById = {};
// `res` doesn't include full documents (which live in `docs`), so we create a map of
// (id -> error), and check for errors while iterating over `docs`
var errorsById = Object.create(null);
res.forEach(function (res) {
if (res.error) {
result.doc_write_failures++;
errors.push(res);
errorsById[res.id] = res;
}
});
allErrors = allErrors.concat(errors);
result.docs_written += currentBatch.docs.length - errors.length;
var non403s = errors.filter(function (error) {
return error.name !== 'unauthorized' && error.name !== 'forbidden';
});
var errorsNo = Object.keys(errorsById).length;
result.doc_write_failures += errorsNo;
result.docs_written += docs.length - errorsNo;
docs.forEach(function (doc) {
var error = errorsById[doc._id];
if (error) {
returnValue.emit('denied', pouchdbUtils.clone(error));
result.errors.push(error);
if (error.name === 'unauthorized' || error.name === 'forbidden') {
returnValue.emit('denied', pouchdbUtils.clone(error));
} else {
throw error;
}
} else {

@@ -300,8 +304,2 @@ changedDocs.push(doc);

if (non403s.length > 0) {
var error = new Error('bulkDocs error');
error.other_errors = errors;
abortReplication('target.bulkDocs failed to write docs', error);
throw new Error('bulkWrite partial failure');
}
}, function (err) {

@@ -334,3 +332,6 @@ result.doc_write_failures += docs.length;

getChanges();
}).catch(onCheckpointError);
}).catch(function (err) {
onCheckpointError(err);
throw err;
});
}

@@ -434,4 +435,2 @@

result.status = 'aborting';
result.errors.push(err);
allErrors = allErrors.concat(err);
batches = [];

@@ -443,7 +442,7 @@ pendingBatch = {

};
completeReplication();
completeReplication(err);
}
function completeReplication() {
function completeReplication(fatalError) {
if (replicationCompleted) {

@@ -463,16 +462,15 @@ return;

replicationCompleted = true;
var non403s = allErrors.filter(function (error) {
return error.name !== 'unauthorized' && error.name !== 'forbidden';
});
if (non403s.length > 0) {
var error = allErrors.pop();
if (allErrors.length > 0) {
error.other_errors = allErrors;
if (fatalError) {
fatalError.result = result;
if (fatalError.name === 'unauthorized' || fatalError.name === 'forbidden') {
returnValue.emit('error', fatalError);
returnValue.removeAllListeners();
} else {
backOff(opts, returnValue, fatalError, function () {
replicate$1(src, target, opts, returnValue);
});
}
error.result = result;
backOff(opts, returnValue, error, function () {
replicate$1(src, target, opts, returnValue);
});
} else {
result.errors = allErrors;
returnValue.emit('complete', result);

@@ -635,3 +633,2 @@ returnValue.removeAllListeners();

abortReplication('writeCheckpoint completed with error', err);
throw err;
}

@@ -967,4 +964,22 @@

PouchDB.sync = sync;
Object.defineProperty(PouchDB.prototype, 'replicate', {
get: function () {
var self = this;
return {
from: function (other, opts, callback) {
return self.constructor.replicate(other, self, opts, callback);
},
to: function (other, opts, callback) {
return self.constructor.replicate(self, other, opts, callback);
}
};
}
});
PouchDB.prototype.sync = function (dbName, opts, callback) {
return this.constructor.sync(this, dbName, opts, callback);
};
}
module.exports = replication;
{
"name": "pouchdb-replication",
"version": "5.4.5",
"version": "6.0.0",
"description": "PouchDB's replication and sync algorithm, as a plugin.",

@@ -18,9 +18,12 @@ "main": "./lib/index.js",

"js-extend": "1.0.1",
"pouchdb-collate": "1.2.0",
"pouchdb-checkpointer": "5.4.5",
"pouchdb-errors": "5.4.5",
"pouchdb-generate-replication-id": "5.4.5",
"pouchdb-promise": "5.4.5",
"pouchdb-utils": "5.4.5"
"pouchdb-collate": "6.0.0",
"pouchdb-checkpointer": "6.0.0",
"pouchdb-errors": "6.0.0",
"pouchdb-generate-replication-id": "6.0.0",
"pouchdb-promise": "6.0.0",
"pouchdb-utils": "6.0.0"
},
"peerDependencies": {
"pouchdb-core": "6.0.0"
}
}

@@ -7,4 +7,22 @@ import { replicate } from './replicateWrapper';

PouchDB.sync = sync;
Object.defineProperty(PouchDB.prototype, 'replicate', {
get: function () {
var self = this;
return {
from: function (other, opts, callback) {
return self.constructor.replicate(other, self, opts, callback);
},
to: function (other, opts, callback) {
return self.constructor.replicate(self, other, opts, callback);
}
};
}
});
PouchDB.prototype.sync = function (dbName, opts, callback) {
return this.constructor.sync(this, dbName, opts, callback);
};
}
export default replication;

@@ -27,3 +27,2 @@ import { clone, filterChange, uuid } from 'pouchdb-utils';

var checkpointer;
var allErrors = [];
var changedDocs = [];

@@ -62,3 +61,4 @@ // Like couchdb, every replication gets a unique session id

var docs = currentBatch.docs;
return target.bulkDocs({docs: docs, new_edits: false}).then(function (res) {
var bulkOpts = {timeout: opts.timeout};
return target.bulkDocs({docs: docs, new_edits: false}, bulkOpts).then(function (res) {
/* istanbul ignore if */

@@ -69,21 +69,25 @@ if (returnValue.cancelled) {

}
var errors = [];
var errorsById = {};
// `res` doesn't include full documents (which live in `docs`), so we create a map of
// (id -> error), and check for errors while iterating over `docs`
var errorsById = Object.create(null);
res.forEach(function (res) {
if (res.error) {
result.doc_write_failures++;
errors.push(res);
errorsById[res.id] = res;
}
});
allErrors = allErrors.concat(errors);
result.docs_written += currentBatch.docs.length - errors.length;
var non403s = errors.filter(function (error) {
return error.name !== 'unauthorized' && error.name !== 'forbidden';
});
var errorsNo = Object.keys(errorsById).length;
result.doc_write_failures += errorsNo;
result.docs_written += docs.length - errorsNo;
docs.forEach(function (doc) {
var error = errorsById[doc._id];
if (error) {
returnValue.emit('denied', clone(error));
result.errors.push(error);
if (error.name === 'unauthorized' || error.name === 'forbidden') {
returnValue.emit('denied', clone(error));
} else {
throw error;
}
} else {

@@ -94,8 +98,2 @@ changedDocs.push(doc);

if (non403s.length > 0) {
var error = new Error('bulkDocs error');
error.other_errors = errors;
abortReplication('target.bulkDocs failed to write docs', error);
throw new Error('bulkWrite partial failure');
}
}, function (err) {

@@ -128,3 +126,6 @@ result.doc_write_failures += docs.length;

getChanges();
}).catch(onCheckpointError);
}).catch(function (err) {
onCheckpointError(err);
throw err;
});
}

@@ -228,4 +229,2 @@

result.status = 'aborting';
result.errors.push(err);
allErrors = allErrors.concat(err);
batches = [];

@@ -237,7 +236,7 @@ pendingBatch = {

};
completeReplication();
completeReplication(err);
}
function completeReplication() {
function completeReplication(fatalError) {
if (replicationCompleted) {

@@ -257,16 +256,15 @@ return;

replicationCompleted = true;
var non403s = allErrors.filter(function (error) {
return error.name !== 'unauthorized' && error.name !== 'forbidden';
});
if (non403s.length > 0) {
var error = allErrors.pop();
if (allErrors.length > 0) {
error.other_errors = allErrors;
if (fatalError) {
fatalError.result = result;
if (fatalError.name === 'unauthorized' || fatalError.name === 'forbidden') {
returnValue.emit('error', fatalError);
returnValue.removeAllListeners();
} else {
backOff(opts, returnValue, fatalError, function () {
replicate(src, target, opts, returnValue);
});
}
error.result = result;
backOff(opts, returnValue, error, function () {
replicate(src, target, opts, returnValue);
});
} else {
result.errors = allErrors;
returnValue.emit('complete', result);

@@ -429,3 +427,2 @@ returnValue.removeAllListeners();

abortReplication('writeCheckpoint completed with error', err);
throw err;
}

@@ -432,0 +429,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc