lib/eventstore.js
function (query, revMax, callback) {
    if (typeof revMax === 'function') {
      callback = revMax;
      revMax = -1;
    }

    if (typeof query === 'string') {
      query = { aggregateId: query };
    }

    if (!query.aggregateId) {
      var err = new Error('An aggregateId should be passed!');
      debug(err);
      if (callback) callback(err);
      return;
    }

    var self = this;

    async.waterfall([

      function getSnapshot(callback) {
        self.store.getSnapshot(query, revMax, callback);
      },

      function getEventStream(snap, callback) {
        var rev = 0;

        if (snap && (snap.revision !== undefined && snap.revision !== null)) {
          rev = snap.revision + 1;
        }

        self.getEventStream(query, rev, revMax, function(err, stream) {
          if (err) {
            return callback(err);
          }

          if (rev > 0 && stream.lastRevision == -1) {
            stream.lastRevision = snap.revision;
          }

          callback(null, snap, stream);
        });
      }],

      callback
    );
  }
function (query, revMax, callback) {
    if (typeof revMax === 'function') {
      callback = revMax;
      revMax = -1;
    }

    if (typeof query === 'string') {
      query = { aggregateId: query };
    }

    if (!query.aggregateId) {
      var err = new Error('An aggregateId should be passed!');
      debug(err);
      if (callback) callback(err);
      return;
    }

    var self = this;

    async.waterfall([

      function getSnapshot(callback) {
        self.store.getSnapshot(query, revMax, callback);
      },

      function getEventStream(snap, callback) {
        var rev = 0;

        if (snap && (snap.revision !== undefined && snap.revision !== null)) {
          rev = snap.revision + 1;
        }

        self.getEventStream(query, rev, revMax, function(err, stream) {
          if (err) {
            return callback(err);
          }

          if (rev > 0 && stream.lastRevision == -1) {
            stream.lastRevision = snap.revision;
          }

          callback(null, snap, stream);
        });
      }],

      callback
    );
  }
function ( query , revMax , callback ) { if ( typeof revMax === 'function' ) { callback = revMax ; revMax = - 1 ; } if ( typeof query === 'string' ) { query = { aggregateId : query } ; } if ( ! query . aggregateId ) { var err = new Error ( 'An aggregateId should be passed!' ) ; debug ( err ) ; if ( callback ) callback ( err ) ; return ; } var self = this ; async . waterfall ( [ function getSnapshot ( callback ) { self . store . getSnapshot ( query , revMax , callback ) ; } , function getEventStream ( snap , callback ) { var rev = 0 ; if ( snap && ( snap . revision !== undefined && snap . revision !== null ) ) { rev = snap . revision + 1 ; } self . getEventStream ( query , rev , revMax , function ( err , stream ) { if ( err ) { return callback ( err ) ; } if ( rev > 0 && stream . lastRevision == - 1 ) { stream . lastRevision = snap . revision ; } callback ( null , snap , stream ) ; } ) ; } ] , callback ) ; }
loads the next snapshot back from given max revision
@param {Object || String} query    the query object
@param {Number}           revMax   revision end point (hint: -1 = to end) [optional]
@param {Function}         callback the function that will be called when this action has finished
`function(err, snapshot, eventstream){}`
loads the next snapshot back from given max revision