v1beta1/cloud_redis_client.js

"use strict";
// 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. **
Object.defineProperty(exports, "__esModule", { value: true });
const gax = require("google-gax");
const path = require("path");
const gapicConfig = require("./cloud_redis_client_config.json");
const version = require('../../../package.json').version;
/**
 *  Configures and manages Cloud Memorystore for Redis instances
 *
 *  Google Cloud Memorystore for Redis v1beta1
 *
 *  The `redis.googleapis.com` service implements the Google Cloud Memorystore
 *  for Redis API and defines the following resource model for managing Redis
 *  instances:
 *  * The service works with a collection of cloud projects, named: `/projects/*`
 *  * Each project has a collection of available locations, named: `/locations/*`
 *  * Each location has a collection of Redis instances, named: `/instances/*`
 *  * As such, Redis instances are resources of the form:
 *    `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
 *
 *  Note that location_id must be refering to a GCP `region`; for example:
 *  * `projects/redpepper-1290/locations/us-central1/instances/my-redis`
 * @class
 * @memberof v1beta1
 */
class CloudRedisClient {
    /**
     * Construct an instance of CloudRedisClient.
     *
     * @param {object} [options] - The configuration object. See the subsequent
     *   parameters for more details.
     * @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://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
     *     your project ID will be detected automatically.
     * @param {function} [options.promise] - Custom promise module to use instead
     *     of native Promises.
     * @param {string} [options.apiEndpoint] - The domain name of the
     *     API remote host.
     */
    constructor(opts) {
        this._descriptors = { page: {}, stream: {}, longrunning: {} };
        this._terminated = false;
        // Ensure that options include the service address and port.
        const staticMembers = this.constructor;
        const servicePath = opts && opts.servicePath
            ? opts.servicePath
            : opts && opts.apiEndpoint
                ? opts.apiEndpoint
                : staticMembers.servicePath;
        const port = opts && opts.port ? opts.port : staticMembers.port;
        if (!opts) {
            opts = { servicePath, port };
        }
        opts.servicePath = opts.servicePath || servicePath;
        opts.port = opts.port || port;
        opts.clientConfig = opts.clientConfig || {};
        const isBrowser = typeof window !== 'undefined';
        if (isBrowser) {
            opts.fallback = true;
        }
        // If we are in browser, we are already using fallback because of the
        // "browser" field in package.json.
        // But if we were explicitly requested to use fallback, let's do it now.
        const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax;
        // Create a `gaxGrpc` object, with any grpc-specific options
        // sent to the client.
        opts.scopes = this.constructor.scopes;
        const gaxGrpc = new gaxModule.GrpcClient(opts);
        // Save the auth object to the client, for use by other methods.
        this.auth = gaxGrpc.auth;
        // Determine the client header string.
        const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`];
        if (typeof process !== 'undefined' && 'versions' in process) {
            clientHeader.push(`gl-node/${process.versions.node}`);
        }
        else {
            clientHeader.push(`gl-web/${gaxModule.version}`);
        }
        if (!opts.fallback) {
            clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
        }
        if (opts.libName && opts.libVersion) {
            clientHeader.push(`${opts.libName}/${opts.libVersion}`);
        }
        // Load the applicable protos.
        // For Node.js, pass the path to JSON proto file.
        // For browsers, pass the JSON content.
        const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json');
        const protos = gaxGrpc.loadProto(opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath);
        // This API contains "path templates"; forward-slash-separated
        // identifiers to uniquely identify resources within the API.
        // Create useful helper objects for these.
        this._pathTemplates = {
            locationPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}'),
            instancePathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}/instances/{instance}'),
        };
        // 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 = {
            listInstances: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'instances'),
        };
        // 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 protoFilesRoot = opts.fallback
            ? gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json'))
            : gaxModule.protobuf.loadSync(nodejsProtoPath);
        this.operationsClient = gaxModule
            .lro({
            auth: this.auth,
            grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined,
        })
            .operationsClient(opts);
        const createInstanceResponse = protoFilesRoot.lookup('.google.cloud.redis.v1beta1.Instance');
        const createInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        const updateInstanceResponse = protoFilesRoot.lookup('.google.cloud.redis.v1beta1.Instance');
        const updateInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        const importInstanceResponse = protoFilesRoot.lookup('.google.cloud.redis.v1beta1.Instance');
        const importInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        const exportInstanceResponse = protoFilesRoot.lookup('.google.cloud.redis.v1beta1.Instance');
        const exportInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        const failoverInstanceResponse = protoFilesRoot.lookup('.google.cloud.redis.v1beta1.Instance');
        const failoverInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        const deleteInstanceResponse = protoFilesRoot.lookup('.google.protobuf.Empty');
        const deleteInstanceMetadata = protoFilesRoot.lookup('.google.protobuf.Any');
        this._descriptors.longrunning = {
            createInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, createInstanceResponse.decode.bind(createInstanceResponse), createInstanceMetadata.decode.bind(createInstanceMetadata)),
            updateInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, updateInstanceResponse.decode.bind(updateInstanceResponse), updateInstanceMetadata.decode.bind(updateInstanceMetadata)),
            importInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, importInstanceResponse.decode.bind(importInstanceResponse), importInstanceMetadata.decode.bind(importInstanceMetadata)),
            exportInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, exportInstanceResponse.decode.bind(exportInstanceResponse), exportInstanceMetadata.decode.bind(exportInstanceMetadata)),
            failoverInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, failoverInstanceResponse.decode.bind(failoverInstanceResponse), failoverInstanceMetadata.decode.bind(failoverInstanceMetadata)),
            deleteInstance: new gaxModule.LongrunningDescriptor(this.operationsClient, deleteInstanceResponse.decode.bind(deleteInstanceResponse), deleteInstanceMetadata.decode.bind(deleteInstanceMetadata)),
        };
        // Put together the default options sent with requests.
        const defaults = gaxGrpc.constructSettings('google.cloud.redis.v1beta1.CloudRedis', gapicConfig, 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 = {};
        // Put together the "service stub" for
        // google.cloud.redis.v1beta1.CloudRedis.
        this.cloudRedisStub = gaxGrpc.createStub(opts.fallback
            ? protos.lookupService('google.cloud.redis.v1beta1.CloudRedis')
            : // tslint:disable-next-line no-any
                protos.google.cloud.redis.v1beta1.CloudRedis, opts);
        // Iterate over each of the methods that the service provides
        // and create an API call method for each.
        const cloudRedisStubMethods = [
            'listInstances',
            'getInstance',
            'createInstance',
            'updateInstance',
            'importInstance',
            'exportInstance',
            'failoverInstance',
            'deleteInstance',
        ];
        for (const methodName of cloudRedisStubMethods) {
            const innerCallPromise = this.cloudRedisStub.then(stub => (...args) => {
                if (this._terminated) {
                    return Promise.reject('The client has already been closed.');
                }
                return stub[methodName].apply(stub, args);
            }, (err) => () => {
                throw err;
            });
            const apiCall = gaxModule.createApiCall(innerCallPromise, defaults[methodName], this._descriptors.page[methodName] ||
                this._descriptors.stream[methodName] ||
                this._descriptors.longrunning[methodName]);
            this._innerApiCalls[methodName] = (argument, callOptions, callback) => {
                return apiCall(argument, callOptions, callback);
            };
        }
    }
    /**
     * The DNS address for this API service.
     */
    static get servicePath() {
        return 'redis.googleapis.com';
    }
    /**
     * The DNS address for this API service - same as servicePath(),
     * exists for compatibility reasons.
     */
    static get apiEndpoint() {
        return 'redis.googleapis.com';
    }
    /**
     * The port for this API service.
     */
    static get port() {
        return 443;
    }
    /**
     * The scopes needed to make gRPC calls for every method defined
     * in this service.
     */
    static get scopes() {
        return ['https://www.googleapis.com/auth/cloud-platform'];
    }
    /**
     * Return the project ID used by this class.
     * @param {function(Error, string)} callback - the callback to
     *   be called with the current project Id.
     */
    getProjectId(callback) {
        if (callback) {
            this.auth.getProjectId(callback);
            return;
        }
        return this.auth.getProjectId();
    }
    /**
     * Gets the details of a specific Redis instance.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. Redis instance resource name using the form:
     *       `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
     *   where `location_id` refers to a GCP region.
     * @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 [Instance]{@link google.cloud.redis.v1beta1.Instance}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.getInstance(request, options, callback);
    }
    /**
     * Creates a Redis instance based on the specified tier and memory size.
     *
     * By default, the instance is accessible from the project's
     * [default network](https://cloud.google.com/compute/docs/networks-and-firewalls#networks).
     *
     * The creation is executed asynchronously and callers may check the returned
     * operation to track its progress. Once the operation is completed the Redis
     * instance will be fully functional. Completed longrunning.Operation will
     * contain the new instance object in the response field.
     *
     * The returned operation is automatically deleted after a few hours, so there
     * is no need to call DeleteOperation.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the instance location using the form:
     *       `projects/{project_id}/locations/{location_id}`
     *   where `location_id` refers to a GCP region.
     * @param {string} request.instanceId
     *   Required. The logical name of the Redis instance in the customer project
     *   with the following restrictions:
     *
     *   * Must contain only lowercase letters, numbers, and hyphens.
     *   * Must start with a letter.
     *   * Must be between 1-40 characters.
     *   * Must end with a number or a letter.
     *   * Must be unique within the customer project / location
     * @param {google.cloud.redis.v1beta1.Instance} request.instance
     *   Required. A Redis [Instance] resource
     * @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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    createInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.createInstance(request, options, callback);
    }
    /**
     * Updates the metadata and configuration of a specific Redis instance.
     *
     * Completed longrunning.Operation will contain the new instance object
     * in the response field. The returned operation is automatically deleted
     * after a few hours, so there is no need to call DeleteOperation.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {google.protobuf.FieldMask} request.updateMask
     *   Required. Mask of fields to update. At least one path must be supplied in
     *   this field. The elements of the repeated paths field may only include these
     *   fields from [Instance][google.cloud.redis.v1beta1.Instance]:
     *
     *    *   `displayName`
     *    *   `labels`
     *    *   `memorySizeGb`
     *    *   `redisConfig`
     * @param {google.cloud.redis.v1beta1.Instance} request.instance
     *   Required. Update description.
     *   Only fields specified in update_mask are 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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    updateInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            instance_name: request.instance.name || '',
        });
        return this._innerApiCalls.updateInstance(request, options, callback);
    }
    /**
     * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance.
     *
     * Redis may stop serving during this operation. Instance state will be
     * IMPORTING for entire operation. When complete, the instance will contain
     * only data from the imported file.
     *
     * The returned operation is automatically deleted after a few hours, so
     * there is no need to call DeleteOperation.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. Redis instance resource name using the form:
     *       `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
     *   where `location_id` refers to a GCP region.
     * @param {google.cloud.redis.v1beta1.InputConfig} request.inputConfig
     *   Required. Specify data to be imported.
     * @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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    importInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.importInstance(request, options, callback);
    }
    /**
     * Export Redis instance data into a Redis RDB format file in Cloud Storage.
     *
     * Redis will continue serving during this operation.
     *
     * The returned operation is automatically deleted after a few hours, so
     * there is no need to call DeleteOperation.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. Redis instance resource name using the form:
     *       `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
     *   where `location_id` refers to a GCP region.
     * @param {google.cloud.redis.v1beta1.OutputConfig} request.outputConfig
     *   Required. Specify data to be exported.
     * @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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    exportInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.exportInstance(request, options, callback);
    }
    /**
     * Initiates a failover of the master node to current replica node for a
     * specific STANDARD tier Cloud Memorystore for Redis instance.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. Redis instance resource name using the form:
     *       `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
     *   where `location_id` refers to a GCP region.
     * @param {google.cloud.redis.v1beta1.FailoverInstanceRequest.DataProtectionMode} [request.dataProtectionMode]
     *   Optional. Available data protection modes that the user can choose. If it's
     *   unspecified, data protection mode will be LIMITED_DATA_LOSS by default.
     * @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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    failoverInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.failoverInstance(request, options, callback);
    }
    /**
     * Deletes a specific Redis instance.  Instance stops serving and data is
     * deleted.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. Redis instance resource name using the form:
     *       `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
     *   where `location_id` refers to a GCP region.
     * @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 [Operation]{@link google.longrunning.Operation}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    deleteInstance(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.deleteInstance(request, options, callback);
    }
    /**
     * Lists all Redis instances owned by a project in either the specified
     * location (region) or all locations.
     *
     * The location should have the following format:
     * * `projects/{project_id}/locations/{location_id}`
     *
     * If `location_id` is specified as `-` (wildcard), then all regions
     * available to the project are queried, and the results are aggregated.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the instance location using the form:
     *       `projects/{project_id}/locations/{location_id}`
     *   where `location_id` refers to a GCP region.
     * @param {number} request.pageSize
     *   The maximum number of items to return.
     *
     *   If not specified, a default value of 1000 will be used by the service.
     *   Regardless of the page_size value, the response may include a partial list
     *   and a caller should only rely on response's
     *   [next_page_token][CloudRedis.ListInstancesResponse.next_page_token]
     *   to determine if there are more instances left to be queried.
     * @param {string} request.pageToken
     *   The next_page_token value returned from a previous List request,
     *   if any.
     * @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 [Instance]{@link google.cloud.redis.v1beta1.Instance}.
     *   The client library support 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.
     *
     *   When autoPaginate: false is specified through options, the array has three elements.
     *   The first element is Array of [Instance]{@link google.cloud.redis.v1beta1.Instance} that corresponds to
     *   the one page received from the API server.
     *   If the second element is not null it contains the request object of type [ListInstancesRequest]{@link google.cloud.redis.v1beta1.ListInstancesRequest}
     *   that can be used to obtain the next page of the results.
     *   If it is null, the next page does not exist.
     *   The third element contains the raw response received from the API server. Its type is
     *   [ListInstancesResponse]{@link google.cloud.redis.v1beta1.ListInstancesResponse}.
     *
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    listInstances(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.listInstances(request, options, callback);
    }
    /**
     * Equivalent to {@link listInstances}, but returns a NodeJS Stream object.
     *
     * This fetches the paged responses for {@link listInstances} continuously
     * and invokes the callback registered for 'data' event for each element in the
     * responses.
     *
     * The returned object has 'end' method when no more elements are required.
     *
     * autoPaginate option will be ignored.
     *
     * @see {@link https://nodejs.org/api/stream.html}
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the instance location using the form:
     *       `projects/{project_id}/locations/{location_id}`
     *   where `location_id` refers to a GCP region.
     * @param {number} request.pageSize
     *   The maximum number of items to return.
     *
     *   If not specified, a default value of 1000 will be used by the service.
     *   Regardless of the page_size value, the response may include a partial list
     *   and a caller should only rely on response's
     *   [next_page_token][CloudRedis.ListInstancesResponse.next_page_token]
     *   to determine if there are more instances left to be queried.
     * @param {string} request.pageToken
     *   The next_page_token value returned from a previous List request,
     *   if any.
     * @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 [Instance]{@link google.cloud.redis.v1beta1.Instance} on 'data' event.
     */
    listInstancesStream(request, options) {
        request = request || {};
        const callSettings = new gax.CallSettings(options);
        return this._descriptors.page.listInstances.createStream(this._innerApiCalls.listInstances, request, callSettings);
    }
    // --------------------
    // -- Path templates --
    // --------------------
    /**
     * Return a fully-qualified location resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @returns {string} Resource name string.
     */
    locationPath(project, location) {
        return this._pathTemplates.locationPathTemplate.render({
            project,
            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) {
        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) {
        return this._pathTemplates.locationPathTemplate.match(locationName)
            .location;
    }
    /**
     * Return a fully-qualified instance resource name string.
     *
     * @param {string} project
     * @param {string} location
     * @param {string} instance
     * @returns {string} Resource name string.
     */
    instancePath(project, location, instance) {
        return this._pathTemplates.instancePathTemplate.render({
            project,
            location,
            instance,
        });
    }
    /**
     * Parse the project from Instance resource.
     *
     * @param {string} instanceName
     *   A fully-qualified path representing Instance resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromInstanceName(instanceName) {
        return this._pathTemplates.instancePathTemplate.match(instanceName).project;
    }
    /**
     * Parse the location from Instance resource.
     *
     * @param {string} instanceName
     *   A fully-qualified path representing Instance resource.
     * @returns {string} A string representing the location.
     */
    matchLocationFromInstanceName(instanceName) {
        return this._pathTemplates.instancePathTemplate.match(instanceName)
            .location;
    }
    /**
     * Parse the instance from Instance resource.
     *
     * @param {string} instanceName
     *   A fully-qualified path representing Instance resource.
     * @returns {string} A string representing the instance.
     */
    matchInstanceFromInstanceName(instanceName) {
        return this._pathTemplates.instancePathTemplate.match(instanceName)
            .instance;
    }
    /**
     * Terminate the GRPC channel and close the client.
     *
     * The client will no longer be usable and all future behavior is undefined.
     */
    close() {
        if (!this._terminated) {
            return this.cloudRedisStub.then(stub => {
                this._terminated = true;
                stub.close();
            });
        }
        return Promise.resolve();
    }
}
exports.CloudRedisClient = CloudRedisClient;
//# sourceMappingURL=cloud_redis_client.js.map