@swizzyweb/express-unuse 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/unuse.d.ts +5 -4
- package/dist/unuse.d.ts.map +1 -1
- package/dist/unuse.js +8 -2
- package/dist/unuse.js.map +1 -1
- package/package.json +1 -1
- package/src/unuse.ts +13 -7
- package/test/unuse-controller.test.ts +34 -0
package/dist/unuse.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { type Application,
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { type Application, type Request, type Response, type NextFunction } from "express";
|
|
2
|
+
import * as express from "express";
|
|
3
|
+
export declare function unuseRouter(app: Application, router: express.Router): number | undefined;
|
|
4
|
+
export declare function unuseController(router: express.Router, controller: {
|
|
4
5
|
path: string;
|
|
5
6
|
method: string;
|
|
6
7
|
}): {
|
|
7
8
|
pathIndex: number;
|
|
8
9
|
methodIndex: number;
|
|
9
10
|
} | undefined;
|
|
10
|
-
export declare function unuseMiddleware(appOrRouter: Application | Router, middleware: (req: Request, res: Response, next: NextFunction) => void): number | undefined;
|
|
11
|
+
export declare function unuseMiddleware(appOrRouter: Application | express.Router, middleware: (req: Request, res: Response, next: NextFunction) => void): number | undefined;
|
|
11
12
|
//# sourceMappingURL=unuse.d.ts.map
|
package/dist/unuse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unuse.d.ts","sourceRoot":"","sources":["../src/unuse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unuse.d.ts","sourceRoot":"","sources":["../src/unuse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,YAAY,EAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,sBAWnE;AACD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,UAAU,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;cA2B7C;AAED,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EACzC,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,sBA4BtE"}
|
package/dist/unuse.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// @deno-types="npm:@types/express@5"
|
|
2
|
+
import {} from "express";
|
|
3
|
+
// @deno-types="npm:@types/express@5"
|
|
4
|
+
import * as express from "express";
|
|
2
5
|
export function unuseRouter(app, router) {
|
|
3
6
|
let index = 0;
|
|
4
7
|
for (const stack of app.router?.stack) {
|
|
@@ -15,7 +18,10 @@ export function unuseController(router, controller) {
|
|
|
15
18
|
const routerStack = router.stack;
|
|
16
19
|
for (const outterStack of routerStack) {
|
|
17
20
|
const { route } = outterStack;
|
|
18
|
-
const { path, stack: controllerStack } = route;
|
|
21
|
+
const { path, stack: controllerStack } = route ?? { path: undefined };
|
|
22
|
+
if (!path || !controllerStack) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
19
25
|
for (const innerStack of controllerStack) {
|
|
20
26
|
let index = 0;
|
|
21
27
|
const { method } = innerStack;
|
package/dist/unuse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unuse.js","sourceRoot":"","sources":["../src/unuse.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"unuse.js","sourceRoot":"","sources":["../src/unuse.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAKN,MAAM,SAA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
package/package.json
CHANGED
package/src/unuse.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
// @deno-types="npm:@types/express@5"
|
|
1
2
|
import {
|
|
2
3
|
type Application,
|
|
3
|
-
Router,
|
|
4
4
|
type Request,
|
|
5
5
|
type Response,
|
|
6
6
|
type NextFunction,
|
|
7
7
|
} from "express";
|
|
8
|
+
// @deno-types="npm:@types/express@5"
|
|
9
|
+
import * as express from "express";
|
|
8
10
|
|
|
9
|
-
export function unuseRouter(app: Application, router: Router) {
|
|
11
|
+
export function unuseRouter(app: Application, router: express.Router) {
|
|
10
12
|
let index = 0;
|
|
11
13
|
|
|
12
14
|
for (const stack of app.router?.stack) {
|
|
@@ -19,7 +21,7 @@ export function unuseRouter(app: Application, router: Router) {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
export function unuseController(
|
|
22
|
-
router: Router,
|
|
24
|
+
router: express.Router,
|
|
23
25
|
controller: { path: string; method: string },
|
|
24
26
|
) {
|
|
25
27
|
let outterIndex = 0;
|
|
@@ -27,7 +29,11 @@ export function unuseController(
|
|
|
27
29
|
|
|
28
30
|
for (const outterStack of routerStack) {
|
|
29
31
|
const { route } = outterStack;
|
|
30
|
-
const { path, stack: controllerStack } = route
|
|
32
|
+
const { path, stack: controllerStack } = route ?? { path: undefined };
|
|
33
|
+
|
|
34
|
+
if (!path || !controllerStack) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
for (const innerStack of controllerStack) {
|
|
33
39
|
let index = 0;
|
|
@@ -46,7 +52,7 @@ export function unuseController(
|
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export function unuseMiddleware(
|
|
49
|
-
appOrRouter: Application | Router,
|
|
55
|
+
appOrRouter: Application | express.Router,
|
|
50
56
|
middleware: (req: Request, res: Response, next: NextFunction) => void,
|
|
51
57
|
) {
|
|
52
58
|
if ((appOrRouter as Application).router) {
|
|
@@ -61,8 +67,8 @@ export function unuseMiddleware(
|
|
|
61
67
|
}
|
|
62
68
|
index++;
|
|
63
69
|
}
|
|
64
|
-
} else if ((appOrRouter as Router).stack) {
|
|
65
|
-
const router = appOrRouter as Router;
|
|
70
|
+
} else if ((appOrRouter as express.Router).stack) {
|
|
71
|
+
const router = appOrRouter as express.Router;
|
|
66
72
|
let index = 0;
|
|
67
73
|
for (const stack of router.stack) {
|
|
68
74
|
const { handle } = stack;
|
|
@@ -37,7 +37,41 @@ test("Test unuse 4 controllers on 1 router", () => {
|
|
|
37
37
|
});
|
|
38
38
|
expect(router.stack.length).toBe(0);
|
|
39
39
|
});
|
|
40
|
+
test("Test unuse 4 controllers on 1 router", () => {
|
|
41
|
+
const router = Router();
|
|
42
|
+
const constoller = function handle(req: Request, res: Response) {
|
|
43
|
+
console.log("get");
|
|
44
|
+
};
|
|
45
|
+
router.get("/getController", constoller);
|
|
46
|
+
|
|
47
|
+
router.post("postController/", (req: Request, res: Response) => {
|
|
48
|
+
console.log("post");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
router.put("/putController/", (req: Request, res: Response) => {
|
|
52
|
+
console.log("put");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
router.patch("patchController", (req: Request, res: Response) => {
|
|
56
|
+
console.log("patch");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(router.stack.length).toBe(4);
|
|
60
|
+
unuseController(router, { path: "/getController", method: "get" });
|
|
61
|
+
expect(router.stack.length).toBe(3);
|
|
62
|
+
|
|
63
|
+
unuseController(router, { path: "postController/", method: "post" });
|
|
64
|
+
expect(router.stack.length).toBe(2);
|
|
65
|
+
|
|
66
|
+
unuseController(router, { path: "/putController/", method: "put" });
|
|
67
|
+
expect(router.stack.length).toBe(1);
|
|
40
68
|
|
|
69
|
+
unuseController(router, {
|
|
70
|
+
path: "patchController",
|
|
71
|
+
method: "patch",
|
|
72
|
+
});
|
|
73
|
+
expect(router.stack.length).toBe(0);
|
|
74
|
+
});
|
|
41
75
|
/*
|
|
42
76
|
test("Test unuse 4 controllers on 1 router", () => {
|
|
43
77
|
const router = Router();
|