@midwayjs/core 3.0.11 → 3.1.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.
@@ -1,5 +1,4 @@
1
1
  import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, CommonMiddleware, MiddlewareRespond } from './interface';
2
- import { FrameworkType } from '@midwayjs/decorator';
3
2
  import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
4
3
  import { MidwayEnvironmentService } from './service/environmentService';
5
4
  import { MidwayConfigService } from './service/configService';
@@ -47,7 +46,6 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
47
46
  getCurrentEnvironment(): string;
48
47
  getApplication(): APP;
49
48
  abstract applicationInitialize(options: IMidwayBootstrapOptions): any;
50
- abstract getFrameworkType(): FrameworkType;
51
49
  abstract run(): Promise<void>;
52
50
  protected createContextLogger(ctx: CTX, name?: string): ILogger;
53
51
  stop(): Promise<void>;
@@ -77,7 +75,7 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
77
75
  createLogger(name: string, option?: LoggerOptions): ILogger;
78
76
  getProjectName(): string;
79
77
  getFrameworkName(): string;
80
- useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
78
+ useMiddleware(middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
81
79
  getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
82
80
  useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): void;
83
81
  protected createMiddlewareManager(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
@@ -86,9 +86,36 @@ class BaseFramework {
86
86
  }
87
87
  createContextLogger(ctx, name) {
88
88
  const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.contextLoggerApplyLogger);
89
- return appLogger.createContextLogger(ctx, {
90
- contextFormat: this.contextLoggerFormat,
91
- });
89
+ if (name) {
90
+ let ctxLoggerCache = ctx.getAttr(interface_1.REQUEST_CTX_LOGGER_CACHE_KEY);
91
+ if (!ctxLoggerCache) {
92
+ ctxLoggerCache = new Map();
93
+ ctx.setAttr(interface_1.REQUEST_CTX_LOGGER_CACHE_KEY, ctxLoggerCache);
94
+ }
95
+ if (!name) {
96
+ name = 'appLogger';
97
+ }
98
+ // if logger exists
99
+ if (ctxLoggerCache.has(name)) {
100
+ return ctxLoggerCache.get(name);
101
+ }
102
+ // create new context logger
103
+ const ctxLogger = appLogger.createContextLogger(ctx, {
104
+ contextFormat: this.contextLoggerFormat,
105
+ });
106
+ ctxLoggerCache.set(name, ctxLogger);
107
+ return ctxLogger;
108
+ }
109
+ else {
110
+ // avoid maximum call stack size exceeded
111
+ if (ctx['_logger']) {
112
+ return ctx['_logger'];
113
+ }
114
+ ctx['_logger'] = appLogger.createContextLogger(ctx, {
115
+ contextFormat: this.contextLoggerFormat,
116
+ });
117
+ return ctx['_logger'];
118
+ }
92
119
  }
