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

Commit b433238

Browse files
feat: support regapic LRO (#98)
* 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 3dcf6a7 commit b433238

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

src/v1/service_usage_client.ts

Lines changed: 24 additions & 12 deletions
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,
@@ -75,7 +76,7 @@ export class ServiceUsageClient {
7576
*
7677
* @param {object} [options] - The configuration object.
7778
* The options accepted by the constructor are described in detail
78-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
79+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7980
* The common options are:
8081
* @param {object} [options.credentials] - Credentials object.
8182
* @param {string} [options.credentials.client_email]
@@ -98,11 +99,10 @@ export class ServiceUsageClient {
9899
* API remote host.
99100
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
100101
* Follows the structure of {@link gapicConfig}.
101-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
102-
* In fallback mode, a special browser-compatible transport implementation is used
103-
* instead of gRPC transport. In browser context (if the `window` object is defined)
104-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
105-
* if you need to override this behavior.
102+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
103+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
104+
* For more information, please check the
105+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
106106
*/
107107
constructor(opts?: ClientOptions) {
108108
// Ensure that options include all the required fields.
@@ -177,16 +177,28 @@ export class ServiceUsageClient {
177177
};
178178

179179
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
180-
181180
// This API contains "long-running operations", which return a
182181
// an Operation object that allows for tracking of the operation,
183182
// rather than holding a request open.
184-
183+
const lroOptions: GrpcClientOptions = {
184+
auth: this.auth,
185+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
186+
};
187+
if (opts.fallback === 'rest') {
188+
lroOptions.protoJson = protoFilesRoot;
189+
lroOptions.httpRules = [
190+
{
191+
selector: 'google.longrunning.Operations.GetOperation',
192+
get: '/v1/{name=operations/*}',
193+
},
194+
{
195+
selector: 'google.longrunning.Operations.ListOperations',
196+
get: '/v1/operations',
197+
},
198+
];
199+
}
185200
this.operationsClient = this._gaxModule
186-
.lro({
187-
auth: this.auth,
188-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
189-
})
201+
.lro(lroOptions)
190202
.operationsClient(opts);
191203
const enableServiceResponse = protoFilesRoot.lookup(
192204
'.google.api.serviceusage.v1.EnableServiceResponse'

src/v1beta1/service_usage_client.ts

Lines changed: 24 additions & 12 deletions
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,
@@ -71,7 +72,7 @@ export class ServiceUsageClient {
7172
*
7273
* @param {object} [options] - The configuration object.
7374
* The options accepted by the constructor are described in detail
74-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
75+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7576
* The common options are:
7677
* @param {object} [options.credentials] - Credentials object.
7778
* @param {string} [options.credentials.client_email]
@@ -94,11 +95,10 @@ export class ServiceUsageClient {
9495
* API remote host.
9596
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
9697
* Follows the structure of {@link gapicConfig}.
97-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
98-
* In fallback mode, a special browser-compatible transport implementation is used
99-
* instead of gRPC transport. In browser context (if the `window` object is defined)
100-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
101-
* if you need to override this behavior.
98+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
99+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
100+
* For more information, please check the
101+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
102102
*/
103103
constructor(opts?: ClientOptions) {
104104
// Ensure that options include all the required fields.
@@ -188,16 +188,28 @@ export class ServiceUsageClient {
188188
};
189189

190190
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
191-
192191
// This API contains "long-running operations", which return a
193192
// an Operation object that allows for tracking of the operation,
194193
// rather than holding a request open.
195-
194+
const lroOptions: GrpcClientOptions = {
195+
auth: this.auth,
196+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
197+
};
198+
if (opts.fallback === 'rest') {
199+
lroOptions.protoJson = protoFilesRoot;
200+
lroOptions.httpRules = [
201+
{
202+
selector: 'google.longrunning.Operations.GetOperation',
203+
get: '/v1beta1/{name=operations/*}',
204+
},
205+
{
206+
selector: 'google.longrunning.Operations.ListOperations',
207+
get: '/v1beta1/operations',
208+
},
209+
];
210+
}
196211
this.operationsClient = this._gaxModule
197-
.lro({
198-
auth: this.auth,
199-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
200-
})
212+
.lro(lroOptions)
201213
.operationsClient(opts);
202214
const enableServiceResponse = protoFilesRoot.lookup(
203215
'.google.protobuf.Empty'

0 commit comments

Comments
 (0)