Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update masks for topic should be snake case #1778

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"google-gax": "^3.6.1",
"heap-js": "^2.2.0",
"is-stream-ended": "^0.1.4",
"lodash.snakecase": "^4.1.1",
"p-defer": "^3.0.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import {EventEmitter} from 'events';
import * as extend from 'extend';
import {CallOptions} from 'google-gax';
import snakeCase = require('lodash.snakecase');

import {google} from '../protos/protos';

Expand All @@ -44,7 +43,7 @@ import {
} from './snapshot';
import {Subscriber, SubscriberOptions} from './subscriber';
import {Topic} from './topic';
import {promisifySome} from './util';
import {camelToSnake, promisifySome} from './util';

export {AckError, AckResponse, AckResponses} from './subscriber';

Expand Down Expand Up @@ -1100,7 +1099,7 @@ export class Subscription extends EventEmitter {
callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;

const subscription = Subscription.formatMetadata_(metadata);
const fields = Object.keys(subscription).map(snakeCase);
const fields = Object.keys(subscription).map(camelToSnake);
subscription.name = this.name;
const reqOpts = {
subscription,
Expand Down
4 changes: 2 additions & 2 deletions src/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
Subscription,
SubscriptionOptions,
} from './subscription';
import {promisifySome} from './util';
import {camelToSnake, promisifySome} from './util';

export type TopicMetadata = google.pubsub.v1.ITopic;

Expand Down Expand Up @@ -951,7 +951,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(camelToSnake)};
const reqOpts = {topic, updateMask};

this.request<TopicMetadata>(
Expand Down
9 changes: 9 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ export function addToBucket<T, U>(map: Map<T, U[]>, bucket: T, item: U) {
items.push(item);
map.set(bucket, items);
}

/**
* Converts a string from camelCase to snake_case.
*
* @private
*/
export function camelToSnake(input: string): string {
return input.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to double check what should happen with numbers. E. g. abc360Value - should it be abc_360_value or abc360_value? Ask me why I care :)

Copy link

@leahecole leahecole Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I brought up in a 1-1 chat that I want to see a test so this would be a good test case too 😁

}