Skip to content

Commit

Permalink
added optional snapshot version
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jan 16, 2014
1 parent 0f54471 commit 7a4ac4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions lib/eventStore.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion 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" }
Expand Down
3 changes: 2 additions & 1 deletion test/eventStoreSpec.js
Expand Up @@ -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();
});
Expand All @@ -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();
});

Expand Down

0 comments on commit 7a4ac4f

Please sign in to comment.