Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

feat: add UUID autogeneration for fields listed as autoPopulate in service.yaml#1511

Merged
sofisl merged 40 commits intomainfrom
addUUID
Jan 31, 2024
Merged

feat: add UUID autogeneration for fields listed as autoPopulate in service.yaml#1511
sofisl merged 40 commits intomainfrom
addUUID

Conversation

@sofisl
Copy link
Contributor

@sofisl sofisl commented Jan 4, 2024

No description provided.

@sofisl sofisl requested a review from a team as a code owner January 4, 2024 03:49
@sofisl sofisl requested a review from a team January 4, 2024 03:49
@sofisl
Copy link
Contributor Author

sofisl commented Jan 9, 2024

@alexander-fenster, I think the failing tests are due to gapic-tools not recognizing the field_info.proto. Once we publish a new version of gax with the new version of nodejs-proto-files, I can also update gapic-tools and I think it will just work.

@alexander-fenster
Copy link
Contributor

Let me review this after #1503 gets in.


import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
import * as crypto from 'crypto';
Copy link
Contributor

Choose a reason for hiding this comment

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

This immediately disqualifies the library from the browser or any other non-Node.js usage. One way to solve this would be to move everything that needs crypto to google-gax and export it from there, and in gax, make it similar to https://github.com/googleapis/google-auth-library-nodejs/tree/main/src/crypto to use either Node.js crypto or window.crypto.subtle, whichever is available.

Also, I don't see any crypto usage in this particular file, which probably means that this import should be conditional.

]>|void {
request = request || {};
{% for field in method.autoPopulatedFields %}if (!request.{{ field.toCamelCase() }}) {
request.{{ field.toCamelCase() }} = crypto.randomUUID();
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it compatible with browser, we have two options: either use uuid module instead of crypto (which will force us make uuid a dependency for all libraries), or - probably better - export a createUUID() function from gax, and have it there instead.


export interface ServiceDescriptorProto
extends protos.google.protobuf.IServiceDescriptorProto {
getAutoPopulatedFields: MethodDescriptorProto[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this field actually used anywhere? I see the function getAutoPopulatedFields but I don't see if this added field is accessed anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

REmoved!

]>|void {
request = request || {};
if (!request.requestId) {
request.requestId = gax.makeUUID();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a generated unit test that would check that this code is actually executed? It would be similar to an existing test that makes a request, but in a stub, it can check that the field was indeed assigned to some UUID. Similar to

.

@sofisl sofisl merged commit e731e91 into main Jan 31, 2024
@sofisl sofisl deleted the addUUID branch January 31, 2024 19:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants