total5 0.0.1-5 → 0.0.1-7

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/builders.js CHANGED
@@ -196,7 +196,7 @@ Options.prototype.done = function(arg) {
196
196
  Options.prototype.invalid = function(error, path, index) {
197
197
  var self = this;
198
198
  self.error.push(error, path, index);
199
- self.$callback(error);
199
+ self.$callback(true);
200
200
  };
201
201
 
202
202
  Options.prototype.cookie = function(name, value, expire, options) {
@@ -321,8 +321,10 @@ ErrorBuilder.prototype.output = function(language = 'default') {
321
321
 
322
322
  let err = m.error;
323
323
 
324
- if (err[0] == '@')
324
+ if (err == '@')
325
325
  err = F.resource(language, 'T' + (err === '@' ? m.name : err.substring(1)).hash(true).toString(36)) || 'The field "' + m.name + '" is invalid';
326
+ else if (err[0] === '@')
327
+ err = F.translate(language, err);
326
328
 
327
329
  if (self.replacer) {
328
330
  for (let key in self.replacer)
@@ -1159,13 +1161,17 @@ exports.newaction = function(name, obj) {
1159
1161
  return obj;
1160
1162
  };
1161
1163
 
1164
+ function ActionCallerExec(self) {
1165
+ self.exec();
1166
+ }
1167
+
1162
1168
  function ActionCaller() {
1163
1169
  var self = this;
1164
1170
  self.$ = new Options();
1165
1171
  self.error = new ErrorBuilder();
1166
1172
  self.options = {};
1167
1173
  self.actions = [];
1168
- setImmediate(self => self.exec(), self);
1174
+ setImmediate(ActionCallerExec, self);
1169
1175
  }
1170
1176
 
1171
1177
  ActionCaller.prototype.debug = function() {
@@ -1271,13 +1277,15 @@ ActionCaller.prototype.exec = function() {
1271
1277
  if (action.jsquery) {
1272
1278
  self.error.prefix = 'query.';
1273
1279
  response = action.jsquery.transform(query, false, self.error);
1280
+ console.log(query, response, action);
1274
1281
  self.error.prefix = '';
1275
1282
  if (response.error) {
1276
1283
  self.cancel();
1277
1284
  return;
1278
1285
  }
1279
1286
  $.query = response.response;
1280
- }
1287
+ } else
1288
+ $.query = query;
1281
1289
 
1282
1290
  if (action.jsparams) {
1283
1291
  self.error.prefix = 'params.';
@@ -1288,7 +1296,8 @@ ActionCaller.prototype.exec = function() {
1288
1296
  return;
1289
1297
  }
1290
1298
  $.params = response.response;
1291
- }
1299
+ } else
1300
+ $.params = params;
1292
1301
 
1293
1302
  if (action.jsinput && type !== '-') {
1294
1303
  response = action.jsinput.transform(payload, type === '%', self.error);
@@ -1297,7 +1306,8 @@ ActionCaller.prototype.exec = function() {
1297
1306
  return;
1298
1307
  }
1299
1308
  $.payload = response.response;
1300
- }
1309
+ } else
1310
+ $.payload = payload;
1301
1311
 
1302
1312
  action.action($, $.payload);
1303
1313
  };
package/controller.js CHANGED
@@ -11,7 +11,7 @@ const REG_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Min
11
11
  const REG_ENCODINGCLEANER = /[;\s]charset=utf-8/g;
12
12
 
13
13
  const CHECK_DATA = { POST: 1, PUT: 1, PATCH: 1, DELETE: 1 };
14
- const CHECK_COMPRESSION = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'text/xml': true, 'image/svg+xml': true, 'text/x-markdown': true, 'text/html': true };
14
+ const CHECK_COMPRESSION = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'application/xml': true, 'text/xml': true, 'image/svg+xml': true, 'text/x-markdown': true, 'text/html': true };
15
15
  const CHECK_CHARSET = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'text/xml': true, 'text/x-markdown': true, 'text/html': true };
16
16
  const CHECK_NOCACHE = { zip: 1, rar: 1 };
17
17
 
