Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// istanbul since its catching a race condition.
/* istanbul ignore if */
if (err && err.status && err.status === 412) {
return true;
}
return Promise.reject(err);
});
setupPromise.catch(function () {
setupPromise = null;
});
return setupPromise;
}
nextTick(function () {
callback(null, api);
});
api._remote = true;
/* istanbul ignore next */
api.type = function () {
return 'http';
};
api.id = adapterFun('id', function (callback) {
ourFetch(genUrl(host, '')).then(function (response) {
return response.json();
}).catch(function () {
return {};
}).then(function (result) {
function complete(err) {
/* istanbul ignore if */
if (err) {
return nextTick(function () {
callback(err);
});
}
txn.batch([
{
prefix: stores.metaStore,
type: 'put',
key: UPDATE_SEQ_KEY,
value: newUpdateSeq
},
{
prefix: stores.metaStore,
type: 'put',
key: DOC_COUNT_KEY,
value: db._docCount + docCountDelta
}
if (returnValue.cancelled) {
return completeReplication();
}
// Attach 'pending' property if server supports it (CouchDB 2.0+)
/* istanbul ignore if */
if (typeof pending === 'number') {
pendingBatch.pending = pending;
}
var filter = filterChange(opts)(change);
if (!filter) {
return;
}
pendingBatch.seq = change.seq || lastSeq;
pendingBatch.changes.push(change);
nextTick(function () {
processPendingBatch(batches.length === 0 && changesOpts.live);
});
}
openReqList.delete(dbName);
if (hasLocalStorage() && (dbName in localStorage)) {
delete localStorage[dbName];
}
callback(null, { 'ok': true });
};
req.onerror = idbError(callback);
};
var cached = cachedDBs.get(dbName);
if (cached) {
idb = cached.idb;
api._meta = cached.global;
return nextTick(function () {
callback(null, api);
});
}
var req = indexedDB.open(dbName, ADAPTER_VERSION);
openReqList.set(dbName, req);
req.onupgradeneeded = function (e) {
var db = e.target.result;
if (e.oldVersion < 1) {
return createSchema(db); // new db, initial schema
}
// do migrations
var txn = e.currentTarget.transaction;
// these migrations have to be done in this function, before
return getArguments(function (args) {
db._queue.push({
fun: fun,
args: args,
type: 'read'
});
if (db._queue.length === 1) {
nextTick(executeNext);
}
});
}