@google-cloud/pubsub 2.16.6 → 2.18.2

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +54 -53
  3. package/build/protos/protos.d.ts +2 -1
  4. package/build/protos/protos.js +7 -0
  5. package/build/protos/protos.json +14 -1
  6. package/build/src/iam.d.ts +180 -0
  7. package/build/src/iam.js +11 -176
  8. package/build/src/iam.js.map +1 -1
  9. package/build/src/index.d.ts +13 -4
  10. package/build/src/index.js +12 -4
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/lease-manager.d.ts +7 -2
  13. package/build/src/lease-manager.js +19 -4
  14. package/build/src/lease-manager.js.map +1 -1
  15. package/build/src/publisher/flow-control.d.ts +90 -0
  16. package/build/src/publisher/flow-control.js +145 -0
  17. package/build/src/publisher/flow-control.js.map +1 -0
  18. package/build/src/publisher/flow-publisher.d.ts +95 -0
  19. package/build/src/publisher/flow-publisher.js +133 -0
  20. package/build/src/publisher/flow-publisher.js.map +1 -0
  21. package/build/src/publisher/index.d.ts +33 -5
  22. package/build/src/publisher/index.js +16 -39
  23. package/build/src/publisher/index.js.map +1 -1
  24. package/build/src/publisher/message-batch.d.ts +1 -1
  25. package/build/src/publisher/message-batch.js +4 -3
  26. package/build/src/publisher/message-batch.js.map +1 -1
  27. package/build/src/publisher/message-queues.js.map +1 -1
  28. package/build/src/publisher/pubsub-message.d.ts +52 -0
  29. package/build/src/publisher/pubsub-message.js +56 -0
  30. package/build/src/publisher/pubsub-message.js.map +1 -0
  31. package/build/src/pubsub.d.ts +354 -4
  32. package/build/src/pubsub.js +28 -322
  33. package/build/src/pubsub.js.map +1 -1
  34. package/build/src/schema.d.ts +9 -4
  35. package/build/src/schema.js +9 -4
  36. package/build/src/schema.js.map +1 -1
  37. package/build/src/snapshot.d.ts +87 -0
  38. package/build/src/snapshot.js +7 -83
  39. package/build/src/snapshot.js.map +1 -1
  40. package/build/src/subscriber.d.ts +6 -0
  41. package/build/src/subscriber.js +6 -0
  42. package/build/src/subscriber.js.map +1 -1
  43. package/build/src/subscription.d.ts +439 -9
  44. package/build/src/subscription.js +38 -404
  45. package/build/src/subscription.js.map +1 -1
  46. package/build/src/topic.d.ts +481 -1
  47. package/build/src/topic.js +51 -430
  48. package/build/src/topic.js.map +1 -1
  49. package/build/src/util.d.ts +2 -1
  50. package/build/src/util.js +2 -2
  51. package/build/src/util.js.map +1 -1
  52. package/build/src/v1/publisher_client.d.ts +262 -0
  53. package/build/src/v1/publisher_client.js +11 -244
  54. package/build/src/v1/publisher_client.js.map +1 -1
  55. package/build/src/v1/publisher_client_config.json +2 -2
  56. package/build/src/v1/schema_service_client.d.ts +165 -0
  57. package/build/src/v1/schema_service_client.js +7 -153
  58. package/build/src/v1/schema_service_client.js.map +1 -1
  59. package/build/src/v1/subscriber_client.d.ts +566 -0
  60. package/build/src/v1/subscriber_client.js +11 -534
  61. package/build/src/v1/subscriber_client.js.map +1 -1
  62. package/package.json +2 -2
@@ -17,9 +17,10 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.Topic = void 0;
19
19
  const paginator_1 = require("@google-cloud/paginator");
20
- const promisify_1 = require("@google-cloud/promisify");
21
20
  const iam_1 = require("./iam");
22
21
  const publisher_1 = require("./publisher");
