diff --git a/packages/node_modules/pouchdb-adapter-http/src/index.js b/packages/node_modules/pouchdb-adapter-http/src/index.js index b19f2b4122..161667b40c 100644 --- a/packages/node_modules/pouchdb-adapter-http/src/index.js +++ b/packages/node_modules/pouchdb-adapter-http/src/index.js @@ -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 @@ -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 { @@ -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 @@ -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 = { diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js index 54e3e014ba..640146344f 100644 --- a/packages/node_modules/pouchdb-checkpointer/src/index.js +++ b/packages/node_modules/pouchdb-checkpointer/src/index.js @@ -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( @@ -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; }); @@ -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); } @@ -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; @@ -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 */ @@ -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 */ diff --git a/packages/node_modules/pouchdb-replication/src/replicate.js b/packages/node_modules/pouchdb-replication/src/replicate.js index 23c97023a4..fa3fa76839 100644 --- a/packages/node_modules/pouchdb-replication/src/replicate.js +++ b/packages/node_modules/pouchdb-replication/src/replicate.js @@ -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') { @@ -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); }); @@ -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) { diff --git a/packages/node_modules/pouchdb-replication/src/replicateWrapper.js b/packages/node_modules/pouchdb-replication/src/replicateWrapper.js index e5362084f1..eaaf5ea0e9 100644 --- a/packages/node_modules/pouchdb-replication/src/replicateWrapper.js +++ b/packages/node_modules/pouchdb-replication/src/replicateWrapper.js @@ -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);