Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliav2 committed Apr 27, 2024
2 parents 2dc34fe + cc8c125 commit c5f19b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/express-typed/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-typed",
"version": "0.0.3",
"version": "0.1.0",
"description": "",
"type": "module",
"main": "dist/express-typed.js",
Expand Down
13 changes: 6 additions & 7 deletions packages/express-typed/src/express-typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type IHandlerResponse<Res extends any[] = []> = {
jsonp<const T>(arg: T): IHandlerResponse<[...Res, { jsonp: T }]>;
send<const T>(arg: T): IHandlerResponse<[...Res, { send: T }]>;
} & Response;

export type SendMethod = "send" | "json" | "jsonp";

export type IHandlerRequest<Req extends any[] = []> = {} & Request;
Expand All @@ -32,7 +31,7 @@ export class TypedRouter<
[key in HandlerMethods]?: (req: IHandlerRequest, res: IHandlerResponse, next: NextFunction) => void;
}
| TypedRouter<any>;
}
},
> {
router: express.Router;
routes: R;
Expand All @@ -59,7 +58,7 @@ export type FlatNestedRouters<T> = {
? (
x: T[K] extends TypedRouter<infer N>
? FlatNestedRouters<{ [K2 in keyof N extends string ? `${keyof N}` : "" as `${K}${K2}`]: N[K2] }>
: Pick<T, K>
: Pick<T, K>,
) => void
: never;
} extends { [k: string]: (x: infer I) => void }
Expand All @@ -71,7 +70,7 @@ export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) ex
export type GetRouteResponseInfoHelper<
Router extends TypedRouter<any>["routes"],
Path extends keyof FlatNestedRouters<Router>,
Method extends keyof FlatNestedRouters<Router>[Path]
Method extends keyof FlatNestedRouters<Router>[Path],
> = UnionToIntersection<
(
ReturnType<
Expand All @@ -88,13 +87,13 @@ export type GetRouteResponseInfo<
Router extends TypedRouter<any>["routes"],
Path extends keyof FlatNestedRouters<Router>,
Method extends keyof FlatNestedRouters<Router>[Path],
Info extends keyof GetRouteResponseInfoHelper<Router, Path, Method> | "body" = "body"
Info extends keyof GetRouteResponseInfoHelper<Router, Path, Method> | "body" = "body",
// Info extends "body" | undefined = undefined
> = Info extends "body"
? GetRouteResponseInfoHelper<Router, Path, Method>[Extract<keyof GetRouteResponseInfoHelper<Router, Path, Method>, SendMethod>]
: Info extends keyof GetRouteResponseInfoHelper<Router, Path, Method>
? GetRouteResponseInfoHelper<Router, Path, Method>[Info]
: GetRouteResponseInfoHelper<Router, Path, Method>;
? GetRouteResponseInfoHelper<Router, Path, Method>[Info]
: GetRouteResponseInfoHelper<Router, Path, Method>;

export type ParseRoutes<T extends TypedRouter<any>> = FlatNestedRouters<T["routes"]>;

Expand Down

0 comments on commit c5f19b8

Please sign in to comment.