total5 0.0.1-6 → 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 +4 -2
- package/flow-flowstream.js +41 -22
- package/flow.js +14 -31
- package/global.js +59 -1
- package/package.json +1 -1
- package/tms.js +6 -7
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(
|
|
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
|
|
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)
|
package/flow-flowstream.js
CHANGED
|
@@ -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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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,31 +583,32 @@ Instance.prototype.reconfigure = function(id, config) {
|
|
|
573
583
|
return self;
|
|
574
584
|
};
|
|
575
585
|
|
|
576
|
-
Instance.prototype.reload = function(data
|
|
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
|
-
|
|
584
|
-
|
|
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;
|
|
594
|
-
|
|
595
608
|
if (data.variables2)
|
|
596
609
|
flow.variables2 = data.variables2;
|
|
597
|
-
|
|
598
610
|
flow.rewrite(data, () => flow.proxy.refreshmeta());
|
|
599
611
|
}
|
|
600
|
-
|
|
601
612
|
return self;
|
|
602
613
|
};
|
|
603
614
|
|
|
@@ -1405,6 +1416,14 @@ function init_worker(meta, type, callback) {
|
|
|
1405
1416
|
|
|
1406
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'));
|
|
1407
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
|
+
|
|
1408
1427
|
if (!worker.postMessage) {
|
|
1409
1428
|
worker.postMessage = worker.send;
|
|
1410
1429
|
ischild = true;
|
|
@@ -1510,7 +1529,7 @@ function init_worker(meta, type, callback) {
|
|
|
1510
1529
|
break;
|
|
1511
1530
|
|
|
1512
1531
|
case 'stream/error':
|
|
1513
|
-
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() };
|
|
1514
1533
|
worker.$socket && worker.$socket.send(tmp);
|
|
1515
1534
|
worker.$client && worker.$client.send(tmp);
|
|
1516
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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
77
|
+
var instance = FS.instances[flow.id];
|
|
78
|
+
instance.worker = flow.worker;
|
|
79
|
+
instance.proxypath = flow.proxypath;
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
|
|
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,
|
|
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
|
|
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
|
|
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);
|
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/package.json
CHANGED
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
|
-
|
|
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
|
-
|
|
75
|
-
for (
|
|
76
|
-
|
|
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]
|
|
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
|
|