Skip to content

Commit

Permalink
Quite some stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-de-vries committed May 7, 2014
1 parent 692e39e commit a7eedd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use strict";

//TODO: call http equivalent if http adapter

var Promise = require("lie");

var coucheval = require("../utils/coucheval.js");
var addCallback = require("../utils/promisewrapper.js");
var buildUserContextObject = require("../builders/couchusercontextobject.js");
var buildSecurityObject = require("../builders/couchsecurityobject.js");
var couchdb_objects = require("../couchdb-objects");

function addOldDoc(db, id, args) {
return db.get(id).then(function (err) {
Expand Down Expand Up @@ -80,10 +81,11 @@ function completeValidationOptions(db, options) {
options = {};
}
if (!options.secObj) {
options.secObj = buildSecurityObject();
options.secObj = couchdb_objects.buildSecurityObject();
}
if (!options.userCtx) {
return db.info().then(buildUserContextObject).then(function (userCtx) {
var buildUserContext = couchdb_objects.buildUserContextObject;
return db.info().then(buildUserContext).then(function (userCtx) {
options.userCtx = userCtx;
return options;
});
Expand Down Expand Up @@ -111,7 +113,7 @@ function parseValidationFunctions(resp) {
});
validationFuncs = validationFuncs.map(function (info) {
//convert str -> function
return coucheval.eval(info.doc, {}, info.func);
return coucheval.evaluate(info.doc, {}, info.func);
});
return validationFuncs;
}
Expand Down Expand Up @@ -187,7 +189,7 @@ exports.validatingBulkDocs = function (bulkDocs, options, callback) {
return promise;
};

exports.validatingPutAttachment = function (docId, attachmentId, rev, attachment, type, options, callback) {
var vpa = function (docId, attachmentId, rev, attachment, type, options, callback) {
var args = processArgs(this, callback, options);

//get the doc
Expand All @@ -210,8 +212,9 @@ exports.validatingPutAttachment = function (docId, attachmentId, rev, attachment
addCallback(promise, callback);
return promise;
};
exports.validatingPutAttachment = vpa;

exports.validatingRemoveAttachment = function (docId, attachmentId, rev, options, callback) {
var vra = function (docId, attachmentId, rev, options, callback) {
var args = processArgs(this, callback, options);
//get the doc
var promise = args.db.get(docId, {rev: rev}).then(function (doc) {
Expand All @@ -226,3 +229,4 @@ exports.validatingRemoveAttachment = function (docId, attachmentId, rev, options
addCallback(promise, callback);
return promise;
};
exports.validatingRemoveAttachment = vra;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"name": "pouchdb-validation",
"main": "index.js"
"main": "index.js",
"scripts": {
"build-js": "mkdir -p ../../dist && browserify index.js -s Validation -o ../../dist/pouchdb-validation.js",
"build": "npm run build-js; cd ../../dist; uglifyjs pouchdb-validation.js -mc > pouchdb-validation.min.js"
}
}

0 comments on commit a7eedd2

Please sign in to comment.