Skip to content

Commit

Permalink
Merge pull request #1351 from tediousjs/arthur/deprecations
Browse files Browse the repository at this point in the history
Emit deprecation warnings for deprecated functionality
  • Loading branch information
arthurschreiber authored Sep 28, 2021
2 parents fad0ba6 + aa0f790 commit 778985a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@azure/keyvault-keys": "^4.3.0",
"@js-joda/core": "^4.0.0",
"bl": "^5.0.0",
"depd": "^2.0.0",
"iconv-lite": "^0.6.3",
"jsbi": "^3.2.1",
"native-duplexpair": "^1.0.0",
Expand Down
36 changes: 36 additions & 0 deletions src/bulk-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ class BulkLoad extends EventEmitter {
addRow(row: unknown[]): void

addRow(...input: [ { [key: string]: unknown } ] | unknown[]) {
emitAddRowDeprecationWarning();

this.firstRowWritten = true;

let row: any;
Expand Down Expand Up @@ -695,6 +697,8 @@ class BulkLoad extends EventEmitter {
* stream or an `AsyncGenerator`) when calling [[Connection.execBulkLoad]]. This method will be removed in the future.
*/
getRowStream() {
emitGetRowStreamDeprecationWarning();

if (this.firstRowWritten) {
throw new Error('BulkLoad cannot be switched to streaming mode after first row has been written using addRow().');
}
Expand All @@ -720,5 +724,37 @@ class BulkLoad extends EventEmitter {
}
}

let addRowDeprecationWarningEmitted = false;
function emitAddRowDeprecationWarning() {
if (addRowDeprecationWarningEmitted) {
return;
}

addRowDeprecationWarningEmitted = true;

process.emitWarning(
'The BulkLoad.addRow method is deprecated. Please provide the row data for ' +
'the bulk load as the second argument to Connection.execBulkLoad instead.',
'DeprecationWarning',
BulkLoad.prototype.addRow
);
}

let getRowStreamDeprecationWarningEmitted = false;
function emitGetRowStreamDeprecationWarning() {
if (getRowStreamDeprecationWarningEmitted) {
return;
}

getRowStreamDeprecationWarningEmitted = true;

process.emitWarning(
'The BulkLoad.getRowStream method is deprecated. You can pass an Iterable, AsyncIterable or ' +
'stream.Readable object containing the row data as a second argument to Connection.execBulkLoad instead.',
'DeprecationWarning',
BulkLoad.prototype.getRowStream
);
}

export default BulkLoad;
module.exports = BulkLoad;
31 changes: 27 additions & 4 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Message from './message';
import { Metadata } from './metadata-parser';
import { createNTLMRequest } from './ntlm';
import { ColumnEncryptionAzureKeyVaultProvider } from './always-encrypted/keystore-provider-azure-key-vault';
import depd from 'depd';

import { AbortController, AbortSignal } from 'node-abort-controller';
import { Parameter, TYPES } from './data-type';
Expand All @@ -48,9 +47,6 @@ import { version } from '../package.json';
import { URL } from 'url';
import { AttentionTokenHandler, InitialSqlTokenHandler, Login7TokenHandler, RequestTokenHandler, TokenHandler } from './token/handler';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const deprecate = depd('tedious');

type BeginTransactionCallback =
/**
* The callback is called when the request to start the transaction has completed,
Expand Down Expand Up @@ -1773,7 +1769,18 @@ class Connection extends EventEmitter {
*/
on(event: 'secure', listener: (cleartext: import('tls').TLSSocket) => void): this

/**
* A SSPI token was send by the server.
*
* @deprecated
*/
on(event: 'sspichallenge', listener: (token: import('./token/token').SSPIToken) => void): this

on(event: string | symbol, listener: (...args: any[]) => void) {
if (event === 'sspichallenge') {
emitSSPIChallengeEventDeprecationWarning();
}

return super.on(event, listener);
}

Expand Down Expand Up @@ -1837,6 +1844,7 @@ class Connection extends EventEmitter {
* @private
*/
emit(event: 'sspichallenge', token: import('./token/token').SSPIToken): boolean

emit(event: string | symbol, ...args: any[]) {
return super.emit(event, ...args);
}
Expand Down Expand Up @@ -3120,6 +3128,21 @@ class Connection extends EventEmitter {
}
}

let sspichallengeEventDeprecationWarningEmitted = false;
function emitSSPIChallengeEventDeprecationWarning() {
if (sspichallengeEventDeprecationWarningEmitted) {
return;
}

sspichallengeEventDeprecationWarningEmitted = true;

process.emitWarning(
'The `sspichallenge` event is deprecated and will be removed.',
'DeprecationWarning',
Connection.prototype.on
);
}

export default Connection;
module.exports = Connection;

Expand Down

0 comments on commit 778985a

Please sign in to comment.