-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
New decorator @TypedHeaders()
#473
Labels
enhancement
New feature or request
Comments
samchon
added a commit
that referenced
this issue
Jul 31, 2023
Close #473 - new decorator `@TypedHeaders()`
samchon
added a commit
that referenced
this issue
Aug 1, 2023
From now on, `@nestia/fetcher` and `@nestia/sdk` will support `@TypedHeaders()`. In the `@nestia/fetcher` case, it will enhance `IConnection.headers` type to accept atomic and atomic array types. The other `@nestia/sdk` case, it will also support the `@TypedHeaders()` in SDK and Mockup simulator level. ```typescript export interface IConnection<Headers extends object = {}> { headers?: Record<string, IConnection.HeaderValue> & IConnection.Headerify<Headers>; } export namespace IConnection { export type HeaderValue = | string | boolean | number | bigint | string | Array<boolean> | Array<number> | Array<bigint> | Array<number> | Array<string>; export type Headerify<T extends object> = { [P in keyof T]?: T[P] extends HeaderValue | undefined ? T[P] | undefined : never; }; } ```
samchon
added a commit
that referenced
this issue
Aug 1, 2023
Enhance #473 - support `@TypedHeaders()` in `fetcher` and `sdk`
samchon
added a commit
that referenced
this issue
Aug 2, 2023
Enhanced `IConnection.Headerify` type of `@nestia/fetcher` to be much stronger. It will validate special cases whether each property allows Array type or not through their key name. For example, "set-cookie" type must be Array type, and `Authorization` must be atomic type. ```typescript export namespace IConnection { export type Headerify<T extends object> = { [P in keyof T]?: T[P] extends HeaderValue | undefined ? P extends string ? Lowercase<P> extends "set-cookie" ? T[P] extends Array<HeaderValue> ? T[P] | undefined : never : Lowercase<P> extends | "age" | "authorization" | "content-length" | "content-type" | "etag" | "expires" | "from" | "host" | "if-modified-since" | "if-unmodified-since" | "last-modified" | "location" | "max-forwards" | "proxy-authorization" | "referer" | "retry-after" | "server" | "user-agent" ? T[P] extends Array<HeaderValue> ? never : T[P] | undefined : T[P] | undefined : never : never; } ```
samchon
added a commit
that referenced
this issue
Aug 2, 2023
Enhance #473 - `IConnection.Headerify` to be much stronger
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implement a new decorator
@TypeHeaders()
, which can take variables from header.Also,
TypedHeaders()
can have only one object type, and each properties must be atomic or array of atomic type like below.Some may have doubts about the header parameters. Looking at API of headers property of
express
orfastify
, which can parse header variables, only string typed property values are allowed. However, above interfaceIHeaders
has numeber and boolean types. How it can be possible? Isn't it something wrong?The answer is such number and boolean typed properties would be automatically casted, by analyzing the DTO structure in the compilation level, as other decorator functions like
@TypedHeaders()
could.The text was updated successfully, but these errors were encountered: