@midwayjs/core 3.4.10 → 3.4.13

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.
@@ -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 = [];
@@ -69,12 +70,10 @@ let MidwayConfigService = class MidwayConfigService {
69
70
  else {
70
71
  // object add
71
72
  for (const env in dir) {
73
+ this.getEnvSet(env).add(dir[env]);
72
74
  if (this.aliasMap[env]) {
73
75
  this.getEnvSet(this.aliasMap[env]).add(dir[env]);
74
76
  }
75
- else {
76
- this.getEnvSet(env).add(dir[env]);
77
- }
78
77
  }
79
78
  }
80
79
  }
@@ -161,6 +160,10 @@ let MidwayConfigService = class MidwayConfigService {
161
160
  for (let externalObject of this.externalObject) {
162
161
  if (externalObject) {
163
162
  externalObject = this.runWithFilter(externalObject);
163
+ if (!externalObject) {
164
+ debug('[config]: Filter config and got undefined will be drop it');
165
+ continue;
166
+ }
164
167
  debug('[config]: Loaded external object %j', externalObject);
165
168
  (0, extend_1.extend)(true, target, externalObject);
166
169
  this.configMergeOrder.push({
@@ -199,7 +202,7 @@ let MidwayConfigService = class MidwayConfigService {
199
202
  return exports;
200
203
  }
201
204
  clearAllConfig() {
202
- this.configuration.clear();
205
+ this.configuration = {};
203
206
  }
204
207
  clearConfigMergeOrder() {
205
208
  this.configMergeOrder.length = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.4.10",
3
+ "version": "3.4.13",
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": "aeb117633ecbc3299002b220f436dc3b5450d361"
48
+ "gitHead": "bde878f01df0a4b27919eea367d100b5ee5edb04"
49
49
  }