From 36a54bf3da307b891c0d0361bfe69b09d8dfeed8 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Wed, 17 Jan 2024 17:28:32 -0800 Subject: [PATCH 1/5] feat: expose uuid for autopopulation of request_id --- gax/package.json | 6 ++++-- gax/src/util.ts | 10 ++++++++++ gax/test/unit/util.ts | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gax/package.json b/gax/package.json index d005d1c81..0942ea231 100644 --- a/gax/package.json +++ b/gax/package.json @@ -13,6 +13,7 @@ "@grpc/grpc-js": "~1.9.6", "@grpc/proto-loader": "^0.7.0", "@types/long": "^4.0.0", + "@types/uuid": "^9.0.7", "abort-controller": "^3.0.0", "duplexify": "^4.0.0", "google-auth-library": "^9.0.0", @@ -20,11 +21,12 @@ "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", diff --git a/gax/src/util.ts b/gax/src/util.ts index 264dddd5d..382da4e15 100644 --- a/gax/src/util.ts +++ b/gax/src/util.ts @@ -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 +import {v4 as uuidv4} from 'uuid'; function words(str: string, normalize = false) { if (normalize) { @@ -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(); +} diff --git a/gax/test/unit/util.ts b/gax/test/unit/util.ts index 4b9879e28..614e1c06f 100644 --- a/gax/test/unit/util.ts +++ b/gax/test/unit/util.ts @@ -20,6 +20,7 @@ import { toCamelCase as snakeToCamelCase, camelToSnakeCase, toLowerCamelCase, + makeUUID, } from '../../src/util'; describe('util.ts', () => { @@ -79,4 +80,8 @@ describe('util.ts', () => { 'pascalCaseString' ); }); + + it('returns UUID', () => { + assert.match(makeUUID(), /[a-z0-9-]{36}/); + }); }); From 9a625b088e2d3080331cd45dafc494659fdf0a89 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Thu, 18 Jan 2024 11:10:40 -0800 Subject: [PATCH 2/5] respond to comments --- gax/package.json | 1 + gax/src/util.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/gax/package.json b/gax/package.json index 0942ea231..09712bedc 100644 --- a/gax/package.json +++ b/gax/package.json @@ -25,6 +25,7 @@ "uuid": "^9.0.1" }, "devDependencies": { + "@types/uuid": "^9.0.7", "@babel/plugin-proposal-private-methods": "^7.18.6", "@compodoc/compodoc": "1.1.23", "@types/mocha": "^9.0.0", diff --git a/gax/src/util.ts b/gax/src/util.ts index 382da4e15..8aab5e316 100644 --- a/gax/src/util.ts +++ b/gax/src/util.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// eslint-disable-next-line node/no-extraneous-import import {v4 as uuidv4} from 'uuid'; function words(str: string, normalize = false) { From 1959df8c790097fb5c60e78bbd47ff99566573f7 Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:40:04 -0800 Subject: [PATCH 3/5] Update package.json --- gax/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax/package.json b/gax/package.json index ca6adeba4..9a6666047 100644 --- a/gax/package.json +++ b/gax/package.json @@ -21,7 +21,7 @@ "object-hash": "^3.0.0", "proto3-json-serializer": "^2.0.0", "retry-request": "^7.0.0", - "uuid": "^9.0.1" + "uuid": "^9.0.1", "protobufjs": "7.2.6" }, "devDependencies": { From f3d6c810dfde96c3f0b9b7d2201878127ecd4e0c Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Thu, 18 Jan 2024 13:23:17 -0800 Subject: [PATCH 4/5] chore: export makeUUID --- gax/src/fallback.ts | 2 ++ gax/src/index.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/gax/src/fallback.ts b/gax/src/fallback.ts index cbc49dbff..8c6a8fa67 100644 --- a/gax/src/fallback.ts +++ b/gax/src/fallback.ts @@ -69,6 +69,8 @@ export {OperationsClient} from './operationsClient'; export {IamClient} from './iamService'; export {LocationsClient} from './locationService'; +export {makeUUID} from './util'; + export const defaultToObjectOptions = { keepCase: false, longs: String, diff --git a/gax/src/index.ts b/gax/src/index.ts index aca9bdfb0..2393ce798 100644 --- a/gax/src/index.ts +++ b/gax/src/index.ts @@ -107,6 +107,8 @@ export { PaginationResponse, } from './clientInterface'; +export {makeUUID} from './util'; + export {ServiceError, ChannelCredentials} from '@grpc/grpc-js'; export {warn} from './warnings'; From b33111f4a4397a22cf6be76665119a5a95114609 Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:14:45 -0800 Subject: [PATCH 5/5] Update package.json --- gax/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/gax/package.json b/gax/package.json index 9a6666047..eb1861c92 100644 --- a/gax/package.json +++ b/gax/package.json @@ -13,7 +13,6 @@ "@grpc/grpc-js": "~1.9.6", "@grpc/proto-loader": "^0.7.0", "@types/long": "^4.0.0", - "@types/uuid": "^9.0.7", "abort-controller": "^3.0.0", "duplexify": "^4.0.0", "google-auth-library": "^9.0.0",