@midwayjs/core 3.7.0 → 3.8.0

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.
@@ -2,6 +2,7 @@ export declare abstract class DataSourceManager<T> {
2
2
  protected dataSource: Map<string, T>;
3
3
  protected options: {};
4
4
  protected modelMapping: WeakMap<object, any>;
5
+ private innerDefaultDataSourceName;
5
6
  protected initDataSource(options: any, appDir: string): Promise<void>;
6
7
  /**
7
8
  * get a data source instance
@@ -113,7 +113,20 @@ class DataSourceManager {
113
113
  this.dataSource.clear();
114
114
  }
115
115
  getDefaultDataSourceName() {
116
- return this.options['defaultDataSourceName'];
116
+ if (this.innerDefaultDataSourceName === undefined) {
117
+ if (this.options['defaultDataSourceName']) {
118
+ this.innerDefaultDataSourceName = this.options['defaultDataSourceName'];
119
+ }
120
+ else if (this.dataSource.size === 1) {
121
+ // Set the default source name when there is only one data source
122
+ this.innerDefaultDataSourceName = Array.from(this.dataSource.keys())[0];
123
+ }
124
+ else {
125
+ // Set empty string for cache
126
+ this.innerDefaultDataSourceName = '';
127
+ }
128
+ }
129
+ return this.innerDefaultDataSourceName;
117
130
  }
118
131
  }
119
132
  exports.DataSourceManager = DataSourceManager;
@@ -127,7 +140,6 @@ function globModels(globString, appDir) {
127
140
  if (/\*/.test(globString)) {
128
141
  cwd = appDir;
129
142
  pattern = [...constants_1.DEFAULT_PATTERN.map(p => (0, path_1.join)(globString, p))];
130
- pattern.push(globString);
131
143
  }
132
144
  else {
133
145
  pattern = [...constants_1.DEFAULT_PATTERN];
@@ -12,5 +12,6 @@ export declare abstract class ServiceFactory<T> {
12
12
  protected abstract createClient(config: any, clientName: any): Promise<T | void> | (T | void);
13
13
  protected destroyClient(client: T): Promise<void>;
14
14
  stop(): Promise<void>;
15
+ getDefaultClientName(): string;
15
16
  }
16
17
  //# sourceMappingURL=serviceFactory.d.ts.map
@@ -17,7 +17,6 @@ class ServiceFactory {
17
17
  options.clients = options.clients || {};
18
18
  options.clients['default'] = options.clients['default'] || {};
19
19
  (0, extend_1.extend)(true, options.clients['default'], options.client);
20
- delete options.client;
21
20
  }
22
21
  // multi client
23
22
  if (options.clients) {
@@ -49,6 +48,9 @@ class ServiceFactory {
49
48
  await this.destroyClient(value);
50
49
  }
51
50
  }
51
+ getDefaultClientName() {
52
+ return this.options['defaultClientName'];
53
+ }
52
54
  }
53
55
  exports.ServiceFactory = ServiceFactory;
54
56
  //# sourceMappingURL=serviceFactory.js.map
@@ -22,6 +22,7 @@ export declare type ServiceFactoryConfigOption<OPTIONS> = {
22
22
  clients?: {
23
23
  [key: string]: PowerPartial<OPTIONS>;
24
24
  };
25
+ defaultClientName?: string;
25
26
  };
