Skip to content

Conversation

i5shuyi
Copy link

@i5shuyi i5shuyi commented Apr 16, 2022

Description

  1. Pass the metadata object
  2. Return a specific typed Promise instead of Promise
  3. Support send binary data to binding
  4. Issue reference

    Optimize the binding call without affecting the API, and there are no associated issues

    Checklist

    Please make sure you've completed the relevant tasks for this PR, out of the following list:

    • Code compiles correctly
    • Created/updated tests
    • Extended the documentation

@i5shuyi i5shuyi requested review from a team as code owners April 16, 2022 03:19
Amast added 3 commits April 17, 2022 00:18
Signed-off-by: Amast <snow@amast.dev>
Signed-off-by: Amast <snow@amast.dev>
…ead of Promise<object>

Signed-off-by: Amast <snow@amast.dev>
@XavierGeerinck
Copy link
Contributor

Loving some of the ideas in this PR that will benefit a lot of the JS SDK going forward! Thanks a lot for this!

Some initial remarks:

  • Could you split up the PR in multiple ones? Since it fixes more than just the "Return specific Promise type" (I see metadata adding as well)
  • Could you add a test?

We will review this as a team later today and come back to you.

constructor(bindingName: string, operation: string) {
this.bindingName = bindingName;
this.operation = operation;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra line

operation: string,
data: any,
metadata: Record<string, string>,
): Promise<BindingResponse> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be this?

Suggested change
): Promise<BindingResponse> {
): Promise<InvokeBindingResponse> {

import { types } from 'util';
import { InvokeBindingResponse } from '../../../types/binding/InvokeBindingResponse.type';

export class BindingRequest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export BindingRequest and BindingResponse?

Can we use parameter properties instead of members? Class definition will be cleaner.

Copy link
Member

@shubham1172 shubham1172 Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, do we need these classes at all? send function can directly call makeRequest (instead of going via invoke), and BindingRequest or BindingResponse won't be needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this is that we do not want to make destructive changes to the send function. The long-term plan is to add invoke(req: BindingRequest): Promise<BindingResponse> and invoke(name: string, operation: string, data: any, metadata: Record<string, string>): Promise<BindingResponse>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about changing the API name from client.binding.send to client.binding.invoke? https://docs.dapr.io/reference/api/bindings_api/#invoking-output-bindings we technically need only one method in our IClientBinding, which we have as send today.

Do we really need the BindingRequest class? Isn't it simpler to use the params name, operation, data, and metadata directly? It makes sense from a consumer point of view and eliminates the need to pack and unpack the data. The class BindingRequest itself provides no value (it's more like a struct).

Similar argument for BindingResponse. Since we already have InvokeBindingResponse, do we need to introduce yet another class here?

/cc @XavierGeerinck

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, deprecating send in favor of invoke is not something we want to do at this moment.

Regarding classes, I personally also would refrain from adding extra abstraction classes. The gRPC Classes build from dapr/dapr already provide a DTO, this would just add another DTO on top.

I can however see where this is coming from as the Java SDK does it through this way.

@i5shuyi
Copy link
Author

i5shuyi commented Apr 19, 2022

I tried to add tests for metadata, but I didn't find a way to test metadata. I need help

@shubham1172
Copy link
Member

@xAmast You can try http bindings to test metadata.

@XavierGeerinck
Copy link
Contributor

I tried to add tests for metadata, but I didn't find a way to test metadata. I need help

This one you can leave out for now seeing we are working on structuring this part better

@shubham1172
Copy link
Member

ping @xAmast

@XavierGeerinck
Copy link
Contributor

We decided to split up this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants