total5 0.0.1-9 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.js +18 -10
- package/bin/flow5 +142 -0
- package/bin/total5 +166 -905
- package/builders.js +90 -35
- package/changelog.txt +3 -1
- package/cluster.js +1 -1
- package/cms.js +185 -51
- package/controller.js +233 -70
- package/cron.js +1 -1
- package/debug.js +12 -5
- package/edit.js +26 -33
- package/filestorage.js +38 -17
- package/flow-flowstream.js +199 -68
- package/flow.js +16 -10
- package/flowstream.js +4 -3
- package/global.js +84 -1
- package/htmlparser.js +41 -29
- package/http.js +3 -1
- package/image.js +4 -0
- package/images.js +1 -1
- package/index.js +246 -117
- package/jsonschema.js +21 -17
- package/macros.js +222 -0
- package/mail.js +11 -27
- package/markdown.js +21 -11
- package/minificators.js +1 -1
- package/nosql-querybuilder.js +4 -0
- package/nosql.js +8 -0
- package/openclient.js +1 -1
- package/package.json +4 -3
- package/pause.html +1 -1
- package/release.js +1 -1
- package/routing.js +118 -35
- package/sourcemap.js +6 -3
- package/test.js +9 -2
- package/tms.js +11 -14
- package/uibuilder.js +59 -23
- package/utils.js +147 -102
- package/viewengine.js +19 -8
- package/websocket.js +10 -6
- package/503.html +0 -65
- package/CONTRIBUTING.md +0 -55
- package/helpers/index.js +0 -32
- package/templates.json +0 -74
- package/tests/bundles/index.js +0 -25
- package/tests/cron.js +0 -0
- package/tests/htmlparser.js +0 -0
- package/tests/minifactors.js +0 -17
- package/tests/nosql.js +0 -18
- package/tests/proxy/index.js +0 -21
- package/tests/routing/index.js +0 -27
- package/tests/schemas.js +0 -17
- package/tests/server/index.js +0 -24
- package/tests/staticfiles/index.js +0 -24
- package/tests/utils.js +0 -17
- package/tmsclient.js +0 -125
- package/todo.txt +0 -11
- package/tools/beta.sh +0 -6
- package/tools/release.sh +0 -6
package/global.js
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
7
|
global.ON = (name, fn) => F.on(name, fn);
|
|
8
|
+
global.ONCE = (name, fn) => F.once(name, fn);
|
|
8
9
|
global.EMIT = (name, a, b, c, d, e, f, g) => F.emit(name, a, b, c, d, e, f, g);
|
|
9
10
|
global.OFF = (name, fn) => F.off(name, fn);
|
|
10
11
|
global.ROUTE = F.TRouting.route;
|
|
11
12
|
global.PROXY = F.TRouting.proxy;
|
|
12
13
|
global.print = console.log;
|
|
14
|
+
global.LOAD = F.load;
|
|
13
15
|
global.LOADCONFIG = F.loadconfig;
|
|
14
16
|
global.LOADRESOURCE = F.loadresource;
|
|
15
17
|
global.SHELL = F.shell;
|
|
@@ -21,6 +23,7 @@ global.LOCALIZE = F.localize;
|
|
|
21
23
|
global.AUTH = F.auth;
|
|
22
24
|
global.CLEANUP = F.cleanup;
|
|
23
25
|
global.NEWDB = F.newdb;
|
|
26
|
+
global.IMPORT = F.import;
|
|
24
27
|
global.REQUIRE = F.require;
|
|
25
28
|
global.CRON = F.cron;
|
|
26
29
|
global.UID = F.uid;
|
|
@@ -30,6 +33,7 @@ global.AUDIT = F.audit;
|
|
|
30
33
|
global.TRANSLATE = F.translate;
|
|
31
34
|
global.TRANSFORM = F.transform;
|
|
32
35
|
global.NEWTRANSFORM = F.newtransform;
|
|
36
|
+
global.MIDDLEWARE = F.middleware;
|
|
33
37
|
global.DATA = new F.TQueryBuilder.Controller(true);
|
|
34
38
|
global.DB = () => new F.TQueryBuilder.Controller();
|
|
35
39
|
global.CACHE = F.cache;
|
|
@@ -55,6 +59,8 @@ global.Mail = F.TMail.Mailer;
|
|
|
55
59
|
global.RESTBuilder = F.TBuilders.RESTBuilder;
|
|
56
60
|
global.ErrorBuilder = F.TBuilders.ErrorBuilder;
|
|
57
61
|
global.DOWNLOAD = F.download;
|
|
62
|
+
global.OPENCLIENT = (url, id) => require('./openclient').create(url, id);
|
|
63
|
+
global.NEWMACRO = (str, nocompile, isasync) => require('./macros').compile(str, nocompile, isasync);
|
|
58
64
|
|
|
59
65
|
global.BLOCKED = function($, limit, expire) {
|
|
60
66
|
|
|
@@ -97,7 +103,84 @@ global.LDAP = function(opt, callback) {
|
|
|
97
103
|
};
|
|
98
104
|
|
|
99
105
|
global.CORS = function(origin) {
|
|
100
|
-
|
|
106
|
+
if (origin && origin[0] === '+') {
|
|
107
|
+
if (F.config.$cors !== '*')
|
|
108
|
+
F.config.$cors = (F.config.$cors ? ',' : '') + origin.substring(1);
|
|
109
|
+
} else
|
|
110
|
+
F.config.$cors = origin || '*';
|
|
111
|
+
F.emit('$cors');
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
global.AJAX = function(url, data, callback) {
|
|
115
|
+
|
|
116
|
+
if (typeof(data) === 'function') {
|
|
117
|
+
callback = data;
|
|
118
|
+
data = null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!callback)
|
|
122
|
+
return new Promise((resolve, reject) => global.AJAX(url, data, (err, response) => err ? reject(err) : resolve(response)));
|
|
123
|
+
|
|
124
|
+
var index = url.indexOf(' ');
|
|
125
|
+
var opt = {};
|
|
126
|
+
|
|
127
|
+
if (index !== -1) {
|
|
128
|
+
opt.method = url.substring(0, index);
|
|
129
|
+
opt.url = url.substring(index + 1);
|
|
130
|
+
} else {
|
|
131
|
+
opt.method = 'GET';
|
|
132
|
+
opt.url = url;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (data) {
|
|
136
|
+
opt.type = 'json';
|
|
137
|
+
opt.body = JSON.stringify(data);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
opt.headers = { 'X-Requested-With': 'XMLHttpRequest' };
|
|
141
|
+
|
|
142
|
+
opt.callback = function(err, response) {
|
|
143
|
+
|
|
144
|
+
if (err) {
|
|
145
|
+
callback && callback(err, null, response);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var type = err ? '' : response.headers['content-type'] || '';
|
|
150
|
+
if (type) {
|
|
151
|
+
var index = type.lastIndexOf(';');
|
|
152
|
+
if (index !== -1)
|
|
153
|
+
type = type.substring(0, index).trim();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var value = null;
|
|
157
|
+
|
|
158
|
+
switch (type.toLowerCase()) {
|
|
159
|
+
case 'text/xml':
|
|
160
|
+
case 'application/xml':
|
|
161
|
+
value = response.body ? response.body.parseXML(self.$replace ? true : false) : {};
|
|
162
|
+
break;
|
|
163
|
+
case 'application/x-www-form-urlencoded':
|
|
164
|
+
value = response.body ? DEF.parsers.urlencoded(response.body) : {};
|
|
165
|
+
break;
|
|
166
|
+
case 'application/json':
|
|
167
|
+
case 'text/json':
|
|
168
|
+
value = response.body ? response.body.parseJSON(true) : null;
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
value = response.body;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (response.status >= 400) {
|
|
176
|
+
err = value;
|
|
177
|
+
value = null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
delete response.body;
|
|
181
|
+
callback && callback(err, value, response);
|
|
182
|
+
};
|
|
183
|
+
F.TUtils.request(opt);
|
|
101
184
|
};
|
|
102
185
|
|
|
103
186
|
// Utils
|
package/htmlparser.js
CHANGED
|
@@ -46,20 +46,22 @@ function parseRule(selector, output) {
|
|
|
46
46
|
|
|
47
47
|
selector = selector.replace(/\[\d+\]/, text => cache[+text.substring(1, text.length - 1)]);
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
// attribute search
|
|
50
|
+
match = selector.match(/\[.*?\]/i);
|
|
50
51
|
if (match) {
|
|
51
52
|
for (var m of match) {
|
|
52
|
-
var
|
|
53
|
-
rule.attrs.push({ id: m
|
|
53
|
+
var index = m.indexOf('=');
|
|
54
|
+
rule.attrs.push({ id: m.substring(1, index).trim(), value: m.substring(index + 2, m.length - 2).trim() });
|
|
54
55
|
}
|
|
55
56
|
selector = selector.replace(match, '');
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
// #id or .class
|
|
60
|
+
var match = selector.match(/[#|.][a-z-_0-9]+/i);
|
|
59
61
|
if (match) {
|
|
60
62
|
for (var m of match) {
|
|
61
|
-
var
|
|
62
|
-
rule.attrs.push({ id: m
|
|
63
|
+
var val = m.substring(1);
|
|
64
|
+
rule.attrs.push({ id: m[0] === '#' ? 'id' : 'class', value: val });
|
|
63
65
|
}
|
|
64
66
|
selector = selector.replace(match, '');
|
|
65
67
|
}
|
|
@@ -134,6 +136,13 @@ function extendarr(output) {
|
|
|
134
136
|
return this;
|
|
135
137
|
};
|
|
136
138
|
|
|
139
|
+
output.toString = output.html = function(formatted) {
|
|
140
|
+
var builder = [];
|
|
141
|
+
for (var item of this)
|
|
142
|
+
builder.push(item.toString(formatted));
|
|
143
|
+
return builder.join(formatted ? '\n' : '');
|
|
144
|
+
};
|
|
145
|
+
|
|
137
146
|
return output;
|
|
138
147
|
}
|
|
139
148
|
|
|
@@ -160,9 +169,7 @@ HTMLElement.prototype.find = function(selector, reverse) {
|
|
|
160
169
|
skip = true;
|
|
161
170
|
|
|
162
171
|
if (rule.attrs.length && !skip) {
|
|
163
|
-
|
|
164
172
|
for (var attr of rule.attrs) {
|
|
165
|
-
|
|
166
173
|
switch (attr.id) {
|
|
167
174
|
|
|
168
175
|
case 'class':
|
|
@@ -278,7 +285,7 @@ HTMLElement.prototype.stringifycache = function() {
|
|
|
278
285
|
var tmp = [];
|
|
279
286
|
|
|
280
287
|
for (var key in self.cache.css)
|
|
281
|
-
tmp.push(key + ':' + self.cache.css[key]);
|
|
288
|
+
self.cache.css[key] && tmp.push(key + ':' + self.cache.css[key]);
|
|
282
289
|
|
|
283
290
|
if (tmp.length)
|
|
284
291
|
self.attrs.style = tmp.join(';');
|
|
@@ -353,7 +360,7 @@ HTMLElement.prototype.css = function(key, value) {
|
|
|
353
360
|
var self = this;
|
|
354
361
|
self.parsecache();
|
|
355
362
|
if (typeof(key) === 'object') {
|
|
356
|
-
for (var k of key) {
|
|
363
|
+
for (var k of Object.keys(key)) {
|
|
357
364
|
value = key[k];
|
|
358
365
|
if (value)
|
|
359
366
|
self.cache.css[k] = value;
|
|
@@ -383,7 +390,7 @@ HTMLElement.prototype.remove = function() {
|
|
|
383
390
|
HTMLElement.prototype.append = function(str) {
|
|
384
391
|
|
|
385
392
|
var self = this;
|
|
386
|
-
var dom = parseHTML(str);
|
|
393
|
+
var dom = parseHTML(str, null, null, self.xml);
|
|
387
394
|
|
|
388
395
|
for (var item of dom.children)
|
|
389
396
|
self.children.push(item);
|
|
@@ -394,7 +401,7 @@ HTMLElement.prototype.append = function(str) {
|
|
|
394
401
|
HTMLElement.prototype.prepend = function(str) {
|
|
395
402
|
|
|
396
403
|
var self = this;
|
|
397
|
-
var dom = parseHTML(str);
|
|
404
|
+
var dom = parseHTML(str, null, null, self.xml);
|
|
398
405
|
|
|
399
406
|
for (var item of dom.children)
|
|
400
407
|
self.children.unshift(item);
|
|
@@ -462,17 +469,18 @@ function removeComments(html) {
|
|
|
462
469
|
break;
|
|
463
470
|
|
|
464
471
|
var comment = html.substring(beg, end + 3);
|
|
465
|
-
html = html.
|
|
472
|
+
html = html.replaceAll(comment, '');
|
|
466
473
|
beg = html.indexOf(tagBeg, beg);
|
|
467
474
|
}
|
|
468
475
|
|
|
469
476
|
return html;
|
|
470
477
|
}
|
|
471
478
|
|
|
472
|
-
function parseHTML(html, trim, onerror) {
|
|
479
|
+
function parseHTML(html, trim, onerror, isxml) {
|
|
473
480
|
|
|
474
481
|
var makeText = function(parent, str) {
|
|
475
482
|
var obj = new HTMLElement();
|
|
483
|
+
obj.xml = isxml;
|
|
476
484
|
obj.tagName = 'TEXT';
|
|
477
485
|
obj.children = [];
|
|
478
486
|
obj.attrs = {};
|
|
@@ -482,7 +490,7 @@ function parseHTML(html, trim, onerror) {
|
|
|
482
490
|
};
|
|
483
491
|
|
|
484
492
|
var parseAttrs = function(str) {
|
|
485
|
-
var attrs = str.match(/[a-z-0-
|
|
493
|
+
var attrs = str.match(/[a-z-0-9A-Z\:]+(=("|').*?("|'))?/g);
|
|
486
494
|
var obj = {};
|
|
487
495
|
if (attrs) {
|
|
488
496
|
for (var m of attrs) {
|
|
@@ -532,8 +540,10 @@ function parseHTML(html, trim, onerror) {
|
|
|
532
540
|
var node = str.substring(beg + 1, end);
|
|
533
541
|
var dom = new HTMLElement();
|
|
534
542
|
|
|
535
|
-
|
|
536
|
-
|
|
543
|
+
dom.xml = isxml;
|
|
544
|
+
|
|
545
|
+
// Doctype or xml?
|
|
546
|
+
if (node[0] === '!' || node[0] === '?')
|
|
537
547
|
return str.substring(end + 1);
|
|
538
548
|
|
|
539
549
|
if (node[node.length - 1] === '/') {
|
|
@@ -565,15 +575,17 @@ function parseHTML(html, trim, onerror) {
|
|
|
565
575
|
str = str.substring(end + 1);
|
|
566
576
|
|
|
567
577
|
// Unpair tags
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
578
|
+
if (!isxml) {
|
|
579
|
+
switch (dom.tagName) {
|
|
580
|
+
case 'BR':
|
|
581
|
+
case 'HR':
|
|
582
|
+
case 'IMG':
|
|
583
|
+
case 'META':
|
|
584
|
+
case 'LINK':
|
|
585
|
+
case 'INPUT':
|
|
586
|
+
dom.unpair = true;
|
|
587
|
+
return str;
|
|
588
|
+
}
|
|
577
589
|
}
|
|
578
590
|
|
|
579
591
|
var pos = 0;
|
|
@@ -614,8 +626,7 @@ function parseHTML(html, trim, onerror) {
|
|
|
614
626
|
}
|
|
615
627
|
|
|
616
628
|
var inner = str.substring(0, pos - tagEnd.length);
|
|
617
|
-
|
|
618
|
-
if (inner.indexOf('<') === -1 || (/script|style|template/).test(tag)) {
|
|
629
|
+
if (inner.indexOf('<') === -1 || (/\<(script|style|template)/).test(tag)) {
|
|
619
630
|
if (trim)
|
|
620
631
|
inner = inner.trim();
|
|
621
632
|
if (inner)
|
|
@@ -640,6 +651,7 @@ function parseHTML(html, trim, onerror) {
|
|
|
640
651
|
html = removeComments(html);
|
|
641
652
|
|
|
642
653
|
var dom = new HTMLElement();
|
|
654
|
+
dom.xml = isxml;
|
|
643
655
|
|
|
644
656
|
while (html)
|
|
645
657
|
html = parseElements(html, dom);
|
|
@@ -647,4 +659,4 @@ function parseHTML(html, trim, onerror) {
|
|
|
647
659
|
return dom;
|
|
648
660
|
}
|
|
649
661
|
|
|
650
|
-
exports.parseHTML = parseHTML;
|
|
662
|
+
exports.parseHTML = parseHTML;
|
package/http.js
CHANGED
|
@@ -20,6 +20,8 @@ exports.listen = function(req, res) {
|
|
|
20
20
|
// res.write();
|
|
21
21
|
// res.end()
|
|
22
22
|
|
|
23
|
+
F.stats.request.request++;
|
|
24
|
+
|
|
23
25
|
// Not supported
|
|
24
26
|
if (req.method === 'HEAD') {
|
|
25
27
|
F.stats.request.blocked++;
|
|
@@ -63,7 +65,7 @@ exports.listen = function(req, res) {
|
|
|
63
65
|
// Pending requests
|
|
64
66
|
F.temporary.pending.push(ctrl);
|
|
65
67
|
|
|
66
|
-
if (
|
|
68
|
+
if (ctrl.headers.origin && (F.def.onCORS || F.config.$cors)) {
|
|
67
69
|
if (F.TRouting.lookupcors(ctrl))
|
|
68
70
|
ctrl.$route();
|
|
69
71
|
} else
|
package/image.js
CHANGED
package/images.js
CHANGED
|
@@ -196,7 +196,7 @@ ImageProto.measure = function(callback) {
|
|
|
196
196
|
|
|
197
197
|
F.stats.performance.open++;
|
|
198
198
|
var extension = self.filename.substring(index).toLowerCase();
|
|
199
|
-
var stream =
|
|
199
|
+
var stream = F.Fs.createReadStream(self.filename, { start: 0, end: (extension === '.jpg' || extension === '.webp') ? 40000 : 24 });
|
|
200
200
|
|
|
201
201
|
stream.on('data', function(buffer) {
|
|
202
202
|
|