Skip to content

Commit 4fbc224

Browse files
committed
new branch v1.9.0 + new improvements
1 parent e456d47 commit 4fbc224

9 files changed

Lines changed: 162 additions & 130 deletions

File tree

builders.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @module FrameworkBuilders
3-
* @version 1.8.1
3+
* @version 1.9.0
44
*/
55

66
'use strict';
@@ -1380,7 +1380,7 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
13801380
// string
13811381
case 3:
13821382
tmp = val === undefined || val === null ? '' : autotrim(self, val.toString());
1383-
if (type.length > 0 && type.length < tmp.length)
1383+
if (type.length&& type.length < tmp.length)
13841384
tmp = tmp.substring(0, type.length);
13851385
item[property] = onPrepare(property, tmp);
13861386
break;
@@ -1465,7 +1465,7 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
14651465

14661466
case 3:
14671467
tmp = tmp === undefined || tmp === null ? '' : autotrim(self, tmp.toString());
1468-
if (type.length > 0 && tmp.length < tmp.length)
1468+
if (type.length && tmp.length < tmp.length)
14691469
tmp = tmp.substring(0, type.length);
14701470
tmp = onPrepare(property, tmp, j);
14711471
break;

changes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BETA ======= 1.8.1
1+
BETA ======= 1.9.0
22

33
- added: (IMPORTANT) ISOMORPHIC using
44
- added: (IMPORTANT) new flag `mobile` (mobile routing), you can create a route to mobile device
@@ -80,6 +80,8 @@ BETA ======= 1.8.1
8080
- fixed: Number formatting (problem with negative numbers)
8181

8282
- improved: code optimalization
83+
- improved: Date.prototype.format()
84+
- imrpoved: String.prototype.format()
8385

8486
__IMPORTANT:__
8587
`exports.install = function(framework) {}` framework variable is removed but with backward compatibility (`config['allow-compatibility']`).

image.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @module FrameworkImage
3-
* @version 1.8.1
3+
* @version 1.9.0
44
*/
55

66
'use strict';
@@ -9,7 +9,6 @@ var child = require('child_process');
99
var exec = child.exec;
1010
var spawn = child.spawn;
1111
var path = require('path');
12-
1312
var sof = { 0xc0: true, 0xc1: true, 0xc2: true, 0xc3: true, 0xc5: true, 0xc6: true, 0xc7: true, 0xc9: true, 0xca: true, 0xcb: true, 0xcd: true, 0xce: true, 0xcf: true };
1413

