@middy/ws-router 3.0.3 → 3.0.4
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.cjs +27 -1
- package/index.js +21 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
module.exports = void 0;
|
|
6
|
+
var _util = require("@middy/util");
|
|
7
|
+
const wsRouteHandler = (routes)=>{
|
|
8
|
+
const routesStatic = {};
|
|
9
|
+
for (const route of routes){
|
|
10
|
+
const { routeKey , handler } = route;
|
|
11
|
+
routesStatic[routeKey] = handler;
|
|
12
|
+
}
|
|
13
|
+
return (event, context, abort)=>{
|
|
14
|
+
const { routeKey } = event.requestContext ?? {};
|
|
15
|
+
if (!routeKey) {
|
|
16
|
+
throw new Error('[ws-router] Unknown ws event format');
|
|
17
|
+
}
|
|
18
|
+
const handler = routesStatic[routeKey];
|
|
19
|
+
if (handler !== undefined) {
|
|
20
|
+
return handler(event, context, abort);
|
|
21
|
+
}
|
|
22
|
+
throw (0, _util).createError(404, 'Route does not exist');
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var _default = wsRouteHandler;
|
|
26
|
+
module.exports = _default;
|
|
27
|
+
|
|
2
28
|
|
|
3
29
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
import{createError}from
|
|
1
|
+
import { createError } from '@middy/util';
|
|
2
|
+
const wsRouteHandler = (routes)=>{
|
|
3
|
+
const routesStatic = {};
|
|
4
|
+
for (const route of routes){
|
|
5
|
+
const { routeKey , handler } = route;
|
|
6
|
+
routesStatic[routeKey] = handler;
|
|
7
|
+
}
|
|
8
|
+
return (event, context, abort)=>{
|
|
9
|
+
const { routeKey } = event.requestContext ?? {};
|
|
10
|
+
if (!routeKey) {
|
|
11
|
+
throw new Error('[ws-router] Unknown ws event format');
|
|
12
|
+
}
|
|
13
|
+
const handler = routesStatic[routeKey];
|
|
14
|
+
if (handler !== undefined) {
|
|
15
|
+
return handler(event, context, abort);
|
|
16
|
+
}
|
|
17
|
+
throw createError(404, 'Route does not exist');
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export default wsRouteHandler;
|
|
21
|
+
|
|
2
22
|
|
|
3
23
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ws-router",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "WebSocket event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://middy.js.org",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@middy/util": "3.0.
|
|
58
|
+
"@middy/util": "3.0.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@middy/core": "3.0.
|
|
61
|
+
"@middy/core": "3.0.4"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "3e9bc83e791f943c71cd7003fc27f0a3692d83a1"
|
|
64
64
|
}
|