Skip to content

Commit cfbbd6f

Browse files
committed
add warning for deprecated clientId param
1 parent 94b2a9d commit cfbbd6f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/DBSQLClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
160160
* const session = client.connect({host, path, token});
161161
*/
162162
public async connect(options: ConnectionOptions, authProvider?: IAuthentication): Promise<IDBSQLClient> {
163+
const deprecatedClientId = (options as any).clientId;
164+
if (deprecatedClientId !== undefined) {
165+
this.logger.log(
166+
LogLevel.warn,
167+
'Warning: The "clientId" option is deprecated. Please use "userAgentEntry" instead.',
168+
);
169+
}
170+
163171
this.authProvider = this.createAuthProvider(options, authProvider);
164172

165173
this.connectionProvider = this.createConnectionProvider(options);

tests/unit/DBSQLClient.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ describe('DBSQLClient.connect', () => {
7979

8080
expect(thriftConnectionStub.on.called).to.be.true;
8181
});
82+
83+
it('should log a warning when deprecated clientId is passed', async () => {
84+
const client = new DBSQLClient();
85+
const logSpy = sinon.spy((client as any).logger, 'log');
86+
87+
const optionsWithDeprecated = {
88+
...connectOptions,
89+
clientId: 'clientId',
90+
};
91+
92+
await client.connect(optionsWithDeprecated as any);
93+
94+
const warningRegex = /Warning: The "clientId" option is deprecated\. Please use "userAgentEntry" instead\./;
95+
const callFound = logSpy.getCalls().some((call) => warningRegex.test(call.args[1]));
96+
97+
expect(callFound).to.be.true;
98+
99+
logSpy.restore();
100+
});
82101
});
83102

84103
describe('DBSQLClient.openSession', () => {

0 commit comments

Comments
 (0)