@midwayjs/core 2.13.1 → 2.14.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,55 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.14.0](https://github.com/midwayjs/midway/compare/v2.13.5...v2.14.0) (2021-12-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([5d5f299](https://github.com/midwayjs/midway/commit/5d5f2992be116ca71b21f01fd782e3a2ac072496))
12
+ * router sort ([#1383](https://github.com/midwayjs/midway/issues/1383)) ([6b3ab56](https://github.com/midwayjs/midway/commit/6b3ab56a0525435c67f9730742aa1573d61ea0fc))
13
+
14
+
15
+
16
+
17
+
18
+ ## [2.13.4](https://github.com/midwayjs/midway/compare/v2.13.3...v2.13.4) (2021-10-21)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * load component with enabledEnvironment ([#1329](https://github.com/midwayjs/midway/issues/1329)) ([803cd46](https://github.com/midwayjs/midway/commit/803cd4617502973daf06072f252767309554e272))
24
+ * static prefix ([#1321](https://github.com/midwayjs/midway/issues/1321)) ([e6b4e46](https://github.com/midwayjs/midway/commit/e6b4e4673c1d2480da23d6bd664b613c813ee131))
25
+
26
+
27
+ ### Features
28
+
29
+ * add mongoose component and support multi-instance for typegoose ([#1334](https://github.com/midwayjs/midway/issues/1334)) ([ec54224](https://github.com/midwayjs/midway/commit/ec54224d775a3cfde3ff280538c8db79bcff4610))
30
+
31
+
32
+
33
+
34
+
35
+ ## [2.13.3](https://github.com/midwayjs/midway/compare/v2.13.2...v2.13.3) (2021-09-28)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * circular inject for provide uuid ([#1285](https://github.com/midwayjs/midway/issues/1285)) ([29a7ab7](https://github.com/midwayjs/midway/commit/29a7ab742359f7803f5dc562329e887b191a2d63))
41
+ * functional configuration load async code ([#1300](https://github.com/midwayjs/midway/issues/1300)) ([8cb4bd6](https://github.com/midwayjs/midway/commit/8cb4bd679e7e731f8649466cfb7f6a4b35ba2683))
42
+
43
+
44
+
45
+
46
+
47
+ ## [2.13.2](https://github.com/midwayjs/midway/compare/v2.13.1...v2.13.2) (2021-09-09)
48
+
49
+ **Note:** Version bump only for package @midwayjs/core
50
+
51
+
52
+
53
+
54
+
6
55
  ## [2.13.1](https://github.com/midwayjs/midway/compare/v2.13.0...v2.13.1) (2021-09-08)
7
56
 
8
57
 
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
@@ -21,7 +21,7 @@ class ContainerConfiguration {
21
21
  this.loadDirs.push(dir);
22
22
  }
23
23
  addImports(imports = [], baseDir) {
24
- var _a, _b;
24
+ var _a, _b, _c;
25
25
  // 处理 imports
26
26
  for (const importPackage of imports) {
27
27
  if (!importPackage)
@@ -44,7 +44,12 @@ class ContainerConfiguration {
44
44
  }
45
45
  else if ('component' in importPackage) {
46
46
  subContainerConfiguration.newVersion = true;
47
- if ((_b = (_a = importPackage) === null || _a === void 0 ? void 0 : _a.enabledEnvironment) === null || _b === void 0 ? void 0 : _b.includes(this.container.getCurrentEnv())) {
47
+ if ((_a = importPackage) === null || _a === void 0 ? void 0 : _a.enabledEnvironment) {
48
+ if ((_c = (_b = importPackage) === null || _b === void 0 ? void 0 : _b.enabledEnvironment) === null || _c === void 0 ? void 0 : _c.includes(this.container.getCurrentEnv())) {
49
+ subContainerConfiguration.loadComponentObject(importPackage.component);
50
+ }
51
+ }
52
+ else {
48
53
  subContainerConfiguration.loadComponentObject(importPackage.component);
49
54
  }
50
55
  }
@@ -574,6 +574,21 @@ class ManagedResolverFactory {
574
574
  if (ref && ref.name) {
575
575
  iden = ref.name;
576
576
  }
577
+ let subDefinition = this.context.registry.getDefinition(iden);
578
+ if (!subDefinition && this.context.parent) {
579
+ subDefinition = this.context.parent.registry.getDefinition(iden);
580
+ }
581
+ // find uuid
582
+ if (!subDefinition && /:/.test(iden)) {
583
+ iden = iden.replace(/^.*?:/, '');
584
+ subDefinition = this.context.registry.getDefinition(iden);
585
+ if (!subDefinition && this.context.parent) {
586
+ subDefinition = this.context.parent.registry.getDefinition(iden);
587
+ }
588
+ }
589
+ if (subDefinition) {
590
+ iden = subDefinition.id;
591
+ }
577
592
  if (iden === identifier) {
578
593
  debug('dfs exist in properties key %s == %s.', identifier, definition.id);
579
594
  return true;
@@ -586,10 +601,6 @@ class ManagedResolverFactory {
586
601
  depth.push(iden);
587
602
  debug('dfs depth push %s == %s, %j.', identifier, iden, depth);
588
603
  }
589
- let subDefinition = this.context.registry.getDefinition(iden);
590
- if (!subDefinition && this.context.parent) {
591
- subDefinition = this.context.parent.registry.getDefinition(iden);
592
- }
593
604
  if (this.depthFirstSearch(identifier, subDefinition, depth)) {
594
605
  debug('dfs exist in sub tree %s == %s subId = %s.', identifier, definition.id, subDefinition.id);
595
606
  return true;
@@ -6,9 +6,9 @@ export declare class FunctionalConfiguration {
6
6
  private configLoadHandler;
7
7
  private options;
8
8
  constructor(options: InjectionConfigurationOptions);
9
- onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): this;
10
- onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): this;
11
- onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): this;
9
+ onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): any;
10
+ onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
11
+ onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
12
12
  getConfigurationOptions(): InjectionConfigurationOptions;
13
13
  }
14
14
  export declare const createConfiguration: (options: InjectionConfigurationOptions) => FunctionalConfiguration;
@@ -13,7 +13,7 @@ class FunctionalConfiguration {
13
13
  this.configLoadHandler = configLoadHandler;
14
14
  }
15
15
  else {
16
- this.configLoadHandler(configLoadHandler, app);
16
+ return this.configLoadHandler(configLoadHandler, app);
17
17
  }
18
18
  return this;
19
19
  }
@@ -22,7 +22,7 @@ class FunctionalConfiguration {
22
22
  this.readyHandler = readyHandler;
23
23
  }
24
24
  else {
25
- this.readyHandler(readyHandler, app);
25
+ return this.readyHandler(readyHandler, app);
26
26
  }
27
27
  return this;
28
28
  }
@@ -31,7 +31,7 @@ class FunctionalConfiguration {
31
31
  this.stopHandler = stopHandler;
32
32
  }
33
33
  else {
34
- this.stopHandler(stopHandler, app);
34
+ return this.stopHandler(stopHandler, app);
35
35
  }
36
36
  return this;
37
37
  }
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { MidwayRequestContainer } from './context/requestContainer';
6
6
  export { BaseFramework } from './baseFramework';
7
7
  export * from './context/providerWrapper';
8
8
  export * from './common/constants';
9
- export { safelyGet, safeRequire, delegateTargetPrototypeMethod } from './util/';
9
+ export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, } from './util/';
10
10
  export * from './util/pathFileUtil';
11
11
  export * from './features';
12
12
  export * from './util/webRouterParam';
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.MidwayContextLogger = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.classToPlain = exports.plainToClass = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = exports.clearContainerCache = exports.MidwayContainer = exports.ContainerLoader = exports.generateProvideId = exports.classNamed = exports.getObjectDefinition = exports.getProviderId = exports.getParamNames = exports.clearAllModule = exports.resetModule = exports.listModule = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getMethodMetadata = exports.attachMethodMetadata = exports.saveMethodMetadata = exports.listMethodDataFromClass = exports.getMethodDataFromClass = exports.attachMethodDataToClass = exports.saveMethodDataToClass = exports.getClassMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.MidwayFrameworkType = exports.ScopeEnum = void 0;
13
+ exports.MidwayContextLogger = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.classToPlain = exports.plainToClass = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = exports.clearContainerCache = exports.MidwayContainer = exports.ContainerLoader = exports.generateProvideId = exports.classNamed = exports.getObjectDefinition = exports.getProviderId = exports.getParamNames = exports.clearAllModule = exports.resetModule = exports.listModule = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getMethodMetadata = exports.attachMethodMetadata = exports.saveMethodMetadata = exports.listMethodDataFromClass = exports.getMethodDataFromClass = exports.attachMethodDataToClass = exports.saveMethodDataToClass = exports.getClassMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.MidwayFrameworkType = exports.ScopeEnum = void 0;
14
14
  var decorator_1 = require("@midwayjs/decorator");
15
15
  Object.defineProperty(exports, "ScopeEnum", { enumerable: true, get: function () { return decorator_1.ScopeEnum; } });
16
16
  Object.defineProperty(exports, "MidwayFrameworkType", { enumerable: true, get: function () { return decorator_1.MidwayFrameworkType; } });
@@ -58,6 +58,8 @@ var util_1 = require("./util/");
58
58
  Object.defineProperty(exports, "safelyGet", { enumerable: true, get: function () { return util_1.safelyGet; } });
59
59
  Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function () { return util_1.safeRequire; } });
60
60
  Object.defineProperty(exports, "delegateTargetPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetPrototypeMethod; } });
61
+ Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get: function () { return util_1.delegateTargetMethod; } });
62
+ Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
61
63
  __exportStar(require("./util/pathFileUtil"), exports);
62
64
  __exportStar(require("./features"), exports);
63
65
  __exportStar(require("./util/webRouterParam"), exports);
@@ -17,5 +17,22 @@ export declare function safelyGet(list: string | string[], obj?: Record<string,
17
17
  export declare function parsePrefix(provideId: string): string;
18
18
  export declare function getUserHome(): string;
19
19
  export declare function joinURLPath(...strArray: any[]): string;
20
+ /**
21
+ * 代理目标所有的原型方法,不包括构造器和内部隐藏方法
22
+ * @param derivedCtor
23
+ * @param constructors
24
+ */
20
25
  export declare function delegateTargetPrototypeMethod(derivedCtor: any, constructors: any[]): void;
26
+ /**
27
+ * 代理目标原型上的特定方法
28
+ * @param derivedCtor
29
+ * @param methods
30
+ */
31
+ export declare function delegateTargetMethod(derivedCtor: any, methods: string[]): void;
32
+ /**
33
+ * 代理目标原型属性
34
+ * @param derivedCtor
35
+ * @param properties
36
+ */
37
+ export declare function delegateTargetProperties(derivedCtor: any, properties: string[]): void;
21
38
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
3
+ exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
4
4
  const path_1 = require("path");
5
5
  const fs_1 = require("fs");
6
6
  const util_1 = require("util");
@@ -29,8 +29,7 @@ const safeRequire = (p, enabledCache = true) => {
29
29
  }
30
30
  }
31
31
  catch (err) {
32
- debug('SafeRequire Warning');
33
- debug(err);
32
+ debug('SafeRequire Warning', err.message);
34
33
  return undefined;
35
34
  }
36
35
  };
@@ -91,11 +90,16 @@ function joinURLPath(...strArray) {
91
90
  return p;
92
91
  }
93
92
  exports.joinURLPath = joinURLPath;
93
+ /**
94
+ * 代理目标所有的原型方法,不包括构造器和内部隐藏方法
95
+ * @param derivedCtor
96
+ * @param constructors
97
+ */
94
98
  function delegateTargetPrototypeMethod(derivedCtor, constructors) {
95
99
  constructors.forEach(baseCtor => {
96
100
  Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
97
101
  if (name !== 'constructor' && !/^_/.test(name)) {
98
- derivedCtor.prototype[name] = async function (...args) {
102
+ derivedCtor.prototype[name] = function (...args) {
99
103
  return this.instance[name](...args);
100
104
  };
101
105
  }
@@ -103,4 +107,32 @@ function delegateTargetPrototypeMethod(derivedCtor, constructors) {
103
107
  });
104
108
  }
105
109
  exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
110
+ /**
111
+ * 代理目标原型上的特定方法
112
+ * @param derivedCtor
113
+ * @param methods
114
+ */
115
+ function delegateTargetMethod(derivedCtor, methods) {
116
+ methods.forEach(name => {
117
+ derivedCtor.prototype[name] = function (...args) {
118
+ return this.instance[name](...args);
119
+ };
120
+ });
121
+ }
122
+ exports.delegateTargetMethod = delegateTargetMethod;
123
+ /**
124
+ * 代理目标原型属性
125
+ * @param derivedCtor
126
+ * @param properties
127
+ */
128
+ function delegateTargetProperties(derivedCtor, properties) {
129
+ properties.forEach(name => {
130
+ Object.defineProperty(derivedCtor.prototype, name, {
131
+ get() {
132
+ return this.instance[name];
133
+ },
134
+ });
135
+ });
136
+ }
137
+ exports.delegateTargetProperties = delegateTargetProperties;
106
138
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * 多客户端工厂实现
3
3
  */
4
- export declare abstract class ServiceFactory<T> {
5
- private clients;
6
- private options;
4
+ export declare abstract class ServiceFactory<T, U = T> {
5
+ protected clients: Map<string, T>;
6
+ protected options: {};
7
7
  protected initClients(options: any): Promise<void>;
8
8
  get<U = T>(id?: string): U;
9
- createInstance(config: any, clientName?: any): Promise<any>;
10
- abstract getName(): any;
11
- protected abstract createClient(config: any): any;
9
+ createInstance(config: any, clientName?: any): Promise<T>;
10
+ abstract getName(): string;
11
+ protected abstract createClient(config: any, clientName: any): Promise<T>;
12
12
  protected destroyClient(client: T): Promise<void>;
13
13
  stop(): Promise<void>;
14
14
  }
@@ -31,7 +31,7 @@ class ServiceFactory {
31
31
  async createInstance(config, clientName) {
32
32
  // options.default will be merge in to options.clients[id]
33
33
  config = Object.assign({}, this.options['default'], config);
34
- const client = await this.createClient(config);
34
+ const client = await this.createClient(config, clientName);
35
35
  if (clientName) {
36
36
  this.clients.set(clientName, client);
37
37
  }
@@ -261,12 +261,14 @@ class WebRouterCollector {
261
261
  .map(item => {
262
262
  const urlString = item.url.toString();
263
263
  const weightArr = (0, decorator_1.isRegExp)(item.url)
264
- ? urlString.split('/')
264
+ ? urlString.split('\\/')
265
265
  : urlString.split('/');
266
266
  let weight = 0;
267
267
  // 权重,比如通配的不加权,非通配加权,防止通配出现在最前面
268
268
  for (const fragment of weightArr) {
269
- if (fragment.includes(':') || fragment.includes('*')) {
269
+ if (fragment === '' ||
270
+ fragment.includes(':') ||
271
+ fragment.includes('*')) {
270
272
  weight += 0;
271
273
  }
272
274
  else {
@@ -297,12 +299,12 @@ class WebRouterCollector {
297
299
  if (handlerA._category !== handlerB._category) {
298
300
  return handlerB._category - handlerA._category;
299
301
  }
302
+ // 不同权重
303
+ if (handlerA._weight !== handlerB._weight) {
304
+ return handlerB._weight - handlerA._weight;
305
+ }
300
306
  // 不同长度
301
307
  if (handlerA._level === handlerB._level) {
302
- // 不同权重
303
- if (handlerA._weight !== handlerB._weight) {
304
- return handlerB._weight - handlerA._weight;
305
- }
306
308
  if (handlerB._pureRouter === handlerA._pureRouter) {
307
309
  return (handlerA.url.toString().length - handlerB.url.toString().length);
308
310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "2.13.1",
3
+ "version": "2.14.0",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,8 +21,9 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^2.13.0",
24
+ "@midwayjs/decorator": "^2.14.0",
25
25
  "chai": "^4.2.0",
26
+ "midway-test-component": "*",
26
27
  "mm": "3",
27
28
  "sinon": "^7.2.2"
28
29
  },
@@ -39,7 +40,6 @@
39
40
  "lodash.get": "^4.4.2",
40
41
  "lodash.set": "^4.3.2",
41
42
  "lodash.template": "^4.4.0",
42
- "midway-test-component": "*",
43
43
  "picomatch": "^2.2.2",
44
44
  "reflect-metadata": "^0.1.13"
45
45
  },
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">= 10.0.0"
53
53
  },
54
- "gitHead": "d50576713e723aef47f1f7464eeecae82e605874"
54
+ "gitHead": "5fd716b0e731162d8e9f0931790fde7402fb83de"
55
55
  }