question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Optional Metadata Parameter to Service Interface

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
MaikelHcommented, Jul 27, 2017

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:

getPage( request: logbook.getPageRequest, metadata ?: Metadata ): Observable<logbook.Page>;

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;
  }
0reactions
kondicommented, Mar 5, 2019

Released in v0.2.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Can't use optional parameters when implementing an ...
In my interface I have declared this. [OperationContract] [WebGet] String GetStuff(String beep, String boop = "too lazy to type"); I ...
Read more >
Metadata - the OpenNMS Documentation
Adding Metadata through the Web UI · Under the admin menu, select Configure OpenNMS. · Select Manage Provisioning Requisitions. · Click the edit...
Read more >
How do I pick a service implementation by context?
Option 1: Redesign Your Interfaces. Option 2: Change the Registrations. Option 3: Use Keyed Services. Option 4: Use Metadata ...
Read more >
Use IMDSv2 - Amazon Elastic Compute Cloud
Use the modify-instance-metadata-options CLI command (or the ModifyInstanceMetadataOptions API) to require the use of IMDSv2 on the existing instances, or ...
Read more >
Configuring dependency providers - Angular
If you specify the service class as the provider token, the default behavior is for the injector to instantiate that class using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found