@midwayjs/core 3.0.0-alpha.2 → 3.0.0-alpha.40
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.d.ts +0 -1
- package/dist/baseFramework.js +36 -80
- package/dist/common/reflectTool.d.ts +3 -1
- package/dist/context/container.d.ts +49 -24
- package/dist/context/container.js +245 -224
- 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.d.ts +1 -2
- package/dist/context/requestContainer.js +5 -12
- package/dist/context/resolverHandler.d.ts +3 -2
- package/dist/context/resolverHandler.js +5 -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 +2 -1
- package/dist/index.js +2 -23
- package/dist/interface.d.ts +24 -32
- package/dist/logger.js +4 -4
- package/dist/service/aspectService.js +9 -4
- package/dist/service/configService.d.ts +2 -2
- package/dist/service/configService.js +30 -18
- package/dist/service/environmentService.js +2 -2
- package/dist/service/informationService.js +4 -4
- package/dist/util/containerUtil.d.ts +11 -0
- package/dist/util/containerUtil.js +26 -0
- 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 +9 -4
- package/dist/util/webRouterCollector.js +83 -132
- package/package.json +5 -4
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -247
- package/dist/context/configuration.d.ts +0 -1
- package/dist/context/configuration.js +0 -370
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/context/midwayContainer.d.ts +0 -1
- package/dist/context/midwayContainer.js +0 -695
- 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.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMi
|
|
|
2
2
|
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
4
4
|
export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, OPT extends IConfigurationOptions> implements IMidwayFramework<APP, OPT> {
|
|
5
|
-
protected isTsMode: boolean;
|
|
6
5
|
protected applicationContext: IMidwayContainer;
|
|
7
6
|
protected logger: ILogger;
|
|
8
7
|
protected appLogger: ILogger;
|
package/dist/baseFramework.js
CHANGED
|
@@ -2,26 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseFramework = void 0;
|
|
4
4
|
const interface_1 = require("./interface");
|
|
5
|
-
const container_1 = require("./context/container");
|
|
6
5
|
const decorator_1 = require("@midwayjs/decorator");
|
|
7
6
|
const logger_1 = require("@midwayjs/logger");
|
|
8
|
-
const path_1 = require("path");
|
|
9
7
|
const logger_2 = require("./logger");
|
|
10
8
|
const requestContainer_1 = require("./context/requestContainer");
|
|
11
9
|
const configuration_1 = require("./functional/configuration");
|
|
12
10
|
const informationService_1 = require("./service/informationService");
|
|
13
|
-
|
|
14
|
-
// if (!isAbsolute(dir)) {
|
|
15
|
-
// return join(baseDir, dir);
|
|
16
|
-
// }
|
|
17
|
-
// return dir;
|
|
18
|
-
// }
|
|
19
|
-
function setupAppDir(baseDir) {
|
|
20
|
-
return path_1.dirname(baseDir);
|
|
21
|
-
}
|
|
11
|
+
const containerUtil_1 = require("./util/containerUtil");
|
|
22
12
|
class BaseFramework {
|
|
23
13
|
constructor() {
|
|
24
|
-
this.isTsMode = true;
|
|
25
14
|
this.defaultContext = {};
|
|
26
15
|
}
|
|
27
16
|
configure(options) {
|
|
@@ -61,7 +50,7 @@ class BaseFramework {
|
|
|
61
50
|
*/
|
|
62
51
|
await this.applicationInitialize(options);
|
|
63
52
|
/**
|
|
64
|
-
* start
|
|
53
|
+
* start container ready
|
|
65
54
|
*/
|
|
66
55
|
await this.containerReady(options);
|
|
67
56
|
if (this.isMainFramework !== undefined) {
|
|
@@ -85,19 +74,16 @@ class BaseFramework {
|
|
|
85
74
|
}
|
|
86
75
|
async initializeLogger(options) {
|
|
87
76
|
if (!this.logger) {
|
|
88
|
-
this.logger = new Proxy(logger_2.createMidwayLogger(this, 'coreLogger'), {});
|
|
77
|
+
this.logger = new Proxy((0, logger_2.createMidwayLogger)(this, 'coreLogger'), {});
|
|
89
78
|
this.logger.updateDefaultLabel(this.getFrameworkName());
|
|
90
79
|
}
|
|
91
80
|
if (!this.appLogger) {
|
|
92
|
-
this.appLogger = logger_2.createMidwayLogger(this, 'logger', {
|
|
81
|
+
this.appLogger = (0, logger_2.createMidwayLogger)(this, 'logger', {
|
|
93
82
|
fileLogName: 'midway-app.log',
|
|
94
83
|
});
|
|
95
84
|
}
|
|
96
85
|
}
|
|
97
86
|
async containerInitialize(options) {
|
|
98
|
-
if (!options.appDir) {
|
|
99
|
-
options.appDir = setupAppDir(options.baseDir);
|
|
100
|
-
}
|
|
101
87
|
/**
|
|
102
88
|
* initialize container
|
|
103
89
|
*/
|
|
@@ -105,11 +91,12 @@ class BaseFramework {
|
|
|
105
91
|
this.applicationContext = options.applicationContext;
|
|
106
92
|
}
|
|
107
93
|
else {
|
|
108
|
-
this.applicationContext =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.applicationContext.registerObject('isTsMode', this.isTsMode);
|
|
94
|
+
this.applicationContext = (0, containerUtil_1.createDirectoryGlobContainer)({
|
|
95
|
+
baseDir: options.baseDir,
|
|
96
|
+
});
|
|
112
97
|
}
|
|
98
|
+
this.applicationContext.registerObject('baseDir', options.baseDir);
|
|
99
|
+
this.applicationContext.registerObject('appDir', options.appDir);
|
|
113
100
|
/**
|
|
114
101
|
* initialize base information
|
|
115
102
|
*/
|
|
@@ -120,28 +107,6 @@ class BaseFramework {
|
|
|
120
107
|
await this.initializeLogger(options);
|
|
121
108
|
}
|
|
122
109
|
async containerDirectoryLoad(options) {
|
|
123
|
-
if (options.applicationContext) {
|
|
124
|
-
// 如果有传入全局容器,就不需要再次扫描了
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* load directory and bind files to ioc container
|
|
129
|
-
*/
|
|
130
|
-
if (!this.isTsMode && options.disableAutoLoad === undefined) {
|
|
131
|
-
// disable auto load in js mode by default
|
|
132
|
-
options.disableAutoLoad = true;
|
|
133
|
-
}
|
|
134
|
-
if (options.disableAutoLoad)
|
|
135
|
-
return;
|
|
136
|
-
// use baseDir in parameter first
|
|
137
|
-
// const defaultLoadDir = this.isTsMode ? [options.baseDir] : [];
|
|
138
|
-
// this.applicationContext.load({
|
|
139
|
-
// loadDir: (options.loadDir || defaultLoadDir).map(dir => {
|
|
140
|
-
// return buildLoadDir(options.baseDir, dir);
|
|
141
|
-
// }),
|
|
142
|
-
// pattern: options.pattern,
|
|
143
|
-
// ignore: options.ignore,
|
|
144
|
-
// });
|
|
145
110
|
if (options.preloadModules && options.preloadModules.length) {
|
|
146
111
|
for (const preloadModule of options.preloadModules) {
|
|
147
112
|
this.applicationContext.bindClass(preloadModule);
|
|
@@ -302,40 +267,40 @@ class BaseFramework {
|
|
|
302
267
|
// agent 不加载生命周期
|
|
303
268
|
if (this.app.getProcessType() === interface_1.MidwayProcessTypeEnum.AGENT)
|
|
304
269
|
return;
|
|
305
|
-
const cycles = decorator_1.listModule(decorator_1.CONFIGURATION_KEY);
|
|
270
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
271
|
+
const lifecycleInstanceList = [];
|
|
306
272
|
for (const cycle of cycles) {
|
|
307
|
-
let inst;
|
|
308
273
|
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
309
274
|
// 函数式写法
|
|
310
|
-
|
|
275
|
+
cycle.instance = cycle.target;
|
|
311
276
|
}
|
|
312
277
|
else {
|
|
313
278
|
// 普通类写法
|
|
314
|
-
const providerId = decorator_1.
|
|
315
|
-
|
|
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
|
+
}
|
|
316
284
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return Reflect.get(target, prop, receiver);
|
|
332
|
-
},
|
|
333
|
-
}), 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);
|
|
334
299
|
}
|
|
335
300
|
}
|
|
336
301
|
}
|
|
337
302
|
async stopLifeCycles() {
|
|
338
|
-
const cycles = decorator_1.listModule(decorator_1.CONFIGURATION_KEY);
|
|
303
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
339
304
|
for (const cycle of cycles) {
|
|
340
305
|
let inst;
|
|
341
306
|
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
@@ -343,20 +308,11 @@ class BaseFramework {
|
|
|
343
308
|
inst = cycle.target;
|
|
344
309
|
}
|
|
345
310
|
else {
|
|
346
|
-
const providerId = decorator_1.
|
|
311
|
+
const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
|
|
347
312
|
inst = await this.applicationContext.getAsync(providerId);
|
|
348
313
|
}
|
|
349
314
|
if (inst.onStop && typeof inst.onStop === 'function') {
|
|
350
|
-
await inst.onStop(
|
|
351
|
-
get: function (target, prop, receiver) {
|
|
352
|
-
if (prop === 'getCurrentNamespace' && cycle.namespace) {
|
|
353
|
-
return () => {
|
|
354
|
-
return cycle.namespace;
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
return Reflect.get(target, prop, receiver);
|
|
358
|
-
},
|
|
359
|
-
}), this.app);
|
|
315
|
+
await inst.onStop(this.getApplicationContext(), this.app);
|
|
360
316
|
}
|
|
361
317
|
}
|
|
362
318
|
}
|
|
@@ -366,7 +322,7 @@ class BaseFramework {
|
|
|
366
322
|
*/
|
|
367
323
|
async loadPreloadModule() {
|
|
368
324
|
// some common decorator implementation
|
|
369
|
-
const modules = decorator_1.listPreloadModule();
|
|
325
|
+
const modules = (0, decorator_1.listPreloadModule)();
|
|
370
326
|
for (const module of modules) {
|
|
371
327
|
// preload init context
|
|
372
328
|
await this.applicationContext.getAsync(module);
|
|
@@ -380,7 +336,7 @@ class BaseFramework {
|
|
|
380
336
|
return this.logger;
|
|
381
337
|
}
|
|
382
338
|
createLogger(name, option = {}) {
|
|
383
|
-
return logger_2.createMidwayLogger(this, name, option);
|
|
339
|
+
return (0, logger_2.createMidwayLogger)(this, name, option);
|
|
384
340
|
}
|
|
385
341
|
getProjectName() {
|
|
386
342
|
return this.applicationContext.getInformationService().getProjectName();
|
|
@@ -1,19 +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
|
-
bindConfigurationClass(clzz: any, filePath?: string): void;
|
|
12
|
-
private getConfigurationExport;
|
|
13
|
-
}
|
|
14
|
-
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;
|
|
15
12
|
private debugLogger;
|
|
16
|
-
private definitionMetadataList;
|
|
17
13
|
protected resolverHandler: ResolverHandler;
|
|
18
14
|
protected ctx: {};
|
|
19
15
|
protected configService: IConfigService;
|
|
@@ -23,21 +19,22 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
|
|
|
23
19
|
private fileDetector;
|
|
24
20
|
private attrMap;
|
|
25
21
|
private isLoad;
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
29
|
load(module?: any): void;
|
|
29
|
-
|
|
30
|
-
protected getIdentifier(target: any): string;
|
|
31
|
-
ready(): Promise<void>;
|
|
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;
|
|
37
|
+
createChild(): IMidwayContainer;
|
|
41
38
|
registerDataHandler(handlerType: string, handler: (...args: any[]) => any): void;
|
|
42
39
|
getConfigService(): IConfigService;
|
|
43
40
|
getEnvironmentService(): IEnvironmentService;
|
|
@@ -48,6 +45,34 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
|
|
|
48
45
|
getResolverHandler(): ResolverHandler;
|
|
49
46
|
setAttr(key: string, value: any): void;
|
|
50
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;
|
|
51
77
|
}
|
|
52
|
-
export {};
|
|
53
78
|
//# sourceMappingURL=container.d.ts.map
|