Socket
Socket
Sign inDemoInstall

couchdb-emily-tools

Package Overview
Dependencies
21
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

README.md

18

build/CouchDBTools.js

@@ -6,13 +6,13 @@ /*

*/
define("CouchDBSecurity",["CouchDBStore"],function(k){function j(){var f="_security";this.setName=function(h){return h?(f=h,true):false};this.getName=function(){return f};this.load=function(h){return this.sync(h,f)}}return function(){j.prototype=new k;return new j}});
define("CouchDBStore",["Store","StateMachine","Tools","Promise"],function(k,j,f,h){function l(){var b=null,a={},i=new h,d={getView:function(){a.query=a.query||{};b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_design/"+a.design+"/"+a.view,query:a.query},function(c){var e=JSON.parse(c);if(e.rows)this.reset(e.rows),i.resolve(this),typeof e.total_rows=="undefined"&&this.setReducedViewInfo(true),g.event("subscribeToViewChanges");else throw Error("CouchDBStore ["+a.database+", "+a.design+", "+
a.view+"].sync() failed: "+c);},this)},getDocument:function(){b.request("CouchDB",{method:"GET",path:"/"+a.database+"/"+a.document,query:a.query},function(c){var a=JSON.parse(c);a._id?(this.reset(a),i.resolve(this),g.event("subscribeToDocumentChanges")):i.reject(c)},this)},getBulkDocuments:function(){var c={path:"/"+a.database+"/_all_docs",query:a.query},e;a.keys instanceof Array?(c.method="POST",c.data=JSON.stringify({keys:a.keys}),c.headers={"Content-Type":"application/json"},e=c.data):(c.method=
"GET",e=JSON.stringify(a.query));a.query.include_docs=true;b.request("CouchDB",c,function(c){var b=JSON.parse(c);if(b.rows)this.reset(b.rows),i.resolve(this),g.event("subscribeToBulkChanges");else throw Error('CouchDBStore.sync("'+a.database+'", '+e+") failed: "+c);},this)},createDocument:function(c){b.request("CouchDB",{method:"PUT",path:"/"+a.database+"/"+a.document,headers:{"Content-Type":"application/json"},data:this.toJSON()},function(a){a=JSON.parse(a);a.ok?(c.resolve(a),g.event("subscribeToDocumentChanges")):
c.reject(a)})},subscribeToViewChanges:function(){f.mixin({feed:"continuous",heartbeat:2E4,limit:0,descending:true},a.query);this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",query:a.query},function(c){if(c=="\n")return false;var c=JSON.parse(c),e;e=a.reducedView?"updateReduced":c.deleted?"delete":c.changes[0].rev.search("1-")==0?"add":"change";g.event(e,c.id)},this)},subscribeToDocumentChanges:function(){this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",query:{feed:"continuous",
heartbeat:2E4,limit:0,descending:true}},function(c){if(c=="\n")return false;c=JSON.parse(c);c.id==a.document&&c.changes.pop().rev!=this.get("_rev")&&(c.deleted?g.event("deleteDoc"):g.event("updateDoc"))},this)},subscribeToBulkChanges:function(){f.mixin({feed:"continuous",heartbeat:2E4,limit:0,descending:true,include_docs:true},a.query);this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",query:a.query},function(a){if(a=="\n")return false;var a=JSON.parse(a),e;e=a.changes[0].rev.search("1-")==
define("CouchDBBase",["Store","StateMachine","Tools","Promise"],function(){});define("CouchDBSecurity",["CouchDBStore"],function(k){function j(){var f="_security";this.setName=function(h){return h?(f=h,true):false};this.getName=function(){return f};this.load=function(h){return this.sync(h,f)}}return function(){j.prototype=new k;return new j}});
define("CouchDBStore",["Store","StateMachine","Tools","Promise"],function(k,j,f,h){function l(){var b=null,a={},i=new h,d={getView:function(){a.query=a.query||{};b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_design/"+a.design+"/"+a.view,query:a.query},function(c){var e=JSON.parse(c);if(e.rows)this.reset(e.rows),i.fulfill(this),typeof e.total_rows=="undefined"&&this.setReducedViewInfo(true),g.event("subscribeToViewChanges");else throw Error("CouchDBStore ["+a.database+", "+a.design+", "+
a.view+"].sync() failed: "+c);},this)},getDocument:function(){b.request("CouchDB",{method:"GET",path:"/"+a.database+"/"+a.document,query:a.query},function(c){var a=JSON.parse(c);a._id?(this.reset(a),i.fulfill(this),g.event("subscribeToDocumentChanges")):i.reject(c)},this)},getBulkDocuments:function(){var c={path:"/"+a.database+"/_all_docs",query:a.query},e;a.keys instanceof Array?(c.method="POST",c.data=JSON.stringify({keys:a.keys}),c.headers={"Content-Type":"application/json"},e=c.data):(c.method=
"GET",e=JSON.stringify(a.query));a.query.include_docs=true;b.request("CouchDB",c,function(c){var b=JSON.parse(c);if(b.rows)this.reset(b.rows),i.fulfill(this),g.event("subscribeToBulkChanges");else throw Error('CouchDBStore.sync("'+a.database+'", '+e+") failed: "+c);},this)},createDocument:function(c){b.request("CouchDB",{method:"PUT",path:"/"+a.database+"/"+a.document,headers:{"Content-Type":"application/json"},data:this.toJSON()},function(a){a=JSON.parse(a);a.ok?(c.fulfill(a),g.event("subscribeToDocumentChanges")):
c.reject(a)})},subscribeToViewChanges:function(){f.mixin({feed:"continuous",heartbeat:2E4,descending:true},a.query);this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",query:a.query},function(c){if(c=="\n")return false;var c=JSON.parse(c),e;e=a.reducedView?"updateReduced":c.deleted?"delete":c.changes&&c.changes[0].rev.search("1-")==0?"add":"change";g.event(e,c.id)},this)},subscribeToDocumentChanges:function(){this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",
query:{feed:"continuous",heartbeat:2E4,descending:true}},function(c){if(c=="\n")return false;c=JSON.parse(c);c.id==a.document&&c.changes.pop().rev!=this.get("_rev")&&(c.deleted?g.event("deleteDoc"):g.event("updateDoc"))},this)},subscribeToBulkChanges:function(){f.mixin({feed:"continuous",heartbeat:2E4,descending:true,include_docs:true},a.query);this.stopListening=b.listen("CouchDB",{path:"/"+a.database+"/_changes",query:a.query},function(a){if(a=="\n")return false;var a=JSON.parse(a),e;e=a.changes[0].rev.search("1-")==
0?"bulkAdd":a.deleted?"delete":"bulkChange";g.event(e,a.id,a.doc)},this)},updateDocInStore:function(c){b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_design/"+a.design+"/"+a.view,query:a.query},function(a){a=JSON.parse(a);a.rows.length==this.getNbItems()?a.rows.some(function(a,e){a.id==c&&this.set(e,a)},this):this.actions.evenDocsInStore.call(this,a.rows,c)},this)},evenDocsInStore:function(a,e){var b=this.getNbItems();a.length<b?this.loop(function(a,c){a.id==e&&this.del(c)},this):a.length>
b&&a.some(function(a,c){if(a.id==e)return this.alter("splice",c,0,a)},this)},addBulkDocInStore:function(c){if(a.query.startkey||a.query.endkey)a.query.include_docs=true,a.query.update_seq=true,b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_all_docs",query:a.query},function(a){JSON.parse(a).rows.forEach(function(a,e){a.id==c&&this.alter("splice",e,0,a.doc)},this)},this);else return false},updateBulkDocInStore:function(a,e){this.loop(function(b,d){b.id==a&&this.set(d,e)},this)},removeDocInStore:function(a){this.loop(function(e,
b){e.id==a&&this.del(b)},this)},addDocInStore:function(c){b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_design/"+a.design+"/"+a.view,query:a.query},function(a){JSON.parse(a).rows.some(function(a,b){a.id==c&&this.alter("splice",b,0,a)},this)},this)},updateReduced:function(){b.request("CouchDB",{method:"GET",path:"/"+a.database+"/_design/"+a.design+"/"+a.view,query:a.query},function(a){this.set(0,JSON.parse(a).rows[0])},this)},updateDoc:function(){b.request("CouchDB",{method:"GET",path:"/"+
a.database+"/"+a.document},function(a){this.reset(JSON.parse(a))},this)},deleteDoc:function(){this.reset({})},updateDatabase:function(c){b.request("CouchDB",{method:"PUT",path:"/"+a.database+"/"+a.document,headers:{"Content-Type":"application/json"},data:this.toJSON()},function(a){a=JSON.parse(a);a.ok?(this.set("_rev",a.rev),c.resolve(a)):c.reject(a)},this)},updateDatabaseWithBulkDoc:function(c){var e=[];this.loop(function(a){e.push(a.doc)});b.request("CouchDB",{method:"POST",path:"/"+a.database+
"/_bulk_docs",headers:{"Content-Type":"application/json"},data:JSON.stringify({docs:e})},function(a){c.resolve(JSON.parse(a))})},removeFromDatabase:function(){b.request("CouchDB",{method:"DELETE",path:"/"+a.database+"/"+a.document,query:{rev:this.get("_rev")}})},unsync:function(){this.stopListening();delete this.stopListening}},g=new j("Unsynched",{Unsynched:[["getView",d.getView,this,"Synched"],["getDocument",d.getDocument,this,"Synched"],["getBulkDocuments",d.getBulkDocuments,this,"Synched"]],Synched:[["updateDatabase",
a.database+"/"+a.document},function(a){this.reset(JSON.parse(a))},this)},deleteDoc:function(){this.reset({})},updateDatabase:function(c){b.request("CouchDB",{method:"PUT",path:"/"+a.database+"/"+a.document,headers:{"Content-Type":"application/json"},data:this.toJSON()},function(a){a=JSON.parse(a);a.ok?(this.set("_rev",a.rev),c.fulfill(a)):c.reject(a)},this)},updateDatabaseWithBulkDoc:function(c){var e=[];this.loop(function(a){e.push(a.doc)});b.request("CouchDB",{method:"POST",path:"/"+a.database+
"/_bulk_docs",headers:{"Content-Type":"application/json"},data:JSON.stringify({docs:e})},function(a){c.fulfill(JSON.parse(a))})},removeFromDatabase:function(){b.request("CouchDB",{method:"DELETE",path:"/"+a.database+"/"+a.document,query:{rev:this.get("_rev")}})},unsync:function(){this.stopListening();delete this.stopListening}},g=new j("Unsynched",{Unsynched:[["getView",d.getView,this,"Synched"],["getDocument",d.getDocument,this,"Synched"],["getBulkDocuments",d.getBulkDocuments,this,"Synched"]],Synched:[["updateDatabase",
d.createDocument,this],["subscribeToViewChanges",d.subscribeToViewChanges,this,"Listening"],["subscribeToDocumentChanges",d.subscribeToDocumentChanges,this,"Listening"],["subscribeToBulkChanges",d.subscribeToBulkChanges,this,"Listening"],["unsync",function(){},"Unsynched"]],Listening:[["change",d.updateDocInStore,this],["bulkAdd",d.addBulkDocInStore,this],["bulkChange",d.updateBulkDocInStore,this],["delete",d.removeDocInStore,this],["add",d.addDocInStore,this],["updateReduced",d.updateReduced,this],

@@ -24,3 +24,3 @@ ["updateDoc",d.updateDoc,this],["deleteDoc",d.deleteDoc,this],["updateDatabase",d.updateDatabase,this],["updateDatabaseWithBulkDoc",d.updateDatabaseWithBulkDoc,this],["removeFromDatabase",d.removeFromDatabase,this],["unsync",d.unsync,this,"Unsynched"]]});this.sync=function(a,b,d,f){i=new h;if(typeof a=="string"&&typeof b=="string"&&typeof d=="string")return this.setSyncInfo(a,b,d,f),g.event("getView"),i;else if(typeof a=="string"&&typeof b=="string"&&typeof d!="string")return this.setSyncInfo(a,b,

define("CouchDBUser",["CouchDBStore","Promise"],function(k,j){function f(){var h="_users",f="org.couchdb.user:";this.getUserDB=function(){return h};this.setUserDB=function(b){return b?(h=b,true):false};this.getIdPrefix=function(){return f};this.setIdPrefix=function(b){return b?(f=b,true):false};this.setId=function(b){return b?(this.set("_id",f+b),true):false};this.getId=function(){return this.get("_id")};this.load=function(b){return this.sync(h,f+b)};this.login=function(){var b=new j,a=this.get("name"),
f=this.get("password");a&&typeof a=="string"&&typeof f=="string"?this.getTransport().request("CouchDB",{method:"GET",path:"/_users/org.couchdb.user:"+a,auth:a+":"+f},b.resolve,b):b.reject({error:"name & password must be strings"});return b};this.create=function(){var b=new j;this.get("type")||this.set("type","user");this.get("roles")||this.set("roles",[]);this.load(this.get("name")).then(function(){b.reject({error:"Failed to create user. The user already exists"})},function(){this.upload().then(function(a){b.resolve(a)},
f=this.get("password");a&&typeof a=="string"&&typeof f=="string"?this.getTransport().request("CouchDB",{method:"GET",path:"/_users/org.couchdb.user:"+a,auth:a+":"+f},b.fulfill,b):b.reject({error:"name & password must be strings"});return b};this.create=function(){var b=new j;this.get("type")||this.set("type","user");this.get("roles")||this.set("roles",[]);this.load(this.get("name")).then(function(){b.reject({error:"Failed to create user. The user already exists"})},function(){this.upload().then(function(a){b.fulfill(a)},
function(a){b.reject(a)})},this);return b}}return function(){f.prototype=new k;return new f}});

@@ -9,9 +9,22 @@ /**

* The MIT License (MIT)
* Copyright (c) 2012 Olivier Scherrer <pode.fr@gmail.com>
* Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com>
*/
define("CouchDBSecurity",
["CouchDBStore"],
define("CouchDBBase",
["Store", "StateMachine", "Tools", "Promise"],
function CouchDBBase() {
});
/**
* https://github.com/flams/CouchDB-emily-tools
* The MIT License (MIT)
* Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com>
*/
define("CouchDBSecurity",
["CouchDBStore"],
/**
* @class

@@ -21,3 +34,3 @@ * CouchDBSecurity synchronises a CouchDBStore with _security document

function CouchDBSecurity(CouchDBStore) {
/**

@@ -28,3 +41,3 @@ * Defines CouchDBSecurity

function CouchDBSecurityConstructor() {
/**

@@ -35,3 +48,3 @@ * the name of the _security document

var _name = "_security";
/**

@@ -50,3 +63,3 @@ * Set the name of the _security document

};
/**

@@ -59,3 +72,3 @@ * Get the name of the _Security document

};
/**

@@ -68,6 +81,6 @@ * Load the security document

};
};
return function CouchDBSecurityFactory() {

@@ -77,9 +90,10 @@ CouchDBSecurityConstructor.prototype = new CouchDBStore;

};
});/**
});
/**
* https://github.com/flams/CouchDB-emily-tools
* The MIT License (MIT)
* Copyright (c) 2012 Olivier Scherrer <pode.fr@gmail.com>
* Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com>
*/

@@ -157,3 +171,3 @@

this.reset(json.rows);
_syncPromise.resolve(this);
_syncPromise.fulfill(this);
if (typeof json.total_rows == "undefined") {

@@ -182,3 +196,3 @@ this.setReducedViewInfo(true);

this.reset(json);
_syncPromise.resolve(this);
_syncPromise.fulfill(this);
_stateMachine.event("subscribeToDocumentChanges");

@@ -230,3 +244,3 @@ } else {

this.reset(json.rows);
_syncPromise.resolve(this);
_syncPromise.fulfill(this);
_stateMachine.event("subscribeToBulkChanges");

@@ -253,3 +267,3 @@ }

if (json.ok) {
promise.resolve(json);
promise.fulfill(json);
_stateMachine.event("subscribeToDocumentChanges");

@@ -271,3 +285,2 @@ } else {

heartbeat: 20000,
limit: 0,
descending: true

@@ -296,3 +309,3 @@ }, _syncInfo.query);

action = "delete";
} else if (json.changes[0].rev.search("1-") == 0) {
} else if (json.changes && json.changes[0].rev.search("1-") == 0) {
action = "add";

@@ -319,3 +332,2 @@ } else {

heartbeat: 20000,
limit: 0,
descending: true

@@ -356,3 +368,2 @@ }

heartbeat: 20000,
limit: 0,
descending: true,

@@ -585,3 +596,3 @@ include_docs: true

this.set("_rev", json.rev);
promise.resolve(json);
promise.fulfill(json);
} else {

@@ -612,3 +623,3 @@ promise.reject(json);

}, function (response) {
promise.resolve(JSON.parse(response));
promise.fulfill(JSON.parse(response));
});

@@ -857,8 +868,8 @@ },

* The MIT License (MIT)
* Copyright (c) 2012 Olivier Scherrer <pode.fr@gmail.com>
* Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com>
*/
define("CouchDBUser",
["CouchDBStore", "Promise"],
define("CouchDBUser",
["CouchDBStore", "Promise"],
/**

@@ -870,3 +881,3 @@ * @class

function CouchDBUser(CouchDBStore, Promise) {
/**

@@ -877,3 +888,3 @@ * Defines CouchDBUser

function CouchDBUserConstructor() {
/**

@@ -884,9 +895,9 @@ * the name of the table in which users are saved

var _userDB = "_users",
/**
* the string which prefixes a user's id
* the string which prefixes a user's id
* @private
*/
_idPrefix = "org.couchdb.user:";
/**

@@ -899,3 +910,3 @@ * Get the name of the users' db

};
/**

@@ -914,3 +925,3 @@ * Set the name of the users' db

};
/**

@@ -923,3 +934,3 @@ * Get the string that prefixes the users' id

};
/**

@@ -938,3 +949,3 @@ * Set the string that prefixes the users' id

};
/**

@@ -953,3 +964,3 @@ * Set user's id

};
/**

@@ -962,3 +973,3 @@ * Get the user's id

};
/**

@@ -972,3 +983,3 @@ * Load a user given it's id

};
/**

@@ -984,3 +995,3 @@ * Gets the user profile in couchDB by using its own credentials.

* type: 'user' }
*
*
* @returns {Promise}

@@ -992,3 +1003,3 @@ */

password = this.get("password");
if (name && typeof name == "string" && typeof password == "string") {

@@ -999,4 +1010,4 @@ this.getTransport().request("CouchDB", {

auth: name + ":" + password
},
promise.resolve,
},
promise.fulfill,
promise);

@@ -1008,6 +1019,6 @@ } else {

}
return promise;
};
/**

@@ -1037,3 +1048,3 @@ * Adds a user to the database

}
this.load(this.get("name")).then(function () {

@@ -1043,3 +1054,3 @@ promise.reject({error: "Failed to create user. The user already exists"});

this.upload().then(function (success) {
promise.resolve(success);
promise.fulfill(success);
}, function (error) {

@@ -1049,7 +1060,7 @@ promise.reject(error);

}, this);
return promise;
};
};
return function CouchDBUserFactory() {

@@ -1059,5 +1070,5 @@ CouchDBUserConstructor.prototype = new CouchDBStore;

};
});
});
{
"name": "couchdb-emily-tools",
"description": "CouchDB Tools for Emily&Olives applications",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/flams/CouchDB-emily-tools",

@@ -18,3 +18,4 @@ "licenses": [{

"requirejs": ">=2.0.4",
"emily": ">=1.2.0"
"emily": ">=1.3.1",
"cookies": ">=0.3.6"
},

@@ -30,5 +31,5 @@ "keywords": ["CouchDB", "Emily", "Olives", "Tools"],

"main":"tools.js",
"engines": {
"engines": {
"node":">= 0.8.0"
},
},
"scripts": {

@@ -35,0 +36,0 @@ "test": "jake tests:node"

/**
* @license https://github.com/flams/CouchDB-emily-tools
* The MIT License (MIT)
* Copyright (c) 2012 Olivier Scherrer <pode.fr@gmail.com>
* Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com>
*/
var requirejs = require("requirejs"),
emily = require("emily");
http = require("http"),
qs = require("querystring"),
cookie = require("cookie");
requirejs(__dirname + "/build/CouchDBTools.js");
module.exports.requirejs = requirejs;
var configuration = {
hostname: "localhost",
port: 5984
},
handler = function (data, onEnd, onData) {
var req;
data.hostname = configuration.hostname;
data.port = configuration.port;
data.path += "?" + qs.stringify(data.query);
var exec = function () {
req = http.request(data, function (res) {
var body = "";
res.on("data", function (chunk) {
onData && onData(chunk);
body += chunk;
});
res.on("end", function () {
onEnd(body);
});
});
req.end(data.data, "utf8");
};
if (data.handshake) {
var cookieJSON = cookie.parse(data.handshake.headers.cookie);
// I don't like the split but is there a better solution?
configuration.sessionStore.get(cookieJSON["suggestions.sid"].split("s:")[1].split(".")[0], function (err, session) {
if (err) {
throw new Error(err);
} else {
data.auth = session.auth;
exec();
}
});
} else {
exec();
}
return function () {
req.abort && req.abort();
};
};
exports.requirejs = requirejs;
exports.handler = handler;
exports.configuration = configuration;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc