From 39e285c08f851ff02fc23f951957267620ebde91 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Mon, 11 Nov 2019 09:52:34 -0800 Subject: [PATCH] feat: use common interface from gax (#122) * add comments for page strea,m * use common interface from gax * only import LROperation for service with LR method * check LR method --- package.json | 2 +- .../src/$version/$service_client.ts.njk | 42 ++++---------- .../key_management_service_client.ts.baseline | 24 +------- .../src/v1beta1/echo_client.ts.baseline | 37 ++---------- .../src/v1/text_to_speech_client.ts.baseline | 24 +------- .../translation_service_client.ts.baseline | 57 ++++++------------- 6 files changed, 35 insertions(+), 151 deletions(-) diff --git a/package.json b/package.json index 44a24dab7..8362ea50e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 60ca43dc4..97909de26 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -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'; @@ -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 extends gax.Operation { - promise(): Promise<[ResultType, MetadataType, protosTypes.google.longrunning.IOperation]>; -} -{%- endif %} - {% if (service.paging.length > 0) %} export interface PaginationCallback< RequestObject, ResponseObject, ResponseType> { @@ -465,14 +443,14 @@ export class {{ service.name }}Client { request: protosTypes{{ util.toInterface(method.inputInterface) }}, options?: gax.CallOptions): Promise<[ - Operation, + LROperation, protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined ]>; {{ method.name.toCamelCase() }}( request: protosTypes{{ util.toInterface(method.inputInterface) }}, options: gax.CallOptions, callback: Callback< - Operation, + LROperation, protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined>): void; /** @@ -481,14 +459,14 @@ export class {{ service.name }}Client { {{ method.name.toCamelCase() }}( request: protosTypes{{ util.toInterface(method.inputInterface) }}, optionsOrCallback?: gax.CallOptions|Callback< - Operation, + LROperation, protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined>, callback?: Callback< - Operation, + LROperation, protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined>): Promise<[ - Operation, + LROperation, protosTypes{{ util.toInterface(method.outputInterface) }}|undefined, {}|undefined ]>|void { request = request || {}; diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 74737a1c5..a53eb19be 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -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'; @@ -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> { diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 54c58e198..dcba87364 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -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'; @@ -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 extends gax.Operation { - promise(): Promise<[ResultType, MetadataType, protosTypes.google.longrunning.IOperation]>; -} - export interface PaginationCallback< RequestObject, ResponseObject, ResponseType> { @@ -441,14 +416,14 @@ export class EchoClient { request: protosTypes.google.showcase.v1beta1.IWaitRequest, options?: gax.CallOptions): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>; wait( request: protosTypes.google.showcase.v1beta1.IWaitRequest, options: gax.CallOptions, callback: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): void; /** @@ -475,14 +450,14 @@ export class EchoClient { wait( request: protosTypes.google.showcase.v1beta1.IWaitRequest, optionsOrCallback?: gax.CallOptions|Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>, callback?: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>|void { request = request || {}; diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index 82cd76ab4..a206c8b6e 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -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 * as protosTypes from '../../protos/protos'; @@ -24,29 +25,6 @@ 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; -} - - /** diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index ca2e9409b..d0a06fd1a 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -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'; @@ -25,32 +26,6 @@ import * as gapicConfig from './translation_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 Operation extends gax.Operation { - promise(): Promise<[ResultType, MetadataType, protosTypes.google.longrunning.IOperation]>; -} - export interface PaginationCallback< RequestObject, ResponseObject, ResponseType> { @@ -684,14 +659,14 @@ export class TranslationServiceClient { request: protosTypes.google.cloud.translation.v3beta1.IBatchTranslateTextRequest, options?: gax.CallOptions): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>; batchTranslateText( request: protosTypes.google.cloud.translation.v3beta1.IBatchTranslateTextRequest, options: gax.CallOptions, callback: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): void; /** @@ -766,14 +741,14 @@ export class TranslationServiceClient { batchTranslateText( request: protosTypes.google.cloud.translation.v3beta1.IBatchTranslateTextRequest, optionsOrCallback?: gax.CallOptions|Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>, callback?: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>|void { request = request || {}; @@ -799,14 +774,14 @@ export class TranslationServiceClient { request: protosTypes.google.cloud.translation.v3beta1.ICreateGlossaryRequest, options?: gax.CallOptions): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>; createGlossary( request: protosTypes.google.cloud.translation.v3beta1.ICreateGlossaryRequest, options: gax.CallOptions, callback: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): void; /** @@ -828,14 +803,14 @@ export class TranslationServiceClient { createGlossary( request: protosTypes.google.cloud.translation.v3beta1.ICreateGlossaryRequest, optionsOrCallback?: gax.CallOptions|Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>, callback?: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>|void { request = request || {}; @@ -861,14 +836,14 @@ export class TranslationServiceClient { request: protosTypes.google.cloud.translation.v3beta1.IDeleteGlossaryRequest, options?: gax.CallOptions): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>; deleteGlossary( request: protosTypes.google.cloud.translation.v3beta1.IDeleteGlossaryRequest, options: gax.CallOptions, callback: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): void; /** @@ -889,14 +864,14 @@ export class TranslationServiceClient { deleteGlossary( request: protosTypes.google.cloud.translation.v3beta1.IDeleteGlossaryRequest, optionsOrCallback?: gax.CallOptions|Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>, callback?: Callback< - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined>): Promise<[ - Operation, + LROperation, protosTypes.google.longrunning.IOperation|undefined, {}|undefined ]>|void { request = request || {};