-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add Optional Metadata Parameter to Service Interface #11
Comments
Thank you for the idea, I like it! |
I agree, the It seems to just be a class with a single "private"
https://grpc.io/grpc/node/grpc.Metadata.html for the full interface. |
There is some work being done on getting an a typescript definition file for gRPC, see #11020. Luckily for us that contains a definition file, I copied the metadata part below. With that definition we can type the metadata parameter:
Definition copied from index.d.ts export class Metadata {
/**
* Class for storing metadata. Keys are normalized to lowercase ASCII.
*/
constructor();
/**
* Sets the given value for the given key, replacing any other values associated
* with that key. Normalizes the key.
* @param key The key to set
* @param value The value to set. Must be a buffer if and only if the normalized key ends with '-bin'
*/
set(key: string, value: string | Buffer): void;
/**
* Adds the given value for the given key. Normalizes the key.
* @param key The key to add to.
* @param value The value to add. Must be a buffer if and only if the normalized key ends with '-bin'
*/
add(key: string, value: string | Buffer): void;
/**
* Remove the given key and any associated values. Normalizes the key.
* @param key The key to remove
*/
remove(key: string): void;
/**
* Gets a list of all values associated with the key. Normalizes the key.
* @param key The key to get
* @return The values associated with that key
*/
get(key: string): (string | Buffer)[];
/**
* Get a map of each key to a single associated value. This reflects the most
* common way that people will want to see metadata.
* @return A key/value mapping of the metadata
*/
getMap(): { [index: string]: string | Buffer };
/**
* Clone the metadata object.
* @return The new cloned object
*/
clone(): Metadata;
} |
Perfect, thank you! |
My comment above is already obsolete. New PR here. |
@kondi the typings file above has been merged in. Looks like it will be included in the next gRPC release (1.7). |
Hey, when will have the metadata params? Here is a very ugly hack for the client side:
Now you can do:
The reason why it works is that rxjs-grpc just passes the arguments downstream to grpc. |
@kondi the TypeScript typings for gRPC are now included in the latest release (1.7). Let me know if you'd like me to try to put together a PR. |
Released in v0.2.0. |
Currently, the generated service interface methods accept a single parameter as an argument.
Example:
getPage(request: logbook.getPageRequest): Observable<logbook.Page>;
gRPC allows you to pass optional parameters to service calls in the form of metadata. This information is passed through correctly at the moment due to
...args
spread, however the type signature causes the compiler to complain. I could just add things such as the JWT token to the request proto definition itself, but metadata feels like the appropriate use case.Do you think it would be appropriate for the interface service definitions to include metadata as an optional parameter?
getPage(request: logbook.getPageRequest, metadata?: any): Observable<logbook.Page>;
I can try to get a PR together if you'd like.
The text was updated successfully, but these errors were encountered: