Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -61,6 +61,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 @@ -109,6 +110,7 @@ export class WsConsumer {
auto_commit: String(this._wsConfig.auto_commit),
auto_commit_interval_ms: String(this._wsConfig.auto_commit_interval_ms),
config: Object.fromEntries(this._wsConfig.otherConfigs),
connector: ConnectorInfo,
},
};
this._topics = topics;
Expand Down
22 changes: 21 additions & 1 deletion nodejs/test/bulkPulling/sql.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebSocketConnectionPool } from "../../src/client/wsConnectorPool";
import { WSConfig } from "../../src/common/config";
import { WsSql } from "../../src/sql/wsSql";
import { Sleep, testPassword, testUsername, testEnterprise } from "../utils";
import { Sleep, testPassword, testUsername, testEnterprise, testNon3360 } from "../utils";
import { setLevel } from "../../src/common/log";

let dsn = "ws://localhost:6041";
Expand Down Expand Up @@ -326,6 +326,26 @@ describe("TDWebSocket.WsSql()", () => {
message: expect.stringMatching(/invalid url/i),
});
});

testNon3360("connector version info", async () => {
const conf = new WSConfig(dsn);
conf.setUser(testUsername());
conf.setPwd(testPassword());
const wsSql = await WsSql.open(conf);
await Sleep(2000);
const 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: 27 additions & 1 deletion nodejs/test/bulkPulling/tmq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TMQConstants } from "../../src/tmq/constant";
import { WsConsumer } from "../../src/tmq/wsTmq";
import { WSConfig } from "../../src/common/config";
import { WsSql } from "../../src/sql/wsSql";
import { createSTable, insertStable, testPassword, testUsername, Sleep, testEnterprise } from "../utils";
import { createSTable, insertStable, testPassword, testUsername, Sleep, testEnterprise, testNon3360 } from "../utils";
import { WebSocketConnectionPool } from "../../src/client/wsConnectorPool";
import { setLevel } from "../../src/common/log";

Expand Down Expand Up @@ -510,6 +510,32 @@ describe("TDWebSocket.Tmq()", () => {
message: expect.stringMatching(/invalid url/i),
});
});

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

const conf = new WSConfig("ws://localhost:6041");
conf.setUser(testUsername());
conf.setPwd(testPassword());
const wsSql = await WsSql.open(conf);
await Sleep(2000);

const 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
1 change: 1 addition & 0 deletions nodejs/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,4 @@ export function testPassword(): string {
}

export const testEnterprise = process.env.TEST_ENTERPRISE?.toLowerCase() === "true" ? test : test.skip;
export const testNon3360 = process.env.TEST_3360?.toLowerCase() === "true" ? test.skip : test;
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