lib/services/pages.js
function getPageClonePutOperations(pageData, locals) {
  return bluebird.all(_.reduce(pageData, (promises, pageValue, pageKey) => {
    if (typeof pageValue === 'string' && getComponentName(pageValue)) {
      // for all strings that are component references
      promises.push(components.get(pageValue, locals)
        // only follow the paths of instance references.  Don't clone default components
        .then(refData => composer.resolveComponentReferences(refData, locals, isInstanceReferenceObject))
        .then(resolvedData => {
          // for each instance reference within resolved data
          _.each(references.listDeepObjects(resolvedData, isInstanceReferenceObject), obj => {
            obj._ref = renameReferenceUniquely(obj._ref);
          });

          // rename reference in pageData
          const ref = renameReferenceUniquely(pageValue);

          pageData[pageKey] = ref;

          // put new data using cascading PUT at place that page now points
          return dbOps.getPutOperations(components.cmptPut, ref, resolvedData, locals);
        }));
    } else {
      // for all object-like things (i.e., objects and arrays)
      promises = promises.concat(getPageClonePutOperations(pageValue, locals));
    }
    return promises;
  }, [])).then(_.flatten); // only one level of flattening needed
}
function getPageClonePutOperations(pageData, locals) {
  return bluebird.all(_.reduce(pageData, (promises, pageValue, pageKey) => {
    if (typeof pageValue === 'string' && getComponentName(pageValue)) {
      // for all strings that are component references
      promises.push(components.get(pageValue, locals)
        // only follow the paths of instance references.  Don't clone default components
        .then(refData => composer.resolveComponentReferences(refData, locals, isInstanceReferenceObject))
        .then(resolvedData => {
          // for each instance reference within resolved data
          _.each(references.listDeepObjects(resolvedData, isInstanceReferenceObject), obj => {
            obj._ref = renameReferenceUniquely(obj._ref);
          });

          // rename reference in pageData
          const ref = renameReferenceUniquely(pageValue);

          pageData[pageKey] = ref;

          // put new data using cascading PUT at place that page now points
          return dbOps.getPutOperations(components.cmptPut, ref, resolvedData, locals);
        }));
    } else {
      // for all object-like things (i.e., objects and arrays)
      promises = promises.concat(getPageClonePutOperations(pageValue, locals));
    }
    return promises;
  }, [])).then(_.flatten); // only one level of flattening needed
}
function getPageClonePutOperations ( pageData , locals ) { return bluebird . all ( _ . reduce ( pageData , ( promises , pageValue , pageKey ) => { if ( typeof pageValue === 'string' && getComponentName ( pageValue ) ) { // for all strings that are component references promises . push ( components . get ( pageValue , locals ) // only follow the paths of instance references.  Don't clone default components . then ( refData => composer . resolveComponentReferences ( refData , locals , isInstanceReferenceObject ) ) . then ( resolvedData => { // for each instance reference within resolved data _ . each ( references . listDeepObjects ( resolvedData , isInstanceReferenceObject ) , obj => { obj . _ref = renameReferenceUniquely ( obj . _ref ) ; } ) ; // rename reference in pageData const ref = renameReferenceUniquely ( pageValue ) ; pageData [ pageKey ] = ref ; // put new data using cascading PUT at place that page now points return dbOps . getPutOperations ( components . cmptPut , ref , resolvedData , locals ) ; } ) ) ; } else { // for all object-like things (i.e., objects and arrays) promises = promises . concat ( getPageClonePutOperations ( pageValue , locals ) ) ; } return promises ; } , [ ] ) ) . then ( _ . flatten ) ; // only one level of flattening needed }
Clone all instance components that are referenced by this page data, and maintain the data's object structure.

@param {object} pageData
@param {object} locals
@returns {Promise}
Clone all instance components that are referenced by this page data and maintain the data s object structure .