@lad-tech/nsc-toolkit 1.22.3 → 1.22.5

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.22.3](https://github.com/lad-tech/nsc-toolkit/compare/v1.22.2...v1.22.3) (2024-08-19)
1
+ ## [1.22.5](https://github.com/lad-tech/nsc-toolkit/compare/v1.22.4...v1.22.5) (2024-09-08)
2
2
 
3
3
 
4
4
  ### Bug Fixes
5
5
 
6
- * Fix consumer filter erasing ([#119](https://github.com/lad-tech/nsc-toolkit/issues/119)) ([17c7823](https://github.com/lad-tech/nsc-toolkit/commit/17c782364dc7d2b50883e406b234f55a397a0700))
6
+ * Error for create same consumer ([#124](https://github.com/lad-tech/nsc-toolkit/issues/124)) ([8664809](https://github.com/lad-tech/nsc-toolkit/commit/8664809486f0d59c4a04a62cb0690f09d9cf9d97))
package/dist/Client.js CHANGED
@@ -99,7 +99,9 @@ class Client extends Root_1.Root {
99
99
  return method.call(target, eventName, handler);
100
100
  }
101
101
  catch (error) {
102
- this.logger.error(`Failed subscribe to subject`, error);
102
+ const errorMessage = 'Failed subscribe to subject';
103
+ this.logger.error(errorMessage, error);
104
+ throw new Error(`${errorMessage} ${this.serviceName}.${String(eventName)}`);
103
105
  }
104
106
  };
105
107
  }
@@ -13,6 +13,7 @@ class StreamManager extends Root_1.Root {
13
13
  this.GREATER_WILDCARD = '>';
14
14
  this.TWO_WEEKS_IN_SECOND = 1209600;
15
15
  this.ONE_DAY_IN_SECOND = 86400;
16
+ this.CONSUMER_NOT_FOUND = 'consumer not found';
16
17
  this.defaultStreamOption = {
17
18
  storage: 'file',
18
19
  retentionPolicy: 'limits',
@@ -105,7 +106,15 @@ class StreamManager extends Root_1.Root {
105
106
  throw new Error(`Error creating consumer ${consumerName}. Stream for subject ${subject} not found`);
106
107
  }
107
108
  if ((0, types_1.isConsumerOptsBuilder)(options)) {
108
- await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
109
+ const isConsumerExist = await this.jsm.consumers.info(streamName, consumerName).catch(async (error) => {
110
+ if (error.message === this.CONSUMER_NOT_FOUND) {
111
+ return false;
112
+ }
113
+ throw error;
114
+ });
115
+ if (!isConsumerExist) {
116
+ await this.jsm.consumers.add(streamName, { ...options.config, filter_subject: subject });
117
+ }
109
118
  }
110
119
  return isPullConsumer
111
120
  ? new StreamFetcher_1.StreamFetcher(this.broker.jetstream(), streamName, consumerName, {
@@ -8,6 +8,7 @@ export declare class StreamManager extends Root {
8
8
  private readonly GREATER_WILDCARD;
9
9
  private readonly TWO_WEEKS_IN_SECOND;
10
10
  private readonly ONE_DAY_IN_SECOND;
11
+ private readonly CONSUMER_NOT_FOUND;
11
12
  private readonly defaultStreamOption;
12
13
  private jsm?;
13
14
  constructor(param: StreamManagerParam);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lad-tech/nsc-toolkit",
3
- "version": "1.22.3",
3
+ "version": "1.22.5",
4
4
  "description": "Toolkit for create microservices around NATS",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/types/index.d.ts",