1514
function u16(buf, o) {

index.js

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @module Framework
3-
* @version 1.8.1
3+
* @version 1.9.0
44
*/
55

66
'use strict';
@@ -142,8 +142,8 @@ global.ROUTING = function(name) {
142142
return framework.routing(name);
143143
};
144144

145-
global.SCHEDULE = function(date, fn) {
146-
return framework.schedule(date, fn);
145+
global.SCHEDULE = function(date, each, fn) {
146+
return framework.schedule(date, each, fn);
147147
};
148148

149149
global.FINISHED = function(stream, callback) {
@@ -197,8 +197,8 @@ global.is_server = true;
197197
function Framework() {
198198

199199
this.id = null;
200-
this.version = 1810;
201-
this.version_header = '1.8.1-48';
200+
this.version = 1900;
201+
this.version_header = '1.9.0-1';
202202

203203
var version = process.version.toString().replace('v', '').replace(/\./g, '');
204204
if (version[1] === '0')
@@ -292,7 +292,7 @@ function Framework() {
292292
this.connections = {};
293293
this.functions = {};
294294
this.versions = null;
295-
this.schedules = {};
295+
this.schedules = [];
296296

297297
this.isDebug = true;
298298
this.isTest = false;
@@ -411,7 +411,6 @@ function Framework() {
411411
this._length_middleware = 0;
412412
this._length_request_middleware = 0;
413413
this._length_files = 0;
414-
this._schedules = false;
415414

416415
this.isVirtualDirectory = false;
417416
this.isWindows = os.platform().substring(0, 3).toLowerCase() === 'win';
@@ -625,10 +624,16 @@ Framework.prototype.redirect = function(host, newHost, withPath, permanent) {
625624
/**
626625
* Schedule job
627626
* @param {Date or String} date
627+
* @param {Boolean} repeat Repeat schedule
628628
* @param {Function} fn
629629
* @return {Framework}
630630
*/
631-
Framework.prototype.schedule = function(date, fn) {
631+
Framework.prototype.schedule = function(date, repeat, fn) {
632+
633+
if (fn === undefined) {
634+
fn = repeat;
635+
repeat = false;
636+
}
632637

633638
var self = this;
634639
var type = typeof(date);
@@ -639,11 +644,12 @@ Framework.prototype.schedule = function(date, fn) {
639644
date = new Date(date);
640645

641646
var sum = date.getTime();
642-
var id = Utils.GUID(5) + Utils.random(10000);
647+
var id = framework_utils.GUID(5) + framework_utils.random(10000);
643648

644-
self.schedules[id] = { expire: sum, fn: fn };
645-
self._schedules = true;
649+
if (repeat)
650+
repeat = repeat.replace('each', '1');
646651

652+
self.schedules.push({ expire: sum, fn: fn, repeat: repeat });
647653
return self;
648654
};
649655

@@ -1268,7 +1274,7 @@ Framework.prototype.middleware = function(name, funcExecute) {
12681274
Framework.prototype.use = function(name) {
12691275
var self = this;
12701276

1271-
if (arguments.length > 0) {
1277+
if (arguments.length) {
12721278
for (var i = 0; i < arguments.length; i++)
12731279
self.routes.request.push(arguments[i]);
12741280
} else if (name instanceof Array) {
@@ -2287,7 +2293,7 @@ Framework.prototype.install_prepare = function(noRecursive) {
22872293
clearTimeout(self.temporary.other.dependencies);
22882294
self.temporary.other.dependencies = setTimeout(function() {
22892295
var keys = Object.keys(framework.temporary.dependencies);
2290-
if (keys.length > 0)
2296+
if (keys.length)
22912297
throw new Error('Dependency exception (module): missing dependencies for: ' + keys.join(', ').trim());
22922298
delete self.temporary.other.dependencies;
22932299
}, 1500);
@@ -2731,7 +2737,6 @@ Framework.prototype.usage = function(detailed) {
27312737
var modules = Object.keys(self.modules);
27322738
var isomorphic = Object.keys(self.isomorphic);
27332739
var models = Object.keys(self.models);
2734-
var schedules = Object.keys(self.schedules);
27352740
var helpers = Object.keys(self.helpers);
27362741
var staticFiles = Object.keys(self.temporary.path);
27372742
var staticRange = Object.keys(self.temporary.range);
@@ -2766,7 +2771,7 @@ Framework.prototype.usage = function(detailed) {
27662771
cache: cache.length,
27672772
worker: workers.length,
27682773
connection: connections.length,
2769-
schedule: schedules.length,
2774+
schedule: self.schedules.length,
27702775
helpers: helpers.length,
27712776
error: self.errors.length,
27722777
problem: self.problems.length,
@@ -4864,29 +4869,32 @@ Framework.prototype._service = function(count) {
48644869

48654870
self.emit('service', count);
48664871

4872+
var length = self.schedules.length;
4873+
48674874
// Run schedules
4868-
if (!self._schedules)
4875+
if (!length)
48694876
return self;
48704877

48714878
var expire = new Date().getTime();
4872-
var pending = false;
4873-
4874-
// F.schedules() sets this property to true
4875-
self._schedules = false;
4879+
var index = 0;
48764880

4877-
for (var key in self.schedules) {
4878-
var obj = self.schedules[key];
4879-
if (obj.expire > expire) {
4880-
pending = true;
4881+
while (true) {
4882+
var schedule = self.schedules[index++];
4883+
if (!schedule)
4884+
break;
4885+
if (schedule.expire > expire)
48814886
continue;
4882-
}
4883-
delete self.schedules[key];
4887+
4888+
index--;
4889+
4890+
if (!schedule.repeat)
4891+
self.schedules.splice(index, 1);
4892+
else
4893+
schedule.expire = new Date().add(schedule.repeat);
4894+
48844895
obj.fn.call(self);
48854896
}
48864897

4887-
if (pending)
4888-
self._schedules = true;
4889-
48904898
return self;
48914899
};
48924900

@@ -5324,7 +5332,7 @@ Framework.prototype._upgrade_continue = function(route, req, path) {
53245332
return self;
53255333
}
53265334

5327-
var id = path + (route.flags.length > 0 ? '#' + route.flags.join('-') : '');
5335+
var id = path + (route.flags.length ? '#' + route.flags.join('-') : '');
53285336

53295337
if (route.isBINARY)
53305338
socket.type = 1;
@@ -5336,12 +5344,12 @@ Framework.prototype._upgrade_continue = function(route, req, path) {
53365344
var connection = new WebSocket(self, path, route.controller, id);
53375345
connection.route = route;
53385346
self.connections[id] = connection;
5339-
route.onInitialize.apply(connection, framework_internal.routeParam(route.param.length > 0 ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, route));
5347+
route.onInitialize.apply(connection, framework_internal.routeParam(route.param.length ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, route));
53405348
}
53415349
socket.upgrade(self.connections[id]);
53425350
};
53435351

5344-
if (route.middleware instanceof Array && route.middleware.length > 0) {
5352+
if (route.middleware instanceof Array && route.middleware.length) {
53455353
var func = new Array(route.middleware.length);
53465354
var indexer = 0;
53475355
for (var i = 0, length = route.middleware.length; i < length; i++) {
@@ -5623,7 +5631,7 @@ Framework.prototype.assert = function(name, url, flags, callback, data, cookies,
56235631
for (var i = 0; i < length; i++)
56245632
builder.push(keys[i] + '=' + encodeURIComponent(cookies[keys[i]]));
56255633

5626-
if (builder.length > 0)
5634+
if (builder.length)
56275635
headers['Cookie'] = builder.join('; ');
56285636
}
56295637

@@ -5771,7 +5779,7 @@ Framework.prototype.testing = function(stop, callback) {
57715779

57725780
var buf;
57735781

5774-
if (test.data && test.data.length > 0) {
5782+
if (test.data && test.data.length) {
57755783
buf = new Buffer(test.data, ENCODING);
57765784
test.headers[RESPONSE_HEADER_CONTENTLENGTH] = buf.length;
57775785
}
@@ -5881,7 +5889,7 @@ Framework.prototype.test = function(stop, names, cb) {
58815889
if (ext !== EXTENSION_JS)
58825890
return;
58835891

5884-
if (names.length > 0 && names.indexOf(name.substring(0, name.length - 3)) === -1)
5892+
if (names.length && names.indexOf(name.substring(0, name.length - 3)) === -1)
58855893
return;
58865894

58875895
var test = require(filename);
@@ -6562,7 +6570,7 @@ Framework.prototype._configure = function(arr, rewrite) {
65626570
if (self.config['default-timezone'])
65636571
process.env.TZ = self.config['default-timezone'];
65646572

6565-
if (accepts !== null && accepts.length > 0) {
6573+
if (accepts !== null && accepts.length) {
65666574
accepts.forEach(function(accept) {
65676575
self.config['static-accepts'][accept] = true;
65686576
});
@@ -6799,7 +6807,7 @@ Framework.prototype.lookup = function(req, url, flags, noLoggedUnlogged) {
67996807
continue;
68006808
}
68016809

6802-
if (route.flags !== null && route.flags.length > 0) {
6810+
if (route.flags !== null && route.flags.length) {
68036811
var result = framework_internal.routeCompareFlags2(req, route, noLoggedUnlogged ? true : route.isMEMBER);
68046812
if (result === -1)
68056813
req.$isAuthorized = false; // request is not authorized
@@ -6869,7 +6877,7 @@ Framework.prototype.lookup_websocket = function(req, url, noLoggedUnlogged) {
68696877
continue;
68706878
}
68716879

6872-
if (route.flags !== null && route.flags.length > 0) {
6880+
if (route.flags !== null && route.flags.length) {
68736881

68746882
// var result = framework_internal.routeCompareFlags(req.flags, route.flags, noLoggedUnlogged ? true : route.isMEMBER);
68756883
var result = framework_internal.routeCompareFlags2(req, route, noLoggedUnlogged ? true : route.isMEMBER);
@@ -8197,9 +8205,9 @@ Subscribe.prototype.doExecute = function() {
81978205
return self;
81988206

81998207
if (self.route.isGENERATOR)
8200-
async.call(controller, self.route.execute, true)(controller, framework_internal.routeParam(self.route.param.length > 0 ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, self.route));
8208+
async.call(controller, self.route.execute, true)(controller, framework_internal.routeParam(self.route.param.length ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, self.route));
82018209
else
8202-
self.route.execute.apply(controller, framework_internal.routeParam(self.route.param.length > 0 ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, self.route));
8210+
self.route.execute.apply(controller, framework_internal.routeParam(self.route.param.length ? framework_internal.routeSplit(req.uri.pathname, true) : req.path, self.route));
82038211

82048212
return self;
82058213

@@ -9113,7 +9121,7 @@ Controller.prototype.transfer = function(url, flags) {
91139121
break;
91149122
}
91159123

9116-
if (route.flags !== null && route.flags.length > 0) {
9124+
if (route.flags !== null && route.flags.length) {
91179125
var result = framework_internal.routeCompareFlags(route.flags, flags, true);
91189126
if (result === -1)
91199127
self.req.$isAuthorized = false;
@@ -12296,7 +12304,7 @@ WebSocketClient.prototype.prepare = function(flags, protocols, allow, length, ve
1229612304

1229712305
var origin = self.req.headers['origin'] || '';
1229812306

12299-
if (allow.length > 0) {
12307+
if (allow.length) {
1230012308

1230112309
if (allow.indexOf('*') === -1) {
1230212310
for (var i = 0; i < allow.length; i++) {
@@ -12311,7 +12319,7 @@ WebSocketClient.prototype.prepare = function(flags, protocols, allow, length, ve
1231112319
return false;
1231212320
}
1231312321

12314-
if (protocols.length > 0) {
12322+
if (protocols.length) {
1231512323
for (var i = 0; i < protocols.length; i++) {
1231612324
if (self.protocol.indexOf(protocols[i]) === -1)
1231712325
return false;

internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @module FrameworkInternal
3-
* @version 1.8.1
3+
* @version 1.9.0
44
*/
55

66
'use strict';
@@ -1926,7 +1926,7 @@ function view_parse(content, minify, filename) {
19261926
builder += '+' + escaper(text);
19271927
}
19281928

1929-
var fn = '(function(self,repository,model,session,query,body,url,global,helpers,user,config,functions,index,output,date,cookie,files,mobile){var get=query;var post=body;var language=this.language;var cookie=function(name){return controller.req.cookie(name);};' + (isSitemap ? 'var sitemap=function(){return self.sitemap.apply(self,arguments);};' : '') + (functions.length > 0 ? functions.join('') + ';' : '') + 'var controller=self;' + builder + ';return $output;})';
1929+
var fn = '(function(self,repository,model,session,query,body,url,global,helpers,user,config,functions,index,output,date,cookie,files,mobile){var get=query;var post=body;var language=this.language;var cookie=function(name){return controller.req.cookie(name);};' + (isSitemap ? 'var sitemap=function(){return self.sitemap.apply(self,arguments);};' : '') + (functions.length ? functions.join('') + ';' : '') + 'var controller=self;' + builder + ';return $output;})';
19301930
return eval(fn);
19311931
}
19321932

0 commit comments

Comments
 (0)