@midwayjs/core 3.2.2 → 3.3.2

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.
@@ -272,7 +272,7 @@ class BaseFramework {
272
272
  return this.informationService.getProjectName();
273
273
  }
274
274
  getFrameworkName() {
275
- return '';
275
+ return this.constructor.name;
276
276
  }
277
277
  useMiddleware(middleware) {
278
278
  this.middlewareManager.insertLast(middleware);
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { MidwayRequestContainer } from './context/requestContainer';
4
4
  export { BaseFramework } from './baseFramework';
5
5
  export * from './context/providerWrapper';
6
6
  export * from './common/constants';
7
- export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
7
+ export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, delegateTargetAllPrototypeMethod, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
8
8
  export { extend } from './util/extend';
9
9
  export * from './util/pathFileUtil';
10
10
  export * from './util/webRouterParam';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MidwayFrameworkType = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
17
+ exports.MidwayFrameworkType = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
18
18
  __exportStar(require("./interface"), exports);
19
19
  __exportStar(require("./context/container"), exports);
20
20
  var requestContainer_1 = require("./context/requestContainer");
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function
29
29
  Object.defineProperty(exports, "delegateTargetPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetPrototypeMethod; } });
30
30
  Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get: function () { return util_1.delegateTargetMethod; } });
31
31
  Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
32
+ Object.defineProperty(exports, "delegateTargetAllPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetAllPrototypeMethod; } });
32
33
  Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: function () { return util_1.deprecatedOutput; } });
33
34
  Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
34
35
  Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
@@ -67,8 +67,12 @@ let MidwayConfigService = class MidwayConfigService {
67
67
  else {
68
68
  // object add
69
69
  for (const env in dir) {
70
- const envSet = this.getEnvSet(env);
71
- envSet.add(dir[env]);
70
+ if (this.aliasMap[env]) {
71
+ this.getEnvSet(this.aliasMap[env]).add(dir[env]);
72
+ }
73
+ else {
74
+ this.getEnvSet(env).add(dir[env]);
75
+ }
72
76
  }
73
77
  }
74
78
  }
@@ -29,7 +29,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
29
29
  this.globalFrameworkList = [];
30
30
  }
