diff --git a/packages/node_modules/pouchdb-adapter-idb/src/allDocs.js b/packages/node_modules/pouchdb-adapter-idb/src/allDocs.js index 3103b5c862..92b1f16d93 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/allDocs.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/allDocs.js @@ -19,8 +19,8 @@ import getAll from './getAll'; function allDocsKeys(keys, docStore, onBatch) { // It's not guaranteed to be returned in right order - var valuesBatch = new Array(keys.length); - var count = 0; + const valuesBatch = new Array(keys.length); + let count = 0; keys.forEach(function (key, index) { docStore.get(key).onsuccess = function (event) { if (event.target.result) { @@ -66,16 +66,16 @@ function createKeyRange(start, end, inclusiveEnd, key, descending) { } function idbAllDocs(opts, idb, callback) { - var start = 'startkey' in opts ? opts.startkey : false; - var end = 'endkey' in opts ? opts.endkey : false; - var key = 'key' in opts ? opts.key : false; - var keys = 'keys' in opts ? opts.keys : false; - var skip = opts.skip || 0; - var limit = typeof opts.limit === 'number' ? opts.limit : -1; - var inclusiveEnd = opts.inclusive_end !== false; - - var keyRange ; - var keyRangeError; + const start = 'startkey' in opts ? opts.startkey : false; + const end = 'endkey' in opts ? opts.endkey : false; + const key = 'key' in opts ? opts.key : false; + const keys = 'keys' in opts ? opts.keys : false; + let skip = opts.skip || 0; + const limit = typeof opts.limit === 'number' ? opts.limit : -1; + const inclusiveEnd = opts.inclusive_end !== false; + + let keyRange; + let keyRangeError; if (!keys) { keyRange = createKeyRange(start, end, inclusiveEnd, key, opts.descending); keyRangeError = keyRange && keyRange.error; @@ -88,25 +88,25 @@ function idbAllDocs(opts, idb, callback) { } } - var stores = [DOC_STORE, BY_SEQ_STORE, META_STORE]; + const stores = [DOC_STORE, BY_SEQ_STORE, META_STORE]; if (opts.attachments) { stores.push(ATTACH_STORE); } - var txnResult = openTransactionSafely(idb, stores, 'readonly'); + const txnResult = openTransactionSafely(idb, stores, 'readonly'); if (txnResult.error) { return callback(txnResult.error); } - var txn = txnResult.txn; + const txn = txnResult.txn; txn.oncomplete = onTxnComplete; txn.onabort = idbError(callback); - var docStore = txn.objectStore(DOC_STORE); - var seqStore = txn.objectStore(BY_SEQ_STORE); - var metaStore = txn.objectStore(META_STORE); - var docIdRevIndex = seqStore.index('_doc_id_rev'); - var results = []; - var docCount; - var updateSeq; + const docStore = txn.objectStore(DOC_STORE); + const seqStore = txn.objectStore(BY_SEQ_STORE); + const metaStore = txn.objectStore(META_STORE); + const docIdRevIndex = seqStore.index('_doc_id_rev'); + const results = []; + let docCount; + let updateSeq; metaStore.get(META_STORE).onsuccess = function (e) { docCount = e.target.result.docCount; @@ -116,7 +116,7 @@ function idbAllDocs(opts, idb, callback) { if (opts.update_seq) { // get max updateSeq seqStore.openKeyCursor(null, 'prev').onsuccess = e => { - var cursor = e.target.result; + const cursor = e.target.result; if (cursor && cursor.key) { updateSeq = cursor.key; } @@ -126,11 +126,11 @@ function idbAllDocs(opts, idb, callback) { // if the user specifies include_docs=true, then we don't // want to block the main cursor while we're fetching the doc function fetchDocAsynchronously(metadata, row, winningRev) { - var key = metadata.id + "::" + winningRev; + const key = metadata.id + "::" + winningRev; docIdRevIndex.get(key).onsuccess = function onGetDoc(e) { row.doc = decodeDoc(e.target.result) || {}; if (opts.conflicts) { - var conflicts = collectConflicts(metadata); + const conflicts = collectConflicts(metadata); if (conflicts.length) { row.doc._conflicts = conflicts; } @@ -140,14 +140,14 @@ function idbAllDocs(opts, idb, callback) { } function allDocsInner(winningRev, metadata) { - var row = { + const row = { id: metadata.id, key: metadata.id, value: { rev: winningRev } }; - var deleted = metadata.deleted; + const deleted = metadata.deleted; if (deleted) { if (keys) { results.push(row); @@ -164,18 +164,18 @@ function idbAllDocs(opts, idb, callback) { } function processBatch(batchValues) { - for (var i = 0, len = batchValues.length; i < len; i++) { + for (let i = 0, len = batchValues.length; i < len; i++) { if (results.length === limit) { break; } - var batchValue = batchValues[i]; + const batchValue = batchValues[i]; if (batchValue.error && keys) { // key was not found with "keys" requests results.push(batchValue); continue; } - var metadata = decodeMetadata(batchValue); - var winningRev = metadata.winningRev; + const metadata = decodeMetadata(batchValue); + const winningRev = metadata.winningRev; allDocsInner(winningRev, metadata); } } @@ -191,7 +191,7 @@ function idbAllDocs(opts, idb, callback) { } function onGetAll(e) { - var values = e.target.result; + let values = e.target.result; if (opts.descending) { values = values.reverse(); } @@ -199,7 +199,7 @@ function idbAllDocs(opts, idb, callback) { } function onResultsReady() { - var returnVal = { + const returnVal = { total_rows: docCount, offset: opts.skip, rows: results diff --git a/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js b/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js index a9dfdf2db1..806ba02d88 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js @@ -30,18 +30,18 @@ import { import changesHandler from './changesHandler'; function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { - var docInfos = req.docs; - var txn; - var docStore; - var bySeqStore; - var attachStore; - var attachAndSeqStore; - var metaStore; - var docInfoError; - var metaDoc; - - for (var i = 0, len = docInfos.length; i < len; i++) { - var doc = docInfos[i]; + const docInfos = req.docs; + let txn; + let docStore; + let bySeqStore; + let attachStore; + let attachAndSeqStore; + let metaStore; + let docInfoError; + let metaDoc; + + for (let i = 0, len = docInfos.length; i < len; i++) { + let doc = docInfos[i]; if (doc._id && isLocalId(doc._id)) { continue; } @@ -55,12 +55,12 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { return callback(docInfoError); } - var allDocsProcessed = false; - var docCountDelta = 0; - var results = new Array(docInfos.length); - var fetchedDocs = new Map(); - var preconditionErrored = false; - var blobType = api._meta.blobSupport ? 'blob' : 'base64'; + let allDocsProcessed = false; + let docCountDelta = 0; + const results = new Array(docInfos.length); + const fetchedDocs = new Map(); + let preconditionErrored = false; + const blobType = api._meta.blobSupport ? 'blob' : 'base64'; preprocessAttachments(docInfos, blobType, function (err) { if (err) { @@ -71,13 +71,13 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { function startTransaction() { - var stores = [ + const stores = [ DOC_STORE, BY_SEQ_STORE, ATTACH_STORE, LOCAL_STORE, ATTACH_AND_SEQ_STORE, META_STORE ]; - var txnResult = openTransactionSafely(idb, stores, 'readwrite'); + const txnResult = openTransactionSafely(idb, stores, 'readwrite'); if (txnResult.error) { return callback(txnResult.error); } @@ -131,7 +131,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { return; } - var numFetched = 0; + let numFetched = 0; function checkDone() { if (++numFetched === docInfos.length) { @@ -140,7 +140,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { } function readMetadata(event) { - var metadata = decodeMetadata(event.target.result); + const metadata = decodeMetadata(event.target.result); if (metadata) { fetchedDocs.set(metadata.id, metadata); @@ -148,13 +148,13 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { checkDone(); } - for (var i = 0, len = docInfos.length; i < len; i++) { - var docInfo = docInfos[i]; + for (let i = 0, len = docInfos.length; i < len; i++) { + const docInfo = docInfos[i]; if (docInfo._id && isLocalId(docInfo._id)) { checkDone(); // skip local docs continue; } - var req = docStore.get(docInfo.metadata.id); + const req = docStore.get(docInfo.metadata.id); req.onsuccess = readMetadata; } } @@ -170,10 +170,10 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { function verifyAttachment(digest, callback) { - var req = attachStore.get(digest); + const req = attachStore.get(digest); req.onsuccess = function (e) { if (!e.target.result) { - var err = createError(MISSING_STUB, + const err = createError(MISSING_STUB, 'unknown stub attachment with digest ' + digest); err.status = 412; @@ -187,11 +187,11 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { function verifyAttachments(finish) { - var digests = []; + const digests = []; docInfos.forEach(function (docInfo) { if (docInfo.data && docInfo.data._attachments) { Object.keys(docInfo.data._attachments).forEach(function (filename) { - var att = docInfo.data._attachments[filename]; + const att = docInfo.data._attachments[filename]; if (att.stub) { digests.push(att.digest); } @@ -201,8 +201,8 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { if (!digests.length) { return finish(); } - var numDone = 0; - var err; + let numDone = 0; + let err; function checkDone() { if (++numDone === digests.length) { @@ -225,7 +225,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { docInfo.metadata.winningRev = winningRev; docInfo.metadata.deleted = winningRevIsDeleted; - var doc = docInfo.data; + const doc = docInfo.data; doc._id = docInfo.metadata.id; doc._rev = docInfo.metadata.rev; @@ -233,7 +233,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { doc._deleted = true; } - var hasAttachments = doc._attachments && + const hasAttachments = doc._attachments && Object.keys(doc._attachments).length; if (hasAttachments) { return writeAttachments(docInfo, winningRev, winningRevIsDeleted, @@ -250,15 +250,15 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { function finishDoc(docInfo, winningRev, winningRevIsDeleted, isUpdate, resultsIdx, callback) { - var doc = docInfo.data; - var metadata = docInfo.metadata; + const doc = docInfo.data; + const metadata = docInfo.metadata; doc._doc_id_rev = metadata.id + '::' + metadata.rev; delete doc._id; delete doc._rev; function afterPutDoc(e) { - var revsToDelete = docInfo.stemmedRevs || []; + let revsToDelete = docInfo.stemmedRevs || []; if (isUpdate && api.auto_compaction) { revsToDelete = revsToDelete.concat(compactTree(docInfo.metadata)); @@ -271,9 +271,9 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { metadata.seq = e.target.result; // Current _rev is calculated from _rev_tree on read // delete metadata.rev; - var metadataToStore = encodeMetadata(metadata, winningRev, + const metadataToStore = encodeMetadata(metadata, winningRev, winningRevIsDeleted); - var metaDataReq = docStore.put(metadataToStore); + const metaDataReq = docStore.put(metadataToStore); metaDataReq.onsuccess = afterPutMetadata; } @@ -281,10 +281,10 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { // ConstraintError, need to update, not put (see #1638 for details) e.preventDefault(); // avoid transaction abort e.stopPropagation(); // avoid transaction onerror - var index = bySeqStore.index('_doc_id_rev'); - var getKeyReq = index.getKey(doc._doc_id_rev); + const index = bySeqStore.index('_doc_id_rev'); + const getKeyReq = index.getKey(doc._doc_id_rev); getKeyReq.onsuccess = function (e) { - var putReq = bySeqStore.put(doc, e.target.result); + const putReq = bySeqStore.put(doc, e.target.result); putReq.onsuccess = afterPutDoc; }; } @@ -299,7 +299,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { insertAttachmentMappings(docInfo, metadata.seq, callback); } - var putReq = bySeqStore.put(doc); + const putReq = bySeqStore.put(doc); putReq.onsuccess = afterPutDoc; putReq.onerror = afterPutDocError; @@ -309,10 +309,10 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { isUpdate, resultsIdx, callback) { - var doc = docInfo.data; + const doc = docInfo.data; - var numDone = 0; - var attachments = Object.keys(doc._attachments); + let numDone = 0; + const attachments = Object.keys(doc._attachments); function collectResults() { if (numDone === attachments.length) { @@ -327,12 +327,12 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { } attachments.forEach(function (key) { - var att = docInfo.data._attachments[key]; + const att = docInfo.data._attachments[key]; if (!att.stub) { - var data = att.data; + const data = att.data; delete att.data; att.revpos = parseInt(winningRev, 10); - var digest = att.digest; + const digest = att.digest; saveAttachment(digest, data, attachmentSaved); } else { numDone++; @@ -345,8 +345,8 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { // we will need later during compaction function insertAttachmentMappings(docInfo, seq, callback) { - var attsAdded = 0; - var attsToAdd = Object.keys(docInfo.data._attachments || {}); + let attsAdded = 0; + const attsToAdd = Object.keys(docInfo.data._attachments || {}); if (!attsToAdd.length) { return callback(); @@ -359,8 +359,8 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { } function add(att) { - var digest = docInfo.data._attachments[att].digest; - var req = attachAndSeqStore.put({ + const digest = docInfo.data._attachments[att].digest; + const req = attachAndSeqStore.put({ seq, digestSeq: digest + '::' + seq }); @@ -375,7 +375,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { checkDone(); }; } - for (var i = 0; i < attsToAdd.length; i++) { + for (let i = 0; i < attsToAdd.length; i++) { add(attsToAdd[i]); // do in parallel } } @@ -383,17 +383,17 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) { function saveAttachment(digest, data, callback) { - var getKeyReq = attachStore.count(digest); + const getKeyReq = attachStore.count(digest); getKeyReq.onsuccess = function (e) { - var count = e.target.result; + const count = e.target.result; if (count) { return callback(); // already exists } - var newAtt = { + const newAtt = { digest, body: data }; - var putReq = attachStore.put(newAtt); + const putReq = attachStore.put(newAtt); putReq.onsuccess = callback; }; } diff --git a/packages/node_modules/pouchdb-adapter-idb/src/changes.js b/packages/node_modules/pouchdb-adapter-idb/src/changes.js index 1c1840cbed..11321a470b 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/changes.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/changes.js @@ -23,7 +23,7 @@ function changes(opts, api, dbName, idb) { opts = clone(opts); if (opts.continuous) { - var id = dbName + ':' + uuid(); + const id = dbName + ':' + uuid(); changesHandler.addListener(dbName, id, api, opts); changesHandler.notify(dbName); return { @@ -33,39 +33,39 @@ function changes(opts, api, dbName, idb) { }; } - var docIds = opts.doc_ids && new Set(opts.doc_ids); + const docIds = opts.doc_ids && new Set(opts.doc_ids); opts.since = opts.since || 0; - var lastSeq = opts.since; + let lastSeq = opts.since; - var limit = 'limit' in opts ? opts.limit : -1; + let limit = 'limit' in opts ? opts.limit : -1; if (limit === 0) { limit = 1; // per CouchDB _changes spec } - var results = []; - var numResults = 0; - var filter = filterChange(opts); - var docIdsToMetadata = new Map(); + const results = []; + let numResults = 0; + const filter = filterChange(opts); + const docIdsToMetadata = new Map(); - var txn; - var bySeqStore; - var docStore; - var docIdRevIndex; + let txn; + let bySeqStore; + let docStore; + let docIdRevIndex; function onBatch(batchKeys, batchValues, cursor) { if (!cursor || !batchKeys.length) { // done return; } - var winningDocs = new Array(batchKeys.length); - var metadatas = new Array(batchKeys.length); + const winningDocs = new Array(batchKeys.length); + const metadatas = new Array(batchKeys.length); function processMetadataAndWinningDoc(metadata, winningDoc) { - var change = opts.processChange(winningDoc, metadata, opts); + const change = opts.processChange(winningDoc, metadata, opts); lastSeq = change.seq = metadata.seq; - var filtered = filter(change); + const filtered = filter(change); if (typeof filtered === 'object') { // anything but true/false indicates error return Promise.reject(filtered); } @@ -93,21 +93,21 @@ function changes(opts, api, dbName, idb) { } function onBatchDone() { - var promises = []; - for (var i = 0, len = winningDocs.length; i < len; i++) { + const promises = []; + for (let i = 0, len = winningDocs.length; i < len; i++) { if (numResults === limit) { break; } - var winningDoc = winningDocs[i]; + const winningDoc = winningDocs[i]; if (!winningDoc) { continue; } - var metadata = metadatas[i]; + const metadata = metadatas[i]; promises.push(processMetadataAndWinningDoc(metadata, winningDoc)); } Promise.all(promises).then(function (changes) { - for (var i = 0, len = changes.length; i < len; i++) { + for (let i = 0, len = changes.length; i < len; i++) { if (changes[i]) { opts.onChange(changes[i]); } @@ -122,10 +122,10 @@ function changes(opts, api, dbName, idb) { // Fetch all metadatas/winningdocs from this batch in parallel, then process // them all only once all data has been collected. This is done in parallel // because it's faster than doing it one-at-a-time. - var numDone = 0; + let numDone = 0; batchValues.forEach(function (value, i) { - var doc = decodeDoc(value); - var seq = batchKeys[i]; + const doc = decodeDoc(value); + const seq = batchKeys[i]; fetchWinningDocAndMetadata(doc, seq, function (metadata, winningDoc) { metadatas[i] = metadata; winningDocs[i] = winningDoc; @@ -148,8 +148,8 @@ function changes(opts, api, dbName, idb) { } // fetch winning doc in separate request - var docIdRev = doc._id + '::' + metadata.winningRev; - var req = docIdRevIndex.get(docIdRev); + const docIdRev = doc._id + '::' + metadata.winningRev; + const req = docIdRevIndex.get(docIdRev); req.onsuccess = function (e) { cb(metadata, decodeDoc(e.target.result)); }; @@ -160,7 +160,7 @@ function changes(opts, api, dbName, idb) { return cb(); } - var metadata = docIdsToMetadata.get(doc._id); + let metadata = docIdsToMetadata.get(doc._id); if (metadata) { // cached return onGetMetadata(doc, seq, metadata, cb); } @@ -189,11 +189,11 @@ function changes(opts, api, dbName, idb) { } } - var objectStores = [DOC_STORE, BY_SEQ_STORE]; + const objectStores = [DOC_STORE, BY_SEQ_STORE]; if (opts.attachments) { objectStores.push(ATTACH_STORE); } - var txnResult = openTransactionSafely(idb, objectStores, 'readonly'); + const txnResult = openTransactionSafely(idb, objectStores, 'readonly'); if (txnResult.error) { return opts.complete(txnResult.error); } @@ -205,7 +205,7 @@ function changes(opts, api, dbName, idb) { docStore = txn.objectStore(DOC_STORE); docIdRevIndex = bySeqStore.index('_doc_id_rev'); - var keyRange = (opts.since && !opts.descending) ? + const keyRange = (opts.since && !opts.descending) ? IDBKeyRange.lowerBound(opts.since, true) : null; runBatchedCursor(bySeqStore, keyRange, opts.descending, limit, onBatch); diff --git a/packages/node_modules/pouchdb-adapter-idb/src/constants.js b/packages/node_modules/pouchdb-adapter-idb/src/constants.js index f9b0208ce2..a2d485d984 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/constants.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/constants.js @@ -1,27 +1,27 @@ // IndexedDB requires a versioned database structure, so we use the // version here to manage migrations. -var ADAPTER_VERSION = 5; +const ADAPTER_VERSION = 5; // The object stores created for each database // DOC_STORE stores the document meta data, its revision history and state // Keyed by document id -var DOC_STORE = 'document-store'; +const DOC_STORE = 'document-store'; // BY_SEQ_STORE stores a particular version of a document, keyed by its // sequence id -var BY_SEQ_STORE = 'by-sequence'; +const BY_SEQ_STORE = 'by-sequence'; // Where we store attachments -var ATTACH_STORE = 'attach-store'; +const ATTACH_STORE = 'attach-store'; // Where we store many-to-many relations // between attachment digests and seqs -var ATTACH_AND_SEQ_STORE = 'attach-seq-store'; +const ATTACH_AND_SEQ_STORE = 'attach-seq-store'; // Where we store database-wide meta data in a single record // keyed by id: META_STORE -var META_STORE = 'meta-store'; +const META_STORE = 'meta-store'; // Where we store local documents -var LOCAL_STORE = 'local-store'; +const LOCAL_STORE = 'local-store'; // Where we detect blob support -var DETECT_BLOB_SUPPORT_STORE = 'detect-blob-support'; +const DETECT_BLOB_SUPPORT_STORE = 'detect-blob-support'; export { ADAPTER_VERSION as ADAPTER_VERSION, diff --git a/packages/node_modules/pouchdb-adapter-idb/src/countDocs.js b/packages/node_modules/pouchdb-adapter-idb/src/countDocs.js index 111616aac8..eb95ee5546 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/countDocs.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/countDocs.js @@ -1,7 +1,7 @@ import { DOC_STORE } from './constants'; function countDocs(txn, cb) { - var index = txn.objectStore(DOC_STORE).index('deletedOrLocal'); + const index = txn.objectStore(DOC_STORE).index('deletedOrLocal'); index.count(IDBKeyRange.only('0')).onsuccess = function (e) { cb(e.target.result); }; diff --git a/packages/node_modules/pouchdb-adapter-idb/src/getAll.js b/packages/node_modules/pouchdb-adapter-idb/src/getAll.js index 0a8abd4dd8..0ade5de056 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/getAll.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/getAll.js @@ -6,10 +6,10 @@ function getAll(objectStore, keyRange, onSuccess) { return; } // fall back to cursors - var values = []; + const values = []; function onCursor(e) { - var cursor = e.target.result; + const cursor = e.target.result; if (cursor) { values.push(cursor.value); cursor.continue(); diff --git a/packages/node_modules/pouchdb-adapter-idb/src/index.js b/packages/node_modules/pouchdb-adapter-idb/src/index.js index 586ca50f03..de2eff34bd 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/index.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/index.js @@ -50,12 +50,12 @@ import { enqueueTask } from './taskQueue'; import changesHandler from './changesHandler'; import changes from './changes'; -var cachedDBs = new Map(); -var blobSupportPromise; -var openReqList = new Map(); +const cachedDBs = new Map(); +let blobSupportPromise; +const openReqList = new Map(); function IdbPouch(opts, callback) { - var api = this; + const api = this; enqueueTask(function (thisCallback) { init(api, opts, thisCallback); @@ -64,10 +64,10 @@ function IdbPouch(opts, callback) { function init(api, opts, callback) { - var dbName = opts.name; + const dbName = opts.name; - var idb = null; - var idbGlobalFailureError = null; + let idb = null; + let idbGlobalFailureError = null; api._meta = null; function enrichCallbackError(callback) { @@ -84,7 +84,7 @@ function init(api, opts, callback) { // called when creating a fresh new database function createSchema(db) { - var docStore = db.createObjectStore(DOC_STORE, {keyPath : 'id'}); + const docStore = db.createObjectStore(DOC_STORE, {keyPath : 'id'}); db.createObjectStore(BY_SEQ_STORE, {autoIncrement: true}) .createIndex('_doc_id_rev', '_doc_id_rev', {unique: true}); db.createObjectStore(ATTACH_STORE, {keyPath: 'digest'}); @@ -98,7 +98,7 @@ function init(api, opts, callback) { db.createObjectStore(LOCAL_STORE, {keyPath: '_id'}); // added in v4 - var attAndSeqStore = db.createObjectStore(ATTACH_AND_SEQ_STORE, + const attAndSeqStore = db.createObjectStore(ATTACH_AND_SEQ_STORE, {autoIncrement: true}); attAndSeqStore.createIndex('seq', 'seq'); attAndSeqStore.createIndex('digestSeq', 'digestSeq', {unique: true}); @@ -108,14 +108,14 @@ function init(api, opts, callback) { // unfortunately "deletedOrLocal" is a misnomer now that we no longer // store local docs in the main doc-store, but whaddyagonnado function addDeletedOrLocalIndex(txn, callback) { - var docStore = txn.objectStore(DOC_STORE); + const docStore = txn.objectStore(DOC_STORE); docStore.createIndex('deletedOrLocal', 'deletedOrLocal', {unique : false}); docStore.openCursor().onsuccess = function (event) { - var cursor = event.target.result; + const cursor = event.target.result; if (cursor) { - var metadata = cursor.value; - var deleted = isDeleted(metadata); + const metadata = cursor.value; + const deleted = isDeleted(metadata); metadata.deletedOrLocal = deleted ? "1" : "0"; docStore.put(metadata); cursor.continue(); @@ -133,27 +133,27 @@ function init(api, opts, callback) { // migration to version 3 (part 2) function migrateLocalStore(txn, cb) { - var localStore = txn.objectStore(LOCAL_STORE); - var docStore = txn.objectStore(DOC_STORE); - var seqStore = txn.objectStore(BY_SEQ_STORE); + const localStore = txn.objectStore(LOCAL_STORE); + const docStore = txn.objectStore(DOC_STORE); + const seqStore = txn.objectStore(BY_SEQ_STORE); - var cursor = docStore.openCursor(); + const cursor = docStore.openCursor(); cursor.onsuccess = function (event) { - var cursor = event.target.result; + const cursor = event.target.result; if (cursor) { - var metadata = cursor.value; - var docId = metadata.id; - var local = isLocalId(docId); - var rev = calculateWinningRev(metadata); + const metadata = cursor.value; + const docId = metadata.id; + const local = isLocalId(docId); + const rev = calculateWinningRev(metadata); if (local) { - var docIdRev = docId + "::" + rev; + const docIdRev = docId + "::" + rev; // remove all seq entries // associated with this docId - var start = docId + "::"; - var end = docId + "::~"; - var index = seqStore.index('_doc_id_rev'); - var range = IDBKeyRange.bound(start, end, false, false); - var seqCursor = index.openCursor(range); + const start = docId + "::"; + const end = docId + "::~"; + const index = seqStore.index('_doc_id_rev'); + const range = IDBKeyRange.bound(start, end, false, false); + let seqCursor = index.openCursor(range); seqCursor.onsuccess = function (e) { seqCursor = e.target.result; if (!seqCursor) { @@ -161,7 +161,7 @@ function init(api, opts, callback) { docStore.delete(cursor.primaryKey); cursor.continue(); } else { - var data = seqCursor.value; + const data = seqCursor.value; if (data._doc_id_rev === docIdRev) { localStore.put(data); } @@ -180,7 +180,7 @@ function init(api, opts, callback) { // migration to version 4 (part 1) function addAttachAndSeqStore(db) { - var attAndSeqStore = db.createObjectStore(ATTACH_AND_SEQ_STORE, + const attAndSeqStore = db.createObjectStore(ATTACH_AND_SEQ_STORE, {autoIncrement: true}); attAndSeqStore.createIndex('seq', 'seq'); attAndSeqStore.createIndex('digestSeq', 'digestSeq', {unique: true}); @@ -188,36 +188,36 @@ function init(api, opts, callback) { // migration to version 4 (part 2) function migrateAttsAndSeqs(txn, callback) { - var seqStore = txn.objectStore(BY_SEQ_STORE); - var attStore = txn.objectStore(ATTACH_STORE); - var attAndSeqStore = txn.objectStore(ATTACH_AND_SEQ_STORE); + const seqStore = txn.objectStore(BY_SEQ_STORE); + const attStore = txn.objectStore(ATTACH_STORE); + const attAndSeqStore = txn.objectStore(ATTACH_AND_SEQ_STORE); // need to actually populate the table. this is the expensive part, // so as an optimization, check first that this database even // contains attachments - var req = attStore.count(); + const req = attStore.count(); req.onsuccess = function (e) { - var count = e.target.result; + const count = e.target.result; if (!count) { return callback(); // done } seqStore.openCursor().onsuccess = function (e) { - var cursor = e.target.result; + const cursor = e.target.result; if (!cursor) { return callback(); // done } - var doc = cursor.value; - var seq = cursor.primaryKey; - var atts = Object.keys(doc._attachments || {}); - var digestMap = {}; - for (var j = 0; j < atts.length; j++) { - var att = doc._attachments[atts[j]]; + const doc = cursor.value; + const seq = cursor.primaryKey; + const atts = Object.keys(doc._attachments || {}); + const digestMap = {}; + for (let j = 0; j < atts.length; j++) { + const att = doc._attachments[atts[j]]; digestMap[att.digest] = true; // uniq digests, just in case } - var digests = Object.keys(digestMap); - for (j = 0; j < digests.length; j++) { - var digest = digests[j]; + const digests = Object.keys(digestMap); + for (let j = 0; j < digests.length; j++) { + const digest = digests[j]; attAndSeqStore.put({ seq, digestSeq: digest + '::' + seq @@ -247,15 +247,15 @@ function init(api, opts, callback) { // ensure that every metadata has a winningRev and seq, // which was previously created on-the-fly but better to migrate - var bySeqStore = txn.objectStore(BY_SEQ_STORE); - var docStore = txn.objectStore(DOC_STORE); - var cursor = docStore.openCursor(); + const bySeqStore = txn.objectStore(BY_SEQ_STORE); + const docStore = txn.objectStore(DOC_STORE); + const cursor = docStore.openCursor(); cursor.onsuccess = function (e) { - var cursor = e.target.result; + const cursor = e.target.result; if (!cursor) { return; // done } - var metadata = decodeMetadataCompat(cursor.value); + const metadata = decodeMetadataCompat(cursor.value); metadata.winningRev = metadata.winningRev || calculateWinningRev(metadata); @@ -263,19 +263,19 @@ function init(api, opts, callback) { function fetchMetadataSeq() { // metadata.seq was added post-3.2.0, so if it's missing, // we need to fetch it manually - var start = metadata.id + '::'; - var end = metadata.id + '::\uffff'; - var req = bySeqStore.index('_doc_id_rev').openCursor( + const start = metadata.id + '::'; + const end = metadata.id + '::\uffff'; + const req = bySeqStore.index('_doc_id_rev').openCursor( IDBKeyRange.bound(start, end)); - var metadataSeq = 0; + let metadataSeq = 0; req.onsuccess = function (e) { - var cursor = e.target.result; + const cursor = e.target.result; if (!cursor) { metadata.seq = metadataSeq; return onGetMetadataSeq(); } - var seq = cursor.primaryKey; + const seq = cursor.primaryKey; if (seq > metadataSeq) { metadataSeq = seq; } @@ -284,10 +284,10 @@ function init(api, opts, callback) { } function onGetMetadataSeq() { - var metadataToStore = encodeMetadata(metadata, + const metadataToStore = encodeMetadata(metadata, metadata.winningRev, metadata.deleted); - var req = docStore.put(metadataToStore); + const req = docStore.put(metadataToStore); req.onsuccess = function () { cursor.continue(); }; @@ -318,12 +318,12 @@ function init(api, opts, callback) { // First we look up the metadata in the ids database, then we fetch the // current revision(s) from the by sequence store api._get = function idb_get(id, opts, callback) { - var doc; - var metadata; - var err; - var txn = opts.ctx; + let doc; + let metadata; + let err; + let txn = opts.ctx; if (!txn) { - var txnResult = openTransactionSafely(idb, + const txnResult = openTransactionSafely(idb, [DOC_STORE, BY_SEQ_STORE, ATTACH_STORE], 'readonly'); if (txnResult.error) { return callback(txnResult.error); @@ -347,10 +347,10 @@ function init(api, opts, callback) { return finish(); } - var rev; + let rev; if (!opts.rev) { rev = metadata.winningRev; - var deleted = isDeleted(metadata); + const deleted = isDeleted(metadata); if (deleted) { err = createError(MISSING_DOC, "deleted"); return finish(); @@ -359,8 +359,8 @@ function init(api, opts, callback) { rev = opts.latest ? getLatest(opts.rev, metadata) : opts.rev; } - var objectStore = txn.objectStore(BY_SEQ_STORE); - var key = metadata.id + '::' + rev; + const objectStore = txn.objectStore(BY_SEQ_STORE); + const key = metadata.id + '::' + rev; objectStore.index('_doc_id_rev').get(key).onsuccess = function (e) { doc = e.target.result; @@ -377,22 +377,22 @@ function init(api, opts, callback) { }; api._getAttachment = function (docId, attachId, attachment, opts, callback) { - var txn; + let txn; if (opts.ctx) { txn = opts.ctx; } else { - var txnResult = openTransactionSafely(idb, + const txnResult = openTransactionSafely(idb, [DOC_STORE, BY_SEQ_STORE, ATTACH_STORE], 'readonly'); if (txnResult.error) { return callback(txnResult.error); } txn = txnResult.txn; } - var digest = attachment.digest; - var type = attachment.content_type; + const digest = attachment.digest; + const type = attachment.content_type; txn.objectStore(ATTACH_STORE).get(digest).onsuccess = function (e) { - var body = e.target.result.body; + const body = e.target.result.body; readBlobData(body, type, opts.binary, function (blobData) { callback(null, blobData); }); @@ -400,19 +400,19 @@ function init(api, opts, callback) { }; api._info = function idb_info(callback) { - var updateSeq; - var docCount; + let updateSeq; + let docCount; - var txnResult = openTransactionSafely(idb, [META_STORE, BY_SEQ_STORE], 'readonly'); + const txnResult = openTransactionSafely(idb, [META_STORE, BY_SEQ_STORE], 'readonly'); if (txnResult.error) { return callback(txnResult.error); } - var txn = txnResult.txn; + const txn = txnResult.txn; txn.objectStore(META_STORE).get(META_STORE).onsuccess = function (e) { docCount = e.target.result.docCount; }; txn.objectStore(BY_SEQ_STORE).openKeyCursor(null, 'prev').onsuccess = function (e) { - var cursor = e.target.result; + const cursor = e.target.result; updateSeq = cursor ? cursor.key : 0; }; @@ -443,14 +443,14 @@ function init(api, opts, callback) { }; api._getRevisionTree = function (docId, callback) { - var txnResult = openTransactionSafely(idb, [DOC_STORE], 'readonly'); + const txnResult = openTransactionSafely(idb, [DOC_STORE], 'readonly'); if (txnResult.error) { return callback(txnResult.error); } - var txn = txnResult.txn; - var req = txn.objectStore(DOC_STORE).get(docId); + const txn = txnResult.txn; + const req = txn.objectStore(DOC_STORE).get(docId); req.onsuccess = function (event) { - var doc = decodeMetadata(event.target.result); + const doc = decodeMetadata(event.target.result); if (!doc) { callback(createError(MISSING_DOC)); } else { @@ -463,32 +463,32 @@ function init(api, opts, callback) { // which are listed in revs and sets this document // revision to to rev_tree api._doCompaction = function (docId, revs, callback) { - var stores = [ + const stores = [ DOC_STORE, BY_SEQ_STORE, ATTACH_STORE, ATTACH_AND_SEQ_STORE ]; - var txnResult = openTransactionSafely(idb, stores, 'readwrite'); + const txnResult = openTransactionSafely(idb, stores, 'readwrite'); if (txnResult.error) { return callback(txnResult.error); } - var txn = txnResult.txn; + const txn = txnResult.txn; - var docStore = txn.objectStore(DOC_STORE); + const docStore = txn.objectStore(DOC_STORE); docStore.get(docId).onsuccess = function (event) { - var metadata = decodeMetadata(event.target.result); + const metadata = decodeMetadata(event.target.result); traverseRevTree(metadata.rev_tree, function (isLeaf, pos, revHash, ctx, opts) { - var rev = pos + '-' + revHash; + const rev = pos + '-' + revHash; if (revs.indexOf(rev) !== -1) { opts.status = 'missing'; } }); compactRevs(revs, docId, txn); - var winningRev = metadata.winningRev; - var deleted = metadata.deleted; + const winningRev = metadata.winningRev; + const deleted = metadata.deleted; txn.objectStore(DOC_STORE).put( encodeMetadata(metadata, winningRev, deleted)); }; @@ -500,16 +500,16 @@ function init(api, opts, callback) { api._getLocal = function (id, callback) { - var txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readonly'); + const txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readonly'); if (txnResult.error) { return callback(txnResult.error); } - var tx = txnResult.txn; - var req = tx.objectStore(LOCAL_STORE).get(id); + const tx = txnResult.txn; + const req = tx.objectStore(LOCAL_STORE).get(id); req.onerror = idbError(callback); req.onsuccess = function (e) { - var doc = e.target.result; + const doc = e.target.result; if (!doc) { callback(createError(MISSING_DOC)); } else { @@ -525,18 +525,18 @@ function init(api, opts, callback) { opts = {}; } delete doc._revisions; // ignore this, trust the rev - var oldRev = doc._rev; - var id = doc._id; + const oldRev = doc._rev; + const id = doc._id; if (!oldRev) { doc._rev = '0-1'; } else { doc._rev = '0-' + (parseInt(oldRev.split('-')[1], 10) + 1); } - var tx = opts.ctx; - var ret; + let tx = opts.ctx; + let ret; if (!tx) { - var txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readwrite'); + const txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readwrite'); if (txnResult.error) { return callback(txnResult.error); } @@ -549,16 +549,16 @@ function init(api, opts, callback) { }; } - var oStore = tx.objectStore(LOCAL_STORE); - var req; + const oStore = tx.objectStore(LOCAL_STORE); + let req; if (oldRev) { req = oStore.get(id); req.onsuccess = function (e) { - var oldDoc = e.target.result; + const oldDoc = e.target.result; if (!oldDoc || oldDoc._rev !== oldRev) { callback(createError(REV_CONFLICT)); } else { // update - var req = oStore.put(doc); + const req = oStore.put(doc); req.onsuccess = function () { ret = {ok: true, id: doc._id, rev: doc._rev}; if (opts.ctx) { // return immediately @@ -589,9 +589,9 @@ function init(api, opts, callback) { callback = opts; opts = {}; } - var tx = opts.ctx; + let tx = opts.ctx; if (!tx) { - var txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readwrite'); + const txnResult = openTransactionSafely(idb, [LOCAL_STORE], 'readwrite'); if (txnResult.error) { return callback(txnResult.error); } @@ -602,14 +602,14 @@ function init(api, opts, callback) { } }; } - var ret; - var id = doc._id; - var oStore = tx.objectStore(LOCAL_STORE); - var req = oStore.get(id); + let ret; + const id = doc._id; + const oStore = tx.objectStore(LOCAL_STORE); + const req = oStore.get(id); req.onerror = idbError(callback); req.onsuccess = function (e) { - var oldDoc = e.target.result; + const oldDoc = e.target.result; if (!oldDoc || oldDoc._rev !== doc._rev) { callback(createError(MISSING_DOC)); } else { @@ -626,12 +626,12 @@ function init(api, opts, callback) { changesHandler.removeAllListeners(dbName); //Close open request for "dbName" database to fix ie delay. - var openReq = openReqList.get(dbName); + const openReq = openReqList.get(dbName); if (openReq && openReq.result) { openReq.result.close(); cachedDBs.delete(dbName); } - var req = indexedDB.deleteDatabase(dbName); + const req = indexedDB.deleteDatabase(dbName); req.onsuccess = function () { //Remove open request from the list. @@ -645,7 +645,7 @@ function init(api, opts, callback) { req.onerror = idbError(callback); }; - var cached = cachedDBs.get(dbName); + const cached = cachedDBs.get(dbName); if (cached) { idb = cached.idb; @@ -655,17 +655,17 @@ function init(api, opts, callback) { }); } - var req = indexedDB.open(dbName, ADAPTER_VERSION); + const req = indexedDB.open(dbName, ADAPTER_VERSION); openReqList.set(dbName, req); req.onupgradeneeded = function (e) { - var db = e.target.result; + const db = e.target.result; if (e.oldVersion < 1) { return createSchema(db); // new db, initial schema } // do migrations - var txn = e.currentTarget.transaction; + const txn = e.currentTarget.transaction; // these migrations have to be done in this function, before // control is returned to the event loop, because IndexedDB @@ -676,17 +676,17 @@ function init(api, opts, callback) { addAttachAndSeqStore(db); // v3 -> v4 } - var migrations = [ + const migrations = [ addDeletedOrLocalIndex, // v1 -> v2 migrateLocalStore, // v2 -> v3 migrateAttsAndSeqs, // v3 -> v4 migrateMetadata // v4 -> v5 ]; - var i = e.oldVersion; + let i = e.oldVersion; function next() { - var migration = migrations[i - 1]; + const migration = migrations[i - 1]; i++; if (migration) { migration(txn, next); @@ -719,17 +719,17 @@ function init(api, opts, callback) { // 4. Generate an instanceId if necessary // 5. Store docCount and instanceId on meta doc - var txn = idb.transaction([ + const txn = idb.transaction([ META_STORE, DETECT_BLOB_SUPPORT_STORE, DOC_STORE ], 'readwrite'); - var storedMetaDoc = false; - var metaDoc; - var docCount; - var blobSupport; - var instanceId; + let storedMetaDoc = false; + let metaDoc; + let docCount; + let blobSupport; + let instanceId; function completeSetup() { if (typeof blobSupport === 'undefined' || !storedMetaDoc) { @@ -752,7 +752,7 @@ function init(api, opts, callback) { if (typeof docCount === 'undefined' || typeof metaDoc === 'undefined') { return; } - var instanceKey = dbName + '_id'; + const instanceKey = dbName + '_id'; if (instanceKey in metaDoc) { instanceId = metaDoc[instanceKey]; } else { @@ -801,7 +801,7 @@ function init(api, opts, callback) { }; req.onerror = function (e) { - var msg = e.target.error && e.target.error.message; + let msg = e.target.error && e.target.error.message; if (!msg) { msg = 'Failed to open indexedDB, are you in private browsing mode?'; diff --git a/packages/node_modules/pouchdb-adapter-idb/src/runBatchedCursor.js b/packages/node_modules/pouchdb-adapter-idb/src/runBatchedCursor.js index 236a612ef8..dc25166893 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/runBatchedCursor.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/runBatchedCursor.js @@ -13,13 +13,13 @@ function runBatchedCursor(objectStore, keyRange, descending, batchSize, onBatch) // 2) batchSize is 1 (might as well use IDBCursor) // 3) descending – no real way to do this via getAll()/getAllKeys() - var useGetAll = typeof objectStore.getAll === 'function' && + const useGetAll = typeof objectStore.getAll === 'function' && typeof objectStore.getAllKeys === 'function' && batchSize > 1 && !descending; - var keysBatch; - var valuesBatch; - var pseudoCursor; + let keysBatch; + let valuesBatch; + let pseudoCursor; function onGetAll(e) { valuesBatch = e.target.result; @@ -40,8 +40,8 @@ function runBatchedCursor(objectStore, keyRange, descending, batchSize, onBatch) return onBatch(); } // fetch next batch, exclusive start - var lastKey = keysBatch[keysBatch.length - 1]; - var newKeyRange; + const lastKey = keysBatch[keysBatch.length - 1]; + let newKeyRange; if (keyRange && keyRange.upper) { try { newKeyRange = IDBKeyRange.bound(lastKey, keyRange.upper, @@ -62,7 +62,7 @@ function runBatchedCursor(objectStore, keyRange, descending, batchSize, onBatch) } function onCursor(e) { - var cursor = e.target.result; + const cursor = e.target.result; if (!cursor) { // done return onBatch(); } diff --git a/packages/node_modules/pouchdb-adapter-idb/src/taskQueue.js b/packages/node_modules/pouchdb-adapter-idb/src/taskQueue.js index efd797c7da..fee6f6ea7a 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/taskQueue.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/taskQueue.js @@ -4,8 +4,8 @@ import { nextTick } from 'pouchdb-utils'; -var running = false; -var queue = []; +let running = false; +const queue = []; function tryCode(fun, err, res, PouchDB) { try { diff --git a/packages/node_modules/pouchdb-adapter-idb/src/utils.js b/packages/node_modules/pouchdb-adapter-idb/src/utils.js index ec8439c036..7b2ce9e8be 100644 --- a/packages/node_modules/pouchdb-adapter-idb/src/utils.js +++ b/packages/node_modules/pouchdb-adapter-idb/src/utils.js @@ -17,7 +17,7 @@ import { ATTACH_AND_SEQ_STORE, ATTACH_STORE, BY_SEQ_STORE } from './constants'; function idbError(callback) { return function (evt) { - var message = 'unknown_error'; + let message = 'unknown_error'; if (evt.target && evt.target.error) { message = evt.target.error.name || evt.target.error.message; } @@ -46,7 +46,7 @@ function decodeMetadata(storedObject) { if (!storedObject) { return null; } - var metadata = safeJsonParse(storedObject.data); + const metadata = safeJsonParse(storedObject.data); metadata.winningRev = storedObject.winningRev; metadata.deleted = storedObject.deletedOrLocal === '1'; metadata.seq = storedObject.seq; @@ -59,7 +59,7 @@ function decodeDoc(doc) { if (!doc) { return doc; } - var idx = doc._doc_id_rev.lastIndexOf(':'); + const idx = doc._doc_id_rev.lastIndexOf(':'); doc._id = doc._doc_id_rev.substring(0, idx - 1); doc._rev = doc._doc_id_rev.substring(idx + 1); delete doc._doc_id_rev; @@ -92,11 +92,11 @@ function readBlobData(body, type, asBlob, callback) { } function fetchAttachmentsIfNecessary(doc, opts, txn, cb) { - var attachments = Object.keys(doc._attachments || {}); + const attachments = Object.keys(doc._attachments || {}); if (!attachments.length) { return cb && cb(); } - var numDone = 0; + let numDone = 0; function checkDone() { if (++numDone === attachments.length && cb) { @@ -105,9 +105,9 @@ function fetchAttachmentsIfNecessary(doc, opts, txn, cb) { } function fetchAttachment(doc, att) { - var attObj = doc._attachments[att]; - var digest = attObj.digest; - var req = txn.objectStore(ATTACH_STORE).get(digest); + const attObj = doc._attachments[att]; + const digest = attObj.digest; + const req = txn.objectStore(ATTACH_STORE).get(digest); req.onsuccess = function (e) { attObj.body = e.target.result.body; checkDone(); @@ -131,14 +131,14 @@ function fetchAttachmentsIfNecessary(doc, opts, txn, cb) { function postProcessAttachments(results, asBlob) { return Promise.all(results.map(function (row) { if (row.doc && row.doc._attachments) { - var attNames = Object.keys(row.doc._attachments); + const attNames = Object.keys(row.doc._attachments); return Promise.all(attNames.map(function (att) { - var attObj = row.doc._attachments[att]; + const attObj = row.doc._attachments[att]; if (!('body' in attObj)) { // already processed return; } - var body = attObj.body; - var type = attObj.content_type; + const body = attObj.body; + const type = attObj.content_type; return new Promise(function (resolve) { readBlobData(body, type, asBlob, function (data) { row.doc._attachments[att] = Object.assign( @@ -155,11 +155,11 @@ function postProcessAttachments(results, asBlob) { function compactRevs(revs, docId, txn) { - var possiblyOrphanedDigests = []; - var seqStore = txn.objectStore(BY_SEQ_STORE); - var attStore = txn.objectStore(ATTACH_STORE); - var attAndSeqStore = txn.objectStore(ATTACH_AND_SEQ_STORE); - var count = revs.length; + const possiblyOrphanedDigests = []; + const seqStore = txn.objectStore(BY_SEQ_STORE); + const attStore = txn.objectStore(ATTACH_STORE); + const attAndSeqStore = txn.objectStore(ATTACH_AND_SEQ_STORE); + let count = revs.length; function checkDone() { count--; @@ -173,11 +173,11 @@ function compactRevs(revs, docId, txn) { return; } possiblyOrphanedDigests.forEach(function (digest) { - var countReq = attAndSeqStore.index('digestSeq').count( + const countReq = attAndSeqStore.index('digestSeq').count( IDBKeyRange.bound( digest + '::', digest + '::\uffff', false, false)); countReq.onsuccess = function (e) { - var count = e.target.result; + const count = e.target.result; if (!count) { // orphaned attStore.delete(digest); @@ -187,22 +187,22 @@ function compactRevs(revs, docId, txn) { } revs.forEach(function (rev) { - var index = seqStore.index('_doc_id_rev'); - var key = docId + "::" + rev; + const index = seqStore.index('_doc_id_rev'); + const key = docId + "::" + rev; index.getKey(key).onsuccess = function (e) { - var seq = e.target.result; + const seq = e.target.result; if (typeof seq !== 'number') { return checkDone(); } seqStore.delete(seq); - var cursor = attAndSeqStore.index('seq') + const cursor = attAndSeqStore.index('seq') .openCursor(IDBKeyRange.only(seq)); cursor.onsuccess = function (event) { - var cursor = event.target.result; + const cursor = event.target.result; if (cursor) { - var digest = cursor.value.digestSeq.split('::')[0]; + const digest = cursor.value.digestSeq.split('::')[0]; possiblyOrphanedDigests.push(digest); attAndSeqStore.delete(cursor.primaryKey); cursor.continue();