xcraft-core-busclient 5.2.0 → 5.2.1

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/index.js CHANGED
@@ -533,28 +533,28 @@ class BusClient extends EventEmitter {
533
533
  }
534
534
 
535
535
  registerEvents(topic, handler) {
536
- const escapeTopic = xUtils.regex.toXcraftRegExpStr(topic);
536
+ const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
537
+ const ids = topic.ids || extractIds(topic);
538
+ const reg = topic.reg || new RegExp(str);
537
539
 
538
- if (this._eventsRegistry[escapeTopic]) {
540
+ if (this._eventsRegistry[str]) {
539
541
  xLog.info(`${topic} already registered, unsub and sub again`);
540
542
  this.unregisterEvents(topic);
541
543
  }
542
544
 
543
- const re = new RegExp(escapeTopic);
544
- const ids = extractIds(topic);
545
545
  const id = ids[ids.length - 1];
546
- this._eventsCache.set(id, escapeTopic, re);
547
- this._eventsRegistry[escapeTopic] = {
548
- topic: re,
546
+ this._eventsCache.set(id, str, reg);
547
+ this._eventsRegistry[str] = {
548
+ topic: reg,
549
549
  handler,
550
- unregister: () => this._unregister(id, escapeTopic),
550
+ unregister: () => this._unregister(id, str),
551
551
  };
552
552
  }
553
553
 
554
554
  unregisterEvents(topic) {
555
- const escapeTopic = xUtils.regex.toXcraftRegExpStr(topic);
556
- if (this._eventsRegistry[escapeTopic]) {
557
- this._eventsRegistry[escapeTopic].unregister();
555
+ const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
556
+ if (this._eventsRegistry[str]) {
557
+ this._eventsRegistry[str].unregister();
558
558
  }
559
559
  }
560
560
 
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 = routingKey;
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
@@ -74,12 +74,11 @@ Events.prototype.subscribe = function (topic, handler, backend, orcName) {
74
74
  }
75
75
 
76
76
  this._handlers.set(topic, new Map([[id, handler]]));
77
- this._sub.subscribe(topic, backend, orcName);
78
-
77
+ const topicCtx = this._sub.subscribe(topic, backend, orcName);
79
78
  const handlers = this._handlers.get(topic);
80
79
 
81
80
  /* register a pre-handler for deserialize object if needed */
82
- this._busClient.registerEvents(topic, (msg) => {
81
+ this._busClient.registerEvents(topicCtx, (msg) => {
83
82
  /* FIXME: it's not safe. */
84
83
  if (msg.serialized) {
85
84
  msg.data = JSON.parse(msg.data, function (key, value) {
@@ -125,8 +124,8 @@ Events.prototype.unsubscribeAll = function (topic, backend, orcName) {
125
124
 
126
125
  xLog.verb('client removing handler on topic: ' + topic);
127
126
 
128
- this._sub.unsubscribe(topic, backend, orcName);
129
- this._busClient.unregisterEvents(topic);
127
+ const topicCtx = this._sub.unsubscribe(topic, backend, orcName);
128
+ this._busClient.unregisterEvents(topicCtx);
130
129
  this._handlers.delete(topic);
131
130
  };
132
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcraft-core-busclient",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
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.2.0",
28
+ "xcraft-core-transport": "^4.5.0",
29
29
  "xcraft-core-utils": "^4.0.0"
30
30
  },
31
31
  "author": "Mathieu Schroeter & Samuel Loup",