@midwayjs/core 3.0.0-alpha.10 → 3.0.0-alpha.37

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +3 -17
  2. package/dist/baseFramework.js +30 -44
  3. package/dist/common/reflectTool.d.ts +3 -1
  4. package/dist/context/container.d.ts +48 -24
  5. package/dist/context/container.js +212 -215
  6. package/dist/context/definitionRegistry.d.ts +26 -0
  7. package/dist/context/definitionRegistry.js +124 -0
  8. package/dist/context/managedResolverFactory.d.ts +15 -19
  9. package/dist/context/managedResolverFactory.js +27 -256
  10. package/dist/context/providerWrapper.d.ts +2 -3
  11. package/dist/context/requestContainer.js +7 -10
  12. package/dist/context/resolverHandler.d.ts +2 -2
  13. package/dist/context/resolverHandler.js +2 -2
  14. package/dist/definitions/functionDefinition.d.ts +0 -2
  15. package/dist/definitions/functionDefinition.js +0 -6
  16. package/dist/definitions/objectCreator.js +6 -6
  17. package/dist/definitions/objectDefinition.d.ts +1 -4
  18. package/dist/definitions/objectDefinition.js +0 -8
  19. package/dist/definitions/properties.d.ts +0 -2
  20. package/dist/definitions/properties.js +5 -21
  21. package/dist/definitions/resource.js +13 -13
  22. package/dist/features/pipeline.d.ts +3 -3
  23. package/dist/features/pipeline.js +1 -1
  24. package/dist/functional/configuration.d.ts +2 -0
  25. package/dist/functional/configuration.js +10 -0
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -23
  28. package/dist/interface.d.ts +21 -32
  29. package/dist/logger.js +4 -4
  30. package/dist/service/aspectService.js +9 -4
  31. package/dist/service/configService.d.ts +4 -4
  32. package/dist/service/configService.js +32 -20
  33. package/dist/service/environmentService.js +2 -2
  34. package/dist/service/informationService.js +4 -4
  35. package/dist/util/containerUtil.d.ts +3 -1
  36. package/dist/util/containerUtil.js +3 -3
  37. package/dist/util/contextUtil.js +2 -2
  38. package/dist/util/fileDetector.js +2 -2
  39. package/dist/util/index.js +3 -3
  40. package/dist/util/pathFileUtil.js +2 -2
  41. package/dist/util/serviceFactory.d.ts +4 -2
  42. package/dist/util/serviceFactory.js +11 -3
  43. package/dist/util/webRouterCollector.d.ts +8 -0
  44. package/dist/util/webRouterCollector.js +72 -128
  45. package/package.json +6 -5
  46. package/dist/context/applicationContext.d.ts +0 -81
  47. package/dist/context/applicationContext.js +0 -263
  48. package/dist/context/managed.d.ts +0 -45
  49. package/dist/context/managed.js +0 -69
  50. package/dist/util/staticConfig.d.ts +0 -10
  51. package/dist/util/staticConfig.js +0 -67
