@tdengine/websocket 3.1.7 → 3.1.8
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/src/client/wsClient.d.ts.map +1 -1
- package/lib/src/client/wsClient.js +10 -9
- package/lib/src/client/wsConnector.d.ts.map +1 -1
- package/lib/src/client/wsConnector.js +4 -10
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
- package/lib/src/client/wsConnectorPool.js +16 -5
- package/lib/src/client/wsResponse.d.ts +0 -16
- package/lib/src/client/wsResponse.d.ts.map +1 -1
- package/lib/src/client/wsResponse.js +1 -11
- package/lib/src/sql/wsRows.d.ts.map +1 -1
- package/lib/src/sql/wsRows.js +10 -4
- package/lib/src/sql/wsSql.js +2 -2
- package/lib/src/tmq/config.d.ts.map +1 -1
- package/lib/src/tmq/config.js +1 -1
- package/lib/test/bulkPulling/cloud.tmq.test.d.ts +2 -0
- package/lib/test/bulkPulling/cloud.tmq.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/cloud.tmq.test.js +80 -0
- package/lib/test/bulkPulling/sql.test.js +3 -1
- package/lib/test/bulkPulling/stmt.func.test.js +2 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +2 -2
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../../src/client/wsClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAEH,eAAe,EAClB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"wsClient.d.ts","sourceRoot":"","sources":["../../../src/client/wsClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAEH,eAAe,EAClB,MAAM,cAAc,CAAC;AAMtB,qBAAa,QAAQ;IACjB,OAAO,CAAC,YAAY,CAAC,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,CAA2B;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAK;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAa;gBAEpC,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;IAsC5D,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,EAAE,aAAa,GAAE,OAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IA0B/I,QAAQ;IAQF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,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;IASX,YAAY;CAQrB"}
|
|
@@ -11,6 +11,7 @@ const wsResponse_1 = require("./wsResponse");
|
|
|
11
11
|
const reqid_1 = require("../common/reqid");
|
|
12
12
|
const log_1 = __importDefault(require("../common/log"));
|
|
13
13
|
const utils_1 = require("../common/utils");
|
|
14
|
+
const websocket_1 = require("websocket");
|
|
14
15
|
class WsClient {
|
|
15
16
|
constructor(url, timeout) {
|
|
16
17
|
this.checkURL(url);
|
|
@@ -32,7 +33,7 @@ class WsClient {
|
|
|
32
33
|
},
|
|
33
34
|
};
|
|
34
35
|
this._wsConnector = await wsConnectorPool_1.WebSocketConnectionPool.instance().getConnection(this._url, this._timeout);
|
|
35
|
-
if (this._wsConnector.readyState()
|
|
36
|
+
if (this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
try {
|
|
@@ -52,7 +53,7 @@ class WsClient {
|
|
|
52
53
|
}
|
|
53
54
|
async execNoResp(queryMsg) {
|
|
54
55
|
log_1.default.debug('[wsQueryInterface.query.queryMsg]===>' + queryMsg);
|
|
55
|
-
if (this._wsConnector && this._wsConnector.readyState()
|
|
56
|
+
if (this._wsConnector && this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
56
57
|
await this._wsConnector.sendMsgNoResp(queryMsg);
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
@@ -62,7 +63,7 @@ class WsClient {
|
|
|
62
63
|
async exec(queryMsg, bSqlQuery = true) {
|
|
63
64
|
return new Promise((resolve, reject) => {
|
|
64
65
|
log_1.default.debug('[wsQueryInterface.query.queryMsg]===>' + queryMsg);
|
|
65
|
-
if (this._wsConnector && this._wsConnector.readyState()
|
|
66
|
+
if (this._wsConnector && this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
66
67
|
this._wsConnector.sendMsg(queryMsg).then((e) => {
|
|
67
68
|
if (e.msg.code == 0) {
|
|
68
69
|
if (bSqlQuery) {
|
|
@@ -85,7 +86,7 @@ class WsClient {
|
|
|
85
86
|
// need to construct Response.
|
|
86
87
|
async sendBinaryMsg(reqId, action, message, bSqlQuery = true, bResultBinary = false) {
|
|
87
88
|
return new Promise((resolve, reject) => {
|
|
88
|
-
if (this._wsConnector && this._wsConnector.readyState()
|
|
89
|
+
if (this._wsConnector && this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
89
90
|
this._wsConnector.sendBinaryMsg(reqId, action, message).then((e) => {
|
|
90
91
|
if (bResultBinary) {
|
|
91
92
|
resolve(e);
|
|
@@ -117,7 +118,7 @@ class WsClient {
|
|
|
117
118
|
async ready() {
|
|
118
119
|
try {
|
|
119
120
|
this._wsConnector = await wsConnectorPool_1.WebSocketConnectionPool.instance().getConnection(this._url, this._timeout);
|
|
120
|
-
if (this._wsConnector.readyState()
|
|
121
|
+
if (this._wsConnector.readyState() !== websocket_1.w3cwebsocket.OPEN) {
|
|
121
122
|
await this._wsConnector.ready();
|
|
122
123
|
}
|
|
123
124
|
log_1.default.debug("ready status ", this._url, this._wsConnector.readyState());
|
|
@@ -131,7 +132,7 @@ class WsClient {
|
|
|
131
132
|
async sendMsg(msg) {
|
|
132
133
|
return new Promise((resolve, reject) => {
|
|
133
134
|
log_1.default.debug("[wsQueryInterface.sendMsg]===>" + msg);
|
|
134
|
-
if (this._wsConnector && this._wsConnector.readyState()
|
|
135
|
+
if (this._wsConnector && this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
135
136
|
this._wsConnector.sendMsg(msg).then((e) => {
|
|
136
137
|
resolve(e);
|
|
137
138
|
}).catch((e) => reject(e));
|
|
@@ -152,8 +153,8 @@ class WsClient {
|
|
|
152
153
|
return new Promise((resolve, reject) => {
|
|
153
154
|
let jsonStr = json_bigint_1.default.stringify(freeResultMsg);
|
|
154
155
|
log_1.default.debug("[wsQueryInterface.freeResult.freeResultMsg]===>" + jsonStr);
|
|
155
|
-
if (this._wsConnector && this._wsConnector.readyState()
|
|
156
|
-
this._wsConnector.
|
|
156
|
+
if (this._wsConnector && this._wsConnector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
157
|
+
this._wsConnector.sendMsgNoResp(jsonStr)
|
|
157
158
|
.then((e) => { resolve(e); })
|
|
158
159
|
.catch((e) => reject(e));
|
|
159
160
|
}
|
|
@@ -171,7 +172,7 @@ class WsClient {
|
|
|
171
172
|
};
|
|
172
173
|
if (this._wsConnector) {
|
|
173
174
|
try {
|
|
174
|
-
if (this._wsConnector.readyState()
|
|
175
|
+
if (this._wsConnector.readyState() !== websocket_1.w3cwebsocket.OPEN) {
|
|
175
176
|
await this._wsConnector.ready();
|
|
176
177
|
}
|
|
177
178
|
let result = await this._wsConnector.sendMsg(json_bigint_1.default.stringify(versionMsg));
|
|
@@ -1 +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;YAcG,QAAQ;IAKtB,OAAO,CAAC,UAAU;
|
|
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;YAcG,QAAQ;IAKtB,OAAO,CAAC,UAAU;IAmBlB,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,QAAQ,IAAI,GAAG;CAGzB"}
|
|
@@ -53,12 +53,6 @@ class WebSocketConnector {
|
|
|
53
53
|
let id = new DataView(data, 26, 8).getBigUint64(0, true);
|
|
54
54
|
wsEventCallback_1.WsEventCallback.instance().handleEventCallback({ id: id, action: '', req_id: BigInt(0) }, wsEventCallback_1.OnMessageType.MESSAGE_TYPE_ARRAYBUFFER, data);
|
|
55
55
|
}
|
|
56
|
-
else if (Object.prototype.toString.call(data) === '[object Blob]') {
|
|
57
|
-
data.arrayBuffer().then((d) => {
|
|
58
|
-
let id = new DataView(d, 8, 8).getBigUint64(0, true);
|
|
59
|
-
wsEventCallback_1.WsEventCallback.instance().handleEventCallback({ id: id, action: '', req_id: BigInt(0) }, wsEventCallback_1.OnMessageType.MESSAGE_TYPE_BLOB, d);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
56
|
else if (Object.prototype.toString.call(data) === '[object String]') {
|
|
63
57
|
let msg = JSON.parse(data);
|
|
64
58
|
log_1.default.debug("[_onmessage.stringType]==>:" + data);
|
|
@@ -86,7 +80,7 @@ class WebSocketConnector {
|
|
|
86
80
|
msg.args.id = BigInt(msg.args.id);
|
|
87
81
|
}
|
|
88
82
|
return new Promise((resolve, reject) => {
|
|
89
|
-
if (this._wsConn && this._wsConn.readyState
|
|
83
|
+
if (this._wsConn && this._wsConn.readyState === websocket_1.w3cwebsocket.OPEN) {
|
|
90
84
|
this._wsConn.send(message);
|
|
91
85
|
resolve();
|
|
92
86
|
}
|
|
@@ -102,12 +96,12 @@ class WebSocketConnector {
|
|
|
102
96
|
msg.args.id = BigInt(msg.args.id);
|
|
103
97
|
}
|
|
104
98
|
return new Promise((resolve, reject) => {
|
|
105
|
-
if (this._wsConn && this._wsConn.readyState
|
|
99
|
+
if (this._wsConn && this._wsConn.readyState === websocket_1.w3cwebsocket.OPEN) {
|
|
106
100
|
if (register) {
|
|
107
101
|
wsEventCallback_1.WsEventCallback.instance().registerCallback({ action: msg.action, req_id: msg.args.req_id,
|
|
108
102
|
timeout: this._timeout, id: msg.args.id === undefined ? msg.args.id : BigInt(msg.args.id) }, resolve, reject);
|
|
109
103
|
}
|
|
110
|
-
log_1.default.debug(
|
|
104
|
+
log_1.default.debug(`[wsClient.sendMessage.msg]===> ${message}`);
|
|
111
105
|
this._wsConn.send(message);
|
|
112
106
|
}
|
|
113
107
|
else {
|
|
@@ -117,7 +111,7 @@ class WebSocketConnector {
|
|
|
117
111
|
}
|
|
118
112
|
async sendBinaryMsg(reqId, action, message, register = true) {
|
|
119
113
|
return new Promise((resolve, reject) => {
|
|
120
|
-
if (this._wsConn && this._wsConn.readyState
|
|
114
|
+
if (this._wsConn && this._wsConn.readyState === websocket_1.w3cwebsocket.OPEN) {
|
|
121
115
|
if (register) {
|
|
122
116
|
wsEventCallback_1.WsEventCallback.instance().registerCallback({ action: action, req_id: reqId,
|
|
123
117
|
timeout: this._timeout, id: reqId }, resolve, reject);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsConnectorPool.d.ts","sourceRoot":"","sources":["../../../src/client/wsConnectorPool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"wsConnectorPool.d.ts","sourceRoot":"","sources":["../../../src/client/wsConnectorPool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AASnD,qBAAa,uBAAuB;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAyB;IAClD,OAAO,CAAC,IAAI,CAAgD;IAC5D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAoB;IAC/C,OAAO,CAAC,MAAM,CAAC,WAAW,CAAa;IAEvC,OAAO;WAOO,QAAQ,CAAC,cAAc,GAAE,MAAW,GAAE,uBAAuB;IAOrE,aAAa,CAAC,GAAG,EAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAuCvF,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAE,OAAO,CAAC,IAAI,CAAC;IA4BpE,SAAS;CAcZ"}
|
|
@@ -8,6 +8,7 @@ const async_mutex_1 = require("async-mutex");
|
|
|
8
8
|
const wsConnector_1 = require("./wsConnector");
|
|
9
9
|
const wsError_1 = require("../common/wsError");
|
|
10
10
|
const log_1 = __importDefault(require("../common/log"));
|
|
11
|
+
const websocket_1 = require("websocket");
|
|
11
12
|
const mutex = new async_mutex_1.Mutex();
|
|
12
13
|
class WebSocketConnectionPool {
|
|
13
14
|
constructor(maxConnections = -1) {
|
|
@@ -29,10 +30,20 @@ class WebSocketConnectionPool {
|
|
|
29
30
|
const unlock = await mutex.acquire();
|
|
30
31
|
try {
|
|
31
32
|
if (this.pool.has(connectAddr)) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const connectors = this.pool.get(connectAddr);
|
|
34
|
+
while (connectors && connectors.length > 0) {
|
|
35
|
+
const candidate = connectors.pop();
|
|
36
|
+
if (!candidate) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (candidate && candidate.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
40
|
+
connector = candidate;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
else if (candidate) {
|
|
44
|
+
Atomics.add(WebSocketConnectionPool.sharedArray, 0, -1);
|
|
45
|
+
candidate.close();
|
|
46
|
+
log_1.default.error(`getConnection, current connection status fail, url: ${connectAddr}`);
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
}
|
|
@@ -55,7 +66,7 @@ class WebSocketConnectionPool {
|
|
|
55
66
|
if (connector) {
|
|
56
67
|
const unlock = await mutex.acquire();
|
|
57
68
|
try {
|
|
58
|
-
if (connector.readyState()
|
|
69
|
+
if (connector.readyState() === websocket_1.w3cwebsocket.OPEN) {
|
|
59
70
|
let url = connector.getWsURL();
|
|
60
71
|
let connectAddr = url.origin.concat(url.pathname).concat(url.search);
|
|
61
72
|
let connectors = this.pool.get(connectAddr);
|
|
@@ -42,20 +42,4 @@ export declare class WSFetchBlockResponse {
|
|
|
42
42
|
textDecoder: TextDecoder;
|
|
43
43
|
constructor(msg: ArrayBuffer);
|
|
44
44
|
}
|
|
45
|
-
interface IWSConnResponse {
|
|
46
|
-
code: number;
|
|
47
|
-
message: string;
|
|
48
|
-
action: string;
|
|
49
|
-
req_id: number;
|
|
50
|
-
timing: bigint;
|
|
51
|
-
}
|
|
52
|
-
export declare class WSConnResponse {
|
|
53
|
-
code: number;
|
|
54
|
-
message: string;
|
|
55
|
-
action: string;
|
|
56
|
-
req_id: number;
|
|
57
|
-
timing: bigint;
|
|
58
|
-
constructor(msg: IWSConnResponse);
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
61
45
|
//# sourceMappingURL=wsResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsResponse.d.ts","sourceRoot":"","sources":["../../../src/client/wsResponse.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAe,MAAM,sBAAsB,CAAC;AAEhE,qBAAa,iBAAiB;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;gBACN,IAAI,EAAC,WAAW;CAO/B;AAED,qBAAa,eAAe;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACpC,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAC,WAAW;IAI5B,OAAO,CAAC,OAAO;CAoBlB;AAED,qBAAa,oBAAoB;IAC7B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,WAAW,EAAE,WAAW,CAAA;gBACZ,GAAG,EAAE,WAAW;CAgC/B
|
|
1
|
+
{"version":3,"file":"wsResponse.d.ts","sourceRoot":"","sources":["../../../src/client/wsResponse.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAe,MAAM,sBAAsB,CAAC;AAEhE,qBAAa,iBAAiB;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;gBACN,IAAI,EAAC,WAAW;CAO/B;AAED,qBAAa,eAAe;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACpC,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAC,WAAW;IAI5B,OAAO,CAAC,OAAO;CAoBlB;AAED,qBAAa,oBAAoB;IAC7B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,WAAW,EAAE,WAAW,CAAA;gBACZ,GAAG,EAAE,WAAW;CAgC/B"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* define ws Response type|class, for query?
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.WSFetchBlockResponse = exports.WSQueryResponse = exports.WSVersionResponse = void 0;
|
|
7
7
|
const taosResult_1 = require("../common/taosResult");
|
|
8
8
|
class WSVersionResponse {
|
|
9
9
|
constructor(resp) {
|
|
@@ -76,13 +76,3 @@ class WSFetchBlockResponse {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
exports.WSFetchBlockResponse = WSFetchBlockResponse;
|
|
79
|
-
class WSConnResponse {
|
|
80
|
-
constructor(msg) {
|
|
81
|
-
this.code = msg.code;
|
|
82
|
-
this.message = msg.message;
|
|
83
|
-
this.action = msg.action;
|
|
84
|
-
this.req_id = msg.req_id;
|
|
85
|
-
this.timing = BigInt(msg.timing);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.WSConnResponse = WSConnResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsRows.d.ts","sourceRoot":"","sources":["../../../src/sql/wsRows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAwB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,qBAAa,MAAM;IACf,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAW;gBAEf,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe;IAOlD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;YAoBhB,YAAY;
|
|
1
|
+
{"version":3,"file":"wsRows.d.ts","sourceRoot":"","sources":["../../../src/sql/wsRows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAwB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,qBAAa,MAAM;IACf,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAW;gBAEf,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe;IAOlD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;YAoBhB,YAAY;IAiC1B,OAAO,IAAG,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI;IAIpC,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS;IAc3B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;CAQ9B"}
|
package/lib/src/sql/wsRows.js
CHANGED
|
@@ -20,7 +20,7 @@ class WSRows {
|
|
|
20
20
|
}
|
|
21
21
|
async next() {
|
|
22
22
|
if (this._wsQueryResponse.is_update || this._isClose) {
|
|
23
|
-
log_1.default.debug(
|
|
23
|
+
log_1.default.debug(`WSRows::Next::End=> ${this._taosResult}, ${this._isClose}`);
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
let data = this._taosResult.getData();
|
|
@@ -43,7 +43,8 @@ class WSRows {
|
|
|
43
43
|
this._taosResult.addTotalTime(resp.totalTime);
|
|
44
44
|
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
45
45
|
if (wsResponse.code != 0) {
|
|
46
|
-
|
|
46
|
+
await this.close();
|
|
47
|
+
log_1.default.error(`Executing SQL statement returns error: ${wsResponse.code}, ${wsResponse.message}`);
|
|
47
48
|
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
48
49
|
}
|
|
49
50
|
if (wsResponse.finished == 1) {
|
|
@@ -57,7 +58,12 @@ class WSRows {
|
|
|
57
58
|
return this._taosResult;
|
|
58
59
|
}
|
|
59
60
|
catch (err) {
|
|
60
|
-
|
|
61
|
+
try {
|
|
62
|
+
await this.close();
|
|
63
|
+
}
|
|
64
|
+
catch (closeErr) {
|
|
65
|
+
log_1.default.error(`GetBlockData encountered an exception while calling the close method, reason: ${closeErr.message}`);
|
|
66
|
+
}
|
|
61
67
|
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
62
68
|
}
|
|
63
69
|
}
|
|
@@ -81,7 +87,7 @@ class WSRows {
|
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
83
89
|
this._isClose = true;
|
|
84
|
-
this._wsClient.freeResult(this._wsQueryResponse);
|
|
90
|
+
await this._wsClient.freeResult(this._wsQueryResponse);
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
exports.WSRows = WSRows;
|
package/lib/src/sql/wsSql.js
CHANGED
|
@@ -115,7 +115,7 @@ class WsSql {
|
|
|
115
115
|
taosResult.addTotalTime(resp.totalTime);
|
|
116
116
|
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
117
117
|
if (wsResponse.code != 0) {
|
|
118
|
-
log_1.default.error(
|
|
118
|
+
log_1.default.error(`Executing SQL statement returns error: ${wsResponse.code}, ${wsResponse.message}`);
|
|
119
119
|
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
120
120
|
}
|
|
121
121
|
if (wsResponse.finished == 1) {
|
|
@@ -129,7 +129,7 @@ class WsSql {
|
|
|
129
129
|
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
130
130
|
}
|
|
131
131
|
finally {
|
|
132
|
-
this._wsClient.freeResult(wsQueryResponse);
|
|
132
|
+
await this._wsClient.freeResult(wsQueryResponse);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, "The result data of the query is incorrect");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/tmq/config.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAS;IAElB,GAAG,EAAE,GAAG,GAAG,IAAI,CAAQ;IACvB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAQ;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAClC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,WAAW,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/tmq/config.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAS;IAElB,GAAG,EAAE,GAAG,GAAG,IAAI,CAAQ;IACvB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAQ;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAClC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,WAAW,EAAE,OAAO,CAAQ;IAC5B,uBAAuB,EAAE,MAAM,CAAY;IAC3C,OAAO,EAAE,MAAM,CAAQ;IACvB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAGnB,QAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;CAyDxC"}
|
package/lib/src/tmq/config.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.tmq.test.d.ts","sourceRoot":"","sources":["../../../test/bulkPulling/cloud.tmq.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constant_1 = require("../../src/tmq/constant");
|
|
4
|
+
const wsTmq_1 = require("../../src/tmq/wsTmq");
|
|
5
|
+
const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
6
|
+
const log_1 = require("../../src/common/log");
|
|
7
|
+
const config_1 = require("../../src/common/config");
|
|
8
|
+
const wsSql_1 = require("../../src/sql/wsSql");
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
const url = `wss://${process.env.TDENGINE_CLOUD_URL}?token=${process.env.TDENGINE_CLOUD_TOKEN}`;
|
|
11
|
+
let wsSql = null;
|
|
12
|
+
try {
|
|
13
|
+
const conf = new config_1.WSConfig(url);
|
|
14
|
+
conf.setUser('root');
|
|
15
|
+
conf.setPwd('taosdata');
|
|
16
|
+
wsSql = await wsSql_1.WsSql.open(conf);
|
|
17
|
+
let sql = `INSERT INTO dmeters.d1001 USING dmeters.meters (groupid, location) TAGS(2, 'SanFrancisco')
|
|
18
|
+
VALUES (NOW + 1a, 10.30000, 219, 0.31000) (NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
|
|
19
|
+
dmeters.d1002 USING dmeters.meters (groupid, location) TAGS(3, 'SanFrancisco')
|
|
20
|
+
VALUES (NOW + 1a, 10.30000, 218, 0.25000)`;
|
|
21
|
+
let res = await wsSql.exec(sql);
|
|
22
|
+
console.log(res);
|
|
23
|
+
expect(res.getAffectRows()).toBeGreaterThanOrEqual(3);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
if (wsSql) {
|
|
30
|
+
await wsSql.close();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
describe('TDWebSocket.Tmq()', () => {
|
|
35
|
+
jest.setTimeout(20 * 1000);
|
|
36
|
+
test('normal connect', async () => {
|
|
37
|
+
const url = `wss://${process.env.TDENGINE_CLOUD_URL}?token=${process.env.TDENGINE_CLOUD_TOKEN}`;
|
|
38
|
+
// const TDENGINE_CLOUD_URL = 'wss://gw.cloud.taosdata.com?token=1eb78307be0681ac2fc07c2817ba8a9719641fb9';
|
|
39
|
+
const topic = 'topic_meters';
|
|
40
|
+
const topics = [topic];
|
|
41
|
+
const groupId = 'group1';
|
|
42
|
+
const clientId = 'client1';
|
|
43
|
+
let configMap = new Map([
|
|
44
|
+
[constant_1.TMQConstants.GROUP_ID, groupId],
|
|
45
|
+
[constant_1.TMQConstants.CLIENT_ID, clientId],
|
|
46
|
+
[constant_1.TMQConstants.AUTO_OFFSET_RESET, 'earliest'],
|
|
47
|
+
[constant_1.TMQConstants.WS_URL, url],
|
|
48
|
+
[constant_1.TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
|
|
49
|
+
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000'],
|
|
50
|
+
]);
|
|
51
|
+
(0, log_1.setLevel)("debug");
|
|
52
|
+
// create consumer
|
|
53
|
+
let consumer = await wsTmq_1.WsConsumer.newConsumer(configMap);
|
|
54
|
+
console.log(`Create consumer successfully, host: ${url}, groupId: ${groupId}, clientId: ${clientId}`);
|
|
55
|
+
// subscribe
|
|
56
|
+
await consumer.subscribe(topics);
|
|
57
|
+
console.log(`Subscribe topics successfully, topics: ${topics}`);
|
|
58
|
+
let res = new Map();
|
|
59
|
+
while (res.size == 0) {
|
|
60
|
+
// poll
|
|
61
|
+
res = await consumer.poll(1000);
|
|
62
|
+
for (let [key, value] of res) {
|
|
63
|
+
// Add your data processing logic here
|
|
64
|
+
console.log(`data: ${key} ${value}`);
|
|
65
|
+
}
|
|
66
|
+
// commit
|
|
67
|
+
await consumer.commit();
|
|
68
|
+
}
|
|
69
|
+
// seek
|
|
70
|
+
let assignment = await consumer.assignment();
|
|
71
|
+
await consumer.seekToBeginning(assignment);
|
|
72
|
+
console.log('Assignment seek to beginning successfully');
|
|
73
|
+
// clean
|
|
74
|
+
await consumer.unsubscribe();
|
|
75
|
+
await consumer.close();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
afterAll(async () => {
|
|
79
|
+
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
80
|
+
});
|
|
@@ -26,10 +26,12 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
26
26
|
jest.setTimeout(20 * 1000);
|
|
27
27
|
test('normal connect', async () => {
|
|
28
28
|
let wsSql = null;
|
|
29
|
-
let conf = new config_1.WSConfig(
|
|
29
|
+
let conf = new config_1.WSConfig('');
|
|
30
|
+
conf.setUrl(dns);
|
|
30
31
|
conf.setUser('root');
|
|
31
32
|
conf.setPwd('taosdata');
|
|
32
33
|
conf.setDb('power');
|
|
34
|
+
conf.setTimeOut(6000);
|
|
33
35
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
34
36
|
expect(wsSql.state()).toBeGreaterThan(0);
|
|
35
37
|
await wsSql.close();
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
|
|
4
4
|
const config_1 = require("../../src/common/config");
|
|
5
|
+
const log_1 = require("../../src/common/log");
|
|
5
6
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
7
|
let dns = 'ws://localhost:6041';
|
|
8
|
+
(0, log_1.setLevel)("debug");
|
|
7
9
|
beforeAll(async () => {
|
|
8
10
|
let conf = new config_1.WSConfig(dns);
|
|
9
11
|
conf.setUser('root');
|
|
@@ -80,7 +80,7 @@ async function tmqConnect() {
|
|
|
80
80
|
try {
|
|
81
81
|
consumer = await wsTmq_1.WsConsumer.newConsumer(configMap);
|
|
82
82
|
await consumer.subscribe(topics);
|
|
83
|
-
let res = await consumer.poll(
|
|
83
|
+
let res = await consumer.poll(100);
|
|
84
84
|
for (let [key, value] of res) {
|
|
85
85
|
console.log(key, value.getMeta());
|
|
86
86
|
let data = value.getData();
|
|
@@ -118,7 +118,7 @@ beforeAll(async () => {
|
|
|
118
118
|
await ws.close();
|
|
119
119
|
});
|
|
120
120
|
describe('TDWebSocket.WsSql()', () => {
|
|
121
|
-
jest.setTimeout(
|
|
121
|
+
jest.setTimeout(60 * 1000);
|
|
122
122
|
test('ReqId', async () => {
|
|
123
123
|
const allp = [];
|
|
124
124
|
for (let i = 0; i < 10; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdengine/websocket",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
|
|
5
5
|
"source": "index.ts",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"winston": "^3.17.0",
|
|
48
48
|
"winston-daily-rotate-file": "^5.0.0"
|
|
49
49
|
},
|
|
50
|
-
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@parcel/packager-ts": "^2.7.0",
|
|
53
52
|
"@parcel/transformer-typescript-types": "^2.7.0",
|
|
@@ -56,7 +55,7 @@
|
|
|
56
55
|
"@types/node": "^18.0.0",
|
|
57
56
|
"@types/uuid": "^9.0.8",
|
|
58
57
|
"@types/websocket": "^1.0",
|
|
59
|
-
"jest": "^29.
|
|
58
|
+
"jest": "^29.7.0",
|
|
60
59
|
"parcel": "^2.7.0",
|
|
61
60
|
"qingwa": "^1.0.7",
|
|
62
61
|
"ts-jest": "^29.0.3",
|