Comparing version 0.1.0-alpha-7 to 0.1.0-alpha-8
@@ -9,2 +9,3 @@ "use strict"; | ||
component = di.load('core/component'), | ||
ENV_END_PATTERN = new RegExp('.*\\.json$'), | ||
DEFAULT_SERVER_PORT = 8080, | ||
@@ -25,3 +26,3 @@ Bootstrap; | ||
* @description | ||
* Bootstrap is base class for setup Framework behavior | ||
* Bootstrap is base object for setup Framework behavior | ||
*/ | ||
@@ -39,3 +40,3 @@ _construct: function Bootstrap() { | ||
*/ | ||
init: function Bootstrap_init(appPath) { | ||
init: function Bootstrap_init(appPath, envFileName) { | ||
@@ -47,3 +48,2 @@ var file, | ||
envPath, | ||
requestHooks, | ||
Request, | ||
@@ -61,3 +61,10 @@ filePath; | ||
envPath = di.getAlias('appPath'); | ||
filePath = envPath + "env.json"; | ||
if (Type.isString(envFileName) && ENV_END_PATTERN.test(envFileName)) { | ||
filePath = envPath + envFileName; | ||
} else { | ||
filePath = envPath + "env.json"; | ||
} | ||
// load config | ||
@@ -67,3 +74,3 @@ try { | ||
} catch (e) { | ||
throw new error.Exception(filePath, 'Problem with loading file, do you have "env.json" in path: "' + envPath + '" ?', e); | ||
throw new error.DataError({filePath: filePath}, 'Problem with loading file, do you have your environment file json in path: "' + envPath + '" ?', e); | ||
} | ||
@@ -73,3 +80,3 @@ try { | ||
} catch (e) { | ||
throw new error.Exception(file, 'Problem with parsing file', e); | ||
throw new error.DataError({file: file}, 'Problem with parsing environment json file', e); | ||
} | ||
@@ -76,0 +83,0 @@ // set aliases |
@@ -6,2 +6,3 @@ "use strict"; | ||
CacheInterface = di.load('interface/cache'), | ||
error = di.load('error'), | ||
MemoryCache; | ||
@@ -18,3 +19,3 @@ /** | ||
*/ | ||
MemoryCache = CacheInterface.inherit({},{ | ||
MemoryCache = CacheInterface.inherit({}, { | ||
/** | ||
@@ -27,2 +28,3 @@ * @since 0.0.1 | ||
* Add value to cache | ||
* @return {object} | ||
*/ | ||
@@ -33,4 +35,5 @@ set: function MemoryCache_setValue(key, value, ttl) { | ||
} else { | ||
this.logger.error('Cache.add: key is already in cache', key); | ||
return false; | ||
} | ||
if (Type.isNumber(ttl) && !isNaN(ttl) && ttl > 0) { | ||
@@ -41,5 +44,8 @@ setTimeout(clearCache.bind(this), ttl); | ||
} | ||
function clearCache() { | ||
this.remove(key); | ||
} | ||
return true; | ||
}, | ||
@@ -46,0 +52,0 @@ /** |
@@ -101,3 +101,5 @@ "use strict"; | ||
} | ||
this.set(component.name, component); | ||
if (!this.has(component.name)) { | ||
this.set(component.name, component); | ||
} | ||
} | ||
@@ -104,0 +106,0 @@ } |
@@ -75,16 +75,6 @@ "use strict"; | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#hasAction | ||
* | ||
* @description | ||
* Check if controller have action | ||
*/ | ||
hasAction: function Controller_hasAction(name) { | ||
return (name in this); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#renderFile | ||
@@ -112,2 +102,14 @@ * | ||
* @author Igor Ivanovic | ||
* @method Controller#hasAction | ||
* | ||
* @description | ||
* Check if controller have action | ||
* @return {boolean} | ||
*/ | ||
has: function Controller_has(name) { | ||
return (name in this); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Controller#getAction | ||
@@ -117,4 +119,5 @@ * | ||
* Get controller action | ||
* @return {object} | ||
*/ | ||
getAction: function Controller_getAction(name) { | ||
get: function Controller_get(name) { | ||
if (Type.isFunction(this[name])) { | ||
@@ -128,3 +131,3 @@ return this[name]; | ||
// export Controller class | ||
// export Controller object | ||
module.exports = Controller; |
@@ -7,6 +7,6 @@ "use strict"; | ||
etag = di.load('etag'), | ||
fs = di.load('fs'), | ||
component = di.load('core/component'), | ||
logger = component.get('core/logger'), | ||
hook = component.get('hooks/request'), | ||
fs = di.load('fs'), | ||
Favicon; | ||
@@ -25,3 +25,3 @@ /** | ||
Favicon = Type.create({ | ||
buffer: Type.OBJECT, | ||
file: Type.OBJECT, | ||
config: Type.OBJECT | ||
@@ -52,6 +52,6 @@ }, { | ||
api.addHeader('Cache-Control', 'public, max-age=' + ~~(maxAge)); | ||
api.addHeader('ETag', etag(this.buffer)); | ||
api.addHeader('ETag', etag(this.file)); | ||
if (api.getMethod() !== 'GET') { | ||
return false; | ||
throw new error.HttpError(500, {}, 'Favicon is accessible only via GET request'); | ||
} else if (api.isHeaderCacheUnModified()) { | ||
@@ -61,3 +61,3 @@ api.sendNoChange(); | ||
return this.buffer; | ||
return this.file; | ||
}, | ||
@@ -73,11 +73,10 @@ /** | ||
readFile: function Favicon_readFile() { | ||
var path = di.normalizePath(this.config.path), that = this; | ||
var path = di.normalizePath(this.config.path); | ||
logger.print('Favicon.readFile', path); | ||
fs.readFile(path, function (err, buf) { | ||
if (err) { | ||
logger.error(err); | ||
throw new error.HttpError(500, err, 'Cannot load favicon'); | ||
} | ||
that.buffer = buf; | ||
}); | ||
try { | ||
this.file = fs.readFileSync(path, {encoding: null}); | ||
} catch (e) { | ||
throw new error.HttpError(500, {}, 'Cannot load favicon', e); | ||
} | ||
} | ||
@@ -84,0 +83,0 @@ }); |
@@ -16,3 +16,3 @@ "use strict"; | ||
* @description | ||
* HttpService class | ||
* HttpService object | ||
*/ | ||
@@ -19,0 +19,0 @@ HttpService = HttpServiceInterface.inherit({ |
@@ -45,20 +45,12 @@ "use strict"; | ||
if (this.config.debug) { | ||
try { | ||
file = di.normalizePath('@{basePath}/' + this.config.file); | ||
this.stream = fs.createWriteStream(file, {encoding: 'utf8'}); | ||
} catch (e) { | ||
throw new error.Exception('Invalid write stream', e); | ||
} | ||
file = di.normalizePath('@{basePath}/' + this.config.file); | ||
this.stream = fs.createWriteStream(file, {encoding: 'utf8'}); | ||
if (this.config.publish) { | ||
this.server = http.createServer(); | ||
this.server.on('request', function (request, response) { | ||
var read; | ||
try { | ||
read = fs.readFileSync(file); | ||
response.writeHead(200, {'Content-type': 'text/plain', 'Content-Length': read.length}); | ||
response.end(read); | ||
} catch (e) { | ||
response.writeHead(200, {'Content-type': 'text/plain'}); | ||
response.end(e.stack); | ||
} | ||
var read = fs.readFileSync(file); | ||
response.writeHead(200, {'Content-type': 'text/plain', 'Content-Length': read.length}); | ||
response.end(read); | ||
}); | ||
@@ -145,18 +137,2 @@ this.server.listen(this.config.port); | ||
*/ | ||
error: function Logger_error() { | ||
var log = "", args = Array.prototype.slice.call(arguments); | ||
util.inspect.styles.string = 'red'; | ||
args.forEach(function (item) { | ||
log += " " + util.inspect(item, {colors: true, depth: this.config.level}); | ||
}.bind(this)); | ||
return this.log(log); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Logger#inspect | ||
* | ||
* @description | ||
* Inspect | ||
*/ | ||
print: function Logger_print() { | ||
@@ -163,0 +139,0 @@ var log = "", args = Array.prototype.slice.call(arguments); |
@@ -138,3 +138,3 @@ "use strict"; | ||
} else { | ||
throw new error.HttpError(500, {key: key}, "Request.hasHeader: Header key must be string type"); | ||
throw new error.HttpError(500, {key: key}, "Request.getRequestHeader: Header key must be string type"); | ||
} | ||
@@ -182,3 +182,3 @@ }, | ||
if (Type.isString(key)) { | ||
this.headers[key.toLowerCase()] = value; | ||
this.headers[key.toLowerCase()] = Type.isString(value) ? value : value.toString(); | ||
} else { | ||
@@ -188,3 +188,3 @@ throw new error.HttpError(500, { | ||
value: value | ||
}, "Request.addHeader: Header key and value must be string type"); | ||
}, "Request.addHeader: Header key must be string type"); | ||
} | ||
@@ -248,3 +248,3 @@ }, | ||
sendNoChange: function () { | ||
this.response.writeHead(304); | ||
this.response.writeHead(304, this.headers); | ||
this.response.end(); | ||
@@ -316,3 +316,3 @@ }, | ||
if (response instanceof Error && !this.isERROR && di.exists(errorController, '.js')) { | ||
if (response instanceof Error && !this.isERROR && di.exists(di.normalizePath(errorController) + '.js')) { | ||
@@ -328,5 +328,5 @@ if (response.code) { | ||
errorController = new Controller(); | ||
if (errorController.hasAction('action_' + errorAction)) { | ||
if (errorController.has('action_' + errorAction)) { | ||
response = errorController.getAction('action_' + errorAction)(response); | ||
response = errorController.get('action_' + errorAction)(response); | ||
if (response.trace) { | ||
@@ -340,3 +340,3 @@ this._render(response.trace); | ||
} else { | ||
logger.print('Request.render: no error controller provided', errorController); | ||
throw new error.HttpError(500, {errorAction: errorAction}, "No error action defined at error controller"); | ||
} | ||
@@ -358,3 +358,3 @@ } catch (e) { | ||
} else { | ||
return this._render(response); | ||
this._render(response); | ||
} | ||
@@ -430,4 +430,11 @@ }, | ||
if (!promise) { | ||
return Promise.resolve(_handler()); | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
resolve(next.apply(next, arguments)); | ||
} catch (e) { | ||
reject(new error.HttpError(500, arguments, "Error on executing action", e)); | ||
} | ||
}); | ||
} | ||
return promise.then(function (data) { | ||
@@ -458,3 +465,5 @@ return Promise.resolve(_handler(data)); | ||
action, | ||
promise; | ||
promise, | ||
afterActionPromise = false, | ||
afterEachPromise = false; | ||
@@ -484,16 +493,16 @@ try { | ||
if (controller.hasAction("beforeEach")) { | ||
if (controller.has("beforeEach")) { | ||
promise = this._chain(null, controller.beforeEach.bind(controller, this.action, this.params)); | ||
} | ||
if (controller.hasAction('before_' + this.action)) { | ||
promise = this._chain(promise, controller.getAction('before_' + this.action).bind(controller, this.params)); | ||
if (controller.has('before_' + this.action)) { | ||
promise = this._chain(promise, controller.get('before_' + this.action).bind(controller, this.params)); | ||
} | ||
if (controller.hasAction('action_' + this.action)) { | ||
promise = this._chain(promise, controller.getAction('action_' + this.action).bind(controller, this.params)); | ||
if (controller.has('action_' + this.action)) { | ||
promise = this._chain(promise, controller.get('action_' + this.action).bind(controller, this.params)); | ||
} else { | ||
throw new error.HttpError(500, { | ||
controller: controller, | ||
hasAction: controller.hasAction(this.action), | ||
hasAction: controller.has(this.action), | ||
route: { | ||
@@ -509,8 +518,8 @@ controller: this.controller, | ||
if (controller.hasAction('after_' + this.action)) { | ||
promise = this._chain(promise, controller.getAction('after_' + this.action).bind(controller, this.params)); | ||
if (controller.has('after_' + this.action)) { | ||
afterActionPromise = this._chain(promise, controller.get('after_' + this.action).bind(controller, this.params)); | ||
} | ||
if (controller.hasAction("afterEach")) { | ||
promise = this._chain(promise, controller.afterEach.bind(controller, this.action, this.params)); | ||
if (controller.has("afterEach")) { | ||
afterEachPromise = this._chain(promise, controller.afterEach.bind(controller, this.action, this.params)); | ||
} | ||
@@ -520,3 +529,6 @@ | ||
return promise; | ||
return Promise.all([afterActionPromise, afterEachPromise]).then(function (data) { | ||
logger.print('afterActionPromise, afterEachPromise', data); | ||
return promise; | ||
}); | ||
}, | ||
@@ -532,2 +544,3 @@ | ||
* @return {object} Promise | ||
* @todo implement modules | ||
*/ | ||
@@ -534,0 +547,0 @@ _resolveRoute: function Request__resolveRoute(routeRule) { |
@@ -7,7 +7,7 @@ "use strict"; | ||
error = di.load('error'), | ||
Promise = di.load('promise'), | ||
RouteRuleInterface = di.load('interface/routeRule'), | ||
RouteRule = di.load('core/routeRule'), | ||
component = di.load('core/component'), | ||
RouteRule = di.load('core/routeRule'), | ||
Promise = di.load('promise'), | ||
logger = component.get('core/logger'), | ||
RouteRuleInterface = di.load('interface/routeRule'), | ||
Router; | ||
@@ -27,3 +27,3 @@ /** | ||
config: Type.OBJECT | ||
},{ | ||
}, { | ||
_construct: function Router(config) { | ||
@@ -66,13 +66,13 @@ this.routes = []; | ||
if (route.dynamic) { | ||
if (core.isFunction(route.constructor)) { | ||
rule = new route.constructor(component); | ||
if (Type.isFunction(route.constructor)) { | ||
rule = new route.constructor(); | ||
} else { | ||
throw new error.HttpError(500, route, 'Router.add: dynamic route is not constructor'); | ||
throw new error.HttpError(500, {route: route}, 'Router.add: dynamic route is not function'); | ||
} | ||
} else { | ||
rule = new RouteRule(component, route); | ||
rule = new RouteRule(route); | ||
} | ||
if (!(rule instanceof RouteRuleInterface)) { | ||
throw new error.HttpError(500, rule, 'Router.add: rule must be instance of RouteRuleInterface'); | ||
throw new error.HttpError(500, {rule: rule}, 'Router.add: rule must be instance of RouteRuleInterface'); | ||
} | ||
@@ -84,3 +84,3 @@ | ||
}, | ||
/** | ||
@@ -99,3 +99,3 @@ * @since 0.0.1 | ||
if (!Type.isString(route)) { | ||
throw new error.HttpError(500, route, 'RouteRule.createUrl: route must be string type'); | ||
throw new error.HttpError(500, {route: route}, 'RouteRule.createUrl: route must be string type'); | ||
} | ||
@@ -105,3 +105,3 @@ if (!params) { | ||
} else if (!Type.isObject(params)) { | ||
throw new error.HttpError(500, params, 'RouteRule.createUrl: params must be object type'); | ||
throw new error.HttpError(500, {params: params}, 'RouteRule.createUrl: params must be object type'); | ||
} | ||
@@ -202,11 +202,21 @@ | ||
process: function Router_process(method, parsedUrl) { | ||
return Promise.resolve(this.parseRequest(method, parsedUrl)).then(function(routeRule) { | ||
if (Type.isArray(routeRule) && routeRule.length === 2) { | ||
return Promise.resolve(routeRule); | ||
return new Promise(handlePromise.bind(this)) | ||
.then(function (routeRule) { | ||
if (Type.isArray(routeRule) && routeRule.length === 2) { | ||
return Promise.resolve(routeRule); | ||
} | ||
// only on not found throw an error 404 | ||
throw new error.HttpError(404, core.toObject(routeRule), 'Not found'); | ||
}, function (e) { | ||
throw new error.HttpError(500, {}, 'Not found', e); | ||
}); | ||
function handlePromise(resolve, reject) { | ||
try { | ||
resolve(this.parseRequest(method, parsedUrl)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
// only on not found throw an error 404 | ||
throw new error.HttpError(404, core.toObject(routeRule), 'Not found'); | ||
}, function (error) { | ||
throw new error.HttpError(500, error, 'Not found'); | ||
}); | ||
} | ||
} | ||
@@ -213,0 +223,0 @@ }); |
@@ -8,5 +8,7 @@ "use strict"; | ||
RouteRuleInterface = di.load('interface/routeRule'), | ||
component = di.load('core/component'), | ||
logger = component.get('core/logger'), | ||
PATTERN_MATCH = /<(\w+):?([^>]+)?>/ig, | ||
ROUTE_MATCH = /<(\w+)>/ig, | ||
PATTERN_CAPTURE_REGEX = /\(((\?P?<(\w+)>)((\:?(\((.*)\)))?|([^\)]+))|([^\)]+))\)/g, | ||
PATTERN_CAPTURE_REGEX = /\(((\?P?<(\w+)>)((:?(\(([^\/]+)\)))?|([^\)]+))|([^\)]+))\)/g, | ||
IS_NAMED = /\(\?P?<(\w+)>([^\)]+)\)/, | ||
@@ -34,3 +36,3 @@ RouteRule; | ||
}, { | ||
_construct: function RouteRule(component, config) { | ||
_construct: function RouteRule(config) { | ||
var matches, name, pattern, escapePattern = [], escapeRule = [], template; | ||
@@ -41,3 +43,2 @@ this.routeParams = []; | ||
this.routeRule = null; | ||
this.logger = component.get('core/logger'); | ||
@@ -56,3 +57,3 @@ if (!config.pattern) { | ||
this.logger.print('route', this.route); | ||
logger.print('route', this.route); | ||
@@ -74,2 +75,3 @@ if (this.route.indexOf('<') > -1) { | ||
if (Array.isArray(matches) && matches.length) { | ||
@@ -106,3 +108,3 @@ matches.forEach(function (item) { | ||
if (this.routeParams.length) { | ||
this.routeRule = this.escape(this.route, escapeRule); | ||
this.routeRule = '^' + this.escape(this.route, escapeRule) + '$'; | ||
} | ||
@@ -116,3 +118,9 @@ | ||
this.logger.print('RouteRule', { | ||
if (this.template.indexOf('<') > -1 && this.route.indexOf('<') > -1) { | ||
if (this.template.indexOf(this.route) === -1) { | ||
throw new error.HttpError(500, config, 'RouteRule: invalid route rule'); | ||
} | ||
} | ||
logger.print('RouteRule', { | ||
escapePattern: escapePattern, | ||
@@ -187,3 +195,2 @@ escapeRule: escapeRule, | ||
result.push(route); | ||
@@ -201,2 +208,3 @@ result.push(params); | ||
* Create an url | ||
* @return {object} | ||
*/ | ||
@@ -225,9 +233,6 @@ createUrl: function RouteRule_createUrl(route, params) { | ||
c = this.paramRules[i]; | ||
this.logger.print('template2', c.value, params[c.key], this.match(c.value, params[c.key])); | ||
if (params.hasOwnProperty(c.key) && (c.value === '' || (Type.isRegExp(c.value) && c.value.test(params[c.key])) || this.match(c.value, params[c.key]).length > 0) ) { | ||
if (params.hasOwnProperty(c.key) && (c.value === '' || (Type.isRegExp(c.value) && c.value.test(params[c.key])) || this.match(c.value, params[c.key].toString()).length > 0)) { | ||
escape.push({ | ||
key: '<' + c.key + '>', | ||
value: params[c.key] | ||
value: params[c.key].toString() | ||
}); | ||
@@ -241,4 +246,5 @@ delete params[c.key]; | ||
url = this.trim(this.escape(this.template, escape), '/'); | ||
if (url.indexOf('//') > -1) { | ||
url = url.replace(/\/+/g, '/'); | ||
if (this.match(this.pattern.regex, url).length === 0) { | ||
return false; | ||
} | ||
@@ -285,4 +291,4 @@ | ||
*/ | ||
find: function RouteRule_find(data, key, filter) { | ||
return data.filter(filter ? filter : function (item) { | ||
find: function RouteRule_find(data, key) { | ||
return data.filter(Type.isFunction(key) ? key : function (item) { | ||
return item.key === key; | ||
@@ -386,2 +392,7 @@ }).pop(); | ||
escape: function RouteRule_escape(str, escape) { | ||
if (!Type.isString(str)) { | ||
throw new error.HttpError(500, {str: str}, 'RouteRule.escape: str must be a string type'); | ||
} else if(!Type.isArray(escape)) { | ||
throw new error.HttpError(500, {escape: escape}, 'RouteRule.escape: escape must be a array type'); | ||
} | ||
escape.forEach(function (item) { | ||
@@ -388,0 +399,0 @@ str = str.replace(item.key, item.value); |
@@ -44,4 +44,3 @@ "use strict"; | ||
suffix: '.twig', | ||
theme: false, | ||
prelaod: false | ||
theme: false | ||
}, config); | ||
@@ -56,3 +55,3 @@ | ||
} else { | ||
this.suffix = new RegExp(this.config.suffix + '$'); | ||
throw new error.HttpError(500, this.config, 'View.construct: view suffix must be string type'); | ||
} | ||
@@ -115,3 +114,3 @@ | ||
if (!!this.config.cache && !isPreloaded) { | ||
throw new error.DataError({key: key}, "ENOENT, no such file or directory "); | ||
throw new error.DataError({key: key}, "ENOENT, no such file or directory"); | ||
} | ||
@@ -167,2 +166,4 @@ return isPreloaded; | ||
this.config.theme = name; | ||
} else if(Type.isNull(name)) { | ||
this.config.theme = null; | ||
} else { | ||
@@ -197,4 +198,7 @@ throw new error.HttpError(500, {name: name}, "ViewLoader.setTheme: name must be string type"); | ||
normalizeResolveValue: function View_normalizeResolveValue(value) { | ||
if (Type.isString(value)) { | ||
return value.replace(this.getPath(), "").replace(this.suffix, ""); | ||
var theme = this.getPath(), view = this.getPath(true); | ||
if (Type.isString(value) && value.match(theme)) { | ||
return value.replace(theme, "").replace(this.suffix, ""); | ||
} else if (Type.isString(value) && value.match(view)) { | ||
return value.replace(view, "").replace(this.suffix, ""); | ||
} | ||
@@ -201,0 +205,0 @@ return value; |
@@ -18,3 +18,3 @@ "use strict"; | ||
* @description | ||
* DI is main class for handling dependency injection | ||
* DI is main object for handling dependency injection | ||
*/ | ||
@@ -117,7 +117,8 @@ var DI = Type.create({ | ||
*/ | ||
exists: function DI_exists(file, fileType) { | ||
if (!Type.isString(fileType) && !Type.isString(file)) { | ||
throw new error.DataError({file: file, fileType: fileType}, 'DI.exists: file or fileType must bi string'); | ||
exists: function DI_exists(file) { | ||
if (!Type.isString(file)) { | ||
error = this.load('error'); | ||
throw new error.DataError({file: file}, 'DI.exists: file or fileType must bi string'); | ||
} | ||
return fs.existsSync(this.normalizePath(file) + fileType); | ||
return fs.existsSync(file); | ||
}, | ||
@@ -127,2 +128,52 @@ /** | ||
* @author Igor Ivanovic | ||
* @method DI#mockLoad | ||
* | ||
* @description | ||
* Mock load for testing purposes | ||
*/ | ||
mock: function DI_mock(file, mocks) { | ||
// save original | ||
var load = DI.prototype.load, path; | ||
// mock load | ||
DI.prototype.load = function (name) { | ||
return mocks[name]; | ||
}; | ||
try { | ||
// load module or exec if its function | ||
if (Type.isString(file)) { | ||
// get file | ||
path = this.getFilePath(file); | ||
// because all modules in node are cached while executing tests we want to delete cached version | ||
delete require.cache[require.resolve(path + '.js')]; | ||
// do require | ||
return require(path); | ||
} else if (Type.isFunction(file)) { | ||
return file(); | ||
} | ||
} catch (e) { | ||
return e; | ||
} finally { | ||
// restore load | ||
DI.prototype.load = load; | ||
} | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method DI#getPath | ||
* | ||
* @description | ||
* Get module path so we can load it | ||
*/ | ||
getFilePath: function DI_getFilePath(moduleName) { | ||
if (moduleName in this.filePaths) { | ||
moduleName = this.filePaths[moduleName]; | ||
} | ||
return this.normalizePath(moduleName); | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method DI#load | ||
@@ -133,8 +184,5 @@ * | ||
*/ | ||
load: function DI_load(file) { | ||
load: function DI_load(name) { | ||
try { | ||
if (file in this.filePaths) { | ||
file = this.filePaths[file]; | ||
} | ||
return require(this.normalizePath(file)); | ||
return require(this.getFilePath(name)); | ||
} catch (e) { | ||
@@ -141,0 +189,0 @@ error = this.load('error'); |
@@ -8,3 +8,2 @@ "use strict"; | ||
DataError, | ||
SilentError, | ||
Exception, | ||
@@ -50,9 +49,3 @@ HttpError; | ||
nError.name = 'Exception'; | ||
try { | ||
error = core.extend(nError, this.__dynamic__); | ||
} catch (e) { | ||
console.log('Exception.extend', e); | ||
} | ||
toString = nError.toString; | ||
@@ -63,6 +56,7 @@ nError.toString = function() { | ||
} | ||
return toString(); | ||
return this.name + ': ' + this.stack; | ||
}; | ||
// extend | ||
error = core.extend(nError, this.__dynamic__); | ||
throw error; | ||
@@ -96,6 +90,4 @@ }, | ||
return 1; | ||
} else if (a.key < b.key) { | ||
return -1; | ||
} | ||
return 0; | ||
return -1; | ||
}); | ||
@@ -118,22 +110,2 @@ | ||
* @author Igor Ivanovic | ||
* @name SilentError | ||
* | ||
* @constructor | ||
* @description | ||
* Exception is used to throw http error | ||
*/ | ||
SilentError = Exception.inherit({}, { | ||
_construct: function SilentError(msg, error) { | ||
try { | ||
this._super(msg, error); | ||
} catch (e) { | ||
e.name = 'SilentError'; | ||
console.log(e); | ||
} | ||
} | ||
}); | ||
/** | ||
* @license Mit Licence 2014 | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @name DataError | ||
@@ -187,4 +159,3 @@ * | ||
HttpError: HttpError, | ||
DataError: DataError, | ||
SilentError: SilentError | ||
DataError: DataError | ||
}; |
@@ -22,3 +22,2 @@ { | ||
"interface/requestHooks": "@{framework}/interface/requestHooks", | ||
"interface/config": "@{framework}/interface/config", | ||
"interface/cache": "@{framework}/interface/cache", | ||
@@ -25,0 +24,0 @@ "interface/controller": "@{framework}/interface/controller", |
@@ -36,4 +36,2 @@ "use strict"; | ||
throw new error.DataError({key: key, value: value}, "RequestHooks.add hook value must be function type"); | ||
} else if (!Type.isRegExp(key)) { | ||
throw new error.DataError({key: key, value: value}, "RequestHooks.add hook key must be regex type"); | ||
} | ||
@@ -56,2 +54,5 @@ this.hooks.push({ | ||
get: function RequestHooks_get(value) { | ||
if (!Type.isString(value)) { | ||
throw new error.DataError({value: value}, "RequestHooks.get value must be string type"); | ||
} | ||
return this.hooks.filter(function (item) { | ||
@@ -58,0 +59,0 @@ return item.key.test(value); |
"use strict"; | ||
/* global loader: true, Type: true,, error: true, CacheInterface: true */ | ||
var di = require('../di'), | ||
component = di.load('core/component'), | ||
Type = di.load('typejs'), | ||
@@ -16,7 +15,6 @@ error = di.load('error'), | ||
* @description | ||
* Cache class | ||
* Cache object | ||
*/ | ||
CacheInterface = Type.create({ | ||
cache: Type.OBJECT, | ||
logger: Type.OBJECT, | ||
config: Type.OBJECT, | ||
@@ -27,3 +25,2 @@ ttl: Type.NUMBER | ||
this.cache = {}; | ||
this.logger = component.get('core/logger'); | ||
this.config = config; | ||
@@ -33,3 +30,3 @@ this.ttl = 1000 * 60 * 60; // one hour | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'CacheInterface: missing method in cache class'); | ||
throw new error.DataError({method: method}, 'CacheInterface: missing method in cache object'); | ||
} | ||
@@ -36,0 +33,0 @@ }.bind(this)); |
@@ -27,3 +27,3 @@ "use strict"; | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'ComponentInterface: missing method in Component class'); | ||
throw new error.DataError({method: method}, 'ComponentInterface: missing method in Component object'); | ||
} | ||
@@ -30,0 +30,0 @@ }.bind(this)); |
@@ -23,5 +23,5 @@ "use strict"; | ||
this._request = request; | ||
["hasAction", "getAction", "redirect", "forward", "addHeader", "onEnd", "createUrl"].forEach(function (method) { | ||
["has", "get", "redirect", "forward", "addHeader", "onEnd", "createUrl"].forEach(function (method) { | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'ControllerInterface: missing method in Controller class'); | ||
throw new error.DataError({method: method}, 'ControllerInterface: missing method in Controller object'); | ||
} | ||
@@ -28,0 +28,0 @@ }.bind(this)); |
@@ -24,3 +24,3 @@ "use strict"; | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'HttpServiceInterface: missing method in HttpService class'); | ||
throw new error.DataError({method: method}, 'HttpServiceInterface: missing method in HttpService object'); | ||
} | ||
@@ -27,0 +27,0 @@ }.bind(this)); |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'RequestHooksInterface: missing method in Hook class'); | ||
throw new error.DataError({method: method}, 'RequestHooksInterface: missing method in Hook object'); | ||
} | ||
@@ -28,0 +28,0 @@ }.bind(this)); |
"use strict"; | ||
/* global loader: true, Type: true, error: true, RouteRuleInterface: true, require: true */ | ||
var di = require('../di'), | ||
Type = di.load('static-type-js'), | ||
Type = di.load('typejs'), | ||
error = di.load('error'), | ||
@@ -21,3 +21,3 @@ RouteRuleInterface; | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'RouteRuleInterface: missing method in routerRule class'); | ||
throw new error.DataError({method: method}, 'RouteRuleInterface: missing method in routerRule object'); | ||
} | ||
@@ -24,0 +24,0 @@ }.bind(this)); |
"use strict"; | ||
/* global loader: true, Type: true, error: true, RouteRuleInterface: true, require: true */ | ||
var di = require('../di'), | ||
Type = di.load('static-type-js'), | ||
Type = di.load('typejs'), | ||
error = di.load('error'), | ||
@@ -30,3 +30,3 @@ ViewInterface; | ||
if (!(method in this)) { | ||
throw new error.DataError({method: method}, 'ViewInterface: missing method in view class'); | ||
throw new error.DataError({method: method}, 'ViewInterface: missing method in view object'); | ||
} | ||
@@ -33,0 +33,0 @@ }.bind(this) |
@@ -5,3 +5,3 @@ { | ||
"description": "Powerful lightweight mvc framework for nodejs", | ||
"version": "0.1.0-alpha-7", | ||
"version": "0.1.0-alpha-8", | ||
"dependencies" : { | ||
@@ -18,3 +18,4 @@ "mongoose": "3.8.x", | ||
"gulp-istanbul": "0.5.x", | ||
"gulp-jasmine": "1.0.x" | ||
"gulp-jasmine": "1.0.x", | ||
"gulp-exit": "0.0.x" | ||
}, | ||
@@ -21,0 +22,0 @@ "repository": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
97769
3149
4
30
4