source.js
function listRequest (path, options = {}, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }
  // serialise options
  let opts = [];
  for (let k in options) {
    // The whole URL *minus* the scheme and "://" (for whatever benighted reason) has to be at most
    // 4096 characters long. Taking the extra bloat that `encodeURIComponent()` adds we truncate the
    // query to 2000 chars. We could be more precise and regenerate the URL until we reach as close
    // as possible to 4096, but frankly if you're searching for a string longer than 2000 characters
    // you're probably doing something wrong.
    if (k === 'query') {
      if (options.query.length > 2000) options.query = options.query.substr(0, 2000);
      opts.push(`query=${encodeURIComponent(options.query)}`);
    }
    else if (k === 'filter') {
      let filts = [];
      for (let f in options.filter) {
        if (Array.isArray(options.filter[f])) {
          options.filter[f].forEach(val => {
            filts.push(`${f}:${val}`);
          });
        }
        else {
          filts.push(`${f}:${options.filter[f]}`);
        }
      }
      opts.push(`filter=${filts.join(',')}`);
    }
    else if (k === 'facet' && options.facet) opts.push('facet=t');
    else opts.push(`${k}=${options[k]}`);
  }
  if (opts.length) path += `?${opts.join('&')}`;
  return GET(path, (err, msg) => {
    if (err) return cb(err);
    let objects = msg.items;
    delete msg.items;
    let nextOffset = 0
      , isDone = false
      , nextOptions
    ;
    // /types is a list but it does not behave like the other lists
    // Once again the science.ai League of JStice saves the day papering over inconsistency!
    if (msg['items-per-page'] && msg.query) {
      nextOffset = msg.query['start-index'] + msg['items-per-page'];
      if (nextOffset > msg['total-results']) isDone = true;
      nextOptions = assign({}, options, { offset: nextOffset });
    }
    else {
      isDone = true;
      nextOptions = assign({}, options);
    }
    cb(null, objects, nextOptions, isDone, msg);
  });
}
function listRequest (path, options = {}, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }
  // serialise options
  let opts = [];
  for (let k in options) {
    // The whole URL *minus* the scheme and "://" (for whatever benighted reason) has to be at most
    // 4096 characters long. Taking the extra bloat that `encodeURIComponent()` adds we truncate the
    // query to 2000 chars. We could be more precise and regenerate the URL until we reach as close
    // as possible to 4096, but frankly if you're searching for a string longer than 2000 characters
    // you're probably doing something wrong.
    if (k === 'query') {
      if (options.query.length > 2000) options.query = options.query.substr(0, 2000);
      opts.push(`query=${encodeURIComponent(options.query)}`);
    }
    else if (k === 'filter') {
      let filts = [];
      for (let f in options.filter) {
        if (Array.isArray(options.filter[f])) {
          options.filter[f].forEach(val => {
            filts.push(`${f}:${val}`);
          });
        }
        else {
          filts.push(`${f}:${options.filter[f]}`);
        }
      }
      opts.push(`filter=${filts.join(',')}`);
    }
    else if (k === 'facet' && options.facet) opts.push('facet=t');
    else opts.push(`${k}=${options[k]}`);
  }
  if (opts.length) path += `?${opts.join('&')}`;
  return GET(path, (err, msg) => {
    if (err) return cb(err);
    let objects = msg.items;
    delete msg.items;
    let nextOffset = 0
      , isDone = false
      , nextOptions
    ;
    // /types is a list but it does not behave like the other lists
    // Once again the science.ai League of JStice saves the day papering over inconsistency!
    if (msg['items-per-page'] && msg.query) {
      nextOffset = msg.query['start-index'] + msg['items-per-page'];
      if (nextOffset > msg['total-results']) isDone = true;
      nextOptions = assign({}, options, { offset: nextOffset });
    }
    else {
      isDone = true;
      nextOptions = assign({}, options);
    }
    cb(null, objects, nextOptions, isDone, msg);
  });
}
function listRequest ( path , options = { } , cb ) { if ( typeof options === 'function' ) { cb = options ; options = { } ; } // serialise options let opts = [ ] ; for ( let k in options ) { // The whole URL *minus* the scheme and "://" (for whatever benighted reason) has to be at most // 4096 characters long. Taking the extra bloat that `encodeURIComponent()` adds we truncate the // query to 2000 chars. We could be more precise and regenerate the URL until we reach as close // as possible to 4096, but frankly if you're searching for a string longer than 2000 characters // you're probably doing something wrong. if ( k === 'query' ) { if ( options . query . length > 2000 ) options . query = options . query . substr ( 0 , 2000 ) ; opts . push ( ` ${ encodeURIComponent ( options . query ) } ` ) ; } else if ( k === 'filter' ) { let filts = [ ] ; for ( let f in options . filter ) { if ( Array . isArray ( options . filter [ f ] ) ) { options . filter [ f ] . forEach ( val => { filts . push ( ` ${ f } ${ val } ` ) ; } ) ; } else { filts . push ( ` ${ f } ${ options . filter [ f ] } ` ) ; } } opts . push ( ` ${ filts . join ( ',' ) } ` ) ; } else if ( k === 'facet' && options . facet ) opts . push ( 'facet=t' ) ; else opts . push ( ` ${ k } ${ options [ k ] } ` ) ; } if ( opts . length ) path += ` ${ opts . join ( '&' ) } ` ; return GET ( path , ( err , msg ) => { if ( err ) return cb ( err ) ; let objects = msg . items ; delete msg . items ; let nextOffset = 0 , isDone = false , nextOptions ; // /types is a list but it does not behave like the other lists // Once again the science.ai League of JStice saves the day papering over inconsistency! if ( msg [ 'items-per-page' ] && msg . query ) { nextOffset = msg . query [ 'start-index' ] + msg [ 'items-per-page' ] ; if ( nextOffset > msg [ 'total-results' ] ) isDone = true ; nextOptions = assign ( { } , options , { offset : nextOffset } ) ; } else { isDone = true ; nextOptions = assign ( { } , options ) ; } cb ( null , objects , nextOptions , isDone , msg ) ; } ) ; }
backend for list requests
backend for list requests