@midwayjs/core 3.4.0 → 3.4.4
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/dist/common/fileDetector.d.ts +1 -0
- package/dist/common/fileDetector.js +1 -1
- package/dist/common/filterManager.js +2 -1
- package/dist/context/container.js +10 -3
- package/dist/service/configService.d.ts +7 -0
- package/dist/service/configService.js +28 -1
- package/dist/service/webRouterService.js +1 -1
- package/package.json +3 -3
|
@@ -45,7 +45,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
45
45
|
});
|
|
46
46
|
// 检查重复模块
|
|
47
47
|
const checkDuplicatedHandler = (module, options) => {
|
|
48
|
-
if (decorator_1.Types.isClass(module)) {
|
|
48
|
+
if (this.extraDetectorOptions.conflictCheck && decorator_1.Types.isClass(module)) {
|
|
49
49
|
const name = (0, decorator_1.getProviderName)(module);
|
|
50
50
|
if (name) {
|
|
51
51
|
if (this.duplicateModuleCheckSet.has(name)) {
|
|
@@ -31,10 +31,11 @@ class FilterManager {
|
|
|
31
31
|
const filter = await applicationContext.getAsync(FilterClass);
|
|
32
32
|
const exceptionMetadata = (0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, FilterClass);
|
|
33
33
|
if (exceptionMetadata && exceptionMetadata.catchTargets) {
|
|
34
|
+
exceptionMetadata.catchOptions = exceptionMetadata.catchOptions || {};
|
|
34
35
|
for (const Exception of exceptionMetadata.catchTargets) {
|
|
35
36
|
this.exceptionMap.set(Exception, {
|
|
36
37
|
filter,
|
|
37
|
-
catchOptions: exceptionMetadata.catchOptions
|
|
38
|
+
catchOptions: exceptionMetadata.catchOptions,
|
|
38
39
|
});
|
|
39
40
|
if (exceptionMetadata.catchOptions['matchPrototype']) {
|
|
40
41
|
this.protoMatchList.push(err => {
|
|
@@ -53,13 +53,15 @@ class ContainerConfiguration {
|
|
|
53
53
|
namespace = configurationOptions.namespace;
|
|
54
54
|
this.namespaceList.push(namespace);
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
this.detectorOptionsList.push({
|
|
57
|
+
conflictCheck: configurationOptions.conflictCheck,
|
|
58
|
+
...configurationOptions.detectorOptions,
|
|
59
|
+
});
|
|
59
60
|
debug(`[core]: load configuration in namespace="${namespace}"`);
|
|
60
61
|
this.addImports(configurationOptions.imports);
|
|
61
62
|
this.addImportObjects(configurationOptions.importObjects);
|
|
62
63
|
this.addImportConfigs(configurationOptions.importConfigs);
|
|
64
|
+
this.addImportConfigFilter(configurationOptions.importConfigFilter);
|
|
63
65
|
this.bindConfigurationClass(configurationExport, namespace);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -78,6 +80,11 @@ class ContainerConfiguration {
|
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
}
|
|
83
|
+
addImportConfigFilter(importConfigFilter) {
|
|
84
|
+
if (importConfigFilter) {
|
|
85
|
+
this.container.get(configService_1.MidwayConfigService).addFilter(importConfigFilter);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
81
88
|
addImports(imports = []) {
|
|
82
89
|
var _a;
|
|
83
90
|
// 处理 imports
|
|
@@ -14,6 +14,7 @@ export declare class MidwayConfigService implements IConfigService {
|
|
|
14
14
|
protected isReady: boolean;
|
|
15
15
|
protected externalObject: Record<string, unknown>[];
|
|
16
16
|
protected appInfo: MidwayAppInfo;
|
|
17
|
+
protected configFilterList: Array<(config: Record<string, any>) => Record<string, any> | undefined>;
|
|
17
18
|
protected environmentService: MidwayEnvironmentService;
|
|
18
19
|
protected informationService: MidwayInformationService;
|
|
19
20
|
protected init(): void;
|
|
@@ -27,6 +28,12 @@ export declare class MidwayConfigService implements IConfigService {
|
|
|
27
28
|
private loadConfig;
|
|
28
29
|
clearAllConfig(): void;
|
|
29
30
|
clearConfigMergeOrder(): void;
|
|
31
|
+
/**
|
|
32
|
+
* add a config filter
|
|
33
|
+
* @param filter
|
|
34
|
+
*/
|
|
35
|
+
addFilter(filter: (config: Record<string, any>) => Record<string, any>): void;
|
|
36
|
+
protected runWithFilter(config: Record<string, any>): Record<string, any>;
|
|
30
37
|
}
|
|
31
38
|
export {};
|
|
32
39
|
//# sourceMappingURL=configService.d.ts.map
|
|
@@ -30,6 +30,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
30
30
|
this.configMergeOrder = [];
|
|
31
31
|
this.isReady = false;
|
|
32
32
|
this.externalObject = [];
|
|
33
|
+
this.configFilterList = [];
|
|
33
34
|
}
|
|
34
35
|
init() {
|
|
35
36
|
this.appInfo = {
|
|
@@ -80,6 +81,11 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
80
81
|
}
|
|
81
82
|
addObject(obj, reverse = false) {
|
|
82
83
|
if (this.isReady) {
|
|
84
|
+
obj = this.runWithFilter(obj);
|
|
85
|
+
if (!obj) {
|
|
86
|
+
debug('[config]: Filter config and got undefined will be drop it');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
83
89
|
this.configMergeOrder.push({
|
|
84
90
|
env: 'default',
|
|
85
91
|
extraPath: '',
|
|
@@ -131,6 +137,11 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
131
137
|
if (!config) {
|
|
132
138
|
continue;
|
|
133
139
|
}
|
|
140
|
+
config = this.runWithFilter(config);
|
|
141
|
+
if (!config) {
|
|
142
|
+
debug('[config]: Filter config and got undefined will be drop it');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
134
145
|
if (typeof filename === 'string') {
|
|
135
146
|
debug('[config]: Loaded config %s, %j', filename, config);
|
|
136
147
|
}
|
|
@@ -147,8 +158,9 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
147
158
|
(0, extend_1.extend)(true, target, config);
|
|
148
159
|
}
|
|
149
160
|
if (this.externalObject.length) {
|
|
150
|
-
for (
|
|
161
|
+
for (let externalObject of this.externalObject) {
|
|
151
162
|
if (externalObject) {
|
|
163
|
+
externalObject = this.runWithFilter(externalObject);
|
|
152
164
|
debug('[config]: Loaded external object %j', externalObject);
|
|
153
165
|
(0, extend_1.extend)(true, target, externalObject);
|
|
154
166
|
this.configMergeOrder.push({
|
|
@@ -192,6 +204,21 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
192
204
|
clearConfigMergeOrder() {
|
|
193
205
|
this.configMergeOrder.length = 0;
|
|
194
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* add a config filter
|
|
209
|
+
* @param filter
|
|
210
|
+
*/
|
|
211
|
+
addFilter(filter) {
|
|
212
|
+
this.configFilterList.push(filter);
|
|
213
|
+
}
|
|
214
|
+
runWithFilter(config) {
|
|
215
|
+
for (const filter of this.configFilterList) {
|
|
216
|
+
debug(`[config]: Filter config by filter = "${filter.name || 'anonymous filter'}"`);
|
|
217
|
+
config = filter(config);
|
|
218
|
+
debug('[config]: Filter config result = %j', config);
|
|
219
|
+
}
|
|
220
|
+
return config;
|
|
221
|
+
}
|
|
195
222
|
};
|
|
196
223
|
__decorate([
|
|
197
224
|
(0, decorator_1.Inject)(),
|
|
@@ -95,7 +95,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
97
|
// 不同的 controller,可能会有相同的 prefix,一旦 options 不同,就要报错
|
|
98
|
-
if (middleware) {
|
|
98
|
+
if (middleware && middleware.length > 0) {
|
|
99
99
|
const originRoute = this.routesPriority.filter(el => {
|
|
100
100
|
return el.prefix === prefix;
|
|
101
101
|
})[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/decorator": "^3.4.
|
|
24
|
+
"@midwayjs/decorator": "^3.4.4",
|
|
25
25
|
"koa": "2.13.4",
|
|
26
26
|
"midway-test-component": "*",
|
|
27
27
|
"mm": "3.2.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f6b5a3ff3d19ae2a0d33a5a14357bee2a8463767"
|
|
49
49
|
}
|