Skip to content

Conversation

velzie
Copy link
Collaborator

@velzie velzie commented Jan 21, 2024

No description provided.

remote: URL,
method: string,
body: BodyInit | null,
headers: BareHeaders,
Copy link

Choose a reason for hiding this comment

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

Why not Headers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the js headers class forbids certain headers and doesn't let you have 2 values per key

Copy link

Choose a reason for hiding this comment

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

reasonable

Choose a reason for hiding this comment

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

Is there any case when the order of the headers (and the case of the header name) actually matters? In that case, you'd want [string, string][] and not a Map<string, string | string[]>.

body: BodyInit | null,
headers: BareHeaders,
signal: AbortSignal | undefined
) => Promise<SmallResponse>;
Copy link

Choose a reason for hiding this comment

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

Why not Response?

Choose a reason for hiding this comment

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

Response has a bunch of methods, but then again, you can construct Responses with ease...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

better to let switcher construct the response, less code duplication. plus we want to return BareHeaders not headers so

Choose a reason for hiding this comment

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

Ah, good point. Also, generally, the switcher shouldn't construct the response either, as the proxy might have its own implementation of Response.

Comment on lines +19 to +22
onopen: () => void,
onmessage: (data: ArrayBuffer | string) => void,
onclose: (code: number, reason: string) => void,
onerror: (error: string) => void,
Copy link

Choose a reason for hiding this comment

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

Just use an event emitter...

Choose a reason for hiding this comment

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

If you mean Node event emitters, then that's a huge dependency for each Bare client, and no one is crazy enough to use EventTarget.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that makes the types much more confusing, and there would only be one listener

Copy link

Choose a reason for hiding this comment

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

Use an EventTarget.

export interface BareTransport {
connect: (
url: URL,
protocols: [string],
Copy link

Choose a reason for hiding this comment

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

This is not how you specify a string array

Choose a reason for hiding this comment

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

See the protocols argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct!

Copy link

Choose a reason for hiding this comment

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

that is valid syntax???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well it is, but it's not what i wanted here

Choose a reason for hiding this comment

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

Yeah, you wanted string[], and I missed that, whoops.


export type SmallResponse =
{
body: ReadableStream | ArrayBuffer | Blob | string,
Copy link

Choose a reason for hiding this comment

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

How do you specify what type to get?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

instanceof? i don't see the need to specify

Copy link

Choose a reason for hiding this comment

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

that's bad practice in this case imo
almost always you should be returning a ReadableStream even if you output a single buffer to it and end it there

Choose a reason for hiding this comment

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

I was about to disagree with @Semisol, but he's actually fully in the right. I was about to point out that ReadableStreams are annoying to construct, but every response should be treated as a stream, as the response body is usually (read: almost always) sent over multiple messages/datagrams/whatever.

{
body: ReadableStream | ArrayBuffer | Blob | string,
headers: BareHeaders,
status: number
Copy link

Choose a reason for hiding this comment

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

where is statusText?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

up to the bare switcher to add

Choose a reason for hiding this comment

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

I'm fairly certain statusText is from the server's response, so it should be added.


export type BareHeaders = Map<string, string | string[]>;

export type SmallResponse =
Copy link

@CountBleck CountBleck Jan 22, 2024

Choose a reason for hiding this comment

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

Is this all that's needed for responses?

url: URL,
protocols: [string],
onopen: () => void,
onmessage: (data: ArrayBuffer | string) => void,

Choose a reason for hiding this comment

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

Suggested change
onmessage: (data: ArrayBuffer | string) => void,
onmessage: (data: Blob | string) => void,

Blobs can be made into ArrayBuffers (and vice versa) with relative ease, but they're also better for large messages. Plus, WSes themselves have an option to use Blobs instead of ArrayBuffers, so this benefit isn't something I'm making up.

Choose a reason for hiding this comment

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

Actually, I've changed my mind. ArrayBuffers might make more sense, as constructing a Blob requires all the parts to be present in memory anyway.

Copy link

@MovByte MovByte left a comment

Choose a reason for hiding this comment

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

Looking good so far!

body: ReadableStream | ArrayBuffer | Blob | string,
headers: BareHeaders,
status: number
}
Copy link

Choose a reason for hiding this comment

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

Personally, I would yoink the prototype interface from lib.dom.d.ts, remove the readonly keywords, and make some properties optional

onerror: (error: string) => void,
) => (data) => void;

// somethingforwebtransportsidk: (???)=>???
Copy link

Choose a reason for hiding this comment

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

I recommend using TODO's for this


// somethingforwebtransportsidk: (???)=>???

request: (
Copy link

Choose a reason for hiding this comment

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

I would prefer this method being named "fetch"


export type BareHeaders = Map<string, string | string[]>;

export type SmallResponse =
Copy link

Choose a reason for hiding this comment

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

I would prefer this type being called "MinimalResponse"

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.

4 participants