Skip to content

Commit

Permalink
fix: do not modify options object, use defaultScopes (#46)
Browse files Browse the repository at this point in the history
Regenerated the library using
[gapic-generator-typescript](https://github.com/googleapis/gapic-generator-typescript)
v1.2.1.
  • Loading branch information
alexander-fenster authored Nov 6, 2020
1 parent c8f32f2 commit 411c2ad
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 89 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-bigquery-connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"api-documenter": "api-documenter yaml --input-folder=temp"
},
"dependencies": {
"google-gax": "^2.6.1"
"google-gax": "^2.9.2"
},
"devDependencies": {
"@types/mocha": "^8.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-bigquery-connection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import * as v1 from './v1';
const ConnectionServiceClient = v1.ConnectionServiceClient;
type ConnectionServiceClient = v1.ConnectionServiceClient;
export {v1, ConnectionServiceClient};
export default {v1, ConnectionServiceClient};
import * as protos from '../protos/protos';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export class ConnectionServiceClient {
/**
* Construct an instance of ConnectionServiceClient.
*
* @param {object} [options] - The configuration object. See the subsequent
* parameters for more details.
* @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/master/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]
Expand All @@ -81,42 +83,33 @@ export class ConnectionServiceClient {
* 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.
* TODO(@alexander-fenster): link to gax documentation.
* @param {boolean} fallback - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
* if you need to override this behavior.
*/

constructor(opts?: ClientOptions) {
// Ensure that options include the service address and port.
// Ensure that options include all the required fields.
const staticMembers = this.constructor as typeof ConnectionServiceClient;
const servicePath =
opts && opts.servicePath
? opts.servicePath
: opts && opts.apiEndpoint
? opts.apiEndpoint
: staticMembers.servicePath;
const port = opts && opts.port ? opts.port : staticMembers.port;
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
const port = opts?.port || staticMembers.port;
const clientConfig = opts?.clientConfig ?? {};
const fallback = opts?.fallback ?? typeof window !== 'undefined';
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);

if (!opts) {
opts = {servicePath, port};
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
opts['scopes'] = staticMembers.scopes;
}
opts.servicePath = opts.servicePath || servicePath;
opts.port = opts.port || port;

// users can override the config from client side, like retry codes name.
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
// The way to override client config for Showcase API:
//
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
// const showcaseClient = new showcaseClient({ projectId, customConfig });
opts.clientConfig = opts.clientConfig || {};

// If we're running in browser, it's OK to omit `fallback` since
// google-gax has `browser` field in its `package.json`.
// For Electron (which does not respect `browser` field),
// pass `{fallback: true}` to the ConnectionServiceClient constructor.
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
this._gaxModule = opts.fallback ? gax.fallback : gax;

// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
opts.scopes = (this.constructor as typeof ConnectionServiceClient).scopes;
// 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.
Expand All @@ -125,6 +118,11 @@ export class ConnectionServiceClient {
// Save the auth object to the client, for use by other methods.
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;

// Set the default scopes in auth client if needed.
if (servicePath === staticMembers.servicePath) {
this.auth.defaultScopes = staticMembers.scopes;
}

// Determine the client header string.
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
if (typeof process !== 'undefined' && 'versions' in process) {
Expand Down Expand Up @@ -264,6 +262,7 @@ export class ConnectionServiceClient {

/**
* The DNS address for this API service.
* @returns {string} The DNS address for this service.
*/
static get servicePath() {
return 'bigqueryconnection.googleapis.com';
Expand All @@ -272,13 +271,15 @@ export class ConnectionServiceClient {
/**
* The DNS address for this API service - same as servicePath(),
* exists for compatibility reasons.
* @returns {string} The DNS address for this service.
*/
static get apiEndpoint() {
return 'bigqueryconnection.googleapis.com';
}

/**
* The port for this API service.
* @returns {number} The default port for this service.
*/
static get port() {
return 443;
Expand All @@ -287,6 +288,7 @@ export class ConnectionServiceClient {
/**
* The scopes needed to make gRPC calls for every method defined
* in this service.
* @returns {string[]} List of default scopes.
*/
static get scopes() {
return [
Expand All @@ -299,8 +301,7 @@ export class ConnectionServiceClient {
getProjectId(callback: Callback<string, undefined, undefined>): void;
/**
* Return the project ID used by this class.
* @param {function(Error, string)} callback - the callback to
* be called with the current project Id.
* @returns {Promise} A promise that resolves to string containing the project ID.
*/
getProjectId(
callback?: Callback<string, undefined, undefined>
Expand Down Expand Up @@ -365,7 +366,11 @@ export class ConnectionServiceClient {
* 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 [Connection]{@link google.cloud.bigquery.connection.v1.Connection}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.createConnection(request);
*/
createConnection(
request: protos.google.cloud.bigquery.connection.v1.ICreateConnectionRequest,
Expand Down Expand Up @@ -460,7 +465,11 @@ export class ConnectionServiceClient {
* 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 [Connection]{@link google.cloud.bigquery.connection.v1.Connection}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.getConnection(request);
*/
getConnection(
request: protos.google.cloud.bigquery.connection.v1.IGetConnectionRequest,
Expand Down Expand Up @@ -560,7 +569,11 @@ export class ConnectionServiceClient {
* 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 [Connection]{@link google.cloud.bigquery.connection.v1.Connection}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.updateConnection(request);
*/
updateConnection(
request: protos.google.cloud.bigquery.connection.v1.IUpdateConnectionRequest,
Expand Down Expand Up @@ -655,7 +668,11 @@ export class ConnectionServiceClient {
* 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 [Empty]{@link google.protobuf.Empty}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.deleteConnection(request);
*/
deleteConnection(
request: protos.google.cloud.bigquery.connection.v1.IDeleteConnectionRequest,
Expand Down Expand Up @@ -748,7 +765,11 @@ export class ConnectionServiceClient {
* 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 [Policy]{@link google.iam.v1.Policy}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.getIamPolicy(request);
*/
getIamPolicy(
request: protos.google.iam.v1.IGetIamPolicyRequest,
Expand Down Expand Up @@ -837,7 +858,11 @@ export class ConnectionServiceClient {
* 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 [Policy]{@link google.iam.v1.Policy}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.setIamPolicy(request);
*/
setIamPolicy(
request: protos.google.iam.v1.ISetIamPolicyRequest,
Expand Down Expand Up @@ -929,7 +954,11 @@ export class ConnectionServiceClient {
* 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 [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
* The promise has a method named "cancel" which cancels the ongoing API call.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.testIamPermissions(request);
*/
testIamPermissions(
request: protos.google.iam.v1.ITestIamPermissionsRequest,
Expand Down Expand Up @@ -1019,19 +1048,14 @@ export class ConnectionServiceClient {
* 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 [Connection]{@link google.cloud.bigquery.connection.v1.Connection}.
* The client library support auto-pagination by default: it will call the API as many
* 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.
*
* When autoPaginate: false is specified through options, the array has three elements.
* The first element is Array of [Connection]{@link google.cloud.bigquery.connection.v1.Connection} 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 [ListConnectionsRequest]{@link google.cloud.bigquery.connection.v1.ListConnectionsRequest}
* 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
* [ListConnectionsResponse]{@link google.cloud.bigquery.connection.v1.ListConnectionsResponse}.
*
* The promise has a method named "cancel" which cancels the ongoing API call.
* Note that it can affect your quota.
* We recommend using `listConnectionsAsync()`
* 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.
*/
listConnections(
request: protos.google.cloud.bigquery.connection.v1.IListConnectionsRequest,
Expand Down Expand Up @@ -1079,18 +1103,7 @@ export class ConnectionServiceClient {
}

/**
* Equivalent to {@link listConnections}, but returns a NodeJS Stream object.
*
* This fetches the paged responses for {@link listConnections} 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}
*
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
* @param {Object} request
* The request object that will be sent.
* @param {string} request.parent
Expand All @@ -1104,6 +1117,13 @@ export class ConnectionServiceClient {
* 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 [Connection]{@link google.cloud.bigquery.connection.v1.Connection} 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 `listConnectionsAsync()`
* 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.
*/
listConnectionsStream(
request?: protos.google.cloud.bigquery.connection.v1.IListConnectionsRequest,
Expand All @@ -1128,10 +1148,9 @@ export class ConnectionServiceClient {
}

/**
* Equivalent to {@link listConnections}, but returns an iterable object.
*
* for-await-of syntax is used with the iterable to recursively get response element on-demand.
* Equivalent to `listConnections`, 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
Expand All @@ -1144,7 +1163,18 @@ export class ConnectionServiceClient {
* @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 conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
* 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
* [Connection]{@link google.cloud.bigquery.connection.v1.Connection}. 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
* const iterable = client.listConnectionsAsync(request);
* for await (const response of iterable) {
* // process response
* }
*/
listConnectionsAsync(
request?: protos.google.cloud.bigquery.connection.v1.IListConnectionsRequest,
Expand Down Expand Up @@ -1261,9 +1291,10 @@ export class ConnectionServiceClient {
}

/**
* Terminate the GRPC channel and close the client.
* 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<void> {
this.initialize();
Expand Down
16 changes: 5 additions & 11 deletions packages/google-cloud-bigquery-connection/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
{
"git": {
"name": ".",
"remote": "https://github.com/googleapis/nodejs-bigquery-connection.git",
"sha": "c68d85664dbe383bf2b3c1ec1d9e7d58274ff8da"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "aa72330a8d16d281df131e8d37bb1a4bde53401f",
"internalRef": "334870265"
"remote": "git@github.com:googleapis/nodejs-bigquery-connection.git",
"sha": "96f7696047a8b935b878805637ffa285a63e99ab"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "ba9918cd22874245b55734f57470c719b577e591"
"sha": "1f1148d3c7a7a52f0c98077f976bd9b3c948ee2b"
}
}
],
Expand Down Expand Up @@ -87,12 +79,14 @@
"README.md",
"api-extractor.json",
"linkinator.config.json",
"package-lock.json.247729600",
"protos/google/cloud/bigquery/connection/v1/connection.proto",
"protos/protos.d.ts",
"protos/protos.js",
"protos/protos.json",
"renovate.json",
"samples/README.md",
"samples/package-lock.json.2458163518",
"src/index.ts",
"src/v1/connection_service_client.ts",
"src/v1/connection_service_client_config.json",
Expand Down
Loading

0 comments on commit 411c2ad

Please sign in to comment.