@lad-tech/nsc-toolkit 1.26.1 → 1.27.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.26.1](https://github.com/lad-tech/nsc-toolkit/compare/v1.26.0...v1.26.1) (2025-01-17)
1
+ # [1.27.0](https://github.com/lad-tech/nsc-toolkit/compare/v1.26.2...v1.27.0) (2025-02-06)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * Remove inbox from config old consumer ([#140](https://github.com/lad-tech/nsc-toolkit/issues/140)) ([69ddd98](https://github.com/lad-tech/nsc-toolkit/commit/69ddd980ebd7258991542946a1252b11d424199a))
6
+ * New option for consumer ackPolicy ([#144](https://github.com/lad-tech/nsc-toolkit/issues/144)) ([0426f4e](https://github.com/lad-tech/nsc-toolkit/commit/0426f4e1da4ff092354f0e175d9ad9a295dfb074))
package/dist/Client.js CHANGED
@@ -24,6 +24,9 @@ class Client extends Root_1.Root {
24
24
  }
25
25
  async startWatch(subscription, listener, eventName) {
26
26
  for await (const event of subscription) {
27
+ if (!event) {
28
+ continue;
29
+ }
27
30
  let data;
28
31
  try {
29
32
  data = (0, nats_1.JSONCodec)().decode(event.data);
package/dist/Service.js CHANGED
@@ -38,6 +38,7 @@ class Service extends Root_1.Root {
38
38
  * Roll-up only same subject message in the stream
39
39
  */
40
40
  this.ROLLUP_STRATEGY = 'sub';
41
+ this.BASE_EVENT_SUFFIX = 'base';
41
42
  this.serviceName = options.name;
42
43
  this.logger.setLocation(this.serviceName);
43
44
  if (options.events) {
@@ -65,6 +66,9 @@ class Service extends Root_1.Root {
65
66
  settings.headers.append(this.ROLLUP_HEADER, this.ROLLUP_STRATEGY);
66
67
  subject.push(rollupId);
67
68
  }
69
+ else {
70
+ subject.push(this.BASE_EVENT_SUFFIX);
71
+ }
68
72
  this.broker.publish(subject.join('.'), this.buildMessage(params), settings);
69
73
  });
70
74
  return result;
@@ -73,11 +73,20 @@ class StreamManager extends Root_1.Root {
73
73
  const isPullConsumer = StreamManager.isPullConsumerOptions(setting);
74
74
  options
75
75
  .durable(consumerName)
76
- .manualAck()
77
- .ackExplicit()
78
76
  .filterSubject(subject)
79
77
  .maxAckPending((setting === null || setting === void 0 ? void 0 : setting.maxPending) || 10);
80
78
  if (isPullConsumer) {
79
+ if (setting.ackPolicy === 'all') {
80
+ options.manualAck();
81
+ options.ackAll();
82
+ }
83
+ if (setting.ackPolicy === 'none') {
84
+ options.ackNone();
85
+ }
86
+ if (!setting.ackPolicy) {
87
+ options.manualAck();
88
+ options.ackExplicit();
89
+ }
81
90
  if (setting.maxPullRequestExpires) {
82
91
  options.maxPullRequestExpires(setting.maxPullRequestExpires);
83
92
  }
@@ -85,6 +94,10 @@ class StreamManager extends Root_1.Root {
85
94
  options.maxPullBatch(setting.maxPullRequestBatch);
86
95
  }
87
96
  }
97
+ else {
98
+ options.manualAck();
99
+ options.ackExplicit();
100
+ }
88
101
  if (setting === null || setting === void 0 ? void 0 : setting.maxAckWaiting) {
89
102
  options.ackWait(setting.maxAckWaiting);
90
103
  }
@@ -114,7 +127,11 @@ class StreamManager extends Root_1.Root {
114
127
  await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
115
128
  }
116
129
  else {
117
- await this.jsm.consumers.update(streamName, consumerName, { ...options.config, filter_subject: subject, deliver_subject: undefined });
130
+ await this.jsm.consumers.update(streamName, consumerName, {
131
+ ...options.config,
132
+ filter_subject: subject,
133
+ deliver_subject: undefined,
134
+ });
118
135
  }
119
136
  }
120
137
  const consumer = await this.broker.jetstream().consumers.get(streamName, consumerName);
@@ -7,21 +7,16 @@ class StreamSingleMsgFetcher {
7
7
  this.done = false;
8
8
  }
9
9
  [Symbol.asyncIterator]() {
10
- const done = {
11
- value: this.msg,
12
- done: true,
13
- };
14
10
  return {
15
11
  next: async () => {
16
12
  const msg = await this.consumer.next();
17
13
  if (msg) {
18
- this.msg = msg;
19
14
  return {
20
- value: this.msg,
15
+ value: msg,
21
16
  done: this.done,
22
17
  };
23
18
  }
24
- return done;
19
+ return { done: false };
25
20
  },
26
21
  };
27
22
  }
@@ -24,6 +24,7 @@ export declare class Service<E extends Emitter = Emitter> extends Root {
24
24
  * Roll-up only same subject message in the stream
25
25
  */
26
26
  private readonly ROLLUP_STRATEGY;
27
+ private readonly BASE_EVENT_SUFFIX;
27
28
  constructor(options: ServiceOptions<E>);
28
29
  /**
29
30
  * Create global Tracer
@@ -1,13 +1,15 @@
1
- import { Consumer, JsMsg } from 'nats';
1
+ import { Consumer } from 'nats';
2
2
  export declare class StreamSingleMsgFetcher {
3
3
  private consumer;
4
4
  private done;
5
- private msg;
6
5
  constructor(consumer: Consumer);
7
6
  [Symbol.asyncIterator](): {
8
7
  next: () => Promise<{
9
- value: JsMsg;
8
+ value: import("nats").JsMsg;
10
9
  done: boolean;
10
+ } | {
11
+ done: boolean;
12
+ value?: undefined;
11
13
  }>;
12
14
  };
13
15
  unsubscribe(): void;
@@ -75,6 +75,7 @@ export interface GetBatchListenerOptions extends GetListenerOptions {
75
75
  batch: true;
76
76
  maxPullRequestBatch?: number;
77
77
  maxPullRequestExpires?: number;
78
+ ackPolicy?: 'all' | 'none';
78
79
  }
79
80
  export interface StreamManagerParam {
80
81
  serviceName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lad-tech/nsc-toolkit",
3
- "version": "1.26.1",
3
+ "version": "1.27.0",
4
4
  "description": "Toolkit for create microservices around NATS",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",