-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type definitions for Request and Response #10724
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #10724 +/- ##
=========================================
Coverage 84.55% 84.55%
+ Complexity 19979 19978 -1
=========================================
Files 2633 2633
Lines 69316 69316
Branches 5596 5596
=========================================
Hits 58612 58612
Misses 8002 8002
Partials 2702 2702 ☔ View full report in Codecov by Sentry. |
modules/lib/core/index.d.ts
Outdated
'sec-ch-ua'?: string | ||
'sec-ch-ua-mobile'?: string | ||
'sec-ch-ua-platform'?: string | ||
'Sec-Fetch-Dest'?: string | ||
'Sec-Fetch-Mode'?: string | ||
'Sec-Fetch-Site'?: string | ||
'Sec-Fetch-User'?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some experimental headers whe really never use. Why are they int default? Why they are different case BTW?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default optional, only for autocomplete. These are the ones in chrome.
Dunno what to use them for on the server-side, so probably can be removed.
Are they in the way though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we need experimental headers in the default list. Most of them are not added automatically, and for some, like Sec-CH-UA-Mobile
, I don’t even see the point in using them in XP.
My suggestion is as follows: drop them. If a developer really needs them, they can always add them at their own risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the experimental ones and added autocompletion to the Sec-Fetch ones.
I also added Priority since both Chrome and Firefox sends it.
There are tons of headers:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Not really sure which ones should be part of DefaultRequestHeaders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, outstanding work. Great job, Christian. Just a few things to improve there.
modules/lib/core/index.d.ts
Outdated
'sec-ch-ua'?: string | ||
'sec-ch-ua-mobile'?: string | ||
'sec-ch-ua-platform'?: string | ||
'Sec-Fetch-Dest'?: string | ||
'Sec-Fetch-Mode'?: string | ||
'Sec-Fetch-Site'?: string | ||
'Sec-Fetch-User'?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we need experimental headers in the default list. Most of them are not added automatically, and for some, like Sec-CH-UA-Mobile
, I don’t even see the point in using them in XP.
My suggestion is as follows: drop them. If a developer really needs them, they can always add them at their own risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! I can see that there has gone in a ton of effort into this!
Is it possible for me to be able to test this in Beta, because I'm interested in seeing if there is a lot of friction when changing from "my" controller types to these.
I would also be interested in seeing how you use these types in your application projects. When you have a beta out, can you try to put them in, so that I can see an example of the intended use from your side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just have a suggestion around the shape of WebSocetEvent
that might be interesting to you.
id: string; | ||
params: Record<string, string | string[]>; | ||
path: string; | ||
user: Omit<User,'type'>; | ||
} | ||
|
||
export type WebSocketEventType = 'open' | 'message' | 'error' | 'close'; | ||
|
||
export interface WebSocketEvent<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my implementation of WebSocketEvent
. It uses a discriminated union based on the type
to ensure the shape of the object.
type AbstractWebSocketEvent<WebSocketData> = {
session: {
id: string;
path: string;
params: { [key: string]: string | undefined };
};
data: WebSocketData;
};
export type OpenWebSocketEvent<WebSocketData = {}> = AbstractWebSocketEvent<WebSocketData> & {
type: "open";
};
export type MessageWebSocketEvent<WebSocketData = {}> = AbstractWebSocketEvent<WebSocketData> & {
type: "message";
message: string;
};
export type CloseWebSocketEvent<WebSocketData = {}> = AbstractWebSocketEvent<WebSocketData> & {
type: "close";
closeReason: number;
};
export type ErrorWebSocketEvent<WebSocketData = {}> = AbstractWebSocketEvent<WebSocketData> & {
type: "error";
error: string;
};
export type WebSocketEvent<WebSocketData = {}> =
| OpenWebSocketEvent<WebSocketData>
| MessageWebSocketEvent<WebSocketData>
| CloseWebSocketEvent<WebSocketData>
| ErrorWebSocketEvent<WebSocketData>;
Just consider if this pattern might be right for you too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first implementation was similar to that, because it was based on the data I was able to generate in real life. I just simplified after looking at the Java class behind it.
No description provided.