@midwayjs/ws 3.0.0-alpha.9 → 3.0.0-beta.4

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,47 @@
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.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
18
+
19
+
20
+ ### Features
21
+
22
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
23
+
24
+
25
+
26
+
27
+
28
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
29
+
30
+ **Note:** Version bump only for package @midwayjs/ws
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * correct aspect chain bug ([#1204](https://github.com/midwayjs/midway/issues/1204)) ([5de5284](https://github.com/midwayjs/midway/commit/5de5284c70b44acc73eaaad651fd2edc72d54f28))
42
+
43
+
44
+
45
+
46
+
6
47
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
48
 
8
49
 
@@ -0,0 +1,3 @@
1
+ export declare class WebSocketConfiguration {
2
+ }
3
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.WebSocketConfiguration = void 0;
10
+ const decorator_1 = require("@midwayjs/decorator");
11
+ let WebSocketConfiguration = class WebSocketConfiguration {
12
+ };
13
+ WebSocketConfiguration = __decorate([
14
+ (0, decorator_1.Configuration)({
15
+ namespace: 'webSocket',
16
+ importConfigs: [
17
+ {
18
+ default: {
19
+ webSocket: {},
20
+ },
21
+ },
22
+ ],
23
+ })
24
+ ], WebSocketConfiguration);
25
+ exports.WebSocketConfiguration = WebSocketConfiguration;
26
+ //# sourceMappingURL=configuration.js.map
@@ -4,6 +4,7 @@ import * as http from 'http';
4
4
  import { IMidwayWSApplication, IMidwayWSConfigurationOptions, IMidwayWSContext } from './interface';
5
5
  export declare class MidwayWSFramework extends BaseFramework<IMidwayWSApplication, IMidwayWSContext, IMidwayWSConfigurationOptions> {
6
6
  server: http.Server;
7
+ configure(): IMidwayWSConfigurationOptions;
7
8
  applicationInitialize(options: IMidwayBootstrapOptions): void;
8
9
  app: IMidwayWSApplication;
9
10
  protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
package/dist/framework.js CHANGED
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.MidwayWSFramework = void 0;
4
10
  const core_1 = require("@midwayjs/core");
5
11
  const http = require("http");
6
12
  const util_1 = require("util");
7
- const debug = util_1.debuglog('midway:ws');
13
+ const debug = (0, util_1.debuglog)('midway:ws');
8
14
  const WebSocket = require("ws");
9
15
  const decorator_1 = require("@midwayjs/decorator");
10
- class MidwayWSFramework extends core_1.BaseFramework {
16
+ let MidwayWSFramework = class MidwayWSFramework extends core_1.BaseFramework {
17
+ configure() {
18
+ return this.configService.getConfiguration('webSocket');
19
+ }
11
20
  applicationInitialize(options) {
12
21
  this.configurationOptions.noServer = true;
13
22
  const opts = Object.assign({}, this.configurationOptions, { port: null });
@@ -55,25 +64,25 @@ class MidwayWSFramework extends core_1.BaseFramework {
55
64
  }
56
65
  async loadMidwayController() {
57
66
  // create room
58
- const controllerModules = core_1.listModule(decorator_1.WS_CONTROLLER_KEY);
67
+ const controllerModules = (0, decorator_1.listModule)(decorator_1.WS_CONTROLLER_KEY);
59
68
  if (controllerModules.length > 0) {
60
69
  // ws just one namespace
61
- await this.addNamespace(controllerModules[0], core_1.getProviderId(controllerModules[0]));
70
+ await this.addNamespace(controllerModules[0]);
62
71
  }
63
72
  }
64
- async addNamespace(target, controllerId) {
73
+ async addNamespace(target) {
65
74
  this.app.on('connection', async (socket, request) => {
66
75
  // create request context
67
76
  this.app.createAnonymousContext(socket);
68
77
  socket.requestContext.registerObject('socket', socket);
69
78
  socket.app = this.app;
70
- const wsEventInfos = core_1.getClassMetadata(decorator_1.WS_EVENT_KEY, target);
79
+ const wsEventInfos = (0, decorator_1.getClassMetadata)(decorator_1.WS_EVENT_KEY, target);
71
80
  // 存储方法对应的响应处理
72
81
  const methodMap = {};
73
82
  if (wsEventInfos.length) {
74
83
  for (const wsEventInfo of wsEventInfos) {
75
84
  methodMap[wsEventInfo.propertyName] = methodMap[wsEventInfo.propertyName] || { responseEvents: [] };
76
- const controller = await socket.requestContext.getAsync(controllerId);
85
+ const controller = await socket.requestContext.getAsync(target);
77
86
  // on connection
78
87
  if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_CONNECTION) {
79
88
  try {
@@ -88,14 +97,22 @@ class MidwayWSFramework extends core_1.BaseFramework {
88
97
  // on user custom event
89
98
  socket.on(wsEventInfo.messageEventName, async (...args) => {
90
99
  debug('got message', wsEventInfo.messageEventName, args);
91
- try {
100
+ const { result, error } = await (await this.getMiddleware(async (ctx, next) => {
92
101
  // eslint-disable-next-line prefer-spread
93
- const result = await controller[wsEventInfo.propertyName].apply(controller, args);
94
- // emit
95
- await this.bindSocketResponse(result, socket, wsEventInfo.propertyName, methodMap);
102
+ return controller[wsEventInfo.propertyName].apply(controller, args);
103
+ }))(socket);
104
+ if (error) {
105
+ this.logger.error(error);
96
106
  }
97
- catch (err) {
98
- this.logger.error(err);
107
+ else {
108
+ if (typeof args[args.length - 1] === 'function') {
109
+ // ack
110
+ args[args.length - 1](result);
111
+ }
112
+ else {
113
+ // emit
114
+ await this.bindSocketResponse(result, socket, wsEventInfo.propertyName, methodMap);
115
+ }
99
116
  }
100
117
  });
101
118
  }
@@ -154,9 +171,12 @@ class MidwayWSFramework extends core_1.BaseFramework {
154
171
  getFrameworkName() {
155
172
  return 'midway:ws';
156
173
  }
157
- }
174
+ };
175
+ MidwayWSFramework = __decorate([
176
+ (0, decorator_1.Framework)()
177
+ ], MidwayWSFramework);
158
178
  exports.MidwayWSFramework = MidwayWSFramework;
159
179
  function formatResult(result) {
160
- return decorator_1.isObject(result) ? JSON.stringify(result) : result;
180
+ return (0, decorator_1.isObject)(result) ? JSON.stringify(result) : result;
161
181
  }
162
182
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { MidwayWSFramework as Framework } from './framework';
2
2
  export * from './interface';
3
+ export { WebSocketConfiguration as Configuration } from './configuration';
3
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,8 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Framework = void 0;
13
+ exports.Configuration = exports.Framework = void 0;
14
14
  var framework_1 = require("./framework");
15
15
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayWSFramework; } });
16
16
  __exportStar(require("./interface"), exports);
17
+ var configuration_1 = require("./configuration");
18
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.WebSocketConfiguration; } });
17
19
  //# sourceMappingURL=index.js.map
@@ -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-alpha.9+d5acc750",
3
+ "version": "3.0.0-beta.4",
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-alpha.2",
26
- "@midwayjs/mock": "^3.0.0-alpha.9+d5acc750",
25
+ "@midwayjs/decorator": "^3.0.0-beta.4",
26
+ "@midwayjs/mock": "^3.0.0-beta.4",
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-alpha.9+d5acc750",
32
- "@midwayjs/logger": "^2.11.3",
31
+ "@midwayjs/core": "^3.0.0-beta.4",
32
+ "@midwayjs/logger": "^3.0.0-beta.4",
33
33
  "ws": "^7.4.5"
34
34
  },
35
35
  "author": "Harry Chen <czy88840616@gmail.com>",
@@ -37,5 +37,8 @@
37
37
  "type": "git",
38
38
  "url": "http://github.com/midwayjs/midway.git"
39
39
  },
40
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
40
+ "engines": {
41
+ "node": ">=12"
42
+ },
43
+ "gitHead": "02e2144e302f807770b512b0d89da3145b1cbf2e"
41
44
  }