@midwayjs/core 3.4.1 → 3.4.6

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.
@@ -28,7 +28,7 @@ export declare abstract class DataSourceManager<T> {
28
28
  abstract getName(): string;
29
29
  protected abstract createDataSource(config: any, dataSourceName: string): Promise<T | void> | (T | void);
30
30
  protected abstract checkConnected(dataSource: T): Promise<boolean>;
31
- protected destroyDataSource(dataSource: T): Promise<void>;
31
+ protected abstract destroyDataSource(dataSource: T): Promise<void>;
32
32
  stop(): Promise<void>;
33
33
  }
34
34
  export declare function globModels(globString: string, appDir: string): any[];
@@ -91,11 +91,11 @@ class DataSourceManager {
91
91
  getDataSourceNameByModel(modelOrRepository) {
92
92
  return this.modelMapping.get(modelOrRepository);
93
93
  }
94
- async destroyDataSource(dataSource) { }
95
94
  async stop() {
96
- for (const value of this.dataSource.values()) {
97
- await this.destroyDataSource(value);
98
- }
95
+ const arr = Array.from(this.dataSource.values());
96
+ await Promise.all(arr.map(dbh => {
97
+ return this.destroyDataSource(dbh);
98
+ }));
99
99
  this.dataSource.clear();
100
100
  }
101
101
  }
@@ -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 => {
@@ -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)(),
@@ -30,6 +30,7 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
30
30
  for (const routerInfo of this.routes.values()) {
31
31
  for (const info of routerInfo) {
32
32
  if (info.requestMethod === 'all') {
33
+ info.functionTriggerMetadata = info.functionTriggerMetadata || {};
33
34
  info.functionTriggerMetadata.method = [
34
35
  'get',
35
36
  'post',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.4.1",
3
+ "version": "3.4.6",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,12 +21,12 @@
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",
28
28
  "raw-body": "2.5.1",
29
- "sinon": "13.0.2"
29
+ "sinon": "14.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@midwayjs/decorator": "*"
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "c7b47267c80f93407537677d8366f68bc6dfc462"
48
+ "gitHead": "36687482782bcf526efc2a4773c09e166820c1a8"
49
49
  }