@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.
Files changed (144) hide show
  1. package/lib/example/basicSchemaless.d.ts +2 -0
  2. package/lib/example/basicSchemaless.d.ts.map +1 -0
  3. package/lib/example/basicSchemaless.js +47 -0
  4. package/lib/example/basicSql.d.ts +2 -0
  5. package/lib/example/basicSql.d.ts.map +1 -0
  6. package/lib/example/basicSql.js +52 -0
  7. package/lib/example/basicStmt.d.ts +2 -0
  8. package/lib/example/basicStmt.d.ts.map +1 -0
  9. package/lib/example/basicStmt.js +58 -0
  10. package/lib/example/basicTmq.d.ts +2 -0
  11. package/lib/example/basicTmq.d.ts.map +1 -0
  12. package/lib/example/basicTmq.js +71 -0
  13. package/lib/index.d.ts +26 -0
  14. package/lib/index.d.ts.map +1 -0
  15. package/lib/index.js +41 -0
  16. package/lib/src/client/wsClient.d.ts +22 -0
  17. package/lib/src/client/wsClient.d.ts.map +1 -0
  18. package/lib/src/client/wsClient.js +253 -0
  19. package/lib/src/client/wsConnector.d.ts +17 -0
  20. package/lib/src/client/wsConnector.d.ts.map +1 -0
  21. package/lib/src/client/wsConnector.js +140 -0
  22. package/lib/src/client/wsConnectorPool.d.ts +13 -0
  23. package/lib/src/client/wsConnectorPool.d.ts.map +1 -0
  24. package/lib/src/client/wsConnectorPool.js +107 -0
  25. package/lib/src/client/wsEventCallback.d.ts +22 -0
  26. package/lib/src/client/wsEventCallback.d.ts.map +1 -0
  27. package/lib/src/client/wsEventCallback.js +97 -0
  28. package/lib/src/client/wsResponse.d.ts +66 -0
  29. package/lib/src/client/wsResponse.d.ts.map +1 -0
  30. package/lib/src/client/wsResponse.js +76 -0
  31. package/lib/src/common/config.d.ts +22 -0
  32. package/lib/src/common/config.d.ts.map +1 -0
  33. package/lib/src/common/config.js +45 -0
  34. package/lib/src/common/constant.d.ts +13 -0
  35. package/lib/src/common/constant.d.ts.map +1 -0
  36. package/{src/constant.ts → lib/src/common/constant.js} +25 -24
  37. package/lib/src/common/log.d.ts +5 -0
  38. package/lib/src/common/log.d.ts.map +1 -0
  39. package/lib/src/common/log.js +40 -0
  40. package/lib/src/common/reqid.d.ts +8 -0
  41. package/lib/src/common/reqid.d.ts.map +1 -0
  42. package/lib/src/common/reqid.js +59 -0
  43. package/lib/src/common/taosResult.d.ts +51 -0
  44. package/lib/src/common/taosResult.d.ts.map +1 -0
  45. package/lib/src/common/taosResult.js +419 -0
  46. package/lib/src/common/ut8Helper.d.ts +2 -0
  47. package/lib/src/common/ut8Helper.d.ts.map +1 -0
  48. package/{src/ut8Helper.ts → lib/src/common/ut8Helper.js} +22 -21
  49. package/lib/src/common/utils.d.ts +5 -0
  50. package/lib/src/common/utils.d.ts.map +1 -0
  51. package/lib/src/common/utils.js +33 -0
  52. package/lib/src/common/wsError.d.ts +29 -0
  53. package/lib/src/common/wsError.d.ts.map +1 -0
  54. package/lib/src/common/wsError.js +51 -0
  55. package/{src/wsOptions.ts → lib/src/common/wsOptions.d.ts} +4 -2
  56. package/lib/src/common/wsOptions.d.ts.map +1 -0
  57. package/lib/src/common/wsOptions.js +2 -0
  58. package/lib/src/index.d.ts +9 -0
  59. package/lib/src/index.d.ts.map +1 -0
  60. package/lib/src/index.js +58 -0
  61. package/lib/src/sql/wsProto.d.ts +26 -0
  62. package/lib/src/sql/wsProto.d.ts.map +1 -0
  63. package/lib/src/sql/wsProto.js +19 -0
  64. package/lib/src/sql/wsRows.d.ts +16 -0
  65. package/lib/src/sql/wsRows.d.ts.map +1 -0
  66. package/lib/src/sql/wsRows.js +76 -0
  67. package/lib/src/sql/wsSql.d.ts +24 -0
  68. package/lib/src/sql/wsSql.d.ts.map +1 -0
  69. package/lib/src/sql/wsSql.js +164 -0
  70. package/lib/src/stmt/wsParams.d.ts +41 -0
  71. package/lib/src/stmt/wsParams.d.ts.map +1 -0
  72. package/lib/src/stmt/wsParams.js +428 -0
  73. package/lib/src/stmt/wsProto.d.ts +27 -0
  74. package/lib/src/stmt/wsProto.d.ts.map +1 -0
  75. package/lib/src/stmt/wsProto.js +67 -0
  76. package/lib/src/stmt/wsStmt.d.ts +30 -0
  77. package/lib/src/stmt/wsStmt.d.ts.map +1 -0
  78. package/lib/src/stmt/wsStmt.js +207 -0
  79. package/lib/src/tmq/config.d.ts +14 -0
  80. package/lib/src/tmq/config.d.ts.map +1 -0
  81. package/lib/src/tmq/config.js +42 -0
  82. package/lib/src/tmq/constant.d.ts +85 -0
  83. package/lib/src/tmq/constant.d.ts.map +1 -0
  84. package/lib/src/tmq/constant.js +89 -0
  85. package/lib/src/tmq/tmqResponse.d.ts +80 -0
  86. package/lib/src/tmq/tmqResponse.d.ts.map +1 -0
  87. package/lib/src/tmq/tmqResponse.js +204 -0
  88. package/lib/src/tmq/wsTmq.d.ts +32 -0
  89. package/lib/src/tmq/wsTmq.d.ts.map +1 -0
  90. package/lib/src/tmq/wsTmq.js +316 -0
  91. package/lib/test/bulkPulling/queryTables.test.d.ts +2 -0
  92. package/lib/test/bulkPulling/queryTables.test.d.ts.map +1 -0
  93. package/lib/test/bulkPulling/queryTables.test.js +297 -0
  94. package/lib/test/bulkPulling/schemaless.test.d.ts +2 -0
  95. package/lib/test/bulkPulling/schemaless.test.d.ts.map +1 -0
  96. package/lib/test/bulkPulling/schemaless.test.js +94 -0
  97. package/lib/test/bulkPulling/sql.test.d.ts +2 -0
  98. package/lib/test/bulkPulling/sql.test.d.ts.map +1 -0
  99. package/lib/test/bulkPulling/sql.test.js +124 -0
  100. package/lib/test/bulkPulling/stmt.func.test.d.ts +2 -0
  101. package/lib/test/bulkPulling/stmt.func.test.d.ts.map +1 -0
  102. package/lib/test/bulkPulling/stmt.func.test.js +381 -0
  103. package/lib/test/bulkPulling/stmt.type.test.d.ts +2 -0
  104. package/lib/test/bulkPulling/stmt.type.test.d.ts.map +1 -0
  105. package/lib/test/bulkPulling/stmt.type.test.js +273 -0
  106. package/lib/test/bulkPulling/tmq.test.d.ts +2 -0
  107. package/lib/test/bulkPulling/tmq.test.d.ts.map +1 -0
  108. package/lib/test/bulkPulling/tmq.test.js +177 -0
  109. package/lib/test/bulkPulling/wsConnectPool.test.d.ts +2 -0
  110. package/lib/test/bulkPulling/wsConnectPool.test.d.ts.map +1 -0
  111. package/lib/test/bulkPulling/wsConnectPool.test.js +129 -0
  112. package/lib/test/utils.d.ts +18 -0
  113. package/lib/test/utils.d.ts.map +1 -0
  114. package/lib/test/utils.js +318 -0
  115. package/package.json +27 -14
  116. package/readme.md +302 -0
  117. package/README.md +0 -59
  118. package/dist/browser/index.js +0 -778
  119. package/dist/main/index.js +0 -711
  120. package/dist/main/index.js.map +0 -1
  121. package/dist/module/index.mjs +0 -704
  122. package/dist/module/index.mjs.map +0 -1
  123. package/dist/types.d.ts +0 -103
  124. package/dist/types.d.ts.map +0 -1
  125. package/example/basicUsageAsync.ts +0 -48
  126. package/example/basicUsagePrimse.ts +0 -43
  127. package/example/cloudUsage.ts +0 -55
  128. package/example/continousConnectAndVersion.ts +0 -16
  129. package/example/test.mjs +0 -51
  130. package/index.ts +0 -7
  131. package/jest.config.js +0 -8
  132. package/src/taosResult.ts +0 -269
  133. package/src/tdengineWebsocket.ts +0 -39
  134. package/src/wsClient.ts +0 -196
  135. package/src/wsError.ts +0 -5
  136. package/src/wsQuery.ts +0 -30
  137. package/src/wsQueryInterface.ts +0 -212
  138. package/src/wsQueryResponse.ts +0 -112
  139. package/tdengine-websocket-3.0.0.tgz +0 -0
  140. package/test/bulkPulling/connect.test.ts +0 -27
  141. package/test/bulkPulling/queryTables.test.ts +0 -274
  142. package/test/bulkPulling/version.test.ts +0 -19
  143. package/test/utils.ts +0 -235
  144. package/tsconfig.json +0 -101
