Skip to content

Commit

Permalink
Improved docs + JS
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-de-vries committed Jul 6, 2014
1 parent 105609a commit e2ddb04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ function validate(validationFuncs, newDoc, oldDoc, options) {
});
} catch (e) {
if (typeof e.unauthorized !== "undefined") {
throw {
throw new PouchPluginError({
name: "unauthorized",
message: e.unauthorized,
status: 401
};
});
} else if (typeof e.forbidden !== "undefined") {
throw {
throw new PouchPluginError({
name: "forbidden",
message: e.forbidden,
status: 403
};
});
} else {
throw coucheval.wrapExecutionError(e);
}
Expand Down Expand Up @@ -203,7 +203,11 @@ exports.validatingBulkDocs = function (bulkDocs, options, callback) {
var done = [];
var notYetDone = [];

var validations = bulkDocs.docs.map(function (doc) {
if (!Array.isArray(bulkDocs)) {
bulkDocs = bulkDocs.docs;
}

var validations = bulkDocs.map(function (doc) {
doc._id = doc._id || uuid.v4();
var validationPromise = doValidation(args.db, doc, args.options);

Expand All @@ -215,7 +219,7 @@ exports.validatingBulkDocs = function (bulkDocs, options, callback) {
});
});
var allValidationsPromise = Promise.all(validations).then(function () {
return methods(args.db).bulkDocs({docs: notYetDone}, args.options);
return methods(args.db).bulkDocs(notYetDone, args.options);
}).then(function (insertedDocs) {
return done.concat(insertedDocs);
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pouchdb-validation",
"version": "1.1.2",
"version": "1.1.3",
"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 @@ -26,7 +26,7 @@
"promise-nodify": "^1.0.0",
"pouchdb-promise": "^0.0.0",
"node-uuid": "^1.4.1",
"pouchdb-plugin-error": "^0.1.0"
"pouchdb-plugin-error": "^0.2.0"
},
"devDependencies": {
"browserify": "^4.1.8",
Expand Down

0 comments on commit e2ddb04

Please sign in to comment.