Skip to content

Commit

Permalink
Makes _users and _replicator databases system databases (sets extra p…
Browse files Browse the repository at this point in the history
…rotections for them like in CouchDB). No regressions, but JS test coverage isn't complete yet.
  • Loading branch information
marten-de-vries committed Aug 31, 2014
1 parent 51cc492 commit 32ff0b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
39 changes: 7 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var coucheval = require("couchdb-eval");
var couchdb_objects = require("couchdb-objects");
var wrappers = require("pouchdb-wrappers");
var createBulkDocsWrapper = require("pouchdb-bulkdocs-wrapper");
var PouchPluginError = require("pouchdb-plugin-error");

var uuid = require("random-uuid-v4");
Expand Down Expand Up @@ -131,12 +132,13 @@ function parseValidationFunctions(resp) {
}

var wrapperApi = {};

wrapperApi.put = function (orig, args) {
return doValidation(args.db, args.doc, args.options).then(orig);
};

wrapperApi.post = function (orig, args) {
args.doc.id = args.doc.id || uuid();
args.doc._id = args.doc._id || uuid();
return doValidation(args.db, args.doc, args.options).then(orig);
};

Expand All @@ -145,37 +147,10 @@ wrapperApi.remove = function (orig, args) {
return doValidation(args.db, args.doc, args.options).then(orig);
};

wrapperApi.bulkDocs = function (original, args) {
//the ``all_or_nothing`` attribute on ``bulkDocs`` is unsupported.
//Also, the result array might not be in the same order as
//``bulkDocs.docs`` argument.

var done = [];
var notYetDone = [];

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

return validationPromise
.then(function (resp) {
notYetDone.push(doc);
})
.catch(function (err) {
err.id = doc._id;
done.push(err);
});
});
return Promise.all(validations)
.then(function () {
args.docs = notYetDone;

return original();
})
.then(function (insertedDocs) {
return done.concat(insertedDocs);
});
};
wrapperApi.bulkDocs = createBulkDocsWrapper(function (doc, args) {
doc._id = doc._id || uuid();
return doValidation(args.db, doc, args.options);
});

wrapperApi.putAttachment = function (orig, args) {
return args.db.get(args.docId, {rev: args.rev, revs: true})
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"couchdb-eval": "^1.0.0",
"pouchdb-promise": "^0.0.0",
"random-uuid-v4": "^0.0.4",
"pouchdb-plugin-error": "^0.2.0"
"pouchdb-plugin-error": "^0.2.0",
"pouchdb-wrappers": "^0.1.0",
"pouchdb-bulkdocs-wrapper": "^0.1.0"
},
"devDependencies": {
"browserify": "^4.1.8",
Expand Down

0 comments on commit 32ff0b4

Please sign in to comment.