Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit ef59a22

Browse files
feat: accept google-gax instance as a parameter (#1757)
* 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 <[email protected]>
1 parent dd01b27 commit ef59a22

4 files changed

Lines changed: 172 additions & 122 deletions

File tree

dev/protos/google/firestore/v1/query.proto

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ syntax = "proto3";
1616

1717
package google.firestore.v1;
1818

19+
import "google/api/field_behavior.proto";
1920
import "google/firestore/v1/document.proto";
2021
import "google/protobuf/wrappers.proto";
2122

@@ -252,22 +253,24 @@ message StructuredQuery {
252253

253254
// The order to apply to the query results.
254255
//
255-
// Firestore guarantees a stable ordering through the following rules:
256+
// Firestore allows callers to provide a full ordering, a partial ordering, or
257+
// no ordering at all. In all cases, Firestore guarantees a stable ordering
258+
// through the following rules:
256259
//
257-
// * Any field required to appear in `order_by`, that is not already
258-
// specified in `order_by`, is appended to the order in field name order
259-
// by default.
260+
// * The `order_by` is required to reference all fields used with an
261+
// inequality filter.
262+
// * All fields that are required to be in the `order_by` but are not already
263+
// present are appended in lexicographical ordering of the field name.
260264
// * If an order on `__name__` is not specified, it is appended by default.
261265
//
262266
// Fields are appended with the same sort direction as the last order
263267
// specified, or 'ASCENDING' if no order was specified. For example:
264268
//
265-
// * `SELECT * FROM Foo ORDER BY A` becomes
266-
// `SELECT * FROM Foo ORDER BY A, __name__`
267-
// * `SELECT * FROM Foo ORDER BY A DESC` becomes
268-
// `SELECT * FROM Foo ORDER BY A DESC, __name__ DESC`
269-
// * `SELECT * FROM Foo WHERE A > 1` becomes
270-
// `SELECT * FROM Foo WHERE A > 1 ORDER BY A, __name__`
269+
// * `ORDER BY a` becomes `ORDER BY a ASC, __name__ ASC`
270+
// * `ORDER BY a DESC` becomes `ORDER BY a DESC, __name__ DESC`
271+
// * `WHERE a > 1` becomes `WHERE a > 1 ORDER BY a ASC, __name__ ASC`
272+
// * `WHERE __name__ > ... AND a > 1` becomes
273+
// `WHERE __name__ > ... AND a > 1 ORDER BY a ASC, __name__ ASC`
271274
repeated Order order_by = 4;
272275

273276
// A starting point for the query results.

dev/src/v1/firestore_admin_client.ts

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// ** All changes to this file may be overwritten. **
1818

1919
/* global window */
20-
import * as gax from 'google-gax';
21-
import {
20+
import type * as gax from 'google-gax';
21+
import type {
2222
Callback,
2323
CallOptions,
2424
Descriptors,
@@ -30,7 +30,6 @@ import {
3030
LocationsClient,
3131
LocationProtos,
3232
} from 'google-gax';
33-
3433
import {Transform} from 'stream';
3534
import * as protos from '../../protos/firestore_admin_v1_proto_api';
3635
import jsonProtos = require('../../protos/admin_v1.json');
@@ -40,7 +39,6 @@ import jsonProtos = require('../../protos/admin_v1.json');
4039
* This file defines retry strategy and timeouts for all API methods in this library.
4140
*/
4241
import * as gapicConfig from './firestore_admin_client_config.json';
43-
import {operationsProtos} from 'google-gax';
4442
const version = require('../../../package.json').version;
4543

4644
/**
@@ -129,8 +127,18 @@ export class FirestoreAdminClient {
129127
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
130128
* For more information, please check the
131129
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
130+
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
131+
* need to avoid loading the default gRPC version and want to use the fallback
132+
* HTTP implementation. Load only fallback version and pass it to the constructor:
133+
* ```
134+
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
135+
* const client = new FirestoreAdminClient({fallback: 'rest'}, gax);
136+
* ```
132137
*/
133-
constructor(opts?: ClientOptions) {
138+
constructor(
139+
opts?: ClientOptions,
140+
gaxInstance?: typeof gax | typeof gax.fallback
141+
) {
134142
// Ensure that options include all the required fields.
135143
const staticMembers = this.constructor as typeof FirestoreAdminClient;
136144
const servicePath =
@@ -150,8 +158,13 @@ export class FirestoreAdminClient {
150158
opts['scopes'] = staticMembers.scopes;
151159
}
152160

161+
// Load google-gax module synchronously if needed
162+
if (!gaxInstance) {
163+
gaxInstance = require('google-gax') as typeof gax;
164+
}
165+
153166
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
154-
this._gaxModule = opts.fallback ? gax.fallback : gax;
167+
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
155168

156169
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
157170
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
@@ -172,7 +185,10 @@ export class FirestoreAdminClient {
172185
if (servicePath === staticMembers.servicePath) {
173186
this.auth.defaultScopes = staticMembers.scopes;
174187
}
175-
this.locationsClient = new LocationsClient(this._gaxGrpc, opts);
188+
this.locationsClient = new this._gaxModule.LocationsClient(
189+
this._gaxGrpc,
190+
opts
191+
);
176192

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

337353
// Add a warn function to the client constructor so it can be easily tested.
338-
this.warn = gax.warn;
354+
this.warn = this._gaxModule.warn;
339355
}
340356

341357
/**
@@ -550,7 +566,7 @@ export class FirestoreAdminClient {
550566
options.otherArgs = options.otherArgs || {};
551567
options.otherArgs.headers = options.otherArgs.headers || {};
552568
options.otherArgs.headers['x-goog-request-params'] =
553-
gax.routingHeader.fromParams({
569+
this._gaxModule.routingHeader.fromParams({
554570
name: request.name || '',
555571
});
556572
this.initialize();
@@ -636,7 +652,7 @@ export class FirestoreAdminClient {
636652
options.otherArgs = options.otherArgs || {};
637653
options.otherArgs.headers = options.otherArgs.headers || {};
638654
options.otherArgs.headers['x-goog-request-params'] =
639-
gax.routingHeader.fromParams({
655+
this._gaxModule.routingHeader.fromParams({
640656
name: request.name || '',
641657
});
642658
this.initialize();
@@ -720,7 +736,7 @@ export class FirestoreAdminClient {
720736
options.otherArgs = options.otherArgs || {};
721737
options.otherArgs.headers = options.otherArgs.headers || {};
722738
options.otherArgs.headers['x-goog-request-params'] =
723-
gax.routingHeader.fromParams({
739+
this._gaxModule.routingHeader.fromParams({
724740
name: request.name || '',
725741
});
726742
this.initialize();
@@ -806,7 +822,7 @@ export class FirestoreAdminClient {
806822
options.otherArgs = options.otherArgs || {};
807823
options.otherArgs.headers = options.otherArgs.headers || {};
808824
options.otherArgs.headers['x-goog-request-params'] =
809-
gax.routingHeader.fromParams({
825+
this._gaxModule.routingHeader.fromParams({
810826
name: request.name || '',
811827
});
812828
this.initialize();
@@ -892,7 +908,7 @@ export class FirestoreAdminClient {
892908
options.otherArgs = options.otherArgs || {};
893909
options.otherArgs.headers = options.otherArgs.headers || {};
894910
options.otherArgs.headers['x-goog-request-params'] =
895-
gax.routingHeader.fromParams({
911+
this._gaxModule.routingHeader.fromParams({
896912
parent: request.parent || '',
897913
});
898914
this.initialize();
@@ -1001,7 +1017,7 @@ export class FirestoreAdminClient {
10011017
options.otherArgs = options.otherArgs || {};
10021018
options.otherArgs.headers = options.otherArgs.headers || {};
10031019
options.otherArgs.headers['x-goog-request-params'] =
1004-
gax.routingHeader.fromParams({
1020+
this._gaxModule.routingHeader.fromParams({
10051021
parent: request.parent || '',
10061022
});
10071023
this.initialize();
@@ -1027,11 +1043,12 @@ export class FirestoreAdminClient {
10271043
protos.google.firestore.admin.v1.IndexOperationMetadata
10281044
>
10291045
> {
1030-
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1031-
{name}
1032-
);
1046+
const request =
1047+
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
1048+
{name}
1049+
);
10331050
const [operation] = await this.operationsClient.getOperation(request);
1034-
const decodeOperation = new gax.Operation(
1051+
const decodeOperation = new this._gaxModule.Operation(
10351052
operation,
10361053
this.descriptors.longrunning.createIndex,
10371054
this._gaxModule.createDefaultBackoffSettings()
@@ -1153,7 +1170,7 @@ export class FirestoreAdminClient {
11531170
options.otherArgs = options.otherArgs || {};
11541171
options.otherArgs.headers = options.otherArgs.headers || {};
11551172
options.otherArgs.headers['x-goog-request-params'] =
1156-
gax.routingHeader.fromParams({
1173+
this._gaxModule.routingHeader.fromParams({
11571174
'field.name': request.field!.name || '',
11581175
});
11591176
this.initialize();
@@ -1179,11 +1196,12 @@ export class FirestoreAdminClient {
11791196
protos.google.firestore.admin.v1.FieldOperationMetadata
11801197
>
11811198
> {
1182-
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1183-
{name}
1184-
);
1199+
const request =
1200+
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
1201+
{name}
1202+
);
11851203
const [operation] = await this.operationsClient.getOperation(request);
1186-
const decodeOperation = new gax.Operation(
1204+
const decodeOperation = new this._gaxModule.Operation(
11871205
operation,
11881206
this.descriptors.longrunning.updateField,
11891207
this._gaxModule.createDefaultBackoffSettings()
@@ -1312,7 +1330,7 @@ export class FirestoreAdminClient {
13121330
options.otherArgs = options.otherArgs || {};
13131331
options.otherArgs.headers = options.otherArgs.headers || {};
13141332
options.otherArgs.headers['x-goog-request-params'] =
1315-
gax.routingHeader.fromParams({
1333+
this._gaxModule.routingHeader.fromParams({
13161334
name: request.name || '',
13171335
});
13181336
this.initialize();
@@ -1338,11 +1356,12 @@ export class FirestoreAdminClient {
13381356
protos.google.firestore.admin.v1.ExportDocumentsMetadata
13391357
>
13401358
> {
1341-
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1342-
{name}
1343-
);
1359+
const request =
1360+
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
1361+
{name}
1362+
);
13441363
const [operation] = await this.operationsClient.getOperation(request);
1345-
const decodeOperation = new gax.Operation(
1364+
const decodeOperation = new this._gaxModule.Operation(
13461365
operation,
13471366
this.descriptors.longrunning.exportDocuments,
13481367
this._gaxModule.createDefaultBackoffSettings()
@@ -1463,7 +1482,7 @@ export class FirestoreAdminClient {
14631482
options.otherArgs = options.otherArgs || {};
14641483
options.otherArgs.headers = options.otherArgs.headers || {};
14651484
options.otherArgs.headers['x-goog-request-params'] =
1466-
gax.routingHeader.fromParams({
1485+
this._gaxModule.routingHeader.fromParams({
14671486
name: request.name || '',
14681487
});
14691488
this.initialize();
@@ -1489,11 +1508,12 @@ export class FirestoreAdminClient {
14891508
protos.google.firestore.admin.v1.ImportDocumentsMetadata
14901509
>
14911510
> {
1492-
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1493-
{name}
1494-
);
1511+
const request =
1512+
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
1513+
{name}
1514+
);
14951515
const [operation] = await this.operationsClient.getOperation(request);
1496-
const decodeOperation = new gax.Operation(
1516+
const decodeOperation = new this._gaxModule.Operation(
14971517
operation,
14981518
this.descriptors.longrunning.importDocuments,
14991519
this._gaxModule.createDefaultBackoffSettings()
@@ -1602,7 +1622,7 @@ export class FirestoreAdminClient {
16021622
options.otherArgs = options.otherArgs || {};
16031623
options.otherArgs.headers = options.otherArgs.headers || {};
16041624
options.otherArgs.headers['x-goog-request-params'] =
1605-
gax.routingHeader.fromParams({
1625+
this._gaxModule.routingHeader.fromParams({
16061626
'database.name': request.database!.name || '',
16071627
});
16081628
this.initialize();
@@ -1628,11 +1648,12 @@ export class FirestoreAdminClient {
16281648
protos.google.firestore.admin.v1.UpdateDatabaseMetadata
16291649
>
16301650
> {
1631-
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1632-
{name}
1633-
);
1651+
const request =
1652+
new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest(
1653+
{name}
1654+
);
16341655
const [operation] = await this.operationsClient.getOperation(request);
1635-
const decodeOperation = new gax.Operation(
1656+
const decodeOperation = new this._gaxModule.Operation(
16361657
operation,
16371658
this.descriptors.longrunning.updateDatabase,
16381659
this._gaxModule.createDefaultBackoffSettings()
@@ -1733,7 +1754,7 @@ export class FirestoreAdminClient {
17331754
options.otherArgs = options.otherArgs || {};
17341755
options.otherArgs.headers = options.otherArgs.headers || {};
17351756
options.otherArgs.headers['x-goog-request-params'] =
1736-
gax.routingHeader.fromParams({
1757+
this._gaxModule.routingHeader.fromParams({
17371758
parent: request.parent || '',
17381759
});
17391760
this.initialize();
@@ -1776,7 +1797,7 @@ export class FirestoreAdminClient {
17761797
options.otherArgs = options.otherArgs || {};
17771798
options.otherArgs.headers = options.otherArgs.headers || {};
17781799
options.otherArgs.headers['x-goog-request-params'] =
1779-
gax.routingHeader.fromParams({
1800+
this._gaxModule.routingHeader.fromParams({
17801801
parent: request.parent || '',
17811802
});
17821803
const defaultCallSettings = this._defaults['listIndexes'];
@@ -1828,7 +1849,7 @@ export class FirestoreAdminClient {
18281849
options.otherArgs = options.otherArgs || {};
18291850
options.otherArgs.headers = options.otherArgs.headers || {};
18301851
options.otherArgs.headers['x-goog-request-params'] =
1831-
gax.routingHeader.fromParams({
1852+
this._gaxModule.routingHeader.fromParams({
18321853
parent: request.parent || '',
18331854
});
18341855
const defaultCallSettings = this._defaults['listIndexes'];
@@ -1940,7 +1961,7 @@ export class FirestoreAdminClient {
19401961
options.otherArgs = options.otherArgs || {};
19411962
options.otherArgs.headers = options.otherArgs.headers || {};
19421963
options.otherArgs.headers['x-goog-request-params'] =
1943-
gax.routingHeader.fromParams({
1964+
this._gaxModule.routingHeader.fromParams({
19441965
parent: request.parent || '',
19451966
});
19461967
this.initialize();
@@ -1987,7 +2008,7 @@ export class FirestoreAdminClient {
19872008
options.otherArgs = options.otherArgs || {};
19882009
options.otherArgs.headers = options.otherArgs.headers || {};
19892010
options.otherArgs.headers['x-goog-request-params'] =
1990-
gax.routingHeader.fromParams({
2011+
this._gaxModule.routingHeader.fromParams({
19912012
parent: request.parent || '',
19922013
});
19932014
const defaultCallSettings = this._defaults['listFields'];
@@ -2043,7 +2064,7 @@ export class FirestoreAdminClient {
20432064
options.otherArgs = options.otherArgs || {};
20442065
options.otherArgs.headers = options.otherArgs.headers || {};
20452066
options.otherArgs.headers['x-goog-request-params'] =
2046-
gax.routingHeader.fromParams({
2067+
this._gaxModule.routingHeader.fromParams({
20472068
parent: request.parent || '',
20482069
});
20492070
const defaultCallSettings = this._defaults['listFields'];

0 commit comments

Comments
 (0)