Skip to content

Commit 4f7419e

Browse files
authored
Merge pull request #314 from jason-fox/feature/prettier
Add prettier code formatting
2 parents 2e8b2ba + c048e0f commit 4f7419e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3306
-2956
lines changed

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"singleQuote": true,
5+
"parser": "flow",
6+
"printWidth": 120,
7+
"trailingComma": "none",
8+
"tabWidth": 4
9+
}

config.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@ var config = {};
3131
*/
3232
config.logLevel = 'INFO';
3333

34-
3534
/**
3635
* Configures the exposed API.
3736
*/
3837
config.endpoint = {
3938
host: 'localhost',
4039
port: 9090,
41-
rulesPath : '/rules',
42-
actionsPath : '/actions/do',
43-
noticesPath : '/notices',
44-
vrPath : '/m2m/vrules',
45-
checkPath : '/check',
46-
versionPath : '/version',
40+
rulesPath: '/rules',
41+
actionsPath: '/actions/do',
42+
noticesPath: '/notices',
43+
vrPath: '/m2m/vrules',
44+
checkPath: '/check',
45+
versionPath: '/version',
4746
logPath: '/admin/log',
4847
metricsPath: '/admin/metrics'
4948
};
@@ -58,38 +57,36 @@ config.isMaster = true;
5857
*/
5958
config.slaveDelay = 500;
6059

61-
6260
/**
6361
* DB Configuration.
6462
*/
6563
config.mongo = {
6664
// The URI to use for the database connection. It supports replica set URIs.
6765
// mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
6866
// I.e.: 'mongodb://user:pass@host1:27017,host2:27018,host3:27019/cep?replicaSet=myrep'
69-
url : 'mongodb://localhost:27017/cep'
67+
url: 'mongodb://localhost:27017/cep'
7068
};
7169

7270
/**
7371
* OrionDB Configuration.
7472
*/
7573
config.orionDb = {
76-
url : 'mongodb://localhost:27017/orion',
77-
collection : 'entities',
78-
prefix : 'orion',
74+
url: 'mongodb://localhost:27017/orion',
75+
collection: 'entities',
76+
prefix: 'orion',
7977
batchSize: 500
8078
};
8179

82-
8380
/**
8481
* EPL core options
8582
*
8683
* interval is the time in milliseconds between refreshing rules
8784
* at core. Each <<interval>> ms, the rules are sent to core.
8885
*/
8986
config.perseoCore = {
90-
rulesURL : 'http://localhost:8080/perseo-core/rules',
91-
noticesURL : 'http://localhost:8080/perseo-core/events',
92-
interval: 60e3*5
87+
rulesURL: 'http://localhost:8080/perseo-core/rules',
88+
noticesURL: 'http://localhost:8080/perseo-core/events',
89+
interval: 60e3 * 5
9390
};
9491
/**
9592
* NEXT EPL core options (with HA)
@@ -104,35 +101,32 @@ config.nextCore = {
104101
*/
105102
};
106103

107-
108104
/**
109105
* SMTP endpoint options
110106
*/
111107
config.smtp = {
112108
port: 25,
113109
host: 'smtpserver',
114-
secure: false
110+
secure: false,
115111
/*
116112
,
117113
auth: {
118114
user: 'abc',
119115
pass: 'xyz'
120116
}
121117
*/
122-
,
123118
tls: {
124-
// keep rejectUnauthorized to false when secure is also false
125-
rejectUnauthorized: false
119+
// keep rejectUnauthorized to false when secure is also false
120+
rejectUnauthorized: false
126121
}
127-
128122
};
129123

