@tdengine/websocket 3.0.0 → 3.1.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/lib/example/basicSchemaless.d.ts +2 -0
- package/lib/example/basicSchemaless.d.ts.map +1 -0
- package/lib/example/basicSchemaless.js +47 -0
- package/lib/example/basicSql.d.ts +2 -0
- package/lib/example/basicSql.d.ts.map +1 -0
- package/lib/example/basicSql.js +52 -0
- package/lib/example/basicStmt.d.ts +2 -0
- package/lib/example/basicStmt.d.ts.map +1 -0
- package/lib/example/basicStmt.js +58 -0
- package/lib/example/basicTmq.d.ts +2 -0
- package/lib/example/basicTmq.d.ts.map +1 -0
- package/lib/example/basicTmq.js +71 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +41 -0
- package/lib/src/client/wsClient.d.ts +22 -0
- package/lib/src/client/wsClient.d.ts.map +1 -0
- package/lib/src/client/wsClient.js +253 -0
- package/lib/src/client/wsConnector.d.ts +17 -0
- package/lib/src/client/wsConnector.d.ts.map +1 -0
- package/lib/src/client/wsConnector.js +140 -0
- package/lib/src/client/wsConnectorPool.d.ts +13 -0
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -0
- package/lib/src/client/wsConnectorPool.js +107 -0
- package/lib/src/client/wsEventCallback.d.ts +22 -0
- package/lib/src/client/wsEventCallback.d.ts.map +1 -0
- package/lib/src/client/wsEventCallback.js +97 -0
- package/lib/src/client/wsResponse.d.ts +66 -0
- package/lib/src/client/wsResponse.d.ts.map +1 -0
- package/lib/src/client/wsResponse.js +76 -0
- package/lib/src/common/config.d.ts +22 -0
- package/lib/src/common/config.d.ts.map +1 -0
- package/lib/src/common/config.js +45 -0
- package/lib/src/common/constant.d.ts +13 -0
- package/lib/src/common/constant.d.ts.map +1 -0
- package/{src/constant.ts → lib/src/common/constant.js} +25 -24
- package/lib/src/common/log.d.ts +5 -0
- package/lib/src/common/log.d.ts.map +1 -0
- package/lib/src/common/log.js +40 -0
- package/lib/src/common/reqid.d.ts +8 -0
- package/lib/src/common/reqid.d.ts.map +1 -0
- package/lib/src/common/reqid.js +59 -0
- package/lib/src/common/taosResult.d.ts +51 -0
- package/lib/src/common/taosResult.d.ts.map +1 -0
- package/lib/src/common/taosResult.js +419 -0
- package/lib/src/common/ut8Helper.d.ts +2 -0
- package/lib/src/common/ut8Helper.d.ts.map +1 -0
- package/{src/ut8Helper.ts → lib/src/common/ut8Helper.js} +22 -21
- package/lib/src/common/utils.d.ts +5 -0
- package/lib/src/common/utils.d.ts.map +1 -0
- package/lib/src/common/utils.js +33 -0
- package/lib/src/common/wsError.d.ts +29 -0
- package/lib/src/common/wsError.d.ts.map +1 -0
- package/lib/src/common/wsError.js +51 -0
- package/{src/wsOptions.ts → lib/src/common/wsOptions.d.ts} +4 -2
- package/lib/src/common/wsOptions.d.ts.map +1 -0
- package/lib/src/common/wsOptions.js +2 -0
- package/lib/src/index.d.ts +9 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +58 -0
- package/lib/src/sql/wsProto.d.ts +26 -0
- package/lib/src/sql/wsProto.d.ts.map +1 -0
- package/lib/src/sql/wsProto.js +19 -0
- package/lib/src/sql/wsRows.d.ts +16 -0
- package/lib/src/sql/wsRows.d.ts.map +1 -0
- package/lib/src/sql/wsRows.js +76 -0
- package/lib/src/sql/wsSql.d.ts +24 -0
- package/lib/src/sql/wsSql.d.ts.map +1 -0
- package/lib/src/sql/wsSql.js +164 -0
- package/lib/src/stmt/wsParams.d.ts +41 -0
- package/lib/src/stmt/wsParams.d.ts.map +1 -0
- package/lib/src/stmt/wsParams.js +428 -0
- package/lib/src/stmt/wsProto.d.ts +27 -0
- package/lib/src/stmt/wsProto.d.ts.map +1 -0
- package/lib/src/stmt/wsProto.js +67 -0
- package/lib/src/stmt/wsStmt.d.ts +30 -0
- package/lib/src/stmt/wsStmt.d.ts.map +1 -0
- package/lib/src/stmt/wsStmt.js +207 -0
- package/lib/src/tmq/config.d.ts +14 -0
- package/lib/src/tmq/config.d.ts.map +1 -0
- package/lib/src/tmq/config.js +42 -0
- package/lib/src/tmq/constant.d.ts +85 -0
- package/lib/src/tmq/constant.d.ts.map +1 -0
- package/lib/src/tmq/constant.js +89 -0
- package/lib/src/tmq/tmqResponse.d.ts +80 -0
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -0
- package/lib/src/tmq/tmqResponse.js +204 -0
- package/lib/src/tmq/wsTmq.d.ts +32 -0
- package/lib/src/tmq/wsTmq.d.ts.map +1 -0
- package/lib/src/tmq/wsTmq.js +316 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts +2 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/queryTables.test.js +297 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts +2 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/schemaless.test.js +94 -0
- package/lib/test/bulkPulling/sql.test.d.ts +2 -0
- package/lib/test/bulkPulling/sql.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/sql.test.js +124 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.func.test.js +381 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.type.test.js +273 -0
- package/lib/test/bulkPulling/tmq.test.d.ts +2 -0
- package/lib/test/bulkPulling/tmq.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/tmq.test.js +177 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts +2 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +129 -0
- package/lib/test/utils.d.ts +18 -0
- package/lib/test/utils.d.ts.map +1 -0
- package/lib/test/utils.js +318 -0
- package/package.json +27 -14
- package/readme.md +302 -0
- package/README.md +0 -59
- package/dist/browser/index.js +0 -778
- package/dist/main/index.js +0 -711
- package/dist/main/index.js.map +0 -1
- package/dist/module/index.mjs +0 -704
- package/dist/module/index.mjs.map +0 -1
- package/dist/types.d.ts +0 -103
- package/dist/types.d.ts.map +0 -1
- package/example/basicUsageAsync.ts +0 -48
- package/example/basicUsagePrimse.ts +0 -43
- package/example/cloudUsage.ts +0 -55
- package/example/continousConnectAndVersion.ts +0 -16
- package/example/test.mjs +0 -51
- package/index.ts +0 -7
- package/jest.config.js +0 -8
- package/src/taosResult.ts +0 -269
- package/src/tdengineWebsocket.ts +0 -39
- package/src/wsClient.ts +0 -196
- package/src/wsError.ts +0 -5
- package/src/wsQuery.ts +0 -30
- package/src/wsQueryInterface.ts +0 -212
- package/src/wsQueryResponse.ts +0 -112
- package/tdengine-websocket-3.0.0.tgz +0 -0
- package/test/bulkPulling/connect.test.ts +0 -27
- package/test/bulkPulling/queryTables.test.ts +0 -274
- package/test/bulkPulling/version.test.ts +0 -19
- package/test/utils.ts +0 -235
- package/tsconfig.json +0 -101
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicSchemaless.d.ts","sourceRoot":"","sources":["../../example/basicSchemaless.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../src/common/config");
|
|
4
|
+
const wsProto_1 = require("../src/sql/wsProto");
|
|
5
|
+
const src_1 = require("../src");
|
|
6
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
7
|
+
let db = 'power';
|
|
8
|
+
let influxdbData = "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000";
|
|
9
|
+
let telnetData = "stb0_0 1626006833 4 host=host0 interface=eth0";
|
|
10
|
+
let jsonData = "{\"metric\": \"meter_current\",\"timestamp\": 1626846400,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1001\"}}";
|
|
11
|
+
const dropDB = `drop database if exists ${db}`;
|
|
12
|
+
async function Prepare() {
|
|
13
|
+
let conf = new config_1.WSConfig(dsn);
|
|
14
|
+
conf.setUser('root');
|
|
15
|
+
conf.setPwd('taosdata');
|
|
16
|
+
let wsSql = await (0, src_1.sqlConnect)(conf);
|
|
17
|
+
const topics = ['pwer_meters_topic'];
|
|
18
|
+
let dropTopic = `DROP TOPIC IF EXISTS ${topics[0]};`;
|
|
19
|
+
await wsSql.exec(dropTopic);
|
|
20
|
+
await wsSql.exec(dropDB);
|
|
21
|
+
await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
22
|
+
await wsSql.exec('CREATE STABLE if not exists power.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
23
|
+
wsSql.close();
|
|
24
|
+
}
|
|
25
|
+
(async () => {
|
|
26
|
+
let wsSchemaless = null;
|
|
27
|
+
try {
|
|
28
|
+
let conf = new config_1.WSConfig(dsn);
|
|
29
|
+
conf.setUser('root');
|
|
30
|
+
conf.setPwd('taosdata');
|
|
31
|
+
conf.setDb('power');
|
|
32
|
+
wsSchemaless = await (0, src_1.sqlConnect)(conf);
|
|
33
|
+
await wsSchemaless.schemalessInsert([influxdbData], wsProto_1.SchemalessProto.InfluxDBLineProtocol, wsProto_1.Precision.NANO_SECONDS, 0);
|
|
34
|
+
await wsSchemaless.schemalessInsert([telnetData], wsProto_1.SchemalessProto.OpenTSDBTelnetLineProtocol, wsProto_1.Precision.SECONDS, 0);
|
|
35
|
+
await wsSchemaless.schemalessInsert([jsonData], wsProto_1.SchemalessProto.OpenTSDBJsonFormatProtocol, wsProto_1.Precision.SECONDS, 0);
|
|
36
|
+
wsSchemaless.close();
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
if (wsSchemaless) {
|
|
43
|
+
await wsSchemaless.close();
|
|
44
|
+
}
|
|
45
|
+
(0, src_1.destroy)();
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicSql.d.ts","sourceRoot":"","sources":["../../example/basicSql.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../src/common/config");
|
|
4
|
+
const src_1 = require("../src");
|
|
5
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
6
|
+
(async () => {
|
|
7
|
+
let wsSql = null;
|
|
8
|
+
let wsRows = null;
|
|
9
|
+
let reqId = 0;
|
|
10
|
+
try {
|
|
11
|
+
(0, src_1.setLogLevel)("debug");
|
|
12
|
+
let conf = new config_1.WSConfig(dsn);
|
|
13
|
+
conf.setUser('root');
|
|
14
|
+
conf.setPwd('taosdata');
|
|
15
|
+
wsSql = await (0, src_1.sqlConnect)(conf);
|
|
16
|
+
let version = await wsSql.version();
|
|
17
|
+
console.log(version);
|
|
18
|
+
let taosResult = await wsSql.exec('show databases', reqId++);
|
|
19
|
+
console.log(taosResult);
|
|
20
|
+
taosResult = await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;', reqId++);
|
|
21
|
+
console.log(taosResult);
|
|
22
|
+
taosResult = await wsSql.exec('use power', reqId++);
|
|
23
|
+
console.log(taosResult);
|
|
24
|
+
taosResult = await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);', reqId++);
|
|
25
|
+
console.log(taosResult);
|
|
26
|
+
taosResult = await wsSql.exec('describe meters', reqId++);
|
|
27
|
+
console.log(taosResult);
|
|
28
|
+
taosResult = await wsSql.exec('INSERT INTO d1001 USING meters TAGS ("California.SanFrancisco", 3) VALUES (NOW, 10.2, 219, 0.32)', reqId++);
|
|
29
|
+
console.log(taosResult);
|
|
30
|
+
wsRows = await wsSql.query('select * from meters', reqId++);
|
|
31
|
+
let meta = wsRows.getMeta();
|
|
32
|
+
console.log("wsRow:meta:=>", meta);
|
|
33
|
+
while (await wsRows.next()) {
|
|
34
|
+
let result = wsRows.getData();
|
|
35
|
+
console.log('queryRes.Scan().then=>', result);
|
|
36
|
+
}
|
|
37
|
+
wsRows.close();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error(err.code, err.message);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (wsRows) {
|
|
44
|
+
await wsRows.close();
|
|
45
|
+
}
|
|
46
|
+
if (wsSql) {
|
|
47
|
+
await wsSql.close();
|
|
48
|
+
}
|
|
49
|
+
(0, src_1.destroy)();
|
|
50
|
+
console.log("finish!");
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicStmt.d.ts","sourceRoot":"","sources":["../../example/basicStmt.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../src/common/config");
|
|
4
|
+
const src_1 = require("../src");
|
|
5
|
+
let db = 'power';
|
|
6
|
+
let stable = 'meters';
|
|
7
|
+
let tags = ['California.SanFrancisco', 3];
|
|
8
|
+
let multi = [
|
|
9
|
+
[1706786044994, 1706786044995, 1706786044996],
|
|
10
|
+
[10.2, 10.3, 10.4],
|
|
11
|
+
[292, 293, 294],
|
|
12
|
+
[0.32, 0.33, 0.34],
|
|
13
|
+
];
|
|
14
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
15
|
+
async function Prepare() {
|
|
16
|
+
let conf = new config_1.WSConfig(dsn);
|
|
17
|
+
let wsSql = await (0, src_1.sqlConnect)(conf);
|
|
18
|
+
await wsSql.exec(`create database if not exists ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`);
|
|
19
|
+
await wsSql.exec(`CREATE STABLE if not exists ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`);
|
|
20
|
+
wsSql.close();
|
|
21
|
+
}
|
|
22
|
+
(async () => {
|
|
23
|
+
let stmt = null;
|
|
24
|
+
let connector = null;
|
|
25
|
+
try {
|
|
26
|
+
await Prepare();
|
|
27
|
+
let wsConf = new config_1.WSConfig(dsn);
|
|
28
|
+
wsConf.setDb(db);
|
|
29
|
+
connector = await (0, src_1.sqlConnect)(wsConf);
|
|
30
|
+
stmt = await connector.stmtInit();
|
|
31
|
+
await stmt.prepare(`INSERT INTO ? USING ${db}.${stable} (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)`);
|
|
32
|
+
await stmt.setTableName('d1001');
|
|
33
|
+
let tagParams = stmt.newStmtParam();
|
|
34
|
+
tagParams.setVarchar([tags[0]]);
|
|
35
|
+
tagParams.setInt([tags[1]]);
|
|
36
|
+
await stmt.setTags(tagParams);
|
|
37
|
+
let bindParams = stmt.newStmtParam();
|
|
38
|
+
bindParams.setTimestamp(multi[0]);
|
|
39
|
+
bindParams.setFloat(multi[1]);
|
|
40
|
+
bindParams.setInt(multi[2]);
|
|
41
|
+
bindParams.setFloat(multi[3]);
|
|
42
|
+
await stmt.bind(bindParams);
|
|
43
|
+
await stmt.batch();
|
|
44
|
+
await stmt.exec();
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (stmt) {
|
|
51
|
+
await stmt.close();
|
|
52
|
+
}
|
|
53
|
+
if (connector) {
|
|
54
|
+
await connector.close();
|
|
55
|
+
}
|
|
56
|
+
(0, src_1.destroy)();
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicTmq.d.ts","sourceRoot":"","sources":["../../example/basicTmq.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../src/common/config");
|
|
4
|
+
const constant_1 = require("../src/tmq/constant");
|
|
5
|
+
const src_1 = require("../src");
|
|
6
|
+
const stable = 'meters';
|
|
7
|
+
const db = 'power';
|
|
8
|
+
const topics = ['pwer_meters_topic'];
|
|
9
|
+
let dropTopic = `DROP TOPIC IF EXISTS ${topics[0]};`;
|
|
10
|
+
let configMap = new Map([
|
|
11
|
+
[constant_1.TMQConstants.GROUP_ID, "gId"],
|
|
12
|
+
[constant_1.TMQConstants.CONNECT_USER, "root"],
|
|
13
|
+
[constant_1.TMQConstants.CONNECT_PASS, "taosdata"],
|
|
14
|
+
[constant_1.TMQConstants.AUTO_OFFSET_RESET, "earliest"],
|
|
15
|
+
[constant_1.TMQConstants.CLIENT_ID, 'test_tmq_client'],
|
|
16
|
+
[constant_1.TMQConstants.WS_URL, 'ws://localhost:6041'],
|
|
17
|
+
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
|
|
18
|
+
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000']
|
|
19
|
+
]);
|
|
20
|
+
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
21
|
+
async function Prepare() {
|
|
22
|
+
let conf = new config_1.WSConfig(dsn);
|
|
23
|
+
const createDB = `create database if not exists ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`;
|
|
24
|
+
const createStable = `CREATE STABLE if not exists ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`;
|
|
25
|
+
let createTopic = `create topic if not exists ${topics[0]} as select * from ${db}.${stable}`;
|
|
26
|
+
const useDB = `use ${db}`;
|
|
27
|
+
let ws = await (0, src_1.sqlConnect)(conf);
|
|
28
|
+
await ws.exec(createDB);
|
|
29
|
+
await ws.exec(useDB);
|
|
30
|
+
await ws.exec(createStable);
|
|
31
|
+
await ws.exec(createTopic);
|
|
32
|
+
for (let i = 0; i < 10; i++) {
|
|
33
|
+
await ws.exec(`INSERT INTO d1001 USING ${stable} (location, groupId) TAGS ("California.SanFrancisco", 3) VALUES (NOW, ${10 + i}, ${200 + i}, ${0.32 + i})`);
|
|
34
|
+
}
|
|
35
|
+
ws.close();
|
|
36
|
+
}
|
|
37
|
+
(async () => {
|
|
38
|
+
let consumer = null;
|
|
39
|
+
try {
|
|
40
|
+
await Prepare();
|
|
41
|
+
consumer = await (0, src_1.tmqConnect)(configMap);
|
|
42
|
+
await consumer.subscribe(topics);
|
|
43
|
+
for (let i = 0; i < 5; i++) {
|
|
44
|
+
let res = await consumer.poll(500);
|
|
45
|
+
for (let [key, value] of res) {
|
|
46
|
+
console.log(key, value);
|
|
47
|
+
}
|
|
48
|
+
if (res.size == 0) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
await consumer.commit();
|
|
52
|
+
}
|
|
53
|
+
let assignment = await consumer.assignment();
|
|
54
|
+
console.log(assignment);
|
|
55
|
+
await consumer.seekToBeginning(assignment);
|
|
56
|
+
assignment = await consumer.assignment();
|
|
57
|
+
for (let i in assignment) {
|
|
58
|
+
console.log("seek after:", assignment[i]);
|
|
59
|
+
}
|
|
60
|
+
await consumer.unsubscribe();
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (consumer) {
|
|
67
|
+
await consumer.close();
|
|
68
|
+
}
|
|
69
|
+
(0, src_1.destroy)();
|
|
70
|
+
}
|
|
71
|
+
})();
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./src/client/wsClient";
|
|
2
|
+
export * from "./src/client/wsConnector";
|
|
3
|
+
export * from "./src/client/wsConnectorPool";
|
|
4
|
+
export * from "./src/client/wsEventCallback";
|
|
5
|
+
export * from "./src/client/wsResponse";
|
|
6
|
+
export * from "./src/common/config";
|
|
7
|
+
export * from "./src/common/constant";
|
|
8
|
+
export * from "./src/common/log";
|
|
9
|
+
export * from "./src/common/reqid";
|
|
10
|
+
export * from "./src/common/taosResult";
|
|
11
|
+
export * from "./src/common/ut8Helper";
|
|
12
|
+
export * from "./src/common/utils";
|
|
13
|
+
export * from "./src/common/wsError";
|
|
14
|
+
export * from "./src/common/wsOptions";
|
|
15
|
+
export * from "./src/index";
|
|
16
|
+
export * from "./src/sql/wsProto";
|
|
17
|
+
export * from "./src/sql/wsRows";
|
|
18
|
+
export * from "./src/sql/wsSql";
|
|
19
|
+
export * from "./src/stmt/wsParams";
|
|
20
|
+
export * from "./src/stmt/wsProto";
|
|
21
|
+
export * from "./src/stmt/wsStmt";
|
|
22
|
+
export * from "./src/tmq/config";
|
|
23
|
+
export * from "./src/tmq/constant";
|
|
24
|
+
export * from "./src/tmq/tmqResponse";
|
|
25
|
+
export * from "./src/tmq/wsTmq";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/client/wsClient"), exports);
|
|
18
|
+
__exportStar(require("./src/client/wsConnector"), exports);
|
|
19
|
+
__exportStar(require("./src/client/wsConnectorPool"), exports);
|
|
20
|
+
__exportStar(require("./src/client/wsEventCallback"), exports);
|
|
21
|
+
__exportStar(require("./src/client/wsResponse"), exports);
|
|
22
|
+
__exportStar(require("./src/common/config"), exports);
|
|
23
|
+
__exportStar(require("./src/common/constant"), exports);
|
|
24
|
+
__exportStar(require("./src/common/log"), exports);
|
|
25
|
+
__exportStar(require("./src/common/reqid"), exports);
|
|
26
|
+
__exportStar(require("./src/common/taosResult"), exports);
|
|
27
|
+
__exportStar(require("./src/common/ut8Helper"), exports);
|
|
28
|
+
__exportStar(require("./src/common/utils"), exports);
|
|
29
|
+
__exportStar(require("./src/common/wsError"), exports);
|
|
30
|
+
__exportStar(require("./src/common/wsOptions"), exports);
|
|
31
|
+
__exportStar(require("./src/index"), exports);
|
|
32
|
+
__exportStar(require("./src/sql/wsProto"), exports);
|
|
33
|
+
__exportStar(require("./src/sql/wsRows"), exports);
|
|
34
|
+
__exportStar(require("./src/sql/wsSql"), exports);
|
|
35
|
+
__exportStar(require("./src/stmt/wsParams"), exports);
|
|
36
|
+
__exportStar(require("./src/stmt/wsProto"), exports);
|
|
37
|
+
__exportStar(require("./src/stmt/wsStmt"), exports);
|
|
38
|
+
__exportStar(require("./src/tmq/config"), exports);
|
|
39
|
+
__exportStar(require("./src/tmq/constant"), exports);
|
|
40
|
+
__exportStar(require("./src/tmq/tmqResponse"), exports);
|
|
41
|
+
__exportStar(require("./src/tmq/wsTmq"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TaosResult } from '../common/taosResult';
|
|
2
|
+
import { WSQueryResponse, WSFetchResponse } from './wsResponse';
|
|
3
|
+
export declare class WsClient {
|
|
4
|
+
private _wsConnector?;
|
|
5
|
+
private _timeout?;
|
|
6
|
+
private readonly _url;
|
|
7
|
+
constructor(url: URL, timeout?: number | undefined | null);
|
|
8
|
+
connect(database?: string | undefined | null): Promise<void>;
|
|
9
|
+
execNoResp(queryMsg: string): Promise<void>;
|
|
10
|
+
exec(queryMsg: string, bSqlQuery?: boolean): Promise<any>;
|
|
11
|
+
sendBinaryMsg(reqId: bigint, action: string, message: ArrayBuffer, bSqlQuery?: boolean): Promise<any>;
|
|
12
|
+
getState(): number;
|
|
13
|
+
ready(): Promise<void>;
|
|
14
|
+
fetch(res: WSQueryResponse): Promise<WSFetchResponse>;
|
|
15
|
+
fetchBlock(fetchResponse: WSFetchResponse, taosResult: TaosResult): Promise<TaosResult>;
|
|
16
|
+
sendMsg(msg: string): Promise<any>;
|
|
17
|
+
freeResult(res: WSQueryResponse): Promise<unknown>;
|
|
18
|
+
version(): Promise<string>;
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
checkURL(url: URL): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=wsClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../../src/client/wsClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,EAGH,eAAe,EACf,eAAe,EAClB,MAAM,cAAc,CAAC;AAKtB,qBAAa,QAAQ;IACjB,OAAO,CAAC,YAAY,CAAC,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,CAA2B;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAK;gBAEd,GAAG,EAAE,GAAG,EAAE,OAAQ,CAAC,EAAC,MAAM,GAAG,SAAS,GAAG,IAAI;IAOnD,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC5D,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAC,OAAc,GAAG,OAAO,CAAC,GAAG,CAAC;IAuB9D,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAC,OAAc,GAAG,OAAO,CAAC,GAAG,CAAC;IAsB/G,QAAQ;IAQF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,KAAK,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IA0BrD,UAAU,CAAC,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA2BvF,OAAO,CAAC,GAAG,EAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAajC,UAAU,CAAC,GAAG,EAAE,eAAe;IAqB/B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IA4B1B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;IAS3B,QAAQ,CAAC,GAAG,EAAE,GAAG;CASpB"}
|
|
@@ -0,0 +1,253 @@
|
|
|
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.WsClient = void 0;
|
|
7
|
+
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
8
|
+
const wsConnectorPool_1 = require("./wsConnectorPool");
|
|
9
|
+
const taosResult_1 = require("../common/taosResult");
|
|
10
|
+
const wsError_1 = require("../common/wsError");
|
|
11
|
+
const wsResponse_1 = require("./wsResponse");
|
|
12
|
+
const reqid_1 = require("../common/reqid");
|
|
13
|
+
const log_1 = __importDefault(require("../common/log"));
|
|
14
|
+
class WsClient {
|
|
15
|
+
constructor(url, timeout) {
|
|
16
|
+
this.checkURL(url);
|
|
17
|
+
this._url = url;
|
|
18
|
+
this._timeout = timeout;
|
|
19
|
+
}
|
|
20
|
+
async connect(database) {
|
|
21
|
+
let _db = this._url.pathname.split('/')[3];
|
|
22
|
+
if (database) {
|
|
23
|
+
_db = database;
|
|
24
|
+
}
|
|
25
|
+
let connMsg = {
|
|
26
|
+
action: 'conn',
|
|
27
|
+
args: {
|
|
28
|
+
req_id: reqid_1.ReqId.getReqID(),
|
|
29
|
+
user: this._url.username,
|
|
30
|
+
password: this._url.password,
|
|
31
|
+
db: _db,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
this._wsConnector = await wsConnectorPool_1.WebSocketConnectionPool.instance().getConnection(this._url, this._timeout);
|
|
35
|
+
if (this._wsConnector.readyState() > 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
await this._wsConnector.ready();
|
|
40
|
+
let result = await this._wsConnector.sendMsg(JSON.stringify(connMsg));
|
|
41
|
+
if (result.msg.code == 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw (new wsError_1.WebSocketQueryError(result.msg.code, result.msg.message));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
log_1.default.error(e.code, e.message);
|
|
48
|
+
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_WEBSOCKET_CONNECTION_FAIL, `connection creation failed, url: ${this._url}`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async execNoResp(queryMsg) {
|
|
52
|
+
log_1.default.debug('[wsQueryInterface.query.queryMsg]===>' + queryMsg);
|
|
53
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
54
|
+
await this._wsConnector.sendMsgNoResp(queryMsg);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
58
|
+
}
|
|
59
|
+
// need to construct Response.
|
|
60
|
+
async exec(queryMsg, bSqlQuery = true) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
log_1.default.debug('[wsQueryInterface.query.queryMsg]===>' + queryMsg);
|
|
63
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
64
|
+
this._wsConnector.sendMsg(queryMsg).then((e) => {
|
|
65
|
+
if (e.msg.code == 0) {
|
|
66
|
+
if (bSqlQuery) {
|
|
67
|
+
resolve(new wsResponse_1.WSQueryResponse(e));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolve(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
reject(new wsError_1.WebSocketInterfaceError(e.msg.code, e.msg.message));
|
|
75
|
+
}
|
|
76
|
+
}).catch((e) => { reject(e); });
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// need to construct Response.
|
|
84
|
+
async sendBinaryMsg(reqId, action, message, bSqlQuery = true) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
87
|
+
this._wsConnector.sendBinaryMsg(reqId, action, message).then((e) => {
|
|
88
|
+
if (e.msg.code == 0) {
|
|
89
|
+
if (bSqlQuery) {
|
|
90
|
+
resolve(new wsResponse_1.WSQueryResponse(e));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
resolve(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
reject(new wsError_1.WebSocketInterfaceError(e.msg.code, e.msg.message));
|
|
98
|
+
}
|
|
99
|
+
}).catch((e) => { reject(e); });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
getState() {
|
|
107
|
+
if (this._wsConnector) {
|
|
108
|
+
return this._wsConnector.readyState();
|
|
109
|
+
}
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
async ready() {
|
|
113
|
+
try {
|
|
114
|
+
this._wsConnector = await wsConnectorPool_1.WebSocketConnectionPool.instance().getConnection(this._url, this._timeout);
|
|
115
|
+
if (this._wsConnector.readyState() <= 0) {
|
|
116
|
+
await this._wsConnector.ready();
|
|
117
|
+
}
|
|
118
|
+
log_1.default.debug("ready status ", this._url, this._wsConnector.readyState());
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
log_1.default.error(e.code, e.message);
|
|
123
|
+
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_WEBSOCKET_CONNECTION_FAIL, `connection creation failed, url: ${this._url}`));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async fetch(res) {
|
|
127
|
+
let fetchMsg = {
|
|
128
|
+
action: 'fetch',
|
|
129
|
+
args: {
|
|
130
|
+
req_id: reqid_1.ReqId.getReqID(),
|
|
131
|
+
id: res.id,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
let jsonStr = json_bigint_1.default.stringify(fetchMsg);
|
|
136
|
+
log_1.default.debug('[wsQueryInterface.fetch.fetchMsg]===>' + jsonStr);
|
|
137
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
138
|
+
this._wsConnector.sendMsg(jsonStr).then((e) => {
|
|
139
|
+
if (e.msg.code == 0) {
|
|
140
|
+
resolve(new wsResponse_1.WSFetchResponse(e));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
reject(new wsError_1.WebSocketInterfaceError(e.msg.code, e.msg.message));
|
|
144
|
+
}
|
|
145
|
+
}).catch((e) => { reject(e); });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async fetchBlock(fetchResponse, taosResult) {
|
|
153
|
+
let fetchBlockMsg = {
|
|
154
|
+
action: 'fetch_block',
|
|
155
|
+
args: {
|
|
156
|
+
req_id: reqid_1.ReqId.getReqID(),
|
|
157
|
+
id: fetchResponse.id,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
let jsonStr = json_bigint_1.default.stringify(fetchBlockMsg);
|
|
162
|
+
log_1.default.debug("[wsQueryInterface.fetchBlock.fetchBlockMsg]===>" + jsonStr);
|
|
163
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
164
|
+
this._wsConnector.sendMsg(jsonStr).then((e) => {
|
|
165
|
+
let resp = e;
|
|
166
|
+
taosResult.addTotalTime(resp.totalTime);
|
|
167
|
+
// if retrieve JSON then reject with message
|
|
168
|
+
// else is binary , so parse raw block to TaosResult
|
|
169
|
+
(0, taosResult_1.parseBlock)(fetchResponse.rows, new wsResponse_1.WSFetchBlockResponse(resp.msg), taosResult);
|
|
170
|
+
resolve(taosResult);
|
|
171
|
+
}).catch((e) => reject(e));
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async sendMsg(msg) {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
log_1.default.debug("[wsQueryInterface.sendMsg]===>" + msg);
|
|
181
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
182
|
+
this._wsConnector.sendMsg(msg).then((e) => {
|
|
183
|
+
resolve(e);
|
|
184
|
+
}).catch((e) => reject(e));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async freeResult(res) {
|
|
192
|
+
let freeResultMsg = {
|
|
193
|
+
action: 'free_result',
|
|
194
|
+
args: {
|
|
195
|
+
req_id: reqid_1.ReqId.getReqID(),
|
|
196
|
+
id: res.id,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
let jsonStr = json_bigint_1.default.stringify(freeResultMsg);
|
|
201
|
+
log_1.default.debug("[wsQueryInterface.freeResult.freeResultMsg]===>" + jsonStr);
|
|
202
|
+
if (this._wsConnector && this._wsConnector.readyState() > 0) {
|
|
203
|
+
this._wsConnector.sendMsg(jsonStr, false)
|
|
204
|
+
.then((e) => { resolve(e); })
|
|
205
|
+
.catch((e) => reject(e));
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
reject(new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect"));
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async version() {
|
|
213
|
+
let versionMsg = {
|
|
214
|
+
action: 'version',
|
|
215
|
+
args: {
|
|
216
|
+
req_id: reqid_1.ReqId.getReqID()
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
if (this._wsConnector) {
|
|
220
|
+
try {
|
|
221
|
+
if (this._wsConnector.readyState() <= 0) {
|
|
222
|
+
await this._wsConnector.ready();
|
|
223
|
+
}
|
|
224
|
+
let result = await this._wsConnector.sendMsg(json_bigint_1.default.stringify(versionMsg));
|
|
225
|
+
if (result.msg.code == 0) {
|
|
226
|
+
return new wsResponse_1.WSVersionResponse(result).version;
|
|
227
|
+
}
|
|
228
|
+
throw (new wsError_1.WebSocketInterfaceError(result.msg.code, result.msg.message));
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
log_1.default.error(e.code, e.message);
|
|
232
|
+
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_WEBSOCKET_CONNECTION_FAIL, `connection creation failed, url: ${this._url}`));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
throw (wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "invalid websocket connect");
|
|
236
|
+
}
|
|
237
|
+
async close() {
|
|
238
|
+
if (this._wsConnector) {
|
|
239
|
+
await wsConnectorPool_1.WebSocketConnectionPool.instance().releaseConnection(this._wsConnector);
|
|
240
|
+
this._wsConnector = undefined;
|
|
241
|
+
// this._wsConnector.close();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
checkURL(url) {
|
|
245
|
+
// Assert is cloud url
|
|
246
|
+
if (!url.searchParams.has('token')) {
|
|
247
|
+
if (!(url.username || url.password)) {
|
|
248
|
+
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_AUTHENTICATION, 'invalid url, password or username needed.');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.WsClient = WsClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class WebSocketConnector {
|
|
2
|
+
private _wsConn;
|
|
3
|
+
private _wsURL;
|
|
4
|
+
_timeout: number;
|
|
5
|
+
constructor(url: URL, timeout: number | undefined | null);
|
|
6
|
+
ready(): Promise<unknown>;
|
|
7
|
+
private _onclose;
|
|
8
|
+
private _onmessage;
|
|
9
|
+
close(): void;
|
|
10
|
+
readyState(): number;
|
|
11
|
+
sendMsgNoResp(message: string): Promise<void>;
|
|
12
|
+
sendMsg(message: string, register?: Boolean): Promise<unknown>;
|
|
13
|
+
sendBinaryMsg(reqId: bigint, action: string, message: ArrayBuffer, register?: Boolean): Promise<unknown>;
|
|
14
|
+
configTimeout(ms: number): void;
|
|
15
|
+
getWsURL(): URL;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=wsConnector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsConnector.d.ts","sourceRoot":"","sources":["../../../src/client/wsConnector.ts"],"names":[],"mappings":"AAMA,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,MAAM,CAAM;IACpB,QAAQ,SAAQ;gBAGJ,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAsBlD,KAAK;YAeG,QAAQ;IAKtB,OAAO,CAAC,UAAU;IA0BlB,KAAK;IASL,UAAU,IAAI,MAAM;IAId,aAAa,CAAC,OAAO,EAAE,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC;IAmB5C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAc;IAuBjD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAE,OAAc;IAgBzF,aAAa,CAAC,EAAE,EAAE,MAAM;IAIxB,QAAQ,IAAI,GAAG;CAGzB"}
|