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/flow-flowstream.js
CHANGED
|
@@ -81,6 +81,25 @@ function Instance(instance, id) {
|
|
|
81
81
|
// this.onoutput = null;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
Instance.prototype = {
|
|
85
|
+
|
|
86
|
+
get stats() {
|
|
87
|
+
return this.worker ? this.worker.stats : this.flow.stats;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
get worker() {
|
|
91
|
+
return this.flow;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
get stream() {
|
|
95
|
+
return this.flow;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
Instance.prototype.postMessage = function(msg) {
|
|
100
|
+
this.flow.postMessage && this.flow.postMessage(msg);
|
|
101
|
+
};
|
|
102
|
+
|
|
84
103
|
Instance.prototype.httprequest = function(opt, callback) {
|
|
85
104
|
|
|
86
105
|
// opt.route {String} a URL address
|
|
@@ -191,7 +210,7 @@ Instance.prototype.httprouting = function() {
|
|
|
191
210
|
|
|
192
211
|
if (meta.headers) {
|
|
193
212
|
for (var key in meta.headers)
|
|
194
|
-
self.
|
|
213
|
+
self.response.headers[key] = meta.headers[key];
|
|
195
214
|
}
|
|
196
215
|
|
|
197
216
|
if (meta.cookies && meta.cookies instanceof Array) {
|
|
@@ -200,7 +219,7 @@ Instance.prototype.httprouting = function() {
|
|
|
200
219
|
var value = item.value;
|
|
201
220
|
var expiration = item.expiration || item.expires || item.expire;
|
|
202
221
|
if (name && value && expiration)
|
|
203
|
-
self.
|
|
222
|
+
self.cookie(name, value, expiration, item.options || item.config);
|
|
204
223
|
}
|
|
205
224
|
}
|
|
206
225
|
|
|
@@ -211,13 +230,13 @@ Instance.prototype.httprouting = function() {
|
|
|
211
230
|
break;
|
|
212
231
|
case 'text':
|
|
213
232
|
case 'plain':
|
|
214
|
-
self.
|
|
233
|
+
self.text(data);
|
|
215
234
|
break;
|
|
216
235
|
case 'html':
|
|
217
|
-
self.
|
|
236
|
+
self.html(data);
|
|
218
237
|
break;
|
|
219
238
|
case 'xml':
|
|
220
|
-
self.
|
|
239
|
+
self.binary(Buffer.from(data, 'utf8'), 'text/xml');
|
|
221
240
|
break;
|
|
222
241
|
case 'json':
|
|
223
242
|
self.json(data);
|
|
@@ -307,20 +326,20 @@ function execfn(self, name, id, data) {
|
|
|
307
326
|
if (!flow.paused) {
|
|
308
327
|
if (id[0] === '@') {
|
|
309
328
|
id = id.substring(1);
|
|
310
|
-
for (
|
|
311
|
-
|
|
329
|
+
for (let key in flow.meta.flow) {
|
|
330
|
+
let com = flow.meta.flow[key];
|
|
312
331
|
if (com.component === id && com[name])
|
|
313
332
|
com[name](data);
|
|
314
333
|
}
|
|
315
334
|
} else if (id[0] === '#') {
|
|
316
335
|
id = id.substring(1);
|
|
317
|
-
for (
|
|
318
|
-
|
|
336
|
+
for (let key in flow.meta.flow) {
|
|
337
|
+
let com = flow.meta.flow[key];
|
|
319
338
|
if (com.module.name === id && com[name])
|
|
320
339
|
com[name](data);
|
|
321
340
|
}
|
|
322
341
|
} else {
|
|
323
|
-
|
|
342
|
+
let com = flow.meta.flow[id];
|
|
324
343
|
if (com && com[name])
|
|
325
344
|
com[name](data);
|
|
326
345
|
}
|
|
@@ -381,6 +400,10 @@ Instance.prototype.restart = function() {
|
|
|
381
400
|
self.flow.kill(9);
|
|
382
401
|
};
|
|
383
402
|
|
|
403
|
+
Instance.prototype.remove = function() {
|
|
404
|
+
F.TFlow.remove(this.id);
|
|
405
|
+
};
|
|
406
|
+
|
|
384
407
|
// Destroys the Flow
|
|
385
408
|
Instance.prototype.kill = Instance.prototype.destroy = function() {
|
|
386
409
|
|
|
@@ -388,16 +411,12 @@ Instance.prototype.kill = Instance.prototype.destroy = function() {
|
|
|
388
411
|
|
|
389
412
|
setTimeout(() => exports.refresh(self.id, 'destroy'), 500);
|
|
390
413
|
self.flow.$destroyed = true;
|
|
414
|
+
self.flow.$terminated = true;
|
|
391
415
|
|
|
392
416
|
if (self.flow.isworkerthread) {
|
|
393
417
|
|
|
394
|
-
self.
|
|
395
|
-
self.flow
|
|
396
|
-
|
|
397
|
-
if (self.flow.terminate)
|
|
398
|
-
self.flow.terminate();
|
|
399
|
-
else
|
|
400
|
-
self.flow.kill(9);
|
|
418
|
+
self.postMessage({ TYPE: 'stream/destroy' });
|
|
419
|
+
setTimeout(self => self.flow.terminate ? self.flow.terminate() : self.flow.kill(9), 1000, self);
|
|
401
420
|
|
|
402
421
|
if (PROXIES[self.id]) {
|
|
403
422
|
PROXIES[self.id].remove();
|
|
@@ -409,11 +428,12 @@ Instance.prototype.kill = Instance.prototype.destroy = function() {
|
|
|
409
428
|
for (var key in self.flow.sockets)
|
|
410
429
|
self.flow.sockets[key].destroy();
|
|
411
430
|
}
|
|
412
|
-
self.flow.$socket && self.flow.$socket.destroy();
|
|
413
|
-
self.flow.$client && self.flow.$client.destroy();
|
|
414
431
|
self.flow.destroy();
|
|
415
432
|
}
|
|
416
433
|
|
|
434
|
+
self.flow.$socket && self.flow.$socket.destroy();
|
|
435
|
+
self.flow.$client && self.flow.$client.destroy();
|
|
436
|
+
|
|
417
437
|
for (var key in CALLBACKS) {
|
|
418
438
|
if (CALLBACKS[key].id === self.id)
|
|
419
439
|
delete CALLBACKS[key];
|
|
@@ -594,13 +614,22 @@ Instance.prototype.reload = function(data) {
|
|
|
594
614
|
|
|
595
615
|
if (flow.isworkerthread) {
|
|
596
616
|
|
|
597
|
-
if (data.proxypath)
|
|
617
|
+
if (data.proxypath) {
|
|
618
|
+
|
|
619
|
+
if (!data.unixsocket) {
|
|
620
|
+
data.unixsocket = flow.$schema.unixsocket || makeunixsocket(data.id);
|
|
621
|
+
flow.$schema.unixsocket = data.unixsocket;
|
|
622
|
+
}
|
|
623
|
+
|
|
598
624
|
PROXIES[data.id] = F.proxy(data.proxypath, data.unixsocket);
|
|
625
|
+
}
|
|
599
626
|
|
|
600
627
|
for (let key in data)
|
|
601
628
|
flow.$schema[key] = data[key];
|
|
629
|
+
|
|
602
630
|
self.proxypath = data.proxypath;
|
|
603
631
|
flow.postMessage2({ TYPE: 'stream/rewrite', data: data });
|
|
632
|
+
|
|
604
633
|
} else {
|
|
605
634
|
for (let key in data)
|
|
606
635
|
flow.$schema[key] = data[key];
|
|
@@ -774,7 +803,7 @@ function send(self, id, data, callback) {
|
|
|
774
803
|
} else if (id[0] === '#') {
|
|
775
804
|
id = id.substring(1);
|
|
776
805
|
for (let key in instances) {
|
|
777
|
-
if (instances[key].module
|
|
806
|
+
if (instances[key].module.name === id) {
|
|
778
807
|
instance = instances[key];
|
|
779
808
|
break;
|
|
780
809
|
}
|
|
@@ -834,14 +863,14 @@ function exec(self, opt) {
|
|
|
834
863
|
|
|
835
864
|
if (opt.id[0] === '@') {
|
|
836
865
|
id = opt.id.substring(1);
|
|
837
|
-
for (
|
|
866
|
+
for (let key in instances) {
|
|
838
867
|
if (instances[key].component === id)
|
|
839
868
|
target.push(instances[key]);
|
|
840
869
|
}
|
|
841
870
|
} else if (opt.id[0] === '#') {
|
|
842
871
|
id = opt.id.substring(1);
|
|
843
|
-
for (
|
|
844
|
-
if (instances[key].module.
|
|
872
|
+
for (let key in instances) {
|
|
873
|
+
if (instances[key].module.name === id)
|
|
845
874
|
target.push(instances[key]);
|
|
846
875
|
}
|
|
847
876
|
} else {
|
|
@@ -958,7 +987,7 @@ function init_current(meta, callback, nested) {
|
|
|
958
987
|
|
|
959
988
|
// Due to C/C++ modules
|
|
960
989
|
if (W.workerData || meta.sandbox)
|
|
961
|
-
|
|
990
|
+
F.config.$node_modules = F.path.join(meta.directory, meta.id, 'node_modules');
|
|
962
991
|
|
|
963
992
|
ASFILES = meta.asfiles === true;
|
|
964
993
|
|
|
@@ -977,6 +1006,12 @@ function init_current(meta, callback, nested) {
|
|
|
977
1006
|
}
|
|
978
1007
|
}
|
|
979
1008
|
|
|
1009
|
+
flow.env = meta.env;
|
|
1010
|
+
flow.origin = meta.origin;
|
|
1011
|
+
flow.proxypath = meta.proxypath || '';
|
|
1012
|
+
flow.proxy.online = false;
|
|
1013
|
+
flow.proxy.ping = 0;
|
|
1014
|
+
|
|
980
1015
|
if (meta.import) {
|
|
981
1016
|
var tmp = meta.import.split(/,|;/).trim();
|
|
982
1017
|
for (var m of tmp) {
|
|
@@ -986,11 +1021,13 @@ function init_current(meta, callback, nested) {
|
|
|
986
1021
|
}
|
|
987
1022
|
}
|
|
988
1023
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1024
|
+
if (meta.initscript) {
|
|
1025
|
+
try {
|
|
1026
|
+
new Function('instance', meta.initscript)(flow);
|
|
1027
|
+
} catch (e) {
|
|
1028
|
+
flow.error(e, 'initscript');
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
994
1031
|
|
|
995
1032
|
flow.$instance = new Instance(flow, meta.id);
|
|
996
1033
|
|
|
@@ -999,7 +1036,6 @@ function init_current(meta, callback, nested) {
|
|
|
999
1036
|
};
|
|
1000
1037
|
|
|
1001
1038
|
if (!nested && Parent) {
|
|
1002
|
-
|
|
1003
1039
|
Parent.on('message', function(msg) {
|
|
1004
1040
|
|
|
1005
1041
|
var id;
|
|
@@ -1011,6 +1047,10 @@ function init_current(meta, callback, nested) {
|
|
|
1011
1047
|
flow.proxy.ping = setTimeout(killprocess, 10000);
|
|
1012
1048
|
break;
|
|
1013
1049
|
|
|
1050
|
+
case 'stream/destroy':
|
|
1051
|
+
flow.destroy();
|
|
1052
|
+
break;
|
|
1053
|
+
|
|
1014
1054
|
case 'stream/export':
|
|
1015
1055
|
msg.data = flow.export2();
|
|
1016
1056
|
Parent.postMessage(msg);
|
|
@@ -1235,6 +1275,10 @@ function init_current(meta, callback, nested) {
|
|
|
1235
1275
|
}
|
|
1236
1276
|
});
|
|
1237
1277
|
|
|
1278
|
+
flow.proxy.remove = function() {
|
|
1279
|
+
Parent.postMessage({ TYPE: 'stream/remove' });
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1238
1282
|
flow.proxy.kill = function() {
|
|
1239
1283
|
Parent.postMessage({ TYPE: 'stream/kill' });
|
|
1240
1284
|
};
|
|
@@ -1268,12 +1312,20 @@ function init_current(meta, callback, nested) {
|
|
|
1268
1312
|
var componentid = '';
|
|
1269
1313
|
|
|
1270
1314
|
if (instance) {
|
|
1271
|
-
if (
|
|
1315
|
+
if (typeof(instance) === 'string') {
|
|
1316
|
+
if (source === 'add') {
|
|
1317
|
+
componentid = instance;
|
|
1318
|
+
F.error(err, 'FlowStream | register component | ' + instance);
|
|
1319
|
+
} else if (meta.design[instance]) {
|
|
1320
|
+
instanceid = instance;
|
|
1321
|
+
componentid = meta.design[instance].component;
|
|
1322
|
+
}
|
|
1323
|
+
} else if (source === 'instance_message') {
|
|
1272
1324
|
if (instance.instance) {
|
|
1273
1325
|
instanceid = instance.instance.id;
|
|
1274
1326
|
componentid = instance.instance.component;
|
|
1275
1327
|
} else
|
|
1276
|
-
|
|
1328
|
+
F.error(err, 'FlowStream | message | ' + instance);
|
|
1277
1329
|
} else if (source === 'instance_close') {
|
|
1278
1330
|
instanceid = instance.id;
|
|
1279
1331
|
componentid = instance.component;
|
|
@@ -1336,6 +1388,10 @@ function init_current(meta, callback, nested) {
|
|
|
1336
1388
|
// nothing
|
|
1337
1389
|
};
|
|
1338
1390
|
|
|
1391
|
+
flow.proxy.remove = function() {
|
|
1392
|
+
flow.$instance.remove();
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1339
1395
|
flow.proxy.kill = function() {
|
|
1340
1396
|
flow.$instance.kill();
|
|
1341
1397
|
};
|
|
@@ -1370,8 +1426,8 @@ function init_current(meta, callback, nested) {
|
|
|
1370
1426
|
|
|
1371
1427
|
flow.proxy.error = function(err, source, instance) {
|
|
1372
1428
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1429
|
+
let instanceid = '';
|
|
1430
|
+
let componentid = '';
|
|
1375
1431
|
|
|
1376
1432
|
if (instance) {
|
|
1377
1433
|
if (source === 'instance_message') {
|
|
@@ -1392,6 +1448,9 @@ function init_current(meta, callback, nested) {
|
|
|
1392
1448
|
}
|
|
1393
1449
|
}
|
|
1394
1450
|
|
|
1451
|
+
let tmp = { TYPE: 'flow/error', error: err.toString(), source: source, id: instanceid, component: componentid, ts: new Date() };
|
|
1452
|
+
flow.$socket && flow.$socket.send(tmp);
|
|
1453
|
+
flow.$client && flow.$client.send(tmp);
|
|
1395
1454
|
flow.$instance.onerror && flow.$instance.onerror(err, source, instanceid, componentid);
|
|
1396
1455
|
};
|
|
1397
1456
|
|
|
@@ -1414,7 +1473,7 @@ function init_worker(meta, type, callback) {
|
|
|
1414
1473
|
var worker = type === 'worker' ? (new W.Worker(__filename, { workerData: meta })) : Fork(__filename, forkargs, { serialization: 'json', detached: false });
|
|
1415
1474
|
var ischild = false;
|
|
1416
1475
|
|
|
1417
|
-
meta.unixsocket =
|
|
1476
|
+
meta.unixsocket = makeunixsocket(meta.id);
|
|
1418
1477
|
|
|
1419
1478
|
if (PROXIES[meta.id]) {
|
|
1420
1479
|
PROXIES[meta.id].remove();
|
|
@@ -1466,10 +1525,14 @@ function init_worker(meta, type, callback) {
|
|
|
1466
1525
|
|
|
1467
1526
|
var tmp;
|
|
1468
1527
|
|
|
1528
|
+
Flow.$events.message && Flow.emit('message', worker.$instance.id, msg);
|
|
1529
|
+
|
|
1469
1530
|
switch (msg.TYPE) {
|
|
1470
1531
|
|
|
1471
1532
|
case 'stream/stats':
|
|
1472
1533
|
worker.stats = msg.data;
|
|
1534
|
+
if (Flow.$events.stats)
|
|
1535
|
+
Flow.emit('stats', meta.id, msg.data);
|
|
1473
1536
|
break;
|
|
1474
1537
|
|
|
1475
1538
|
case 'stream/restart':
|
|
@@ -1484,6 +1547,11 @@ function init_worker(meta, type, callback) {
|
|
|
1484
1547
|
worker.$instance.destroy(msg.code || 9);
|
|
1485
1548
|
break;
|
|
1486
1549
|
|
|
1550
|
+
case 'stream/remove':
|
|
1551
|
+
if (!worker.$terminated)
|
|
1552
|
+
worker.$instance.remove();
|
|
1553
|
+
break;
|
|
1554
|
+
|
|
1487
1555
|
case 'stream/send':
|
|
1488
1556
|
tmp = CALLBACKS[msg.callbackid];
|
|
1489
1557
|
if (tmp) {
|
|
@@ -1843,51 +1911,44 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
1843
1911
|
}
|
|
1844
1912
|
};
|
|
1845
1913
|
|
|
1914
|
+
function stringifyskip(key, value) {
|
|
1915
|
+
return key === '$$ID' || key === '$$REQUIRED' ? undefined : value;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1846
1918
|
flow.export2 = function() {
|
|
1847
1919
|
|
|
1848
1920
|
var variables = flow.variables;
|
|
1849
1921
|
var design = {};
|
|
1850
1922
|
var components = {};
|
|
1851
|
-
var sources = {};
|
|
1852
|
-
|
|
1853
|
-
for (var key in flow.sources) {
|
|
1854
|
-
var com = flow.sources[key];
|
|
1855
|
-
sources[key] = com;
|
|
1856
|
-
}
|
|
1923
|
+
var sources = flow.sources ? JSON.parse(JSON.stringify(flow.sources, stringifyskip)) : {};
|
|
1857
1924
|
|
|
1858
|
-
for (
|
|
1859
|
-
|
|
1925
|
+
for (let key in flow.meta.components) {
|
|
1926
|
+
let com = flow.meta.components[key];
|
|
1860
1927
|
components[key] = com.ui.raw;
|
|
1861
1928
|
}
|
|
1862
1929
|
|
|
1863
|
-
for (
|
|
1930
|
+
for (let key in flow.meta.flow) {
|
|
1864
1931
|
design[key] = flow.export_instance2(key);
|
|
1932
|
+
delete design[key].template;
|
|
1933
|
+
}
|
|
1865
1934
|
|
|
1866
1935
|
var data = {};
|
|
1936
|
+
var blacklist = { unixsocket: 1, components: 1, variables2: 1, sources: 1, design: 1, size: 1, directory: 1 };
|
|
1937
|
+
|
|
1938
|
+
for (let key in flow.$schema) {
|
|
1939
|
+
if (!blacklist[key])
|
|
1940
|
+
data[key] = flow.$schema[key];
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1867
1943
|
data.paused = flow.paused;
|
|
1868
|
-
data.id = flow.$schema.id;
|
|
1869
|
-
data.reference = flow.$schema.reference;
|
|
1870
|
-
data.author = flow.$schema.author;
|
|
1871
|
-
data.group = flow.$schema.group;
|
|
1872
|
-
data.icon = flow.$schema.icon;
|
|
1873
|
-
data.color = flow.$schema.color;
|
|
1874
|
-
data.version = flow.$schema.version;
|
|
1875
|
-
data.cloning = flow.$schema.cloning;
|
|
1876
|
-
data.readme = flow.$schema.readme;
|
|
1877
|
-
data.url = flow.$schema.url;
|
|
1878
|
-
data.name = flow.$schema.name;
|
|
1879
1944
|
data.components = components;
|
|
1880
1945
|
data.design = design;
|
|
1881
1946
|
data.variables = variables;
|
|
1882
1947
|
data.sources = sources;
|
|
1883
|
-
data.proxypath = flow.$schema.proxypath;
|
|
1884
|
-
data.origin = flow.$schema.origin;
|
|
1885
|
-
data.dtcreated = flow.$schema.dtcreated;
|
|
1886
|
-
data.import = flow.$schema.import;
|
|
1887
1948
|
return data;
|
|
1888
1949
|
};
|
|
1889
1950
|
|
|
1890
|
-
var
|
|
1951
|
+
var saveforce = function() {
|
|
1891
1952
|
saveid && clearTimeout(saveid);
|
|
1892
1953
|
saveid = null;
|
|
1893
1954
|
flow.proxy.save(flow.export2());
|
|
@@ -1903,13 +1964,17 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
1903
1964
|
return;
|
|
1904
1965
|
|
|
1905
1966
|
clearTimeout(saveid);
|
|
1906
|
-
saveid = setTimeout(
|
|
1967
|
+
saveid = setTimeout(saveforce, 5000);
|
|
1907
1968
|
};
|
|
1908
1969
|
|
|
1909
1970
|
flow.save = function() {
|
|
1910
1971
|
save();
|
|
1911
1972
|
};
|
|
1912
1973
|
|
|
1974
|
+
flow.remove = function() {
|
|
1975
|
+
flow.proxy.remove();
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1913
1978
|
flow.kill = function(code) {
|
|
1914
1979
|
flow.proxy.kill(code);
|
|
1915
1980
|
};
|
|
@@ -1945,7 +2010,7 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
1945
2010
|
};
|
|
1946
2011
|
|
|
1947
2012
|
flow.redraw = refresh_components;
|
|
1948
|
-
flow.sources = meta.sources;
|
|
2013
|
+
flow.sources = meta.sources || {};
|
|
1949
2014
|
flow.proxy = {};
|
|
1950
2015
|
|
|
1951
2016
|
flow.proxy.variables = function(data) {
|
|
@@ -1962,6 +2027,9 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
1962
2027
|
};
|
|
1963
2028
|
|
|
1964
2029
|
flow.proxy.message = function(msg, clientid, callback) {
|
|
2030
|
+
|
|
2031
|
+
var tmp;
|
|
2032
|
+
|
|
1965
2033
|
switch (msg.TYPE) {
|
|
1966
2034
|
|
|
1967
2035
|
case 'call':
|
|
@@ -2243,6 +2311,19 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2243
2311
|
break;
|
|
2244
2312
|
|
|
2245
2313
|
case 'component_read':
|
|
2314
|
+
|
|
2315
|
+
tmp = flow.meta.components[msg.id];
|
|
2316
|
+
if (tmp && tmp.meta) {
|
|
2317
|
+
if (tmp.meta.readonly) {
|
|
2318
|
+
msg.TYPE = 'flow/component_read';
|
|
2319
|
+
msg.data = null;
|
|
2320
|
+
msg.error = 'The component cannot be edited';
|
|
2321
|
+
flow.proxy.online && flow.proxy.send(msg, 1, clientid);
|
|
2322
|
+
callback && callback(msg);
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2246
2327
|
msg.TYPE = 'flow/component_read';
|
|
2247
2328
|
msg.data = flow.meta.components[msg.id] ? flow.meta.components[msg.id].ui.raw : null;
|
|
2248
2329
|
msg.error = msg.data == null ? 'Not found' : null;
|
|
@@ -2251,6 +2332,19 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2251
2332
|
break;
|
|
2252
2333
|
|
|
2253
2334
|
case 'component_save':
|
|
2335
|
+
|
|
2336
|
+
// check prev functionality
|
|
2337
|
+
tmp = flow.meta.components[msg.id];
|
|
2338
|
+
if (tmp && tmp.meta) {
|
|
2339
|
+
if (tmp.meta.readonly) {
|
|
2340
|
+
msg.TYPE = 'flow/component_save';
|
|
2341
|
+
msg.error = 'The component cannot be edited';
|
|
2342
|
+
flow.proxy.online && flow.proxy.send(msg, 1, clientid);
|
|
2343
|
+
callback && callback(msg);
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2254
2348
|
flow.add(msg.id, msg.data, function(err) {
|
|
2255
2349
|
delete msg.data;
|
|
2256
2350
|
msg.TYPE = 'flow/component_save';
|
|
@@ -2263,10 +2357,24 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2263
2357
|
break;
|
|
2264
2358
|
|
|
2265
2359
|
case 'component_remove':
|
|
2360
|
+
|
|
2361
|
+
// check prev functionality
|
|
2362
|
+
tmp = flow.meta.components[msg.id];
|
|
2363
|
+
if (tmp && tmp.meta) {
|
|
2364
|
+
if (tmp.meta.protected) {
|
|
2365
|
+
msg.TYPE = 'flow/component_remove';
|
|
2366
|
+
msg.error = 'The component cannot be removed';
|
|
2367
|
+
flow.proxy.online && flow.proxy.send(msg, 1, clientid);
|
|
2368
|
+
callback && callback(msg);
|
|
2369
|
+
return;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2266
2373
|
flow.unregister(msg.id, function() {
|
|
2267
2374
|
refresh_components();
|
|
2268
2375
|
save();
|
|
2269
2376
|
});
|
|
2377
|
+
|
|
2270
2378
|
break;
|
|
2271
2379
|
}
|
|
2272
2380
|
};
|
|
@@ -2340,7 +2448,8 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2340
2448
|
|
|
2341
2449
|
if (stats.minutes !== minutes) {
|
|
2342
2450
|
minutes = stats.minutes;
|
|
2343
|
-
|
|
2451
|
+
if (isFLOWSTREAMWORKER)
|
|
2452
|
+
memory = process.memoryUsage().heapUsed;
|
|
2344
2453
|
}
|
|
2345
2454
|
|
|
2346
2455
|
flow.stats.memory = memory;
|
|
@@ -2349,7 +2458,13 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2349
2458
|
// Each 9 seconds
|
|
2350
2459
|
if (notifier % 3 === 0) {
|
|
2351
2460
|
notifier = 0;
|
|
2352
|
-
Parent
|
|
2461
|
+
if (Parent || Flow.$events.stats) {
|
|
2462
|
+
let pstats = { paused: flow.paused, messages: flow.stats.messages, pending: flow.stats.pending, memory: flow.stats.memory, minutes: flow.stats.minutes, errors: flow.stats.errors, mm: flow.stats.mm, pid: process.pid };
|
|
2463
|
+
if (Parent)
|
|
2464
|
+
Parent.postMessage({ TYPE: 'stream/stats', data: pstats });
|
|
2465
|
+
else if (Flow.$events.stats)
|
|
2466
|
+
Flow.emit(flow.$schema.id, pstats);
|
|
2467
|
+
}
|
|
2353
2468
|
}
|
|
2354
2469
|
|
|
2355
2470
|
notifier++;
|
|
@@ -2580,12 +2695,22 @@ function MAKEFLOWSTREAM(meta) {
|
|
|
2580
2695
|
});
|
|
2581
2696
|
|
|
2582
2697
|
var makemeta = function() {
|
|
2583
|
-
return { TYPE: 'flow/flowstream', id: flow.$schema.id, version: VERSION, paused: flow.paused, node: F.version_node, total: F.version, name: flow.$schema.name, version2: flow.$schema.version, icon: flow.$schema.icon, reference: flow.$schema.reference, author: flow.$schema.author, color: flow.$schema.color, origin: flow.$schema.origin, notify: flow.$schema.origin + NOTIFYPATH + flow.$schema.id + '-/', readme: flow.$schema.readme, url: flow.$schema.url, proxypath: flow.$schema.proxypath, env: flow.$schema.env, worker: isFLOWSTREAMWORKER ? (W.workerData ? 'Worker Thread' : 'Child Process') : false, cloning: flow.cloning };
|
|
2698
|
+
return { TYPE: 'flow/flowstream', id: flow.$schema.id, version: VERSION, paused: flow.paused, node: F.version_node, total: F.version, name: flow.$schema.name, version2: flow.$schema.version, icon: flow.$schema.icon, reference: flow.$schema.reference, author: flow.$schema.author, color: flow.$schema.color, origin: flow.$schema.origin, notify: flow.$schema.origin + NOTIFYPATH + flow.$schema.id + '-/', readme: flow.$schema.readme, url: flow.$schema.url, proxypath: isFLOWSTREAMWORKER ? flow.$schema.proxypath : '/', env: flow.$schema.env, worker: isFLOWSTREAMWORKER ? (W.workerData ? 'Worker Thread' : 'Child Process') : false, cloning: flow.cloning };
|
|
2584
2699
|
};
|
|
2585
2700
|
|
|
2586
2701
|
flow.proxy.refreshmeta = function() {
|
|
2702
|
+
|
|
2587
2703
|
flow.origin = flow.$schema.origin;
|
|
2588
2704
|
flow.proxypath = flow.$schema.proxypath || '';
|
|
2705
|
+
|
|
2706
|
+
if (isFLOWSTREAMWORKER) {
|
|
2707
|
+
if (flow.proxypath) {
|
|
2708
|
+
if (!F.server)
|
|
2709
|
+
F.httpload({ unixsocket: flow.$schema.unixsocket });
|
|
2710
|
+
} else if (F.server)
|
|
2711
|
+
F.server.close();
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2589
2714
|
flow.cloning = flow.$schema.cloning != false;
|
|
2590
2715
|
flow.proxy.send(makemeta(), 0);
|
|
2591
2716
|
};
|
|
@@ -2831,13 +2956,14 @@ TMS.connect = function(fs, sourceid, callback) {
|
|
|
2831
2956
|
callback && setImmediate(callback);
|
|
2832
2957
|
};
|
|
2833
2958
|
|
|
2959
|
+
// In the Flow will be the "Publish" mentioned in the "Subscribe" group
|
|
2834
2960
|
const TEMPLATE_PUBLISH = `<script total>
|
|
2835
2961
|
|
|
2836
2962
|
exports.name = '{0}';
|
|
2837
2963
|
exports.icon = '{3}';
|
|
2838
2964
|
exports.config = {};
|
|
2839
2965
|
exports.outputs = [{ id: 'publish', name: 'Output' }];
|
|
2840
|
-
exports.group = '
|
|
2966
|
+
exports.group = 'Subscribe';
|
|
2841
2967
|
exports.type = 'pub';
|
|
2842
2968
|
exports.schemaid = ['{7}', '{1}'];
|
|
2843
2969
|
|
|
@@ -2864,11 +2990,12 @@ const TEMPLATE_PUBLISH = `<script total>
|
|
|
2864
2990
|
</header>
|
|
2865
2991
|
</body>`;
|
|
2866
2992
|
|
|
2993
|
+
// In the Flow will be the "Subscribe" mentioned in the "Publish" group
|
|
2867
2994
|
const TEMPLATE_SUBSCRIBE = `<script total>
|
|
2868
2995
|
|
|
2869
2996
|
exports.name = '{0}';
|
|
2870
2997
|
exports.icon = '{3}';
|
|
2871
|
-
exports.group = '
|
|
2998
|
+
exports.group = 'Publish';
|
|
2872
2999
|
exports.config = {};
|
|
2873
3000
|
exports.inputs = [{ id: 'subscribe', name: 'Input' }];
|
|
2874
3001
|
exports.type = 'sub';
|
|
@@ -3190,6 +3317,10 @@ function initrunning() {
|
|
|
3190
3317
|
|
|
3191
3318
|
}
|
|
3192
3319
|
|
|
3320
|
+
function makeunixsocket(id) {
|
|
3321
|
+
return F.isWindows ? ('\\\\?\\pipe\\flowstream' + F.directory.makeid() + id + Date.now().toString(36)) : (F.Path.join(F.Os.tmpdir(), 'flowstream_' + F.directory.makeid() + '_' + id + '_' + Date.now().toString(36) + '.socket'));
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3193
3324
|
if (process.argv[1].endsWith('flow-flowstream.js')) {
|
|
3194
3325
|
|
|
3195
3326
|
isFLOWSTREAMWORKER = W.workerData || process.argv.indexOf('--fork') !== -1;
|
package/flow.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Total.js Flow module
|
|
2
|
+
// The MIT License
|
|
3
|
+
// Copyright 2023 (c) Peter Širka <petersirka@gmail.com>
|
|
2
4
|
|
|
3
5
|
'use strict';
|
|
4
6
|
|
|
@@ -40,7 +42,7 @@ FS.onerror = function(err, source, id, componentid, stack) {
|
|
|
40
42
|
meta.source = source;
|
|
41
43
|
meta.instanceid = id;
|
|
42
44
|
meta.componentid = componentid;
|
|
43
|
-
|
|
45
|
+
F.emit('flowstream_error', meta);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
};
|
|
@@ -68,6 +70,7 @@ FS.remove = function(id) {
|
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
FS.reload = function(flow, restart = false) {
|
|
73
|
+
|
|
71
74
|
var prev = FS.instances[flow.id];
|
|
72
75
|
if (!prev)
|
|
73
76
|
return false;
|
|
@@ -75,7 +78,7 @@ FS.reload = function(flow, restart = false) {
|
|
|
75
78
|
FS.db[flow.id] = flow;
|
|
76
79
|
|
|
77
80
|
var instance = FS.instances[flow.id];
|
|
78
|
-
instance.
|
|
81
|
+
instance.workertype = flow.worker;
|
|
79
82
|
instance.proxypath = flow.proxypath;
|
|
80
83
|
|
|
81
84
|
if (restart)
|
|
@@ -129,6 +132,9 @@ FS.init = function(directory, callback) {
|
|
|
129
132
|
|
|
130
133
|
FS.load = function(flow, callback) {
|
|
131
134
|
|
|
135
|
+
if (!flow.id)
|
|
136
|
+
flow.id = F.TUtils.random_string(10).toLowerCase();
|
|
137
|
+
|
|
132
138
|
// flow.directory {String}
|
|
133
139
|
// flow.asfiles {Boolean}
|
|
134
140
|
// flow.worker {String/Boolean}
|
|
@@ -147,12 +153,6 @@ FS.load = function(flow, callback) {
|
|
|
147
153
|
|
|
148
154
|
FS.module.init(flow, flow.worker, function(err, instance) {
|
|
149
155
|
|
|
150
|
-
FS.$events.load && FS.emit('load', instance, flow);
|
|
151
|
-
|
|
152
|
-
// instance.httprouting();
|
|
153
|
-
if (callback)
|
|
154
|
-
instance.ondone = err => callback(err, err ? null : instance);
|
|
155
|
-
|
|
156
156
|
instance.onerror = FS.onerror;
|
|
157
157
|
|
|
158
158
|
instance.onsave = function(data) {
|
|
@@ -162,6 +162,12 @@ FS.load = function(flow, callback) {
|
|
|
162
162
|
};
|
|
163
163
|
|
|
164
164
|
FS.instances[id] = instance;
|
|
165
|
+
|
|
166
|
+
// instance.httprouting();
|
|
167
|
+
instance.ondone = function(err) {
|
|
168
|
+
FS.$events.load && FS.emit('load', instance, flow);
|
|
169
|
+
callback && callback(err, err ? null : instance);
|
|
170
|
+
};
|
|
165
171
|
});
|
|
166
172
|
|
|
167
173
|
};
|
|
@@ -229,4 +235,4 @@ global.FlowStream = exports;
|
|
|
229
235
|
setImmediate(function() {
|
|
230
236
|
FS.socket = FS.module.socket;
|
|
231
237
|
FS.client = FS.module.client;
|
|
232
|
-
});
|
|
238
|
+
});
|
package/flowstream.js
CHANGED
|
@@ -754,7 +754,7 @@ FP.destroy = function() {
|
|
|
754
754
|
self.emit('destroy');
|
|
755
755
|
self.meta = null;
|
|
756
756
|
self.$events = null;
|
|
757
|
-
delete F.
|
|
757
|
+
delete F.flowstreams[self.name];
|
|
758
758
|
});
|
|
759
759
|
|
|
760
760
|
};
|
|
@@ -1266,8 +1266,8 @@ FP.load = function(data, callback) {
|
|
|
1266
1266
|
self.use(data.design, function(err) {
|
|
1267
1267
|
self.inc(0);
|
|
1268
1268
|
err && error.push(err);
|
|
1269
|
-
callback && callback(err);
|
|
1270
1269
|
self.clean();
|
|
1270
|
+
callback && callback(err);
|
|
1271
1271
|
});
|
|
1272
1272
|
|
|
1273
1273
|
});
|
|
@@ -1320,8 +1320,8 @@ FP.rewrite = function(data, callback) {
|
|
|
1320
1320
|
|
|
1321
1321
|
self.inc(0);
|
|
1322
1322
|
err && error.push(err);
|
|
1323
|
-
callback && callback(err);
|
|
1324
1323
|
self.clean();
|
|
1324
|
+
callback && callback(err);
|
|
1325
1325
|
});
|
|
1326
1326
|
});
|
|
1327
1327
|
});
|
|
@@ -1602,6 +1602,7 @@ FP.initcomponent = function(key, component) {
|
|
|
1602
1602
|
instance.transform = newtransform;
|
|
1603
1603
|
instance.replace = variables;
|
|
1604
1604
|
instance.instances = self.meta.flow;
|
|
1605
|
+
instance.components = self.meta.components;
|
|
1605
1606
|
|
|
1606
1607
|
self.onconnect && self.onconnect(instance);
|
|
1607
1608
|
self.$events.connect && self.emit('connect', instance);
|