Skip to content

Commit d2e953c

Browse files
feat: support regapic LRO (#798)
* feat: support regapic LRO Use gapic-generator-typescript v2.15.1. PiperOrigin-RevId: 456946341 Source-Link: googleapis/googleapis@88fd18d Source-Link: googleapis/googleapis-gen@accfa37 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWNjZmEzNzFmNjY3NDM5MzEzMzM1YzY0MDQyYjA2M2MxYzUzMTAyZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent c8c5588 commit d2e953c

File tree

2 files changed

+92
-24
lines changed

2 files changed

+92
-24
lines changed

packages/google-cloud-translate/src/v3/translation_service_client.ts

+46-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
26+
GrpcClientOptions,
2627
LROperation,
2728
PaginationCallback,
2829
GaxCall,
@@ -72,7 +73,7 @@ export class TranslationServiceClient {
7273
*
7374
* @param {object} [options] - The configuration object.
7475
* The options accepted by the constructor are described in detail
75-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
76+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7677
* The common options are:
7778
* @param {object} [options.credentials] - Credentials object.
7879
* @param {string} [options.credentials.client_email]
@@ -95,11 +96,10 @@ export class TranslationServiceClient {
9596
* API remote host.
9697
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
9798
* Follows the structure of {@link gapicConfig}.
98-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
99-
* In fallback mode, a special browser-compatible transport implementation is used
100-
* instead of gRPC transport. In browser context (if the `window` object is defined)
101-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
102-
* if you need to override this behavior.
99+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
100+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
101+
* For more information, please check the
102+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
103103
*/
104104
constructor(opts?: ClientOptions) {
105105
// Ensure that options include all the required fields.
@@ -186,16 +186,50 @@ export class TranslationServiceClient {
186186
};
187187

188188
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
189-
190189
// This API contains "long-running operations", which return a
191190
// an Operation object that allows for tracking of the operation,
192191
// rather than holding a request open.
193-
192+
const lroOptions: GrpcClientOptions = {
193+
auth: this.auth,
194+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
195+
};
196+
if (opts.fallback === 'rest') {
197+
lroOptions.protoJson = protoFilesRoot;
198+
lroOptions.httpRules = [
199+
{
200+
selector: 'google.cloud.location.Locations.GetLocation',
201+
get: '/v3/{name=projects/*/locations/*}',
202+
},
203+
{
204+
selector: 'google.cloud.location.Locations.ListLocations',
205+
get: '/v3/{name=projects/*}/locations',
206+
},
207+
{
208+
selector: 'google.longrunning.Operations.CancelOperation',
209+
post: '/v3/{name=projects/*/locations/*/operations/*}:cancel',
210+
body: '*',
211+
},
212+
{
213+
selector: 'google.longrunning.Operations.DeleteOperation',
214+
delete: '/v3/{name=projects/*/locations/*/operations/*}',
215+
},
216+
{
217+
selector: 'google.longrunning.Operations.GetOperation',
218+
get: '/v3/{name=projects/*/locations/*/operations/*}',
219+
},
220+
{
221+
selector: 'google.longrunning.Operations.ListOperations',
222+
get: '/v3/{name=projects/*/locations/*}/operations',
223+
},
224+
{
225+
selector: 'google.longrunning.Operations.WaitOperation',
226+
post: '/v3/{name=projects/*/locations/*/operations/*}:wait',
227+
body: '*',
228+
},
229+
];
230+
}
194231
this.operationsClient = this._gaxModule
195-
.lro({
196-
auth: this.auth,
197-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
198-
})
232+
.lro(lroOptions)
199233
.operationsClient(opts);
200234
const batchTranslateTextResponse = protoFilesRoot.lookup(
201235
'.google.cloud.translation.v3.BatchTranslateResponse'

packages/google-cloud-translate/src/v3beta1/translation_service_client.ts

+46-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
26+
GrpcClientOptions,
2627
LROperation,
2728
PaginationCallback,
2829
GaxCall,
@@ -72,7 +73,7 @@ export class TranslationServiceClient {
7273
*
7374
* @param {object} [options] - The configuration object.
7475
* The options accepted by the constructor are described in detail
75-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
76+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7677
* The common options are:
7778
* @param {object} [options.credentials] - Credentials object.
7879
* @param {string} [options.credentials.client_email]
@@ -95,11 +96,10 @@ export class TranslationServiceClient {
9596
* API remote host.
9697
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
9798
* Follows the structure of {@link gapicConfig}.
98-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
99-
* In fallback mode, a special browser-compatible transport implementation is used
100-
* instead of gRPC transport. In browser context (if the `window` object is defined)
101-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
102-
* if you need to override this behavior.
99+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
100+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
101+
* For more information, please check the
102+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
103103
*/
104104
constructor(opts?: ClientOptions) {
105105
// Ensure that options include all the required fields.
@@ -186,16 +186,50 @@ export class TranslationServiceClient {
186186
};
187187

188188
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
189-
190189
// This API contains "long-running operations", which return a
191190
// an Operation object that allows for tracking of the operation,
192191
// rather than holding a request open.
193-
192+
const lroOptions: GrpcClientOptions = {
193+
auth: this.auth,
194+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
195+
};
196+
if (opts.fallback === 'rest') {
197+
lroOptions.protoJson = protoFilesRoot;
198+
lroOptions.httpRules = [
199+
{
200+
selector: 'google.cloud.location.Locations.GetLocation',
201+
get: '/v3beta1/{name=projects/*/locations/*}',
202+
},
203+
{
204+
selector: 'google.cloud.location.Locations.ListLocations',
205+
get: '/v3beta1/{name=projects/*}/locations',
206+
},
207+
{
208+
selector: 'google.longrunning.Operations.CancelOperation',
209+
post: '/v3beta1/{name=projects/*/locations/*/operations/*}:cancel',
210+
body: '*',
211+
},
212+
{
213+
selector: 'google.longrunning.Operations.DeleteOperation',
214+
delete: '/v3beta1/{name=projects/*/locations/*/operations/*}',
215+
},
216+
{
217+
selector: 'google.longrunning.Operations.GetOperation',
218+
get: '/v3beta1/{name=projects/*/locations/*/operations/*}',
219+
},
220+
{
221+
selector: 'google.longrunning.Operations.ListOperations',
222+
get: '/v3beta1/{name=projects/*/locations/*}/operations',
223+
},
224+
{
225+
selector: 'google.longrunning.Operations.WaitOperation',
226+
post: '/v3beta1/{name=projects/*/locations/*/operations/*}:wait',
227+
body: '*',
228+
},
229+
];
230+
}
194231
this.operationsClient = this._gaxModule
195-
.lro({
196-
auth: this.auth,
197-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
198-
})
232+
.lro(lroOptions)
199233
.operationsClient(opts);
200234
const batchTranslateTextResponse = protoFilesRoot.lookup(
201235
'.google.cloud.translation.v3beta1.BatchTranslateResponse'

0 commit comments

Comments
 (0)