Skip to content

Commit

Permalink
feat: allow constructors with no parameters (#65)
Browse files Browse the repository at this point in the history
* add checking config & proto list file to baseline test

* restructure setup

* compare all files generated

* iterate output folder for multiple layers

* remove console warn

* check all baseline files are generated

* feedback

* reuse compare function to multiple proto test

* console error & not stop the test

* gtc check

* typo

* fix

* order of dependencies

* make it work after merge

* gts fix

* skip comparing proto file

* update config yaml

* assert in test, warn in util

* service config & update baseline

* polish

* fix

* fix result

* update baseline for keymanager

* feat: client constructor with no parameters

* merge conflict
  • Loading branch information
alexander-fenster authored Oct 21, 2019
1 parent 963d118 commit 8ba98a0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
36 changes: 19 additions & 17 deletions templates/typescript_gapic/src/$version/$service_client.ts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface PaginationResponse<
}
{% endif %}
export class {{ service.name }}Client {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

/**
* Construct an instance of {{ service.name }}Client.
*
Expand Down Expand Up @@ -77,13 +81,23 @@ export class {{ service.name }}Client {
* @@param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
*/
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

constructor(opts: ClientOptions) {
constructor(opts?: ClientOptions) {
// Ensure that options include the service address and port.
opts = opts || {};
const staticMembers = this.constructor as typeof {{ service.name }}Client;
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;
Expand All @@ -92,18 +106,6 @@ export class {{ service.name }}Client {
// "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;
const servicePath =
opts.servicePath ||
opts.apiEndpoint ||
(this.constructor as typeof {{service.name}}Client).servicePath;

opts = Object.assign(
{
clientConfig: {},
port: (this.constructor as typeof {{ service.name }}Client).port,
servicePath: servicePath,
},
opts);

// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export interface PaginationResponse<
}

export class KeyManagementServiceClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

/**
* Construct an instance of KeyManagementServiceClient.
*
Expand Down Expand Up @@ -90,13 +94,23 @@ export class KeyManagementServiceClient {
* @@param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
*/
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

constructor(opts: ClientOptions) {
constructor(opts?: ClientOptions) {
// Ensure that options include the service address and port.
opts = opts || {};
const staticMembers = this.constructor as typeof KeyManagementServiceClient;
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;
Expand All @@ -105,18 +119,6 @@ export class KeyManagementServiceClient {
// "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;
const servicePath =
opts.servicePath ||
opts.apiEndpoint ||
(this.constructor as typeof KeyManagementServiceClient).servicePath;

opts = Object.assign(
{
clientConfig: {},
port: (this.constructor as typeof KeyManagementServiceClient).port,
servicePath: servicePath,
},
opts);

// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface PaginationResponse<
}

export class EchoClient {
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

/**
* Construct an instance of EchoClient.
*
Expand Down Expand Up @@ -93,13 +97,23 @@ export class EchoClient {
* @@param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
*/
private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}};
private _innerApiCalls: {[name: string]: Function};
auth: gax.GoogleAuth;

constructor(opts: ClientOptions) {
constructor(opts?: ClientOptions) {
// Ensure that options include the service address and port.
opts = opts || {};
const staticMembers = this.constructor as typeof EchoClient;
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;
Expand All @@ -108,18 +122,6 @@ export class EchoClient {
// "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;
const servicePath =
opts.servicePath ||
opts.apiEndpoint ||
(this.constructor as typeof EchoClient).servicePath;

opts = Object.assign(
{
clientConfig: {},
port: (this.constructor as typeof EchoClient).port,
servicePath: servicePath,
},
opts);

// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
Expand Down

0 comments on commit 8ba98a0

Please sign in to comment.