@rayondigital/nest-dapr 0.9.37 → 0.9.39

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");
@@ -88,7 +89,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
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) => {
@@ -108,7 +109,22 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
108
109
  }
109
110
  try {
110
111
  const contentType = (_a = messages[0].contentType) !== null && _a !== void 0 ? _a : 'application/json';
111
- yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId }, contentType } : undefined);
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 failedMessages = response.failedMessages.map((m, i) => {
115
+ var _a;
116
+ const messageId = this.getMessageId(m.message.event, m.message.entryID);
117
+ return {
118
+ id: messageId,
119
+ name,
120
+ topic,
121
+ payload: m.message.event,
122
+ metadata: m.message.metadata,
123
+ contentType: (_a = m.message.contentType) !== null && _a !== void 0 ? _a : contentType,
124
+ };
125
+ });
126
+ yield this.handleError(failedMessages, response.failedMessages[0].error);
127
+ }
112
128
  }
113
129
  catch (error) {
114
130
  yield this.handleError(messages, error);
@@ -116,7 +132,7 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
116
132
  }
117
133
  });
118
134
  }
119
- publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
135
+ publishDirectly(id, name, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
120
136
  return __awaiter(this, void 0, void 0, function* () {
121
137
  try {
122
138
  if (!name)
@@ -135,23 +151,30 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
135
151
  if (fireAndForget) {
136
152
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
137
153
  try {
138
- yield this.daprClient.pubsub.publish(name, topic, payload, options);
154
+ const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
155
+ if (response.error) {
156
+ throw response.error;
157
+ }
139
158
  }
140
159
  catch (error) {
141
- yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
160
+ yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
142
161
  }
143
162
  }));
144
163
  return;
145
164
  }
146
- yield this.daprClient.pubsub.publish(name, topic, payload, options);
165
+ const response = yield this.daprClient.pubsub.publish(name, topic, payload, options);
166
+ if (response.error) {
167
+ throw response.error;
168
+ }
147
169
  }
148
170
  catch (error) {
149
- yield this.handleError([{ producerId, name, topic, payload, metadata }], error);
171
+ yield this.handleError([{ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), producerId, name, topic, payload, metadata }], error);
150
172
  }
151
173
  });
152
174
  }
153
175
  publish(...args) {
154
176
  return __awaiter(this, void 0, void 0, function* () {
177
+ let id;
155
178
  let name;
156
179
  let producerId;
157
180
  let topic;
@@ -159,11 +182,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
159
182
  let buffer;
160
183
  let metadata;
161
184
  let contentType;
162
- if (args.length === 7) {
163
- [name, producerId, topic, payload, buffer, metadata, contentType] = args;
185
+ if (args.length === 8) {
186
+ [id, name, producerId, topic, payload, buffer, metadata, contentType] = args;
164
187
  }
165
188
  else {
166
- [producerId, topic, payload, buffer, metadata, contentType] = args;
189
+ [id, producerId, topic, payload, buffer, metadata, contentType] = args;
167
190
  name = this.defaultName;
168
191
  }
169
192
  if (!name)
@@ -171,10 +194,10 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
171
194
  if (!contentType)
172
195
  contentType = 'application/json';
173
196
  if (buffer === undefined || buffer) {
174
- this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
197
+ this.buffer.next({ id: id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, producerId, topic, payload, metadata, contentType });
175
198
  return;
176
199
  }
177
- yield this.publishDirectly(name, topic, payload, producerId, metadata, true, contentType);
200
+ yield this.publishDirectly(id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)(), name, topic, payload, producerId, metadata, true, contentType);
178
201
  });
179
202
  }
180
203
  publishBulk(...args) {
@@ -201,14 +224,27 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
201
224
  if (!contentType)
202
225
  contentType = 'application/json';
203
226
  if (payloads.length === 1) {
204
- yield this.publishDirectly(name, topic, payloads[0], producerId, metadata, true, contentType);
227
+ const messageId = this.getMessageId(payloads[0]);
228
+ yield this.publishDirectly(messageId, name, topic, payloads[0], producerId, metadata, true, contentType);
205
229
  return;
206
230
  }
207
231
  for (const payload of payloads) {
208
- this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
232
+ this.buffer.next({
233
+ id: this.getMessageId(payloads),
234
+ name,
235
+ producerId,
236
+ topic,
237
+ payload,
238
+ metadata,
239
+ contentType,
240
+ });
209
241
  }
210
242
  });
211
243
  }
244
+ getMessageId(payload, defaultValue) {
245
+ var _a, _b, _c, _d;
246
+ 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)();
247
+ }
212
248
  };
213
249
  DaprPubSubClient = DaprPubSubClient_1 = __decorate([
214
250
  (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.37",
3
+ "version": "0.9.39",
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",