Skip to content

Commit b38dff3

Browse files
authored
Merge pull request #5 from BoolJS/develop
Version bump to v0.5.0
2 parents 544de8b + 3d98540 commit b38dff3

24 files changed

Lines changed: 257 additions & 295 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*]
2+
indent_size=4
3+
[package.json]
4+
indent_size=2

.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = {
4+
extends: [ 'standard' ],
5+
env: {
6+
es6: true,
7+
node: true
8+
},
9+
rules: {
10+
indent: [ 'error', 4 ],
11+
semi: [ 'error', 'always' ],
12+
'no-multi-spaces': 0
13+
}
14+
};

.jshintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: node_js
22
node_js:
3-
- 4.0
3+
- 8.0

example/dependant-class.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const { Middleware } = require('..');
4+
5+
module.exports = class DependantMiddleware extends Middleware {
6+
constructor () {
7+
super('dependant-middleware');
8+
}
9+
action (req, res, next) {
10+
next();
11+
}
12+
};

example/plugin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
var API = require('..');
3+
const { Middleware } = require('..');
44

5-
module.exports = class ExampleMiddleware extends API.Middleware {
6-
constructor(){
7-
super('example-middleware');
5+
module.exports = class ExampleMiddleware extends Middleware {
6+
constructor () {
7+
super('example-middleware', [ require.resolve('./dependant-class') ]);
88
}
9-
action(req, res, next) {
9+
action (req, res, next) {
1010
next();
1111
}
1212
};

lib/app/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
var AppInstance = require('./instance')
4-
, instancePool = {};
3+
const AppInstance = require('./instance');
4+
const instancePool = {};
55

66
/**
77
* @class App
@@ -17,7 +17,7 @@ module.exports = {
1717
* @return {String[]} An array with the namespaces of the instances in
1818
* the pool.
1919
*/
20-
listInstances: function(){
20+
listInstances: function () {
2121
return Object.keys(instancePool);
2222
},
2323
/**
@@ -29,8 +29,8 @@ module.exports = {
2929
* otherwise, it won't work after.
3030
* @return {API.Component.AppInstance} The application object.
3131
*/
32-
getInstance: function(namespace, dependencies){
33-
if(instancePool[namespace] === undefined){
32+
getInstance: function (namespace, dependencies) {
33+
if (instancePool[namespace] === undefined) {
3434
var newInstance = new AppInstance(namespace, dependencies);
3535
instancePool[namespace] = newInstance;
3636
}
@@ -41,7 +41,7 @@ module.exports = {
4141
* @description Removes instance of an application from the pool.
4242
* @param {String} namespace - The namespace of the application.
4343
*/
44-
removeInstance: function(namespace){
44+
removeInstance: function (namespace) {
4545
delete instancePool[namespace];
4646
}
4747

lib/app/instance/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
var Store = require('./store')
4-
, Namespace = require('./namespace')
5-
, AppComponents = require('./components');
3+
const Store = require('./store');
4+
const Namespace = require('./namespace');
5+
const AppComponents = require('./components');
6+
const injector = require('object-injector');
67

78
/**
89
* @class AppInstance
@@ -13,11 +14,10 @@ var Store = require('./store')
1314
* @param {String[]} [dependencies] - A list of packages that instance
1415
* depends
1516
*/
16-
module.exports = function(namespace, dependencies){
17-
18-
if(!Namespace.checker(namespace)) throw new Error(
19-
"Specified namespace is invalid"
20-
);
17+
module.exports = function (namespace, dependencies) {
18+
if (!Namespace.checker(namespace)) {
19+
throw new Error('Specified namespace is invalid');
20+
}
2121

2222
var components = new AppComponents();
2323
injector(this, components);
@@ -47,8 +47,7 @@ module.exports = function(namespace, dependencies){
4747
* @description Shortcut for long schema skeleton of namespace.
4848
* @return {Object} The skeleton of the application, including namespaces.
4949
*/
50-
this.getSkeleton = function(){
51-
return Namespace.generator(namespace, {}, this.getComponents);
50+
this.getSkeleton = function () {
51+
return Namespace.generator(namespace, this.getComponents);
5252
};
53-
5453
};

lib/app/instance/namespace.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@
1212
* @throws {Error} In case namespace is not according to standard naming
1313
* conventions.
1414
*/
15-
var namespaceGenerator = exports.generator = function(namespace, skel, final){
15+
exports.generator = function namespaceGenerator (namespace, final) {
16+
const packages = namespace.split('.');
1617

17-
var skeleton = {};
18-
skel = skel || {}; //Empty object for initial call
18+
let current = { [packages.pop()]: final() };
1919

20-
var ns = namespace.split('.');
21-
22-
if(ns.length > 0 && ns[0] !== ''){
23-
skeleton[ns[0]] = namespaceGenerator(
24-
ns.slice(1).join("."), {}, final
25-
);
26-
return skeleton;
27-
} else {
28-
return final();
20+
while (packages.length > 1) {
21+
current = { [packages.pop()]: current };
2922
}
3023

24+
return { [packages.pop()]: current };
3125
};
3226

3327
/**
@@ -39,6 +33,6 @@ var namespaceGenerator = exports.generator = function(namespace, skel, final){
3933
* @returns {Boolean} A boolean value stating true if the namespace is valid,
4034
* and false otherwise.
4135
*/
42-
var namespaceChecker = exports.checker = function(namespace){
36+
exports.checker = function namespaceChecker (namespace) {
4337
return /^(@?[a-z_A-Z]\w+(?:\.?[a-z_A-Z]\w+)*)$/.test(namespace);
4438
};

lib/error.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
* @return {API.Error} An {@link API.Error} instance.
1212
*/
1313
module.exports = class BoolError extends Error {
14-
constructor(status, code, message, uri) {
14+
constructor (status, code, message, uri) {
1515
super();
1616
// Executed in case first argument is `code`.
17-
if(!(typeof status === 'number' && (status % 1) === 0)) {
17+
if (!(typeof status === 'number' && (status % 1) === 0)) {
1818
status = 500;
1919
code = status || 'server_error';
2020
message = code || null;
@@ -26,7 +26,6 @@ module.exports = class BoolError extends Error {
2626
uri = uri || null;
2727
}
2828

29-
3029
/**
3130
* @value name
3231
* @description Name of error

0 commit comments

Comments
 (0)