@midwayjs/core 3.4.9 → 3.4.12

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.
@@ -18,38 +18,36 @@ class DataSourceManager {
18
18
  }
19
19
  async initDataSource(options, appDir) {
20
20
  this.options = options;
21
- if (options.dataSource) {
22
- for (const dataSourceName in options.dataSource) {
23
- const dataSourceOptions = options.dataSource[dataSourceName];
24
- if (dataSourceOptions['entities']) {
25
- const entities = new Set();
26
- // loop entities and glob files to model
27
- for (const entity of dataSourceOptions['entities']) {
28
- if (typeof entity === 'string') {
29
- // string will be glob file
30
- const models = globModels(entity, appDir);
31
- for (const model of models) {
32
- entities.add(model);
33
- this.modelMapping.set(model, dataSourceName);
34
- }
35
- }
36
- else {
37
- // model will be add to array
38
- entities.add(entity);
39
- this.modelMapping.set(entity, dataSourceName);
21
+ if (!options.dataSource) {
22
+ throw new error_1.MidwayParameterError('DataSourceManager must set options.dataSource.');
23
+ }
24
+ for (const dataSourceName in options.dataSource) {
25
+ const dataSourceOptions = options.dataSource[dataSourceName];
26
+ if (dataSourceOptions['entities']) {
27
+ const entities = new Set();
28
+ // loop entities and glob files to model
29
+ for (const entity of dataSourceOptions['entities']) {
30
+ if (typeof entity === 'string') {
31
+ // string will be glob file
32
+ const models = globModels(entity, appDir);
33
+ for (const model of models) {
34
+ entities.add(model);
35
+ this.modelMapping.set(model, dataSourceName);
40
36
  }
41
37
  }
42
- dataSourceOptions['entities'] = Array.from(entities);
38
+ else {
39
+ // model will be add to array
40
+ entities.add(entity);
41
+ this.modelMapping.set(entity, dataSourceName);
42
+ }
43
43
  }
44
- // create data source
45
- const opts = {
46
- cacheInstance: options.cacheInstance, // will default true
47
- };
48
- await this.createInstance(dataSourceOptions, dataSourceName, opts);
44
+ dataSourceOptions['entities'] = Array.from(entities);
49
45
  }
50
- }
51
- else {
52
- throw new error_1.MidwayParameterError('DataSourceManager must set options.dataSource.');
46
+ // create data source
47
+ const opts = {
48
+ cacheInstance: options.cacheInstance, // will default true
49
+ };
50
+ await this.createInstance(dataSourceOptions, dataSourceName, opts);
53
51
  }
54
52
  }
55
53
  /**
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServiceFactory = void 0;
4
- const assert = require("assert");
5
4
  const extend_1 = require("../util/extend");
6
5
  /**
7
6
  * 多客户端工厂实现
@@ -13,13 +12,14 @@ class ServiceFactory {
13
12
  }
14
13
  async initClients(options = {}) {
15
14
  this.options = options;
16
- assert(!(options.client && options.clients), `midway:${this.getName()} can not set options.client and options.clients both`);
17
- // alias app[name] as client, but still support createInstance method
15
+ // merge options.client to options.clients['default']
18
16
  if (options.client) {
19
- await this.createInstance(options.client, 'default');
20
- return;
17
+ options.clients = options.clients || {};
18
+ options.clients['default'] = options.clients['default'] || {};
19
+ (0, extend_1.extend)(true, options.clients['default'], options.client);
20
+ delete options.client;
21
21
  }
22
- // multi client, use app[name].getInstance(id)
22
+ // multi client
23
23
  if (options.clients) {
24
24
  for (const id of Object.keys(options.clients)) {
25
25
  await this.createInstance(options.clients[id], id);
@@ -307,9 +307,9 @@ export declare type NextFunction = () => Promise<any>;
307
307
  * Common middleware definition
308
308
  */
309
309
  export interface IMiddleware<CTX, R, N = unknown> {
310
- resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N> | Promise<FunctionMiddleware<CTX, R, N>>;
311
- match?: (ctx?: CTX) => boolean;
312
- ignore?: (ctx?: CTX) => boolean;
310
+ resolve: (app: IMidwayApplication) => FunctionMiddleware<CTX, R, N> | Promise<FunctionMiddleware<CTX, R, N>>;
311
+ match?: (ctx: CTX) => boolean;
312
+ ignore?: (ctx: CTX) => boolean;
313
313
  }
314
314
  export declare type FunctionMiddleware<CTX, R, N = unknown> = N extends true ? (req: CTX, res: R, next: N) => any : (context: CTX, next: R, options?: any) => any;
315
315
  export declare type ClassMiddleware<CTX, R, N> = new (...args: any[]) => IMiddleware<CTX, R, N>;
@@ -10,7 +10,7 @@ export declare class MidwayConfigService implements IConfigService {
10
10
  private envDirMap;
11
11
  private aliasMap;
12
12
  private configMergeOrder;
13
- protected configuration: any;
13
+ protected configuration: {};
14
14
  protected isReady: boolean;
15
15
  protected externalObject: Record<string, unknown>[];
16
16
  protected appInfo: MidwayAppInfo;
@@ -28,6 +28,7 @@ let MidwayConfigService = class MidwayConfigService {
28
28
  unittest: 'test',
29
29
  };
30
30
  this.configMergeOrder = [];
31
+ this.configuration = {};
31
32
  this.isReady = false;
32
33
  this.externalObject = [];
33
34
  this.configFilterList = [];
@@ -161,6 +162,10 @@ let MidwayConfigService = class MidwayConfigService {
161
162
  for (let externalObject of this.externalObject) {
162
163
  if (externalObject) {
163
164
  externalObject = this.runWithFilter(externalObject);
165
+ if (!externalObject) {
166
+ debug('[config]: Filter config and got undefined will be drop it');
167
+ continue;
168
+ }
164
169
  debug('[config]: Loaded external object %j', externalObject);
165
170
  (0, extend_1.extend)(true, target, externalObject);
166
171
  this.configMergeOrder.push({
@@ -199,7 +204,7 @@ let MidwayConfigService = class MidwayConfigService {
199
204
  return exports;
200
205
  }
201
206
  clearAllConfig() {
202
- this.configuration.clear();
207
+ this.configuration = {};
203
208
  }
204
209
  clearConfigMergeOrder() {
205
210
  this.configMergeOrder.length = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.4.9",
3
+ "version": "3.4.12",
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.4",
24
+ "@midwayjs/decorator": "^3.4.11",
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": "bc8113cff70d88a31e44bde69c395f61a7de2045"
48
+ "gitHead": "96425bbb3a39dbe8f66069facc5b7440886f9cfe"
49
49
  }