Skip to content

Commit

Permalink
Some minor JS stuff mostly.
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-de-vries committed Jun 6, 2014
1 parent 0348435 commit faa6e0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var coucheval = require("couchdb-eval");
var couchdb_objects = require("couchdb-objects");
var nodify = require("promise-nodify");

var uuid = require("node-uuid");
var Promise = require("pouchdb-promise");

function oldDoc(db, id) {
return db.get(id, {revs: true}).catch(function () {
return null;
Expand Down Expand Up @@ -56,8 +59,6 @@ function validate(validationFuncs, newDoc, oldDoc, options) {
}

function doValidation(db, newDoc, options, callback) {
var Promise = db.constructor.utils.Promise;

var isHttp = ["http", "https"].indexOf(db.type()) !== -1;
if (isHttp && !options.checkHttp) {
//CouchDB does the checking for itself. Validate succesful.
Expand Down Expand Up @@ -91,7 +92,6 @@ function completeValidationOptions(db, options) {
options.secObj = couchdb_objects.buildSecurityObject();
}

var Promise = db.constructor.utils.Promise;
var userCtxPromise;
if (options.userCtx) {
userCtxPromise = Promise.resolve(options.userCtx);
Expand Down Expand Up @@ -153,9 +153,8 @@ exports.validatingPut = function (doc, options, callback) {

exports.validatingPost = function (doc, options, callback) {
var args = processArgs(this, callback, options);
var PouchDB = args.db.constructor;

doc._id = doc._id || PouchDB.utils.uuid();
doc._id = doc._id || uuid.v4();
var promise = doValidation(args.db, doc, args.options).then(function () {
return args.db.post(doc, args.options);
});
Expand All @@ -179,14 +178,12 @@ exports.validatingBulkDocs = function (bulkDocs, options, callback) {
//Also, the result array might not be in the same order as
//``bulkDocs.docs``
var args = processArgs(this, callback, options);
var PouchDB = args.db.constructor;
var Promise = PouchDB.utils.Promise;

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

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

return validationPromise.then(function (resp) {
Expand Down
21 changes: 19 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
{
"name": "pouchdb-validation",
"version": "1.0.0",
"version": "1.0.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": {
"type": "bzr",
"url": "http:https://bazaar.launchpad.net/~marten-de-vries/python-pouchdb/0.x"
},
"homepage": "http:https://python-pouchdb.marten-de-vries.nl/plugins.html",
"bugs": "https://bugs.launchpad.net/python-pouchdb",
"keywords": [
"pouch",
"pouchdb",
"couch",
"couchdb",
"validation",
"validate",
"validate_doc_update"
],
"license": "Apache-2.0",
"author": "Marten de Vries",
"dependencies": {
"couchdb-objects": "^0.1.0",
"couchdb-eval": "^1.0.0",
"promise-nodify": "^1.0.0"
"promise-nodify": "^1.0.0",
"pouchdb-promise": "^0.0.0",
"node-uuid": "^1.4.1"
},
"devDependencies": {
"browserify": "^4.1.8",
"uglify-js": "^2.4.13",
"es3ify": "^0.1.3"
},
"scripts": {
Expand Down

0 comments on commit faa6e0b

Please sign in to comment.