@midwayjs/express 3.5.1 → 3.6.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.
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ExpressConfiguration = void 0;
13
- const decorator_1 = require("@midwayjs/decorator");
14
13
  const core_1 = require("@midwayjs/core");
15
14
  const session = require("@midwayjs/express-session");
16
15
  const framework_1 = require("./framework");
@@ -19,7 +18,7 @@ const cookieParser = require("cookie-parser");
19
18
  const DefaultConfig = require("./config/config.default");
20
19
  let ExpressConfiguration = class ExpressConfiguration {
21
20
  init() {
22
- this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
21
+ this.decoratorService.registerParameterHandler(core_1.WEB_ROUTER_PARAM_KEY, options => {
23
22
  return (0, core_1.extractExpressLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1], options.originArgs[2]);
24
23
  });
25
24
  }
@@ -54,25 +53,25 @@ let ExpressConfiguration = class ExpressConfiguration {
54
53
  }
55
54
  };
56
55
  __decorate([
57
- (0, decorator_1.Inject)(),
56
+ (0, core_1.Inject)(),
58
57
  __metadata("design:type", core_1.MidwayDecoratorService)
59
58
  ], ExpressConfiguration.prototype, "decoratorService", void 0);
60
59
  __decorate([
61
- (0, decorator_1.Inject)(),
60
+ (0, core_1.Inject)(),
62
61
  __metadata("design:type", framework_1.MidwayExpressFramework)
63
62
  ], ExpressConfiguration.prototype, "expressFramework", void 0);
64
63
  __decorate([
65
- (0, decorator_1.Inject)(),
64
+ (0, core_1.Inject)(),
66
65
  __metadata("design:type", core_1.MidwayConfigService)
67
66
  ], ExpressConfiguration.prototype, "configService", void 0);
68
67
  __decorate([
69
- (0, decorator_1.Init)(),
68
+ (0, core_1.Init)(),
70
69
  __metadata("design:type", Function),
71
70
  __metadata("design:paramtypes", []),
72
71
  __metadata("design:returntype", void 0)
73
72
  ], ExpressConfiguration.prototype, "init", null);