@@ -1,12 +1,7 @@
1
- interface IndexableString {
2
- [index: number]: string
3
- }
4
-
5
- interface StringIndexable {
6
- [index: string]: number
7
- }
8
-
9
- export const TDengineTypeName: IndexableString = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrecisionLength = exports.TDengineTypeLength = exports.TDenginePrecision = exports.TDengineTypeCode = exports.ColumnsBlockType = exports.TDengineTypeName = void 0;
4
+ exports.TDengineTypeName = {
10
5
  0: 'NULL',
11
6
  1: 'BOOL',
12
7
  2: 'TINYINT',
@@ -23,16 +18,17 @@ export const TDengineTypeName: IndexableString = {
23
18
  13: 'INT UNSIGNED',
24
19
  14: 'BIGINT UNSIGNED',
25
20
  15: 'JSON',
26
- }
27
-
28
- export const ColumnsBlockType: StringIndexable = {
21
+ 16: 'VARBINARY',
22
+ 20: 'GEOMETRY',
23
+ };
24
+ exports.ColumnsBlockType = {
29
25
  'SOLID': 0,
30
26
  'VARCHAR': 1,
31
- 'NCHAR': 2
32
- }
33
-
34
-
35
- export const TDengineTypeCode: StringIndexable = {
27
+ 'NCHAR': 2,
28
+ 'GEOMETRY': 3,
29
+ 'VARBINARY': 4,
30
+ };
31
+ exports.TDengineTypeCode = {
36
32
  'NULL': 0,
37
33
  'BOOL': 1,
38
34
  'TINYINT': 2,
@@ -50,15 +46,15 @@ export const TDengineTypeCode: StringIndexable = {
50
46
  'INT UNSIGNED': 13,
51
47
  'BIGINT UNSIGNED': 14,
52
48
  'JSON': 15,
53
- }
54
-
55
- export const TDenginePrecision: IndexableString = {
49
+ 'VARBINARY': 16,
50
+ 'GEOMETRY': 20,
51
+ };
52
+ exports.TDenginePrecision = {
56
53
  0: 'MILLISECOND',
57
54
  1: "MICROSECOND",
58
55
  2: "NANOSECOND",
59
- }
60
-
61
- export const TDengineTypeLength: StringIndexable = {
56
+ };
57
+ exports.TDengineTypeLength = {
62
58
  'BOOL': 1,
63
59
  'TINYINT': 1,
64
60
  'SMALLINT': 2,
@@ -71,4 +67,9 @@ export const TDengineTypeLength: StringIndexable = {
71
67
  'SMALLINT UNSIGNED': 2,
72
68
  'INT UNSIGNED': 4,
73
69
  'BIGINT UNSIGNED': 8,
74
- }
70
+ };
71
+ exports.PrecisionLength = {
72
+ 'ms': 13,
73
+ 'us': 16,
74
+ 'ns': 19
75
+ };
@@ -0,0 +1,5 @@
1
+ import winston from 'winston';
2
+ declare const logger: winston.Logger;
3
+ export declare function setLevel(level: string): void;
4
+ export default logger;
5
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/common/log.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAwB9B,QAAA,MAAM,MAAM,gBAGV,CAAC;AAUH,wBAAgB,QAAQ,CAAC,KAAK,EAAC,MAAM,QAEpC;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,40 @@
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.setLevel = void 0;
7
+ const winston_1 = __importDefault(require("winston"));
8
+ const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
9
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
10
+ const customFormat = winston_1.default.format.printf(({ timestamp, level, message, ...meta }) => {
11
+ const formattedTime = (0, moment_timezone_1.default)(timestamp).tz('Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss.SSS'); // 使用上海时区
12
+ return `${formattedTime} ${level}: ${message} ${Object.keys(meta).length ? JSON.stringify(meta, null, 2) : ''}`;
13
+ });
14
+ const transport = new winston_daily_rotate_file_1.default({
15
+ filename: './logs/app-%DATE%.log', // Here is the file name template
16
+ datePattern: 'YYYY-MM-DD', // date format
17
+ zippedArchive: true, // Whether to compress the archive file into gzip format
18
+ maxSize: '20m', // Single file size limit
19
+ maxFiles: '14d', // Keep log files for 14 days
20
+ handleExceptions: true, // Whether to handle exceptions
21
+ json: false, // Whether to output logs in JSON format
22
+ format: winston_1.default.format.combine(winston_1.default.format.timestamp(), customFormat),
23
+ level: 'info', // set log level
24
+ });
25
+ const logger = winston_1.default.createLogger({
26
+ transports: [transport],
27
+ exitOnError: false, // Do not exit the process when an error occurs
28
+ });
29
+ // 设置 BigInt 类型的序列化处理
30
+ transport.format = winston_1.default.format((info) => {
31
+ if (info && info.message && typeof info.message === 'object' && typeof info.message.toJSON === 'function') {
32
+ info.message = info.message.toJSON();
33
+ }
34
+ return info;
35
+ })();
36
+ function setLevel(level) {
37
+ transport.level = level;
38
+ }
39
+ exports.setLevel = setLevel;
40
+ exports.default = logger;
@@ -0,0 +1,8 @@
1
+ export declare class ReqId {
2
+ private static _uuid;
3
+ private static _pid;
4
+ private static sharedBuffer;
5
+ private static int32View;
6
+ static getReqID(req_id?: number): number;
7
+ }
8
+ //# sourceMappingURL=reqid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reqid.d.ts","sourceRoot":"","sources":["../../../src/common/reqid.ts"],"names":[],"mappings":"AA2BA,qBAAa,KAAK;IACd,OAAO,CAAC,MAAM,CAAC,KAAK,CAAK;IACzB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAI;IACvB,OAAO,CAAC,MAAM,CAAC,YAAY,CAA4B;IACvD,OAAO,CAAC,MAAM,CAAC,SAAS,CAAsC;WAahD,QAAQ,CAAC,MAAM,CAAC,EAAC,MAAM,GAAE,MAAM;CAgBhD"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ReqId = void 0;
5
+ const crypto_1 = require("crypto");
6
+ const uuid_1 = require("uuid");
7
+ const node_process_1 = require("node:process");
8
+ function hexStringToNumber(hexString) {
9
+ const number = parseInt(hexString, 16);
10
+ if (isNaN(number)) {
11
+ throw new Error(`number ${hexString} parse int fail!`);
12
+ }
13
+ return number;
14
+ }
15
+ function uuidToHash() {
16
+ let uuid = (0, uuid_1.v4)();
17
+ // create SHA-256 hash
18
+ const hash = (0, crypto_1.createHash)('sha256');
19
+ // update hash contact
20
+ hash.update(uuid);
21
+ // get hex hash code
22
+ const strHex = hash.digest('hex').substring(0, 8);
23
+ let hex = hexStringToNumber(strHex);
24
+ return hex & 0xff;
25
+ }
26
+ class ReqId {
27
+ static getReqID(req_id) {
28
+ if (req_id) {
29
+ return req_id;
30
+ }
31
+ let no = Atomics.add(_a.int32View, 0, 1);
32
+ const buffer = new ArrayBuffer(8);
33
+ const view = new DataView(buffer);
34
+ let ts = new Date().getTime() >> 8;
35
+ view.setUint8(6, this._uuid >> 4);
36
+ view.setUint8(5, (this._uuid & 0x0f) << 4 | this._pid);
37
+ view.setUint8(4, ts >> 16 & 0xff);
38
+ view.setUint16(2, ts & 0xffff, true);
39
+ view.setUint16(0, no & 0xffff, true);
40
+ let id = view.getBigInt64(0, true);
41
+ return Number(id);
42
+ }
43
+ }
44
+ exports.ReqId = ReqId;
45
+ _a = ReqId;
46
+ ReqId._uuid = 0;
47
+ ReqId._pid = 0;
48
+ ReqId.sharedBuffer = new SharedArrayBuffer(4);
49
+ ReqId.int32View = new Int32Array(_a.sharedBuffer);
50
+ (() => {
51
+ _a._uuid = uuidToHash();
52
+ if (node_process_1.pid) {
53
+ _a._pid = node_process_1.pid & 0xf;
54
+ }
55
+ else {
56
+ _a._pid = (Math.floor(Math.random() * 9000) + 1000) & 0xf;
57
+ }
58
+ Atomics.store(_a.int32View, 0, 0);
59
+ })();
@@ -0,0 +1,51 @@
1
+ import { WSFetchBlockResponse, WSQueryResponse } from "../client/wsResponse";
2
+ export interface TDengineMeta {
3
+ name: string;
4
+ type: string;
5
+ length: number;
6
+ }
7
+ interface ResponseMeta {
8
+ name: string;
9
+ type: number;
10
+ length: number;
11
+ }
12
+ export interface MessageResp {
13
+ totalTime: number;
14
+ msg: any;
15
+ }
16
+ export declare class TaosResult {
17
+ private _meta;
18
+ private _data;
19
+ private _precision;
20
+ protected _affectRows: number | null | undefined;
21
+ private _totalTime;
22
+ /** unit nano seconds */
23
+ private _timing;
24
+ constructor(queryResponse?: WSQueryResponse);
25
+ setRowsAndTime(rows: number, timing?: bigint): void;
26
+ getMeta(): Array<TDengineMeta> | null;
27
+ getData(): Array<Array<any>> | null;
28
+ setData(value: Array<Array<any>> | null): void;
29
+ getAffectRows(): number | null | undefined;
30
+ getTaosMeta(): Array<ResponseMeta> | null;
31
+ getPrecision(): number | null | undefined;
32
+ getTotalTime(): number;
33
+ addTotalTime(totalTime: number): void;
34
+ setTiming(timing?: bigint): void;
35
+ /**
36
+ * Mapping the WebSocket response type code to TDengine's type name.
37
+ */
38
+ private getTDengineMeta;
39
+ }
40
+ export declare function parseBlock(rows: number, blocks: WSFetchBlockResponse, taosResult: TaosResult): TaosResult;
41
+ export declare function _isVarType(meta: ResponseMeta): Number;
42
+ export declare function readSolidDataToArray(buffer: ArrayBuffer, colBlockHead: number, rows: number, meta: ResponseMeta, bitMapArr: ArrayBuffer): any[];
43
+ export declare function readSolidData(dataBuffer: ArrayBuffer, colDataHead: number, meta: ResponseMeta): Number | Boolean | BigInt;
44
+ export declare function readBinary(dataBuffer: ArrayBuffer, colDataHead: number, length: number): ArrayBuffer;
45
+ export declare function readVarchar(dataBuffer: ArrayBuffer, colDataHead: number, length: number): string;
46
+ export declare function readNchar(dataBuffer: ArrayBuffer, colDataHead: number, length: number): string;
47
+ export declare function getCharOffset(n: number): number;
48
+ export declare function setBitmapNull(c: number, n: number): number;
49
+ export declare function bitmapLen(n: number): number;
50
+ export {};
51
+ //# sourceMappingURL=taosResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taosResult.d.ts","sourceRoot":"","sources":["../../../src/common/taosResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAM7E,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAC,GAAG,CAAC;CACX;AAED,qBAAa,UAAU;IACnB,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,KAAK,CAA2B;IAExC,OAAO,CAAC,UAAU,CAA4B;IAC9C,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACjD,OAAO,CAAC,UAAU,CAAK;IACvB,wBAAwB;IACxB,OAAO,CAAC,OAAO,CAA4B;gBAC/B,aAAa,CAAC,EAAE,eAAe;IAkCpC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAC,MAAM;IAY3C,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI;IAIrC,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI;IAGnC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI;IAGvC,aAAa,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS;IAI1C,WAAW,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI;IAIzC,YAAY,IAAG,MAAM,GAAG,IAAI,GAAG,SAAS;IAGxC,YAAY;IAGZ,YAAY,CAAC,SAAS,EAAC,MAAM;IAI7B,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM;IAShC;;OAEG;IACH,OAAO,CAAC,eAAe;CAc1B;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAyEzG;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAwBrD;AACD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAC,MAAM,EACzE,IAAI,EAAC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,GAAG,GAAG,EAAE,CAmHlE;AACD,wBAAgB,aAAa,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CA4CzH;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAGpG;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKhG;AAED,wBAAgB,SAAS,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ9F;AAmBD,wBAAgB,aAAa,CAAC,CAAC,EAAC,MAAM,GAAE,MAAM,CAE7C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAC,MAAM,EAAE,CAAC,EAAC,MAAM,GAAE,MAAM,CAEvD;AAMD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C"}
@@ -0,0 +1,419 @@
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.bitmapLen = exports.setBitmapNull = exports.getCharOffset = exports.readNchar = exports.readVarchar = exports.readBinary = exports.readSolidData = exports.readSolidDataToArray = exports._isVarType = exports.parseBlock = exports.TaosResult = void 0;
7
+ const constant_1 = require("./constant");
8
+ const wsError_1 = require("./wsError");
9
+ const ut8Helper_1 = require("./ut8Helper");
10
+ const log_1 = __importDefault(require("./log"));
11
+ class TaosResult {
12
+ constructor(queryResponse) {
13
+ this._totalTime = 0;
14
+ if (queryResponse == null) {
15
+ this._meta = null;
16
+ this._data = null;
17
+ this._timing = BigInt(0);
18
+ return;
19
+ }
20
+ if (queryResponse.is_update == true) {
21
+ this._meta = null;
22
+ this._data = null;
23
+ }
24
+ else {
25
+ if (queryResponse.fields_count && queryResponse.fields_names && queryResponse.fields_types && queryResponse.fields_lengths) {
26
+ let _meta = [];
27
+ for (let i = 0; i < queryResponse.fields_count; i++) {
28
+ _meta.push({
29
+ name: queryResponse.fields_names[i],
30
+ type: queryResponse.fields_types[i],
31
+ length: queryResponse.fields_lengths[i]
32
+ });
33
+ }
34
+ this._meta = _meta;
35
+ }
36
+ else {
37
+ throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, `fields_count,fields_names,fields_types,fields_lengths of the update query response should be null`);
38
+ }
39
+ this._data = [];
40
+ }
41
+ this._affectRows = queryResponse.affected_rows;
42
+ this._timing = queryResponse.timing;
43
+ this._precision = queryResponse.precision;
44
+ this._totalTime = queryResponse.totalTime;
45
+ }
46
+ setRowsAndTime(rows, timing) {
47
+ if (this._affectRows) {
48
+ this._affectRows += rows;
49
+ }
50
+ else {
51
+ this._affectRows = rows;
52
+ }
53
+ if (timing) {
54
+ this.setTiming(timing);
55
+ }
56
+ }
57
+ getMeta() {
58
+ return this.getTDengineMeta();
59
+ }
60
+ getData() {
61
+ return this._data;
62
+ }
63
+ setData(value) {
64
+ this._data = value;
65
+ }
66
+ getAffectRows() {
67
+ return this._affectRows;
68
+ }
69
+ getTaosMeta() {
70
+ return this._meta;
71
+ }
72
+ getPrecision() {
73
+ return this._precision;
74
+ }
75
+ getTotalTime() {
76
+ return this._totalTime;
77
+ }
78
+ addTotalTime(totalTime) {
79
+ this._totalTime += totalTime;
80
+ }
81
+ setTiming(timing) {
82
+ if (!this._timing) {
83
+ this._timing = BigInt(0);
84
+ }
85
+ if (timing) {
86
+ this._timing = this._timing + timing;
87
+ }
88
+ }
89
+ /**
90
+ * Mapping the WebSocket response type code to TDengine's type name.
91
+ */
92
+ getTDengineMeta() {
93
+ if (this._meta) {
94
+ let tdMeta = new Array();
95
+ this._meta.forEach(m => {
96
+ tdMeta.push({
97
+ name: m.name,
98
+ type: constant_1.TDengineTypeName[m.type],
99
+ length: m.length
100
+ });
101
+ });
102
+ return tdMeta;
103
+ }
104
+ return null;
105
+ }
106
+ }
107
+ exports.TaosResult = TaosResult;
108
+ function parseBlock(rows, blocks, taosResult) {
109
+ let metaList = taosResult.getTaosMeta();
110
+ let dataList = taosResult.getData();
111
+ if (metaList && dataList) {
112
+ taosResult.setTiming(blocks.timing);
113
+ const INT_32_SIZE = 4;
114
+ // Offset num of bytes from rawBlockBuffer.
115
+ let bufferOffset = (4 * 5) + 8 + (4 + 1) * metaList.length;
116
+ let colLengthBlockSize = INT_32_SIZE * metaList.length;
117
+ log_1.default.debug("===colLengthBlockSize:" + colLengthBlockSize);
118
+ let bitMapSize = (rows + (1 << 3) - 1) >> 3;
119
+ // whole raw block ArrayBuffer
120
+ let dataBuffer = blocks.data.slice(bufferOffset);
121
+ // record the head of column in block
122
+ let colBlockHead = 0;
123
+ for (let i = 0; i < rows; i++) {
124
+ let row = [];
125
+ // point to the head of the column in the block
126
+ colBlockHead = 0 + colLengthBlockSize;
127
+ // point to the head of columns's data in the block (include bitMap and offsetArray)
128
+ let colDataHead = colBlockHead;
129
+ // traverse row after row.
130
+ for (let j = 0; j < metaList.length; j++) {
131
+ let isVarType = _isVarType(metaList[j]);
132
+ if (isVarType == constant_1.ColumnsBlockType.SOLID) {
133
+ colDataHead = colBlockHead + bitMapSize + metaList[j].length * i;
134
+ let byteArrayIndex = i >> 3;
135
+ let bitwiseOffset = 7 - (i & 7);
136
+ let bitMapArr = dataBuffer.slice(colBlockHead, colBlockHead + bitMapSize);
137
+ let bitFlag = ((new DataView(bitMapArr).getUint8(byteArrayIndex)) & (1 << bitwiseOffset)) >> bitwiseOffset;
138
+ if (bitFlag == 1) {
139
+ row.push("NULL");
140
+ }
141
+ else {
142
+ row.push(readSolidData(dataBuffer, colDataHead, metaList[j]));
143
+ }
144
+ colBlockHead = colBlockHead + bitMapSize + (new DataView(dataBuffer, INT_32_SIZE * j, INT_32_SIZE).getInt32(0, true));
145
+ }
146
+ else {
147
+ // if null check
148
+ let varOffset = new DataView(dataBuffer, colBlockHead + (INT_32_SIZE * i), INT_32_SIZE).getInt32(0, true);
149
+ if (varOffset == -1) {
150
+ row.push("NULL");
151
+ colBlockHead = colBlockHead + INT_32_SIZE * rows + (new DataView(dataBuffer, j * INT_32_SIZE, INT_32_SIZE).getInt32(0, true));
152
+ }
153
+ else {
154
+ colDataHead = colBlockHead + INT_32_SIZE * rows + varOffset;
155
+ let dataLength = (new DataView(dataBuffer, colDataHead, 2).getInt16(0, true));
156
+ if (isVarType == constant_1.ColumnsBlockType.VARCHAR) {
157
+ row.push(readVarchar(dataBuffer, colDataHead + 2, dataLength));
158
+ }
159
+ else if (isVarType == constant_1.ColumnsBlockType.GEOMETRY || isVarType == constant_1.ColumnsBlockType.VARBINARY) {
160
+ row.push(readBinary(dataBuffer, colDataHead + 2, dataLength));
161
+ }
162
+ else {
163
+ row.push(readNchar(dataBuffer, colDataHead + 2, dataLength));
164
+ }
165
+ colBlockHead = colBlockHead + INT_32_SIZE * rows + (new DataView(dataBuffer, j * INT_32_SIZE, INT_32_SIZE).getInt32(0, true));
166
+ }
167
+ }
168
+ }
169
+ dataList.push(row);
170
+ }
171
+ return taosResult;
172
+ }
173
+ else {
174
+ throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, "cannot fetch block for an update query.");
175
+ }
176
+ }
177
+ exports.parseBlock = parseBlock;
178
+ function _isVarType(meta) {
179
+ switch (meta.type) {
180
+ case constant_1.TDengineTypeCode['NCHAR']: {
181
+ return constant_1.ColumnsBlockType['NCHAR'];
182
+ }
183
+ case constant_1.TDengineTypeCode['VARCHAR']: {
184
+ return constant_1.ColumnsBlockType['VARCHAR'];
185
+ }
186
+ case constant_1.TDengineTypeCode['BINARY']: {
187
+ return constant_1.ColumnsBlockType['VARCHAR'];
188
+ }
189
+ case constant_1.TDengineTypeCode['JSON']: {
190
+ return constant_1.ColumnsBlockType['VARCHAR'];
191
+ }
192
+ case constant_1.TDengineTypeCode['GEOMETRY']: {
193
+ return constant_1.ColumnsBlockType['GEOMETRY'];
194
+ }
195
+ case constant_1.TDengineTypeCode['VARBINARY']: {
196
+ return constant_1.ColumnsBlockType['VARBINARY'];
197
+ }
198
+ default: {
199
+ return constant_1.ColumnsBlockType['SOLID'];
200
+ }
201
+ }
202
+ }
203
+ exports._isVarType = _isVarType;
204
+ function readSolidDataToArray(buffer, colBlockHead, rows, meta, bitMapArr) {
205
+ let dataBuffer = new DataView(buffer);
206
+ let result = [];
207
+ switch (meta.type) {
208
+ case constant_1.TDengineTypeCode['BOOL']:
209
+ case constant_1.TDengineTypeCode['TINYINT']:
210
+ case constant_1.TDengineTypeCode['TINYINT UNSIGNED']: {
211
+ for (let i = 0; i < rows; i++, colBlockHead++) {
212
+ if (isNull(bitMapArr, i)) {
213
+ result.push(null);
214
+ }
215
+ else {
216
+ result.push(dataBuffer.getInt8(colBlockHead));
217
+ }
218
+ }
219
+ break;
220
+ }
221
+ case constant_1.TDengineTypeCode['SMALLINT']: {
222
+ for (let i = 0; i < rows; i++, colBlockHead += 2) {
223
+ if (isNull(bitMapArr, i)) {
224
+ result.push(null);
225
+ }
226
+ else {
227
+ result.push(dataBuffer.getInt16(colBlockHead, true));
228
+ }
229
+ }
230
+ break;
231
+ }
232
+ case constant_1.TDengineTypeCode['INT']: {
233
+ for (let i = 0; i < rows; i++, colBlockHead += 4) {
234
+ if (isNull(bitMapArr, i)) {
235
+ result.push(null);
236
+ }
237
+ else {
238
+ result.push(dataBuffer.getInt32(colBlockHead, true));
239
+ }
240
+ }
241
+ break;
242
+ }
243
+ case constant_1.TDengineTypeCode['BIGINT']: {
244
+ for (let i = 0; i < rows; i++, colBlockHead += 8) {
245
+ if (isNull(bitMapArr, i)) {
246
+ result.push(null);
247
+ }
248
+ else {
249
+ result.push(dataBuffer.getBigInt64(colBlockHead, true));
250
+ }
251
+ }
252
+ break;
253
+ }
254
+ case constant_1.TDengineTypeCode['SMALLINT UNSIGNED']: {
255
+ for (let i = 0; i < rows; i++, colBlockHead += 2) {
256
+ if (isNull(bitMapArr, i)) {
257
+ result.push(null);
258
+ }
259
+ else {
260
+ result.push(dataBuffer.getUint16(colBlockHead, true));
261
+ }
262
+ }
263
+ break;
264
+ }
265
+ case constant_1.TDengineTypeCode['INT UNSIGNED']: {
266
+ for (let i = 0; i < rows; i++, colBlockHead += 4) {
267
+ if (isNull(bitMapArr, i)) {
268
+ result.push(null);
269
+ }
270
+ else {
271
+ result.push(dataBuffer.getUint32(colBlockHead, true));
272
+ }
273
+ }
274
+ break;
275
+ }
276
+ case constant_1.TDengineTypeCode['BIGINT UNSIGNED']: {
277
+ for (let i = 0; i < rows; i++, colBlockHead += 8) {
278
+ if (isNull(bitMapArr, i)) {
279
+ result.push(null);
280
+ }
281
+ else {
282
+ result.push(dataBuffer.getBigUint64(colBlockHead, true));
283
+ }
284
+ }
285
+ break;
286
+ }
287
+ case constant_1.TDengineTypeCode['FLOAT']: {
288
+ for (let i = 0; i < rows; i++, colBlockHead += 4) {
289
+ if (isNull(bitMapArr, i)) {
290
+ result.push(null);
291
+ }
292
+ else {
293
+ result.push(parseFloat(dataBuffer.getFloat32(colBlockHead, true).toFixed(5)));
294
+ }
295
+ }
296
+ break;
297
+ }
298
+ case constant_1.TDengineTypeCode['DOUBLE']: {
299
+ for (let i = 0; i < rows; i++, colBlockHead += 8) {
300
+ if (isNull(bitMapArr, i)) {
301
+ result.push(null);
302
+ }
303
+ else {
304
+ result.push(parseFloat(dataBuffer.getFloat64(colBlockHead, true).toFixed(15)));
305
+ }
306
+ }
307
+ break;
308
+ }
309
+ case constant_1.TDengineTypeCode['TIMESTAMP']: {
310
+ for (let i = 0; i < rows; i++, colBlockHead += 8) {
311
+ if (isNull(bitMapArr, i)) {
312
+ result.push(null);
313
+ }
314
+ else {
315
+ result.push(dataBuffer.getBigInt64(colBlockHead, true));
316
+ }
317
+ }
318
+ break;
319
+ }
320
+ default: {
321
+ throw new wsError_1.WebSocketQueryInterFaceError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, `unspported type ${meta.type} for column ${meta.name}`);
322
+ }
323
+ }
324
+ return result;
325
+ }
326
+ exports.readSolidDataToArray = readSolidDataToArray;
327
+ function readSolidData(dataBuffer, colDataHead, meta) {
328
+ switch (meta.type) {
329
+ case constant_1.TDengineTypeCode['BOOL']: {
330
+ return (Boolean)(new DataView(dataBuffer, colDataHead, 1).getInt8(0));
331
+ }
332
+ case constant_1.TDengineTypeCode['TINYINT']: {
333
+ return (new DataView(dataBuffer, colDataHead, 1).getInt8(0));
334
+ }
335
+ case constant_1.TDengineTypeCode['SMALLINT']: {
336
+ return (new DataView(dataBuffer, colDataHead, 2).getInt16(0, true));
337
+ }
338
+ case constant_1.TDengineTypeCode['INT']: {
339
+ return (new DataView(dataBuffer, colDataHead, 4).getInt32(0, true));
340
+ }
341
+ case constant_1.TDengineTypeCode['BIGINT']: {
342
+ return (new DataView(dataBuffer, colDataHead, 8).getBigInt64(0, true));
343
+ }
344
+ case constant_1.TDengineTypeCode['TINYINT UNSIGNED']: {
345
+ return (new DataView(dataBuffer, colDataHead, 1).getUint8(0));
346
+ }
347
+ case constant_1.TDengineTypeCode['SMALLINT UNSIGNED']: {
348
+ return (new DataView(dataBuffer, colDataHead, 2).getUint16(0, true));
349
+ }
350
+ case constant_1.TDengineTypeCode['INT UNSIGNED']: {
351
+ return (new DataView(dataBuffer, colDataHead, 4).getUint32(0, true));
352
+ }
353
+ case constant_1.TDengineTypeCode['BIGINT UNSIGNED']: {
354
+ return (new DataView(dataBuffer, colDataHead, 8).getBigUint64(0, true));
355
+ }
356
+ case constant_1.TDengineTypeCode['FLOAT']: {
357
+ return (parseFloat(new DataView(dataBuffer, colDataHead, 4).getFloat32(0, true).toFixed(5)));
358
+ }
359
+ case constant_1.TDengineTypeCode['DOUBLE']: {
360
+ return (parseFloat(new DataView(dataBuffer, colDataHead, 8).getFloat64(0, true).toFixed(15)));
361
+ }
362
+ case constant_1.TDengineTypeCode['TIMESTAMP']: {
363
+ return (new DataView(dataBuffer, colDataHead, 8).getBigInt64(0, true));
364
+ // could change
365
+ }
366
+ default: {
367
+ throw new wsError_1.WebSocketQueryInterFaceError(wsError_1.ErrorCode.ERR_UNSUPPORTED_TDENGINE_TYPE, `unspported type ${meta.type} for column ${meta.name}`);
368
+ }
369
+ }
370
+ }
371
+ exports.readSolidData = readSolidData;
372
+ function readBinary(dataBuffer, colDataHead, length) {
373
+ let buff = dataBuffer.slice(colDataHead, colDataHead + length);
374
+ return buff;
375
+ }
376
+ exports.readBinary = readBinary;
377
+ function readVarchar(dataBuffer, colDataHead, length) {
378
+ let data = "";
379
+ let buff = dataBuffer.slice(colDataHead, colDataHead + length);
380
+ data += new TextDecoder().decode(buff);
381
+ return data;
382
+ }
383
+ exports.readVarchar = readVarchar;
384
+ function readNchar(dataBuffer, colDataHead, length) {
385
+ let data = "";
386
+ let buff = dataBuffer.slice(colDataHead, colDataHead + length);
387
+ for (let i = 0; i < length / 4; i++) {
388
+ data += (0, ut8Helper_1.appendRune)(new DataView(buff, i * 4, 4).getUint32(0, true));
389
+ }
390
+ return data;
391
+ }
392
+ exports.readNchar = readNchar;
393
+ function iteratorBuff(arr) {
394
+ let buf = Buffer.from(arr);
395
+ for (const value of buf) {
396
+ log_1.default.debug(value.toString());
397
+ }
398
+ }
399
+ function isNull(bitMapArr, n) {
400
+ let c = new Uint8Array(bitMapArr);
401
+ let position = n >>> 3;
402
+ let index = n & 0x7;
403
+ return (c[position] & (1 << (7 - index))) == (1 << (7 - index));
404
+ }
405
+ function getCharOffset(n) {
406
+ return n >> 3;
407
+ }
408
+ exports.getCharOffset = getCharOffset;
409
+ function setBitmapNull(c, n) {
410
+ return c + (1 << (7 - bitPos(n)));
411
+ }
412
+ exports.setBitmapNull = setBitmapNull;
413
+ function bitPos(n) {
414
+ return n & ((1 << 3) - 1);
415
+ }
416
+ function bitmapLen(n) {
417
+ return ((n) + ((1 << 3) - 1)) >> 3;
418
+ }
419
+ exports.bitmapLen = bitmapLen;
@@ -0,0 +1,2 @@
1
+ export declare function appendRune(r: any): string;
2
+ //# sourceMappingURL=ut8Helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ut8Helper.d.ts","sourceRoot":"","sources":["../../../src/common/ut8Helper.ts"],"names":[],"mappings":"AAsBA,wBAAgB,UAAU,CAAC,CAAC,EAAC,GAAG,UAiB/B"}