package/CHANGELOG.md CHANGED
@@ -3,26 +3,12 @@
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-alpha.2](https://github.com/midwayjs/midway/compare/v3.0.0-alpha.1...v3.0.0-alpha.2) (2021-08-05)
6
+ ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
7
 
8
8
 
9
- ### Bug Fixes
10
-
11
- * npe ([b54305c](https://github.com/midwayjs/midway/commit/b54305c500ebead7e98ca8cd21f6e0738a1a050d))
12
- * proxy ([e1601af](https://github.com/midwayjs/midway/commit/e1601afb24b91887736ea32a576019ba3224bf62))
13
-
14
-
15
-
16
-
17
-
18
- # [3.0.0-alpha.1](https://github.com/midwayjs/midway/compare/v2.12.1...v3.0.0-alpha.1) (2021-08-04)
19
-
20
-
21
- ### Bug Fixes
9
+ ### Features
22
10
 
23
- * refactor directory file detector ([259a142](https://github.com/midwayjs/midway/commit/259a1425024acc172a40df474173fd34c35c70d1))
24
- * refactor directory file detector ([f869942](https://github.com/midwayjs/midway/commit/f869942589a4985dfc59457fa80b536be7bdc19f))
25
- * remove check ([6a52e19](https://github.com/midwayjs/midway/commit/6a52e197bd3ae2274b7ced3f1704972f5f4058f2))
11
+ * support object config load and async config ([#1212](https://github.com/midwayjs/midway/issues/1212)) ([a035ccb](https://github.com/midwayjs/midway/commit/a035ccbb513b0ba423bd2b48bc228b5e916c89e8))
26
12
 
27
13
 
28
14
 
@@ -74,11 +74,11 @@ class BaseFramework {
74
74
  }
75
75
  async initializeLogger(options) {
76
76
  if (!this.logger) {
77
- this.logger = new Proxy(logger_2.createMidwayLogger(this, 'coreLogger'), {});
77
+ this.logger = new Proxy((0, logger_2.createMidwayLogger)(this, 'coreLogger'), {});
78
78
  this.logger.updateDefaultLabel(this.getFrameworkName());
79
79
  }
80
80
  if (!this.appLogger) {
81
- this.appLogger = logger_2.createMidwayLogger(this, 'logger', {
81
+ this.appLogger = (0, logger_2.createMidwayLogger)(this, 'logger', {
82
82
  fileLogName: 'midway-app.log',
83
83
  });
84
84
  }
@@ -91,7 +91,7 @@ class BaseFramework {
91
91
  this.applicationContext = options.applicationContext;
92
92
  }
93
93
  else {
94
- this.applicationContext = containerUtil_1.createDirectoryGlobContainer({
94
+ this.applicationContext = (0, containerUtil_1.createDirectoryGlobContainer)({
95
95
  baseDir: options.baseDir,
96
96
  });
97
97
  }
@@ -107,11 +107,6 @@ class BaseFramework {
107
107
  await this.initializeLogger(options);
108
108
  }
109
109
  async containerDirectoryLoad(options) {
110
- if (options.applicationContext) {
111
- // 如果有传入全局容器,就不需要再次扫描了
112
- return;
113
- }
114
- // 废弃 deprecated
115
110
  if (options.preloadModules && options.preloadModules.length) {
116
111
  for (const preloadModule of options.preloadModules) {
117
112
  this.applicationContext.bindClass(preloadModule);
@@ -272,40 +267,40 @@ class BaseFramework {
272
267
  // agent 不加载生命周期
273
268
  if (this.app.getProcessType() === interface_1.MidwayProcessTypeEnum.AGENT)
274
269
  return;
275
- const cycles = decorator_1.listModule(decorator_1.CONFIGURATION_KEY);
270
+ const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
271
+ const lifecycleInstanceList = [];
276
272
  for (const cycle of cycles) {
277
- let inst;
278
273
  if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
279
274
  // 函数式写法
280
- inst = cycle.target;
275
+ cycle.instance = cycle.target;
281
276
  }
282
277
  else {
283
278
  // 普通类写法
284
- const providerId = decorator_1.getProviderId(cycle.target);
285
- inst = await this.getApplicationContext().getAsync(providerId);
279
+ const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
280
+ if (this.getApplicationContext().registry.hasDefinition(providerId)) {
281
+ cycle.instance =
282
+ await this.getApplicationContext().getAsync(providerId);
283
+ }
286
284
  }
287
- if (typeof inst.onReady === 'function') {
288
- /**
289
- * 让组件能正确获取到 bind 之后 registerObject 的对象有三个方法
290
- * 1、在 load 之后修改 bind,不太可行
291
- * 2、每次 getAsync 的时候,去掉 namespace,同时还要查找当前全局的变量,性能差
292
- * 3、一般只会在 onReady 的地方执行 registerObject(否则没有全局的意义),这个取巧的办法就是 onReady 传入一个代理,其中绑定当前的 namespace
293
- */
294
- await inst.onReady(new Proxy(this.getApplicationContext(), {
295
- get: function (target, prop, receiver) {
296
- if (prop === 'getCurrentNamespace' && cycle.namespace) {
297
- return () => {
298
- return cycle.namespace;
299
- };
300
- }
301
- return Reflect.get(target, prop, receiver);
302
- },
303
- }), this.app);
285
+ cycle.instance && lifecycleInstanceList.push(cycle);
286
+ }
287
+ // exec onConfigLoad()
288
+ for (const cycle of lifecycleInstanceList) {
289
+ if (typeof cycle.instance.onConfigLoad === 'function') {
290
+ const configData = await cycle.instance.onConfigLoad(this.getApplicationContext());
291
+ if (configData) {
292
+ this.getApplicationContext().getConfigService().addObject(configData);
293
+ }
294
+ }
295
+ }
296
+ for (const cycle of lifecycleInstanceList) {
297
+ if (typeof cycle.instance.onReady === 'function') {
298
+ await cycle.instance.onReady(this.getApplicationContext(), this.app);
304
299
  }
305
300
  }
306
301
  }
307
302
  async stopLifeCycles() {
308
- const cycles = decorator_1.listModule(decorator_1.CONFIGURATION_KEY);
303
+ const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
309
304
  for (const cycle of cycles) {
310
305
  let inst;
311
306
  if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
@@ -313,20 +308,11 @@ class BaseFramework {
313
308
  inst = cycle.target;
314
309
  }
315
310
  else {
316
- const providerId = decorator_1.getProviderId(cycle.target);
311
+ const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
317
312
  inst = await this.applicationContext.getAsync(providerId);
318
313
  }
319
314
  if (inst.onStop && typeof inst.onStop === 'function') {
320
- await inst.onStop(new Proxy(this.getApplicationContext(), {
321
- get: function (target, prop, receiver) {
322
- if (prop === 'getCurrentNamespace' && cycle.namespace) {
323
- return () => {
324
- return cycle.namespace;
325
- };
326
- }
327
- return Reflect.get(target, prop, receiver);
328
- },
329
- }), this.app);
315
+ await inst.onStop(this.getApplicationContext(), this.app);
330
316
  }
331
317
  }
332
318
  }
@@ -336,7 +322,7 @@ class BaseFramework {
336
322
  */
337
323
  async loadPreloadModule() {
338
324
  // some common decorator implementation
339
- const modules = decorator_1.listPreloadModule();
325
+ const modules = (0, decorator_1.listPreloadModule)();
340
326
  for (const module of modules) {
341
327
  // preload init context
342
328
  await this.applicationContext.getAsync(module);
@@ -350,7 +336,7 @@ class BaseFramework {
350
336
  return this.logger;
351
337
  }
352
338
  createLogger(name, option = {}) {
353
- return logger_2.createMidwayLogger(this, name, option);
339
+ return (0, logger_2.createMidwayLogger)(this, name, option);
354
340
  }
355
341
  getProjectName() {
356
342
  return this.applicationContext.getInformationService().getProjectName();
@@ -1,5 +1,7 @@
1
1
  import 'reflect-metadata';
2
- import { ReflectResult } from '@midwayjs/decorator';
2
+ export interface ReflectResult {
3
+ [key: string]: any[];
4
+ }
3
5
  /**
4
6
  * 以数组形式返回对象所有 property, 数组第一个元素是距离 o 最近的原型
5
7
  * @param target 对象,class 或者 function
@@ -1,20 +1,15 @@
1
+ /// <reference types="node" />
1
2
  import { ObjectDefinitionOptions, ObjectIdentifier } from '@midwayjs/decorator';
2
- import { BaseApplicationContext } from './applicationContext';
3
- import { IConfigService, IEnvironmentService, IFileDetector, IInformationService, IMidwayContainer, IObjectDefinitionMetadata } from '../interface';
3
+ import * as util from 'util';
4
+ import { IConfigService, IEnvironmentService, IFileDetector, IIdentifierRelationShip, IInformationService, IMidwayContainer, IObjectDefinition, IObjectDefinitionRegistry } from '../interface';
4
5
  import { ResolverHandler } from './resolverHandler';
5
- declare class ContainerConfiguration {
6
- readonly container: any;
7
- private namespace;
8
- constructor(container: any);
9
- load(module: any): void;
10
- addImportConfigs(importConfigs: string[]): void;
11
- addImports(imports?: any[]): void;
12
- bindConfigurationClass(clzz: any, filePath?: string): void;
13
- private getConfigurationExport;
14
- }
15
- export declare class MidwayContainer extends BaseApplicationContext implements IMidwayContainer {
6
+ import { ManagedResolverFactory } from './managedResolverFactory';
7
+ export declare class MidwayContainer implements IMidwayContainer {
8
+ private _resolverFactory;
9
+ private _registry;
10
+ private _identifierMapping;
11
+ parent: IMidwayContainer;
16
12
  private debugLogger;
17
- private definitionMetadataList;
18
13
  protected resolverHandler: ResolverHandler;
19
14
  protected ctx: {};
20
15
  protected configService: IConfigService;
@@ -24,19 +19,20 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
24
19
  private fileDetector;
25
20
  private attrMap;
26
21
  private isLoad;
27
- init(): void;
28
- initService(): void;
22
+ constructor(parent?: IMidwayContainer);
23
+ protected init(): void;
24
+ get registry(): IObjectDefinitionRegistry;
25
+ set registry(registry: IObjectDefinitionRegistry);
26
+ get managedResolverFactory(): ManagedResolverFactory;
27
+ get identifierMapping(): IIdentifierRelationShip;
28
+ protected initService(): void;
29
29
  load(module?: any): void;
30
- loadDefinitions(): void;
31
- createConfiguration(): ContainerConfiguration;
30
+ protected loadDefinitions(): void;
32
31
  bindClass(exports: any, namespace?: string, filePath?: string): void;
33
32
  bind<T>(target: T, options?: ObjectDefinitionOptions): void;
34
33
  bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
35
- protected restoreDefinition(definitionMeta: IObjectDefinitionMetadata): void;
36
- protected restoreDefinitions(definitionMetadataList: any): void;
37
- protected getDefinitionMetaList(): any[];
38
- protected bindModule(module: any, namespace?: string, filePath?: string): void;
39
- getDebugLogger(): (msg: string, ...param: any[]) => void;
34
+ protected bindModule(module: any, options?: ObjectDefinitionOptions): void;
35
+ getDebugLogger(): util.DebugLogger;
40
36
  setFileDetector(fileDetector: IFileDetector): void;
41
37
  createChild(): IMidwayContainer;
42
38
  registerDataHandler(handlerType: string, handler: (...args: any[]) => any): void;
@@ -49,6 +45,34 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
49
45
  getResolverHandler(): ResolverHandler;
50
46
  setAttr(key: string, value: any): void;
51
47
  getAttr<T>(key: string): T;
48
+ protected getIdentifier(target: any): string;
49
+ protected findRegisterObject(identifier: any): any;
50
+ protected getManagedResolverFactory(): ManagedResolverFactory;
51
+ stop(): Promise<void>;
52
+ ready(): Promise<void>;
53
+ get<T>(identifier: {
54
+ new (...args: any[]): T;
55
+ }, args?: any): T;
56
+ get<T>(identifier: ObjectIdentifier, args?: any): T;
57
+ getAsync<T>(identifier: {
58
+ new (...args: any[]): T;
59
+ }, args?: any): Promise<T>;
60
+ getAsync<T>(identifier: ObjectIdentifier, args?: any): Promise<T>;
61
+ /**
62
+ * proxy registry.registerObject
63
+ * @param {ObjectIdentifier} identifier
64
+ * @param target
65
+ */
66
+ registerObject(identifier: ObjectIdentifier, target: any): void;
67
+ /**
68
+ * register handler after instance create
69
+ * @param fn
70
+ */
71
+ afterEachCreated(fn: (ins: any, context: IMidwayContainer, definition?: IObjectDefinition) => void): void;
72
+ /**
73
+ * register handler before instance create
74
+ * @param fn
75
+ */
76
+ beforeEachCreated(fn: (Clzz: any, constructorArgs: any[], context: IMidwayContainer) => void): void;
52
77
  }
53
- export {};
54
78
  //# sourceMappingURL=container.d.ts.map