The SSE work introduced the breaking API change which I did not notice:
from:
export interface Client {
request(
path: string,
body: string,
headers: Record<string, string>,
options?: RequestOptions,
): Promise<[number, string]>;
}
to:
export interface Client {
request(
path: string,
body: string,
headers: Record<string, string>,
options?: RequestOptions,
): Promise<Response>;
}
Our options to converge are:
- Request => Response. Most flexible but too generic for implementors to implement, and leaky abstraction, eg. lets to hijack access to response headers, which we agreed to do type safe way via codegen. Also, complicates introspection of Requests and Responses very difficult.
export interface Client {
request(
req: Request,
): Promise<Response>;
}
- as before but with possible
ReadableStream<string> on return type. Restricted explicitly set expectations for implementors AND non breaking! Cons: an implementor should explicitly turn to returning the stream for enabling support for notifications, i.e. would not be trapped at compile time. Problem there is no way to know when stream is expected, when complete is expected if a client implementor needs to introspect the response data.
export interface Client {
request(
path: string,
body: string,
headers: Record<string, string>,
options?: RequestOptions,
): Promise<[number, string | ReadableStream<string>]>;
}
- as before but return stream of text, where a simple request (non streaming) would return a stream of one message and then closed stream). Breaking change, but not too much, easier to implement. Easier to hook introspection for the data. Stronger contract, not leaky.
export interface Client {
request(
path: string,
body: string,
headers: Record<string, string>,
options?: RequestOptions,
): Promise<[number, ReadableStream<string>]>;
}
I think I prefer option 3.
The SSE work introduced the breaking API change which I did not notice:
from:
to:
Our options to converge are:
ReadableStream<string>on return type. Restricted explicitly set expectations for implementors AND non breaking! Cons: an implementor should explicitly turn to returning the stream for enabling support for notifications, i.e. would not be trapped at compile time. Problem there is no way to know when stream is expected, when complete is expected if a client implementor needs to introspect the response data.I think I prefer option 3.