diff --git a/generator/generator.go b/generator/generator.go index ba799af..4c8037d 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -641,6 +641,11 @@ func (g *generator) generateImplementation(service *google_protobuf.ServiceDescr } +func (g *generator) generateClientConfigType() { + g.P() + g.P(fmt.Sprintf("export type ClientConfig = Omit;")) +} + func (g *generator) generateClient(service *google_protobuf.ServiceDescriptorProto, packageName string, protoFileName string) { g.P() if g.isServiceDeprecated(service) { @@ -649,8 +654,8 @@ func (g *generator) generateClient(service *google_protobuf.ServiceDescriptorPro g.P("*/") } g.P(fmt.Sprintf("export class %sClient extends grpcts.Client {", gen.CamelCase(*service.Name))) - g.P("constructor(address: string, credentials?: grpcts.grpc.ChannelCredentials, trace: grpcts.ClientTrace = nodeTrace, options?: object){") - g.P(fmt.Sprintf("super(%sServiceDefinition, address, credentials, trace, options, logger);", g.toLowerFirst(*service.Name))) + g.P("constructor(config: ClientConfig){") + g.P(fmt.Sprintf("super({ definition: %sServiceDefinition, trace: nodeTrace, ...config });", g.toLowerFirst(*service.Name))) g.P("}") for _, method := range service.Method { inputTypeName := g.getTsTypeFromMessage(method.InputType, true) @@ -713,6 +718,7 @@ func (g *generator) Make(protoFile *google_protobuf.FileDescriptorProto, protoFi for _, service := range protoFile.Service { g.generateDefinition(service) g.generateImplementation(service) + g.generateClientConfigType() g.generateClient(service, *protoFile.Package, *protoFile.Name) } diff --git a/integrationTests/__tests__/generated/Test.ts b/integrationTests/__tests__/generated/Test.ts index d746c83..9ccfb55 100644 --- a/integrationTests/__tests__/generated/Test.ts +++ b/integrationTests/__tests__/generated/Test.ts @@ -964,21 +964,11 @@ export namespace Foo { ): void } + export type ClientConfig = Omit + export class UsersClient extends grpcts.Client { - constructor( - address: string, - credentials?: grpcts.grpc.ChannelCredentials, - trace: grpcts.ClientTrace = nodeTrace, - options?: object - ) { - super( - usersServiceDefinition, - address, - credentials, - trace, - options, - logger - ) + constructor(config: ClientConfig) { + super({ definition: usersServiceDefinition, trace: nodeTrace, ...config }) } /** * @deprecated diff --git a/integrationTests/package.json b/integrationTests/package.json index 2829393..6e83b48 100644 --- a/integrationTests/package.json +++ b/integrationTests/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@join-com/gcloud-logger-trace": "^0.1.6", - "@join-com/grpc-ts": "1.1.7", + "@join-com/grpc-ts": "2.0.0", "grpc": "^1.24.2", "protobufjs": "^6.8.8" }, diff --git a/integrationTests/yarn.lock b/integrationTests/yarn.lock index 50eb4ee..31eecd6 100644 --- a/integrationTests/yarn.lock +++ b/integrationTests/yarn.lock @@ -403,10 +403,10 @@ dependencies: "@join-com/gcloud-logger" "^0.1.6" -"@join-com/grpc-ts@1.1.7": - version "1.1.7" - resolved "https://registry.yarnpkg.com/@join-com/grpc-ts/-/grpc-ts-1.1.7.tgz#ce18ee0cb76d25404a6692b0ef58eb237ce649b4" - integrity sha512-S8J1uXCbtRrqo1riS8zYXsxp6i8DgyobBJ1TKfm/c0If1lnAjww25U3EJ+pJaNY8gMSpu+qVq8ErWz2tWQc99w== +"@join-com/grpc-ts@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@join-com/grpc-ts/-/grpc-ts-2.0.0.tgz#7a678936979685cefea98e533a21c24fafc764b1" + integrity sha512-P4ermSbKHUpkpyG9olOs/Y02oyTBp7FtSq+2TQ1ugbjuYcymQ/D/f1brXx27c9f0+dehw6CMJGtHqe3ID1Otew== dependencies: grpc "^1.24.2"