@middy/ws-router 5.0.0-alpha.0 → 5.0.0-alpha.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 (4) hide show
  1. package/README.md +3 -2
  2. package/index.js +31 -19
  3. package/package.json +4 -10
  4. package/index.cjs +0 -29
package/README.md CHANGED
@@ -19,8 +19,9 @@
19
19
  <a href="https://snyk.io/test/github/middyjs/middy">
20
20
  <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
21
21
  </a>
22
- <a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
23
- <img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
22
+ <a href="https://github.com/middyjs/middy/actions/workflows/sast.yml">
23
+ <img src="https://github.com/middyjs/middy/actions/workflows/sast.yml/badge.svg
24
+ ?branch=main&event=push" alt="CodeQL" style="max-width:100%;">
24
25
  </a>
25
26
  <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
26
27
  <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
package/index.js CHANGED
@@ -1,21 +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('[ws-router] Unknown ws event format');
12
- }
13
- const handler = routesStatic[routeKey];
14
- if (typeof handler !== 'undefined') {
15
- return handler(event, context, abort);
16
- }
17
- throw createError(404, 'Route does not exist');
18
- };
19
- };
20
- export default wsRouteHandler;
21
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: { pacakge: '@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.0.0-alpha.0",
3
+ "version": "5.0.0-alpha.1",
4
4
  "description": "WebSocket event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,24 +10,18 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "./index.cjs",
14
13
  "module": "./index.js",
15
14
  "exports": {
16
15
  ".": {
17
16
  "import": {
18
17
  "types": "./index.d.ts",
19
18
  "default": "./index.js"
20
- },
21
- "require": {
22
- "types": "./index.d.ts",
23
- "default": "./index.cjs"
24
19
  }
25
20
  }
26
21
  },
27
22
  "types": "index.d.ts",
28
23
  "files": [
29
24
  "index.js",
30
- "index.cjs",
31
25
  "index.d.ts"
32
26
  ],
33
27
  "scripts": {
@@ -66,11 +60,11 @@
66
60
  "url": "https://github.com/sponsors/willfarrell"
67
61
  },
68
62
  "dependencies": {
69
- "@middy/util": "5.0.0-alpha.0"
63
+ "@middy/util": "5.0.0-alpha.1"
70
64
  },
71
65
  "devDependencies": {
72
- "@middy/core": "5.0.0-alpha.0",
66
+ "@middy/core": "5.0.0-alpha.1",
73
67
  "@types/aws-lambda": "^8.10.100"
74
68
  },
75
- "gitHead": "08c35e3dba9efdad0b86666ce206ce302cc65d07"
69
+ "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1"
76
70
  }
package/index.cjs DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(module, "exports", {
6
- enumerable: true,
7
- get: ()=>_default
8
- });
9
- const _util = require("@middy/util");
10
- const wsRouteHandler = (routes)=>{
11
- const routesStatic = {};
12
- for (const route of routes){
13
- const { routeKey , handler } = route;
14
- routesStatic[routeKey] = handler;
15
- }
16
- return (event, context, abort)=>{
17
- const { routeKey } = event.requestContext ?? {};
18
- if (!routeKey) {
19
- throw new Error('[ws-router] Unknown ws event format');
20
- }
21
- const handler = routesStatic[routeKey];
22
- if (typeof handler !== 'undefined') {
23
- return handler(event, context, abort);
24
- }
25
- throw (0, _util.createError)(404, 'Route does not exist');
26
- };
27
- };
28
- const _default = wsRouteHandler;
29
-