Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate clients into separate files #55

Closed
4 tasks done
timostamm opened this issue Dec 20, 2020 · 0 comments
Closed
4 tasks done

Generate clients into separate files #55

timostamm opened this issue Dec 20, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@timostamm
Copy link
Owner

timostamm commented Dec 20, 2020

At the moment, service clients are generated into a single file.

For example, the following .proto:

syntax = "proto3";
package spec;
import "protobuf-ts.proto";
import "google/protobuf/wrappers.proto";

service AllStyleService {
    option (ts.client) = CALL;
    option (ts.client) = RX;
    option (ts.client) = PROMISE;

    rpc Unary (google.protobuf.StringValue) returns (google.protobuf.Int32Value);
    rpc ServerStream (google.protobuf.StringValue) returns (stream google.protobuf.Int32Value);
    rpc ClientStream (stream google.protobuf.StringValue) returns (google.protobuf.Int32Value);
    rpc Bidi (stream google.protobuf.StringValue) returns (stream google.protobuf.Int32Value);
}

Generates a typescript file service-style-all.ts:

export const AllStyleService = new ServiceType("spec.AllStyleService", [
    { name: "Unary", options: {}, I: StringValue, O: Int32Value },
    { name: "ServerStream", serverStreaming: true, options: {}, I: StringValue, O: Int32Value },
    { name: "ClientStream", clientStreaming: true, options: {}, I: StringValue, O: Int32Value },
    { name: "Bidi", serverStreaming: true, clientStreaming: true, options: {}, I: StringValue, O: Int32Value }
]);

export interface IAllStyleServiceCallClient { /* ... */ }
export class AllStyleServiceCallClient implements IAllStyleServiceCallClient, ServiceInfo { /* ... */ }

export interface IAllStyleServiceRxClient { /* ... */ }
export class AllStyleServiceRxClient implements IAllStyleServiceRxClient, ServiceInfo { /* ... */ }

export interface IAllStyleServicePromiseClient { /* ... */ }
export class AllStyleServicePromiseClient implements IAllStyleServicePromiseClient, ServiceInfo { /* ... */ }

This has the following disadvantages:

  • client names have to be suffixed to prevent name clashes
  • removing / adding a second client style will change client names, breaking imports in other code
  • if we start generating servers (gRPC server support for @grpc/grpc-js #52), the file will have even more symbols

Possible solution:

  • generate individual files for each client style
  • CALL => service-style-all.client.ts
  • RX => service-style-all.rx-client.ts
  • PROMISE => service-style-all.promise-client.ts
  • keep same symbol name for the client: AllStyleServiceClient

TODO:

  • generate individual files for each client style
  • fix collision of ServerStyle.NONE and ClientStyle.NONE
  • prevent file name clashes
  • refactor for better readability
@timostamm timostamm added the enhancement New feature or request label Dec 20, 2020
timostamm added a commit that referenced this issue Dec 21, 2020
- generate into separate files
- fix unit tests
- rename enum values of protobuf-ts.proto / ClientStyle + ServerStyle to prevent collision
- move ClientStyle + ServerStyle from runtime-rpc into plugin, don't export
timostamm added a commit that referenced this issue Dec 21, 2020
timostamm added a commit that referenced this issue Dec 21, 2020
timostamm added a commit that referenced this issue Dec 22, 2020
timostamm added a commit that referenced this issue Dec 22, 2020
timostamm added a commit that referenced this issue Dec 22, 2020
timostamm added a commit that referenced this issue Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant