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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions gax/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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}/);
});
});