@tdengine/websocket 3.1.3 → 3.1.4
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/logs/.007e668bb78549e9a304b8466671945ab2a1553e-audit.json +15 -0
- package/lib/example/logs/app-2025-01-24.log +5580 -0
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
- package/lib/src/client/wsConnectorPool.js +2 -1
- package/lib/src/common/log.js +1 -2
- package/lib/src/common/taosResult.js +12 -12
- package/lib/src/common/ut8Helper.js +1 -2
- package/lib/src/common/utils.d.ts +0 -1
- package/lib/src/common/utils.d.ts.map +1 -1
- package/lib/src/common/utils.js +4 -9
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +17 -7
- package/lib/src/stmt/wsProto.js +2 -2
- package/lib/test/bulkPulling/log.test.js +17 -7
- package/lib/test/bulkPulling/queryTables.test.js +3 -0
- package/lib/test/bulkPulling/schemaless.test.js +6 -0
- package/lib/test/bulkPulling/sql.test.js +9 -1
- package/lib/test/bulkPulling/stmt.func.test.js +34 -28
- package/lib/test/bulkPulling/stmt.type.test.js +4 -0
- package/lib/test/bulkPulling/tmq.test.js +6 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +17 -5
- package/lib/test/utils.d.ts +1 -0
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/test/utils.js +17 -13
- package/package.json +1 -1
- package/readme.md +82 -270
|
@@ -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;AAKnD,qBAAa,uBAAuB;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAyB;IAClD,OAAO,CAAC,IAAI,CAAgD;IAC5D,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO;WAKO,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;
|
|
1
|
+
{"version":3,"file":"wsConnectorPool.d.ts","sourceRoot":"","sources":["../../../src/client/wsConnectorPool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAKnD,qBAAa,uBAAuB;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAyB;IAClD,OAAO,CAAC,IAAI,CAAgD;IAC5D,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO;WAKO,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;IA8BvF,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAE,OAAO,CAAC,IAAI,CAAC;IA0BpE,SAAS;CAYZ"}
|
|
@@ -23,6 +23,7 @@ class WebSocketConnectionPool {
|
|
|
23
23
|
}
|
|
24
24
|
async getConnection(url, timeout) {
|
|
25
25
|
let connectAddr = url.origin.concat(url.pathname).concat(url.search);
|
|
26
|
+
log_1.default.info("url:" + url);
|
|
26
27
|
let connector;
|
|
27
28
|
const unlock = await mutex.acquire();
|
|
28
29
|
try {
|
|
@@ -35,7 +36,7 @@ class WebSocketConnectionPool {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
if (connector) {
|
|
38
|
-
log_1.default.debug("get connection success:"
|
|
39
|
+
log_1.default.debug("get connection success:" + this._connectionCount);
|
|
39
40
|
return connector;
|
|
40
41
|
}
|
|
41
42
|
if (this._maxConnections != -1 && this._connectionCount > this._maxConnections) {
|
package/lib/src/common/log.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setLevel =
|
|
6
|
+
exports.setLevel = setLevel;
|
|
7
7
|
const winston_1 = __importDefault(require("winston"));
|
|
8
8
|
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
9
9
|
const customFormat = winston_1.default.format.printf(({ level, message, label, timestamp }) => {
|
|
@@ -30,5 +30,4 @@ const logger = winston_1.default.createLogger({
|
|
|
30
30
|
function setLevel(level) {
|
|
31
31
|
transport.level = level;
|
|
32
32
|
}
|
|
33
|
-
exports.setLevel = setLevel;
|
|
34
33
|
exports.default = logger;
|
|
@@ -3,7 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.TaosResult = void 0;
|
|
7
|
+
exports.parseBlock = parseBlock;
|
|
8
|
+
exports._isVarType = _isVarType;
|
|
9
|
+
exports.readSolidDataToArray = readSolidDataToArray;
|
|
10
|
+
exports.readSolidData = readSolidData;
|
|
11
|
+
exports.readBinary = readBinary;
|
|
12
|
+
exports.readVarchar = readVarchar;
|
|
13
|
+
exports.readNchar = readNchar;
|
|
14
|
+
exports.getString = getString;
|
|
15
|
+
exports.getCharOffset = getCharOffset;
|
|
16
|
+
exports.setBitmapNull = setBitmapNull;
|
|
17
|
+
exports.bitmapLen = bitmapLen;
|
|
7
18
|
const constant_1 = require("./constant");
|
|
8
19
|
const wsError_1 = require("./wsError");
|
|
9
20
|
const ut8Helper_1 = require("./ut8Helper");
|
|
@@ -199,7 +210,6 @@ function parseBlock(blocks, taosResult) {
|
|
|
199
210
|
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, "cannot fetch block for an update query.");
|
|
200
211
|
}
|
|
201
212
|
}
|
|
202
|
-
exports.parseBlock = parseBlock;
|
|
203
213
|
function _isVarType(metaType) {
|
|
204
214
|
switch (metaType) {
|
|
205
215
|
case constant_1.TDengineTypeCode.NCHAR: {
|
|
@@ -225,7 +235,6 @@ function _isVarType(metaType) {
|
|
|
225
235
|
}
|
|
226
236
|
}
|
|
227
237
|
}
|
|
228
|
-
exports._isVarType = _isVarType;
|
|
229
238
|
function readSolidDataToArray(dataBuffer, colBlockHead, rows, metaType, bitMapArr) {
|
|
230
239
|
let result = [];
|
|
231
240
|
switch (metaType) {
|
|
@@ -347,7 +356,6 @@ function readSolidDataToArray(dataBuffer, colBlockHead, rows, metaType, bitMapAr
|
|
|
347
356
|
}
|
|
348
357
|
return result;
|
|
349
358
|
}
|
|
350
|
-
exports.readSolidDataToArray = readSolidDataToArray;
|
|
351
359
|
function readSolidData(dataBuffer, colDataHead, meta) {
|
|
352
360
|
switch (meta.type) {
|
|
353
361
|
case constant_1.TDengineTypeCode.BOOL: {
|
|
@@ -392,18 +400,15 @@ function readSolidData(dataBuffer, colDataHead, meta) {
|
|
|
392
400
|
}
|
|
393
401
|
}
|
|
394
402
|
}
|
|
395
|
-
exports.readSolidData = readSolidData;
|
|
396
403
|
function readBinary(dataBuffer, colDataHead, length) {
|
|
397
404
|
let buff = dataBuffer.slice(colDataHead, colDataHead + length);
|
|
398
405
|
return buff;
|
|
399
406
|
}
|
|
400
|
-
exports.readBinary = readBinary;
|
|
401
407
|
function readVarchar(dataBuffer, colDataHead, length, textDecoder) {
|
|
402
408
|
// let buff = dataBuffer.slice(colDataHead, colDataHead + length)
|
|
403
409
|
let dataView = new DataView(dataBuffer, colDataHead, length);
|
|
404
410
|
return textDecoder.decode(dataView);
|
|
405
411
|
}
|
|
406
|
-
exports.readVarchar = readVarchar;
|
|
407
412
|
function readNchar(dataBuffer, colDataHead, length) {
|
|
408
413
|
let data = [];
|
|
409
414
|
// let buff: ArrayBuffer = dataBuffer.slice(colDataHead, colDataHead + length);
|
|
@@ -413,13 +418,11 @@ function readNchar(dataBuffer, colDataHead, length) {
|
|
|
413
418
|
}
|
|
414
419
|
return data.join('');
|
|
415
420
|
}
|
|
416
|
-
exports.readNchar = readNchar;
|
|
417
421
|
function getString(dataBuffer, colDataHead, length, textDecoder) {
|
|
418
422
|
// let buff = dataBuffer.slice(colDataHead, colDataHead + length - 1)
|
|
419
423
|
let dataView = new Uint8Array(dataBuffer.buffer, dataBuffer.byteOffset + colDataHead, length - 1);
|
|
420
424
|
return textDecoder.decode(dataView);
|
|
421
425
|
}
|
|
422
|
-
exports.getString = getString;
|
|
423
426
|
function iteratorBuff(arr) {
|
|
424
427
|
let buf = Buffer.from(arr);
|
|
425
428
|
for (const value of buf) {
|
|
@@ -435,15 +438,12 @@ function isNull(bitMapArr, n) {
|
|
|
435
438
|
function getCharOffset(n) {
|
|
436
439
|
return n >> 3;
|
|
437
440
|
}
|
|
438
|
-
exports.getCharOffset = getCharOffset;
|
|
439
441
|
function setBitmapNull(c, n) {
|
|
440
442
|
return c + (1 << (7 - bitPos(n)));
|
|
441
443
|
}
|
|
442
|
-
exports.setBitmapNull = setBitmapNull;
|
|
443
444
|
function bitPos(n) {
|
|
444
445
|
return n & ((1 << 3) - 1);
|
|
445
446
|
}
|
|
446
447
|
function bitmapLen(n) {
|
|
447
448
|
return ((n) + ((1 << 3) - 1)) >> 3;
|
|
448
449
|
}
|
|
449
|
-
exports.bitmapLen = bitmapLen;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appendRune =
|
|
3
|
+
exports.appendRune = appendRune;
|
|
4
4
|
// Numbers fundamental to the encoding.
|
|
5
5
|
// the "error" Rune or "Unicode replacement character"
|
|
6
6
|
const RuneError = '\uFFFD';
|
|
@@ -40,4 +40,3 @@ function appendRune(r) {
|
|
|
40
40
|
}
|
|
41
41
|
return Buffer.from(p).toString();
|
|
42
42
|
}
|
|
43
|
-
exports.appendRune = appendRune;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WSConfig } from "./config";
|
|
2
2
|
export declare function getUrl(wsConfig: WSConfig): URL;
|
|
3
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
4
3
|
export declare function isEmpty(value: any): boolean;
|
|
5
4
|
export declare function getBinarySql(action: bigint, reqId: bigint, resultId: bigint, sql?: string): ArrayBuffer;
|
|
6
5
|
export declare function zigzagDecode(n: number): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,MAAM,CAAC,QAAQ,EAAC,QAAQ,GAAE,GAAG,CAe5C;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,wBAAgB,MAAM,CAAC,QAAQ,EAAC,QAAQ,GAAE,GAAG,CAe5C;AAGD,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAM3C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EAAC,MAAM,GAAG,WAAW,CA6BnG;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/lib/src/common/utils.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getUrl = getUrl;
|
|
4
|
+
exports.isEmpty = isEmpty;
|
|
5
|
+
exports.getBinarySql = getBinarySql;
|
|
6
|
+
exports.zigzagDecode = zigzagDecode;
|
|
4
7
|
function getUrl(wsConfig) {
|
|
5
8
|
let url = new URL(wsConfig.getUrl());
|
|
6
9
|
if (wsConfig.getUser()) {
|
|
@@ -16,11 +19,6 @@ function getUrl(wsConfig) {
|
|
|
16
19
|
url.pathname = '/ws';
|
|
17
20
|
return url;
|
|
18
21
|
}
|
|
19
|
-
exports.getUrl = getUrl;
|
|
20
|
-
function sleep(ms) {
|
|
21
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
22
|
-
}
|
|
23
|
-
exports.sleep = sleep;
|
|
24
22
|
function isEmpty(value) {
|
|
25
23
|
if (value === null || value === undefined)
|
|
26
24
|
return true;
|
|
@@ -30,7 +28,6 @@ function isEmpty(value) {
|
|
|
30
28
|
// if (typeof value === 'object' && Object.keys(value).length === 0) return true;
|
|
31
29
|
return false;
|
|
32
30
|
}
|
|
33
|
-
exports.isEmpty = isEmpty;
|
|
34
31
|
function getBinarySql(action, reqId, resultId, sql) {
|
|
35
32
|
// construct msg
|
|
36
33
|
if (sql) {
|
|
@@ -59,8 +56,6 @@ function getBinarySql(action, reqId, resultId, sql) {
|
|
|
59
56
|
sqlView.setInt16(24, 1, true);
|
|
60
57
|
return sqlBuffer;
|
|
61
58
|
}
|
|
62
|
-
exports.getBinarySql = getBinarySql;
|
|
63
59
|
function zigzagDecode(n) {
|
|
64
60
|
return (n >> 1) ^ (-(n & 1));
|
|
65
61
|
}
|
|
66
|
-
exports.zigzagDecode = zigzagDecode;
|
package/lib/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,QAAA,IAAI,UAAU,SAAgB,QAAQ,mBAQrC,CAAC;AAEF,QAAA,IAAI,UAAU,cAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,QAAA,IAAI,UAAU,SAAgB,QAAQ,mBAQrC,CAAC;AAEF,QAAA,IAAI,UAAU,cAAqB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,wBAOrD,CAAC;AAEF,QAAA,IAAI,WAAW,UAAW,MAAM,SAE/B,CAAC;AAEF,QAAA,IAAI,OAAO,YAEV,CAAC;AACF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC"}
|
package/lib/src/index.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.destroy = exports.setLogLevel = exports.tmqConnect = exports.sqlConnect = void 0;
|
|
27
37
|
const wsSql_1 = require("./sql/wsSql");
|
package/lib/src/stmt/wsProto.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WsStmtQueryResponse = void 0;
|
|
4
|
+
exports.binaryBlockEncode = binaryBlockEncode;
|
|
4
5
|
const wsResponse_1 = require("../client/wsResponse");
|
|
5
6
|
const constant_1 = require("../common/constant");
|
|
6
7
|
class WsStmtQueryResponse extends wsResponse_1.WSQueryResponse {
|
|
@@ -64,4 +65,3 @@ function binaryBlockEncode(bindParams, bindType, stmtId, reqId, row) {
|
|
|
64
65
|
}
|
|
65
66
|
return arrayBuffer;
|
|
66
67
|
}
|
|
67
|
-
exports.binaryBlockEncode = binaryBlockEncode;
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
const log_1 = __importStar(require("../../src/common/log"));
|
|
27
37
|
describe('log level print', () => {
|
|
@@ -292,6 +292,9 @@ describe('ws.query(jsonTable)', () => {
|
|
|
292
292
|
});
|
|
293
293
|
});
|
|
294
294
|
afterAll(async () => {
|
|
295
|
+
let ws = await wsSql_1.WsSql.open(conf);
|
|
296
|
+
await ws.exec(dropDB);
|
|
297
|
+
await ws.close();
|
|
295
298
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
296
299
|
});
|
|
297
300
|
//--detectOpenHandles --maxConcurrency=1 --forceExit
|
|
@@ -91,5 +91,11 @@ describe('TDWebSocket.WsSchemaless()', () => {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
afterAll(async () => {
|
|
94
|
+
let conf = new config_1.WSConfig(dns);
|
|
95
|
+
conf.setUser('root');
|
|
96
|
+
conf.setPwd('taosdata');
|
|
97
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
98
|
+
await wsSql.exec('drop database if exists power_schemaless;');
|
|
99
|
+
await wsSql.close();
|
|
94
100
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
95
101
|
});
|
|
@@ -3,6 +3,7 @@ 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
5
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
6
7
|
let dns = 'ws://localhost:6041';
|
|
7
8
|
beforeAll(async () => {
|
|
8
9
|
let conf = new config_1.WSConfig(dns);
|
|
@@ -10,8 +11,9 @@ beforeAll(async () => {
|
|
|
10
11
|
conf.setPwd('taosdata');
|
|
11
12
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
12
13
|
await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
14
|
+
await (0, utils_1.Sleep)(100);
|
|
13
15
|
await wsSql.exec('use power');
|
|
14
|
-
await wsSql.exec('CREATE STABLE if not exists
|
|
16
|
+
await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
15
17
|
await wsSql.close();
|
|
16
18
|
});
|
|
17
19
|
describe('TDWebSocket.WsSql()', () => {
|
|
@@ -140,5 +142,11 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
140
142
|
});
|
|
141
143
|
});
|
|
142
144
|
afterAll(async () => {
|
|
145
|
+
let conf = new config_1.WSConfig(dns);
|
|
146
|
+
conf.setUser('root');
|
|
147
|
+
conf.setPwd('taosdata');
|
|
148
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
149
|
+
await wsSql.exec('drop database power');
|
|
150
|
+
await wsSql.close();
|
|
143
151
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
144
152
|
});
|
|
@@ -9,8 +9,8 @@ beforeAll(async () => {
|
|
|
9
9
|
conf.setUser('root');
|
|
10
10
|
conf.setPwd('taosdata');
|
|
11
11
|
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
12
|
-
await wsSql.exec('create database if not exists
|
|
13
|
-
await wsSql.exec('CREATE STABLE if not exists
|
|
12
|
+
await wsSql.exec('create database if not exists power_stmt KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
|
|
13
|
+
await wsSql.exec('CREATE STABLE if not exists power_stmt.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
|
|
14
14
|
await wsSql.close();
|
|
15
15
|
});
|
|
16
16
|
describe('TDWebSocket.Stmt()', () => {
|
|
@@ -30,7 +30,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
30
30
|
let conf = new config_1.WSConfig(dns);
|
|
31
31
|
conf.setUser('root');
|
|
32
32
|
conf.setPwd('taosdata');
|
|
33
|
-
conf.setDb('
|
|
33
|
+
conf.setDb('power_stmt');
|
|
34
34
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
35
35
|
let stmt = await connector.stmtInit();
|
|
36
36
|
expect(stmt).toBeTruthy();
|
|
@@ -64,12 +64,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
64
64
|
let conf = new config_1.WSConfig(dns);
|
|
65
65
|
conf.setUser('root');
|
|
66
66
|
conf.setPwd('taosdata');
|
|
67
|
-
conf.setDb('
|
|
67
|
+
conf.setDb('power_stmt');
|
|
68
68
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
69
69
|
let stmt = await connector.stmtInit();
|
|
70
70
|
expect(stmt).toBeTruthy();
|
|
71
71
|
expect(connector.state()).toBeGreaterThan(0);
|
|
72
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
72
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
73
73
|
await stmt.setTableName('d1001');
|
|
74
74
|
let params = stmt.newStmtParam();
|
|
75
75
|
params.setVarchar([tags[0]]);
|
|
@@ -82,12 +82,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
82
82
|
let conf = new config_1.WSConfig(dns);
|
|
83
83
|
conf.setUser('root');
|
|
84
84
|
conf.setPwd('taosdata');
|
|
85
|
-
conf.setDb('
|
|
85
|
+
conf.setDb('power_stmt');
|
|
86
86
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
87
87
|
let stmt = await connector.stmtInit();
|
|
88
88
|
expect(stmt).toBeTruthy();
|
|
89
89
|
expect(connector.state()).toBeGreaterThan(0);
|
|
90
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
90
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
91
91
|
await stmt.setTableName('d1001');
|
|
92
92
|
let params = stmt.newStmtParam();
|
|
93
93
|
params.setVarchar([tags[0]]);
|
|
@@ -104,18 +104,18 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
104
104
|
let conf = new config_1.WSConfig(dns);
|
|
105
105
|
conf.setUser('root');
|
|
106
106
|
conf.setPwd('taosdata');
|
|
107
|
-
conf.setDb('
|
|
107
|
+
conf.setDb('power_stmt');
|
|
108
108
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
109
109
|
let stmt = await connector.stmtInit();
|
|
110
110
|
expect(stmt).toBeTruthy();
|
|
111
111
|
expect(connector.state()).toBeGreaterThan(0);
|
|
112
112
|
try {
|
|
113
|
-
await stmt.prepare('INSERT ? INTO ? USING
|
|
113
|
+
await stmt.prepare('INSERT ? INTO ? USING meters TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
114
114
|
await stmt.setTableName('d1001');
|
|
115
115
|
}
|
|
116
116
|
catch (e) {
|
|
117
117
|
let err = e;
|
|
118
|
-
expect(err.message).toMatch("syntax error near '? into ? using
|
|
118
|
+
expect(err.message).toMatch("syntax error near '? into ? using meters tags (?, ?) values (?, ?, ?, ?)' (keyword INTO is expected)");
|
|
119
119
|
}
|
|
120
120
|
await stmt.close();
|
|
121
121
|
await connector.close();
|
|
@@ -124,18 +124,18 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
124
124
|
let conf = new config_1.WSConfig(dns);
|
|
125
125
|
conf.setUser('root');
|
|
126
126
|
conf.setPwd('taosdata');
|
|
127
|
-
conf.setDb('
|
|
127
|
+
conf.setDb('power_stmt');
|
|
128
128
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
129
129
|
let stmt = await connector.stmtInit();
|
|
130
130
|
expect(stmt).toBeTruthy();
|
|
131
131
|
expect(connector.state()).toBeGreaterThan(0);
|
|
132
132
|
try {
|
|
133
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
133
|
+
await stmt.prepare('INSERT INTO ? USING meters TAGS (?, ?, ?) VALUES (?, ?, ?, ?)');
|
|
134
134
|
await stmt.setTableName('d1001');
|
|
135
135
|
}
|
|
136
136
|
catch (e) {
|
|
137
137
|
let err = e;
|
|
138
|
-
expect(err.message).toMatch("
|
|
138
|
+
expect(err.message).toMatch("Tags number not matched");
|
|
139
139
|
}
|
|
140
140
|
await stmt.close();
|
|
141
141
|
await connector.close();
|
|
@@ -144,11 +144,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
144
144
|
let conf = new config_1.WSConfig(dns);
|
|
145
145
|
conf.setUser('root');
|
|
146
146
|
conf.setPwd('taosdata');
|
|
147
|
-
conf.setDb('
|
|
147
|
+
conf.setDb('power_stmt');
|
|
148
148
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
149
149
|
let stmt = await connector.stmtInit();
|
|
150
150
|
expect(stmt).toBeTruthy();
|
|
151
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
151
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
152
152
|
await stmt.setTableName('d1001');
|
|
153
153
|
let params = stmt.newStmtParam();
|
|
154
154
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -180,12 +180,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
180
180
|
let conf = new config_1.WSConfig(dns);
|
|
181
181
|
conf.setUser('root');
|
|
182
182
|
conf.setPwd('taosdata');
|
|
183
|
-
conf.setDb('
|
|
183
|
+
conf.setDb('power_stmt');
|
|
184
184
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
185
185
|
let stmt = await connector.stmtInit();
|
|
186
186
|
expect(stmt).toBeTruthy();
|
|
187
187
|
expect(connector.state()).toBeGreaterThan(0);
|
|
188
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
188
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
189
189
|
await stmt.setTableName('d1001');
|
|
190
190
|
let params = stmt.newStmtParam();
|
|
191
191
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -218,12 +218,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
218
218
|
let conf = new config_1.WSConfig(dns);
|
|
219
219
|
conf.setUser('root');
|
|
220
220
|
conf.setPwd('taosdata');
|
|
221
|
-
conf.setDb('
|
|
221
|
+
conf.setDb('power_stmt');
|
|
222
222
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
223
223
|
let stmt = await connector.stmtInit();
|
|
224
224
|
expect(stmt).toBeTruthy();
|
|
225
225
|
expect(connector.state()).toBeGreaterThan(0);
|
|
226
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
226
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
227
227
|
await stmt.setTableName('d1001');
|
|
228
228
|
let params = stmt.newStmtParam();
|
|
229
229
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -255,12 +255,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
255
255
|
let conf = new config_1.WSConfig(dns);
|
|
256
256
|
conf.setUser('root');
|
|
257
257
|
conf.setPwd('taosdata');
|
|
258
|
-
conf.setDb('
|
|
258
|
+
conf.setDb('power_stmt');
|
|
259
259
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
260
260
|
let stmt = await connector.stmtInit();
|
|
261
261
|
expect(stmt).toBeTruthy();
|
|
262
262
|
expect(connector.state()).toBeGreaterThan(0);
|
|
263
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
263
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
264
264
|
await stmt.setTableName('d1001');
|
|
265
265
|
let params = stmt.newStmtParam();
|
|
266
266
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -306,12 +306,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
306
306
|
let conf = new config_1.WSConfig(dns);
|
|
307
307
|
conf.setUser('root');
|
|
308
308
|
conf.setPwd('taosdata');
|
|
309
|
-
conf.setDb('
|
|
309
|
+
conf.setDb('power_stmt');
|
|
310
310
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
311
311
|
let stmt = await connector.stmtInit();
|
|
312
312
|
expect(stmt).toBeTruthy();
|
|
313
313
|
expect(connector.state()).toBeGreaterThan(0);
|
|
314
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
314
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
315
315
|
await stmt.setTableName('d1001');
|
|
316
316
|
// await stmt.SetTags(tags)
|
|
317
317
|
try {
|
|
@@ -335,12 +335,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
335
335
|
let conf = new config_1.WSConfig(dns);
|
|
336
336
|
conf.setUser('root');
|
|
337
337
|
conf.setPwd('taosdata');
|
|
338
|
-
conf.setDb('
|
|
338
|
+
conf.setDb('power_stmt');
|
|
339
339
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
340
340
|
let stmt = await connector.stmtInit();
|
|
341
341
|
expect(stmt).toBeTruthy();
|
|
342
342
|
expect(connector.state()).toBeGreaterThan(0);
|
|
343
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
343
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
344
344
|
await stmt.setTableName('d1002');
|
|
345
345
|
let params = stmt.newStmtParam();
|
|
346
346
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -354,7 +354,7 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
354
354
|
await stmt.bind(dataParams);
|
|
355
355
|
await stmt.batch();
|
|
356
356
|
await stmt.exec();
|
|
357
|
-
let result = await connector.exec("select * from
|
|
357
|
+
let result = await connector.exec("select * from power_stmt.meters");
|
|
358
358
|
console.log(result);
|
|
359
359
|
await stmt.close();
|
|
360
360
|
await connector.close();
|
|
@@ -363,12 +363,12 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
363
363
|
let conf = new config_1.WSConfig(dns);
|
|
364
364
|
conf.setUser('root');
|
|
365
365
|
conf.setPwd('taosdata');
|
|
366
|
-
conf.setDb('
|
|
366
|
+
conf.setDb('power_stmt');
|
|
367
367
|
let connector = await wsSql_1.WsSql.open(conf);
|
|
368
368
|
let stmt = await connector.stmtInit();
|
|
369
369
|
expect(stmt).toBeTruthy();
|
|
370
370
|
expect(connector.state()).toBeGreaterThan(0);
|
|
371
|
-
await stmt.prepare('INSERT INTO ? USING
|
|
371
|
+
await stmt.prepare('INSERT INTO ? USING meters (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)');
|
|
372
372
|
await stmt.setTableName('d1001');
|
|
373
373
|
let params = stmt.newStmtParam();
|
|
374
374
|
params.setVarchar(['SanFrancisco']);
|
|
@@ -393,5 +393,11 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
393
393
|
});
|
|
394
394
|
});
|
|
395
395
|
afterAll(async () => {
|
|
396
|
+
let conf = new config_1.WSConfig(dns);
|
|
397
|
+
conf.setUser('root');
|
|
398
|
+
conf.setPwd('taosdata');
|
|
399
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
400
|
+
await wsSql.exec('drop database power_stmt');
|
|
401
|
+
await wsSql.close();
|
|
396
402
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
397
403
|
});
|
|
@@ -265,5 +265,9 @@ describe('TDWebSocket.Stmt()', () => {
|
|
|
265
265
|
});
|
|
266
266
|
});
|
|
267
267
|
afterAll(async () => {
|
|
268
|
+
let conf = new config_1.WSConfig(dsn);
|
|
269
|
+
let ws = await wsSql_1.WsSql.open(conf);
|
|
270
|
+
await ws.exec(dropDB);
|
|
271
|
+
await ws.close();
|
|
268
272
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
269
273
|
});
|
|
@@ -180,5 +180,11 @@ describe('TDWebSocket.Tmq()', () => {
|
|
|
180
180
|
});
|
|
181
181
|
});
|
|
182
182
|
afterAll(async () => {
|
|
183
|
+
const dropDB = `drop database if exists ${db}`;
|
|
184
|
+
let conf = new config_1.WSConfig(dsn);
|
|
185
|
+
let ws = await wsSql_1.WsSql.open(conf);
|
|
186
|
+
await ws.exec(dropTopic);
|
|
187
|
+
await ws.exec(dropDB);
|
|
188
|
+
await ws.close();
|
|
183
189
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
184
190
|
});
|
|
@@ -6,6 +6,7 @@ const reqid_1 = require("../../src/common/reqid");
|
|
|
6
6
|
const wsSql_1 = require("../../src/sql/wsSql");
|
|
7
7
|
const constant_1 = require("../../src/tmq/constant");
|
|
8
8
|
const wsTmq_1 = require("../../src/tmq/wsTmq");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
9
10
|
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
10
11
|
let tags = ['California.SanFrancisco', 3];
|
|
11
12
|
let multi = [
|
|
@@ -25,7 +26,7 @@ let configMap = new Map([
|
|
|
25
26
|
[constant_1.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000']
|
|
26
27
|
]);
|
|
27
28
|
const stable = 'meters';
|
|
28
|
-
const db = '
|
|
29
|
+
const db = 'power_connect';
|
|
29
30
|
const topics = ['pwer_meters_topic'];
|
|
30
31
|
let createTopic = `create topic if not exists ${topics[0]} as select * from ${db}.${stable}`;
|
|
31
32
|
let stmtIds = [];
|
|
@@ -33,7 +34,7 @@ async function connect() {
|
|
|
33
34
|
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
34
35
|
let wsSql = null;
|
|
35
36
|
let conf = new config_1.WSConfig(dsn);
|
|
36
|
-
conf.setDb(
|
|
37
|
+
conf.setDb(db);
|
|
37
38
|
wsSql = await wsSql_1.WsSql.open(conf);
|
|
38
39
|
expect(wsSql.state()).toBeGreaterThan(0);
|
|
39
40
|
console.log(await wsSql.version());
|
|
@@ -42,7 +43,7 @@ async function connect() {
|
|
|
42
43
|
async function stmtConnect() {
|
|
43
44
|
let dsn = 'ws://root:taosdata@localhost:6041';
|
|
44
45
|
let wsConf = new config_1.WSConfig(dsn);
|
|
45
|
-
wsConf.setDb(
|
|
46
|
+
wsConf.setDb(db);
|
|
46
47
|
// let connector = WsStmtConnect.NewConnector(wsConf)
|
|
47
48
|
// let stmt = await connector.Init()
|
|
48
49
|
let connector = await wsSql_1.WsSql.open(wsConf);
|
|
@@ -52,7 +53,7 @@ async function stmtConnect() {
|
|
|
52
53
|
stmtIds.push(id);
|
|
53
54
|
}
|
|
54
55
|
expect(stmt).toBeTruthy();
|
|
55
|
-
await stmt.prepare(
|
|
56
|
+
await stmt.prepare(`INSERT INTO ? USING ${stable} (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)`);
|
|
56
57
|
await stmt.setTableName('d1001');
|
|
57
58
|
await stmt.setJsonTags(tags);
|
|
58
59
|
let lastTs = 0;
|
|
@@ -107,6 +108,10 @@ async function tmqConnect() {
|
|
|
107
108
|
beforeAll(async () => {
|
|
108
109
|
let conf = new config_1.WSConfig(dsn);
|
|
109
110
|
let ws = await wsSql_1.WsSql.open(conf);
|
|
111
|
+
await ws.exec(`create database if not exists ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`);
|
|
112
|
+
await (0, utils_1.Sleep)(100);
|
|
113
|
+
await ws.exec(`CREATE STABLE if not exists ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`);
|
|
114
|
+
await (0, utils_1.Sleep)(100);
|
|
110
115
|
await ws.exec(createTopic, reqid_1.ReqId.getReqID());
|
|
111
116
|
await ws.close();
|
|
112
117
|
});
|
|
@@ -119,7 +124,7 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
119
124
|
}
|
|
120
125
|
await Promise.all(allp);
|
|
121
126
|
});
|
|
122
|
-
test
|
|
127
|
+
test('normal connect', async () => {
|
|
123
128
|
const allp = [];
|
|
124
129
|
for (let i = 0; i < 20; i++) {
|
|
125
130
|
allp.push(connect());
|
|
@@ -132,5 +137,12 @@ describe('TDWebSocket.WsSql()', () => {
|
|
|
132
137
|
});
|
|
133
138
|
});
|
|
134
139
|
afterAll(async () => {
|
|
140
|
+
let conf = new config_1.WSConfig(dsn);
|
|
141
|
+
conf.setUser('root');
|
|
142
|
+
conf.setPwd('taosdata');
|
|
143
|
+
let wsSql = await wsSql_1.WsSql.open(conf);
|
|
144
|
+
await wsSql.exec(`drop topic if exists ${topics[0]};`);
|
|
145
|
+
await wsSql.exec(`drop database if exists ${db};`);
|
|
146
|
+
await wsSql.close();
|
|
135
147
|
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
136
148
|
});
|