@things-factory/integration-base 4.1.10 → 4.1.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.
- package/dist-server/engine/connector/index.js +1 -0
- package/dist-server/engine/connector/index.js.map +1 -1
- package/dist-server/engine/connector/mysql-connector.js +82 -0
- package/dist-server/engine/connector/mysql-connector.js.map +1 -0
- package/package.json +6 -6
- package/server/engine/connector/index.ts +1 -0
- package/server/engine/connector/mysql-connector.ts +92 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,8BAA2B;AAC3B,iCAA8B;AAC9B,4BAAyB;AACzB,+BAA4B;AAC5B,8BAA2B;AAC3B,kCAA+B;AAC/B,4BAAyB;AACzB,6BAA0B;AAC1B,8BAA2B;AAC3B,2BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,8BAA2B;AAC3B,iCAA8B;AAC9B,4BAAyB;AACzB,+BAA4B;AAC5B,8BAA2B;AAC3B,kCAA+B;AAC/B,4BAAyB;AACzB,6BAA0B;AAC1B,8BAA2B;AAC3B,6BAA0B;AAC1B,2BAAwB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mysqlConnector = void 0;
|
|
7
|
+
const connection_manager_1 = require("../connection-manager");
|
|
8
|
+
const promise_1 = __importDefault(require("mysql2/promise"));
|
|
9
|
+
class mysqlConnector {
|
|
10
|
+
async ready(connectionConfigs) {
|
|
11
|
+
await Promise.all(connectionConfigs.map(this.connect));
|
|
12
|
+
connection_manager_1.ConnectionManager.logger.info("mysql-connector connections are ready");
|
|
13
|
+
}
|
|
14
|
+
async connect(connection) {
|
|
15
|
+
const { endpoint, params: { user, password, database }, } = connection;
|
|
16
|
+
const [host, port = 3306] = endpoint.split(":");
|
|
17
|
+
if (!promise_1.default) {
|
|
18
|
+
throw new Error("mysql module loading failed");
|
|
19
|
+
}
|
|
20
|
+
let pool = await promise_1.default.createPool({
|
|
21
|
+
user,
|
|
22
|
+
password,
|
|
23
|
+
host,
|
|
24
|
+
port,
|
|
25
|
+
database,
|
|
26
|
+
});
|
|
27
|
+
const client = await pool.getConnection();
|
|
28
|
+
connection_manager_1.ConnectionManager.addConnectionInstance(connection, {
|
|
29
|
+
query: async (query, params) => {
|
|
30
|
+
var result;
|
|
31
|
+
try {
|
|
32
|
+
const results = await client.query(query);
|
|
33
|
+
if (results && results.length > 0) {
|
|
34
|
+
result = results[0];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
connection_manager_1.ConnectionManager.logger.error(e);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
close: client.end(),
|
|
43
|
+
});
|
|
44
|
+
connection_manager_1.ConnectionManager.logger.info(`mysql Database(${connection.name}:${database}) at ${endpoint} connected.`);
|
|
45
|
+
}
|
|
46
|
+
async disconnect(connection) {
|
|
47
|
+
var client = connection_manager_1.ConnectionManager.getConnectionInstance(connection);
|
|
48
|
+
try {
|
|
49
|
+
await client.close();
|
|
50
|
+
connection_manager_1.ConnectionManager.logger.info(`mysql Database(${connection.name}) closed.`);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
connection_manager_1.ConnectionManager.logger.error(e);
|
|
54
|
+
}
|
|
55
|
+
connection_manager_1.ConnectionManager.removeConnectionInstance(connection);
|
|
56
|
+
}
|
|
57
|
+
get parameterSpec() {
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
type: "string",
|
|
61
|
+
name: "user",
|
|
62
|
+
label: "user",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "password",
|
|
66
|
+
name: "password",
|
|
67
|
+
label: "password",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: "string",
|
|
71
|
+
name: "database",
|
|
72
|
+
label: "database",
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
get taskPrefixes() {
|
|
77
|
+
return ["database"];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.mysqlConnector = mysqlConnector;
|
|
81
|
+
connection_manager_1.ConnectionManager.registerConnector("mysql-connector", new mysqlConnector());
|
|
82
|
+
//# sourceMappingURL=mysql-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/mysql-connector.ts"],"names":[],"mappings":";;;;;;AACA,8DAAyD;AACzD,6DAAmC;AAEnC,MAAa,cAAc;IACzB,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACvD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAU;QACtB,MAAM,EACJ,QAAQ,EACR,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GACrC,GAAG,UAAU,CAAC;QAEf,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEhD,IAAI,CAAC,iBAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,IAAI,IAAI,GAAG,MAAM,iBAAK,CAAC,UAAU,CAAC;YAChC,IAAI;YACJ,QAA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AAI,EAAE,QAAQ;gBACd,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;aACd;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;SACF,CAAC;IACJ,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF;AArFD,wCAqFC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.12",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@apollo/client": "^3.5.6",
|
|
29
|
-
"@things-factory/api": "^4.1.
|
|
30
|
-
"@things-factory/auth-base": "^4.1.
|
|
31
|
-
"@things-factory/oauth2-client": "^4.1.
|
|
32
|
-
"@things-factory/shell": "^4.1.
|
|
29
|
+
"@things-factory/api": "^4.1.12",
|
|
30
|
+
"@things-factory/auth-base": "^4.1.12",
|
|
31
|
+
"@things-factory/oauth2-client": "^4.1.12",
|
|
32
|
+
"@things-factory/shell": "^4.1.12",
|
|
33
33
|
"async-mqtt": "^2.5.0",
|
|
34
34
|
"cron": "^1.7.2",
|
|
35
35
|
"cross-fetch": "^3.0.4",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"promise-socket": "^7.0.0",
|
|
41
41
|
"vm2": "^3.9.2"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9055b83aa979f9c2d706b02cf8d73d848522d7dd"
|
|
44
44
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Connector } from '../types'
|
|
2
|
+
import { ConnectionManager } from '../connection-manager'
|
|
3
|
+
import Mysql from "mysql2/promise";
|
|
4
|
+
|
|
5
|
+
export class mysqlConnector implements Connector {
|
|
6
|
+
async ready(connectionConfigs) {
|
|
7
|
+
await Promise.all(connectionConfigs.map(this.connect));
|
|
8
|
+
ConnectionManager.logger.info("mysql-connector connections are ready");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async connect(connection) {
|
|
12
|
+
const {
|
|
13
|
+
endpoint,
|
|
14
|
+
params: { user, password, database },
|
|
15
|
+
} = connection;
|
|
16
|
+
|
|
17
|
+
const [host, port = 3306] = endpoint.split(":");
|
|
18
|
+
|
|
19
|
+
if (!Mysql) {
|
|
20
|
+
throw new Error("mysql module loading failed");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let pool = await Mysql.createPool({
|
|
24
|
+
user,
|
|
25
|
+
password,
|
|
26
|
+
host,
|
|
27
|
+
port,
|
|
28
|
+
database,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const client = await pool.getConnection();
|
|
32
|
+
ConnectionManager.addConnectionInstance(connection, {
|
|
33
|
+
query: async (query, params) => {
|
|
34
|
+
var result;
|
|
35
|
+
try {
|
|
36
|
+
const results = await client.query(query);
|
|
37
|
+
if (results && results.length > 0) {
|
|
38
|
+
result = results[0];
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
ConnectionManager.logger.error(e);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
45
|
+
close: client.end(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
ConnectionManager.logger.info(
|
|
49
|
+
`mysql Database(${connection.name}:${database}) at ${endpoint} connected.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async disconnect(connection) {
|
|
54
|
+
var client = ConnectionManager.getConnectionInstance(connection);
|
|
55
|
+
try {
|
|
56
|
+
await client.close();
|
|
57
|
+
ConnectionManager.logger.info(
|
|
58
|
+
`mysql Database(${connection.name}) closed.`
|
|
59
|
+
);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
ConnectionManager.logger.error(e);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ConnectionManager.removeConnectionInstance(connection);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get parameterSpec() {
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
type: "string",
|
|
71
|
+
name: "user",
|
|
72
|
+
label: "user",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "password",
|
|
76
|
+
name: "password",
|
|
77
|
+
label: "password",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "string",
|
|
81
|
+
name: "database",
|
|
82
|
+
label: "database",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get taskPrefixes() {
|
|
88
|
+
return ["database"];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
ConnectionManager.registerConnector("mysql-connector", new mysqlConnector());
|