lib/utils/preparePipeline.js
function preparePipeline (pipeline, collection = {}) {
  pipeline = [].concat(pipeline)

  const replaceWithFunction = (key) => (typeof key === 'string') ? collection[key] : key
  const isFunctionOrObject = (obj) => obj && ['function', 'object'].includes(typeof obj)

  return pipeline
    .map(replaceWithFunction)
    .filter(isFunctionOrObject)
}
function preparePipeline (pipeline, collection = {}) {
  pipeline = [].concat(pipeline)

  const replaceWithFunction = (key) => (typeof key === 'string') ? collection[key] : key
  const isFunctionOrObject = (obj) => obj && ['function', 'object'].includes(typeof obj)

  return pipeline
    .map(replaceWithFunction)
    .filter(isFunctionOrObject)
}
Prepare pipeline by replacing keys with functions or function objects from
the collection object, and remove anything that is not functions or function
objects.
@param {array} pipeline - The pipeline definition
@param {Object} collection - Object with pipeline functions
@returns {array} Prepared pipeline