<commit_before>var isFirstOlder = require('logux-core/is-first-older')

var VERSION = 1

function rejectify (request, reject) {
  request.onerror = function (e) {
    reject(e.target.error)
  }
}

function promisify (request) {
  return new Promise(function (resolve, reject) {
    rejectify(request, reject)
    request.onsuccess = function (e) {
      resolve(e.target.result)
    }
  })
}

function nextEntry (request) {
  return function (cursor) {
    if (cursor) {
      cursor.value.meta.added = cursor.value.added
      return {
        entries: [[cursor.value.action, cursor.value.meta]],
        next: function () {
          cursor.continue()
          return promisify(request).then(nextEntry(request))
        }
      }
    } else {
      return { entries: [] }
    }
  }
}

function isDefined (value) {
  return typeof value !== 'undefined'
}

/**
 * `IndexedDB` store for Logux log.
 *
 * @param {string} [name="logux"] Database name to run multiple
 *                                Logux instances on same web page.
 *
 * @class
 * @extends Store
 *
 * @example
 * import IndexedStore from 'logux-client/indexed-store'
 * var log = new Log({ store: new IndexedStore(), nodeId })
 */
function IndexedStore (name) {
  this.name = name || 'logux'
  this.adding = { }
}

IndexedStore.prototype = {

  init: function init () {
    if (this.initing) return this.initing

    var store = this
    var opening = indexedDB.open(this.name, VERSION)

    opening.onupgradeneeded = function (e) {
      var db = e.target.result

      var log = db.createObjectStore('log', {
        keyPath: 'added',
        autoIncrement: true
      })
      log.createIndex('id', 'id', { unique: true })
      log.createIndex('created', 'created', { unique: true })
      log.createIndex('reasons', 'reasons', { multiEntry: true })

      db.createObjectStore('extra', { keyPath: 'key' })
        .transaction.oncomplete = function () {
          db.transaction('extra', 'readwrite')
            .objectStore('extra')
            .add({ key: '<PASSWORD>', sent: 0, received: 0 })
        }
    }

    this.initing = promisify(opening).then(function (db) {
      store.db = db
      db.onversionchange = function () {
        store.db.close()
        if (global.document && global.document.reload) {<commit_msg>Clean up code<commit_after>var isFirstOlder = require('logux-core/is-first-older')

var VERSION = 1

function rejectify (request, reject) {
  request.onerror = function (e) {
    reject(e.target.error)
  }
}

function promisify (request) {
  return new Promise(function (resolve, reject) {
    rejectify(request, reject)
    request.onsuccess = function (e) {
      resolve(e.target.result)
    }
  })
}

function nextEntry (request) {
  return function (cursor) {
    if (cursor) {
      cursor.value.meta.added = cursor.value.added
      return {
        entries: [[cursor.value.action, cursor.value.meta]],
        next: function () {
          cursor.continue()
          return promisify(request).then(nextEntry(request))
        }
      }
    } else {
      return { entries: [] }
    }
  }
}

function isDefined (value) {
  return typeof value !== 'undefined'
}

/**
 * `IndexedDB` store for Logux log.
 *
 * @param {string} [name="logux"] Database name to run multiple
 *                                Logux instances on same web page.
 *
 * @class
 * @extends Store
 *
 * @example
 * import IndexedStore from 'logux-client/indexed-store'
 * var log = new Log({ store: new IndexedStore(), nodeId })
 */
function IndexedStore (name) {
  this.name = name || 'logux'
  this.adding = { }
}

IndexedStore.prototype = {

  init: function init () {
    if (this.initing) return this.initing

    var store = this
    var opening = indexedDB.open(this.name, VERSION)

    opening.onupgradeneeded = function (e) {
      var db = e.target.result

      var log = db.createObjectStore('log', {
        keyPath: 'added',
        autoIncrement: true
      })
      log.createIndex('id', 'id', { unique: true })
      log.createIndex('created', 'created', { unique: true })
      log.createIndex('reasons', 'reasons', { multiEntry: true })

      var creating = db.createObjectStore('extra', { keyPath: 'key' })
      creating.transaction.oncomplete = function () {
        db.transaction('extra', 'readwrite')
          .objectStore('extra')
          .add({ key: 'lastSynced', sent: 0, received: 0 })
      }
    }

    this.initing = promisify(opening).then(function (db) {
      store.db = db
      db.onversionchange = function () {
        store.db.close()
        if (global.document && global.document.reload) {
{'fraction_non_alphanumeric': 0.13976164680390032, 'fraction_numerical': 0.0013001083423618636, 'mean_word_length': 2.5672333848531683, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5157277', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1427, 'n_words': 334}