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.0.3 to 0.0.4

MicroFrameworkRunOptions.js

39

microframework.d.ts

@@ -13,3 +13,3 @@ declare module 'microframework/MicroFrameworkConfig' {

};
odm?: {
typeodm?: {
driver: string;

@@ -26,7 +26,25 @@ documentsDirectories?: string[];

}
declare module 'microframework/MicroFrameworkRunOptions' {
export interface MicroFrameworkRunOptions {
baseDirectory: string;
configurationFiles?: string[];
parametersFiles?: string[];
controllersDirectories?: string[];
odmDocumentsDirectories?: string[];
odmSubscribersDirectories?: string[];
environment?: string;
}
}
declare module 'microframework/MicroFrameworkUtils' {
export class MicroFrameworkUtils {
static getEnvironmentFile(file: string, environment: string): string;
}
}
declare module 'microframework/MicroFrameworkRunner' {
import { Express } from "express";
import { ConnectionManager } from "typeodm/connection/ConnectionManager";
import { MicroFrameworkConfig } from 'microframework/MicroFrameworkConfig';
import { Server } from "http";
import { MicroFrameworkRunOptions } from 'microframework/MicroFrameworkRunOptions';
/**

@@ -37,11 +55,14 @@ * MicroFramework is a bundle of express.js, mongodb ODM, dependancy injection framework and restful controllers for

export class MicroFrameworkRunner {
private directory;
private configuration;
private options;
static DEFAULT_ODM_DOCUMENT_DIRECTORY: string;
static DEFAULT_ODM_SUBSCRIBER_DIRECTORY: string;
static DEFAULT_CONTROLLER_DIRECTORY: string;
static DEFAULT_CONFIG_DIRECTORY: string;
static DEFAULT_CONFIG_FILE: string;
static DEFAULT_PARAMETERS_FILE: string;
private _express;
private _odmConnectionManager;
private _expressServer;
constructor(directory: string, configuration: MicroFrameworkConfig);
private configuration;
constructor(options: MicroFrameworkRunOptions);
express: Express;

@@ -54,4 +75,12 @@ expressServer: Server;

private setupControllers();
private getConfigFiles();
private getParameterFiles();
private getOdmDocumentDirectories();
private getOdmSubscriberDirectories();
private getControllerDirectories();
private loadConfigurations();
private loadParameters();
private requireEnvironmentFile(file);
}
}

@@ -1,12 +0,12 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
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; }; })();
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 _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"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

@@ -17,2 +17,6 @@ var _bodyParser = require('body-parser');

var _fs = require('fs');
var fs = _interopRequireWildcard(_fs);
var _typediContainer = require("typedi/Container");

@@ -28,2 +32,6 @@

var _tConfiguratorConfigurator = require("t-configurator/Configurator");
var _MicroFrameworkUtils = require("./MicroFrameworkUtils");
/**

@@ -39,7 +47,9 @@ * MicroFramework is a bundle of express.js, mongodb ODM, dependancy injection framework and restful controllers for

function MicroFrameworkRunner(directory, configuration) {
function MicroFrameworkRunner(options) {
_classCallCheck(this, MicroFrameworkRunner);
this.directory = directory;
this.configuration = configuration;
this.options = options;
this.loadConfigurations();
this.loadParameters();
this.configuration = _tConfiguratorConfigurator.defaultConfigurator.getAll();
}

@@ -56,3 +66,3 @@

_createClass(MicroFrameworkRunner, [{
key: "run",
key: 'run',

@@ -67,6 +77,6 @@ // -------------------------------------------------------------------------

this.setupExpress();
if (this.configuration.odm) promises.push(this.setupODM());
if (this.configuration.typeodm) promises.push(this.setupODM());
return Promise.all(promises).then(function () {
return _this.setupControllers();
}).then(function () {})["catch"](function (err) {
}).then(function () {})['catch'](function (err) {
if (_this._expressServer) _this._expressServer.close();

@@ -81,15 +91,13 @@ throw err;

}, {
key: "setupODM",
key: 'setupODM',
value: function setupODM() {
var documentDirectories = this.configuration.odm.documentsDirectories || [this.directory + '/' + MicroFrameworkRunner.DEFAULT_ODM_DOCUMENT_DIRECTORY];
var subscriberDirectories = this.configuration.odm.subscribersDirectories || [this.directory + '/' + MicroFrameworkRunner.DEFAULT_ODM_SUBSCRIBER_DIRECTORY];
this._odmConnectionManager = _typediContainer.Container.get(_typeodmConnectionConnectionManager.ConnectionManager);
this._odmConnectionManager.container = _typediContainer.Container;
if (this.configuration.odm.driver === 'mongodb') this._odmConnectionManager.addConnection(new _typeodmDriverMongodbDriver.MongodbDriver(require('mongodb')));
this._odmConnectionManager.importDocumentsFromDirectories(documentDirectories);
this._odmConnectionManager.importSubscribersFromDirectories(subscriberDirectories);
return this._odmConnectionManager.getConnection().connect(this.configuration.odm.connection);
if (this.configuration.typeodm.driver === 'mongodb') this._odmConnectionManager.addConnection(new _typeodmDriverMongodbDriver.MongodbDriver(require('mongodb')));
this._odmConnectionManager.importDocumentsFromDirectories(this.getOdmDocumentDirectories());
this._odmConnectionManager.importSubscribersFromDirectories(this.getOdmSubscriberDirectories());
return this._odmConnectionManager.getConnection().connect(this.configuration.typeodm.connection);
}
}, {
key: "setupExpress",
key: 'setupExpress',
value: function setupExpress() {

@@ -121,7 +129,5 @@ var port = (this.configuration.express ? this.configuration.express.port : undefined) || 3000;

}, {
key: "setupControllers",
key: 'setupControllers',
value: function setupControllers() {
var controllersDirectories = this.configuration.controllers ? this.configuration.controllers.controllerDirectories : null;
controllersDirectories = controllersDirectories || [this.directory + '/' + MicroFrameworkRunner.DEFAULT_CONTROLLER_DIRECTORY];
_typeControllersControllerUtils.ControllerUtils.requireAll(controllersDirectories);
_typeControllersControllerUtils.ControllerUtils.requireAll(this.getControllerDirectories());
_typeControllersActionRegistry.defaultActionRegistry.container = _typediContainer.Container;

@@ -131,3 +137,84 @@ _typeControllersActionRegistry.defaultActionRegistry.registerActions(this._express); // register actions in the app

}, {
key: "express",
key: 'getConfigFiles',
value: function getConfigFiles() {
return this.options.configurationFiles || [this.options.baseDirectory + '/' + MicroFrameworkRunner.DEFAULT_CONFIG_DIRECTORY + '/' + MicroFrameworkRunner.DEFAULT_CONFIG_FILE];
}
}, {
key: 'getParameterFiles',
value: function getParameterFiles() {
return this.options.parametersFiles || [this.options.baseDirectory + '/' + MicroFrameworkRunner.DEFAULT_CONFIG_DIRECTORY + '/' + MicroFrameworkRunner.DEFAULT_PARAMETERS_FILE];
}
}, {
key: 'getOdmDocumentDirectories',
value: function getOdmDocumentDirectories() {
return this.options.odmDocumentsDirectories || [this.options.baseDirectory + '/' + MicroFrameworkRunner.DEFAULT_ODM_DOCUMENT_DIRECTORY];
}
}, {
key: 'getOdmSubscriberDirectories',
value: function getOdmSubscriberDirectories() {
return this.options.odmSubscribersDirectories || [this.options.baseDirectory + '/' + MicroFrameworkRunner.DEFAULT_ODM_SUBSCRIBER_DIRECTORY];
}
}, {
key: 'getControllerDirectories',
value: function getControllerDirectories() {
return this.options.controllersDirectories || [this.options.baseDirectory + '/' + MicroFrameworkRunner.DEFAULT_CONTROLLER_DIRECTORY];
}
}, {
key: 'loadConfigurations',
value: function loadConfigurations() {
var _this2 = this;
var configFiles = this.getConfigFiles();
configFiles.forEach(function (file) {
return _tConfiguratorConfigurator.defaultConfigurator.addConfiguration(require(file));
});
configFiles.map(function (file) {
return _this2.requireEnvironmentFile(file);
}).filter(function (envFile) {
return !!envFile;
}).forEach(function (envFile) {
return _tConfiguratorConfigurator.defaultConfigurator.addConfiguration(envFile);
});
}
}, {
key: 'loadParameters',
value: function loadParameters() {
var _this3 = 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 (fileName) {
return require(fileName);
}).forEach(function (file) {
return merge(file, parameters);
});
parametersFiles.map(function (fileName) {
return _this3.requireEnvironmentFile(fileName);
}).filter(function (envFile) {
return !!envFile;
}).forEach(function (envFile) {
return merge(envFile, parameters);
});
_tConfiguratorConfigurator.defaultConfigurator.replaceWithParameters(parameters);
}
}, {
key: 'requireEnvironmentFile',
value: function requireEnvironmentFile(file) {
var environment = this.options.environment || process.env.NODE_ENV;
if (environment) {
var envConfig = _MicroFrameworkUtils.MicroFrameworkUtils.getEnvironmentFile(file, environment);
try {
fs.statSync(envConfig);
return require(envConfig);
} catch (e) {}
}
return undefined;
}
}, {
key: 'express',
get: function get() {

@@ -137,3 +224,3 @@ return this._express;

}, {
key: "expressServer",
key: 'expressServer',
get: function get() {

@@ -143,3 +230,3 @@ return this._expressServer;

}, {
key: "odmConnectionManager",
key: 'odmConnectionManager',
get: function get() {

@@ -156,2 +243,5 @@ return this._odmConnectionManager;

MicroFrameworkRunner.DEFAULT_ODM_SUBSCRIBER_DIRECTORY = 'subscriber';
MicroFrameworkRunner.DEFAULT_CONTROLLER_DIRECTORY = 'controller';
MicroFrameworkRunner.DEFAULT_CONTROLLER_DIRECTORY = 'controller';
MicroFrameworkRunner.DEFAULT_CONFIG_DIRECTORY = 'configuration';
MicroFrameworkRunner.DEFAULT_CONFIG_FILE = 'config.json';
MicroFrameworkRunner.DEFAULT_PARAMETERS_FILE = 'parameters.json';

11

package.json
{
"name": "microframework",
"version": "0.0.3",
"version": "0.0.4",
"description": "Micro framework is a bundle of express.js, mongodb ODM, validator, dependancy injection framework and restful controllers for your apps using Typescript",

@@ -32,7 +32,10 @@ "license": "Apache-2.0",

"express": "^4.13.3",
"fs": "0.0.2",
"mongodb": "^2.0.45",
"path": "^0.12.7",
"t-configurator": "^0.0.3",
"t-validator": "^0.0.2",
"type-controllers": "^0.0.1",
"typedi": "^0.0.2",
"typeodm": "^0.0.1",
"t-validator": "^0.0.2"
"typedi": "^0.0.4",
"typeodm": "^0.0.2"
},

@@ -39,0 +42,0 @@ "devDependencies": {

# MicroFramework
Micro framework is a bundle of [express.js][1], [Mongodb ODM][2], [dependancy injection framework][3] and [restful controllers][4] for
Micro framework is a bundle of [express.js][1], [Mongodb ODM][2], [validator][5],
[dependancy injection framework][3], [configuration framework][6] and [restful controllers][4] for
your apps using Typescript.

@@ -64,2 +65,4 @@

[3]: https://github.com/PLEEROCK/typedi
[4]: https://github.com/PLEEROCK/type-controllers
[4]: https://github.com/PLEEROCK/type-controllers
[5]: https://github.com/PLEEROCK/t-validator
[6]: https://github.com/PLEEROCK/t-configurator
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