diff --git a/internal/generator/runer_generate_service.go b/internal/generator/runer_generate_service.go index 31605a7..1a0a4ef 100644 --- a/internal/generator/runer_generate_service.go +++ b/internal/generator/runer_generate_service.go @@ -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() @@ -50,7 +55,12 @@ func (r *Runner) generateTypescriptServiceDefinition(generatedFileStream *protog r.P(generatedFileStream, "export const "+strcase.ToLowerCamel(serviceSpec.GetName())+"ServiceDefinition: grpc.ServiceDefinition = {") 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) } @@ -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),") } @@ -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() diff --git a/internal/generator/runner_generate_client.go b/internal/generator/runner_generate_client.go index 1caa8ff..f322275 100644 --- a/internal/generator/runner_generate_client.go +++ b/internal/generator/runner_generate_client.go @@ -1,6 +1,8 @@ package generator import ( + "sort" + "github.com/iancoleman/strcase" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/types/descriptorpb" @@ -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) } @@ -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) } diff --git a/tests/__tests__/generated/Test.ts b/tests/__tests__/generated/Test.ts index 6dec17d..bfde20e 100644 --- a/tests/__tests__/generated/Test.ts +++ b/tests/__tests__/generated/Test.ts @@ -514,15 +514,15 @@ export namespace Foo { export interface IUsersServiceImplementation { Find: grpc.handleUnaryCall - 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 > @@ -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, @@ -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, @@ -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, @@ -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 diff --git a/tests/package.json b/tests/package.json index 01bd9cb..7ba7edc 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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": { diff --git a/tests/yarn.lock b/tests/yarn.lock index 2154282..8acaff6 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -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" @@ -1680,9 +1680,9 @@ ee-first@1.1.1: 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"