Skip to content

0.17.0 version breaking Client injector interface #136

@avkonst

Description

@avkonst

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:

  1. 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>;
}
  1. 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>]>;
}
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions