sharedb 4.1.4 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/backend.js CHANGED
@@ -909,7 +909,7 @@ Backend.prototype._fetchSnapshotByTimestamp = function(collection, id, timestamp
909
909
  };
910
910
 
911
911
  Backend.prototype._buildSnapshotFromOps = function(id, startingSnapshot, ops, callback) {
912
- var snapshot = startingSnapshot || new Snapshot(id, 0, null, undefined, null);
912
+ var snapshot = util.clone(startingSnapshot) || new Snapshot(id, 0, null, undefined, null);
913
913
  var error = ot.applyOps(snapshot, ops, {_normalizeLegacyJson0Ops: true});
914
914
  callback(error, snapshot);
915
915
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharedb",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "JSON OT database backend",
5
5
  "main": "lib/index.js",
6
6
  "dependencies": {
@@ -6,6 +6,7 @@ var sinon = require('sinon');
6
6
  var async = require('async');
7
7
  var json0v2 = require('ot-json0-v2').type;
8
8
  var types = require('../../lib/types');
9
+ var clone = require('../../lib/util').clone;
9
10
 
10
11
  describe('SnapshotVersionRequest', function() {
11
12
  var backend;
@@ -440,6 +441,39 @@ describe('SnapshotVersionRequest', function() {
440
441
  ], done);
441
442
  });
442
443
 
444
+ it('does not mutate the milestone snapshot', function(done) {
445
+ var connection = backendWithMilestones.connect();
446
+ var doc = connection.get('books', 'mocking-bird');
447
+ var milestoneDb = backendWithMilestones.milestoneDb;
448
+ var milestone;
449
+
450
+ async.waterfall([
451
+ doc.create.bind(doc, {title: 'To Kill a Mocking Bird'}),
452
+ doc.submitOp.bind(doc, {p: ['author'], oi: 'Harper Lea'}),
453
+ doc.submitOp.bind(doc, {p: ['author'], od: 'Harper Lea', oi: 'Harper Lee'}),
454
+ milestoneDb.getMilestoneSnapshot.bind(milestoneDb, 'books', 'mocking-bird', 3),
455
+ function(snapshot, next) {
456
+ milestone = clone(snapshot);
457
+ next();
458
+ },
459
+ function(next) {
460
+ // Internally, this calls ot.applyOps(), which mutates the snapshot it's passed.
461
+ // This call shouldn't cause the in-memory milestone snapshot to be mutated.
462
+ connection.fetchSnapshot('books', 'mocking-bird', 3, next);
463
+ },
464
+ function(snapshot, next) {
465
+ expect(snapshot.v).to.equal(3);
466
+ expect(snapshot.data).to.eql({title: 'To Kill a Mocking Bird', author: 'Harper Lee'});
467
+ next();
468
+ },
469
+ milestoneDb.getMilestoneSnapshot.bind(milestoneDb, 'books', 'mocking-bird', 3),
470
+ function(snapshot, next) {
471
+ expect(snapshot).to.eql(milestone);
472
+ next();
473
+ }
474
+ ], done);
475
+ });
476
+
443
477
  describe('with version null', function() {
444
478
  it('fetches a latest version', function(done) {
445
479
  var doc = backendWithMilestones.connect().get('books', 'mocking-bird');