function createListRequest(cid, store, filters, done) {
  // Introspect filters and check if they leverage an indexed field.
  const indexField = Object.keys(filters).find(field => {
    return INDEXED_FIELDS.includes(field);
  });

  if (!indexField) {
    // Get all records for this collection (ie. cid)
    const request = store.index("cid").openCursor(IDBKeyRange.only(cid));
    request.onsuccess = cursorHandlers.all(filters, done);
    return request;
  }

  // If `indexField` was used already, don't filter again.
  const remainingFilters = omitKeys(filters, indexField);

  // value specified in the filter (eg. `filters: { _status: ["created", "updated"] }`)
  const value = filters[indexField];

  // WHERE IN equivalent clause
  if (Array.isArray(value)) {
    if (value.length === 0) {
      return done([]);
    }
    const values = value.map(i => [cid, i]).sort();
    const range = IDBKeyRange.bound(values[0], values[values.length - 1]);
    const request = store.index(indexField).openCursor(range);
    request.onsuccess = cursorHandlers.in(values, remainingFilters, done);
    return request;
  }

  // WHERE field = value clause
  const request = store
    .index(indexField)
    .openCursor(IDBKeyRange.only([cid, value]));
  request.onsuccess = cursorHandlers.all(remainingFilters, done);
  return request;
}
/**
 * Creates an IDB request and attach it the appropriate cursor event handler to
 * perform a list query.
 *
 * Multiple matching values are handled by passing an array.
 *
 * @param  {String}           cid        The collection id (ie. `{bid}/{cid}`)
 * @param  {IDBStore}         store      The IDB store.
 * @param  {Object}           filters    Filter the records by field.
 * @param  {Function}         done       The operation completion handler.
 * @return {IDBRequest}
 */
Creates an IDB request and attach it the appropriate cursor event handler to
perform a list query.

Multiple matching values are handled by passing an array.

@param  {String}           cid        The collection id
@param  {IDBStore}         store      The IDB store.
@param  {Object}           filters    Filter the records by field.
@param  {Function}         done       The operation completion handler.
Creates an IDB request and attach it the appropriate cursor event handler to perform a list query . Multiple matching values are handled by passing an array . @param { String } cid The collection id @param { IDBStore } store The IDB store . @param { Object } filters Filter the records by field . @param { Function } done The operation completion handler .
function createListRequest(cid, store, filters, done) {
  const indexField = Object.keys(filters).find(field => {
    return INDEXED_FIELDS.includes(field);
  });
  if (!indexField) {
    const request = store.index("cid").openCursor(IDBKeyRange.only(cid));
    request.onsuccess = cursorHandlers.all(filters, done);
    return request;
  }
  const remainingFilters = omitKeys(filters, indexField);
  const value = filters[indexField];
  if (Array.isArray(value)) {
    if (value.length === 0) {
      return done([]);
    }
    const values = value.map(i => [cid, i]).sort();
    const range = IDBKeyRange.bound(values[0], values[values.length - 1]);
    const request = store.index(indexField).openCursor(range);
    request.onsuccess = cursorHandlers.in(values, remainingFilters, done);
    return request;
  }
  const request = store
    .index(indexField)
    .openCursor(IDBKeyRange.only([cid, value]));
  request.onsuccess = cursorHandlers.all(remainingFilters, done);
  return request;
}
function createListRequest ( cid , store , filters , done ) { const indexField = Object . keys ( filters ) . find ( field => { return INDEXED_FIELDS . includes ( field ) ; } ) ; if ( ! indexField ) { const request = store . index ( "cid" ) . openCursor ( IDBKeyRange . only ( cid ) ) ; request . onsuccess = cursorHandlers . all ( filters , done ) ; return request ; } const remainingFilters = omitKeys ( filters , indexField ) ; const value = filters [ indexField ] ; if ( Array . isArray ( value ) ) { if ( value . length === 0 ) { return done ( [ ] ) ; } const values = value . map ( i => [ cid , i ] ) . sort ( ) ; const range = IDBKeyRange . bound ( values [ 0 ] , values [ values . length - 1 ] ) ; const request = store . index ( indexField ) . openCursor ( range ) ; request . onsuccess = cursorHandlers . in ( values , remainingFilters , done ) ; return request ; } const request = store . index ( indexField ) . openCursor ( IDBKeyRange . only ( [ cid , value ] ) ) ; request . onsuccess = cursorHandlers . all ( remainingFilters , done ) ; return request ; }
Creates an IDB request and attach it the appropriate cursor event handler to
 perform a list query.
Creates an IDB request and attach it the appropriate cursor event handler to perform a list query .
// Introspect filters and check if they leverage an indexed field. // Get all records for this collection (ie. cid) // If `indexField` was used already, don't filter again. // value specified in the filter (eg. `filters: { _status: ["created", "updated"] }`) // WHERE IN equivalent clause // WHERE field = value clause