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

ifnode

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifnode - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

.eslintrc

240

core/Application.js

@@ -5,2 +5,8 @@ 'use strict';

var _includes = require('lodash/includes');
var FS = require('fs');
var Path = require('path');
var Express = require('express');
var UUID = require('node-uuid');
var Diread = require('diread');
var toArray = require('./helper/toArray');

@@ -10,6 +16,2 @@ var defineProperties = require('./helper/defineProperties');

var debug = require('debug')('ifnode:application');
var FS = require('fs');
var Path = require('path');
var Express = require('express');
var UUID = require('node-uuid');
var Log = require('./extensions/log');

@@ -19,2 +21,8 @@

var SchemaFactory = require('./SchemaFactory');
var ConfigurationBuilder = require('./ConfigurationBuilder');
var SchemasList = require('./application/SchemasList');
var DAOList = require('./application/DAOList');
var ModelBuilder = require('./application/ModelBuilder');
var Controller = require('./Controller');

@@ -24,9 +32,18 @@ var IFNodeVirtualSchema = require('./../plugins/ifnode-virtual');

/**
* @typedef {Object} ApplicationOptions
*
* @property {string} [app_config.alias]
* @property {string} [app_config.project_folder]
* @property {string} [app_config.projectFolder]
* @property {string} [app_config.environment]
*/
/**
* Creates a new Application instance
*
* @class Application
* @param {Object} options
* @param {ApplicationOptions} [options={}]
*/
function Application(options) {
this._initialize(options || {});
this._constructor(options || {});
}

@@ -36,3 +53,2 @@

require('./application/components')(Application);
require('./application/models')(Application);
require('./application/controllers')(Application);

@@ -43,3 +59,3 @@

*
* @param {String} id
* @param {string} id
* @returns {*}

@@ -58,3 +74,3 @@ */

*
* @param {String|Extension|Array.<String|Extension>} plugin
* @param {string|Extension|Array.<string|Extension>} plugin
* @returns {Application}

@@ -84,92 +100,108 @@ */

