@tdengine/websocket 3.0.0 → 3.1.1
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/all_type_query.d.ts +2 -0
- package/lib/example/all_type_query.d.ts.map +1 -0
- package/lib/example/all_type_query.js +89 -0
- package/lib/example/all_type_stmt.d.ts +2 -0
- package/lib/example/all_type_stmt.d.ts.map +1 -0
- package/lib/example/all_type_stmt.js +130 -0
- package/lib/example/basicBatchTmq.d.ts +2 -0
- package/lib/example/basicBatchTmq.d.ts.map +1 -0
- package/lib/example/basicBatchTmq.js +129 -0
- package/lib/example/basicSchemaless.d.ts +2 -0
- package/lib/example/basicSchemaless.d.ts.map +1 -0
- package/lib/example/basicSchemaless.js +47 -0
- package/lib/example/basicSql.d.ts +2 -0
- package/lib/example/basicSql.d.ts.map +1 -0
- package/lib/example/basicSql.js +54 -0
- package/lib/example/basicStmt.d.ts +2 -0
- package/lib/example/basicStmt.d.ts.map +1 -0
- package/lib/example/basicStmt.js +72 -0
- package/lib/example/basicTmq.d.ts +2 -0
- package/lib/example/basicTmq.d.ts.map +1 -0
- package/lib/example/basicTmq.js +73 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +41 -0
- package/lib/src/client/wsClient.d.ts +22 -0
- package/lib/src/client/wsClient.d.ts.map +1 -0
- package/lib/src/client/wsClient.js +256 -0
- package/lib/src/client/wsConnector.d.ts +17 -0
- package/lib/src/client/wsConnector.d.ts.map +1 -0
- package/lib/src/client/wsConnector.js +140 -0
- package/lib/src/client/wsConnectorPool.d.ts +13 -0
- package/lib/src/client/wsConnectorPool.d.ts.map +1 -0
- package/lib/src/client/wsConnectorPool.js +107 -0
- package/lib/src/client/wsEventCallback.d.ts +22 -0
- package/lib/src/client/wsEventCallback.d.ts.map +1 -0
- package/lib/src/client/wsEventCallback.js +97 -0
- package/lib/src/client/wsResponse.d.ts +74 -0
- package/lib/src/client/wsResponse.d.ts.map +1 -0
- package/lib/src/client/wsResponse.js +103 -0
- package/lib/src/common/config.d.ts +22 -0
- package/lib/src/common/config.d.ts.map +1 -0
- package/lib/src/common/config.js +45 -0
- package/lib/src/common/constant.d.ts +35 -0
- package/lib/src/common/constant.d.ts.map +1 -0
- package/lib/src/common/constant.js +78 -0
- package/lib/src/common/log.d.ts +5 -0
- package/lib/src/common/log.d.ts.map +1 -0
- package/lib/src/common/log.js +40 -0
- package/lib/src/common/reqid.d.ts +8 -0
- package/lib/src/common/reqid.d.ts.map +1 -0
- package/lib/src/common/reqid.js +59 -0
- package/lib/src/common/taosResult.d.ts +57 -0
- package/lib/src/common/taosResult.d.ts.map +1 -0
- package/lib/src/common/taosResult.js +449 -0
- package/lib/src/common/ut8Helper.d.ts +2 -0
- package/lib/src/common/ut8Helper.d.ts.map +1 -0
- package/{src/ut8Helper.ts → lib/src/common/ut8Helper.js} +22 -21
- package/lib/src/common/utils.d.ts +7 -0
- package/lib/src/common/utils.d.ts.map +1 -0
- package/lib/src/common/utils.js +66 -0
- package/lib/src/common/wsError.d.ts +29 -0
- package/lib/src/common/wsError.d.ts.map +1 -0
- package/lib/src/common/wsError.js +51 -0
- package/{src/wsOptions.ts → lib/src/common/wsOptions.d.ts} +4 -2
- package/lib/src/common/wsOptions.d.ts.map +1 -0
- package/lib/src/common/wsOptions.js +2 -0
- package/lib/src/index.d.ts +9 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +58 -0
- package/lib/src/sql/wsProto.d.ts +26 -0
- package/lib/src/sql/wsProto.d.ts.map +1 -0
- package/lib/src/sql/wsProto.js +19 -0
- package/lib/src/sql/wsRows.d.ts +16 -0
- package/lib/src/sql/wsRows.d.ts.map +1 -0
- package/lib/src/sql/wsRows.js +87 -0
- package/lib/src/sql/wsSql.d.ts +24 -0
- package/lib/src/sql/wsSql.d.ts.map +1 -0
- package/lib/src/sql/wsSql.js +174 -0
- package/lib/src/stmt/wsParams.d.ts +41 -0
- package/lib/src/stmt/wsParams.d.ts.map +1 -0
- package/lib/src/stmt/wsParams.js +428 -0
- package/lib/src/stmt/wsProto.d.ts +27 -0
- package/lib/src/stmt/wsProto.d.ts.map +1 -0
- package/lib/src/stmt/wsProto.js +67 -0
- package/lib/src/stmt/wsStmt.d.ts +30 -0
- package/lib/src/stmt/wsStmt.d.ts.map +1 -0
- package/lib/src/stmt/wsStmt.js +207 -0
- package/lib/src/tmq/config.d.ts +14 -0
- package/lib/src/tmq/config.d.ts.map +1 -0
- package/lib/src/tmq/config.js +42 -0
- package/lib/src/tmq/constant.d.ts +100 -0
- package/lib/src/tmq/constant.d.ts.map +1 -0
- package/lib/src/tmq/constant.js +105 -0
- package/lib/src/tmq/tmqResponse.d.ts +92 -0
- package/lib/src/tmq/tmqResponse.d.ts.map +1 -0
- package/lib/src/tmq/tmqResponse.js +329 -0
- package/lib/src/tmq/wsTmq.d.ts +32 -0
- package/lib/src/tmq/wsTmq.d.ts.map +1 -0
- package/lib/src/tmq/wsTmq.js +319 -0
- package/lib/test/bulkPulling/log.test.d.ts +2 -0
- package/lib/test/bulkPulling/log.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/log.test.js +44 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts +2 -0
- package/lib/test/bulkPulling/queryTables.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/queryTables.test.js +297 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts +2 -0
- package/lib/test/bulkPulling/schemaless.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/schemaless.test.js +95 -0
- package/lib/test/bulkPulling/sql.test.d.ts +2 -0
- package/lib/test/bulkPulling/sql.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/sql.test.js +144 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.func.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.func.test.js +397 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts +2 -0
- package/lib/test/bulkPulling/stmt.type.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/stmt.type.test.js +269 -0
- package/lib/test/bulkPulling/tmq.test.d.ts +2 -0
- package/lib/test/bulkPulling/tmq.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/tmq.test.js +178 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts +2 -0
- package/lib/test/bulkPulling/wsConnectPool.test.d.ts.map +1 -0
- package/lib/test/bulkPulling/wsConnectPool.test.js +136 -0
- package/lib/test/utils.d.ts +18 -0
- package/lib/test/utils.d.ts.map +1 -0
- package/lib/test/utils.js +318 -0
- package/package.json +27 -14
- package/readme.md +302 -0
- package/README.md +0 -59
- package/dist/browser/index.js +0 -778
- package/dist/main/index.js +0 -711
- package/dist/main/index.js.map +0 -1
- package/dist/module/index.mjs +0 -704
- package/dist/module/index.mjs.map +0 -1
- package/dist/types.d.ts +0 -103
- package/dist/types.d.ts.map +0 -1
- package/example/basicUsageAsync.ts +0 -48
- package/example/basicUsagePrimse.ts +0 -43
- package/example/cloudUsage.ts +0 -55
- package/example/continousConnectAndVersion.ts +0 -16
- package/example/test.mjs +0 -51
- package/index.ts +0 -7
- package/jest.config.js +0 -8
- package/src/constant.ts +0 -74
- package/src/taosResult.ts +0 -269
- package/src/tdengineWebsocket.ts +0 -39
- package/src/wsClient.ts +0 -196
- package/src/wsError.ts +0 -5
- package/src/wsQuery.ts +0 -30
- package/src/wsQueryInterface.ts +0 -212
- package/src/wsQueryResponse.ts +0 -112
- package/tdengine-websocket-3.0.0.tgz +0 -0
- package/test/bulkPulling/connect.test.ts +0 -27
- package/test/bulkPulling/queryTables.test.ts +0 -274
- package/test/bulkPulling/version.test.ts +0 -19
- package/test/utils.ts +0 -235
- package/tsconfig.json +0 -101
|
@@ -2,13 +2,15 @@ export interface User {
|
|
|
2
2
|
user?: string;
|
|
3
3
|
passwd?: string;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
export interface Uri {
|
|
7
6
|
scheme: string;
|
|
8
7
|
url?: string;
|
|
9
8
|
host?: string | undefined | null;
|
|
10
9
|
path: '/rest/sql/' | string;
|
|
11
10
|
port?: number | undefined | null;
|
|
12
|
-
query?: {
|
|
11
|
+
query?: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
13
14
|
fragment?: string | undefined | null;
|
|
14
15
|
}
|
|
16
|
+
//# sourceMappingURL=wsOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsOptions.d.ts","sourceRoot":"","sources":["../../../src/common/wsOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACxC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WsSql } from './sql/wsSql';
|
|
2
|
+
import { WSConfig } from './common/config';
|
|
3
|
+
import { WsConsumer } from './tmq/wsTmq';
|
|
4
|
+
declare let sqlConnect: (conf: WSConfig) => Promise<WsSql>;
|
|
5
|
+
declare let tmqConnect: (configMap: Map<string, string>) => Promise<WsConsumer>;
|
|
6
|
+
declare let setLogLevel: (level: string) => void;
|
|
7
|
+
declare let destroy: () => void;
|
|
8
|
+
export { sqlConnect, tmqConnect, setLogLevel, destroy };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,IAAI,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
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.destroy = exports.setLogLevel = exports.tmqConnect = exports.sqlConnect = void 0;
|
|
27
|
+
const wsSql_1 = require("./sql/wsSql");
|
|
28
|
+
const wsTmq_1 = require("./tmq/wsTmq");
|
|
29
|
+
const log_1 = __importStar(require("./common/log"));
|
|
30
|
+
const wsConnectorPool_1 = require("./client/wsConnectorPool");
|
|
31
|
+
let sqlConnect = async (conf) => {
|
|
32
|
+
try {
|
|
33
|
+
return await wsSql_1.WsSql.open(conf);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
log_1.default.error(err);
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.sqlConnect = sqlConnect;
|
|
41
|
+
let tmqConnect = async (configMap) => {
|
|
42
|
+
try {
|
|
43
|
+
return await wsTmq_1.WsConsumer.newConsumer(configMap);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
log_1.default.error(err);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.tmqConnect = tmqConnect;
|
|
51
|
+
let setLogLevel = (level) => {
|
|
52
|
+
(0, log_1.setLevel)(level);
|
|
53
|
+
};
|
|
54
|
+
exports.setLogLevel = setLogLevel;
|
|
55
|
+
let destroy = () => {
|
|
56
|
+
wsConnectorPool_1.WebSocketConnectionPool.instance().destroyed();
|
|
57
|
+
};
|
|
58
|
+
exports.destroy = destroy;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface SchemalessMessageInfo {
|
|
2
|
+
action: string;
|
|
3
|
+
args: SchemalessParamsInfo;
|
|
4
|
+
}
|
|
5
|
+
export interface SchemalessParamsInfo {
|
|
6
|
+
req_id?: number | undefined | null;
|
|
7
|
+
protocol: number;
|
|
8
|
+
ttl?: number;
|
|
9
|
+
precision: string;
|
|
10
|
+
data: string;
|
|
11
|
+
}
|
|
12
|
+
export declare enum Precision {
|
|
13
|
+
NOT_CONFIGURED = "",
|
|
14
|
+
HOURS = "h",
|
|
15
|
+
MINUTES = "m",
|
|
16
|
+
SECONDS = "s",
|
|
17
|
+
MILLI_SECONDS = "ms",
|
|
18
|
+
MICRO_SECONDS = "u",
|
|
19
|
+
NANO_SECONDS = "ns"
|
|
20
|
+
}
|
|
21
|
+
export declare enum SchemalessProto {
|
|
22
|
+
InfluxDBLineProtocol = 1,
|
|
23
|
+
OpenTSDBTelnetLineProtocol = 2,
|
|
24
|
+
OpenTSDBJsonFormatProtocol = 3
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=wsProto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsProto.d.ts","sourceRoot":"","sources":["../../../src/sql/wsProto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,oBAAoB,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACjC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,SAAS;IACjB,cAAc,KAAK;IACnB,KAAK,MAAM;IACX,OAAO,MAAM;IACb,OAAO,MAAM;IACb,aAAa,OAAO;IACpB,aAAa,MAAM;IACnB,YAAY,OAAO;CACtB;AAED,oBAAY,eAAe;IACvB,oBAAoB,IAAU;IAC9B,0BAA0B,IAAI;IAC9B,0BAA0B,IAAI;CACjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemalessProto = exports.Precision = void 0;
|
|
4
|
+
var Precision;
|
|
5
|
+
(function (Precision) {
|
|
6
|
+
Precision["NOT_CONFIGURED"] = "";
|
|
7
|
+
Precision["HOURS"] = "h";
|
|
8
|
+
Precision["MINUTES"] = "m";
|
|
9
|
+
Precision["SECONDS"] = "s";
|
|
10
|
+
Precision["MILLI_SECONDS"] = "ms";
|
|
11
|
+
Precision["MICRO_SECONDS"] = "u";
|
|
12
|
+
Precision["NANO_SECONDS"] = "ns";
|
|
13
|
+
})(Precision || (exports.Precision = Precision = {}));
|
|
14
|
+
var SchemalessProto;
|
|
15
|
+
(function (SchemalessProto) {
|
|
16
|
+
SchemalessProto[SchemalessProto["InfluxDBLineProtocol"] = 1] = "InfluxDBLineProtocol";
|
|
17
|
+
SchemalessProto[SchemalessProto["OpenTSDBTelnetLineProtocol"] = 2] = "OpenTSDBTelnetLineProtocol";
|
|
18
|
+
SchemalessProto[SchemalessProto["OpenTSDBJsonFormatProtocol"] = 3] = "OpenTSDBJsonFormatProtocol";
|
|
19
|
+
})(SchemalessProto || (exports.SchemalessProto = SchemalessProto = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TDengineMeta } from '../common/taosResult';
|
|
2
|
+
import { WSQueryResponse } from '../client/wsResponse';
|
|
3
|
+
import { WsClient } from '../client/wsClient';
|
|
4
|
+
export declare class WSRows {
|
|
5
|
+
private _wsClient;
|
|
6
|
+
private readonly _wsQueryResponse;
|
|
7
|
+
private _taosResult;
|
|
8
|
+
private _isClose;
|
|
9
|
+
constructor(wsInterface: WsClient, resp: WSQueryResponse);
|
|
10
|
+
next(): Promise<boolean>;
|
|
11
|
+
private getBlockData;
|
|
12
|
+
getMeta(): Array<TDengineMeta> | null;
|
|
13
|
+
getData(): Array<any> | undefined;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=wsRows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsRows.d.ts","sourceRoot":"","sources":["../../../src/sql/wsRows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0B,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAwB,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAM9C,qBAAa,MAAM;IACf,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAW;gBAEf,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe;IAOlD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;YAoBhB,YAAY;IA4B1B,OAAO,IAAG,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI;IAIpC,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS;IAc3B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;CAQ9B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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.WSRows = void 0;
|
|
7
|
+
const taosResult_1 = require("../common/taosResult");
|
|
8
|
+
const wsError_1 = require("../common/wsError");
|
|
9
|
+
const wsResponse_1 = require("../client/wsResponse");
|
|
10
|
+
const log_1 = __importDefault(require("../common/log"));
|
|
11
|
+
const reqid_1 = require("../common/reqid");
|
|
12
|
+
const utils_1 = require("../common/utils");
|
|
13
|
+
const constant_1 = require("../common/constant");
|
|
14
|
+
class WSRows {
|
|
15
|
+
constructor(wsInterface, resp) {
|
|
16
|
+
this._wsClient = wsInterface;
|
|
17
|
+
this._wsQueryResponse = resp;
|
|
18
|
+
this._taosResult = new taosResult_1.TaosResult(resp);
|
|
19
|
+
this._isClose = false;
|
|
20
|
+
}
|
|
21
|
+
async next() {
|
|
22
|
+
if (this._wsQueryResponse.is_update || this._isClose) {
|
|
23
|
+
log_1.default.debug("WSRows::Next::End=>", this._taosResult, this._isClose);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
let data = this._taosResult.getData();
|
|
27
|
+
if (this._taosResult && data != null) {
|
|
28
|
+
if (data && Array.isArray(this._taosResult.getData()) && data.length > 0) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this._taosResult = await this.getBlockData();
|
|
33
|
+
if (this._taosResult.getData()) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
async getBlockData() {
|
|
39
|
+
try {
|
|
40
|
+
if (this._wsQueryResponse.id) {
|
|
41
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID());
|
|
42
|
+
let resp = await this._wsClient.sendBinaryMsg(bigintReqId, "binary_query", (0, utils_1.getBinarySql)(constant_1.FetchRawBlockMessage, bigintReqId, BigInt(this._wsQueryResponse.id)), false, true);
|
|
43
|
+
this._taosResult.addTotalTime(resp.totalTime);
|
|
44
|
+
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
45
|
+
if (wsResponse.code != 0) {
|
|
46
|
+
log_1.default.error("Executing SQL statement returns error: ", wsResponse.code, wsResponse.message);
|
|
47
|
+
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
48
|
+
}
|
|
49
|
+
if (wsResponse.finished == 1) {
|
|
50
|
+
this.close();
|
|
51
|
+
this._taosResult.setData(null);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
(0, taosResult_1.parseBlock)(wsResponse, this._taosResult);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return this._taosResult;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
this.close();
|
|
61
|
+
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getMeta() {
|
|
65
|
+
return this._taosResult.getMeta();
|
|
66
|
+
}
|
|
67
|
+
getData() {
|
|
68
|
+
if (this._wsQueryResponse.is_update) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
let data = this._taosResult.getData();
|
|
72
|
+
if (this._taosResult && data != null) {
|
|
73
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
74
|
+
return data.pop();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
async close() {
|
|
80
|
+
if (this._isClose) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this._isClose = true;
|
|
84
|
+
this._wsClient.freeResult(this._wsQueryResponse);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.WSRows = WSRows;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WSRows } from './wsRows';
|
|
2
|
+
import { TaosResult } from '../common/taosResult';
|
|
3
|
+
import { WSConfig } from '../common/config';
|
|
4
|
+
import { Precision, SchemalessProto } from './wsProto';
|
|
5
|
+
import { WsStmt } from '../stmt/wsStmt';
|
|
6
|
+
export declare class WsSql {
|
|
7
|
+
private wsConfig;
|
|
8
|
+
private _wsClient;
|
|
9
|
+
constructor(wsConfig: WSConfig);
|
|
10
|
+
static open(wsConfig: WSConfig): Promise<WsSql>;
|
|
11
|
+
state(): number;
|
|
12
|
+
/**
|
|
13
|
+
* return client version.
|
|
14
|
+
*/
|
|
15
|
+
version(): Promise<string>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
schemalessInsert(lines: Array<string>, protocol: SchemalessProto, precision: Precision, ttl: number, reqId?: number): Promise<void>;
|
|
18
|
+
stmtInit(reqId?: number): Promise<WsStmt>;
|
|
19
|
+
exec(sql: string, reqId?: number, action?: string): Promise<TaosResult>;
|
|
20
|
+
private executeSchemalessInsert;
|
|
21
|
+
query(sql: string, reqId?: number): Promise<WSRows>;
|
|
22
|
+
private getSql;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=wsSql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsSql.d.ts","sourceRoot":"","sources":["../../../src/sql/wsSql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAc,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG3C,OAAO,EAAE,SAAS,EAAyB,eAAe,EAAE,MAAM,WAAW,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAMvC,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,SAAS,CAAW;gBAChB,QAAQ,EAAC,QAAQ;WAMhB,IAAI,CAAC,QAAQ,EAAC,QAAQ,GAAE,OAAO,CAAC,KAAK,CAAC;IAmBnD,KAAK;IAIL;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC;IAIrB,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnI,QAAQ,CAAC,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBxC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,GAAC,MAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;YA4C9E,uBAAuB;IAa/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAWxD,OAAO,CAAC,MAAM;CAajB"}
|
|
@@ -0,0 +1,174 @@
|
|
|
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.WsSql = void 0;
|
|
7
|
+
const wsRows_1 = require("./wsRows");
|
|
8
|
+
const taosResult_1 = require("../common/taosResult");
|
|
9
|
+
const wsClient_1 = require("../client/wsClient");
|
|
10
|
+
const wsError_1 = require("../common/wsError");
|
|
11
|
+
const utils_1 = require("../common/utils");
|
|
12
|
+
const wsResponse_1 = require("../client/wsResponse");
|
|
13
|
+
const wsStmt_1 = require("../stmt/wsStmt");
|
|
14
|
+
const reqid_1 = require("../common/reqid");
|
|
15
|
+
const constant_1 = require("../common/constant");
|
|
16
|
+
const log_1 = __importDefault(require("../common/log"));
|
|
17
|
+
class WsSql {
|
|
18
|
+
constructor(wsConfig) {
|
|
19
|
+
let url = (0, utils_1.getUrl)(wsConfig);
|
|
20
|
+
this._wsClient = new wsClient_1.WsClient(url, wsConfig.getTimeOut());
|
|
21
|
+
this.wsConfig = wsConfig;
|
|
22
|
+
}
|
|
23
|
+
static async open(wsConfig) {
|
|
24
|
+
if (!wsConfig.getUrl()) {
|
|
25
|
+
throw new wsError_1.WebSocketInterfaceError(wsError_1.ErrorCode.ERR_INVALID_URL, 'invalid url, password or username needed.');
|
|
26
|
+
}
|
|
27
|
+
let wsSql = new WsSql(wsConfig);
|
|
28
|
+
let database = wsConfig.getDb();
|
|
29
|
+
try {
|
|
30
|
+
await wsSql._wsClient.connect(database);
|
|
31
|
+
if (database && database.length > 0) {
|
|
32
|
+
await wsSql.exec(`use ${database}`);
|
|
33
|
+
}
|
|
34
|
+
return wsSql;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
log_1.default.error(e.code, e.message);
|
|
38
|
+
throw (e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
state() {
|
|
42
|
+
return this._wsClient.getState();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* return client version.
|
|
46
|
+
*/
|
|
47
|
+
async version() {
|
|
48
|
+
return await this._wsClient.version();
|
|
49
|
+
}
|
|
50
|
+
async close() {
|
|
51
|
+
await this._wsClient.close();
|
|
52
|
+
}
|
|
53
|
+
async schemalessInsert(lines, protocol, precision, ttl, reqId) {
|
|
54
|
+
let data = '';
|
|
55
|
+
if (!lines || lines.length == 0 || !protocol) {
|
|
56
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_PARAMS, 'WsSchemaless Insert params is error!');
|
|
57
|
+
}
|
|
58
|
+
lines.forEach((element, index) => {
|
|
59
|
+
data += element;
|
|
60
|
+
if (index < lines.length - 1) {
|
|
61
|
+
data += '\n';
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
let queryMsg = {
|
|
65
|
+
action: 'insert',
|
|
66
|
+
args: {
|
|
67
|
+
req_id: reqid_1.ReqId.getReqID(reqId),
|
|
68
|
+
protocol: protocol,
|
|
69
|
+
precision: precision,
|
|
70
|
+
data: data,
|
|
71
|
+
ttl: ttl,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return await this.executeSchemalessInsert(queryMsg);
|
|
75
|
+
}
|
|
76
|
+
async stmtInit(reqId) {
|
|
77
|
+
if (this._wsClient) {
|
|
78
|
+
try {
|
|
79
|
+
let precision = constant_1.PrecisionLength["ms"];
|
|
80
|
+
if (this.wsConfig.getDb()) {
|
|
81
|
+
let sql = "select `precision` from information_schema.ins_databases where name = '" + this.wsConfig.getDb() + "'";
|
|
82
|
+
let result = await this.exec(sql);
|
|
83
|
+
let data = result.getData();
|
|
84
|
+
if (data && data[0] && data[0][0]) {
|
|
85
|
+
precision = constant_1.PrecisionLength[data[0][0]];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return await wsStmt_1.WsStmt.newStmt(this._wsClient, precision, reqId);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
log_1.default.error(e.code, e.message);
|
|
92
|
+
throw (e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw (new wsError_1.TDWebSocketClientError(wsError_1.ErrorCode.ERR_CONNECTION_CLOSED, "stmt connect closed"));
|
|
96
|
+
}
|
|
97
|
+
async exec(sql, reqId, action = 'binary_query') {
|
|
98
|
+
try {
|
|
99
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
100
|
+
let wsQueryResponse = await this._wsClient.sendBinaryMsg(bigintReqId, action, (0, utils_1.getBinarySql)(constant_1.BinaryQueryMessage, bigintReqId, BigInt(0), sql));
|
|
101
|
+
let taosResult = new taosResult_1.TaosResult(wsQueryResponse);
|
|
102
|
+
if (wsQueryResponse.is_update) {
|
|
103
|
+
return taosResult;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
if (wsQueryResponse.id) {
|
|
107
|
+
try {
|
|
108
|
+
while (true) {
|
|
109
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
110
|
+
let resp = await this._wsClient.sendBinaryMsg(bigintReqId, action, (0, utils_1.getBinarySql)(constant_1.FetchRawBlockMessage, bigintReqId, BigInt(wsQueryResponse.id)), false, true);
|
|
111
|
+
taosResult.addTotalTime(resp.totalTime);
|
|
112
|
+
let wsResponse = new wsResponse_1.WSFetchBlockResponse(resp.msg);
|
|
113
|
+
if (wsResponse.code != 0) {
|
|
114
|
+
log_1.default.error("Executing SQL statement returns error: ", wsResponse.code, wsResponse.message);
|
|
115
|
+
throw new wsError_1.TaosResultError(wsResponse.code, wsResponse.message);
|
|
116
|
+
}
|
|
117
|
+
if (wsResponse.finished == 1) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
(0, taosResult_1.parseBlock)(wsResponse, taosResult);
|
|
121
|
+
}
|
|
122
|
+
return taosResult;
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
this._wsClient.freeResult(wsQueryResponse);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
throw new wsError_1.TaosResultError(wsError_1.ErrorCode.ERR_INVALID_FETCH_MESSAGE_DATA, "The result data of the query is incorrect");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async executeSchemalessInsert(queryMsg) {
|
|
139
|
+
return new Promise(async (resolve, reject) => {
|
|
140
|
+
try {
|
|
141
|
+
let reqMsg = JSON.stringify(queryMsg);
|
|
142
|
+
let result = await this._wsClient.exec(reqMsg);
|
|
143
|
+
log_1.default.debug("executeSchemalessInsert:", reqMsg, result);
|
|
144
|
+
resolve();
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
reject(new wsError_1.TaosResultError(e.code, e.message));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async query(sql, reqId) {
|
|
152
|
+
try {
|
|
153
|
+
let bigintReqId = BigInt(reqid_1.ReqId.getReqID(reqId));
|
|
154
|
+
let wsQueryResponse = await this._wsClient.sendBinaryMsg(bigintReqId, 'binary_query', (0, utils_1.getBinarySql)(constant_1.BinaryQueryMessage, bigintReqId, BigInt(0), sql));
|
|
155
|
+
return new wsRows_1.WSRows(this._wsClient, wsQueryResponse);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
throw new wsError_1.TaosResultError(err.code, err.message);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getSql(sql, reqId, action = 'query') {
|
|
162
|
+
// construct msg
|
|
163
|
+
let queryMsg = {
|
|
164
|
+
action: action,
|
|
165
|
+
args: {
|
|
166
|
+
req_id: reqid_1.ReqId.getReqID(reqId),
|
|
167
|
+
sql: sql,
|
|
168
|
+
id: 0
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
return JSON.stringify(queryMsg);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.WsSql = WsSql;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare class ColumnInfo {
|
|
2
|
+
data: ArrayBuffer;
|
|
3
|
+
length: number;
|
|
4
|
+
type: number;
|
|
5
|
+
typeLen: number;
|
|
6
|
+
constructor([length, data]: [number, ArrayBuffer], type: number, typeLen: number);
|
|
7
|
+
}
|
|
8
|
+
export declare class StmtBindParams {
|
|
9
|
+
private readonly precisionLength;
|
|
10
|
+
private readonly _params;
|
|
11
|
+
private _dataTotalLen;
|
|
12
|
+
private _rows;
|
|
13
|
+
constructor(precision?: number);
|
|
14
|
+
getDataRows(): number;
|
|
15
|
+
getDataTotalLen(): number;
|
|
16
|
+
getParams(): ColumnInfo[];
|
|
17
|
+
setBoolean(params: any[]): void;
|
|
18
|
+
setTinyInt(params: any[]): void;
|
|
19
|
+
setUTinyInt(params: any[]): void;
|
|
20
|
+
setSmallInt(params: any[]): void;
|
|
21
|
+
setUSmallInt(params: any[]): void;
|
|
22
|
+
setInt(params: any[]): void;
|
|
23
|
+
setUInt(params: any[]): void;
|
|
24
|
+
setBigint(params: any[]): void;
|
|
25
|
+
setUBigint(params: any[]): void;
|
|
26
|
+
setFloat(params: any[]): void;
|
|
27
|
+
setDouble(params: any[]): void;
|
|
28
|
+
setVarchar(params: any[]): void;
|
|
29
|
+
setBinary(params: any[]): void;
|
|
30
|
+
setNchar(params: any[]): void;
|
|
31
|
+
setJson(params: any[]): void;
|
|
32
|
+
setVarBinary(params: any[]): void;
|
|
33
|
+
setGeometry(params: any[]): void;
|
|
34
|
+
setTimestamp(params: any[]): void;
|
|
35
|
+
private encodeDigitColumns;
|
|
36
|
+
private encodeVarLengthColumn;
|
|
37
|
+
private getBinaryColumnArrayBuffer;
|
|
38
|
+
private encodeNcharColumn;
|
|
39
|
+
private countBigintDigits;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=wsParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsParams.d.ts","sourceRoot":"","sources":["../../../src/stmt/wsParams.ts"],"names":[],"mappings":"AAKA,qBAAa,UAAU;IACnB,IAAI,EAAC,WAAW,CAAC;IACjB,MAAM,EAAC,MAAM,CAAC;IACd,IAAI,EAAC,MAAM,CAAC;IACZ,OAAO,EAAC,MAAM,CAAC;gBACH,CAAC,MAAM,EAAC,IAAI,CAAC,EAAC,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,IAAI,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM;CAM/E;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA+B;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,KAAK,CAAK;gBACN,SAAS,CAAC,EAAC,MAAM;IAQtB,WAAW,IAAI,MAAM;IAIrB,eAAe,IAAI,MAAM;IAIzB,SAAS,IAAI,UAAU,EAAE;IAIhC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IASxB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;IAQxB,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;IAKxB,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IAIvB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAItB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;IAIrB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAI1B,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE;IAIzB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE;IAwE1B,OAAO,CAAC,kBAAkB;IAyF1B,OAAO,CAAC,qBAAqB;IAiD7B,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,iBAAiB;IAuDzB,OAAO,CAAC,iBAAiB;CAa5B"}
|