Skip to content

Commit

Permalink
Switch to grpc-ts 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kirpichenko committed Mar 9, 2020
1 parent fd74da3 commit b57da1b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
10 changes: 8 additions & 2 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<grpcts.Config, 'definition'>;"))
}

func (g *generator) generateClient(service *google_protobuf.ServiceDescriptorProto, packageName string, protoFileName string) {
g.P()
if g.isServiceDeprecated(service) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 4 additions & 14 deletions integrationTests/__tests__/generated/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,21 +964,11 @@ export namespace Foo {
): void
}

export type ClientConfig = Omit<grpcts.Config, 'definition'>

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
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions integrationTests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit b57da1b

Please sign in to comment.