@midwayjs/core 3.4.3 → 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.
@@ -61,6 +61,7 @@ class ContainerConfiguration {
61
61
  this.addImports(configurationOptions.imports);
62
62
  this.addImportObjects(configurationOptions.importObjects);
63
63
  this.addImportConfigs(configurationOptions.importConfigs);
64
+ this.addImportConfigFilter(configurationOptions.importConfigFilter);
64
65
  this.bindConfigurationClass(configurationExport, namespace);
65
66
  }
66
67
  }
@@ -79,6 +80,11 @@ class ContainerConfiguration {
79
80
  }
80
81
  }
81
82
  }
83
+ addImportConfigFilter(importConfigFilter) {
84
+ if (importConfigFilter) {
85
+ this.container.get(configService_1.MidwayConfigService).addFilter(importConfigFilter);
86
+ }
87
+ }
82
88
  addImports(imports = []) {
83
89
  var _a;
84
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 (const externalObject of this.externalObject) {
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)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.4.3",
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.1",
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": "0d79293f56d01a3ef3589e6a6ef53c582ac0c46f"
48
+ "gitHead": "f6b5a3ff3d19ae2a0d33a5a14357bee2a8463767"
49
49
  }