74
73
  ExpressConfiguration = __decorate([
75
- (0, decorator_1.Configuration)({
74
+ (0, core_1.Configuration)({
76
75
  namespace: 'express',
77
76
  imports: [session],
78
77
  importConfigs: [
package/dist/framework.js CHANGED
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MidwayExpressFramework = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
- const decorator_1 = require("@midwayjs/decorator");
12
11
  const express = require("express");
13
12
  const middlewareService_1 = require("./middlewareService");
14
13
  const util_1 = require("util");
@@ -160,6 +159,14 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
160
159
  */
161
160
  generateController(routeInfo) {
162
161
  return (0, middlewareService_1.wrapAsyncHandler)(async (req, res, next) => {
162
+ if (routeInfo.controllerClz && typeof routeInfo.method === 'string') {
163
+ const isPassed = await this.app
164
+ .getFramework()
165
+ .runGuard(req, routeInfo.controllerClz, routeInfo.method);
166
+ if (!isPassed) {
167
+ throw new core_1.httpError.ForbiddenError();
168
+ }
169
+ }
163
170
  let result;
164
171
  if (typeof routeInfo.method !== 'string') {
165
172
  result = await routeInfo.method(req, res, next);
@@ -180,16 +187,16 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
180
187
  routeInfo.responseMetadata.length) {
181
188
  for (const routerRes of routeInfo.responseMetadata) {
182
189
  switch (routerRes.type) {
183
- case decorator_1.WEB_RESPONSE_HTTP_CODE:
190
+ case core_1.WEB_RESPONSE_HTTP_CODE:
184
191
  res.status(routerRes.code);
185
192
  break;
186
- case decorator_1.WEB_RESPONSE_HEADER:
193
+ case core_1.WEB_RESPONSE_HEADER:
187
194
  res.set(routerRes.setHeaders);
188
195
  break;
189
- case decorator_1.WEB_RESPONSE_CONTENT_TYPE:
196
+ case core_1.WEB_RESPONSE_CONTENT_TYPE:
190
197
  res.type(routerRes.contentType);
191
198
  break;
192
- case decorator_1.WEB_RESPONSE_REDIRECT:
199
+ case core_1.WEB_RESPONSE_REDIRECT:
193
200
  res.redirect(routerRes.code, routerRes.url);
194
201
  return;
195
202
  }
@@ -279,7 +286,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
279
286
  }
280
287
  };
281
288
  MidwayExpressFramework = __decorate([
282
- (0, decorator_1.Framework)()
289
+ (0, core_1.Framework)()
283
290
  ], MidwayExpressFramework);
284
291
  exports.MidwayExpressFramework = MidwayExpressFramework;
285
292
  //# sourceMappingURL=framework.js.map
@@ -10,11 +10,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.wrapMiddleware = exports.MidwayExpressMiddlewareService = exports.wrapAsyncHandler = void 0;
13
- const decorator_1 = require("@midwayjs/decorator");
14
13
  const core_1 = require("@midwayjs/core");
15
14
  const util_1 = require("./util");
16
15
  function wrapAsyncHandler(fn) {
17
- if (decorator_1.Types.isAsyncFunction(fn)) {
16
+ if (core_1.Types.isAsyncFunction(fn)) {
18
17
  return (req, res, next) => {
19
18
  return fn(req, res, next).catch(err => {
20
19
  next(err);
@@ -36,7 +35,7 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
36
35
  }
37
36
  const newMiddlewareArr = [];
38
37
  for (let fn of middleware) {
39
- if (decorator_1.Types.isClass(fn) || typeof fn === 'string') {
38
+ if (core_1.Types.isClass(fn) || typeof fn === 'string') {
40
39
  if (typeof fn === 'string' &&
41
40
  !this.applicationContext.hasDefinition(fn)) {
42
41
  throw new core_1.MidwayCommonError('Middleware definition not found in midway container');
@@ -118,8 +117,8 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
118
117
  }
119
118
  };
120
119
  MidwayExpressMiddlewareService = __decorate([
121
- (0, decorator_1.Provide)(),
122
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
120
+ (0, core_1.Provide)(),
121
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton),
123
122
  __metadata("design:paramtypes", [Object])
124
123
  ], MidwayExpressMiddlewareService);
125
124
  exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/express",
3
- "version": "3.5.1",
3
+ "version": "3.6.0",
4
4
  "description": "Midway Web Framework for Express",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -24,17 +24,16 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/decorator": "^3.4.11",
28
27
  "@midwayjs/logger": "^2.15.0",
29
- "@midwayjs/mock": "^3.5.1",
28
+ "@midwayjs/mock": "^3.6.0",
30
29
  "@types/body-parser": "1.19.2",
31
- "@types/express": "4.17.13",
30
+ "@types/express": "4.17.14",
32
31
  "fs-extra": "10.0.1"
33
32
  },
34
33
  "dependencies": {
35
- "@midwayjs/core": "^3.5.1",
36
- "@midwayjs/express-session": "^3.5.1",
37
- "body-parser": "1.20.0",
34
+ "@midwayjs/core": "^3.6.0",
35
+ "@midwayjs/express-session": "^3.6.0",
36
+ "body-parser": "1.20.1",
38
37
  "cookie-parser": "^1.4.6",
39
38
  "express": "4.18.1"
40
39
  },
@@ -46,5 +45,5 @@
46
45
  "engines": {
47
46
  "node": ">=12"
48
47
  },
49
- "gitHead": "3b63fc768617037644602dd5ad66d3734ce01b16"
48
+ "gitHead": "22643b0e8519766bb7c68b975930199fc136336e"
50
49
  }