chore: migrate google-cloud-speech to librarian#8635
Conversation
There was a problem hiding this comment.
Code Review
This pull request transitions the library to a fully auto-generated client by removing the custom "streamingRecognize" helper, its associated tests, and updating the metadata and entry point. The reviewer notes that manual edits to generated TypeScript client files should be avoided, and any custom helpers should be restored upstream in the generator.
| // ** This file is automatically generated by synthtool. ** | ||
| // ** https://github.com/googleapis/synthtool ** | ||
| // ** All changes to this file may be overwritten. ** | ||
|
|
||
| import {ImprovedStreamingClient} from './helpers'; | ||
| import * as v1p1beta1 from './v1p1beta1'; | ||
| import * as v1 from './v1'; | ||
| import * as v1p1beta1 from './v1p1beta1'; | ||
| import * as v2 from './v2'; | ||
|
|
||
| // The following code is adapted from http://www.typescriptlang.org/docs/handbook/mixins.html | ||
| // tslint:disable-next-line no-any | ||
| Object.defineProperty( | ||
| v1.SpeechClient.prototype, | ||
| 'streamingRecognize', | ||
| Object.getOwnPropertyDescriptor( | ||
| ImprovedStreamingClient.prototype, | ||
| 'streamingRecognize' | ||
| )! | ||
| ); | ||
| Object.defineProperty( | ||
| v1p1beta1.SpeechClient.prototype, | ||
| 'streamingRecognize', | ||
| Object.getOwnPropertyDescriptor( | ||
| ImprovedStreamingClient.prototype, | ||
| 'streamingRecognize' | ||
| )! | ||
| ); | ||
| Object.defineProperty( | ||
| v2.SpeechClient.prototype, | ||
| 'streamingRecognize', | ||
| Object.getOwnPropertyDescriptor( | ||
| ImprovedStreamingClient.prototype, | ||
| 'streamingRecognize' | ||
| )! | ||
| ); |
There was a problem hiding this comment.
Do not manually edit generated TypeScript client files. Any changes or updates must be made upstream in the generator. If the custom streamingRecognize helper (previously in helpers.ts) needs to be restored, please ensure this is handled upstream in the generator rather than manually editing the files in this repository.
References
- Do not manually edit generated TypeScript client files. Any changes or updates must be made upstream in the generator.
|
@pearigee and I were debugging the test failures, and we found that this code is being post-processed in by librarian.js. Additionally, the imports in the index file need to be updated to account for the deleted files. |
|
I enriched the pull request description. Let me see a way to avoid user-facing changes. |
suztomo
left a comment
There was a problem hiding this comment.
Adding "Request changes" while I investigate this.
|
With updated keep list: #8648 |
This PR migrates the
google-cloud-speechpackage to use Librarian for code generation.Highlights
Enabled Librarian generation for
google-cloud-speechby removingskip_generate: trueinlibrarian.yaml.Removed OwlBot configuration (
.OwlBot.yaml).Updated
.repo-metadata.json(updated description, documentation links).Removed obsolete test/source files:
packages/google-cloud-speech/src/helpers.ts: The customstreamingRecognizehelper.packages/google-cloud-speech/test/helpers.test.ts: Tests for the custom helper.packages/google-cloud-speech/system-test/*: Legacy system tests.Why are these helper and test files obsolete?
The customstreamingRecognizehelper inhelpers.tswas originally added to provide a better user experience for streaming (e.g., accepting raw audio and wrapping it). However, we are moving towards fully auto-generated clients to ensure consistency and reduce maintenance overhead. The associated tests (helpers.test.tsand legacy system tests) are removed as they target the deleted helper.Prior to this migration, OwlBot copied files from the Bazel-generated assembly package speech-v1-nodejs which included all dependencies. Librarian is more precise and only copies/keeps the protos defined for the API or transitively imported by them (resolved via
*_proto_list.jsongenerated during GAPIC generation), and filters out common protos that are already provided bygoogle-gax. This is handled by copyMissingProtos in Librarian.User-facing Changes (Questionable)
Warning
Breaking Change
The custom
streamingRecognizehelper has been removed. This helper was previously exposed to users by being mixed into theSpeechClientprototype. Users must now use the default generatedstreamingRecognizemethod.Detail of breaking changes and migration path
What changed?
Previously, the custom helper was mixed into
SpeechClient.prototype.streamingRecognizeat runtime. It wrapped the raw gRPC stream to provide a more convenient API:streamingConfigas the first argument tostreamingRecognize(config).write()orpipe()) and automatically wrapped them intoStreamingRecognizeRequestobjects ({audioContent: buffer}).With the removal of the helper, users now interact directly with the raw generated gRPC stream.
Migration Path
Before (with helper):
After (without helper):
You must now write
StreamingRecognizeRequestobjects. The first write must contain the configuration, and subsequent writes must contain the audio content. You can no longer pipe raw audio streams directly without a transform.Fixes needed (for reviewers/author)
packages/google-cloud-speech/librarian.js: This file is still present and is trying to post-process the generated files by importing./helpers(which was deleted). This is causing compilation/test failures.librarian.js, the code should be regenerated to remove the appended helper imports from:packages/google-cloud-speech/src/v1/speech_client.tspackages/google-cloud-speech/src/v1p1beta1/speech_client.tspackages/google-cloud-speech/src/v2/speech_client.ts