Skip to content

Commit

Permalink
A bunch of JS improvements (incl. replicator module (experimental)) &…
Browse files Browse the repository at this point in the history
… some improvements to coroutines (nesting them, most notably)
  • Loading branch information
marten-de-vries committed Jul 4, 2014
1 parent afc1a75 commit 105609a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
28 changes: 8 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -126,7 +110,7 @@ function completeValidationOptions(db, options) {
options = {};
}
if (!options.secObj) {
options.secObj = couchdb_objects.buildSecurityObject();
options.secObj = {};
}

var userCtxPromise;
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -312,4 +296,8 @@ exports.uninstallValidationMethods = function () {
methodNames.forEach(function (name) {
db[name] = meths[name];
});

//cleanup
dbs.splice(index, 1);
methodsByDbsIdx.splice(index, 1);
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down

0 comments on commit 105609a

Please sign in to comment.