src/provider.js
/**
 * Extend the data/records using providers.
 *
 * @param {Endpoint} endpoint Endpoint (Object). It should contains:
 *  - kit.configuration.providers: Array of Providers that have the function
 *  extendRecords
 * @param {Object} records Object, data to extend
 *
 * @returns Extended record
 */
Extend the data/records using providers.
@param {Endpoint} endpoint Endpoint (Object). It should contains:
- kit.configuration.providers: Array of Providers that have the function
extendRecords
@param {Object} records Object, data to extend

@returns Extended record
Extend the data / records using providers . @param { Endpoint } endpoint Endpoint ( Object ) . It should contains : - kit . configuration . providers : Array of Providers that have the function extendRecords @param { Object } records Object data to extend @returns Extended record
function extendRecords(endpoint, records) {
  const providers = endpoint.kit.configuration.providers;
  if (!providers.length) {
    return records;
  }
  return records
    .loop((states, record) => {
      const date = record[PARSED_RECORD][DATE];
      const values = states.map((previous, index) => {
        if (previous && previous > date) {
          return;
        }
        const refresh = providers[index].refresh;
        states[index] = Utils.getDateWindow(date, refresh.origin, refresh.period)[1];
        return record;
      });
      return { seed: states, value: [record, values] };
    }, new Array(providers.length)
      .fill(null))
    .concatMap((data) => most.fromPromise(Promise
      .all(providers.map((provider, index) => {
        const record = data[1][index];
        return record && provider.extendRecord(endpoint, record);
      }))
      .then((extensions) => Object.assign(data[0], ...extensions, data[0]))));
}
function extendRecords ( endpoint , records ) { const providers = endpoint . kit . configuration . providers ; if ( ! providers . length ) { return records ; } return records . loop ( ( states , record ) => { const date = record [ PARSED_RECORD ] [ DATE ] ; const values = states . map ( ( previous , index ) => { if ( previous && previous > date ) { return ; } const refresh = providers [ index ] . refresh ; states [ index ] = Utils . getDateWindow ( date , refresh . origin , refresh . period ) [ 1 ] ; return record ; } ) ; return { seed : states , value : [ record , values ] } ; } , new Array ( providers . length ) . fill ( null ) ) . concatMap ( ( data ) => most . fromPromise ( Promise . all ( providers . map ( ( provider , index ) => { const record = data [ 1 ] [ index ] ; return record && provider . extendRecord ( endpoint , record ) ; } ) ) . then ( ( extensions ) => Object . assign ( data [ 0 ] , ... extensions , data [ 0 ] ) ) ) ) ; }
Extend the data/records using providers.
Extend the data / records using providers .
// Check the providers that have to refresh its output // Compute the extensions and merge them to the record