sharedb 7.0.2 → 7.0.3

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
@@ -809,10 +809,9 @@ Backend.prototype.fetchSnapshot = function(agent, index, id, version, callback)
809
809
 
810
810
  this._fetchSnapshot(collection, id, version, function(error, snapshot) {
811
811
  if (error) return callback(error);
812
- var snapshotProjection = backend._getSnapshotProjection(backend.db, projection);
813
812
  var snapshots = [snapshot];
814
813
  var snapshotType = backend.SNAPSHOT_TYPES.byVersion;
815
- backend._sanitizeSnapshots(agent, snapshotProjection, collection, snapshots, snapshotType, function(error) {
814
+ backend._sanitizeSnapshots(agent, projection, collection, snapshots, snapshotType, function(error) {
816
815
  if (error) return callback(error);
817
816
  backend.emit('timing', 'fetchSnapshot', Date.now() - start, request);
818
817
  callback(null, snapshot);
@@ -875,10 +874,9 @@ Backend.prototype.fetchSnapshotByTimestamp = function(agent, index, id, timestam
875
874
 
876
875
  this._fetchSnapshotByTimestamp(collection, id, timestamp, function(error, snapshot) {
877
876
  if (error) return callback(error);
878
- var snapshotProjection = backend._getSnapshotProjection(backend.db, projection);
879
877
  var snapshots = [snapshot];
880
878
  var snapshotType = backend.SNAPSHOT_TYPES.byTimestamp;
881
- backend._sanitizeSnapshots(agent, snapshotProjection, collection, snapshots, snapshotType, function(error) {
879
+ backend._sanitizeSnapshots(agent, projection, collection, snapshots, snapshotType, function(error) {
882
880
  if (error) return callback(error);
883
881
  backend.emit('timing', 'fetchSnapshot', Date.now() - start, request);
884
882
  callback(null, snapshot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharedb",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "JSON OT database backend",
5
5
  "main": "lib/index.js",
6
6
  "dependencies": {
@@ -26,6 +26,26 @@ module.exports = function(options) {
26
26
  });
27
27
  });
28
28
 
29
+ [null, 1].forEach(function(version) {
30
+ it('snapshot fetchSnapshot at version ' + version, function(done) {
31
+ this.backend.connect().fetchSnapshot('dogs_summary', 'fido', version, function(err, snapshot) {
32
+ if (err) return done(err);
33
+ expect(snapshot.data).eql({age: 3, owner: {name: 'jim'}});
34
+ expect(snapshot.v).eql(1);
35
+ done();
36
+ });
37
+ });
38
+ });
39
+
40
+ it('snapshot fetchSnapshotByTimestamp', function(done) {
41
+ this.backend.connect().fetchSnapshotByTimestamp('dogs_summary', 'fido', null, function(err, snapshot) {
42
+ if (err) return done(err);
43
+ expect(snapshot.data).eql({age: 3, owner: {name: 'jim'}});
44
+ expect(snapshot.v).eql(1);
45
+ done();
46
+ });
47
+ });
48
+
29
49
  if (getQuery) {
30
50
  ['createFetchQuery', 'createSubscribeQuery'].forEach(function(method) {
31
51
  it('snapshot ' + method, function(done) {
@@ -411,6 +411,23 @@ describe('SnapshotTimestampRequest', function() {
411
411
  done();
412
412
  });
413
413
  });
414
+
415
+ describe('when the database projects snapshots', function() {
416
+ beforeEach(function() {
417
+ backend.db.projectsSnapshots = true;
418
+ });
419
+
420
+ [null, day2].forEach(function(timestamp) {
421
+ it('applies the projection to a snapshot at timestamp ' + timestamp, function(done) {
422
+ var connection = backend.connect();
423
+ connection.fetchSnapshotByTimestamp('bookTitles', 'time-machine', timestamp, function(error, snapshot) {
424
+ if (error) return done(error);
425
+ expect(snapshot.data).to.eql({title: 'The Time Machine'});
426
+ done();
427
+ });
428
+ });
429
+ });
430
+ });
414
431
  });
415
432
  });
416
433
 
@@ -351,6 +351,22 @@ describe('SnapshotVersionRequest', function() {
351
351
  done();
352
352
  });
353
353
  });
354
+
355
+ describe('when the database projects snapshots', function() {
356
+ beforeEach(function() {
357
+ backend.db.projectsSnapshots = true;
358
+ });
359
+
360
+ [null, 2].forEach(function(version) {
361
+ it('applies the projection to a snapshot at version ' + version, function(done) {
362
+ backend.connect().fetchSnapshot('bookTitles', 'don-quixote', version, function(error, snapshot) {
363
+ if (error) return done(error);
364
+ expect(snapshot.data).to.eql({title: 'Don Quixote'});
365
+ done();
366
+ });
367
+ });
368
+ });
369
+ });
354
370
  });
355
371
  });
356
372