@lad-tech/nsc-toolkit 1.23.2 → 1.24.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- ## [1.23.2](https://github.com/lad-tech/nsc-toolkit/compare/v1.23.1...v1.23.2) (2024-11-07)
1
+ # [1.24.0](https://github.com/lad-tech/nsc-toolkit/compare/v1.23.3...v1.24.0) (2024-11-08)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * grow subscriptions ([#130](https://github.com/lad-tech/nsc-toolkit/issues/130)) ([d8b0ce2](https://github.com/lad-tech/nsc-toolkit/commit/d8b0ce26c2fab22b3eb9a5d28126fa8987c686e8))
6
+ * Uniq key for event ([#133](https://github.com/lad-tech/nsc-toolkit/issues/133)) ([ff69a67](https://github.com/lad-tech/nsc-toolkit/commit/ff69a67b464f64e9eebb44e2c65bb626c30b68ea))
package/dist/Client.js CHANGED
@@ -58,7 +58,6 @@ class Client extends Root_1.Root {
58
58
  }
59
59
  if (batch.length > 0)
60
60
  listener.emit(eventName, batch);
61
- await events.close();
62
61
  }
63
62
  }
64
63
  getListener(serviceNameFrom, options) {
package/dist/Service.js CHANGED
@@ -25,12 +25,17 @@ class Service extends Root_1.Root {
25
25
  this.subscriptions = [];
26
26
  this.httpMethods = new Map();
27
27
  this.rootSpans = new Map();
28
+ /**
29
+ * Unique identifier NATS header for a message that will be used by the server apply
30
+ * de-duplication within the configured Duplicate Window
31
+ */
32
+ this.UNIQ_ID_HEADER = 'Nats-Msg-Id';
28
33
  this.serviceName = options.name;
29
34
  this.logger.setLocation(this.serviceName);
30
35
  if (options.events) {
31
36
  const events = Object.keys(options.events.list);
32
37
  this.emitter = events.reduce((result, eventName) => {
33
- result[eventName] = ((params) => {
38
+ result[eventName] = ((params, uniqId) => {
34
39
  var _a, _b, _c;
35
40
  const subject = [options.name];
36
41
  const eventOptions = (_a = options.events) === null || _a === void 0 ? void 0 : _a.list[eventName];
@@ -42,7 +47,12 @@ class Service extends Root_1.Root {
42
47
  subject.push(prefix);
43
48
  }
44
49
  subject.push(String(eventName));
45
- this.broker.publish(subject.join('.'), this.buildMessage(params));
50
+ let settings;
51
+ if (uniqId) {
52
+ settings = { headers: (0, nats_1.headers)() };
53
+ settings.headers.append(this.UNIQ_ID_HEADER, uniqId);
54
+ }
55
+ this.broker.publish(subject.join('.'), this.buildMessage(params), settings);
46
56
  });
47
57
  return result;
48
58
  }, this.emitter);
@@ -11,6 +11,11 @@ export declare class Service<E extends Emitter = Emitter> extends Root {
11
11
  private subscriptions;
12
12
  private httpMethods;
13
13
  private rootSpans;
14
+ /**
15
+ * Unique identifier NATS header for a message that will be used by the server apply
16
+ * de-duplication within the configured Duplicate Window
17
+ */
18
+ private readonly UNIQ_ID_HEADER;
14
19
  constructor(options: ServiceOptions<E>);
15
20
  /**
16
21
  * Create global Tracer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lad-tech/nsc-toolkit",
3
- "version": "1.23.2",
3
+ "version": "1.24.0",
4
4
  "description": "Toolkit for create microservices around NATS",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",