Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 5b30a33

Browse files
feat: support regapic LRO (#572)
* feat: support regapic LRO Use gapic-generator-typescript v2.15.1. PiperOrigin-RevId: 456946341 Source-Link: googleapis/googleapis@88fd18d Source-Link: https://github.com/googleapis/googleapis-gen/commit/accfa371f667439313335c64042b063c1c53102e 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 3ace414 commit 5b30a33

File tree

2 files changed

+80
-24
lines changed

2 files changed

+80
-24
lines changed

src/v1/cloud_redis_client.ts

+40-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,
@@ -86,7 +87,7 @@ export class CloudRedisClient {
8687
*
8788
* @param {object} [options] - The configuration object.
8889
* The options accepted by the constructor are described in detail
89-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
90+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
9091
* The common options are:
9192
* @param {object} [options.credentials] - Credentials object.
9293
* @param {string} [options.credentials.client_email]
@@ -109,11 +110,10 @@ export class CloudRedisClient {
109110
* API remote host.
110111
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
111112
* Follows the structure of {@link gapicConfig}.
112-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
113-
* In fallback mode, a special browser-compatible transport implementation is used
114-
* instead of gRPC transport. In browser context (if the `window` object is defined)
115-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
116-
* if you need to override this behavior.
113+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
114+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
115+
* For more information, please check the
116+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
117117
*/
118118
constructor(opts?: ClientOptions) {
119119
// Ensure that options include all the required fields.
@@ -200,16 +200,44 @@ export class CloudRedisClient {
200200
};
201201

202202
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
203-
204203
// This API contains "long-running operations", which return a
205204
// an Operation object that allows for tracking of the operation,
206205
// rather than holding a request open.
207-
206+
const lroOptions: GrpcClientOptions = {
207+
auth: this.auth,
208+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
209+
};
210+
if (opts.fallback === 'rest') {
211+
lroOptions.protoJson = protoFilesRoot;
212+
lroOptions.httpRules = [
213+
{
214+
selector: 'google.cloud.location.Locations.GetLocation',
215+
get: '/v1/{name=projects/*/locations/*}',
216+
},
217+
{
218+
selector: 'google.cloud.location.Locations.ListLocations',
219+
get: '/v1/{name=projects/*}/locations',
220+
},
221+
{
222+
selector: 'google.longrunning.Operations.CancelOperation',
223+
post: '/v1/{name=projects/*/locations/*/operations/*}:cancel',
224+
},
225+
{
226+
selector: 'google.longrunning.Operations.DeleteOperation',
227+
delete: '/v1/{name=projects/*/locations/*/operations/*}',
228+
},
229+
{
230+
selector: 'google.longrunning.Operations.GetOperation',
231+
get: '/v1/{name=projects/*/locations/*/operations/*}',
232+
},
233+
{
234+
selector: 'google.longrunning.Operations.ListOperations',
235+
get: '/v1/{name=projects/*/locations/*}/operations',
236+
},
237+
];
238+
}
208239
this.operationsClient = this._gaxModule
209-
.lro({
210-
auth: this.auth,
211-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
212-
})
240+
.lro(lroOptions)
213241
.operationsClient(opts);
214242
const createInstanceResponse = protoFilesRoot.lookup(
215243
'.google.cloud.redis.v1.Instance'

src/v1beta1/cloud_redis_client.ts

+40-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,
@@ -86,7 +87,7 @@ export class CloudRedisClient {
8687
*
8788
* @param {object} [options] - The configuration object.
8889
* The options accepted by the constructor are described in detail
89-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
90+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
9091
* The common options are:
9192
* @param {object} [options.credentials] - Credentials object.
9293
* @param {string} [options.credentials.client_email]
@@ -109,11 +110,10 @@ export class CloudRedisClient {
109110
* API remote host.
110111
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
111112
* Follows the structure of {@link gapicConfig}.
112-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
113-
* In fallback mode, a special browser-compatible transport implementation is used
114-
* instead of gRPC transport. In browser context (if the `window` object is defined)
115-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
116-
* if you need to override this behavior.
113+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
114+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
115+
* For more information, please check the
116+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
117117
*/
118118
constructor(opts?: ClientOptions) {
119119
// Ensure that options include all the required fields.
@@ -200,16 +200,44 @@ export class CloudRedisClient {
200200
};
201201

202202
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
203-
204203
// This API contains "long-running operations", which return a
205204
// an Operation object that allows for tracking of the operation,
206205
// rather than holding a request open.
207-
206+
const lroOptions: GrpcClientOptions = {
207+
auth: this.auth,
208+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
209+
};
210+
if (opts.fallback === 'rest') {
211+
lroOptions.protoJson = protoFilesRoot;
212+
lroOptions.httpRules = [
213+
{
214+
selector: 'google.cloud.location.Locations.GetLocation',
215+
get: '/v1beta1/{name=projects/*/locations/*}',
216+
},
217+
{
218+
selector: 'google.cloud.location.Locations.ListLocations',
219+
get: '/v1beta1/{name=projects/*}/locations',
220+
},
221+
{
222+
selector: 'google.longrunning.Operations.CancelOperation',
223+
post: '/v1beta1/{name=projects/*/locations/*/operations/*}:cancel',
224+
},
225+
{
226+
selector: 'google.longrunning.Operations.DeleteOperation',
227+
delete: '/v1beta1/{name=projects/*/locations/*/operations/*}',
228+
},
229+
{
230+
selector: 'google.longrunning.Operations.GetOperation',
231+
get: '/v1beta1/{name=projects/*/locations/*/operations/*}',
232+
},
233+
{
234+
selector: 'google.longrunning.Operations.ListOperations',
235+
get: '/v1beta1/{name=projects/*/locations/*}/operations',
236+
},
237+
];
238+
}
208239
this.operationsClient = this._gaxModule
209-
.lro({
210-
auth: this.auth,
211-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
212-
})
240+
.lro(lroOptions)
213241
.operationsClient(opts);
214242
const createInstanceResponse = protoFilesRoot.lookup(
215243
'.google.cloud.redis.v1beta1.Instance'

0 commit comments

Comments
 (0)