Skip to content

Commit de59422

Browse files
authored
Em pubsub (#527)
* Adding code comments to pupsub.ts * Adding code comments to pubsub.ts source file * Removing line breaks between @param and @return tags for TopicBuilder.onPublish() and topic()
1 parent ef4e0db commit de59422

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/providers/pubsub.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ export const provider = 'google.pubsub';
3535
/** @hidden */
3636
export const service = 'pubsub.googleapis.com';
3737

38-
/** Select Cloud Pub/Sub topic to listen to.
39-
* @param topic Name of Pub/Sub topic, must belong to the same project as the function.
38+
/**
39+
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
40+
* is sent to a specified topic.
41+
*
42+
* @param topic The Pub/Sub topic to watch for message events.
43+
* @return Pub/Sub topic builder interface.
4044
*/
4145
export function topic(topic: string) {
4246
return _topicWithOptions(topic, {});
@@ -105,15 +109,26 @@ export function _scheduleWithOptions(
105109
return new ScheduleBuilder({ ...options, schedule: { schedule } });
106110
}
107111

108-
/** Builder used to create Cloud Functions for Google Pub/Sub topics. */
112+
/**
113+
* The Google Cloud Pub/Sub topic builder.
114+
*
115+
* Access via [`functions.pubsub.topic()`](functions.pubsub#.topic).
116+
*/
109117
export class TopicBuilder {
110118
/** @hidden */
111119
constructor(
112120
private triggerResource: () => string,
113121
private options: DeploymentOptions
114122
) {}
115123

116-
/** Handle a Pub/Sub message that was published to a Cloud Pub/Sub topic */
124+
/**
125+
* Event handler that fires every time a Cloud Pub/Sub message is
126+
* published.
127+
*
128+
* @param handler Event handler that runs every time a Cloud Pub/Sub message
129+
* is published.
130+
* @return A Cloud Function that you can export and deploy.
131+
*/
117132
onPublish(
118133
handler: (message: Message, context: EventContext) => PromiseLike<any> | any
119134
): CloudFunction<Message> {
@@ -130,15 +145,22 @@ export class TopicBuilder {
130145
}
131146

132147
/**
133-
* A Pub/Sub message.
148+
* Interface representing a Google Cloud Pub/Sub message.
134149
*
135-
* This class has an additional .json helper which will correctly deserialize any
136-
* message that was a JSON object when published with the JS SDK. .json will throw
137-
* if the message is not a base64 encoded JSON string.
150+
* @param data Payload of a Pub/Sub message.
138151
*/
139152
export class Message {
153+
/**
154+
* The data payload of this message object as a base64-encoded string.
155+
*/
140156
readonly data: string;
157+
158+
/**
159+
* User-defined attributes published with the message, if any.
160+
*/
141161
readonly attributes: { [key: string]: string };
162+
163+
/** @hidden */
142164
private _json: any;
143165

144166
constructor(data: any) {
@@ -149,6 +171,9 @@ export class Message {
149171
];
150172
}
151173

174+
/**
175+
* The JSON data payload of this message object, if any.
176+
*/
152177
get json(): any {
153178
if (typeof this._json === 'undefined') {
154179
this._json = JSON.parse(new Buffer(this.data, 'base64').toString('utf8'));
@@ -157,6 +182,11 @@ export class Message {
157182
return this._json;
158183
}
159184

185+
/**
186+
* Returns a JSON-serializable representation of this object.
187+
*
188+
* @return A JSON-serializable representation of this object.
189+
*/
160190
toJSON(): any {
161191
return {
162192
data: this.data,

0 commit comments

Comments
 (0)