@@ -998,6 +998,15 @@ function execute(ctrl) {
998
998
  if (ctrl.route.api) {
999
999
  let body = ctrl.body;
1000
1000
  if (body && typeof(body) === 'object' && body.schema && typeof(body.schema) === 'string') {
1001
+
1002
+ let index = body.schema.indexOf('?');
1003
+ let query = null;
1004
+
1005
+ if (index !== -1) {
1006
+ query = body.schema.substring(index + 1);
1007
+ body.schema = body.schema.substring(0, index);
1008
+ }
1009
+
1001
1010
  let schema = body.schema.split('/');
1002
1011
  let endpoint = ctrl.route.api[schema[0]];
1003
1012
  let params = {};
@@ -1009,6 +1018,7 @@ function execute(ctrl) {
1009
1018
  body = body.data;
1010
1019
  if (!body || typeof(body) === 'object') {
1011
1020
  ctrl.params = params;
1021
+ ctrl.query = query ? query.parseEncoded() : {};
1012
1022
  F.action(endpoint.actions, body || {}, ctrl).autorespond();
1013
1023
  return;
1014
1024
  }
@@ -16,6 +16,7 @@ var isFLOWSTREAMWORKER = false;
16
16
  var Parent = W.parentPort;
17
17
  var CALLBACKS = {};
18
18
  var FLOWS = {};
19
+ var PROXIES = {};
19
20
  var TMS = {};
20
21
  var RPC = {};
21
22
  var CALLBACKID = 1;
@@ -72,10 +73,11 @@ var isrunning = false;
72
73
  */
73
74
 
74
75
  function Instance(instance, id) {
75
- this.httproutes = {};
76
- this.version = VERSION;
77
- this.id = id;
78
- this.flow = instance;
76
+ var self = this;
77
+ self.httproutes = {};
78
+ self.version = VERSION;
79
+ self.id = id;
80
+ self.flow = instance;
79
81
  // this.onoutput = null;
80
82
  }
81
83
 
@@ -369,6 +371,16 @@ Instance.prototype.eval = function(msg, callback) {
369
371
  return self;
370
372
  };
371
373
 
374
+ Instance.prototype.restart = function() {
375
+ var self = this;
376
+ self.flow.$socket && self.flow.$socket.destroy();
377
+ self.flow.$client && self.flow.$client.destroy();
378
+ if (self.flow.terminate)
379
+ self.flow.terminate();
380
+ else
381
+ self.flow.kill(9);
382
+ };
383
+
372
384
  // Destroys the Flow
373
385
  Instance.prototype.kill = Instance.prototype.destroy = function() {
374
386
 
@@ -387,13 +399,11 @@ Instance.prototype.kill = Instance.prototype.destroy = function() {
387
399
  else
388
400
  self.flow.kill(9);
389
401
 
390
- var schema = self.flow.$schema;
391
-
392
- var tmp = F.TFlow;
393
- if (tmp.proxies[schema.proxypath]) {
394
- tmp.proxies[schema.proxypath].remove();
395
- delete tmp.proxies[schema.proxypath];
402
+ if (PROXIES[self.id]) {
403
+ PROXIES[self.id].remove();
404
+ delete PROXIES[self.id];
396
405
  }
406
+
397
407
  } else {
398
408
  if (self.flow.sockets) {
399
409
  for (var key in self.flow.sockets)
@@ -573,27 +583,32 @@ Instance.prototype.reconfigure = function(id, config) {
573
583
  return self;
574
584
  };
575
585
 
576
- Instance.prototype.reload = function(data, restart = false) {
586
+ Instance.prototype.reload = function(data) {
577
587
  var self = this;
578
588
  var flow = self.flow;
579
589
 
590
+ if (PROXIES[data.id]) {
591
+ PROXIES[data.id].remove();
592
+ delete PROXIES[data.id];
593
+ }
594
+
580
595
  if (flow.isworkerthread) {
596
+
597
+ if (data.proxypath)
598
+ PROXIES[data.id] = F.proxy(data.proxypath, data.unixsocket);
599
+
581
600
  for (let key in data)
582
601
  flow.$schema[key] = data[key];
583
- if (restart) {
584
- if (flow.terminate)
585
- flow.terminate();
586
- else
587
- flow.kill(9);
588
- } else
589
- flow.postMessage2({ TYPE: 'stream/rewrite', data: data });
602
+ self.proxypath = data.proxypath;
603
+ flow.postMessage2({ TYPE: 'stream/rewrite', data: data });
590
604
  } else {
591
605
  for (let key in data)
592
606
  flow.$schema[key] = data[key];
593
607
  flow.variables = data.variables;
608
+ if (data.variables2)
609
+ flow.variables2 = data.variables2;
594
610
  flow.rewrite(data, () => flow.proxy.refreshmeta());
595
611
  }
596
-
597
612
  return self;
598
613
  };
599
614
 
@@ -1401,6 +1416,14 @@ function init_worker(meta, type, callback) {
1401
1416
 
1402
1417
  meta.unixsocket = F.isWindows ? ('\\\\?\\pipe\\flowstream' + F.directory.makeid() + meta.id + Date.now().toString(36)) : (F.Path.join(F.Os.tmpdir(), 'flowstream_' + F.directory.makeid() + '_' + meta.id + '_' + Date.now().toString(36) + '.socket'));
1403
1418
 
1419
+ if (PROXIES[meta.id]) {
1420
+ PROXIES[meta.id].remove();
1421
+ delete PROXIES[meta.id];
1422
+ }
1423
+
1424
+ if (meta.proxypath)
1425
+ PROXIES[meta.id] = F.proxy(meta.proxypath, meta.unixsocket);
1426
+
1404
1427
  if (!worker.postMessage) {
1405
1428
  worker.postMessage = worker.send;
1406
1429
  ischild = true;
@@ -1506,7 +1529,7 @@ function init_worker(meta, type, callback) {
1506
1529
  break;
1507
1530
 
1508
1531
  case 'stream/error':
1509
- tmp = { TYPE: 'flow/error', error: msg.error, stack: msg.stack, source: msg.source, id: msg.id, component: msg.component };
1532
+ tmp = { TYPE: 'flow/error', error: msg.error, stack: msg.stack, source: msg.source, id: msg.id, component: msg.component, ts: new Date() };
1510
1533
  worker.$socket && worker.$socket.send(tmp);
1511
1534
  worker.$client && worker.$client.send(tmp);
1512
1535
  worker.$instance.onerror && worker.$instance.onerror(msg.error, msg.source, msg.id, msg.component, msg.stack);
package/flow.js CHANGED
@@ -9,7 +9,6 @@ var FS = exports;
9
9
 
10
10
  FS.module = require('./flow-flowstream');
11
11
  FS.version = 1;
12
- FS.proxies = {};
13
12
  FS.db = {};
14
13
  FS.worker = false;
15
14
  FS.instances = {};
@@ -69,25 +68,22 @@ FS.remove = function(id) {
69
68
  };
70
69
 
71
70
  FS.reload = function(flow, restart = false) {
72
-
73
71
  var prev = FS.instances[flow.id];
74
72
  if (!prev)
75
- return;
73
+ return false;
76
74
 
77
- if (prev.worker) {
78
- if (prev.proxypath !== flow.proxypath) {
79
- if (FS.proxies[prev.proxypath]) {
80
- FS.proxies[prev.proxypath].remove();
81
- delete FS.proxies[prev.proxypath];
82
- }
83
- }
84
- }
75
+ FS.db[flow.id] = flow;
85
76
 
86
- if (flow.worker && prev.proxypath !== flow.proxypath)
87
- FS.proxies[flow.proxypath] = F.proxy(flow.proxypath, flow.unixsocket);
77
+ var instance = FS.instances[flow.id];
78
+ instance.worker = flow.worker;
79
+ instance.proxypath = flow.proxypath;
88
80
 
89
- FS.db[flow.id] = flow;
90
- FS.instances[flow.id].reload(flow, restart);
81
+ if (restart)
82
+ instance.restart();
83
+ else
84
+ instance.reload(flow);
85
+
86
+ return true;
91
87
  };
92
88
 
93
89
  FS.init = function(directory, callback) {
@@ -120,9 +116,7 @@ FS.init = function(directory, callback) {
120
116
  if (response) {
121
117
  response = response.parseJSON();
122
118
  response.directory = directory;
123
- FS.load(response, function() {
124
- next();
125
- });
119
+ FS.load(response, () => next());
126
120
  } else
127
121
  next();
128
122
  });
@@ -133,7 +127,7 @@ FS.init = function(directory, callback) {
133
127
 
134
128
  };
135
129
 
136
- FS.load = function(flow, callback, restart = false) {
130
+ FS.load = function(flow, callback) {
137
131
 
138
132
  // flow.directory {String}
139
133
  // flow.asfiles {Boolean}
@@ -142,7 +136,7 @@ FS.load = function(flow, callback, restart = false) {
142
136
  // flow.proxypath {String}
143
137
 
144
138
  if (FS.instances[flow.id]) {
145
- FS.reload(flow, restart);
139
+ FS.reload(flow);
146
140
  callback && setImmediate(callback, null, FS.instances[flow.id]);
147
141
  return;
148
142
  }
@@ -155,17 +149,6 @@ FS.load = function(flow, callback, restart = false) {
155
149
 
156
150
  FS.$events.load && FS.emit('load', instance, flow);
157
151
 
158
- if (flow.worker && flow.proxypath) {
159
-
160
- // Removes old
161
- if (FS.proxies[flow.proxypath])
162
- FS.proxies[flow.proxypath].remove();
163
-
164
- // Registers new
165
- FS.proxies[flow.proxypath] = F.proxy(flow.proxypath, flow.unixsocket);
166
-
167
- }
168
-
169
152
  // instance.httprouting();
170
153
  if (callback)
171
154
  instance.ondone = err => callback(err, err ? null : instance);
@@ -214,6 +197,23 @@ FS.notify = function(controller, id) {
214
197
  $.success();
215
198
  };
216
199
 
200
+ FS.restart = function(id) {
201
+ let item = FS.instances[id];
202
+ if (item) {
203
+ if (item.flow) {
204
+ if (item.flow.terminate)
205
+ item.flow.terminate();
206
+ else
207
+ item.flow.kill(9);
208
+ return true;
209
+ }
210
+ }
211
+ };
212
+
213
+ FS.save = function(data) {
214
+ FS.onsave(data);
215
+ };
216
+
217
217
  FS.ping = function() {
218
218
  // ping all services
219
219
  for (let key in FS.instances) {
package/global.js CHANGED
@@ -126,4 +126,62 @@ global.NOSQL = F.TNoSQL.nosql;
126
126
  // Workers
127
127
  global.NEWFORK = F.TWorkers.createfork;
128
128
  global.NEWTHREAD = F.TWorkers.createthread;
129
- global.NEWTHREADPOOL = F.TWorkers.createpool;
129
+ global.NEWTHREADPOOL = F.TWorkers.createpool;
130
+
131
+ // Custom global functionality
132
+ function timeout2(key, a, b, c, d, e) {
133
+ let tmp = F.temporary.internal[key];
134
+ if (tmp) {
135
+ tmp.callback(a, b, c, d, e);
136
+ delete F.temporary.internal[key];
137
+ }
138
+ }
139
+
140
+ global.setTimeout2 = function(id, callback, timeout, limit, a, b, c, d, e) {
141
+
142
+ let key = 'timeout2' + id;
143
+ let internal = F.temporary.internal;
144
+ let cache = internal[key];
145
+
146
+ if (limit > 0) {
147
+
148
+ if (cache && cache.count >= limit) {
149
+ clearTimeout(cache.timer);
150
+ delete internal[key];
151
+ callback();
152
+ return;
153
+ }
154
+
155
+ if (cache) {
156
+ clearTimeout(cache.timer);
157
+ cache.count++;
158
+ } else
159
+ cache = internal[key] = {};
160
+
161
+ cache.callback = callback;
162
+ cache.timer = setTimeout(timeout2, timeout, key, a, b, c, d, e);
163
+
164
+ } else {
165
+
166
+ if (cache)
167
+ clearTimeout(cache.timer);
168
+ else
169
+ cache = internal[key] = {};
170
+
171
+ cache.callback = callback;
172
+ cache.timer = setTimeout(timeout2, timeout, key, a, b, c, d, e);
173
+ }
174
+ };
175
+
176
+ global.clearTimeout2 = function(id) {
177
+
178
+ let key = 'timeout2' + id;
179
+ let tmp = F.temporary.internal[key];
180
+
181
+ if (tmp) {
182
+ clearTimeout(tmp.timer);
183
+ delete F.temporary.internal[key];
184
+ }
185
+
186
+ return !!tmp;
187
+ };
package/index.js CHANGED
@@ -344,7 +344,7 @@ function unlink(arr, callback) {
344
344
  CONF.$httpmaxsize = 256; // 256 kB
345
345
  CONF.$httprangebuffer = 5120; // 5 MB
346
346
  CONF.$httptimeout = 5; // 5 seconds
347
- CONF.$httpfiles = { flac: true, jpg: true, jpeg: true, png: true, gif: true, ico: true, wasm: true, js: true, mjs: true, css: true, txt: true, xml: true, woff: true, woff2: true, otf: true, ttf: true, eot: true, svg: true, zip: true, rar: true, pdf: true, docx: true, xlsx: true, doc: true, xls: true, html: true, htm: true, appcache: true, manifest: true, map: true, ogv: true, ogg: true, mp4: true, mp3: true, webp: true, webm: true, swf: true, package: true, json: true, ui: true, md: true, m4v: true, jsx: true, heif: true, heic: true, ics: true, ts: true, m3u8: true, wav: true };
347
+ CONF.$httpfiles = { flac: true, jpg: true, jpeg: true, png: true, gif: true, ico: true, wasm: true, js: true, mjs: true, css: true, txt: true, xml: true, woff: true, woff2: true, otf: true, ttf: true, eot: true, svg: true, zip: true, rar: true, pdf: true, docx: true, xlsx: true, doc: true, xls: true, html: true, htm: true, appcache: true, manifest: true, map: true, ogv: true, ogg: true, mp4: true, mp3: true, webp: true, webm: true, swf: true, package: true, json: true, ui: true, md: true, m4v: true, jsx: true, heif: true, heic: true, ics: true, ts: true, m3u8: true, wav: true, xsd: true, xsl: true, xslt: true };
348
348
  CONF.$httpchecktypes = true; // for multipart data only
349
349
  CONF.$blacklist = '';
350
350
  CONF.$xpoweredby = 'Total.js';
@@ -2705,6 +2705,7 @@ process.connected && setTimeout(() => process.send('total:init'), 100);
2705
2705
 
2706
2706
  require('./global');
2707
2707
  require('./tangular');
2708
+ require('./markdown');
2708
2709
 
2709
2710
  // Init directories
2710
2711
  F.dir();
package/markdown.js ADDED
@@ -0,0 +1,752 @@
1
+ const REG_DASH = /-{2,}/g;
2
+ const REG_TAGS = /<[^>]*>/g;
3
+ const REG_EMPTYCHAR = /\s|\W/;
4
+ const REG_ICONS = /(^|[^\w]):((fab|far|fas|fal|fad|fa|ti)\s(fa|ti)-)?[a-z-]+:([^\w]|$)/g;
5
+ const REG_KEYWORDS = /\{.*?\}\(.*?\)/g;
6
+ const REG_LINKEXTERNAL = /(https|http):\/\//;
7
+ const REG_FORMAT = /__.*?__|_.*?_|\*\*.*?\*\*|\*.*?\*|~~.*?~~|~.*?~/g;
8
+ const REG_ORDERED = /^[a-z|0-9]{1,3}\.\s|^-\s/i;
9
+ const REG_ORDEREDSIZE = /^(\s|\t)+/;
10
+ const REG_CODE = /`.*?`/g;
11
+ const REG_ENCODETAGS = /<|>/g;
12
+ const ENCODE = val => '&' + (val === '<' ? 'lt' : 'gt') + ';';
13
+ const REG_NIL = /\0/g;
14
+
15
+ function markdown_code(value) {
16
+ return value ? ('<code>' + value.substring(1, value.length - 1) + '</code>') : '';
17
+ }
18
+
19
+ function markdown_imagelinks(value) {
20
+
21
+ if (!value)
22
+ return '';
23
+
24
+ var end = value.lastIndexOf(')') + 1;
25
+ var img = value.substring(0, end);
26
+ var url = value.substring(end + 2, value.length - 1);
27
+ var label = markdown_links(img);
28
+ var footnote = label.substring(0, 13);
29
+
30
+ if (footnote === '<sup data-id=' || footnote === '<span data-id' || label.substring(0, 9) === '<a href="')
31
+ return label;
32
+
33
+ return '<a href="' + url + '"' + (REG_LINKEXTERNAL.test(url) ? ' target="_blank"' : '') + '>' + label + '</a>';
34
+ }
35
+
36
+ function markdown_table(value, align, ishead) {
37
+
38
+ var columns = value.substring(1, value.length - 1).split('|');
39
+ var builder = '';
40
+
41
+ for (var i = 0; i < columns.length; i++) {
42
+ var column = columns[i].trim();
43
+ if (column.charAt(0) != '-') {
44
+ var a = align[i];
45
+ builder += '<' + (ishead ? 'th' : 'td') + (a && a !== 'left' ? (' class="' + a + '"') : '') + '>' + column + '</' + (ishead ? 'th' : 'td') + '>';
46
+ }
47
+ }
48
+
49
+ return '<tr>' + builder + '</tr>';
50
+ }
51
+
52
+ function markdown_links(value) {
53
+
54
+ if (!value)
55
+ return '';
56
+
57
+ var end = value.lastIndexOf(']');
58
+ var img = value.charAt(0) === '!';
59
+ var text = value.substring(img ? 2 : 1, end);
60
+ var link = value.substring(end + 2, value.length - 1);
61
+
62
+ // footnotes
63
+ if ((/^#\d+$/).test(link)) {
64
+ return (/^\d+$/).test(text) ? '<sup data-id="{0}" class="markdown-footnote">{1}</sup>'.format(link.substring(1), text) : '<span data-id="{0}" class="markdown-footnote">{1}</span>'.format(link.substring(1), text);
65
+ }
66
+
67
+ if (link.substring(0, 4) === 'www.')
68
+ link = 'https://' + link;
69
+
70
+ var nofollow = link.charAt(0) === '@' ? ' rel="nofollow"' : REG_LINKEXTERNAL.test(link) ? ' target="_blank"' : '';
71
+ return '<a href="' + link + '"' + nofollow + '>' + text + '</a>';
72
+ }
73
+
74
+ function markdown_image(value) {
75
+
76
+ var end = value.lastIndexOf(']');
77
+ var text = value.substring(2, end);
78
+ var link = value.substring(end + 2, value.length - 1);
79
+ var responsive = 1;
80
+ var f = text.charAt(0);
81
+
82
+ if (f === '+') {
83
+ responsive = 2;
84
+ text = text.substring(1);
85
+ } else if (f === '-') {
86
+ // gallery
87
+ responsive = 3;
88
+ text = text.substring(1);
89
+ }
90
+
91
+ return '<img src="' + link + '" alt="' + text + '"' + (responsive === 1 ? ' class="img-responsive"' : responsive === 3 ? ' class="markdown-gallery"' : '') + ' border="0" loading="lazy" />';
92
+ }
93
+
94
+ function markdown_keywords(value) {
95
+ var keyword = value.substring(1, value.indexOf('}'));
96
+ var type = value.substring(value.lastIndexOf('(') + 1, value.lastIndexOf(')'));
97
+ return '<span class="markdown-keyword" data-type="{0}">{1}</span>'.format(type, keyword);
98
+ }
99
+
100
+ function markdown_links2(value) {
101
+ value = value.substring(4, value.length - 4);
102
+ return '<a href="' + (value.isEmail() ? 'mailto:' : REG_LINKEXTERNAL.test(value) ? '' : 'http://') + value + '" target="_blank">' + value + '</a>';
103
+ }
104
+
105
+ function markdown_format(value, index, text) {
106
+
107
+ var p = text.charAt(index - 1);
108
+ var n = text.charAt(index + value.length);
109
+
110
+ if ((!p || REG_EMPTYCHAR.test(p)) && (!n || REG_EMPTYCHAR.test(n))) {
111
+
112
+ var beg = '';
113
+ var end = '';
114
+ var tag;
115
+
116
+ if (value.indexOf('*') !== -1) {
117
+ tag = value.indexOf('**') === -1 ? 'em' : 'strong';
118
+ beg += '<' + tag + '>';
119
+ end = '</' + tag + '>' + end;
120
+ }
121
+
122
+ if (value.indexOf('_') !== -1) {
123
+ tag = value.indexOf('__') === -1 ? 'u' : 'b';
124
+ beg += '<' + tag + '>';
125
+ end = '</' + tag + '>' + end;
126
+ }
127
+
128
+ if (value.indexOf('~') !== -1) {
129
+ beg += '<strike>';
130
+ end = '</strike>' + end;
131
+ }
132
+
133
+ var count = value.charAt(1) === value.charAt(0) ? 2 : 1;
134
+ return beg + value.substring(count, value.length - count) + end;
135
+ }
136
+
137
+ return value;
138
+ }
139
+
140
+ function markdown_id(value) {
141
+ value = value.replace(REG_TAGS, '');
142
+ return value.slug().replace(REG_DASH, '-');
143
+ }
144
+
145
+ function markdown_icon(value) {
146
+
147
+ var beg = -1;
148
+ var end = -1;
149
+
150
+ for (var i = 0; i < value.length; i++) {
151
+ var code = value.charCodeAt(i);
152
+ if (code === 58) {
153
+ if (beg === -1)
154
+ beg = i + 1;
155
+ else
156
+ end = i;
157
+ }
158
+ }
159
+
160
+ var icon = value.substring(beg, end);
161
+ if (icon.indexOf(' ') === -1)
162
+ icon = 'ti ti-' + icon;
163
+ return value.substring(0, beg - 1) + '<i class="' + icon + '"></i>' + value.substring(end + 1);
164
+ }
165
+
166
+ function markdown_urlify(str) {
167
+ return str.replace(/(^|\s)+(((https?:\/\/)|(www\.))[^\s]+)/g, function(url, b, c) {
168
+ var len = url.length;
169
+ var l = url.charAt(len - 1);
170
+ var f = url.charAt(0);
171
+ if (l === '.' || l === ',')
172
+ url = url.substring(0, len - 1);
173
+ else
174
+ l = '';
175
+ url = (c === 'www.' ? 'http://' + url : url).trim();
176
+ return (f.charCodeAt(0) < 40 ? f : '') + '[' + url + '](' + url + ')' + l;
177
+ });
178
+ }
179
+
180
+ function parseul(builder) {
181
+
182
+ var ul = {};
183
+ var is = false;
184
+ var currentindex = -1;
185
+ var output = [];
186
+
187
+ for (var i = 0; i < builder.length; i++) {
188
+
189
+ var line = builder[i];
190
+
191
+ if (line.charAt(0) === '\0') {
192
+
193
+ if (!is)
194
+ currentindex = output.push('<ul />') - 1;
195
+
196
+ var key = currentindex + '';
197
+ is = true;
198
+
199
+ var tmp = line.substring(1);
200
+ var index = tmp.indexOf('<');
201
+ var obj = {};
202
+ obj.index = i;
203
+ obj.type = tmp.substring(0, 2);
204
+ obj.offset = +tmp.substring(2, index).trim();
205
+ obj.line = line.substring(index + 1);
206
+
207
+ if (ul[key])
208
+ ul[key].push(obj);
209
+ else
210
+ ul[key] = [obj];
211
+
212
+ } else {
213
+ output.push(line);
214
+ is = false;
215
+ }
216
+ }
217
+
218
+ for (var key in ul) {
219
+
220
+ var line = +key;
221
+ var arr = ul[key];
222
+ var lines = [];
223
+ var tags = [];
224
+ var prev;
225
+ var diff;
226
+ var init = false;
227
+ var tmp;
228
+
229
+ for (var i = 0; i < arr.length; i++) {
230
+
231
+ var li = arr[i];
232
+ var beg = li.type === 'ul' ? '<ul>' : li.type === 'o1' ? '<ol type="1">' : '<ol type="a">';
233
+ var end = li.type === 'ul' ? '</ul>' : '</ol>';
234
+
235
+ var diff = li.offset - (prev ? prev.offset : 0);
236
+
237
+ // Init
238
+ if (!init) {
239
+ init = true;
240
+ lines.push(beg);
241
+ tags.push(end);
242
+ }
243
+
244
+ if (diff > 0) {
245
+ var last = lines[lines.length - 1];
246
+ last = last.replace(/<\/li>$/, '');
247
+ lines[lines.length - 1] = last;
248
+ tags.push(end + '</li>');
249
+ lines.push(beg);
250
+ lines.push(li.line);
251
+ } else if (diff < 0) {
252
+ while (diff < 0) {
253
+ tmp = tags.pop();
254
+ lines.push(tmp);
255
+ diff++;
256
+ }
257
+ lines.push(li.line);
258
+ } else {
259
+ lines.push(li.line);
260
+ }
261
+
262
+ prev = li;
263
+
264
+ }
265
+
266
+ while (tags.length)
267
+ lines.push(tags.pop());
268
+
269
+ output[line] = lines.join('\n');
270
+ }
271
+
272
+ return output;
273
+ }
274
+
275
+ function formatline(line) {
276
+ var tmp = [];
277
+ return line.replace(REG_CODE, function(text) {
278
+ tmp.push(text);
279
+ return '\0';
280
+ }).replace(REG_FORMAT, markdown_format).replace(REG_NIL, () => markdown_code(tmp.shift()));
281
+ }
282
+
283
+ function imagescope(val) {
284
+
285
+ var beg = -1;
286
+ var can = false;
287
+ var n;
288
+
289
+ for (var i = 0; i < val.length; i++) {
290
+ var c = val.charAt(i);
291
+
292
+ if (c === '[') {
293
+ beg = i;
294
+ can = false;
295
+ continue;
296
+ }
297
+
298
+ if (c === ']') {
299
+
300
+ can = false;
301
+
302
+ if (beg === -1)
303
+ continue;
304
+
305
+ n = val.charAt(i + 1);
306
+
307
+ // maybe a link mistake
308
+ if (n === ' ')
309
+ n = val.charAt(i + 2);
310
+
311
+ // maybe a link
312
+ can = n === '(';
313
+ }
314
+
315
+ if (beg > -1 && can && c === ')') {
316
+ n = val.charAt(beg - 1);
317
+ var tmp = val.substring(beg - (n === '!' ? 1 : 0), i + 1);
318
+ if (tmp.charAt(0) === '!')
319
+ val = val.replace(tmp, markdown_image(tmp));
320
+ can = false;
321
+ beg = -1;
322
+ }
323
+ }
324
+
325
+ return val;
326
+ }
327
+
328
+ function linkscope(val, index, callback) {
329
+
330
+ var beg = -1;
331
+ var beg2 = -1;
332
+ var can = false;
333
+ var skip = false;
334
+ var find = false;
335
+ var n;
336
+
337
+ for (var i = index; i < val.length; i++) {
338
+ var c = val.charAt(i);
339
+
340
+ if (c === '[') {
341
+ beg = i;
342
+ can = false;
343
+ find = true;
344
+ continue;
345
+ }
346
+
347
+ var codescope = val.substring(i, i + 6);
348
+
349
+ if (skip && codescope === '</code') {
350
+ skip = false;
351
+ i += 7;
352
+ continue;
353
+ }
354
+
355
+ if (skip)
356
+ continue;
357
+
358
+ if (!find && codescope === '<code>') {
359
+ skip = true;
360
+ continue;
361
+ }
362
+
363
+ var il = val.substring(i, i + 4);
364
+
365
+ if (il === '&lt;') {
366
+ beg2 = i;
367
+ continue;
368
+ } else if (beg2 > -1 && il === '&gt;') {
369
+ callback(val.substring(beg2, i + 4), true);
370
+ beg2 = -1;
371
+ continue;
372
+ }
373
+
374
+ if (c === ']') {
375
+
376
+ can = false;
377
+ find = false;
378
+
379
+ if (beg === -1)
380
+ continue;
381
+
382
+ n = val.charAt(i + 1);
383
+
384
+ // maybe a link mistake
385
+ if (n === ' ')
386
+ n = val.charAt(i + 2);
387
+
388
+ // maybe a link
389
+ can = n === '(';
390
+ }
391
+
392
+ if (beg > -1 && can && c === ')') {
393
+ n = val.charAt(beg - 1);
394
+ callback(val.substring(beg - (n === '!' ? 1 : 0), i + 1));
395
+ can = false;
396
+ find = false;
397
+ beg = -1;
398
+ }
399
+ }
400
+ }
401
+
402
+ String.prototype.markdown = function(opt, nested) {
403
+
404
+ // opt.wrap = true;
405
+ // opt.linetag = 'p';
406
+ // opt.ul = true;
407
+ // opt.code = true;
408
+ // opt.images = true;
409
+ // opt.links = true;
410
+ // opt.formatting = true;
411
+ // opt.icons = true;
412
+ // opt.tables = true;
413
+ // opt.br = true;
414
+ // opt.headlines = true;
415
+ // opt.hr = true;
416
+ // opt.blockquotes = true;
417
+ // opt.sections = true;
418
+ // opt.custom
419
+ // opt.footnotes = true;
420
+ // opt.urlify = true;
421
+ // opt.keywords = true;
422
+ // opt.emptynewline = true;
423
+
424
+ var str = this;
425
+
426
+ if (!opt)
427
+ opt = {};
428
+
429
+ var lines = str.split('\n');
430
+ var builder = [];
431
+ var ul = [];
432
+ var table = false;
433
+ var iscode = false;
434
+ var isblock = false;
435
+ var ishead = 0;
436
+ var isprevblock = false;
437
+ var headline = '<{0} id="{3}" class="markdown-line" data-index="{1}">{2}</{0}>';
438
+ var line;
439
+ var tmp;
440
+
441
+ if (opt.wrap == null)
442
+ opt.wrap = true;
443
+
444
+ if (opt.linetag == null)
445
+ opt.linetag = 'p';
446
+
447
+ var closeul = function() {
448
+ while (ul.length) {
449
+ var text = ul.pop();
450
+ builder.push('</' + text + '>');
451
+ }
452
+ };
453
+
454
+ var linkreplace = function(text, inline) {
455
+ if (inline)
456
+ opt.$line = opt.$line.replace(text, markdown_links2);
457
+ else if (opt.images !== false)
458
+ opt.$line = opt.$line.replace(text, markdown_imagelinks);
459
+ else
460
+ opt.$line = opt.$line.replace(text, text => markdown_links(text, opt.images));
461
+ };
462
+
463
+ for (var i = 0; i < lines.length; i++) {
464
+
465
+ lines[i] = lines[i].replace(REG_ENCODETAGS, ENCODE);
466
+
467
+ if (!lines[i]) {
468
+ builder.push('');
469
+ continue;
470
+ }
471
+
472
+ var three = lines[i].substring(0, 3);
473
+
474
+ if (!iscode && (three === ':::' || (three === '==='))) {
475
+
476
+ if (isblock) {
477
+ if (opt.blocks !== false)
478
+ builder[builder.length - 1] += '</div></div>';
479
+ isblock = false;
480
+ isprevblock = true;
481
+ continue;
482
+ }
483
+
484
+ closeul();
485
+ isblock = true;
486
+ if (opt.blocks !== false) {
487
+ line = lines[i].substring(3).trim();
488
+ if (opt.formatting !== false)
489
+ line = formatline(line);
490
+ if (opt.custom)
491
+ line = opt.custom(line);
492
+ if (opt.html)
493
+ line = opt.html(line, 'block');
494
+ builder.push('<div class="markdown-block markdown-line" data-line="{0}"><span class="markdown-showblock"><i class="ti ti-plus"></i>{1}</span><div class="hidden">'.format(i, line));
495
+ }
496
+ continue;
497
+ }
498
+
499
+ if (!isblock && lines[i] && isprevblock) {
500
+ builder.push('<br />');
501
+ isprevblock = false;
502
+ }
503
+
504
+ if (three === '```') {
505
+
506
+ if (iscode) {
507
+ if (opt.code !== false)
508
+ builder[builder.length - 1] += '</code></pre></div>';
509
+ iscode = false;
510
+ continue;
511
+ }
512
+
513
+ closeul();
514
+ iscode = true;
515
+ if (opt.code !== false)
516
+ tmp = '<div class="markdown-code markdown-line hidden"><pre class="noscrollbar"><code class="lang-{0}">'.format(lines[i].substring(3));
517
+ continue;
518
+ }
519
+
520
+ if (iscode) {
521
+ if (opt.code !== false)
522
+ builder.push(tmp + lines[i]);
523
+ if (tmp)
524
+ tmp = '';
525
+ continue;
526
+ }
527
+
528
+ line = lines[i];
529
+
530
+ if (opt.br !== false)
531
+ line = line.replace(/&lt;br(\s\/)?&gt;/g, '<br />');
532
+
533
+ if (line.length > 10 && opt.urlify !== false && opt.links !== false)
534
+ line = markdown_urlify(line);
535
+
536
+ if (opt.custom)
537
+ line = opt.custom(line);
538
+
539
+ if (line.length > 2 && line !== '***' && line !== '---') {
540
+
541
+ if (opt.formatting !== false)
542
+ line = formatline(line);
543
+
544
+ if (opt.images !== false)
545
+ line = imagescope(line);
546
+
547
+ if (opt.links !== false) {
548
+ opt.$line = line;
549
+ linkscope(line, 0, linkreplace);
550
+ line = opt.$line;
551
+ }
552
+
553
+ if (opt.keywords !== false)
554
+ line = line.replace(REG_KEYWORDS, markdown_keywords);
555
+
556
+ if (opt.icons !== false)
557
+ line = line.replace(REG_ICONS, markdown_icon);
558
+ }
559
+
560
+ if (!line) {
561
+ if (table) {
562
+ table = null;
563
+ if (opt.tables !== false)
564
+ builder.push('</tbody></table>');
565
+ }
566
+ }
567
+
568
+ if (line === '' && lines[i - 1] === '') {
569
+ closeul();
570
+ if (opt.emptynewline !== false)
571
+ builder.push('<br />');
572
+ continue;
573
+ }
574
+
575
+ if (line[0] === '|') {
576
+ closeul();
577
+
578
+ if (!table) {
579
+ var next = lines[i + 1];
580
+ if (next[0] === '|') {
581
+ if (next.indexOf('--') === -1) {
582
+ if (opt.tables !== false)
583
+ builder.push('<table class="table table-bordered"><thead>');
584
+ table = [];
585
+ ishead = 2;
586
+ } else {
587
+ table = [];
588
+ var columns = next.substring(1, next.length - 1).split('|');
589
+ for (var j = 0; j < columns.length; j++) {
590
+ var column = columns[j].trim();
591
+ var align = 'left';
592
+ if (column.charAt(column.length - 1) === ':')
593
+ align = column[0] === ':' ? 'center' : 'right';
594
+ table.push(align);
595
+ }
596
+ if (opt.tables !== false)
597
+ builder.push('<table class="table table-bordered"><thead>');
598
+ ishead = 1;
599
+ i++;
600
+ }
601
+ } else
602
+ continue;
603
+ }
604
+
605
+ if (opt.tables !== false) {
606
+ if (ishead === 1)
607
+ builder.push(markdown_table(line, table, true) + '</thead><tbody>');
608
+ else if (ishead === 2)
609
+ builder.push('<tbody>' + markdown_table(line, table));
610
+ else
611
+ builder.push(markdown_table(line, table));
612
+ }
613
+
614
+ ishead = 0;
615
+ continue;
616
+ }
617
+
618
+ if (line.charAt(0) === '#') {
619
+
620
+ closeul();
621
+
622
+ if (line.substring(0, 2) === '# ') {
623
+ tmp = line.substring(2).trim();
624
+ if (opt.headlines !== false) {
625
+ if (opt.html)
626
+ tmp = opt.html(tmp, '#');
627
+ builder.push(headline.format('h1', i, tmp, markdown_id(tmp)));
628
+ }
629
+ continue;
630
+ }
631
+
632
+ if (line.substring(0, 3) === '## ') {
633
+ tmp = line.substring(3).trim();
634
+ if (opt.headlines !== false) {
635
+ if (opt.html)
636
+ tmp = opt.html(tmp, '##');
637
+ builder.push(headline.format('h2', i, tmp, markdown_id(tmp)));
638
+ }
639
+ continue;
640
+ }
641
+
642
+ if (line.substring(0, 4) === '### ') {
643
+ tmp = line.substring(4).trim();
644
+ if (opt.headlines !== false) {
645
+ if (opt.html)
646
+ tmp = opt.html(tmp, '###');
647
+ builder.push(headline.format('h3', i, tmp, markdown_id(tmp)));
648
+ }
649
+ continue;
650
+ }
651
+
652
+ if (line.substring(0, 5) === '#### ') {
653
+ tmp = line.substring(5).trim();
654
+ if (opt.headlines !== false) {
655
+ if (opt.html)
656
+ tmp = opt.html(tmp, '####');
657
+ builder.push(headline.format('h4', i, tmp, markdown_id(tmp)));
658
+ }
659
+ continue;
660
+ }
661
+
662
+ if (line.substring(0, 6) === '##### ') {
663
+ tmp = line.substring(6).trim();
664
+ if (opt.headlines !== false) {
665
+ if (opt.html)
666
+ tmp = opt.html(tmp, '#####');
667
+ builder.push(headline.format('h5', i, tmp, markdown_id(tmp)));
668
+ }
669
+ continue;
670
+ }
671
+ }
672
+
673
+ tmp = line.substring(0, 3);
674
+
675
+ if (tmp === '---' || tmp === '***') {
676
+ if (opt.hr !== false)
677
+ builder.push('<hr class="markdown-line' + (tmp.charAt(0) === '-' ? '1' : '2') + ' markdown-line" data-line="' + i + '" />');
678
+ continue;
679
+ }
680
+
681
+ // footnotes
682
+ if ((/^#\d+:(\s)+/).test(line)) {
683
+ if (opt.footnotes !== false) {
684
+ tmp = line.indexOf(':');
685
+ builder.push('<div class="markdown-footnotebody" data-id="{0}"><span>{0}:</span> {1}</div>'.format(line.substring(1, tmp).trim(), line.substring(tmp + 1).trim()));
686
+ }
687
+ continue;
688
+ }
689
+
690
+ if (line.substring(0, 5) === '&gt; ') {
691
+ if (opt.blockquotes !== false) {
692
+ line = line.substring(5).trim();
693
+ if (opt.html)
694
+ line = opt.html(line, 'blockquote');
695
+ builder.push('<blockquote class="markdown-line" data-line="' + i + '">' + line + '</blockquote>');
696
+ }
697
+ continue;
698
+ }
699
+
700
+ if (line.substring(0, 5) === '&lt; ') {
701
+ if (opt.sections !== false) {
702
+ line = line.substring(5).trim();
703
+ if (opt.html)
704
+ line = opt.html(line, 'section');
705
+ builder.push('<section class="markdown-line" data-line="' + i + '">' + line + '</section>');
706
+ }
707
+ continue;
708
+ }
709
+
710
+ var tmpline = line.trim();
711
+
712
+ if (opt.ul !== false && REG_ORDERED.test(tmpline)) {
713
+
714
+ var size = line.match(REG_ORDEREDSIZE);
715
+ if (size)
716
+ size = size[0].length;
717
+ else
718
+ size = 0;
719
+
720
+ var ultype = tmpline.charAt(0) === '-' ? 'ul' : 'ol';
721
+ var tmpstr = (ultype === 'ol' ? tmpline.substring(tmpline.indexOf('.') + 1) : tmpline.substring(2));
722
+ var istask = false;
723
+
724
+ var tt = tmpstr.trim().substring(0, 3);
725
+ istask = tt === '[ ]' || tt === '[x]';
726
+
727
+ var tmpval = tmpstr.trim();
728
+
729
+ if (opt.html)
730
+ tmpval = opt.html(tmpval, 'li');
731
+
732
+ builder.push('\0' + (ultype === 'ol' ? ('o' + ((/\d+\./).test(tmpline) ? '1' : 'a')) : 'ul') + size + '<li data-line="{0}" class="markdown-line{1}">'.format(i, istask ? ' markdown-task' : '') + tmpval.replace(/\[x\]/g, '<i class="ti ti-check-square green"></i>').replace(/\[\s\]/g, '<i class="ti ti-square"></i>') + '</li>');
733
+
734
+ } else {
735
+ closeul();
736
+ if (line) {
737
+ line = line.trim();
738
+ if (opt.html)
739
+ line = opt.html(line, opt.linetag);
740
+ }
741
+ line && builder.push((opt.linetag ? ('<' + opt.linetag + ' class="markdown-line" data-line="' + i + '">') : '') + line.trim() + (opt.linetag ? ('</' + opt.linetag + '>') : ''));
742
+ }
743
+ }
744
+
745
+ closeul();
746
+
747
+ table && opt.tables !== false && builder.push('</tbody></table>');
748
+ iscode && opt.code !== false && builder.push('</code></pre>');
749
+
750
+ builder = parseul(builder);
751
+ return (opt.wrap ? ('<div class="markdown' + (nested ? '' : ' markdown-container') + '">') : '') + builder.join('\n').replace(/\t/g, ' ') + (opt.wrap ? '</div>' : '');
752
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.1-5",
3
+ "version": "0.0.1-7",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/tms.js CHANGED
@@ -8,7 +8,6 @@ var Cache = {
8
8
  subscribers: {},
9
9
  swatchers: {}, // watchers for subscribers
10
10
  scache: {}, // cache for subscribers
11
- publishers: {},
12
11
  pcache: {}, // cache for publishers
13
12
  calls: {},
14
13
  socket: null,
@@ -46,7 +45,7 @@ function tmscontroller($) {
46
45
  }
47
46
 
48
47
  delete temporary.tmsblocked[client.ip];
49
- Cache.publishers = {};
48
+ client.$subscribers = {};
50
49
  client.tmsready = true;
51
50
  refresh(client);
52
51
  });
@@ -71,9 +70,9 @@ function tmscontroller($) {
71
70
  F.TTMS.subscribe(msg.id, response, client);
72
71
  }
73
72
  } else if (msg.type === 'subscribers' && msg.subscribers instanceof Array) {
74
- Cache.publishers = {};
75
- for (var i = 0; i < msg.subscribers.length; i++)
76
- Cache.publishers[msg.subscribers[i]] = 1;
73
+ client.$subscribers = {};
74
+ for (let sub of msg.subscribers)
75
+ client.$subscribers[sub] = true;
77
76
  } else if (msg.type === 'call' && msg.id) {
78
77
  var tmp = Cache.calls[msg.id];
79
78
  if (tmp) {
@@ -315,9 +314,9 @@ exports.newsubscribe = function(name, schema, callback) {
315
314
  };
316
315
 
317
316
  exports.publish = function(name, value) {
318
- if (Cache.socket && Cache.pcache[name] && Cache.publishers[name]) {
317
+ if (Cache.socket && Cache.pcache[name]) {
319
318
  F.stats.performance.publish++;
320
- Cache.socket.send({ type: 'publish', id: name, data: value }, client => client.tmsready);
319
+ Cache.socket.send({ type: 'publish', id: name, data: value }, client => client.tmsready && client.$subscribers[name]);
321
320
  }
322
321
  };
323
322
 
package/utils.js CHANGED
@@ -349,6 +349,7 @@ var CONTENTTYPES = {
349
349
  xml: 'application/xml',
350
350
  xpm: 'image/x-xpixmap',
351
351
  xsl: 'application/xml',
352
+ xsd: 'application/xml',
352
353
  xslt: 'application/xslt+xml',
353
354
  zip: 'application/zip',
354
355
  '7zip': 'application/x-7z-compressed'
@@ -3163,6 +3164,11 @@ SP.parseConfig = function(def, onerr) {
3163
3164
  } else
3164
3165
  subtype = '';
3165
3166
 
3167
+ if (value.substring(0, 7) === 'base64 ' && value.length > 8)
3168
+ value = Buffer.from(value.substring(7).trim(), 'base64').toString('utf8');
3169
+ else if (value.substring(0, 4) === 'hex ' && value.length > 6)
3170
+ value = Buffer.from(value.substring(4).trim(), 'hex').toString('utf8');
3171
+
3166
3172
  switch (subtype) {
3167
3173
  case 'string':
3168
3174
  obj[name] = value;