es2015/migration/RecordFetcher.js
function fetchRecords(objectStore, preprocessor) {
  return new PromiseSync((resolve, reject) => {
    let records = []
    
    objectStore.openCursor(null, CursorDirection.NEXT, (cursor) => {
      let primaryKey = cursor.primaryKey
      if (primaryKey instanceof Object) {
        Object.freeze(primaryKey)
      }
      
      let preprocessedRecord = preprocessor(cursor.record, primaryKey)
      if (preprocessedRecord === UpgradedDatabaseSchema.DELETE_RECORD) {
        cursor.delete()
        cursor.continue()
        return
      } else if (preprocessedRecord !== UpgradedDatabaseSchema.SKIP_RECORD) {
        records.push({
          key: primaryKey,
          record: preprocessedRecord
        })
      } else {
        // SKIP_RECORD returned, do nothing
      }
      
      cursor.continue()
    }).then(() => resolve(records)).catch(error => reject(error))
  })
}
function fetchRecords(objectStore, preprocessor) {
  return new PromiseSync((resolve, reject) => {
    let records = []
    
    objectStore.openCursor(null, CursorDirection.NEXT, (cursor) => {
      let primaryKey = cursor.primaryKey
      if (primaryKey instanceof Object) {
        Object.freeze(primaryKey)
      }
      
      let preprocessedRecord = preprocessor(cursor.record, primaryKey)
      if (preprocessedRecord === UpgradedDatabaseSchema.DELETE_RECORD) {
        cursor.delete()
        cursor.continue()
        return
      } else if (preprocessedRecord !== UpgradedDatabaseSchema.SKIP_RECORD) {
        records.push({
          key: primaryKey,
          record: preprocessedRecord
        })
      } else {
        // SKIP_RECORD returned, do nothing
      }
      
      cursor.continue()
    }).then(() => resolve(records)).catch(error => reject(error))
  })
}
Extracts all records from the provided object store and preprocess them
using the provided preprocessor.

The method traverses the records of the object store in ascending order of
their primary keys, deleting the records for which the preprocessor returns
the {@linkcode UpgradedDatabaseSchema.DELETE_RECORD} before traversing to
the next record.

@param {ObjectStore} objectStore The read-write accessor the object store
from which the records should be read.
@param {function(*, (number|string|Date|Array)): (*|UpgradedDatabaseSchema.SKIP_RECORD|UpgradedDatabaseSchema.DELETE_RECORD)} preprocessor
The callback to call on each record. The value returned by it will be
stored in the resulting record array instead of the original record.
The record will not be included in the resulting record array if the
preprocessor returns {@linkcode UpgradedDatabaseSchema.SKIP_RECORD}
or {@linkcode UpgradedDatabaseSchema.DELETE_RECORD}.
@return {PromiseSync<{key: (number|string|Date|Array), record: *}[]>} A
promise that resolves once all records in the object store have been
traversed. The promise will resolve to an array of the records
processed by the provided record preprocessor, in the order they
were traversed, and not containing the records that the preprocessor
marked as to be skipped or deleted.