From 7a4ac4f1bc4857ec453157c86e47a751cbc54ec4 Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Thu, 16 Jan 2014 19:45:11 +0100 Subject: [PATCH] added optional snapshot version --- README.markdown | 2 +- lib/eventStore.js | 13 ++++++++++--- package.json | 2 +- test/eventStoreSpec.js | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.markdown b/README.markdown index 8916326b..ff47fa70 100644 --- a/README.markdown +++ b/README.markdown @@ -119,7 +119,7 @@ create a snapshot point // create a new snapshot depending on your rules if (history.length > myRange) { - es.createSnapshot(aggregateId, stream.currentRevision(), myAggregate.getSnap()); + es.createSnapshot(aggregateId, stream.currentRevision(), myAggregate.getSnap()[, snapshotVersion]); } // go on: store new event and commit it diff --git a/lib/eventStore.js b/lib/eventStore.js index f65fb8ff..57fc1ba3 100644 --- a/lib/eventStore.js +++ b/lib/eventStore.js @@ -266,12 +266,18 @@ Store.prototype = { // - __streamId:__ id for requested stream (equal to aggregateId) // - __revision:__ revision - current revision state of the aggregate // - __data:__ the snaphot to store + // - __version:__ the version of this snapshot [optional] // - __callback:__ `function(err){}` [optional] - createSnapshot: function(streamId, revision, data, callback) { + createSnapshot: function(streamId, revision, data, version, callback) { if (this.hasConfigurationErrors(callback)) return; + + if (!callback) { + callback = version; + version = undefined; + } - var snapshot = new Snapshot(null, streamId, revision, data); + var snapshot = new Snapshot(null, streamId, revision, version, data); var self = this; @@ -602,10 +608,11 @@ var Event = function(streamId, event) { // ## Snapshot // The snapshot object will be persisted to the storage. The orginal data will be saved in _data_. -var Snapshot = function(id, streamId, revision, data) { +var Snapshot = function(id, streamId, revision, version, data) { this.id = id; this.streamId = streamId; this.revision = revision; + this.version = version; this.data = data; }; diff --git a/package.json b/package.json index 631e9d95..86079dbb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Jan Muehlemann, Adriano Raiano" , "name": "eventstore" - , "version": "0.7.2" + , "version": "0.7.3" , "contributors": [ { "name": "Jan Muehlemann", "email": "jan.muehlemann@gmail.com" }, { "name": "Adriano Raiano", "email": "adriano@raiano.ch" } diff --git a/test/eventStoreSpec.js b/test/eventStoreSpec.js index 7fcacb33..d744dc5a 100644 --- a/test/eventStoreSpec.js +++ b/test/eventStoreSpec.js @@ -306,7 +306,7 @@ var expect = require('expect.js'), it('it should callback without an error', function(done) { - eventstore.createSnapshot(stream.streamId, stream.currentRevision(), 'data', function(err) { + eventstore.createSnapshot(stream.streamId, stream.currentRevision(), 'data', 2, function(err) { expect(err).not.to.be.ok(); done(); }); @@ -324,6 +324,7 @@ var expect = require('expect.js'), expect(es.currentRevision()).to.be(0); expect(snapshot.revision).to.be(es.lastRevision); expect(snapshot.revision).to.be(es.currentRevision()); + expect(snapshot.version).to.be(2); done(); });