pulse-sdk 1.0.7 → 1.0.8

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.
@@ -4,5 +4,9 @@ export declare class Producer {
4
4
  constructor(host?: string, port?: number);
5
5
  private setupTopics;
6
6
  send(topic: string, payload: any): Promise<void>;
7
+ streamSend(messages: Array<{
8
+ topic: string;
9
+ payload: any;
10
+ }>): Promise<void>;
7
11
  close(): void;
8
12
  }
package/dist/producer.js CHANGED
@@ -61,6 +61,47 @@ class Producer {
61
61
  });
62
62
  });
63
63
  }
64
+ async streamSend(messages) {
65
+ return new Promise((resolve, reject) => {
66
+ const stream = this.client.StreamPublish((err, res) => {
67
+ if (err)
68
+ return reject(err);
69
+ // Stream finished
70
+ });
71
+ stream.on('error', (err) => {
72
+ reject(err);
73
+ });
74
+ stream.on('end', () => {
75
+ resolve();
76
+ });
77
+ for (const msg of messages) {
78
+ let data;
79
+ const headers = {};
80
+ if (Buffer.isBuffer(msg.payload)) {
81
+ data = msg.payload;
82
+ headers['payload-type'] = 'bytes';
83
+ }
84
+ else if (typeof msg.payload === 'string') {
85
+ data = Buffer.from(msg.payload, 'utf-8');
86
+ headers['payload-type'] = 'string';
87
+ }
88
+ else if (typeof msg.payload === 'object') {
89
+ data = Buffer.from(JSON.stringify(msg.payload), 'utf-8');
90
+ headers['payload-type'] = 'json';
91
+ }
92
+ else {
93
+ stream.end();
94
+ return reject(new Error('Payload must be Buffer, string, or object'));
95
+ }
96
+ stream.write({
97
+ topic: msg.topic,
98
+ payload: data,
99
+ headers,
100
+ });
101
+ }
102
+ stream.end();
103
+ });
104
+ }
64
105
  close() {
65
106
  this.client.close();
66
107
  }
@@ -8,6 +8,9 @@ service PulseService {
8
8
  // Publish sends a message to a topic.
9
9
  rpc Publish(PublishRequest) returns (PublishResponse);
10
10
 
11
+ // StreamPublish sends a stream of messages to a topic.
12
+ rpc StreamPublish(stream PublishRequest) returns (stream PublishResponse);
13
+
11
14
  // Consume reads messages from a topic as a stream.
12
15
  rpc Consume(ConsumeRequest) returns (stream ConsumeResponse);
13
16
 
@@ -16,6 +19,9 @@ service PulseService {
16
19
 
17
20
  // CreateTopic creates a new topic.
18
21
  rpc CreateTopic(CreateTopicRequest) returns (CreateTopicResponse);
22
+
23
+ // ListTopics returns a list of all topics.
24
+ rpc ListTopics(ListTopicsRequest) returns (ListTopicsResponse);
19
25
  }
20
26
 
21
27
  message PublishRequest {
@@ -71,3 +77,4 @@ message ListTopicsRequest {}
71
77
  message ListTopicsResponse {
72
78
  repeated string topics = 1;
73
79
  }
80
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulse-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Pulse SDK for Node.js/TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",