93
120
  async stop() {
94
121
  await this.beforeStop();
@@ -117,7 +144,9 @@ class BaseFramework {
117
144
  return this.getConfiguration(key);
118
145
  },
119
146
  getFrameworkType: () => {
120
- return this.getFrameworkType();
147
+ if (this['getFrameworkType']) {
148
+ return this['getFrameworkType']();
149
+ }
121
150
  },
122
151
  getProcessType: () => {
123
152
  return interface_1.MidwayProcessTypeEnum.APPLICATION;
@@ -241,10 +270,10 @@ class BaseFramework {
241
270
  return this.informationService.getProjectName();
242
271
  }
243
272
  getFrameworkName() {
244
- return this.getFrameworkType().name;
273
+ return '';
245
274
  }
246
- useMiddleware(Middleware) {
247
- this.middlewareManager.insertLast(Middleware);
275
+ useMiddleware(middleware) {
276
+ this.middlewareManager.insertLast(middleware);
248
277
  }
249
278
  getMiddleware() {
250
279
  return this.middlewareManager;
@@ -15,7 +15,9 @@ let MidwayApplicationManager = class MidwayApplicationManager {
15
15
  }
16
16
  addFramework(namespace, framework) {
17
17
  this.globalFrameworkMap.set(namespace, framework);
18
- this.globalFrameworkTypeMap.set(framework.getFrameworkType(), framework);
18
+ if (framework['getFrameworkType']) {
19
+ this.globalFrameworkTypeMap.set(framework['getFrameworkType'](), framework);
20
+ }
19
21
  }
20
22
  getFramework(namespaceOrFrameworkType) {
21
23
  if (typeof namespaceOrFrameworkType === 'string') {
@@ -8,7 +8,7 @@ export declare abstract class ServiceFactory<T> {
8
8
  get<U = T>(id?: string): U;
9
9
  createInstance(config: any, clientName?: any): Promise<T | void>;
10
10
  abstract getName(): string;
11
- protected abstract createClient(config: any, clientName: any): Promise<T | void>;
11
+ protected abstract createClient(config: any, clientName: any): Promise<T | void> | (T | void);
12
12
  protected destroyClient(client: T): Promise<void>;
13
13
  stop(): Promise<void>;
14
14
  }
@@ -2,6 +2,9 @@ import { MidwayAppInfo, ServiceFactoryConfigOption } from '../interface';
2
2
  import type { LoggerOptions } from '@midwayjs/logger';
3
3
  declare const _default: (appInfo: MidwayAppInfo) => {
4
4
  midwayLogger?: ServiceFactoryConfigOption<LoggerOptions>;
5
+ debug?: {
6
+ recordConfigMergeOrder?: boolean;
7
+ };
5
8
  };
6
9
  export default _default;
7
10
  //# sourceMappingURL=config.default.d.ts.map
@@ -6,12 +6,15 @@ const path_1 = require("path");
6
6
  exports.default = (appInfo) => {
7
7
  var _a;
8
8
  const isDevelopment = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
9
+ const logRoot = (_a = process.env[interface_1.MIDWAY_LOGGER_WRITEABLE_DIR]) !== null && _a !== void 0 ? _a : appInfo.root;
9
10
  return {
10
11
  midwayLogger: {
11
12
  default: {
12
- dir: (0, path_1.join)((_a = process.env[interface_1.MIDWAY_LOGGER_WRITEABLE_DIR]) !== null && _a !== void 0 ? _a : appInfo.root, 'logs', appInfo.name),
13
+ dir: (0, path_1.join)(logRoot, 'logs', appInfo.name),
13
14
  level: isDevelopment ? 'info' : 'warn',
14
15
  consoleLevel: isDevelopment ? 'info' : 'warn',
16
+ auditFileDir: (0, path_1.join)(logRoot, 'logs', appInfo.name, '.audit'),
17
+ errorDir: (0, path_1.join)(logRoot, 'logs', appInfo.name),
15
18
  },
16
19
  clients: {
17
20
  coreLogger: {
@@ -23,6 +26,9 @@ exports.default = (appInfo) => {
23
26
  },
24
27
  },
25
28
  },
29
+ debug: {
30
+ recordConfigMergeOrder: isDevelopment,
31
+ },
26
32
  };
27
33
  };
28
34
  //# sourceMappingURL=config.default.js.map
@@ -36,7 +36,7 @@ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
36
36
  protected getIdentifier(target: any): string;
37
37
  protected getManagedResolverFactory(): ManagedResolverFactory;
38
38
  stop(): Promise<void>;
39
- ready(): Promise<void>;
39
+ ready(): void;
40
40
  get<T>(identifier: {
41
41
  new (...args: any[]): T;
42
42
  }, args?: any[], objectContext?: ObjectContext): T;
@@ -293,10 +293,10 @@ class MidwayContainer {
293
293
  definition.scope = (options === null || options === void 0 ? void 0 : options.scope) || decorator_1.ScopeEnum.Request;
294
294
  definition.createFrom = options === null || options === void 0 ? void 0 : options.createFrom;
295
295
  if (definition.srcPath) {
296
- debug(`[core]: bind id "${definition.name} (${definition.srcPath})"`);
296
+ debug(`[core]: bind id "${definition.name} (${definition.srcPath}) ${identifier}"`);
297
297
  }
298
298
  else {
299
- debug(`[core]: bind id "${definition.name}"`);
299
+ debug(`[core]: bind id "${definition.name}" ${identifier}`);
300
300
  }
301
301
  // inject properties
302
302
  const props = (0, decorator_1.getPropertyInject)(target);
@@ -397,8 +397,8 @@ class MidwayContainer {
397
397
  await this.getManagedResolverFactory().destroyCache();
398
398
  this.registry.clearAll();
399
399
  }
400
- async ready() {
401
- await this.loadDefinitions();
400
+ ready() {
401
+ this.loadDefinitions();
402
402
  }
403
403
  get(identifier, args, objectContext) {
404
404
  var _a;
@@ -6,7 +6,7 @@ export declare class MidwayRequestContainer extends MidwayContainer {
6
6
  init(): void;
7
7
  get<T = any>(identifier: any, args?: any): T;
8
8
  getAsync<T = any>(identifier: any, args?: any): Promise<T>;
9
- ready(): Promise<void>;
9
+ ready(): void;
10
10
  getContext(): {};
11
11
  }
12
12
  //# sourceMappingURL=requestContainer.d.ts.map
@@ -67,7 +67,7 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
67
67
  return this.parent.getAsync(identifier, args);
68
68
  }
69
69
  }
70
- async ready() {
70
+ ready() {
71
71
  // ignore other things
72
72
  }
73
73
  getContext() {
@@ -182,6 +182,7 @@ export interface IManagedResolverFactoryCreateOptions {
182
182
  export declare const REQUEST_CTX_KEY = "ctx";
183
183
  export declare const REQUEST_OBJ_CTX_KEY = "_req_ctx";
184
184
  export declare const HTTP_SERVER_KEY = "_midway_http_server";
185
+ export declare const REQUEST_CTX_LOGGER_CACHE_KEY = "_midway_ctx_logger_cache";
185
186
  export declare type HandlerFunction = (
186
187
  /**
187
188
  * decorator uuid key
@@ -248,7 +249,7 @@ export interface IFileDetector {
248
249
  }
249
250
  export interface IConfigService {
250
251
  add(configFilePaths: any[]): any;
251
- addObject(obj: object): any;
252
+ addObject(obj: object, reverse?: boolean): any;
252
253
  load(): any;
253
254
  getConfiguration(configKey?: string): any;
254
255
  clearAllConfig(): any;
@@ -330,6 +331,7 @@ export interface IMidwayBaseApplication<CTX extends IMidwayContext> {
330
331
  */
331
332
  getEnv(): string;
332
333
  /**
334
+ * @deprecated
333
335
  * Get current framework type in MidwayFrameworkType enum
334
336
  */
335
337
  getFrameworkType(): FrameworkType;
@@ -424,6 +426,7 @@ export interface IMidwayBootstrapOptions {
424
426
  globalConfig?: Array<{
425
427
  [environmentName: string]: Record<string, any>;
426
428
  }> | Record<string, any>;
429
+ lazyInitializeFramework?: boolean;
427
430
  }
428
431
  export interface IConfigurationOptions {
429
432
  logger?: ILogger;
@@ -443,7 +446,6 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
443
446
  getApplicationContext(): IMidwayContainer;
444
447
  getConfiguration(key?: string): any;
445
448
  getCurrentEnvironment(): string;
446
- getFrameworkType(): FrameworkType;
447
449
  getFrameworkName(): string;
448
450
  getAppDir(): string;
449
451
  getBaseDir(): string;
package/dist/interface.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MIDWAY_LOGGER_WRITEABLE_DIR = exports.MidwayProcessTypeEnum = exports.HTTP_SERVER_KEY = exports.REQUEST_OBJ_CTX_KEY = exports.REQUEST_CTX_KEY = exports.ObjectLifeCycleEvent = void 0;
3
+ exports.MIDWAY_LOGGER_WRITEABLE_DIR = exports.MidwayProcessTypeEnum = exports.REQUEST_CTX_LOGGER_CACHE_KEY = exports.HTTP_SERVER_KEY = exports.REQUEST_OBJ_CTX_KEY = exports.REQUEST_CTX_KEY = exports.ObjectLifeCycleEvent = void 0;
4
4
  var ObjectLifeCycleEvent;
5
5
  (function (ObjectLifeCycleEvent) {
6
6
  ObjectLifeCycleEvent["BEFORE_BIND"] = "beforeBind";
@@ -12,6 +12,7 @@ var ObjectLifeCycleEvent;
12
12
  exports.REQUEST_CTX_KEY = 'ctx';
13
13
  exports.REQUEST_OBJ_CTX_KEY = '_req_ctx';
14
14
  exports.HTTP_SERVER_KEY = '_midway_http_server';
15
+ exports.REQUEST_CTX_LOGGER_CACHE_KEY = '_midway_ctx_logger_cache';
15
16
  var MidwayProcessTypeEnum;
16
17
  (function (MidwayProcessTypeEnum) {
17
18
  MidwayProcessTypeEnum["APPLICATION"] = "APPLICATION";
@@ -1,23 +1,32 @@
1
1
  import { IConfigService, MidwayAppInfo } from '../interface';
2
2
  import { MidwayEnvironmentService } from './environmentService';
3
3
  import { MidwayInformationService } from './informationService';
4
+ interface ConfigMergeInfo {
5
+ value: any;
6
+ env: string;
7
+ extraPath?: string;
8
+ }
4
9
  export declare class MidwayConfigService implements IConfigService {
5
10
  private envDirMap;
6
11
  private aliasMap;
12
+ private configMergeOrder;
7
13
  protected configuration: any;
8
14
  protected isReady: boolean;
9
15
  protected externalObject: Record<string, unknown>[];
10
16
  protected appInfo: MidwayAppInfo;
11
17
  protected environmentService: MidwayEnvironmentService;
12
18
  protected informationService: MidwayInformationService;
13
- protected init(): Promise<void>;
19
+ protected init(): void;
14
20
  add(configFilePaths: any[]): void;
15
- addObject(obj: Record<string, unknown>): void;
21
+ addObject(obj: Record<string, unknown>, reverse?: boolean): void;
16
22
  private getEnvSet;
17
23
  private getConfigEnv;
18
- load(): Promise<void>;
24
+ load(): void;
19
25
  getConfiguration(configKey?: string): any;
26
+ getConfigMergeOrder(): Array<ConfigMergeInfo>;
20
27
  private loadConfig;
21
28
  clearAllConfig(): void;
29
+ clearConfigMergeOrder(): void;
22
30
  }
31
+ export {};
23
32
  //# sourceMappingURL=configService.d.ts.map
@@ -26,10 +26,11 @@ let MidwayConfigService = class MidwayConfigService {
26
26
  prod: 'production',
27
27
  unittest: 'test',
28
28
  };
29
+ this.configMergeOrder = [];
29
30
  this.isReady = false;
30
31
  this.externalObject = [];
31
32
  }
32
- async init() {
33
+ init() {
33
34
  this.appInfo = {
34
35
  pkg: this.informationService.getPkg(),
35
36
  name: this.informationService.getProjectName(),
@@ -72,9 +73,19 @@ let MidwayConfigService = class MidwayConfigService {
72
73
  }
73
74
  }
74
75
  }
75
- addObject(obj) {
76
+ addObject(obj, reverse = false) {
76
77
  if (this.isReady) {
77
- (0, extend_1.extend)(true, this.configuration, obj);
78
+ this.configMergeOrder.push({
79
+ env: 'default',
80
+ extraPath: '',
81
+ value: obj,
82
+ });
83
+ if (reverse) {
84
+ this.configuration = (0, extend_1.extend)(true, obj, this.configuration);
85
+ }
86
+ else {
87
+ (0, extend_1.extend)(true, this.configuration, obj);
88
+ }
78
89
  }
79
90
  else {
80
91
  this.externalObject.push(obj);
@@ -96,7 +107,7 @@ let MidwayConfigService = class MidwayConfigService {
96
107
  }
97
108
  return splits.pop();
98
109
  }
99
- async load() {
110
+ load() {
100
111
  if (this.isReady)
101
112
  return;
102
113
  // get default
@@ -105,8 +116,9 @@ let MidwayConfigService = class MidwayConfigService {
105
116
  const currentEnvSet = this.getEnvSet(this.environmentService.getCurrentEnvironment());
106
117
  // merge set
107
118
  const target = {};
108
- for (const filename of [...defaultSet, ...currentEnvSet]) {
109
- let config = await this.loadConfig(filename);
119
+ const defaultSetLength = defaultSet.size;
120
+ for (const [idx, filename] of [...defaultSet, ...currentEnvSet].entries()) {
121
+ let config = this.loadConfig(filename);
110
122
  if (decorator_1.Types.isFunction(config)) {
111
123
  // eslint-disable-next-line prefer-spread
112
124
  config = config.apply(null, [this.appInfo, target]);
@@ -120,6 +132,13 @@ let MidwayConfigService = class MidwayConfigService {
120
132
  else {
121
133
  debug('[config]: Loaded config %j', config);
122
134
  }
135
+ this.configMergeOrder.push({
136
+ env: idx < defaultSetLength
137
+ ? 'default'
138
+ : this.environmentService.getCurrentEnvironment(),
139
+ extraPath: filename,
140
+ value: config,
141
+ });
123
142
  (0, extend_1.extend)(true, target, config);
124
143
  }
125
144
  if (this.externalObject.length) {
@@ -127,6 +146,11 @@ let MidwayConfigService = class MidwayConfigService {
127
146
  if (externalObject) {
128
147
  debug('[config]: Loaded external object %j', externalObject);
129
148
  (0, extend_1.extend)(true, target, externalObject);
149
+ this.configMergeOrder.push({
150
+ env: 'default',
151
+ extraPath: '',
152
+ value: externalObject,
153
+ });
130
154
  }
131
155
  }
132
156
  }
@@ -139,7 +163,10 @@ let MidwayConfigService = class MidwayConfigService {
139
163
  }
140
164
  return this.configuration;
141
165
  }
142
- async loadConfig(configFilename) {
166
+ getConfigMergeOrder() {
167
+ return this.configMergeOrder;
168
+ }
169
+ loadConfig(configFilename) {
143
170
  let exports = typeof configFilename === 'string'
144
171
  ? require(configFilename)
145
172
  : configFilename;
@@ -151,6 +178,9 @@ let MidwayConfigService = class MidwayConfigService {
151
178
  clearAllConfig() {
152
179
  this.configuration.clear();
153
180
  }
181
+ clearConfigMergeOrder() {
182
+ this.configMergeOrder.length = 0;
183
+ }
154
184
  };
155
185
  __decorate([
156
186
  (0, decorator_1.Inject)(),
@@ -164,7 +194,7 @@ __decorate([
164
194
  (0, decorator_1.Init)(),
165
195
  __metadata("design:type", Function),
166
196
  __metadata("design:paramtypes", []),
167
- __metadata("design:returntype", Promise)
197
+ __metadata("design:returntype", void 0)
168
198
  ], MidwayConfigService.prototype, "init", null);
169
199
  MidwayConfigService = __decorate([
170
200
  (0, decorator_1.Provide)(),
@@ -6,7 +6,7 @@ export declare class MidwayDecoratorService {
6
6
  private parameterDecoratorMap;
7
7
  private aspectService;
8
8
  constructor(applicationContext: IMidwayContainer);
9
- protected init(): Promise<void>;
9
+ protected init(): void;
10
10
  registerPropertyHandler(decoratorKey: string, fn: HandlerFunction): void;
11
11
  registerMethodHandler(decoratorKey: string, fn: MethodHandlerFunction): void;
12
12
  registerParameterHandler(decoratorKey: string, fn: ParameterHandlerFunction): void;
@@ -22,7 +22,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
22
22
  this.methodDecoratorMap = new Map();
23
23
  this.parameterDecoratorMap = new Map();
24
24
  }
25
- async init() {
25
+ init() {
26
26
  // add custom method decorator listener
27
27
  this.applicationContext.onBeforeBind(Clzz => {
28
28
  // find custom method decorator metadata, include method decorator information array
@@ -150,7 +150,7 @@ __decorate([
150
150
  (0, decorator_1.Init)(),
151
151
  __metadata("design:type", Function),
152
152
  __metadata("design:paramtypes", []),
153
- __metadata("design:returntype", Promise)
153
+ __metadata("design:returntype", void 0)
154
154
  ], MidwayDecoratorService.prototype, "init", null);
155
155
  MidwayDecoratorService = __decorate([
156
156
  (0, decorator_1.Provide)(),
@@ -58,6 +58,10 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
58
58
  await this.frameworkService.runFramework();
59
59
  // exec onServerReady()
60
60
  await this.runContainerLifeCycle(lifecycleInstanceList, 'onServerReady');
61
+ // clear config merge cache
62
+ if (!this.configService.getConfiguration('debug.recordConfigMergeOrder')) {
63
+ this.configService.clearConfigMergeOrder();
64
+ }
61
65
  }
62
66
  async stop() {
63
67
  // stop lifecycle
@@ -6,22 +6,10 @@ export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
6
6
  readonly applicationContext: IMidwayContainer;
7
7
  configService: MidwayConfigService;
8
8
  constructor(applicationContext: IMidwayContainer);
9
- protected init(): Promise<void>;
10
- protected transformEggConfig(): {
11
- midwayLogger: {
12
- default: {};
13
- clients: {};
14
- };
15
- };
16
- protected createClient(config: any, name?: string): Promise<void>;
9
+ protected init(): void;
10
+ protected createClient(config: any, name?: string): void;
17
11
  getName(): string;
18
12
  createLogger(name: any, config: any): ILogger;
19
13
  getLogger(name: string): ILogger;
20
- transformEggLogger(options: any): {
21
- midwayLogger: {
22
- default: {};
23
- clients: {};
24
- };
25
- };
26
14
  }
27
15
  //# sourceMappingURL=loggerService.d.ts.map
@@ -14,60 +14,18 @@ const decorator_1 = require("@midwayjs/decorator");
14
14
  const configService_1 = require("./configService");
15
15
  const serviceFactory_1 = require("../common/serviceFactory");
16
16
  const logger_1 = require("@midwayjs/logger");
17
- const levelTransform = level => {
18
- if (!level) {
19
- return undefined;
20
- }
21
- switch (level) {
22
- case 'NONE':
23
- case Infinity: // egg logger 的 none 是这个等级
24
- return 'none';
25
- case 0:
26
- case 'DEBUG':
27
- case 'debug':
28
- return 'debug';
29
- case 1:
30
- case 'INFO':
31
- case 'info':
32
- return 'info';
33
- case 2:
34
- case 'WARN':
35
- case 'warn':
36
- return 'warn';
37
- case 3:
38
- case 'ERROR':
39
- case 'error':
40
- return 'error';
41
- default:
42
- return 'silly';
43
- }
44
- };
45
17
  let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
46
18
  constructor(applicationContext) {
47
19
  super();
48
20
  this.applicationContext = applicationContext;
49
21
  }
50
- async init() {
22
+ init() {
51
23
  var _a;
52
- const eggLoggerConfig = this.transformEggConfig();
53
- if (eggLoggerConfig) {
54
- this.configService.addObject(eggLoggerConfig);
55
- }
56
- await this.initClients(this.configService.getConfiguration('midwayLogger'));
24
+ this.initClients(this.configService.getConfiguration('midwayLogger'));
57
25
  // alias inject logger
58
26
  (_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
59
27
  }
60
- transformEggConfig() {
61
- if (this.configService.getConfiguration('customLogger')) {
62
- // use egg module
63
- return this.transformEggLogger(this.configService.getConfiguration());
64
- }
65
- else {
66
- // it will be use other logger
67
- return;
68
- }
69
- }
70
- async createClient(config, name) {
28
+ createClient(config, name) {
71
29
  logger_1.loggers.createLogger(name, config);
72
30
  }
73
31
  getName() {
@@ -79,32 +37,6 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
79
37
  getLogger(name) {
80
38
  return logger_1.loggers.getLogger(name);
81
39
  }
82
- transformEggLogger(options) {
83
- var _a, _b, _c;
84
- const transformLoggerConfig = {
85
- midwayLogger: {
86
- default: {},
87
- clients: {},
88
- },
89
- };
90
- if (options.midwayLogger && !options.midwayLogger.default) {
91
- transformLoggerConfig.midwayLogger.default = {
92
- dir: options.logger.dir,
93
- level: levelTransform(options.logger.level),
94
- consoleLevel: levelTransform(options.logger.consoleLevel),
95
- };
96
- }
97
- const eggCustomLogger = options['customLogger'];
98
- for (const name in eggCustomLogger) {
99
- transformLoggerConfig.midwayLogger.clients[name] = {
100
- fileLogName: (_a = eggCustomLogger[name]) === null || _a === void 0 ? void 0 : _a.file,
101
- level: levelTransform((_b = eggCustomLogger[name]) === null || _b === void 0 ? void 0 : _b.level),
102
- consoleLevel: levelTransform((_c = eggCustomLogger[name]) === null || _c === void 0 ? void 0 : _c.consoleLevel),
103
- };
104
- cleanUndefinedProperty(transformLoggerConfig.midwayLogger.clients[name]);
105
- }
106
- return transformLoggerConfig;
107
- }
108
40
  };
109
41
  __decorate([
110
42
  (0, decorator_1.Inject)(),
@@ -114,7 +46,7 @@ __decorate([
114
46
  (0, decorator_1.Init)(),
115
47
  __metadata("design:type", Function),
116
48
  __metadata("design:paramtypes", []),
117
- __metadata("design:returntype", Promise)
49
+ __metadata("design:returntype", void 0)
118
50
  ], MidwayLoggerService.prototype, "init", null);
119
51
  MidwayLoggerService = __decorate([
120
52
  (0, decorator_1.Provide)(),
@@ -122,11 +54,4 @@ MidwayLoggerService = __decorate([
122
54
  __metadata("design:paramtypes", [Object])
123
55
  ], MidwayLoggerService);
124
56
  exports.MidwayLoggerService = MidwayLoggerService;
125
- function cleanUndefinedProperty(obj) {
126
- Object.keys(obj).forEach(key => {
127
- if (obj[key] === undefined) {
128
- delete obj[key];
129
- }
130
- });
131
- }
132
57
  //# sourceMappingURL=loggerService.js.map
package/dist/setup.js CHANGED
@@ -53,18 +53,16 @@ async function initializeGlobalApplicationContext(globalOptions) {
53
53
  }
54
54
  }
55
55
  // init default config
56
- const configService = await applicationContext.getAsync(_1.MidwayConfigService);
56
+ const configService = applicationContext.get(_1.MidwayConfigService);
57
57
  configService.add([
58
58
  {
59
59
  default: config_default_1.default,
60
60
  },
61
61
  ]);
62
62
  // init aop support
63
- await applicationContext.getAsync(_1.MidwayAspectService, [applicationContext]);
63
+ applicationContext.get(_1.MidwayAspectService, [applicationContext]);
64
64
  // init decorator service
65
- await applicationContext.getAsync(_1.MidwayDecoratorService, [
66
- applicationContext,
67
- ]);
65
+ applicationContext.get(_1.MidwayDecoratorService, [applicationContext]);
68
66
  if (!globalOptions.imports) {
69
67
  globalOptions.imports = [
70
68
  (0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
@@ -77,7 +75,7 @@ async function initializeGlobalApplicationContext(globalOptions) {
77
75
  applicationContext.load(configurationModule);
78
76
  }
79
77
  // bind user code module
80
- await applicationContext.ready();
78
+ applicationContext.ready();
81
79
  if (globalOptions.globalConfig) {
82
80
  if (Array.isArray(globalOptions.globalConfig)) {
83
81
  configService.add(globalOptions.globalConfig);
@@ -87,23 +85,26 @@ async function initializeGlobalApplicationContext(globalOptions) {
87
85
  }
88
86
  }
89
87
  // merge config
90
- await configService.load();
88
+ configService.load();
91
89
  debug('[core]: Current config = %j', configService.getConfiguration());
92
- // init logger
93
- await applicationContext.getAsync(_1.MidwayLoggerService, [applicationContext]);
94
90
  // middleware support
95
- await applicationContext.getAsync(_1.MidwayMiddlewareService, [
96
- applicationContext,
97
- ]);
98
- // framework/config/plugin/logger/app decorator support
99
- await applicationContext.getAsync(_1.MidwayFrameworkService, [
100
- applicationContext,
101
- globalOptions,
102
- ]);
103
- // lifecycle support
104
- await applicationContext.getAsync(_1.MidwayLifeCycleService, [
105
- applicationContext,
106
- ]);
91
+ applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
92
+ // it will be delay framework initialize in egg cluster mode
93
+ if (!globalOptions.lazyInitializeFramework) {
94
+ // init logger
95
+ await applicationContext.getAsync(_1.MidwayLoggerService, [
96
+ applicationContext,
97
+ ]);
98
+ // framework/config/plugin/logger/app decorator support
99
+ await applicationContext.getAsync(_1.MidwayFrameworkService, [
100
+ applicationContext,
101
+ globalOptions,
102
+ ]);
103
+ // lifecycle support
104
+ await applicationContext.getAsync(_1.MidwayLifeCycleService, [
105
+ applicationContext,
106
+ ]);
107
+ }
107
108
  return applicationContext;
108
109
  }
109
110
  exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
@@ -190,7 +190,8 @@ exports.deprecatedOutput = deprecatedOutput;
190
190
  const transformRequestObjectByType = (originValue, targetType) => {
191
191
  if (targetType === undefined ||
192
192
  targetType === null ||
193
- targetType === Object) {
193
+ targetType === Object ||
194
+ typeof originValue === 'undefined') {
194
195
  return originValue;
195
196
  }
196
197
  switch (targetType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.0.11",
3
+ "version": "3.1.0",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "koa": "2.13.4",
26
26
  "midway-test-component": "*",
27
27
  "mm": "3.2.0",
28
- "raw-body": "2.5.0",
28
+ "raw-body": "2.5.1",
29
29
  "sinon": "13.0.1"
30
30
  },
31
31
  "peerDependencies": {
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "a85e2c88a19b0c0e5d2990d04a3c3c1754e2392d"
48
+ "gitHead": "2074c838e454a9673a044dbe065631dd9f944005"
49
49
  }