26
27
  export declare type DataSourceManagerConfigOption<OPTIONS> = {
27
28
  default?: PowerPartial<OPTIONS>;
@@ -114,8 +114,6 @@ export declare class MidwayWebRouterService {
114
114
  private isReady;
115
115
  protected routes: Map<string, RouterInfo[]>;
116
116
  protected routesPriority: RouterPriority[];
117
- private cachedFlattenRouteList;
118
- private includeCompileUrlPattern;
119
117
  constructor(options?: RouterCollectorOptions);
120
118
  protected analyze(): Promise<void>;
121
119
  protected analyzeController(): void;
@@ -239,7 +237,6 @@ export declare class MidwayWebRouterService {
239
237
  getRouterTable(): Promise<Map<string, RouterInfo[]>>;
240
238
  getFlattenRouterTable(options?: {
241
239
  compileUrlPattern?: boolean;
242
- noCache?: boolean;
243
240
  }): Promise<RouterInfo[]>;
244
241
  getMatchedRouterInfo(routerUrl: string, method: string): Promise<RouterInfo | undefined>;
245
242
  protected checkDuplicateAndPush(prefix: any, routerInfo: RouterInfo): void;
@@ -23,7 +23,6 @@ let MidwayWebRouterService = class MidwayWebRouterService {
23
23
  this.isReady = false;
24
24
  this.routes = new Map();
25
25
  this.routesPriority = [];
26
- this.includeCompileUrlPattern = false;
27
26
  }
28
27
  async analyze() {
29
28
  this.analyzeController();
@@ -182,6 +181,8 @@ let MidwayWebRouterService = class MidwayWebRouterService {
182
181
  this.checkDuplicateAndPush(prefix, Object.assign(routerInfoOption, {
183
182
  method: routerFunction,
184
183
  }));
184
+ // sort again
185
+ this.sortPrefixAndRouter();
185
186
  }
186
187
  sortRouter(urlMatchList) {
187
188
  // 1. 绝对路径规则优先级最高如 /ab/cb/e
@@ -260,18 +261,6 @@ let MidwayWebRouterService = class MidwayWebRouterService {
260
261
  return this.routes;
261
262
  }
262
263
  async getFlattenRouterTable(options = {}) {
263
- if (this.cachedFlattenRouteList && !options.noCache) {
264
- if (options.compileUrlPattern && !this.includeCompileUrlPattern) {
265
- this.includeCompileUrlPattern = true;
266
- // attach match pattern function
267
- for (const item of this.cachedFlattenRouteList) {
268
- if (item.fullUrlFlattenString) {
269
- item.fullUrlCompiledRegexp = pathToRegexp_1.PathToRegexpUtil.toRegexp(item.fullUrlFlattenString);
270
- }
271
- }
272
- }
273
- return this.cachedFlattenRouteList;
274
- }
275
264
  if (!this.isReady) {
276
265
  await this.analyze();
277
266
  this.isReady = true;
@@ -281,7 +270,6 @@ let MidwayWebRouterService = class MidwayWebRouterService {
281
270
  routeArr = routeArr.concat(this.routes.get(routerPriority.prefix));
282
271
  }
283
272
  if (options.compileUrlPattern) {
284
- this.includeCompileUrlPattern = true;
285
273
  // attach match pattern function
286
274
  for (const item of routeArr) {
287
275
  if (item.fullUrlFlattenString) {
@@ -289,7 +277,6 @@ let MidwayWebRouterService = class MidwayWebRouterService {
289
277
  }
290
278
  }
291
279
  }
292
- this.cachedFlattenRouteList = routeArr;
293
280
  return routeArr;
294
281
  }
295
282
  async getMatchedRouterInfo(routerUrl, method) {
@@ -5,11 +5,6 @@ const util = require("util");
5
5
  const ToString = Function.prototype.toString;
6
6
  const hasOwn = Object.prototype.hasOwnProperty;
7
7
  const toStr = Object.prototype.toString;
8
- function fnBody(fn) {
9
- return ToString.call(fn)
10
- .replace(/^[^{]*{\s*/, '')
11
- .replace(/\s*}[^}]*$/, '');
12
- }
13
8
  function isString(value) {
14
9
  return typeof value === 'string';
15
10
  }
@@ -21,10 +16,6 @@ function isClass(fn) {
21
16
  if (/^class[\s{]/.test(ToString.call(fn))) {
22
17
  return true;
23
18
  }
24
- // babel.js classCallCheck() & inlined
25
- const body = fnBody(fn);
26
- return (/classCallCheck\(/.test(body) ||
27
- /TypeError\("Cannot call a class as a function"\)/.test(body));
28
19
  }
29
20
  exports.isClass = isClass;
30
21
  function isAsyncFunction(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "mm": "3.2.0",
27
27
  "pg": "8.8.0",
28
28
  "raw-body": "2.5.1",
29
- "sinon": "14.0.1"
29
+ "sinon": "14.0.2"
30
30
  },
31
31
  "dependencies": {
32
32
  "@midwayjs/glob": "^1.0.2",
@@ -38,10 +38,10 @@
38
38
  "author": "Harry Chen <czy88840616@gmail.com>",
39
39
  "repository": {
40
40
  "type": "git",
41
- "url": "http://github.com/midwayjs/midway.git"
41
+ "url": "https://github.com/midwayjs/midway.git"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=12"
45
45
  },
46
- "gitHead": "99386083ee26b386fd508b9c892091c914e77535"
46
+ "gitHead": "5c640c7182923587139f9f9c0aecf50585798e1e"
47
47
  }