@midwayjs/ws 3.0.0-beta.1 → 3.0.0-beta.13

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/CHANGELOG.md CHANGED
@@ -3,6 +3,123 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * 404 error ([#1465](https://github.com/midwayjs/midway/issues/1465)) ([e7e8a9d](https://github.com/midwayjs/midway/commit/e7e8a9dedfa7198ac05b161b41024c2871f93965))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
18
+
19
+
20
+ ### Features
21
+
22
+ * support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
23
+
24
+
25
+
26
+
27
+
28
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
29
+
30
+ **Note:** Version bump only for package @midwayjs/ws
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
37
+
38
+
39
+ ### Features
40
+
41
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
42
+
43
+
44
+
45
+
46
+
47
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
48
+
49
+ **Note:** Version bump only for package @midwayjs/ws
50
+
51
+
52
+
53
+
54
+
55
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
61
+
62
+
63
+
64
+
65
+
66
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
67
+
68
+
69
+ ### Bug Fixes
70
+
71
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
72
+
73
+
74
+
75
+
76
+
77
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
78
+
79
+ **Note:** Version bump only for package @midwayjs/ws
80
+
81
+
82
+
83
+
84
+
85
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
86
+
87
+ **Note:** Version bump only for package @midwayjs/ws
88
+
89
+
90
+
91
+
92
+
93
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
94
+
95
+
96
+ ### Features
97
+
98
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
99
+
100
+
101
+
102
+
103
+
104
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
105
+
106
+
107
+ ### Features
108
+
109
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
110
+
111
+
112
+
113
+
114
+
115
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
116
+
117
+ **Note:** Version bump only for package @midwayjs/ws
118
+
119
+
120
+
121
+
122
+
6
123
  # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
7
124
 
8
125
 
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # midway framework for socket.io
1
+ # midway framework for WebSocket
2
2
 
3
3
  [![Package Quality](http://npm.packagequality.com/shield/midway-web.svg)](http://packagequality.com/#?package=midway-web)
4
4
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
@@ -1,7 +1,3 @@
1
- import { MidwayWSFramework } from './framework';
2
1
  export declare class WebSocketConfiguration {
3
- framework: MidwayWSFramework;
4
- onReady(): Promise<void>;
5
- onServerReady(): Promise<void>;
6
2
  }
7
3
  //# sourceMappingURL=configuration.d.ts.map
@@ -5,23 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.WebSocketConfiguration = void 0;
13
10
  const decorator_1 = require("@midwayjs/decorator");
14
- const framework_1 = require("./framework");
15
11
  let WebSocketConfiguration = class WebSocketConfiguration {
16
- async onReady() { }
17
- async onServerReady() {
18
- await this.framework.run();
19
- }
20
12
  };
21
- __decorate([
22
- (0, decorator_1.Inject)(),
23
- __metadata("design:type", framework_1.MidwayWSFramework)
24
- ], WebSocketConfiguration.prototype, "framework", void 0);
25
13
  WebSocketConfiguration = __decorate([
26
14
  (0, decorator_1.Configuration)({
27
15
  namespace: 'webSocket',
package/dist/framework.js CHANGED
@@ -10,7 +10,7 @@ exports.MidwayWSFramework = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
11
  const http = require("http");
12
12
  const util_1 = require("util");
13
- const debug = (0, util_1.debuglog)('midway:ws');
13
+ const debug = (0, util_1.debuglog)('midway:debug');
14
14
  const WebSocket = require("ws");
15
15
  const decorator_1 = require("@midwayjs/decorator");
16
16
  let MidwayWSFramework = class MidwayWSFramework extends core_1.BaseFramework {
@@ -96,15 +96,12 @@ let MidwayWSFramework = class MidwayWSFramework extends core_1.BaseFramework {
96
96
  else if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_MESSAGE) {
97
97
  // on user custom event
98
98
  socket.on(wsEventInfo.messageEventName, async (...args) => {
99
- debug('got message', wsEventInfo.messageEventName, args);
100
- const { result, error } = await (await this.getMiddleware(async (ctx, next) => {
101
- // eslint-disable-next-line prefer-spread
102
- return controller[wsEventInfo.propertyName].apply(controller, args);
103
- }))(socket);
104
- if (error) {
105
- this.logger.error(error);
106
- }
107
- else {
99
+ debug('[ws]: got message', wsEventInfo.messageEventName, args);
100
+ try {
101
+ const result = await (await this.applyMiddleware(async (ctx, next) => {
102
+ // eslint-disable-next-line prefer-spread
103
+ return controller[wsEventInfo.propertyName].apply(controller, args);
104
+ }))(socket);
108
105
  if (typeof args[args.length - 1] === 'function') {
109
106
  // ack
110
107
  args[args.length - 1](result);
@@ -114,6 +111,9 @@ let MidwayWSFramework = class MidwayWSFramework extends core_1.BaseFramework {
114
111
  await this.bindSocketResponse(result, socket, wsEventInfo.propertyName, methodMap);
115
112
  }
116
113
  }
114
+ catch (error) {
115
+ this.logger.error(error);
116
+ }
117
117
  });
118
118
  }
119
119
  else if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_DISCONNECTION) {
@@ -1,8 +1,7 @@
1
1
  import * as WebSocket from 'ws';
2
- import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
2
+ import { IConfigurationOptions, IMidwayApplication, IMidwayContext, NextFunction as BaseNextFunction } from '@midwayjs/core';
3
3
  export declare type IMidwayWSApplication = IMidwayApplication<IMidwayWSContext> & WebSocket.Server;
4
4
  export declare type IMidwayWSConfigurationOptions = {
5
- port?: number;
6
5
  pubClient?: any;
7
6
  subClient?: any;
8
7
  } & Partial<WebSocket.ServerOptions> & IConfigurationOptions;
@@ -10,6 +9,12 @@ export declare type IMidwayWSContext = IMidwayContext<WebSocket & {
10
9
  app: IMidwayWSApplication;
11
10
  }>;
12
11
  export declare type Application = IMidwayWSApplication;
12
+ export declare type NextFunction = BaseNextFunction;
13
13
  export interface Context extends IMidwayWSContext {
14
14
  }
15
+ declare module '@midwayjs/core/dist/interface' {
16
+ interface MidwayConfig {
17
+ webSocket?: IMidwayWSConfigurationOptions;
18
+ }
19
+ }
15
20
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/ws",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.13",
4
4
  "description": "Midway Web Framework for ws",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -22,14 +22,14 @@
22
22
  ],
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
- "@midwayjs/decorator": "^3.0.0-beta.1",
26
- "@midwayjs/mock": "^3.0.0-beta.1",
25
+ "@midwayjs/decorator": "^3.0.0-beta.13",
26
+ "@midwayjs/mock": "^3.0.0-beta.13",
27
27
  "@types/ws": "^7.4.4",
28
28
  "fs-extra": "^8.0.1"
29
29
  },
30
30
  "dependencies": {
31
- "@midwayjs/core": "^3.0.0-beta.1",
32
- "@midwayjs/logger": "^3.0.0-beta.1",
31
+ "@midwayjs/core": "^3.0.0-beta.13",
32
+ "@midwayjs/logger": "^3.0.0-beta.13",
33
33
  "ws": "^7.4.5"
34
34
  },
35
35
  "author": "Harry Chen <czy88840616@gmail.com>",
@@ -40,5 +40,5 @@
40
40
  "engines": {
41
41
  "node": ">=12"
42
42
  },
43
- "gitHead": "72e4d20c678e65a5440c4e9a6d3b70046daa497c"
43
+ "gitHead": "d3c47770fee9dce33a8d148882173fd7782864ad"
44
44
  }