130124
/**
131125
* SMS endpoint options
132126
*/
133127
config.sms = {
134-
URL : 'http://sms-endpoint/smsoutbound',
135-
API_KEY : '',
128+
URL: 'http://sms-endpoint/smsoutbound',
129+
API_KEY: '',
136130
API_SECRET: '',
137131
from: 'tel:22012;phone-context=+34'
138132
};
@@ -153,7 +147,7 @@ config.smpp = {
153147
* Orion (Context Broker) endpoint options
154148
*/
155149
config.orion = {
156-
URL : 'http://orion-endpoint:1026/NGSI10/updateContext'
150+
URL: 'http://orion-endpoint:1026/NGSI10/updateContext'
157151
};
158152

159153
/**
@@ -171,7 +165,7 @@ config.authentication = {
171165
* @type {{}}
172166
*/
173167
config.collections = {
174-
rules : 'rules',
168+
rules: 'rules',
175169
executions: 'executions'
176170
};
177171

@@ -190,8 +184,8 @@ config.executionsTTL = 1 * 24 * 60 * 60;
190184
*
191185
* @type {{}}
192186
*/
193-
config.DEFAULT_SUBSERVICE= '/';
194-
config.DEFAULT_SERVICE= 'unknownt';
187+
config.DEFAULT_SUBSERVICE = '/';
188+
config.DEFAULT_SERVICE = 'unknownt';
195189

196190
/**
197191
* CheckDB configuration

ghpages/javascripts/scale.fix.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
var metas = document.getElementsByTagName('meta');
22
var i;
33
if (navigator.userAgent.match(/iPhone/i)) {
4-
for (i=0; i<metas.length; i++) {
5-
if (metas[i].name == "viewport") {
6-
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
4+
for (i = 0; i < metas.length; i++) {
5+
if (metas[i].name == 'viewport') {
6+
metas[i].content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
7+
}
78
}
8-
}
9-
document.addEventListener("gesturestart", gestureStart, false);
9+
document.addEventListener('gesturestart', gestureStart, false);
1010
}
1111
function gestureStart() {
12-
for (i=0; i<metas.length; i++) {
13-
if (metas[i].name == "viewport") {
14-
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
12+
for (i = 0; i < metas.length; i++) {
13+
if (metas[i].name == 'viewport') {
14+
metas[i].content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
15+
}
1516
}
16-
}
17-
}
17+
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/perseo');
1+
module.exports = require('./lib/perseo');

lib/alarm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ var util = require('util'),
2727
logger = require('logops'),
2828
alarms = {};
2929

30-
3130
function raise(alarm, context, message) {
3231
var state = alarms[alarm];
3332
context = (process.domain && process.domain.context) || {};

lib/appContext.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
*/
2323
'use strict';
2424

25-
var
26-
database,
27-
orionDatabase;
25+
var database, orionDatabase;
2826

2927
function SetDB(db) {
3028
database = db;
@@ -67,4 +65,3 @@ module.exports.SetOrionDB = SetOrionDB;
6765
* @return {Object} db connection
6866
*/
6967
module.exports.OrionDb = OrionDB;
70-

lib/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ module.exports = {
3434
REALIP_HEADER: 'X-Real-IP',
3535
COMPONENT_NAME: 'perseo-fe'
3636
};
37-

lib/db.js

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ var async = require('async'),
3232
database,
3333
orionDb,
3434
delay = config.checkDB.delay,
35-
context = {comp: constants.COMPONENT_NAME, op: 'checkDB'};
35+
context = { comp: constants.COMPONENT_NAME, op: 'checkDB' };
3636

3737
function pingAux(db, component, callback) {
38-
db.command({ping: 1}, function(err, result) {
38+
db.command({ ping: 1 }, function(err, result) {
3939
if (err) {
4040
alarm.raise(component, context, err.message);
41-
}
42-
else {
41+
} else {
4342
alarm.release(component, context, result);
4443
}
4544
return callback(err, result);
@@ -49,39 +48,43 @@ function pingAux(db, component, callback) {
4948
function getDbAux(url, component, callback) {
5049
var client = require('mongodb').MongoClient,
5150
checkDbHealthFunc;
52-
client.connect(url, {
53-
db: {
54-
bufferMaxEntries: config.checkDB.bufferMaxEntries,
55-
domainsEnabled: true
51+
client.connect(
52+
url,
53+
{
54+
db: {
55+
bufferMaxEntries: config.checkDB.bufferMaxEntries,
56+
domainsEnabled: true
57+
},
58+
server: {
59+
reconnectTries: config.checkDB.reconnectTries,
60+
reconnectInterval: config.checkDB.reconnectInterval,
61+
domainsEnabled: true
62+
}
5663
},
57-
server: {
58-
reconnectTries: config.checkDB.reconnectTries,
59-
reconnectInterval: config.checkDB.reconnectInterval,
60-
domainsEnabled: true
61-
}
62-
}, function(err, db) {
63-
if (err) {
64-
myutils.logErrorIf(err, 'connect', context);
65-
return callback(err, null);
66-
}
64+
function(err, db) {
65+
if (err) {
66+
myutils.logErrorIf(err, 'connect', context);
67+
return callback(err, null);
68+
}
6769

68-
// This event is emitted only by Server topology (standalone)
69-
// The driver has given up getting a connection, so we will die (restart perseo usually)
70-
// and re-try from scratch.
71-
// The ReplSet does not emit 'reconnectFailed'
72-
db.serverConfig.on('reconnectFailed', function() {
73-
logger.fatal('too many tries to reconnect to database, dying ...');
74-
process.exit(-2);
75-
});
76-
77-
checkDbHealthFunc = function checkDbHealth() {
78-
pingAux(db, component, function(err, result) {
79-
logger.debug('ping (%s) %j', component, err || result);
70+
// This event is emitted only by Server topology (standalone)
71+
// The driver has given up getting a connection, so we will die (restart perseo usually)
72+
// and re-try from scratch.
73+
// The ReplSet does not emit 'reconnectFailed'
74+
db.serverConfig.on('reconnectFailed', function() {
75+
logger.fatal('too many tries to reconnect to database, dying ...');
76+
process.exit(-2);
8077
});
81-
};
82-
setInterval(checkDbHealthFunc, delay);
83-
return callback(null, db);
84-
});
78+
79+
checkDbHealthFunc = function checkDbHealth() {
80+
pingAux(db, component, function(err, result) {
81+
logger.debug('ping (%s) %j', component, err || result);
82+
});
83+
};
84+
setInterval(checkDbHealthFunc, delay);
85+
return callback(null, db);
86+
}
87+
);
8588
}
8689
function getDb(callback) {
8790
getDbAux(config.mongo.url, alarm.DATABASE, function cb(err, db) {
@@ -99,7 +102,7 @@ function getOrionDb(callback) {
99102
function ensureIndex(collection, fields, callback) {
100103
database.collection(collection, function(err, collection) {
101104
myutils.logErrorIf(err, collection, context);
102-
collection.ensureIndex(fields, {unique: true}, function(err, indexName) {
105+
collection.ensureIndex(fields, { unique: true }, function(err, indexName) {
103106
myutils.logErrorIf(err, 'ensureIndex ' + collection, context);
104107
callback(err, indexName);
105108
});
@@ -108,18 +111,25 @@ function ensureIndex(collection, fields, callback) {
108111
function ensureIndexTTL(collection, fields, ttl, callback) {
109112
database.collection(collection, function(err, collection) {
110113
myutils.logErrorIf(err, collection);
111-
collection.ensureIndex(fields, {expireAfterSeconds: ttl}, function(err, indexName) {
114+
collection.ensureIndex(fields, { expireAfterSeconds: ttl }, function(err, indexName) {
112115
myutils.logErrorIf(err, 'ensureIndex ' + collection, context);
113116
callback(err, indexName);
114117
});
115118
});
116119
}
117120

118121
function setUp(cbSU) {
119-
async.parallel([
120-
ensureIndex.bind(null, rulesCollection, {name: 1, subservice: 1, service: 1}),
121-
ensureIndexTTL.bind(null, executionsCollection, {lastTime: 1}, config.executionsTTL)
122-
], cbSU);
122+
async.parallel(
123+
[
124+
ensureIndex.bind(null, rulesCollection, {
125+
name: 1,
126+
subservice: 1,
127+
service: 1
128+
}),
129+
ensureIndexTTL.bind(null, executionsCollection, { lastTime: 1 }, config.executionsTTL)
130+
],
131+
cbSU
132+
);
123133
}
124134

125135
function closeAux(db, callback) {

lib/middleware/domain.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var domain = require('domain'),
4040
* @return {Function} Express middleWare.
4141
*/
4242
function requestDomain() {
43-
4443
return function requestDomain(req, res, next) {
4544
var reqDomain = domain.create();
4645
reqDomain.add(req);
@@ -57,7 +56,8 @@ function requestDomain() {
5756
cleanDomain = function() {
5857
var responseTime = Date.now() - reqDomain.start;
5958
logger.debug('response-time: ' + responseTime + ' statusCode: ' + res.statusCode);
60-
if (req.url.indexOf(config.endpoint.actionsPath) !== 0 &&
59+
if (
60+
req.url.indexOf(config.endpoint.actionsPath) !== 0 &&
6161
req.url.indexOf(config.endpoint.checkPath) !== 0 &&
6262
req.url.indexOf(config.endpoint.versionPath) !== 0 &&
6363
req.url.indexOf(config.endpoint.logPath) !== 0 &&
@@ -114,9 +114,7 @@ function requestDomain() {
114114
res.once('finish', cleanDomain);
115115
reqDomain.on('error', domainErrorHandler);
116116
reqDomain.run(requestHandler);
117-
118117
};
119-
120118
}
121119
/**
122120
* Express middleWare that creates a domain per request

lib/middleware/error.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ exports.middleware = function() {
4242
}
4343
};
4444
};
45-

0 commit comments

Comments
 (0)