Skip to content

Commit

Permalink
Merge pull request #15 from join-com/client-bugfixes
Browse files Browse the repository at this point in the history
fix: generated client type
  • Loading branch information
castarco authored Apr 17, 2021
2 parents 6606200 + 7ef64c4 commit 5880db3
Show file tree
Hide file tree
Showing 38 changed files with 91 additions and 1,651 deletions.
5 changes: 1 addition & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ commands:
name: Compile
command: cd ./tests && yarn compile
- run:
name: Generate TS code (legacy)
name: Generate TS code
command: cd ./tests && yarn proto:build
- run:
name: Generate TS code (v2)
command: cd ./tests && yarn v2:build
- run:
name: Lint generated code
command: cd ./tests && yarn lint
Expand Down
8 changes: 7 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/bin/sh

go build -o ./dist/protoc-gen-ts
# Building binary
go build -o ./dist/protoc-gen-tsx

if [ "${CI}" != "true" ]; then
# Stripping symbols to make the binary more lightweight
strip -u -r -S ./dist/protoc-gen-tsx
fi
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/join-com/protoc-gen-ts
go 1.16

require (
github.com/golang/protobuf v1.5.2 // Legacy import
github.com/iancoleman/strcase v0.1.3
google.golang.org/protobuf v1.26.0
)
13 changes: 10 additions & 3 deletions internal/generator/runer_generate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (r *Runner) generateTypescriptClientInterface(generatedFileStream *protogen
r.P(
generatedFileStream,
"export interface I"+strcase.ToCamel(serviceSpec.GetName())+"Client",
"extends joinGRPC.IClient<grpc.ServiceDefinition<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation>> ",
", joinGRPC.IExtendedClient<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation> {",
"extends joinGRPC.IExtendedClient<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation, '"+r.currentPackage+"."+serviceSpec.GetName()+"'> {",
)
r.indentLevel += 2

Expand Down Expand Up @@ -147,11 +146,19 @@ func (r *Runner) generateTypescriptClient(generatedFileStream *protogen.Generate
r.P(
generatedFileStream,
"export class "+strcase.ToCamel(serviceSpec.GetName())+"Client",
"extends joinGRPC.Client<grpc.ServiceDefinition<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation>> ",
"extends joinGRPC.Client<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation, '"+r.currentPackage+"."+serviceSpec.GetName()+"'> ",
"implements I"+strcase.ToCamel(serviceSpec.GetName())+"Client {",
)
r.indentLevel += 2

r.P(generatedFileStream, "constructor(public readonly config: joinGRPC.IClientConfig<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation>) {")
r.indentLevel += 2

r.P(generatedFileStream, "super(config, '"+r.currentPackage+"."+serviceSpec.GetName()+"')")

r.indentLevel -= 2
r.P(generatedFileStream, "}\n")

for _, methodSpec := range serviceSpec.GetMethod() {
r.generateTypescriptClientMethod(generatedFileStream, serviceSpec, methodSpec)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/generator/runner_generate_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *Runner) generateAsInterfaceMethod(generatedFileStream *protogen.Generat

func (r *Runner) generateFromInterfaceMethod(generatedFileStream *protogen.GeneratedFile, messageSpec *descriptorpb.DescriptorProto, requiredFields bool, hasEnums bool) {
className := strcase.ToCamel(messageSpec.GetName())
r.P(generatedFileStream, "public static fromInterface(value: I"+className+"): "+className+" {")
r.P(generatedFileStream, "public static fromInterface(this: void, value: I"+className+"): "+className+" {")
r.indentLevel += 2

if hasEnums {
Expand All @@ -142,7 +142,7 @@ func (r *Runner) generateFromInterfaceMethod(generatedFileStream *protogen.Gener

func (r *Runner) generateDecodePatchedMethod(generatedFileStream *protogen.GeneratedFile, messageSpec *descriptorpb.DescriptorProto, requiredFields bool, hasEnums bool) {
className := strcase.ToCamel(messageSpec.GetName())
r.P(generatedFileStream, "public static decodePatched(reader: protobufjs.Reader | Uint8Array): I"+className+" {")
r.P(generatedFileStream, "public static decodePatched(this: void, reader: protobufjs.Reader | Uint8Array): I"+className+" {")
r.indentLevel += 2

if hasEnums {
Expand All @@ -158,8 +158,7 @@ func (r *Runner) generateDecodePatchedMethod(generatedFileStream *protogen.Gener
func (r *Runner) generateEncodePatchedMethod(generatedFileStream *protogen.GeneratedFile, messageSpec *descriptorpb.DescriptorProto, requiredFields bool, hasEnums bool) {
className := strcase.ToCamel(messageSpec.GetName())

// public static encode<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
r.P(generatedFileStream, "public static encodePatched(message: I"+className+", writer?: protobufjs.Writer): protobufjs.Writer {")
r.P(generatedFileStream, "public static encodePatched(this: void, message: I"+className+", writer?: protobufjs.Writer): protobufjs.Writer {")
r.indentLevel += 2

if hasEnums {
Expand Down
261 changes: 0 additions & 261 deletions legacy/base/generator.go

This file was deleted.

Loading

0 comments on commit 5880db3

Please sign in to comment.