@tdengine/websocket 3.1.7 → 3.1.9

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 (53) hide show
  1. package/lib/src/client/wsClient.d.ts +3 -0
  2. package/lib/src/client/wsClient.d.ts.map +1 -1
  3. package/lib/src/client/wsClient.js +39 -14
  4. package/lib/src/client/wsConnector.d.ts.map +1 -1
  5. package/lib/src/client/wsConnector.js +4 -10
  6. package/lib/src/client/wsConnectorPool.d.ts.map +1 -1
  7. package/lib/src/client/wsConnectorPool.js +16 -5
  8. package/lib/src/client/wsResponse.d.ts +2 -16
  9. package/lib/src/client/wsResponse.d.ts.map +1 -1
  10. package/lib/src/client/wsResponse.js +3 -11
  11. package/lib/src/common/config.d.ts +3 -0
  12. package/lib/src/common/config.d.ts.map +1 -1
  13. package/lib/src/common/config.js +6 -0
  14. package/lib/src/common/constant.d.ts +9 -1
  15. package/lib/src/common/constant.d.ts.map +1 -1
  16. package/lib/src/common/constant.js +10 -1
  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/wsRows.d.ts.map +1 -1
  24. package/lib/src/sql/wsRows.js +10 -4
  25. package/lib/src/sql/wsSql.d.ts.map +1 -1
  26. package/lib/src/sql/wsSql.js +12 -2
  27. package/lib/src/stmt/wsProto.d.ts +3 -3
  28. package/lib/src/stmt/wsProto.js +2 -2
  29. package/lib/src/stmt/wsStmt.d.ts +1 -1
  30. package/lib/src/stmt/wsStmt.d.ts.map +1 -1
  31. package/lib/src/stmt/wsStmt.js +2 -1
  32. package/lib/src/tmq/config.d.ts.map +1 -1
  33. package/lib/src/tmq/config.js +1 -1
  34. package/lib/src/tmq/constant.d.ts +2 -0
  35. package/lib/src/tmq/constant.d.ts.map +1 -1
  36. package/lib/src/tmq/constant.js +2 -0
  37. package/lib/src/tmq/tmqResponse.d.ts +5 -5
  38. package/lib/src/tmq/tmqResponse.js +7 -7
  39. package/lib/src/tmq/wsTmq.d.ts +1 -0
  40. package/lib/src/tmq/wsTmq.d.ts.map +1 -1
  41. package/lib/src/tmq/wsTmq.js +9 -5
  42. package/lib/test/bulkPulling/cloud.tmq.test.d.ts +2 -0
  43. package/lib/test/bulkPulling/cloud.tmq.test.d.ts.map +1 -0
  44. package/lib/test/bulkPulling/cloud.tmq.test.js +79 -0
  45. package/lib/test/bulkPulling/decimal.test.d.ts +2 -0
  46. package/lib/test/bulkPulling/decimal.test.d.ts.map +1 -0
  47. package/lib/test/bulkPulling/decimal.test.js +129 -0
  48. package/lib/test/bulkPulling/sql.test.js +36 -10
  49. package/lib/test/bulkPulling/stmt.func.test.js +2 -0
  50. package/lib/test/bulkPulling/stmt.type.test.js +41 -0
  51. package/lib/test/bulkPulling/tmq.test.js +2 -0
  52. package/lib/test/bulkPulling/wsConnectPool.test.js +2 -2
  53. package/package.json +2 -3
