@midwayjs/core 3.3.5 → 3.3.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.
@@ -0,0 +1,28 @@
1
+ export declare abstract class DataSourceManager<T> {
2
+ protected dataSource: Map<string, T>;
3
+ protected options: {};
4
+ protected initDataSource(options?: any): Promise<void>;
5
+ /**
6
+ * get a data source instance
7
+ * @param dataSourceName
8
+ */
9
+ getDataSource(dataSourceName: string): T;
10
+ /**
11
+ * check data source has exists
12
+ * @param dataSourceName
13
+ */
14
+ hasDataSource(dataSourceName: string): boolean;
15
+ getDataSourceNames(): string[];
16
+ /**
17
+ * check the data source is connected
18
+ * @param dataSourceName
19
+ */
20
+ isConnected(dataSourceName: string): Promise<boolean>;
21
+ createInstance(config: any, clientName: any): Promise<T | void>;
22
+ abstract getName(): string;
23
+ protected abstract createDataSource(config: any, dataSourceName: string): Promise<T | void> | (T | void);
24
+ protected abstract checkConnected(dataSource: T): Promise<boolean>;
25
+ protected destroyDataSource(dataSource: T): Promise<void>;
26
+ stop(): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=dataSourceManager.d.ts.map
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataSourceManager = void 0;
4
+ /**
5
+ * 数据源管理器实现
6
+ */
7
+ const extend_1 = require("../util/extend");
8
+ const error_1 = require("../error");
9
+ class DataSourceManager {
10
+ constructor() {
11
+ this.dataSource = new Map();
12
+ this.options = {};
13
+ }
14
+ async initDataSource(options = {}) {
15
+ this.options = options;
16
+ if (options.dataSource) {
17
+ for (const dataSourceName in options.dataSource) {
18
+ // create data source
19
+ await this.createInstance(options.dataSource[dataSourceName], dataSourceName);
20
+ }
21
+ }
22
+ else {
23
+ throw new error_1.MidwayParameterError('DataSourceManager must set options.dataSource.');
24
+ }
25
+ }
26
+ /**
27
+ * get a data source instance
28
+ * @param dataSourceName
29
+ */
30
+ getDataSource(dataSourceName) {
31
+ return this.dataSource.get(dataSourceName);
32
+ }
33
+ /**
34
+ * check data source has exists
35
+ * @param dataSourceName
36
+ */
37
+ hasDataSource(dataSourceName) {
38
+ return this.dataSource.has(dataSourceName);
39
+ }
40
+ getDataSourceNames() {
41
+ return Array.from(this.dataSource.keys());
42
+ }
43
+ /**
44
+ * check the data source is connected
45
+ * @param dataSourceName
46
+ */
47
+ async isConnected(dataSourceName) {
48
+ return this.checkConnected(this.getDataSource(dataSourceName));
49
+ }
50
+ async createInstance(config, clientName) {
51
+ // options.default will be merge in to options.clients[id]
52
+ config = (0, extend_1.extend)(true, {}, this.options['default'], config);
53
+ const client = await this.createDataSource(config, clientName);
54
+ if (client) {
55
+ if (clientName) {
56
+ this.dataSource.set(clientName, client);
57
+ }
58
+ return client;
59
+ }
60
+ }
61
+ async destroyDataSource(dataSource) { }
62
+ async stop() {
63
+ for (const value of this.dataSource.values()) {
64
+ await this.destroyDataSource(value);
65
+ }
66
+ }
67
+ }
68
+ exports.DataSourceManager = DataSourceManager;
69
+ //# sourceMappingURL=dataSourceManager.js.map
@@ -50,11 +50,11 @@ let MidwayFrameworkService = class MidwayFrameworkService {
50
50
  return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[interface_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
51
51
  });
52
52
  // register @App decorator handler
53
- this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
54
- if (mete.type) {
55
- const framework = this.applicationManager.getApplication(mete.type);
53
+ this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, meta) => {
54
+ if (meta.type) {
55
+ const framework = this.applicationManager.getApplication(meta.type);
56
56
  if (!framework) {
57
- throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
57
+ throw new error_1.MidwayCommonError(`Framework ${meta.type} not Found`);
58
58
  }
59
59
  return framework;
60
60
  }
@@ -62,8 +62,9 @@ let MidwayFrameworkService = class MidwayFrameworkService {
62
62
  return this.getMainApp();
63
63
  }
64
64
  });
65
- this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
66
- return this.getMainApp()[key];
65
+ this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (propertyName, meta) => {
66
+ var _a;
67
+ return this.getMainApp()[(_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName];
67
68
  });
68
69
  let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
69
70
  // filter proto
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.3.5",
3
+ "version": "3.3.6",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "5a835008aaa26e1b3c7d99c525f4a9fdaa3e41d1"
48
+ "gitHead": "a603d2348d6141f8f723901498f03a162a037708"
49
49
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013 - Now midwayjs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.