lib/defaultCommandHandler.js
function (aggregate, stream, callback) {
    if (!aggregate || !_.isObject(aggregate)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }
    if (!stream || !_.isObject(stream)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }

    var hasAggregateName = !!this.definitions.command.aggregate;
    var hasContextName = !!this.definitions.command.context;

    var query = {
      aggregateId: aggregate.id
    };

    if (hasAggregateName) {
      query.aggregate = this.aggregate.name;
    }

    if (hasContextName) {
      query.context = this.aggregate.context.name;
    }

    query.data = aggregate.toJSON();
    query.revision = stream.lastRevision;
    query.version = this.aggregate.version;

    var self = this;

    process.nextTick(function() {
      var transformer = self.aggregate.committingSnapshotTransformers[self.aggregate.context.name + '.' + self.aggregate.name + '.' + self.aggregate.version] || function (sn, cb) { cb(null, sn); };
      transformer(query.data, function (err, snapData) {
        if (err) {
          debug(err);
          if (callback) callback(err);
          return;
        }

        query.data = snapData;

        debug('cerate new snapshot');
        self.eventStore.createSnapshot(query, function (err) {
          if (err) {
            debug(err);
            if (callback) callback(err);
            return;
          }
          debug('snapshot created');
          if (callback) callback(null);
        });
      });
    });
  }
function (aggregate, stream, callback) {
    if (!aggregate || !_.isObject(aggregate)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }
    if (!stream || !_.isObject(stream)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }

    var hasAggregateName = !!this.definitions.command.aggregate;
    var hasContextName = !!this.definitions.command.context;

    var query = {
      aggregateId: aggregate.id
    };

    if (hasAggregateName) {
      query.aggregate = this.aggregate.name;
    }

    if (hasContextName) {
      query.context = this.aggregate.context.name;
    }

    query.data = aggregate.toJSON();
    query.revision = stream.lastRevision;
    query.version = this.aggregate.version;

    var self = this;

    process.nextTick(function() {
      var transformer = self.aggregate.committingSnapshotTransformers[self.aggregate.context.name + '.' + self.aggregate.name + '.' + self.aggregate.version] || function (sn, cb) { cb(null, sn); };
      transformer(query.data, function (err, snapData) {
        if (err) {
          debug(err);
          if (callback) callback(err);
          return;
        }

        query.data = snapData;

        debug('cerate new snapshot');
        self.eventStore.createSnapshot(query, function (err) {
          if (err) {
            debug(err);
            if (callback) callback(err);
            return;
          }
          debug('snapshot created');
          if (callback) callback(null);
        });
      });
    });
  }
function ( aggregate , stream , callback ) { if ( ! aggregate || ! _ . isObject ( aggregate ) ) { var err = new Error ( 'Please pass a valid aggregate!' ) ; debug ( err ) ; throw err ; } if ( ! stream || ! _ . isObject ( stream ) ) { var err = new Error ( 'Please pass a valid aggregate!' ) ; debug ( err ) ; throw err ; } var hasAggregateName = ! ! this . definitions . command . aggregate ; var hasContextName = ! ! this . definitions . command . context ; var query = { aggregateId : aggregate . id } ; if ( hasAggregateName ) { query . aggregate = this . aggregate . name ; } if ( hasContextName ) { query . context = this . aggregate . context . name ; } query . data = aggregate . toJSON ( ) ; query . revision = stream . lastRevision ; query . version = this . aggregate . version ; var self = this ; process . nextTick ( function ( ) { var transformer = self . aggregate . committingSnapshotTransformers [ self . aggregate . context . name + '.' + self . aggregate . name + '.' + self . aggregate . version ] || function ( sn , cb ) { cb ( null , sn ) ; } ; transformer ( query . data , function ( err , snapData ) { if ( err ) { debug ( err ) ; if ( callback ) callback ( err ) ; return ; } query . data = snapData ; debug ( 'cerate new snapshot' ) ; self . eventStore . createSnapshot ( query , function ( err ) { if ( err ) { debug ( err ) ; if ( callback ) callback ( err ) ; return ; } debug ( 'snapshot created' ) ; if ( callback ) callback ( null ) ; } ) ; } ) ; } ) ; }
Creates a new snapshot.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object}         stream    The event stream.
@param {Function}       callback  The function, that will be called when this action is completed. [optional]
`function(err){}`
Creates a new snapshot .