Application.prototype.load = function() {
var app = this,
function initialize_modules(app) {
var require_module = function(module_name) {
var module;
initialize_models = function() {
var type = 'schema',
modules = app._modules,
try {
module = require(module_name);
} catch(e) {
module = app.ext(module_name);
}
i,
schema,
return module;
};
var modules = app._modules;
modules = toArray(modules).map(function(module) {
return typeof module === 'string'?
require_module(module) :
module;
});
for(i = 0; i < modules.length; ++i) {
module = modules[i][type];
modules.push(IFNodeVirtualSchema);
if(module) {
schema = SchemaFactory();
module(app, schema);
app.attach_schema(schema);
}
}
app._modules = modules;
}
app._init_models();
},
initialize_components = function() {
var type = 'component',
Component = app.Component.bind(app),
modules = app._modules,
function initialize_models(app) {
var db = app.config.db;
i, module;
if(!(db && Object.keys(db).length)) {
return;
}
app._components = {};
app._initialize_components();
var type = 'schema';
var modules = app._modules;
var schemas_list = new SchemasList;
for(i = 0; i < modules.length; ++i) {
module = modules[i][type];
for(var i = 0; i < modules.length; ++i) {
var module = modules[i][type];
if(module) {
module(app, Component);
}
if(module) {
var schema = SchemaFactory();
module(app, schema);
schemas_list.attach_schema(schema);
}
}
app._attach_components();
},
initialize_controllers = function() {
var type = 'controller',
modules = app._modules,
app._models_builder = new ModelBuilder(
new DAOList(schemas_list, db)
);
i, module;
Diread({
src: app.config.application.folders.models
}).each(function(model_file_path) {
require(model_file_path);
});
for(i = 0; i < modules.length; ++i) {
module = modules[i][type];
app.models = app._models_builder.compile_models();
Object.freeze(app.models);
}
if(module) {
module(app, Controller);
}
}
function initialize_components(app) {
var type = 'component',
Component = app.Component.bind(app),
modules = app._modules,
app._init_controllers();
},
i, module;
initialize_modules = function() {
var require_module = function(module_name) {
var module;
app._components = {};
app._initialize_components();
try {
module = require(module_name);
} catch(e) {
module = app.ext(module_name);
}
for(i = 0; i < modules.length; ++i) {
module = modules[i][type];
return module;
};
if(module) {
module(app, Component);
}
}
var modules = app._modules;
app._attach_components();
}
modules = toArray(modules).map(function(module) {
return typeof module === 'string'?
require_module(module) :
module;
});
function initialize_controllers(app) {
var type = 'controller',
modules = app._modules,
modules.push(IFNodeVirtualSchema);
i, module;
app._modules = modules;
};
for(i = 0; i < modules.length; ++i) {
module = modules[i][type];
initialize_modules();
initialize_models();
initialize_components();
initialize_controllers();
if(module) {
module(app, Controller);
}
}
app._init_controllers();
}
initialize_modules(this);
initialize_models(this);
initialize_components(this);
initialize_controllers(this);
this._is_loaded = true;

@@ -183,3 +215,3 @@

*
* @param {Function} callback
* @param {function} callback
*/

@@ -192,3 +224,3 @@ Application.prototype.run = function(callback) {

var app_instance = this,
local_config = this._config.site.local,
local_config = this.config.site.local,
server_params = [];

@@ -208,3 +240,3 @@

this._server.listen.apply(this._server, server_params);
this.server.listen.apply(this.server, server_params);
};

@@ -215,6 +247,6 @@

*
* @param {Function} callback
* @param {function} callback
*/
Application.prototype.down = function(callback) {
this._server.close.call(this._server, callback);
this.server.close.call(this.server, callback);
};

@@ -224,3 +256,3 @@

*
* @param {String} id
* @param {string} id
* @returns {*}

@@ -244,13 +276,20 @@ */

/**
*
* @param {Object} model_config
* @param {Object} options
* @returns {Function}
* @constructor
*/
Application.prototype.Model = function(model_config, options) {
return this._models_builder.make(model_config, options);
};
/**
* Initializes application instance
*
* @constructs Application
* @param {Object} [app_config]
* @param {String} [app_config.alias]
* @param {String} [app_config.project_folder]
* @param {String} [app_config.projectFolder]
* @param {String} [app_config.environment]
* @param {ApplicationOptions} [app_config]
* @private
*/
Application.prototype._initialize = function(app_config) {
Application.prototype._constructor = function(app_config) {
if(app_config.alias && typeof app_config.alias !== 'string') {

@@ -269,3 +308,5 @@ Log.error('application', 'Alias must be String');

this._initialize_config.call(this, app_config.env || app_config.environment);
this._models_builder = null;
this._initialize_config(app_config.env || app_config.environment);
this._initialize_listener.call(this);

@@ -278,3 +319,3 @@ this._initialize_server.call(this);

*
* @param {String} environment
* @param {string} environment
* @private

@@ -289,3 +330,3 @@ */

this._config = require('./config')({
this.config = ConfigurationBuilder({
environment: environment,

@@ -305,3 +346,3 @@ project_folder: this._project_folder,

var app = Express(),
config = this._config,
config = this.config,
app_config = config.application,

@@ -324,3 +365,3 @@

this._listener = app;
this.listener = app;
};

@@ -335,3 +376,3 @@

var server,
credentials = this._config.site.local.ssl;
credentials = this.config.site.local.ssl;

@@ -352,8 +393,8 @@ if(_isPlainObject(credentials)) {

server = require('https').createServer(credentials, this._listener);
server = require('https').createServer(credentials, this.listener);
} else {
server = require('http').createServer(this._listener);
server = require('http').createServer(this.listener);
}
this._server = server;
this.server = server;
};

@@ -365,11 +406,6 @@

'config': function() { return this._config; },
'server': function() { return this._server; },
'listener': function() { return this._listener; },
'components': function() { return this._components; },
'models': function() { return this._models; },
'controllers': function() { return this._controllers; }
'components': function() { return this._components || {}; },
'controllers': function() { return this._controllers || {}; }
});
module.exports = Application;
'use strict';
var path = require('path'),
diread = require('diread'),
var Path = require('path');
var Diread = require('diread');
var Component = require('./../component');
Component = require('./../component');
module.exports = function(Application) {
Application.prototype._components = {};
Application.prototype._initialize_components = function() {
var custom_components_folder = this.config.application.folders.components,
var custom_components_folder = this.config.application.folders.components;
var custom_components_path = Path.resolve(this._project_folder, custom_components_folder);
core_components_path = path.resolve(this._ifnode_core_folder, 'components/'),
custom_components_path = path.resolve(this._project_folder, custom_components_folder),
cb = function(component_file_path) {
require(component_file_path);
};
diread({ src: core_components_path }).each(cb);
diread({ src: custom_components_path }).each(cb);
Diread({
src: custom_components_path
}).each(function(component_file_path) {
require(component_file_path);
});
};

@@ -69,4 +65,4 @@ Application.prototype._attach_components = function() {

component_options.config = this._config.components[component_options.name] || {};
component = Component(component_options);
component_options.config = this.config.components[component_options.name] || {};
component = new Component(component_options);

@@ -73,0 +69,0 @@ this._components[component.name] = component;

@@ -7,3 +7,2 @@ 'use strict';

var debug = require('debug')('ifnode:components');
var Path = require('path');

@@ -34,12 +33,16 @@ var Diread = require('diread');

require(component_path);
try {
require(component_path);
} catch(error) {
Log.warning('components', 'Cannot load component [' + autoformed_config.name + '] by path [' + component_path + ']');
}
});
};
Application.prototype._attach_components = function() {
var self = this,
app_components = self._components;
var self = this;
var app_components = self._components;
Object.keys(app_components).forEach(function(unique_name) {
var component = app_components[unique_name],
aliases = toArray(component.alias);
var component = app_components[unique_name];
var aliases = toArray(component.alias);

@@ -76,5 +79,5 @@ if(component.initialize) {

component_config.config = this._config.components[unique_name] || {};
component_config.config = this.config.components[unique_name] || {};
this._components[unique_name] = Component(component_config);
this._components[unique_name] = new Component(component_config);

@@ -81,0 +84,0 @@ return this._components[unique_name];

@@ -17,3 +17,3 @@ var Path = require('path');

var app_controllers = this._controllers,
app_server = this._server;
app_server = this.server;

@@ -20,0 +20,0 @@ Object.keys(app_controllers).forEach(function(controller_id) {

@@ -126,3 +126,3 @@ 'use strict';

Application.prototype._compile_controllers = function() {
var app = this._listener,
var app = this.listener,
app_controllers = this._controllers,

@@ -129,0 +129,0 @@ app_controllers_ids = Object.keys(app_controllers),

@@ -6,12 +6,19 @@ 'use strict';

var Component = function(options) {
if(!(this instanceof Component)) {
return new Component(options);
}
/**
*
* @class Component
*
* @param {Object} options
* @returns {Component}
* @constructor
*/
function Component(options) {
this.init(options);
};
}
Component.fn = Component.prototype;
Component.fn.init = function(options) {
/**
*
* @param {Object} options
*/
Component.prototype.init = function(options) {
this.id = UUID.v4();

@@ -18,0 +25,0 @@ this.name = options.name;

@@ -189,3 +189,11 @@ 'use strict';

var Controller = function(config) {
/**
*
* @class Controller
*
* @param {Object} config
* @returns {Controller}
* @constructor
*/
function Controller(config) {
if(!(this instanceof Controller)) {

@@ -196,3 +204,3 @@ return new Controller(config);

_initialize.call(this, config);
};
}

@@ -199,0 +207,0 @@ Controller.fn = Controller.prototype;

'use strict';
var sprintf = require('sprintf').sprintf,
log;
var Debug = require('debug');
var sprintf = require('sprintf').sprintf;
var toArray = require('./../helper/toArray');
log = function(args) {
console.log(this.form.apply(this, arguments));
return this;
/**
*
* @class Log
*
* @param {*} args
* @returns {Log}
* @constructor
*/
function Log(args) {
this.log('common', this.form.apply(this, arguments));
}
Log.DEBUG_KEY = 'ifnode:';
Log.TEMPLATE = '[ifnode] [%s] %s';
/**
*
* @param {string} key
* @param {*} args
*/
Log.log = function(key, args) {
var debug = Debug(this.DEBUG_KEY + key);
debug.apply(debug, toArray(arguments, 1));
};
log.form = function(args) {
/**
*
* @param {*} args
* @returns {*}
*/
Log.form = function(args) {
args = [].slice.call(arguments);

@@ -17,10 +44,23 @@

log.error = function(name, message) {
var template = '[ifnode] [%s] %s',
error;
/**
*
* @param {string} name
* @param {Error|string} warning
*/
Log.warning = function(name, warning) {
if(warning instanceof Error) {
warning = warning.message;
}
if(message instanceof Error) {
error = message;
} else {
error = new Error(sprintf(template, name, message));
this.log('warning', this.form(this.TEMPLATE, name, warning));
};
/**
*
* @param {string} name
* @param {Error|string} error
*/
Log.error = function(name, error) {
if(!(error instanceof Error)) {
error = new Error(this.form(this.TEMPLATE, name, error));
}

@@ -31,2 +71,2 @@

module.exports = log;
module.exports = Log;
'use strict';
/**
*
* @param {*} [obj]
* @param {number} [at=0]
* @returns {Array.<*>}
*/
module.exports = function toArray(obj, at) {

@@ -7,3 +13,3 @@ if(!obj) {

}
at = typeof at === 'number'? at : 0;

@@ -10,0 +16,0 @@

'use strict';
/**
*
* @interface SchemaInterface
*/
var UUID = require('node-uuid');
module.exports = function SchemaFactory() {
var Schema = function(model_config) {
/**
*
* @param {Object} model_config
* @returns {Schema}
* @constructor
*/
function Schema(model_config) {
if(!(this instanceof Schema)) {

@@ -18,3 +30,3 @@ return new Schema(model_config);

}
};
}

@@ -21,0 +33,0 @@ Schema.fn = Schema.prototype;

@@ -12,4 +12,3 @@ 'use strict';

*
* @class IFNode
* @param {String|Object} options
* @param {string|ApplicationOptions} options
* @returns {Application}

@@ -21,2 +20,3 @@ */

}
if(typeof options === 'string') {

@@ -23,0 +23,0 @@ return _applications_cache[options];

{
"name": "ifnode",
"version": "1.3.0",
"version": "1.4.0",
"description": "Node.js MVC Framework",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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