Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
TDENGINE_CLOUD_TOKEN: ${{ secrets.TDENGINE_CLOUD_TOKEN }}
TDENGINE_TEST_USERNAME: ${{ secrets.TDENGINE_TEST_USERNAME }}
TDENGINE_TEST_PASSWORD: ${{ secrets.TDENGINE_TEST_PASSWORD }}
TEST_3360: true
run: |
npm install
npm list
Expand Down
4 changes: 2 additions & 2 deletions nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tdengine/websocket",
"version": "3.2.2",
"version": "3.2.3",
"description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
"source": "index.ts",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions nodejs/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require("path");
const { resolve, parse } = path;

const tsFile = /\/src\/.*.ts$/;

async function dir(folder, ts = []) {
let files = await readdir(folder);
for (let f of files) {
Expand Down
3 changes: 2 additions & 1 deletion nodejs/src/client/wsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ReqId } from "../common/reqid";
import logger from "../common/log";
import { safeDecodeURIComponent, compareVersions, maskSensitiveForLog, maskUrlForLog } from "../common/utils";
import { w3cwebsocket } from "websocket";
import { TSDB_OPTION_CONNECTION } from "../common/constant";
import { ConnectorInfo, TSDB_OPTION_CONNECTION } from "../common/constant";

export class WsClient {
private _wsConnector?: WebSocketConnector;
Expand Down Expand Up @@ -44,6 +44,7 @@ export class WsClient {
user: safeDecodeURIComponent(this._url.username),
password: safeDecodeURIComponent(this._url.password),
db: database,
connector: ConnectorInfo,
...(this._timezone && { tz: this._timezone }),
...(this._bearerToken && { bearer_token: this._bearerToken }),
},
Expand Down
3 changes: 3 additions & 0 deletions nodejs/src/common/constant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pkg from "../../package.json";

export interface IndexableString {
[index: number]: string;
}
Expand All @@ -10,6 +12,7 @@ export interface NumberIndexable {
[index: number]: number;
}

export const ConnectorInfo = `nodejs-ws-v${pkg.version}-ncid000`;
export const BinaryQueryMessage: bigint = BigInt(6);
export const FetchRawBlockMessage: bigint = BigInt(7);
export const MinStmt2Version: string = "3.3.6.0";
Expand Down
1 change: 1 addition & 0 deletions nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ let setLogLevel = (level: string) => {
let destroy = () => {
WebSocketConnectionPool.instance().destroyed();
};

export { sqlConnect, tmqConnect, setLogLevel, destroy };
1 change: 1 addition & 0 deletions nodejs/src/tmq/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class TmqConfig {
} else {
this.user = this.url.username;
}

if (this.password) {
this.url.password = this.password;
} else {
Expand Down
2 changes: 2 additions & 0 deletions nodejs/src/tmq/wsTmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ReqId } from "../common/reqid";
import logger from "../common/log";
import { WSFetchBlockResponse } from "../client/wsResponse";
import { maskTmqConfigForLog, maskUrlForLog } from "../common/utils";
import { ConnectorInfo } from "../common/constant";

export class WsConsumer {
private _wsClient: WsClient;
Expand Down Expand Up @@ -110,6 +111,7 @@ export class WsConsumer {
auto_commit: this._wsConfig.auto_commit,
auto_commit_interval_ms: this._wsConfig.auto_commit_interval_ms,
config: this._wsConfig.otherConfigs,
connector: ConnectorInfo,
},
};
this._topics = topics;
Expand Down
22 changes: 22 additions & 0 deletions nodejs/test/bulkPulling/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ describe("TDWebSocket.WsSql()", () => {
message: expect.stringMatching(/invalid url/i),
});
});

const maybeConnectorVersionTest = process.env.TEST_3360 ? test.skip : test;

maybeConnectorVersionTest("connector version info", async () => {
let conf: WSConfig = new WSConfig(dsn);
conf.setUser("root");
conf.setPwd("taosdata");
let wsSql = await WsSql.open(conf);
await Sleep(2000);
let wsRows = await wsSql.query("show connections");
let hasNodejsWs = false;
while (await wsRows.next()) {
const data = wsRows.getData();
if (Array.isArray(data) && data.some(v => typeof v === "string" && v.includes("nodejs-ws"))) {
hasNodejsWs = true;
break;
}
}
expect(hasNodejsWs).toBe(true);
await wsRows.close();
await wsSql.close();
});
});

afterAll(async () => {
Expand Down
28 changes: 28 additions & 0 deletions nodejs/test/bulkPulling/tmq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,34 @@ describe("TDWebSocket.Tmq()", () => {
message: expect.stringMatching(/invalid url/i),
});
});

const maybeConnectorVersionTest = process.env.TEST_3360 ? test.skip : test;

maybeConnectorVersionTest("connector version info", async () => {
let consumer = await WsConsumer.newConsumer(configMap);
await consumer.subscribe(topics);

let conf: WSConfig = new WSConfig("ws://localhost:6041");
conf.setUser("root");
conf.setPwd("taosdata");
let wsSql = await WsSql.open(conf);
await Sleep(2000);

let wsRows = await wsSql.query("show connections");
let count = 0;
while (await wsRows.next()) {
const data = wsRows.getData();
if (Array.isArray(data) && data.some(v => typeof v === "string" && v.includes("nodejs-ws"))) {
count++;
}
}
expect(count).toBeGreaterThanOrEqual(2);
await wsRows.close();
await wsSql.close();

await consumer.unsubscribe();
await consumer.close();
});
});

afterAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion nodejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
"resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
Expand Down
Loading