Skip to content

Commit 1067fe9

Browse files
authored
Comment asAsync (#117)
* Comment asAsync * Comment asAsync
1 parent c2ec80e commit 1067fe9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: src/express/index.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,17 @@ export const asAsync = <Router extends IRouter | RouterT<any, any>>(
160160
): Router => {
161161
return new Proxy(router, {
162162
get(target, prop, receiver) {
163+
// o is the original method of the provided router
163164
const o = Reflect.get(target, prop, receiver);
164-
if (typeof prop !== "string") {
165-
return o;
166-
}
167-
if (![...Method, "all"].includes(prop)) {
168-
return o;
169-
}
170-
if (typeof o !== "function") {
165+
if (
166+
// prop may be string or symbol. We only want to wrap string methods.
167+
typeof prop !== "string" ||
168+
// We only wrap methods that are represents HTTP methods.
169+
![...Method, "all"].includes(prop) ||
170+
// If `prop` is one of the HTTP methods, `o` should be a function, but we check just to be sure.
171+
typeof o !== "function"
172+
) {
173+
// If it's not a method we want to wrap, just return the original method.
171174
return o;
172175
}
173176
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -178,6 +181,7 @@ export const asAsync = <Router extends IRouter | RouterT<any, any>>(
178181
}
179182
const handlers = args
180183
.slice(1)
184+
// wrap all middleware and handlers
181185
.map((h) => (typeof h === "function" ? wrap(h) : h));
182186
// eslint-disable-next-line @typescript-eslint/no-explicit-any
183187
return o.apply(target, [args[0], ...handlers] as any);

0 commit comments

Comments
 (0)