@lad-tech/nsc-toolkit 1.25.0 → 1.26.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.25.0](https://github.com/lad-tech/nsc-toolkit/compare/v1.24.0...v1.25.0) (2024-12-13)
1
+ # [1.26.0](https://github.com/lad-tech/nsc-toolkit/compare/v1.25.0...v1.26.0) (2025-01-14)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * auto update consumer setting \n\n BREAKING CHANGE: all push con… ([#136](https://github.com/lad-tech/nsc-toolkit/issues/136)) ([51d63a1](https://github.com/lad-tech/nsc-toolkit/commit/51d63a17f549cf8ebed37953f8ff0d6433943620))
6
+ * add rollup support ([#138](https://github.com/lad-tech/nsc-toolkit/issues/138)) ([423d1a8](https://github.com/lad-tech/nsc-toolkit/commit/423d1a86b4fb37b97a9cb9af8e4871b1e62caa76))
package/dist/Service.js CHANGED
@@ -30,12 +30,20 @@ class Service extends Root_1.Root {
30
30
  * de-duplication within the configured Duplicate Window
31
31
  */
32
32
  this.UNIQ_ID_HEADER = 'Nats-Msg-Id';
33
+ /**
34
+ * Nats-Rollup header indicating all prior messages should be purged
35
+ */
36
+ this.ROLLUP_HEADER = 'Nats-Rollup';
37
+ /**
38
+ * Roll-up only same subject message in the stream
39
+ */
40
+ this.ROLLUP_STRATEGY = 'sub';
33
41
  this.serviceName = options.name;
34
42
  this.logger.setLocation(this.serviceName);
35
43
  if (options.events) {
36
44
  const events = Object.keys(options.events.list);
37
45
  this.emitter = events.reduce((result, eventName) => {
38
- result[eventName] = ((params, uniqId) => {
46
+ result[eventName] = ((params, uniqId, rollupId) => {
39
47
  var _a, _b, _c;
40
48
  const subject = [options.name];
41
49
  const eventOptions = (_a = options.events) === null || _a === void 0 ? void 0 : _a.list[eventName];
@@ -52,6 +60,11 @@ class Service extends Root_1.Root {
52
60
  settings = { headers: (0, nats_1.headers)() };
53
61
  settings.headers.append(this.UNIQ_ID_HEADER, uniqId);
54
62
  }
63
+ if (rollupId) {
64
+ settings = settings !== null && settings !== void 0 ? settings : { headers: (0, nats_1.headers)() };
65
+ settings.headers.append(this.ROLLUP_HEADER, this.ROLLUP_STRATEGY);
66
+ subject.push(rollupId);
67
+ }
55
68
  this.broker.publish(subject.join('.'), this.buildMessage(params), settings);
56
69
  });
57
70
  return result;
@@ -65,7 +65,7 @@ class StreamManager extends Root_1.Root {
65
65
  async createConsumer(serviceNameFrom, eventName, setting) {
66
66
  const consumerName = this.capitalizeFirstLetter(serviceNameFrom) + this.capitalizeFirstLetter(eventName);
67
67
  const prefix = this.param.options.prefix;
68
- const subject = `${this.param.serviceName}.${prefix}.${eventName}`;
68
+ const subject = `${this.param.serviceName}.${prefix}.${eventName}.*`;
69
69
  if (!this.jsm) {
70
70
  this.jsm = await this.param.broker.jetstreamManager();
71
71
  }
@@ -114,7 +114,7 @@ class StreamManager extends Root_1.Root {
114
114
  await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
115
115
  }
116
116
  else {
117
- await this.jsm.consumers.update(streamName, consumerName, options.config);
117
+ await this.jsm.consumers.update(streamName, consumerName, { ...options.config, filter_subject: subject });
118
118
  }
119
119
  }
120
120
  const consumer = await this.broker.jetstream().consumers.get(streamName, consumerName);
@@ -16,6 +16,14 @@ export declare class Service<E extends Emitter = Emitter> extends Root {
16
16
  * de-duplication within the configured Duplicate Window
17
17
  */
18
18
  private readonly UNIQ_ID_HEADER;
19
+ /**
20
+ * Nats-Rollup header indicating all prior messages should be purged
21
+ */
22
+ private readonly ROLLUP_HEADER;
23
+ /**
24
+ * Roll-up only same subject message in the stream
25
+ */
26
+ private readonly ROLLUP_STRATEGY;
19
27
  constructor(options: ServiceOptions<E>);
20
28
  /**
21
29
  * Create global Tracer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lad-tech/nsc-toolkit",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "description": "Toolkit for create microservices around NATS",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",