@middy/http-router 7.3.1 → 7.3.3
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/index.js +6 -34
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -19,14 +19,17 @@ const optionSchema = {
|
|
|
19
19
|
properties: {
|
|
20
20
|
routes: {
|
|
21
21
|
type: "array",
|
|
22
|
+
uniqueItems: true,
|
|
22
23
|
items: {
|
|
23
24
|
type: "object",
|
|
24
25
|
required: ["method", "path", "handler"],
|
|
25
26
|
properties: {
|
|
26
27
|
method: { type: "string", enum: [...methods, "ANY"] },
|
|
27
28
|
path: {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
allOf: [
|
|
30
|
+
{ type: "string", pattern: "^/" },
|
|
31
|
+
{ type: "string", pattern: "^(/|.*[^/])$" },
|
|
32
|
+
],
|
|
30
33
|
examples: ["/", "/users", "/users/{id}"],
|
|
31
34
|
},
|
|
32
35
|
handler: { instanceof: "Function" },
|
|
@@ -39,39 +42,8 @@ const optionSchema = {
|
|
|
39
42
|
additionalProperties: false,
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
// and rewrite `{name}`/`{name+}` to `{_}`/`{_+}` so two routes that only
|
|
44
|
-
// differ by parameter name collide (they match the same requests).
|
|
45
|
-
// Inner class excludes `{` to keep matches linear (avoids polynomial
|
|
46
|
-
// backtracking on pathological inputs like `{{{{...`).
|
|
47
|
-
const normalizeRoutePath = (path) => {
|
|
48
|
-
if (path.endsWith("/") && path !== "/") path = path.slice(0, -1);
|
|
49
|
-
return path.replace(/\{[^/{}]+(\+?)\}/g, "{_$1}");
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const httpRouterValidateOptions = (options) => {
|
|
45
|
+
export const httpRouterValidateOptions = (options) =>
|
|
53
46
|
validateOptions("@middy/http-router", optionSchema, options);
|
|
54
|
-
const routes = options?.routes;
|
|
55
|
-
if (routes === undefined) return;
|
|
56
|
-
const seen = new Set();
|
|
57
|
-
for (const { method, path } of routes) {
|
|
58
|
-
const expanded = method === "ANY" ? methods : [method];
|
|
59
|
-
const normalized = normalizeRoutePath(path);
|
|
60
|
-
for (const m of expanded) {
|
|
61
|
-
const key = `${m} ${normalized}`;
|
|
62
|
-
if (seen.has(key)) {
|
|
63
|
-
throw new Error("Duplicate route", {
|
|
64
|
-
cause: {
|
|
65
|
-
package: "@middy/http-router",
|
|
66
|
-
data: { method: m, path },
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
seen.add(key);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return options;
|
|
74
|
-
};
|
|
75
47
|
|
|
76
48
|
const httpRouteHandler = (opts = {}) => {
|
|
77
49
|
let options;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-router",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.3",
|
|
4
4
|
"description": "HTTP event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"url": "https://github.com/sponsors/willfarrell"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "7.3.
|
|
65
|
+
"@middy/util": "7.3.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@middy/core": "7.3.
|
|
68
|
+
"@middy/core": "7.3.3",
|
|
69
69
|
"@types/aws-lambda": "^8.0.0",
|
|
70
70
|
"@types/node": "^22.0.0"
|
|
71
71
|
}
|