@middy/ws-router 3.0.3 → 3.1.0-rc.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/README.md +2 -2
- package/index.cjs +27 -1
- package/index.d.ts +8 -2
- package/index.js +21 -1
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -64,13 +64,13 @@ import wsResponseMiddleware from '@middy/ws-response'
|
|
|
64
64
|
import validatorMiddleware from '@middy/validator'
|
|
65
65
|
|
|
66
66
|
const connectHandler = middy()
|
|
67
|
-
.use(validatorMiddleware({
|
|
67
|
+
.use(validatorMiddleware({eventSchema: {...} }))
|
|
68
68
|
.handler((event, context) => {
|
|
69
69
|
return 'connected'
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
const disconnectHandler = middy()
|
|
73
|
-
.use(validatorMiddleware({
|
|
73
|
+
.use(validatorMiddleware({eventSchema: {...} }))
|
|
74
74
|
.handler((event, context) => {
|
|
75
75
|
return 'disconnected'
|
|
76
76
|
})
|
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.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import middy from '@middy/core'
|
|
2
|
+
import { APIGatewayProxyHandlerV2 } from 'aws-lambda'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
interface Route<T = never> {
|
|
5
|
+
routeKey: string
|
|
6
|
+
handler: APIGatewayProxyHandlerV2<T>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare function wsRouterHandler (routes: Route[]): middy.MiddyfiedHandler
|
|
4
10
|
|
|
5
11
|
export default wsRouterHandler
|
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.1.0-rc.1",
|
|
4
4
|
"description": "WebSocket event router for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,11 +10,17 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
+
"main": "./index.cjs",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
|
-
"import":
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"default": "./index.cjs"
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"types": "index.d.ts",
|
|
@@ -55,10 +61,11 @@
|
|
|
55
61
|
},
|
|
56
62
|
"homepage": "https://middy.js.org",
|
|
57
63
|
"dependencies": {
|
|
58
|
-
"@middy/util": "3.0.
|
|
64
|
+
"@middy/util": "3.1.0-rc.1"
|
|
59
65
|
},
|
|
60
66
|
"devDependencies": {
|
|
61
|
-
"@middy/core": "3.0.
|
|
67
|
+
"@middy/core": "3.1.0-rc.1",
|
|
68
|
+
"@types/aws-lambda": "^8.10.100"
|
|
62
69
|
},
|
|
63
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "044c397e7a2b1de516b4b5c21ece2baffdbfa771"
|
|
64
71
|
}
|