From 105609ad05781b32cedb31a08b898cbe9a0d93f4 Mon Sep 17 00:00:00 2001 From: Marten de Vries Date: Fri, 4 Jul 2014 21:11:41 +0200 Subject: [PATCH] A bunch of JS improvements (incl. replicator module (experimental)) & some improvements to coroutines (nesting them, most notably) --- index.js | 28 ++++++++-------------------- package.json | 7 ++++--- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 66b309d..d2e7fcd 100644 --- a/index.js +++ b/index.js @@ -22,23 +22,7 @@ var nodify = require("promise-nodify"); var uuid = require("node-uuid"); var Promise = require("pouchdb-promise"); - -function PouchError(opts) { - this.status = opts.status; - this.name = opts.name; - this.message = opts.message; - this.error = true; -} - -PouchError.prototype__proto__ = Error.prototype; - -PouchError.prototype.toString = function () { - return JSON.stringify({ - status: this.status, - name: this.name, - message: this.message - }); -}; +var PouchPluginError = require("pouchdb-plugin-error"); var dbs = []; var methodNames = ["put", "post", "remove", "bulkDocs", "putAttachment", "removeAttachment"]; @@ -126,7 +110,7 @@ function completeValidationOptions(db, options) { options = {}; } if (!options.secObj) { - options.secObj = couchdb_objects.buildSecurityObject(); + options.secObj = {}; } var userCtxPromise; @@ -283,7 +267,7 @@ exports.installValidationMethods = function () { var db = this; if (dbs.indexOf(db) !== -1) { - throw new PouchError({ + throw new PouchPluginError({ status: 500, name: "already_installed", message: "Validation methods are already installed on this database." @@ -302,7 +286,7 @@ exports.uninstallValidationMethods = function () { var index = dbs.indexOf(db); if (index === -1) { - throw new PouchError({ + throw new PouchPluginError({ status: 500, name: "already_not_installed", message: "Validation methods are already not installed on this database." @@ -312,4 +296,8 @@ exports.uninstallValidationMethods = function () { methodNames.forEach(function (name) { db[name] = meths[name]; }); + + //cleanup + dbs.splice(index, 1); + methodsByDbsIdx.splice(index, 1); }; diff --git a/package.json b/package.json index 0173cd5..24af01d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pouchdb-validation", - "version": "1.1.0", + "version": "1.1.2", "main": "index.js", "description": "A PouchDB plug-in that allows you to re-use your CouchDB validate_doc_update functions on the client side.", "repository": { @@ -21,11 +21,12 @@ "license": "Apache-2.0", "author": "Marten de Vries", "dependencies": { - "couchdb-objects": "^0.1.0", + "couchdb-objects": "^1.0.0", "couchdb-eval": "^1.0.0", "promise-nodify": "^1.0.0", "pouchdb-promise": "^0.0.0", - "node-uuid": "^1.4.1" + "node-uuid": "^1.4.1", + "pouchdb-plugin-error": "^0.1.0" }, "devDependencies": { "browserify": "^4.1.8",