lib/domain.js
function (cmd, err) {
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }
    if (!err || !_.isObject(err)) {
      var err = new Error('Please pass a valid error!');
      debug(err);
      throw err;
    }

    var evt = {};

    if (!!this.definitions.command.meta && !!this.definitions.event.meta) {
      dotty.put(evt, this.definitions.event.meta, dotty.get(cmd, this.definitions.command.meta));
    }

    dotty.put(evt, this.definitions.event.correlationId, dotty.get(cmd, this.definitions.command.id));
    dotty.put(evt, this.definitions.event.name, this.options.commandRejectedEventName);
    dotty.put(evt, this.definitions.event.id, dotty.get(cmd, this.definitions.command.id) + '_rejected');
    dotty.put(evt, this.definitions.event.aggregateId, dotty.get(cmd, this.definitions.command.aggregateId));

    if (!!this.definitions.command.aggregate && !!this.definitions.event.aggregate) {
      dotty.put(evt, this.definitions.event.aggregate, dotty.get(cmd, this.definitions.command.aggregate));
    }

    if (!!this.definitions.command.context && !!this.definitions.event.context) {
      dotty.put(evt, this.definitions.event.context, dotty.get(cmd, this.definitions.command.context));
    }

    if (err instanceof ValidationError || err instanceof BusinessRuleError ||
        err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError ||
        err instanceof DuplicateCommandError) {
      dotty.put(evt, this.definitions.event.payload, {
        command: cmd,
        reason: {
          name: err.name,
          message: err.message,
          more: err.more
        }
      });

      if (!!this.definitions.event.revision && dotty.get(evt, this.definitions.event.revision) === undefined && err.more && err.more.aggregateRevision > -1) {
        dotty.put(evt, this.definitions.event.revision, err.more.aggregateRevision);
      }
    } else {
      evt = null;
    }

    return evt;
  }
function (cmd, err) {
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }
    if (!err || !_.isObject(err)) {
      var err = new Error('Please pass a valid error!');
      debug(err);
      throw err;
    }

    var evt = {};

    if (!!this.definitions.command.meta && !!this.definitions.event.meta) {
      dotty.put(evt, this.definitions.event.meta, dotty.get(cmd, this.definitions.command.meta));
    }

    dotty.put(evt, this.definitions.event.correlationId, dotty.get(cmd, this.definitions.command.id));
    dotty.put(evt, this.definitions.event.name, this.options.commandRejectedEventName);
    dotty.put(evt, this.definitions.event.id, dotty.get(cmd, this.definitions.command.id) + '_rejected');
    dotty.put(evt, this.definitions.event.aggregateId, dotty.get(cmd, this.definitions.command.aggregateId));

    if (!!this.definitions.command.aggregate && !!this.definitions.event.aggregate) {
      dotty.put(evt, this.definitions.event.aggregate, dotty.get(cmd, this.definitions.command.aggregate));
    }

    if (!!this.definitions.command.context && !!this.definitions.event.context) {
      dotty.put(evt, this.definitions.event.context, dotty.get(cmd, this.definitions.command.context));
    }

    if (err instanceof ValidationError || err instanceof BusinessRuleError ||
        err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError ||
        err instanceof DuplicateCommandError) {
      dotty.put(evt, this.definitions.event.payload, {
        command: cmd,
        reason: {
          name: err.name,
          message: err.message,
          more: err.more
        }
      });

      if (!!this.definitions.event.revision && dotty.get(evt, this.definitions.event.revision) === undefined && err.more && err.more.aggregateRevision > -1) {
        dotty.put(evt, this.definitions.event.revision, err.more.aggregateRevision);
      }
    } else {
      evt = null;
    }

    return evt;
  }
function ( cmd , err ) { if ( ! cmd || ! _ . isObject ( cmd ) ) { var err = new Error ( 'Please pass a valid command!' ) ; debug ( err ) ; throw err ; } if ( ! err || ! _ . isObject ( err ) ) { var err = new Error ( 'Please pass a valid error!' ) ; debug ( err ) ; throw err ; } var evt = { } ; if ( ! ! this . definitions . command . meta && ! ! this . definitions . event . meta ) { dotty . put ( evt , this . definitions . event . meta , dotty . get ( cmd , this . definitions . command . meta ) ) ; } dotty . put ( evt , this . definitions . event . correlationId , dotty . get ( cmd , this . definitions . command . id ) ) ; dotty . put ( evt , this . definitions . event . name , this . options . commandRejectedEventName ) ; dotty . put ( evt , this . definitions . event . id , dotty . get ( cmd , this . definitions . command . id ) + '_rejected' ) ; dotty . put ( evt , this . definitions . event . aggregateId , dotty . get ( cmd , this . definitions . command . aggregateId ) ) ; if ( ! ! this . definitions . command . aggregate && ! ! this . definitions . event . aggregate ) { dotty . put ( evt , this . definitions . event . aggregate , dotty . get ( cmd , this . definitions . command . aggregate ) ) ; } if ( ! ! this . definitions . command . context && ! ! this . definitions . event . context ) { dotty . put ( evt , this . definitions . event . context , dotty . get ( cmd , this . definitions . command . context ) ) ; } if ( err instanceof ValidationError || err instanceof BusinessRuleError || err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError || err instanceof DuplicateCommandError ) { dotty . put ( evt , this . definitions . event . payload , { command : cmd , reason : { name : err . name , message : err . message , more : err . more } } ) ; if ( ! ! this . definitions . event . revision && dotty . get ( evt , this . definitions . event . revision ) === undefined && err . more && err . more . aggregateRevision > - 1 ) { dotty . put ( evt , this . definitions . event . revision , err . more . aggregateRevision ) ; } } else { evt = null ; } return evt ; }
Converts an error to the commandRejected event
@param {Object} cmd The command that was handled.
@param {Error}  err The error that occurs.
@returns {Object} The resulting event.
Converts an error to the commandRejected event