Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bump of node,couch client,logger versions. I have no idea what's in t…

…his commit
  • Loading branch information...
commit 6e8a09158a8c3616cb2d1235a0d0150a4d60e7c7 1 parent ac59789
@DelvarWorld authored
View
4 core/lib/cache.js
@@ -111,7 +111,7 @@ exports.getList = function(viewName, viewData, parentKey, cb) {
queryParams.include_docs = true;
}
- this.couch.view('master', viewName, queryParams, function(err, result) {
+ this.couch.view('master/' + viewName, queryParams, function(err, result) {
if(err) {
return cb(new Error('Error querying couch view `' + viewName + ':`' + err.error + ', ' + err.reason));
} else if(!result.rows.length) {
@@ -139,7 +139,7 @@ exports.getList = function(viewName, viewData, parentKey, cb) {
};
cache.getDocsByKey = function(keys, cb) {
- this.couch.getDocsByKey(keys, function(err, result) {
+ this.couch.get(keys, function(err, result) {
if(err) {
return cb(err);
}
View
23 core/lib/templater.js
@@ -1,6 +1,6 @@
var templater = module.exports,
log = require('simple-logger'),
- sys = require('sys'),
+ sys = require('util'),
fs = require('fs'),
path = require('path'),
transients = require('../transients'),
@@ -14,7 +14,7 @@ var templater = module.exports,
themesDirectory = '../../user/themes/',
coreTemplateDir = '../static/';
-log.log_level = 'info';
+log.level = 'info';
// Function code available on front end and back end
exports.transientFunctions = '';
@@ -163,12 +163,12 @@ exports.addNamespacedTransientFunction = function(namespace, name, reference) {
exports.getInstructions = function(plip) {
var conclusion = {
raw: plip
- };
+ }, parts, fields, dotSplit;
if(!plip.indexOf('listItem:')) {
// listItem:field_on_parent:child_id:index
- var fields = plip.split(':');
+ fields = plip.split(':');
conclusion.listItem = true;
conclusion.parentField = fields[1];
@@ -177,7 +177,7 @@ exports.getInstructions = function(plip) {
} else {
// Example: "plip:global.html@info". the actual plip is just "info"
if(!plip.indexOf('plip:')) {
- var parts = plip.match(/:(.+?)@(.+?)$/);
+ parts = plip.match(/:(.+?)@(.+?)$/);
conclusion.doc_id = parts[1];
conclusion.isPlip = true;
@@ -190,14 +190,14 @@ exports.getInstructions = function(plip) {
}
} else if(!plip.indexOf('list:')) {
conclusion.widget = 'list';
- var parts = plip.match(/:(.+?)@(.+?)$/);
+ parts = plip.match(/:(.+?)@(.+?)$/);
plip = parts[2];
conclusion.doc_id = parts[1];
}
- var fields = plip.split(':'),
- dotSplit = fields[0].split('.');
+ fields = plip.split(':');
+ dotSplit = fields[0].split('.');
// The key of the document
conclusion.field = fields[0];
@@ -322,7 +322,8 @@ exports.getViewName = function(instructions) {
templater.createViews = function(views, cb) {
var total = views.length,
- processed = x = 0,
+ processed = 0,
+ x = 0,
view, plip;
if(!total) {
@@ -343,7 +344,7 @@ templater.createViews = function(views, cb) {
};
exports.createViewIfNull = function(instructions, cb) {
- templater.couch.getDesign('master', function(err, doc) {
+ templater.couch.get('_design/master', function(err, doc) {
if(err) {
return cb(new Error('There was a fatal error, master design not found!', err));
}
@@ -396,7 +397,7 @@ exports.createViewIfNull = function(instructions, cb) {
}
}
- templater.couch.saveDesign('master', doc, function(err) {
+ templater.couch.save('_design/master', doc, function(err) {
// If we have a document update conflict on saving a map function then
// most likely another template raced to create it. TODO: This could
// be an issue for multiple lists modifying the design document at once!
View
6 core/lib/utils.js
@@ -1,4 +1,4 @@
-var sys = require('sys'),
+var sys = require('util'),
log = require('simple-logger'),
path = require('path'),
fs = require('fs'),
@@ -46,7 +46,7 @@ exports.generateTitle = function(str) {
};
exports.getOrCreate = function(couch, path, template, cb) {
- couch.getDoc(path, function(err, firstres) {
+ couch.get(path, function(err, firstres) {
if(err) {
// This thing is not yet in the database. Let's put it there!
var d = new Date(),
@@ -171,7 +171,7 @@ exports.bulkDocs = function(couch, docs, cb) {
docs.forEach(function(doc) {
doc.modified = d;
});
- couch.bulkDocs({docs: docs}, cb);
+ couch.save(docs, cb);
};
exports.authSession = function(req) {
View
18 core/permissions.js
@@ -1,4 +1,4 @@
-var sys = require('sys'),
+var sys = require('util'),
log = require('simple-logger'),
fs = require('fs'),
templater = require('./lib/templater'),
@@ -21,7 +21,7 @@ module.exports = [{
},
getField: function(req, res, pageData, urlData, couch) {
- couch.getDoc(req.body.id, function(err, doc) {
+ couch.get(req.body.id, function(err, doc) {
if(err) {
log.error('Error getting main doc from couch: ',err);
res.send({status:'failure', message:err});
@@ -48,7 +48,7 @@ module.exports = [{
return;
}
// Get the document the list is on for context
- couch.getDoc(doc_id, function(err, doc) {
+ couch.get(doc_id, function(err, doc) {
if(err) {
log.error('Error getting main doc from couch: ',err);
res.send({status:'failure', message:err});
@@ -63,7 +63,7 @@ module.exports = [{
fakeData[childId] = {
variables: {title: 'title'},
locals: {}
- }
+ };
// TODO: Please abstract this because we basically duplicate it in templater
var listTemplateView = instructions.listBody + user.role,
@@ -100,7 +100,7 @@ module.exports = [{
}
// Get the stub item in the list to update its title field
- couch.getDoc(item_instr.doc_id, function(err, docToAdd) {
+ couch.get(item_instr.doc_id, function(err, docToAdd) {
if(err) {
return res.send({status:'failure', message:err.message});
}
@@ -136,7 +136,7 @@ module.exports = [{
beginUpdate(pageData, urlData);
// If this list is in an embedded oject on the page, like an include or a sub list
} else {
- couch.getDoc(list_instr.doc_id, function(err, correctPageData) {
+ couch.get(list_instr.doc_id, function(err, correctPageData) {
if(err) {
res.send({status:'failure', message:err.message});
return;
@@ -151,7 +151,7 @@ module.exports = [{
if(urlData._id == home) {
beginUpdate(correctPageData, urlData);
} else {
- couch.getDoc(home, function(err, homepageUrlData) {
+ couch.get(home, function(err, homepageUrlData) {
if(err) {
return res.send({status:'failure', message:err.message});
}
@@ -177,7 +177,7 @@ module.exports = [{
update: function(req, res, pageData, urlData, couch) {
var instructions = req.body.instructions;
- couch.getDoc(instructions.doc_id, function(err, doc) {
+ couch.get(instructions.doc_id, function(err, doc) {
doc[instructions.field] = req.body.value;
@@ -192,7 +192,7 @@ module.exports = [{
updateList: function(req, res, pageData, urlData, couch) {
var parts = req.body.field.split(':');
- couch.getDoc(parts[0], function(err, doc) {
+ couch.get(parts[0], function(err, doc) {
doc[parts[1]] = req.body.value;
utils.saveDoc(couch, doc._id, doc, function(err, dbres) {
if(err) {
View
97 core/server.js
@@ -1,5 +1,5 @@
var http = require('http'),
- sys = require('sys'),
+ sys = require('util'),
fs = require('fs'),
path = require('path'),
log = require('simple-logger'),
@@ -9,17 +9,17 @@ var http = require('http'),
cache = require('./lib/cache'),
flower = require('./lib/flower'),
express_lib = require('express'),
+ cradle = require('cradle'),
server = module.exports;
exports.createServer = function(options, cb) {
- log.log_level = 'info';
+ log.level = 'info';
// Set up express and couch and defaults
var express = express_lib.createServer(),
// TODO: If couch isn't running we just get a top level exception thrown on first access atempt. Would be nice to
// tell user to start couch.
- couch_client = require('node-couchdb').createClient(5984, 'localhost'),
- couch = couch_client.db(options.db_name || 'rayframe'),
+ couch = new(cradle.Connection)().database(options.db_name || 'rayframe'),
theme = options.theme || 'ray-frame',
core_static = 'core/static/',
user_static = 'user/themes/' + theme + '/static/';
@@ -61,7 +61,7 @@ exports.createServer = function(options, cb) {
// This is the handler for any web page. There are URL objects in the database that we look up. So basically every
// URL on the site has its own URL object which contains the id to the model object, and a parent chain of other
// URL objects so we can say, build a breadcrumb trail
- couch.view('master', 'url', {key: dbPath}, function(err, result) {
+ couch.view('master/url', {key: dbPath}, function(err, result) {
if(err) {
log.error('Error fetching URL view `'+dbPath+'`: ',err);
res.writeHead(500, {'Content-Type': 'text/html'});
@@ -115,18 +115,18 @@ exports.createServer = function(options, cb) {
templater.autoRevalidate();
// Set up our transient functions (functions that can run server and client side, right now for core live in transient.js);
- var t = './transients.js';
+ var t = './transients.js', x;
path.exists(t, function(ya) {
if(ya) {
var transients = require(t);
- for(var x in transients) {
- templater.addTransientFunction(x, transients[x]);
+ for(var trans in transients) {
+ templater.addTransientFunction(trans, transients[x]);
}
}
templater.addNamespace('utils');
// Also copy over all the utility functions to be transients
- for(var x in utils) {
- templater.addNamespacedTransientFunction('utils', x, utils[x]);
+ for(var thing in utils) {
+ templater.addNamespacedTransientFunction('utils', thing, utils[thing]);
}
server.setUpAccess(express);
@@ -134,6 +134,10 @@ exports.createServer = function(options, cb) {
express.listen(options.server_port || 8080);
log.info('Server running on '+(options.server_port || 8080)+'!');
+ fs.watch('core', function(event, filename) {
+ log.warn(filename + ' changed!');
+ });
+
if(cb) {
cb(null, server);
}
@@ -144,7 +148,7 @@ exports.createServer = function(options, cb) {
if(options.hard_reset) {
server.resetDatabase(couch, function(err) {
if(err) {
- return log.error('Fatal error encounted while trying to reset database: ',err);
+ return log.error('Fatal error encounted while trying to reset database: ', err);
}
prepareForGoTime();
});
@@ -161,11 +165,13 @@ exports.resetDatabase = function(couch, callback) {
if(err) {
log.error('There was a fatal error creating the database! ',err);
return callback(err);
- } else {
- log.info('Recreated database `'+couch.name+'`');
+ }
+ log.info('Recreated database `'+couch.name+'`');
- // Create a view in a design doc TODO: Is there a way to multi these two calls?
- couch.saveDesign('master', {
+ // Create our homepage object and url object for it. Bulkdocs takes _id
+ utils.bulkDocs(couch, [
+ {
+ _id: '_design/master',
views: {
// Not currently needed, but this is the syntax for a view save
'url':{
@@ -176,42 +182,39 @@ exports.resetDatabase = function(couch, callback) {
}
}
}
- }, function(err) {
- // Create our homepage object and url object for it. Bulkdocs takes _id
- utils.bulkDocs(couch, [
- // TEST DATA
-
- // root is special case. Let couch name other keys for page objects
- {_id:'root', template:'index.html', title:'hello', welcome_msg: 'Velokmen!', url: utils.sanitizeUrl('/'),
- parents: [], blogs: ['ab2', 'ab3', 'ab1'], ponies: {balls: {'ducks': 'in the pond', 'quack': 'my quack'}}},
- {_id:'test.html', template:'test.html', title:'hello', welcome_msg: 'Test says Velokmen!', test_msg: 'Test message!',
- parents: [], pages: ['moo', 'abcdeft'], blogs: ['ab2', 'ab3', 'ab1']},
-
- //{_id:'header.html', template:'header.html'},
- //{_id:'global.html', template:'global.html', info: 'stuff'}, // another by convention
-
- // CRAP DATA
- {_id:'abcdeft', template:'blog.html', title: 'blog post title!', parent_id: 'root', url: utils.sanitizeUrl('/blogpost'), body: 'threenis'},
- {_id:'moo', template:'blog.html', title: 'I should be the first in the array', parent_id: 'root', url: utils.sanitizeUrl('/blogpost2')},
-
- //{_id:'ab1', template:'blog.html', title: 'other blog 1 (last)', parent_id: 'root', url: utils.sanitizeUrl('/blogposta')},
- //{_id:'ab2', template:'blog.html', title: 'other blog 2 (first)', parent_id: 'root', url: utils.sanitizeUrl('/blogpostb')},
- //{_id:'ab3', template:'blog.html', title: 'other blog 3 (midle)', parent_id: 'root', url: utils.sanitizeUrl('/blogpostc')},
-
- // TODO: This should be a core template, overwritable (there currently are no core templates)
- {_id:'login', template:'login.html', title: 'Log in', url: utils.sanitizeUrl('/login')}
- ], function(err) {
- log.info('Database reset complete. The homepage (index.html) has been automatically added.');
- callback(err);
- });
- });
- }
+ },
+ // TEST DATA
+
+ // root is special case. Let couch name other keys for page objects
+ {_id:'root', template:'index.html', title:'hello', welcome_msg: 'Velokmen!', url: utils.sanitizeUrl('/'),
+ parents: [], blogs: ['ab2', 'ab3', 'ab1'], ponies: {balls: {'ducks': 'in the pond', 'quack': 'my quack'}}},
+ {_id:'test.html', template:'test.html', title:'hello', welcome_msg: 'Test says Velokmen!', test_msg: 'Test message!',
+ parents: [], pages: ['moo', 'abcdeft'], blogs: ['ab2', 'ab3', 'ab1']},
+
+ //{_id:'header.html', template:'header.html'},
+ //{_id:'global.html', template:'global.html', info: 'stuff'}, // another by convention
+
+ // CRAP DATA
+ {_id:'abcdeft', template:'blog.html', title: 'blog post title!', parent_id: 'root', url: utils.sanitizeUrl('/blogpost'), body: 'threenis'},
+ {_id:'moo', template:'blog.html', title: 'I should be the first in the array', parent_id: 'root', url: utils.sanitizeUrl('/blogpost2')},
+
+ //{_id:'ab1', template:'blog.html', title: 'other blog 1 (last)', parent_id: 'root', url: utils.sanitizeUrl('/blogposta')},
+ //{_id:'ab2', template:'blog.html', title: 'other blog 2 (first)', parent_id: 'root', url: utils.sanitizeUrl('/blogpostb')},
+ //{_id:'ab3', template:'blog.html', title: 'other blog 3 (midle)', parent_id: 'root', url: utils.sanitizeUrl('/blogpostc')},
+
+ // TODO: This should be a core template, overwritable (there currently are no core templates)
+ {_id:'login', template:'login.html', title: 'Log in', url: utils.sanitizeUrl('/login')}
+ ], function(err) {
+ !err && log.info('Database reset complete. The homepage (index.html) has been automatically added.');
+ callback(err);
+ });
});
+ return true;
}
if(exists) {
log.info('Existing database found, deleting for development');
- couch.remove(recreate);
+ couch.destroy(recreate);
} else {
recreate();
}
@@ -226,7 +229,7 @@ exports.createPost = function(express, role, prefix, name, functionCall) {
utils.authSession(req);
if(utils.isAllowed(permissions, role, req.session.user.role)) {
- server.couch.getDocsByKey([req.body.current_id, req.body.current_url_id], function(err, result) {
+ server.couch.get([req.body.current_id, req.body.current_url_id], function(err, result) {
functionCall(req, res, result.rows[0].doc, result.rows[1].doc, server.couch);
});
}
View
4 core/test/suites/server_tests.js
@@ -8,7 +8,7 @@ module.exports = testutils.testCase({
assert.expect(2);
// Get the homepage to force generation of includesheader.html
testutils.requestURL(self, assert, {}, {url:'/'}, function(server, response) {
- var couch_client = require('../../../../node-couchdb/index.js').createClient(5984, 'localhost'),
+ var couch_client = require('felix-couchdb').createClient(5984, 'localhost'),
couch = couch_client.db('rayframe-test');
// First save two pages to the homepage
@@ -38,7 +38,7 @@ module.exports = testutils.testCase({
assert.expect(3);
// Get the homepage to force generation of includesheader.html
testutils.requestURL(self, assert, {}, {url:'/'}, function(server, response) {
- var couch_client = require('../../../../node-couchdb/index.js').createClient(5984, 'localhost'),
+ var couch_client = require('felix-couchdb').createClient(5984, 'localhost'),
couch = couch_client.db('rayframe-test');
couch.getDocsByKey(['root', 'url:~'], function(err, result) {
View
2  core/test/utils.js
@@ -1,6 +1,6 @@
var log = require('simple-logger'),
http = require('http'),
- sys = require('sys'),
+ sys = require('util'),
nodeunit = require('nodeunit'),
querystring = require('querystring'),
server = require('../server');
View
8 package.json
@@ -18,8 +18,8 @@
"connect": ">=1.4.1",
"connect-auth": ">=0.2.2",
"nodeunit": ">=0.5.1",
- "simple-logger": ">=0.0.2",
- "uglify-js": ">=1.1.1"
- },
- "bundledDependencies": ["node-couchdb"]
+ "simple-logger": ">=1.0.1",
+ "uglify-js": ">=1.1.1",
+ "cradle": ">=0.6.3"
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.