xcraft-core-busclient 5.2.0 → 5.3.0
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/.eslintrc.js +17 -6
- package/.zou-flow +0 -1
- package/index.js +22 -16
- package/lib/command.js +6 -4
- package/lib/events.js +16 -6
- package/lib/resp.js +3 -2
- package/package.json +3 -3
package/.eslintrc.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
root: true,
|
|
5
5
|
parserOptions: {
|
|
6
|
-
ecmaVersion: 7,
|
|
7
6
|
sourceType: 'module',
|
|
8
7
|
ecmaFeatures: {
|
|
9
8
|
jsx: true,
|
|
@@ -11,18 +10,30 @@ module.exports = {
|
|
|
11
10
|
},
|
|
12
11
|
env: {
|
|
13
12
|
browser: true,
|
|
13
|
+
es2022: true,
|
|
14
14
|
mocha: true,
|
|
15
15
|
node: true,
|
|
16
|
-
es6: true,
|
|
17
16
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
plugins: ['react', 'babel', 'jsdoc'],
|
|
18
|
+
extends: [
|
|
19
|
+
'prettier',
|
|
20
|
+
'eslint:recommended',
|
|
21
|
+
'plugin:react/recommended',
|
|
22
|
+
'plugin:jsdoc/recommended',
|
|
23
|
+
],
|
|
21
24
|
rules: {
|
|
22
25
|
// Other rules
|
|
23
26
|
'no-console': 'off',
|
|
24
|
-
'valid-jsdoc': ['error', {requireReturn: false}],
|
|
25
27
|
'eqeqeq': 'error',
|
|
26
28
|
'react/display-name': 'off',
|
|
29
|
+
'no-unused-vars': [
|
|
30
|
+
'error',
|
|
31
|
+
{
|
|
32
|
+
vars: 'all',
|
|
33
|
+
args: 'none',
|
|
34
|
+
ignoreRestSiblings: true,
|
|
35
|
+
destructuredArrayIgnorePattern: '^_',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
27
38
|
},
|
|
28
39
|
};
|
package/.zou-flow
CHANGED
package/index.js
CHANGED
|
@@ -99,7 +99,7 @@ class BusClient extends EventEmitter {
|
|
|
99
99
|
* as soon as possible.
|
|
100
100
|
*/
|
|
101
101
|
const fromSocket = this[`_${from}Socket`];
|
|
102
|
-
if (fromSocket && fromSocket.isLocalOnly) {
|
|
102
|
+
if (fromSocket && fromSocket.isLocalOnly && !this._busConfig?.passive) {
|
|
103
103
|
process.exitCode = 9;
|
|
104
104
|
setTimeout(() => process.exit(), 10000);
|
|
105
105
|
xLog.err('Exit the node, the socket is lost (max wait of 10s)');
|
|
@@ -205,7 +205,7 @@ class BusClient extends EventEmitter {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
if (topic === 'greathall::bus.token.changed') {
|
|
208
|
-
this.emit('token.changed');
|
|
208
|
+
this.emit('token.changed', msg.data.busConfig);
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
211
|
|
|
@@ -216,7 +216,8 @@ class BusClient extends EventEmitter {
|
|
|
216
216
|
this.emit(
|
|
217
217
|
'orcname.changed',
|
|
218
218
|
msg.data.oldOrcName,
|
|
219
|
-
msg.data.newOrcName
|
|
219
|
+
msg.data.newOrcName,
|
|
220
|
+
msg.data.busConfig
|
|
220
221
|
);
|
|
221
222
|
return;
|
|
222
223
|
}
|
|
@@ -314,12 +315,17 @@ class BusClient extends EventEmitter {
|
|
|
314
315
|
xLog.warn(
|
|
315
316
|
`reconnecting to the server has provided a new token: ${this._token} -> ${msg.data.token}`
|
|
316
317
|
);
|
|
317
|
-
this.emit('token.changed');
|
|
318
|
+
this.emit('token.changed', this._busConfig);
|
|
318
319
|
} else if (this._orcName && isNewOrcName) {
|
|
319
320
|
xLog.warn(
|
|
320
321
|
`reconnecting to the server has provided a new orcName: ${this._orcName} -> ${msg.data.orcName}`
|
|
321
322
|
);
|
|
322
|
-
this.emit(
|
|
323
|
+
this.emit(
|
|
324
|
+
'orcname.changed',
|
|
325
|
+
this._orcName,
|
|
326
|
+
msg.data.orcName,
|
|
327
|
+
this._busConfig
|
|
328
|
+
);
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
331
|
|
|
@@ -533,28 +539,28 @@ class BusClient extends EventEmitter {
|
|
|
533
539
|
}
|
|
534
540
|
|
|
535
541
|
registerEvents(topic, handler) {
|
|
536
|
-
const
|
|
542
|
+
const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
|
|
543
|
+
const ids = topic.ids || extractIds(topic);
|
|
544
|
+
const reg = topic.reg || new RegExp(str);
|
|
537
545
|
|
|
538
|
-
if (this._eventsRegistry[
|
|
546
|
+
if (this._eventsRegistry[str]) {
|
|
539
547
|
xLog.info(`${topic} already registered, unsub and sub again`);
|
|
540
548
|
this.unregisterEvents(topic);
|
|
541
549
|
}
|
|
542
550
|
|
|
543
|
-
const re = new RegExp(escapeTopic);
|
|
544
|
-
const ids = extractIds(topic);
|
|
545
551
|
const id = ids[ids.length - 1];
|
|
546
|
-
this._eventsCache.set(id,
|
|
547
|
-
this._eventsRegistry[
|
|
548
|
-
topic:
|
|
552
|
+
this._eventsCache.set(id, str, reg);
|
|
553
|
+
this._eventsRegistry[str] = {
|
|
554
|
+
topic: reg,
|
|
549
555
|
handler,
|
|
550
|
-
unregister: () => this._unregister(id,
|
|
556
|
+
unregister: () => this._unregister(id, str),
|
|
551
557
|
};
|
|
552
558
|
}
|
|
553
559
|
|
|
554
560
|
unregisterEvents(topic) {
|
|
555
|
-
const
|
|
556
|
-
if (this._eventsRegistry[
|
|
557
|
-
this._eventsRegistry[
|
|
561
|
+
const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
|
|
562
|
+
if (this._eventsRegistry[str]) {
|
|
563
|
+
this._eventsRegistry[str].unregister();
|
|
558
564
|
}
|
|
559
565
|
}
|
|
560
566
|
|
package/lib/command.js
CHANGED
|
@@ -8,6 +8,11 @@ var xLog = require('xcraft-core-log')(moduleName, null);
|
|
|
8
8
|
function Command(busClient, pushSocket) {
|
|
9
9
|
this._busClient = busClient;
|
|
10
10
|
this._push = pushSocket;
|
|
11
|
+
|
|
12
|
+
const {appId, appArgs} = require('xcraft-core-host');
|
|
13
|
+
const {tribe} = appArgs();
|
|
14
|
+
|
|
15
|
+
this._routingKey = tribe ? `${appId}-${tribe}` : appId;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
Command.prototype.connectedWith = function () {
|
|
@@ -67,11 +72,8 @@ Command.prototype.send = function (
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
if (!busMessage.arp) {
|
|
70
|
-
const {appId, appArgs} = require('xcraft-core-host');
|
|
71
|
-
const {tribe} = appArgs();
|
|
72
|
-
const routingKey = tribe ? `${appId}-${tribe}` : appId;
|
|
73
75
|
let token = xBus.getToken();
|
|
74
|
-
let nodeName =
|
|
76
|
+
let nodeName = this._routingKey;
|
|
75
77
|
let {orcName} = busMessage;
|
|
76
78
|
let nice = 0;
|
|
77
79
|
let noForwarding = false;
|
package/lib/events.js
CHANGED
|
@@ -39,7 +39,13 @@ Events.prototype.catchAll = function (handler, proxy = false) {
|
|
|
39
39
|
* @param {string} [orcName] - Subscriber orcName (internal use)
|
|
40
40
|
* @return {function} unsubscribe function.
|
|
41
41
|
*/
|
|
42
|
-
Events.prototype.subscribe = function (
|
|
42
|
+
Events.prototype.subscribe = function (
|
|
43
|
+
topic,
|
|
44
|
+
handler,
|
|
45
|
+
backend,
|
|
46
|
+
orcName,
|
|
47
|
+
options
|
|
48
|
+
) {
|
|
43
49
|
if (!topic.includes('::')) {
|
|
44
50
|
xLog.err(new Error().stack);
|
|
45
51
|
throw new Error('namespace missing');
|
|
@@ -74,12 +80,16 @@ Events.prototype.subscribe = function (topic, handler, backend, orcName) {
|
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
this._handlers.set(topic, new Map([[id, handler]]));
|
|
77
|
-
this._sub.subscribe(
|
|
78
|
-
|
|
83
|
+
const topicCtx = this._sub.subscribe(
|
|
84
|
+
topic,
|
|
85
|
+
backend,
|
|
86
|
+
orcName,
|
|
87
|
+
options?.xcraftRPC
|
|
88
|
+
);
|
|
79
89
|
const handlers = this._handlers.get(topic);
|
|
80
90
|
|
|
81
91
|
/* register a pre-handler for deserialize object if needed */
|
|
82
|
-
this._busClient.registerEvents(
|
|
92
|
+
this._busClient.registerEvents(topicCtx, (msg) => {
|
|
83
93
|
/* FIXME: it's not safe. */
|
|
84
94
|
if (msg.serialized) {
|
|
85
95
|
msg.data = JSON.parse(msg.data, function (key, value) {
|
|
@@ -125,8 +135,8 @@ Events.prototype.unsubscribeAll = function (topic, backend, orcName) {
|
|
|
125
135
|
|
|
126
136
|
xLog.verb('client removing handler on topic: ' + topic);
|
|
127
137
|
|
|
128
|
-
this._sub.unsubscribe(topic, backend, orcName);
|
|
129
|
-
this._busClient.unregisterEvents(
|
|
138
|
+
const topicCtx = this._sub.unsubscribe(topic, backend, orcName);
|
|
139
|
+
this._busClient.unregisterEvents(topicCtx);
|
|
130
140
|
this._handlers.delete(topic);
|
|
131
141
|
};
|
|
132
142
|
|
package/lib/resp.js
CHANGED
|
@@ -32,7 +32,7 @@ class Events {
|
|
|
32
32
|
this._busClient.events.catchAll(handler);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
subscribe(topic, handler) {
|
|
35
|
+
subscribe(topic, handler, xcraftRPC = false) {
|
|
36
36
|
if (!this._busClient) {
|
|
37
37
|
this._log.err('events.subscribe not available');
|
|
38
38
|
return;
|
|
@@ -42,7 +42,8 @@ class Events {
|
|
|
42
42
|
this._fixTopic(topic),
|
|
43
43
|
handler,
|
|
44
44
|
undefined,
|
|
45
|
-
this._orcName
|
|
45
|
+
this._orcName,
|
|
46
|
+
{xcraftRPC}
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xcraft-core-busclient",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Xcraft bus client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"xcraft-core-host": "^3.0.0",
|
|
26
26
|
"xcraft-core-etc": "^3.0.0",
|
|
27
27
|
"xcraft-core-log": "^2.0.0",
|
|
28
|
-
"xcraft-core-transport": "^4.
|
|
28
|
+
"xcraft-core-transport": "^4.5.0",
|
|
29
29
|
"xcraft-core-utils": "^4.0.0"
|
|
30
30
|
},
|
|
31
31
|
"author": "Mathieu Schroeter & Samuel Loup",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"prettier": "2.0.4",
|
|
39
39
|
"xcraft-dev-prettier": "^2.0.0",
|
|
40
|
-
"xcraft-dev-rules": "^
|
|
40
|
+
"xcraft-dev-rules": "^4.1.0"
|
|
41
41
|
},
|
|
42
42
|
"prettier": "xcraft-dev-prettier"
|
|
43
43
|
}
|