@simpleview/sv-pubsub 1.0.19 → 1.0.21

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # sv-pubsub-client
1
+ # sv-pubsub
2
2
 
3
3
  Client for communicating with the Google Pub/Sub service.
4
4
 
@@ -34,6 +34,19 @@ class PubSubClient {
34
34
  throw error;
35
35
  }
36
36
  }
37
+ async publishMessage(topicName, message) {
38
+ const topic = this.pubsub.topic(topicName);
39
+ try {
40
+ return await topic.publishMessage(message);
41
+ }
42
+ catch (e) {
43
+ if (e.code === 5) { // NOT_FOUND
44
+ const [newTopic] = await this.pubsub.createTopic(topicName);
45
+ return await newTopic.publishMessage(message);
46
+ }
47
+ throw e;
48
+ }
49
+ }
37
50
  close() {
38
51
  return this.pubsub.close();
39
52
  }
@@ -1,4 +1,5 @@
1
1
  import { PubSub, Subscription } from "@google-cloud/pubsub";
2
+ import { MessageOptions } from "@google-cloud/pubsub/build/src/topic";
2
3
  export type PubSubClientOptions = {
3
4
  projectId: string;
4
5
  credentials: {
@@ -11,5 +12,6 @@ export default class PubSubClient {
11
12
  constructor(options: PubSubClientOptions);
12
13
  createTopic(topicName: string): Promise<import("@google-cloud/pubsub").Topic>;
13
14
  createSubscription(topicName: string, subscriptionName: string, retentionDuration?: number): Promise<Subscription>;
15
+ publishMessage(topicName: string, message: MessageOptions): Promise<string>;
14
16
  close(): Promise<void>;
15
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleview/sv-pubsub",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Client for communicating with Google Pub/Sub",
5
5
  "author": "Paul Riding <paul.riding@granicus.com>",
6
6
  "devDependencies": {