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

feat: expose uuid for autopopulation of request_id #1542

Merged
merged 7 commits into from
Jan 18, 2024
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
6 changes: 4 additions & 2 deletions gax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
"@grpc/grpc-js": "~1.9.6",
"@grpc/proto-loader": "^0.7.0",
"@types/long": "^4.0.0",
"@types/uuid": "^9.0.7",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go to devDependencies unless there is a reason not to. @types/long is an exception, it's a dependency of the generated .d.ts files so we must list it as if it is a runtime dependency. Other types go to devDeps.

"abort-controller": "^3.0.0",
"duplexify": "^4.0.0",
"google-auth-library": "^9.0.0",
"node-fetch": "^2.6.1",
"object-hash": "^3.0.0",
"proto3-json-serializer": "^2.0.0",
"protobufjs": "7.2.5",
"retry-request": "^7.0.0"
"retry-request": "^7.0.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@compodoc/compodoc": "1.1.23",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@compodoc/compodoc": "1.1.23",
"@types/mocha": "^9.0.0",
"@types/ncp": "^2.0.1",
"@types/node": "^20.5.0",
Expand Down
10 changes: 10 additions & 0 deletions gax/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line node/no-extraneous-import
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 not extraneous?

import {v4 as uuidv4} from 'uuid';

function words(str: string, normalize = false) {
if (normalize) {
Expand Down Expand Up @@ -103,3 +105,11 @@ export function toLowerCamelCase(str: string) {
}
return camelCase[0].toLowerCase() + camelCase.slice(1);
}

/**
* Converts a given string to lower camel case (forcing the first character to be
* in lower case).
*/
export function makeUUID() {
return uuidv4();
}
5 changes: 5 additions & 0 deletions gax/test/unit/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
toCamelCase as snakeToCamelCase,
camelToSnakeCase,
toLowerCamelCase,
makeUUID,
} from '../../src/util';

describe('util.ts', () => {
Expand Down Expand Up @@ -79,4 +80,8 @@ describe('util.ts', () => {
'pascalCaseString'
);
});

it('returns UUID', () => {
assert.match(makeUUID(), /[a-z0-9-]{36}/);
});
});
Loading