@middy/ws-router 5.1.0 → 5.2.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.
Files changed (2) hide show
  1. package/index.js +31 -28
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,30 +1,33 @@
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;
1
+ import { createError } from '@middy/util'
2
+
3
+ const wsRouteHandler = (routes) => {
4
+ const routesStatic = {}
5
+ for (const route of routes) {
6
+ const { routeKey, handler } = route
7
+
8
+ // Static
9
+ routesStatic[routeKey] = handler
10
+ }
11
+
12
+ return (event, context, abort) => {
13
+ const { routeKey } = event.requestContext ?? {}
14
+ if (!routeKey) {
15
+ throw new Error('Unknown WebSocket event format', {
16
+ cause: { package: '@middy/ws-router' }
17
+ })
7
18
  }
8
- return (event, context, abort)=>{
9
- const { routeKey } = event.requestContext ?? {};
10
- if (!routeKey) {
11
- throw new Error('Unknown WebSocket event format', {
12
- cause: {
13
- package: '@middy/ws-router'
14
- }
15
- });
16
- }
17
- const handler = routesStatic[routeKey];
18
- if (typeof handler !== 'undefined') {
19
- return handler(event, context, abort);
20
- }
21
- throw createError(404, 'Route does not exist', {
22
- cause: {
23
- package: '@middy/ws-router',
24
- data: routeKey
25
- }
26
- });
27
- };
28
- };
29
- export default wsRouteHandler;
30
19
 
20
+ // Static
21
+ const handler = routesStatic[routeKey]
22
+ if (typeof handler !== 'undefined') {
23
+ return handler(event, context, abort)
24
+ }
25
+
26
+ // Not Found
27
+ throw createError(404, 'Route does not exist', {
28
+ cause: { package: '@middy/ws-router', data: routeKey }
29
+ })
30
+ }
31
+ }
32
+
33
+ export default wsRouteHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/ws-router",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "description": "WebSocket event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -60,11 +60,11 @@
60
60
  "url": "https://github.com/sponsors/willfarrell"
61
61
  },
62
62
  "dependencies": {
63
- "@middy/util": "5.1.0"
63
+ "@middy/util": "5.2.1"
64
64
  },
65
65
  "devDependencies": {
66
- "@middy/core": "5.1.0",
66
+ "@middy/core": "5.2.1",
67
67
  "@types/aws-lambda": "^8.10.100"
68
68
  },
69
- "gitHead": "bbdaf5843914921804ba085dd58117273febe6b5"
69
+ "gitHead": "4d55da221b9165b4b3e59a12632fd40a149a1e92"
70
70
  }