22
+ const flow_publisher_1 = require("./publisher/flow-publisher");
23
+ const util_1 = require("./util");
23
24
  /**
24
25
  * A Topic object allows you to interact with a Cloud Pub/Sub topic.
25
26
  *
@@ -29,13 +30,17 @@ const publisher_1 = require("./publisher");
29
30
  * @param {PublishOptions} [options] Publisher configuration object.
30
31
  *
31
32
  * @example
33
+ * ```
32
34
  * const {PubSub} = require('@google-cloud/pubsub');
33
35
  * const pubsub = new PubSub();
34
36
  *
35
37
  * const topic = pubsub.topic('my-topic');
36
38
  *
37
- * @example <caption>To enable message ordering, set `enableMessageOrdering` to true. Please note that this does not persist to an actual topic.</caption>
39
+ * ```
40
+ * @example To enable message ordering, set `enableMessageOrdering` to true. Please note that this does not persist to an actual topic.
41
+ * ```
38
42
  * const topic = pubsub.topic('ordered-topic', {enableMessageOrdering: true});
43
+ * ```
39
44
  */
40
45
  class Topic {
41
46
  constructor(pubsub, name, options) {
@@ -80,6 +85,7 @@ class Topic {
80
85
  * @see [What is Cloud IAM?]{@link https://cloud.google.com/iam/}
81
86
  *
82
87
  * @example
88
+ * ```
83
89
  * const {PubSub} = require('@google-cloud/pubsub');
84
90
  * const pubsub = new PubSub();
85
91
  *
@@ -99,124 +105,25 @@ class Topic {
99
105
  * const policy = data[0];
100
106
  * const apiResponse = data[1];
101
107
  * });
108
+ * ```
102
109
  */
103
110
  this.iam = new iam_1.IAM(pubsub, this.name);
104
111
  }
105
- /**
106
- * Immediately sends all remaining queued data. This is mostly useful
107
- * if you are planning to call close() on the PubSub object that holds
108
- * the server connections.
109
- *
110
- * @param {EmptyCallback} [callback] Callback function.
111
- * @returns {Promise<EmptyResponse>}
112
- */
113
112
  flush(callback) {
114
113
  // It doesn't matter here if callback is undefined; the Publisher
115
114
  // flush() will handle it.
116
115
  this.publisher.flush(callback);
117
116
  }
118
- /**
119
- * Create a topic.
120
- *
121
- * @param {object} [gaxOpts] Request configuration options, outlined
122
- * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
123
- * @param {CreateTopicCallback} [callback] Callback function.
124
- * @returns {Promise<CreateTopicResponse>}
125
- *
126
- * @example
127
- * const {PubSub} = require('@google-cloud/pubsub');
128
- * const pubsub = new PubSub();
129
- *
130
- * const topic = pubsub.topic('my-topic');
131
- *
132
- * topic.create((err, topic, apiResponse) => {
133
- * if (!err) {
134
- * // The topic was created successfully.
135
- * }
136
- * });
137
- *
138
- * //-
139
- * // If the callback is omitted, we'll return a Promise.
140
- * //-
141
- * topic.create().then((data) => {
142
- * const topic = data[0];
143
- * const apiResponse = data[1];
144
- * });
145
- */
146
117
  create(optsOrCallback, callback) {
147
118
  const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {};
148
119
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
149
120
  this.pubsub.createTopic(this.name, gaxOpts, callback);
150
121
  }
151
- /**
152
- * Create a subscription to this topic.
153
- *
154
- * @see [Subscriptions: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create}
155
- *
156
- * @throws {Error} If subscription name is omitted.
157
- *
158
- * @param {string} name The name of the subscription.
159
- * @param {CreateSubscriptionRequest} [options] See a
160
- * [Subscription
161
- * resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).
162
- * @param {CreateSubscriptionCallback} [callback] Callback function.
163
- * @returns {Promise<CreateSubscriptionResponse>}
164
- *
165
- * @example
166
- * const {PubSub} = require('@google-cloud/pubsub');
167
- * const pubsub = new PubSub();
168
- *
169
- * const topic = pubsub.topic('my-topic');
170
- * const callback = function(err, subscription, apiResponse) {};
171
- *
172
- * // Without specifying any options.
173
- * topic.createSubscription('newMessages', callback);
174
- *
175
- * // With options.
176
- * topic.createSubscription('newMessages', {
177
- * ackDeadlineSeconds: 90
178
- * }, callback);
179
- *
180
- * //-
181
- * // If the callback is omitted, we'll return a Promise.
182
- * //-
183
- * topic.createSubscription('newMessages').then((data) => {
184
- * const subscription = data[0];
185
- * const apiResponse = data[1];
186
- * });
187
- */
188
122
  createSubscription(name, optsOrCallback, callback) {
189
123
  const options = typeof optsOrCallback === 'object' ? optsOrCallback : {};
190
124
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
191
125
  this.pubsub.createSubscription(this, name, options, callback);
192
126
  }
193
- /**
194
- * Delete the topic. This will not delete subscriptions to this topic.
195
- *
196
- * @see [Topics: delete API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/delete}
197
- *
198
- * @param {object} [gaxOpts] Request configuration options, outlined
199
- * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
200
- * @param {function} [callback] The callback function.
201
- * @param {?error} callback.err An error returned while making this
202
- * request.
203
- * @param {object} callback.apiResponse Raw API response.
204
- *
205
- * @example
206
- * const {PubSub} = require('@google-cloud/pubsub');
207
- * const pubsub = new PubSub();
208
- *
209
- * const topic = pubsub.topic('my-topic');
210
- *
211
- * topic.delete((err, apiResponse) => {});
212
- *
213
- * //-
214
- * // If the callback is omitted, we'll return a Promise.
215
- * //-
216
- * topic.delete().then((data) => {
217
- * const apiResponse = data[0];
218
- * });
219
- */
220
127
  delete(optsOrCallback, callback) {
221
128
  const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {};
222
129
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
@@ -230,36 +137,6 @@ class Topic {
230
137
  gaxOpts: gaxOpts,
231
138
  }, callback);
232
139
  }
233
- /**
234
- * @typedef {array} TopicExistsResponse
235
- * @property {boolean} 0 Whether the topic exists
236
- */
237
- /**
238
- * @callback TopicExistsCallback
239
- * @param {?Error} err Request error, if any.
240
- * @param {boolean} exists Whether the topic exists.
241
- */
242
- /**
243
- * Check if a topic exists.
244
- *
245
- * @param {TopicExistsCallback} [callback] Callback function.
246
- * @returns {Promise<TopicExistsResponse>}
247
- *
248
- * @example
249
- * const {PubSub} = require('@google-cloud/pubsub');
250
- * const pubsub = new PubSub();
251
- *
252
- * const topic = pubsub.topic('my-topic');
253
- *
254
- * topic.exists((err, exists) => {});
255
- *
256
- * //-
257
- * // If the callback is omitted, we'll return a Promise.
258
- * //-
259
- * topic.exists().then((data) => {
260
- * const exists = data[0];
261
- * });
262
- */
263
140
  exists(callback) {
264
141
  this.getMetadata(err => {
265
142
  if (!err) {
@@ -273,45 +150,6 @@ class Topic {
273
150
  callback(err);
274
151
  });
275
152
  }
276
- /**
277
- * @typedef {array} GetTopicResponse
278
- * @property {Topic} 0 The {@link Topic}.
279
- * @property {object} 1 The full API response.
280
- */
281
- /**
282
- * @callback GetTopicCallback
283
- * @param {?Error} err Request error, if any.
284
- * @param {Topic} topic The {@link Topic}.
285
- * @param {object} apiResponse The full API response.
286
- */
287
- /**
288
- * Get a topic if it exists.
289
- *
290
- * @param {object} [gaxOpts] Request configuration options, outlined
291
- * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
292
- * @param {boolean} [gaxOpts.autoCreate=false] Automatically create the topic
293
- * does not already exist.
294
- * @param {GetTopicCallback} [callback] Callback function.
295
- * @returns {Promise<GetTopicResponse>}
296
- *
297
- * @example
298
- * const {PubSub} = require('@google-cloud/pubsub');
299
- * const pubsub = new PubSub();
300
- *
301
- * const topic = pubsub.topic('my-topic');
302
- *
303
- * topic.get((err, topic, apiResponse) => {
304
- * // The `topic` data has been populated.
305
- * });
306
- *
307
- * //-
308
- * // If the callback is omitted, we'll return a Promise.
309
- * //-
310
- * topic.get().then((data) => {
311
- * const topic = data[0];
312
- * const apiResponse = data[1];
313
- * });
314
- */
315
153
  get(optsOrCallback, callback) {
316
154
  const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {};
317
155
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
@@ -329,40 +167,6 @@ class Topic {
329
167
  this.create(gaxOpts, callback);
330
168
  });
331
169
  }
332
- /**
333
- * @typedef {array} GetTopicMetadataResponse
334
- * @property {object} 0 The full API response.
335
- */
336
- /**
337
- * @callback GetTopicMetadataCallback
338
- * @param {?Error} err Request error, if any.
339
- * @param {object} apiResponse The full API response.
340
- */
341
- /**
342
- * Get the official representation of this topic from the API.
343
- *
344
- * @see [Topics: get API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/get}
345
- *
346
- * @param {object} [gaxOpts] Request configuration options, outlined
347
- * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
348
- * @param {GetTopicMetadataCallback} [callback] Callback function.
349
- * @returns {Promise<GetTopicMetadataResponse>}
350
- *
351
- * @example
352
- * const {PubSub} = require('@google-cloud/pubsub');
353
- * const pubsub = new PubSub();
354
- *
355
- * const topic = pubsub.topic('my-topic');
356
- *
357
- * topic.getMetadata((err, apiResponse) => {});
358
- *
359
- * //-
360
- * // If the callback is omitted, we'll return a Promise.
361
- * //-
362
- * topic.getMetadata().then((data) => {
363
- * const apiResponse = data[0];
364
- * });
365
- */
366
170
  getMetadata(optsOrCallback, callback) {
367
171
  const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {};
368
172
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
@@ -381,42 +185,6 @@ class Topic {
381
185
  callback(err, apiResponse);
382
186
  });
383
187
  }
384
- /**
385
- * Get a list of the subscriptions registered to this topic. You may
386
- * optionally provide a query object as the first argument to customize the
387
- * response.
388
- *
389
- * Your provided callback will be invoked with an error object if an API error
390
- * occurred or an array of {module:pubsub/subscription} objects.
391
- *
392
- * @see [Subscriptions: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics.subscriptions/list}
393
- *
394
- * @param {GetSubscriptionsRequest} [query] Query object for listing subscriptions.
395
- * @param {GetSubscriptionsCallback} [callback] Callback function.
396
- * @returns {Promise<GetSubscriptionsResponse>}
397
- *
398
- * @example
399
- * const {PubSub} = require('@google-cloud/pubsub');
400
- * const pubsub = new PubSub();
401
- *
402
- * const topic = pubsub.topic('my-topic');
403
- *
404
- * topic.getSubscriptions((err, subscriptions) => {
405
- * // subscriptions is an array of `Subscription` objects.
406
- * });
407
- *
408
- * // Customize the query.
409
- * topic.getSubscriptions({
410
- * pageSize: 3
411
- * }, callback);
412
- *
413
- * //-
414
- * // If the callback is omitted, we'll return a Promise.
415
- * //-
416
- * topic.getSubscriptions().then((data) => {
417
- * const subscriptions = data[0];
418
- * });
419
- */
420
188
  getSubscriptions(optsOrCallback, callback) {
421
189
  const options = typeof optsOrCallback === 'object' ? optsOrCallback : {};
422
190
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
@@ -441,93 +209,11 @@ class Topic {
441
209
  callback(err, subscriptions, ...args);
442
210
  });
443
211
  }
444
- /**
445
- * Publish the provided message.
446
- *
447
- * @deprecated Please use {@link Topic#publishMessage}.
448
- *
449
- * @throws {TypeError} If data is not a Buffer object.
450
- * @throws {TypeError} If any value in `attributes` object is not a string.
451
- *
452
- * @param {buffer} data The message data. This must come in the form of a
453
- * Buffer object.
454
- * @param {object.<string, string>} [attributes] Attributes for this message.
455
- * @param {PublishCallback} [callback] Callback function.
456
- * @returns {Promise<PublishResponse>}
457
- *
458
- * @example
459
- * const {PubSub} = require('@google-cloud/pubsub');
460
- * const pubsub = new PubSub();
461
- *
462
- * const topic = pubsub.topic('my-topic');
463
- * const data = Buffer.from('Hello, world!');
464
- *
465
- * const callback = (err, messageId) => {
466
- * if (err) {
467
- * // Error handling omitted.
468
- * }
469
- * };
470
- *
471
- * topic.publish(data, callback);
472
- *
473
- * @example <caption>Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.</caption>
474
- * const attributes = {
475
- * key: 'value'
476
- * };
477
- *
478
- * topic.publish(data, attributes, callback);
479
- *
480
- * @example <caption>If the callback is omitted, we'll return a Promise.</caption>
481
- * topic.publish(data).then((messageId) => {});
482
- */
483
212
  publish(data, attrsOrCb, callback) {
484
213
  const attributes = typeof attrsOrCb === 'object' ? attrsOrCb : {};
485
214
  callback = typeof attrsOrCb === 'function' ? attrsOrCb : callback;
486
215
  return this.publishMessage({ data, attributes }, callback);
487
216
  }
488
- /**
489
- * Publish the provided JSON. It should be noted that all messages published
490
- * are done so in the form of a Buffer. This is simply a convenience method
491
- * that will transform JSON into a Buffer before publishing.
492
- * {@link Subscription} objects will always return message data in the form of
493
- * a Buffer, so any JSON published will require manual deserialization.
494
- *
495
- * @deprecated Please use the `json` option via {@link Topic#publishMessage}.
496
- *
497
- * @throws {Error} If non-object data is provided.
498
- *
499
- * @param {object} json The JSON data to publish.
500
- * @param {object} [attributes] Attributes for this message.
501
- * @param {PublishCallback} [callback] Callback function.
502
- * @returns {Promise<PublishResponse>}
503
- *
504
- * @example
505
- * const {PubSub} = require('@google-cloud/pubsub');
506
- * const pubsub = new PubSub();
507
- * const topic = pubsub.topic('my-topic');
508
- *
509
- * const data = {
510
- * foo: 'bar'
511
- * };
512
- *
513
- * const callback = (err, messageId) => {
514
- * if (err) {
515
- * // Error handling omitted.
516
- * }
517
- * };
518
- *
519
- * topic.publishJSON(data, callback);
520
- *
521
- * @example <caption>Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.</caption>
522
- * const attributes = {
523
- * key: 'value'
524
- * };
525
- *
526
- * topic.publishJSON(data, attributes, callback);
527
- *
528
- * @example <caption>If the callback is omitted, we'll return a Promise.</caption>
529
- * topic.publishJSON(data).then((messageId) => {});
530
- */
531
217
  publishJSON(json, attrsOrCb, callback) {
532
218
  if (!json || typeof json !== 'object') {
533
219
  throw new Error('First parameter should be an object.');
@@ -536,58 +222,9 @@ class Topic {
536
222
  callback = typeof attrsOrCb === 'function' ? attrsOrCb : callback;
537
223
  return this.publishMessage({ json, attributes }, callback);
538
224
  }
539
- /**
540
- * @typedef {object} MessageOptions
541
- * @property {buffer} [data] The message data.
542
- * @property {object} [json] Convenience property to publish JSON data. This
543
- * will transform the provided JSON into a Buffer before publishing.
544
- * {@link Subscription} objects will always return message data in the
545
- * form of a Buffer, so any JSON published will require manual
546
- * deserialization.
547
- * @property {object.<string, string>} [attributes] Attributes for this
548
- * message.
549
- * @property {string} [orderingKey] A message ordering key.
550
- */
551
- /**
552
- * Publish the provided message.
553
- *
554
- * @throws {TypeError} If data is not a Buffer object.
555
- * @throws {TypeError} If any value in `attributes` object is not a string.
556
- *
557
- * @param {MessageOptions} message Message object.
558
- * @param {PublishCallback} [callback] Callback function.
559
- * @returns {Promise<PublishResponse>}
560
- *
561
- * @example
562
- * const {PubSub} = require('@google-cloud/pubsub');
563
- * const pubsub = new PubSub();
564
- * const topic = pubsub.topic('my-topic');
565
- *
566
- * const data = Buffer.from('Hello, world!');
567
- *
568
- * const callback = (err, messageId) => {
569
- * if (err) {
570
- * // Error handling omitted.
571
- * }
572
- * };
573
- *
574
- * topic.publishMessage({data}, callback);
575
- *
576
- * @example <caption>Publish JSON message data.</caption>
577
- * const json = {foo: 'bar'};
578
- *
579
- * topic.publishMessage({json}, callback);
580
- *
581
- * @example <caption>To publish messages in order (this is still experimental), make sure message ordering is enabled and provide an ordering key</caption>
582
- * const topic = pubsub.topic('ordered-topic', {messageOrdering: true});
583
- * const orderingKey = 'my-key';
584
- *
585
- * topic.publishMessage({data, orderingKey}, callback);
586
- *
587
- * @example <caption>If the callback is omitted, we'll return a Promise.</caption>
588
- * const [messageId] = await topic.publishMessage({data});
589
- */
590
225
  publishMessage(message, callback) {
226
+ // Make a copy to ensure that any changes we make to it will not
227
+ // propagate up to the user's data.
591
228
  message = Object.assign({}, message);
592
229
  if (message.json && typeof message.json === 'object') {
593
230
  message.data = Buffer.from(JSON.stringify(message.json));
@@ -595,6 +232,22 @@ class Topic {
595
232
  }
596
233
  return this.publisher.publishMessage(message, callback);
597
234
  }
235
+ /**
236
+ * Creates a FlowControlledPublisher for this Topic.
237
+ *
238
+ * FlowControlledPublisher is a helper that lets you control how many messages
239
+ * are simultaneously queued to send, to avoid ballooning memory usage on
240
+ * a low bandwidth connection to Pub/Sub.
241
+ *
242
+ * Note that it's perfectly fine to create more than one on the same Topic.
243
+ * The actual flow control settings on the Topic will apply across all
244
+ * FlowControlledPublisher objects on that Topic.
245
+ *
246
+ * @returns {FlowControlledPublisher} The flow control helper.
247
+ */
248
+ flowControlled() {
249
+ return new flow_publisher_1.FlowControlledPublisher(this.publisher);
250
+ }
598
251
  /**
599
252
  * In the event that the client fails to publish an ordered message, all
600
253
  * subsequent publish calls using the same ordering key will fail. Calling
@@ -604,6 +257,7 @@ class Topic {
604
257
  * @param {string} orderingKey The ordering key in question.
605
258
  *
606
259
  * @example
260
+ * ```
607
261
  * const {PubSub} = require('@google-cloud/pubsub');
608
262
  * const pubsub = new PubSub();
609
263
  * const topic = pubsub.topic('my-topic', {messageOrdering: true});
@@ -616,54 +270,11 @@ class Topic {
616
270
  * topic.resumePublishing(orderingKey);
617
271
  * }
618
272
  * });
273
+ * ```
619
274
  */
620
275
  resumePublishing(orderingKey) {
621
276
  this.publisher.resumePublishing(orderingKey);
622
277
  }
623
- /**
624
- * @typedef {array} SetTopicMetadataResponse
625
- * @property {object} 0 The full API response.
626
- */
627
- /**
628
- * @callback SetTopicMetadataCallback
629
- * @param {?Error} err Request error, if any.
630
- * @param {object} apiResponse The full API response.
631
- */
632
- /**
633
- * Updates the topic.
634
- *
635
- * @see [UpdateTopicRequest API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.UpdateTopicRequest}
636
- *
637
- * @param {object} metadata The fields to update. This should be structured
638
- * like a {@link
639
- * https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics#Topic|Topic
640
- * object}.
641
- * @param {object} [gaxOpts] Request configuration options, outlined
642
- * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
643
- * @param {SetTopicMetadataCallback} [callback] Callback function.
644
- * @returns {Promise<SetTopicMetadataResponse>}
645
- *
646
- * @example
647
- * const {PubSub} = require('@google-cloud/pubsub');
648
- * const pubsub = new PubSub();
649
- *
650
- * const topic = pubsub.topic('my-topic');
651
- * const metadata = {
652
- * labels: {foo: 'bar'}
653
- * };
654
- *
655
- * topic.setMetadata(metadata, err => {
656
- * if (err) {
657
- * // Error handling omitted.
658
- * }
659
- * });
660
- *
661
- * @example <caption>If the callback is omitted, we'll return a
662
- * Promise.</caption>
663
- * topic.setMetadata(metadata).then((data) => {
664
- * const apiResponse = data[0];
665
- * });
666
- */
667
278
  setMetadata(options, optsOrCallback, callback) {
668
279
  const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {};
669
280
  callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;
@@ -683,6 +294,7 @@ class Topic {
683
294
  * @param {PublishOptions} options The publisher options.
684
295
  *
685
296
  * @example
297
+ * ```
686
298
  * const {PubSub} = require('@google-cloud/pubsub');
687
299
  * const pubsub = new PubSub();
688
300
  *
@@ -693,6 +305,7 @@ class Topic {
693
305
  * maxMilliseconds: 10
694
306
  * }
695
307
  * });
308
+ * ```
696
309
  */
697
310
  setPublishOptions(options) {
698
311
  this.publisher.setOptions(options);
@@ -702,6 +315,7 @@ class Topic {
702
315
  * back into {@link Topic#setPublishOptions}.
703
316
  *
704
317
  * @example
318
+ * ```
705
319
  * const {PubSub} = require('@google-cloud/pubsub');
706
320
  * const pubsub = new PubSub();
707
321
  *
@@ -710,6 +324,7 @@ class Topic {
710
324
  * const defaults = topic.getPublishOptionDefaults();
711
325
  * defaults.batching.maxMilliseconds = 10;
712
326
  * topic.setPublishOptions(defaults);
327
+ * ```
713
328
  */
714
329
  getPublishOptionDefaults() {
715
330
  // Generally I'd leave this as a static, but it'll be easier for users to
@@ -728,6 +343,7 @@ class Topic {
728
343
  * @return {Subscription}
729
344
  *
730
345
  * @example
346
+ * ```
731
347
  * const {PubSub} = require('@google-cloud/pubsub');
732
348
  * const pubsub = new PubSub();
733
349
  *
@@ -743,6 +359,7 @@ class Topic {
743
359
  * // message.attributes = Attributes of the message.
744
360
  * // message.publishTime = Timestamp when Pub/Sub received the message.
745
361
  * });
362
+ * ```
746
363
  */
747
364
  subscription(name, options) {
748
365
  options = options || {};
@@ -776,6 +393,7 @@ exports.Topic = Topic;
776
393
  * @returns {ReadableStream} A readable stream of {@link Subscription} instances.
777
394
  *
778
395
  * @example
396
+ * ```
779
397
  * const {PubSub} = require('@google-cloud/pubsub');
780
398
  * const pubsub = new PubSub();
781
399
  *
@@ -798,6 +416,7 @@ exports.Topic = Topic;
798
416
  * .on('data', function(subscription) {
799
417
  * this.end();
800
418
  * });
419
+ * ```
801
420
  */
802
421
  /*! Developer Documentation
803
422
  *
@@ -806,17 +425,19 @@ exports.Topic = Topic;
806
425
  paginator_1.paginator.extend(Topic, ['getSubscriptions']);
807
426
  /*! Developer Documentation
808
427
  *
809
- * All async methods (except for streams) will return a Promise in the event
810
- * that a callback is omitted.
428
+ * Existing async methods (except for streams) will return a Promise in the event
429
+ * that a callback is omitted. Future methods will not allow for a callback.
430
+ * (Use .then() on the returned Promise instead.)
811
431
  */
812
- promisify_1.promisifyAll(Topic, {
813
- exclude: [
814
- 'publish',
815
- 'publishJSON',
816
- 'publishMessage',
817
- 'setPublishOptions',
818
- 'getPublishOptionDefaults',
819
- 'subscription',
820
- ],
821
- });
432
+ util_1.promisifySome(Topic, Topic.prototype, [
433
+ 'flush',
434
+ 'create',
435
+ 'createSubscription',
436
+ 'delete',
437
+ 'exists',
438
+ 'get',
439
+ 'getMetadata',
440
+ 'getSubscriptions',
441
+ 'setMetadata',
442
+ ]);
822
443
  //# sourceMappingURL=topic.js.map