Skip to content

Commit

Permalink
feat: support regapic LRO (#1729)
Browse files Browse the repository at this point in the history
* fix: fixes for dynamic routing and streaming descriptors

Use gapic-generator-typescript v2.14.5.

PiperOrigin-RevId: 450616838

Source-Link: googleapis/googleapis@7a47b72

Source-Link: googleapis/googleapis-gen@42cc633
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDJjYzYzMzFiYWUwYjk5ZjYxYjhlMDFhZTE1YjA1MjExNzE2YzRmOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* chore: expose new TTL / Database Admin experimental API

PiperOrigin-RevId: 451252826

Source-Link: googleapis/googleapis@dea7c80

Source-Link: googleapis/googleapis-gen@ac376d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWMzNzZkMDVjYjI4MDhlZTI2ZDQ1ZTJjM2EyMGY2ZmQ4NTJlNjc2ZCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* feat: expose read_time fields in Firestore PartitionQuery and ListCollectionIds, currently only available in private preview

PiperOrigin-RevId: 453719952

Source-Link: googleapis/googleapis@bdea286

Source-Link: googleapis/googleapis-gen@03f0c73
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDNmMGM3M2EyYTljMDY0ZTZmNDk5MzU5ZmY0ZWQwNWUxODc2Mjc0MSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 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>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
Co-authored-by: Alexander Fenster <fenster@google.com>
  • Loading branch information
4 people committed Jul 1, 2022
1 parent 07de28a commit b9d8fef
Show file tree
Hide file tree
Showing 6 changed files with 892 additions and 53 deletions.
307 changes: 295 additions & 12 deletions dev/src/v1/firestore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import {
CallOptions,
Descriptors,
ClientOptions,
GrpcClientOptions,
LROperation,
PaginationCallback,
GaxCall,
LocationsClient,
LocationProtos,
} from 'google-gax';

import {Transform} from 'stream';
Expand Down Expand Up @@ -90,6 +93,7 @@ export class FirestoreAdminClient {
};
warn: (code: string, message: string, warnType?: string) => void;
innerApiCalls: {[name: string]: Function};
locationsClient: LocationsClient;
pathTemplates: {[name: string]: gax.PathTemplate};
operationsClient: gax.OperationsClient;
firestoreAdminStub?: Promise<{[name: string]: Function}>;
Expand All @@ -99,7 +103,7 @@ export class FirestoreAdminClient {
*
* @param {object} [options] - The configuration object.
* The options accepted by the constructor are described in detail
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
* The common options are:
* @param {object} [options.credentials] - Credentials object.
* @param {string} [options.credentials.client_email]
Expand All @@ -122,11 +126,10 @@ export class FirestoreAdminClient {
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
* if you need to override this behavior.
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
*/
constructor(opts?: ClientOptions) {
// Ensure that options include all the required fields.
Expand Down Expand Up @@ -170,6 +173,7 @@ export class FirestoreAdminClient {
if (servicePath === staticMembers.servicePath) {
this.auth.defaultScopes = staticMembers.scopes;
}
this.locationsClient = new LocationsClient(this._gaxGrpc, opts);

// Determine the client header string.
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
Expand Down Expand Up @@ -227,16 +231,37 @@ export class FirestoreAdminClient {
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// This API contains "long-running operations", which return a
// an Operation object that allows for tracking of the operation,
// rather than holding a request open.

const lroOptions: GrpcClientOptions = {
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
};
if (opts.fallback === 'rest') {
lroOptions.protoJson = protoFilesRoot;
lroOptions.httpRules = [
{
selector: 'google.longrunning.Operations.CancelOperation',
post: '/v1/{name=projects/*/databases/*/operations/*}:cancel',
body: '*',
},
{
selector: 'google.longrunning.Operations.DeleteOperation',
delete: '/v1/{name=projects/*/databases/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.GetOperation',
get: '/v1/{name=projects/*/databases/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.ListOperations',
get: '/v1/{name=projects/*/databases/*}/operations',
},
];
}
this.operationsClient = this._gaxModule
.lro({
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
})
.lro(lroOptions)
.operationsClient(opts);
const createIndexResponse = protoFilesRoot.lookup(
'.google.firestore.admin.v1.Index'
Expand Down Expand Up @@ -2030,6 +2055,263 @@ export class FirestoreAdminClient {
callSettings
) as AsyncIterable<protos.google.firestore.admin.v1.IField>;
}
/**
* Gets information about a location.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.name
* Resource name for the location.
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Location]{@link google.cloud.location.Location}.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* ```
* const [response] = await client.getLocation(request);
* ```
*/
getLocation(
request: LocationProtos.google.cloud.location.IGetLocationRequest,
options?:
| gax.CallOptions
| Callback<
LocationProtos.google.cloud.location.ILocation,
| LocationProtos.google.cloud.location.IGetLocationRequest
| null
| undefined,
{} | null | undefined
>,
callback?: Callback<
LocationProtos.google.cloud.location.ILocation,
| LocationProtos.google.cloud.location.IGetLocationRequest
| null
| undefined,
{} | null | undefined
>
): Promise<LocationProtos.google.cloud.location.ILocation> {
return this.locationsClient.getLocation(request, options, callback);
}

/**
* Lists information about the supported locations for this service. Returns an iterable object.
*
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
* @param {Object} request
* The request object that will be sent.
* @param {string} request.name
* The resource that owns the locations collection, if applicable.
* @param {string} request.filter
* The standard list filter.
* @param {number} request.pageSize
* The standard list page size.
* @param {string} request.pageToken
* The standard list page token.
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Object}
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
* When you iterate the returned iterable, each element will be an object representing
* [Location]{@link google.cloud.location.Location}. The API will be called under the hood as needed, once per the page,
* so you can stop the iteration when you don't need more results.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
* for more details and examples.
* @example
* ```
* const iterable = client.listLocationsAsync(request);
* for await (const response of iterable) {
* // process response
* }
* ```
*/
listLocationsAsync(
request: LocationProtos.google.cloud.location.IListLocationsRequest,
options?: CallOptions
): AsyncIterable<LocationProtos.google.cloud.location.ILocation> {
return this.locationsClient.listLocationsAsync(request, options);
}

/**
* Gets the latest state of a long-running operation. Clients can use this
* method to poll the operation result at intervals as recommended by the API
* service.
*
* @param {Object} request - The request object that will be sent.
* @param {string} request.name - The name of the operation resource.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call,
* e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
* https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
* details.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing
* [google.longrunning.Operation]{@link
* external:"google.longrunning.Operation"}.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing
* [google.longrunning.Operation]{@link
* external:"google.longrunning.Operation"}. The promise has a method named
* "cancel" which cancels the ongoing API call.
*
* @example
* ```
* const client = longrunning.operationsClient();
* const name = '';
* const [response] = await client.getOperation({name});
* // doThingsWith(response)
* ```
*/
getOperation(
request: protos.google.longrunning.GetOperationRequest,
options?:
| gax.CallOptions
| Callback<
protos.google.longrunning.Operation,
protos.google.longrunning.GetOperationRequest,
{} | null | undefined
>,
callback?: Callback<
protos.google.longrunning.Operation,
protos.google.longrunning.GetOperationRequest,
{} | null | undefined
>
): Promise<[protos.google.longrunning.Operation]> {
return this.operationsClient.getOperation(request, options, callback);
}
/**
* Lists operations that match the specified filter in the request. If the
* server doesn't support this method, it returns `UNIMPLEMENTED`. Returns an iterable object.
*
* For-await-of syntax is used with the iterable to recursively get response element on-demand.
*
* @param {Object} request - The request object that will be sent.
* @param {string} request.name - The name of the operation collection.
* @param {string} request.filter - The standard list filter.
* @param {number=} request.pageSize -
* The maximum number of resources contained in the underlying API
* response. If page streaming is performed per-resource, this
* parameter does not affect the return value. If page streaming is
* performed per-page, this determines the maximum number of
* resources in a page.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call,
* e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
* https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
* details.
* @returns {Object}
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
*
* @example
* ```
* const client = longrunning.operationsClient();
* for await (const response of client.listOperationsAsync(request));
* // doThingsWith(response)
* ```
*/
listOperationsAsync(
request: protos.google.longrunning.ListOperationsRequest,
options?: gax.CallOptions
): AsyncIterable<protos.google.longrunning.ListOperationsResponse> {
return this.operationsClient.listOperationsAsync(request, options);
}
/**
* Starts asynchronous cancellation on a long-running operation. The server
* makes a best effort to cancel the operation, but success is not
* guaranteed. If the server doesn't support this method, it returns
* `google.rpc.Code.UNIMPLEMENTED`. Clients can use
* {@link Operations.GetOperation} or
* other methods to check whether the cancellation succeeded or whether the
* operation completed despite cancellation. On successful cancellation,
* the operation is not deleted; instead, it becomes an operation with
* an {@link Operation.error} value with a {@link google.rpc.Status.code} of
* 1, corresponding to `Code.CANCELLED`.
*
* @param {Object} request - The request object that will be sent.
* @param {string} request.name - The name of the operation resource to be cancelled.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call,
* e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
* https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
* details.
* @param {function(?Error)=} callback
* The function which will be called with the result of the API call.
* @return {Promise} - The promise which resolves when API call finishes.
* The promise has a method named "cancel" which cancels the ongoing API
* call.
*
* @example
* ```
* const client = longrunning.operationsClient();
* await client.cancelOperation({name: ''});
* ```
*/
cancelOperation(
request: protos.google.longrunning.CancelOperationRequest,
options?:
| gax.CallOptions
| Callback<
protos.google.protobuf.Empty,
protos.google.longrunning.CancelOperationRequest,
{} | undefined | null
>,
callback?: Callback<
protos.google.longrunning.CancelOperationRequest,
protos.google.protobuf.Empty,
{} | undefined | null
>
): Promise<protos.google.protobuf.Empty> {
return this.operationsClient.cancelOperation(request, options, callback);
}

/**
* Deletes a long-running operation. This method indicates that the client is
* no longer interested in the operation result. It does not cancel the
* operation. If the server doesn't support this method, it returns
* `google.rpc.Code.UNIMPLEMENTED`.
*
* @param {Object} request - The request object that will be sent.
* @param {string} request.name - The name of the operation resource to be deleted.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call,
* e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
* https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
* details.
* @param {function(?Error)=} callback
* The function which will be called with the result of the API call.
* @return {Promise} - The promise which resolves when API call finishes.
* The promise has a method named "cancel" which cancels the ongoing API
* call.
*
* @example
* ```
* const client = longrunning.operationsClient();
* await client.deleteOperation({name: ''});
* ```
*/
deleteOperation(
request: protos.google.longrunning.DeleteOperationRequest,
options?:
| gax.CallOptions
| Callback<
protos.google.protobuf.Empty,
protos.google.longrunning.DeleteOperationRequest,
{} | null | undefined
>,
callback?: Callback<
protos.google.protobuf.Empty,
protos.google.longrunning.DeleteOperationRequest,
{} | null | undefined
>
): Promise<protos.google.protobuf.Empty> {
return this.operationsClient.deleteOperation(request, options, callback);
}

// --------------------
// -- Path templates --
// --------------------
Expand Down Expand Up @@ -2293,6 +2575,7 @@ export class FirestoreAdminClient {
return this.firestoreAdminStub.then(stub => {
this._terminated = true;
stub.close();
this.locationsClient.close();
this.operationsClient.close();
});
}
Expand Down
Loading

0 comments on commit b9d8fef

Please sign in to comment.