@@ -16,9 +16,9 @@ beforeAll(async () => {
16
16
  let wsSql = await wsSql_1.WsSql.open(conf);
17
17
  await wsSql.exec(`CREATE USER user1 PASS '${password1}'`);
18
18
  await wsSql.exec(`CREATE USER user2 PASS '${password2}'`);
19
- await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
19
+ await wsSql.exec('create database if not exists sql_test KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
20
20
  await (0, utils_1.Sleep)(100);
21
- await wsSql.exec('use power');
21
+ await wsSql.exec('use sql_test');
22
22
  await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
23
23
  await wsSql.close();
24
24
  });
@@ -26,12 +26,22 @@ describe('TDWebSocket.WsSql()', () => {
26
26
  jest.setTimeout(20 * 1000);
27
27
  test('normal connect', async () => {
28
28
  let wsSql = null;
29
- let conf = new config_1.WSConfig(dns);
29
+ let conf = new config_1.WSConfig('');
30
+ conf.setUrl(dns);
30
31
  conf.setUser('root');
31
32
  conf.setPwd('taosdata');
32
- conf.setDb('power');
33
+ conf.setDb('sql_test');
34
+ conf.setTimezone('America/New_York');
35
+ conf.setTimeOut(6000);
33
36
  wsSql = await wsSql_1.WsSql.open(conf);
34
37
  expect(wsSql.state()).toBeGreaterThan(0);
38
+ let wsRows = await wsSql.query('select timezone()');
39
+ while (await wsRows.next()) {
40
+ let result = wsRows.getData();
41
+ console.log(result);
42
+ expect(result).toBeTruthy();
43
+ expect(JSON.stringify(result)).toContain('America/New_York');
44
+ }
35
45
  await wsSql.close();
36
46
  });
37
47
  test('special characters connect1', async () => {
@@ -78,6 +88,22 @@ describe('TDWebSocket.WsSql()', () => {
78
88
  }
79
89
  }
80
90
  });
91
+ test('connect url', async () => {
92
+ let url = 'ws://root:taosdata@localhost:6041/information_schema?timezone=Asia/Shanghai';
93
+ let conf = new config_1.WSConfig(url);
94
+ let wsSql = await wsSql_1.WsSql.open(conf);
95
+ let version = await wsSql.version();
96
+ console.log(version);
97
+ expect(version).toBeTruthy();
98
+ let wsRows = await wsSql.query('select timezone()');
99
+ while (await wsRows.next()) {
100
+ let result = wsRows.getData();
101
+ console.log(result);
102
+ expect(result).toBeTruthy();
103
+ expect(JSON.stringify(result)).toContain('Asia/Shanghai');
104
+ }
105
+ await wsSql.close();
106
+ });
81
107
  test('get taosc version', async () => {
82
108
  let conf = new config_1.WSConfig(dns);
83
109
  conf.setUser('root');
@@ -103,7 +129,7 @@ describe('TDWebSocket.WsSql()', () => {
103
129
  conf.setUser('root');
104
130
  conf.setPwd('taosdata');
105
131
  let wsSql = await wsSql_1.WsSql.open(conf);
106
- let taosResult = await wsSql.exec('create database if not exists power KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
132
+ let taosResult = await wsSql.exec('create database if not exists sql_create KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;');
107
133
  await wsSql.close();
108
134
  console.log(taosResult);
109
135
  expect(taosResult).toBeTruthy();
@@ -113,7 +139,7 @@ describe('TDWebSocket.WsSql()', () => {
113
139
  conf.setUser('root');
114
140
  conf.setPwd('taosdata');
115
141
  let wsSql = await wsSql_1.WsSql.open(conf);
116
- let taosResult = await wsSql.exec('use power');
142
+ let taosResult = await wsSql.exec('use sql_test');
117
143
  console.log(taosResult);
118
144
  expect(taosResult).toBeTruthy();
119
145
  taosResult = await wsSql.exec('CREATE STABLE if not exists meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);');
@@ -126,7 +152,7 @@ describe('TDWebSocket.WsSql()', () => {
126
152
  conf.setUser('root');
127
153
  conf.setPwd('taosdata');
128
154
  let wsSql = await wsSql_1.WsSql.open(conf);
129
- let taosResult = await wsSql.exec('use power');
155
+ let taosResult = await wsSql.exec('use sql_test');
130
156
  console.log(taosResult);
131
157
  expect(taosResult).toBeTruthy();
132
158
  taosResult = await wsSql.exec('describe meters');
@@ -141,7 +167,7 @@ describe('TDWebSocket.WsSql()', () => {
141
167
  conf.setUser('root');
142
168
  conf.setPwd('taosdata');
143
169
  let wsSql = await wsSql_1.WsSql.open(conf);
144
- let taosResult = await wsSql.exec('use power');
170
+ let taosResult = await wsSql.exec('use sql_test');
145
171
  console.log(taosResult);
146
172
  expect(taosResult).toBeTruthy();
147
173
  for (let i = 0; i < 10; i++) {
@@ -163,7 +189,7 @@ describe('TDWebSocket.WsSql()', () => {
163
189
  conf.setUser('root');
164
190
  conf.setPwd('taosdata');
165
191
  let wsSql = await wsSql_1.WsSql.open(conf);
166
- let taosResult = await wsSql.exec('use power');
192
+ let taosResult = await wsSql.exec('use sql_test');
167
193
  console.log(taosResult);
168
194
  expect(taosResult).toBeTruthy();
169
195
  let wsRows = await wsSql.query('select * from meters');
@@ -176,7 +202,7 @@ afterAll(async () => {
176
202
  conf.setUser('root');
177
203
  conf.setPwd('taosdata');
178
204
  let wsSql = await wsSql_1.WsSql.open(conf);
179
- await wsSql.exec('drop database power');
205
+ await wsSql.exec('drop database sql_test');
180
206
  await wsSql.exec('DROP USER user1;');
181
207
  await wsSql.exec('DROP USER user2;');
182
208
  await wsSql.close();
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
4
4
  const config_1 = require("../../src/common/config");
5
+ const log_1 = require("../../src/common/log");
5
6
  const wsSql_1 = require("../../src/sql/wsSql");
6
7
  let dns = 'ws://localhost:6041';
8
+ (0, log_1.setLevel)("debug");
7
9
  beforeAll(async () => {
8
10
  let conf = new config_1.WSConfig(dns);
9
11
  conf.setUser('root');
@@ -264,6 +264,47 @@ describe('TDWebSocket.Stmt()', () => {
264
264
  await connector.close();
265
265
  });
266
266
  });
267
+ test('test bind exception cases', async () => {
268
+ let wsConf = new config_1.WSConfig(dsn);
269
+ let connector = await wsSql_1.WsSql.open(wsConf);
270
+ let stmt = await connector.stmtInit();
271
+ const params = stmt.newStmtParam();
272
+ const emptyArrayMethods = [
273
+ { method: 'setBoolean', name: 'SetBooleanColumn' },
274
+ { method: 'setTinyInt', name: 'SetTinyIntColumn' },
275
+ { method: 'setUTinyInt', name: 'SetUTinyIntColumn' },
276
+ { method: 'setSmallInt', name: 'SetSmallIntColumn' },
277
+ { method: 'setUSmallInt', name: 'SetSmallIntColumn' },
278
+ { method: 'setInt', name: 'SetIntColumn' },
279
+ { method: 'setUInt', name: 'SetUIntColumn' },
280
+ { method: 'setBigint', name: 'SetBigIntColumn' },
281
+ { method: 'setUBigint', name: 'SetUBigIntColumn' },
282
+ { method: 'setFloat', name: 'SetFloatColumn' },
283
+ { method: 'setDouble', name: 'SetDoubleColumn' },
284
+ { method: 'setTimestamp', name: 'SeTimestampColumn' }
285
+ ];
286
+ emptyArrayMethods.forEach(({ method, name }) => {
287
+ expect(() => {
288
+ params[method]([]);
289
+ }).toThrow(`${name} params is invalid!`);
290
+ expect(() => {
291
+ params[method](null);
292
+ }).toThrow(`${name} params is invalid!`);
293
+ expect(() => {
294
+ params[method](undefined);
295
+ }).toThrow(`${name} params is invalid!`);
296
+ });
297
+ expect(() => {
298
+ params.setBoolean(['not boolean']);
299
+ }).toThrow('SetTinyIntColumn params is invalid!');
300
+ expect(() => {
301
+ params.setTinyInt(['not number']);
302
+ }).toThrow('SetTinyIntColumn params is invalid!');
303
+ expect(() => {
304
+ params.setBigint(['not bigint']);
305
+ }).toThrow('SetTinyIntColumn params is invalid!');
306
+ await connector.close();
307
+ });
267
308
  afterAll(async () => {
268
309
  let conf = new config_1.WSConfig(dsn);
269
310
  let ws = await wsSql_1.WsSql.open(conf);
@@ -6,6 +6,8 @@ const config_1 = require("../../src/common/config");
6
6
  const wsSql_1 = require("../../src/sql/wsSql");
7
7
  const utils_1 = require("../utils");
8
8
  const wsConnectorPool_1 = require("../../src/client/wsConnectorPool");
9
+ const log_1 = require("../../src/common/log");
10
+ (0, log_1.setLevel)("debug");
9
11
  const stable = 'st';
10
12
  const db = 'ws_tmq_test';
11
13
  const topics = ['topic_ws_bean'];
@@ -80,7 +80,7 @@ async function tmqConnect() {
80
80
  try {
81
81
  consumer = await wsTmq_1.WsConsumer.newConsumer(configMap);
82
82
  await consumer.subscribe(topics);
83
- let res = await consumer.poll(500);
83
+ let res = await consumer.poll(100);
84
84
  for (let [key, value] of res) {
85
85
  console.log(key, value.getMeta());
86
86
  let data = value.getData();
@@ -118,7 +118,7 @@ beforeAll(async () => {
118
118
  await ws.close();
119
119
  });
120
120
  describe('TDWebSocket.WsSql()', () => {
121
- jest.setTimeout(20 * 1000);
121
+ jest.setTimeout(60 * 1000);
122
122
  test('ReqId', async () => {
123
123
  const allp = [];
124
124
  for (let i = 0; i < 10; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdengine/websocket",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
5
5
  "source": "index.ts",
6
6
  "main": "lib/index.js",
@@ -47,7 +47,6 @@
47
47
  "winston": "^3.17.0",
48
48
  "winston-daily-rotate-file": "^5.0.0"
49
49
  },
50
-
51
50
  "devDependencies": {
52
51
  "@parcel/packager-ts": "^2.7.0",
53
52
  "@parcel/transformer-typescript-types": "^2.7.0",
@@ -56,7 +55,7 @@
56
55
  "@types/node": "^18.0.0",
57
56
  "@types/uuid": "^9.0.8",
58
57
  "@types/websocket": "^1.0",
59
- "jest": "^29.2.2",
58
+ "jest": "^29.7.0",
60
59
  "parcel": "^2.7.0",
61
60
  "qingwa": "^1.0.7",
62
61
  "ts-jest": "^29.0.3",