Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export type GenericMeta =
{
// ???
};

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?

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"

{
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.

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.

}
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


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.

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.

onclose: (code: number, reason: string) => void,
onerror: (error: string) => void,
Comment on lines +19 to +22
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.

) => (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


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"

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[]>.

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.


meta: () => GenericMeta
}
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ThinClient",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}