31
31
  async init() {
32
- var _a;
32
+ var _a, _b;
33
33
  // register base config hook
34
34
  this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
35
35
  var _a;
@@ -55,6 +55,10 @@ let MidwayFrameworkService = class MidwayFrameworkService {
55
55
  debug(`[core]: Found Framework length = ${frameworks.length}`);
56
56
  if (frameworks.length) {
57
57
  for (const frameworkClz of frameworks) {
58
+ if (!this.applicationContext.hasDefinition((0, decorator_1.getProviderUUId)(frameworkClz))) {
59
+ debug(`[core]: Found Framework "${frameworkClz.name}" but missing definition, skip initialize.`);
60
+ continue;
61
+ }
58
62
  const frameworkInstance = await this.applicationContext.getAsync(frameworkClz, [this.applicationContext]);
59
63
  // if enable, just init framework
60
64
  if (frameworkInstance.isEnable()) {
@@ -89,8 +93,13 @@ let MidwayFrameworkService = class MidwayFrameworkService {
89
93
  this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
90
94
  return this.getMainApp()[key];
91
95
  });
96
+ const nsSet = this.applicationContext['namespaceSet'];
97
+ let mainNs;
98
+ if (nsSet.size > 0) {
99
+ [mainNs] = nsSet;
100
+ }
92
101
  global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
93
- this.globalFrameworkList[0];
102
+ (_b = this.applicationManager.getFramework(mainNs)) !== null && _b !== void 0 ? _b : this.globalFrameworkList[0];
94
103
  }
95
104
  // init aspect module
96
105
  await this.aspectService.loadAspect();
@@ -27,7 +27,7 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
27
27
  if (decorator_1.Types.isClass(fn) || typeof fn === 'string') {
28
28
  if (typeof fn === 'string' &&
29
29
  !this.applicationContext.hasDefinition(fn)) {
30
- throw new error_1.MidwayCommonError('Middleware definition not found in midway container');
30
+ throw new error_1.MidwayCommonError(`Middleware definition of "${fn}" not found in midway container`);
31
31
  }
32
32
  const classMiddleware = await this.applicationContext.getAsync(fn);
33
33
  if (classMiddleware) {
@@ -9,6 +9,10 @@ export declare class MidwayMockService {
9
9
  }>;
10
10
  protected cache: Map<any, any>;
11
11
  constructor(applicationContext: IMidwayContainer);
12
+ init(): Promise<void>;
13
+ static prepareMocks: any[];
14
+ static mockClassProperty(clzz: new (...args: any[]) => any, propertyName: string, value: any): void;
15
+ static mockProperty(obj: new (...args: any[]) => any, key: string, value: any): void;
12
16
  mockClassProperty(clzz: new (...args: any[]) => any, propertyName: string, value: any): void;
13
17
  mockProperty(obj: any, key: string, value: any): void;
14
18
  mockContext(app: IMidwayApplication, key: string | ((ctx: IMidwayContext) => void), value?: PropertyDescriptor | any): void;
@@ -16,7 +20,6 @@ export declare class MidwayMockService {
16
20
  isMocked(obj: any, key: any): any;
17
21
  applyContextMocks(app: IMidwayApplication, ctx: IMidwayContext): void;
18
22
  getContextMocksSize(): number;
19
- getMocksSize(): number;
20
23
  private overridePropertyDescriptor;
21
24
  }
22
25
  //# sourceMappingURL=mockService.d.ts.map
@@ -8,16 +8,35 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var MidwayMockService_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.MidwayMockService = void 0;
13
14
  const decorator_1 = require("@midwayjs/decorator");
14
- let MidwayMockService = class MidwayMockService {
15
+ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
15
16
  constructor(applicationContext) {
16
17
  this.applicationContext = applicationContext;
17
18
  this.mocks = [];
18
19
  this.contextMocks = [];
19
20
  this.cache = new Map();
20
21
  }
22
+ async init() {
23
+ if (MidwayMockService_1.prepareMocks.length > 0) {
24
+ for (const item of MidwayMockService_1.prepareMocks) {
25
+ this.mockProperty(item.obj, item.key, item.value);
26
+ }
27
+ MidwayMockService_1.prepareMocks = [];
28
+ }
29
+ }
30
+ static mockClassProperty(clzz, propertyName, value) {
31
+ this.mockProperty(clzz.prototype, propertyName, value);
32
+ }
33
+ static mockProperty(obj, key, value) {
34
+ this.prepareMocks.push({
35
+ obj,
36
+ key,
37
+ value,
38
+ });
39
+ }
21
40
  mockClassProperty(clzz, propertyName, value) {
22
41
  return this.mockProperty(clzz.prototype, propertyName, value);
23
42
  }
@@ -67,6 +86,7 @@ let MidwayMockService = class MidwayMockService {
67
86
  this.mocks = [];
68
87
  this.contextMocks = [];
69
88
  this.cache.clear();
89
+ MidwayMockService_1.prepareMocks = [];
70
90
  }
71
91
  isMocked(obj, key) {
72
92
  const flag = this.cache.get(obj);
@@ -90,9 +110,6 @@ let MidwayMockService = class MidwayMockService {
90
110
  getContextMocksSize() {
91
111
  return this.contextMocks.length;
92
112
  }
93
- getMocksSize() {
94
- return this.mocks.length;
95
- }
96
113
  overridePropertyDescriptor(value) {
97
114
  const descriptor = {
98
115
  configurable: true,
@@ -111,13 +128,20 @@ let MidwayMockService = class MidwayMockService {
111
128
  return descriptor;
112
129
  }
113
130
  };
131
+ MidwayMockService.prepareMocks = [];
132
+ __decorate([
133
+ (0, decorator_1.Init)(),
134
+ __metadata("design:type", Function),
135
+ __metadata("design:paramtypes", []),
136
+ __metadata("design:returntype", Promise)
137
+ ], MidwayMockService.prototype, "init", null);
114
138
  __decorate([
115
139
  (0, decorator_1.Destroy)(),
116
140
  __metadata("design:type", Function),
117
141
  __metadata("design:paramtypes", []),
118
142
  __metadata("design:returntype", void 0)
119
143
  ], MidwayMockService.prototype, "restore", null);
120
- MidwayMockService = __decorate([
144
+ MidwayMockService = MidwayMockService_1 = __decorate([
121
145
  (0, decorator_1.Provide)(),
122
146
  (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
123
147
  __metadata("design:paramtypes", [Object])
@@ -10,7 +10,11 @@ const getCurrentMainFramework = () => {
10
10
  };
11
11
  exports.getCurrentMainFramework = getCurrentMainFramework;
12
12
  const getCurrentMainApp = () => {
13
- return (0, exports.getCurrentMainFramework)().getApplication();
13
+ const framework = (0, exports.getCurrentMainFramework)();
14
+ if (framework) {
15
+ return framework.getApplication();
16
+ }
17
+ return undefined;
14
18
  };
15
19
  exports.getCurrentMainApp = getCurrentMainApp;
16
20
  //# sourceMappingURL=contextUtil.js.map
@@ -40,6 +40,13 @@ export declare function joinURLPath(...strArray: any[]): string;
40
40
  * @since 2.0.0
41
41
  */
42
42
  export declare function delegateTargetPrototypeMethod(derivedCtor: any, constructors: any[], otherMethods?: string[]): void;
43
+ /**
44
+ * 代理目标所有的原型方法,包括原型链,不包括构造器和内部隐藏方法
45
+ * @param derivedCtor
46
+ * @param constructor
47
+ * @since 3.0.0
48
+ */
49
+ export declare function delegateTargetAllPrototypeMethod(derivedCtor: any, constructor: any): void;
43
50
  /**
44
51
  * 代理目标原型上的特定方法
45
52
  * @param derivedCtor
@@ -55,7 +62,7 @@ export declare function delegateTargetMethod(derivedCtor: any, methods: string[]
55
62
  */
56
63
  export declare function delegateTargetProperties(derivedCtor: any, properties: string[]): void;
57
64
  /**
58
- * 代理目标原型属性
65
+ * 获取当前的时间戳
59
66
  * @since 2.0.0
60
67
  * @param timestamp
61
68
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
3
+ exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
4
4
  const path_1 = require("path");
5
5
  const fs_1 = require("fs");
6
6
  const util_1 = require("util");
@@ -117,19 +117,36 @@ exports.joinURLPath = joinURLPath;
117
117
  */
118
118
  function delegateTargetPrototypeMethod(derivedCtor, constructors, otherMethods) {
119
119
  constructors.forEach(baseCtor => {
120
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
121
- if (name !== 'constructor' && !/^_/.test(name)) {
122
- derivedCtor.prototype[name] = function (...args) {
123
- return this.instance[name](...args);
124
- };
125
- }
126
- });
120
+ if (baseCtor.prototype) {
121
+ Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
122
+ if (name !== 'constructor' &&
123
+ !/^_/.test(name) &&
124
+ !derivedCtor.prototype[name]) {
125
+ derivedCtor.prototype[name] = function (...args) {
126
+ return this.instance[name](...args);
127
+ };
128
+ }
129
+ });
130
+ }
127
131
  });
128
132
  if (otherMethods) {
129
133
  delegateTargetMethod(derivedCtor, otherMethods);
130
134
  }
131
135
  }
132
136
  exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
137
+ /**
138
+ * 代理目标所有的原型方法,包括原型链,不包括构造器和内部隐藏方法
139
+ * @param derivedCtor
140
+ * @param constructor
141
+ * @since 3.0.0
142
+ */
143
+ function delegateTargetAllPrototypeMethod(derivedCtor, constructor) {
144
+ do {
145
+ delegateTargetPrototypeMethod(derivedCtor, [constructor]);
146
+ constructor = Object.getPrototypeOf(constructor);
147
+ } while (constructor);
148
+ }
149
+ exports.delegateTargetAllPrototypeMethod = delegateTargetAllPrototypeMethod;
133
150
  /**
134
151
  * 代理目标原型上的特定方法
135
152
  * @param derivedCtor
@@ -161,7 +178,7 @@ function delegateTargetProperties(derivedCtor, properties) {
161
178
  }
162
179
  exports.delegateTargetProperties = delegateTargetProperties;
163
180
  /**
164
- * 代理目标原型属性
181
+ * 获取当前的时间戳
165
182
  * @since 2.0.0
166
183
  * @param timestamp
167
184
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.2.2",
3
+ "version": "3.3.2",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "6bc097035302d01ae901d76a10e080db8554a864"
48
+ "gitHead": "2c7c235421ba904f8943efe31a71f452089d5d53"
49
49
  }