@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
|
@@ -1,27 +1,31 @@
|
|
|
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.MidwayAspectService = void 0;
|
|
4
13
|
const decorator_1 = require("@midwayjs/decorator");
|
|
5
14
|
const pm = require("picomatch");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(container) {
|
|
10
|
-
this.container = container;
|
|
11
|
-
this.aspectMappingMap = new WeakMap();
|
|
12
|
-
this.aspectModuleSet = new Set();
|
|
15
|
+
let MidwayAspectService = class MidwayAspectService {
|
|
16
|
+
constructor(applicationContext) {
|
|
17
|
+
this.applicationContext = applicationContext;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* load aspect method for container
|
|
16
|
-
* @private
|
|
17
21
|
*/
|
|
18
22
|
async loadAspect() {
|
|
19
23
|
// for aop implementation
|
|
20
|
-
const aspectModules = decorator_1.listModule(decorator_1.ASPECT_KEY);
|
|
24
|
+
const aspectModules = (0, decorator_1.listModule)(decorator_1.ASPECT_KEY);
|
|
21
25
|
// sort for aspect target
|
|
22
26
|
let aspectDataList = [];
|
|
23
27
|
for (const module of aspectModules) {
|
|
24
|
-
const data = decorator_1.getClassMetadata(decorator_1.ASPECT_KEY, module);
|
|
28
|
+
const data = (0, decorator_1.getClassMetadata)(decorator_1.ASPECT_KEY, module);
|
|
25
29
|
aspectDataList = aspectDataList.concat(data.map(el => {
|
|
26
30
|
el.aspectModule = module;
|
|
27
31
|
return el;
|
|
@@ -32,37 +36,15 @@ class MidwayAspectService {
|
|
|
32
36
|
return (next.priority || 0) - (pre.priority || 0);
|
|
33
37
|
});
|
|
34
38
|
for (const aspectData of aspectDataList) {
|
|
35
|
-
|
|
39
|
+
// aspect instance init
|
|
40
|
+
const aspectIns = await this.applicationContext.getAsync(aspectData.aspectModule);
|
|
36
41
|
await this.addAspect(aspectIns, aspectData);
|
|
37
42
|
}
|
|
38
|
-
// 合并拦截器方法,提升性能
|
|
39
|
-
for (const module of this.aspectModuleSet) {
|
|
40
|
-
const aspectMapping = this.aspectMappingMap.get(module);
|
|
41
|
-
for (const [method, aspectFn] of aspectMapping) {
|
|
42
|
-
const composeFn = (ins, originMethod) => {
|
|
43
|
-
for (const fn of aspectFn) {
|
|
44
|
-
originMethod = fn(ins, originMethod);
|
|
45
|
-
}
|
|
46
|
-
return originMethod;
|
|
47
|
-
};
|
|
48
|
-
aspectMapping.set(method, [composeFn]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// 绑定完后清理 Set 记录
|
|
52
|
-
this.aspectModuleSet.clear();
|
|
53
43
|
}
|
|
54
44
|
async addAspect(aspectIns, aspectData) {
|
|
55
45
|
const module = aspectData.aspectTarget;
|
|
56
46
|
const names = Object.getOwnPropertyNames(module.prototype);
|
|
57
47
|
const isMatch = aspectData.match ? pm(aspectData.match) : () => true;
|
|
58
|
-
// 存到 set 里用来做循环
|
|
59
|
-
this.aspectModuleSet.add(module);
|
|
60
|
-
/**
|
|
61
|
-
* 拦截器流程
|
|
62
|
-
* 1、在每个被拦截的 class 上做拦截标记,记录哪些方法需要被拦截
|
|
63
|
-
* 2、Container 保存每个 class 的方法对应的拦截器数组
|
|
64
|
-
* 3、创建完实例后,在返回前执行包裹逻辑,把需要拦截的方法都执行一遍拦截(不对原型做修改)
|
|
65
|
-
*/
|
|
66
48
|
for (const name of names) {
|
|
67
49
|
if (name === 'constructor' || !isMatch(name)) {
|
|
68
50
|
continue;
|
|
@@ -71,149 +53,111 @@ class MidwayAspectService {
|
|
|
71
53
|
if (!descriptor || descriptor.writable === false) {
|
|
72
54
|
continue;
|
|
73
55
|
}
|
|
74
|
-
|
|
75
|
-
if (!this.aspectMappingMap.has(module)) {
|
|
76
|
-
this.aspectMappingMap.set(module, new Map());
|
|
77
|
-
}
|
|
78
|
-
const mappingMap = this.aspectMappingMap.get(module);
|
|
79
|
-
if (!mappingMap.has(name)) {
|
|
80
|
-
mappingMap.set(name, []);
|
|
81
|
-
}
|
|
82
|
-
// 把拦截器本身加到数组中
|
|
83
|
-
const methodAspectCollection = mappingMap.get(name);
|
|
84
|
-
if (decorator_1.isAsyncFunction(descriptor.value)) {
|
|
85
|
-
debugLogger(`aspect [#${module.name}:${name}], isAsync=true, aspect class=[${aspectIns.constructor.name}]`);
|
|
86
|
-
const fn = (ins, originMethod) => {
|
|
87
|
-
return async (...args) => {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
let error, result;
|
|
90
|
-
const newProceed = (...args) => {
|
|
91
|
-
return originMethod.apply(ins, args);
|
|
92
|
-
};
|
|
93
|
-
const joinPoint = {
|
|
94
|
-
methodName: name,
|
|
95
|
-
target: ins,
|
|
96
|
-
args: args,
|
|
97
|
-
proceed: newProceed,
|
|
98
|
-
};
|
|
99
|
-
try {
|
|
100
|
-
await ((_a = aspectIns.before) === null || _a === void 0 ? void 0 : _a.call(aspectIns, joinPoint));
|
|
101
|
-
if (aspectIns.around) {
|
|
102
|
-
result = await aspectIns.around(joinPoint);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
result = await originMethod.apply(ins, joinPoint.args);
|
|
106
|
-
}
|
|
107
|
-
joinPoint.proceed = undefined;
|
|
108
|
-
const resultTemp = await ((_b = aspectIns.afterReturn) === null || _b === void 0 ? void 0 : _b.call(aspectIns, joinPoint, result));
|
|
109
|
-
result = typeof resultTemp === 'undefined' ? result : resultTemp;
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
joinPoint.proceed = undefined;
|
|
114
|
-
error = err;
|
|
115
|
-
if (aspectIns.afterThrow) {
|
|
116
|
-
await aspectIns.afterThrow(joinPoint, error);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
throw err;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
finally {
|
|
123
|
-
await ((_c = aspectIns.after) === null || _c === void 0 ? void 0 : _c.call(aspectIns, joinPoint, result, error));
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
methodAspectCollection.push(fn);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
debugLogger(`aspect [#${module.name}:${name}], isAsync=false, aspect class=[${aspectIns.constructor.name}]`);
|
|
131
|
-
const fn = (ins, originMethod) => {
|
|
132
|
-
return (...args) => {
|
|
133
|
-
var _a, _b, _c;
|
|
134
|
-
let error, result;
|
|
135
|
-
const newProceed = (...args) => {
|
|
136
|
-
return originMethod.apply(ins, args);
|
|
137
|
-
};
|
|
138
|
-
const joinPoint = {
|
|
139
|
-
methodName: name,
|
|
140
|
-
target: ins,
|
|
141
|
-
args: args,
|
|
142
|
-
proceed: newProceed,
|
|
143
|
-
};
|
|
144
|
-
try {
|
|
145
|
-
(_a = aspectIns.before) === null || _a === void 0 ? void 0 : _a.call(aspectIns, joinPoint);
|
|
146
|
-
if (aspectIns.around) {
|
|
147
|
-
result = aspectIns.around(joinPoint);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
result = originMethod.apply(ins, joinPoint.args);
|
|
151
|
-
}
|
|
152
|
-
const resultTemp = (_b = aspectIns.afterReturn) === null || _b === void 0 ? void 0 : _b.call(aspectIns, joinPoint, result);
|
|
153
|
-
result = typeof resultTemp === 'undefined' ? result : resultTemp;
|
|
154
|
-
if (result && decorator_1.isClass(result.constructor)) {
|
|
155
|
-
return this.wrapperAspectToInstance(ins);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (err) {
|
|
162
|
-
error = err;
|
|
163
|
-
if (aspectIns.afterThrow) {
|
|
164
|
-
aspectIns.afterThrow(joinPoint, error);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw err;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
(_c = aspectIns.after) === null || _c === void 0 ? void 0 : _c.call(aspectIns, joinPoint, result, error);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
methodAspectCollection.push(fn);
|
|
176
|
-
}
|
|
56
|
+
this.interceptPrototypeMethod(module, name, aspectIns);
|
|
177
57
|
}
|
|
178
58
|
}
|
|
179
59
|
/**
|
|
180
|
-
*
|
|
181
|
-
* @param
|
|
182
|
-
* @
|
|
60
|
+
* intercept class method in prototype
|
|
61
|
+
* @param Clz class you want to intercept
|
|
62
|
+
* @param methodName method name you want to intercept
|
|
63
|
+
* @param aspectObject aspect object, before, round, etc.
|
|
183
64
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
65
|
+
interceptPrototypeMethod(Clz, methodName, aspectObject) {
|
|
66
|
+
const originMethod = Clz.prototype[methodName];
|
|
67
|
+
if ((0, decorator_1.isAsyncFunction)(Clz.prototype[methodName])) {
|
|
68
|
+
Clz.prototype[methodName] = async function (...args) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
let error, result;
|
|
71
|
+
const newProceed = (...args) => {
|
|
72
|
+
return originMethod.apply(this, args);
|
|
73
|
+
};
|
|
74
|
+
const joinPoint = {
|
|
75
|
+
methodName,
|
|
76
|
+
target: this,
|
|
77
|
+
args: args,
|
|
78
|
+
proceed: newProceed,
|
|
79
|
+
};
|
|
80
|
+
if (typeof aspectObject === 'function') {
|
|
81
|
+
aspectObject = aspectObject();
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await ((_a = aspectObject.before) === null || _a === void 0 ? void 0 : _a.call(aspectObject, joinPoint));
|
|
85
|
+
if (aspectObject.around) {
|
|
86
|
+
result = await aspectObject.around(joinPoint);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
result = await originMethod.call(this, ...joinPoint.args);
|
|
90
|
+
}
|
|
91
|
+
joinPoint.proceed = undefined;
|
|
92
|
+
const resultTemp = await ((_b = aspectObject.afterReturn) === null || _b === void 0 ? void 0 : _b.call(aspectObject, joinPoint, result));
|
|
93
|
+
result = typeof resultTemp === 'undefined' ? result : resultTemp;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
joinPoint.proceed = undefined;
|
|
98
|
+
error = err;
|
|
99
|
+
if (aspectObject.afterThrow) {
|
|
100
|
+
await aspectObject.afterThrow(joinPoint, error);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await ((_c = aspectObject.after) === null || _c === void 0 ? void 0 : _c.call(aspectObject, joinPoint, result, error));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
Clz.prototype[methodName] = function (...args) {
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
let error, result;
|
|
115
|
+
const newProceed = (...args) => {
|
|
116
|
+
return originMethod.apply(this, args);
|
|
117
|
+
};
|
|
118
|
+
const joinPoint = {
|
|
119
|
+
methodName,
|
|
120
|
+
target: this,
|
|
121
|
+
args: args,
|
|
122
|
+
proceed: newProceed,
|
|
123
|
+
};
|
|
124
|
+
if (typeof aspectObject === 'function') {
|
|
125
|
+
aspectObject = aspectObject();
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
(_a = aspectObject.before) === null || _a === void 0 ? void 0 : _a.call(aspectObject, joinPoint);
|
|
129
|
+
if (aspectObject.around) {
|
|
130
|
+
result = aspectObject.around(joinPoint);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
result = originMethod.call(this, ...joinPoint.args);
|
|
134
|
+
}
|
|
135
|
+
joinPoint.proceed = undefined;
|
|
136
|
+
const resultTemp = (_b = aspectObject.afterReturn) === null || _b === void 0 ? void 0 : _b.call(aspectObject, joinPoint, result);
|
|
137
|
+
result = typeof resultTemp === 'undefined' ? result : resultTemp;
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
joinPoint.proceed = undefined;
|
|
142
|
+
error = err;
|
|
143
|
+
if (aspectObject.afterThrow) {
|
|
144
|
+
aspectObject.afterThrow(joinPoint, error);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
(_c = aspectObject.after) === null || _c === void 0 ? void 0 : _c.call(aspectObject, joinPoint, result, error);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
211
154
|
}
|
|
212
|
-
return proxy || ins;
|
|
213
|
-
}
|
|
214
|
-
hasAspect(module) {
|
|
215
|
-
return this.aspectMappingMap.has(module);
|
|
216
155
|
}
|
|
217
|
-
}
|
|
156
|
+
};
|
|
157
|
+
MidwayAspectService = __decorate([
|
|
158
|
+
(0, decorator_1.Provide)(),
|
|
159
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
160
|
+
__metadata("design:paramtypes", [Object])
|
|
161
|
+
], MidwayAspectService);
|
|
218
162
|
exports.MidwayAspectService = MidwayAspectService;
|
|
219
163
|
//# sourceMappingURL=aspectService.js.map
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { IConfigService } from '../interface';
|
|
2
|
+
import { MidwayEnvironmentService } from './environmentService';
|
|
3
|
+
import { MidwayInformationService } from './informationService';
|
|
2
4
|
export declare class MidwayConfigService implements IConfigService {
|
|
3
5
|
private envDirMap;
|
|
4
|
-
private container;
|
|
5
6
|
private aliasMap;
|
|
6
|
-
configuration: any;
|
|
7
|
-
isReady: boolean;
|
|
8
|
-
externalObject: Record<string, unknown>[];
|
|
9
|
-
|
|
7
|
+
protected configuration: any;
|
|
8
|
+
protected isReady: boolean;
|
|
9
|
+
protected externalObject: Record<string, unknown>[];
|
|
10
|
+
protected environmentService: MidwayEnvironmentService;
|
|
11
|
+
protected informationService: MidwayInformationService;
|
|
10
12
|
add(configFilePaths: any[]): void;
|
|
11
13
|
addObject(obj: Record<string, unknown>): void;
|
|
12
|
-
getEnvSet
|
|
13
|
-
getConfigEnv
|
|
14
|
+
private getEnvSet;
|
|
15
|
+
private getConfigEnv;
|
|
14
16
|
load(): Promise<void>;
|
|
15
17
|
getConfiguration(configKey?: string): any;
|
|
16
|
-
loadConfig
|
|
18
|
+
private loadConfig;
|
|
17
19
|
clearAllConfig(): void;
|
|
18
20
|
}
|
|
19
21
|
//# sourceMappingURL=configService.d.ts.map
|
|
@@ -1,4 +1,13 @@
|
|
|
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.MidwayConfigService = void 0;
|
|
4
13
|
const extend = require("extend2");
|
|
@@ -7,17 +16,18 @@ const util_1 = require("../util");
|
|
|
7
16
|
const fs_1 = require("fs");
|
|
8
17
|
const decorator_1 = require("@midwayjs/decorator");
|
|
9
18
|
const util = require("util");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
const environmentService_1 = require("./environmentService");
|
|
20
|
+
const informationService_1 = require("./informationService");
|
|
21
|
+
const debug = util.debuglog('midway:debug');
|
|
22
|
+
let MidwayConfigService = class MidwayConfigService {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.envDirMap = new Map();
|
|
13
25
|
this.aliasMap = {
|
|
14
26
|
prod: 'production',
|
|
15
27
|
unittest: 'test',
|
|
16
28
|
};
|
|
17
29
|
this.isReady = false;
|
|
18
30
|
this.externalObject = [];
|
|
19
|
-
this.container = container;
|
|
20
|
-
this.envDirMap = new Map();
|
|
21
31
|
}
|
|
22
32
|
add(configFilePaths) {
|
|
23
33
|
for (const dir of configFilePaths) {
|
|
@@ -33,11 +43,11 @@ class MidwayConfigService {
|
|
|
33
43
|
}
|
|
34
44
|
else {
|
|
35
45
|
// directory
|
|
36
|
-
const fileStat = fs_1.statSync(dir);
|
|
46
|
+
const fileStat = (0, fs_1.statSync)(dir);
|
|
37
47
|
if (fileStat.isDirectory()) {
|
|
38
|
-
const files = fs_1.readdirSync(dir);
|
|
48
|
+
const files = (0, fs_1.readdirSync)(dir);
|
|
39
49
|
this.add(files.map(file => {
|
|
40
|
-
return path_1.join(dir, file);
|
|
50
|
+
return (0, path_1.join)(dir, file);
|
|
41
51
|
}));
|
|
42
52
|
}
|
|
43
53
|
}
|
|
@@ -67,7 +77,7 @@ class MidwayConfigService {
|
|
|
67
77
|
}
|
|
68
78
|
getConfigEnv(configFilePath) {
|
|
69
79
|
// parse env
|
|
70
|
-
const configFileBaseName = path_1.basename(configFilePath);
|
|
80
|
+
const configFileBaseName = (0, path_1.basename)(configFilePath);
|
|
71
81
|
const splits = configFileBaseName.split('.');
|
|
72
82
|
const suffix = splits.pop();
|
|
73
83
|
if (suffix !== 'js' && suffix !== 'ts') {
|
|
@@ -81,24 +91,41 @@ class MidwayConfigService {
|
|
|
81
91
|
// get default
|
|
82
92
|
const defaultSet = this.getEnvSet('default');
|
|
83
93
|
// get current set
|
|
84
|
-
const currentEnvSet = this.getEnvSet(this.
|
|
94
|
+
const currentEnvSet = this.getEnvSet(this.environmentService.getCurrentEnvironment());
|
|
85
95
|
// merge set
|
|
86
96
|
const target = {};
|
|
87
97
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
88
|
-
let config = filename;
|
|
89
|
-
if (
|
|
90
|
-
|
|
98
|
+
let config = await this.loadConfig(filename);
|
|
99
|
+
if ((0, decorator_1.isFunction)(config)) {
|
|
100
|
+
// eslint-disable-next-line prefer-spread
|
|
101
|
+
config = config.apply(null, [
|
|
102
|
+
{
|
|
103
|
+
pkg: this.informationService.getPkg(),
|
|
104
|
+
name: this.informationService.getProjectName(),
|
|
105
|
+
baseDir: this.informationService.getBaseDir(),
|
|
106
|
+
appDir: this.informationService.getAppDir(),
|
|
107
|
+
HOME: this.informationService.getHome(),
|
|
108
|
+
root: this.informationService.getRoot(),
|
|
109
|
+
env: this.environmentService.getCurrentEnvironment(),
|
|
110
|
+
},
|
|
111
|
+
target,
|
|
112
|
+
]);
|
|
91
113
|
}
|
|
92
114
|
if (!config) {
|
|
93
115
|
continue;
|
|
94
116
|
}
|
|
95
|
-
|
|
117
|
+
if (typeof filename === 'string') {
|
|
118
|
+
debug('[config]: Loaded config %s, %j', filename, config);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
debug('[config]: Loaded config %j', config);
|
|
122
|
+
}
|
|
96
123
|
extend(true, target, config);
|
|
97
124
|
}
|
|
98
125
|
if (this.externalObject.length) {
|
|
99
126
|
for (const externalObject of this.externalObject) {
|
|
100
127
|
if (externalObject) {
|
|
101
|
-
debug('Loaded external object %j', externalObject);
|
|
128
|
+
debug('[config]: Loaded external object %j', externalObject);
|
|
102
129
|
extend(true, target, externalObject);
|
|
103
130
|
}
|
|
104
131
|
}
|
|
@@ -108,38 +135,34 @@ class MidwayConfigService {
|
|
|
108
135
|
}
|
|
109
136
|
getConfiguration(configKey) {
|
|
110
137
|
if (configKey) {
|
|
111
|
-
|
|
112
|
-
return util_1.safelyGet(configKey, this.configuration);
|
|
138
|
+
return (0, util_1.safelyGet)(configKey, this.configuration);
|
|
113
139
|
}
|
|
114
140
|
return this.configuration;
|
|
115
141
|
}
|
|
116
|
-
async loadConfig(configFilename
|
|
117
|
-
|
|
118
|
-
|
|
142
|
+
async loadConfig(configFilename) {
|
|
143
|
+
let exports = typeof configFilename === 'string'
|
|
144
|
+
? require(configFilename)
|
|
145
|
+
: configFilename;
|
|
119
146
|
if (exports && exports['default'] && Object.keys(exports).length === 1) {
|
|
120
147
|
exports = exports['default'];
|
|
121
148
|
}
|
|
122
|
-
|
|
123
|
-
if (decorator_1.isFunction(exports)) {
|
|
124
|
-
const informationService = this.container.getInformationService();
|
|
125
|
-
// eslint-disable-next-line prefer-spread
|
|
126
|
-
result = exports.apply(null, [
|
|
127
|
-
{
|
|
128
|
-
pkg: informationService.getPkg(),
|
|
129
|
-
name: informationService.getProjectName(),
|
|
130
|
-
baseDir: informationService.getBaseDir(),
|
|
131
|
-
appDir: informationService.getAppDir(),
|
|
132
|
-
HOME: informationService.getHome(),
|
|
133
|
-
root: informationService.getRoot(),
|
|
134
|
-
},
|
|
135
|
-
target,
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
149
|
+
return exports;
|
|
139
150
|
}
|
|
140
151
|
clearAllConfig() {
|
|
141
152
|
this.configuration.clear();
|
|
142
153
|
}
|
|
143
|
-
}
|
|
154
|
+
};
|
|
155
|
+
__decorate([
|
|
156
|
+
(0, decorator_1.Inject)(),
|
|
157
|
+
__metadata("design:type", environmentService_1.MidwayEnvironmentService)
|
|
158
|
+
], MidwayConfigService.prototype, "environmentService", void 0);
|
|
159
|
+
__decorate([
|
|
160
|
+
(0, decorator_1.Inject)(),
|
|
161
|
+
__metadata("design:type", informationService_1.MidwayInformationService)
|
|
162
|
+
], MidwayConfigService.prototype, "informationService", void 0);
|
|
163
|
+
MidwayConfigService = __decorate([
|
|
164
|
+
(0, decorator_1.Provide)(),
|
|
165
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
166
|
+
], MidwayConfigService);
|
|
144
167
|
exports.MidwayConfigService = MidwayConfigService;
|
|
145
168
|
//# sourceMappingURL=configService.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HandlerFunction, IMidwayContainer, MethodHandlerFunction, ParameterHandlerFunction } from '../interface';
|
|
2
|
+
export declare class MidwayDecoratorService {
|
|
3
|
+
readonly applicationContext: IMidwayContainer;
|
|
4
|
+
private propertyHandlerMap;
|
|
5
|
+
private methodDecoratorMap;
|
|
6
|
+
private parameterDecoratorMap;
|
|
7
|
+
private aspectService;
|
|
8
|
+
constructor(applicationContext: IMidwayContainer);
|
|
9
|
+
protected init(): Promise<void>;
|
|
10
|
+
registerPropertyHandler(decoratorKey: string, fn: HandlerFunction): void;
|
|
11
|
+
registerMethodHandler(decoratorKey: string, fn: MethodHandlerFunction): void;
|
|
12
|
+
registerParameterHandler(decoratorKey: string, fn: ParameterHandlerFunction): void;
|
|
13
|
+
/**
|
|
14
|
+
* binding getter method for decorator
|
|
15
|
+
*
|
|
16
|
+
* @param prop
|
|
17
|
+
* @param instance
|
|
18
|
+
* @param getterHandler
|
|
19
|
+
*/
|
|
20
|
+
private defineGetterPropertyValue;
|
|
21
|
+
private getHandler;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=decoratorService.d.ts.map
|