Skip to content

Commit

Permalink
fix: do not modify options object, use defaultScopes (#218)
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 committed Nov 7, 2020
1 parent 9de845e commit f096118
Show file tree
Hide file tree
Showing 9 changed files with 769 additions and 498 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-datacatalog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Google Cloud Data Catalog API"
],
"dependencies": {
"google-gax": "^2.1.0"
"google-gax": "^2.9.2"
},
"devDependencies": {
"@types/mocha": "^8.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/google-cloud-datacatalog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import * as v1 from './v1';
import * as v1beta1 from './v1beta1';

const DataCatalogClient = v1.DataCatalogClient;
type DataCatalogClient = v1.DataCatalogClient;
const PolicyTagManagerClient = v1beta1.PolicyTagManagerClient;
type PolicyTagManagerClient = v1beta1.PolicyTagManagerClient;
const PolicyTagManagerSerializationClient =
v1beta1.PolicyTagManagerSerializationClient;
type PolicyTagManagerSerializationClient = v1beta1.PolicyTagManagerSerializationClient;

export {
v1,
Expand Down
436 changes: 267 additions & 169 deletions packages/google-cloud-datacatalog/src/v1/data_catalog_client.ts

Large diffs are not rendered by default.

432 changes: 265 additions & 167 deletions packages/google-cloud-datacatalog/src/v1beta1/data_catalog_client.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export class PolicyTagManagerSerializationClient {
/**
* Construct an instance of PolicyTagManagerSerializationClient.
*
* @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 @@ -73,44 +75,34 @@ export class PolicyTagManagerSerializationClient {
* 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 PolicyTagManagerSerializationClient;
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?.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 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 PolicyTagManagerSerializationClient 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 PolicyTagManagerSerializationClient).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 @@ -119,6 +111,11 @@ export class PolicyTagManagerSerializationClient {
// 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 @@ -262,6 +259,7 @@ export class PolicyTagManagerSerializationClient {

/**
* The DNS address for this API service.
* @returns {string} The DNS address for this service.
*/
static get servicePath() {
return 'datacatalog.googleapis.com';
Expand All @@ -270,13 +268,15 @@ export class PolicyTagManagerSerializationClient {
/**
* 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 'datacatalog.googleapis.com';
}

/**
* The port for this API service.
* @returns {number} The default port for this service.
*/
static get port() {
return 443;
Expand All @@ -285,6 +285,7 @@ export class PolicyTagManagerSerializationClient {
/**
* 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'];
Expand All @@ -294,8 +295,7 @@ export class PolicyTagManagerSerializationClient {
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 @@ -362,7 +362,11 @@ export class PolicyTagManagerSerializationClient {
* 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 [ImportTaxonomiesResponse]{@link google.cloud.datacatalog.v1beta1.ImportTaxonomiesResponse}.
* 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.importTaxonomies(request);
*/
importTaxonomies(
request: protos.google.cloud.datacatalog.v1beta1.IImportTaxonomiesRequest,
Expand Down Expand Up @@ -464,7 +468,11 @@ export class PolicyTagManagerSerializationClient {
* 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 [ExportTaxonomiesResponse]{@link google.cloud.datacatalog.v1beta1.ExportTaxonomiesResponse}.
* 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.exportTaxonomies(request);
*/
exportTaxonomies(
request: protos.google.cloud.datacatalog.v1beta1.IExportTaxonomiesRequest,
Expand Down Expand Up @@ -1025,9 +1033,10 @@ export class PolicyTagManagerSerializationClient {
}

/**
* 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-datacatalog/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-datacatalog.git",
"sha": "afeda4fc20a5ec2b4229e96fd3f026addb49b55d"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "4c5071b615d96ef9dfd6a63d8429090f1f2872bb",
"internalRef": "327369997"
"remote": "git@github.com:googleapis/nodejs-datacatalog.git",
"sha": "b44fdb110b252944b9e3037fded40c2f44a55d74"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "ba9918cd22874245b55734f57470c719b577e591"
"sha": "1f1148d3c7a7a52f0c98077f976bd9b3c948ee2b"
}
}
],
Expand Down Expand Up @@ -95,6 +87,7 @@
"LICENSE",
"README.md",
"api-extractor.json",
"package-lock.json.2401090590",
"protos/google/cloud/datacatalog/v1/common.proto",
"protos/google/cloud/datacatalog/v1/datacatalog.proto",
"protos/google/cloud/datacatalog/v1/gcs_fileset_spec.proto",
Expand All @@ -117,6 +110,7 @@
"protos/protos.js",
"protos/protos.json",
"renovate.json",
"samples/package-lock.json.292908405",
"src/index.ts",
"src/v1/data_catalog_client.ts",
"src/v1/data_catalog_client_config.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,31 @@ import {
PolicyTagManagerSerializationClient,
} from '@google-cloud/datacatalog';

// check that the client class type name can be used
function doStuffWithDataCatalogClient(client: DataCatalogClient) {
client.close();
}
function doStuffWithPolicyTagManagerClient(client: PolicyTagManagerClient) {
client.close();
}
function doStuffWithPolicyTagManagerSerializationClient(
client: PolicyTagManagerSerializationClient
) {
client.close();
}

function main() {
new DataCatalogClient();
new PolicyTagManagerClient();
new PolicyTagManagerSerializationClient();
// check that the client instance can be created
const dataCatalogClient = new DataCatalogClient();
doStuffWithDataCatalogClient(dataCatalogClient);
// check that the client instance can be created
const policyTagManagerClient = new PolicyTagManagerClient();
doStuffWithPolicyTagManagerClient(policyTagManagerClient);
// check that the client instance can be created
const policyTagManagerSerializationClient = new PolicyTagManagerSerializationClient();
doStuffWithPolicyTagManagerSerializationClient(
policyTagManagerSerializationClient
);
}

main();
18 changes: 9 additions & 9 deletions packages/google-cloud-datacatalog/system-test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ import {packNTest} from 'pack-n-play';
import {readFileSync} from 'fs';
import {describe, it} from 'mocha';

describe('typescript consumer tests', () => {
it('should have correct type signature for typescript users', async function () {
describe('📦 pack-n-play test', () => {
it('TypeScript code', async function () {
this.timeout(300000);
const options = {
packageDir: process.cwd(), // path to your module.
packageDir: process.cwd(),
sample: {
description: 'typescript based user can use the type definitions',
description: 'TypeScript user can use the type definitions',
ts: readFileSync(
'./system-test/fixtures/sample/src/index.ts'
).toString(),
},
};
await packNTest(options); // will throw upon error.
await packNTest(options);
});

it('should have correct type signature for javascript users', async function () {
it('JavaScript code', async function () {
this.timeout(300000);
const options = {
packageDir: process.cwd(), // path to your module.
packageDir: process.cwd(),
sample: {
description: 'typescript based user can use the type definitions',
description: 'JavaScript user can use the library',
ts: readFileSync(
'./system-test/fixtures/sample/src/index.js'
).toString(),
},
};
await packNTest(options); // will throw upon error.
await packNTest(options);
});
});

0 comments on commit f096118

Please sign in to comment.