@middy/ws-router 5.4.6 → 5.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.
Files changed (2) hide show
  1. package/index.js +15 -4
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,6 +1,19 @@
1
1
  import { createError } from '@middy/util'
2
+ const defaults = {
3
+ routes: [],
4
+ notFoundResponse: ({ routeKey }) => {
5
+ const err = createError(404, 'Route does not exist', {
6
+ cause: { package: '@middy/ws-router', data: { routeKey } }
7
+ })
8
+ throw err
9
+ }
10
+ }
11
+ const wsRouteHandler = (opts = {}) => {
12
+ if (Array.isArray(opts)) {
13
+ opts = { routes: opts }
14
+ }
15
+ const { routes, notFoundResponse } = { ...defaults, ...opts }
2
16
 
3
- const wsRouteHandler = (routes) => {
4
17
  const routesStatic = {}
5
18
  for (const route of routes) {
6
19
  const { routeKey, handler } = route
@@ -24,9 +37,7 @@ const wsRouteHandler = (routes) => {
24
37
  }
25
38
 
26
39
  // Not Found
27
- throw createError(404, 'Route does not exist', {
28
- cause: { package: '@middy/ws-router', data: routeKey }
29
- })
40
+ return notFoundResponse({ routeKey })
30
41
  }
31
42
  }
32
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/ws-router",
3
- "version": "5.4.6",
3
+ "version": "5.5.0",
4
4
  "description": "WebSocket event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -60,10 +60,10 @@
60
60
  "url": "https://github.com/sponsors/willfarrell"
61
61
  },
62
62
  "dependencies": {
63
- "@middy/util": "5.4.6"
63
+ "@middy/util": "5.5.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@middy/core": "5.4.6",
66
+ "@middy/core": "5.5.0",
67
67
  "@types/aws-lambda": "^8.10.100"
68
68
  },
69
69
  "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"