Skip to content

Commit 2164615

Browse files
authored
Update pubsub docs (#1106)
* Update pubsub docs
1 parent 27b4c10 commit 2164615

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

src/providers/pubsub.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const service = 'pubsub.googleapis.com';
3939
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
4040
* is sent to a specified topic.
4141
*
42-
* @param topic The Pub/Sub topic to watch for message events.
43-
* @return Pub/Sub topic builder interface.
42+
* @param topic - The Pub/Sub topic to watch for message events.
43+
* @returns Pub/Sub topic builder interface.
4444
*/
4545
export function topic(topic: string) {
4646
return _topicWithOptions(topic, {});
@@ -79,7 +79,7 @@ export class TopicBuilder {
7979
* Event handler that fires every time a Cloud Pub/Sub message is
8080
* published.
8181
*
82-
* @param handler Event handler that runs every time a Cloud Pub/Sub message
82+
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
8383
* is published.
8484
* @return A Cloud Function that you can export and deploy.
8585
*/
@@ -101,7 +101,7 @@ export class TopicBuilder {
101101
/**
102102
* Registers a Cloud Function to run at specified times.
103103
*
104-
* @param schedule The schedule, in Unix Crontab or AppEngine syntax.
104+
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
105105
* @return ScheduleBuilder interface.
106106
*/
107107
export function schedule(schedule: string): ScheduleBuilder {
@@ -156,7 +156,7 @@ export class ScheduleBuilder {
156156
* Event handler for scheduled functions. Triggered whenever the associated
157157
* scheduler job sends a Pub/Sub message.
158158
*
159-
* @param handler Handler that fires whenever the associated
159+
* @param handler - Handler that fires whenever the associated
160160
* scheduler job sends a Pub/Sub message.
161161
* @return A Cloud Function that you can export and deploy.
162162
*/
@@ -177,7 +177,7 @@ export class ScheduleBuilder {
177177
/**
178178
* Interface representing a Google Cloud Pub/Sub message.
179179
*
180-
* @param data Payload of a Pub/Sub message.
180+
* @param data - Payload of a Pub/Sub message.
181181
*/
182182
export class Message {
183183
/**

src/v2/providers/pubsub.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ import { ManifestEndpoint } from '../../runtime/manifest';
33
import { CloudEvent, CloudFunction } from '../core';
44
import * as options from '../options';
55

6+
/**
7+
* A PubSub Topic is:
8+
* <ul>
9+
* <li>A resource that you can publish messages to and then consume those messages via subscriptions.
10+
* <li>An isolated data stream for Pub/Sub messages.
11+
* <li>Messages are published to a topic.
12+
* <li>Messages are listened to via a subscription.
13+
* <li>Each subscription listens to the messages published to exactly one topic.
14+
*/
15+
export type PubSubTopic = string;
16+
17+
/**
18+
* Resource that listens to the messages published by exactly one topic.
19+
*/
20+
export type PubSubSubscription = string;
21+
622
/**
723
* Interface representing a Google Cloud Pub/Sub message.
824
*
9-
* @param data Payload of a Pub/Sub message.
25+
* @param data - Payload of a Pub/Sub message.
26+
* @typeParam T - Type representing `Message.data`'s JSON format
1027
*/
1128
export class Message<T> {
1229
/**
@@ -68,7 +85,7 @@ export class Message<T> {
6885
/**
6986
* Returns a JSON-serializable representation of this object.
7087
*
71-
* @return A JSON-serializable representation of this object.
88+
* @returns A JSON-serializable representation of this object.
7289
*/
7390
toJSON(): any {
7491
const json: Record<string, any> = {
@@ -86,29 +103,51 @@ export class Message<T> {
86103
}
87104
}
88105

89-
/** The interface published in a Pub/Sub publish subscription. */
106+
/**
107+
* The interface published in a Pub/Sub publish subscription.
108+
* @typeParam T - Type representing `Message.data`'s JSON format
109+
*/
90110
export interface MessagePublishedData<T = any> {
111+
/** Google Cloud Pub/Sub message. */
91112
readonly message: Message<T>;
92-
readonly subscription: string;
113+
/** A subscription resource. */
114+
readonly subscription: PubSubSubscription;
93115
}
94116

95117
/** PubSubOptions extend EventHandlerOptions but must include a topic. */
96118
export interface PubSubOptions extends options.EventHandlerOptions {
97-
topic: string;
119+
/** The Pub/Sub topic to watch for message events */
120+
topic: PubSubTopic;
98121
}
99122

100-
/** Handle a message being published to a Pub/Sub topic. */
123+
/**
124+
* Handle a message being published to a Pub/Sub topic.
125+
* @param topic - The Pub/Sub topic to watch for message events.
126+
* @param handler - runs every time a Cloud Pub/Sub message is published
127+
* @typeParam T - Type representing `Message.data`'s JSON format
128+
*/
101129
export function onMessagePublished<T = any>(
102-
topic: string,
130+
topic: PubSubTopic,
103131
handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>
104132
): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
105133

106-
/** Handle a message being published to a Pub/Sub topic. */
134+
/**
135+
* Handle a message being published to a Pub/Sub topic.
136+
* @param options - Option containing information (topic) for event
137+
* @param handler - runs every time a Cloud Pub/Sub message is published
138+
* @typeParam T - Type representing `Message.data`'s JSON format
139+
*/
107140
export function onMessagePublished<T = any>(
108141
options: PubSubOptions,
109142
handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>
110143
): CloudFunction<CloudEvent<MessagePublishedData<T>>>;
111144

145+
/**
146+
* Handle a message being published to a Pub/Sub topic.
147+
* @param topicOrOptions - A string representing the PubSub topic or an option (which contains the topic)
148+
* @param handler - runs every time a Cloud Pub/Sub message is published
149+
* @typeParam T - Type representing `Message.data`'s JSON format
150+
*/
112151
export function onMessagePublished<T = any>(
113152
topicOrOptions: string | PubSubOptions,
114153
handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>
@@ -127,7 +166,7 @@ export function onMessagePublished<T = any>(
127166
const func = (raw: CloudEvent<unknown>) => {
128167
const messagePublishedData = raw.data as {
129168
message: unknown;
130-
subscription: string;
169+
subscription: PubSubSubscription;
131170
};
132171
messagePublishedData.message = new Message(messagePublishedData.message);
133172
return handler(raw as CloudEvent<MessagePublishedData<T>>);

0 commit comments

Comments
 (0)