@things-factory/integration-base 7.0.1-rc.8 → 7.0.1
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/connection-manager.js +10 -3
- package/dist-server/engine/connection-manager.js.map +1 -1
- package/dist-server/engine/connector/postgresql-connector.d.ts +8 -2
- package/dist-server/engine/connector/postgresql-connector.js +60 -13
- package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
- package/dist-server/service/scenario/scenario.d.ts +11 -2
- package/dist-server/service/scenario/scenario.js +8 -4
- package/dist-server/service/scenario/scenario.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/server/engine/connection-manager.ts +10 -2
- package/server/engine/connector/postgresql-connector.ts +61 -13
- package/server/service/scenario/scenario.ts +19 -4
- package/translations/en.json +4 -1
- package/translations/ja.json +4 -1
- package/translations/ko.json +4 -1
- package/translations/ms.json +4 -1
- package/translations/zh.json +4 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/integration-base",
|
3
|
-
"version": "7.0.1
|
3
|
+
"version": "7.0.1",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -26,15 +26,15 @@
|
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
28
|
"@apollo/client": "^3.6.9",
|
29
|
-
"@operato/moment-timezone-es": "^7.0.0
|
30
|
-
"@things-factory/api": "^7.0.
|
31
|
-
"@things-factory/auth-base": "^7.0.
|
32
|
-
"@things-factory/cache-service": "^7.0.
|
33
|
-
"@things-factory/env": "^7.0.
|
34
|
-
"@things-factory/oauth2-client": "^7.0.
|
35
|
-
"@things-factory/scheduler-client": "^7.0.
|
36
|
-
"@things-factory/shell": "^7.0.
|
37
|
-
"@things-factory/utils": "^7.0.
|
29
|
+
"@operato/moment-timezone-es": "^7.0.0",
|
30
|
+
"@things-factory/api": "^7.0.0",
|
31
|
+
"@things-factory/auth-base": "^7.0.0",
|
32
|
+
"@things-factory/cache-service": "^7.0.0",
|
33
|
+
"@things-factory/env": "^7.0.0",
|
34
|
+
"@things-factory/oauth2-client": "^7.0.0",
|
35
|
+
"@things-factory/scheduler-client": "^7.0.0",
|
36
|
+
"@things-factory/shell": "^7.0.0",
|
37
|
+
"@things-factory/utils": "^7.0.0",
|
38
38
|
"async-mqtt": "^2.5.0",
|
39
39
|
"chance": "^1.1.11",
|
40
40
|
"cross-fetch": "^3.0.4",
|
@@ -44,5 +44,5 @@
|
|
44
44
|
"readline": "^1.3.0",
|
45
45
|
"ses": "^1.5.0"
|
46
46
|
},
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "02f50498ba92589813db2d13907894d2b9220d8c"
|
48
48
|
}
|
@@ -138,14 +138,22 @@ export class ConnectionManager {
|
|
138
138
|
}
|
139
139
|
|
140
140
|
static getConnectionInstanceEntityByName(domain: Domain, name: string): any {
|
141
|
-
const
|
142
|
-
|
141
|
+
const connection = ConnectionManager.entities[domain.id]?.[name]
|
142
|
+
if(connection) {
|
143
|
+
return connection
|
144
|
+
}
|
145
|
+
|
146
|
+
if(domain.parentId) {
|
147
|
+
return ConnectionManager.entities[domain.id]?.[name]
|
148
|
+
}
|
143
149
|
}
|
144
150
|
|
145
151
|
static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {
|
146
152
|
const connections = ConnectionManager.connections[domain.id]
|
153
|
+
const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId]
|
147
154
|
|
148
155
|
return {
|
156
|
+
...parentConnections,
|
149
157
|
...connections
|
150
158
|
}
|
151
159
|
}
|
@@ -5,7 +5,7 @@ import { Connector } from '../types'
|
|
5
5
|
import { InputConnection } from '../../service/connection/connection-type'
|
6
6
|
|
7
7
|
try {
|
8
|
-
var { Client } = require('pg')
|
8
|
+
var { Client, Pool } = require('pg')
|
9
9
|
} catch (err) {
|
10
10
|
logger.error('postgresql module loading failed', err)
|
11
11
|
}
|
@@ -20,35 +20,66 @@ export class PostgresqlConnector implements Connector {
|
|
20
20
|
async connect(connection: InputConnection) {
|
21
21
|
const {
|
22
22
|
endpoint,
|
23
|
-
params: { user, password, database }
|
23
|
+
params: { user, password, database, maxPoolConnection, idleTimeoutMillis, connectionTimeoutMillis }
|
24
24
|
} = connection
|
25
25
|
const [host, port = 5432] = endpoint.split(':')
|
26
26
|
|
27
|
-
if (!
|
27
|
+
if (!Pool) {
|
28
28
|
throw new Error('postgresql module loading failed')
|
29
29
|
}
|
30
30
|
|
31
|
-
|
31
|
+
// create a new pool
|
32
|
+
const pool = new Pool({
|
32
33
|
user,
|
33
34
|
host,
|
34
35
|
database,
|
35
36
|
password,
|
36
|
-
port: Number(port)
|
37
|
+
port: Number(port),
|
38
|
+
max: maxPoolConnection || 10,
|
39
|
+
idleTimeoutMillis: idleTimeoutMillis || 30000,
|
40
|
+
connectionTimeoutMillis: connectionTimeoutMillis || 2000
|
37
41
|
})
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
this.connect(connection)
|
43
|
+
pool.on('error', (err, client) => {
|
44
|
+
logger.error('unexpected error on postgres pool.', err)
|
42
45
|
})
|
43
46
|
|
44
47
|
try {
|
45
|
-
|
48
|
+
// try to connect to database to check the connection at initial time
|
49
|
+
const entryConnection = await pool.connect().catch(async e => {
|
50
|
+
ConnectionManager.logger.error(e)
|
51
|
+
throw e
|
52
|
+
})
|
53
|
+
entryConnection.release()
|
54
|
+
|
46
55
|
ConnectionManager.addConnectionInstance(connection, {
|
47
56
|
query: async (query, params) => {
|
48
|
-
|
57
|
+
try {
|
58
|
+
// get a connection from the pool
|
59
|
+
var client = await pool.connect().catch(async e => {
|
60
|
+
ConnectionManager.logger.error(e)
|
61
|
+
throw e
|
62
|
+
})
|
63
|
+
|
64
|
+
client?.on('error', async err => {
|
65
|
+
logger.error('unexpected error on postgres client.', err)
|
66
|
+
ConnectionManager.logger.error(err)
|
67
|
+
})
|
68
|
+
|
69
|
+
// try to query
|
70
|
+
var result = (await client.query(query, params)).rows
|
71
|
+
} catch (e) {
|
72
|
+
ConnectionManager.logger.error(e)
|
73
|
+
throw e
|
74
|
+
} finally {
|
75
|
+
// release the connection back to the pool
|
76
|
+
client?.release()
|
77
|
+
}
|
78
|
+
return result
|
49
79
|
},
|
50
80
|
close: async () => {
|
51
|
-
|
81
|
+
// close the pool
|
82
|
+
await pool?.end()
|
52
83
|
}
|
53
84
|
})
|
54
85
|
|
@@ -62,9 +93,9 @@ export class PostgresqlConnector implements Connector {
|
|
62
93
|
}
|
63
94
|
|
64
95
|
async disconnect(connection: InputConnection) {
|
65
|
-
var
|
96
|
+
var connectionInstance = ConnectionManager.getConnectionInstance(connection)
|
66
97
|
try {
|
67
|
-
await
|
98
|
+
await connectionInstance.close()
|
68
99
|
ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}) closed.`)
|
69
100
|
} catch (e) {
|
70
101
|
ConnectionManager.logger.error(e)
|
@@ -88,6 +119,23 @@ export class PostgresqlConnector implements Connector {
|
|
88
119
|
type: 'string',
|
89
120
|
name: 'database',
|
90
121
|
label: 'database'
|
122
|
+
},
|
123
|
+
{
|
124
|
+
type: 'number',
|
125
|
+
name: 'maxPoolConnection',
|
126
|
+
label: 'maxPoolConnection'
|
127
|
+
},
|
128
|
+
{
|
129
|
+
type: 'number',
|
130
|
+
name: 'idleTimeoutMillis',
|
131
|
+
label: 'idleTimeoutMillis',
|
132
|
+
placeHolder: 'milli-seconds'
|
133
|
+
},
|
134
|
+
{
|
135
|
+
type: 'number',
|
136
|
+
name: 'connectionTimeoutMillis',
|
137
|
+
label: 'connectionTimeoutMillis',
|
138
|
+
placeHolder: 'milli-seconds'
|
91
139
|
}
|
92
140
|
]
|
93
141
|
}
|
@@ -98,15 +98,30 @@ export class Scenario {
|
|
98
98
|
@RelationId((scenario: Scenario) => scenario.updater)
|
99
99
|
updaterId?: string
|
100
100
|
|
101
|
-
async start(
|
101
|
+
async start(options?: {
|
102
|
+
instanceName?: string;
|
103
|
+
domain?: Domain;
|
104
|
+
user?: User;
|
105
|
+
variables?: any;
|
106
|
+
}) {
|
102
107
|
try {
|
103
|
-
await ScenarioEngine.load(instanceName || this.name,
|
108
|
+
await ScenarioEngine.load(options?.instanceName || this.name,
|
109
|
+
this,
|
110
|
+
{
|
111
|
+
domain: options?.domain || this.domain,
|
112
|
+
user: options?.user || this.updater,
|
113
|
+
variables: options?.variables
|
114
|
+
})
|
104
115
|
} catch (ex) {}
|
105
116
|
}
|
106
117
|
|
107
|
-
async stop(
|
118
|
+
async stop(options?: {
|
119
|
+
instanceName?: string;
|
120
|
+
domain?: Domain,
|
121
|
+
user?: User
|
122
|
+
}) {
|
108
123
|
try {
|
109
|
-
await ScenarioEngine.unload(this.domain, instanceName || this.name)
|
124
|
+
await ScenarioEngine.unload(options?.domain || this.domain, options?.instanceName || this.name)
|
110
125
|
} finally {
|
111
126
|
}
|
112
127
|
}
|
package/translations/en.json
CHANGED
@@ -7,5 +7,8 @@
|
|
7
7
|
"error.scenario instance not found": "scenario instance '{instance}' not found.",
|
8
8
|
"label.auth-key": "authentication key",
|
9
9
|
"label.subscription-handlers": "subscription handlers",
|
10
|
-
"label.trust-server-certificate": "trust server certificate"
|
10
|
+
"label.trust-server-certificate": "trust server certificate",
|
11
|
+
"label.maxPoolConnection": "Max Pool Connection",
|
12
|
+
"label.idleTimeoutMillis": "Idle Timeout (milliseconds)",
|
13
|
+
"label.connectionTimeoutMillis": "Connection Timeout (milliseconds)"
|
11
14
|
}
|
package/translations/ja.json
CHANGED
@@ -7,5 +7,8 @@
|
|
7
7
|
"error.scenario instance not found": "シナリオ インスタンス'{instance}'が見つかりません. 既に終了している可能性があります.",
|
8
8
|
"label.auth-key": "認証キー",
|
9
9
|
"label.subscription-handlers": "サブスクリプションハンドラー",
|
10
|
-
"label.trust-server-certificate": "サーバー証明書を信頼する"
|
10
|
+
"label.trust-server-certificate": "サーバー証明書を信頼する",
|
11
|
+
"label.maxPoolConnection": "最大プール接続数",
|
12
|
+
"label.idleTimeoutMillis": "アイドルタイムアウト(ミリ秒)",
|
13
|
+
"label.connectionTimeoutMillis": "接続タイムアウト(ミリ秒)"
|
11
14
|
}
|
package/translations/ko.json
CHANGED
@@ -7,5 +7,8 @@
|
|
7
7
|
"error.scenario instance not found": "시나리오 인스턴스 '{instance}'를 찾을 수 없습니다. 이미 종료되었을 수 있습니다.",
|
8
8
|
"label.auth-key": "인증 키",
|
9
9
|
"label.subscription-handlers": "구독 핸들러",
|
10
|
-
"label.trust-server-certificate": "서버 인증서 신뢰"
|
10
|
+
"label.trust-server-certificate": "서버 인증서 신뢰",
|
11
|
+
"label.maxPoolConnection": "최대 풀 연결 수",
|
12
|
+
"label.idleTimeoutMillis": "유휴 시간 제한 (밀리초)",
|
13
|
+
"label.connectionTimeoutMillis": "연결 시간 제한 (밀리초)"
|
11
14
|
}
|
package/translations/ms.json
CHANGED
@@ -7,5 +7,8 @@
|
|
7
7
|
"error.scenario instance not found": "Tidak dapat mencari instans senario '{instance}'. Mungkin telah berakhir.",
|
8
8
|
"label.auth-key": "Kunci pengesahan",
|
9
9
|
"label.subscription-handlers": "pengendali langganan",
|
10
|
-
"label.trust-server-certificate": "percaya sijil pelayan"
|
10
|
+
"label.trust-server-certificate": "percaya sijil pelayan",
|
11
|
+
"label.maxPoolConnection": "Sambungan Pool Maksimum",
|
12
|
+
"label.idleTimeoutMillis": "Had Masa Tanpa Aktiviti (milisaat)",
|
13
|
+
"label.connectionTimeoutMillis": "Had Masa Sambungan (milisaat)"
|
11
14
|
}
|
package/translations/zh.json
CHANGED
@@ -7,5 +7,8 @@
|
|
7
7
|
"error.scenario instance not found": "无法找到场景实例 '{instance}'。它可能已经结束。",
|
8
8
|
"label.auth-key": "认证密钥",
|
9
9
|
"label.subscription-handlers": "订阅处理程序",
|
10
|
-
"label.trust-server-certificate": "信任服务器证书"
|
10
|
+
"label.trust-server-certificate": "信任服务器证书",
|
11
|
+
"label.maxPoolConnection": "最大连接池连接数",
|
12
|
+
"label.idleTimeoutMillis": "空闲超时时间(毫秒)",
|
13
|
+
"label.connectionTimeoutMillis": "连接超时时间(毫秒)"
|
11
14
|
}
|