@tdengine/websocket 3.1.8 → 3.2.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 (86) hide show
  1. package/lib/index.d.ts +8 -1
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +8 -1
  4. package/lib/src/client/wsClient.d.ts +4 -0
  5. package/lib/src/client/wsClient.d.ts.map +1 -1
  6. package/lib/src/client/wsClient.js +35 -8
  7. package/lib/src/client/wsConnector.d.ts.map +1 -1
  8. package/lib/src/client/wsResponse.d.ts +2 -0
  9. package/lib/src/client/wsResponse.d.ts.map +1 -1
  10. package/lib/src/client/wsResponse.js +2 -0
  11. package/lib/src/common/config.d.ts +6 -1
  12. package/lib/src/common/config.d.ts.map +1 -1
  13. package/lib/src/common/config.js +17 -1
  14. package/lib/src/common/constant.d.ts +20 -2
  15. package/lib/src/common/constant.d.ts.map +1 -1
  16. package/lib/src/common/constant.js +30 -13
  17. package/lib/src/common/taosResult.d.ts +5 -2
  18. package/lib/src/common/taosResult.d.ts.map +1 -1
  19. package/lib/src/common/taosResult.js +59 -5
  20. package/lib/src/common/utils.d.ts +1 -0
  21. package/lib/src/common/utils.d.ts.map +1 -1
  22. package/lib/src/common/utils.js +31 -0
  23. package/lib/src/sql/wsSql.d.ts.map +1 -1
  24. package/lib/src/sql/wsSql.js +18 -2
  25. package/lib/src/stmt/FieldBindParams.d.ts +9 -0
  26. package/lib/src/stmt/FieldBindParams.d.ts.map +1 -0
  27. package/lib/src/stmt/FieldBindParams.js +13 -0
  28. package/lib/src/stmt/wsColumnInfo.d.ts +12 -0
  29. package/lib/src/stmt/wsColumnInfo.d.ts.map +1 -0
  30. package/lib/src/stmt/wsColumnInfo.js +17 -0
  31. package/lib/src/stmt/wsParams1.d.ts +14 -0
  32. package/lib/src/stmt/wsParams1.d.ts.map +1 -0
  33. package/lib/src/stmt/wsParams1.js +274 -0
  34. package/lib/src/stmt/wsParams2.d.ts +14 -0
  35. package/lib/src/stmt/wsParams2.d.ts.map +1 -0
  36. package/lib/src/stmt/wsParams2.js +188 -0
  37. package/lib/src/stmt/wsParamsBase.d.ts +45 -0
  38. package/lib/src/stmt/wsParamsBase.d.ts.map +1 -0
  39. package/lib/src/stmt/wsParamsBase.js +218 -0
  40. package/lib/src/stmt/wsProto.d.ts +16 -4
  41. package/lib/src/stmt/wsProto.d.ts.map +1 -1
  42. package/lib/src/stmt/wsProto.js +197 -4
  43. package/lib/src/stmt/wsStmt.d.ts +6 -16
  44. package/lib/src/stmt/wsStmt.d.ts.map +1 -1
  45. package/lib/src/stmt/wsStmt.js +0 -200
  46. package/lib/src/stmt/wsStmt1.d.ts +30 -0
  47. package/lib/src/stmt/wsStmt1.d.ts.map +1 -0
  48. package/lib/src/stmt/wsStmt1.js +206 -0
  49. package/lib/src/stmt/wsStmt2.d.ts +37 -0
  50. package/lib/src/stmt/wsStmt2.d.ts.map +1 -0
  51. package/lib/src/stmt/wsStmt2.js +280 -0
  52. package/lib/src/stmt/wsTableInfo.d.ts +17 -0
  53. package/lib/src/stmt/wsTableInfo.d.ts.map +1 -0
  54. package/lib/src/stmt/wsTableInfo.js +54 -0
  55. package/lib/src/tmq/constant.d.ts +2 -0
  56. package/lib/src/tmq/constant.d.ts.map +1 -1
  57. package/lib/src/tmq/constant.js +2 -0
  58. package/lib/src/tmq/tmqResponse.d.ts +5 -5
  59. package/lib/src/tmq/tmqResponse.js +8 -8
  60. package/lib/src/tmq/wsTmq.d.ts +1 -0
  61. package/lib/src/tmq/wsTmq.d.ts.map +1 -1
  62. package/lib/src/tmq/wsTmq.js +9 -5
  63. package/lib/test/bulkPulling/cloud.tmq.test.js +0 -1
  64. package/lib/test/bulkPulling/decimal.test.d.ts +2 -0
  65. package/lib/test/bulkPulling/decimal.test.d.ts.map +1 -0
  66. package/lib/test/bulkPulling/decimal.test.js +129 -0
  67. package/lib/test/bulkPulling/sql.test.js +36 -9
  68. package/lib/test/bulkPulling/stmt.func.test.js +99 -11
  69. package/lib/test/bulkPulling/stmt.type.test.js +49 -6
  70. package/lib/test/bulkPulling/stmt1.func.test.d.ts +2 -0
  71. package/lib/test/bulkPulling/stmt1.func.test.d.ts.map +1 -0
  72. package/lib/test/bulkPulling/stmt1.func.test.js +417 -0
  73. package/lib/test/bulkPulling/stmt1.type.test.d.ts +2 -0
  74. package/lib/test/bulkPulling/stmt1.type.test.d.ts.map +1 -0
  75. package/lib/test/bulkPulling/stmt1.type.test.js +323 -0
  76. package/lib/test/bulkPulling/stmt2.func.test.d.ts +2 -0
  77. package/lib/test/bulkPulling/stmt2.func.test.d.ts.map +1 -0
  78. package/lib/test/bulkPulling/stmt2.func.test.js +539 -0
  79. package/lib/test/bulkPulling/stmt2.type.test.d.ts +2 -0
  80. package/lib/test/bulkPulling/stmt2.type.test.d.ts.map +1 -0
  81. package/lib/test/bulkPulling/stmt2.type.test.js +325 -0
  82. package/lib/test/bulkPulling/tmq.test.js +2 -0
  83. package/lib/test/bulkPulling/wsConnectPool.test.js +2 -2
  84. package/lib/test/utils.d.ts.map +1 -1
  85. package/lib/test/utils.js +1 -0
  86. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ export declare class FieldBindParams {
2
+ params: any[];
3
+ dataType: string;
4
+ typeLen: number;
5
+ columnType: number;
6
+ bindType: number;
7
+ constructor(params: any[], dataType: string, typeLen: number, columnType: number, bindType: number);
8
+ }
9
+ //# sourceMappingURL=FieldBindParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldBindParams.d.ts","sourceRoot":"","sources":["../../../src/stmt/FieldBindParams.ts"],"names":[],"mappings":"AACA,qBAAa,eAAe;IACxB,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;gBACL,MAAM,EAAC,GAAG,EAAE,EAAE,QAAQ,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM;CAOhG"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FieldBindParams = void 0;
4
+ class FieldBindParams {
5
+ constructor(params, dataType, typeLen, columnType, bindType) {
6
+ this.params = [...params];
7
+ this.dataType = dataType;
8
+ this.typeLen = typeLen;
9
+ this.columnType = columnType;
10
+ this.bindType = bindType;
11
+ }
12
+ }
13
+ exports.FieldBindParams = FieldBindParams;
@@ -0,0 +1,12 @@
1
+ export declare class ColumnInfo {
2
+ data: ArrayBuffer;
3
+ length: number;
4
+ type: number;
5
+ typeLen: number;
6
+ isNull?: number[];
7
+ _rows: number;
8
+ _haveLength: number;
9
+ _dataLengths?: number[];
10
+ constructor([length, data]: [number, ArrayBuffer], type: number, typeLen: number, rows: number, isNull?: number[], dataLengths?: number[], haveLength?: number);
11
+ }
12
+ //# sourceMappingURL=wsColumnInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsColumnInfo.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsColumnInfo.ts"],"names":[],"mappings":"AACA,qBAAa,UAAU;IACnB,IAAI,EAAC,WAAW,CAAC;IACjB,MAAM,EAAC,MAAM,CAAC;IACd,IAAI,EAAC,MAAM,CAAC;IACZ,OAAO,EAAC,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAK;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;gBACZ,CAAC,MAAM,EAAC,IAAI,CAAC,EAAC,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,EACrF,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE,UAAU,GAAE,MAAU;CAWxE"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColumnInfo = void 0;
4
+ class ColumnInfo {
5
+ constructor([length, data], type, typeLen, rows, isNull, dataLengths, haveLength = 0) {
6
+ this._haveLength = 0;
7
+ this.data = data;
8
+ this.type = type;
9
+ this.length = length;
10
+ this.typeLen = typeLen;
11
+ this._rows = rows;
12
+ this.isNull = isNull;
13
+ this._dataLengths = dataLengths;
14
+ this._haveLength = haveLength;
15
+ }
16
+ }
17
+ exports.ColumnInfo = ColumnInfo;
@@ -0,0 +1,14 @@
1
+ import { IDataEncoder, StmtBindParams } from "./wsParamsBase";
2
+ export declare class Stmt1BindParams extends StmtBindParams implements IDataEncoder {
3
+ constructor(precision?: number);
4
+ encode(): void;
5
+ mergeParams(bindParams: StmtBindParams): void;
6
+ addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
7
+ setTimestamp(params: any[]): void;
8
+ private encodeDigitColumns;
9
+ private encodeVarLengthColumn;
10
+ private getBinaryColumnArrayBuffer;
11
+ private encodeNcharColumn;
12
+ private countBigintDigits;
13
+ }
14
+ //# sourceMappingURL=wsParams1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsParams1.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsParams1.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE9D,qBAAa,eAAgB,SAAQ,cAAe,YAAW,YAAY;gBAC3D,SAAS,CAAC,EAAC,MAAM;IAI7B,MAAM,IAAI,IAAI;IAId,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAI7C,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAgBrF,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAwE1B,OAAO,CAAC,kBAAkB;IA2B1B,OAAO,CAAC,qBAAqB;IAiD7B,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,iBAAiB;IAuDzB,OAAO,CAAC,iBAAiB;CAa5B"}
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stmt1BindParams = void 0;
4
+ const constant_1 = require("../common/constant");
5
+ const wsError_1 = require("../common/wsError");
6
+ const taosResult_1 = require("../common/taosResult");
7
+ const utils_1 = require("../common/utils");
8
+ const wsColumnInfo_1 = require("./wsColumnInfo");
9
+ const wsParamsBase_1 = require("./wsParamsBase");
10
+ class Stmt1BindParams extends wsParamsBase_1.StmtBindParams {
11
+ constructor(precision) {
12
+ super(precision);
13
+ }
14
+ encode() {
15
+ return;
16
+ }
17
+ mergeParams(bindParams) {
18
+ return;
19
+ }
20
+ addParams(params, dataType, typeLen, columnType) {
21
+ if (!params || params.length == 0) {
22
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
23
+ }
24
+ if (dataType === "number" || dataType === "bigint" || dataType === "boolean") {
25
+ this._params.push(this.encodeDigitColumns(params, dataType, typeLen, columnType));
26
+ }
27
+ else {
28
+ if (columnType === constant_1.TDengineTypeCode.NCHAR) {
29
+ this._params.push(this.encodeNcharColumn(params));
30
+ }
31
+ else {
32
+ this._params.push(this.encodeVarLengthColumn(params, columnType));
33
+ }
34
+ }
35
+ }
36
+ setTimestamp(params) {
37
+ if (!params || params.length == 0) {
38
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params is invalid!");
39
+ }
40
+ //computing bitmap length
41
+ let bitMapLen = (0, taosResult_1.bitmapLen)(params.length);
42
+ //Computing the length of data
43
+ let arrayBuffer = new ArrayBuffer(bitMapLen + constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TIMESTAMP] * params.length);
44
+ //bitmap get data range
45
+ let bitmapBuffer = new DataView(arrayBuffer);
46
+ //skip bitmap get data range
47
+ let dataBuffer = new DataView(arrayBuffer, bitMapLen);
48
+ if (this._rows > 0) {
49
+ if (this._rows !== params.length) {
50
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
51
+ }
52
+ }
53
+ else {
54
+ this._rows = params.length;
55
+ }
56
+ for (let i = 0; i < params.length; i++) {
57
+ if (!(0, utils_1.isEmpty)(params[i])) {
58
+ if (params[i] instanceof Date) {
59
+ let date = params[i];
60
+ //node only support milliseconds, need fill 0
61
+ if (this.precisionLength == constant_1.PrecisionLength['us']) {
62
+ let ms = date.getTime() * 1000;
63
+ dataBuffer.setBigInt64(i * 8, BigInt(ms), true);
64
+ }
65
+ else if (this.precisionLength == constant_1.PrecisionLength['ns']) {
66
+ let ns = date.getTime() * 1000 * 1000;
67
+ dataBuffer.setBigInt64(i * 8, BigInt(ns), true);
68
+ }
69
+ else {
70
+ dataBuffer.setBigInt64(i * 8, BigInt(date.getTime()), true);
71
+ }
72
+ }
73
+ else if (typeof params[i] == 'bigint' || typeof params[i] == 'number') {
74
+ let data;
75
+ if (typeof params[i] == 'number') {
76
+ data = BigInt(params[i]);
77
+ }
78
+ else {
79
+ data = params[i];
80
+ }
81
+ //statistical bits of digit
82
+ let digit = this.countBigintDigits(data);
83
+ //check digit same table Precision
84
+ if (this.precisionLength == constant_1.PrecisionLength['ns']) {
85
+ if (this.precisionLength <= digit) {
86
+ dataBuffer.setBigInt64(i * 8, data, true);
87
+ }
88
+ else {
89
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params precisionLength is invalid! param:=" + params[i]);
90
+ }
91
+ }
92
+ else if (this.precisionLength == digit) {
93
+ dataBuffer.setBigInt64(i * 8, data, true);
94
+ }
95
+ else {
96
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "SeTimestampColumn params is invalid! param:=" + params[i]);
97
+ }
98
+ }
99
+ }
100
+ else {
101
+ //set bitmap bit is null
102
+ let charOffset = (0, taosResult_1.getCharOffset)(i);
103
+ let nullVal = (0, taosResult_1.setBitmapNull)(dataBuffer.getInt8(charOffset), i);
104
+ bitmapBuffer.setInt8(charOffset, nullVal);
105
+ }
106
+ }
107
+ this._dataTotalLen += arrayBuffer.byteLength;
108
+ this._params.push(new wsColumnInfo_1.ColumnInfo([constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TIMESTAMP] * params.length, arrayBuffer], constant_1.TDengineTypeCode.TIMESTAMP, constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.TIMESTAMP], this._rows));
109
+ }
110
+ encodeDigitColumns(params, dataType = 'number', typeLen, columnType) {
111
+ let bitMapLen = (0, taosResult_1.bitmapLen)(params.length);
112
+ let arrayBuffer = new ArrayBuffer(typeLen * params.length + bitMapLen);
113
+ let bitmapBuffer = new DataView(arrayBuffer);
114
+ let dataBuffer = new DataView(arrayBuffer, bitMapLen);
115
+ if (this._rows > 0) {
116
+ if (this._rows !== params.length) {
117
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
118
+ }
119
+ }
120
+ else {
121
+ this._rows = params.length;
122
+ }
123
+ for (let i = 0; i < params.length; i++) {
124
+ if (!(0, utils_1.isEmpty)(params[i])) {
125
+ this.writeDataToBuffer(dataBuffer, params[i], dataType, typeLen, columnType, i);
126
+ }
127
+ else {
128
+ //set bitmap bit is null
129
+ let charOffset = (0, taosResult_1.getCharOffset)(i);
130
+ let nullVal = (0, taosResult_1.setBitmapNull)(bitmapBuffer.getUint8(charOffset), i);
131
+ bitmapBuffer.setInt8(charOffset, nullVal);
132
+ }
133
+ }
134
+ this._dataTotalLen += dataBuffer.buffer.byteLength;
135
+ return new wsColumnInfo_1.ColumnInfo([typeLen * params.length, dataBuffer.buffer], columnType, typeLen, this._rows);
136
+ }
137
+ encodeVarLengthColumn(params, columnType) {
138
+ let data = [];
139
+ let dataLength = 0;
140
+ //create params length buffer
141
+ let paramsLenBuffer = new ArrayBuffer(constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT] * params.length);
142
+ let paramsLenView = new DataView(paramsLenBuffer);
143
+ if (this._rows > 0) {
144
+ if (this._rows !== params.length) {
145
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
146
+ }
147
+ }
148
+ else {
149
+ this._rows = params.length;
150
+ }
151
+ for (let i = 0; i < params.length; i++) {
152
+ //get param length offset 4byte
153
+ let offset = constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT] * i;
154
+ if (!(0, utils_1.isEmpty)(params[i])) {
155
+ //save param length offset 4byte
156
+ paramsLenView.setInt32(offset, dataLength, true);
157
+ if (typeof params[i] == 'string') {
158
+ //string TextEncoder
159
+ let encode = new TextEncoder();
160
+ let value = encode.encode(params[i]).buffer;
161
+ data.push(value);
162
+ //add offset length
163
+ dataLength += value.byteLength + constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
164
+ }
165
+ else if (params[i] instanceof ArrayBuffer) {
166
+ //input arraybuffer, save not need encode
167
+ let value = params[i];
168
+ dataLength += value.byteLength + constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
169
+ data.push(value);
170
+ }
171
+ else {
172
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
173
+ }
174
+ }
175
+ else {
176
+ //set length -1, param is null
177
+ for (let j = 0; j < constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT]; j++) {
178
+ paramsLenView.setInt8(offset + j, 255);
179
+ }
180
+ }
181
+ }
182
+ this._dataTotalLen += paramsLenBuffer.byteLength + dataLength;
183
+ return new wsColumnInfo_1.ColumnInfo([dataLength, this.getBinaryColumnArrayBuffer(data, paramsLenView.buffer, dataLength)], columnType, 0, this._rows);
184
+ }
185
+ //splicing encode params to arraybuffer
186
+ getBinaryColumnArrayBuffer(data, paramsLenBuffer, dataLength) {
187
+ //create arraybuffer
188
+ let paramsBuffer = new ArrayBuffer(paramsLenBuffer.byteLength + dataLength);
189
+ //get length data range
190
+ const paramsUint8 = new Uint8Array(paramsBuffer);
191
+ const paramsLenView = new Uint8Array(paramsLenBuffer);
192
+ paramsUint8.set(paramsLenView, 0);
193
+ //get data range
194
+ const paramsView = new DataView(paramsBuffer, paramsLenBuffer.byteLength);
195
+ let offset = 0;
196
+ for (let i = 0; i < data.length; i++) {
197
+ //save param field length
198
+ paramsView.setInt16(offset, data[i].byteLength, true);
199
+ const dataView = new DataView(data[i]);
200
+ //save data
201
+ for (let j = 0; j < data[i].byteLength; j++) {
202
+ paramsView.setUint8(offset + 2 + j, dataView.getUint8(j));
203
+ }
204
+ offset += data[i].byteLength + 2;
205
+ }
206
+ return paramsBuffer;
207
+ }
208
+ //encode nchar type params
209
+ encodeNcharColumn(params) {
210
+ let data = [];
211
+ let dataLength = 0;
212
+ let indexBuffer = new ArrayBuffer(constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT] * params.length);
213
+ let indexView = new DataView(indexBuffer);
214
+ if (this._rows > 0) {
215
+ if (this._rows !== params.length) {
216
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
217
+ }
218
+ }
219
+ else {
220
+ this._rows = params.length;
221
+ }
222
+ for (let i = 0; i < params.length; i++) {
223
+ let offset = constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT] * i;
224
+ if (!(0, utils_1.isEmpty)(params[i])) {
225
+ indexView.setInt32(offset, dataLength, true);
226
+ if (typeof params[i] == 'string') {
227
+ let codes = [];
228
+ let strNcharParams = params[i];
229
+ for (let j = 0; j < params[i].length; j++) {
230
+ //get char, cn char need 3~4 byte
231
+ codes.push(strNcharParams.charCodeAt(j));
232
+ }
233
+ let ncharBuffer = new ArrayBuffer(codes.length * 4);
234
+ let ncharView = new DataView(ncharBuffer);
235
+ for (let j = 0; j < codes.length; j++) {
236
+ //1char, save into uint32
237
+ ncharView.setUint32(j * 4, codes[j], true);
238
+ }
239
+ data.push(ncharBuffer);
240
+ dataLength += codes.length * 4 + constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
241
+ }
242
+ else if (params[i] instanceof ArrayBuffer) {
243
+ let value = params[i];
244
+ dataLength += value.byteLength + constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.SMALLINT];
245
+ data.push(value);
246
+ }
247
+ else {
248
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
249
+ }
250
+ }
251
+ else {
252
+ //set length -1, param is null
253
+ for (let j = 0; j < constant_1.TDengineTypeLength[constant_1.TDengineTypeCode.INT]; j++) {
254
+ indexView.setInt8(offset + j, 255);
255
+ }
256
+ }
257
+ }
258
+ this._dataTotalLen += indexBuffer.byteLength + dataLength;
259
+ return new wsColumnInfo_1.ColumnInfo([dataLength, this.getBinaryColumnArrayBuffer(data, indexView.buffer, dataLength)], constant_1.TDengineTypeCode.NCHAR, 0, this._rows);
260
+ }
261
+ countBigintDigits(numeral) {
262
+ if (numeral === 0n) {
263
+ return 1;
264
+ }
265
+ let count = 0;
266
+ let temp = numeral;
267
+ while (temp !== 0n) {
268
+ temp /= 10n;
269
+ count++;
270
+ }
271
+ return count;
272
+ }
273
+ }
274
+ exports.Stmt1BindParams = Stmt1BindParams;
@@ -0,0 +1,14 @@
1
+ import { IDataEncoder, StmtBindParams } from "./wsParamsBase";
2
+ import { StmtFieldInfo } from "./wsProto";
3
+ export declare class Stmt2BindParams extends StmtBindParams implements IDataEncoder {
4
+ private _fields;
5
+ protected paramIndex: number;
6
+ constructor(paramsCount?: number, precision?: number, fields?: Array<StmtFieldInfo>);
7
+ addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
8
+ mergeParams(bindParams: StmtBindParams): void;
9
+ encode(): void;
10
+ private encodeVarColumns;
11
+ private encodeDigitColumns;
12
+ private encodeTimestampColumn;
13
+ }
14
+ //# sourceMappingURL=wsParams2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsParams2.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsParams2.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAI9D,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qBAAa,eAAgB,SAAQ,cAAe,YAAW,YAAY;IACvE,OAAO,CAAC,OAAO,CAAuB;IACtC,SAAS,CAAC,UAAU,EAAC,MAAM,CAAK;gBACpB,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAKlF,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IA4BrF,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAa7C,MAAM,IAAI,IAAI;IAgCd,OAAO,CAAC,gBAAgB;IAmCxB,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,qBAAqB;CAgChC"}
@@ -0,0 +1,188 @@
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.Stmt2BindParams = void 0;
7
+ const constant_1 = require("../common/constant");
8
+ const wsError_1 = require("../common/wsError");
9
+ const utils_1 = require("../common/utils");
10
+ const wsColumnInfo_1 = require("./wsColumnInfo");
11
+ const wsParamsBase_1 = require("./wsParamsBase");
12
+ const taosResult_1 = require("../common/taosResult");
13
+ const FieldBindParams_1 = require("./FieldBindParams");
14
+ const json_bigint_1 = __importDefault(require("json-bigint"));
15
+ class Stmt2BindParams extends wsParamsBase_1.StmtBindParams {
16
+ constructor(paramsCount, precision, fields) {
17
+ super(precision, paramsCount);
18
+ this.paramIndex = 0;
19
+ this._fields = fields || [];
20
+ }
21
+ addParams(params, dataType, typeLen, columnType) {
22
+ if (!params || params.length == 0) {
23
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
24
+ }
25
+ if (this._fieldParams) {
26
+ if (this.paramsCount > 0) {
27
+ if (this._fieldParams[this.paramIndex]) {
28
+ if (this._fieldParams[this.paramIndex].dataType !== dataType || this._fieldParams[this.paramIndex].columnType !== columnType) {
29
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, `StmtBindParams params type is not match! ${this.paramIndex} ${this.paramsCount} ${json_bigint_1.default.stringify({ dataType, columnType })} vs ${json_bigint_1.default.stringify({ dataType: this._fieldParams[this.paramIndex].dataType, columnType: this._fieldParams[this.paramIndex].columnType })}`);
30
+ }
31
+ this._fieldParams[this.paramIndex].params.push(...params);
32
+ }
33
+ else {
34
+ let bindType = this._fields[this.paramIndex].bind_type || 0;
35
+ this._fieldParams[this.paramIndex] = new FieldBindParams_1.FieldBindParams(params, dataType, typeLen, columnType, bindType);
36
+ this._bindCount++;
37
+ }
38
+ this.paramIndex++;
39
+ if (this.paramIndex >= this.paramsCount) {
40
+ this.paramIndex = 0;
41
+ }
42
+ }
43
+ else {
44
+ this._fieldParams.push(new FieldBindParams_1.FieldBindParams(params, dataType, typeLen, columnType, constant_1.FieldBindType.TAOS_FIELD_COL));
45
+ }
46
+ }
47
+ }
48
+ mergeParams(bindParams) {
49
+ if (!bindParams || !bindParams._fieldParams || bindParams._fieldParams.length === 0 || !this._fieldParams) {
50
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
51
+ }
52
+ this.paramIndex = 0;
53
+ for (let i = 0; i < bindParams._fieldParams.length; i++) {
54
+ let fieldParam = bindParams._fieldParams[i];
55
+ if (fieldParam) {
56
+ this.addParams(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType);
57
+ }
58
+ }
59
+ }
60
+ encode() {
61
+ this.paramIndex = 0;
62
+ if (!this._fieldParams || this._fieldParams.length == 0) {
63
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "StmtBindParams params is invalid!");
64
+ }
65
+ if (this._rows > 0) {
66
+ if (this._rows !== this._fieldParams[0].params.length) {
67
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "wrong row length!");
68
+ }
69
+ }
70
+ else {
71
+ this._rows = this._fieldParams[0].params.length;
72
+ }
73
+ for (let i = 0; i < this._fieldParams.length; i++) {
74
+ let fieldParam = this._fieldParams[i];
75
+ if (!fieldParam) {
76
+ continue;
77
+ }
78
+ let isVarType = (0, taosResult_1._isVarType)(fieldParam.columnType);
79
+ if (isVarType == constant_1.ColumnsBlockType.SOLID) {
80
+ if (fieldParam.dataType === "TIMESTAMP") {
81
+ this._params.push(this.encodeTimestampColumn(fieldParam.params, fieldParam.typeLen, fieldParam.columnType));
82
+ }
83
+ else {
84
+ this._params.push(this.encodeDigitColumns(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType));
85
+ }
86
+ }
87
+ else {
88
+ this._params.push(this.encodeVarColumns(fieldParam.params, fieldParam.dataType, fieldParam.typeLen, fieldParam.columnType));
89
+ }
90
+ }
91
+ }
92
+ encodeVarColumns(params, dataType = 'number', typeLen, columnType) {
93
+ let isNull = [];
94
+ let dataLengths = [];
95
+ // TotalLength(4) + Type (4) + Num(4) + IsNull(1) * size + haveLength(1) + BufferLength(4) + 4 * v.length + totalLength
96
+ // 17 + (5 * params.length) + totalLength;
97
+ let totalLength = 17 + (5 * params.length);
98
+ const bytes = [];
99
+ for (let i = 0; i < params.length; i++) {
100
+ if (!(0, utils_1.isEmpty)(params[i])) {
101
+ isNull.push(0);
102
+ if (typeof params[i] == 'string') {
103
+ let encoder = new TextEncoder().encode(params[i]);
104
+ let length = encoder.length;
105
+ totalLength += length;
106
+ dataLengths.push(length);
107
+ bytes.push(...encoder);
108
+ }
109
+ else if (params[i] instanceof ArrayBuffer) {
110
+ //input arraybuffer, save not need encode
111
+ let value = params[i];
112
+ totalLength += value.byteLength;
113
+ dataLengths.push(value.byteLength);
114
+ bytes.push(...new Uint8Array(value));
115
+ }
116
+ else {
117
+ throw new wsError_1.TaosError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, "getColumString params is invalid! param_type:=" + typeof params[i]);
118
+ }
119
+ }
120
+ else {
121
+ isNull.push(1);
122
+ }
123
+ }
124
+ this._dataTotalLen += totalLength;
125
+ const dataBuffer = new Uint8Array(bytes).buffer;
126
+ return new wsColumnInfo_1.ColumnInfo([totalLength, dataBuffer], columnType, typeLen, this._rows, isNull, dataLengths, 1);
127
+ }
128
+ encodeDigitColumns(params, dataType = 'number', typeLen, columnType) {
129
+ let isNull = [];
130
+ // TotalLength(4) + Type (4) + Num(4) + IsNull(1) * size + haveLength(1) + BufferLength(4) + size * dataLen
131
+ let dataLength = 17 + (typeLen + 1) * params.length;
132
+ let arrayBuffer = new ArrayBuffer(typeLen * params.length);
133
+ let dataBuffer = new DataView(arrayBuffer);
134
+ for (let i = 0; i < params.length; i++) {
135
+ if (!(0, utils_1.isEmpty)(params[i])) {
136
+ isNull.push(0);
137
+ this.writeDataToBuffer(dataBuffer, params[i], dataType, typeLen, columnType, i);
138
+ }
139
+ else {
140
+ isNull.push(1);
141
+ if (dataType === 'bigint') {
142
+ this.writeDataToBuffer(dataBuffer, BigInt(0), dataType, typeLen, columnType, i);
143
+ }
144
+ else {
145
+ this.writeDataToBuffer(dataBuffer, 0, dataType, typeLen, columnType, i);
146
+ }
147
+ }
148
+ }
149
+ this._dataTotalLen += dataLength;
150
+ return new wsColumnInfo_1.ColumnInfo([dataLength, dataBuffer.buffer], columnType, typeLen, this._rows, isNull);
151
+ }
152
+ encodeTimestampColumn(params, typeLen, columnType) {
153
+ let timeStamps = [];
154
+ for (let i = 0; i < params.length; i++) {
155
+ if (!(0, utils_1.isEmpty)(params[i])) {
156
+ let timeStamp = BigInt(0);
157
+ if (params[i] instanceof Date) {
158
+ let date = params[i];
159
+ //node only support milliseconds, need fill 0
160
+ if (this.precisionLength == constant_1.PrecisionLength['us']) {
161
+ timeStamp = BigInt(date.getTime() * 1000);
162
+ }
163
+ else if (this.precisionLength == constant_1.PrecisionLength['ns']) {
164
+ timeStamp = BigInt(date.getTime() * 1000 * 1000);
165
+ }
166
+ else {
167
+ timeStamp = BigInt(date.getTime());
168
+ }
169
+ }
170
+ else if (typeof params[i] == 'bigint' || typeof params[i] == 'number') {
171
+ if (typeof params[i] == 'number') {
172
+ timeStamp = BigInt(params[i]);
173
+ }
174
+ else {
175
+ timeStamp = params[i];
176
+ }
177
+ }
178
+ timeStamps.push(timeStamp);
179
+ }
180
+ else {
181
+ //set bitmap bit is null
182
+ timeStamps.push(null);
183
+ }
184
+ }
185
+ return this.encodeDigitColumns(timeStamps, 'bigint', typeLen, columnType);
186
+ }
187
+ }
188
+ exports.Stmt2BindParams = Stmt2BindParams;
@@ -0,0 +1,45 @@
1
+ import { FieldBindParams } from "./FieldBindParams";
2
+ import { ColumnInfo } from "./wsColumnInfo";
3
+ export interface IDataEncoder {
4
+ encode(): void;
5
+ addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
6
+ mergeParams(bindParams: StmtBindParams): void;
7
+ }
8
+ export declare abstract class StmtBindParams {
9
+ protected readonly precisionLength: number;
10
+ protected readonly _params: ColumnInfo[];
11
+ _fieldParams?: FieldBindParams[];
12
+ protected _dataTotalLen: number;
13
+ protected paramsCount: number;
14
+ protected _rows: number;
15
+ protected _bindCount: number;
16
+ constructor(precision?: number, paramsCount?: number);
17
+ abstract encode(): void;
18
+ abstract addParams(params: any[], dataType: string, typeLen: number, columnType: number): void;
19
+ addBindFieldParams(fieldParams: FieldBindParams): void;
20
+ abstract mergeParams(bindParams: StmtBindParams): void;
21
+ getBindCount(): number;
22
+ getDataRows(): number;
23
+ getDataTotalLen(): number;
24
+ getParams(): ColumnInfo[];
25
+ setBoolean(params: any[]): void;
26
+ setTinyInt(params: any[]): void;
27
+ setUTinyInt(params: any[]): void;
28
+ setSmallInt(params: any[]): void;
29
+ setUSmallInt(params: any[]): void;
30
+ setInt(params: any[]): void;
31
+ setUInt(params: any[]): void;
32
+ setBigint(params: any[]): void;
33
+ setUBigint(params: any[]): void;
34
+ setFloat(params: any[]): void;
35
+ setDouble(params: any[]): void;
36
+ setVarchar(params: any[]): void;
37
+ setBinary(params: any[]): void;
38
+ setNchar(params: any[]): void;
39
+ setJson(params: any[]): void;
40
+ setVarBinary(params: any[]): void;
41
+ setGeometry(params: any[]): void;
42
+ setTimestamp(params: any[]): void;
43
+ protected writeDataToBuffer(dataBuffer: DataView, params: any, dataType: string | undefined, typeLen: number, columnType: number, i: number): void;
44
+ }
45
+ //# sourceMappingURL=wsParamsBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsParamsBase.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsParamsBase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,WAAW,YAAY;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACtF,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CACjD;AAED,8BAAsB,cAAc;IAChC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAC,MAAM,CAAwB;IACjE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;IACzC,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;IACjC,SAAS,CAAC,aAAa,EAAC,MAAM,CAAK;IACnC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAK;IAClC,SAAS,CAAC,KAAK,SAAK;IACpB,SAAS,CAAC,UAAU,SAAK;gBAEb,SAAS,CAAC,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAcnD,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAE9F,kBAAkB,CAAC,WAAW,EAAE,eAAe,GAAG,IAAI;IAUtD,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAGtD,YAAY,IAAI,MAAM;IAItB,WAAW,IAAI,MAAM;IAIrB,eAAe,IAAI,MAAM;IAKlB,SAAS,IAAI,UAAU,EAAE;IAIhC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAOxB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAOxB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IAQzB,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IASzB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAQ1B,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE;IAQpB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;IAQrB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAQxB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAQtB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAQxB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAQvB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAOtB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;IAQrB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAO1B,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IAQzB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAQ1B,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAW,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,EAAC,MAAM,GAAG,IAAI;CAmEnJ"}