Skip to content

Commit

Permalink
Merge pull request #41 from join-com/minor-fixes
Browse files Browse the repository at this point in the history
feat: always sort object properties
  • Loading branch information
castarco authored Jun 25, 2021
2 parents f6756c6 + 5e34726 commit db83ffb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
26 changes: 18 additions & 8 deletions internal/generator/runer_generate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ func (r *Runner) generateTypescriptServiceImplementationInterface(generatedFileS
r.P(generatedFileStream, "export interface I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation {")
r.indentLevel += 2

for _, methodSpec := range serviceSpec.GetMethod() {
methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
clientStream := methodSpec.GetClientStreaming()
serverStream := methodSpec.GetServerStreaming()

Expand Down Expand Up @@ -50,7 +55,12 @@ func (r *Runner) generateTypescriptServiceDefinition(generatedFileStream *protog
r.P(generatedFileStream, "export const "+strcase.ToLowerCamel(serviceSpec.GetName())+"ServiceDefinition: grpc.ServiceDefinition<I"+strcase.ToCamel(serviceSpec.GetName())+"ServiceImplementation> = {")
r.indentLevel += 2

for _, methodSpec := range serviceSpec.GetMethod() {
methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
r.generateTypescriptServiceDefinitionMethod(generatedFileStream, serviceSpec, methodSpec)
}

Expand Down Expand Up @@ -101,7 +111,12 @@ func (r *Runner) generateTypescriptServiceAbstractClass(generatedFileStream *pro
" {",
)

for _, methodSpec := range serviceSpec.GetMethod() {
methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
methodName := methodSpec.GetName()
r.P(generatedFileStream, " "+strcase.ToLowerCamel(methodName)+": (call) => this."+methodName+"(call),")
}
Expand All @@ -114,11 +129,6 @@ func (r *Runner) generateTypescriptServiceAbstractClass(generatedFileStream *pro
"}\n",
)

methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
methodName := methodSpec.GetName()

Expand Down
16 changes: 14 additions & 2 deletions internal/generator/runner_generate_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package generator

import (
"sort"

"github.com/iancoleman/strcase"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
Expand All @@ -27,7 +29,12 @@ func (r *Runner) generateTypescriptClientInterface(generatedFileStream *protogen
)
r.indentLevel += 2

for _, methodSpec := range serviceSpec.GetMethod() {
methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
r.generateTypescriptClientInterfaceMethod(generatedFileStream, serviceSpec, methodSpec)
}

Expand Down Expand Up @@ -118,7 +125,12 @@ func (r *Runner) generateTypescriptClientClass(generatedFileStream *protogen.Gen
r.indentLevel -= 2
r.P(generatedFileStream, "}\n")

for _, methodSpec := range serviceSpec.GetMethod() {
methods := serviceSpec.GetMethod()
sort.Slice(methods, func(i, j int) bool {
return methods[i].GetName() < methods[j].GetName()
})

for _, methodSpec := range methods {
r.generateTypescriptClientMethod(generatedFileStream, serviceSpec, methodSpec)
}

Expand Down
28 changes: 14 additions & 14 deletions tests/__tests__/generated/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,15 @@ export namespace Foo {

export interface IUsersServiceImplementation {
Find: grpc.handleUnaryCall<IRequest, Common_Common.IOtherPkgMessage>
FindClientStream: grpc.handleClientStreamingCall<
FindBidiStream: grpc.handleBidiStreamingCall<
IRequest,
Common_Common.IOtherPkgMessage
>
FindServerStream: grpc.handleServerStreamingCall<
FindClientStream: grpc.handleClientStreamingCall<
IRequest,
Common_Common.IOtherPkgMessage
>
FindBidiStream: grpc.handleBidiStreamingCall<
FindServerStream: grpc.handleServerStreamingCall<
IRequest,
Common_Common.IOtherPkgMessage
>
Expand All @@ -543,10 +543,10 @@ export namespace Foo {
).finish() as Buffer,
responseDeserialize: Common_Common.OtherPkgMessage.decodePatched,
},
FindClientStream: {
path: '/foo.Users/FindClientStream',
FindBidiStream: {
path: '/foo.Users/FindBidiStream',
requestStream: true,
responseStream: false,
responseStream: true,
requestSerialize: (request: IRequest) =>
Request.encodePatched(request).finish() as Buffer,
requestDeserialize: Request.decodePatched,
Expand All @@ -556,10 +556,10 @@ export namespace Foo {
).finish() as Buffer,
responseDeserialize: Common_Common.OtherPkgMessage.decodePatched,
},
FindServerStream: {
path: '/foo.Users/FindServerStream',
requestStream: false,
responseStream: true,
FindClientStream: {
path: '/foo.Users/FindClientStream',
requestStream: true,
responseStream: false,
requestSerialize: (request: IRequest) =>
Request.encodePatched(request).finish() as Buffer,
requestDeserialize: Request.decodePatched,
Expand All @@ -569,9 +569,9 @@ export namespace Foo {
).finish() as Buffer,
responseDeserialize: Common_Common.OtherPkgMessage.decodePatched,
},
FindBidiStream: {
path: '/foo.Users/FindBidiStream',
requestStream: true,
FindServerStream: {
path: '/foo.Users/FindServerStream',
requestStream: false,
responseStream: true,
requestSerialize: (request: IRequest) =>
Request.encodePatched(request).finish() as Buffer,
Expand All @@ -593,9 +593,9 @@ export namespace Foo {
usersServiceDefinition,
{
find: (call) => this.Find(call),
findBidiStream: (call) => this.FindBidiStream(call),
findClientStream: (call) => this.FindClientStream(call),
findServerStream: (call) => this.FindServerStream(call),
findBidiStream: (call) => this.FindBidiStream(call),
},
logger,
trace
Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@coderspirit/nominal": "^3.0.0",
"@join-com/gcloud-logger-trace": "^0.1.17",
"@join-com/grpc": "^2.0.0",
"@join-com/grpc": "^2.0.2",
"protobufjs": "^6.11.2"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@
dependencies:
grpc "^1.24.5"

"@join-com/grpc@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@join-com/grpc/-/grpc-2.0.0.tgz#c72c904026cbf4c516b81c030749e5cb307f6491"
integrity sha512-+SKr8Y2faUxS3qH3bjuP22ewJOgzsGbTBJjptmTXBS0tZm7LE9ka/5iF3kdvNXX79FSLp5iSxRuVLNEICgZajQ==
"@join-com/grpc@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@join-com/grpc/-/grpc-2.0.2.tgz#c42237a0f80d0674eb1b5332253925b7c179989e"
integrity sha512-96i34ubXWcITcGQEL9bE/CMneUtIPjnLaMdrbumWyI3YzYOt18dZVASzn7QiM1/iqzOETBsTO+0fGJlcaEXrew==
dependencies:
"@coderspirit/nominal" "^3.0.0"
"@grpc/grpc-js" "^1.3.2"
Expand Down Expand Up @@ -1680,9 +1680,9 @@ [email protected]:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.723:
version "1.3.756"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.756.tgz#942cee59cd64d19f576d8d5804eef09cb423740c"
integrity sha512-WsmJym1TMeHVndjPjczTFbnRR/c4sbzg8fBFtuhlb2Sru3i/S1VGpzDSrv/It8ctMU2bj8G7g7/O3FzYMGw6eA==
version "1.3.757"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.757.tgz#ff99436c99ca0fc5d120e11030a868401396e0e1"
integrity sha512-kP0ooyrvavDC+Y9UG6G/pUVxfRNM2VTJwtLQLvgsJeyf1V+7shMCb68Wj0/TETmfx8dWv9pToGkVT39udE87wQ==

emittery@^0.8.1:
version "0.8.1"
Expand Down

0 comments on commit db83ffb

Please sign in to comment.