From 3731f143b254a311f9c91c8b9d9ef2a03ce787cb Mon Sep 17 00:00:00 2001 From: Tyler Johnson Date: Mon, 12 Jan 2015 12:19:59 -0700 Subject: [PATCH] sync bug fixes --- README.md | 2 +- lib/index.js | 8 ++++---- lib/sync.js | 6 +++--- lib/utils.js | 14 ++------------ test/test.js | 2 +- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b602603..8571fec 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ When `.connect()` is called, the database will listen to the database changes fe ## Documentation -For quick documentation, please see the inline comments in the source code. These comments are written in markdown, so you can also build them for a prettier experience. +For quick documentation on each function, please see the inline comments in the source code. These comments are in [Doxxo](https://github.com/BeneathTheInk/doxxo) format, so you can also build them for a prettier experience. ```bash npm run build-docs diff --git a/lib/index.js b/lib/index.js index b92b7db..9ebe98e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,7 +41,7 @@ function Lazybones(name, opts) { // create PouchDB instance from options this.pouch = opts.pouch instanceof PouchDB ? opts.pouch : new PouchDB(name, opts.pouch); - // set the database on the object for easy access + // set the database name on the object for easy access Object.defineProperty(this, "name", { value: name, writeable: false, @@ -132,7 +132,7 @@ _.extend(Lazybones.prototype, { conflicts: true, returnDocs: false, live: true - }, _.pick(options, utils.pouchOptionKeys.changes), { + }, options, { include_docs: true })) @@ -313,7 +313,7 @@ _.extend(Lazybones.prototype, { // return result async .map(function(result, index) { // resolve or reject depending on result - docs[index][result.ok ? "resolve" : "reject"](result); + docs[index][result.error ? "reject" : "resolve"](result); // remove from the queue if resolution was successful delete queue[ids[index]]; @@ -323,7 +323,7 @@ _.extend(Lazybones.prototype, { }, { concurrency: 20 }) // after a successful write, invalidate the queue again - .then(this._invalidateWrites) + .then(this._invalidateWrites); }) // always, always reset state diff --git a/lib/sync.js b/lib/sync.js index 5ab08c4..01b3cc7 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -58,10 +58,10 @@ module.exports = function sync(method, model, options) { case "read": // fetch single if document if (isdoc) { - pouch_opts = _.defaults(_.pick(options, utils.pouchOptionKeys.get), { + pouch_opts = _.extend({ conflicts: true, attachments: false - }); + }, options); return Promise.cast(db.pouch.get(id, pouch_opts)).tap(options.success); } @@ -71,7 +71,7 @@ module.exports = function sync(method, model, options) { pouch_opts = _.extend({ conflicts: true, attachments: false - }, _.pick(options, utils.pouchOptionKeys.allDocs), { + }, options, { include_docs: true // always must include the full document }); diff --git a/lib/utils.js b/lib/utils.js index 7bcdeb2..f035a1d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,17 +22,6 @@ exports.uuid = PouchDB.utils.uuid; */ exports.Promise = Promise; -/** - * ### pouchOptionKeys - * - * Lists of option keys by method names that can be used in PouchDB requests. This allows option objects to be sanitized before being passed to PouchDB. - */ -exports.pouchOptionKeys = { - get: [ "rev", "revs", "revs_info", "open_revs", "conflicts", "attachments", "local_seq", "ajax" ], - allDocs: [ "include_docs", "conflicts", "attachments", "startkey", "endkey", "inclusive_end", "limit", "skip", "descending", "key", "keys" ], - changes: [ "include_docs", "conflicts", "attachments", "filter", "doc_ids", "since", "live", "limit", "style", "view", "returnDocs", "batch_size" ] -}; - /** * ### parse() * @@ -155,7 +144,8 @@ LazyError.errors = { */ exports.transformPouchError = function(e) { // make sure this is a real pouch error - if (!(e || e.error)) throw e; + if (!e) throw new LazyError; + if (!e.error || e instanceof LazyError) throw e; var nerr = new LazyError("POUCH_ERROR", e.message); nerr.error = true; // keep it consistent diff --git a/test/test.js b/test/test.js index 18e9765..8c09153 100644 --- a/test/test.js +++ b/test/test.js @@ -176,4 +176,4 @@ describe("Live Sync", function() { describe("Conflicts", function() { -}); \ No newline at end of file +});