Skip to content

Commit

Permalink
feat: use common interface from gax (#122)
Browse files Browse the repository at this point in the history
* add comments for page strea,m

* use common interface from gax

* only import LROperation for service with LR method

* check LR method
  • Loading branch information
xiaozhenliu-gg5 authored and alexander-fenster committed Nov 11, 2019
1 parent b910471 commit 39e285c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 151 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file-system": "^2.2.2",
"fs-extra": "^8.1.0",
"get-stdin": "^7.0.0",
"google-gax": "^1.8.0",
"google-gax": "^1.9.0",
"nunjucks": "^3.1.3",
"object-hash": "^2.0.0",
"protobufjs": "^6.8.8",
Expand Down
42 changes: 10 additions & 32 deletions templates/typescript_gapic/src/$version/$service_client.ts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ limitations under the License.
{% import "../../_util.njk" as util -%}

import * as gax from 'google-gax';
{% if service.longRunning.length > 0 -%}
import {Callback, LROperation, Descriptors, ClientOptions} from 'google-gax';
{%- else -%}
import {Callback, Descriptors, ClientOptions} from 'google-gax';
{%- endif %}
import * as path from 'path';
{% if (service.paging.length > 0) %}
import { Transform } from 'stream';
Expand All @@ -29,33 +34,6 @@ import * as gapicConfig from './{{ service.name.toSnakeCase() }}_client_config.j

const version = require('../../../package.json').version;

export interface ClientOptions extends gax.GrpcClientOptions,
gax.GoogleAuthOptions,
gax.ClientStubOptions {
libName?: string;
libVersion?: string;
clientConfig?: gax.ClientConfig;
fallback?: boolean;
apiEndpoint?: string;
}

interface Descriptors {
page: {[name: string]: gax.PageDescriptor};
stream: {[name: string]: gax.StreamDescriptor};
longrunning: {[name: string]: gax.LongrunningDescriptor};
}

export interface Callback<
ResponseObject, NextRequestObject, RawResponseObject> {
(err: Error|null|undefined, value?: ResponseObject|null,
nextRequest?: NextRequestObject, rawResponse?: RawResponseObject): void;
}
{% if (service.longRunning.length > 0) %}
export interface Operation<ResultType, MetadataType> extends gax.Operation {
promise(): Promise<[ResultType, MetadataType, protosTypes.google.longrunning.IOperation]>;
}
{%- endif %}

{% if (service.paging.length > 0) %}
export interface PaginationCallback<
RequestObject, ResponseObject, ResponseType> {
Expand Down Expand Up @@ -465,14 +443,14 @@ export class {{ service.name }}Client {
request: protosTypes{{ util.toInterface(method.inputInterface) }},
options?: gax.CallOptions):
Promise<[
Operation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
LROperation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined
]>;
{{ method.name.toCamelCase() }}(
request: protosTypes{{ util.toInterface(method.inputInterface) }},
options: gax.CallOptions,
callback: Callback<
Operation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
LROperation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
protosTypes{{ util.toInterface(method.outputInterface) }}|undefined,
{}|undefined>): void;
/**
Expand All @@ -481,14 +459,14 @@ export class {{ service.name }}Client {
{{ method.name.toCamelCase() }}(
request: protosTypes{{ util.toInterface(method.inputInterface) }},
optionsOrCallback?: gax.CallOptions|Callback<
Operation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType)}}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
LROperation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType)}}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined>,
callback?: Callback<
Operation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
LROperation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
protosTypes{{ util.toInterface(method.outputInterface) }}|undefined,
{}|undefined>):
Promise<[
Operation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
LROperation<protosTypes{{ util.toInterface(method.longRunningResponseType, method.inputType) }}, protosTypes{{ util.toInterface(method.longRunningMetadataType, method.inputType) }}>,
protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined
]>|void {
request = request || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// ** All changes to this file may be overwritten. **

import * as gax from 'google-gax';
import {Callback, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import { Transform } from 'stream';
Expand All @@ -25,29 +26,6 @@ import * as gapicConfig from './key_management_service_client_config.json';

const version = require('../../../package.json').version;

export interface ClientOptions extends gax.GrpcClientOptions,
gax.GoogleAuthOptions,
gax.ClientStubOptions {
libName?: string;
libVersion?: string;
clientConfig?: gax.ClientConfig;
fallback?: boolean;
apiEndpoint?: string;
}

interface Descriptors {
page: {[name: string]: gax.PageDescriptor};
stream: {[name: string]: gax.StreamDescriptor};
longrunning: {[name: string]: gax.LongrunningDescriptor};
}

export interface Callback<
ResponseObject, NextRequestObject, RawResponseObject> {
(err: Error|null|undefined, value?: ResponseObject|null,
nextRequest?: NextRequestObject, rawResponse?: RawResponseObject): void;
}



export interface PaginationCallback<
RequestObject, ResponseObject, ResponseType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// ** All changes to this file may be overwritten. **

import * as gax from 'google-gax';
import {Callback, LROperation, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import { Transform } from 'stream';
Expand All @@ -25,32 +26,6 @@ import * as gapicConfig from './echo_client_config.json';

const version = require('../../../package.json').version;

export interface ClientOptions extends gax.GrpcClientOptions,
gax.GoogleAuthOptions,
gax.ClientStubOptions {
libName?: string;
libVersion?: string;
clientConfig?: gax.ClientConfig;
fallback?: boolean;
apiEndpoint?: string;
}

interface Descriptors {
page: {[name: string]: gax.PageDescriptor};
stream: {[name: string]: gax.StreamDescriptor};
longrunning: {[name: string]: gax.LongrunningDescriptor};
}

export interface Callback<
ResponseObject, NextRequestObject, RawResponseObject> {
(err: Error|null|undefined, value?: ResponseObject|null,
nextRequest?: NextRequestObject, rawResponse?: RawResponseObject): void;
}

export interface Operation<ResultType, MetadataType> extends gax.Operation {
promise(): Promise<[ResultType, MetadataType, protosTypes.google.longrunning.IOperation]>;
}


export interface PaginationCallback<
RequestObject, ResponseObject, ResponseType> {
Expand Down Expand Up @@ -441,14 +416,14 @@ export class EchoClient {
request: protosTypes.google.showcase.v1beta1.IWaitRequest,
options?: gax.CallOptions):
Promise<[
Operation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
LROperation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
protosTypes.google.longrunning.IOperation|undefined, {}|undefined
]>;
wait(
request: protosTypes.google.showcase.v1beta1.IWaitRequest,
options: gax.CallOptions,
callback: Callback<
Operation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
LROperation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
protosTypes.google.longrunning.IOperation|undefined,
{}|undefined>): void;
/**
Expand All @@ -475,14 +450,14 @@ export class EchoClient {
wait(
request: protosTypes.google.showcase.v1beta1.IWaitRequest,
optionsOrCallback?: gax.CallOptions|Callback<
Operation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
LROperation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
protosTypes.google.longrunning.IOperation|undefined, {}|undefined>,
callback?: Callback<
Operation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
LROperation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
protosTypes.google.longrunning.IOperation|undefined,
{}|undefined>):
Promise<[
Operation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
LROperation<protosTypes.google.showcase.v1beta1.IWaitResponse, protosTypes.google.showcase.v1beta1.IWaitMetadata>,
protosTypes.google.longrunning.IOperation|undefined, {}|undefined
]>|void {
request = request || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,14 @@
// ** All changes to this file may be overwritten. **

import * as gax from 'google-gax';
import {Callback, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import * as protosTypes from '../../protos/protos';
import * as gapicConfig from './text_to_speech_client_config.json';

const version = require('../../../package.json').version;

export interface ClientOptions extends gax.GrpcClientOptions,
gax.GoogleAuthOptions,
gax.ClientStubOptions {
libName?: string;
libVersion?: string;
clientConfig?: gax.ClientConfig;
fallback?: boolean;
apiEndpoint?: string;
}

interface Descriptors {
page: {[name: string]: gax.PageDescriptor};
stream: {[name: string]: gax.StreamDescriptor};
longrunning: {[name: string]: gax.LongrunningDescriptor};
}

export interface Callback<
ResponseObject, NextRequestObject, RawResponseObject> {
(err: Error|null|undefined, value?: ResponseObject|null,
nextRequest?: NextRequestObject, rawResponse?: RawResponseObject): void;
}




/**
Expand Down
Loading

0 comments on commit 39e285c

Please sign in to comment.