Skip to content

Commit f096118

Browse files
fix: do not modify options object, use defaultScopes (#218)
Regenerated the library using [gapic-generator-typescript](https://github.com/googleapis/gapic-generator-typescript) v1.2.1.
1 parent 9de845e commit f096118

9 files changed

Lines changed: 769 additions & 498 deletions

File tree

packages/google-cloud-datacatalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Google Cloud Data Catalog API"
2626
],
2727
"dependencies": {
28-
"google-gax": "^2.1.0"
28+
"google-gax": "^2.9.2"
2929
},
3030
"devDependencies": {
3131
"@types/mocha": "^8.0.0",

packages/google-cloud-datacatalog/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import * as v1 from './v1';
2020
import * as v1beta1 from './v1beta1';
2121

2222
const DataCatalogClient = v1.DataCatalogClient;
23+
type DataCatalogClient = v1.DataCatalogClient;
2324
const PolicyTagManagerClient = v1beta1.PolicyTagManagerClient;
25+
type PolicyTagManagerClient = v1beta1.PolicyTagManagerClient;
2426
const PolicyTagManagerSerializationClient =
2527
v1beta1.PolicyTagManagerSerializationClient;
28+
type PolicyTagManagerSerializationClient = v1beta1.PolicyTagManagerSerializationClient;
2629

2730
export {
2831
v1,

packages/google-cloud-datacatalog/src/v1/data_catalog_client.ts

Lines changed: 267 additions & 169 deletions
Large diffs are not rendered by default.

packages/google-cloud-datacatalog/src/v1beta1/data_catalog_client.ts

Lines changed: 265 additions & 167 deletions
Large diffs are not rendered by default.

packages/google-cloud-datacatalog/src/v1beta1/policy_tag_manager_client.ts

Lines changed: 149 additions & 101 deletions
Large diffs are not rendered by default.

packages/google-cloud-datacatalog/src/v1beta1/policy_tag_manager_serialization_client.ts

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ export class PolicyTagManagerSerializationClient {
5252
/**
5353
* Construct an instance of PolicyTagManagerSerializationClient.
5454
*
55-
* @param {object} [options] - The configuration object. See the subsequent
56-
* parameters for more details.
55+
* @param {object} [options] - The configuration object.
56+
* The options accepted by the constructor are described in detail
57+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
58+
* The common options are:
5759
* @param {object} [options.credentials] - Credentials object.
5860
* @param {string} [options.credentials.client_email]
5961
* @param {string} [options.credentials.private_key]
@@ -73,44 +75,34 @@ export class PolicyTagManagerSerializationClient {
7375
* your project ID will be detected automatically.
7476
* @param {string} [options.apiEndpoint] - The domain name of the
7577
* API remote host.
78+
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
79+
* TODO(@alexander-fenster): link to gax documentation.
80+
* @param {boolean} fallback - Use HTTP fallback mode.
81+
* In fallback mode, a special browser-compatible transport implementation is used
82+
* instead of gRPC transport. In browser context (if the `window` object is defined)
83+
* the fallback mode is enabled automatically; set `options.fallback` to `false`
84+
* if you need to override this behavior.
7685
*/
77-
7886
constructor(opts?: ClientOptions) {
79-
// Ensure that options include the service address and port.
87+
// Ensure that options include all the required fields.
8088
const staticMembers = this
8189
.constructor as typeof PolicyTagManagerSerializationClient;
8290
const servicePath =
83-
opts && opts.servicePath
84-
? opts.servicePath
85-
: opts && opts.apiEndpoint
86-
? opts.apiEndpoint
87-
: staticMembers.servicePath;
88-
const port = opts && opts.port ? opts.port : staticMembers.port;
89-
90-
if (!opts) {
91-
opts = {servicePath, port};
91+
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
92+
const port = opts?.port || staticMembers.port;
93+
const clientConfig = opts?.clientConfig ?? {};
94+
const fallback = opts?.fallback ?? typeof window !== 'undefined';
95+
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
96+
97+
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
98+
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
99+
opts['scopes'] = staticMembers.scopes;
92100
}
93-
opts.servicePath = opts.servicePath || servicePath;
94-
opts.port = opts.port || port;
95-
96-
// users can override the config from client side, like retry codes name.
97-
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
98-
// The way to override client config for Showcase API:
99-
//
100-
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
101-
// const showcaseClient = new showcaseClient({ projectId, customConfig });
102-
opts.clientConfig = opts.clientConfig || {};
103-
104-
// If we're running in browser, it's OK to omit `fallback` since
105-
// google-gax has `browser` field in its `package.json`.
106-
// For Electron (which does not respect `browser` field),
107-
// pass `{fallback: true}` to the PolicyTagManagerSerializationClient constructor.
101+
102+
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
108103
this._gaxModule = opts.fallback ? gax.fallback : gax;
109104

110-
// Create a `gaxGrpc` object, with any grpc-specific options
111-
// sent to the client.
112-
opts.scopes = (this
113-
.constructor as typeof PolicyTagManagerSerializationClient).scopes;
105+
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
114106
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
115107

116108
// Save options to use in initialize() method.
@@ -119,6 +111,11 @@ export class PolicyTagManagerSerializationClient {
119111
// Save the auth object to the client, for use by other methods.
120112
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
121113

114+
// Set the default scopes in auth client if needed.
115+
if (servicePath === staticMembers.servicePath) {
116+
this.auth.defaultScopes = staticMembers.scopes;
117+
}
118+
122119
// Determine the client header string.
123120
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
124121
if (typeof process !== 'undefined' && 'versions' in process) {
@@ -262,6 +259,7 @@ export class PolicyTagManagerSerializationClient {
262259

263260
/**
264261
* The DNS address for this API service.
262+
* @returns {string} The DNS address for this service.
265263
*/
266264
static get servicePath() {
267265
return 'datacatalog.googleapis.com';
@@ -270,13 +268,15 @@ export class PolicyTagManagerSerializationClient {
270268
/**
271269
* The DNS address for this API service - same as servicePath(),
272270
* exists for compatibility reasons.
271+
* @returns {string} The DNS address for this service.
273272
*/
274273
static get apiEndpoint() {
275274
return 'datacatalog.googleapis.com';
276275
}
277276

278277
/**
279278
* The port for this API service.
279+
* @returns {number} The default port for this service.
280280
*/
281281
static get port() {
282282
return 443;
@@ -285,6 +285,7 @@ export class PolicyTagManagerSerializationClient {
285285
/**
286286
* The scopes needed to make gRPC calls for every method defined
287287
* in this service.
288+
* @returns {string[]} List of default scopes.
288289
*/
289290
static get scopes() {
290291
return ['https://www.googleapis.com/auth/cloud-platform'];
@@ -294,8 +295,7 @@ export class PolicyTagManagerSerializationClient {
294295
getProjectId(callback: Callback<string, undefined, undefined>): void;
295296
/**
296297
* Return the project ID used by this class.
297-
* @param {function(Error, string)} callback - the callback to
298-
* be called with the current project Id.
298+
* @returns {Promise} A promise that resolves to string containing the project ID.
299299
*/
300300
getProjectId(
301301
callback?: Callback<string, undefined, undefined>
@@ -362,7 +362,11 @@ export class PolicyTagManagerSerializationClient {
362362
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
363363
* @returns {Promise} - The promise which resolves to an array.
364364
* The first element of the array is an object representing [ImportTaxonomiesResponse]{@link google.cloud.datacatalog.v1beta1.ImportTaxonomiesResponse}.
365-
* The promise has a method named "cancel" which cancels the ongoing API call.
365+
* Please see the
366+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
367+
* for more details and examples.
368+
* @example
369+
* const [response] = await client.importTaxonomies(request);
366370
*/
367371
importTaxonomies(
368372
request: protos.google.cloud.datacatalog.v1beta1.IImportTaxonomiesRequest,
@@ -464,7 +468,11 @@ export class PolicyTagManagerSerializationClient {
464468
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
465469
* @returns {Promise} - The promise which resolves to an array.
466470
* The first element of the array is an object representing [ExportTaxonomiesResponse]{@link google.cloud.datacatalog.v1beta1.ExportTaxonomiesResponse}.
467-
* The promise has a method named "cancel" which cancels the ongoing API call.
471+
* Please see the
472+
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
473+
* for more details and examples.
474+
* @example
475+
* const [response] = await client.exportTaxonomies(request);
468476
*/
469477
exportTaxonomies(
470478
request: protos.google.cloud.datacatalog.v1beta1.IExportTaxonomiesRequest,
@@ -1025,9 +1033,10 @@ export class PolicyTagManagerSerializationClient {
10251033
}
10261034

10271035
/**
1028-
* Terminate the GRPC channel and close the client.
1036+
* Terminate the gRPC channel and close the client.
10291037
*
10301038
* The client will no longer be usable and all future behavior is undefined.
1039+
* @returns {Promise} A promise that resolves when the client is closed.
10311040
*/
10321041
close(): Promise<void> {
10331042
this.initialize();

packages/google-cloud-datacatalog/synth.metadata

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
{
44
"git": {
55
"name": ".",
6-
"remote": "https://github.com/googleapis/nodejs-datacatalog.git",
7-
"sha": "afeda4fc20a5ec2b4229e96fd3f026addb49b55d"
8-
}
9-
},
10-
{
11-
"git": {
12-
"name": "googleapis",
13-
"remote": "https://github.com/googleapis/googleapis.git",
14-
"sha": "4c5071b615d96ef9dfd6a63d8429090f1f2872bb",
15-
"internalRef": "327369997"
6+
"remote": "git@github.com:googleapis/nodejs-datacatalog.git",
7+
"sha": "b44fdb110b252944b9e3037fded40c2f44a55d74"
168
}
179
},
1810
{
1911
"git": {
2012
"name": "synthtool",
2113
"remote": "https://github.com/googleapis/synthtool.git",
22-
"sha": "ba9918cd22874245b55734f57470c719b577e591"
14+
"sha": "1f1148d3c7a7a52f0c98077f976bd9b3c948ee2b"
2315
}
2416
}
2517
],
@@ -95,6 +87,7 @@
9587
"LICENSE",
9688
"README.md",
9789
"api-extractor.json",
90+
"package-lock.json.2401090590",
9891
"protos/google/cloud/datacatalog/v1/common.proto",
9992
"protos/google/cloud/datacatalog/v1/datacatalog.proto",
10093
"protos/google/cloud/datacatalog/v1/gcs_fileset_spec.proto",
@@ -117,6 +110,7 @@
117110
"protos/protos.js",
118111
"protos/protos.json",
119112
"renovate.json",
113+
"samples/package-lock.json.292908405",
120114
"src/index.ts",
121115
"src/v1/data_catalog_client.ts",
122116
"src/v1/data_catalog_client_config.json",

packages/google-cloud-datacatalog/system-test/fixtures/sample/src/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,31 @@ import {
2222
PolicyTagManagerSerializationClient,
2323
} from '@google-cloud/datacatalog';
2424

25+
// check that the client class type name can be used
26+
function doStuffWithDataCatalogClient(client: DataCatalogClient) {
27+
client.close();
28+
}
29+
function doStuffWithPolicyTagManagerClient(client: PolicyTagManagerClient) {
30+
client.close();
31+
}
32+
function doStuffWithPolicyTagManagerSerializationClient(
33+
client: PolicyTagManagerSerializationClient
34+
) {
35+
client.close();
36+
}
37+
2538
function main() {
26-
new DataCatalogClient();
27-
new PolicyTagManagerClient();
28-
new PolicyTagManagerSerializationClient();
39+
// check that the client instance can be created
40+
const dataCatalogClient = new DataCatalogClient();
41+
doStuffWithDataCatalogClient(dataCatalogClient);
42+
// check that the client instance can be created
43+
const policyTagManagerClient = new PolicyTagManagerClient();
44+
doStuffWithPolicyTagManagerClient(policyTagManagerClient);
45+
// check that the client instance can be created
46+
const policyTagManagerSerializationClient = new PolicyTagManagerSerializationClient();
47+
doStuffWithPolicyTagManagerSerializationClient(
48+
policyTagManagerSerializationClient
49+
);
2950
}
3051

3152
main();

packages/google-cloud-datacatalog/system-test/install.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ import {packNTest} from 'pack-n-play';
2020
import {readFileSync} from 'fs';
2121
import {describe, it} from 'mocha';
2222

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

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

0 commit comments

Comments
 (0)