smnbbrv / ngx-grpc

Angular gRPC framework
MIT License
238 stars 34 forks source link

feat(protoc-gen-ng): add support for custom WKT #67

Closed Grubana closed 2 years ago

Grubana commented 3 years ago

When using a service like https://buf.build there is no possibility to add custom well known types that are referenced from an import.

Adds the possibility to configure a custom WKT in the protoc-gen-ng config file

smnbbrv commented 2 years ago

Hi @Grubana

first of all, I'm very sorry for a so later reply, which is normally not typical.

Thank you for the BUF tool, I haven't seen it before and thanks for adopting the project styles in your PRs.

From what I see from the changes the custom well-known types are coming from the config file?

  public customWellKnownTypes: {[key: string]: string};

So, the types will be listed inside this map under the type name as key and the type definition as the value? I'm sorry if the question seem dumb, just want to understand how the custom types get into the generator.

Thanks!

Grubana commented 2 years ago

Yeah, I'm currently using a shared proto commons library in my projects. I package this commons library for use in all projects I have and therefore I need some possibility to link the commons library into the transpiled typescript code.

The map defines the include to use for a given proto package name. For example:

module.exports = {
  customWellKnownTypes: {
    "company.internal.commons": "@company-internal/grpc-commons"
  }
}

Currently it's a bit restricting as you have to carefully bundle specific proto packages into your libraries and then ensure that the config in the other projects is correct. But basically the solution works pretty well for my usecases and I think it could help others too.

smnbbrv commented 2 years ago

I generally like the idea, but this should be well-documented in the README.md, otherwise it would be hard for others to adopt it :)

Could you, please, add some section describing the use case, maybe also a short example? I could do it as well, but as long as I'm still out of scope here, would be better if one who fully understands it does it

smnbbrv commented 2 years ago

Thank you very much! I'll merge it and once I get out the dependency maintenance hell, it will be released

Grubana commented 2 years ago

Thank you