Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}; // next batch, not yet ready to be processed
var writingCheckpoint = false; // true while checkpoint is being written
var changesCompleted = false; // true when all changes received
var replicationCompleted = false; // true when replication has completed
var last_seq = 0;
var continuous = opts.continuous || opts.live || false;
var batch_size = opts.batch_size || 100;
var batches_limit = opts.batches_limit || 10;
var changesPending = false; // true while src.changes is running
var doc_ids = opts.doc_ids;
var selector = opts.selector;
var repId;
var checkpointer;
var changedDocs = [];
// Like couchdb, every replication gets a unique session id
var session = uuid();
result = result || {
ok: true,
start_time: new Date().toISOString(),
docs_read: 0,
docs_written: 0,
doc_write_failures: 0,
errors: []
};
var changesOpts = {};
returnValue.ready(src, target);
function initCheckpointer() {
if (checkpointer) {
return Promise.resolve();
tx.executeSql(meta, [], function () {
// mark the db version, and new dbid
var initSeq = 'INSERT INTO ' + META_STORE +
' (db_version, dbid) VALUES (?,?)';
instanceId = uuid();
var initSeqArgs = [ADAPTER_VERSION, instanceId];
tx.executeSql(initSeq, initSeqArgs, function () {
onGetInstanceId();
});
});
});
export default function(db, api, opts) {
const continuous = opts.continuous
if (continuous) {
const id = db.opts.name + ':' + uuid()
db.changes.addListener(db.opts.name, id, api, opts)
db.changes.notify(db.opts.name)
return {
cancel() {
db.changes.removeListener(db.opts.name, id)
}
}
}
// const descending = opts.descending
const lastSeq = opts.since || 0
const limit = 'limit' in opts && opts.limit >= 0 ? opts.limit : -1
const filterDocIds = opts.doc_ids && new Set(opts.doc_ids)
const returnDocs =
'return_docs' in opts
? opts.return_docs
export default function (txn, idbChanges, api, dbOpts, opts) {
if (txn.error) {
return opts.complete(txn.error);
}
if (opts.continuous) {
var id = dbOpts.name + ':' + uuid();
idbChanges.addListener(dbOpts.name, id, api, opts);
idbChanges.notify(dbOpts.name);
return {
cancel: function () {
idbChanges.removeListener(dbOpts.name, id);
}
};
}
var limit = 'limit' in opts ? opts.limit : -1;
if (limit === 0) {
limit = 1;
}
var store = txn.txn.objectStore(DOC_STORE).index('seq');
function storeMetaDocIfReady() {
if (typeof docCount === 'undefined' || typeof metaDoc === 'undefined') {
return;
}
var instanceKey = dbName + '_id';
if (instanceKey in metaDoc) {
instanceId = metaDoc[instanceKey];
} else {
metaDoc[instanceKey] = instanceId = uuid();
}
metaDoc.docCount = docCount;
txn.objectStore(META_STORE).put(metaDoc);
}
api._changes = function (opts) {
opts = pouchdbUtils.clone(opts);
if (opts.continuous) {
var id = name + ':' + pouchdbUtils.uuid();
levelChanges.addListener(name, id, api, opts);
levelChanges.notify(name);
return {
cancel: function () {
levelChanges.removeListener(name, id);
}
};
}
var descending = opts.descending;
var results = [];
var lastSeq = opts.since || 0;
var called = 0;
var streamOpts = {
reverse: descending
};
stores.metaStore.get(UUID_KEY, function (err, value) {
instanceId = !err ? value : pouchdbUtils.uuid();
stores.metaStore.put(UUID_KEY, instanceId, function () {
process.nextTick(function () {
callback(null, api);
});
});
});
});
api._changes = function (opts) {
opts = clone(opts);
if (opts.continuous) {
var id = name + ':' + uuid();
levelChanges.addListener(name, id, api, opts);
levelChanges.notify(name);
return {
cancel: function () {
levelChanges.removeListener(name, id);
}
};
}
var descending = opts.descending;
var results = [];
var lastSeq = opts.since || 0;
var called = 0;
var streamOpts = {
reverse: descending
};
stores.metaStore.get(UUID_KEY, function (err, value) {
instanceId = !err ? value : uuid();
stores.metaStore.put(UUID_KEY, instanceId, function () {
process.nextTick(function () {
callback(null, api);
});
});
});
});
stores.metaStore.get(UUID_KEY, function (err, value) {
instanceId = !err ? value : pouchdbUtils.uuid();
stores.metaStore.put(UUID_KEY, instanceId, function () {
process.nextTick(function () {
callback(null, api);
});
});
});
});