@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.
- package/CHANGELOG.md +3 -17
- package/dist/baseFramework.js +30 -44
- package/dist/common/reflectTool.d.ts +3 -1
- package/dist/context/container.d.ts +48 -24
- package/dist/context/container.js +212 -215
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -19
- package/dist/context/managedResolverFactory.js +27 -256
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.js +7 -10
- package/dist/context/resolverHandler.d.ts +2 -2
- package/dist/context/resolverHandler.js +2 -2
- package/dist/definitions/functionDefinition.d.ts +0 -2
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +6 -6
- package/dist/definitions/objectDefinition.d.ts +1 -4
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +0 -2
- package/dist/definitions/properties.js +5 -21
- package/dist/definitions/resource.js +13 -13
- package/dist/features/pipeline.d.ts +3 -3
- package/dist/features/pipeline.js +1 -1
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -23
- package/dist/interface.d.ts +21 -32
- package/dist/logger.js +4 -4
- package/dist/service/aspectService.js +9 -4
- package/dist/service/configService.d.ts +4 -4
- package/dist/service/configService.js +32 -20
- package/dist/service/environmentService.js +2 -2
- package/dist/service/informationService.js +4 -4
- package/dist/util/containerUtil.d.ts +3 -1
- package/dist/util/containerUtil.js +3 -3
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/fileDetector.js +2 -2
- package/dist/util/index.js +3 -3
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/serviceFactory.d.ts +4 -2
- package/dist/util/serviceFactory.js +11 -3
- package/dist/util/webRouterCollector.d.ts +8 -0
- package/dist/util/webRouterCollector.js +72 -128
- package/package.json +6 -5
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -263
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/util/staticConfig.d.ts +0 -10
- 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
|
-
|
|
6
|
+
## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
###
|
|
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
|
-
*
|
|
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
|
|
package/dist/baseFramework.js
CHANGED
|
@@ -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
|
-
|
|
275
|
+
cycle.instance = cycle.target;
|
|
281
276
|
}
|
|
282
277
|
else {
|
|
283
278
|
// 普通类写法
|
|
284
|
-
const providerId = decorator_1.
|
|
285
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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.
|
|
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(
|
|
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,20 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ObjectDefinitionOptions, ObjectIdentifier } from '@midwayjs/decorator';
|
|
2
|
-
import
|
|
3
|
-
import { IConfigService, IEnvironmentService, IFileDetector, IInformationService, IMidwayContainer,
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
|
36
|
-
|
|
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
|