@midwayjs/core 3.0.0-alpha.6 → 3.0.0-beta.11
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 +137 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +56 -22
- package/dist/baseFramework.js +157 -232
- package/dist/common/applicationManager.d.ts +12 -0
- package/dist/common/applicationManager.js +66 -0
- package/dist/{util → common}/fileDetector.d.ts +0 -0
- package/dist/{util → common}/fileDetector.js +16 -10
- package/dist/common/filterManager.d.ts +19 -0
- package/dist/common/filterManager.js +85 -0
- package/dist/common/middlewareManager.d.ts +68 -0
- package/dist/common/middlewareManager.js +183 -0
- package/dist/common/serviceFactory.d.ts +15 -0
- package/dist/{util → common}/serviceFactory.js +16 -6
- package/dist/{util → common}/triggerCollector.d.ts +0 -0
- package/dist/{util → common}/triggerCollector.js +0 -0
- package/dist/common/webGenerator.d.ts +16 -0
- package/dist/common/webGenerator.js +114 -0
- package/dist/{util → common}/webRouterCollector.d.ts +21 -2
- package/dist/common/webRouterCollector.js +331 -0
- package/dist/config/config.default.d.ts +7 -0
- package/dist/config/config.default.js +28 -0
- package/dist/context/container.d.ts +73 -43
- package/dist/context/container.js +289 -271
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -32
- package/dist/context/managedResolverFactory.js +88 -317
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.d.ts +0 -2
- package/dist/context/requestContainer.js +9 -26
- package/dist/definitions/functionDefinition.d.ts +3 -4
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +6 -6
- package/dist/definitions/objectDefinition.d.ts +4 -6
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +2 -15
- package/dist/definitions/properties.js +3 -72
- package/dist/error/base.d.ts +13 -0
- package/dist/error/base.js +19 -0
- package/dist/error/code.d.ts +60 -0
- package/dist/error/code.js +65 -0
- package/dist/error/framework.d.ts +24 -0
- package/dist/error/framework.js +58 -0
- package/dist/error/http.d.ts +58 -0
- package/dist/error/http.js +82 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.js +16 -0
- package/dist/functional/configuration.d.ts +4 -2
- package/dist/functional/configuration.js +12 -2
- package/dist/index.d.ts +24 -11
- package/dist/index.js +36 -36
- package/dist/interface.d.ts +270 -184
- package/dist/interface.js +9 -1
- package/dist/service/aspectService.d.ts +11 -14
- package/dist/service/aspectService.js +116 -172
- package/dist/service/configService.d.ts +10 -8
- package/dist/service/configService.js +61 -38
- package/dist/service/decoratorService.d.ts +23 -0
- package/dist/service/decoratorService.js +149 -0
- package/dist/service/environmentService.js +15 -4
- package/dist/service/frameworkService.d.ts +26 -0
- package/dist/service/frameworkService.js +176 -0
- package/dist/service/informationService.d.ts +4 -7
- package/dist/service/informationService.js +41 -10
- package/dist/service/lifeCycleService.d.ts +14 -0
- package/dist/service/lifeCycleService.js +130 -0
- package/dist/service/loggerService.d.ts +27 -0
- package/dist/service/loggerService.js +132 -0
- package/dist/service/middlewareService.d.ts +11 -0
- package/dist/service/middlewareService.js +127 -0
- package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
- package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
- package/dist/setup.d.ts +4 -0
- package/dist/setup.js +119 -0
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/index.d.ts +64 -0
- package/dist/util/index.js +195 -7
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/pathToRegexp.d.ts +17 -0
- package/dist/util/pathToRegexp.js +280 -0
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +19 -20
- package/package.json +10 -15
- package/dist/common/lodashWrap.d.ts +0 -9
- package/dist/common/lodashWrap.js +0 -18
- package/dist/common/notFoundError.d.ts +0 -8
- package/dist/common/notFoundError.js +0 -20
- package/dist/common/reflectTool.d.ts +0 -15
- package/dist/common/reflectTool.js +0 -83
- 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/context/resolverHandler.d.ts +0 -34
- package/dist/context/resolverHandler.js +0 -88
- package/dist/definitions/messageSource.d.ts +0 -13
- package/dist/definitions/messageSource.js +0 -74
- package/dist/definitions/resource.d.ts +0 -27
- package/dist/definitions/resource.js +0 -116
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.js +0 -3
- package/dist/logger.d.ts +0 -4
- package/dist/logger.js +0 -20
- package/dist/util/containerUtil.d.ts +0 -9
- package/dist/util/containerUtil.js +0 -26
- package/dist/util/emptyFramework.d.ts +0 -62
- package/dist/util/emptyFramework.js +0 -72
- package/dist/util/serviceFactory.d.ts +0 -13
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
- package/dist/util/webRouterCollector.js +0 -348
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayDecoratorService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const aspectService_1 = require("./aspectService");
|
|
15
|
+
const error_1 = require("../error");
|
|
16
|
+
const util = require("util");
|
|
17
|
+
const debug = util.debuglog('midway:debug');
|
|
18
|
+
let MidwayDecoratorService = class MidwayDecoratorService {
|
|
19
|
+
constructor(applicationContext) {
|
|
20
|
+
this.applicationContext = applicationContext;
|
|
21
|
+
this.propertyHandlerMap = new Map();
|
|
22
|
+
this.methodDecoratorMap = new Map();
|
|
23
|
+
this.parameterDecoratorMap = new Map();
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
// add custom method decorator listener
|
|
27
|
+
this.applicationContext.onBeforeBind(Clzz => {
|
|
28
|
+
// find custom method decorator metadata, include method decorator information array
|
|
29
|
+
const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
|
|
30
|
+
if (methodDecoratorMetadataList) {
|
|
31
|
+
// loop it, save this order for decorator run
|
|
32
|
+
for (const meta of methodDecoratorMetadataList) {
|
|
33
|
+
const { propertyName, key, metadata } = meta;
|
|
34
|
+
// add aspect implementation first
|
|
35
|
+
this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
|
|
36
|
+
const methodDecoratorHandler = this.methodDecoratorMap.get(key);
|
|
37
|
+
if (!methodDecoratorHandler) {
|
|
38
|
+
throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
|
|
39
|
+
}
|
|
40
|
+
return this.methodDecoratorMap.get(key)({
|
|
41
|
+
target: Clzz,
|
|
42
|
+
propertyName,
|
|
43
|
+
metadata,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// find custom param decorator metadata
|
|
49
|
+
const parameterDecoratorMetadata = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PARAM, Clzz);
|
|
50
|
+
if (parameterDecoratorMetadata) {
|
|
51
|
+
// loop it, save this order for decorator run
|
|
52
|
+
for (const methodName of Object.keys(parameterDecoratorMetadata)) {
|
|
53
|
+
// add aspect implementation first
|
|
54
|
+
this.aspectService.interceptPrototypeMethod(Clzz, methodName, () => {
|
|
55
|
+
return {
|
|
56
|
+
before: async (joinPoint) => {
|
|
57
|
+
// joinPoint.args
|
|
58
|
+
const newArgs = [...joinPoint.args];
|
|
59
|
+
for (const meta of parameterDecoratorMetadata[methodName]) {
|
|
60
|
+
const { propertyName, key, metadata, parameterIndex } = meta;
|
|
61
|
+
const parameterDecoratorHandler = this.parameterDecoratorMap.get(key);
|
|
62
|
+
if (!parameterDecoratorHandler) {
|
|
63
|
+
throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
|
|
64
|
+
}
|
|
65
|
+
const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
|
|
66
|
+
newArgs[parameterIndex] = await parameterDecoratorHandler({
|
|
67
|
+
metadata,
|
|
68
|
+
propertyName,
|
|
69
|
+
parameterIndex,
|
|
70
|
+
target: Clzz,
|
|
71
|
+
originArgs: joinPoint.args,
|
|
72
|
+
originParamType: paramTypes[parameterIndex],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
joinPoint.args = newArgs;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
// add custom property decorator listener
|
|
83
|
+
this.applicationContext.onObjectCreated((instance, options) => {
|
|
84
|
+
if (this.propertyHandlerMap.size > 0 &&
|
|
85
|
+
Array.isArray(options.definition.handlerProps)) {
|
|
86
|
+
// has bind in container
|
|
87
|
+
for (const item of options.definition.handlerProps) {
|
|
88
|
+
this.defineGetterPropertyValue(item, instance, this.getHandler(item.key));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// register @ApplicationContext
|
|
93
|
+
this.registerPropertyHandler(decorator_1.APPLICATION_CONTEXT_KEY, (propertyName, mete) => {
|
|
94
|
+
return this.applicationContext;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
registerPropertyHandler(decoratorKey, fn) {
|
|
98
|
+
debug(`[core]: Register property decorator key="${decoratorKey}"`);
|
|
99
|
+
this.propertyHandlerMap.set(decoratorKey, fn);
|
|
100
|
+
}
|
|
101
|
+
registerMethodHandler(decoratorKey, fn) {
|
|
102
|
+
debug(`[core]: Register method decorator key="${decoratorKey}"`);
|
|
103
|
+
this.methodDecoratorMap.set(decoratorKey, fn);
|
|
104
|
+
}
|
|
105
|
+
registerParameterHandler(decoratorKey, fn) {
|
|
106
|
+
debug(`[core]: Register parameter decorator key="${decoratorKey}"`);
|
|
107
|
+
this.parameterDecoratorMap.set(decoratorKey, fn);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* binding getter method for decorator
|
|
111
|
+
*
|
|
112
|
+
* @param prop
|
|
113
|
+
* @param instance
|
|
114
|
+
* @param getterHandler
|
|
115
|
+
*/
|
|
116
|
+
defineGetterPropertyValue(prop, instance, getterHandler) {
|
|
117
|
+
if (prop && getterHandler) {
|
|
118
|
+
if (prop.propertyName) {
|
|
119
|
+
Object.defineProperty(instance, prop.propertyName, {
|
|
120
|
+
get: () => { var _a; return getterHandler(prop.propertyName, (_a = prop.metadata) !== null && _a !== void 0 ? _a : {}, instance); },
|
|
121
|
+
configurable: true,
|
|
122
|
+
enumerable: true,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getHandler(key) {
|
|
128
|
+
if (this.propertyHandlerMap.has(key)) {
|
|
129
|
+
return this.propertyHandlerMap.get(key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, decorator_1.Inject)(),
|
|
135
|
+
__metadata("design:type", aspectService_1.MidwayAspectService)
|
|
136
|
+
], MidwayDecoratorService.prototype, "aspectService", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, decorator_1.Init)(),
|
|
139
|
+
__metadata("design:type", Function),
|
|
140
|
+
__metadata("design:paramtypes", []),
|
|
141
|
+
__metadata("design:returntype", Promise)
|
|
142
|
+
], MidwayDecoratorService.prototype, "init", null);
|
|
143
|
+
MidwayDecoratorService = __decorate([
|
|
144
|
+
(0, decorator_1.Provide)(),
|
|
145
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
146
|
+
__metadata("design:paramtypes", [Object])
|
|
147
|
+
], MidwayDecoratorService);
|
|
148
|
+
exports.MidwayDecoratorService = MidwayDecoratorService;
|
|
149
|
+
//# sourceMappingURL=decoratorService.js.map
|
|
@@ -1,11 +1,18 @@
|
|
|
1
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
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.MidwayEnvironmentService = void 0;
|
|
4
10
|
const util_1 = require("../util");
|
|
5
|
-
|
|
11
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
12
|
+
let MidwayEnvironmentService = class MidwayEnvironmentService {
|
|
6
13
|
getCurrentEnvironment() {
|
|
7
14
|
if (!this.environment) {
|
|
8
|
-
this.environment = util_1.getCurrentEnvironment();
|
|
15
|
+
this.environment = (0, util_1.getCurrentEnvironment)();
|
|
9
16
|
}
|
|
10
17
|
return this.environment;
|
|
11
18
|
}
|
|
@@ -13,8 +20,12 @@ class MidwayEnvironmentService {
|
|
|
13
20
|
this.environment = environment;
|
|
14
21
|
}
|
|
15
22
|
isDevelopmentEnvironment() {
|
|
16
|
-
return util_1.isDevelopmentEnvironment(this.environment);
|
|
23
|
+
return (0, util_1.isDevelopmentEnvironment)(this.environment);
|
|
17
24
|
}
|
|
18
|
-
}
|
|
25
|
+
};
|
|
26
|
+
MidwayEnvironmentService = __decorate([
|
|
27
|
+
(0, decorator_1.Provide)(),
|
|
28
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
29
|
+
], MidwayEnvironmentService);
|
|
19
30
|
exports.MidwayEnvironmentService = MidwayEnvironmentService;
|
|
20
31
|
//# sourceMappingURL=environmentService.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
2
|
+
import { IMidwayContainer, IMidwayFramework } from '../interface';
|
|
3
|
+
import { MidwayConfigService } from './configService';
|
|
4
|
+
import { MidwayLoggerService } from './loggerService';
|
|
5
|
+
import { MidwayDecoratorService } from './decoratorService';
|
|
6
|
+
import { MidwayAspectService } from './aspectService';
|
|
7
|
+
import { MidwayApplicationManager } from '../common/applicationManager';
|
|
8
|
+
export declare class MidwayFrameworkService {
|
|
9
|
+
readonly applicationContext: IMidwayContainer;
|
|
10
|
+
readonly globalOptions: any;
|
|
11
|
+
configService: MidwayConfigService;
|
|
12
|
+
loggerService: MidwayLoggerService;
|
|
13
|
+
aspectService: MidwayAspectService;
|
|
14
|
+
decoratorService: MidwayDecoratorService;
|
|
15
|
+
applicationManager: MidwayApplicationManager;
|
|
16
|
+
constructor(applicationContext: IMidwayContainer, globalOptions: any);
|
|
17
|
+
private mainFramework;
|
|
18
|
+
private globalFrameworkList;
|
|
19
|
+
protected init(): Promise<void>;
|
|
20
|
+
getMainApp(): any;
|
|
21
|
+
getMainFramework(): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
22
|
+
getFramework(namespaceOrFrameworkType: string | MidwayFrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
23
|
+
runFramework(): Promise<void>;
|
|
24
|
+
stopFramework(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=frameworkService.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayFrameworkService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const interface_1 = require("../interface");
|
|
15
|
+
const configService_1 = require("./configService");
|
|
16
|
+
const loggerService_1 = require("./loggerService");
|
|
17
|
+
const baseFramework_1 = require("../baseFramework");
|
|
18
|
+
const pipelineService_1 = require("./pipelineService");
|
|
19
|
+
const decoratorService_1 = require("./decoratorService");
|
|
20
|
+
const aspectService_1 = require("./aspectService");
|
|
21
|
+
const applicationManager_1 = require("../common/applicationManager");
|
|
22
|
+
const util = require("util");
|
|
23
|
+
const error_1 = require("../error");
|
|
24
|
+
const debug = util.debuglog('midway:debug');
|
|
25
|
+
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
26
|
+
constructor(applicationContext, globalOptions) {
|
|
27
|
+
this.applicationContext = applicationContext;
|
|
28
|
+
this.globalOptions = globalOptions;
|
|
29
|
+
this.globalFrameworkList = [];
|
|
30
|
+
}
|
|
31
|
+
async init() {
|
|
32
|
+
var _a;
|
|
33
|
+
// register base config hook
|
|
34
|
+
this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
|
|
35
|
+
var _a;
|
|
36
|
+
if (meta.identifier === decorator_1.ALL) {
|
|
37
|
+
return this.configService.getConfiguration();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return this.configService.getConfiguration((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// register @Logger decorator handler
|
|
44
|
+
this.decoratorService.registerPropertyHandler(decorator_1.LOGGER_KEY, (propertyName, meta) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return this.loggerService.getLogger((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
|
|
47
|
+
});
|
|
48
|
+
this.decoratorService.registerPropertyHandler(decorator_1.PIPELINE_IDENTIFIER, (key, meta, instance) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[interface_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
|
|
51
|
+
});
|
|
52
|
+
let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
|
|
53
|
+
// filter proto
|
|
54
|
+
frameworks = filterProtoFramework(frameworks);
|
|
55
|
+
debug(`[core]: Found Framework length = ${frameworks.length}`);
|
|
56
|
+
if (frameworks.length) {
|
|
57
|
+
for (const frameworkClz of frameworks) {
|
|
58
|
+
const frameworkInstance = await this.applicationContext.getAsync(frameworkClz, [this.applicationContext]);
|
|
59
|
+
// if enable, just init framework
|
|
60
|
+
if (frameworkInstance.isEnable()) {
|
|
61
|
+
// app init
|
|
62
|
+
await frameworkInstance.initialize({
|
|
63
|
+
applicationContext: this.applicationContext,
|
|
64
|
+
...this.globalOptions,
|
|
65
|
+
});
|
|
66
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and delay initialize.`);
|
|
70
|
+
}
|
|
71
|
+
// app init
|
|
72
|
+
const definition = this.applicationContext.registry.getDefinition((0, decorator_1.getProviderUUId)(frameworkClz));
|
|
73
|
+
this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
|
|
74
|
+
this.globalFrameworkList.push(frameworkInstance);
|
|
75
|
+
}
|
|
76
|
+
// register @App decorator handler
|
|
77
|
+
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
|
|
78
|
+
if (mete.type) {
|
|
79
|
+
const framework = this.applicationManager.getApplication(mete.type);
|
|
80
|
+
if (!framework) {
|
|
81
|
+
throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
|
|
82
|
+
}
|
|
83
|
+
return framework;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return this.getMainApp();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
|
|
90
|
+
return this.getMainApp()[key];
|
|
91
|
+
});
|
|
92
|
+
global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
|
|
93
|
+
this.globalFrameworkList[0];
|
|
94
|
+
}
|
|
95
|
+
// init aspect module
|
|
96
|
+
await this.aspectService.loadAspect();
|
|
97
|
+
// some preload module init
|
|
98
|
+
const modules = (0, decorator_1.listPreloadModule)();
|
|
99
|
+
for (const module of modules) {
|
|
100
|
+
// preload init context
|
|
101
|
+
await this.applicationContext.getAsync(module);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getMainApp() {
|
|
105
|
+
var _a;
|
|
106
|
+
return (_a = this.mainFramework) === null || _a === void 0 ? void 0 : _a.getApplication();
|
|
107
|
+
}
|
|
108
|
+
getMainFramework() {
|
|
109
|
+
return this.mainFramework;
|
|
110
|
+
}
|
|
111
|
+
getFramework(namespaceOrFrameworkType) {
|
|
112
|
+
return this.applicationManager.getFramework(namespaceOrFrameworkType);
|
|
113
|
+
}
|
|
114
|
+
async runFramework() {
|
|
115
|
+
for (const frameworkInstance of this.globalFrameworkList) {
|
|
116
|
+
// if enable, just init framework
|
|
117
|
+
if (frameworkInstance.isEnable()) {
|
|
118
|
+
// app init
|
|
119
|
+
await frameworkInstance.run();
|
|
120
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and run.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async stopFramework() {
|
|
125
|
+
await Promise.all(Array.from(this.globalFrameworkList).map(frameworkInstance => {
|
|
126
|
+
return frameworkInstance.stop();
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, decorator_1.Inject)(),
|
|
132
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
133
|
+
], MidwayFrameworkService.prototype, "configService", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, decorator_1.Inject)(),
|
|
136
|
+
__metadata("design:type", loggerService_1.MidwayLoggerService)
|
|
137
|
+
], MidwayFrameworkService.prototype, "loggerService", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, decorator_1.Inject)(),
|
|
140
|
+
__metadata("design:type", aspectService_1.MidwayAspectService)
|
|
141
|
+
], MidwayFrameworkService.prototype, "aspectService", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, decorator_1.Inject)(),
|
|
144
|
+
__metadata("design:type", decoratorService_1.MidwayDecoratorService)
|
|
145
|
+
], MidwayFrameworkService.prototype, "decoratorService", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, decorator_1.Inject)(),
|
|
148
|
+
__metadata("design:type", applicationManager_1.MidwayApplicationManager)
|
|
149
|
+
], MidwayFrameworkService.prototype, "applicationManager", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, decorator_1.Init)(),
|
|
152
|
+
__metadata("design:type", Function),
|
|
153
|
+
__metadata("design:paramtypes", []),
|
|
154
|
+
__metadata("design:returntype", Promise)
|
|
155
|
+
], MidwayFrameworkService.prototype, "init", null);
|
|
156
|
+
MidwayFrameworkService = __decorate([
|
|
157
|
+
(0, decorator_1.Provide)(),
|
|
158
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
159
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
160
|
+
], MidwayFrameworkService);
|
|
161
|
+
exports.MidwayFrameworkService = MidwayFrameworkService;
|
|
162
|
+
function filterProtoFramework(frameworks) {
|
|
163
|
+
const frameworkProtoArr = [];
|
|
164
|
+
// 这里把继承的框架父类都找出来,然后排除掉,只取第一层
|
|
165
|
+
for (const framework of frameworks) {
|
|
166
|
+
let proto = Object.getPrototypeOf(framework);
|
|
167
|
+
while (proto.name && proto.name !== baseFramework_1.BaseFramework.name) {
|
|
168
|
+
frameworkProtoArr.push(proto);
|
|
169
|
+
proto = Object.getPrototypeOf(proto);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return frameworks.filter(framework => {
|
|
173
|
+
return !frameworkProtoArr.includes(framework);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=frameworkService.js.map
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { IInformationService } from '../interface';
|
|
2
2
|
export declare class MidwayInformationService implements IInformationService {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
baseDir?: string;
|
|
8
|
-
appDir?: string;
|
|
9
|
-
});
|
|
3
|
+
private pkg;
|
|
4
|
+
protected appDir: string;
|
|
5
|
+
protected baseDir: string;
|
|
6
|
+
protected init(): void;
|
|
10
7
|
getAppDir(): string;
|
|
11
8
|
getBaseDir(): string;
|
|
12
9
|
getHome(): string;
|
|
@@ -1,16 +1,29 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.MidwayInformationService = void 0;
|
|
4
13
|
const util_1 = require("../util");
|
|
5
14
|
const path_1 = require("path");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
16
|
+
let MidwayInformationService = class MidwayInformationService {
|
|
17
|
+
init() {
|
|
18
|
+
if (this.baseDir) {
|
|
19
|
+
if (!this.appDir) {
|
|
20
|
+
this.appDir = (0, path_1.dirname)(this.baseDir);
|
|
21
|
+
}
|
|
22
|
+
this.pkg = (0, util_1.safeRequire)((0, path_1.join)(this.appDir, 'package.json')) || {};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.pkg = {};
|
|
12
26
|
}
|
|
13
|
-
this.pkg = util_1.safeRequire(path_1.join(this.appDir, 'package.json')) || {};
|
|
14
27
|
}
|
|
15
28
|
getAppDir() {
|
|
16
29
|
return this.appDir;
|
|
@@ -19,7 +32,7 @@ class MidwayInformationService {
|
|
|
19
32
|
return this.baseDir;
|
|
20
33
|
}
|
|
21
34
|
getHome() {
|
|
22
|
-
return util_1.getUserHome();
|
|
35
|
+
return (0, util_1.getUserHome)();
|
|
23
36
|
}
|
|
24
37
|
getPkg() {
|
|
25
38
|
return this.pkg;
|
|
@@ -29,9 +42,27 @@ class MidwayInformationService {
|
|
|
29
42
|
return ((_a = this.pkg) === null || _a === void 0 ? void 0 : _a['name']) || '';
|
|
30
43
|
}
|
|
31
44
|
getRoot() {
|
|
32
|
-
const isDevelopmentEnv = util_1.isDevelopmentEnvironment(util_1.getCurrentEnvironment());
|
|
45
|
+
const isDevelopmentEnv = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
|
|
33
46
|
return isDevelopmentEnv ? this.getAppDir() : this.getHome();
|
|
34
47
|
}
|
|
35
|
-
}
|
|
48
|
+
};
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, decorator_1.Inject)(),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], MidwayInformationService.prototype, "appDir", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, decorator_1.Inject)(),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], MidwayInformationService.prototype, "baseDir", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, decorator_1.Init)(),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", []),
|
|
61
|
+
__metadata("design:returntype", void 0)
|
|
62
|
+
], MidwayInformationService.prototype, "init", null);
|
|
63
|
+
MidwayInformationService = __decorate([
|
|
64
|
+
(0, decorator_1.Provide)(),
|
|
65
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
66
|
+
], MidwayInformationService);
|
|
36
67
|
exports.MidwayInformationService = MidwayInformationService;
|
|
37
68
|
//# sourceMappingURL=informationService.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IMidwayContainer } from '../interface';
|
|
2
|
+
import { MidwayFrameworkService } from './frameworkService';
|
|
3
|
+
import { MidwayConfigService } from './configService';
|
|
4
|
+
export declare class MidwayLifeCycleService {
|
|
5
|
+
readonly applicationContext: IMidwayContainer;
|
|
6
|
+
protected frameworkService: MidwayFrameworkService;
|
|
7
|
+
protected configService: MidwayConfigService;
|
|
8
|
+
constructor(applicationContext: IMidwayContainer);
|
|
9
|
+
protected init(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
private runContainerLifeCycle;
|
|
12
|
+
private runObjectLifeCycle;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=lifeCycleService.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayLifeCycleService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const configuration_1 = require("../functional/configuration");
|
|
15
|
+
const frameworkService_1 = require("./frameworkService");
|
|
16
|
+
const configService_1 = require("./configService");
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
19
|
+
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
20
|
+
constructor(applicationContext) {
|
|
21
|
+
this.applicationContext = applicationContext;
|
|
22
|
+
}
|
|
23
|
+
async init() {
|
|
24
|
+
// run lifecycle
|
|
25
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
26
|
+
debug(`[core]: Found Configuration length = ${cycles.length}`);
|
|
27
|
+
const lifecycleInstanceList = [];
|
|
28
|
+
for (const cycle of cycles) {
|
|
29
|
+
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
30
|
+
// 函数式写法
|
|
31
|
+
cycle.instance = cycle.target;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// 普通类写法
|
|
35
|
+
debug(`[core]: run ${cycle.target.name} init`);
|
|
36
|
+
cycle.instance = await this.applicationContext.getAsync(cycle.target);
|
|
37
|
+
}
|
|
38
|
+
cycle.instance && lifecycleInstanceList.push(cycle);
|
|
39
|
+
}
|
|
40
|
+
// bind object lifecycle
|
|
41
|
+
await Promise.all([
|
|
42
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onBeforeObjectCreated'),
|
|
43
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onObjectCreated'),
|
|
44
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onObjectInit'),
|
|
45
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onBeforeObjectDestroy'),
|
|
46
|
+
]);
|
|
47
|
+
// bind framework lifecycle
|
|
48
|
+
// onAppError
|
|
49
|
+
// exec onConfigLoad()
|
|
50
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onConfigLoad', configData => {
|
|
51
|
+
if (configData) {
|
|
52
|
+
this.configService.addObject(configData);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// exec onReady()
|
|
56
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onReady');
|
|
57
|
+
// exec framework.run()
|
|
58
|
+
await this.frameworkService.runFramework();
|
|
59
|
+
// exec onServerReady()
|
|
60
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onServerReady');
|
|
61
|
+
}
|
|
62
|
+
async stop() {
|
|
63
|
+
// stop lifecycle
|
|
64
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
65
|
+
for (const cycle of cycles) {
|
|
66
|
+
let inst;
|
|
67
|
+
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
68
|
+
// 函数式写法
|
|
69
|
+
inst = cycle.target;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
inst = await this.applicationContext.getAsync(cycle.target);
|
|
73
|
+
}
|
|
74
|
+
await this.runContainerLifeCycle(inst, 'onStop');
|
|
75
|
+
}
|
|
76
|
+
// stop framework
|
|
77
|
+
await this.frameworkService.stopFramework();
|
|
78
|
+
}
|
|
79
|
+
async runContainerLifeCycle(lifecycleInstanceOrList, lifecycle, resultHandler) {
|
|
80
|
+
if (Array.isArray(lifecycleInstanceOrList)) {
|
|
81
|
+
for (const cycle of lifecycleInstanceOrList) {
|
|
82
|
+
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
83
|
+
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
84
|
+
const result = await cycle.instance[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
85
|
+
if (resultHandler) {
|
|
86
|
+
resultHandler(result);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (typeof lifecycleInstanceOrList[lifecycle] === 'function') {
|
|
93
|
+
debug(`[core]: run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
94
|
+
const result = await lifecycleInstanceOrList[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
95
|
+
if (resultHandler) {
|
|
96
|
+
resultHandler(result);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async runObjectLifeCycle(lifecycleInstanceList, lifecycle) {
|
|
102
|
+
for (const cycle of lifecycleInstanceList) {
|
|
103
|
+
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
104
|
+
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
105
|
+
return this.applicationContext[lifecycle](cycle.instance[lifecycle].bind(cycle.instance));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, decorator_1.Inject)(),
|
|
112
|
+
__metadata("design:type", frameworkService_1.MidwayFrameworkService)
|
|
113
|
+
], MidwayLifeCycleService.prototype, "frameworkService", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, decorator_1.Inject)(),
|
|
116
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
117
|
+
], MidwayLifeCycleService.prototype, "configService", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, decorator_1.Init)(),
|
|
120
|
+
__metadata("design:type", Function),
|
|
121
|
+
__metadata("design:paramtypes", []),
|
|
122
|
+
__metadata("design:returntype", Promise)
|
|
123
|
+
], MidwayLifeCycleService.prototype, "init", null);
|
|
124
|
+
MidwayLifeCycleService = __decorate([
|
|
125
|
+
(0, decorator_1.Provide)(),
|
|
126
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
127
|
+
__metadata("design:paramtypes", [Object])
|
|
128
|
+
], MidwayLifeCycleService);
|
|
129
|
+
exports.MidwayLifeCycleService = MidwayLifeCycleService;
|
|
130
|
+
//# sourceMappingURL=lifeCycleService.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MidwayConfigService } from './configService';
|
|
2
|
+
import { ServiceFactory } from '../common/serviceFactory';
|
|
3
|
+
import { ILogger } from '@midwayjs/logger';
|
|
4
|
+
import { IMidwayContainer } from '../interface';
|
|
5
|
+
export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
|
|
6
|
+
readonly applicationContext: IMidwayContainer;
|
|
7
|
+
configService: MidwayConfigService;
|
|
8
|
+
constructor(applicationContext: IMidwayContainer);
|
|
9
|
+
protected init(): Promise<void>;
|
|
10
|
+
transformEggConfig(): {
|
|
11
|
+
midwayLogger: {
|
|
12
|
+
default: {};
|
|
13
|
+
clients: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
protected createClient(config: any, name?: string): Promise<void>;
|
|
17
|
+
getName(): string;
|
|
18
|
+
createLogger(name: any, config: any): ILogger;
|
|
19
|
+
getLogger(name: string): ILogger;
|
|
20
|
+
transformEggLogger(options: any): {
|
|
21
|
+
midwayLogger: {
|
|
22
|
+
default: {};
|
|
23
|
+
clients: {};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=loggerService.d.ts.map
|