diff --git a/handwritten/firestore/.OwlBot.yaml b/handwritten/firestore/.OwlBot.yaml deleted file mode 100644 index 4bf33471f7ff..000000000000 --- a/handwritten/firestore/.OwlBot.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -deep-remove-regex: - - /owl-bot-staging - -deep-copy-regex: - - source: /google/firestore/(v.*)/.*-nodejs - dest: /owl-bot-staging/firestore/$1 - - source: /google/firestore/admin/(v.*)/.*-nodejs - dest: /owl-bot-staging/admin/$1/$2 - -begin-after-commit-hash: d3509d2520fb8db862129633f1cf8406d17454e1 - diff --git a/handwritten/firestore/dev/src/index.ts b/handwritten/firestore/dev/src/index.ts index 5218efaf939e..359c0e2cb717 100644 --- a/handwritten/firestore/dev/src/index.ts +++ b/handwritten/firestore/dev/src/index.ts @@ -1,3 +1,5 @@ +import {protos} from '@google-cloud/firestore-api'; +export {protos}; /*! * Copyright 2017 Google Inc. All Rights Reserved. * @@ -75,7 +77,7 @@ import { } from './validate'; import {WriteBatch} from './write-batch'; -import {interfaces} from './v1/firestore_client_config.json'; +import {interfaces} from '@google-cloud/firestore-api/build/src/v1/firestore_client_config.json'; const serviceConfig = interfaces['google.firestore.v1.Firestore']; import api = google.firestore.v1; @@ -636,33 +638,30 @@ export class Firestore implements firestore.Firestore { } } - if (this._settings.ssl === false) { - const grpcModule = this._settings.grpc ?? require('google-gax').grpc; - const sslCreds = grpcModule.credentials.createInsecure(); + const grpcOptions = Object.assign( + { + 'grpc-node.flow_control_window': 256 * 1024, + }, + this._settings.grpcOptions, + ); - const settings: ClientOptions = { - sslCreds, - ...this._settings, - fallback: useFallback, - }; + let settings: ClientOptions = { + ...this._settings, + grpcOptions, + fallback: useFallback, + }; - // Since `ssl === false`, if we're using the GAX fallback then - // also set the `protocol` option for GAX fallback to force http + if (this._settings.ssl === false) { + const grpcModule = this._settings.grpc ?? require('google-gax').grpc; + settings.sslCreds = grpcModule.credentials.createInsecure(); if (useFallback) { settings.protocol = 'http'; } - - client = new module.exports.v1(settings, gax); - } else { - client = new module.exports.v1( - { - ...this._settings, - fallback: useFallback, - }, - gax, - ); } + const v1Client = (module.exports.v1 && module.exports.v1.FirestoreClient) || module.exports.v1; + client = new v1Client(settings, gax); + logger( 'clientFactory', null, @@ -2028,8 +2027,14 @@ module.exports = Object.assign(module.exports, existingExports); */ Object.defineProperty(module.exports, 'v1beta1', { // The v1beta1 module is very large. To avoid pulling it in from static - // scope, we lazy-load the module. - get: () => require('./v1beta1'), + // scope, we lazy-load the module. + get: () => { + const api = require('@google-cloud/firestore-api').v1beta1; + const fn = function(this: any, ...args: any[]) { + return new (api.FirestoreClient as any)(...args); + }; + return Object.assign(fn, api); + }, }); /** @@ -2043,17 +2048,15 @@ Object.defineProperty(module.exports, 'v1beta1', { Object.defineProperty(module.exports, 'v1', { // The v1 module is very large. To avoid pulling it in from static // scope, we lazy-load the module. - get: () => require('./v1'), + get: () => { + const api = require('@google-cloud/firestore-api').v1; + const fn = function(this: any, ...args: any[]) { + return new (api.FirestoreClient as any)(...args); + }; + return Object.assign(fn, api); + }, }); -/** - * {@link Status} factory function. - * - * @private - * @internal - * @name Firestore.GrpcStatus - * @type {function} - */ Object.defineProperty(module.exports, 'GrpcStatus', { // The gax module is very large. To avoid pulling it in from static // scope, we lazy-load the module. diff --git a/handwritten/firestore/dev/src/telemetry/enabled-trace-util.ts b/handwritten/firestore/dev/src/telemetry/enabled-trace-util.ts index a74eeb65d0d7..7330f4b2dacf 100644 --- a/handwritten/firestore/dev/src/telemetry/enabled-trace-util.ts +++ b/handwritten/firestore/dev/src/telemetry/enabled-trace-util.ts @@ -33,8 +33,8 @@ import { TraceUtil, } from './trace-util'; -import {interfaces} from '../v1/firestore_client_config.json'; -import {FirestoreClient} from '../v1'; +import {interfaces} from '@google-cloud/firestore-api/build/src/v1/firestore_client_config.json'; +import {FirestoreClient} from '@google-cloud/firestore-api/build/src/v1'; import {DEFAULT_DATABASE_ID} from '../path'; import {DEFAULT_MAX_IDLE_CHANNELS} from '../index'; const serviceConfig = interfaces['google.firestore.v1.Firestore']; diff --git a/handwritten/firestore/dev/src/util.ts b/handwritten/firestore/dev/src/util.ts index d8ef4fd4f714..36ac95eec99a 100644 --- a/handwritten/firestore/dev/src/util.ts +++ b/handwritten/firestore/dev/src/util.ts @@ -19,7 +19,7 @@ import {DocumentData} from '@google-cloud/firestore'; import {randomBytes} from 'crypto'; import type {CallSettings, ClientConfig, GoogleError} from 'google-gax'; import type {BackoffSettings} from 'google-gax/build/src/gax'; -import * as gapicConfig from './v1/firestore_client_config.json'; +import * as gapicConfig from '@google-cloud/firestore-api/build/src/v1/firestore_client_config.json'; import Dict = NodeJS.Dict; /** diff --git a/handwritten/firestore/dev/src/v1/firestore_admin_client.ts b/handwritten/firestore/dev/src/v1/firestore_admin_client.ts deleted file mode 100644 index 6f270b170a8e..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_admin_client.ts +++ /dev/null @@ -1,6513 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type { - Callback, - CallOptions, - Descriptors, - ClientOptions, - GrpcClientOptions, - LROperation, - PaginationCallback, - GaxCall, - 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'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; - -/** - * Client JSON configuration object, loaded from - * `src/v1/firestore_admin_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './firestore_admin_client_config.json'; -const version = require('../../../package.json').version; - -/** - * The Cloud Firestore Admin API. - * - * This API provides several administrative services for Cloud Firestore. - * - * Project, Database, Namespace, Collection, Collection Group, and Document are - * used as defined in the Google Cloud Firestore API. - * - * Operation: An Operation represents work being performed in the background. - * - * The index service manages Cloud Firestore indexes. - * - * Index creation is performed asynchronously. - * An Operation resource is created for each such asynchronous operation. - * The state of the operation (including any errors encountered) - * may be queried via the Operation resource. - * - * The Operations collection provides a record of actions performed for the - * specified Project (including any Operations in progress). Operations are not - * created directly but through calls on other collections or resources. - * - * An Operation that is done may be deleted so that it is no longer listed as - * part of the Operation collection. Operations are garbage collected after - * 30 days. By default, ListOperations will only return in progress and failed - * operations. To list completed operation, issue a ListOperations request with - * the filter `done: true`. - * - * Operations are created by service `FirestoreAdmin`, but are accessed via - * service `google.longrunning.Operations`. - * @class - * @memberof v1 - */ -export class FirestoreAdminClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - private _universeDomain: string; - private _servicePath: string; - private _log = logging.log('firestore-admin'); - - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - 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}>; - - /** - * Construct an instance of 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/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * 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: true}, gax); - * ``` - */ - constructor( - opts?: ClientOptions, - gaxInstance?: typeof gax | typeof gax.fallback, - ) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof FirestoreAdminClient; - if ( - opts?.universe_domain && - opts?.universeDomain && - opts?.universe_domain !== opts?.universeDomain - ) { - throw new Error( - 'Please set either universe_domain or universeDomain, but not both.', - ); - } - const universeDomainEnvVar = - typeof process === 'object' && typeof process.env === 'object' - ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] - : undefined; - this._universeDomain = - opts?.universeDomain ?? - opts?.universe_domain ?? - universeDomainEnvVar ?? - 'googleapis.com'; - this._servicePath = 'firestore.' + this._universeDomain; - const servicePath = - opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!( - opts?.servicePath || opts?.apiEndpoint - ); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = - opts?.fallback ?? - (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== this._servicePath && !('scopes' in opts)) { - 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 ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = this._servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === this._servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - this.locationsClient = new this._gaxModule.LocationsClient( - this._gaxGrpc, - opts, - ); - - // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; - if (typeof process === 'object' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/locations/{location}/backups/{backup}', - ), - backupSchedulePathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}/backupSchedules/{backup_schedule}', - ), - collectionGroupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}/collectionGroups/{collection}', - ), - databasePathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}', - ), - fieldPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}/collectionGroups/{collection}/fields/{field}', - ), - indexPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}/collectionGroups/{collection}/indexes/{index}', - ), - locationPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/locations/{location}', - ), - projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}', - ), - userCredsPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/databases/{database}/userCreds/{user_creds}', - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listIndexes: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'indexes', - ), - listFields: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'fields', - ), - }; - - const protoFilesRoot = this._gaxModule.protobufFromJSON(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) { - 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(lroOptions) - .operationsClient(opts); - const createIndexResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Index', - ) as gax.protobuf.Type; - const createIndexMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.IndexOperationMetadata', - ) as gax.protobuf.Type; - const updateFieldResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Field', - ) as gax.protobuf.Type; - const updateFieldMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.FieldOperationMetadata', - ) as gax.protobuf.Type; - const exportDocumentsResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.ExportDocumentsResponse', - ) as gax.protobuf.Type; - const exportDocumentsMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.ExportDocumentsMetadata', - ) as gax.protobuf.Type; - const importDocumentsResponse = protoFilesRoot.lookup( - '.google.protobuf.Empty', - ) as gax.protobuf.Type; - const importDocumentsMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.ImportDocumentsMetadata', - ) as gax.protobuf.Type; - const bulkDeleteDocumentsResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.BulkDeleteDocumentsResponse', - ) as gax.protobuf.Type; - const bulkDeleteDocumentsMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.BulkDeleteDocumentsMetadata', - ) as gax.protobuf.Type; - const createDatabaseResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Database', - ) as gax.protobuf.Type; - const createDatabaseMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.CreateDatabaseMetadata', - ) as gax.protobuf.Type; - const updateDatabaseResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Database', - ) as gax.protobuf.Type; - const updateDatabaseMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.UpdateDatabaseMetadata', - ) as gax.protobuf.Type; - const deleteDatabaseResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Database', - ) as gax.protobuf.Type; - const deleteDatabaseMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.DeleteDatabaseMetadata', - ) as gax.protobuf.Type; - const restoreDatabaseResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Database', - ) as gax.protobuf.Type; - const restoreDatabaseMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.RestoreDatabaseMetadata', - ) as gax.protobuf.Type; - const cloneDatabaseResponse = protoFilesRoot.lookup( - '.google.firestore.admin.v1.Database', - ) as gax.protobuf.Type; - const cloneDatabaseMetadata = protoFilesRoot.lookup( - '.google.firestore.admin.v1.CloneDatabaseMetadata', - ) as gax.protobuf.Type; - - this.descriptors.longrunning = { - createIndex: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - createIndexResponse.decode.bind(createIndexResponse), - createIndexMetadata.decode.bind(createIndexMetadata), - ), - updateField: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - updateFieldResponse.decode.bind(updateFieldResponse), - updateFieldMetadata.decode.bind(updateFieldMetadata), - ), - exportDocuments: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - exportDocumentsResponse.decode.bind(exportDocumentsResponse), - exportDocumentsMetadata.decode.bind(exportDocumentsMetadata), - ), - importDocuments: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - importDocumentsResponse.decode.bind(importDocumentsResponse), - importDocumentsMetadata.decode.bind(importDocumentsMetadata), - ), - bulkDeleteDocuments: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - bulkDeleteDocumentsResponse.decode.bind(bulkDeleteDocumentsResponse), - bulkDeleteDocumentsMetadata.decode.bind(bulkDeleteDocumentsMetadata), - ), - createDatabase: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - createDatabaseResponse.decode.bind(createDatabaseResponse), - createDatabaseMetadata.decode.bind(createDatabaseMetadata), - ), - updateDatabase: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - updateDatabaseResponse.decode.bind(updateDatabaseResponse), - updateDatabaseMetadata.decode.bind(updateDatabaseMetadata), - ), - deleteDatabase: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - deleteDatabaseResponse.decode.bind(deleteDatabaseResponse), - deleteDatabaseMetadata.decode.bind(deleteDatabaseMetadata), - ), - restoreDatabase: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - restoreDatabaseResponse.decode.bind(restoreDatabaseResponse), - restoreDatabaseMetadata.decode.bind(restoreDatabaseMetadata), - ), - cloneDatabase: new this._gaxModule.LongrunningDescriptor( - this.operationsClient, - cloneDatabaseResponse.decode.bind(cloneDatabaseResponse), - cloneDatabaseMetadata.decode.bind(cloneDatabaseMetadata), - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.firestore.admin.v1.FirestoreAdmin', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')}, - ); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.firestoreAdminStub) { - return this.firestoreAdminStub; - } - - // Put together the "service stub" for - // google.firestore.admin.v1.FirestoreAdmin. - this.firestoreAdminStub = this._gaxGrpc.createStub( - this._opts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.firestore.admin.v1.FirestoreAdmin', - ) - : // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.firestore.admin.v1.FirestoreAdmin, - this._opts, - this._providedCustomServicePath, - ) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const firestoreAdminStubMethods = [ - 'createIndex', - 'listIndexes', - 'getIndex', - 'deleteIndex', - 'getField', - 'updateField', - 'listFields', - 'exportDocuments', - 'importDocuments', - 'bulkDeleteDocuments', - 'createDatabase', - 'getDatabase', - 'listDatabases', - 'updateDatabase', - 'deleteDatabase', - 'createUserCreds', - 'getUserCreds', - 'listUserCreds', - 'enableUserCreds', - 'disableUserCreds', - 'resetUserPassword', - 'deleteUserCreds', - 'getBackup', - 'listBackups', - 'deleteBackup', - 'restoreDatabase', - 'createBackupSchedule', - 'getBackupSchedule', - 'listBackupSchedules', - 'updateBackupSchedule', - 'deleteBackupSchedule', - 'cloneDatabase', - ]; - for (const methodName of firestoreAdminStubMethods) { - const callPromise = this.firestoreAdminStub.then( - stub => - (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error | null | undefined) => () => { - throw err; - }, - ); - - const descriptor = - this.descriptors.page[methodName] || - this.descriptors.longrunning[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback, - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.firestoreAdminStub; - } - - /** - * The DNS address for this API service. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static servicePath is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static apiEndpoint is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - get apiEndpoint() { - return this._servicePath; - } - - get universeDomain() { - return this._universeDomain; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/datastore', - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId( - callback?: Callback, - ): Promise | void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - /** - * Gets a composite index. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}` - * @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 {@link protos.google.firestore.admin.v1.Index|Index}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_index.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetIndex_async - */ - getIndex( - request?: protos.google.firestore.admin.v1.IGetIndexRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | undefined, - {} | undefined, - ] - >; - getIndex( - request: protos.google.firestore.admin.v1.IGetIndexRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | null | undefined, - {} | null | undefined - >, - ): void; - getIndex( - request: protos.google.firestore.admin.v1.IGetIndexRequest, - callback: Callback< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | null | undefined, - {} | null | undefined - >, - ): void; - getIndex( - request?: protos.google.firestore.admin.v1.IGetIndexRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getIndex request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getIndex response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getIndex(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IGetIndexRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getIndex response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a composite index. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/indexes/{index_id}` - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_index.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteIndex_async - */ - deleteIndex( - request?: protos.google.firestore.admin.v1.IDeleteIndexRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | undefined, - {} | undefined, - ] - >; - deleteIndex( - request: protos.google.firestore.admin.v1.IDeleteIndexRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteIndex( - request: protos.google.firestore.admin.v1.IDeleteIndexRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteIndex( - request?: protos.google.firestore.admin.v1.IDeleteIndexRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteIndexRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteIndex request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteIndexRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteIndex response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteIndex(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteIndexRequest | undefined, - {} | undefined, - ]) => { - this._log.info('deleteIndex response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Gets the metadata and configuration for a Field. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}/fields/{field_id}` - * @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 {@link protos.google.firestore.admin.v1.Field|Field}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_field.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetField_async - */ - getField( - request?: protos.google.firestore.admin.v1.IGetFieldRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | undefined, - {} | undefined, - ] - >; - getField( - request: protos.google.firestore.admin.v1.IGetFieldRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | null | undefined, - {} | null | undefined - >, - ): void; - getField( - request: protos.google.firestore.admin.v1.IGetFieldRequest, - callback: Callback< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | null | undefined, - {} | null | undefined - >, - ): void; - getField( - request?: protos.google.firestore.admin.v1.IGetFieldRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getField request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getField response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getField(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IGetFieldRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getField response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Gets information about a database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}` - * @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 {@link protos.google.firestore.admin.v1.Database|Database}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetDatabase_async - */ - getDatabase( - request?: protos.google.firestore.admin.v1.IGetDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | undefined, - {} | undefined, - ] - >; - getDatabase( - request: protos.google.firestore.admin.v1.IGetDatabaseRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDatabase( - request: protos.google.firestore.admin.v1.IGetDatabaseRequest, - callback: Callback< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDatabase( - request?: protos.google.firestore.admin.v1.IGetDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IDatabase, - | protos.google.firestore.admin.v1.IGetDatabaseRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getDatabase request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IDatabase, - | protos.google.firestore.admin.v1.IGetDatabaseRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getDatabase response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getDatabase(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IGetDatabaseRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getDatabase response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * List all the databases in the project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}` - * @param {boolean} request.showDeleted - * If true, also returns deleted resources. - * @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 {@link protos.google.firestore.admin.v1.ListDatabasesResponse|ListDatabasesResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_databases.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListDatabases_async - */ - listDatabases( - request?: protos.google.firestore.admin.v1.IListDatabasesRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | undefined, - {} | undefined, - ] - >; - listDatabases( - request: protos.google.firestore.admin.v1.IListDatabasesRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | null | undefined, - {} | null | undefined - >, - ): void; - listDatabases( - request: protos.google.firestore.admin.v1.IListDatabasesRequest, - callback: Callback< - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | null | undefined, - {} | null | undefined - >, - ): void; - listDatabases( - request?: protos.google.firestore.admin.v1.IListDatabasesRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IListDatabasesResponse, - | protos.google.firestore.admin.v1.IListDatabasesRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listDatabases request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IListDatabasesResponse, - | protos.google.firestore.admin.v1.IListDatabasesRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('listDatabases response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .listDatabases(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IListDatabasesResponse, - protos.google.firestore.admin.v1.IListDatabasesRequest | undefined, - {} | undefined, - ]) => { - this._log.info('listDatabases response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Create a user creds. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}` - * @param {google.firestore.admin.v1.UserCreds} request.userCreds - * Required. The user creds to create. - * @param {string} request.userCredsId - * Required. The ID to use for the user creds, which will become the final - * component of the user creds's resource name. - * - * This value should be 4-63 characters. Valid characters are /{@link protos.0-9|a-z}-/ - * with first character a letter and the last a letter or a number. Must not - * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/. - * @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 {@link protos.google.firestore.admin.v1.UserCreds|UserCreds}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateUserCreds_async - */ - createUserCreds( - request?: protos.google.firestore.admin.v1.ICreateUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.ICreateUserCredsRequest | undefined, - {} | undefined, - ] - >; - createUserCreds( - request: protos.google.firestore.admin.v1.ICreateUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.ICreateUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - createUserCreds( - request: protos.google.firestore.admin.v1.ICreateUserCredsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.ICreateUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - createUserCreds( - request?: protos.google.firestore.admin.v1.ICreateUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.ICreateUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.ICreateUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.ICreateUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('createUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.ICreateUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('createUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .createUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.ICreateUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('createUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Gets a user creds resource. Note that the returned resource does not - * contain the secret value itself. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` - * @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 {@link protos.google.firestore.admin.v1.UserCreds|UserCreds}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetUserCreds_async - */ - getUserCreds( - request?: protos.google.firestore.admin.v1.IGetUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | undefined, - {} | undefined, - ] - >; - getUserCreds( - request: protos.google.firestore.admin.v1.IGetUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): void; - getUserCreds( - request: protos.google.firestore.admin.v1.IGetUserCredsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): void; - getUserCreds( - request?: protos.google.firestore.admin.v1.IGetUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IGetUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IGetUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IGetUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * List all user creds in the database. Note that the returned resource - * does not contain the secret value itself. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent database name of the form - * `projects/{project_id}/databases/{database_id}` - * @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 {@link protos.google.firestore.admin.v1.ListUserCredsResponse|ListUserCredsResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListUserCreds_async - */ - listUserCreds( - request?: protos.google.firestore.admin.v1.IListUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | undefined, - {} | undefined, - ] - >; - listUserCreds( - request: protos.google.firestore.admin.v1.IListUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): void; - listUserCreds( - request: protos.google.firestore.admin.v1.IListUserCredsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): void; - listUserCreds( - request?: protos.google.firestore.admin.v1.IListUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IListUserCredsResponse, - | protos.google.firestore.admin.v1.IListUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IListUserCredsResponse, - | protos.google.firestore.admin.v1.IListUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('listUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .listUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IListUserCredsResponse, - protos.google.firestore.admin.v1.IListUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('listUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Enables a user creds. No-op if the user creds are already enabled. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` - * @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 {@link protos.google.firestore.admin.v1.UserCreds|UserCreds}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.enable_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_EnableUserCreds_async - */ - enableUserCreds( - request?: protos.google.firestore.admin.v1.IEnableUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IEnableUserCredsRequest | undefined, - {} | undefined, - ] - >; - enableUserCreds( - request: protos.google.firestore.admin.v1.IEnableUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IEnableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - enableUserCreds( - request: protos.google.firestore.admin.v1.IEnableUserCredsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IEnableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - enableUserCreds( - request?: protos.google.firestore.admin.v1.IEnableUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IEnableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IEnableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IEnableUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('enableUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IEnableUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('enableUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .enableUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IEnableUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('enableUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Disables a user creds. No-op if the user creds are already disabled. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` - * @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 {@link protos.google.firestore.admin.v1.UserCreds|UserCreds}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.disable_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DisableUserCreds_async - */ - disableUserCreds( - request?: protos.google.firestore.admin.v1.IDisableUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IDisableUserCredsRequest | undefined, - {} | undefined, - ] - >; - disableUserCreds( - request: protos.google.firestore.admin.v1.IDisableUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IDisableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - disableUserCreds( - request: protos.google.firestore.admin.v1.IDisableUserCredsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IDisableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - disableUserCreds( - request?: protos.google.firestore.admin.v1.IDisableUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IDisableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IDisableUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IDisableUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('disableUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IDisableUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('disableUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .disableUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IDisableUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('disableUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Resets the password of a user creds. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` - * @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 {@link protos.google.firestore.admin.v1.UserCreds|UserCreds}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.reset_user_password.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ResetUserPassword_async - */ - resetUserPassword( - request?: protos.google.firestore.admin.v1.IResetUserPasswordRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IResetUserPasswordRequest | undefined, - {} | undefined, - ] - >; - resetUserPassword( - request: protos.google.firestore.admin.v1.IResetUserPasswordRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - resetUserPassword( - request: protos.google.firestore.admin.v1.IResetUserPasswordRequest, - callback: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - resetUserPassword( - request?: protos.google.firestore.admin.v1.IResetUserPasswordRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IUserCreds, - protos.google.firestore.admin.v1.IResetUserPasswordRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('resetUserPassword request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IUserCreds, - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('resetUserPassword response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .resetUserPassword(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IUserCreds, - ( - | protos.google.firestore.admin.v1.IResetUserPasswordRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('resetUserPassword response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a user creds. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}/userCreds/{user_creds_id}` - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_user_creds.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteUserCreds_async - */ - deleteUserCreds( - request?: protos.google.firestore.admin.v1.IDeleteUserCredsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteUserCredsRequest | undefined, - {} | undefined, - ] - >; - deleteUserCreds( - request: protos.google.firestore.admin.v1.IDeleteUserCredsRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - deleteUserCreds( - request: protos.google.firestore.admin.v1.IDeleteUserCredsRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - deleteUserCreds( - request?: protos.google.firestore.admin.v1.IDeleteUserCredsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteUserCredsRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteUserCredsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteUserCreds request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteUserCredsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteUserCreds response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteUserCreds(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteUserCredsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('deleteUserCreds response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Gets information about a backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the backup to fetch. - * - * Format is `projects/{project}/locations/{location}/backups/{backup}`. - * @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 {@link protos.google.firestore.admin.v1.Backup|Backup}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_backup.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetBackup_async - */ - getBackup( - request?: protos.google.firestore.admin.v1.IGetBackupRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | undefined, - {} | undefined, - ] - >; - getBackup( - request: protos.google.firestore.admin.v1.IGetBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | null | undefined, - {} | null | undefined - >, - ): void; - getBackup( - request: protos.google.firestore.admin.v1.IGetBackupRequest, - callback: Callback< - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | null | undefined, - {} | null | undefined - >, - ): void; - getBackup( - request?: protos.google.firestore.admin.v1.IGetBackupRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getBackup request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getBackup response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getBackup(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IBackup, - protos.google.firestore.admin.v1.IGetBackupRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getBackup response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Lists all the backups. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The location to list backups from. - * - * Format is `projects/{project}/locations/{location}`. - * Use `{location} = '-'` to list backups from all locations for the given - * project. This allows listing backups from a single location or from all - * locations. - * @param {string} request.filter - * An expression that filters the list of returned backups. - * - * A filter expression consists of a field name, a comparison operator, and a - * value for filtering. - * The value must be a string, a number, or a boolean. The comparison operator - * must be one of: `<`, `>`, `<=`, `>=`, `!=`, `=`, or `:`. - * Colon `:` is the contains operator. Filter rules are not case sensitive. - * - * The following fields in the {@link protos.google.firestore.admin.v1.Backup|Backup} are - * eligible for filtering: - * - * * `database_uid` (supports `=` only) - * @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 {@link protos.google.firestore.admin.v1.ListBackupsResponse|ListBackupsResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_backups.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListBackups_async - */ - listBackups( - request?: protos.google.firestore.admin.v1.IListBackupsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | undefined, - {} | undefined, - ] - >; - listBackups( - request: protos.google.firestore.admin.v1.IListBackupsRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | null | undefined, - {} | null | undefined - >, - ): void; - listBackups( - request: protos.google.firestore.admin.v1.IListBackupsRequest, - callback: Callback< - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | null | undefined, - {} | null | undefined - >, - ): void; - listBackups( - request?: protos.google.firestore.admin.v1.IListBackupsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IListBackupsResponse, - | protos.google.firestore.admin.v1.IListBackupsRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listBackups request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IListBackupsResponse, - | protos.google.firestore.admin.v1.IListBackupsRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('listBackups response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .listBackups(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IListBackupsResponse, - protos.google.firestore.admin.v1.IListBackupsRequest | undefined, - {} | undefined, - ]) => { - this._log.info('listBackups response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the backup to delete. - * - * format is `projects/{project}/locations/{location}/backups/{backup}`. - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_backup.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteBackup_async - */ - deleteBackup( - request?: protos.google.firestore.admin.v1.IDeleteBackupRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | undefined, - {} | undefined, - ] - >; - deleteBackup( - request: protos.google.firestore.admin.v1.IDeleteBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteBackup( - request: protos.google.firestore.admin.v1.IDeleteBackupRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteBackup( - request?: protos.google.firestore.admin.v1.IDeleteBackupRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteBackup request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteBackup response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteBackup(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupRequest | undefined, - {} | undefined, - ]) => { - this._log.info('deleteBackup response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Creates a backup schedule on a database. - * At most two backup schedules can be configured on a database, one daily - * backup schedule and one weekly backup schedule. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent database. - * - * Format `projects/{project}/databases/{database}` - * @param {google.firestore.admin.v1.BackupSchedule} request.backupSchedule - * Required. The backup schedule to create. - * @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 {@link protos.google.firestore.admin.v1.BackupSchedule|BackupSchedule}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_backup_schedule.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateBackupSchedule_async - */ - createBackupSchedule( - request?: protos.google.firestore.admin.v1.ICreateBackupScheduleRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.ICreateBackupScheduleRequest | undefined, - {} | undefined, - ] - >; - createBackupSchedule( - request: protos.google.firestore.admin.v1.ICreateBackupScheduleRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - createBackupSchedule( - request: protos.google.firestore.admin.v1.ICreateBackupScheduleRequest, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - createBackupSchedule( - request?: protos.google.firestore.admin.v1.ICreateBackupScheduleRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.ICreateBackupScheduleRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('createBackupSchedule request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('createBackupSchedule response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .createBackupSchedule(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IBackupSchedule, - ( - | protos.google.firestore.admin.v1.ICreateBackupScheduleRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('createBackupSchedule response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Gets information about a backup schedule. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup schedule. - * - * Format - * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` - * @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 {@link protos.google.firestore.admin.v1.BackupSchedule|BackupSchedule}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.get_backup_schedule.js - * region_tag:firestore_v1_generated_FirestoreAdmin_GetBackupSchedule_async - */ - getBackupSchedule( - request?: protos.google.firestore.admin.v1.IGetBackupScheduleRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.IGetBackupScheduleRequest | undefined, - {} | undefined, - ] - >; - getBackupSchedule( - request: protos.google.firestore.admin.v1.IGetBackupScheduleRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - getBackupSchedule( - request: protos.google.firestore.admin.v1.IGetBackupScheduleRequest, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - getBackupSchedule( - request?: protos.google.firestore.admin.v1.IGetBackupScheduleRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.IGetBackupScheduleRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getBackupSchedule request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getBackupSchedule response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getBackupSchedule(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IBackupSchedule, - ( - | protos.google.firestore.admin.v1.IGetBackupScheduleRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('getBackupSchedule response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * List backup schedules. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent database. - * - * Format is `projects/{project}/databases/{database}`. - * @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 {@link protos.google.firestore.admin.v1.ListBackupSchedulesResponse|ListBackupSchedulesResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_backup_schedules.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListBackupSchedules_async - */ - listBackupSchedules( - request?: protos.google.firestore.admin.v1.IListBackupSchedulesRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - protos.google.firestore.admin.v1.IListBackupSchedulesRequest | undefined, - {} | undefined, - ] - >; - listBackupSchedules( - request: protos.google.firestore.admin.v1.IListBackupSchedulesRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - listBackupSchedules( - request: protos.google.firestore.admin.v1.IListBackupSchedulesRequest, - callback: Callback< - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - listBackupSchedules( - request?: protos.google.firestore.admin.v1.IListBackupSchedulesRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - protos.google.firestore.admin.v1.IListBackupSchedulesRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listBackupSchedules request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('listBackupSchedules response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .listBackupSchedules(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IListBackupSchedulesResponse, - ( - | protos.google.firestore.admin.v1.IListBackupSchedulesRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('listBackupSchedules response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Updates a backup schedule. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.firestore.admin.v1.BackupSchedule} request.backupSchedule - * Required. The backup schedule to update. - * @param {google.protobuf.FieldMask} request.updateMask - * The list of fields to be updated. - * @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 {@link protos.google.firestore.admin.v1.BackupSchedule|BackupSchedule}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.update_backup_schedule.js - * region_tag:firestore_v1_generated_FirestoreAdmin_UpdateBackupSchedule_async - */ - updateBackupSchedule( - request?: protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest | undefined, - {} | undefined, - ] - >; - updateBackupSchedule( - request: protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - updateBackupSchedule( - request: protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest, - callback: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - updateBackupSchedule( - request?: protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IBackupSchedule, - protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - 'backup_schedule.name': request.backupSchedule!.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('updateBackupSchedule request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.admin.v1.IBackupSchedule, - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('updateBackupSchedule response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .updateBackupSchedule(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.admin.v1.IBackupSchedule, - ( - | protos.google.firestore.admin.v1.IUpdateBackupScheduleRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('updateBackupSchedule response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a backup schedule. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup schedule. - * - * Format - * `projects/{project}/databases/{database}/backupSchedules/{backup_schedule}` - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_backup_schedule.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteBackupSchedule_async - */ - deleteBackupSchedule( - request?: protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest | undefined, - {} | undefined, - ] - >; - deleteBackupSchedule( - request: protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - deleteBackupSchedule( - request: protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - deleteBackupSchedule( - request?: protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteBackupSchedule request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteBackupSchedule response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteBackupSchedule(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - ( - | protos.google.firestore.admin.v1.IDeleteBackupScheduleRequest - | undefined - ), - {} | undefined, - ]) => { - this._log.info('deleteBackupSchedule response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - - /** - * Creates a composite index. This returns a - * {@link protos.google.longrunning.Operation|google.longrunning.Operation} which may be - * used to track the status of the creation. The metadata for the operation - * will be the type - * {@link protos.google.firestore.admin.v1.IndexOperationMetadata|IndexOperationMetadata}. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {google.firestore.admin.v1.Index} request.index - * Required. The composite index to create. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_index.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateIndex_async - */ - createIndex( - request?: protos.google.firestore.admin.v1.ICreateIndexRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - createIndex( - request: protos.google.firestore.admin.v1.ICreateIndexRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - createIndex( - request: protos.google.firestore.admin.v1.ICreateIndexRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - createIndex( - request?: protos.google.firestore.admin.v1.ICreateIndexRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('createIndex response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('createIndex request %j', request); - return this.innerApiCalls - .createIndex(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('createIndex response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `createIndex()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_index.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateIndex_async - */ - async checkCreateIndexProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Index, - protos.google.firestore.admin.v1.IndexOperationMetadata - > - > { - this._log.info('createIndex long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.createIndex, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Index, - protos.google.firestore.admin.v1.IndexOperationMetadata - >; - } - /** - * Updates a field configuration. Currently, field updates apply only to - * single field index configuration. However, calls to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.UpdateField|FirestoreAdmin.UpdateField} - * should provide a field mask to avoid changing any configuration that the - * caller isn't aware of. The field mask should be specified as: `{ paths: - * "index_config" }`. - * - * This call returns a - * {@link protos.google.longrunning.Operation|google.longrunning.Operation} which may be - * used to track the status of the field update. The metadata for the - * operation will be the type - * {@link protos.google.firestore.admin.v1.FieldOperationMetadata|FieldOperationMetadata}. - * - * To configure the default field settings for the database, use - * the special `Field` with resource name: - * `projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*`. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.firestore.admin.v1.Field} request.field - * Required. The field to be updated. - * @param {google.protobuf.FieldMask} request.updateMask - * A mask, relative to the field. If specified, only configuration specified - * by this field_mask will be updated in the field. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.update_field.js - * region_tag:firestore_v1_generated_FirestoreAdmin_UpdateField_async - */ - updateField( - request?: protos.google.firestore.admin.v1.IUpdateFieldRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - updateField( - request: protos.google.firestore.admin.v1.IUpdateFieldRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - updateField( - request: protos.google.firestore.admin.v1.IUpdateFieldRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - updateField( - request?: protos.google.firestore.admin.v1.IUpdateFieldRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - 'field.name': request.field!.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('updateField response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('updateField request %j', request); - return this.innerApiCalls - .updateField(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('updateField response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `updateField()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.update_field.js - * region_tag:firestore_v1_generated_FirestoreAdmin_UpdateField_async - */ - async checkUpdateFieldProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Field, - protos.google.firestore.admin.v1.FieldOperationMetadata - > - > { - this._log.info('updateField long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.updateField, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Field, - protos.google.firestore.admin.v1.FieldOperationMetadata - >; - } - /** - * Exports a copy of all or a subset of documents from Google Cloud Firestore - * to another storage system, such as Google Cloud Storage. Recent updates to - * documents may not be reflected in the export. The export occurs in the - * background and its progress can be monitored and managed via the - * Operation resource that is created. The output of an export may only be - * used once the associated operation is done. If an export operation is - * cancelled before completion it may leave partial data behind in Google - * Cloud Storage. - * - * For more details on export behavior and output format, refer to: - * https://cloud.google.com/firestore/docs/manage-data/export-import - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Database to export. Should be of the form: - * `projects/{project_id}/databases/{database_id}`. - * @param {string[]} request.collectionIds - * IDs of the collection groups to export. Unspecified means all - * collection groups. Each collection group in this list must be unique. - * @param {string} request.outputUriPrefix - * The output URI. Currently only supports Google Cloud Storage URIs of the - * form: `gs://BUCKET_NAME[/NAMESPACE_PATH]`, where `BUCKET_NAME` is the name - * of the Google Cloud Storage bucket and `NAMESPACE_PATH` is an optional - * Google Cloud Storage namespace path. When - * choosing a name, be sure to consider Google Cloud Storage naming - * guidelines: https://cloud.google.com/storage/docs/naming. - * If the URI is a bucket (without a namespace path), a prefix will be - * generated based on the start time. - * @param {string[]} request.namespaceIds - * An empty list represents all namespaces. This is the preferred - * usage for databases that don't use namespaces. - * - * An empty string element represents the default namespace. This should be - * used if the database has data in non-default namespaces, but doesn't want - * to include them. Each namespace in this list must be unique. - * @param {google.protobuf.Timestamp} request.snapshotTime - * The timestamp that corresponds to the version of the database to be - * exported. The timestamp must be in the past, rounded to the minute and not - * older than - * {@link protos.google.firestore.admin.v1.Database.earliest_version_time|earliestVersionTime}. - * If specified, then the exported documents will represent a consistent view - * of the database at the provided time. Otherwise, there are no guarantees - * about the consistency of the exported documents. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.export_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ExportDocuments_async - */ - exportDocuments( - request?: protos.google.firestore.admin.v1.IExportDocumentsRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - exportDocuments( - request: protos.google.firestore.admin.v1.IExportDocumentsRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - exportDocuments( - request: protos.google.firestore.admin.v1.IExportDocumentsRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - exportDocuments( - request?: protos.google.firestore.admin.v1.IExportDocumentsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('exportDocuments response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('exportDocuments request %j', request); - return this.innerApiCalls - .exportDocuments(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('exportDocuments response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `exportDocuments()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.export_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ExportDocuments_async - */ - async checkExportDocumentsProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.ExportDocumentsResponse, - protos.google.firestore.admin.v1.ExportDocumentsMetadata - > - > { - this._log.info('exportDocuments long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.exportDocuments, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.ExportDocumentsResponse, - protos.google.firestore.admin.v1.ExportDocumentsMetadata - >; - } - /** - * Imports documents into Google Cloud Firestore. Existing documents with the - * same name are overwritten. The import occurs in the background and its - * progress can be monitored and managed via the Operation resource that is - * created. If an ImportDocuments operation is cancelled, it is possible - * that a subset of the data has already been imported to Cloud Firestore. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Database to import into. Should be of the form: - * `projects/{project_id}/databases/{database_id}`. - * @param {string[]} request.collectionIds - * IDs of the collection groups to import. Unspecified means all collection - * groups that were included in the export. Each collection group in this list - * must be unique. - * @param {string} request.inputUriPrefix - * Location of the exported files. - * This must match the output_uri_prefix of an ExportDocumentsResponse from - * an export that has completed successfully. - * See: - * {@link protos.google.firestore.admin.v1.ExportDocumentsResponse.output_uri_prefix|google.firestore.admin.v1.ExportDocumentsResponse.output_uri_prefix}. - * @param {string[]} request.namespaceIds - * An empty list represents all namespaces. This is the preferred - * usage for databases that don't use namespaces. - * - * An empty string element represents the default namespace. This should be - * used if the database has data in non-default namespaces, but doesn't want - * to include them. Each namespace in this list must be unique. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.import_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ImportDocuments_async - */ - importDocuments( - request?: protos.google.firestore.admin.v1.IImportDocumentsRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - importDocuments( - request: protos.google.firestore.admin.v1.IImportDocumentsRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - importDocuments( - request: protos.google.firestore.admin.v1.IImportDocumentsRequest, - callback: Callback< - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - importDocuments( - request?: protos.google.firestore.admin.v1.IImportDocumentsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('importDocuments response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('importDocuments request %j', request); - return this.innerApiCalls - .importDocuments(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('importDocuments response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `importDocuments()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.import_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ImportDocuments_async - */ - async checkImportDocumentsProgress( - name: string, - ): Promise< - LROperation< - protos.google.protobuf.Empty, - protos.google.firestore.admin.v1.ImportDocumentsMetadata - > - > { - this._log.info('importDocuments long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.importDocuments, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.protobuf.Empty, - protos.google.firestore.admin.v1.ImportDocumentsMetadata - >; - } - /** - * Bulk deletes a subset of documents from Google Cloud Firestore. - * Documents created or updated after the underlying system starts to process - * the request will not be deleted. The bulk delete occurs in the background - * and its progress can be monitored and managed via the Operation resource - * that is created. - * - * For more details on bulk delete behavior, refer to: - * https://cloud.google.com/firestore/docs/manage-data/bulk-delete - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Database to operate. Should be of the form: - * `projects/{project_id}/databases/{database_id}`. - * @param {string[]} [request.collectionIds] - * Optional. IDs of the collection groups to delete. Unspecified means all - * collection groups. - * - * Each collection group in this list must be unique. - * @param {string[]} [request.namespaceIds] - * Optional. Namespaces to delete. - * - * An empty list means all namespaces. This is the recommended - * usage for databases that don't use namespaces. - * - * An empty string element represents the default namespace. This should be - * used if the database has data in non-default namespaces, but doesn't want - * to delete from them. - * - * Each namespace in this list must be unique. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.bulk_delete_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_BulkDeleteDocuments_async - */ - bulkDeleteDocuments( - request?: protos.google.firestore.admin.v1.IBulkDeleteDocumentsRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - bulkDeleteDocuments( - request: protos.google.firestore.admin.v1.IBulkDeleteDocumentsRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - bulkDeleteDocuments( - request: protos.google.firestore.admin.v1.IBulkDeleteDocumentsRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - bulkDeleteDocuments( - request?: protos.google.firestore.admin.v1.IBulkDeleteDocumentsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('bulkDeleteDocuments response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('bulkDeleteDocuments request %j', request); - return this.innerApiCalls - .bulkDeleteDocuments(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('bulkDeleteDocuments response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `bulkDeleteDocuments()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.bulk_delete_documents.js - * region_tag:firestore_v1_generated_FirestoreAdmin_BulkDeleteDocuments_async - */ - async checkBulkDeleteDocumentsProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.BulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.BulkDeleteDocumentsMetadata - > - > { - this._log.info('bulkDeleteDocuments long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.bulkDeleteDocuments, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.BulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.BulkDeleteDocumentsMetadata - >; - } - /** - * Create a database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}` - * @param {google.firestore.admin.v1.Database} request.database - * Required. The Database to create. - * @param {string} request.databaseId - * Required. The ID to use for the database, which will become the final - * component of the database's resource name. - * - * This value should be 4-63 characters. Valid characters are /{@link protos.0-9|a-z}-/ - * with first character a letter and the last a letter or a number. Must not - * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/. - * - * "(default)" database ID is also valid if the database is Standard edition. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateDatabase_async - */ - createDatabase( - request?: protos.google.firestore.admin.v1.ICreateDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - createDatabase( - request: protos.google.firestore.admin.v1.ICreateDatabaseRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - createDatabase( - request: protos.google.firestore.admin.v1.ICreateDatabaseRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - createDatabase( - request?: protos.google.firestore.admin.v1.ICreateDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('createDatabase response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('createDatabase request %j', request); - return this.innerApiCalls - .createDatabase(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('createDatabase response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `createDatabase()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.create_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CreateDatabase_async - */ - async checkCreateDatabaseProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.CreateDatabaseMetadata - > - > { - this._log.info('createDatabase long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.createDatabase, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.CreateDatabaseMetadata - >; - } - /** - * Updates a database. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.firestore.admin.v1.Database} request.database - * Required. The database to update. - * @param {google.protobuf.FieldMask} request.updateMask - * The list of fields to be updated. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.update_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_UpdateDatabase_async - */ - updateDatabase( - request?: protos.google.firestore.admin.v1.IUpdateDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - updateDatabase( - request: protos.google.firestore.admin.v1.IUpdateDatabaseRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - updateDatabase( - request: protos.google.firestore.admin.v1.IUpdateDatabaseRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - updateDatabase( - request?: protos.google.firestore.admin.v1.IUpdateDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - 'database.name': request.database!.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('updateDatabase response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('updateDatabase request %j', request); - return this.innerApiCalls - .updateDatabase(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('updateDatabase response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `updateDatabase()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.update_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_UpdateDatabase_async - */ - async checkUpdateDatabaseProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.UpdateDatabaseMetadata - > - > { - this._log.info('updateDatabase long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.updateDatabase, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.UpdateDatabaseMetadata - >; - } - /** - * Deletes a database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. A name of the form - * `projects/{project_id}/databases/{database_id}` - * @param {string} request.etag - * The current etag of the Database. - * If an etag is provided and does not match the current etag of the database, - * deletion will be blocked and a FAILED_PRECONDITION error will be returned. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteDatabase_async - */ - deleteDatabase( - request?: protos.google.firestore.admin.v1.IDeleteDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - deleteDatabase( - request: protos.google.firestore.admin.v1.IDeleteDatabaseRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - deleteDatabase( - request: protos.google.firestore.admin.v1.IDeleteDatabaseRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - deleteDatabase( - request?: protos.google.firestore.admin.v1.IDeleteDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('deleteDatabase response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('deleteDatabase request %j', request); - return this.innerApiCalls - .deleteDatabase(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('deleteDatabase response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `deleteDatabase()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.delete_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_DeleteDatabase_async - */ - async checkDeleteDatabaseProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.DeleteDatabaseMetadata - > - > { - this._log.info('deleteDatabase long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.deleteDatabase, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.DeleteDatabaseMetadata - >; - } - /** - * Creates a new database by restoring from an existing backup. - * - * The new database must be in the same cloud region or multi-region location - * as the existing backup. This behaves similar to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.CreateDatabase|FirestoreAdmin.CreateDatabase} - * except instead of creating a new empty database, a new database is created - * with the database type, index configuration, and documents from an existing - * backup. - * - * The {@link protos.google.longrunning.Operation|long-running operation} can be used to - * track the progress of the restore, with the Operation's - * {@link protos.google.longrunning.Operation.metadata|metadata} field type being the - * {@link protos.google.firestore.admin.v1.RestoreDatabaseMetadata|RestoreDatabaseMetadata}. - * The {@link protos.google.longrunning.Operation.response|response} type is the - * {@link protos.google.firestore.admin.v1.Database|Database} if the restore was - * successful. The new database is not readable or writeable until the LRO has - * completed. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The project to restore the database in. Format is - * `projects/{project_id}`. - * @param {string} request.databaseId - * Required. The ID to use for the database, which will become the final - * component of the database's resource name. This database ID must not be - * associated with an existing database. - * - * This value should be 4-63 characters. Valid characters are /{@link protos.0-9|a-z}-/ - * with first character a letter and the last a letter or a number. Must not - * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/. - * - * "(default)" database ID is also valid if the database is Standard edition. - * @param {string} request.backup - * Required. Backup to restore from. Must be from the same project as the - * parent. - * - * The restored database will be created in the same location as the source - * backup. - * - * Format is: `projects/{project_id}/locations/{location}/backups/{backup}` - * @param {google.firestore.admin.v1.Database.EncryptionConfig} [request.encryptionConfig] - * Optional. Encryption configuration for the restored database. - * - * If this field is not specified, the restored database will use - * the same encryption configuration as the backup, namely - * {@link protos.google.firestore.admin.v1.Database.EncryptionConfig.use_source_encryption|use_source_encryption}. - * @param {number[]} request.tags - * Optional. Immutable. Tags to be bound to the restored database. - * - * The tags should be provided in the format of - * `tagKeys/{tag_key_id} -> tagValues/{tag_value_id}`. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.restore_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_RestoreDatabase_async - */ - restoreDatabase( - request?: protos.google.firestore.admin.v1.IRestoreDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - restoreDatabase( - request: protos.google.firestore.admin.v1.IRestoreDatabaseRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - restoreDatabase( - request: protos.google.firestore.admin.v1.IRestoreDatabaseRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - restoreDatabase( - request?: protos.google.firestore.admin.v1.IRestoreDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('restoreDatabase response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('restoreDatabase request %j', request); - return this.innerApiCalls - .restoreDatabase(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('restoreDatabase response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `restoreDatabase()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.restore_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_RestoreDatabase_async - */ - async checkRestoreDatabaseProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.RestoreDatabaseMetadata - > - > { - this._log.info('restoreDatabase long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.restoreDatabase, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.RestoreDatabaseMetadata - >; - } - /** - * Creates a new database by cloning an existing one. - * - * The new database must be in the same cloud region or multi-region location - * as the existing database. This behaves similar to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.CreateDatabase|FirestoreAdmin.CreateDatabase} - * except instead of creating a new empty database, a new database is created - * with the database type, index configuration, and documents from an existing - * database. - * - * The {@link protos.google.longrunning.Operation|long-running operation} can be used to - * track the progress of the clone, with the Operation's - * {@link protos.google.longrunning.Operation.metadata|metadata} field type being the - * {@link protos.google.firestore.admin.v1.CloneDatabaseMetadata|CloneDatabaseMetadata}. - * The {@link protos.google.longrunning.Operation.response|response} type is the - * {@link protos.google.firestore.admin.v1.Database|Database} if the clone was - * successful. The new database is not readable or writeable until the LRO has - * completed. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The project to clone the database in. Format is - * `projects/{project_id}`. - * @param {string} request.databaseId - * Required. The ID to use for the database, which will become the final - * component of the database's resource name. This database ID must not be - * associated with an existing database. - * - * This value should be 4-63 characters. Valid characters are /{@link protos.0-9|a-z}-/ - * with first character a letter and the last a letter or a number. Must not - * be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/. - * - * "(default)" database ID is also valid if the database is Standard edition. - * @param {google.firestore.admin.v1.PitrSnapshot} request.pitrSnapshot - * Required. Specification of the PITR data to clone from. The source database - * must exist. - * - * The cloned database will be created in the same location as the source - * database. - * @param {google.firestore.admin.v1.Database.EncryptionConfig} [request.encryptionConfig] - * Optional. Encryption configuration for the cloned database. - * - * If this field is not specified, the cloned database will use - * the same encryption configuration as the source database, namely - * {@link protos.google.firestore.admin.v1.Database.EncryptionConfig.use_source_encryption|use_source_encryption}. - * @param {number[]} request.tags - * Optional. Immutable. Tags to be bound to the cloned database. - * - * The tags should be provided in the format of - * `tagKeys/{tag_key_id} -> tagValues/{tag_value_id}`. - * @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 - * a long running operation. Its `promise()` method returns a promise - * you can `await` for. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.clone_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CloneDatabase_async - */ - cloneDatabase( - request?: protos.google.firestore.admin.v1.ICloneDatabaseRequest, - options?: CallOptions, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - >; - cloneDatabase( - request: protos.google.firestore.admin.v1.ICloneDatabaseRequest, - options: CallOptions, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - cloneDatabase( - request: protos.google.firestore.admin.v1.ICloneDatabaseRequest, - callback: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): void; - cloneDatabase( - request?: protos.google.firestore.admin.v1.ICloneDatabaseRequest, - optionsOrCallback?: - | CallOptions - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - callback?: Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const routingParameter = {}; - { - const fieldValue = request.pitrSnapshot?.database; - if (fieldValue !== undefined && fieldValue !== null) { - const match = fieldValue - .toString() - .match(RegExp('projects/(?[^/]+)(?:/.*)?')); - if (match) { - const parameterValue = match.groups?.['project_id'] ?? fieldValue; - Object.assign(routingParameter, {project_id: parameterValue}); - } - } - } - { - const fieldValue = request.pitrSnapshot?.database; - if (fieldValue !== undefined && fieldValue !== null) { - const match = fieldValue - .toString() - .match( - RegExp('projects/[^/]+/databases/(?[^/]+)(?:/.*)?'), - ); - if (match) { - const parameterValue = match.groups?.['database_id'] ?? fieldValue; - Object.assign(routingParameter, {database_id: parameterValue}); - } - } - } - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams(routingParameter); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | Callback< - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, rawResponse, _) => { - this._log.info('cloneDatabase response %j', rawResponse); - callback!(error, response, rawResponse, _); // We verified callback above. - } - : undefined; - this._log.info('cloneDatabase request %j', request); - return this.innerApiCalls - .cloneDatabase(request, options, wrappedCallback) - ?.then( - ([response, rawResponse, _]: [ - LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >, - protos.google.longrunning.IOperation | undefined, - {} | undefined, - ]) => { - this._log.info('cloneDatabase response %j', rawResponse); - return [response, rawResponse, _]; - }, - ); - } - /** - * Check the status of the long running operation returned by `cloneDatabase()`. - * @param {String} name - * The operation name that will be passed. - * @returns {Promise} - The promise which resolves to an object. - * The decoded operation object has result and metadata field to get information from. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.clone_database.js - * region_tag:firestore_v1_generated_FirestoreAdmin_CloneDatabase_async - */ - async checkCloneDatabaseProgress( - name: string, - ): Promise< - LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.CloneDatabaseMetadata - > - > { - this._log.info('cloneDatabase long-running'); - const request = - new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( - {name}, - ); - const [operation] = await this.operationsClient.getOperation(request); - const decodeOperation = new this._gaxModule.Operation( - operation, - this.descriptors.longrunning.cloneDatabase, - this._gaxModule.createDefaultBackoffSettings(), - ); - return decodeOperation as LROperation< - protos.google.firestore.admin.v1.Database, - protos.google.firestore.admin.v1.CloneDatabaseMetadata - >; - } - /** - * Lists composite indexes. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListIndexes|FirestoreAdmin.ListIndexes}, - * that may be used to get the next page of results. - * @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 Array of {@link protos.google.firestore.admin.v1.Index|Index}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listIndexesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listIndexes( - request?: protos.google.firestore.admin.v1.IListIndexesRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IIndex[], - protos.google.firestore.admin.v1.IListIndexesRequest | null, - protos.google.firestore.admin.v1.IListIndexesResponse, - ] - >; - listIndexes( - request: protos.google.firestore.admin.v1.IListIndexesRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.admin.v1.IListIndexesRequest, - protos.google.firestore.admin.v1.IListIndexesResponse | null | undefined, - protos.google.firestore.admin.v1.IIndex - >, - ): void; - listIndexes( - request: protos.google.firestore.admin.v1.IListIndexesRequest, - callback: PaginationCallback< - protos.google.firestore.admin.v1.IListIndexesRequest, - protos.google.firestore.admin.v1.IListIndexesResponse | null | undefined, - protos.google.firestore.admin.v1.IIndex - >, - ): void; - listIndexes( - request?: protos.google.firestore.admin.v1.IListIndexesRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.admin.v1.IListIndexesRequest, - | protos.google.firestore.admin.v1.IListIndexesResponse - | null - | undefined, - protos.google.firestore.admin.v1.IIndex - >, - callback?: PaginationCallback< - protos.google.firestore.admin.v1.IListIndexesRequest, - protos.google.firestore.admin.v1.IListIndexesResponse | null | undefined, - protos.google.firestore.admin.v1.IIndex - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IIndex[], - protos.google.firestore.admin.v1.IListIndexesRequest | null, - protos.google.firestore.admin.v1.IListIndexesResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.admin.v1.IListIndexesRequest, - | protos.google.firestore.admin.v1.IListIndexesResponse - | null - | undefined, - protos.google.firestore.admin.v1.IIndex - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listIndexes values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listIndexes request %j', request); - return this.innerApiCalls - .listIndexes(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.admin.v1.IIndex[], - protos.google.firestore.admin.v1.IListIndexesRequest | null, - protos.google.firestore.admin.v1.IListIndexesResponse, - ]) => { - this._log.info('listIndexes values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listIndexes`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListIndexes|FirestoreAdmin.ListIndexes}, - * that may be used to get the next page of results. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.admin.v1.Index|Index} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listIndexesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listIndexesStream( - request?: protos.google.firestore.admin.v1.IListIndexesRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listIndexes']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listIndexes stream %j', request); - return this.descriptors.page.listIndexes.createStream( - this.innerApiCalls.listIndexes as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listIndexes`, but 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.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListIndexes|FirestoreAdmin.ListIndexes}, - * that may be used to get the next page of results. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.admin.v1.Index|Index}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_indexes.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListIndexes_async - */ - listIndexesAsync( - request?: protos.google.firestore.admin.v1.IListIndexesRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listIndexes']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listIndexes iterate %j', request); - return this.descriptors.page.listIndexes.asyncIterate( - this.innerApiCalls['listIndexes'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * Lists the field configuration and metadata for this database. - * - * Currently, - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * only supports listing fields that have been explicitly overridden. To issue - * this query, call - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * with the filter set to `indexConfig.usesAncestorConfig:false` or - * `ttlConfig:*`. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. Currently, - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * only supports listing fields that have been explicitly overridden. To issue - * this query, call - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * with a filter that includes `indexConfig.usesAncestorConfig:false` or - * `ttlConfig:*`. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields}, - * that may be used to get the next page of results. - * @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 Array of {@link protos.google.firestore.admin.v1.Field|Field}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listFieldsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listFields( - request?: protos.google.firestore.admin.v1.IListFieldsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.admin.v1.IField[], - protos.google.firestore.admin.v1.IListFieldsRequest | null, - protos.google.firestore.admin.v1.IListFieldsResponse, - ] - >; - listFields( - request: protos.google.firestore.admin.v1.IListFieldsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.admin.v1.IListFieldsRequest, - protos.google.firestore.admin.v1.IListFieldsResponse | null | undefined, - protos.google.firestore.admin.v1.IField - >, - ): void; - listFields( - request: protos.google.firestore.admin.v1.IListFieldsRequest, - callback: PaginationCallback< - protos.google.firestore.admin.v1.IListFieldsRequest, - protos.google.firestore.admin.v1.IListFieldsResponse | null | undefined, - protos.google.firestore.admin.v1.IField - >, - ): void; - listFields( - request?: protos.google.firestore.admin.v1.IListFieldsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.admin.v1.IListFieldsRequest, - | protos.google.firestore.admin.v1.IListFieldsResponse - | null - | undefined, - protos.google.firestore.admin.v1.IField - >, - callback?: PaginationCallback< - protos.google.firestore.admin.v1.IListFieldsRequest, - protos.google.firestore.admin.v1.IListFieldsResponse | null | undefined, - protos.google.firestore.admin.v1.IField - >, - ): Promise< - [ - protos.google.firestore.admin.v1.IField[], - protos.google.firestore.admin.v1.IListFieldsRequest | null, - protos.google.firestore.admin.v1.IListFieldsResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.admin.v1.IListFieldsRequest, - | protos.google.firestore.admin.v1.IListFieldsResponse - | null - | undefined, - protos.google.firestore.admin.v1.IField - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listFields values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listFields request %j', request); - return this.innerApiCalls - .listFields(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.admin.v1.IField[], - protos.google.firestore.admin.v1.IListFieldsRequest | null, - protos.google.firestore.admin.v1.IListFieldsResponse, - ]) => { - this._log.info('listFields values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listFields`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. Currently, - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * only supports listing fields that have been explicitly overridden. To issue - * this query, call - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * with a filter that includes `indexConfig.usesAncestorConfig:false` or - * `ttlConfig:*`. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields}, - * that may be used to get the next page of results. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.admin.v1.Field|Field} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listFieldsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listFieldsStream( - request?: protos.google.firestore.admin.v1.IListFieldsRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listFields']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listFields stream %j', request); - return this.descriptors.page.listFields.createStream( - this.innerApiCalls.listFields as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listFields`, but 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.parent - * Required. A parent name of the form - * `projects/{project_id}/databases/{database_id}/collectionGroups/{collection_id}` - * @param {string} request.filter - * The filter to apply to list results. Currently, - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * only supports listing fields that have been explicitly overridden. To issue - * this query, call - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields} - * with a filter that includes `indexConfig.usesAncestorConfig:false` or - * `ttlConfig:*`. - * @param {number} request.pageSize - * The number of results to return. - * @param {string} request.pageToken - * A page token, returned from a previous call to - * {@link protos.google.firestore.admin.v1.FirestoreAdmin.ListFields|FirestoreAdmin.ListFields}, - * that may be used to get the next page of results. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.admin.v1.Field|Field}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore_admin.list_fields.js - * region_tag:firestore_v1_generated_FirestoreAdmin_ListFields_async - */ - listFieldsAsync( - request?: protos.google.firestore.admin.v1.IListFieldsRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listFields']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listFields iterate %j', request); - return this.descriptors.page.listFields.asyncIterate( - this.innerApiCalls['listFields'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * 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 {@link google.cloud.location.Location | Location}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * 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 { - 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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.location.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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * 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 { - 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 {@link - * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.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 - * {@link google.longrunning.Operation | google.longrunning.Operation}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing - * {@link google.longrunning.Operation | 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, - optionsOrCallback?: - | 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]> { - let options: gax.CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as gax.CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - 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 {@link - * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.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 | 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 { - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - 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 {@link - * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the - * details. - * @param {function(?Error)=} callback - * The function which will be called with the result of the API call. - * @returns {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, - optionsOrCallback?: - | gax.CallOptions - | Callback< - protos.google.longrunning.CancelOperationRequest, - protos.google.protobuf.Empty, - {} | undefined | null - >, - callback?: Callback< - protos.google.longrunning.CancelOperationRequest, - protos.google.protobuf.Empty, - {} | undefined | null - >, - ): Promise { - let options: gax.CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as gax.CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - 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 {@link - * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} - * for the details. - * @param {function(?Error)=} callback - * The function which will be called with the result of the API call. - * @returns {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, - optionsOrCallback?: - | 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 { - let options: gax.CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as gax.CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - return this.operationsClient.deleteOperation(request, options, callback); - } - - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified backup resource name string. - * - * @param {string} project - * @param {string} location - * @param {string} backup - * @returns {string} Resource name string. - */ - backupPath(project: string, location: string, backup: string) { - return this.pathTemplates.backupPathTemplate.render({ - project: project, - location: location, - backup: backup, - }); - } - - /** - * Parse the project from Backup resource. - * - * @param {string} backupName - * A fully-qualified path representing Backup resource. - * @returns {string} A string representing the project. - */ - matchProjectFromBackupName(backupName: string) { - return this.pathTemplates.backupPathTemplate.match(backupName).project; - } - - /** - * Parse the location from Backup resource. - * - * @param {string} backupName - * A fully-qualified path representing Backup resource. - * @returns {string} A string representing the location. - */ - matchLocationFromBackupName(backupName: string) { - return this.pathTemplates.backupPathTemplate.match(backupName).location; - } - - /** - * Parse the backup from Backup resource. - * - * @param {string} backupName - * A fully-qualified path representing Backup resource. - * @returns {string} A string representing the backup. - */ - matchBackupFromBackupName(backupName: string) { - return this.pathTemplates.backupPathTemplate.match(backupName).backup; - } - - /** - * Return a fully-qualified backupSchedule resource name string. - * - * @param {string} project - * @param {string} database - * @param {string} backup_schedule - * @returns {string} Resource name string. - */ - backupSchedulePath( - project: string, - database: string, - backupSchedule: string, - ) { - return this.pathTemplates.backupSchedulePathTemplate.render({ - project: project, - database: database, - backup_schedule: backupSchedule, - }); - } - - /** - * Parse the project from BackupSchedule resource. - * - * @param {string} backupScheduleName - * A fully-qualified path representing BackupSchedule resource. - * @returns {string} A string representing the project. - */ - matchProjectFromBackupScheduleName(backupScheduleName: string) { - return this.pathTemplates.backupSchedulePathTemplate.match( - backupScheduleName, - ).project; - } - - /** - * Parse the database from BackupSchedule resource. - * - * @param {string} backupScheduleName - * A fully-qualified path representing BackupSchedule resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromBackupScheduleName(backupScheduleName: string) { - return this.pathTemplates.backupSchedulePathTemplate.match( - backupScheduleName, - ).database; - } - - /** - * Parse the backup_schedule from BackupSchedule resource. - * - * @param {string} backupScheduleName - * A fully-qualified path representing BackupSchedule resource. - * @returns {string} A string representing the backup_schedule. - */ - matchBackupScheduleFromBackupScheduleName(backupScheduleName: string) { - return this.pathTemplates.backupSchedulePathTemplate.match( - backupScheduleName, - ).backup_schedule; - } - - /** - * Return a fully-qualified collectionGroup resource name string. - * - * @param {string} project - * @param {string} database - * @param {string} collection - * @returns {string} Resource name string. - */ - collectionGroupPath(project: string, database: string, collection: string) { - return this.pathTemplates.collectionGroupPathTemplate.render({ - project: project, - database: database, - collection: collection, - }); - } - - /** - * Parse the project from CollectionGroup resource. - * - * @param {string} collectionGroupName - * A fully-qualified path representing CollectionGroup resource. - * @returns {string} A string representing the project. - */ - matchProjectFromCollectionGroupName(collectionGroupName: string) { - return this.pathTemplates.collectionGroupPathTemplate.match( - collectionGroupName, - ).project; - } - - /** - * Parse the database from CollectionGroup resource. - * - * @param {string} collectionGroupName - * A fully-qualified path representing CollectionGroup resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromCollectionGroupName(collectionGroupName: string) { - return this.pathTemplates.collectionGroupPathTemplate.match( - collectionGroupName, - ).database; - } - - /** - * Parse the collection from CollectionGroup resource. - * - * @param {string} collectionGroupName - * A fully-qualified path representing CollectionGroup resource. - * @returns {string} A string representing the collection. - */ - matchCollectionFromCollectionGroupName(collectionGroupName: string) { - return this.pathTemplates.collectionGroupPathTemplate.match( - collectionGroupName, - ).collection; - } - - /** - * Return a fully-qualified database resource name string. - * - * @param {string} project - * @param {string} database - * @returns {string} Resource name string. - */ - databasePath(project: string, database: string) { - return this.pathTemplates.databasePathTemplate.render({ - project: project, - database: database, - }); - } - - /** - * Parse the project from Database resource. - * - * @param {string} databaseName - * A fully-qualified path representing Database resource. - * @returns {string} A string representing the project. - */ - matchProjectFromDatabaseName(databaseName: string) { - return this.pathTemplates.databasePathTemplate.match(databaseName).project; - } - - /** - * Parse the database from Database resource. - * - * @param {string} databaseName - * A fully-qualified path representing Database resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromDatabaseName(databaseName: string) { - return this.pathTemplates.databasePathTemplate.match(databaseName).database; - } - - /** - * Return a fully-qualified field resource name string. - * - * @param {string} project - * @param {string} database - * @param {string} collection - * @param {string} field - * @returns {string} Resource name string. - */ - fieldPath( - project: string, - database: string, - collection: string, - field: string, - ) { - return this.pathTemplates.fieldPathTemplate.render({ - project: project, - database: database, - collection: collection, - field: field, - }); - } - - /** - * Parse the project from Field resource. - * - * @param {string} fieldName - * A fully-qualified path representing Field resource. - * @returns {string} A string representing the project. - */ - matchProjectFromFieldName(fieldName: string) { - return this.pathTemplates.fieldPathTemplate.match(fieldName).project; - } - - /** - * Parse the database from Field resource. - * - * @param {string} fieldName - * A fully-qualified path representing Field resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromFieldName(fieldName: string) { - return this.pathTemplates.fieldPathTemplate.match(fieldName).database; - } - - /** - * Parse the collection from Field resource. - * - * @param {string} fieldName - * A fully-qualified path representing Field resource. - * @returns {string} A string representing the collection. - */ - matchCollectionFromFieldName(fieldName: string) { - return this.pathTemplates.fieldPathTemplate.match(fieldName).collection; - } - - /** - * Parse the field from Field resource. - * - * @param {string} fieldName - * A fully-qualified path representing Field resource. - * @returns {string} A string representing the field. - */ - matchFieldFromFieldName(fieldName: string) { - return this.pathTemplates.fieldPathTemplate.match(fieldName).field; - } - - /** - * Return a fully-qualified index resource name string. - * - * @param {string} project - * @param {string} database - * @param {string} collection - * @param {string} index - * @returns {string} Resource name string. - */ - indexPath( - project: string, - database: string, - collection: string, - index: string, - ) { - return this.pathTemplates.indexPathTemplate.render({ - project: project, - database: database, - collection: collection, - index: index, - }); - } - - /** - * Parse the project from Index resource. - * - * @param {string} indexName - * A fully-qualified path representing Index resource. - * @returns {string} A string representing the project. - */ - matchProjectFromIndexName(indexName: string) { - return this.pathTemplates.indexPathTemplate.match(indexName).project; - } - - /** - * Parse the database from Index resource. - * - * @param {string} indexName - * A fully-qualified path representing Index resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromIndexName(indexName: string) { - return this.pathTemplates.indexPathTemplate.match(indexName).database; - } - - /** - * Parse the collection from Index resource. - * - * @param {string} indexName - * A fully-qualified path representing Index resource. - * @returns {string} A string representing the collection. - */ - matchCollectionFromIndexName(indexName: string) { - return this.pathTemplates.indexPathTemplate.match(indexName).collection; - } - - /** - * Parse the index from Index resource. - * - * @param {string} indexName - * A fully-qualified path representing Index resource. - * @returns {string} A string representing the index. - */ - matchIndexFromIndexName(indexName: string) { - return this.pathTemplates.indexPathTemplate.match(indexName).index; - } - - /** - * Return a fully-qualified location resource name string. - * - * @param {string} project - * @param {string} location - * @returns {string} Resource name string. - */ - locationPath(project: string, location: string) { - return this.pathTemplates.locationPathTemplate.render({ - project: project, - location: location, - }); - } - - /** - * Parse the project from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the project. - */ - matchProjectFromLocationName(locationName: string) { - return this.pathTemplates.locationPathTemplate.match(locationName).project; - } - - /** - * Parse the location from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the location. - */ - matchLocationFromLocationName(locationName: string) { - return this.pathTemplates.locationPathTemplate.match(locationName).location; - } - - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project: string) { - return this.pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this.pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified userCreds resource name string. - * - * @param {string} project - * @param {string} database - * @param {string} user_creds - * @returns {string} Resource name string. - */ - userCredsPath(project: string, database: string, userCreds: string) { - return this.pathTemplates.userCredsPathTemplate.render({ - project: project, - database: database, - user_creds: userCreds, - }); - } - - /** - * Parse the project from UserCreds resource. - * - * @param {string} userCredsName - * A fully-qualified path representing UserCreds resource. - * @returns {string} A string representing the project. - */ - matchProjectFromUserCredsName(userCredsName: string) { - return this.pathTemplates.userCredsPathTemplate.match(userCredsName) - .project; - } - - /** - * Parse the database from UserCreds resource. - * - * @param {string} userCredsName - * A fully-qualified path representing UserCreds resource. - * @returns {string} A string representing the database. - */ - matchDatabaseFromUserCredsName(userCredsName: string) { - return this.pathTemplates.userCredsPathTemplate.match(userCredsName) - .database; - } - - /** - * Parse the user_creds from UserCreds resource. - * - * @param {string} userCredsName - * A fully-qualified path representing UserCreds resource. - * @returns {string} A string representing the user_creds. - */ - matchUserCredsFromUserCredsName(userCredsName: string) { - return this.pathTemplates.userCredsPathTemplate.match(userCredsName) - .user_creds; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.firestoreAdminStub && !this._terminated) { - return this.firestoreAdminStub.then(stub => { - this._log.info('ending gRPC channel'); - this._terminated = true; - stub.close(); - this.locationsClient.close().catch(err => { - throw err; - }); - void this.operationsClient.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/handwritten/firestore/dev/src/v1/firestore_admin_client_config.json b/handwritten/firestore/dev/src/v1/firestore_admin_client_config.json deleted file mode 100644 index 101263bf1244..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_admin_client_config.json +++ /dev/null @@ -1,172 +0,0 @@ -{ - "interfaces": { - "google.firestore.admin.v1.FirestoreAdmin": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "deadline_exceeded_internal_unavailable": [ - "DEADLINE_EXCEEDED", - "INTERNAL", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "CreateIndex": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListIndexes": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "GetIndex": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "DeleteIndex": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "GetField": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "UpdateField": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListFields": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "ExportDocuments": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ImportDocuments": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "BulkDeleteDocuments": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "CreateDatabase": { - "timeout_millis": 120000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "GetDatabase": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListDatabases": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "UpdateDatabase": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DeleteDatabase": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "CreateUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "GetUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "EnableUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DisableUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ResetUserPassword": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DeleteUserCreds": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "GetBackup": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListBackups": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DeleteBackup": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "RestoreDatabase": { - "timeout_millis": 120000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "CreateBackupSchedule": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "GetBackupSchedule": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListBackupSchedules": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "UpdateBackupSchedule": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DeleteBackupSchedule": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "CloneDatabase": { - "timeout_millis": 120000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - } - } - } - } -} diff --git a/handwritten/firestore/dev/src/v1/firestore_admin_proto_list.json b/handwritten/firestore/dev/src/v1/firestore_admin_proto_list.json deleted file mode 100644 index 8b50432407cb..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_admin_proto_list.json +++ /dev/null @@ -1,13 +0,0 @@ -[ - "../../protos/google/firestore/admin/v1/backup.proto", - "../../protos/google/firestore/admin/v1/database.proto", - "../../protos/google/firestore/admin/v1/field.proto", - "../../protos/google/firestore/admin/v1/firestore_admin.proto", - "../../protos/google/firestore/admin/v1/index.proto", - "../../protos/google/firestore/admin/v1/location.proto", - "../../protos/google/firestore/admin/v1/operation.proto", - "../../protos/google/firestore/admin/v1/realtime_updates.proto", - "../../protos/google/firestore/admin/v1/schedule.proto", - "../../protos/google/firestore/admin/v1/snapshot.proto", - "../../protos/google/firestore/admin/v1/user_creds.proto" -] diff --git a/handwritten/firestore/dev/src/v1/firestore_client.ts b/handwritten/firestore/dev/src/v1/firestore_client.ts deleted file mode 100644 index add6b41abf34..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_client.ts +++ /dev/null @@ -1,2927 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type { - Callback, - CallOptions, - Descriptors, - ClientOptions, - PaginationCallback, - GaxCall, - LocationsClient, - LocationProtos, -} from 'google-gax'; -import {Transform, PassThrough} from 'stream'; -import * as protos from '../../protos/firestore_v1_proto_api'; -import jsonProtos = require('../../protos/v1.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; - -/** - * Client JSON configuration object, loaded from - * `src/v1/firestore_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './firestore_client_config.json'; -const version = require('../../../package.json').version; - -/** - * The Cloud Firestore service. - * - * Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL - * document database that simplifies storing, syncing, and querying data for - * your mobile, web, and IoT apps at global scale. Its client libraries provide - * live synchronization and offline support, while its security features and - * integrations with Firebase and Google Cloud Platform accelerate building - * truly serverless apps. - * @class - * @memberof v1 - */ -export class FirestoreClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - private _universeDomain: string; - private _servicePath: string; - private _log = logging.log('firestore'); - - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - locationsClient: LocationsClient; - firestoreStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of FirestoreClient. - * - * @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/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * 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 FirestoreClient({fallback: true}, gax); - * ``` - */ - constructor( - opts?: ClientOptions, - gaxInstance?: typeof gax | typeof gax.fallback, - ) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof FirestoreClient; - if ( - opts?.universe_domain && - opts?.universeDomain && - opts?.universe_domain !== opts?.universeDomain - ) { - throw new Error( - 'Please set either universe_domain or universeDomain, but not both.', - ); - } - const universeDomainEnvVar = - typeof process === 'object' && typeof process.env === 'object' - ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] - : undefined; - this._universeDomain = - opts?.universeDomain ?? - opts?.universe_domain ?? - universeDomainEnvVar ?? - 'googleapis.com'; - this._servicePath = 'firestore.' + this._universeDomain; - const servicePath = - opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!( - opts?.servicePath || opts?.apiEndpoint - ); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = - opts?.fallback ?? - (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign( - { - servicePath, - port, - clientConfig, - fallback, - }, - opts, - ); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== this._servicePath && !('scopes' in opts)) { - 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 ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = this._servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === this._servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - this.locationsClient = new this._gaxModule.LocationsClient( - this._gaxGrpc, - opts, - ); - - // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; - if (typeof process === 'object' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listDocuments: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'documents', - ), - partitionQuery: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'partitions', - ), - listCollectionIds: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'collectionIds', - ), - }; - - // Some of the methods on this service provide streaming responses. - // Provide descriptors for these. - this.descriptors.stream = { - batchGetDocuments: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - runQuery: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - executePipeline: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - runAggregationQuery: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - write: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.BIDI_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - listen: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.BIDI_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.firestore.v1.Firestore', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')}, - ); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.firestoreStub) { - return this.firestoreStub; - } - - // Clone the existing options to avoid mutating shared state - const clientOpts: ClientOptions = Object.assign({}, this._opts); - - const flowControlWindowSize = 256 * 1024; // 256 KB - const maxMessageLength = 17 * 1024 * 1024; // 17 MB (16 MB documents + overlead) - clientOpts.grpcOptions = Object.assign( - { - 'grpc.max_receive_message_length': maxMessageLength, - 'grpc.max_send_message_length': maxMessageLength, - 'grpc-node.flow_control_window': flowControlWindowSize, - }, - clientOpts.grpcOptions, // Can overwrite grpc options - ); - - // Pass the updated options into the stub creator - this.firestoreStub = this._gaxGrpc.createStub( - clientOpts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.firestore.v1.Firestore', - ) - : (this._protos as any).google.firestore.v1.Firestore, - clientOpts, - this._providedCustomServicePath, - ) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const firestoreStubMethods = [ - 'getDocument', - 'listDocuments', - 'updateDocument', - 'deleteDocument', - 'batchGetDocuments', - 'beginTransaction', - 'commit', - 'rollback', - 'runQuery', - 'executePipeline', - 'runAggregationQuery', - 'partitionQuery', - 'write', - 'listen', - 'listCollectionIds', - 'batchWrite', - 'createDocument', - ]; - for (const methodName of firestoreStubMethods) { - const callPromise = this.firestoreStub.then( - stub => - (...args: Array<{}>) => { - if (this._terminated) { - if (methodName in this.descriptors.stream) { - const stream = new PassThrough({objectMode: true}); - setImmediate(() => { - stream.emit( - 'error', - new this._gaxModule.GoogleError( - 'The client has already been closed.', - ), - ); - }); - return stream; - } - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error | null | undefined) => () => { - throw err; - }, - ); - - const descriptor = - this.descriptors.page[methodName] || - this.descriptors.stream[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback, - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.firestoreStub; - } - - /** - * The DNS address for this API service. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static servicePath is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static apiEndpoint is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - get apiEndpoint() { - return this._servicePath; - } - - get universeDomain() { - return this._universeDomain; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/datastore', - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId( - callback?: Callback, - ): Promise | void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - /** - * Gets a single document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the Document to get. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * @param {google.firestore.v1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Reads the document in a transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Reads the version of the document at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @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 {@link protos.google.firestore.v1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.get_document.js - * region_tag:firestore_v1_generated_Firestore_GetDocument_async - */ - getDocument( - request?: protos.google.firestore.v1.IGetDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | undefined, - {} | undefined, - ] - >; - getDocument( - request: protos.google.firestore.v1.IGetDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDocument( - request: protos.google.firestore.v1.IGetDocumentRequest, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDocument( - request?: protos.google.firestore.v1.IGetDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IGetDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Updates or inserts a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.firestore.v1.Document} request.document - * Required. The updated document. - * Creates the document if it does not already exist. - * @param {google.firestore.v1.DocumentMask} request.updateMask - * The fields to update. - * None of the field paths in the mask may contain a reserved name. - * - * If the document exists on the server and has fields not referenced in the - * mask, they are left unchanged. - * Fields referenced in the mask, but not present in the input document, are - * deleted from the document on the server. - * @param {google.firestore.v1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {google.firestore.v1.Precondition} request.currentDocument - * An optional precondition on the document. - * The request will fail if this is set and not met by the target document. - * @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 {@link protos.google.firestore.v1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.update_document.js - * region_tag:firestore_v1_generated_Firestore_UpdateDocument_async - */ - updateDocument( - request?: protos.google.firestore.v1.IUpdateDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | undefined, - {} | undefined, - ] - >; - updateDocument( - request: protos.google.firestore.v1.IUpdateDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - updateDocument( - request: protos.google.firestore.v1.IUpdateDocumentRequest, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - updateDocument( - request?: protos.google.firestore.v1.IUpdateDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - 'document.name': request.document!.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('updateDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('updateDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .updateDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.IUpdateDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('updateDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the Document to delete. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * @param {google.firestore.v1.Precondition} request.currentDocument - * An optional precondition on the document. - * The request will fail if this is set and not met by the target document. - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.delete_document.js - * region_tag:firestore_v1_generated_Firestore_DeleteDocument_async - */ - deleteDocument( - request?: protos.google.firestore.v1.IDeleteDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | undefined, - {} | undefined, - ] - >; - deleteDocument( - request: protos.google.firestore.v1.IDeleteDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteDocument( - request: protos.google.firestore.v1.IDeleteDocumentRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteDocument( - request?: protos.google.firestore.v1.IDeleteDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IDeleteDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('deleteDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Starts a new transaction. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {google.firestore.v1.TransactionOptions} request.options - * The options for the transaction. - * Defaults to a read-write transaction. - * @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 {@link protos.google.firestore.v1.BeginTransactionResponse|BeginTransactionResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.begin_transaction.js - * region_tag:firestore_v1_generated_Firestore_BeginTransaction_async - */ - beginTransaction( - request?: protos.google.firestore.v1.IBeginTransactionRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | undefined, - {} | undefined, - ] - >; - beginTransaction( - request: protos.google.firestore.v1.IBeginTransactionRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | null | undefined, - {} | null | undefined - >, - ): void; - beginTransaction( - request: protos.google.firestore.v1.IBeginTransactionRequest, - callback: Callback< - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | null | undefined, - {} | null | undefined - >, - ): void; - beginTransaction( - request?: protos.google.firestore.v1.IBeginTransactionRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.IBeginTransactionResponse, - | protos.google.firestore.v1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('beginTransaction request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.IBeginTransactionResponse, - | protos.google.firestore.v1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('beginTransaction response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .beginTransaction(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.IBeginTransactionResponse, - protos.google.firestore.v1.IBeginTransactionRequest | undefined, - {} | undefined, - ]) => { - this._log.info('beginTransaction response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Commits a transaction, while optionally updating documents. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {number[]} request.writes - * The writes to apply. - * - * Always executed atomically and in order. - * @param {Buffer} request.transaction - * If set, applies all writes in this transaction, and commits it. - * @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 {@link protos.google.firestore.v1.CommitResponse|CommitResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.commit.js - * region_tag:firestore_v1_generated_Firestore_Commit_async - */ - commit( - request?: protos.google.firestore.v1.ICommitRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | undefined, - {} | undefined, - ] - >; - commit( - request: protos.google.firestore.v1.ICommitRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): void; - commit( - request: protos.google.firestore.v1.ICommitRequest, - callback: Callback< - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): void; - commit( - request?: protos.google.firestore.v1.ICommitRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('commit request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('commit response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .commit(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.ICommitResponse, - protos.google.firestore.v1.ICommitRequest | undefined, - {} | undefined, - ]) => { - this._log.info('commit response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Rolls back a transaction. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {Buffer} request.transaction - * Required. The transaction to roll back. - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.rollback.js - * region_tag:firestore_v1_generated_Firestore_Rollback_async - */ - rollback( - request?: protos.google.firestore.v1.IRollbackRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | undefined, - {} | undefined, - ] - >; - rollback( - request: protos.google.firestore.v1.IRollbackRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): void; - rollback( - request: protos.google.firestore.v1.IRollbackRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): void; - rollback( - request?: protos.google.firestore.v1.IRollbackRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('rollback request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('rollback response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .rollback(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1.IRollbackRequest | undefined, - {} | undefined, - ]) => { - this._log.info('rollback response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Applies a batch of write operations. - * - * The BatchWrite method does not apply the write operations atomically - * and can apply them out of order. Method does not allow more than one write - * per document. Each write succeeds or fails independently. See the - * {@link protos.google.firestore.v1.BatchWriteResponse|BatchWriteResponse} for the - * success status of each write. - * - * If you require an atomically applied set of writes, use - * {@link protos.google.firestore.v1.Firestore.Commit|Commit} instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {number[]} request.writes - * The writes to apply. - * - * Method does not apply writes atomically and does not guarantee ordering. - * Each write succeeds or fails independently. You cannot write to the same - * document more than once per request. - * @param {number[]} request.labels - * Labels associated with this batch write. - * @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 {@link protos.google.firestore.v1.BatchWriteResponse|BatchWriteResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.batch_write.js - * region_tag:firestore_v1_generated_Firestore_BatchWrite_async - */ - batchWrite( - request?: protos.google.firestore.v1.IBatchWriteRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | undefined, - {} | undefined, - ] - >; - batchWrite( - request: protos.google.firestore.v1.IBatchWriteRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): void; - batchWrite( - request: protos.google.firestore.v1.IBatchWriteRequest, - callback: Callback< - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): void; - batchWrite( - request?: protos.google.firestore.v1.IBatchWriteRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('batchWrite request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('batchWrite response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .batchWrite(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.IBatchWriteResponse, - protos.google.firestore.v1.IBatchWriteRequest | undefined, - {} | undefined, - ]) => { - this._log.info('batchWrite response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Creates a new document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource. For example: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}` - * @param {string} request.collectionId - * Required. The collection ID, relative to `parent`, to list. For example: - * `chatrooms`. - * @param {string} request.documentId - * The client-assigned document ID to use for this document. - * - * Optional. If not specified, an ID will be assigned by the service. - * @param {google.firestore.v1.Document} request.document - * Required. The document to create. `name` must not be set. - * @param {google.firestore.v1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @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 {@link protos.google.firestore.v1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.create_document.js - * region_tag:firestore_v1_generated_Firestore_CreateDocument_async - */ - createDocument( - request?: protos.google.firestore.v1.ICreateDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | undefined, - {} | undefined, - ] - >; - createDocument( - request: protos.google.firestore.v1.ICreateDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - createDocument( - request: protos.google.firestore.v1.ICreateDocumentRequest, - callback: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - createDocument( - request?: protos.google.firestore.v1.ICreateDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('createDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('createDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .createDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1.IDocument, - protos.google.firestore.v1.ICreateDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('createDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - - /** - * Gets multiple documents. - * - * Documents returned by this method are not guaranteed to be returned in the - * same order that they were requested. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {string[]} request.documents - * The names of the documents to retrieve. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * The request will fail if any of the document is not a child resource of the - * given `database`. Duplicate names will be elided. - * @param {google.firestore.v1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field will - * not be returned in the response. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.firestore.v1.TransactionOptions} request.newTransaction - * Starts a new transaction and reads the documents. - * Defaults to a read-only transaction. - * The new transaction ID will be returned as the first response in the - * stream. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1.BatchGetDocumentsResponse|BatchGetDocumentsResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.batch_get_documents.js - * region_tag:firestore_v1_generated_Firestore_BatchGetDocuments_async - */ - batchGetDocuments( - request?: protos.google.firestore.v1.IBatchGetDocumentsRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('batchGetDocuments stream %j', options); - return this.innerApiCalls.batchGetDocuments(request, options); - } - - /** - * Runs a query. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {google.firestore.v1.StructuredQuery} request.structuredQuery - * A structured query. - * @param {Buffer} request.transaction - * Run the query within an already active transaction. - * - * The value here is the opaque transaction ID to execute the query in. - * @param {google.firestore.v1.TransactionOptions} request.newTransaction - * Starts a new transaction and reads the documents. - * Defaults to a read-only transaction. - * The new transaction ID will be returned as the first response in the - * stream. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {google.firestore.v1.ExplainOptions} [request.explainOptions] - * Optional. Explain options for the query. If set, additional query - * statistics will be returned. If not, only query results will be returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1.RunQueryResponse|RunQueryResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.run_query.js - * region_tag:firestore_v1_generated_Firestore_RunQuery_async - */ - runQuery( - request?: protos.google.firestore.v1.IRunQueryRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('runQuery stream %j', options); - return this.innerApiCalls.runQuery(request, options); - } - - /** - * Executes a pipeline query. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. Database identifier, in the form - * `projects/{project}/databases/{database}`. - * @param {google.firestore.v1.StructuredPipeline} request.structuredPipeline - * A pipelined operation. - * @param {Buffer} request.transaction - * Run the query within an already active transaction. - * - * The value here is the opaque transaction ID to execute the query in. - * @param {google.firestore.v1.TransactionOptions} request.newTransaction - * Execute the pipeline in a new transaction. - * - * The identifier of the newly created transaction will be returned in the - * first response on the stream. This defaults to a read-only transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Execute the pipeline in a snapshot transaction at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1.ExecutePipelineResponse|ExecutePipelineResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.execute_pipeline.js - * region_tag:firestore_v1_generated_Firestore_ExecutePipeline_async - */ - executePipeline( - request?: protos.google.firestore.v1.IExecutePipelineRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const routingParameter = {}; - { - const fieldValue = request.database; - if (fieldValue !== undefined && fieldValue !== null) { - const match = fieldValue - .toString() - .match(RegExp('projects/(?[^/]+)(?:/.*)?')); - if (match) { - const parameterValue = match.groups?.['project_id'] ?? fieldValue; - Object.assign(routingParameter, {project_id: parameterValue}); - } - } - } - { - const fieldValue = request.database; - if (fieldValue !== undefined && fieldValue !== null) { - const match = fieldValue - .toString() - .match( - RegExp('projects/[^/]+/databases/(?[^/]+)(?:/.*)?'), - ); - if (match) { - const parameterValue = match.groups?.['database_id'] ?? fieldValue; - Object.assign(routingParameter, {database_id: parameterValue}); - } - } - } - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams(routingParameter); - this.initialize().catch(err => { - throw err; - }); - this._log.info('executePipeline stream %j', options); - return this.innerApiCalls.executePipeline(request, options); - } - - /** - * Runs an aggregation query. - * - * Rather than producing {@link protos.google.firestore.v1.Document|Document} results like - * {@link protos.google.firestore.v1.Firestore.RunQuery|Firestore.RunQuery}, this API - * allows running an aggregation to produce a series of - * {@link protos.google.firestore.v1.AggregationResult|AggregationResult} server-side. - * - * High-Level Example: - * - * ``` - * -- Return the number of documents in table given a filter. - * SELECT COUNT(*) FROM ( SELECT * FROM k where a = true ); - * ``` - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {google.firestore.v1.StructuredAggregationQuery} request.structuredAggregationQuery - * An aggregation query. - * @param {Buffer} request.transaction - * Run the aggregation within an already active transaction. - * - * The value here is the opaque transaction ID to execute the query in. - * @param {google.firestore.v1.TransactionOptions} request.newTransaction - * Starts a new transaction as part of the query, defaulting to read-only. - * - * The new transaction ID will be returned as the first response in the - * stream. - * @param {google.protobuf.Timestamp} request.readTime - * Executes the query at the given timestamp. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {google.firestore.v1.ExplainOptions} [request.explainOptions] - * Optional. Explain options for the query. If set, additional query - * statistics will be returned. If not, only query results will be returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1.RunAggregationQueryResponse|RunAggregationQueryResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.run_aggregation_query.js - * region_tag:firestore_v1_generated_Firestore_RunAggregationQuery_async - */ - runAggregationQuery( - request?: protos.google.firestore.v1.IRunAggregationQueryRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('runAggregationQuery stream %j', options); - return this.innerApiCalls.runAggregationQuery(request, options); - } - - /** - * Streams batches of document updates and deletes, in order. This method is - * only available via gRPC or WebChannel (not REST). - * - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which is both readable and writable. It accepts objects - * representing {@link protos.google.firestore.v1.WriteRequest|WriteRequest} for write() method, and - * will emit objects representing {@link protos.google.firestore.v1.WriteResponse|WriteResponse} on 'data' event asynchronously. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.write.js - * region_tag:firestore_v1_generated_Firestore_Write_async - */ - write(options?: CallOptions): gax.CancellableStream { - this.initialize().catch(err => { - throw err; - }); - this._log.info('write stream %j', options); - return this.innerApiCalls.write(null, options); - } - - /** - * Listens to changes. This method is only available via gRPC or WebChannel - * (not REST). - * - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which is both readable and writable. It accepts objects - * representing {@link protos.google.firestore.v1.ListenRequest|ListenRequest} for write() method, and - * will emit objects representing {@link protos.google.firestore.v1.ListenResponse|ListenResponse} on 'data' event asynchronously. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.listen.js - * region_tag:firestore_v1_generated_Firestore_Listen_async - */ - listen(options?: CallOptions): gax.CancellableStream { - this.initialize().catch(err => { - throw err; - }); - this._log.info('listen stream %j', options); - return this.innerApiCalls.listen(null, options); - } - - /** - * Lists documents. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} [request.collectionId] - * Optional. The collection ID, relative to `parent`, to list. - * - * For example: `chatrooms` or `messages`. - * - * This is optional, and when not provided, Firestore will list documents - * from all collections under the provided `parent`. - * @param {number} [request.pageSize] - * Optional. The maximum number of documents to return in a single response. - * - * Firestore may return fewer than this value. - * @param {string} [request.pageToken] - * Optional. A page token, received from a previous `ListDocuments` response. - * - * Provide this to retrieve the subsequent page. When paginating, all other - * parameters (with the exception of `page_size`) must match the values set - * in the request that generated the page token. - * @param {string} [request.orderBy] - * Optional. The optional ordering of the documents to return. - * - * For example: `priority desc, __name__ desc`. - * - * This mirrors the {@link protos.google.firestore.v1.StructuredQuery.order_by|`ORDER BY`} - * used in Firestore queries but in a string representation. When absent, - * documents are ordered based on `__name__ ASC`. - * @param {google.firestore.v1.DocumentMask} [request.mask] - * Optional. The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Perform the read as part of an already active transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Perform the read at the provided time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {boolean} request.showMissing - * If the list should show missing documents. - * - * A document is missing if it does not exist, but there are sub-documents - * nested underneath it. When true, such missing documents will be returned - * with a key but will not have fields, - * {@link protos.google.firestore.v1.Document.create_time|`create_time`}, or - * {@link protos.google.firestore.v1.Document.update_time|`update_time`} set. - * - * Requests with `show_missing` may not specify `where` or `order_by`. - * @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 Array of {@link protos.google.firestore.v1.Document|Document}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listDocumentsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listDocuments( - request?: protos.google.firestore.v1.IListDocumentsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.IDocument[], - protos.google.firestore.v1.IListDocumentsRequest | null, - protos.google.firestore.v1.IListDocumentsResponse, - ] - >; - listDocuments( - request: protos.google.firestore.v1.IListDocumentsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1.IListDocumentsRequest, - protos.google.firestore.v1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1.IDocument - >, - ): void; - listDocuments( - request: protos.google.firestore.v1.IListDocumentsRequest, - callback: PaginationCallback< - protos.google.firestore.v1.IListDocumentsRequest, - protos.google.firestore.v1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1.IDocument - >, - ): void; - listDocuments( - request?: protos.google.firestore.v1.IListDocumentsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1.IListDocumentsRequest, - protos.google.firestore.v1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1.IDocument - >, - callback?: PaginationCallback< - protos.google.firestore.v1.IListDocumentsRequest, - protos.google.firestore.v1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1.IDocument - >, - ): Promise< - [ - protos.google.firestore.v1.IDocument[], - protos.google.firestore.v1.IListDocumentsRequest | null, - protos.google.firestore.v1.IListDocumentsResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1.IListDocumentsRequest, - protos.google.firestore.v1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1.IDocument - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listDocuments values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listDocuments request %j', request); - return this.innerApiCalls - .listDocuments(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.v1.IDocument[], - protos.google.firestore.v1.IListDocumentsRequest | null, - protos.google.firestore.v1.IListDocumentsResponse, - ]) => { - this._log.info('listDocuments values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listDocuments`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} [request.collectionId] - * Optional. The collection ID, relative to `parent`, to list. - * - * For example: `chatrooms` or `messages`. - * - * This is optional, and when not provided, Firestore will list documents - * from all collections under the provided `parent`. - * @param {number} [request.pageSize] - * Optional. The maximum number of documents to return in a single response. - * - * Firestore may return fewer than this value. - * @param {string} [request.pageToken] - * Optional. A page token, received from a previous `ListDocuments` response. - * - * Provide this to retrieve the subsequent page. When paginating, all other - * parameters (with the exception of `page_size`) must match the values set - * in the request that generated the page token. - * @param {string} [request.orderBy] - * Optional. The optional ordering of the documents to return. - * - * For example: `priority desc, __name__ desc`. - * - * This mirrors the {@link protos.google.firestore.v1.StructuredQuery.order_by|`ORDER BY`} - * used in Firestore queries but in a string representation. When absent, - * documents are ordered based on `__name__ ASC`. - * @param {google.firestore.v1.DocumentMask} [request.mask] - * Optional. The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Perform the read as part of an already active transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Perform the read at the provided time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {boolean} request.showMissing - * If the list should show missing documents. - * - * A document is missing if it does not exist, but there are sub-documents - * nested underneath it. When true, such missing documents will be returned - * with a key but will not have fields, - * {@link protos.google.firestore.v1.Document.create_time|`create_time`}, or - * {@link protos.google.firestore.v1.Document.update_time|`update_time`} set. - * - * Requests with `show_missing` may not specify `where` or `order_by`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.v1.Document|Document} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listDocumentsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listDocumentsStream( - request?: protos.google.firestore.v1.IListDocumentsRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - const defaultCallSettings = this._defaults['listDocuments']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listDocuments stream %j', request); - return this.descriptors.page.listDocuments.createStream( - this.innerApiCalls.listDocuments as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listDocuments`, but 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.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} [request.collectionId] - * Optional. The collection ID, relative to `parent`, to list. - * - * For example: `chatrooms` or `messages`. - * - * This is optional, and when not provided, Firestore will list documents - * from all collections under the provided `parent`. - * @param {number} [request.pageSize] - * Optional. The maximum number of documents to return in a single response. - * - * Firestore may return fewer than this value. - * @param {string} [request.pageToken] - * Optional. A page token, received from a previous `ListDocuments` response. - * - * Provide this to retrieve the subsequent page. When paginating, all other - * parameters (with the exception of `page_size`) must match the values set - * in the request that generated the page token. - * @param {string} [request.orderBy] - * Optional. The optional ordering of the documents to return. - * - * For example: `priority desc, __name__ desc`. - * - * This mirrors the {@link protos.google.firestore.v1.StructuredQuery.order_by|`ORDER BY`} - * used in Firestore queries but in a string representation. When absent, - * documents are ordered based on `__name__ ASC`. - * @param {google.firestore.v1.DocumentMask} [request.mask] - * Optional. The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Perform the read as part of an already active transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Perform the read at the provided time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {boolean} request.showMissing - * If the list should show missing documents. - * - * A document is missing if it does not exist, but there are sub-documents - * nested underneath it. When true, such missing documents will be returned - * with a key but will not have fields, - * {@link protos.google.firestore.v1.Document.create_time|`create_time`}, or - * {@link protos.google.firestore.v1.Document.update_time|`update_time`} set. - * - * Requests with `show_missing` may not specify `where` or `order_by`. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.v1.Document|Document}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.list_documents.js - * region_tag:firestore_v1_generated_Firestore_ListDocuments_async - */ - listDocumentsAsync( - request?: protos.google.firestore.v1.IListDocumentsRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - const defaultCallSettings = this._defaults['listDocuments']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listDocuments iterate %j', request); - return this.descriptors.page.listDocuments.asyncIterate( - this.innerApiCalls['listDocuments'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * Partitions a query by returning partition cursors that can be used to run - * the query in parallel. The returned partition cursors are split points that - * can be used by RunQuery as starting/end points for the query results. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @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 Array of {@link protos.google.firestore.v1.Cursor|Cursor}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `partitionQueryAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - partitionQuery( - request?: protos.google.firestore.v1.IPartitionQueryRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1.ICursor[], - protos.google.firestore.v1.IPartitionQueryRequest | null, - protos.google.firestore.v1.IPartitionQueryResponse, - ] - >; - partitionQuery( - request: protos.google.firestore.v1.IPartitionQueryRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1.IPartitionQueryRequest, - protos.google.firestore.v1.IPartitionQueryResponse | null | undefined, - protos.google.firestore.v1.ICursor - >, - ): void; - partitionQuery( - request: protos.google.firestore.v1.IPartitionQueryRequest, - callback: PaginationCallback< - protos.google.firestore.v1.IPartitionQueryRequest, - protos.google.firestore.v1.IPartitionQueryResponse | null | undefined, - protos.google.firestore.v1.ICursor - >, - ): void; - partitionQuery( - request?: protos.google.firestore.v1.IPartitionQueryRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1.IPartitionQueryRequest, - protos.google.firestore.v1.IPartitionQueryResponse | null | undefined, - protos.google.firestore.v1.ICursor - >, - callback?: PaginationCallback< - protos.google.firestore.v1.IPartitionQueryRequest, - protos.google.firestore.v1.IPartitionQueryResponse | null | undefined, - protos.google.firestore.v1.ICursor - >, - ): Promise< - [ - protos.google.firestore.v1.ICursor[], - protos.google.firestore.v1.IPartitionQueryRequest | null, - protos.google.firestore.v1.IPartitionQueryResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1.IPartitionQueryRequest, - protos.google.firestore.v1.IPartitionQueryResponse | null | undefined, - protos.google.firestore.v1.ICursor - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('partitionQuery values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('partitionQuery request %j', request); - return this.innerApiCalls - .partitionQuery(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.v1.ICursor[], - protos.google.firestore.v1.IPartitionQueryRequest | null, - protos.google.firestore.v1.IPartitionQueryResponse, - ]) => { - this._log.info('partitionQuery values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `partitionQuery`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.v1.Cursor|Cursor} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `partitionQueryAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - partitionQueryStream( - request?: protos.google.firestore.v1.IPartitionQueryRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['partitionQuery']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('partitionQuery stream %j', request); - return this.descriptors.page.partitionQuery.createStream( - this.innerApiCalls.partitionQuery as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `partitionQuery`, but 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.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.v1.Cursor|Cursor}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.partition_query.js - * region_tag:firestore_v1_generated_Firestore_PartitionQuery_async - */ - partitionQueryAsync( - request?: protos.google.firestore.v1.IPartitionQueryRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['partitionQuery']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('partitionQuery iterate %j', request); - return this.descriptors.page.partitionQuery.asyncIterate( - this.innerApiCalls['partitionQuery'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * Lists all the collection IDs underneath a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @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 Array of string. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listCollectionIdsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listCollectionIds( - request?: protos.google.firestore.v1.IListCollectionIdsRequest, - options?: CallOptions, - ): Promise< - [ - string[], - protos.google.firestore.v1.IListCollectionIdsRequest | null, - protos.google.firestore.v1.IListCollectionIdsResponse, - ] - >; - listCollectionIds( - request: protos.google.firestore.v1.IListCollectionIdsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1.IListCollectionIdsRequest, - protos.google.firestore.v1.IListCollectionIdsResponse | null | undefined, - string - >, - ): void; - listCollectionIds( - request: protos.google.firestore.v1.IListCollectionIdsRequest, - callback: PaginationCallback< - protos.google.firestore.v1.IListCollectionIdsRequest, - protos.google.firestore.v1.IListCollectionIdsResponse | null | undefined, - string - >, - ): void; - listCollectionIds( - request?: protos.google.firestore.v1.IListCollectionIdsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1.IListCollectionIdsRequest, - | protos.google.firestore.v1.IListCollectionIdsResponse - | null - | undefined, - string - >, - callback?: PaginationCallback< - protos.google.firestore.v1.IListCollectionIdsRequest, - protos.google.firestore.v1.IListCollectionIdsResponse | null | undefined, - string - >, - ): Promise< - [ - string[], - protos.google.firestore.v1.IListCollectionIdsRequest | null, - protos.google.firestore.v1.IListCollectionIdsResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1.IListCollectionIdsRequest, - | protos.google.firestore.v1.IListCollectionIdsResponse - | null - | undefined, - string - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listCollectionIds values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listCollectionIds request %j', request); - return this.innerApiCalls - .listCollectionIds(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - string[], - protos.google.firestore.v1.IListCollectionIdsRequest | null, - protos.google.firestore.v1.IListCollectionIdsResponse, - ]) => { - this._log.info('listCollectionIds values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listCollectionIds`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing string on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listCollectionIdsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listCollectionIdsStream( - request?: protos.google.firestore.v1.IListCollectionIdsRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listCollectionIds']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listCollectionIds stream %j', request); - return this.descriptors.page.listCollectionIds.createStream( - this.innerApiCalls.listCollectionIds as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listCollectionIds`, but 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.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * - * This must be a microsecond precision timestamp within the past one hour, - * or if Point-in-Time Recovery is enabled, can additionally be a whole - * minute timestamp within the past 7 days. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * string. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1/firestore.list_collection_ids.js - * region_tag:firestore_v1_generated_Firestore_ListCollectionIds_async - */ - listCollectionIdsAsync( - request?: protos.google.firestore.v1.IListCollectionIdsRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listCollectionIds']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listCollectionIds iterate %j', request); - return this.descriptors.page.listCollectionIds.asyncIterate( - this.innerApiCalls['listCollectionIds'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * 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 {@link google.cloud.location.Location | Location}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * 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 { - 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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.location.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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * 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 { - return this.locationsClient.listLocationsAsync(request, options); - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.firestoreStub && !this._terminated) { - return this.firestoreStub.then(stub => { - this._log.info('ending gRPC channel'); - this._terminated = true; - stub.close(); - this.locationsClient.close().catch(err => { - throw err; - }); - }); - } - return Promise.resolve(); - } -} diff --git a/handwritten/firestore/dev/src/v1/firestore_client_config.json b/handwritten/firestore/dev/src/v1/firestore_client_config.json deleted file mode 100644 index d820a4667edd..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_client_config.json +++ /dev/null @@ -1,131 +0,0 @@ -{ - "interfaces": { - "google.firestore.v1.Firestore": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "deadline_exceeded_resource_exhausted_internal_unavailable": [ - "DEADLINE_EXCEEDED", - "RESOURCE_EXHAUSTED", - "INTERNAL", - "UNAVAILABLE" - ], - "resource_exhausted_unavailable": [ - "RESOURCE_EXHAUSTED", - "UNAVAILABLE" - ], - "deadline_exceeded_internal_unavailable": [ - "DEADLINE_EXCEEDED", - "INTERNAL", - "UNAVAILABLE" - ], - "resource_exhausted_aborted_unavailable": [ - "RESOURCE_EXHAUSTED", - "ABORTED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "GetDocument": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "ListDocuments": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "UpdateDocument": { - "timeout_millis": 60000, - "retry_codes_name": "resource_exhausted_unavailable", - "retry_params_name": "default" - }, - "DeleteDocument": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "BatchGetDocuments": { - "timeout_millis": 300000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "BeginTransaction": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "Commit": { - "timeout_millis": 60000, - "retry_codes_name": "resource_exhausted_unavailable", - "retry_params_name": "default" - }, - "Rollback": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "RunQuery": { - "timeout_millis": 300000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "ExecutePipeline": { - "timeout_millis": 300000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "RunAggregationQuery": { - "timeout_millis": 300000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "PartitionQuery": { - "timeout_millis": 300000, - "retry_codes_name": "deadline_exceeded_internal_unavailable", - "retry_params_name": "default" - }, - "Write": { - "timeout_millis": 86400000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "Listen": { - "timeout_millis": 86400000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "ListCollectionIds": { - "timeout_millis": 60000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_internal_unavailable", - "retry_params_name": "default" - }, - "BatchWrite": { - "timeout_millis": 60000, - "retry_codes_name": "resource_exhausted_aborted_unavailable", - "retry_params_name": "default" - }, - "CreateDocument": { - "timeout_millis": 60000, - "retry_codes_name": "resource_exhausted_unavailable", - "retry_params_name": "default" - } - } - } - } -} diff --git a/handwritten/firestore/dev/src/v1/firestore_proto_list.json b/handwritten/firestore/dev/src/v1/firestore_proto_list.json deleted file mode 100644 index 6b67f4f49545..000000000000 --- a/handwritten/firestore/dev/src/v1/firestore_proto_list.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - "../../protos/google/firestore/v1/aggregation_result.proto", - "../../protos/google/firestore/v1/bloom_filter.proto", - "../../protos/google/firestore/v1/common.proto", - "../../protos/google/firestore/v1/document.proto", - "../../protos/google/firestore/v1/explain_stats.proto", - "../../protos/google/firestore/v1/firestore.proto", - "../../protos/google/firestore/v1/pipeline.proto", - "../../protos/google/firestore/v1/query.proto", - "../../protos/google/firestore/v1/query_profile.proto", - "../../protos/google/firestore/v1/write.proto" -] diff --git a/handwritten/firestore/dev/src/v1/gapic_metadata.json b/handwritten/firestore/dev/src/v1/gapic_metadata.json deleted file mode 100644 index 700dcb2c480c..000000000000 --- a/handwritten/firestore/dev/src/v1/gapic_metadata.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "schema": "1.0", - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "typescript", - "protoPackage": "google.firestore.v1", - "libraryPackage": "@google-cloud/firestore", - "services": { - "Firestore": { - "clients": { - "grpc": { - "libraryClient": "FirestoreClient", - "rpcs": { - "GetDocument": { - "methods": [ - "getDocument" - ] - }, - "UpdateDocument": { - "methods": [ - "updateDocument" - ] - }, - "DeleteDocument": { - "methods": [ - "deleteDocument" - ] - }, - "BeginTransaction": { - "methods": [ - "beginTransaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "BatchWrite": { - "methods": [ - "batchWrite" - ] - }, - "CreateDocument": { - "methods": [ - "createDocument" - ] - }, - "BatchGetDocuments": { - "methods": [ - "batchGetDocuments" - ] - }, - "RunQuery": { - "methods": [ - "runQuery" - ] - }, - "ExecutePipeline": { - "methods": [ - "executePipeline" - ] - }, - "RunAggregationQuery": { - "methods": [ - "runAggregationQuery" - ] - }, - "Write": { - "methods": [ - "write" - ] - }, - "Listen": { - "methods": [ - "listen" - ] - }, - "ListDocuments": { - "methods": [ - "listDocuments", - "listDocumentsStream", - "listDocumentsAsync" - ] - }, - "PartitionQuery": { - "methods": [ - "partitionQuery", - "partitionQueryStream", - "partitionQueryAsync" - ] - }, - "ListCollectionIds": { - "methods": [ - "listCollectionIds", - "listCollectionIdsStream", - "listCollectionIdsAsync" - ] - } - } - }, - "grpc-fallback": { - "libraryClient": "FirestoreClient", - "rpcs": { - "GetDocument": { - "methods": [ - "getDocument" - ] - }, - "UpdateDocument": { - "methods": [ - "updateDocument" - ] - }, - "DeleteDocument": { - "methods": [ - "deleteDocument" - ] - }, - "BeginTransaction": { - "methods": [ - "beginTransaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "BatchWrite": { - "methods": [ - "batchWrite" - ] - }, - "CreateDocument": { - "methods": [ - "createDocument" - ] - }, - "ListDocuments": { - "methods": [ - "listDocuments", - "listDocumentsStream", - "listDocumentsAsync" - ] - }, - "PartitionQuery": { - "methods": [ - "partitionQuery", - "partitionQueryStream", - "partitionQueryAsync" - ] - }, - "ListCollectionIds": { - "methods": [ - "listCollectionIds", - "listCollectionIdsStream", - "listCollectionIdsAsync" - ] - } - } - } - } - } - } -} diff --git a/handwritten/firestore/dev/src/v1/index.ts b/handwritten/firestore/dev/src/v1/index.ts deleted file mode 100644 index b6d83aaf9ed9..000000000000 --- a/handwritten/firestore/dev/src/v1/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import {FirestoreAdminClient} from './firestore_admin_client'; -import {FirestoreClient} from './firestore_client'; - -export {FirestoreClient, FirestoreAdminClient}; - -// Doing something really horrible for reverse compatibility with original JavaScript exports -const existingExports = module.exports; -module.exports = FirestoreClient; -module.exports = Object.assign(module.exports, existingExports); diff --git a/handwritten/firestore/dev/src/v1beta1/firestore_client.ts b/handwritten/firestore/dev/src/v1beta1/firestore_client.ts deleted file mode 100644 index 77dfad222690..000000000000 --- a/handwritten/firestore/dev/src/v1beta1/firestore_client.ts +++ /dev/null @@ -1,2592 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type { - Callback, - CallOptions, - Descriptors, - ClientOptions, - PaginationCallback, - GaxCall, -} from 'google-gax'; -import {Transform, PassThrough} from 'stream'; -import * as protos from '../../protos/firestore_v1beta1_proto_api'; -import jsonProtos = require('../../protos/v1beta1.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; - -/** - * Client JSON configuration object, loaded from - * `src/v1beta1/firestore_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './firestore_client_config.json'; -// tslint:disable deprecation - -// tslint:disable deprecation - -// tslint:disable deprecation - -// tslint:disable deprecation - -const version = require('../../../package.json').version; - -/** - * The Cloud Firestore service. - * - * Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL - * document database that simplifies storing, syncing, and querying data for - * your mobile, web, and IoT apps at global scale. Its client libraries provide - * live synchronization and offline support, while its security features and - * integrations with Firebase and Google Cloud Platform (GCP) accelerate - * building truly serverless apps. - * @class - * @deprecated Use v1/firestore_client instead. - * @deprecated Use v1/firestore_client instead. - * @deprecated Use v1/firestore_client instead. - * @deprecated Use v1/firestore_client instead. - * @memberof v1beta1 - */ -export class FirestoreClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - private _universeDomain: string; - private _servicePath: string; - private _log = logging.log('firestore'); - - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - firestoreStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of FirestoreClient. - * - * @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/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * 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 FirestoreClient({fallback: true}, gax); - * ``` - */ - constructor( - opts?: ClientOptions, - gaxInstance?: typeof gax | typeof gax.fallback, - ) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof FirestoreClient; - if ( - opts?.universe_domain && - opts?.universeDomain && - opts?.universe_domain !== opts?.universeDomain - ) { - throw new Error( - 'Please set either universe_domain or universeDomain, but not both.', - ); - } - const universeDomainEnvVar = - typeof process === 'object' && typeof process.env === 'object' - ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] - : undefined; - this._universeDomain = - opts?.universeDomain ?? - opts?.universe_domain ?? - universeDomainEnvVar ?? - 'googleapis.com'; - this._servicePath = 'firestore.' + this._universeDomain; - const servicePath = - opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!( - opts?.servicePath || opts?.apiEndpoint - ); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = - opts?.fallback ?? - (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== this._servicePath && !('scopes' in opts)) { - 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 ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = this._servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === this._servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - - // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; - if (typeof process === 'object' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listDocuments: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'documents', - ), - partitionQuery: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'partitions', - ), - listCollectionIds: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'collectionIds', - ), - }; - - // Some of the methods on this service provide streaming responses. - // Provide descriptors for these. - this.descriptors.stream = { - batchGetDocuments: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - runQuery: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.SERVER_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - write: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.BIDI_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - listen: new this._gaxModule.StreamDescriptor( - this._gaxModule.StreamType.BIDI_STREAMING, - !!opts.fallback, - !!opts.gaxServerStreamingRetries, - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.firestore.v1beta1.Firestore', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')}, - ); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.firestoreStub) { - return this.firestoreStub; - } - - // Put together the "service stub" for - // google.firestore.v1beta1.Firestore. - this.firestoreStub = this._gaxGrpc.createStub( - this._opts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.firestore.v1beta1.Firestore', - ) - : // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.firestore.v1beta1.Firestore, - this._opts, - this._providedCustomServicePath, - ) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const firestoreStubMethods = [ - 'getDocument', - 'listDocuments', - 'updateDocument', - 'deleteDocument', - 'batchGetDocuments', - 'beginTransaction', - 'commit', - 'rollback', - 'runQuery', - 'partitionQuery', - 'write', - 'listen', - 'listCollectionIds', - 'batchWrite', - 'createDocument', - ]; - for (const methodName of firestoreStubMethods) { - const callPromise = this.firestoreStub.then( - stub => - (...args: Array<{}>) => { - if (this._terminated) { - if (methodName in this.descriptors.stream) { - const stream = new PassThrough({objectMode: true}); - setImmediate(() => { - stream.emit( - 'error', - new this._gaxModule.GoogleError( - 'The client has already been closed.', - ), - ); - }); - return stream; - } - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error | null | undefined) => () => { - throw err; - }, - ); - - const descriptor = - this.descriptors.page[methodName] || - this.descriptors.stream[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback, - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.firestoreStub; - } - - /** - * The DNS address for this API service. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static servicePath is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath. - * @deprecated Use the apiEndpoint method of the client instance. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - process.emitWarning( - 'Static apiEndpoint is deprecated, please use the instance method instead.', - 'DeprecationWarning', - ); - } - return 'firestore.googleapis.com'; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - get apiEndpoint() { - return this._servicePath; - } - - get universeDomain() { - return this._universeDomain; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/datastore', - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId( - callback?: Callback, - ): Promise | void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - /** - * Gets a single document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the Document to get. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Reads the document in a transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Reads the version of the document at the given time. - * This may not be older than 270 seconds. - * @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 {@link protos.google.firestore.v1beta1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.get_document.js - * region_tag:firestore_v1beta1_generated_Firestore_GetDocument_async - */ - getDocument( - request?: protos.google.firestore.v1beta1.IGetDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | undefined, - {} | undefined, - ] - >; - getDocument( - request: protos.google.firestore.v1beta1.IGetDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDocument( - request: protos.google.firestore.v1beta1.IGetDocumentRequest, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - getDocument( - request?: protos.google.firestore.v1beta1.IGetDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.IGetDocumentRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('getDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.IGetDocumentRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('getDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .getDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IGetDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('getDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Updates or inserts a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.firestore.v1beta1.Document} request.document - * Required. The updated document. - * Creates the document if it does not already exist. - * @param {google.firestore.v1beta1.DocumentMask} request.updateMask - * The fields to update. - * None of the field paths in the mask may contain a reserved name. - * - * If the document exists on the server and has fields not referenced in the - * mask, they are left unchanged. - * Fields referenced in the mask, but not present in the input document, are - * deleted from the document on the server. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {google.firestore.v1beta1.Precondition} request.currentDocument - * An optional precondition on the document. - * The request will fail if this is set and not met by the target document. - * @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 {@link protos.google.firestore.v1beta1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.update_document.js - * region_tag:firestore_v1beta1_generated_Firestore_UpdateDocument_async - */ - updateDocument( - request?: protos.google.firestore.v1beta1.IUpdateDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | undefined, - {} | undefined, - ] - >; - updateDocument( - request: protos.google.firestore.v1beta1.IUpdateDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - updateDocument( - request: protos.google.firestore.v1beta1.IUpdateDocumentRequest, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - updateDocument( - request?: protos.google.firestore.v1beta1.IUpdateDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.IUpdateDocumentRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - 'document.name': request.document!.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('updateDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.IUpdateDocumentRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('updateDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .updateDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.IUpdateDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('updateDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Deletes a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the Document to delete. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * @param {google.firestore.v1beta1.Precondition} request.currentDocument - * An optional precondition on the document. - * The request will fail if this is set and not met by the target document. - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.delete_document.js - * region_tag:firestore_v1beta1_generated_Firestore_DeleteDocument_async - */ - deleteDocument( - request?: protos.google.firestore.v1beta1.IDeleteDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | undefined, - {} | undefined, - ] - >; - deleteDocument( - request: protos.google.firestore.v1beta1.IDeleteDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteDocument( - request: protos.google.firestore.v1beta1.IDeleteDocumentRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - deleteDocument( - request?: protos.google.firestore.v1beta1.IDeleteDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.v1beta1.IDeleteDocumentRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('deleteDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - | protos.google.firestore.v1beta1.IDeleteDocumentRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('deleteDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .deleteDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IDeleteDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('deleteDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Starts a new transaction. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {google.firestore.v1beta1.TransactionOptions} request.options - * The options for the transaction. - * Defaults to a read-write transaction. - * @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 {@link protos.google.firestore.v1beta1.BeginTransactionResponse|BeginTransactionResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.begin_transaction.js - * region_tag:firestore_v1beta1_generated_Firestore_BeginTransaction_async - */ - beginTransaction( - request?: protos.google.firestore.v1beta1.IBeginTransactionRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IBeginTransactionResponse, - protos.google.firestore.v1beta1.IBeginTransactionRequest | undefined, - {} | undefined, - ] - >; - beginTransaction( - request: protos.google.firestore.v1beta1.IBeginTransactionRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.IBeginTransactionResponse, - | protos.google.firestore.v1beta1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - beginTransaction( - request: protos.google.firestore.v1beta1.IBeginTransactionRequest, - callback: Callback< - protos.google.firestore.v1beta1.IBeginTransactionResponse, - | protos.google.firestore.v1beta1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - >, - ): void; - beginTransaction( - request?: protos.google.firestore.v1beta1.IBeginTransactionRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.IBeginTransactionResponse, - | protos.google.firestore.v1beta1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.IBeginTransactionResponse, - | protos.google.firestore.v1beta1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IBeginTransactionResponse, - protos.google.firestore.v1beta1.IBeginTransactionRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('beginTransaction request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.IBeginTransactionResponse, - | protos.google.firestore.v1beta1.IBeginTransactionRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('beginTransaction response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .beginTransaction(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.IBeginTransactionResponse, - protos.google.firestore.v1beta1.IBeginTransactionRequest | undefined, - {} | undefined, - ]) => { - this._log.info('beginTransaction response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Commits a transaction, while optionally updating documents. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {number[]} request.writes - * The writes to apply. - * - * Always executed atomically and in order. - * @param {Buffer} request.transaction - * If set, applies all writes in this transaction, and commits it. - * @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 {@link protos.google.firestore.v1beta1.CommitResponse|CommitResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.commit.js - * region_tag:firestore_v1beta1_generated_Firestore_Commit_async - */ - commit( - request?: protos.google.firestore.v1beta1.ICommitRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | undefined, - {} | undefined, - ] - >; - commit( - request: protos.google.firestore.v1beta1.ICommitRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): void; - commit( - request: protos.google.firestore.v1beta1.ICommitRequest, - callback: Callback< - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): void; - commit( - request?: protos.google.firestore.v1beta1.ICommitRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('commit request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('commit response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .commit(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.ICommitResponse, - protos.google.firestore.v1beta1.ICommitRequest | undefined, - {} | undefined, - ]) => { - this._log.info('commit response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Rolls back a transaction. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {Buffer} request.transaction - * Required. The transaction to roll back. - * @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 {@link protos.google.protobuf.Empty|Empty}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.rollback.js - * region_tag:firestore_v1beta1_generated_Firestore_Rollback_async - */ - rollback( - request?: protos.google.firestore.v1beta1.IRollbackRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | undefined, - {} | undefined, - ] - >; - rollback( - request: protos.google.firestore.v1beta1.IRollbackRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): void; - rollback( - request: protos.google.firestore.v1beta1.IRollbackRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): void; - rollback( - request?: protos.google.firestore.v1beta1.IRollbackRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('rollback request %j', request); - const wrappedCallback: - | Callback< - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('rollback response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .rollback(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.firestore.v1beta1.IRollbackRequest | undefined, - {} | undefined, - ]) => { - this._log.info('rollback response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Applies a batch of write operations. - * - * The BatchWrite method does not apply the write operations atomically - * and can apply them out of order. Method does not allow more than one write - * per document. Each write succeeds or fails independently. See the - * {@link protos.google.firestore.v1beta1.BatchWriteResponse|BatchWriteResponse} for the success status of each write. - * - * If you require an atomically applied set of writes, use - * {@link protos.google.firestore.v1beta1.Firestore.Commit|Commit} instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {number[]} request.writes - * The writes to apply. - * - * Method does not apply writes atomically and does not guarantee ordering. - * Each write succeeds or fails independently. You cannot write to the same - * document more than once per request. - * @param {number[]} request.labels - * Labels associated with this batch write. - * @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 {@link protos.google.firestore.v1beta1.BatchWriteResponse|BatchWriteResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.batch_write.js - * region_tag:firestore_v1beta1_generated_Firestore_BatchWrite_async - */ - batchWrite( - request?: protos.google.firestore.v1beta1.IBatchWriteRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | undefined, - {} | undefined, - ] - >; - batchWrite( - request: protos.google.firestore.v1beta1.IBatchWriteRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): void; - batchWrite( - request: protos.google.firestore.v1beta1.IBatchWriteRequest, - callback: Callback< - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): void; - batchWrite( - request?: protos.google.firestore.v1beta1.IBatchWriteRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('batchWrite request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | null | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('batchWrite response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .batchWrite(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.IBatchWriteResponse, - protos.google.firestore.v1beta1.IBatchWriteRequest | undefined, - {} | undefined, - ]) => { - this._log.info('batchWrite response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - /** - * Creates a new document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource. For example: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}` - * @param {string} request.collectionId - * Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`. - * @param {string} request.documentId - * The client-assigned document ID to use for this document. - * - * Optional. If not specified, an ID will be assigned by the service. - * @param {google.firestore.v1beta1.Document} request.document - * Required. The document to create. `name` must not be set. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If the document has a field that is not present in this mask, that field - * will not be returned in the response. - * @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 {@link protos.google.firestore.v1beta1.Document|Document}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.create_document.js - * region_tag:firestore_v1beta1_generated_Firestore_CreateDocument_async - */ - createDocument( - request?: protos.google.firestore.v1beta1.ICreateDocumentRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | undefined, - {} | undefined, - ] - >; - createDocument( - request: protos.google.firestore.v1beta1.ICreateDocumentRequest, - options: CallOptions, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - createDocument( - request: protos.google.firestore.v1beta1.ICreateDocumentRequest, - callback: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): void; - createDocument( - request?: protos.google.firestore.v1beta1.ICreateDocumentRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.ICreateDocumentRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | null | undefined, - {} | null | undefined - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | undefined, - {} | undefined, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('createDocument request %j', request); - const wrappedCallback: - | Callback< - protos.google.firestore.v1beta1.IDocument, - | protos.google.firestore.v1beta1.ICreateDocumentRequest - | null - | undefined, - {} | null | undefined - > - | undefined = callback - ? (error, response, options, rawResponse) => { - this._log.info('createDocument response %j', response); - callback!(error, response, options, rawResponse); // We verified callback above. - } - : undefined; - return this.innerApiCalls - .createDocument(request, options, wrappedCallback) - ?.then( - ([response, options, rawResponse]: [ - protos.google.firestore.v1beta1.IDocument, - protos.google.firestore.v1beta1.ICreateDocumentRequest | undefined, - {} | undefined, - ]) => { - this._log.info('createDocument response %j', response); - return [response, options, rawResponse]; - }, - ) - .catch((error: any) => { - if ( - error && - 'statusDetails' in error && - error.statusDetails instanceof Array - ) { - const protos = this._gaxModule.protobuf.Root.fromJSON( - jsonProtos, - ) as unknown as gax.protobuf.Type; - error.statusDetails = decodeAnyProtosInArray( - error.statusDetails, - protos, - ); - } - throw error; - }); - } - - /** - * Gets multiple documents. - * - * Documents returned by this method are not guaranteed to be returned in the - * same order that they were requested. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Required. The database name. In the format: - * `projects/{project_id}/databases/{database_id}`. - * @param {string[]} request.documents - * The names of the documents to retrieve. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * The request will fail if any of the document is not a child resource of the - * given `database`. Duplicate names will be elided. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field will - * not be returned in the response. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.firestore.v1beta1.TransactionOptions} request.newTransaction - * Starts a new transaction and reads the documents. - * Defaults to a read-only transaction. - * The new transaction ID will be returned as the first response in the - * stream. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * This may not be older than 270 seconds. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1beta1.BatchGetDocumentsResponse|BatchGetDocumentsResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.batch_get_documents.js - * region_tag:firestore_v1beta1_generated_Firestore_BatchGetDocuments_async - */ - batchGetDocuments( - request?: protos.google.firestore.v1beta1.IBatchGetDocumentsRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - database: request.database ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('batchGetDocuments stream %j', options); - return this.innerApiCalls.batchGetDocuments(request, options); - } - - /** - * Runs a query. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {google.firestore.v1beta1.StructuredQuery} request.structuredQuery - * A structured query. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.firestore.v1beta1.TransactionOptions} request.newTransaction - * Starts a new transaction and reads the documents. - * Defaults to a read-only transaction. - * The new transaction ID will be returned as the first response in the - * stream. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * This may not be older than 270 seconds. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits {@link protos.google.firestore.v1beta1.RunQueryResponse|RunQueryResponse} on 'data' event. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.run_query.js - * region_tag:firestore_v1beta1_generated_Firestore_RunQuery_async - */ - runQuery( - request?: protos.google.firestore.v1beta1.IRunQueryRequest, - options?: CallOptions, - ): gax.CancellableStream { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - this._log.info('runQuery stream %j', options); - return this.innerApiCalls.runQuery(request, options); - } - - /** - * Streams batches of document updates and deletes, in order. - * - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which is both readable and writable. It accepts objects - * representing {@link protos.google.firestore.v1beta1.WriteRequest|WriteRequest} for write() method, and - * will emit objects representing {@link protos.google.firestore.v1beta1.WriteResponse|WriteResponse} on 'data' event asynchronously. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.write.js - * region_tag:firestore_v1beta1_generated_Firestore_Write_async - */ - write(options?: CallOptions): gax.CancellableStream { - this.initialize().catch(err => { - throw err; - }); - this._log.info('write stream %j', options); - return this.innerApiCalls.write(null, options); - } - - /** - * Listens to changes. - * - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which is both readable and writable. It accepts objects - * representing {@link protos.google.firestore.v1beta1.ListenRequest|ListenRequest} for write() method, and - * will emit objects representing {@link protos.google.firestore.v1beta1.ListenResponse|ListenResponse} on 'data' event asynchronously. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.listen.js - * region_tag:firestore_v1beta1_generated_Firestore_Listen_async - */ - listen(options?: CallOptions): gax.CancellableStream { - this.initialize().catch(err => { - throw err; - }); - this._log.info('listen stream %j', options); - return this.innerApiCalls.listen(null, options); - } - - /** - * Lists documents. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} request.collectionId - * Required. The collection ID, relative to `parent`, to list. For example: `chatrooms` - * or `messages`. - * @param {number} request.pageSize - * The maximum number of documents to return. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous List request, if any. - * @param {string} request.orderBy - * The order to sort results by. For example: `priority desc, name`. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * This may not be older than 270 seconds. - * @param {boolean} request.showMissing - * If the list should show missing documents. A missing document is a - * document that does not exist but has sub-documents. These documents will - * be returned with a key but will not have fields, {@link protos.google.firestore.v1beta1.Document.create_time|Document.create_time}, - * or {@link protos.google.firestore.v1beta1.Document.update_time|Document.update_time} set. - * - * Requests with `show_missing` may not specify `where` or - * `order_by`. - * @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 Array of {@link protos.google.firestore.v1beta1.Document|Document}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listDocumentsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listDocuments( - request?: protos.google.firestore.v1beta1.IListDocumentsRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument[], - protos.google.firestore.v1beta1.IListDocumentsRequest | null, - protos.google.firestore.v1beta1.IListDocumentsResponse, - ] - >; - listDocuments( - request: protos.google.firestore.v1beta1.IListDocumentsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IListDocumentsRequest, - protos.google.firestore.v1beta1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1beta1.IDocument - >, - ): void; - listDocuments( - request: protos.google.firestore.v1beta1.IListDocumentsRequest, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IListDocumentsRequest, - protos.google.firestore.v1beta1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1beta1.IDocument - >, - ): void; - listDocuments( - request?: protos.google.firestore.v1beta1.IListDocumentsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1beta1.IListDocumentsRequest, - | protos.google.firestore.v1beta1.IListDocumentsResponse - | null - | undefined, - protos.google.firestore.v1beta1.IDocument - >, - callback?: PaginationCallback< - protos.google.firestore.v1beta1.IListDocumentsRequest, - protos.google.firestore.v1beta1.IListDocumentsResponse | null | undefined, - protos.google.firestore.v1beta1.IDocument - >, - ): Promise< - [ - protos.google.firestore.v1beta1.IDocument[], - protos.google.firestore.v1beta1.IListDocumentsRequest | null, - protos.google.firestore.v1beta1.IListDocumentsResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1beta1.IListDocumentsRequest, - | protos.google.firestore.v1beta1.IListDocumentsResponse - | null - | undefined, - protos.google.firestore.v1beta1.IDocument - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listDocuments values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listDocuments request %j', request); - return this.innerApiCalls - .listDocuments(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.v1beta1.IDocument[], - protos.google.firestore.v1beta1.IListDocumentsRequest | null, - protos.google.firestore.v1beta1.IListDocumentsResponse, - ]) => { - this._log.info('listDocuments values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listDocuments`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} request.collectionId - * Required. The collection ID, relative to `parent`, to list. For example: `chatrooms` - * or `messages`. - * @param {number} request.pageSize - * The maximum number of documents to return. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous List request, if any. - * @param {string} request.orderBy - * The order to sort results by. For example: `priority desc, name`. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * This may not be older than 270 seconds. - * @param {boolean} request.showMissing - * If the list should show missing documents. A missing document is a - * document that does not exist but has sub-documents. These documents will - * be returned with a key but will not have fields, {@link protos.google.firestore.v1beta1.Document.create_time|Document.create_time}, - * or {@link protos.google.firestore.v1beta1.Document.update_time|Document.update_time} set. - * - * Requests with `show_missing` may not specify `where` or - * `order_by`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.v1beta1.Document|Document} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listDocumentsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listDocumentsStream( - request?: protos.google.firestore.v1beta1.IListDocumentsRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - const defaultCallSettings = this._defaults['listDocuments']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listDocuments stream %j', request); - return this.descriptors.page.listDocuments.createStream( - this.innerApiCalls.listDocuments as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listDocuments`, but 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.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents` or - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents` or - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {string} request.collectionId - * Required. The collection ID, relative to `parent`, to list. For example: `chatrooms` - * or `messages`. - * @param {number} request.pageSize - * The maximum number of documents to return. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous List request, if any. - * @param {string} request.orderBy - * The order to sort results by. For example: `priority desc, name`. - * @param {google.firestore.v1beta1.DocumentMask} request.mask - * The fields to return. If not set, returns all fields. - * - * If a document has a field that is not present in this mask, that field - * will not be returned in the response. - * @param {Buffer} request.transaction - * Reads documents in a transaction. - * @param {google.protobuf.Timestamp} request.readTime - * Reads documents as they were at the given time. - * This may not be older than 270 seconds. - * @param {boolean} request.showMissing - * If the list should show missing documents. A missing document is a - * document that does not exist but has sub-documents. These documents will - * be returned with a key but will not have fields, {@link protos.google.firestore.v1beta1.Document.create_time|Document.create_time}, - * or {@link protos.google.firestore.v1beta1.Document.update_time|Document.update_time} set. - * - * Requests with `show_missing` may not specify `where` or - * `order_by`. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.v1beta1.Document|Document}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.list_documents.js - * region_tag:firestore_v1beta1_generated_Firestore_ListDocuments_async - */ - listDocumentsAsync( - request?: protos.google.firestore.v1beta1.IListDocumentsRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - collection_id: request.collectionId?.toString() ?? '', - }); - const defaultCallSettings = this._defaults['listDocuments']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listDocuments iterate %j', request); - return this.descriptors.page.listDocuments.asyncIterate( - this.innerApiCalls['listDocuments'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * Partitions a query by returning partition cursors that can be used to run - * the query in parallel. The returned partition cursors are split points that - * can be used by RunQuery as starting/end points for the query results. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1beta1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @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 Array of {@link protos.google.firestore.v1beta1.Cursor|Cursor}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `partitionQueryAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - partitionQuery( - request?: protos.google.firestore.v1beta1.IPartitionQueryRequest, - options?: CallOptions, - ): Promise< - [ - protos.google.firestore.v1beta1.ICursor[], - protos.google.firestore.v1beta1.IPartitionQueryRequest | null, - protos.google.firestore.v1beta1.IPartitionQueryResponse, - ] - >; - partitionQuery( - request: protos.google.firestore.v1beta1.IPartitionQueryRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IPartitionQueryRequest, - | protos.google.firestore.v1beta1.IPartitionQueryResponse - | null - | undefined, - protos.google.firestore.v1beta1.ICursor - >, - ): void; - partitionQuery( - request: protos.google.firestore.v1beta1.IPartitionQueryRequest, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IPartitionQueryRequest, - | protos.google.firestore.v1beta1.IPartitionQueryResponse - | null - | undefined, - protos.google.firestore.v1beta1.ICursor - >, - ): void; - partitionQuery( - request?: protos.google.firestore.v1beta1.IPartitionQueryRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1beta1.IPartitionQueryRequest, - | protos.google.firestore.v1beta1.IPartitionQueryResponse - | null - | undefined, - protos.google.firestore.v1beta1.ICursor - >, - callback?: PaginationCallback< - protos.google.firestore.v1beta1.IPartitionQueryRequest, - | protos.google.firestore.v1beta1.IPartitionQueryResponse - | null - | undefined, - protos.google.firestore.v1beta1.ICursor - >, - ): Promise< - [ - protos.google.firestore.v1beta1.ICursor[], - protos.google.firestore.v1beta1.IPartitionQueryRequest | null, - protos.google.firestore.v1beta1.IPartitionQueryResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1beta1.IPartitionQueryRequest, - | protos.google.firestore.v1beta1.IPartitionQueryResponse - | null - | undefined, - protos.google.firestore.v1beta1.ICursor - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('partitionQuery values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('partitionQuery request %j', request); - return this.innerApiCalls - .partitionQuery(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - protos.google.firestore.v1beta1.ICursor[], - protos.google.firestore.v1beta1.IPartitionQueryRequest | null, - protos.google.firestore.v1beta1.IPartitionQueryResponse, - ]) => { - this._log.info('partitionQuery values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `partitionQuery`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1beta1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link protos.google.firestore.v1beta1.Cursor|Cursor} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `partitionQueryAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - partitionQueryStream( - request?: protos.google.firestore.v1beta1.IPartitionQueryRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['partitionQuery']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('partitionQuery stream %j', request); - return this.descriptors.page.partitionQuery.createStream( - this.innerApiCalls.partitionQuery as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `partitionQuery`, but 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.parent - * Required. The parent resource name. In the format: - * `projects/{project_id}/databases/{database_id}/documents`. - * Document resource names are not supported; only database resource names - * can be specified. - * @param {google.firestore.v1beta1.StructuredQuery} request.structuredQuery - * A structured query. - * Query must specify collection with all descendants and be ordered by name - * ascending. Other filters, order bys, limits, offsets, and start/end - * cursors are not supported. - * @param {number} request.partitionCount - * The desired maximum number of partition points. - * The partitions may be returned across multiple pages of results. - * The number must be positive. The actual number of partitions - * returned may be fewer. - * - * For example, this may be set to one fewer than the number of parallel - * queries to be run, or in running a data pipeline job, one fewer than the - * number of workers or compute instances available. - * @param {string} request.pageToken - * The `next_page_token` value returned from a previous call to - * PartitionQuery that may be used to get an additional set of results. - * There are no ordering guarantees between sets of results. Thus, using - * multiple sets of results will require merging the different result sets. - * - * For example, two subsequent calls using a page_token may return: - * - * * cursor B, cursor M, cursor Q - * * cursor A, cursor U, cursor W - * - * To obtain a complete result set ordered with respect to the results of the - * query supplied to PartitionQuery, the results sets should be merged: - * cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W - * @param {number} request.pageSize - * The maximum number of partitions to return in this call, subject to - * `partition_count`. - * - * For example, if `partition_count` = 10 and `page_size` = 8, the first call - * to PartitionQuery will return up to 8 partitions and a `next_page_token` - * if more results exist. A second call to PartitionQuery will return up to - * 2 partitions, to complete the total of 10 specified in `partition_count`. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * {@link protos.google.firestore.v1beta1.Cursor|Cursor}. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.partition_query.js - * region_tag:firestore_v1beta1_generated_Firestore_PartitionQuery_async - */ - partitionQueryAsync( - request?: protos.google.firestore.v1beta1.IPartitionQueryRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['partitionQuery']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('partitionQuery iterate %j', request); - return this.descriptors.page.partitionQuery.asyncIterate( - this.innerApiCalls['partitionQuery'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - /** - * Lists all the collection IDs underneath a document. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1beta1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @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 Array of string. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listCollectionIdsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listCollectionIds( - request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - options?: CallOptions, - ): Promise< - [ - string[], - protos.google.firestore.v1beta1.IListCollectionIdsRequest | null, - protos.google.firestore.v1beta1.IListCollectionIdsResponse, - ] - >; - listCollectionIds( - request: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IListCollectionIdsRequest, - | protos.google.firestore.v1beta1.IListCollectionIdsResponse - | null - | undefined, - string - >, - ): void; - listCollectionIds( - request: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - callback: PaginationCallback< - protos.google.firestore.v1beta1.IListCollectionIdsRequest, - | protos.google.firestore.v1beta1.IListCollectionIdsResponse - | null - | undefined, - string - >, - ): void; - listCollectionIds( - request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.firestore.v1beta1.IListCollectionIdsRequest, - | protos.google.firestore.v1beta1.IListCollectionIdsResponse - | null - | undefined, - string - >, - callback?: PaginationCallback< - protos.google.firestore.v1beta1.IListCollectionIdsRequest, - | protos.google.firestore.v1beta1.IListCollectionIdsResponse - | null - | undefined, - string - >, - ): Promise< - [ - string[], - protos.google.firestore.v1beta1.IListCollectionIdsRequest | null, - protos.google.firestore.v1beta1.IListCollectionIdsResponse, - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize().catch(err => { - throw err; - }); - const wrappedCallback: - | PaginationCallback< - protos.google.firestore.v1beta1.IListCollectionIdsRequest, - | protos.google.firestore.v1beta1.IListCollectionIdsResponse - | null - | undefined, - string - > - | undefined = callback - ? (error, values, nextPageRequest, rawResponse) => { - this._log.info('listCollectionIds values %j', values); - callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. - } - : undefined; - this._log.info('listCollectionIds request %j', request); - return this.innerApiCalls - .listCollectionIds(request, options, wrappedCallback) - ?.then( - ([response, input, output]: [ - string[], - protos.google.firestore.v1beta1.IListCollectionIdsRequest | null, - protos.google.firestore.v1beta1.IListCollectionIdsResponse, - ]) => { - this._log.info('listCollectionIds values %j', response); - return [response, input, output]; - }, - ); - } - - /** - * Equivalent to `listCollectionIds`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1beta1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing string on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listCollectionIdsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - */ - listCollectionIdsStream( - request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - options?: CallOptions, - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listCollectionIds']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listCollectionIds stream %j', request); - return this.descriptors.page.listCollectionIds.createStream( - this.innerApiCalls.listCollectionIds as GaxCall, - request, - callSettings, - ); - } - - /** - * Equivalent to `listCollectionIds`, but 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.parent - * Required. The parent document. In the format: - * `projects/{project_id}/databases/{database_id}/documents/{document_path}`. - * For example: - * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom` - * @param {number} request.pageSize - * The maximum number of results to return. - * @param {string} request.pageToken - * A page token. Must be a value from - * {@link protos.google.firestore.v1beta1.ListCollectionIdsResponse|ListCollectionIdsResponse}. - * @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 {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. - * When you iterate the returned iterable, each element will be an object representing - * string. 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 {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } - * for more details and examples. - * @example include:samples/generated/v1beta1/firestore.list_collection_ids.js - * region_tag:firestore_v1beta1_generated_Firestore_ListCollectionIds_async - */ - listCollectionIdsAsync( - request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, - options?: CallOptions, - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listCollectionIds']; - const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => { - throw err; - }); - this._log.info('listCollectionIds iterate %j', request); - return this.descriptors.page.listCollectionIds.asyncIterate( - this.innerApiCalls['listCollectionIds'] as GaxCall, - request as {}, - callSettings, - ) as AsyncIterable; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.firestoreStub && !this._terminated) { - return this.firestoreStub.then(stub => { - this._log.info('ending gRPC channel'); - this._terminated = true; - stub.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/handwritten/firestore/dev/src/v1beta1/firestore_client_config.json b/handwritten/firestore/dev/src/v1beta1/firestore_client_config.json deleted file mode 100644 index b0366d662600..000000000000 --- a/handwritten/firestore/dev/src/v1beta1/firestore_client_config.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "interfaces": { - "google.firestore.v1beta1.Firestore": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "GetDocument": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "ListDocuments": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "UpdateDocument": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "DeleteDocument": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "BatchGetDocuments": { - "timeout_millis": 300000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "BeginTransaction": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "Commit": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "Rollback": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "RunQuery": { - "timeout_millis": 300000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "PartitionQuery": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "Write": { - "timeout_millis": 86400000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "Listen": { - "timeout_millis": 86400000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "ListCollectionIds": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "BatchWrite": { - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "CreateDocument": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - } - } - } - } -} diff --git a/handwritten/firestore/dev/src/v1beta1/firestore_proto_list.json b/handwritten/firestore/dev/src/v1beta1/firestore_proto_list.json deleted file mode 100644 index 735b79559172..000000000000 --- a/handwritten/firestore/dev/src/v1beta1/firestore_proto_list.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - "../../protos/google/firestore/v1beta1/common.proto", - "../../protos/google/firestore/v1beta1/document.proto", - "../../protos/google/firestore/v1beta1/firestore.proto", - "../../protos/google/firestore/v1beta1/query.proto", - "../../protos/google/firestore/v1beta1/undeliverable_first_gen_event.proto", - "../../protos/google/firestore/v1beta1/write.proto" -] diff --git a/handwritten/firestore/dev/src/v1beta1/gapic_metadata.json b/handwritten/firestore/dev/src/v1beta1/gapic_metadata.json deleted file mode 100644 index 90ed69dcf903..000000000000 --- a/handwritten/firestore/dev/src/v1beta1/gapic_metadata.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "schema": "1.0", - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "typescript", - "protoPackage": "google.firestore.v1beta1", - "libraryPackage": "@google-cloud/firestore", - "services": { - "Firestore": { - "clients": { - "grpc": { - "libraryClient": "FirestoreClient", - "rpcs": { - "GetDocument": { - "methods": [ - "getDocument" - ] - }, - "UpdateDocument": { - "methods": [ - "updateDocument" - ] - }, - "DeleteDocument": { - "methods": [ - "deleteDocument" - ] - }, - "BeginTransaction": { - "methods": [ - "beginTransaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "BatchWrite": { - "methods": [ - "batchWrite" - ] - }, - "CreateDocument": { - "methods": [ - "createDocument" - ] - }, - "BatchGetDocuments": { - "methods": [ - "batchGetDocuments" - ] - }, - "RunQuery": { - "methods": [ - "runQuery" - ] - }, - "Write": { - "methods": [ - "write" - ] - }, - "Listen": { - "methods": [ - "listen" - ] - }, - "ListDocuments": { - "methods": [ - "listDocuments", - "listDocumentsStream", - "listDocumentsAsync" - ] - }, - "PartitionQuery": { - "methods": [ - "partitionQuery", - "partitionQueryStream", - "partitionQueryAsync" - ] - }, - "ListCollectionIds": { - "methods": [ - "listCollectionIds", - "listCollectionIdsStream", - "listCollectionIdsAsync" - ] - } - } - }, - "grpc-fallback": { - "libraryClient": "FirestoreClient", - "rpcs": { - "GetDocument": { - "methods": [ - "getDocument" - ] - }, - "UpdateDocument": { - "methods": [ - "updateDocument" - ] - }, - "DeleteDocument": { - "methods": [ - "deleteDocument" - ] - }, - "BeginTransaction": { - "methods": [ - "beginTransaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "BatchWrite": { - "methods": [ - "batchWrite" - ] - }, - "CreateDocument": { - "methods": [ - "createDocument" - ] - }, - "ListDocuments": { - "methods": [ - "listDocuments", - "listDocumentsStream", - "listDocumentsAsync" - ] - }, - "PartitionQuery": { - "methods": [ - "partitionQuery", - "partitionQueryStream", - "partitionQueryAsync" - ] - }, - "ListCollectionIds": { - "methods": [ - "listCollectionIds", - "listCollectionIdsStream", - "listCollectionIdsAsync" - ] - } - } - } - } - } - } -} diff --git a/handwritten/firestore/dev/src/v1beta1/index.ts b/handwritten/firestore/dev/src/v1beta1/index.ts deleted file mode 100644 index b19eff7ed37b..000000000000 --- a/handwritten/firestore/dev/src/v1beta1/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// tslint:disable deprecation - -import {FirestoreClient} from './firestore_client'; -export {FirestoreClient}; - -// Doing something really horrible for reverse compatibility with original JavaScript exports -const existingExports = module.exports; -module.exports = FirestoreClient; -module.exports = Object.assign(module.exports, existingExports); diff --git a/handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts b/handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts deleted file mode 100644 index a64653426b6c..000000000000 --- a/handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts +++ /dev/null @@ -1,6597 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/firestore_admin_v1_proto_api'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as firestoreadminModule from '../src/v1'; - -import {PassThrough} from 'stream'; - -import { - protobuf, - LROperation, - operationsProtos, - LocationProtos, -} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - require('../protos/admin_v1.json'), -).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = ( - instance.constructor as typeof protobuf.Message - ).toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject( - filledObject, - ) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error - ? sinon.stub().rejects(error) - : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback( - response?: ResponseType, - error?: Error, -) { - return error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall( - response?: ResponseType, - callError?: Error, - lroError?: Error, -) { - const innerStub = lroError - ? sinon.stub().rejects(lroError) - : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError - ? sinon.stub().rejects(callError) - : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback( - response?: ResponseType, - callError?: Error, - lroError?: Error, -) { - const innerStub = lroError - ? sinon.stub().rejects(lroError) - : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError - ? sinon.stub().callsArgWith(2, callError) - : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall( - responses?: ResponseType[], - error?: Error, -) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { - mockStream.write({}); - }); - } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall( - responses?: ResponseType[], - error?: Error, -) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - }, - }; - }, - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.FirestoreAdminClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new firestoreadminModule.FirestoreAdminClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new firestoreadminModule.FirestoreAdminClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, 'googleapis.com'); - }); - - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = - firestoreadminModule.FirestoreAdminClient.servicePath; - assert.strictEqual(servicePath, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = - firestoreadminModule.FirestoreAdminClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - universeDomain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - universe_domain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreadminModule.FirestoreAdminClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreadminModule.FirestoreAdminClient({ - universeDomain: 'configured.example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { - new firestoreadminModule.FirestoreAdminClient({ - universe_domain: 'example.com', - universeDomain: 'example.net', - }); - }); - }); - - it('has port', () => { - const port = firestoreadminModule.FirestoreAdminClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new firestoreadminModule.FirestoreAdminClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreAdminStub, undefined); - await client.initialize(); - assert(client.firestoreAdminStub); - }); - - it('has close method for the initialized client', done => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => { - throw err; - }); - assert(client.firestoreAdminStub); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreAdminStub, undefined); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('getIndex', () => { - it('invokes getIndex without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Index(), - ); - client.innerApiCalls.getIndex = stubSimpleCall(expectedResponse); - const [response] = await client.getIndex(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIndex without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Index(), - ); - client.innerApiCalls.getIndex = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIndex( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IIndex | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIndex with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getIndex = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIndex(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIndex with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getIndex(request), expectedError); - }); - }); - - describe('deleteIndex', () => { - it('invokes deleteIndex without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteIndex = stubSimpleCall(expectedResponse); - const [response] = await client.deleteIndex(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteIndex without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteIndex = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteIndex( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteIndex with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteIndex = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteIndex(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteIndex with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteIndexRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteIndex(request), expectedError); - }); - }); - - describe('getField', () => { - it('invokes getField without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetFieldRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetFieldRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Field(), - ); - client.innerApiCalls.getField = stubSimpleCall(expectedResponse); - const [response] = await client.getField(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getField without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetFieldRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetFieldRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Field(), - ); - client.innerApiCalls.getField = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getField( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IField | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getField with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetFieldRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetFieldRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getField = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getField(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getField with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetFieldRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetFieldRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getField(request), expectedError); - }); - }); - - describe('getDatabase', () => { - it('invokes getDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Database(), - ); - client.innerApiCalls.getDatabase = stubSimpleCall(expectedResponse); - const [response] = await client.getDatabase(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Database(), - ); - client.innerApiCalls.getDatabase = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDatabase( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IDatabase | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDatabase with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDatabase = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.getDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDatabase with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getDatabase(request), expectedError); - }); - }); - - describe('listDatabases', () => { - it('invokes listDatabases without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListDatabasesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesResponse(), - ); - client.innerApiCalls.listDatabases = stubSimpleCall(expectedResponse); - const [response] = await client.listDatabases(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatabases without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListDatabasesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesResponse(), - ); - client.innerApiCalls.listDatabases = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDatabases( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IListDatabasesResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatabases with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListDatabasesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDatabases = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listDatabases(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDatabases as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatabases with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListDatabasesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListDatabasesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.listDatabases(request), expectedError); - }); - }); - - describe('createUserCreds', () => { - it('invokes createUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.createUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.createUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.createUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IUserCreds | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.createUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.createUserCreds(request), expectedError); - }); - }); - - describe('getUserCreds', () => { - it('invokes getUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.getUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.getUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.getUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IUserCreds | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.getUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getUserCreds(request), expectedError); - }); - }); - - describe('listUserCreds', () => { - it('invokes listUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsResponse(), - ); - client.innerApiCalls.listUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.listUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsResponse(), - ); - client.innerApiCalls.listUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IListUserCredsResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListUserCredsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.listUserCreds(request), expectedError); - }); - }); - - describe('enableUserCreds', () => { - it('invokes enableUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.EnableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.EnableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.enableUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.enableUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enableUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.EnableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.EnableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.enableUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.enableUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IUserCreds | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enableUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.EnableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.EnableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.enableUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.enableUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.enableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enableUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.EnableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.EnableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.enableUserCreds(request), expectedError); - }); - }); - - describe('disableUserCreds', () => { - it('invokes disableUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DisableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DisableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.disableUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.disableUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes disableUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DisableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DisableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.disableUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.disableUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IUserCreds | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes disableUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DisableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DisableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.disableUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.disableUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.disableUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes disableUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DisableUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DisableUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.disableUserCreds(request), expectedError); - }); - }); - - describe('resetUserPassword', () => { - it('invokes resetUserPassword without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ResetUserPasswordRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ResetUserPasswordRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.resetUserPassword = stubSimpleCall(expectedResponse); - const [response] = await client.resetUserPassword(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetUserPassword without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ResetUserPasswordRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ResetUserPasswordRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.UserCreds(), - ); - client.innerApiCalls.resetUserPassword = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resetUserPassword( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IUserCreds | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetUserPassword with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ResetUserPasswordRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ResetUserPasswordRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.resetUserPassword = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.resetUserPassword(request), expectedError); - const actualRequest = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.resetUserPassword as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetUserPassword with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ResetUserPasswordRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ResetUserPasswordRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.resetUserPassword(request), expectedError); - }); - }); - - describe('deleteUserCreds', () => { - it('invokes deleteUserCreds without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteUserCreds = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUserCreds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUserCreds without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteUserCreds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUserCreds( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUserCreds with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUserCreds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteUserCreds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteUserCreds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUserCreds with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteUserCredsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteUserCredsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteUserCreds(request), expectedError); - }); - }); - - describe('getBackup', () => { - it('invokes getBackup without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Backup(), - ); - client.innerApiCalls.getBackup = stubSimpleCall(expectedResponse); - const [response] = await client.getBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackup without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.Backup(), - ); - client.innerApiCalls.getBackup = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBackup( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IBackup | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackup with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBackup(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackup with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getBackup(request), expectedError); - }); - }); - - describe('listBackups', () => { - it('invokes listBackups without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsResponse(), - ); - client.innerApiCalls.listBackups = stubSimpleCall(expectedResponse); - const [response] = await client.listBackups(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackups without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsResponse(), - ); - client.innerApiCalls.listBackups = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBackups( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IListBackupsResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackups with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBackups = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listBackups(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackups as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackups with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.listBackups(request), expectedError); - }); - }); - - describe('deleteBackup', () => { - it('invokes deleteBackup without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteBackup = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackup without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteBackup = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBackup( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackup with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBackup = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteBackup(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackup as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackup with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteBackup(request), expectedError); - }); - }); - - describe('createBackupSchedule', () => { - it('invokes createBackupSchedule without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateBackupScheduleRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.createBackupSchedule = - stubSimpleCall(expectedResponse); - const [response] = await client.createBackupSchedule(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBackupSchedule without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateBackupScheduleRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.createBackupSchedule = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBackupSchedule( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IBackupSchedule | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBackupSchedule with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateBackupScheduleRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBackupSchedule = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.createBackupSchedule(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBackupSchedule with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateBackupScheduleRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.createBackupSchedule(request), expectedError); - }); - }); - - describe('getBackupSchedule', () => { - it('invokes getBackupSchedule without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.getBackupSchedule = stubSimpleCall(expectedResponse); - const [response] = await client.getBackupSchedule(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackupSchedule without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.getBackupSchedule = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBackupSchedule( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IBackupSchedule | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackupSchedule with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBackupSchedule = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.getBackupSchedule(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBackupSchedule with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.GetBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.GetBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getBackupSchedule(request), expectedError); - }); - }); - - describe('listBackupSchedules', () => { - it('invokes listBackupSchedules without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupSchedulesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesResponse(), - ); - client.innerApiCalls.listBackupSchedules = - stubSimpleCall(expectedResponse); - const [response] = await client.listBackupSchedules(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackupSchedules without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupSchedulesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesResponse(), - ); - client.innerApiCalls.listBackupSchedules = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBackupSchedules( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IListBackupSchedulesResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackupSchedules with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupSchedulesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBackupSchedules = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listBackupSchedules(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listBackupSchedules as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBackupSchedules with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListBackupSchedulesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListBackupSchedulesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.listBackupSchedules(request), expectedError); - }); - }); - - describe('updateBackupSchedule', () => { - it('invokes updateBackupSchedule without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateBackupScheduleRequest(), - ); - request.backupSchedule ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateBackupScheduleRequest', - ['backupSchedule', 'name'], - ); - request.backupSchedule.name = defaultValue1; - const expectedHeaderRequestParams = `backup_schedule.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.updateBackupSchedule = - stubSimpleCall(expectedResponse); - const [response] = await client.updateBackupSchedule(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBackupSchedule without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateBackupScheduleRequest(), - ); - request.backupSchedule ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateBackupScheduleRequest', - ['backupSchedule', 'name'], - ); - request.backupSchedule.name = defaultValue1; - const expectedHeaderRequestParams = `backup_schedule.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.admin.v1.BackupSchedule(), - ); - client.innerApiCalls.updateBackupSchedule = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBackupSchedule( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IBackupSchedule | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBackupSchedule with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateBackupScheduleRequest(), - ); - request.backupSchedule ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateBackupScheduleRequest', - ['backupSchedule', 'name'], - ); - request.backupSchedule.name = defaultValue1; - const expectedHeaderRequestParams = `backup_schedule.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBackupSchedule = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.updateBackupSchedule(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBackupSchedule with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateBackupScheduleRequest(), - ); - request.backupSchedule ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateBackupScheduleRequest', - ['backupSchedule', 'name'], - ); - request.backupSchedule.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.updateBackupSchedule(request), expectedError); - }); - }); - - describe('deleteBackupSchedule', () => { - it('invokes deleteBackupSchedule without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteBackupSchedule = - stubSimpleCall(expectedResponse); - const [response] = await client.deleteBackupSchedule(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackupSchedule without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteBackupSchedule = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBackupSchedule( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackupSchedule with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBackupSchedule = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteBackupSchedule(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteBackupSchedule as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBackupSchedule with closed client', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteBackupScheduleRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteBackupScheduleRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteBackupSchedule(request), expectedError); - }); - }); - - describe('createIndex', () => { - it('invokes createIndex without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateIndexRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.createIndex = stubLongRunningCall(expectedResponse); - const [operation] = await client.createIndex(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createIndex without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateIndexRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.createIndex = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createIndex( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IIndex, - protos.google.firestore.admin.v1.IIndexOperationMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createIndex with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateIndexRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createIndex = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.createIndex(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createIndex with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateIndexRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateIndexRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createIndex = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.createIndex(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createIndex as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateIndexProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateIndexProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateIndexProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.checkCreateIndexProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('updateField', () => { - it('invokes updateField without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateFieldRequest(), - ); - request.field ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateFieldRequest', - ['field', 'name'], - ); - request.field.name = defaultValue1; - const expectedHeaderRequestParams = `field.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.updateField = stubLongRunningCall(expectedResponse); - const [operation] = await client.updateField(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateField without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateFieldRequest(), - ); - request.field ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateFieldRequest', - ['field', 'name'], - ); - request.field.name = defaultValue1; - const expectedHeaderRequestParams = `field.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.updateField = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateField( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IField, - protos.google.firestore.admin.v1.IFieldOperationMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateField with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateFieldRequest(), - ); - request.field ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateFieldRequest', - ['field', 'name'], - ); - request.field.name = defaultValue1; - const expectedHeaderRequestParams = `field.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateField = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.updateField(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateField with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateFieldRequest(), - ); - request.field ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateFieldRequest', - ['field', 'name'], - ); - request.field.name = defaultValue1; - const expectedHeaderRequestParams = `field.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateField = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.updateField(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateField as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkUpdateFieldProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkUpdateFieldProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkUpdateFieldProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.checkUpdateFieldProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('exportDocuments', () => { - it('invokes exportDocuments without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ExportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ExportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.exportDocuments = - stubLongRunningCall(expectedResponse); - const [operation] = await client.exportDocuments(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportDocuments without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ExportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ExportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.exportDocuments = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportDocuments( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IExportDocumentsResponse, - protos.google.firestore.admin.v1.IExportDocumentsMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportDocuments with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ExportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ExportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportDocuments = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.exportDocuments(request), expectedError); - const actualRequest = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportDocuments with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ExportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ExportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportDocuments = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.exportDocuments(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.exportDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportDocumentsProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportDocumentsProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportDocumentsProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkExportDocumentsProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('importDocuments', () => { - it('invokes importDocuments without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ImportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ImportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.importDocuments = - stubLongRunningCall(expectedResponse); - const [operation] = await client.importDocuments(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importDocuments without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ImportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ImportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.importDocuments = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importDocuments( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.protobuf.IEmpty, - protos.google.firestore.admin.v1.IImportDocumentsMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importDocuments with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ImportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ImportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.importDocuments = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.importDocuments(request), expectedError); - const actualRequest = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importDocuments with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ImportDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ImportDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.importDocuments = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.importDocuments(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.importDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportDocumentsProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportDocumentsProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportDocumentsProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkImportDocumentsProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('bulkDeleteDocuments', () => { - it('invokes bulkDeleteDocuments without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.BulkDeleteDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.BulkDeleteDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.bulkDeleteDocuments = - stubLongRunningCall(expectedResponse); - const [operation] = await client.bulkDeleteDocuments(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes bulkDeleteDocuments without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.BulkDeleteDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.BulkDeleteDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.bulkDeleteDocuments = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.bulkDeleteDocuments( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IBulkDeleteDocumentsResponse, - protos.google.firestore.admin.v1.IBulkDeleteDocumentsMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes bulkDeleteDocuments with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.BulkDeleteDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.BulkDeleteDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.bulkDeleteDocuments = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.bulkDeleteDocuments(request), expectedError); - const actualRequest = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes bulkDeleteDocuments with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.BulkDeleteDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.BulkDeleteDocumentsRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.bulkDeleteDocuments = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.bulkDeleteDocuments(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.bulkDeleteDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkBulkDeleteDocumentsProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkBulkDeleteDocumentsProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkBulkDeleteDocumentsProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkBulkDeleteDocumentsProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('createDatabase', () => { - it('invokes createDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.createDatabase = - stubLongRunningCall(expectedResponse); - const [operation] = await client.createDatabase(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.createDatabase = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDatabase( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICreateDatabaseMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDatabase with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDatabase = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.createDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDatabase with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CreateDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.CreateDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDatabase = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.createDatabase(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateDatabaseProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateDatabaseProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateDatabaseProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkCreateDatabaseProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('updateDatabase', () => { - it('invokes updateDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateDatabaseRequest(), - ); - request.database ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateDatabaseRequest', - ['database', 'name'], - ); - request.database.name = defaultValue1; - const expectedHeaderRequestParams = `database.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.updateDatabase = - stubLongRunningCall(expectedResponse); - const [operation] = await client.updateDatabase(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateDatabaseRequest(), - ); - request.database ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateDatabaseRequest', - ['database', 'name'], - ); - request.database.name = defaultValue1; - const expectedHeaderRequestParams = `database.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.updateDatabase = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDatabase( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IUpdateDatabaseMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDatabase with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateDatabaseRequest(), - ); - request.database ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateDatabaseRequest', - ['database', 'name'], - ); - request.database.name = defaultValue1; - const expectedHeaderRequestParams = `database.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDatabase = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.updateDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDatabase with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.UpdateDatabaseRequest(), - ); - request.database ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.UpdateDatabaseRequest', - ['database', 'name'], - ); - request.database.name = defaultValue1; - const expectedHeaderRequestParams = `database.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDatabase = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.updateDatabase(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkUpdateDatabaseProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkUpdateDatabaseProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkUpdateDatabaseProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkUpdateDatabaseProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('deleteDatabase', () => { - it('invokes deleteDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.deleteDatabase = - stubLongRunningCall(expectedResponse); - const [operation] = await client.deleteDatabase(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.deleteDatabase = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDatabase( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IDeleteDatabaseMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDatabase with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDatabase = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDatabase with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.DeleteDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.DeleteDatabaseRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDatabase = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.deleteDatabase(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkDeleteDatabaseProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkDeleteDatabaseProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkDeleteDatabaseProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkDeleteDatabaseProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('restoreDatabase', () => { - it('invokes restoreDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.RestoreDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.RestoreDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.restoreDatabase = - stubLongRunningCall(expectedResponse); - const [operation] = await client.restoreDatabase(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.RestoreDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.RestoreDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.restoreDatabase = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restoreDatabase( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.IRestoreDatabaseMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreDatabase with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.RestoreDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.RestoreDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreDatabase = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.restoreDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreDatabase with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.RestoreDatabaseRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.RestoreDatabaseRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreDatabase = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.restoreDatabase(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.restoreDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRestoreDatabaseProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRestoreDatabaseProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRestoreDatabaseProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkRestoreDatabaseProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('cloneDatabase', () => { - it('invokes cloneDatabase without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CloneDatabaseRequest(), - ); - request.pitrSnapshot = {}; - // path template: projects/*/databases/{database_id=*}/** - request.pitrSnapshot.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.cloneDatabase = - stubLongRunningCall(expectedResponse); - const [operation] = await client.cloneDatabase(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cloneDatabase without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CloneDatabaseRequest(), - ); - request.pitrSnapshot = {}; - // path template: projects/*/databases/{database_id=*}/** - request.pitrSnapshot.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation(), - ); - client.innerApiCalls.cloneDatabase = - stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cloneDatabase( - request, - ( - err?: Error | null, - result?: LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - > | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const operation = (await promise) as LROperation< - protos.google.firestore.admin.v1.IDatabase, - protos.google.firestore.admin.v1.ICloneDatabaseMetadata - >; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cloneDatabase with call error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CloneDatabaseRequest(), - ); - request.pitrSnapshot = {}; - // path template: projects/*/databases/{database_id=*}/** - request.pitrSnapshot.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedError = new Error('expected'); - client.innerApiCalls.cloneDatabase = stubLongRunningCall( - undefined, - expectedError, - ); - await assert.rejects(client.cloneDatabase(request), expectedError); - const actualRequest = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cloneDatabase with LRO error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.CloneDatabaseRequest(), - ); - request.pitrSnapshot = {}; - // path template: projects/*/databases/{database_id=*}/** - request.pitrSnapshot.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedError = new Error('expected'); - client.innerApiCalls.cloneDatabase = stubLongRunningCall( - undefined, - undefined, - expectedError, - ); - const [operation] = await client.cloneDatabase(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.cloneDatabase as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCloneDatabaseProgress without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCloneDatabaseProgress( - expectedResponse.name, - ); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCloneDatabaseProgress with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.checkCloneDatabaseProgress(''), - expectedError, - ); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - }); - - describe('listIndexes', () => { - it('invokes listIndexes without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - ]; - client.innerApiCalls.listIndexes = stubSimpleCall(expectedResponse); - const [response] = await client.listIndexes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listIndexes without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - ]; - client.innerApiCalls.listIndexes = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listIndexes( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IIndex[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listIndexes with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listIndexes = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listIndexes(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listIndexes as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listIndexesStream without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - ]; - client.descriptors.page.listIndexes.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listIndexesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.admin.v1.Index[] = []; - stream.on( - 'data', - (response: protos.google.firestore.admin.v1.Index) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listIndexes.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listIndexes, request), - ); - assert( - (client.descriptors.page.listIndexes.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listIndexesStream with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listIndexes.createStream = stubPageStreamingCall( - undefined, - expectedError, - ); - const stream = client.listIndexesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.admin.v1.Index[] = []; - stream.on( - 'data', - (response: protos.google.firestore.admin.v1.Index) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listIndexes.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listIndexes, request), - ); - assert( - (client.descriptors.page.listIndexes.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listIndexes without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - generateSampleMessage(new protos.google.firestore.admin.v1.Index()), - ]; - client.descriptors.page.listIndexes.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.admin.v1.IIndex[] = []; - const iterable = client.listIndexesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listIndexes.asyncIterate as SinonStub).getCall( - 0, - ).args[1], - request, - ); - assert( - (client.descriptors.page.listIndexes.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listIndexes with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListIndexesRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListIndexesRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listIndexes.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError, - ); - const iterable = client.listIndexesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.admin.v1.IIndex[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listIndexes.asyncIterate as SinonStub).getCall( - 0, - ).args[1], - request, - ); - assert( - (client.descriptors.page.listIndexes.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - - describe('listFields', () => { - it('invokes listFields without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - ]; - client.innerApiCalls.listFields = stubSimpleCall(expectedResponse); - const [response] = await client.listFields(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFields without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - ]; - client.innerApiCalls.listFields = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listFields( - request, - ( - err?: Error | null, - result?: protos.google.firestore.admin.v1.IField[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFields with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listFields = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listFields(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listFields as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFieldsStream without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - ]; - client.descriptors.page.listFields.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listFieldsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.admin.v1.Field[] = []; - stream.on( - 'data', - (response: protos.google.firestore.admin.v1.Field) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listFields.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listFields, request), - ); - assert( - (client.descriptors.page.listFields.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listFieldsStream with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listFields.createStream = stubPageStreamingCall( - undefined, - expectedError, - ); - const stream = client.listFieldsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.admin.v1.Field[] = []; - stream.on( - 'data', - (response: protos.google.firestore.admin.v1.Field) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listFields.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listFields, request), - ); - assert( - (client.descriptors.page.listFields.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listFields without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - generateSampleMessage(new protos.google.firestore.admin.v1.Field()), - ]; - client.descriptors.page.listFields.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.admin.v1.IField[] = []; - const iterable = client.listFieldsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listFields.asyncIterate as SinonStub).getCall( - 0, - ).args[1], - request, - ); - assert( - (client.descriptors.page.listFields.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listFields with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.admin.v1.ListFieldsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.admin.v1.ListFieldsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listFields.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError, - ); - const iterable = client.listFieldsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.admin.v1.IField[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listFields.asyncIterate as SinonStub).getCall( - 0, - ).args[1], - request, - ); - assert( - (client.descriptors.page.listFields.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ); - client.locationsClient.getLocation = stubSimpleCall(expectedResponse); - const response = await client.getLocation(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert( - (client.locationsClient.getLocation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined), - ); - }); - it('invokes getLocation without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ); - client.locationsClient.getLocation = sinon - .stub() - .callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLocation( - request, - expectedOptions, - ( - err?: Error | null, - result?: LocationProtos.google.cloud.location.ILocation | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.locationsClient.getLocation as SinonStub).getCall(0)); - }); - it('invokes getLocation with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.locationsClient.getLocation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.getLocation(request, expectedOptions), - expectedError, - ); - assert( - (client.locationsClient.getLocation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined), - ); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams, - ), - ); - }); - it('uses async iteration with listLocations with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams, - ), - ); - }); - }); - describe('getOperation', () => { - it('invokes getOperation without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const response = await client.getOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert( - (client.operationsClient.getOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - it('invokes getOperation without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation(), - ); - client.operationsClient.getOperation = sinon - .stub() - .callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient - .getOperation( - request, - undefined, - ( - err?: Error | null, - result?: operationsProtos.google.longrunning.Operation | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ) - .catch(err => { - throw err; - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - it('invokes getOperation with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest(), - ); - const expectedError = new Error('expected'); - client.operationsClient.getOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(async () => { - await client.getOperation(request); - }, expectedError); - assert( - (client.operationsClient.getOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - }); - describe('cancelOperation', () => { - it('invokes cancelOperation without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.operationsClient.cancelOperation = - stubSimpleCall(expectedResponse); - const response = await client.cancelOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert( - (client.operationsClient.cancelOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - it('invokes cancelOperation without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.operationsClient.cancelOperation = sinon - .stub() - .callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient - .cancelOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ) - .catch(err => { - throw err; - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.cancelOperation as SinonStub).getCall(0)); - }); - it('invokes cancelOperation with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest(), - ); - const expectedError = new Error('expected'); - client.operationsClient.cancelOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(async () => { - await client.cancelOperation(request); - }, expectedError); - assert( - (client.operationsClient.cancelOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - }); - describe('deleteOperation', () => { - it('invokes deleteOperation without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.operationsClient.deleteOperation = - stubSimpleCall(expectedResponse); - const response = await client.deleteOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert( - (client.operationsClient.deleteOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - it('invokes deleteOperation without error using callback', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest(), - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.operationsClient.deleteOperation = sinon - .stub() - .callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient - .deleteOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ) - .catch(err => { - throw err; - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.deleteOperation as SinonStub).getCall(0)); - }); - it('invokes deleteOperation with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest(), - ); - const expectedError = new Error('expected'); - client.operationsClient.deleteOperation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(async () => { - await client.deleteOperation(request); - }, expectedError); - assert( - (client.operationsClient.deleteOperation as SinonStub) - .getCall(0) - .calledWith(request), - ); - }); - }); - describe('listOperationsAsync', () => { - it('uses async iteration with listOperations without error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest(), - ); - const expectedResponse = [ - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse(), - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse(), - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse(), - ), - ]; - client.operationsClient.descriptor.listOperations.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: operationsProtos.google.longrunning.IOperation[] = []; - const iterable = client.operationsClient.listOperationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.operationsClient.descriptor.listOperations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - }); - it('uses async iteration with listOperations with error', async () => { - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest(), - ); - const expectedError = new Error('expected'); - client.operationsClient.descriptor.listOperations.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.operationsClient.listOperationsAsync(request); - await assert.rejects(async () => { - const responses: operationsProtos.google.longrunning.IOperation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.operationsClient.descriptor.listOperations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - }); - }); - - describe('Path templates', () => { - describe('backup', async () => { - const fakePath = '/rendered/path/backup'; - const expectedParameters = { - project: 'projectValue', - location: 'locationValue', - backup: 'backupValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.backupPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath( - 'projectValue', - 'locationValue', - 'backupValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchLocationFromBackupName', () => { - const result = client.matchLocationFromBackupName(fakePath); - assert.strictEqual(result, 'locationValue'); - assert( - (client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, 'backupValue'); - assert( - (client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('backupSchedule', async () => { - const fakePath = '/rendered/path/backupSchedule'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - backup_schedule: 'backupScheduleValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupSchedulePathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.backupSchedulePathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('backupSchedulePath', () => { - const result = client.backupSchedulePath( - 'projectValue', - 'databaseValue', - 'backupScheduleValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.backupSchedulePathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromBackupScheduleName', () => { - const result = client.matchProjectFromBackupScheduleName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.backupSchedulePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromBackupScheduleName', () => { - const result = client.matchDatabaseFromBackupScheduleName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.backupSchedulePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchBackupScheduleFromBackupScheduleName', () => { - const result = - client.matchBackupScheduleFromBackupScheduleName(fakePath); - assert.strictEqual(result, 'backupScheduleValue'); - assert( - (client.pathTemplates.backupSchedulePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('collectionGroup', async () => { - const fakePath = '/rendered/path/collectionGroup'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - collection: 'collectionValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.collectionGroupPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.collectionGroupPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('collectionGroupPath', () => { - const result = client.collectionGroupPath( - 'projectValue', - 'databaseValue', - 'collectionValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.collectionGroupPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromCollectionGroupName', () => { - const result = client.matchProjectFromCollectionGroupName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.collectionGroupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromCollectionGroupName', () => { - const result = client.matchDatabaseFromCollectionGroupName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.collectionGroupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchCollectionFromCollectionGroupName', () => { - const result = client.matchCollectionFromCollectionGroupName(fakePath); - assert.strictEqual(result, 'collectionValue'); - assert( - (client.pathTemplates.collectionGroupPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('database', async () => { - const fakePath = '/rendered/path/database'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.databasePathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.databasePathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('databasePath', () => { - const result = client.databasePath('projectValue', 'databaseValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.databasePathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromDatabaseName', () => { - const result = client.matchProjectFromDatabaseName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.databasePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromDatabaseName', () => { - const result = client.matchDatabaseFromDatabaseName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.databasePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('field', async () => { - const fakePath = '/rendered/path/field'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - collection: 'collectionValue', - field: 'fieldValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.fieldPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.fieldPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('fieldPath', () => { - const result = client.fieldPath( - 'projectValue', - 'databaseValue', - 'collectionValue', - 'fieldValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.fieldPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromFieldName', () => { - const result = client.matchProjectFromFieldName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.fieldPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromFieldName', () => { - const result = client.matchDatabaseFromFieldName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.fieldPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchCollectionFromFieldName', () => { - const result = client.matchCollectionFromFieldName(fakePath); - assert.strictEqual(result, 'collectionValue'); - assert( - (client.pathTemplates.fieldPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchFieldFromFieldName', () => { - const result = client.matchFieldFromFieldName(fakePath); - assert.strictEqual(result, 'fieldValue'); - assert( - (client.pathTemplates.fieldPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('index', async () => { - const fakePath = '/rendered/path/index'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - collection: 'collectionValue', - index: 'indexValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.indexPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.indexPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('indexPath', () => { - const result = client.indexPath( - 'projectValue', - 'databaseValue', - 'collectionValue', - 'indexValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.indexPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromIndexName', () => { - const result = client.matchProjectFromIndexName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.indexPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromIndexName', () => { - const result = client.matchDatabaseFromIndexName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.indexPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchCollectionFromIndexName', () => { - const result = client.matchCollectionFromIndexName(fakePath); - assert.strictEqual(result, 'collectionValue'); - assert( - (client.pathTemplates.indexPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchIndexFromIndexName', () => { - const result = client.matchIndexFromIndexName(fakePath); - assert.strictEqual(result, 'indexValue'); - assert( - (client.pathTemplates.indexPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('location', async () => { - const fakePath = '/rendered/path/location'; - const expectedParameters = { - project: 'projectValue', - location: 'locationValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.locationPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.locationPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath('projectValue', 'locationValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, 'locationValue'); - assert( - (client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('project', async () => { - const fakePath = '/rendered/path/project'; - const expectedParameters = { - project: 'projectValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.projectPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath('projectValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - - describe('userCreds', async () => { - const fakePath = '/rendered/path/userCreds'; - const expectedParameters = { - project: 'projectValue', - database: 'databaseValue', - user_creds: 'userCredsValue', - }; - const client = new firestoreadminModule.FirestoreAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userCredsPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.userCredsPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('userCredsPath', () => { - const result = client.userCredsPath( - 'projectValue', - 'databaseValue', - 'userCredsValue', - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.userCredsPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters), - ); - }); - - it('matchProjectFromUserCredsName', () => { - const result = client.matchProjectFromUserCredsName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.userCredsPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchDatabaseFromUserCredsName', () => { - const result = client.matchDatabaseFromUserCredsName(fakePath); - assert.strictEqual(result, 'databaseValue'); - assert( - (client.pathTemplates.userCredsPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - - it('matchUserCredsFromUserCredsName', () => { - const result = client.matchUserCredsFromUserCredsName(fakePath); - assert.strictEqual(result, 'userCredsValue'); - assert( - (client.pathTemplates.userCredsPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath), - ); - }); - }); - }); -}); diff --git a/handwritten/firestore/dev/test/gapic_firestore_v1.ts b/handwritten/firestore/dev/test/gapic_firestore_v1.ts deleted file mode 100644 index 4e91b6d2de22..000000000000 --- a/handwritten/firestore/dev/test/gapic_firestore_v1.ts +++ /dev/null @@ -1,3379 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/firestore_v1_proto_api'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as firestoreModule from '../src/v1'; - -import {PassThrough} from 'stream'; - -import {protobuf, LocationProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/v1.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = ( - instance.constructor as typeof protobuf.Message - ).toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject( - filledObject, - ) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error - ? sinon.stub().rejects(error) - : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback( - response?: ResponseType, - error?: Error, -) { - return error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall( - response?: ResponseType, - error?: Error, -) { - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall( - response?: ResponseType, - error?: Error, -) { - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubPageStreamingCall( - responses?: ResponseType[], - error?: Error, -) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { - mockStream.write({}); - }); - } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall( - responses?: ResponseType[], - error?: Error, -) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - }, - }; - }, - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.FirestoreClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new firestoreModule.FirestoreClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new firestoreModule.FirestoreClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, 'googleapis.com'); - }); - - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = firestoreModule.FirestoreClient.servicePath; - assert.strictEqual(servicePath, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = firestoreModule.FirestoreClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new firestoreModule.FirestoreClient({ - universeDomain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new firestoreModule.FirestoreClient({ - universe_domain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreModule.FirestoreClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreModule.FirestoreClient({ - universeDomain: 'configured.example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { - new firestoreModule.FirestoreClient({ - universe_domain: 'example.com', - universeDomain: 'example.net', - }); - }); - }); - - it('has port', () => { - const port = firestoreModule.FirestoreClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new firestoreModule.FirestoreClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new firestoreModule.FirestoreClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreStub, undefined); - await client.initialize(); - assert(client.firestoreStub); - }); - - it('has close method for the initialized client', done => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => { - throw err; - }); - assert(client.firestoreStub); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreStub, undefined); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('getDocument', () => { - it('invokes getDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.getDocument = stubSimpleCall(expectedResponse); - const [response] = await client.getDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.getDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.getDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getDocument(request), expectedError); - }); - }); - - describe('updateDocument', () => { - it('invokes updateDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.updateDocument = stubSimpleCall(expectedResponse); - const [response] = await client.updateDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.updateDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.updateDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.updateDocument(request), expectedError); - }); - }); - - describe('deleteDocument', () => { - it('invokes deleteDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteDocument = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDocument( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteDocument(request), expectedError); - }); - }); - - describe('beginTransaction', () => { - it('invokes beginTransaction without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionResponse(), - ); - client.innerApiCalls.beginTransaction = stubSimpleCall(expectedResponse); - const [response] = await client.beginTransaction(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionResponse(), - ); - client.innerApiCalls.beginTransaction = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.beginTransaction( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IBeginTransactionResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.beginTransaction = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.beginTransaction(request), expectedError); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.beginTransaction(request), expectedError); - }); - }); - - describe('commit', () => { - it('invokes commit without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.CommitResponse(), - ); - client.innerApiCalls.commit = stubSimpleCall(expectedResponse); - const [response] = await client.commit(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.CommitResponse(), - ); - client.innerApiCalls.commit = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.commit( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.ICommitResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.commit = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.commit(request), expectedError); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.commit(request), expectedError); - }); - }); - - describe('rollback', () => { - it('invokes rollback without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.rollback = stubSimpleCall(expectedResponse); - const [response] = await client.rollback(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.rollback = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rollback( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.rollback = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rollback(request), expectedError); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.rollback(request), expectedError); - }); - }); - - describe('batchWrite', () => { - it('invokes batchWrite without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteResponse(), - ); - client.innerApiCalls.batchWrite = stubSimpleCall(expectedResponse); - const [response] = await client.batchWrite(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteResponse(), - ); - client.innerApiCalls.batchWrite = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchWrite( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IBatchWriteResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchWrite = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.batchWrite(request), expectedError); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.batchWrite(request), expectedError); - }); - }); - - describe('createDocument', () => { - it('invokes createDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.createDocument = stubSimpleCall(expectedResponse); - const [response] = await client.createDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.Document(), - ); - client.innerApiCalls.createDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.createDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.createDocument(request), expectedError); - }); - }); - - describe('batchGetDocuments', () => { - it('invokes batchGetDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsResponse(), - ); - client.innerApiCalls.batchGetDocuments = - stubServerStreamingCall(expectedResponse); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.BatchGetDocumentsResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsResponse(), - ); - client.innerApiCalls.batchGetDocuments = - stubServerStreamingCall(expectedResponse); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.BatchGetDocumentsResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchGetDocuments = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.BatchGetDocumentsResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.batchGetDocuments(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.BatchGetDocumentsResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('runQuery', () => { - it('invokes runQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.RunQueryResponse(), - ); - client.innerApiCalls.runQuery = stubServerStreamingCall(expectedResponse); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.RunQueryResponse(), - ); - client.innerApiCalls.runQuery = stubServerStreamingCall(expectedResponse); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.runQuery = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.runQuery(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('executePipeline', () => { - it('invokes executePipeline without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineRequest(), - ); - // path template: projects/*/databases/{database_id=*}/** - request.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineResponse(), - ); - client.innerApiCalls.executePipeline = - stubServerStreamingCall(expectedResponse); - const stream = client.executePipeline(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ExecutePipelineResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executePipeline without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineRequest(), - ); - // path template: projects/*/databases/{database_id=*}/** - request.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineResponse(), - ); - client.innerApiCalls.executePipeline = - stubServerStreamingCall(expectedResponse); - const stream = client.executePipeline(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ExecutePipelineResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executePipeline with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineRequest(), - ); - // path template: projects/*/databases/{database_id=*}/** - request.database = 'projects/value/databases/value/value'; - const expectedHeaderRequestParams = 'database_id=value'; - const expectedError = new Error('expected'); - client.innerApiCalls.executePipeline = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.executePipeline(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ExecutePipelineResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.executePipeline as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executePipeline with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ExecutePipelineRequest(), - ); - // path template: projects/*/databases/{database_id=*}/** - request.database = 'projects/value/databases/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.executePipeline(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ExecutePipelineResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('runAggregationQuery', () => { - it('invokes runAggregationQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunAggregationQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryResponse(), - ); - client.innerApiCalls.runAggregationQuery = - stubServerStreamingCall(expectedResponse); - const stream = client.runAggregationQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1.RunAggregationQueryResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runAggregationQuery without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunAggregationQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryResponse(), - ); - client.innerApiCalls.runAggregationQuery = - stubServerStreamingCall(expectedResponse); - const stream = client.runAggregationQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1.RunAggregationQueryResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runAggregationQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunAggregationQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.runAggregationQuery = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.runAggregationQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1.RunAggregationQueryResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runAggregationQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runAggregationQuery with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.RunAggregationQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.RunAggregationQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.runAggregationQuery(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1.RunAggregationQueryResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('write', () => { - it('invokes write without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.WriteRequest(), - ); - - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.WriteResponse(), - ); - client.innerApiCalls.write = stubBidiStreamingCall(expectedResponse); - const stream = client.write(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.WriteResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.write as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - - it('invokes write with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.WriteRequest(), - ); - const expectedError = new Error('expected'); - client.innerApiCalls.write = stubBidiStreamingCall( - undefined, - expectedError, - ); - const stream = client.write(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.WriteResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert( - (client.innerApiCalls.write as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - }); - - describe('listen', () => { - it('invokes listen without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListenRequest(), - ); - - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1.ListenResponse(), - ); - client.innerApiCalls.listen = stubBidiStreamingCall(expectedResponse); - const stream = client.listen(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ListenResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listen as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - - it('invokes listen with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListenRequest(), - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listen = stubBidiStreamingCall( - undefined, - expectedError, - ); - const stream = client.listen(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1.ListenResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert( - (client.innerApiCalls.listen as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - }); - - describe('listDocuments', () => { - it('invokes listDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - ]; - client.innerApiCalls.listDocuments = stubSimpleCall(expectedResponse); - const [response] = await client.listDocuments(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocuments without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - ]; - client.innerApiCalls.listDocuments = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDocuments( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.IDocument[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDocuments = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listDocuments(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocumentsStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - ]; - client.descriptors.page.listDocuments.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listDocumentsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1.Document[] = []; - stream.on('data', (response: protos.google.firestore.v1.Document) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listDocuments, request), - ); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listDocumentsStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listDocuments.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listDocumentsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1.Document[] = []; - stream.on('data', (response: protos.google.firestore.v1.Document) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listDocuments, request), - ); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - generateSampleMessage(new protos.google.firestore.v1.Document()), - ]; - client.descriptors.page.listDocuments.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.v1.IDocument[] = []; - const iterable = client.listDocumentsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listDocuments.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listDocuments.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listDocuments.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDocumentsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.v1.IDocument[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listDocuments.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listDocuments.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - - describe('partitionQuery', () => { - it('invokes partitionQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - ]; - client.innerApiCalls.partitionQuery = stubSimpleCall(expectedResponse); - const [response] = await client.partitionQuery(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQuery without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - ]; - client.innerApiCalls.partitionQuery = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.partitionQuery( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1.ICursor[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.partitionQuery = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.partitionQuery(request), expectedError); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQueryStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - ]; - client.descriptors.page.partitionQuery.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.partitionQueryStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1.Cursor[] = []; - stream.on('data', (response: protos.google.firestore.v1.Cursor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.partitionQuery, request), - ); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes partitionQueryStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.partitionQuery.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.partitionQueryStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1.Cursor[] = []; - stream.on('data', (response: protos.google.firestore.v1.Cursor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.partitionQuery, request), - ); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with partitionQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1.Cursor()), - ]; - client.descriptors.page.partitionQuery.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.v1.ICursor[] = []; - const iterable = client.partitionQueryAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.partitionQuery.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.partitionQuery.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with partitionQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.partitionQuery.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.partitionQueryAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.v1.ICursor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.partitionQuery.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.partitionQuery.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - - describe('listCollectionIds', () => { - it('invokes listCollectionIds without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listCollectionIds = stubSimpleCall(expectedResponse); - const [response] = await client.listCollectionIds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIds without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listCollectionIds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCollectionIds( - request, - (err?: Error | null, result?: string[] | null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIds with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCollectionIds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listCollectionIds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIdsStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listCollectionIds.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listCollectionIdsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listCollectionIds, request), - ); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listCollectionIdsStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listCollectionIds.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listCollectionIdsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listCollectionIds, request), - ); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listCollectionIds without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listCollectionIds.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listCollectionIdsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listCollectionIds.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listCollectionIds.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listCollectionIds with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listCollectionIds.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCollectionIdsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listCollectionIds.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listCollectionIds.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ); - client.locationsClient.getLocation = stubSimpleCall(expectedResponse); - const response = await client.getLocation(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert( - (client.locationsClient.getLocation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined), - ); - }); - it('invokes getLocation without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ); - client.locationsClient.getLocation = sinon - .stub() - .callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLocation( - request, - expectedOptions, - ( - err?: Error | null, - result?: LocationProtos.google.cloud.location.ILocation | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.locationsClient.getLocation as SinonStub).getCall(0)); - }); - it('invokes getLocation with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.GetLocationRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.locationsClient.getLocation = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects( - client.getLocation(request, expectedOptions), - expectedError, - ); - assert( - (client.locationsClient.getLocation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined), - ); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location(), - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams, - ), - ); - }); - it('uses async iteration with listLocations with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest(), - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - ( - client.locationsClient.descriptors.page.listLocations - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams, - ), - ); - }); - }); -}); diff --git a/handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts b/handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts deleted file mode 100644 index 802d93a22541..000000000000 --- a/handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts +++ /dev/null @@ -1,2857 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/firestore_v1beta1_proto_api'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as firestoreModule from '../src/v1beta1'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - require('../protos/v1beta1.json'), -).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = ( - instance.constructor as typeof protobuf.Message - ).toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject( - filledObject, - ) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error - ? sinon.stub().rejects(error) - : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback( - response?: ResponseType, - error?: Error, -) { - return error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall( - response?: ResponseType, - error?: Error, -) { - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall( - response?: ResponseType, - error?: Error, -) { - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubPageStreamingCall( - responses?: ResponseType[], - error?: Error, -) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { - mockStream.write({}); - }); - } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall( - responses?: ResponseType[], - error?: Error, -) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - }, - }; - }, - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.FirestoreClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new firestoreModule.FirestoreClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new firestoreModule.FirestoreClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, 'googleapis.com'); - }); - - if ( - typeof process === 'object' && - typeof process.emitWarning === 'function' - ) { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = firestoreModule.FirestoreClient.servicePath; - assert.strictEqual(servicePath, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = firestoreModule.FirestoreClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'firestore.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new firestoreModule.FirestoreClient({ - universeDomain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new firestoreModule.FirestoreClient({ - universe_domain: 'example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreModule.FirestoreClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new firestoreModule.FirestoreClient({ - universeDomain: 'configured.example.com', - }); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'firestore.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { - new firestoreModule.FirestoreClient({ - universe_domain: 'example.com', - universeDomain: 'example.net', - }); - }); - }); - - it('has port', () => { - const port = firestoreModule.FirestoreClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new firestoreModule.FirestoreClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new firestoreModule.FirestoreClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreStub, undefined); - await client.initialize(); - assert(client.firestoreStub); - }); - - it('has close method for the initialized client', done => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => { - throw err; - }); - assert(client.firestoreStub); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.firestoreStub, undefined); - client - .close() - .then(() => { - done(); - }) - .catch(err => { - throw err; - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('getDocument', () => { - it('invokes getDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.getDocument = stubSimpleCall(expectedResponse); - const [response] = await client.getDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.getDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.getDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.GetDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.GetDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.getDocument(request), expectedError); - }); - }); - - describe('updateDocument', () => { - it('invokes updateDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.updateDocument = stubSimpleCall(expectedResponse); - const [response] = await client.updateDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.updateDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedHeaderRequestParams = `document.name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.updateDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.UpdateDocumentRequest(), - ); - request.document ??= {}; - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.UpdateDocumentRequest', - ['document', 'name'], - ); - request.document.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.updateDocument(request), expectedError); - }); - }); - - describe('deleteDocument', () => { - it('invokes deleteDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteDocument = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.deleteDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDocument( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.deleteDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.deleteDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.DeleteDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.DeleteDocumentRequest', - ['name'], - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.deleteDocument(request), expectedError); - }); - }); - - describe('beginTransaction', () => { - it('invokes beginTransaction without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionResponse(), - ); - client.innerApiCalls.beginTransaction = stubSimpleCall(expectedResponse); - const [response] = await client.beginTransaction(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionResponse(), - ); - client.innerApiCalls.beginTransaction = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.beginTransaction( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IBeginTransactionResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.beginTransaction = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.beginTransaction(request), expectedError); - const actualRequest = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.beginTransaction as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes beginTransaction with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BeginTransactionRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BeginTransactionRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.beginTransaction(request), expectedError); - }); - }); - - describe('commit', () => { - it('invokes commit without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitResponse(), - ); - client.innerApiCalls.commit = stubSimpleCall(expectedResponse); - const [response] = await client.commit(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitResponse(), - ); - client.innerApiCalls.commit = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.commit( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.ICommitResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.commit = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.commit(request), expectedError); - const actualRequest = (client.innerApiCalls.commit as SinonStub).getCall( - 0, - ).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.commit as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commit with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CommitRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CommitRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.commit(request), expectedError); - }); - }); - - describe('rollback', () => { - it('invokes rollback without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.rollback = stubSimpleCall(expectedResponse); - const [response] = await client.rollback(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty(), - ); - client.innerApiCalls.rollback = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rollback( - request, - ( - err?: Error | null, - result?: protos.google.protobuf.IEmpty | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.rollback = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rollback(request), expectedError); - const actualRequest = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.rollback as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollback with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RollbackRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RollbackRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.rollback(request), expectedError); - }); - }); - - describe('batchWrite', () => { - it('invokes batchWrite without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteResponse(), - ); - client.innerApiCalls.batchWrite = stubSimpleCall(expectedResponse); - const [response] = await client.batchWrite(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteResponse(), - ); - client.innerApiCalls.batchWrite = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchWrite( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IBatchWriteResponse | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchWrite = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.batchWrite(request), expectedError); - const actualRequest = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchWrite as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchWrite with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchWriteRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchWriteRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.batchWrite(request), expectedError); - }); - }); - - describe('createDocument', () => { - it('invokes createDocument without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.createDocument = stubSimpleCall(expectedResponse); - const [response] = await client.createDocument(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.Document(), - ); - client.innerApiCalls.createDocument = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDocument( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IDocument | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDocument = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.createDocument(request), expectedError); - const actualRequest = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.createDocument as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDocument with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.CreateDocumentRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.CreateDocumentRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - await assert.rejects(client.createDocument(request), expectedError); - }); - }); - - describe('batchGetDocuments', () => { - it('invokes batchGetDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsResponse(), - ); - client.innerApiCalls.batchGetDocuments = - stubServerStreamingCall(expectedResponse); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1beta1.BatchGetDocumentsResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsResponse(), - ); - client.innerApiCalls.batchGetDocuments = - stubServerStreamingCall(expectedResponse); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1beta1.BatchGetDocumentsResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedHeaderRequestParams = `database=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchGetDocuments = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.batchGetDocuments(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1beta1.BatchGetDocumentsResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.batchGetDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetDocuments with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.BatchGetDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.BatchGetDocumentsRequest', - ['database'], - ); - request.database = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.batchGetDocuments(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - ( - response: protos.google.firestore.v1beta1.BatchGetDocumentsResponse, - ) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('runQuery', () => { - it('invokes runQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryResponse(), - ); - client.innerApiCalls.runQuery = stubServerStreamingCall(expectedResponse); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery without error and gaxServerStreamingRetries enabled', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true, - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryResponse(), - ); - client.innerApiCalls.runQuery = stubServerStreamingCall(expectedResponse); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.runQuery = stubServerStreamingCall( - undefined, - expectedError, - ); - const stream = client.runQuery(request); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.runQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runQuery with closed client', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.RunQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.RunQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => { - throw err; - }); - const stream = client.runQuery(request, { - retryRequestOptions: {noResponseRetries: 0}, - }); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.RunQueryResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new firestoreModule.FirestoreClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('write', () => { - it('invokes write without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.WriteRequest(), - ); - - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.WriteResponse(), - ); - client.innerApiCalls.write = stubBidiStreamingCall(expectedResponse); - const stream = client.write(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.WriteResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.write as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - - it('invokes write with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.WriteRequest(), - ); - const expectedError = new Error('expected'); - client.innerApiCalls.write = stubBidiStreamingCall( - undefined, - expectedError, - ); - const stream = client.write(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.WriteResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert( - (client.innerApiCalls.write as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - }); - - describe('listen', () => { - it('invokes listen without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListenRequest(), - ); - - const expectedResponse = generateSampleMessage( - new protos.google.firestore.v1beta1.ListenResponse(), - ); - client.innerApiCalls.listen = stubBidiStreamingCall(expectedResponse); - const stream = client.listen(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.ListenResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listen as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - - it('invokes listen with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListenRequest(), - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listen = stubBidiStreamingCall( - undefined, - expectedError, - ); - const stream = client.listen(); - const promise = new Promise((resolve, reject) => { - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.ListenResponse) => { - resolve(response); - }, - ); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert( - (client.innerApiCalls.listen as SinonStub).getCall(0).calledWith(null), - ); - assert.deepStrictEqual( - ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) - .args[0], - request, - ); - }); - }); - - describe('listDocuments', () => { - it('invokes listDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - ]; - client.innerApiCalls.listDocuments = stubSimpleCall(expectedResponse); - const [response] = await client.listDocuments(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocuments without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - ]; - client.innerApiCalls.listDocuments = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDocuments( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.IDocument[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDocuments = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listDocuments(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listDocuments as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDocumentsStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - ]; - client.descriptors.page.listDocuments.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listDocumentsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1beta1.Document[] = []; - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.Document) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listDocuments, request), - ); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listDocumentsStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listDocuments.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listDocumentsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1beta1.Document[] = []; - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.Document) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listDocuments, request), - ); - assert( - (client.descriptors.page.listDocuments.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listDocuments without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - generateSampleMessage(new protos.google.firestore.v1beta1.Document()), - ]; - client.descriptors.page.listDocuments.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.v1beta1.IDocument[] = []; - const iterable = client.listDocumentsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listDocuments.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listDocuments.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listDocuments with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListDocumentsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const defaultValue2 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListDocumentsRequest', - ['collectionId'], - ); - request.collectionId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}&collection_id=${defaultValue2 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listDocuments.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDocumentsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.v1beta1.IDocument[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listDocuments.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listDocuments.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - - describe('partitionQuery', () => { - it('invokes partitionQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - ]; - client.innerApiCalls.partitionQuery = stubSimpleCall(expectedResponse); - const [response] = await client.partitionQuery(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQuery without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - ]; - client.innerApiCalls.partitionQuery = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.partitionQuery( - request, - ( - err?: Error | null, - result?: protos.google.firestore.v1beta1.ICursor[] | null, - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.partitionQuery = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.partitionQuery(request), expectedError); - const actualRequest = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.partitionQuery as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes partitionQueryStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - ]; - client.descriptors.page.partitionQuery.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.partitionQueryStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1beta1.Cursor[] = []; - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.Cursor) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.partitionQuery, request), - ); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes partitionQueryStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.partitionQuery.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.partitionQueryStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.firestore.v1beta1.Cursor[] = []; - stream.on( - 'data', - (response: protos.google.firestore.v1beta1.Cursor) => { - responses.push(response); - }, - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.partitionQuery, request), - ); - assert( - (client.descriptors.page.partitionQuery.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with partitionQuery without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - generateSampleMessage(new protos.google.firestore.v1beta1.Cursor()), - ]; - client.descriptors.page.partitionQuery.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.firestore.v1beta1.ICursor[] = []; - const iterable = client.partitionQueryAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.partitionQuery.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.partitionQuery.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with partitionQuery with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.PartitionQueryRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.PartitionQueryRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.partitionQuery.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.partitionQueryAsync(request); - await assert.rejects(async () => { - const responses: protos.google.firestore.v1beta1.ICursor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.partitionQuery.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.partitionQuery.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); - - describe('listCollectionIds', () => { - it('invokes listCollectionIds without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listCollectionIds = stubSimpleCall(expectedResponse); - const [response] = await client.listCollectionIds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIds without error using callback', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listCollectionIds = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCollectionIds( - request, - (err?: Error | null, result?: string[] | null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }, - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIds with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCollectionIds = stubSimpleCall( - undefined, - expectedError, - ); - await assert.rejects(client.listCollectionIds(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listCollectionIds as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCollectionIdsStream without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listCollectionIds.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listCollectionIdsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listCollectionIds, request), - ); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('invokes listCollectionIdsStream with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listCollectionIds.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listCollectionIdsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listCollectionIds, request), - ); - assert( - (client.descriptors.page.listCollectionIds.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listCollectionIds without error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listCollectionIds.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listCollectionIdsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listCollectionIds.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listCollectionIds.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - - it('uses async iteration with listCollectionIds with error', async () => { - const client = new firestoreModule.FirestoreClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.firestore.v1beta1.ListCollectionIdsRequest(), - ); - const defaultValue1 = getTypeDefaultValue( - '.google.firestore.v1beta1.ListCollectionIdsRequest', - ['parent'], - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; - const expectedError = new Error('expected'); - client.descriptors.page.listCollectionIds.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCollectionIdsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listCollectionIds.asyncIterate as SinonStub - ).getCall(0).args[1], - request, - ); - assert( - (client.descriptors.page.listCollectionIds.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers[ - 'x-goog-request-params' - ].includes(expectedHeaderRequestParams), - ); - }); - }); -}); diff --git a/handwritten/firestore/dev/test/util/helpers.ts b/handwritten/firestore/dev/test/util/helpers.ts index 3764af179ad9..fbe447bfb96e 100644 --- a/handwritten/firestore/dev/test/util/helpers.ts +++ b/handwritten/firestore/dev/test/util/helpers.ts @@ -27,7 +27,7 @@ import * as through2 from 'through2'; import {firestore} from '../../protos/firestore_v1_proto_api'; import type {grpc} from 'google-gax'; import * as proto from '../../protos/firestore_v1_proto_api'; -import * as v1 from '../../src/v1'; +import * as v1 from '@google-cloud/firestore-api/build/src/v1'; import {Firestore, QueryDocumentSnapshot} from '../../src'; import {ClientPool} from '../../src/pool'; import {GapicClient} from '../../src/types'; diff --git a/handwritten/firestore/owlbot.py b/handwritten/firestore/owlbot.py deleted file mode 100644 index 284518f7a07c..000000000000 --- a/handwritten/firestore/owlbot.py +++ /dev/null @@ -1,246 +0,0 @@ -import synthtool as s -import synthtool.gcp as gcp -import synthtool.languages.node_mono_repo as node -import logging -import os -import subprocess -from pathlib import Path -from synthtool import _tracked_paths -import shutil -from synthtool import shell -from synthtool.log import logger - -logging.basicConfig(level=logging.DEBUG) - -staging = Path("owl-bot-staging") -if staging.is_dir(): - try: - v1_admin_library = staging / "admin/v1" - v1beta1_library = staging / "firestore" / "v1beta1" - v1_library = staging / "firestore" / "v1" - - _tracked_paths.add(v1_admin_library) - _tracked_paths.add(v1beta1_library) - _tracked_paths.add(v1_library) - - # skip index, protos, package.json, and README.md - s.copy(v1_admin_library, "handwritten/firestore/dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1/index.ts", - "tsconfig.json", "linkinator.config.json", "webpack.config.js"]) - s.copy(v1beta1_library, "handwritten/firestore/dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1beta1/index.ts", - "tsconfig.json", "linkinator.config.json", "webpack.config.js"]) - s.copy(v1_library, "handwritten/firestore/dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1/index.ts", - "tsconfig.json", "linkinator.config.json", "webpack.config.js"]) - - # Fix dropping of google-cloud-resource-header - # See: https://github.com/googleapis/nodejs-firestore/pull/375 - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"return this\.innerApiCalls\.listen\(options\);", - "return this.innerApiCalls.listen({}, options);", - ) - s.replace( - "handwritten/firestore/dev/src/v1/firestore_client.ts", - r"return this\.innerApiCalls\.listen\(options\);", - "return this.innerApiCalls.listen({}, options);", - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"calledWithExactly\(undefined\)", - "calledWithExactly({}, undefined)", - ) - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"return this\.innerApiCalls\.write\(options\);", - "return this.innerApiCalls.write({}, options);", - ) - s.replace( - "handwritten/firestore/dev/src/v1/firestore_client.ts", - r"return this\.innerApiCalls\.write\(options\);", - "return this.innerApiCalls.write({}, options);", - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"calledWithExactly\(undefined\)", - "calledWithExactly({}, undefined)", - ) - - # use the existing proto .js / .d.ts files - s.replace( - "handwritten/firestore/dev/src/v1/firestore_client.ts", - r"/protos/protos'", - "/protos/firestore_v1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"/protos/protos'", - "/protos/firestore_v1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"import \* as firestoreModule from '\.\./src';", - "import * as firestoreModule from '../src/v1';" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"firestoreModule\.v1", - "firestoreModule" - ) - s.replace( - "handwritten/firestore/dev/src/v1/firestore_admin_client.ts", - r"/protos/protos'", - "/protos/firestore_admin_v1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts", - r"/protos/protos'", - "/protos/firestore_admin_v1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts", - r"import \* as firestoreadminModule from '\.\./src';", - "import * as firestoreadminModule from '../src/v1';" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts", - r"firestoreadminModule\.v1", - "firestoreadminModule" - ) - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"/protos/protos'", - "/protos/firestore_v1beta1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts", - r"/protos/protos'", - "/protos/firestore_v1beta1_proto_api'" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts", - r"import \* as firestoreModule from \'../src\';", - "import * as firestoreModule from '../src/v1beta1';" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts", - r"firestoreModule\.v1beta1", - "firestoreModule" - ) - s.replace( - "handwritten/firestore/dev/src/v1/firestore_client.ts", - r"\.\./\.\./protos/protos.json", - "../../protos/v1.json" - ) - s.replace( - "handwritten/firestore/dev/src/v1/firestore_admin_client.ts", - r"\.\./\.\./protos/protos.json", - "../../protos/admin_v1.json" - ) - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"\.\./\.\./protos/protos.json", - "../../protos/v1beta1.json" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1.ts", - r"\.\./protos/protos.json", - "../protos/v1.json" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_admin_v1.ts", - r"\.\./protos/protos.json", - "../protos/admin_v1.json" - ) - s.replace( - "handwritten/firestore/dev/test/gapic_firestore_v1beta1.ts", - r"\.\./protos/protos.json", - "../protos/v1beta1.json" - ) - - # Mark v1beta1 as deprecated - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"@class", - "@class\n * @deprecated Use v1/firestore_client instead." - ) - s.replace( - "handwritten/firestore/dev/src/v1beta1/firestore_client.ts", - r"const version", - "// tslint:disable deprecation\n\nconst version", - 1 - ) - - os.rename("handwritten/firestore/dev/.gitignore", "handwritten/firestore/.gitignore") - os.rename("handwritten/firestore/dev/.eslintignore", "handwritten/firestore/.eslintignore") - os.rename("handwritten/firestore/dev/.mocharc.js", "handwritten/firestore/.mocharc.js") - os.rename("handwritten/firestore/dev/.jsdoc.js", "handwritten/firestore/.jsdoc.js") - os.rename("handwritten/firestore/dev/.prettierrc.js", "handwritten/firestore/.prettierrc.js") - os.unlink("handwritten/firestore/dev/.eslintrc.json") - - s.replace(".jsdoc.js", r"protos", "build/protos", 1) - - # Remove auto-generated packaging tests - os.system('rm -rf handwritten/firestore/dev/system-test/fixtures handwritten/firestore/dev/system-test/install.ts') - - node.compile_protos_hermetic(relative_dir="handwritten/firestore") - os.unlink('handwritten/firestore/dev/protos.js') - os.unlink('handwritten/firestore/dev/protos.d.ts') - os.unlink('handwritten/firestore/dev/protos.json') - subprocess.run('handwritten/firestore/dev/protos/update.sh', shell=True) - - # Copy types into types/ - logger.debug("Running compile...") - shell.run(["npm", "run", "compile"], cwd="handwritten/firestore", hide_output=True) - s.copy("handwritten/firestore/build/src/v1/firestore*.d.ts", "handwritten/firestore/types/v1") - s.copy("handwritten/firestore/build/src/v1beta1/firestore_client.d.ts", "handwritten/firestore/types/v1beta1") - s.copy("handwritten/firestore/build/protos/firestore*.d.ts", "handwritten/firestore/types/protos") - s.replace( - "handwritten/firestore/types/v1/firestore_client.d.ts", - r"../../protos", - "../protos" - ) - s.replace( - "handwritten/firestore/types/v1/firestore_admin_client.d.ts", - r"../../protos", - "../protos" - ) - s.replace( - "handwritten/firestore/types/v1beta1/firestore_client.d.ts", - r"../../protos", - "../protos" - ) - s.replace( - "handwritten/firestore/types/protos/firestore_admin_v1_proto_api.d.ts", - 'import Long = require\("long"\);', - "" - ) - s.replace( - "handwritten/firestore/types/protos/firestore_v1_proto_api.d.ts", - r'import Long = require\("long"\);', - "" - ) - s.replace( - "handwritten/firestore/types/protos/firestore_v1beta1_proto_api.d.ts", - r'import Long = require\("long"\);', - "" - ) - - finally: - # The staging directory should never be merged into the main branch. - shutil.rmtree(staging) - - -# Copy template files -common_templates = gcp.CommonTemplates() -templates = common_templates.node_mono_repo_library(relative_dir="handwritten/firestore", - source_location="build/src", test_project="node-gcloud-ci" -) - -s.copy(templates, destination="handwritten/firestore", excludes=[".eslintrc.json", ".kokoro/**/*", ".github/CODEOWNERS", "README.md"]) - -# Remove generated samples from veneer library: -shell.run(('rm', '-rf', 'handwritten/firestore/dev/samples/generated'), hide_output = False) - -shell.run(('node', 'handwritten/firestore/scripts/license.js', 'handwritten/firestore/dev/protos'), hide_output = False) -shell.run(('node', 'handwritten/firestore/scripts/license.js', 'handwritten/firestore/types'), hide_output = False) - -node.fix_hermetic(relative_dir="handwritten/firestore") # fix formatting \ No newline at end of file diff --git a/handwritten/firestore/package.json b/handwritten/firestore/package.json index df5d2f16a557..f3b4254d133c 100644 --- a/handwritten/firestore/package.json +++ b/handwritten/firestore/package.json @@ -58,7 +58,7 @@ "lint": "gts check", "clean": "gts clean", "compile": "tsc -p .", - "postcompile": "node scripts/init-directories.js && cp -r dev/protos build && cp dev/src/v1beta1/*.json build/src/v1beta1/ && cp dev/src/v1/*.json build/src/v1/ && cp dev/conformance/test-definition.proto build/conformance && cp dev/conformance/conformance-tests/*.json build/conformance/conformance-tests && minifyProtoJson", + "postcompile": "node scripts/init-directories.js && cp -r dev/protos build && cp dev/conformance/test-definition.proto build/conformance && cp dev/conformance/conformance-tests/*.json build/conformance/conformance-tests && minifyProtoJson", "fix": "gts fix", "prepare": "npm run compile", "precompile": "gts clean" @@ -68,7 +68,8 @@ "fast-deep-equal": "^3.1.3", "functional-red-black-tree": "^1.0.1", "google-gax": "^5.0.1", - "protobufjs": "^7.5.3" + "protobufjs": "^7.5.3", + "@google-cloud/firestore-api": "^0.2.0" }, "devDependencies": { "@google-cloud/cloud-rad": "^0.4.10",