@middy/ws-router 7.2.3 → 7.3.1
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.d.ts +4 -0
- package/index.js +40 -1
- package/package.json +3 -6
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
import { createError } from "@middy/util";
|
|
3
|
+
import { createError, validateOptions } from "@middy/util";
|
|
4
4
|
|
|
5
5
|
const defaults = {
|
|
6
6
|
routes: [],
|
|
@@ -11,6 +11,45 @@ const defaults = {
|
|
|
11
11
|
throw err;
|
|
12
12
|
},
|
|
13
13
|
};
|
|
14
|
+
|
|
15
|
+
const optionSchema = {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
routes: {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: {
|
|
21
|
+
type: "object",
|
|
22
|
+
required: ["routeKey", "handler"],
|
|
23
|
+
properties: {
|
|
24
|
+
routeKey: { type: "string" },
|
|
25
|
+
handler: { instanceof: "Function" },
|
|
26
|
+
},
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
notFoundResponse: { instanceof: "Function" },
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const wsRouterValidateOptions = (options) => {
|
|
36
|
+
validateOptions("@middy/ws-router", optionSchema, options);
|
|
37
|
+
const routes = options?.routes;
|
|
38
|
+
if (routes === undefined) return options;
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const { routeKey } of routes) {
|
|
41
|
+
if (seen.has(routeKey)) {
|
|
42
|
+
throw new Error("Duplicate route", {
|
|
43
|
+
cause: {
|
|
44
|
+
package: "@middy/ws-router",
|
|
45
|
+
data: { routeKey },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
seen.add(routeKey);
|
|
50
|
+
}
|
|
51
|
+
return options;
|
|
52
|
+
};
|
|
14
53
|
const wsRouteHandler = (opts = {}) => {
|
|
15
54
|
let options;
|
|
16
55
|
if (Array.isArray(opts)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ws-router",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "WebSocket event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
"import": {
|
|
18
18
|
"types": "./index.d.ts",
|
|
19
19
|
"default": "./index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"default": "./index.js"
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
},
|
|
@@ -65,10 +62,10 @@
|
|
|
65
62
|
"url": "https://github.com/sponsors/willfarrell"
|
|
66
63
|
},
|
|
67
64
|
"dependencies": {
|
|
68
|
-
"@middy/util": "7.
|
|
65
|
+
"@middy/util": "7.3.1"
|
|
69
66
|
},
|
|
70
67
|
"devDependencies": {
|
|
71
|
-
"@middy/core": "7.
|
|
68
|
+
"@middy/core": "7.3.1",
|
|
72
69
|
"@types/aws-lambda": "^8.0.0",
|
|
73
70
|
"@types/node": "^22.0.0"
|
|
74
71
|
}
|