@midwayjs/core 3.2.0 → 3.3.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.
@@ -7,6 +7,7 @@ import { MidwayLoggerService } from './service/loggerService';
7
7
  import { ContextMiddlewareManager } from './common/middlewareManager';
8
8
  import { MidwayMiddlewareService } from './service/middlewareService';
9
9
  import { FilterManager } from './common/filterManager';
10
+ import { MidwayMockService } from './service/mockService';
10
11
  export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, OPT extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> implements IMidwayFramework<APP, CTX, OPT, ResOrNext, Next> {
11
12
  readonly applicationContext: IMidwayContainer;
12
13
  app: APP;
@@ -24,6 +25,7 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
24
25
  configService: MidwayConfigService;
25
26
  informationService: MidwayInformationService;
26
27
  middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
28
+ mockService: MidwayMockService;
27
29
  constructor(applicationContext: IMidwayContainer);
28
30
  init(): Promise<this>;
29
31
  abstract configure(options?: OPT): any;
@@ -20,6 +20,7 @@ const loggerService_1 = require("./service/loggerService");
20
20
  const middlewareManager_1 = require("./common/middlewareManager");
21
21
  const middlewareService_1 = require("./service/middlewareService");
22
22
  const filterManager_1 = require("./common/filterManager");
23
+ const mockService_1 = require("./service/mockService");
23
24
  const util = require("util");
24
25
  const debug = util.debuglog('midway:debug');
25
26
  class BaseFramework {
@@ -232,6 +233,7 @@ class BaseFramework {
232
233
  async applyMiddleware(lastMiddleware) {
233
234
  if (!this.composeMiddleware) {
234
235
  this.middlewareManager.insertFirst((async (ctx, next) => {
236
+ this.mockService.applyContextMocks(this.app, ctx);
235
237
  let returnResult = undefined;
236
238
  try {
237
239
  const result = await next();
@@ -270,7 +272,7 @@ class BaseFramework {
270
272
  return this.informationService.getProjectName();
271
273
  }
272
274
  getFrameworkName() {
273
- return '';
275
+ return this.constructor.name;
274
276
  }
275
277
  useMiddleware(middleware) {
276
278
  this.middlewareManager.insertLast(middleware);
@@ -308,6 +310,10 @@ __decorate([
308
310
  (0, decorator_1.Inject)(),
309
311
  __metadata("design:type", middlewareService_1.MidwayMiddlewareService)
310
312
  ], BaseFramework.prototype, "middlewareService", void 0);
313
+ __decorate([
314
+ (0, decorator_1.Inject)(),
315
+ __metadata("design:type", mockService_1.MidwayMockService)
316
+ ], BaseFramework.prototype, "mockService", void 0);
311
317
  __decorate([
312
318
  (0, decorator_1.Init)(),
313
319
  __metadata("design:type", Function),
@@ -32,7 +32,12 @@ class RefResolver {
32
32
  const mr = managed;
33
33
  if (mr.injectMode === decorator_1.InjectModeEnum.Class &&
34
34
  !((_a = this.factory.context.parent) !== null && _a !== void 0 ? _a : this.factory.context).hasDefinition(mr.name)) {
35
- throw new error_1.MidwayMissingImportComponentError(originName);
35
+ if (originName === 'loggerService') {
36
+ throw new error_1.MidwayInconsistentVersionError();
37
+ }
38
+ else {
39
+ throw new error_1.MidwayMissingImportComponentError(originName);
40
+ }
36
41
  }
37
42
  return this.factory.context.get(mr.name, mr.args, {
38
43
  originName,
@@ -43,7 +48,12 @@ class RefResolver {
43
48
  const mr = managed;
44
49
  if (mr.injectMode === decorator_1.InjectModeEnum.Class &&
45
50
  !((_a = this.factory.context.parent) !== null && _a !== void 0 ? _a : this.factory.context).hasDefinition(mr.name)) {
46
- throw new error_1.MidwayMissingImportComponentError(originName);
51
+ if (originName === 'loggerService') {
52
+ throw new error_1.MidwayInconsistentVersionError();
53
+ }
54
+ else {
55
+ throw new error_1.MidwayMissingImportComponentError(originName);
56
+ }
47
57
  }
48
58
  return this.factory.context.getAsync(mr.name, mr.args, {
49
59
  originName,
@@ -14,6 +14,7 @@ export declare const FrameworkErrorEnum: {
14
14
  readonly SINGLETON_INJECT_REQUEST: "MIDWAY_10010";
15
15
  readonly MISSING_IMPORTS: "MIDWAY_10011";
16
16
  readonly UTIL_HTTP_TIMEOUT: "MIDWAY_10012";
17
+ readonly INCONSISTENT_VERSION: "MIDWAY_10013";
17
18
  };
18
19
  export declare class MidwayCommonError extends MidwayError {
19
20
  constructor(message: string);
@@ -54,4 +55,7 @@ export declare class MidwayMissingImportComponentError extends MidwayError {
54
55
  export declare class MidwayUtilHttpClientTimeoutError extends MidwayError {
55
56
  constructor(message: string);
56
57
  }
58
+ export declare class MidwayInconsistentVersionError extends MidwayError {
59
+ constructor();
60
+ }
57
61
  //# sourceMappingURL=framework.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
3
+ exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
4
4
  const base_1 = require("./base");
5
5
  exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
6
6
  UNKNOWN: 10000,
@@ -16,6 +16,7 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
16
16
  SINGLETON_INJECT_REQUEST: 10010,
17
17
  MISSING_IMPORTS: 10011,
18
18
  UTIL_HTTP_TIMEOUT: 10012,
19
+ INCONSISTENT_VERSION: 10013,
19
20
  });
20
21
  class MidwayCommonError extends base_1.MidwayError {
21
22
  constructor(message) {
@@ -107,4 +108,11 @@ class MidwayUtilHttpClientTimeoutError extends base_1.MidwayError {
107
108
  }
108
109
  }
109
110
  exports.MidwayUtilHttpClientTimeoutError = MidwayUtilHttpClientTimeoutError;
111
+ class MidwayInconsistentVersionError extends base_1.MidwayError {
112
+ constructor() {
113
+ const text = 'We find a latest dependency package installed, please remove the lock file and use "npm update" to upgrade all dependencies first.';
114
+ super(text, exports.FrameworkErrorEnum.INCONSISTENT_VERSION);
115
+ }
116
+ }
117
+ exports.MidwayInconsistentVersionError = MidwayInconsistentVersionError;
110
118
  //# sourceMappingURL=framework.js.map
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';
@@ -20,6 +20,7 @@ export { MidwayAspectService } from './service/aspectService';
20
20
  export { MidwayLifeCycleService } from './service/lifeCycleService';
21
21
  export { MidwayMiddlewareService } from './service/middlewareService';
22
22
  export { MidwayDecoratorService } from './service/decoratorService';
23
+ export { MidwayMockService } from './service/mockService';
23
24
  export * from './service/pipelineService';
24
25
  export * from './util/contextUtil';
25
26
  export * from './common/serviceFactory';
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.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; } });
@@ -59,6 +60,8 @@ var middlewareService_1 = require("./service/middlewareService");
59
60
  Object.defineProperty(exports, "MidwayMiddlewareService", { enumerable: true, get: function () { return middlewareService_1.MidwayMiddlewareService; } });
60
61
  var decoratorService_1 = require("./service/decoratorService");
61
62
  Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get: function () { return decoratorService_1.MidwayDecoratorService; } });
63
+ var mockService_1 = require("./service/mockService");
64
+ Object.defineProperty(exports, "MidwayMockService", { enumerable: true, get: function () { return mockService_1.MidwayMockService; } });
62
65
  __exportStar(require("./service/pipelineService"), exports);
63
66
  __exportStar(require("./util/contextUtil"), exports);
64
67
  __exportStar(require("./common/serviceFactory"), exports);
@@ -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
  }
@@ -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()) {
@@ -18,6 +18,7 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
18
18
  this.applicationContext = applicationContext;
19
19
  }
20
20
  async compose(middleware, app, name) {
21
+ var _a, _b;
21
22
  if (!Array.isArray(middleware)) {
22
23
  throw new error_1.MidwayParameterError('Middleware stack must be an array');
23
24
  }
@@ -26,7 +27,7 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
26
27
  if (decorator_1.Types.isClass(fn) || typeof fn === 'string') {
27
28
  if (typeof fn === 'string' &&
28
29
  !this.applicationContext.hasDefinition(fn)) {
29
- 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`);
30
31
  }
31
32
  const classMiddleware = await this.applicationContext.getAsync(fn);
32
33
  if (classMiddleware) {
@@ -42,8 +43,8 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
42
43
  // wrap ignore and match
43
44
  const mw = fn;
44
45
  const match = (0, util_1.pathMatching)({
45
- match: classMiddleware.match,
46
- ignore: classMiddleware.ignore,
46
+ match: (_a = classMiddleware.match) === null || _a === void 0 ? void 0 : _a.bind(classMiddleware),
47
+ ignore: (_b = classMiddleware.ignore) === null || _b === void 0 ? void 0 : _b.bind(classMiddleware),
47
48
  });
48
49
  fn = (ctx, next, options) => {
49
50
  if (!match(ctx))
@@ -0,0 +1,25 @@
1
+ import { IMidwayApplication, IMidwayContainer, IMidwayContext } from '../interface';
2
+ export declare class MidwayMockService {
3
+ readonly applicationContext: IMidwayContainer;
4
+ protected mocks: any[];
5
+ protected contextMocks: Array<{
6
+ app: IMidwayApplication;
7
+ key: string | ((ctx: IMidwayContext) => void);
8
+ value: any;
9
+ }>;
10
+ protected cache: Map<any, any>;
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;
16
+ mockClassProperty(clzz: new (...args: any[]) => any, propertyName: string, value: any): void;
17
+ mockProperty(obj: any, key: string, value: any): void;
18
+ mockContext(app: IMidwayApplication, key: string | ((ctx: IMidwayContext) => void), value?: PropertyDescriptor | any): void;
19
+ restore(): void;
20
+ isMocked(obj: any, key: any): any;
21
+ applyContextMocks(app: IMidwayApplication, ctx: IMidwayContext): void;
22
+ getContextMocksSize(): number;
23
+ private overridePropertyDescriptor;
24
+ }
25
+ //# sourceMappingURL=mockService.d.ts.map
@@ -0,0 +1,150 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var MidwayMockService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.MidwayMockService = void 0;
14
+ const decorator_1 = require("@midwayjs/decorator");
15
+ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
16
+ constructor(applicationContext) {
17
+ this.applicationContext = applicationContext;
18
+ this.mocks = [];
19
+ this.contextMocks = [];
20
+ this.cache = new Map();
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
+ }
40
+ mockClassProperty(clzz, propertyName, value) {
41
+ return this.mockProperty(clzz.prototype, propertyName, value);
42
+ }
43
+ mockProperty(obj, key, value) {
44
+ // eslint-disable-next-line no-prototype-builtins
45
+ const hasOwnProperty = obj.hasOwnProperty(key);
46
+ this.mocks.push({
47
+ obj,
48
+ key,
49
+ descriptor: Object.getOwnPropertyDescriptor(obj, key),
50
+ // Make sure the key exists on object not the prototype
51
+ hasOwnProperty,
52
+ });
53
+ // Delete the origin key, redefine it below
54
+ if (hasOwnProperty) {
55
+ delete obj[key];
56
+ }
57
+ // Set a flag that checks if it is mocked
58
+ let flag = this.cache.get(obj);
59
+ if (!flag) {
60
+ flag = new Set();
61
+ this.cache.set(obj, flag);
62
+ }
63
+ flag.add(key);
64
+ const descriptor = this.overridePropertyDescriptor(value);
65
+ Object.defineProperty(obj, key, descriptor);
66
+ }
67
+ mockContext(app, key, value) {
68
+ this.contextMocks.push({
69
+ app,
70
+ key,
71
+ value,
72
+ });
73
+ }
74
+ restore() {
75
+ for (let i = this.mocks.length - 1; i >= 0; i--) {
76
+ const m = this.mocks[i];
77
+ if (!m.hasOwnProperty) {
78
+ // Delete the mock key, use key on the prototype
79
+ delete m.obj[m.key];
80
+ }
81
+ else {
82
+ // Redefine the origin key instead of the mock key
83
+ Object.defineProperty(m.obj, m.key, m.descriptor);
84
+ }
85
+ }
86
+ this.mocks = [];
87
+ this.contextMocks = [];
88
+ this.cache.clear();
89
+ MidwayMockService_1.prepareMocks = [];
90
+ }
91
+ isMocked(obj, key) {
92
+ const flag = this.cache.get(obj);
93
+ return flag ? flag.has(key) : false;
94
+ }
95
+ applyContextMocks(app, ctx) {
96
+ if (this.contextMocks.length > 0) {
97
+ for (const mockItem of this.contextMocks) {
98
+ if (mockItem.app === app) {
99
+ const descriptor = this.overridePropertyDescriptor(mockItem.value);
100
+ if (typeof mockItem.key === 'string') {
101
+ Object.defineProperty(ctx, mockItem.key, descriptor);
102
+ }
103
+ else {
104
+ mockItem.key(ctx);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ getContextMocksSize() {
111
+ return this.contextMocks.length;
112
+ }
113
+ overridePropertyDescriptor(value) {
114
+ const descriptor = {
115
+ configurable: true,
116
+ enumerable: true,
117
+ };
118
+ if (value && (value.get || value.set)) {
119
+ // Default to undefined
120
+ descriptor.get = value.get;
121
+ descriptor.set = value.set;
122
+ }
123
+ else {
124
+ // Without getter/setter mode
125
+ descriptor.value = value;
126
+ descriptor.writable = true;
127
+ }
128
+ return descriptor;
129
+ }
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);
138
+ __decorate([
139
+ (0, decorator_1.Destroy)(),
140
+ __metadata("design:type", Function),
141
+ __metadata("design:paramtypes", []),
142
+ __metadata("design:returntype", void 0)
143
+ ], MidwayMockService.prototype, "restore", null);
144
+ MidwayMockService = MidwayMockService_1 = __decorate([
145
+ (0, decorator_1.Provide)(),
146
+ (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
147
+ __metadata("design:paramtypes", [Object])
148
+ ], MidwayMockService);
149
+ exports.MidwayMockService = MidwayMockService;
150
+ //# sourceMappingURL=mockService.js.map
package/dist/setup.js CHANGED
@@ -94,6 +94,7 @@ function prepareGlobalApplicationContext(globalOptions) {
94
94
  applicationContext.bindClass(_1.MidwayFrameworkService);
95
95
  applicationContext.bindClass(_1.MidwayMiddlewareService);
96
96
  applicationContext.bindClass(_1.MidwayLifeCycleService);
97
+ applicationContext.bindClass(_1.MidwayMockService);
97
98
  // bind preload module
98
99
  if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
99
100
  for (const preloadModule of globalOptions.preloadModules) {
@@ -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.0",
3
+ "version": "3.3.1",
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": "cee3e5ddbb4f0cc5f80176a7b1e271e809686a97"
48
+ "gitHead": "f603b622b205ec126de628eeab59f90045a75dd2"
49
49
  }