Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ComLock
Copy link
Member

@ComLock ComLock commented Oct 11, 2024

No description provided.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.55%. Comparing base (cda1144) to head (7b1f13b).
Report is 10 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Show resolved Hide resolved
Comment on lines 244 to 250
'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
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/test/RequestImplementation.ts Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
@alansemenov alansemenov changed the title 9742 ts add request and response to lib portal Add type definitions for Request and Response Oct 16, 2024
Copy link
Member

@edloidas edloidas left a 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.

Comment on lines 244 to 250
'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
Copy link
Member

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.

modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/test/Controller.test-d.ts Outdated Show resolved Hide resolved
modules/lib/test/ErrorController.test-d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/test/IdProviderController.test-d.ts Outdated Show resolved Hide resolved
modules/lib/test/Response.test-d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@tajakobsen tajakobsen left a 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?

modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/core/index.d.ts Outdated Show resolved Hide resolved
modules/lib/test/Controller.test-d.ts Outdated Show resolved Hide resolved
modules/lib/test/tsconfig.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@tajakobsen tajakobsen left a 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> {
Copy link
Collaborator

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?

Copy link
Member Author

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.

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.

Add type definitions for Request and Response
5 participants