Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function getHost({ name, prefix }) {

// Generate a URL with the host data given by opts and the given path
function genDBUrl(opts, path) {
return genUrl(opts, opts.db + '/' + path);
const dbPath = opts.scope && path !== '' ? `${opts.db}.${opts.scope}.${opts.collection}` :opts.db;
return genUrl(opts, dbPath + '/' + path);
}

// Generate a URL with the host data given by opts and the given path
Expand Down Expand Up @@ -561,6 +562,11 @@ function HttpPouch(opts, callback) {
}
return fetchAttachments(docOrDocs);
}
// only add scope and collection to _local documents
if (id.startsWith('_local/')) {
host.scope = opts.scope;
host.collection = opts.collection;
}

const url = genDBUrl(host, id + paramsToStr(params));
try {
Expand Down Expand Up @@ -855,7 +861,6 @@ function HttpPouch(opts, callback) {
// TODO According to the README, there should be two other methods here,
// api.changes.addListener and api.changes.removeListener.
api._changes = function (opts) {

// We internally page the results of a changes request, this means
// if there is a large set of changes to be returned we can start
// processing them quicker instead of waiting on the entire
Expand Down Expand Up @@ -992,7 +997,8 @@ function HttpPouch(opts, callback) {
params.limit = (!limit || leftToFetch > batchSize) ?
batchSize : leftToFetch;
}

host.scope = opts.scope;
host.collection = opts.collection;
// Set the options for the ajax call
const url = genDBUrl(host, '_changes' + paramsToStr(params));
const fetchOpts = {
Expand Down
18 changes: 9 additions & 9 deletions packages/node_modules/pouchdb-checkpointer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var REPLICATOR = "pouchdb";
var CHECKPOINT_HISTORY_SIZE = 5;
var LOWEST_SEQ = 0;

function updateCheckpoint(db, id, checkpoint, session, returnValue) {
return db.get(id).catch(function (err) {
function updateCheckpoint(db, id, checkpoint, session, returnValue, opts) {
return db.get(id, opts).catch(function (err) {
if (err.status === 404) {
if (db.adapter === 'http' || db.adapter === 'https') {
explainError(
Expand Down Expand Up @@ -62,10 +62,10 @@ function updateCheckpoint(db, id, checkpoint, session, returnValue) {
doc.session_id = session;
doc.last_seq = checkpoint;

return db.put(doc).catch(function (err) {
return db.put(doc, opts).catch(function (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
return updateCheckpoint(db, id, checkpoint, session, returnValue);
return updateCheckpoint(db, id, checkpoint, session, returnValue, opts);
}
throw err;
});
Expand Down Expand Up @@ -102,7 +102,7 @@ class CheckpointerInternal {
updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
return updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
session, this.returnValue,this.opts);
} else {
return Promise.resolve(true);
}
Expand All @@ -112,7 +112,7 @@ class CheckpointerInternal {
if (this.opts.writeSourceCheckpoint) {
var self = this;
return updateCheckpoint(this.src, this.id, checkpoint,
session, this.returnValue)
session, this.returnValue, this.opts)
.catch(function (err) {
if (isForbiddenError(err)) {
self.opts.writeSourceCheckpoint = false;
Expand All @@ -133,7 +133,7 @@ class CheckpointerInternal {
}

if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
return self.src.get(self.id).then(function (sourceDoc) {
return self.src.get(self.id, self.opts).then(function (sourceDoc) {
return sourceDoc.last_seq || LOWEST_SEQ;
}).catch(function (err) {
/* istanbul ignore if */
Expand All @@ -144,12 +144,12 @@ class CheckpointerInternal {
});
}

return self.target.get(self.id).then(function (targetDoc) {
return self.target.get(self.id, self.opts).then(function (targetDoc) {
if (self.opts && self.opts.writeTargetCheckpoint && !self.opts.writeSourceCheckpoint) {
return targetDoc.last_seq || LOWEST_SEQ;
}

return self.src.get(self.id).then(function (sourceDoc) {
return self.src.get(self.id, self.opts).then(function (sourceDoc) {
// Since we can't migrate an old version doc to a new one
// (no session id), we just go with the lowest seq in this case
/* istanbul ignore if */
Expand Down
6 changes: 6 additions & 0 deletions packages/node_modules/pouchdb-replication/src/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function replicate(src, target, opts, returnValue, result) {
repId = res;

var checkpointOpts = {};
checkpointOpts.scope = opts.scope;
checkpointOpts.collection = opts.collection;
if (opts.checkpoint === false) {
checkpointOpts = { writeSourceCheckpoint: false, writeTargetCheckpoint: false };
} else if (opts.checkpoint === 'source') {
Expand All @@ -64,6 +66,8 @@ function replicate(src, target, opts, returnValue, result) {
} else {
checkpointOpts = { writeSourceCheckpoint: true, writeTargetCheckpoint: true };
}
checkpointOpts.collection = opts.collection;
checkpointOpts.scope = opts.scope;

checkpointer = new Checkpointer(src, target, repId, returnValue, checkpointOpts);
});
Expand Down Expand Up @@ -470,6 +474,8 @@ function replicate(src, target, opts, returnValue, result) {
style,
doc_ids,
selector,
scope: opts.scope,
collection: opts.collection,
return_docs: true // required so we know when we're done
};
if (opts.filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function replicateWrapper(src, target, opts, callback) {
opts.continuous = opts.continuous || opts.live;
opts.retry = ('retry' in opts) ? opts.retry : false;
opts.PouchConstructor = opts.PouchConstructor || this;
opts.scope = opts.scope || '_default';
opts.collection = opts.collection || '_default';
var replicateRet = new Replication(opts);
var srcPouch = toPouch(src, opts);
var targetPouch = toPouch(target, opts);
Expand Down