mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-04-28 17:35:50 +08:00
Fixed most lint errors
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
node_modules
|
||||
lib/util/uuid.js
|
||||
clib/socket.io.js
|
||||
clib/socket.io.min.js
|
||||
|
||||
test-app/node_modules/request
|
||||
test-app/public/mocha.js
|
||||
test-app/public/jquery.js
|
||||
@@ -6,4 +10,7 @@ test-app/public/chai.js
|
||||
|
||||
lib/resources/dashboard/js/lib
|
||||
lib/resources/collection/dashboard/js/lib
|
||||
lib/resources/dashboard/bootstrap
|
||||
lib/resources/dashboard/bootstrap
|
||||
|
||||
# TODO: We don't really want to ignore this, but the minified socket.io in the beginning throws it off so we need to find another way
|
||||
clib/dpd.js
|
||||
@@ -1,3 +1,7 @@
|
||||
{
|
||||
"laxcomma": true
|
||||
"laxcomma": true,
|
||||
"expr": true,
|
||||
"proto": true,
|
||||
"lastsemic": true,
|
||||
"laxbreak": true
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -21,7 +21,7 @@ function Deployment(appPath, user, subdomain) {
|
||||
if(~key.indexOf(remote)) {
|
||||
subdomain = config[key].subdomain;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
this.name = this.sanitize(subdomain || path.basename(this.path));
|
||||
@@ -43,7 +43,7 @@ Deployment.prototype.sanitize = function (name) {
|
||||
name = name.trim().toLowerCase();
|
||||
name = name.replace(/ +/g, '-');
|
||||
name = name.replace(/\.+/g, '-');
|
||||
name = name.replace(/[^0-9a-z-]/g, '');
|
||||
name = name.replace(/[^0-9a-z\-]/g, '');
|
||||
|
||||
if(name.length === 0) error();
|
||||
if(name === '-') error();
|
||||
@@ -56,7 +56,7 @@ Deployment.prototype.sanitize = function (name) {
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Deployment.prototype.package = function (tarball, callback) {
|
||||
function filter(info) {
|
||||
@@ -79,7 +79,7 @@ Deployment.prototype.package = function (tarball, callback) {
|
||||
.on('error', callback)
|
||||
.pipe(fstream.Writer({ type: "File", path: tarball }))
|
||||
.on('close', callback);
|
||||
}
|
||||
};
|
||||
|
||||
Deployment.prototype.publish = function (url, tar, key, callback) {
|
||||
function done(err, res, body) {
|
||||
@@ -100,8 +100,8 @@ Deployment.prototype.publish = function (url, tar, key, callback) {
|
||||
'X-App-User': this.user,
|
||||
'X-App-Subdomain': this.subdomain
|
||||
}
|
||||
}, done))
|
||||
}
|
||||
}, done));
|
||||
};
|
||||
|
||||
Deployment.prototype.getConfig = function(key) {
|
||||
var cur;
|
||||
@@ -113,7 +113,7 @@ Deployment.prototype.getConfig = function(key) {
|
||||
}
|
||||
|
||||
return key ? cur[key] : cur;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Deployment.prototype.setConfig = function(key, val) {
|
||||
@@ -122,4 +122,4 @@ Deployment.prototype.setConfig = function(key, val) {
|
||||
cur[key] = val;
|
||||
|
||||
fs.writeFileSync(this.path + '/.dpd/deployments.json', JSON.stringify(cur));
|
||||
}
|
||||
};
|
||||
@@ -3,42 +3,42 @@
|
||||
*/
|
||||
|
||||
var http = require('http')
|
||||
, util = require('util')
|
||||
, request = require('request')
|
||||
, Keys = require('../keys')
|
||||
, debug = require('debug')('remote')
|
||||
, httpProxy = require('http-proxy')
|
||||
, url = require('url');
|
||||
, util = require('util')
|
||||
, request = require('request')
|
||||
, Keys = require('../keys')
|
||||
, debug = require('debug')('remote')
|
||||
, httpProxy = require('http-proxy')
|
||||
, url = require('url');
|
||||
|
||||
/*!
|
||||
* Create a remote and host it at the given port.
|
||||
*/
|
||||
|
||||
exports.createRemote = function(remote, port) {
|
||||
debug('proxying to %s', remote);
|
||||
debug('proxying to %s', remote);
|
||||
|
||||
if(remote.substr(0,7) !== 'http://') remote = 'http://' + remote;
|
||||
if(remote.substr(0,7) !== 'http://') remote = 'http://' + remote;
|
||||
|
||||
var remoteUrl = url.parse(remote);
|
||||
var keys = new Keys();
|
||||
var remoteUrl = url.parse(remote);
|
||||
var keys = new Keys();
|
||||
var server = httpProxy.createServer(function(req, res, proxy) {
|
||||
var buffer = httpProxy.buffer(req);
|
||||
var buffer = httpProxy.buffer(req);
|
||||
|
||||
debug('[%s] %s', req.method, req.url);
|
||||
keys.getLocal(function(err, key) {
|
||||
debug('key [%s]', key);
|
||||
if(err) return res.end('error reading .dpd/keys.json: ' + err.message);
|
||||
req.headers['dpd-ssh-key'] = key;
|
||||
req.headers.host = remoteUrl.hostname;
|
||||
proxy.proxyRequest(req, res, {
|
||||
host: remoteUrl.hostname,
|
||||
port: remoteUrl.port || 80,
|
||||
buffer: buffer
|
||||
});
|
||||
});
|
||||
});
|
||||
server.listen(port || 2403);
|
||||
server.on('listening', function() {
|
||||
console.log('remote dashboard is available at http://localhost:%s/dashboard', port || 2403)
|
||||
})
|
||||
debug('[%s] %s', req.method, req.url);
|
||||
keys.getLocal(function(err, key) {
|
||||
debug('key [%s]', key);
|
||||
if(err) return res.end('error reading .dpd/keys.json: ' + err.message);
|
||||
req.headers['dpd-ssh-key'] = key;
|
||||
req.headers.host = remoteUrl.hostname;
|
||||
proxy.proxyRequest(req, res, {
|
||||
host: remoteUrl.hostname,
|
||||
port: remoteUrl.port || 80,
|
||||
buffer: buffer
|
||||
});
|
||||
});
|
||||
});
|
||||
server.listen(port || 2403);
|
||||
server.on('listening', function() {
|
||||
console.log('remote dashboard is available at http://localhost:%s/dashboard', port || 2403);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -12,15 +12,16 @@ var server;
|
||||
module.exports = function (dpd) {
|
||||
console.log('type help for a list of commands');
|
||||
var repl = require("repl")
|
||||
, context = repl.start("dpd > ", null, replEval, true, true).context
|
||||
, context = repl.start("dpd > ", null, replEval, true, true).context;
|
||||
server = dpd;
|
||||
|
||||
context.dpd = buildReplClient(dpd);
|
||||
|
||||
return commands;
|
||||
}
|
||||
};
|
||||
|
||||
function replEval(src, ctx, name, fn) {
|
||||
/*jshint evil:true*/
|
||||
var result;
|
||||
|
||||
// first try to match a command
|
||||
@@ -57,7 +58,7 @@ var commands = {
|
||||
resources: function () {
|
||||
server.resources && server.resources.forEach(function (r) {
|
||||
if(r.settings.type) console.log('\t' + r.settings.path, '(' + r.settings.type + ')');
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
dashboard: function () {
|
||||
@@ -67,7 +68,7 @@ var commands = {
|
||||
open: function () {
|
||||
open();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function open(url) {
|
||||
url = url || '';
|
||||
@@ -78,7 +79,7 @@ var help = {
|
||||
dashboard: 'open the resource editor in a browser',
|
||||
dpd: 'the server object',
|
||||
resources: 'list your resources'
|
||||
}
|
||||
};
|
||||
|
||||
function tryCommand(cmd) {
|
||||
console.info(cmd);
|
||||
@@ -94,20 +95,21 @@ function buildReplClient(dpd) {
|
||||
Object.keys(client[key]).forEach(function(k) {
|
||||
var orig = client[key][k];
|
||||
client[key][k] = function () {
|
||||
if(typeof arguments[arguments.length - 1] != 'function') {
|
||||
arguments[arguments.length] = function (res, err) {
|
||||
var args = Array.protoype.slice.call(arguments);
|
||||
if(typeof args[args.length - 1] !== 'function') {
|
||||
args[args.length] = function(res, err) {
|
||||
if(err) {
|
||||
console.log('Error', err);
|
||||
} else {
|
||||
console.log(res);
|
||||
}
|
||||
}
|
||||
arguments.length++;
|
||||
};
|
||||
args.length++;
|
||||
}
|
||||
orig.apply(client[key], arguments);
|
||||
}
|
||||
orig.apply(client[key], args);
|
||||
};
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
@@ -51,11 +51,11 @@ module.exports.loadConfig = function(basepath, server, fn) {
|
||||
|
||||
debug('done, adding internals');
|
||||
|
||||
var clientLib = new ClientLib('dpd.js', { config: { resources: resources }, server: server})
|
||||
var clientLib = new ClientLib('dpd.js', { config: { resources: resources }, server: server});
|
||||
|
||||
clientLib.load(function(err) {
|
||||
if (err) return fn(err);
|
||||
resources.push(new Files('', { config: { public: './public' }, server: server }));
|
||||
resources.push(new Files('', { config: { 'public': './public' }, server: server }));
|
||||
resources.push(clientLib);
|
||||
resources.push(new InternalResources('__resources', {config: {configPath: basepath}, server: server}));
|
||||
resources.push(new Dashboard('dashboard', {server: server}));
|
||||
|
||||
@@ -35,7 +35,7 @@ function Context(resource, req, res, server) {
|
||||
var done = this.done;
|
||||
this.done = function() {
|
||||
done.apply(ctx, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
if ((this.query && typeof this.query.$limitRecursion !== 'undefined') || (this.body && typeof this.body.$limitRecursion !== 'undefined')) {
|
||||
var recursionLimit = this.query.$limitRecursion || this.body.$limitRecursion || 0;
|
||||
@@ -110,6 +110,6 @@ Context.prototype.done = function(err, res) {
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Context;
|
||||
12
lib/db.js
12
lib/db.js
@@ -32,7 +32,7 @@ db.connect = function (options, fn) {
|
||||
var db = new Db(options);
|
||||
db.open(fn);
|
||||
return db;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A `Db` abstracts a driver implementation of the database. This allows for
|
||||
@@ -86,7 +86,7 @@ Db.prototype.open = function (fn) {
|
||||
debug('opened connection');
|
||||
self.emit('connected');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Drop the underlying database.
|
||||
@@ -97,7 +97,7 @@ Db.prototype.open = function (fn) {
|
||||
|
||||
Db.prototype.drop = function (fn) {
|
||||
this._mdb.dropDatabase(fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new database store (eg. a collection).
|
||||
@@ -115,7 +115,7 @@ Db.prototype.drop = function (fn) {
|
||||
|
||||
Db.prototype.createStore = function (namespace) {
|
||||
return new Store(namespace, this);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a space in the database (eg. a collection).
|
||||
@@ -151,7 +151,7 @@ function collection(store, fn) {
|
||||
} else {
|
||||
execute();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Change public IDs to private IDs.
|
||||
@@ -390,7 +390,7 @@ Store.prototype.update = function (query, object, fn) {
|
||||
command.$set = object;
|
||||
}
|
||||
|
||||
var multi = query._id ? false : true;
|
||||
multi = query._id ? false : true;
|
||||
|
||||
debug('update - query', query);
|
||||
debug('update - object', object);
|
||||
|
||||
@@ -51,7 +51,7 @@ function joinPath() {
|
||||
return normalizePath(paths.filter(function(p, index) {
|
||||
return p && typeof p === 'string';
|
||||
}).join('/'));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ exports.build = function(server, session, stack) {
|
||||
|
||||
baseMethods.get = function(options, fn) {
|
||||
return baseMethods.request("GET", options, fn);
|
||||
}
|
||||
};
|
||||
|
||||
baseMethods.post = function(options, fn) {
|
||||
return baseMethods.request("POST", options, fn);
|
||||
|
||||
64
lib/keys.js
64
lib/keys.js
@@ -1,12 +1,12 @@
|
||||
var fs = require('fs')
|
||||
, crypto = require('crypto');
|
||||
, crypto = require('crypto');
|
||||
|
||||
/*!
|
||||
* A collection of keys backed by a file.
|
||||
*/
|
||||
|
||||
function Keys(path) {
|
||||
this.path = path || '.dpd/keys.json';
|
||||
this.path = path || '.dpd/keys.json';
|
||||
}
|
||||
module.exports = Keys;
|
||||
|
||||
@@ -16,42 +16,42 @@ module.exports = Keys;
|
||||
|
||||
Keys.prototype.get = function(key, fn) {
|
||||
this.readFile(function(err, data) {
|
||||
fn(err, data[key]);
|
||||
fn(err, data[key]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Generate a key using cryptographically strong pseudo-random data.
|
||||
*/
|
||||
|
||||
Keys.prototype.generate = function() {
|
||||
return crypto.randomBytes(256).toString('hex');
|
||||
}
|
||||
return crypto.randomBytes(256).toString('hex');
|
||||
};
|
||||
|
||||
/*!
|
||||
* Create a new key and save it in the keys file.
|
||||
*/
|
||||
|
||||
Keys.prototype.create = function(fn) {
|
||||
var key = this.generate()
|
||||
, keys = this;
|
||||
var key = this.generate()
|
||||
, keys = this;
|
||||
|
||||
this.readFile(function(err, data) {
|
||||
if(err) return fn(err);
|
||||
this.readFile(function(err, data) {
|
||||
if(err) return fn(err);
|
||||
|
||||
data[key] = true;
|
||||
keys.writeFile(data, function(err) {
|
||||
fn(err, key);
|
||||
});
|
||||
data[key] = true;
|
||||
keys.writeFile(data, function(err) {
|
||||
fn(err, key);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Read the contents of the key file as JSON
|
||||
*/
|
||||
|
||||
Keys.prototype.readFile = function(fn) {
|
||||
fs.readFile(this.path, 'utf-8', function(err, data) {
|
||||
fs.readFile(this.path, 'utf-8', function(err, data) {
|
||||
var jsonData
|
||||
, error;
|
||||
|
||||
@@ -63,7 +63,7 @@ Keys.prototype.readFile = function(fn) {
|
||||
|
||||
fn(error, jsonData);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
@@ -71,16 +71,16 @@ Keys.prototype.readFile = function(fn) {
|
||||
*/
|
||||
|
||||
Keys.prototype.writeFile = function(data, fn) {
|
||||
var str;
|
||||
var str;
|
||||
|
||||
try {
|
||||
str = JSON.stringify(data)
|
||||
} catch(e) {
|
||||
return fn(r);
|
||||
}
|
||||
try {
|
||||
str = JSON.stringify(data);
|
||||
} catch(e) {
|
||||
return fn(r);
|
||||
}
|
||||
|
||||
fs.writeFile(this.path, str, fn);
|
||||
}
|
||||
fs.writeFile(this.path, str, fn);
|
||||
};
|
||||
|
||||
/*
|
||||
* Get the first local key
|
||||
@@ -89,11 +89,11 @@ Keys.prototype.writeFile = function(data, fn) {
|
||||
|
||||
Keys.prototype.getLocal = function(fn) {
|
||||
this.readFile(function(err, data) {
|
||||
if(err) return fn(err);
|
||||
if(data && typeof data == 'object') {
|
||||
fn(null, Object.keys(data)[0]);
|
||||
} else {
|
||||
fn()
|
||||
}
|
||||
if(err) return fn(err);
|
||||
if(data && typeof data == 'object') {
|
||||
fn(null, Object.keys(data)[0]);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -24,7 +24,7 @@ ClientLib.prototype.handle = function (ctx, next) {
|
||||
ctx.res.setHeader('Content-Type', 'text/javascript');
|
||||
var lib = resource.clientLib;
|
||||
|
||||
var host = ctx.req.headers['host'];
|
||||
var host = ctx.req.headers.host;
|
||||
if (lib) lib = lib.replace('var root = window.location.origin;', 'var root = "http://' + host + '";');
|
||||
|
||||
ctx.res.write(lib);
|
||||
@@ -34,7 +34,7 @@ ClientLib.prototype.handle = function (ctx, next) {
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ClientLib.prototype.generate = function(res, fn) {
|
||||
var clientLib = this;
|
||||
@@ -47,19 +47,20 @@ ClientLib.prototype.generate = function(res, fn) {
|
||||
};
|
||||
|
||||
ClientLib.prototype.generateResource = function(r, res) {
|
||||
var jsName = r.path.replace(/[^A-Za-z0-9]/g, '');
|
||||
var jsName = r.path.replace(/[^A-Za-z0-9]/g, '')
|
||||
, i;
|
||||
|
||||
if (r.clientGeneration && jsName) {
|
||||
res.write('dpd.' + jsName + ' = dpd("' + r.path + '");\n')
|
||||
res.write('dpd.' + jsName + ' = dpd("' + r.path + '");\n');
|
||||
if (r.clientGenerationExec) {
|
||||
for (var i = 0; i < r.clientGenerationExec.length; i++) {
|
||||
for (i = 0; i < r.clientGenerationExec.length; i++) {
|
||||
res.write('dpd.' + jsName + '.' + r.clientGenerationExec[i] + ' = function(path, body, fn) {\n');
|
||||
res.write(' return dpd.' + jsName + '.exec("' + r.clientGenerationExec[i] + '", path, body, fn);\n');
|
||||
res.write('}\n');
|
||||
}
|
||||
}
|
||||
if (r.clientGenerationGet) {
|
||||
for (var i = 0; i < r.clientGenerationGet.length; i++) {
|
||||
for (i = 0; i < r.clientGenerationGet.length; i++) {
|
||||
res.write('dpd.' + jsName + '.' + r.clientGenerationGet[i] + ' = function(path, query, fn) {\n');
|
||||
res.write(' return dpd.' + jsName + '.get("' + r.clientGenerationGet[i] + '", path, query, fn);\n');
|
||||
res.write('}\n');
|
||||
@@ -76,7 +77,7 @@ ClientLib.prototype.generateResource = function(r, res) {
|
||||
res.write('dpd.' + jsName + '.' + name + ' = function (path, body, fn) {\n');
|
||||
res.write(' dpd.exec("' + name + '", path, body, fn);\n');
|
||||
res.write('}\n');
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
res.write('\n');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
var apiTemplate = _.template($('#api-template').html());
|
||||
|
||||
dpd('__resources').get(Context.resourceId, function(res, err) {
|
||||
/*jshint boss:true */
|
||||
$('#api').show().html(apiTemplate({
|
||||
resourceData: res
|
||||
, ns: function(path) {
|
||||
|
||||
@@ -24,15 +24,15 @@ var createRow = function(data, props, vm) {
|
||||
self.c_errors = ko.observable({});
|
||||
|
||||
self.c_formatted = function(name, type) {
|
||||
var name = ko.utils.unwrapObservable(name);
|
||||
var type = ko.utils.unwrapObservable(type);
|
||||
name = ko.utils.unwrapObservable(name);
|
||||
type = ko.utils.unwrapObservable(type);
|
||||
var value = ko.utils.unwrapObservable(self[name]);
|
||||
if (type === 'password' || typeof value === 'undefined') {
|
||||
return '...';
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.c_toggleEditing = function() {
|
||||
if (self.c_editing() && !self.isNew) {
|
||||
@@ -92,7 +92,7 @@ var create = function() {
|
||||
return ko.utils.unwrapObservable(data.id);
|
||||
}
|
||||
, create: function(options) {
|
||||
return createRow(options.data, ko.mapping.toJS(self.properties), self)
|
||||
return createRow(options.data, ko.mapping.toJS(self.properties), self);
|
||||
}
|
||||
, update: function(options) {
|
||||
if (!options.target.c_editing()) {
|
||||
|
||||
@@ -23,7 +23,7 @@ ko.bindingHandlers.sortable = {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var propertyMapping = {
|
||||
include: ['required', 'id', '$renameFrom']
|
||||
@@ -82,7 +82,7 @@ function createPropertyViewModel(data, contextToAdd) {
|
||||
self.editingName = ko.observable(self.name()).extend({variableName: true});
|
||||
self.nameFocus = ko.observable();
|
||||
|
||||
self.isNew = contextToAdd != null;
|
||||
self.isNew = contextToAdd !== null;
|
||||
|
||||
self.tooltipEvent = new ui.Emitter();
|
||||
|
||||
@@ -141,7 +141,7 @@ function createPropertyViewModel(data, contextToAdd) {
|
||||
data = {
|
||||
id: data
|
||||
, label: data
|
||||
}
|
||||
};
|
||||
}
|
||||
self.type(ko.utils.unwrapObservable(data.id));
|
||||
self.typeLabel(ko.utils.unwrapObservable(data.label));
|
||||
@@ -291,7 +291,7 @@ function create() {
|
||||
} else {
|
||||
vm.otherItems(false);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function subscribe() {
|
||||
if (subscribed) return;
|
||||
|
||||
@@ -11,7 +11,7 @@ window.CollectionUtil = (function() {
|
||||
});
|
||||
|
||||
return propertiesArray;
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ Collection.dashboard = {
|
||||
, '/js/lib/knockout-util.js'
|
||||
, '/js/util.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate the request `body` against the `Collection` `properties`
|
||||
@@ -89,7 +89,7 @@ Collection.prototype.validate = function (body, create) {
|
||||
});
|
||||
|
||||
if(Object.keys(errors).length) return errors;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sanitize the request `body` against the `Collection` `properties`
|
||||
@@ -126,7 +126,7 @@ Collection.prototype.sanitize = function (body) {
|
||||
});
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
};
|
||||
|
||||
Collection.prototype.sanitizeQuery = function (query) {
|
||||
var sanitized = {}
|
||||
@@ -153,7 +153,7 @@ Collection.prototype.sanitizeQuery = function (query) {
|
||||
});
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle an incoming http `req` and `res` and execute
|
||||
@@ -177,6 +177,7 @@ Collection.prototype.handle = function (ctx) {
|
||||
ctx.done("must provide id to update an object");
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case 'POST':
|
||||
this.save(ctx, ctx.done);
|
||||
break;
|
||||
@@ -184,7 +185,7 @@ Collection.prototype.handle = function (ctx) {
|
||||
this.remove(ctx, ctx.done);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@@ -196,7 +197,7 @@ Collection.prototype.handle = function (ctx) {
|
||||
|
||||
Collection.prototype.parseId = function(ctx) {
|
||||
if(ctx.url && ctx.url !== '/') return ctx.url.split('/')[1];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find all the objects in a collection that match the given
|
||||
@@ -222,7 +223,7 @@ Collection.prototype.find = function (ctx, fn) {
|
||||
err = err || {
|
||||
message: 'not found',
|
||||
statusCode: 404
|
||||
}
|
||||
};
|
||||
debug('could not find object by id %s', query.id);
|
||||
}
|
||||
if(err) {
|
||||
@@ -263,7 +264,7 @@ Collection.prototype.find = function (ctx, fn) {
|
||||
delete data[property];
|
||||
}
|
||||
},
|
||||
this: data,
|
||||
'this': data,
|
||||
data: data
|
||||
};
|
||||
|
||||
@@ -297,7 +298,7 @@ Collection.prototype.find = function (ctx, fn) {
|
||||
delete data[property];
|
||||
}
|
||||
},
|
||||
this: data,
|
||||
'this': data,
|
||||
data: data
|
||||
};
|
||||
|
||||
@@ -308,7 +309,7 @@ Collection.prototype.find = function (ctx, fn) {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute a `delete` event script, if one exists, using each object found.
|
||||
@@ -346,13 +347,13 @@ Collection.prototype.remove = function (ctx, fn) {
|
||||
}
|
||||
};
|
||||
|
||||
domain.this = domain.data = result;
|
||||
domain['this'] = domain.data = result;
|
||||
collection.events.Delete.run(ctx, domain, done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the onPost or onPut listener. If it succeeds,
|
||||
@@ -381,7 +382,7 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
if(k[0] == '$') {
|
||||
commands[key] = item[key];
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -415,7 +416,7 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
delete item[property];
|
||||
}
|
||||
},
|
||||
this: item,
|
||||
'this': item,
|
||||
data: item
|
||||
};
|
||||
|
||||
@@ -465,7 +466,7 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
done(null, item);
|
||||
|
||||
if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
if (collection.events.Validate) {
|
||||
@@ -495,7 +496,7 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
debug('inserting item', item);
|
||||
store.insert(item, done);
|
||||
if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');
|
||||
})
|
||||
});
|
||||
} else {
|
||||
store.insert(item, done);
|
||||
if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');
|
||||
@@ -512,14 +513,14 @@ Collection.prototype.save = function (ctx, fn) {
|
||||
} else {
|
||||
post();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Collection.defaultPath = '/my-objects';
|
||||
|
||||
Collection.prototype.configDeleted = function(config, fn) {
|
||||
debug('resource deleted');
|
||||
return this.store.remove(fn);
|
||||
}
|
||||
};
|
||||
|
||||
Collection.prototype.configChanged = function(config, fn) {
|
||||
var store = this.store;
|
||||
@@ -537,7 +538,7 @@ Collection.prototype.configChanged = function(config, fn) {
|
||||
}
|
||||
|
||||
fn(null);
|
||||
}
|
||||
};
|
||||
|
||||
Collection.external.rename = function (options, ctx, fn) {
|
||||
if(!ctx.req && !ctx.req.isRoot) return fn(new Error('cannot rename multiple'));
|
||||
@@ -545,7 +546,7 @@ Collection.external.rename = function (options, ctx, fn) {
|
||||
if(options.properties) {
|
||||
this.store.update({}, {$rename: options.properties}, fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Collection.prototype.execCommands = function (type, obj, commands) {
|
||||
try {
|
||||
@@ -595,14 +596,14 @@ Collection.prototype.execCommands = function (type, obj, commands) {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
} catch(e) {
|
||||
debug('error while executing commands', type, obj, commands);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Collection;
|
||||
@@ -47,7 +47,7 @@ Dashboard.prototype.render = function(ctx, options) {
|
||||
} catch (ex) {
|
||||
ctx.res.end(ex.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (options.pagePath) {
|
||||
fs.readFile(options.pagePath, 'utf-8', function(err, file) {
|
||||
@@ -84,7 +84,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
|
||||
if (resource) {
|
||||
|
||||
function renderResource(extras) {
|
||||
var renderResource = function(extras) {
|
||||
var options = {
|
||||
resourceId: resourceId
|
||||
, resourceType: resourceType.name
|
||||
@@ -101,9 +101,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
}
|
||||
|
||||
render(ctx, options);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
resourceType = resource.constructor;
|
||||
|
||||
@@ -129,7 +127,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
pagePath = path.join(resourceType.dashboard.path, page + '.html')
|
||||
pagePath = path.join(resourceType.dashboard.path, page + '.html');
|
||||
|
||||
var checkFilesAndRender = function() {
|
||||
fs.stat(path.join(resourceType.dashboard.path, 'js', page + '.js'), function(err, stat) {
|
||||
@@ -145,7 +143,7 @@ Dashboard.prototype.route = function(ctx) {
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (page === 'events') {
|
||||
return fs.stat(pagePath, function(err, stat) {
|
||||
@@ -227,7 +225,7 @@ Dashboard.prototype.serve = function(ctx, next) {
|
||||
// , reqUrl = parts.slice(2).join('/');
|
||||
|
||||
// filed(path.join(dashboardPath, reqUrl)).pipe(ctx.res);
|
||||
}
|
||||
};
|
||||
|
||||
Dashboard.prototype.auth = function(ctx) {
|
||||
filed(path.join(__dirname, 'dashboard', 'auth.html')).pipe(ctx.res);
|
||||
@@ -256,4 +254,4 @@ Dashboard.prototype.handle = function(ctx, next) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
@@ -39,7 +39,7 @@ function getValue($input) {
|
||||
if ($input.attr('type') === 'checkbox') {
|
||||
val = $input.is(':checked');
|
||||
} else if ($input.attr('type') === 'number') {
|
||||
val = parseInt(val);
|
||||
val = parseInt(val, 10);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ function trackUpdate(name, editor) {
|
||||
function update(showError) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
delete timeout;
|
||||
timeout = undefined;
|
||||
}
|
||||
try {
|
||||
var newSettings = JSON.parse(editor.getSession().getValue());
|
||||
|
||||
@@ -89,7 +89,7 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
function update(name, editor) {
|
||||
var update = { value: editor.getSession().getValue() }
|
||||
var put = { value: editor.getSession().getValue() }
|
||||
, fileName = name.toLowerCase() + '.js';
|
||||
|
||||
if (timeouts[name]) {
|
||||
@@ -97,7 +97,7 @@ $(document).ready(function() {
|
||||
delete timeouts[name];
|
||||
}
|
||||
|
||||
dpd('__resources').put(Context.resourceId + '/' + fileName, update, function(res, err) {
|
||||
dpd('__resources').put(Context.resourceId + '/' + fileName, put, function(res, err) {
|
||||
if (err) { return ui.error("Error saving event", err.message).effect('slide'); }
|
||||
if (!$('#notifications li').length) ui.notify("Saved").hide(1000).effect('slide');
|
||||
});
|
||||
|
||||
@@ -20,8 +20,8 @@ var validation = require('validation')
|
||||
|
||||
function Files(name, options) {
|
||||
Resource.apply(this, arguments);
|
||||
if(this.config.public) {
|
||||
this.public = this.config.public;
|
||||
if(this.config['public']) {
|
||||
this['public'] = this.config['public'];
|
||||
} else {
|
||||
throw new Error('public root folder location required when creating a file resource');
|
||||
}
|
||||
@@ -32,8 +32,8 @@ Files.prototype.handle = function (ctx, next) {
|
||||
if(ctx.req && ctx.req.method !== 'GET') return next();
|
||||
|
||||
send(ctx.req, url.parse(ctx.url).pathname)
|
||||
.root(path.resolve(this.public))
|
||||
.root(path.resolve(this['public']))
|
||||
.pipe(ctx.res);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Files;
|
||||
@@ -81,7 +81,7 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
};
|
||||
});
|
||||
ctx.done(null, defaults);
|
||||
})
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
fs.writeFile(file, value, function(err) {
|
||||
if (err) return ctx.done(err);
|
||||
|
||||
if (fileName.lastIndexOf('config.json') === fileName.length - ('config.json').length
|
||||
&& newId && newId !== id) {
|
||||
if (fileName.lastIndexOf('config.json') === fileName.length - ('config.json').length &&
|
||||
newId && newId !== id) {
|
||||
//rename
|
||||
if (newId.indexOf('/') === 0) newId = newId.substring(1);
|
||||
fs.rename(path.join(basepath, 'resources', id), path.join(basepath, 'resources', newId), function(err) {
|
||||
@@ -176,8 +176,8 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
break;
|
||||
case 'GET':
|
||||
if(id) {
|
||||
var isJson;
|
||||
var file = id;
|
||||
isJson = undefined;
|
||||
file = id;
|
||||
if (id.lastIndexOf('.') <= id.lastIndexOf('/')) {
|
||||
file += '/config.json';
|
||||
}
|
||||
@@ -213,7 +213,7 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
if (remaining <= 0) {
|
||||
resources = resources.sort(function(a, b) {
|
||||
var sort = a.__ctime - b.__ctime;
|
||||
if (sort == 0) {
|
||||
if (sort === 0) {
|
||||
sort = a.id.localeCompare(b.id);
|
||||
}
|
||||
return sort;
|
||||
@@ -267,7 +267,7 @@ InternalResources.prototype.handle = function(ctx, next) {
|
||||
default:
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function notifyType(id, event, config, server, fn) {
|
||||
if(server) {
|
||||
|
||||
@@ -84,8 +84,7 @@ UserCollection.prototype.handle = function (ctx) {
|
||||
case 'POST':
|
||||
if(ctx.url === '/login') {
|
||||
var path = this.path
|
||||
, credentials = ctx.req.body
|
||||
, uc = this;
|
||||
, credentials = ctx.req.body;
|
||||
|
||||
debug('trying to login as %s', credentials.username);
|
||||
|
||||
@@ -108,6 +107,7 @@ UserCollection.prototype.handle = function (ctx) {
|
||||
});
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case 'PUT':
|
||||
if(ctx.body && ctx.body.password) {
|
||||
var salt = uuid.create(SALT_LEN);
|
||||
@@ -124,7 +124,7 @@ UserCollection.prototype.handle = function (ctx) {
|
||||
this.store.first({username: ctx.body.username}, function (err, u) {
|
||||
if(u) return ctx.done({errors: {username: 'is already in use'}});
|
||||
uc.save(ctx, done);
|
||||
})
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'DELETE':
|
||||
@@ -132,7 +132,7 @@ UserCollection.prototype.handle = function (ctx) {
|
||||
this.remove(ctx, ctx.done);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UserCollection.prototype.handleSession = function (ctx, fn) {
|
||||
// called when any session has been created
|
||||
@@ -147,11 +147,11 @@ UserCollection.prototype.handleSession = function (ctx, fn) {
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UserCollection.prototype.hash = function (password, salt) {
|
||||
return crypto.createHmac('sha256', salt).update(password).digest('hex');
|
||||
}
|
||||
};
|
||||
|
||||
UserCollection.label = 'Users Collection';
|
||||
UserCollection.defaultPath = '/users';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var db = require('./db')
|
||||
, Context = require('./context')
|
||||
, escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g
|
||||
, escapeRegExp = /[\-\[\]{}()+?.,\\\^$|#\s]/g
|
||||
, debug = require('debug')('router');
|
||||
|
||||
/**
|
||||
@@ -46,8 +46,8 @@ Router.prototype.route = function (req, res) {
|
||||
globals++;
|
||||
return function() {
|
||||
globals--;
|
||||
if(!globals) { nextResource() }
|
||||
}
|
||||
if(!globals) { nextResource(); }
|
||||
};
|
||||
}
|
||||
|
||||
// global hooks
|
||||
@@ -132,7 +132,7 @@ Router.prototype.matchResources = function(url) {
|
||||
return specificness(b) - specificness(a);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a regular expression from a base path.
|
||||
@@ -144,9 +144,9 @@ Router.prototype.matchResources = function(url) {
|
||||
|
||||
Router.prototype.generateRegex = function(path) {
|
||||
if (!path || path === '/') path = '';
|
||||
path = path.replace(escapeRegExp, '\\$&')
|
||||
path = path.replace(escapeRegExp, '\\$&');
|
||||
return new RegExp('^' + path + '(?:[/?].*)?$');
|
||||
}
|
||||
};
|
||||
|
||||
function specificness(resource) {
|
||||
var path = resource.path;
|
||||
|
||||
@@ -165,9 +165,9 @@ function wrapAsyncFunctions(asyncFunctions, sandbox, events, done, sandboxRoot)
|
||||
callback.apply(sandboxRoot._this, arguments);
|
||||
events.emit('finishCallback');
|
||||
} catch (err) {
|
||||
err = wrapError(err);
|
||||
sandbox._error = err;
|
||||
return done(err);
|
||||
var wrappedErr = wrapError(err);
|
||||
sandbox._error = wrappedErr;
|
||||
return done(wrappedErr);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -179,9 +179,9 @@ function wrapAsyncFunctions(asyncFunctions, sandbox, events, done, sandboxRoot)
|
||||
try {
|
||||
asyncFunctions[k].apply(sandboxRoot._this, args);
|
||||
} catch(err) {
|
||||
err = wrapError(err);
|
||||
sandbox._error = err;
|
||||
return done(err);
|
||||
var wrappedErr = wrapError(err);
|
||||
sandbox._error = wrappedErr;
|
||||
return done(wrappedErr);
|
||||
}
|
||||
};
|
||||
} else if (typeof asyncFunctions[k] === 'object') {
|
||||
|
||||
@@ -96,7 +96,7 @@ function Server(options) {
|
||||
req.cookies.set('sid', session.sid);
|
||||
req.session = session;
|
||||
|
||||
function route() {
|
||||
var route = function() {
|
||||
config.loadConfig('./', server, function(err, resourcesInstances) {
|
||||
if (err) {
|
||||
res.statusCode = 500;
|
||||
@@ -109,7 +109,7 @@ function Server(options) {
|
||||
server.resources = resourcesInstances;
|
||||
router.route(req, res);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var root = req.headers['dpd-ssh-key'] || req.cookies.get('DpdSshKey');
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ function SessionStore(namespace, db, sockets) {
|
||||
socketIndex[sid] = socket;
|
||||
socketQueue.emit(sid, socket);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Store.apply(this, arguments);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ function Session(data, store, sockets, rawSockets) {
|
||||
}
|
||||
},
|
||||
_socket: sockets[this.sid]
|
||||
}
|
||||
};
|
||||
|
||||
this.emitToUsers = function(collection, query, event, data) {
|
||||
collection.get(query, function(users) {
|
||||
@@ -154,12 +154,12 @@ function Session(data, store, sockets, rawSockets) {
|
||||
userSession.socket.emit(event, data);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.emitToAll = function() {
|
||||
rawSockets.emit.apply(rawSockets, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
// resolve queue once a socket is ready
|
||||
store.socketQueue.once(this.sid, function (socket) {
|
||||
@@ -168,15 +168,15 @@ function Session(data, store, sockets, rawSockets) {
|
||||
if(socketWrapper._bindQueue && socketWrapper._bindQueue.length) {
|
||||
socketWrapper._bindQueue.forEach(function (args) {
|
||||
socket.on.apply(socket, args);
|
||||
})
|
||||
});
|
||||
}
|
||||
// drain emit queue
|
||||
if(socketWrapper._emitQueue && socketWrapper._emitQueue.length) {
|
||||
socketWrapper._emitQueue.forEach(function (args) {
|
||||
socket.emit.apply(socket, args);
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,4 +44,4 @@ module.exports = function loadTypes(basepath, fn) {
|
||||
fn(defaults, types);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
var Cookies = require('cookies')
|
||||
, qs = require('querystring')
|
||||
, qs = require('querystring')
|
||||
, parseUrl = require('url').parse;
|
||||
|
||||
/*!
|
||||
@@ -8,9 +8,9 @@ var Cookies = require('cookies')
|
||||
|
||||
exports.setup = function(req, res, next) {
|
||||
var mime = req.headers['content-type'] || '';
|
||||
mime = mime.split(';')[0]; //Just in case there's multiple mime types, pick the first
|
||||
mime = mime.split(';')[0]; //Just in case there's multiple mime types, pick the first
|
||||
|
||||
req.cookies = res.cookies = new Cookies(req, res);
|
||||
req.cookies = res.cookies = new Cookies(req, res);
|
||||
|
||||
if(~req.url.indexOf('?')) {
|
||||
try {
|
||||
@@ -21,16 +21,15 @@ exports.setup = function(req, res, next) {
|
||||
res.end('Failed to parse querystring: ' + ex);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(autoParse[mime]) {
|
||||
autoParse[mime](req, res, mime, next);
|
||||
autoParse[mime](req, res, mime, next);
|
||||
} else {
|
||||
req.pause();
|
||||
next();
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Attempts to parse the stream. Currently supports the following formats:
|
||||
@@ -46,7 +45,7 @@ exports.setup = function(req, res, next) {
|
||||
var parseBody = exports.parseBody = function(req, res, mime, callback) {
|
||||
var buf = '';
|
||||
|
||||
req.on('data', function(chunk){ buf += chunk });
|
||||
req.on('data', function(chunk){ buf += chunk; });
|
||||
req.on('end', function(){
|
||||
var parser = JSON;
|
||||
|
||||
@@ -55,7 +54,7 @@ var parseBody = exports.parseBody = function(req, res, mime, callback) {
|
||||
}
|
||||
|
||||
try {
|
||||
req.body = parser.parse(buf)
|
||||
req.body = parser.parse(buf);
|
||||
callback();
|
||||
} catch (ex) {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
@@ -63,19 +62,19 @@ var parseBody = exports.parseBody = function(req, res, mime, callback) {
|
||||
res.end('Failed to parse body as ' + mime);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var parseQuery = exports.parseQuery = function(url) {
|
||||
var q = url.substr(url.indexOf('?') + 1);
|
||||
var q = url.substr(url.indexOf('?') + 1);
|
||||
|
||||
if(q) q = decodeURI(q);
|
||||
|
||||
if(q[0] === '{' && q[q.length - 1] === '}') {
|
||||
return JSON.parse(q);
|
||||
} else {
|
||||
return qs.parse(parseUrl(url).query);
|
||||
}
|
||||
}
|
||||
if(q[0] === '{' && q[q.length - 1] === '}') {
|
||||
return JSON.parse(q);
|
||||
} else {
|
||||
return qs.parse(parseUrl(url).query);
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Redirects to the given url.
|
||||
|
||||
@@ -53,4 +53,4 @@ exports.restart = function (mongod, env, port, fn) {
|
||||
|
||||
process.on('exit', kill);
|
||||
process.on('uncaughtException', kill);
|
||||
}
|
||||
};
|
||||
@@ -12,4 +12,4 @@ module.exports = function(url) {
|
||||
command += ' ' + url;
|
||||
debug(command);
|
||||
sh.exec(command, {async: true});
|
||||
}
|
||||
};
|
||||
2
test-app/node_modules/hello.js
generated
vendored
2
test-app/node_modules/hello.js
generated
vendored
@@ -11,4 +11,4 @@ Hello.prototype.handle = function (ctx, next) {
|
||||
if(ctx.req && ctx.req.method !== 'GET') return next();
|
||||
|
||||
ctx.done(null, {hello: 'world'});
|
||||
}
|
||||
};
|
||||
4
test-app/node_modules/proxy/index.js
generated
vendored
4
test-app/node_modules/proxy/index.js
generated
vendored
@@ -17,7 +17,7 @@ Proxy.prototype.handle = function (ctx, next) {
|
||||
if(ctx.req && ctx.req.method !== 'GET') return next();
|
||||
var remote = this.remote;
|
||||
request.get(remote + ctx.url).pipe(ctx.res);
|
||||
}
|
||||
};
|
||||
|
||||
Proxy.label = 'HTTP Proxy';
|
||||
Proxy.defaultPath = '/proxy';
|
||||
@@ -28,4 +28,4 @@ Proxy.basicDashboard = {
|
||||
, type: "text" //"textarea", "number", and "checkbox" work as well
|
||||
, description: "The remote server to proxy to."
|
||||
}]
|
||||
}
|
||||
};
|
||||
@@ -1,374 +0,0 @@
|
||||
// JSDeferred 0.4.0 Copyright (c) 2007 cho45 ( www.lowreal.net )
|
||||
// See http://github.com/cho45/jsdeferred
|
||||
function Deferred () { return (this instanceof Deferred) ? this.init() : new Deferred() }
|
||||
Deferred.ok = function (x) { return x };
|
||||
Deferred.ng = function (x) { throw x };
|
||||
Deferred.prototype = {
|
||||
|
||||
_id : 0xe38286e381ae,
|
||||
|
||||
|
||||
init : function () {
|
||||
this._next = null;
|
||||
this.callback = {
|
||||
ok: Deferred.ok,
|
||||
ng: Deferred.ng
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
next : function (fun) { return this._post("ok", fun) },
|
||||
|
||||
|
||||
error : function (fun) { return this._post("ng", fun) },
|
||||
|
||||
|
||||
call : function (val) { return this._fire("ok", val) },
|
||||
|
||||
|
||||
fail : function (err) { return this._fire("ng", err) },
|
||||
|
||||
|
||||
cancel : function () {
|
||||
(this.canceller || function () {})();
|
||||
return this.init();
|
||||
},
|
||||
|
||||
_post : function (okng, fun) {
|
||||
this._next = new Deferred();
|
||||
this._next.callback[okng] = fun;
|
||||
return this._next;
|
||||
},
|
||||
|
||||
_fire : function (okng, value) {
|
||||
var next = "ok";
|
||||
try {
|
||||
value = this.callback[okng].call(this, value);
|
||||
} catch (e) {
|
||||
next = "ng";
|
||||
value = e;
|
||||
if (Deferred.onerror) Deferred.onerror(e);
|
||||
}
|
||||
if (Deferred.isDeferred(value)) {
|
||||
value._next = this._next;
|
||||
} else {
|
||||
if (this._next) this._next._fire(next, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
};
|
||||
Deferred.isDeferred = function (obj) {
|
||||
return !!(obj && obj._id === Deferred.prototype._id);
|
||||
};
|
||||
|
||||
Deferred.next_default = function (fun) {
|
||||
var d = new Deferred();
|
||||
var id = setTimeout(function () { d.call() }, 0);
|
||||
d.canceller = function () { clearTimeout(id) };
|
||||
if (fun) d.callback.ok = fun;
|
||||
return d;
|
||||
};
|
||||
Deferred.next_faster_way_readystatechange = ((typeof window === 'object') && (location.protocol == "http:") && !window.opera && /\bMSIE\b/.test(navigator.userAgent)) && function (fun) {
|
||||
var d = new Deferred();
|
||||
var t = new Date().getTime();
|
||||
if (t - arguments.callee._prev_timeout_called < 150) {
|
||||
var cancel = false;
|
||||
var script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = "data:text/javascript,";
|
||||
script.onreadystatechange = function () {
|
||||
if (!cancel) {
|
||||
d.canceller();
|
||||
d.call();
|
||||
}
|
||||
};
|
||||
d.canceller = function () {
|
||||
if (!cancel) {
|
||||
cancel = true;
|
||||
script.onreadystatechange = null;
|
||||
document.body.removeChild(script);
|
||||
}
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
} else {
|
||||
arguments.callee._prev_timeout_called = t;
|
||||
var id = setTimeout(function () { d.call() }, 0);
|
||||
d.canceller = function () { clearTimeout(id) };
|
||||
}
|
||||
if (fun) d.callback.ok = fun;
|
||||
return d;
|
||||
};
|
||||
Deferred.next_faster_way_Image = ((typeof window === 'object') && (typeof(Image) != "undefined") && !window.opera && document.addEventListener) && function (fun) {
|
||||
var d = new Deferred();
|
||||
var img = new Image();
|
||||
var handler = function () {
|
||||
d.canceller();
|
||||
d.call();
|
||||
};
|
||||
img.addEventListener("load", handler, false);
|
||||
img.addEventListener("error", handler, false);
|
||||
d.canceller = function () {
|
||||
img.removeEventListener("load", handler, false);
|
||||
img.removeEventListener("error", handler, false);
|
||||
};
|
||||
img.src = "data:image/png," + Math.random();
|
||||
if (fun) d.callback.ok = fun;
|
||||
return d;
|
||||
};
|
||||
Deferred.next_tick = (typeof process === 'object' && typeof process.nextTick === 'function') && function (fun) {
|
||||
var d = new Deferred();
|
||||
process.nextTick(function() { d.call() });
|
||||
if (fun) d.callback.ok = fun;
|
||||
return d;
|
||||
};
|
||||
Deferred.next =
|
||||
Deferred.next_faster_way_readystatechange ||
|
||||
Deferred.next_faster_way_Image ||
|
||||
Deferred.next_tick ||
|
||||
Deferred.next_default;
|
||||
|
||||
Deferred.chain = function () {
|
||||
var chain = Deferred.next();
|
||||
for (var i = 0, len = arguments.length; i < len; i++) (function (obj) {
|
||||
switch (typeof obj) {
|
||||
case "function":
|
||||
var name = null;
|
||||
try {
|
||||
name = obj.toString().match(/^\s*function\s+([^\s()]+)/)[1];
|
||||
} catch (e) { }
|
||||
if (name != "error") {
|
||||
chain = chain.next(obj);
|
||||
} else {
|
||||
chain = chain.error(obj);
|
||||
}
|
||||
break;
|
||||
case "object":
|
||||
chain = chain.next(function() { return Deferred.parallel(obj) });
|
||||
break;
|
||||
default:
|
||||
throw "unknown type in process chains";
|
||||
}
|
||||
})(arguments[i]);
|
||||
return chain;
|
||||
};
|
||||
|
||||
Deferred.wait = function (n) {
|
||||
var d = new Deferred(), t = new Date();
|
||||
var id = setTimeout(function () {
|
||||
d.call((new Date()).getTime() - t.getTime());
|
||||
}, n * 1000);
|
||||
d.canceller = function () { clearTimeout(id) };
|
||||
return d;
|
||||
};
|
||||
|
||||
Deferred.call = function (fun) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
return Deferred.next(function () {
|
||||
return fun.apply(this, args);
|
||||
});
|
||||
};
|
||||
|
||||
Deferred.parallel = function (dl) {
|
||||
var isArray = false;
|
||||
if (arguments.length > 1) {
|
||||
dl = Array.prototype.slice.call(arguments);
|
||||
isArray = true;
|
||||
} else if (Array.isArray && Array.isArray(dl) || typeof dl.length == "number") {
|
||||
isArray = true;
|
||||
}
|
||||
var ret = new Deferred(), values = {}, num = 0;
|
||||
for (var i in dl) if (dl.hasOwnProperty(i)) (function (d, i) {
|
||||
if (typeof d == "function") dl[i] = d = Deferred.next(d);
|
||||
d.next(function (v) {
|
||||
values[i] = v;
|
||||
if (--num <= 0) {
|
||||
if (isArray) {
|
||||
values.length = dl.length;
|
||||
values = Array.prototype.slice.call(values, 0);
|
||||
}
|
||||
ret.call(values);
|
||||
}
|
||||
}).error(function (e) {
|
||||
ret.fail(e);
|
||||
});
|
||||
num++;
|
||||
})(dl[i], i);
|
||||
|
||||
if (!num) Deferred.next(function () { ret.call() });
|
||||
ret.canceller = function () {
|
||||
for (var i in dl) if (dl.hasOwnProperty(i)) {
|
||||
dl[i].cancel();
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
};
|
||||
|
||||
Deferred.earlier = function (dl) {
|
||||
var isArray = false;
|
||||
if (arguments.length > 1) {
|
||||
dl = Array.prototype.slice.call(arguments);
|
||||
isArray = true;
|
||||
} else if (Array.isArray && Array.isArray(dl) || typeof dl.length == "number") {
|
||||
isArray = true;
|
||||
}
|
||||
var ret = new Deferred(), values = {}, num = 0;
|
||||
for (var i in dl) if (dl.hasOwnProperty(i)) (function (d, i) {
|
||||
d.next(function (v) {
|
||||
values[i] = v;
|
||||
if (isArray) {
|
||||
values.length = dl.length;
|
||||
values = Array.prototype.slice.call(values, 0);
|
||||
}
|
||||
ret.call(values);
|
||||
ret.canceller();
|
||||
}).error(function (e) {
|
||||
ret.fail(e);
|
||||
});
|
||||
num++;
|
||||
})(dl[i], i);
|
||||
|
||||
if (!num) Deferred.next(function () { ret.call() });
|
||||
ret.canceller = function () {
|
||||
for (var i in dl) if (dl.hasOwnProperty(i)) {
|
||||
dl[i].cancel();
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
Deferred.loop = function (n, fun) {
|
||||
var o = {
|
||||
begin : n.begin || 0,
|
||||
end : (typeof n.end == "number") ? n.end : n - 1,
|
||||
step : n.step || 1,
|
||||
last : false,
|
||||
prev : null
|
||||
};
|
||||
var ret, step = o.step;
|
||||
return Deferred.next(function () {
|
||||
function _loop (i) {
|
||||
if (i <= o.end) {
|
||||
if ((i + step) > o.end) {
|
||||
o.last = true;
|
||||
o.step = o.end - i + 1;
|
||||
}
|
||||
o.prev = ret;
|
||||
ret = fun.call(this, i, o);
|
||||
if (Deferred.isDeferred(ret)) {
|
||||
return ret.next(function (r) {
|
||||
ret = r;
|
||||
return Deferred.call(_loop, i + step);
|
||||
});
|
||||
} else {
|
||||
return Deferred.call(_loop, i + step);
|
||||
}
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return (o.begin <= o.end) ? Deferred.call(_loop, o.begin) : null;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Deferred.repeat = function (n, fun) {
|
||||
var i = 0, end = {}, ret = null;
|
||||
return Deferred.next(function () {
|
||||
var t = (new Date()).getTime();
|
||||
do {
|
||||
if (i >= n) return null;
|
||||
ret = fun(i++);
|
||||
} while ((new Date()).getTime() - t < 20);
|
||||
return Deferred.call(arguments.callee);
|
||||
});
|
||||
};
|
||||
|
||||
Deferred.register = function (name, fun) {
|
||||
this.prototype[name] = function () {
|
||||
var a = arguments;
|
||||
return this.next(function () {
|
||||
return fun.apply(this, a);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Deferred.register("loop", Deferred.loop);
|
||||
Deferred.register("wait", Deferred.wait);
|
||||
|
||||
Deferred.connect = function (funo, options) {
|
||||
var target, func, obj;
|
||||
if (typeof arguments[1] == "string") {
|
||||
target = arguments[0];
|
||||
func = target[arguments[1]];
|
||||
obj = arguments[2] || {};
|
||||
} else {
|
||||
func = arguments[0];
|
||||
obj = arguments[1] || {};
|
||||
target = obj.target;
|
||||
}
|
||||
|
||||
var partialArgs = obj.args ? Array.prototype.slice.call(obj.args, 0) : [];
|
||||
var callbackArgIndex = isFinite(obj.ok) ? obj.ok : obj.args ? obj.args.length : undefined;
|
||||
var errorbackArgIndex = obj.ng;
|
||||
|
||||
return function () {
|
||||
var d = new Deferred().next(function (args) {
|
||||
var next = this._next.callback.ok;
|
||||
this._next.callback.ok = function () {
|
||||
return next.apply(this, args.args);
|
||||
};
|
||||
});
|
||||
|
||||
var args = partialArgs.concat(Array.prototype.slice.call(arguments, 0));
|
||||
if (!(isFinite(callbackArgIndex) && callbackArgIndex !== null)) {
|
||||
callbackArgIndex = args.length;
|
||||
}
|
||||
var callback = function () { d.call(new Deferred.Arguments(arguments)) };
|
||||
args.splice(callbackArgIndex, 0, callback);
|
||||
if (isFinite(errorbackArgIndex) && errorbackArgIndex !== null) {
|
||||
var errorback = function () { d.fail(arguments) };
|
||||
args.splice(errorbackArgIndex, 0, errorback);
|
||||
}
|
||||
Deferred.next(function () { func.apply(target, args) });
|
||||
return d;
|
||||
};
|
||||
};
|
||||
Deferred.Arguments = function (args) { this.args = Array.prototype.slice.call(args, 0) };
|
||||
|
||||
Deferred.retry = function (retryCount, funcDeferred, options) {
|
||||
if (!options) options = {};
|
||||
|
||||
var wait = options.wait || 0;
|
||||
var d = new Deferred();
|
||||
var retry = function () {
|
||||
var m = funcDeferred(retryCount);
|
||||
m.
|
||||
next(function (mes) {
|
||||
d.call(mes);
|
||||
}).
|
||||
error(function (e) {
|
||||
if (--retryCount <= 0) {
|
||||
d.fail(['retry failed', e]);
|
||||
} else {
|
||||
setTimeout(retry, wait * 1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
setTimeout(retry, 0);
|
||||
return d;
|
||||
};
|
||||
|
||||
Deferred.methods = ["parallel", "wait", "next", "call", "loop", "repeat", "chain"];
|
||||
Deferred.define = function (obj, list) {
|
||||
if (!list) list = Deferred.methods;
|
||||
if (!obj) obj = (function getGlobal () { return this })();
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var n = list[i];
|
||||
obj[n] = Deferred[n];
|
||||
}
|
||||
return Deferred;
|
||||
};
|
||||
|
||||
this.Deferred = Deferred;
|
||||
@@ -1,8 +1,8 @@
|
||||
describe('Collection', function() {
|
||||
describe('dpd.todos', function() {
|
||||
it('should exist', function() {
|
||||
expect(dpd.todos).to.exist
|
||||
})
|
||||
expect(dpd.todos).to.exist;
|
||||
});
|
||||
|
||||
describe('dpd.on("createTodo", fn)', function() {
|
||||
it('should respond to a realtime event', function(done) {
|
||||
@@ -14,8 +14,8 @@ describe('Collection', function() {
|
||||
});
|
||||
|
||||
dpd.todos.post({title: '$REALTIME'});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('dpd.on("createTodo2", fn)', function() {
|
||||
it('should respond to a realtime event without a parameter', function(done) {
|
||||
@@ -25,8 +25,8 @@ describe('Collection', function() {
|
||||
});
|
||||
|
||||
dpd.todos.post({title: '$REALTIME2'});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('dpd.todos.on("changed", fn)', function() {
|
||||
it('should respond to the built-in changed event on post', function(done) {
|
||||
@@ -35,7 +35,7 @@ describe('Collection', function() {
|
||||
});
|
||||
|
||||
dpd.todos.post({title: 'changed - create'});
|
||||
})
|
||||
});
|
||||
|
||||
it('should respond to the built-in changed event on put', function(done) {
|
||||
dpd.todos.post({title: 'changed - create'}, function(item) {
|
||||
@@ -45,7 +45,7 @@ describe('Collection', function() {
|
||||
|
||||
dpd.todos.put(item.id, {title: 'changed - updated'});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
it('should respond to the built-in changed event on del', function(done) {
|
||||
dpd.todos.post({title: 'changed - create'}, function(item) {
|
||||
@@ -55,19 +55,19 @@ describe('Collection', function() {
|
||||
|
||||
dpd.todos.del(item.id);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.post({title: \'faux\'}, fn)', function() {
|
||||
it('should create a todo with an id', function(done) {
|
||||
dpd.todos.post({title: 'faux'}, function (todo, err) {
|
||||
expect(todo.id.length).to.equal(16)
|
||||
expect(todo.title).to.equal('faux')
|
||||
expect(err).to.not.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
expect(todo.id.length).to.equal(16);
|
||||
expect(todo.title).to.equal('faux');
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.post({title: "notvalid"}, fn)', function() {
|
||||
it('should properly return an error', function(done) {
|
||||
@@ -106,10 +106,10 @@ describe('Collection', function() {
|
||||
dpd.todos.post({title: "foo", owner: 7}, function (todo, err) {
|
||||
delete todo.id;
|
||||
expect(todo).to.eql({title: "foo", done: false});
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.post({title: "$TESTFAIL", fn)', function() {
|
||||
it('should correctly respond to errors in event IO', function(done) {
|
||||
@@ -136,9 +136,9 @@ describe('Collection', function() {
|
||||
expect(res.length).to.equal(1);
|
||||
expect(res[0].title).to.equal("This one is OK");
|
||||
done();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get({title: title}, fn)', function() {
|
||||
it('should return a single result', function(done) {
|
||||
@@ -149,11 +149,11 @@ describe('Collection', function() {
|
||||
dpd.todos.get({title: title}, function (todos, err) {
|
||||
expect(todos.length).to.equal(1);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get({$sort: {title: 1}}, fn)', function() {
|
||||
it('should order by title', function(done) {
|
||||
@@ -164,7 +164,7 @@ describe('Collection', function() {
|
||||
}).chain(function(next) {
|
||||
dpd.todos.post({title: "B"}, next);
|
||||
}).chain(function(next) {
|
||||
dpd.todos.get({$sort: {title: 1}}, next)
|
||||
dpd.todos.get({$sort: {title: 1}}, next);
|
||||
}).chain(function(next, result, err) {
|
||||
expect(result).to.exist;
|
||||
expect(result.length).to.equal(3);
|
||||
@@ -191,12 +191,12 @@ describe('Collection', function() {
|
||||
expect(todos.length).to.equal(1);
|
||||
expect(todos[0].id).to.not.equal(id);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get({id: "non existent"}, fn)', function() {
|
||||
it('should return a 404', function(done) {
|
||||
@@ -208,9 +208,9 @@ describe('Collection', function() {
|
||||
expect(err.message).to.equal('not found');
|
||||
expect(err.statusCode).to.equal(404);
|
||||
done();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get({title: "$TESTFAIL2"}, fn)', function() {
|
||||
it('should correctly respond to errors in event IO', function(done) {
|
||||
@@ -233,8 +233,8 @@ describe('Collection', function() {
|
||||
expect(todos.length).to.equal(1);
|
||||
expect(todos[0].custom).to.equal('arbitrary');
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should run events when an id is included', function(done) {
|
||||
@@ -242,9 +242,9 @@ describe('Collection', function() {
|
||||
dpd.todos.get({arbitrary: true, id: todo.id}, function (t) {
|
||||
expect(t.custom).to.equal('arbitrary');
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get(id, fn)', function() {
|
||||
@@ -253,7 +253,7 @@ describe('Collection', function() {
|
||||
dpd.todos.get(todo.id, function (t) {
|
||||
expect(t.custom).to.equal('custom');
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -261,9 +261,9 @@ describe('Collection', function() {
|
||||
describe('.put(id, {done: true}, fn)', function() {
|
||||
it('should add properties', function(done) {
|
||||
chain(function(next) {
|
||||
dpd.todos.post({title: 'foobar'}, next)
|
||||
dpd.todos.post({title: 'foobar'}, next);
|
||||
}).chain(function(next, result) {
|
||||
dpd.todos.put(result.id, {done: true}, next)
|
||||
dpd.todos.put(result.id, {done: true}, next);
|
||||
}).chain(function(next, result) {
|
||||
expect(result.title).to.equal('foobar');
|
||||
expect(result.done).to.equal(true);
|
||||
@@ -272,16 +272,16 @@ describe('Collection', function() {
|
||||
expect(result.title).to.equal('foobar');
|
||||
expect(result.done).to.equal(true);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.put(id, {done: true}, fn)', function() {
|
||||
it('should be able to access old properties in On Put', function(done) {
|
||||
chain(function(next) {
|
||||
dpd.todos.post({title: '$PUT_TEST', message: "x"}, next)
|
||||
dpd.todos.post({title: '$PUT_TEST', message: "x"}, next);
|
||||
}).chain(function(next, result) {
|
||||
dpd.todos.put(result.id, {done: true}, next)
|
||||
dpd.todos.put(result.id, {done: true}, next);
|
||||
}).chain(function(next, result) {
|
||||
expect(result.message).to.equal("xx");
|
||||
dpd.todos.get(result.id, next);
|
||||
@@ -289,17 +289,17 @@ describe('Collection', function() {
|
||||
expect(result.message).to.equal("xx");
|
||||
expect(result.done).to.equal(true);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.put(id, {done: true}, fn)', function() {
|
||||
it('should be able to access old properties in On Validate', function(done) {
|
||||
chain(function(next) {
|
||||
dpd.todos.post({title: '$VALIDATE_TEST', message: ""}, next)
|
||||
dpd.todos.post({title: '$VALIDATE_TEST', message: ""}, next);
|
||||
}).chain(function(next, result) {
|
||||
expect(result.message).to.equal("x");
|
||||
dpd.todos.put(result.id, {done: true}, next)
|
||||
dpd.todos.put(result.id, {done: true}, next);
|
||||
}).chain(function(next, result) {
|
||||
expect(result.message).to.equal("xx");
|
||||
dpd.todos.get(result.id, next);
|
||||
@@ -307,7 +307,7 @@ describe('Collection', function() {
|
||||
expect(result.message).to.equal("xx");
|
||||
expect(result.done).to.equal(true);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -327,7 +327,7 @@ describe('Collection', function() {
|
||||
expect(result.tags.length).to.equal(2);
|
||||
expect(result.tags).to.include("red").and.include("blue");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -355,7 +355,7 @@ describe('Collection', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe('.put(id, {tags: {$pushAll: ["red", "yellow"]}}, fn)', function() {
|
||||
it('should update an array', function(done) {
|
||||
@@ -369,7 +369,7 @@ describe('Collection', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe('.put(id, tags: {$pull: "red"}, fn)', function() {
|
||||
it('should remove an item from an array', function(done) {
|
||||
@@ -417,9 +417,9 @@ describe('Collection', function() {
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
cleanCollection(dpd.todos, done);
|
||||
})
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
describe('internal cancel()', function(){
|
||||
it('should not cancel the internal call', function(done) {
|
||||
@@ -428,15 +428,15 @@ describe('Collection', function() {
|
||||
dpd.todos.get({title: '$INTERNAL_CANCEL_TEST'}, function (todos) {
|
||||
expect(todos.length).to.equal(1);
|
||||
done();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
cleanCollection(dpd.todos, done);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('dpd.recursive', function() {
|
||||
beforeEach(function(done) {
|
||||
@@ -474,7 +474,7 @@ describe('Collection', function() {
|
||||
expect(current).to.exist;
|
||||
expect(current.more).to.exist;
|
||||
current = current.more[0];
|
||||
};
|
||||
}
|
||||
expect(current.more).to.not.exist;
|
||||
done(err);
|
||||
});
|
||||
@@ -487,7 +487,7 @@ describe('Collection', function() {
|
||||
}).chain(function(next) {
|
||||
dpd.recursive.post({name: "test3"}, next);
|
||||
}).chain(function(next) {
|
||||
dpd.recursive.get({$limitRecursion: 10, mode: "self"}, next)
|
||||
dpd.recursive.get({$limitRecursion: 10, mode: "self"}, next);
|
||||
}).chain(function(next, res, err) {
|
||||
if (err) return done(err);
|
||||
expect(res.length).to.equal(3);
|
||||
@@ -499,13 +499,13 @@ describe('Collection', function() {
|
||||
expect(self.randQuery).to.equal(x.rand);
|
||||
});
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
cleanCollection(dpd.recursive, done);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('dpd.empty', function() {
|
||||
@@ -531,8 +531,8 @@ describe('Collection', function() {
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
cleanCollection(dpd.empty, done);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var credentials = {
|
||||
username: 'foo@bar.com',
|
||||
password: '123456'
|
||||
}
|
||||
};
|
||||
|
||||
describe('User Collection', function() {
|
||||
describe('dpd.users', function() {
|
||||
@@ -11,12 +11,12 @@ describe('User Collection', function() {
|
||||
if(!user) {
|
||||
throw 'user did not exist';
|
||||
}
|
||||
expect(user.id.length).to.equal(16)
|
||||
expect(user.id.length).to.equal(16);
|
||||
delete user.id;
|
||||
expect(user).to.eql({username: credentials.username});
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should validate for duplicate username', function(done) {
|
||||
chain(function(next) {
|
||||
@@ -46,7 +46,7 @@ describe('User Collection', function() {
|
||||
dpd.users.post({id: res.id, username: 'test'}, next);
|
||||
}).chain(function(next, res, err) {
|
||||
done(err);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should update if id is passed in the url', function(done) {
|
||||
@@ -56,20 +56,20 @@ describe('User Collection', function() {
|
||||
dpd.users.post(res.id, {username: 'test'}, next);
|
||||
}).chain(function(next, res, err) {
|
||||
done(err);
|
||||
})
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
describe('.login(credentials, fn)', function() {
|
||||
it('should login a user', function(done) {
|
||||
dpd.users.post(credentials, function (user, err) {
|
||||
expect(user.id.length).to.equal(16)
|
||||
expect(user.id.length).to.equal(16);
|
||||
dpd.users.login(credentials, function (session, err) {
|
||||
expect(session.id.length).to.equal(128)
|
||||
expect(session.uid.length).to.equal(16)
|
||||
expect(session.id.length).to.equal(128);
|
||||
expect(session.uid.length).to.equal(16);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash the server when called without a body', function(done) {
|
||||
dpd.users.login(null, function(session, err) {
|
||||
@@ -77,34 +77,34 @@ describe('User Collection', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
describe('.me(fn)', function() {
|
||||
it('should return the current user', function(done) {
|
||||
dpd.users.post(credentials, function (user, err) {
|
||||
expect(user.id.length).to.equal(16)
|
||||
expect(user.id.length).to.equal(16);
|
||||
dpd.users.login(credentials, function (session, err) {
|
||||
dpd.users.me(function (me, err) {
|
||||
expect(me).to.exist;
|
||||
expect(me.id.length).to.equal(16);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.del({id: \'...\'}, fn)', function() {
|
||||
it('should remove a user', function(done) {
|
||||
dpd.users.post(credentials, function (user, err) {
|
||||
expect(user.id.length).to.equal(16)
|
||||
expect(user.id.length).to.equal(16);
|
||||
dpd.users.del({id: user.id}, function (session, err) {
|
||||
dpd.users.get({id: user.id}, function (user) {
|
||||
expect(user).to.not.exist;
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('dpd.users.on("changed", fn)', function() {
|
||||
it('should respond to the built-in changed event on post', function(done) {
|
||||
dpd.users.on('changed', function() {
|
||||
@@ -112,7 +112,7 @@ describe('User Collection', function() {
|
||||
});
|
||||
|
||||
dpd.users.post({username: 'foo@bar.com', password: '123456'});
|
||||
})
|
||||
});
|
||||
|
||||
it('should respond to the built-in changed event on put', function(done) {
|
||||
dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
|
||||
@@ -122,7 +122,7 @@ describe('User Collection', function() {
|
||||
|
||||
dpd.users.put(item.id, {username: 'foo3@bar.com'});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
it('should respond to the built-in changed event on del', function(done) {
|
||||
dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
|
||||
@@ -132,8 +132,8 @@ describe('User Collection', function() {
|
||||
|
||||
dpd.users.del(item.id);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('dpd.users.put({}, fn)', function() {
|
||||
it('should allow omitting username and password', function(done) {
|
||||
@@ -143,10 +143,10 @@ describe('User Collection', function() {
|
||||
dpd.users.put(res.id, {username: 'test'}, next);
|
||||
}).chain(function(next, res, err) {
|
||||
done(err);
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
this.timeout(10000);
|
||||
@@ -160,11 +160,11 @@ describe('User Collection', function() {
|
||||
if(!total) {
|
||||
done();
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -58,15 +58,15 @@ describe('chain() function', function() {
|
||||
it('should pass results to the next function asynchronously', function(done) {
|
||||
this.timeout(1000);
|
||||
chain(function(next) {
|
||||
setTimeout(function() {next(1)}, 5);
|
||||
setTimeout(function() {next(1);}, 5);
|
||||
}).chain(function(next, val) {
|
||||
expect(val).to.equal(1);
|
||||
val++;
|
||||
setTimeout(function() {next(val)}, 5);
|
||||
setTimeout(function() {next(val);}, 5);
|
||||
}).chain(function(next, val) {
|
||||
expect(val).to.equal(2);
|
||||
val++;
|
||||
setTimeout(function() {next(val)}, 5);
|
||||
setTimeout(function() {next(val);}, 5);
|
||||
}).chain(function(next, val) {
|
||||
expect(val).to.equal(3);
|
||||
done();
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('collection', function(){
|
||||
var errs = r.validate({title: 'foobar'});
|
||||
|
||||
expect(errs).to.not.exist;
|
||||
})
|
||||
});
|
||||
|
||||
it('should fail to validate the invalid request', function() {
|
||||
var r = createCollection({
|
||||
@@ -33,7 +33,7 @@ describe('collection', function(){
|
||||
var errs = r.validate({title: 7});
|
||||
|
||||
expect(errs).to.eql({'title': 'must be a string'});
|
||||
})
|
||||
});
|
||||
|
||||
it('should fail to validate the invalid request with multiple errors', function() {
|
||||
var r = createCollection({
|
||||
@@ -53,8 +53,8 @@ describe('collection', function(){
|
||||
var errs = r.validate({title: 7, created: 'foo'}, true);
|
||||
|
||||
expect(errs).to.eql({title: 'must be a string', age: 'is required', created: 'must be a date'});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.sanitize(body)', function(){
|
||||
it('should remove properties outside the schema', function() {
|
||||
@@ -69,7 +69,7 @@ describe('collection', function(){
|
||||
expect(sanitized.foo).to.not.exist;
|
||||
expect(sanitized.bar).to.not.exist;
|
||||
expect(sanitized.title).to.equal('foo');
|
||||
})
|
||||
});
|
||||
|
||||
it('should convert int strings to numbers', function() {
|
||||
var r = createCollection({
|
||||
@@ -80,14 +80,14 @@ describe('collection', function(){
|
||||
|
||||
var sanitized = r.sanitize({age: '22'});
|
||||
expect(sanitized.age).to.equal(22);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.handle(ctx)', function(){
|
||||
it('should have a store', function() {
|
||||
var c = new Collection('foo', { db: db.connect(TEST_DB) });
|
||||
expect(c.store).to.exist;
|
||||
})
|
||||
});
|
||||
|
||||
function example(method, path, properties, body, query, test, done, testData) {
|
||||
var c = new Collection(path, {db: db.connect(TEST_DB), config: { properties: properties } });
|
||||
@@ -97,14 +97,14 @@ describe('collection', function(){
|
||||
// faux body
|
||||
req.body = body;
|
||||
req.query = query;
|
||||
c.handle({req: req, res: res, query: query || {}, session: {}, done: function() {res.end()}});
|
||||
c.handle({req: req, res: res, query: query || {}, session: {}, done: function() {res.end();}});
|
||||
}, function (req, res) {
|
||||
test(req, res, method, path, properties, body, query);
|
||||
// cleanup
|
||||
c.store.remove(function (err) {
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if(testData) {
|
||||
@@ -122,7 +122,7 @@ describe('collection', function(){
|
||||
},
|
||||
done
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
it('should handle GET', function(done) {
|
||||
var testData = [{test: true}, {test: false}];
|
||||
@@ -133,7 +133,7 @@ describe('collection', function(){
|
||||
done,
|
||||
testData
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
it('should handle GET without data', function(done) {
|
||||
var testData = [];
|
||||
@@ -144,7 +144,7 @@ describe('collection', function(){
|
||||
done,
|
||||
testData
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
it('should handle PUT', function(done) {
|
||||
var testData = [{test: true}, {test: false}];
|
||||
@@ -155,7 +155,7 @@ describe('collection', function(){
|
||||
done,
|
||||
testData
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
it('should handle DELETE', function(done) {
|
||||
example('DELETE', '/foo', {test: {type: 'boolean'}}, null, {id: 7},
|
||||
@@ -164,8 +164,8 @@ describe('collection', function(){
|
||||
},
|
||||
done
|
||||
);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.save()', function() {
|
||||
it('should save the provided data', function(done) {
|
||||
@@ -271,4 +271,4 @@ describe('collection', function(){
|
||||
c.execCommands('update', item, {names: {$pushAll: ['jim', 'sam']}});
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
@@ -32,8 +32,8 @@ describe('config-loader', function() {
|
||||
configLoader.loadConfig(basepath, this.server, function(err, resources) {
|
||||
if (err) return done(err);
|
||||
expect(resources).to.have.length(6);
|
||||
expect(resources.filter(function(r) { return r.name == 'foo'})).to.have.length(1);
|
||||
expect(resources.filter(function(r) { return r.name == 'bar'})).to.have.length(1);
|
||||
expect(resources.filter(function(r) { return r.name == 'foo';})).to.have.length(1);
|
||||
expect(resources.filter(function(r) { return r.name == 'bar';})).to.have.length(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
122
test/db.unit.js
122
test/db.unit.js
@@ -10,9 +10,9 @@ beforeEach(function(done){
|
||||
expect(err).to.not.exist;
|
||||
expect(result).to.eql([]);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('db', function(){
|
||||
describe('.connect(options)', function(){
|
||||
@@ -22,9 +22,9 @@ describe('db', function(){
|
||||
tester.on('connected', function () {
|
||||
done();
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('db', function(){
|
||||
// TODO: this takes forever, move to integration?
|
||||
@@ -38,13 +38,13 @@ describe('db', function(){
|
||||
// store.find(function (err, res) {
|
||||
// expect(res).to.not.exist;
|
||||
// done(err);
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
})
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
describe('store', function(){
|
||||
|
||||
@@ -53,8 +53,8 @@ describe('store', function(){
|
||||
store.find(function (err, empty) {
|
||||
expect(empty).to.eql([]);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass the query to the underlying database', function(done) {
|
||||
store.insert([{i:1},{i:2},{i:3}], function () {
|
||||
@@ -65,9 +65,9 @@ describe('store', function(){
|
||||
});
|
||||
expect(result).to.have.length(2);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.find({$limit: n}, fn)', function() {
|
||||
it('should limit the result', function(done) {
|
||||
@@ -76,10 +76,10 @@ describe('store', function(){
|
||||
expect(result).to.exist;
|
||||
expect(result).to.have.length(2);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.find({$skip: n}, fn)', function() {
|
||||
it('should skip the n results', function(done) {
|
||||
@@ -88,25 +88,25 @@ describe('store', function(){
|
||||
expect(result).to.exist;
|
||||
expect(result[0].i).to.equal(33333);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.identify(object)', function() {
|
||||
it('should add an _id to the object', function() {
|
||||
var object = {};
|
||||
store.identify(object);
|
||||
expect(object._id.length).to.equal(16);
|
||||
})
|
||||
});
|
||||
|
||||
it('should change _id to id', function() {
|
||||
var object = {_id: 'aaaaaaaabbbbbbbb'};
|
||||
store.identify(object);
|
||||
expect(object.id.length).to.equal(16);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.remove(query, fn)', function(){
|
||||
it('should remove all the objects that match the query', function(done) {
|
||||
@@ -116,10 +116,10 @@ describe('store', function(){
|
||||
store.find(function (err, result) {
|
||||
expect(result).to.have.length(1);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove all the objects', function(done) {
|
||||
store.insert([{i:1},{i:2},{i:3}], function () {
|
||||
@@ -128,11 +128,11 @@ describe('store', function(){
|
||||
store.find(function (err, result) {
|
||||
expect(result).to.eql([]);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.insert(namespace, object, fn)', function(){
|
||||
it('should insert the given object into the namespace', function(done) {
|
||||
@@ -140,8 +140,8 @@ describe('store', function(){
|
||||
expect(result.id).to.exist;
|
||||
expect(result.testing).to.equal(123);
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should insert the given array into the namespace', function(done) {
|
||||
store.insert([{a:1}, {b:2}], function (err, result) {
|
||||
@@ -152,9 +152,9 @@ describe('store', function(){
|
||||
expect(result[1].b).to.equal(2);
|
||||
expect(result).to.have.length(2);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.update(query, updates, fn)', function(){
|
||||
it('should update only the properties provided', function(done) {
|
||||
@@ -166,10 +166,10 @@ describe('store', function(){
|
||||
store.first(query, function (err, result) {
|
||||
expect(result.foo).to.equal('baz');
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should rename all objects', function(done) {
|
||||
store.insert([{foo: 'bar'}, {foo: 'bat'}, {foo: 'baz'}], function (err) {
|
||||
@@ -182,11 +182,11 @@ describe('store', function(){
|
||||
expect(item.foo).to.not.exist;
|
||||
});
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.rename(namespace, fn)', function(){
|
||||
it('should rename the underlying database representation of the store', function(done) {
|
||||
@@ -200,11 +200,11 @@ describe('store', function(){
|
||||
expect(result).to.exist;
|
||||
expect(result).to.have.length(2);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,7 @@ after(function () {
|
||||
try {
|
||||
fs.unlink(__dirname + '/../test-app/.dpd/deployments.json');
|
||||
} catch(e) {}
|
||||
})
|
||||
});
|
||||
|
||||
describe('Deployment', function(){
|
||||
it('should sanitize the name', function() {
|
||||
@@ -25,7 +25,7 @@ describe('Deployment', function(){
|
||||
var d = new Deployment(__dirname + '/../test-app');
|
||||
d.setConfig('test-app.deploydapp.com', {subdomain: 'abcdefg'});
|
||||
// recreate
|
||||
var d = new Deployment(__dirname + '/../test-app');
|
||||
d = new Deployment(__dirname + '/../test-app');
|
||||
expect(d.subdomain).to.equal('abcdefg');
|
||||
});
|
||||
|
||||
@@ -87,8 +87,8 @@ describe('Deployment', function(){
|
||||
var json = require(__dirname + '/../test-app/.dpd/deployments.json');
|
||||
expect(json).to.exist;
|
||||
expect(json.foo).to.equal('bar');
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getConfig()', function(){
|
||||
it('should return a persisted config value', function() {
|
||||
@@ -97,8 +97,8 @@ describe('Deployment', function(){
|
||||
d.setConfig('foo', 'bar');
|
||||
var val = d.getConfig('foo');
|
||||
expect(val).to.equal('bar');
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.publish()', function() {
|
||||
it('should make an http request to POSTing a tar, username, key, and subdomain', function(done) {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// var Files = require('../lib/resources/files');
|
||||
|
||||
// describe('Files', function() {
|
||||
// describe('.handle(ctx, next)', function() {
|
||||
// it('should handle /', function() {
|
||||
// var resource = new Files({path: '/', public: __dirname + '/support/public'});
|
||||
// fauxContext(resource, 'index.html');
|
||||
// });
|
||||
// describe('.handle(ctx, next)', function() {
|
||||
// it('should handle /', function() {
|
||||
// var resource = new Files({path: '/', public: __dirname + '/support/public'});
|
||||
// fauxContext(resource, 'index.html');
|
||||
// });
|
||||
|
||||
// it('should call next when a file does not exist', function(done) {
|
||||
// var resource = new Files({path: '/', public: __dirname + '/support/public'});
|
||||
// fauxContext(resource, 'this-file-doesnt-exist.jpg', null, null, {
|
||||
// done: done,
|
||||
// next: true
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// it('should call next when a file does not exist', function(done) {
|
||||
// var resource = new Files({path: '/', public: __dirname + '/support/public'});
|
||||
// fauxContext(resource, 'this-file-doesnt-exist.jpg', null, null, {
|
||||
// done: done,
|
||||
// next: true
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
@@ -10,13 +10,13 @@ describe('resource', function(){
|
||||
this.on('test', function(data) {
|
||||
expect(data).to.equal('foo');
|
||||
done();
|
||||
})
|
||||
});
|
||||
}
|
||||
util.inherits(Test, Resource);
|
||||
var t = new Test();
|
||||
t.emit('test', 'foo');
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.parse(url)', function(){
|
||||
function example(url, basepath, id, parts, query) {
|
||||
@@ -35,8 +35,8 @@ describe('resource', function(){
|
||||
example('/foo/bat/baz', 'foo', 'baz', ['foo', 'bat', 'baz']);
|
||||
// should also auto encode q={...}
|
||||
example('/foo/boo/bar/baz?q=' + encodeURI(JSON.stringify({"a":"b"})), 'foo', 'baz', ['foo', 'boo', 'bar', 'baz'], {'q':{'a': 'b'}});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.handle(ctx, next)', function(){
|
||||
it('should respond with 200 OK', function(done) {
|
||||
@@ -47,8 +47,8 @@ describe('resource', function(){
|
||||
}, function (req, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
@@ -48,7 +48,7 @@ describe('Router', function() {
|
||||
next();
|
||||
};
|
||||
foo.handle = function() {
|
||||
expect(foobarCalled).to.be.true
|
||||
expect(foobarCalled).to.be['true'];
|
||||
done();
|
||||
};
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('Router', function() {
|
||||
this.timeout(100);
|
||||
|
||||
foo.handle = function() {
|
||||
throw "/foo was handled"
|
||||
throw "/foo was handled";
|
||||
};
|
||||
|
||||
router.route({url: '/dont-match'}, {end: function() {
|
||||
@@ -102,7 +102,7 @@ describe('Router', function() {
|
||||
foo.handle = function(ctx, res) {
|
||||
expect(ctx.url).to.equal('/1234');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
router.route({url: '/foo/1234'}, {});
|
||||
});
|
||||
@@ -116,7 +116,7 @@ describe('Router', function() {
|
||||
resource.handle = function(ctx, res) {
|
||||
expect(ctx.url).to.equal('/index.html');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
router.route({url: '/index.html'}, {});
|
||||
});
|
||||
@@ -137,7 +137,7 @@ describe('Router', function() {
|
||||
});
|
||||
|
||||
function paths(result) {
|
||||
return result.map(function(r) { return r.path });
|
||||
return result.map(function(r) { return r.path; });
|
||||
}
|
||||
|
||||
it ('should match /index.html to /', function() {
|
||||
@@ -216,7 +216,7 @@ describe('Router', function() {
|
||||
expect('/food', '/foo', false);
|
||||
// TODO: I think this one's OK
|
||||
// example('/foo', '/foo/../bar', false);
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ describe('script', function(){
|
||||
it('should execute the script', function(done) {
|
||||
var s = new Script('2 + 2');
|
||||
s.run({}, done);
|
||||
})
|
||||
});
|
||||
|
||||
it('should always have access to cancel()', function(done) {
|
||||
var s = new Script('cancel()');
|
||||
@@ -13,7 +13,7 @@ describe('script', function(){
|
||||
expect(e).to.exist;
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
it('should have access to the current user if one exists', function(done) {
|
||||
var s = new Script('if(!me) throw "no user"');
|
||||
@@ -21,15 +21,15 @@ describe('script', function(){
|
||||
user: {name: 'foo'}
|
||||
};
|
||||
s.run({session: session}, done);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.run(ctx, domain, fn)', function(){
|
||||
it('should expose the domain directly to the script', function(done) {
|
||||
var s = new Script('if(!foo) throw "foo not passed"');
|
||||
s.run({}, {foo: 123}, done);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('async', function(){
|
||||
it('should return after all callbacks are complete', function(done) {
|
||||
@@ -44,7 +44,7 @@ describe('script', function(){
|
||||
expect(i).to.equal(1);
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
it('should callback even an error occurs asynchronously', function(done) {
|
||||
var s = new Script('setTimeout(function() { throw "test err" }, 22)');
|
||||
@@ -62,7 +62,7 @@ describe('script', function(){
|
||||
baz: function (fn) {
|
||||
setTimeout(function () {
|
||||
fn();
|
||||
}, 50)
|
||||
}, 50);
|
||||
throw 'test error baz';
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,9 @@ describe('script', function(){
|
||||
expect(e).to.exist;
|
||||
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@ var Server = require('../lib/server')
|
||||
describe('Server', function() {
|
||||
describe('.listen()', function() {
|
||||
it('should start a new deployd server', function(done) {
|
||||
var PORT = genPort();
|
||||
var PORT = genPort();
|
||||
var opts = {
|
||||
port: PORT,
|
||||
db: {
|
||||
@@ -21,7 +21,7 @@ describe('Server', function() {
|
||||
expect(server.db instanceof Db).to.equal(true);
|
||||
expect(server.options).to.eql(opts);
|
||||
server.on('listening', function () {
|
||||
server.close();
|
||||
server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,8 +21,8 @@ describe('SessionStore', function() {
|
||||
, sid = store.createUniqueIdentifier();
|
||||
|
||||
expect(sid.length).to.equal(128);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('.createSession(fn)', function() {
|
||||
it('should create a session', function(done) {
|
||||
@@ -32,10 +32,10 @@ describe('SessionStore', function() {
|
||||
store.createSession(function (err, session) {
|
||||
expect(session.sid).to.have.length(128);
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Session', function() {
|
||||
function createSession(fn) {
|
||||
@@ -44,7 +44,7 @@ describe('Session', function() {
|
||||
store.createSession(function (err, session) {
|
||||
expect(session.sid).to.have.length(128);
|
||||
fn(err, session);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -89,9 +89,9 @@ describe('Session', function() {
|
||||
session.set({foo: 'bar'});
|
||||
expect(session.data).to.eql({id: session.sid, foo: 'bar'});
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.save(fn)', function() {
|
||||
it('should persist the session data in the store', function(done) {
|
||||
@@ -100,11 +100,11 @@ describe('Session', function() {
|
||||
session.store.first({id: session.sid}, function (err, sdata) {
|
||||
expect(sdata.foo).to.equal('bar');
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.remove(fn)', function() {
|
||||
it('should remove the session data from the store', function(done) {
|
||||
@@ -116,13 +116,13 @@ describe('Session', function() {
|
||||
session.store.first({id: session.sid}, function (err, sdata) {
|
||||
expect(sdata).to.not.exist;
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.fetch(fn)', function() {
|
||||
it('should fetch the session data from the store', function(done) {
|
||||
@@ -133,10 +133,10 @@ describe('Session', function() {
|
||||
session.fetch(function (err) {
|
||||
expect(session.data).to.eql({id: session.sid, foo: 'bar'});
|
||||
done(err);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,9 +13,9 @@ sh = require('shelljs');
|
||||
// port generation
|
||||
genPort = function() {
|
||||
var min = 6666, max = 9999;
|
||||
var result = min + (Math.random() * (max - min))
|
||||
var result = min + (Math.random() * (max - min));
|
||||
return Math.floor(result);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// request mock
|
||||
@@ -31,7 +31,7 @@ freq = function(url, options, fn, callback) {
|
||||
var r = end.apply(res, arguments);
|
||||
s.close();
|
||||
return r;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
s.close();
|
||||
}
|
||||
@@ -40,8 +40,8 @@ freq = function(url, options, fn, callback) {
|
||||
.listen(port)
|
||||
.on('listening', function () {
|
||||
request(options);
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
var mdb = new mongodb.Db(TEST_DB.name, new mongodb.Server(TEST_DB.host, TEST_DB.port));
|
||||
@@ -50,8 +50,8 @@ before(function (done) {
|
||||
done(err);
|
||||
mdb.close();
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,24 +86,24 @@ fauxContext = function(resource, url, input, expectedOutput, behavior) {
|
||||
if(expectedOutput && typeof expectedOutput == 'object') expect(res).to.eql(expectedOutput);
|
||||
context.done = function() {
|
||||
throw 'done called twice...';
|
||||
}
|
||||
};
|
||||
if(behavior && behavior.done) behavior.done(err, res);
|
||||
},
|
||||
res: input.res || new ServerResponse(new ServerRequest())
|
||||
}
|
||||
};
|
||||
|
||||
context.res.end = function() {
|
||||
context.done();
|
||||
}
|
||||
};
|
||||
|
||||
function next(err) {
|
||||
if(!(behavior && behavior.next)) {
|
||||
throw new Error('should not call next')
|
||||
throw new Error('should not call next');
|
||||
}
|
||||
if(behavior && behavior.done) behavior.done(err);
|
||||
}
|
||||
|
||||
resource.handle(context, next);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
2 + 2
|
||||
2 + 2;
|
||||
@@ -15,7 +15,7 @@ describe('UserCollection', function() {
|
||||
done: function(err, res) {
|
||||
if(test.complete) test.complete(err, res);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should login a user when credentials are POSTed to "/login"', function(done) {
|
||||
@@ -39,10 +39,10 @@ describe('UserCollection', function() {
|
||||
this.uc.store.find = function(query, fn) {
|
||||
expect(query).to.eql({email: 'foo@bar.com', password: 'abcd'});
|
||||
fn(null, {id: '123', email: 'foo@bar.com'});
|
||||
}
|
||||
};
|
||||
this.complete = function(err, res) {
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
this.uc.handle(this.ctx);
|
||||
});
|
||||
@@ -57,7 +57,7 @@ describe('UserCollection', function() {
|
||||
expect(fn).to.be.a('function');
|
||||
fn();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.ctx.req.url = '/users/logout';
|
||||
this.ctx.req.method = 'POST';
|
||||
this.ctx.req.body.email = 'foo@bar.com';
|
||||
@@ -65,7 +65,7 @@ describe('UserCollection', function() {
|
||||
this.complete = function(err, res) {
|
||||
expect(removed).to.equal(true);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
this.uc.handle(this.ctx);
|
||||
});
|
||||
@@ -86,7 +86,7 @@ describe('UserCollection', function() {
|
||||
expect(query).to.eql({id: '123', $fields: {password: 0}});
|
||||
found = true;
|
||||
fn();
|
||||
}
|
||||
};
|
||||
|
||||
uc.handleSession(ctx, function() {
|
||||
expect(found).to.equal(true);
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('uuid', function() {
|
||||
var i = 1000; // replace this with a larger number to really test
|
||||
while(i--) {
|
||||
var next = uuid.create();
|
||||
if(used[next]) throw 'already used'
|
||||
if(used[next]) throw 'already used';
|
||||
used[next] = 1;
|
||||
}
|
||||
});
|
||||
@@ -36,8 +36,8 @@ describe('.parseBody()', function() {
|
||||
setHeader: function () {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
it ('should parse json', function(done) {
|
||||
var obj = {foo: 'bar'}
|
||||
@@ -53,8 +53,8 @@ describe('.parseBody()', function() {
|
||||
});
|
||||
|
||||
it('should parse json in chunks', function(done) {
|
||||
var req = new Stream()
|
||||
, chunks = ['{"fo',
|
||||
var req = new Stream()
|
||||
, chunks = ['{"fo'
|
||||
, 'o": "bar"'
|
||||
, ', "bar"'
|
||||
, ': "baz"'
|
||||
@@ -67,7 +67,7 @@ describe('.parseBody()', function() {
|
||||
});
|
||||
chunks.forEach(function(c) {
|
||||
req.emit('data', c);
|
||||
})
|
||||
});
|
||||
req.emit('end');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user