@tahminator/sapling 1.4.0 → 1.5.0
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.
|
@@ -36,12 +36,14 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
36
36
|
const fn = controllerInstance[fnName];
|
|
37
37
|
if (typeof fn !== "function")
|
|
38
38
|
continue;
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// When path is a RegExp, use it directly without prefix
|
|
40
|
+
// When path is a string, prepend the prefix
|
|
41
|
+
const fp = path instanceof RegExp ? path : prefix + path;
|
|
42
|
+
const routeKey = method + " " + (path instanceof RegExp ? path.source : fp);
|
|
41
43
|
// Only check for duplicates on non-middleware routes
|
|
42
44
|
// Middleware (USE) can have duplicate paths, and different HTTP methods can share paths
|
|
43
45
|
if (method !== "USE" && usedRoutes.has(routeKey)) {
|
|
44
|
-
throw new Error(`Duplicate route [${method}] "${fp}" detected in controller "${target.name}"`);
|
|
46
|
+
throw new Error(`Duplicate route [${method}] "${path instanceof RegExp ? path.source : fp}" detected in controller "${target.name}"`);
|
|
45
47
|
}
|
|
46
48
|
if (method !== "USE") {
|
|
47
49
|
usedRoutes.add(routeKey);
|
|
@@ -68,7 +70,7 @@ export function Controller({ prefix = "", deps = [] } = {
|
|
|
68
70
|
if (!response.writableEnded) {
|
|
69
71
|
response
|
|
70
72
|
.status(404)
|
|
71
|
-
.send(Html404ErrorPage(`Cannot ${methodName.toUpperCase()} ${fp}`));
|
|
73
|
+
.send(Html404ErrorPage(`Cannot ${methodName.toUpperCase()} ${path instanceof RegExp ? path.source : fp}`));
|
|
72
74
|
}
|
|
73
75
|
}));
|
|
74
76
|
}
|
|
@@ -5,40 +5,40 @@ import { RouteDefinition, ExpressRouterMethodKey } from "../types";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function _Route({ method, path, }: {
|
|
7
7
|
method: ExpressRouterMethodKey;
|
|
8
|
-
path: string | undefined;
|
|
8
|
+
path: string | RegExp | undefined;
|
|
9
9
|
}): MethodDecorator;
|
|
10
10
|
/**
|
|
11
11
|
* Register GET route on the given path (default "") for the given controller.
|
|
12
12
|
*/
|
|
13
|
-
export declare const GET: (path?: string | undefined) => MethodDecorator;
|
|
13
|
+
export declare const GET: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
14
14
|
/**
|
|
15
15
|
* Register POST route on the given path (default "") for the given controller.
|
|
16
16
|
*/
|
|
17
|
-
export declare const POST: (path?: string | undefined) => MethodDecorator;
|
|
17
|
+
export declare const POST: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
18
18
|
/**
|
|
19
19
|
* Register PUT route on the given path (default "") for the given controller.
|
|
20
20
|
*/
|
|
21
|
-
export declare const PUT: (path?: string | undefined) => MethodDecorator;
|
|
21
|
+
export declare const PUT: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
22
22
|
/**
|
|
23
23
|
* Register DELETE route on the given path (default "") for the given controller.
|
|
24
24
|
*/
|
|
25
|
-
export declare const DELETE: (path?: string | undefined) => MethodDecorator;
|
|
25
|
+
export declare const DELETE: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
26
26
|
/**
|
|
27
27
|
* Register OPTIONS route on the given path (default "") for the given controller.
|
|
28
28
|
*/
|
|
29
|
-
export declare const OPTIONS: (path?: string | undefined) => MethodDecorator;
|
|
29
|
+
export declare const OPTIONS: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
30
30
|
/**
|
|
31
31
|
* Register PATCH route on the given path (default "") for the given controller.
|
|
32
32
|
*/
|
|
33
|
-
export declare const PATCH: (path?: string | undefined) => MethodDecorator;
|
|
33
|
+
export declare const PATCH: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
34
34
|
/**
|
|
35
35
|
* Register HEAD route on the given path (default "") for the given controller.
|
|
36
36
|
*/
|
|
37
|
-
export declare const HEAD: (path?: string | undefined) => MethodDecorator;
|
|
37
|
+
export declare const HEAD: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
38
38
|
/**
|
|
39
39
|
* Register a middleware route on the given path (default "") for the given controller.
|
|
40
40
|
*/
|
|
41
|
-
export declare const Middleware: (path?: string | undefined) => MethodDecorator;
|
|
41
|
+
export declare const Middleware: (path?: string | RegExp | undefined) => MethodDecorator;
|
|
42
42
|
/**
|
|
43
43
|
* Given a class constructor, fetch all the routes attached.
|
|
44
44
|
*/
|
package/dist/src/types.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export type RouteDefinition = {
|
|
|
8
8
|
*/
|
|
9
9
|
method: ExpressRouterMethodKey;
|
|
10
10
|
/**
|
|
11
|
-
* The path to define the route on.
|
|
11
|
+
* The path to define the route on. Can be a string or RegExp.
|
|
12
12
|
*/
|
|
13
|
-
path: string;
|
|
13
|
+
path: string | RegExp;
|
|
14
14
|
/**
|
|
15
15
|
* The name of the function the `@Route` annotation was applied on.
|
|
16
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tahminator/sapling",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A library to help you write cleaner Express.js code",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"/dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@types/express": "^5.0.
|
|
20
|
-
"express": "^5.1
|
|
19
|
+
"@types/express": "^5.0.6",
|
|
20
|
+
"express": "^5.2.1"
|
|
21
21
|
}
|
|
22
22
|
}
|