@rayondigital/nest-dapr 0.9.38 → 0.9.40

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,11 +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(name: string, topic: string, payload: any, producerId?: string, metadata?: any, fireAndForget?: boolean, contentType?: string): Promise<void>;
21
- publish(name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<void>;
22
- publish(producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any, contentType?: string): Promise<void>;
23
- publish(producerId: string, topic: string, payload: any): 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
24
  publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<void>;
25
25
  publishBulk(producerId: string, topic: string, payloads: any[], metadata?: any, contentType?: string): Promise<void>;
26
26
  publishBulk(producerId: string, topic: string, payloads: any[]): Promise<void>;
27
+ private getMessageId;
27
28
  }
@@ -20,6 +20,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  var DaprPubSubClient_1;
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.DaprPubSubClient = void 0;
23
+ const crypto_1 = require("crypto");
23
24
  const dapr_1 = require("@dapr/dapr");
24
25
  const common_1 = require("@nestjs/common");
25
26
  const rxjs_1 = require("rxjs");
@@ -84,11 +85,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
84
85
  }));
85
86
  }
86
87
  publishBulkDirectly(messages) {
87
- var _a;
88
+ var _a, _b;
88
89
  return __awaiter(this, void 0, void 0, function* () {
89
90
  if (messages.length === 1) {
90
91
  const message = messages[0];
91
- yield this.publishDirectly(message.name, message.topic, message.payload, message.producerId, message.metadata, false, message.contentType);
92
+ yield this.publishDirectly(message.id, message.name, message.topic, message.payload, message.producerId, message.metadata, false, message.contentType);
92
93
  return;
93
94
  }
94
95
  const grouped = messages.reduce((acc, message) => {
@@ -110,9 +111,12 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
110
111
  const contentType = (_a = messages[0].contentType) !== null && _a !== void 0 ? _a : 'application/json';
111
112
  const response = yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId }, contentType } : undefined);
112
113
  if (response.failedMessages) {
114
+ const error = (_b = response.failedMessages[0].error) !== null && _b !== void 0 ? _b : new Error('Unable to publish message');
113
115
  const failedMessages = response.failedMessages.map((m, i) => {
114
116
  var _a;
117
+ const messageId = this.getMessageId(m.message.event, m.message.entryID);
115
118
  return {
119
+ id: messageId,
116
120
  name,
117
121
  topic,
118
122
  payload: m.message.event,
@@ -120,7 +124,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
120
124
  contentType: (_a = m.message.contentType) !== null && _a !== void 0 ? _a : contentType,
121
125
  };
122
126
  });
123
- yield this.handleError(failedMessages, response.failedMessages[0].error);
127
+ yield this.handleError(failedMessages, error);
124
128
  }
125
129
  }
126
130
  catch (error) {
@@ -129,7 +133,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
129
133
  }
130
134
  });
131
135
  }
132
- publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
136
+ publishDirectly(id, name, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
133
137
  return __awaiter(this, void 0, void 0, function* () {
134
138
  try {
135
139
  if (!name)
@@ -149,28 +153,29 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
149
153
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
150
154
  try {
151
155
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
152
- if (response.error) {
156
+ if (response === null || response === void 0 ? void 0 : response.error) {
153
157
  throw response.error;
154
158
  }
155
159
  }
156
160
  catch (error) {
157
- yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
161
+ yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
158
162
  }
159
163
  }));
160
164
  return;
161
165
  }
162
166
  const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
163
- if (response.error) {
167
+ if (response === null || response === void 0 ? void 0 : response.error) {
164
168
  throw response.error;
165
169
  }
166
170
  }
167
171
  catch (error) {
168
- yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
172
+ yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
169
173
  }
170
174
  });
171
175
  }
172
176
  publish(...args) {
173
177
  return __awaiter(this, void 0, void 0, function* () {
178
+ let id;
174
179
  let name;
175
180
  let producerId;
176
181
  let topic;
@@ -178,11 +183,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
178
183
  let buffer;
179
184
  let metadata;
180
185
  let contentType;
181
- if (args.length === 7) {
182
- [name, producerId, topic, payload, buffer, metadata, contentType] = args;
186
+ if (args.length === 8) {
187
+ [id, name, producerId, topic, payload, buffer, metadata, contentType] = args;
183
188
  }
184
189
  else {
185
- [producerId, topic, payload, buffer, metadata, contentType] = args;
190
+ [id, producerId, topic, payload, buffer, metadata, contentType] = args;
186
191
  name = this.defaultName;
187
192
  }
188
193
  if (!name)
@@ -190,10 +195,10 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
190
195
  if (!contentType)
191
196
  contentType = 'application/json';
192
197
  if (buffer === undefined || buffer) {
193
- this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
198
+ this.buffer.next({ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, producerId, topic, payload, metadata, contentType });
194
199
  return;
195
200
  }
196
- yield this.publishDirectly(name, topic, payload, producerId, metadata, true, contentType);
201
+ yield this.publishDirectly(id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, topic, payload, producerId, metadata, true, contentType);
197
202
  });
198
203
  }
199
204
  publishBulk(...args) {
@@ -220,14 +225,27 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
220
225
  if (!contentType)
221
226
  contentType = 'application/json';
222
227
  if (payloads.length === 1) {
223
- yield this.publishDirectly(name, topic, payloads[0], producerId, metadata, true, contentType);
228
+ const messageId = this.getMessageId(payloads[0]);
229
+ yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
224
230
  return;
225
231
  }
226
232
  for (const payload of payloads) {
227
- this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
233
+ this.buffer.next({
234
+ id: this.getMessageId(payloads),
235
+ name,
236
+ producerId,
237
+ topic,
238
+ payload,
239
+ metadata,
240
+ contentType,
241
+ });
228
242
  }
229
243
  });
230
244
  }
245
+ getMessageId(payload, defaultValue) {
246
+ var _a, _b, _c, _d;
247
+ return (_d = (_c = (_b = (_a = payload.id) !== null && _a !== void 0 ? _a : payload.messageId) !== null && _b !== void 0 ? _b : payload.correlationId) !== null && _c !== void 0 ? _c : defaultValue) !== null && _d !== void 0 ? _d : (0, crypto_1.randomUUID)();
248
+ }
231
249
  };
232
250
  DaprPubSubClient = DaprPubSubClient_1 = __decorate([
233
251
  (0, common_1.Injectable)(),
@@ -1,4 +1,5 @@
1
1
  export interface PublishMessage {
2
+ id: string;
2
3
  name: string;
3
4
  producerId?: string;
4
5
  topic: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.38",
3
+ "version": "0.9.40",
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",