diff --git a/index.js b/index.js index 785d20d..7fab1cc 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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. @@ -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); @@ -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); }); @@ -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) { diff --git a/package.json b/package.json index 497125d..a334521 100644 --- a/package.json +++ b/package.json @@ -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://bazaar.launchpad.net/~marten-de-vries/python-pouchdb/0.x" }, + "homepage": "http://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": {