Skip to content

Commit

Permalink
feat: expose uuid for autopopulation of request_id (#1542)
Browse files Browse the repository at this point in the history
* feat: expose uuid for autopopulation of request_id
  • Loading branch information
sofisl committed Jan 18, 2024
1 parent 36c1ce7 commit 6c66e22
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gax/package.json
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions gax/src/fallback.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions gax/src/index.ts
Expand Up @@ -107,6 +107,8 @@ export {
PaginationResponse,
} from './clientInterface';

export {makeUUID} from './util';

export {ServiceError, ChannelCredentials} from '@grpc/grpc-js';
export {warn} from './warnings';

Expand Down
9 changes: 9 additions & 0 deletions gax/src/util.ts
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
5 changes: 5 additions & 0 deletions gax/test/unit/util.ts
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}/);
});
});

0 comments on commit 6c66e22

Please sign in to comment.