@rayondigital/nest-dapr 0.9.39 → 0.9.41

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;
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];
@@ -111,6 +111,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
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
113
  if (response.failedMessages) {
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');
114
115
  const failedMessages = response.failedMessages.map((m, i) => {
115
116
  var _a;
116
117
  const messageId = this.getMessageId(m.message.event, m.message.entryID);
@@ -123,7 +124,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
123
124
  contentType: (_a = m.message.contentType) !== null && _a !== void 0 ? _a : contentType,
124
125
  };
125
126
  });
126
- yield this.handleError(failedMessages, response.failedMessages[0].error);
127
+ yield this.handleError(failedMessages, error);
127
128
  }
128
129
  }
129
130
  catch (error) {
@@ -152,23 +153,26 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
152
153
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
153
154
  try {
154
155
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
155
- if (response.error) {
156
+ if (response !== undefined && response.error) {
156
157
  throw response.error;
157
158
  }
158
159
  }
159
160
  catch (error) {
160
161
  yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
162
+ return false;
161
163
  }
162
164
  }));
163
- return;
165
+ return true;
164
166
  }
165
167
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
166
- if (response.error) {
168
+ if (response !== undefined && response.error) {
167
169
  throw response.error;
168
170
  }
171
+ return true;
169
172
  }
170
173
  catch (error) {
171
174
  yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
175
+ return false;
172
176
  }
173
177
  });
174
178
  }
@@ -197,7 +201,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
197
201
  this.buffer.next({ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, producerId, topic, payload, metadata, contentType });
198
202
  return;
199
203
  }
200
- 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);
201
205
  });
202
206
  }
203
207
  publishBulk(...args) {
@@ -225,8 +229,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
225
229
  contentType = 'application/json';
226
230
  if (payloads.length === 1) {
227
231
  const messageId = this.getMessageId(payloads[0]);
228
- yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
229
- return;
232
+ return yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
230
233
  }
231
234
  for (const payload of payloads) {
232
235
  this.buffer.next({
@@ -239,6 +242,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
239
242
  contentType,
240
243
  });
241
244
  }
245
+ return true;
242
246
  });
243
247
  }
244
248
  getMessageId(payload, defaultValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.39",
3
+ "version": "0.9.41",
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",