lib/services/composer.js
function resolveComponentReferences(data, locals, filter = referenceProperty) {
  const referenceObjects = references.listDeepObjects(data, filter);

  return bluebird.all(referenceObjects).each(referenceObject => {
    return components.get(referenceObject[referenceProperty], locals)
      .then(obj => {
        // the thing we got back might have its own references
        return resolveComponentReferences(obj, locals, filter).finally(() => {
          _.assign(referenceObject, _.omit(obj, referenceProperty));
        }).catch(function (error) {
          const logObj = {
            stack: error.stack,
            cmpt: referenceObject[referenceProperty]
          };

          if (error.status) {
            logObj.status = error.status;
          }

          log('error', `${error.message}`, logObj);

          return bluebird.reject(error);
        });
      });
  }).then(() => data);
}
function resolveComponentReferences(data, locals, filter = referenceProperty) {
  const referenceObjects = references.listDeepObjects(data, filter);

  return bluebird.all(referenceObjects).each(referenceObject => {
    return components.get(referenceObject[referenceProperty], locals)
      .then(obj => {
        // the thing we got back might have its own references
        return resolveComponentReferences(obj, locals, filter).finally(() => {
          _.assign(referenceObject, _.omit(obj, referenceProperty));
        }).catch(function (error) {
          const logObj = {
            stack: error.stack,
            cmpt: referenceObject[referenceProperty]
          };

          if (error.status) {
            logObj.status = error.status;
          }

          log('error', `${error.message}`, logObj);

          return bluebird.reject(error);
        });
      });
  }).then(() => data);
}
function resolveComponentReferences ( data , locals , filter = referenceProperty ) { const referenceObjects = references . listDeepObjects ( data , filter ) ; return bluebird . all ( referenceObjects ) . each ( referenceObject => { return components . get ( referenceObject [ referenceProperty ] , locals ) . then ( obj => { // the thing we got back might have its own references return resolveComponentReferences ( obj , locals , filter ) . finally ( ( ) => { _ . assign ( referenceObject , _ . omit ( obj , referenceProperty ) ) ; } ) . catch ( function ( error ) { const logObj = { stack : error . stack , cmpt : referenceObject [ referenceProperty ] } ; if ( error . status ) { logObj . status = error . status ; } log ( 'error' , ` ${ error . message } ` , logObj ) ; return bluebird . reject ( error ) ; } ) ; } ) ; } ) . then ( ( ) => data ) ; }
Compose a component, recursively filling in all component references with
instance data.
@param {object} data
@param {object} locals  Extra data that some GETs use
@param {function|string} [filter='_ref']
@returns {Promise} - Resolves with composed component data
Compose a component recursively filling in all component references with instance data .