Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microframework

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microframework - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

ConfigLoader.d.ts

207

ConfigLoader.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _fs = require("fs");
var fs = _interopRequireWildcard(_fs);
var _configuratorTsConfigurator = require("configurator.ts/Configurator");
var _MicroFrameworkUtils = require("./MicroFrameworkUtils");
var fs = require("fs");
var Configurator_1 = require("configurator.ts/Configurator");
var MicroFrameworkUtils_1 = require("./MicroFrameworkUtils");
/**
* Loads configuration files into the framework.
*/
var ConfigLoader = (function () {

@@ -29,14 +12,6 @@ // -------------------------------------------------------------------------

// -------------------------------------------------------------------------
function ConfigLoader(settings) {
_classCallCheck(this, ConfigLoader);
this.settings = settings;
}
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Public Methods

@@ -47,110 +22,80 @@ // -------------------------------------------------------------------------

*/
_createClass(ConfigLoader, [{
key: "load",
value: function load() {
this.loadConfigurations();
this.loadParameters();
ConfigLoader.prototype.load = function () {
this.loadConfigurations();
this.loadParameters();
};
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
ConfigLoader.prototype.loadConfigurations = function () {
var _this = this;
var configFiles = this.getConfigFiles();
configFiles
.map(function (file) { return _this.requireFile(file); })
.filter(function (file) { return !!file; })
.forEach(function (file) { return Configurator_1.defaultConfigurator.addConfiguration(file); });
configFiles
.map(function (file) { return _this.requireEnvironmentFile(file); })
.filter(function (envFile) { return !!envFile; })
.forEach(function (envFile) { return Configurator_1.defaultConfigurator.addConfiguration(envFile); });
};
ConfigLoader.prototype.loadParameters = function () {
var _this = this;
var merge = function (file, parameters) { return Object.keys(file).forEach(function (c) { return parameters[c] = file[c]; }); };
var parameters = {};
var parametersFiles = this.getParameterFiles();
parametersFiles
.map(function (file) { return _this.requireFile(file); })
.filter(function (file) { return !!file; })
.forEach(function (file) { return merge(file, parameters); });
parametersFiles
.map(function (fileName) { return _this.requireEnvironmentFile(fileName); })
.filter(function (envFile) { return !!envFile; })
.forEach(function (envFile) { return merge(envFile, parameters); });
Configurator_1.defaultConfigurator.replaceWithParameters(parameters);
};
ConfigLoader.prototype.requireFile = function (file) {
try {
fs.statSync(file);
return require(file);
}
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
}, {
key: "loadConfigurations",
value: function loadConfigurations() {
var _this = this;
var configFiles = this.getConfigFiles();
configFiles.map(function (file) {
return _this.requireFile(file);
}).filter(function (file) {
return !!file;
}).forEach(function (file) {
return _configuratorTsConfigurator.defaultConfigurator.addConfiguration(file);
});
configFiles.map(function (file) {
return _this.requireEnvironmentFile(file);
}).filter(function (envFile) {
return !!envFile;
}).forEach(function (envFile) {
return _configuratorTsConfigurator.defaultConfigurator.addConfiguration(envFile);
});
}
}, {
key: "loadParameters",
value: function loadParameters() {
var _this2 = this;
var merge = function merge(file, parameters) {
return Object.keys(file).forEach(function (c) {
return parameters[c] = file[c];
});
};
var parameters = {};
var parametersFiles = this.getParameterFiles();
parametersFiles.map(function (file) {
return _this2.requireFile(file);
}).filter(function (file) {
return !!file;
}).forEach(function (file) {
return merge(file, parameters);
});
parametersFiles.map(function (fileName) {
return _this2.requireEnvironmentFile(fileName);
}).filter(function (envFile) {
return !!envFile;
}).forEach(function (envFile) {
return merge(envFile, parameters);
});
_configuratorTsConfigurator.defaultConfigurator.replaceWithParameters(parameters);
}
}, {
key: "requireFile",
value: function requireFile(file) {
catch (e) { }
return undefined;
};
ConfigLoader.prototype.requireEnvironmentFile = function (file) {
var environment = this.getEnvironment();
if (environment) {
var envConfig = MicroFrameworkUtils_1.MicroFrameworkUtils.getEnvironmentFile(file, environment);
try {
fs.statSync(file);
return require(file);
} catch (e) {}
return undefined;
}
}, {
key: "requireEnvironmentFile",
value: function requireEnvironmentFile(file) {
var environment = this.getEnvironment();
if (environment) {
var envConfig = _MicroFrameworkUtils.MicroFrameworkUtils.getEnvironmentFile(file, environment);
try {
fs.statSync(envConfig);
return require(envConfig);
} catch (e) {}
fs.statSync(envConfig);
return require(envConfig);
}
return undefined;
catch (e) { }
}
}, {
key: "getEnvironment",
value: function getEnvironment() {
if (!this.settings.environment && process.env.MICROFRAMEWORK_ENV) return process.env.MICROFRAMEWORK_ENV;
return this.settings.environment;
}
}, {
key: "getConfigFiles",
value: function getConfigFiles() {
if (!this.settings.configurationFiles) return [this.settings.baseDirectory + '/' + ConfigLoader.DEFAULT_CONFIG_DIRECTORY + '/' + ConfigLoader.DEFAULT_CONFIG_FILE];
return this.settings.configurationFiles;
}
}, {
key: "getParameterFiles",
value: function getParameterFiles() {
if (!this.settings.parametersFiles) return [this.settings.baseDirectory + '/' + ConfigLoader.DEFAULT_CONFIG_DIRECTORY + '/' + ConfigLoader.DEFAULT_PARAMETERS_FILE];
return this.settings.parametersFiles;
}
}]);
return undefined;
};
ConfigLoader.prototype.getEnvironment = function () {
if (!this.settings.environment && process.env.MICROFRAMEWORK_ENV)
return process.env.MICROFRAMEWORK_ENV;
return this.settings.environment;
};
ConfigLoader.prototype.getConfigFiles = function () {
if (!this.settings.configurationFiles)
return [this.settings.baseDirectory + "/" + ConfigLoader.DEFAULT_CONFIG_DIRECTORY + "/" + ConfigLoader.DEFAULT_CONFIG_FILE];
return this.settings.configurationFiles;
};
ConfigLoader.prototype.getParameterFiles = function () {
if (!this.settings.parametersFiles)
return [this.settings.baseDirectory + "/" + ConfigLoader.DEFAULT_CONFIG_DIRECTORY + "/" + ConfigLoader.DEFAULT_PARAMETERS_FILE];
return this.settings.parametersFiles;
};
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
ConfigLoader.DEFAULT_CONFIG_DIRECTORY = "config";
ConfigLoader.DEFAULT_CONFIG_FILE = "config.json";
ConfigLoader.DEFAULT_PARAMETERS_FILE = "parameters.json";
return ConfigLoader;
})();
}());
exports.ConfigLoader = ConfigLoader;
ConfigLoader.DEFAULT_CONFIG_DIRECTORY = 'config';
ConfigLoader.DEFAULT_CONFIG_FILE = 'config.json';
ConfigLoader.DEFAULT_PARAMETERS_FILE = 'parameters.json';
//# sourceMappingURL=ConfigLoader.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ModuleExports = ModuleExports;
var _MicroFrameworkRegistry = require("./MicroFrameworkRegistry");
var _typediContainer = require("typedi/Container");
var MicroFrameworkRegistry_1 = require("./MicroFrameworkRegistry");
var Container_1 = require("typedi/Container");
function ModuleExports(microframeworkNameOrModuleType, moduleType) {
var name = undefined;
if (typeof microframeworkNameOrModuleType === 'string') {
var name;
if (typeof microframeworkNameOrModuleType === "string") {
name = microframeworkNameOrModuleType;
} else {
}
else {
moduleType = microframeworkNameOrModuleType;
}
return function (target, key, index) {
_typediContainer.Container.registerParamHandler({
Container_1.Container.registerParamHandler({
type: target,
index: index,
getValue: function getValue() {
var microFramework = _MicroFrameworkRegistry.MicroFrameworkRegistry.get(name || 'default');
if (!microFramework) return;
getValue: function () {
var microFramework = MicroFrameworkRegistry_1.MicroFrameworkRegistry.get(name || "default");
if (!microFramework)
return;
var module = microFramework.findModuleByType(moduleType);
if (!module) throw new Error('Module ' + moduleType + ' was not found in the microframework ' + name);
if (!module.getModuleExports) throw new Error('Module ' + moduleType + ' in the microframework ' + name + ' does not export anything.');
if (!module)
throw new Error("Module " + moduleType + " was not found in the microframework " + name);
if (!module.getModuleExports)
throw new Error("Module " + moduleType + " in the microframework " + name + " does not export anything.");
return module.getModuleExports();

@@ -33,2 +29,4 @@ }

};
}
}
exports.ModuleExports = ModuleExports;
//# sourceMappingURL=Decorators.js.map

@@ -1,27 +0,18 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var DependenciesMissingException = (function (_Error) {
_inherits(DependenciesMissingException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var DependenciesMissingException = (function (_super) {
__extends(DependenciesMissingException, _super);
function DependenciesMissingException(moduleName, dependModules) {
_classCallCheck(this, DependenciesMissingException);
_get(Object.getPrototypeOf(DependenciesMissingException.prototype), 'constructor', this).call(this);
this.name = 'DependenciesMissingException';
this.message = 'Module error. ' + moduleName + ' depend on ' + dependModules + ' but no dependencies were ' + 'resolved. Maybe you need to install and register theses modules in a microframework?';
_super.call(this);
this.name = "DependenciesMissingException";
this.message = "Module error. " + moduleName + " depend on " + dependModules + " but no dependencies were " +
"resolved. Maybe you need to install and register theses modules in a microframework?";
}
return DependenciesMissingException;
})(Error);
exports.DependenciesMissingException = DependenciesMissingException;
}(Error));
exports.DependenciesMissingException = DependenciesMissingException;
//# sourceMappingURL=DependenciesMissingException.js.map

@@ -1,31 +0,24 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MicroframeworkNameAlreadyExistException = (function (_Error) {
_inherits(MicroframeworkNameAlreadyExistException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var MicroframeworkNameAlreadyExistException = (function (_super) {
__extends(MicroframeworkNameAlreadyExistException, _super);
function MicroframeworkNameAlreadyExistException(name) {
_classCallCheck(this, MicroframeworkNameAlreadyExistException);
_get(Object.getPrototypeOf(MicroframeworkNameAlreadyExistException.prototype), 'constructor', this).call(this);
this.name = 'MicroframeworkNameAlreadyExistException';
_super.call(this);
this.name = "MicroframeworkNameAlreadyExistException";
if (name) {
throw new Error('Microframework without name already was bootstrapped once, you cannot create two ' + 'microframework instances without name. Please specify a name to your microframework instance on creation.');
} else {
throw new Error('Microframework with name ' + name + ' already was bootstrapped. You cannot bootstrap two ' + 'microframework instances with the same name. Please specify different name on your microframework instance creation.');
throw new Error("Microframework without name already was bootstrapped once, you cannot create two " +
"microframework instances without name. Please specify a name to your microframework instance on creation.");
}
else {
throw new Error("Microframework with name " + name + " already was bootstrapped. You cannot bootstrap two " +
"microframework instances with the same name. Please specify different name on your microframework instance creation.");
}
}
return MicroframeworkNameAlreadyExistException;
})(Error);
exports.MicroframeworkNameAlreadyExistException = MicroframeworkNameAlreadyExistException;
}(Error));
exports.MicroframeworkNameAlreadyExistException = MicroframeworkNameAlreadyExistException;
//# sourceMappingURL=MicroframeworkNameAlreadyExistException.js.map

@@ -1,27 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ModuleAlreadyRegisteredException = (function (_Error) {
_inherits(ModuleAlreadyRegisteredException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ModuleAlreadyRegisteredException = (function (_super) {
__extends(ModuleAlreadyRegisteredException, _super);
function ModuleAlreadyRegisteredException(moduleName) {
_classCallCheck(this, ModuleAlreadyRegisteredException);
_get(Object.getPrototypeOf(ModuleAlreadyRegisteredException.prototype), 'constructor', this).call(this);
this.name = 'ModuleAlreadyRegisteredException';
this.message = 'Module with such name (' + moduleName + ') already registered ';
_super.call(this);
this.name = "ModuleAlreadyRegisteredException";
this.message = "Module with such name (" + moduleName + ") already registered ";
}
return ModuleAlreadyRegisteredException;
})(Error);
exports.ModuleAlreadyRegisteredException = ModuleAlreadyRegisteredException;
}(Error));
exports.ModuleAlreadyRegisteredException = ModuleAlreadyRegisteredException;
//# sourceMappingURL=ModuleAlreadyRegisteredException.js.map

@@ -1,27 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ModuleConfigurationMissingException = (function (_Error) {
_inherits(ModuleConfigurationMissingException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ModuleConfigurationMissingException = (function (_super) {
__extends(ModuleConfigurationMissingException, _super);
function ModuleConfigurationMissingException(moduleName) {
_classCallCheck(this, ModuleConfigurationMissingException);
_get(Object.getPrototypeOf(ModuleConfigurationMissingException.prototype), 'constructor', this).call(this);
this.name = 'ModuleConfigurationMissingException';
this.message = 'Configuration for module ' + moduleName + ' is required, however its not set';
_super.call(this);
this.name = "ModuleConfigurationMissingException";
this.message = "Configuration for module " + moduleName + " is required, however its not set";
}
return ModuleConfigurationMissingException;
})(Error);
exports.ModuleConfigurationMissingException = ModuleConfigurationMissingException;
}(Error));
exports.ModuleConfigurationMissingException = ModuleConfigurationMissingException;
//# sourceMappingURL=ModuleConfigurationMissingException.js.map

@@ -1,27 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ModuleProblemsException = (function (_Error) {
_inherits(ModuleProblemsException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ModuleProblemsException = (function (_super) {
__extends(ModuleProblemsException, _super);
function ModuleProblemsException(message) {
_classCallCheck(this, ModuleProblemsException);
_get(Object.getPrototypeOf(ModuleProblemsException.prototype), 'constructor', this).call(this);
this.name = 'ModuleProblemsException';
this.message = 'Registered modules have a problems: ' + message;
_super.call(this);
this.name = "ModuleProblemsException";
this.message = "Registered modules have a problems: " + message;
}
return ModuleProblemsException;
})(Error);
exports.ModuleProblemsException = ModuleProblemsException;
}(Error));
exports.ModuleProblemsException = ModuleProblemsException;
//# sourceMappingURL=ModuleProblemsException.js.map

@@ -1,27 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ModuleWithoutNameException = (function (_Error) {
_inherits(ModuleWithoutNameException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ModuleWithoutNameException = (function (_super) {
__extends(ModuleWithoutNameException, _super);
function ModuleWithoutNameException(module) {
_classCallCheck(this, ModuleWithoutNameException);
_get(Object.getPrototypeOf(ModuleWithoutNameException.prototype), 'constructor', this).call(this);
this.name = 'ModuleWithoutNameException';
this.message = 'Invalid module has been supplied. Given module ' + JSON.stringify(module) + ' must have a name.';
_super.call(this);
this.name = "ModuleWithoutNameException";
this.message = "Invalid module has been supplied. Given module " + JSON.stringify(module) + " must have a name.";
}
return ModuleWithoutNameException;
})(Error);
exports.ModuleWithoutNameException = ModuleWithoutNameException;
}(Error));
exports.ModuleWithoutNameException = ModuleWithoutNameException;
//# sourceMappingURL=ModuleWithoutNameException.js.map

@@ -1,27 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var NoModulesLoadedException = (function (_Error) {
_inherits(NoModulesLoadedException, _Error);
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var NoModulesLoadedException = (function (_super) {
__extends(NoModulesLoadedException, _super);
function NoModulesLoadedException() {
_classCallCheck(this, NoModulesLoadedException);
_get(Object.getPrototypeOf(NoModulesLoadedException.prototype), 'constructor', this).call(this);
this.name = 'NoModulesLoadedException';
this.message = 'You did not register any modules into framework.';
_super.call(this);
this.name = "NoModulesLoadedException";
this.message = "You did not register any modules into framework.";
}
return NoModulesLoadedException;
})(Error);
exports.NoModulesLoadedException = NoModulesLoadedException;
}(Error));
exports.NoModulesLoadedException = NoModulesLoadedException;
//# sourceMappingURL=NoModulesLoadedException.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _path = require("path");
var path = _interopRequireWildcard(_path);
var _typediContainer = require("typedi/Container");
var _ModulesRegistry = require("./ModulesRegistry");
var _ConfigLoader = require("./ConfigLoader");
var _configuratorTsConfigurator = require("configurator.ts/Configurator");
var _MicroFrameworkRegistry = require("./MicroFrameworkRegistry");
var _exceptionMicroframeworkNameAlreadyExistException = require("./exception/MicroframeworkNameAlreadyExistException");
var path = require("path");
var Container_1 = require("typedi/Container");
var ModulesRegistry_1 = require("./ModulesRegistry");
var ConfigLoader_1 = require("./ConfigLoader");
var Configurator_1 = require("configurator.ts/Configurator");
var MicroFrameworkRegistry_1 = require("./MicroFrameworkRegistry");
var MicroframeworkNameAlreadyExistException_1 = require("./exception/MicroframeworkNameAlreadyExistException");
/**
* This class runs microframework and its specified modules.
*/
var MicroFrameworkBootstrapper = (function () {
function MicroFrameworkBootstrapper(nameOrSettings, settings, _configurator, modulesRegistry, configLoader) {
_classCallCheck(this, MicroFrameworkBootstrapper);
this._configurator = _configurator;
this.modulesRegistry = modulesRegistry;
if (typeof nameOrSettings === 'string') {
if (typeof nameOrSettings === "string") {
this._name = nameOrSettings;
this.settings = settings;
} else {
this._name = 'default';
}
else {
this._name = "default";
this.settings = nameOrSettings;

@@ -48,125 +26,108 @@ }

this.settings.srcDirectory = path.normalize(this.settings.srcDirectory);
if (!this.settings.baseDirectory) this.settings.baseDirectory = require('find-root')(this.settings.srcDirectory);
if (!_configurator) this._configurator = _configuratorTsConfigurator.defaultConfigurator;
if (!configLoader) configLoader = new _ConfigLoader.ConfigLoader(this.settings);
if (!this.settings.baseDirectory)
this.settings.baseDirectory = require("find-root")(this.settings.srcDirectory);
if (!_configurator)
this._configurator = Configurator_1.defaultConfigurator;
if (!configLoader)
configLoader = new ConfigLoader_1.ConfigLoader(this.settings);
configLoader.load();
this.configuration = this._configurator.get('framework') || {};
if (this.settings && !modulesRegistry) this.modulesRegistry = new _ModulesRegistry.ModuleRegistry(this.settings, this.configuration, this._configurator);
this.configuration = this._configurator.get("framework") || {};
if (this.settings && !modulesRegistry)
this.modulesRegistry = new ModulesRegistry_1.ModuleRegistry(this.settings, this.configuration, this._configurator);
}
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
/**
* Gets the Container of the typedi module.
*/
_createClass(MicroFrameworkBootstrapper, [{
key: "setName",
// todo: later rename this to rootDirectory too
Object.defineProperty(MicroFrameworkBootstrapper.prototype, "container", {
// -------------------------------------------------------------------------
// Public Methods
// Accessors
// -------------------------------------------------------------------------
/**
* Sets the name used by microframework. Note that name must be set before bootstrapping the framework.
* Gets the Container of the typedi module.
*/
value: function setName(name) {
if (_MicroFrameworkRegistry.MicroFrameworkRegistry.has(name || 'default')) throw new _exceptionMicroframeworkNameAlreadyExistException.MicroframeworkNameAlreadyExistException(name);
this._name = name || 'default';
return this;
}
/**
* Sets the settings. Used if settings was not passed during object construction. Note that settings must be set
* before bootstrapping the framework.
*/
}, {
key: "setSettings",
value: function setSettings(settings) {
this.settings = settings;
return this;
}
/**
* Registers all given modules in the framework.
*/
}, {
key: "registerModules",
value: function registerModules(modules) {
this.modulesRegistry.registerModules(modules);
return this;
}
/**
* Registers a new module in the framework.
*/
}, {
key: "registerModule",
value: function registerModule(module) {
this.modulesRegistry.registerModule(module);
return this;
}
}, {
key: "findModuleByType",
value: function findModuleByType(type) {
return this.modulesRegistry.findModuleByType(type);
}
/**
* Bootstraps the framework and all its modules.
*/
}, {
key: "bootstrap",
value: function bootstrap() {
var _this = this;
_MicroFrameworkRegistry.MicroFrameworkRegistry.put(this);
return this.modulesRegistry.bootstrapAllModules().then(function () {
return _this;
});
}
/**
* Shutdowns the framework and all its modules.
*/
}, {
key: "shutdown",
value: function shutdown() {
_MicroFrameworkRegistry.MicroFrameworkRegistry.remove(this);
return this.modulesRegistry.shutdownAllModules();
}
}, {
key: "container",
get: function get() {
return _typediContainer.Container;
}
}, {
key: "name",
get: function get() {
get: function () {
return Container_1.Container;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MicroFrameworkBootstrapper.prototype, "name", {
get: function () {
return this._name;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MicroFrameworkBootstrapper.prototype, "configurator", {
/**
* Gets the configurator used to config framework and its modules.
*/
}, {
key: "configurator",
get: function get() {
get: function () {
return this._configurator; // todo: find the way to remove global dependency
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MicroFrameworkBootstrapper.prototype, "rootDirectory", {
/**
* Gets the root directory of the running application.
*/
}, {
key: "rootDirectory",
get: function get() {
return this.settings.baseDirectory;
}
}]);
get: function () {
return this.settings.baseDirectory; // todo: later rename this to rootDirectory too
},
enumerable: true,
configurable: true
});
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
/**
* Sets the name used by microframework. Note that name must be set before bootstrapping the framework.
*/
MicroFrameworkBootstrapper.prototype.setName = function (name) {
if (MicroFrameworkRegistry_1.MicroFrameworkRegistry.has(name || "default"))
throw new MicroframeworkNameAlreadyExistException_1.MicroframeworkNameAlreadyExistException(name);
this._name = name || "default";
return this;
};
/**
* Sets the settings. Used if settings was not passed during object construction. Note that settings must be set
* before bootstrapping the framework.
*/
MicroFrameworkBootstrapper.prototype.setSettings = function (settings) {
this.settings = settings;
return this;
};
/**
* Registers all given modules in the framework.
*/
MicroFrameworkBootstrapper.prototype.registerModules = function (modules) {
this.modulesRegistry.registerModules(modules);
return this;
};
/**
* Registers a new module in the framework.
*/
MicroFrameworkBootstrapper.prototype.registerModule = function (module) {
this.modulesRegistry.registerModule(module);
return this;
};
MicroFrameworkBootstrapper.prototype.findModuleByType = function (type) {
return this.modulesRegistry.findModuleByType(type);
};
/**
* Bootstraps the framework and all its modules.
*/
MicroFrameworkBootstrapper.prototype.bootstrap = function () {
var _this = this;
MicroFrameworkRegistry_1.MicroFrameworkRegistry.put(this);
return this.modulesRegistry.bootstrapAllModules().then(function () { return _this; });
};
/**
* Shutdowns the framework and all its modules.
*/
MicroFrameworkBootstrapper.prototype.shutdown = function () {
MicroFrameworkRegistry_1.MicroFrameworkRegistry.remove(this);
return this.modulesRegistry.shutdownAllModules();
};
return MicroFrameworkBootstrapper;
})();
exports.MicroFrameworkBootstrapper = MicroFrameworkBootstrapper;
}());
exports.MicroFrameworkBootstrapper = MicroFrameworkBootstrapper;
//# sourceMappingURL=MicroFrameworkBootstrapper.js.map

@@ -1,1 +0,2 @@

"use strict";
"use strict";
//# sourceMappingURL=MicroFrameworkConfig.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var MicroFrameworkRegistry = (function () {
function MicroFrameworkRegistry() {
_classCallCheck(this, MicroFrameworkRegistry);
}
// -------------------------------------------------------------------------
// Public Static Methods
// -------------------------------------------------------------------------
MicroFrameworkRegistry.put = function (microFramework) {
this.instances.push(microFramework);
};
MicroFrameworkRegistry.remove = function (microFramework) {
var index = this.instances.indexOf(microFramework);
if (index !== -1)
this.instances.splice(index, 1);
};
MicroFrameworkRegistry.get = function (name) {
return this.instances.reduce(function (found, instance) { return instance.name === name ? instance : found; }, undefined);
};
MicroFrameworkRegistry.has = function (name) {
return this.get(name) !== undefined;
};
// -------------------------------------------------------------------------
// Private Static Properties
// -------------------------------------------------------------------------
_createClass(MicroFrameworkRegistry, null, [{
key: "put",
// -------------------------------------------------------------------------
// Public Static Methods
// -------------------------------------------------------------------------
value: function put(microFramework) {
this.instances.push(microFramework);
}
}, {
key: "remove",
value: function remove(microFramework) {
var index = this.instances.indexOf(microFramework);
if (index !== -1) this.instances.splice(index, 1);
}
}, {
key: "get",
value: function get(name) {
return this.instances.reduce(function (found, instance) {
return instance.name === name ? instance : found;
}, undefined);
}
}, {
key: "has",
value: function has(name) {
return this.get(name) !== undefined;
}
}]);
MicroFrameworkRegistry.instances = [];
return MicroFrameworkRegistry;
})();
}());
exports.MicroFrameworkRegistry = MicroFrameworkRegistry;
MicroFrameworkRegistry.instances = [];
//# sourceMappingURL=MicroFrameworkRegistry.js.map

@@ -1,1 +0,2 @@

"use strict";
"use strict";
//# sourceMappingURL=MicroFrameworkSettings.js.map

@@ -1,113 +0,95 @@

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _path = require("path");
var path = _interopRequireWildcard(_path);
"use strict";
var path = require("path");
var MicroFrameworkUtils = (function () {
function MicroFrameworkUtils() {
_classCallCheck(this, MicroFrameworkUtils);
}
_createClass(MicroFrameworkUtils, null, [{
key: 'getEnvironmentFile',
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
value: function getEnvironmentFile(file, environment) {
var baseName = path.basename(file);
var extension = path.extname(file);
var fileName = baseName.substr(0, baseName.lastIndexOf(extension)) + '.' + environment + extension;
return path.dirname(file) + '/' + fileName;
}
}, {
key: 'sortModulesByDependencies',
value: function sortModulesByDependencies(modules) {
var modulesDependencyTree = modules.reduce(function (object, mod) {
if (mod.getDependentModules) object[mod.getName()] = mod.getDependentModules();
return object;
}, {});
var sortedModuleNames = this.recursiveDependencies(modulesDependencyTree);
modules.sort(function (a, b) {
return sortedModuleNames.indexOf(a.getName()) - sortedModuleNames.indexOf(b.getName());
});
}
}, {
key: 'deepClone',
value: function deepClone(object) {
var newObj = object instanceof Array ? [] : {};
var obj = object;
for (var i in obj) {
if (obj[i] && typeof obj[i] == "object") {
newObj[i] = this.deepClone(obj[i]);
} else {
newObj[i] = obj[i];
}
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
MicroFrameworkUtils.getEnvironmentFile = function (file, environment) {
var baseName = path.basename(file);
var extension = path.extname(file);
var fileName = baseName.substr(0, baseName.lastIndexOf(extension)) + "." + environment + extension;
return path.dirname(file) + "/" + fileName;
};
MicroFrameworkUtils.sortModulesByDependencies = function (modules) {
var modulesDependencyTree = modules.reduce(function (object, mod) {
if (mod.getDependentModules)
object[mod.getName()] = mod.getDependentModules();
return object;
}, {});
var sortedModuleNames = this.recursiveDependencies(modulesDependencyTree);
modules.sort(function (a, b) {
return sortedModuleNames.indexOf(a.getName()) - sortedModuleNames.indexOf(b.getName());
});
};
MicroFrameworkUtils.deepClone = function (object) {
var newObj = (object instanceof Array) ? [] : {};
var obj = object;
for (var i in obj) {
if (obj[i] && typeof obj[i] === "object") {
newObj[i] = this.deepClone(obj[i]);
}
return newObj;
else {
newObj[i] = obj[i];
}
}
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
}, {
key: 'recursiveDependencies',
value: function recursiveDependencies(dependencies, root) {
var nodes = {};
var nodeCount = 0;
var ready = [];
var output = [];
// build the graph
function add(element) {
nodeCount++;
nodes[element] = { needs: [], neededBy: [], name: element };
if (dependencies[element]) {
dependencies[element].forEach(function (dependency) {
if (!nodes[dependency]) add(dependency);
nodes[element].needs.push(nodes[dependency]);
nodes[dependency].neededBy.push(nodes[element]);
});
}
if (!nodes[element].needs.length) ready.push(nodes[element]);
}
if (root) {
add(root);
} else {
for (var element in dependencies) {
if (!nodes[element]) add(element);
}
}
//sort the graph
while (ready.length) {
var dependency = ready.pop();
output.push(dependency.getName);
dependency.neededBy.forEach(function (element) {
element.needs = element.needs.filter(function (x) {
return x != dependency;
});
if (!element.needs.length) ready.push(element);
return newObj;
};
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
MicroFrameworkUtils.recursiveDependencies = function (dependencies, root) {
var nodes = {};
var nodeCount = 0;
var ready = [];
var output = [];
// build the graph
function add(element) {
nodeCount++;
nodes[element] = { needs: [], neededBy: [], name: element };
if (dependencies[element]) {
dependencies[element].forEach(function (dependency) {
if (!nodes[dependency])
add(dependency);
nodes[element].needs.push(nodes[dependency]);
nodes[dependency].neededBy.push(nodes[element]);
});
}
//error-check
if (output.length != nodeCount) {
throw 'circular dependency in modules detected: ' + JSON.stringify(dependencies);
if (!nodes[element].needs.length)
ready.push(nodes[element]);
}
if (root) {
add(root);
}
else {
for (var element in dependencies) {
if (!nodes[element])
add(element);
}
return output;
}
}]);
// sort the graph
var _loop_1 = function() {
var dependency = ready.pop();
output.push(dependency.getName);
dependency.neededBy.forEach(function (element) {
element.needs = element.needs.filter(function (x) {
return x !== dependency;
});
if (!element.needs.length)
ready.push(element);
});
};
while (ready.length) {
_loop_1();
}
// error-check
if (output.length !== nodeCount) {
throw "circular dependency in modules detected: " + JSON.stringify(dependencies);
}
return output;
};
return MicroFrameworkUtils;
})();
exports.MicroFrameworkUtils = MicroFrameworkUtils;
}());
exports.MicroFrameworkUtils = MicroFrameworkUtils;
//# sourceMappingURL=MicroFrameworkUtils.js.map

@@ -1,1 +0,2 @@

"use strict";
"use strict";
//# sourceMappingURL=Module.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _typediContainer = require("typedi/Container");
var _MicroFrameworkUtils = require("./MicroFrameworkUtils");
var _exceptionDependenciesMissingException = require("./exception/DependenciesMissingException");
var _exceptionModuleConfigurationMissingException = require("./exception/ModuleConfigurationMissingException");
var _exceptionModuleProblemsException = require("./exception/ModuleProblemsException");
var _exceptionNoModulesLoadedException = require("./exception/NoModulesLoadedException");
var _exceptionModuleAlreadyRegisteredException = require("./exception/ModuleAlreadyRegisteredException");
var _exceptionModuleWithoutNameException = require("./exception/ModuleWithoutNameException");
var Container_1 = require("typedi/Container");
var MicroFrameworkUtils_1 = require("./MicroFrameworkUtils");
var DependenciesMissingException_1 = require("./exception/DependenciesMissingException");
var ModuleConfigurationMissingException_1 = require("./exception/ModuleConfigurationMissingException");
var ModuleProblemsException_1 = require("./exception/ModuleProblemsException");
var NoModulesLoadedException_1 = require("./exception/NoModulesLoadedException");
var ModuleAlreadyRegisteredException_1 = require("./exception/ModuleAlreadyRegisteredException");
var ModuleWithoutNameException_1 = require("./exception/ModuleWithoutNameException");
/**
* Registry for framework modules.
*/
var ModuleRegistry = (function () {

@@ -35,6 +17,3 @@ // -------------------------------------------------------------------------

// -------------------------------------------------------------------------
function ModuleRegistry(settings, configuration, configurator) {
_classCallCheck(this, ModuleRegistry);
this.settings = settings;

@@ -48,3 +27,2 @@ this.configuration = configuration;

}
// -------------------------------------------------------------------------

@@ -56,132 +34,97 @@ // Public Methods

*/
_createClass(ModuleRegistry, [{
key: "registerModules",
value: function registerModules(modules) {
var _this = this;
modules.forEach(function (mod) {
return _this.registerModule(mod);
});
ModuleRegistry.prototype.registerModules = function (modules) {
var _this = this;
modules.forEach(function (mod) { return _this.registerModule(mod); });
};
/**
* Registers a new module in the framework.
*/
ModuleRegistry.prototype.registerModule = function (module) {
if (!module.getName())
throw new ModuleWithoutNameException_1.ModuleWithoutNameException(module);
var moduleWithSameName = this.modules.reduce(function (found, mod) { return mod.getName() === module.getName() ? mod : found; }, undefined);
if (moduleWithSameName)
throw new ModuleAlreadyRegisteredException_1.ModuleAlreadyRegisteredException(module.getName());
this.modules.push(module);
};
/**
* Finds a module with given type registered in the registry.
*/
ModuleRegistry.prototype.findModuleByType = function (type) {
return this.modules.reduce(function (found, module) { return module instanceof type ? module : found; }, undefined);
};
/**
* Bootstraps all modules.
*/
ModuleRegistry.prototype.bootstrapAllModules = function () {
var _this = this;
if (this.modules.length === 0)
throw new NoModulesLoadedException_1.NoModulesLoadedException();
// sort modules in a
try {
MicroFrameworkUtils_1.MicroFrameworkUtils.sortModulesByDependencies(this.modules);
}
/**
* Registers a new module in the framework.
*/
}, {
key: "registerModule",
value: function registerModule(module) {
if (!module.getName()) throw new _exceptionModuleWithoutNameException.ModuleWithoutNameException(module);
var moduleWithSameName = this.modules.reduce(function (found, mod) {
return mod.getName() === module.getName() ? mod : found;
}, undefined);
if (moduleWithSameName) throw new _exceptionModuleAlreadyRegisteredException.ModuleAlreadyRegisteredException(module.getName());
this.modules.push(module);
catch (error) {
throw new ModuleProblemsException_1.ModuleProblemsException(error.message ? error.message : "");
}
/**
* Finds a module with given type registered in the registry.
*/
}, {
key: "findModuleByType",
value: function findModuleByType(type) {
return this.modules.reduce(function (found, module) {
return module instanceof type ? module : found;
}, undefined);
}
/**
* Bootstraps all modules.
*/
}, {
key: "bootstrapAllModules",
value: function bootstrapAllModules() {
var _this2 = this;
if (this.modules.length === 0) throw new _exceptionNoModulesLoadedException.NoModulesLoadedException();
// sort modules in a
try {
_MicroFrameworkUtils.MicroFrameworkUtils.sortModulesByDependencies(this.modules);
} catch (error) {
throw new _exceptionModuleProblemsException.ModuleProblemsException(error.message ? error.message : '');
}
this.modules.forEach(function (mod) {
var config = {
frameworkSettings: _MicroFrameworkUtils.MicroFrameworkUtils.deepClone(_this2.settings),
debugMode: _this2.configuration.debugMode || false,
container: _typediContainer.Container
};
mod.init(config, _this2.findConfigurationForModule(mod), _this2.findDependantModulesForModule(mod));
this.modules.forEach(function (mod) {
var config = {
frameworkSettings: MicroFrameworkUtils_1.MicroFrameworkUtils.deepClone(_this.settings),
debugMode: _this.configuration.debugMode || false,
container: Container_1.Container
};
mod.init(config, _this.findConfigurationForModule(mod), _this.findDependantModulesForModule(mod));
});
if (this.configuration.bootstrap && this.configuration.bootstrap.timeout > 0) {
return new Promise(function (ok, fail) {
setTimeout(function () { return ok(_this.bootstrapModules()); }, _this.configuration.bootstrap.timeout);
});
if (this.configuration.bootstrap && this.configuration.bootstrap.timeout > 0) {
return new Promise(function (ok, fail) {
setTimeout(function () {
return ok(_this2.bootstrapModules());
}, _this2.configuration.bootstrap.timeout);
});
}
return this.bootstrapModules();
}
/**
* Shutdowns all modules.
*/
}, {
key: "shutdownAllModules",
value: function shutdownAllModules() {
return Promise.all(this.modules.map(function (mod) {
return mod.onShutdown();
})).then(function () {});
}
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
}, {
key: "bootstrapModules",
value: function bootstrapModules() {
var _this3 = this;
return Promise.all(this.modules.map(function (mod) {
return mod.onBootstrap();
})).then(function () {
return Promise.all(_this3.modules.map(function (module) {
return module.afterBootstrap ? module.afterBootstrap() : undefined;
}));
}).then(function () {})["catch"](function (err) {
return _this3.shutdownAllModules().then(function () {
throw err;
});
});
}
}, {
key: "findConfigurationForModule",
value: function findConfigurationForModule(module) {
if (!module.getConfigurationName || !module.getConfigurationName()) return undefined;
var config = this.configurator.get(module.getConfigurationName());
if (!config && module.isConfigurationRequired && module.isConfigurationRequired()) throw new _exceptionModuleConfigurationMissingException.ModuleConfigurationMissingException(module.getName());
return config;
}
}, {
key: "findDependantModulesForModule",
value: function findDependantModulesForModule(module) {
var _this4 = this;
if (!module.getDependentModules || !module.getDependentModules() || !module.getDependentModules().length) return undefined;
var missingDependantModuleNames = [];
var dependantModules = module.getDependentModules().map(function (dependantModuleName) {
var dependantModule = _this4.modules.reduce(function (found, mod) {
return mod.getName() === dependantModuleName ? mod : found;
}, undefined);
if (!dependantModule) missingDependantModuleNames.push(dependantModuleName);
return dependantModule;
});
if (missingDependantModuleNames.length > 0) throw new _exceptionDependenciesMissingException.DependenciesMissingException(module.getName(), missingDependantModuleNames);
return dependantModules;
}
}]);
return this.bootstrapModules();
};
/**
* Shutdowns all modules.
*/
ModuleRegistry.prototype.shutdownAllModules = function () {
return Promise.all(this.modules.map(function (mod) { return mod.onShutdown(); }))
.then(function () { });
};
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
ModuleRegistry.prototype.bootstrapModules = function () {
var _this = this;
return Promise.all(this.modules.map(function (mod) { return mod.onBootstrap(); }))
.then(function () { return Promise.all(_this.modules.map(function (module) { return module.afterBootstrap ? module.afterBootstrap() : undefined; })); })
.then(function () { })
.catch(function (err) {
return _this.shutdownAllModules().then(function () { throw err; });
});
};
ModuleRegistry.prototype.findConfigurationForModule = function (module) {
if (!module.getConfigurationName || !module.getConfigurationName())
return undefined;
var config = this.configurator.get(module.getConfigurationName());
if (!config && module.isConfigurationRequired && module.isConfigurationRequired())
throw new ModuleConfigurationMissingException_1.ModuleConfigurationMissingException(module.getName());
return config;
};
ModuleRegistry.prototype.findDependantModulesForModule = function (module) {
var _this = this;
if (!module.getDependentModules || !module.getDependentModules() || !module.getDependentModules().length)
return undefined;
var missingDependantModuleNames = [];
var dependantModules = module.getDependentModules().map(function (dependantModuleName) {
var dependantModule = _this.modules.reduce(function (found, mod) { return mod.getName() === dependantModuleName ? mod : found; }, undefined);
if (!dependantModule)
missingDependantModuleNames.push(dependantModuleName);
return dependantModule;
});
if (missingDependantModuleNames.length > 0)
throw new DependenciesMissingException_1.DependenciesMissingException(module.getName(), missingDependantModuleNames);
return dependantModules;
};
return ModuleRegistry;
})();
exports.ModuleRegistry = ModuleRegistry;
}());
exports.ModuleRegistry = ModuleRegistry;
//# sourceMappingURL=ModulesRegistry.js.map
{
"name": "microframework",
"version": "0.3.1",
"private": false,
"version": "0.4.0",
"description": "Micro framework is a bundle of express.js, mongodb ODM, validator, dependancy injection framework and restful controllers for your apps using Typescript",

@@ -9,10 +10,10 @@ "license": "Apache-2.0",

"name": "Umed Khudoiberdiev",
"email": "zarrhost@gmail.com"
"email": "pleerock.me@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/PLEEROCK/microframework.git"
"url": "https://github.com/pleerock/microframework.git"
},
"bugs": {
"url": "https://github.com/PLEEROCK/microframework/issues"
"url": "https://github.com/pleerock/microframework/issues"
},

@@ -24,29 +25,27 @@ "tags": [

],
"typescript": {
"definitions": [
"index.d.ts"
]
},
"dependencies": {
"configurator.ts": "~0.1.0",
"configurator.ts": "~0.2.0",
"find-root": "0.1.1",
"fs": "^0.0.2",
"path": "^0.12.7",
"typedi": "~0.1.0"
"typedi": "~0.2.0"
},
"devDependencies": {
"chai": "^3.4.1",
"chai-as-promised": "^5.2.0",
"del": "^2.0.2",
"dts-generator": "^1.6.2",
"gulp": "^3.9.0",
"gulp-mocha": "^2.2.0",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.0",
"gulp-babel": "^5.2.1",
"gulp-plumber": "^1.0.1",
"gulp-typescript": "^2.9.0",
"run-sequence": "^1.1.4",
"tsd": "^0.6.4",
"typescript": "^1.6.2"
},
"scripts": {
"postversion": "./node_modules/.bin/gulp package"
"gulp-tslint": "^4.3.1",
"gulpclass": "0.1.0",
"mocha": "^2.3.4",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0",
"tslint": "^3.3.0",
"tslint-stylish": "^2.1.0-beta",
"typescript": "^1.8.0",
"typings": "^0.6.6"
}
}

@@ -23,10 +23,12 @@ # MicroFramework

2. Install required tsd dependencies:
2. Use [typings](https://github.com/typings/typings) to install all required definition dependencies.
`tsd install es6-promise express mongodb --save`
`typings install`
3. Link definitions of the installed npm modules:
3. ES6 features are used, so you may want to install [es6-shim](https://github.com/paulmillr/es6-shim) too:
`tsd link`
`npm install es6-shim --save`
you may want to `require("es6-shim");` in your app
## Usage

@@ -36,3 +38,3 @@

```typescript
```javascript
import {MicroFrameworkBootstrapper} from "microframework/MicroFrameworkBootstrapper";

@@ -54,4 +56,4 @@ import {ExpressModule} from "microframework-express/ExpressModule";

.bootstrap()
.then(result => console.log('Module is running. Open localhost:3000'))
.catch(error => console.error('Error: ', error));
.then(result => console.log("Module is running. Open localhost:3000"))
.catch(error => console.error("Error: ", error));
```

@@ -80,3 +82,3 @@

```typescript
```javascript
import {JsonController, Get} from "controllers.ts/Annotations";

@@ -88,7 +90,7 @@ import {Response, Request} from "express";

@Get('/questions')
@Get("/questions")
all(): any[] {
return [
{ title: 'Which processor to choose?', text: 'Which processor is better: Core i5 or Core i7?' },
{ title: 'When new star wars gonna be released?', text: 'When star wars gonna be released? I think in december' }
{ title: "Which processor to choose?", text: "Which processor is better: Core i5 or Core i7?" },
{ title: "When new star wars gonna be released?", text: "When star wars gonna be released? I think in december" }
];

@@ -103,10 +105,10 @@ }

* [microframework-express](https://github.com/PLEEROCK/microframework-express) - integration with [express.js][1]
* [microframework-typeodm](https://github.com/PLEEROCK/microframework-typeodm) - integration with [TypeODM][2]
* [microframework-controllers.ts](https://github.com/PLEEROCK/microframework-controllers.ts) - integration with [controllers.ts][4]
* [microframework-validator.ts](https://github.com/PLEEROCK/microframework-validator.ts) - integration with [validator.ts][5]
* [microframework-event-dispatcher.ts](https://github.com/PLEEROCK/microframework-event-dispatcher.ts) - integration with [event-dispatcher.ts][7]
* [microframework-winston](https://github.com/PLEEROCK/microframework-winston) - integration with [winston][8]
* [microframework-elasticsearch](https://github.com/PLEEROCK/microframework-elasticsearch) - integration with [elasticsearch][9]
* [microframework-rabbit.ts](https://github.com/PLEEROCK/microframework-rabbit.ts) - integration with [rabbit.js][10]
* [microframework-express](https://github.com/pleerock/microframework-express) - integration with [express.js][1]
* [microframework-typeodm](https://github.com/pleerock/microframework-typeodm) - integration with [TypeODM][2]
* [microframework-controllers.ts](https://github.com/pleerock/microframework-controllers.ts) - integration with [controllers.ts][4]
* [microframework-validator.ts](https://github.com/pleerock/microframework-validator.ts) - integration with [validator.ts][5]
* [microframework-event-dispatcher.ts](https://github.com/pleerock/microframework-event-dispatcher.ts) - integration with [event-dispatcher.ts][7]
* [microframework-winston](https://github.com/pleerock/microframework-winston) - integration with [winston][8]
* [microframework-elasticsearch](https://github.com/pleerock/microframework-elasticsearch) - integration with [elasticsearch][9]
* [microframework-rabbit.ts](https://github.com/pleerock/microframework-rabbit.ts) - integration with [rabbit.js][10]

@@ -118,12 +120,15 @@ ## Todos

* more modules
* add ability to include other configs by include path in the object?
* add yo generator
* good to have todo mvc sample
[1]: http://expressjs.com/
[2]: https://github.com/PLEEROCK/typeodm
[3]: https://github.com/PLEEROCK/typedi
[4]: https://github.com/PLEEROCK/controllers.ts
[5]: https://github.com/PLEEROCK/validator.ts
[6]: https://github.com/PLEEROCK/configurator.ts
[7]: https://github.com/PLEEROCK/event-dispatcher.ts
[2]: https://github.com/pleerock/typeodm
[3]: https://github.com/pleerock/typedi
[4]: https://github.com/pleerock/controllers.ts
[5]: https://github.com/pleerock/validator.ts
[6]: https://github.com/pleerock/configurator.ts
[7]: https://github.com/pleerock/event-dispatcher.ts
[8]: https://github.com/winstonjs/winston
[9]: https://github.com/elastic/elasticsearch-js
[10]: https://github.com/squaremo/rabbit.js/
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc