{"size": 626, "ext": "js", "max_stars_repo_path": "src/lib/complexFlow.js", "max_stars_repo_name": "parkhub/circe-key-generator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/complexFlow.js", "max_issues_repo_name": "parkhub/circe-key-generator", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/complexFlow.js", "max_forks_repo_name": "parkhub/circe-key-generator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.2173913043, "max_line_length": 81, "alphanum_fraction": 0.6869009585}
import simpleFlow from './simpleFlow';

function doesKeyPropExists(keyPropValue) {
  return keyPropValue != null;
}

export default function complexFlow(publishCfgs, complexCfgs, next) {
  const { message, key: masterKey } = publishCfgs;
  const { keyProp } = complexCfgs;

  if (typeof message === 'string' || keyProp == null) {
    return simpleFlow(publishCfgs, next);
  }

  const keyPropValue = message[keyProp];

  if (doesKeyPropExists(keyPropValue) && masterKey == null) {
    return next({ ...publishCfgs, key: keyPropValue });
  }

  return next({ ...publishCfgs, message: { ...message, [keyProp]: masterKey } });
}
