Skip to content

Commit

Permalink
feat: accept google-gax instance as a parameter (#1757)
Browse files Browse the repository at this point in the history
* chore: update count up_to field type in aggregation queries

PiperOrigin-RevId: 469554568

Source-Link: googleapis/googleapis@c17c5a6

Source-Link: googleapis/googleapis-gen@0b6d950
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGI2ZDk1MDA0MGRhYzdiZDQzMTk0MWJlYTYwZGQ5Njk3NzAwMTFiYyJ9

* 🦉 Updates from OwlBot post-processor

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

* feat: accept google-gax instance as a parameter

Please see the documentation of the client constructor for details.

PiperOrigin-RevId: 470332808

Source-Link: googleapis/googleapis@d4a2367

Source-Link: googleapis/googleapis-gen@e97a1ac
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTk3YTFhYzIwNGVhZDRmZTczNDFmOTFlNzJkYjdjNmFjNjAxNjM0MSJ9

* 🦉 Updates from OwlBot post-processor

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

* fix: use _gaxModule when accessing gax for bundling

PiperOrigin-RevId: 470911839

Source-Link: googleapis/googleapis@3527566

Source-Link: googleapis/googleapis-gen@f16a1d2
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE2YTFkMjI0ZjAwYTYzMGVhNDNkNmE5YTFhMzFmNTY2ZjQ1Y2RlYSJ9

* 🦉 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: Alexander Fenster <fenster@google.com>
  • Loading branch information
3 people committed Aug 30, 2022
1 parent dd01b27 commit ef59a22
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 122 deletions.
23 changes: 13 additions & 10 deletions dev/protos/google/firestore/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ syntax = "proto3";

package google.firestore.v1;

import "google/api/field_behavior.proto";
import "google/firestore/v1/document.proto";
import "google/protobuf/wrappers.proto";

Expand Down Expand Up @@ -252,22 +253,24 @@ message StructuredQuery {

// The order to apply to the query results.
//
// Firestore guarantees a stable ordering through the following rules:
// Firestore allows callers to provide a full ordering, a partial ordering, or
// no ordering at all. In all cases, Firestore guarantees a stable ordering
// through the following rules:
//
// * Any field required to appear in `order_by`, that is not already
// specified in `order_by`, is appended to the order in field name order
// by default.
// * The `order_by` is required to reference all fields used with an
// inequality filter.
// * All fields that are required to be in the `order_by` but are not already
// present are appended in lexicographical ordering of the field name.
// * If an order on `__name__` is not specified, it is appended by default.
//
// Fields are appended with the same sort direction as the last order
// specified, or 'ASCENDING' if no order was specified. For example:
//
// * `SELECT * FROM Foo ORDER BY A` becomes
// `SELECT * FROM Foo ORDER BY A, __name__`
// * `SELECT * FROM Foo ORDER BY A DESC` becomes
// `SELECT * FROM Foo ORDER BY A DESC, __name__ DESC`
// * `SELECT * FROM Foo WHERE A > 1` becomes
// `SELECT * FROM Foo WHERE A > 1 ORDER BY A, __name__`
// * `ORDER BY a` becomes `ORDER BY a ASC, __name__ ASC`
// * `ORDER BY a DESC` becomes `ORDER BY a DESC, __name__ DESC`
// * `WHERE a > 1` becomes `WHERE a > 1 ORDER BY a ASC, __name__ ASC`
// * `WHERE __name__ > ... AND a > 1` becomes
// `WHERE __name__ > ... AND a > 1 ORDER BY a ASC, __name__ ASC`
repeated Order order_by = 4;

// A starting point for the query results.
Expand Down
109 changes: 65 additions & 44 deletions dev/src/v1/firestore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
import type * as gax from 'google-gax';
import type {
Callback,
CallOptions,
Descriptors,
Expand All @@ -30,7 +30,6 @@ import {
LocationsClient,
LocationProtos,
} from 'google-gax';

import {Transform} from 'stream';
import * as protos from '../../protos/firestore_admin_v1_proto_api';
import jsonProtos = require('../../protos/admin_v1.json');
Expand All @@ -40,7 +39,6 @@ import jsonProtos = require('../../protos/admin_v1.json');
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './firestore_admin_client_config.json';
import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -129,8 +127,18 @@ export class FirestoreAdminClient {
* 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}.
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
* need to avoid loading the default gRPC version and want to use the fallback
* HTTP implementation. Load only fallback version and pass it to the constructor:
* ```
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
* const client = new FirestoreAdminClient({fallback: 'rest'}, gax);
* ```
*/
constructor(opts?: ClientOptions) {
constructor(
opts?: ClientOptions,
gaxInstance?: typeof gax | typeof gax.fallback
) {
// Ensure that options include all the required fields.
const staticMembers = this.constructor as typeof FirestoreAdminClient;
const servicePath =
Expand All @@ -150,8 +158,13 @@ export class FirestoreAdminClient {
opts['scopes'] = staticMembers.scopes;
}

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
this._gaxModule = opts.fallback ? gax.fallback : gax;
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;

// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
Expand All @@ -172,7 +185,10 @@ export class FirestoreAdminClient {
if (servicePath === staticMembers.servicePath) {
this.auth.defaultScopes = staticMembers.scopes;
}
this.locationsClient = new LocationsClient(this._gaxGrpc, opts);
this.locationsClient = new this._gaxModule.LocationsClient(
this._gaxGrpc,
opts
);

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

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
this.warn = this._gaxModule.warn;
}

/**
Expand Down Expand Up @@ -550,7 +566,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand Down Expand Up @@ -636,7 +652,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand Down Expand Up @@ -720,7 +736,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand Down Expand Up @@ -806,7 +822,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand Down Expand Up @@ -892,7 +908,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
this.initialize();
Expand Down Expand Up @@ -1001,7 +1017,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
this.initialize();
Expand All @@ -1027,11 +1043,12 @@ export class FirestoreAdminClient {
protos.google.firestore.admin.v1.IndexOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const request =
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
const decodeOperation = new this._gaxModule.Operation(
operation,
this.descriptors.longrunning.createIndex,
this._gaxModule.createDefaultBackoffSettings()
Expand Down Expand Up @@ -1153,7 +1170,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
'field.name': request.field!.name || '',
});
this.initialize();
Expand All @@ -1179,11 +1196,12 @@ export class FirestoreAdminClient {
protos.google.firestore.admin.v1.FieldOperationMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const request =
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
const decodeOperation = new this._gaxModule.Operation(
operation,
this.descriptors.longrunning.updateField,
this._gaxModule.createDefaultBackoffSettings()
Expand Down Expand Up @@ -1312,7 +1330,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand All @@ -1338,11 +1356,12 @@ export class FirestoreAdminClient {
protos.google.firestore.admin.v1.ExportDocumentsMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const request =
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
const decodeOperation = new this._gaxModule.Operation(
operation,
this.descriptors.longrunning.exportDocuments,
this._gaxModule.createDefaultBackoffSettings()
Expand Down Expand Up @@ -1463,7 +1482,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
name: request.name || '',
});
this.initialize();
Expand All @@ -1489,11 +1508,12 @@ export class FirestoreAdminClient {
protos.google.firestore.admin.v1.ImportDocumentsMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const request =
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
const decodeOperation = new this._gaxModule.Operation(
operation,
this.descriptors.longrunning.importDocuments,
this._gaxModule.createDefaultBackoffSettings()
Expand Down Expand Up @@ -1602,7 +1622,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
'database.name': request.database!.name || '',
});
this.initialize();
Expand All @@ -1628,11 +1648,12 @@ export class FirestoreAdminClient {
protos.google.firestore.admin.v1.UpdateDatabaseMetadata
>
> {
const request = new operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const request =
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
{name}
);
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new gax.Operation(
const decodeOperation = new this._gaxModule.Operation(
operation,
this.descriptors.longrunning.updateDatabase,
this._gaxModule.createDefaultBackoffSettings()
Expand Down Expand Up @@ -1733,7 +1754,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
this.initialize();
Expand Down Expand Up @@ -1776,7 +1797,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
const defaultCallSettings = this._defaults['listIndexes'];
Expand Down Expand Up @@ -1828,7 +1849,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
const defaultCallSettings = this._defaults['listIndexes'];
Expand Down Expand Up @@ -1940,7 +1961,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
this.initialize();
Expand Down Expand Up @@ -1987,7 +2008,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
const defaultCallSettings = this._defaults['listFields'];
Expand Down Expand Up @@ -2043,7 +2064,7 @@ export class FirestoreAdminClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
this._gaxModule.routingHeader.fromParams({
parent: request.parent || '',
});
const defaultCallSettings = this._defaults['listFields'];
Expand Down
Loading

0 comments on commit ef59a22

Please sign in to comment.