-
Notifications
You must be signed in to change notification settings - Fork 349
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
feat: Add google.api.http support #1075
base: main
Are you sure you want to change the base?
Conversation
Hi @jas-chen ! This looks amazing! Just scanning the PR, everything looks great, but I won't have time to review more thoroughly until this weekend, if that's okay...I'll take a closer look, and maybe leave a few minor comments/suggestions then. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jas-chen ; thanks again for the PR, I had a chance to leave some feedback.
I'd really like to avoid vendoring the other code generator, and re-deserializing the request--lmk if you have ideas for how to avoid that by getting ts-proto-descriptors
to have the info you need/want.
Also, per the comment, would love to have this PR (or a follow up) come with mapped types / runtime support to "just make a client" for users to use out-of-the-box.
Thanks!
HTTP.markdown
Outdated
## Client implementation example | ||
|
||
```typescript | ||
// This is just an example, do not use it directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jas-chen , I think this is a great so far--I'm wondering if we could further and remove the need for this createApi
method...
I.e. if a user has ~10 services with ~10 methods each, they''ll have to call createApi
against each of them--granted, they could write a method to do that in a loop...
Like our current non-google impl looks like:
export interface MyService {
MyMethod(request: RequestType): Promise<ResponseType>;
}
export const MyServiceServiceName = "MyService";
export class MyServiceClientImpl implements MyService {
private readonly rpc: Rpc;
private readonly service: string;
constructor(rpc: Rpc, opts?: { service?: string }) {
this.service = opts?.service || MyServiceServiceName;
this.rpc = rpc;
this.MyMethod = this.MyMethod.bind(this);
}
MyMethod(request: RequestType): Promise<ResponseType> {
const data = RequestType.encode(request).finish();
const promise = this.rpc.request(this.service, "MyMethod", data);
return promise.then((data) => ResponseType.decode(_m0.Reader.create(data)));
}
}
And it seems like it'd be nice to provide a similar sort of API to users...
I suppose with the export const Messaging
, the users could provide their own mapped types & helper methods to achieve this same output, i.e. something like:
// creates the `MessagingService.MyMethod` / `MessagingService.updateMessage` interface
type MessagingService = ClientService<typeof Messaging>;
const client: MessagingService = createClient(Messaging);
await client.getMessage(...);
I'm thinking it'd be great for ts-proto to eventually provide those ClientService
and createClient
implementations (i.e. that could automatically parse & replace the {message_id}
based on the rules in their docs).
Granted, sometimes I've just codegen-d out the export interface MyService { ... }
and export class MyServiceImpl
, which was a very old-school approach code generation, but it's definitely doable to use TS mapped types & runtime libraries to achieve the same effect.
Wdyt about the goal of shipping a ClientService
& createClient
method that took in the Messaging
config? Maybe it could be like a ts-proto-google-http
runtime library, which didn't bloat the codegen output. Would you be interesting in contributing that as well as this config output?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the client implementation example code, the createApi
takes a service definition now.
Hi @stephenh, Thank you for reviewing my PR. I want to confirm this point first:
I tried using To be more specific, I want to make // Add to the top of the file
const annotations = require('../api/annotations');
const http = require('../api/http');
// Add one more case in MethodOptions.decode
case annotations.http.number:
if (tag !== annotations.http.tag) {
break;
}
message.http = http.HttpRule.decode(reader, reader.uint32());
continue; Do you have any suggestions? |
Hi @jas-chen ! I think we can do this like this: Unfortunately it looks like we might have a bug in our extensions support, because I'm getting this error:
On that branch...maybe we're just missing an undefined check in the generated code? Do you have time to look into fixing ^? It probably involves updating the extension code in If not, I can try and take a look soon. Thanks! |
Hi @stephenh, After much consideration of the API design, I decided to extend the current We can add a client implementation later if needed. Regarding the Please help review it again and let me know what you think; thank you! |
After testing this API with a bunch of .proto files I have, I realized that the generated code from grpc and I pushed a commit 2715391 to introduce the |
This is functionality that I need badly enough that I'm using @jas-chen 's fork :p Happy to chip in and fix bugs and such if that would be at all helpful towards getting this merged in. |
@stephenh, are you reviewing this PR? Is there anything I need to change? |
@jas-chen hello! Sorry, I've just been really busy with work lately; I definitely want to review & accept this PR--I should be able to review/accept it this weekend when I have some time. Thanks again! |
Hi @stephenh, |
@stephenh Hi 👋🏻 When you have the time can you please help check whether the direction of adding Can I also ask when does Also going forward, maybe it's better for me to open a new PR from my own fork referencing this PR? 🤔 |
It seems that many of us need this PR :D
on the directory
I still get a simple.ts file without any google.http.api
|
Hey @williamsk91 , @angelorc , sorry, this is a larger PR in an area that I'm not very familiar (I don't personally use But, as long as you're patient with me reviewing it & landing it, yep, would definitely love to have this feature/PR ship in ts-proto. Kinda looks like the PR needs rebased/spruced up, which is undertandable given it's probably just stale; lmk if you need anything from me, but otherwise thanks for tackling this! |
Fixes #948.
This PR adds support for generating
google.api.http
-based metadata for developers to implement an HTTP client based on it.To retrieve the information,
google-protobuf
and related vendor codes are included. They will be loaded on demand to reduce the performance hit.It also introduces a top-level CLI option
http
just like thenestJs
option.