import * as gax from 'google-gax' ; import { Callback , CallOptions , Descriptors , ClientOptions , LROperation , PaginationCallback , GaxCall , } from 'google-gax' ; import { Transform } from 'stream' ; import { RequestType } from 'google-gax/build/src/apitypes' ; import * as protos from '../../protos/protos' ; import jsonProtos = require ( '../../protos/protos.json' ) ; /**
 * Client JSON configuration object, loaded from
 * `src/v1/target_pools_client_config.json`.
 * This file defines retry strategy and timeouts for all API methods in this library.
 */ import * as gapicConfig from './target_pools_client_config.json' ; const version = require ( '../../../package.json' ) . version ; class memberof export class TargetPoolsClient { 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 ] : gax . CallSettings ; } ; auth : gax . GoogleAuth ; descriptors : Descriptors = { page : { } , stream : { } , longrunning : { } , batching : { } , } ; warn : ( code : string , message : string , warnType ? : string ) => void ; innerApiCalls : { [ name ] : Function ; } ; targetPoolsStub ? : Promise < { [ name ] : Function ; } > ; param options param options . credentials param { string } options . credentials . client_email param { string } options . credentials . private_key param { string } options . email param { string } options . keyFilename param { number } options . port 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
     *      https ,
     *     your project ID will be detected automatically.
     *  param { string } options . apiEndpoint param { gax . ClientConfig } options . clientConfig - Client configuration override.
     *     Follows the structure of  gapicConfig .
     *  param { boolean } options . fallback constructor ( opts ? ) { const staticMembers = this . constructor as typeof TargetPoolsClient ; const servicePath = opts ?. servicePath || opts ?. apiEndpoint || staticMembers . servicePath ; this . _providedCustomServicePath = ! ! ( opts ?. servicePath || opts ?. apiEndpoint ) ; const port = opts ?. port || staticMembers . port ; const clientConfig = opts ?. clientConfig ?? { } ; if ( ! opts ) { opts = { fallback : 'rest' } ; } else { opts . fallback = opts . fallback ?? 'rest' ; } const fallback = opts ?. fallback ?? ( typeof window !== 'undefined' && typeof window ?. fetch === 'function' ) ; opts = Object . assign ( { servicePath , port , clientConfig , fallback } , opts ) ; if ( servicePath !== staticMembers . servicePath && ! ( 'scopes' in opts ) ) { opts [ 'scopes' ] = staticMembers . scopes ; } this . _gaxModule = opts . fallback ? gax . fallback : gax ; this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ; this . _opts = opts ; this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ; this . auth . defaultServicePath = staticMembers . servicePath ; if ( servicePath === staticMembers . servicePath ) { this . auth . defaultScopes = staticMembers . scopes ; } const clientHeader = [ `gax/${ this . _gaxModule . version }` , `gapic/${ version }` ] ; if ( typeof process !== 'undefined' && '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 if ( opts . fallback === 'rest' ) { clientHeader . push ( `rest/${ this . _gaxGrpc . grpcVersion }` ) ; } if ( opts . libName && opts . libVersion ) { clientHeader . push ( `${ opts . libName }/${ opts . libVersion }` ) ; } this . _protos = this . _gaxGrpc . loadProtoJSON ( jsonProtos ) ; this . descriptors . page = { aggregatedList : new this . _gaxModule . PageDescriptor ( 'pageToken' , 'nextPageToken' , 'items' ) , list : new this . _gaxModule . PageDescriptor ( 'pageToken' , 'nextPageToken' , 'items' ) , } ; this . _defaults = this . _gaxGrpc . constructSettings ( 'google.cloud.compute.v1.TargetPools' , gapicConfig as gax . ClientConfig , opts . clientConfig || { } , { 'x-goog-api-client' : clientHeader . join ( ' ' ) } ) ; this . innerApiCalls = { } ; this . warn = gax . warn ; } returns { Promise } initialize ( ) { if ( this . targetPoolsStub ) { return this . targetPoolsStub ; } this . targetPoolsStub = this . _gaxGrpc . createStub ( this . _opts . fallback ? ( this . _protos as protobuf . Root ) . lookupService ( 'google.cloud.compute.v1.TargetPools' ) : ( this . _protos as any ) . google . cloud . compute . v1 . TargetPools , this . _opts , this . _providedCustomServicePath ) as Promise < { [ method ] : Function ; } > ; const targetPoolsStubMethods = [ 'addHealthCheck' , 'addInstance' , 'aggregatedList' , 'delete' , 'get' , 'getHealth' , 'insert' , 'list' , 'removeHealthCheck' , 'removeInstance' , 'setBackup' , ] ; for ( const methodName of targetPoolsStubMethods ) { const callPromise = this . targetPoolsStub . then ( stub => ( ... args ) => { if ( this . _terminated ) { return Promise . reject ( 'The client has already been closed.' ) ; } const func = stub [ methodName ] ; return func . apply ( stub , args ) ; } , ( err ) => ( ) => { throw err ; } ) ; const descriptor = this . descriptors . page [ methodName ] || undefined ; const apiCall = this . _gaxModule . createApiCall ( callPromise , this . _defaults [ methodName ] , descriptor ) ; this . innerApiCalls [ methodName ] = apiCall ; } return this . targetPoolsStub ; } returns { string } static get servicePath ( ) { return 'compute.googleapis.com' ; } returns { string } static get apiEndpoint ( ) { return 'compute.googleapis.com' ; } returns { number } static get port ( ) { return 443 ; } returns { string [ ] } static get scopes ( ) { return [ 'https://www.googleapis.com/auth/compute' , 'https://www.googleapis.com/auth/cloud-platform' , ] ; } getProjectId ( ) ; getProjectId ( callback ) ; returns { Promise } getProjectId ( callback ? ) { if ( callback ) { this . auth . getProjectId ( callback ) ; return ; } return this . auth . getProjectId ( ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { google . cloud . compute . v1 . TargetPoolsAddHealthCheckRequest } request . targetPoolsAddHealthCheckRequestResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example addHealthCheck ( request ? , options ? ) ; addHealthCheck ( request , options , callback ) ; addHealthCheck ( request , callback ) ; addHealthCheck ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . addHealthCheck ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { google . cloud . compute . v1 . TargetPoolsAddInstanceRequest } request . targetPoolsAddInstanceRequestResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example addInstance ( request ? , options ? ) ; addInstance ( request , options , callback ) ; addInstance ( request , callback ) ; addInstance ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . addInstance ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { object } options Call options. See  https for more details.
     *  returns { Promise } example delete ( request ? , options ? ) ; delete ( request , options , callback ) ; delete ( request , callback ) ; delete ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . delete ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . project param { string } request . region param { string } request . targetPool param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [TargetPool] google . cloud . compute . v1 . TargetPool .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example get ( request ? , options ? ) ; get ( request , options , callback ) ; get ( request , callback ) ; get ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . get ( request , options , callback ) ; } param request param { google . cloud . compute . v1 . InstanceReference } request . instanceReferenceResource param { string } request . project param { string } request . region param { string } request . targetPool param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [TargetPoolInstanceHealth] google . cloud . compute . v1 . TargetPoolInstanceHealth .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example getHealth ( request ? , options ? ) ; getHealth ( request , options , callback ) ; getHealth ( request , callback ) ; getHealth ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . getHealth ( request , options , callback ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { google . cloud . compute . v1 . TargetPool } request . targetPoolResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example insert ( request ? , options ? ) ; insert ( request , options , callback ) ; insert ( request , callback ) ; insert ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . insert ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { google . cloud . compute . v1 . TargetPoolsRemoveHealthCheckRequest } request . targetPoolsRemoveHealthCheckRequestResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example removeHealthCheck ( request ? , options ? ) ; removeHealthCheck ( request , options , callback ) ; removeHealthCheck ( request , callback ) ; removeHealthCheck ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . removeHealthCheck ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { google . cloud . compute . v1 . TargetPoolsRemoveInstanceRequest } request . targetPoolsRemoveInstanceRequestResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example removeInstance ( request ? , options ? ) ; removeInstance ( request , options , callback ) ; removeInstance ( request , callback ) ; removeInstance ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . removeInstance ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { number } request . failoverRatio param { string } request . project param { string } request . region param { string } request . requestId param { string } request . targetPool param { google . cloud . compute . v1 . TargetReference } request . targetReferenceResource param { object } options Call options. See  https for more details.
     *  returns { Promise } example setBackup ( request ? , options ? ) ; setBackup ( request , options , callback ) ; setBackup ( request , callback ) ; setBackup ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . setBackup ( request , options , callback ) . then ( ( [ response , operation , rawResponse ] ) => { return [ { latestResponse : response , done : false , name : response . id , metadata : null , result : { } , } , operation , rawResponse , ] ; } ) ; } param request param { string } request . filter param { boolean } request . includeAllScopes param { number } request . maxResults param { string } request . orderBy param { string } request . pageToken param { string } request . project param { boolean } request . returnPartialSuccess param { object } options Call options. See  https for more details.
     *  returns { Object } *   An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
     *   When you iterate the returned iterable, each element will be an object representing
     *   as tuple [string, [TargetPoolsScopedList] google . cloud . compute . v1 . TargetPoolsScopedList ]. The API will be called under the hood as needed, once per the page,
     *   so you can stop the iteration when you don't need more results.
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
     *   for more details and examples.
     *  example aggregatedListAsync ( request ? , options ? ) { request = request || { } ; options = options || { } ; options . otherArgs = options . otherArgs || { } ; options . otherArgs . headers = options . otherArgs . headers || { } ; options . otherArgs . headers [ 'x-goog-request-params' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; const defaultCallSettings = this . _defaults [ 'aggregatedList' ] ; const callSettings = defaultCallSettings . merge ( options ) ; this . initialize ( ) ; return this . descriptors . page . aggregatedList . asyncIterate ( this . innerApiCalls [ 'aggregatedList' ] as GaxCall , request as unknown as RequestType , callSettings ) as AsyncIterable < [ string , protos . google . cloud . compute . v1 . ITargetPoolsScopedList ] > ; } param request param { string } request . filter param { number } request . maxResults param { string } request . orderBy param { string } request . pageToken param { string } request . project param { string } request . region param { boolean } request . returnPartialSuccess param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is Array of [TargetPool] google . cloud . compute . v1 . TargetPool .
     *   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 `listAsync()`
     *   method described below for async iteration which you can stop as needed.
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
     *   for more details and examples.
      list ( request ? , options ? ) ; list ( request , options , callback ) ; list ( request , callback ) ; list ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . list ( request , options , callback ) ; } param request param { string } request . filter param { number } request . maxResults param { string } request . orderBy param { string } request . pageToken param { string } request . project param { string } request . region param { boolean } request . returnPartialSuccess param { object } options Call options. See  https for more details.
     *  returns { Stream } *   An object stream which emits an object representing [TargetPool] google . cloud . compute . v1 . TargetPool 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 `listAsync()`
     *   method described below for async iteration which you can stop as needed.
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
     *   for more details and examples.
      listStream ( request ? , options ? ) { request = request || { } ; options = options || { } ; options . otherArgs = options . otherArgs || { } ; options . otherArgs . headers = options . otherArgs . headers || { } ; options . otherArgs . headers [ 'x-goog-request-params' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; const defaultCallSettings = this . _defaults [ 'list' ] ; const callSettings = defaultCallSettings . merge ( options ) ; this . initialize ( ) ; return this . descriptors . page . list . createStream ( this . innerApiCalls . list as gax . GaxCall , request , callSettings ) ; } param request param { string } request . filter param { number } request . maxResults param { string } request . orderBy param { string } request . pageToken param { string } request . project param { string } request . region param { boolean } request . returnPartialSuccess param { object } options Call options. See  https for more details.
     *  returns { Object } *   An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
     *   When you iterate the returned iterable, each element will be an object representing
     *   [TargetPool] google . cloud . compute . v1 . TargetPool . The API will be called under the hood as needed, once per the page,
     *   so you can stop the iteration when you don't need more results.
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
     *   for more details and examples.
     *  example listAsync ( request ? , options ? ) { request = request || { } ; options = options || { } ; options . otherArgs = options . otherArgs || { } ; options . otherArgs . headers = options . otherArgs . headers || { } ; options . otherArgs . headers [ 'x-goog-request-params' ] = gax . routingHeader . fromParams ( { project : request . project || '' , } ) ; const defaultCallSettings = this . _defaults [ 'list' ] ; const callSettings = defaultCallSettings . merge ( options ) ; this . initialize ( ) ; return this . descriptors . page . list . asyncIterate ( this . innerApiCalls [ 'list' ] as GaxCall , request as unknown as RequestType , callSettings ) as AsyncIterable < protos . google . cloud . compute . v1 . ITargetPool > ; } returns { Promise } close ( ) { this . initialize ( ) ; if ( ! this . _terminated ) { return this . targetPoolsStub ! . then ( stub => { this . _terminated = true ; stub . close ( ) ; } ) ; } return Promise . resolve ( ) ; } }