diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b277120..d5981c755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ [1]: https://www.npmjs.com/package/@google-cloud/pubsub?activeTab=versions +## [3.7.3](https://github.com/googleapis/nodejs-pubsub/compare/v3.7.2...v3.7.3) (2023-07-26) + + +### Bug Fixes + +* Update masks for topic should be snake case ([#1778](https://github.com/googleapis/nodejs-pubsub/issues/1778)) ([ba72638](https://github.com/googleapis/nodejs-pubsub/commit/ba7263836e6951454f77f631c9d2eb0a4df98da5)) + ## [3.7.2](https://github.com/googleapis/nodejs-pubsub/compare/v3.7.1...v3.7.2) (2023-07-24) diff --git a/package.json b/package.json index 1983860f8..9da69f11f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@google-cloud/pubsub", "description": "Cloud Pub/Sub Client Library for Node.js", - "version": "3.7.2", + "version": "3.7.3", "license": "Apache-2.0", "author": "Google Inc.", "engines": { diff --git a/protos/google/pubsub/v1/pubsub.proto b/protos/google/pubsub/v1/pubsub.proto index 9ff80f2f6..4468de178 100644 --- a/protos/google/pubsub/v1/pubsub.proto +++ b/protos/google/pubsub/v1/pubsub.proto @@ -1030,7 +1030,11 @@ message CloudStorageConfig { // Message payloads and metadata will be written to files as an Avro binary. message AvroConfig { // When true, write the subscription name, message_id, publish_time, - // attributes, and ordering_key as additional fields in the output. + // attributes, and ordering_key as additional fields in the output. The + // subscription name, message_id, and publish_time fields are put in their + // own fields while all other message properties other than data (for + // example, an ordering_key, if present) are added as entries in the + // attributes map. bool write_metadata = 1; } diff --git a/samples/package.json b/samples/package.json index 17d22cc10..62c162c7b 100644 --- a/samples/package.json +++ b/samples/package.json @@ -21,7 +21,7 @@ "precompile": "npm run clean" }, "dependencies": { - "@google-cloud/pubsub": "^3.7.2", + "@google-cloud/pubsub": "^3.7.3", "@opentelemetry/api": "^1.0.0", "@opentelemetry/tracing": "^0.24.0", "avro-js": "^1.10.1", diff --git a/src/topic.ts b/src/topic.ts index 03a54c37c..96b33490e 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -48,6 +48,7 @@ import { SubscriptionOptions, } from './subscription'; import {promisifySome} from './util'; +import snakeCase = require('lodash.snakecase'); export type TopicMetadata = google.pubsub.v1.ITopic; @@ -951,7 +952,7 @@ export class Topic { callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const topic = Object.assign({name: this.name}, options); - const updateMask = {paths: Object.keys(options)}; + const updateMask = {paths: Object.keys(options).map(snakeCase)}; const reqOpts = {topic, updateMask}; this.request( diff --git a/system-test/pubsub.ts b/system-test/pubsub.ts index eab472ca8..4301292aa 100644 --- a/system-test/pubsub.ts +++ b/system-test/pubsub.ts @@ -307,6 +307,22 @@ describe('pubsub', () => { ); }); + it('should set metadata for a topic', async () => { + const threeDaysInSeconds = 3 * 24 * 60 * 60; + + const topic = pubsub.topic(TOPIC_NAMES[0]); + await topic.setMetadata({ + messageRetentionDuration: { + seconds: threeDaysInSeconds, + }, + }); + const [metadata] = await topic.getMetadata(); + const {seconds, nanos} = metadata.messageRetentionDuration!; + + assert.strictEqual(Number(seconds), threeDaysInSeconds); + assert.strictEqual(Number(nanos), 0); + }); + describe('ordered messages', () => { interface Expected { key: string; diff --git a/test/topic.ts b/test/topic.ts index bbd0aa2df..1179c718b 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -671,6 +671,7 @@ describe('Topic', () => { describe('setMetadata', () => { const METADATA = { labels: {yee: 'haw'}, + messageRetentionDuration: {moo: 'cows'}, }; let requestStub: sinon.SinonStub; @@ -691,7 +692,9 @@ describe('Topic', () => { topic.setMetadata(METADATA, assert.ifError); const expectedTopic = Object.assign({name: topic.name}, METADATA); - const expectedUpdateMask = {paths: ['labels']}; + const expectedUpdateMask = { + paths: ['labels', 'message_retention_duration'], + }; const [{reqOpts}] = requestStub.lastCall.args; assert.deepStrictEqual(reqOpts.topic, expectedTopic);