Draft client interface#10
Conversation
| } | ||
|
|
||
| export interface ClientStartOperationResultSync<T> { | ||
| isSync(): this is ClientStartOperationResultSync<T>; |
There was a problem hiding this comment.
isSync: Why a method rather than a readonly field? And how would you generally expect this to be implemented by the framework or library providing the client?
There was a problem hiding this comment.
E 77 ▎ isSync: this is ClientStartOperationResultSync<T>; ■ A type predicate is only allowed in return type position for functions and methods.
There was a problem hiding this comment.
Yeah, but it could have been just a bool property, hardcoded to either true or false in the variants. That would make it a type determinant by itself, so no need for a type predicate.
I don't really mind, but the problem with current approach is that tsc can't assert that function creating a ClientStartOperationResult(Sync|Async) is self-coherent, whereas a boolean property would implicitly assert that.
There was a problem hiding this comment.
Ah, good point, I can just change to isSync: false and isSync: true.
| * Inbound links that contain arbitrary information, e.g. provided by the caller. | ||
| * Used as metadata for the call. | ||
| */ | ||
| readonly inboundLinks?: Link[]; |
There was a problem hiding this comment.
Here, it's called inboundLinks, but in Result, it is only links.
There was a problem hiding this comment.
Good point, we should be consistent. Thanks.
|
|
||
| export interface ResultWithDetails<T> { | ||
| result: T; | ||
| links: Link[]; |
There was a problem hiding this comment.
Given the current design, I think it would make more sense for this property to be optional.
I mean, if having Client only as abstraction, that means implementers will be responsible for producing objects of this interface. And therefore, adding new required properties to this interface at a later time would be breaking. So we'll instead make new properties be optional, and links will therefore adhere to a different semantic than other properties added later.
There was a problem hiding this comment.
Making this optional would put the burden of null checks on the consumer and I'd rather avoid that.
There was a problem hiding this comment.
Making this optional would put the burden of null checks on the consumer and I'd rather avoid that.
I know, and so would I. Yet, this is what we'll have to do for all other properties added going forward if we don't want to break existing Client implementations in the future.
That is, unless we make the Nexus RPC library itself ensure normalization of the return value.
There was a problem hiding this comment.
Agree, but at least for now it's part of the established contract. This concern will come into play if this contract is extended though.
I would consider introducing a transport abstraction and wrapping the transport's results in the client as you suggested.
a7b18f3 to
0b3f9af
Compare
No description provided.