diff --git a/gax/package.json b/gax/package.json index b56988abb..eb1861c92 100644 --- a/gax/package.json +++ b/gax/package.json @@ -19,12 +19,14 @@ "node-fetch": "^2.6.1", "object-hash": "^3.0.0", "proto3-json-serializer": "^2.0.0", - "protobufjs": "7.2.6", - "retry-request": "^7.0.0" + "retry-request": "^7.0.0", + "uuid": "^9.0.1", + "protobufjs": "7.2.6" }, "devDependencies": { - "@compodoc/compodoc": "1.1.23", + "@types/uuid": "^9.0.7", "@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/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'; diff --git a/gax/src/util.ts b/gax/src/util.ts index 264dddd5d..8aab5e316 100644 --- a/gax/src/util.ts +++ b/gax/src/util.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import {v4 as uuidv4} from 'uuid'; function words(str: string, normalize = false) { if (normalize) { @@ -103,3 +104,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}/); + }); });