@rayondigital/nest-dapr 0.9.35 → 0.9.36

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,11 @@ 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): Promise<void>;
21
- publish(name: string, producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): Promise<void>;
22
- publish(producerId: string, topic: string, payload: any, buffer: boolean, metadata?: any): 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
23
  publish(producerId: string, topic: string, payload: any): Promise<void>;
24
- publishBulk(name: string, producerId: string, topic: string, payloads: any[], metadata?: any): Promise<void>;
25
- publishBulk(producerId: string, topic: string, payloads: any[], metadata?: 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
26
  publishBulk(producerId: string, topic: string, payloads: any[]): Promise<void>;
27
27
  }
@@ -84,10 +84,11 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
84
84
  }));
85
85
  }
86
86
  publishBulkDirectly(messages) {
87
+ var _a;
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
89
  if (messages.length === 1) {
89
90
  const message = messages[0];
90
- yield this.publishDirectly(message.name, message.topic, message.payload, message.producerId, message.metadata);
91
+ yield this.publishDirectly(message.name, message.topic, message.payload, message.producerId, message.metadata, false, message.contentType);
91
92
  return;
92
93
  }
93
94
  const grouped = messages.reduce((acc, message) => {
@@ -102,11 +103,12 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
102
103
  const [name, topic, producerId] = key.split(':');
103
104
  const messages = grouped[key];
104
105
  if (messages.length === 1) {
105
- yield this.publishDirectly(name, topic, messages[0].payload, producerId, messages[0].metadata);
106
+ yield this.publishDirectly(name, topic, messages[0].payload, producerId, messages[0].metadata, false, messages[0].contentType);
106
107
  continue;
107
108
  }
108
109
  try {
109
- yield this.daprClient.pubsub.publishBulk(name, topic, messages.map((m) => m.payload), producerId ? { metadata: { partitionKey: producerId } } : undefined);
110
+ 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);
110
112
  }
111
113
  catch (error) {
112
114
  yield this.handleError(messages, error);
@@ -114,12 +116,16 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
114
116
  }
115
117
  });
116
118
  }
117
- publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false) {
119
+ publishDirectly(name, topic, payload, producerId, metadata, fireAndForget = false, contentType) {
118
120
  return __awaiter(this, void 0, void 0, function* () {
119
121
  try {
120
122
  if (!name)
121
123
  name = this.defaultName;
122
- const options = {};
124
+ if (!contentType)
125
+ contentType = 'application/json';
126
+ const options = {
127
+ contentType,
128
+ };
123
129
  if (metadata) {
124
130
  options['metadata'] = metadata;
125
131
  }
@@ -147,20 +153,23 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
147
153
  let payload;
148
154
  let buffer;
149
155
  let metadata;
150
- if (args.length === 6) {
151
- [name, producerId, topic, payload, buffer, metadata] = args;
156
+ let contentType;
157
+ if (args.length === 7) {
158
+ [name, producerId, topic, payload, buffer, metadata, contentType] = args;
152
159
  }
153
160
  else {
154
- [producerId, topic, payload, buffer, metadata] = args;
161
+ [producerId, topic, payload, buffer, metadata, contentType] = args;
155
162
  name = this.defaultName;
156
163
  }
157
164
  if (!name)
158
165
  name = this.defaultName;
166
+ if (!contentType)
167
+ contentType = 'application/json';
159
168
  if (buffer === undefined || buffer) {
160
- this.buffer.next({ name, producerId, topic, payload, metadata });
169
+ this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
161
170
  return;
162
171
  }
163
- yield this.publishDirectly(name, topic, payload, producerId, true);
172
+ yield this.publishDirectly(name, topic, payload, producerId, metadata, true, contentType);
164
173
  });
165
174
  }
166
175
  publishBulk(...args) {
@@ -170,25 +179,28 @@ let DaprPubSubClient = DaprPubSubClient_1 = class DaprPubSubClient {
170
179
  let topic;
171
180
  let payloads;
172
181
  let metadata;
173
- if (args.length === 5) {
174
- [name, producerId, topic, payloads, metadata] = args;
182
+ let contentType;
183
+ if (args.length === 6) {
184
+ [name, producerId, topic, payloads, metadata, contentType] = args;
175
185
  }
176
- else if (args.length === 4) {
177
- [producerId, topic, payloads, metadata] = args;
186
+ else if (args.length === 5) {
187
+ [producerId, topic, payloads, metadata, contentType] = args;
178
188
  name = this.defaultName;
179
189
  }
180
- else if (args.length === 3) {
190
+ else {
181
191
  [producerId, topic, payloads] = args;
182
192
  name = this.defaultName;
183
193
  }
184
194
  if (!name)
185
195
  name = this.defaultName;
196
+ if (!contentType)
197
+ contentType = 'application/json';
186
198
  if (payloads.length === 1) {
187
- yield this.publishDirectly(name, topic, payloads[0], producerId, metadata);
199
+ yield this.publishDirectly(name, topic, payloads[0], producerId, metadata, true, contentType);
188
200
  return;
189
201
  }
190
202
  for (const payload of payloads) {
191
- this.buffer.next({ name, producerId, topic, payload, metadata });
203
+ this.buffer.next({ name, producerId, topic, payload, metadata, contentType });
192
204
  }
193
205
  });
194
206
  }
@@ -4,4 +4,5 @@ export interface PublishMessage {
4
4
  topic: string;
5
5
  payload: any;
6
6
  metadata?: any;
7
+ contentType?: string;
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayondigital/nest-dapr",
3
- "version": "0.9.35",
3
+ "version": "0.9.36",
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",