Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit ef2ec51

Browse files
authored
chore(cloud-rad): Add code fencing (#1415)
Code examples need code fencing around them to distingish from rich text for TSDoc. Internally b/179483748 Script used: https://github.com/fhinkel/cloud-rad-script/blob/main/fixExampleComments.js
1 parent a3bfd5f commit ef2ec51

12 files changed

Lines changed: 271 additions & 36 deletions

src/iam.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export type TestIamPermissionsCallback = ResourceCallback<
8383
* @see [What is Cloud IAM?]{@link https://cloud.google.com/iam/}
8484
*
8585
* @example
86+
* ```
8687
* const {PubSub} = require('@google-cloud/pubsub');
8788
* const pubsub = new PubSub();
8889
*
@@ -91,6 +92,7 @@ export type TestIamPermissionsCallback = ResourceCallback<
9192
*
9293
* const subscription = pubsub.subscription('my-subscription');
9394
* // subscription.iam
95+
* ```
9496
*/
9597
export class IAM {
9698
pubsub: PubSub;
@@ -127,6 +129,7 @@ export class IAM {
127129
* @see [Subscriptions: getIamPolicy API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/getIamPolicy}
128130
*
129131
* @example
132+
* ```
130133
* const {PubSub} = require('@google-cloud/pubsub');
131134
* const pubsub = new PubSub();
132135
*
@@ -144,6 +147,7 @@ export class IAM {
144147
* const policy = data[0];
145148
* const apiResponse = data[1];
146149
* });
150+
* ```
147151
*/
148152
getPolicy(
149153
optsOrCallback?: CallOptions | GetPolicyCallback,
@@ -202,6 +206,7 @@ export class IAM {
202206
* @see [Policy]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/Policy}
203207
*
204208
* @example
209+
* ```
205210
* const {PubSub} = require('@google-cloud/pubsub');
206211
* const pubsub = new PubSub();
207212
*
@@ -230,6 +235,7 @@ export class IAM {
230235
* const policy = data[0];
231236
* const apiResponse = data[1];
232237
* });
238+
* ```
233239
*/
234240
setPolicy(
235241
policy: Policy,
@@ -306,6 +312,7 @@ export class IAM {
306312
* @see [Permissions Reference]{@link https://cloud.google.com/pubsub/access_control#permissions}
307313
*
308314
* @example
315+
* ```
309316
* const {PubSub} = require('@google-cloud/pubsub');
310317
* const pubsub = new PubSub();
311318
*
@@ -347,6 +354,7 @@ export class IAM {
347354
* const permissions = data[0];
348355
* const apiResponse = data[1];
349356
* });
357+
* ```
350358
*/
351359
testPermissions(
352360
permissions: string | string[],

src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,29 @@
3131
* @module {PubSub} @google-cloud/pubsub
3232
* @alias nodejs-pubsub
3333
*
34-
* @example <caption>Install the client library with <a href="https://www.npmjs.com/">npm</a>:</caption>
34+
* @example Install the client library with <a href="https://www.npmjs.com/">npm</a>:
35+
* ```
3536
* npm install @google-cloud/pubsub
3637
*
37-
* @example <caption>Import the client library</caption>
38+
* ```
39+
* @example Import the client library
40+
* ```
3841
* const {PubSub} = require('@google-cloud/pubsub');
3942
*
40-
* @example <caption>Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:</caption>
43+
* ```
44+
* @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
45+
* ```
4146
* const pubsub = new PubSub();
4247
*
43-
* @example <caption>Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:</caption>
48+
* ```
49+
* @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
50+
* ```
4451
* const pubsub = new PubSub({
4552
* projectId: 'your-project-id',
4653
* keyFilename: '/path/to/keyfile.json'
4754
* });
4855
*
56+
* ```
4957
* @example <caption>include:samples/quickstart.js</caption>
5058
* region_tag:pubsub_quickstart_create_topic
5159
* Full quickstart example:

src/publisher/flow-publisher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,18 @@ export class FlowControlledPublisher {
6262
* @returns null, or a Promise that resolves when sending may resume.
6363
*
6464
* @example
65+
* ```
6566
* const wait = flowControlled.publish({data});
6667
* if (wait) {
6768
* await wait;
6869
* }
6970
*
71+
* ```
7072
* @example
73+
* ```
7174
* // It's okay to await unconditionally, it's equivalent to nextTick().
7275
* await flowControlled.publish(data);
76+
* ```
7377
*/
7478
publish(message: PubsubMessage): Promise<void> | null {
7579
const doPublish = () => {
@@ -97,9 +101,11 @@ export class FlowControlledPublisher {
97101
* @param {Attributes} [attributes] Optional attributes.
98102
*
99103
* @example
104+
* ```
100105
* if (!flowControlled.wouldExceed(data)) {
101106
* flowControlled.publishNow(data);
102107
* }
108+
* ```
103109
*/
104110
publishNow(message: PubsubMessage): void {
105111
this.flowControl.addToCount(calculateMessageSize(message), 1);

src/pubsub.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,24 @@ interface GetClientCallback {
227227
*
228228
* @param {ClientConfig} [options] Configuration options.
229229
*
230-
* @example <caption>Import the client library</caption>
230+
* @example Import the client library
231+
* ```
231232
* const {PubSub} = require('@google-cloud/pubsub');
232233
*
233-
* @example <caption>Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:</caption>
234+
* ```
235+
* @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
236+
* ```
234237
* const pubsub = new PubSub();
235238
*
236-
* @example <caption>Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:</caption>
239+
* ```
240+
* @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
241+
* ```
237242
* const pubsub = new PubSub({
238243
* projectId: 'your-project-id',
239244
* keyFilename: '/path/to/keyfile.json'
240245
* });
241246
*
247+
* ```
242248
* @example <caption>include:samples/quickstart.js</caption>
243249
* region_tag:pubsub_quickstart_create_topic
244250
* Full quickstart example:
@@ -352,7 +358,8 @@ export class PubSub {
352358
* here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
353359
* @returns {Promise<Schema>}
354360
*
355-
* @example <caption>Create a schema.</caption>
361+
* @example Create a schema.
362+
* ```
356363
* const {PubSub} = require('@google-cloud/pubsub');
357364
* const pubsub = new PubSub();
358365
*
@@ -361,6 +368,7 @@ export class PubSub {
361368
* SchemaTypes.Avro,
362369
* '{...avro definition...}'
363370
* );
371+
* ```
364372
*/
365373
async createSchema(
366374
schemaId: string,
@@ -465,7 +473,8 @@ export class PubSub {
465473
* @param {CreateSubscriptionCallback} [callback] Callback function.
466474
* @returns {Promise<CreateSubscriptionResponse>}
467475
*
468-
* @example <caption>Subscribe to a topic.</caption>
476+
* @example Subscribe to a topic.
477+
* ```
469478
* const {PubSub} = require('@google-cloud/pubsub');
470479
* const pubsub = new PubSub();
471480
*
@@ -476,12 +485,15 @@ export class PubSub {
476485
*
477486
* pubsub.createSubscription(topic, name, callback);
478487
*
479-
* @example <caption>If the callback is omitted, we'll return a Promise.</caption>
488+
* ```
489+
* @example If the callback is omitted, we'll return a Promise.
490+
* ```
480491
* pubsub.createSubscription(topic, name)
481492
* .then(function(data) {
482493
* const subscription = data[0];
483494
* const apiResponse = data[1];
484495
* });
496+
* ```
485497
*/
486498
createSubscription(
487499
topic: Topic | string,
@@ -580,6 +592,7 @@ export class PubSub {
580592
* @returns {Promise<CreateTopicResponse>}
581593
*
582594
* @example
595+
* ```
583596
* const {PubSub} = require('@google-cloud/pubsub');
584597
* const pubsub = new PubSub();
585598
*
@@ -596,6 +609,7 @@ export class PubSub {
596609
* const topic = data[0];
597610
* const apiResponse = data[1];
598611
* });
612+
* ```
599613
*/
600614
createTopic(
601615
name: string | TopicMetadata,
@@ -658,6 +672,7 @@ export class PubSub {
658672
* @returns {Promise<DetachSubscriptionResponse>}
659673
*
660674
* @example
675+
* ```
661676
* const {PubSub} = require('@google-cloud/pubsub');
662677
* const pubsub = new PubSub();
663678
*
@@ -673,6 +688,7 @@ export class PubSub {
673688
* pubsub.detachSubscription('my-sub').then(data => {
674689
* const apiResponse = data[0];
675690
* });
691+
* ```
676692
*/
677693
detachSubscription(
678694
name: string,
@@ -786,9 +802,11 @@ export class PubSub {
786802
* @returns {AsyncIterable<ISchema>}
787803
*
788804
* @example
805+
* ```
789806
* for await (const s of pubsub.listSchemas()) {
790807
* const moreInfo = await s.get();
791808
* }
809+
* ```
792810
*/
793811
async *listSchemas(
794812
view: SchemaView = SchemaViews.Basic,
@@ -838,6 +856,7 @@ export class PubSub {
838856
* @returns {Promise<GetSnapshotsResponse>}
839857
*
840858
* @example
859+
* ```
841860
* const {PubSub} = require('@google-cloud/pubsub');
842861
* const pubsub = new PubSub();
843862
*
@@ -853,6 +872,7 @@ export class PubSub {
853872
* pubsub.getSnapshots().then(function(data) {
854873
* const snapshots = data[0];
855874
* });
875+
* ```
856876
*/
857877
getSnapshots(
858878
optsOrCallback?: PageOptions | GetSnapshotsCallback,
@@ -955,6 +975,7 @@ export class PubSub {
955975
* @returns {Promise<GetSubscriptionsResponse>}
956976
*
957977
* @example
978+
* ```
958979
* const {PubSub} = require('@google-cloud/pubsub');
959980
* const pubsub = new PubSub();
960981
*
@@ -970,6 +991,7 @@ export class PubSub {
970991
* pubsub.getSubscriptions().then(function(data) {
971992
* const subscriptions = data[0];
972993
* });
994+
* ```
973995
*/
974996
getSubscriptions(
975997
optsOrCallback?: GetSubscriptionsOptions | GetSubscriptionsCallback,
@@ -1066,6 +1088,7 @@ export class PubSub {
10661088
* @returns {Promise<GetTopicsResponse>}
10671089
*
10681090
* @example
1091+
* ```
10691092
* const {PubSub} = require('@google-cloud/pubsub');
10701093
* const pubsub = new PubSub();
10711094
*
@@ -1088,6 +1111,7 @@ export class PubSub {
10881111
* pubsub.getTopics().then(function(data) {
10891112
* const topics = data[0];
10901113
* });
1114+
* ```
10911115
*/
10921116
getTopics(
10931117
optsOrCallback?: PageOptions | GetTopicsCallback,
@@ -1291,10 +1315,12 @@ export class PubSub {
12911315
* @returns {Schema} A {@link Schema} instance.
12921316
*
12931317
* @example
1318+
* ```
12941319
* const {PubSub} = require('@google-cloud/pubsub');
12951320
* const pubsub = new PubSub();
12961321
*
12971322
* const schema = pubsub.schema('my-schema');
1323+
* ```
12981324
*/
12991325
schema(idOrName: string): Schema {
13001326
return new Schema(this, idOrName);
@@ -1310,10 +1336,12 @@ export class PubSub {
13101336
* @returns {Snapshot} A {@link Snapshot} instance.
13111337
*
13121338
* @example
1339+
* ```
13131340
* const {PubSub} = require('@google-cloud/pubsub');
13141341
* const pubsub = new PubSub();
13151342
*
13161343
* const snapshot = pubsub.snapshot('my-snapshot');
1344+
* ```
13171345
*/
13181346
snapshot(name: string): Snapshot {
13191347
if (typeof name !== 'string') {
@@ -1333,6 +1361,7 @@ export class PubSub {
13331361
* @returns {Subscription} A {@link Subscription} instance.
13341362
*
13351363
* @example
1364+
* ```
13361365
* const {PubSub} = require('@google-cloud/pubsub');
13371366
* const pubsub = new PubSub();
13381367
*
@@ -1347,6 +1376,7 @@ export class PubSub {
13471376
* // message.attributes = Attributes of the message.
13481377
* // message.publishTime = Date when Pub/Sub received the message.
13491378
* });
1379+
* ```
13501380
*/
13511381
subscription(name: string, options?: SubscriptionOptions): Subscription {
13521382
if (!name) {
@@ -1364,10 +1394,12 @@ export class PubSub {
13641394
* @returns {Topic} A {@link Topic} instance.
13651395
*
13661396
* @example
1397+
* ```
13671398
* const {PubSub} = require('@google-cloud/pubsub');
13681399
* const pubsub = new PubSub();
13691400
*
13701401
* const topic = pubsub.topic('my-topic');
1402+
* ```
13711403
*/
13721404
topic(name: string, options?: PublishOptions): Topic {
13731405
if (!name) {
@@ -1430,6 +1462,7 @@ export class PubSub {
14301462
* @returns {ReadableStream} A readable stream of {@link Snapshot} instances.
14311463
*
14321464
* @example
1465+
* ```
14331466
* const {PubSub} = require('@google-cloud/pubsub');
14341467
* const pubsub = new PubSub();
14351468
*
@@ -1450,6 +1483,7 @@ export class PubSub {
14501483
* .on('data', function(snapshot) {
14511484
* this.end();
14521485
* });
1486+
* ```
14531487
*/
14541488

14551489
/**
@@ -1462,6 +1496,7 @@ export class PubSub {
14621496
* @returns {ReadableStream} A readable stream of {@link Subscription} instances.
14631497
*
14641498
* @example
1499+
* ```
14651500
* const {PubSub} = require('@google-cloud/pubsub');
14661501
* const pubsub = new PubSub();
14671502
*
@@ -1482,6 +1517,7 @@ export class PubSub {
14821517
* .on('data', function(subscription) {
14831518
* this.end();
14841519
* });
1520+
* ```
14851521
*/
14861522

14871523
/**
@@ -1494,6 +1530,7 @@ export class PubSub {
14941530
* @returns {ReadableStream} A readable stream of {@link Topic} instances.
14951531
*
14961532
* @example
1533+
* ```
14971534
* const {PubSub} = require('@google-cloud/pubsub');
14981535
* const pubsub = new PubSub();
14991536
*
@@ -1514,6 +1551,7 @@ export class PubSub {
15141551
* .on('data', function(topic) {
15151552
* this.end();
15161553
* });
1554+
* ```
15171555
*/
15181556

15191557
/*! Developer Documentation

0 commit comments

Comments
 (0)