@rayondigital/nest-dapr 0.9.40 → 0.9.42

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.
@@ -17,12 +17,12 @@ export declare class DaprPubSubClient implements OnApplicationShutdown {
17
17
  onApplicationShutdown(signal?: string): Promise<void>;
18
18
  protected setupBufferSubscription(): void;
19
19
  protected publishBulkDirectly(messages: PublishMessage[]): Promise<void>;
20
- protected publishDirectly(id: string, name: string, topic: string, payload: any, producerId?: string, metadata?: any, fireAndForget?: boolean, contentType?: string): Promise<void>;
21
- publish(id: string, name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<void>;
22
- publish(id: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<void>;
23
- publish(id: string, producerId: string, topic: string, payload: any): Promise<void>;
24
- publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<void>;
25
- publishBulk(producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<void>;
26
- publishBulk(producerId: string, topic: string, payloads: any[]): Promise<void>;
20
+ protected publishDirectly(id: string, name: string, topic: string, payload: any, producerId?: string, metadata?: any, fireAndForget?: boolean, contentType?: string): Promise<boolean>;
21
+ publish(id: string, name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<boolean>;
22
+ publish(id: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<boolean>;
23
+ publish(id: string, producerId: string, topic: string, payload: any): Promise<boolean>;
24
+ publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<boolean>;
25
+ publishBulk(producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<boolean>;
26
+ publishBulk(producerId: string, topic: string, payloads: any[]): Promise<boolean>;
27
27
  private getMessageId;
28
28
  }
@@ -43,10 +43,10 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
43
43
  }
44
44
  handleError(messages, error) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
+ this.logger.error(`Error publishing ${messages.length ? 'message' : 'messages'} to pubsub`, error);
46
47
  if (this.onError) {
47
48
  yield this.onError(messages, error);
48
49
  }
49
- this.logger.error(`Error publishing ${messages.length ? 'message' : 'messages'} to pubsub`, error);
50
50
  });
51
51
  }
52
52
  onApplicationShutdown(signal) {
@@ -85,7 +85,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
85
85
  }));
86
86
  }
87
87
  publishBulkDirectly(messages) {
88
- var _a, _b;
88
+ var _a, _b, _c;
89
89
  return __awaiter(this, void 0, void 0, function* () {
90
90
  if (messages.length === 1) {
91
91
  const message = messages[0];
@@ -110,8 +110,8 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
110
110
  try {
111
111
  const contentType = (_a = messages[0].contentType) !== null && _a !== void 0 ? _a : 'application/json';
112
112
  const response = yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId }, contentType } : undefined);
113
- if (response.failedMessages) {
114
- const error = (_b = response.failedMessages[0].error) !== null && _b !== void 0 ? _b : new Error('Unable to publish message');
113
+ if (response !== undefined && response.failedMessages && response.failedMessages.length > 0) {
114
+ const error = (_c = (_b = response.failedMessages[0]) === null || _b === void 0 ? void 0 : _b.error) !== null && _c !== void 0 ? _c : new Error('Unable to publish message');
115
115
  const failedMessages = response.failedMessages.map((m, i) => {
116
116
  var _a;
117
117
  const messageId = this.getMessageId(m.message.event, m.message.entryID);
@@ -153,23 +153,26 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
153
153
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
154
154
  try {
155
155
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
156
- if (response === null || response === void 0 ? void 0 : response.error) {
156
+ if (response !== undefined && response.error) {
157
157
  throw response.error;
158
158
  }
159
159
  }
160
160
  catch (error) {
161
161
  yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
162
+ return false;
162
163
  }
163
164
  }));
164
- return;
165
+ return true;
165
166
  }
166
167
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
167
- if (response === null || response === void 0 ? void 0 : response.error) {
168
+ if (response !== undefined && response.error) {
168
169
  throw response.error;
169
170
  }
171
+ return true;
170
172
  }
171
173
  catch (error) {
172
174
  yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
175
+ return false;
173
176
  }
174
177
  });
175
178
  }
@@ -198,7 +201,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
198
201
  this.buffer.next({ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, producerId, topic, payload, metadata, contentType });
199
202
  return;
200
203
  }
201
- yield this.publishDirectly(id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, topic, payload, producerId, metadata, true, contentType);
204
+ return yield this.publishDirectly(id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, topic, payload, producerId, metadata, true, contentType);
202
205
  });
203
206
  }
204
207
  publishBulk(...args) {
@@ -226,8 +229,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
226
229
  contentType = 'application/json';
227
230
  if (payloads.length === 1) {
228
231
  const messageId = this.getMessageId(payloads[0]);
229
- yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
230
- return;
232
+ return yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
231
233
  }
232
234
  for (const payload of payloads) {
233
235
  this.buffer.next({
@@ -240,6 +242,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
240
242
  contentType,
241
243
  });
242
244
  }
245
+ return true;
243
246
  });
244
247
  }
245
248
  getMessageId(payload, defaultValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.40",
3
+ "version": "0.9.42",
4
4
  "description": "Develop NestJs microservices using Dapr pubsub, actors and other bindings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",