Skip to content

Commit

Permalink
feat: improve performance on Node.js 16 by disabling class property d…
Browse files Browse the repository at this point in the history
…efinitions (#1581)
  • Loading branch information
MichaelSun90 committed Oct 8, 2023
1 parent f4d91f1 commit 443701f
Show file tree
Hide file tree
Showing 30 changed files with 297 additions and 297 deletions.
14 changes: 7 additions & 7 deletions src/always-encrypted/aead-aes-256-cbc-hmac-algorithm.ts
Expand Up @@ -10,13 +10,13 @@ const algorithmVersion = 0x1;
const blockSizeInBytes = 16;

export class AeadAes256CbcHmac256Algorithm implements EncryptionAlgorithm {
private columnEncryptionkey: AeadAes256CbcHmac256EncryptionKey;
private isDeterministic: boolean;
private keySizeInBytes: number;
private version: Buffer;
private versionSize: Buffer;
private minimumCipherTextLengthInBytesNoAuthenticationTag: number;
private minimumCipherTextLengthInBytesWithAuthenticationTag: number;
declare private columnEncryptionkey: AeadAes256CbcHmac256EncryptionKey;
declare private isDeterministic: boolean;
declare private keySizeInBytes: number;
declare private version: Buffer;
declare private versionSize: Buffer;
declare private minimumCipherTextLengthInBytesNoAuthenticationTag: number;
declare private minimumCipherTextLengthInBytesWithAuthenticationTag: number;

constructor(columnEncryptionKey: AeadAes256CbcHmac256EncryptionKey, encryptionType: SQLServerEncryptionType) {
this.keySizeInBytes = keySize / 8;
Expand Down
14 changes: 7 additions & 7 deletions src/always-encrypted/aead-aes-256-cbc-hmac-encryption-key.ts
Expand Up @@ -22,13 +22,13 @@ export const generateKeySalt = (
`with encryption algorithm:${algorithmName} and key length:${keySize}`;

export class AeadAes256CbcHmac256EncryptionKey extends SymmetricKey {
private readonly algorithmName: string;
private encryptionKeySaltFormat: string;
private macKeySaltFormat: string;
private ivKeySaltFormat: string;
private encryptionKey: SymmetricKey;
private macKey: SymmetricKey;
private ivKey: SymmetricKey;
declare private readonly algorithmName: string;
declare private encryptionKeySaltFormat: string;
declare private macKeySaltFormat: string;
declare private ivKeySaltFormat: string;
declare private encryptionKey: SymmetricKey;
declare private macKey: SymmetricKey;
declare private ivKey: SymmetricKey;

constructor(rootKey: Buffer, algorithmName: string) {
super(rootKey);
Expand Down
12 changes: 6 additions & 6 deletions src/always-encrypted/cek-entry.ts
Expand Up @@ -4,12 +4,12 @@
import { type EncryptionKeyInfo } from './types';

export class CEKEntry {
columnEncryptionKeyValues: EncryptionKeyInfo[];
ordinal: number;
databaseId: number;
cekId: number;
cekVersion: number;
cekMdVersion: Buffer;
declare columnEncryptionKeyValues: EncryptionKeyInfo[];
declare ordinal: number;
declare databaseId: number;
declare cekId: number;
declare cekVersion: number;
declare cekMdVersion: Buffer;

constructor(ordinalVal: number) {
this.ordinal = ordinalVal;
Expand Down
14 changes: 7 additions & 7 deletions src/always-encrypted/keystore-provider-azure-key-vault.ts
Expand Up @@ -13,13 +13,13 @@ interface ParsedKeyPath {
}

export class ColumnEncryptionAzureKeyVaultProvider {
public readonly name: string;
private url: undefined | string;
private readonly rsaEncryptionAlgorithmWithOAEPForAKV: string;
private readonly firstVersion: Buffer;
private credentials: ClientSecretCredential;
private readonly azureKeyVaultDomainName: string;
private keyClient: undefined | KeyClient;
declare public readonly name: string;
declare private url: undefined | string;
declare private readonly rsaEncryptionAlgorithmWithOAEPForAKV: string;
declare private readonly firstVersion: Buffer;
declare private credentials: ClientSecretCredential;
declare private readonly azureKeyVaultDomainName: string;
declare private keyClient: undefined | KeyClient;

constructor(clientId: string, clientKey: string, tenantId: string) {
this.name = 'AZURE_KEY_VAULT';
Expand Down
2 changes: 1 addition & 1 deletion src/always-encrypted/symmetric-key.ts
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2019 Microsoft Corporation

export class SymmetricKey {
rootKey: Buffer;
declare rootKey: Buffer;

constructor(rootKey: Buffer) {
if (!rootKey) {
Expand Down
4 changes: 2 additions & 2 deletions src/bulk-load-payload.ts
@@ -1,8 +1,8 @@
import BulkLoad from './bulk-load';

export class BulkLoadPayload implements AsyncIterable<Buffer> {
bulkLoad: BulkLoad;
iterator: AsyncIterableIterator<Buffer>;
declare bulkLoad: BulkLoad;
declare iterator: AsyncIterableIterator<Buffer>;

constructor(bulkLoad: BulkLoad) {
this.bulkLoad = bulkLoad;
Expand Down
44 changes: 22 additions & 22 deletions src/bulk-load.ts
Expand Up @@ -139,19 +139,19 @@ class RowTransform extends Transform {
/**
* @private
*/
columnMetadataWritten: boolean;
declare columnMetadataWritten: boolean;
/**
* @private
*/
bulkLoad: BulkLoad;
declare bulkLoad: BulkLoad;
/**
* @private
*/
mainOptions: BulkLoad['options'];
declare mainOptions: BulkLoad['options'];
/**
* @private
*/
columns: BulkLoad['columns'];
declare columns: BulkLoad['columns'];

/**
* @private
Expand Down Expand Up @@ -255,78 +255,78 @@ class BulkLoad extends EventEmitter {
/**
* @private
*/
error: Error | undefined;
declare error: Error | undefined;
/**
* @private
*/
canceled: boolean;
declare canceled: boolean;
/**
* @private
*/
executionStarted: boolean;
declare executionStarted: boolean;
/**
* @private
*/
streamingMode: boolean;
declare streamingMode: boolean;
/**
* @private
*/
table: string;
declare table: string;
/**
* @private
*/
timeout: number | undefined;
declare timeout: number | undefined;

/**
* @private
*/
options: InternalConnectionOptions;
declare options: InternalConnectionOptions;
/**
* @private
*/
callback: Callback;
declare callback: Callback;

/**
* @private
*/
columns: Array<Column>;
declare columns: Array<Column>;
/**
* @private
*/
columnsByName: { [name: string]: Column };
declare columnsByName: { [name: string]: Column };

/**
* @private
*/
firstRowWritten: boolean;
declare firstRowWritten: boolean;
/**
* @private
*/
rowToPacketTransform: RowTransform;
declare rowToPacketTransform: RowTransform;

/**
* @private
*/
bulkOptions: InternalOptions;
declare bulkOptions: InternalOptions;

/**
* @private
*/
connection: Connection | undefined;
declare connection: Connection | undefined;
/**
* @private
*/
rows: Array<any> | undefined;
declare rows: Array<any> | undefined;
/**
* @private
*/
rst: Array<any> | undefined;
declare rst: Array<any> | undefined;
/**
* @private
*/
rowCount: number | undefined;
declare rowCount: number | undefined;

collation: Collation | undefined;
declare collation: Collation | undefined;

/**
* @private
Expand Down
12 changes: 6 additions & 6 deletions src/collation.ts
Expand Up @@ -293,13 +293,13 @@ export const Flags = {
};

export class Collation {
readonly lcid: number;
readonly flags: number;
readonly version: number;
readonly sortId: number;
readonly codepage: Encoding | undefined;
declare readonly lcid: number;
declare readonly flags: number;
declare readonly version: number;
declare readonly sortId: number;
declare readonly codepage: Encoding | undefined;

private buffer: Buffer | undefined;
declare private buffer: Buffer | undefined;

static fromBuffer(buffer: Buffer, offset = 0) {
let lcid = (buffer[offset + 2] & 0x0F) << 16;
Expand Down
54 changes: 27 additions & 27 deletions src/connection.ts
Expand Up @@ -897,59 +897,59 @@ class Connection extends EventEmitter {
/**
* @private
*/
fedAuthRequired: boolean;
declare fedAuthRequired: boolean;
/**
* @private
*/
config: InternalConnectionConfig;
declare config: InternalConnectionConfig;
/**
* @private
*/
secureContextOptions: SecureContextOptions;
declare secureContextOptions: SecureContextOptions;
/**
* @private
*/
inTransaction: boolean;
declare inTransaction: boolean;
/**
* @private
*/
transactionDescriptors: Buffer[];
declare transactionDescriptors: Buffer[];
/**
* @private
*/
transactionDepth: number;
declare transactionDepth: number;
/**
* @private
*/
isSqlBatch: boolean;
declare isSqlBatch: boolean;
/**
* @private
*/
curTransientRetryCount: number;
declare curTransientRetryCount: number;
/**
* @private
*/
transientErrorLookup: TransientErrorLookup;
declare transientErrorLookup: TransientErrorLookup;
/**
* @private
*/
closed: boolean;
declare closed: boolean;
/**
* @private
*/
loginError: undefined | AggregateError | ConnectionError;
declare loginError: undefined | AggregateError | ConnectionError;
/**
* @private
*/
debug: Debug;
declare debug: Debug;
/**
* @private
*/
ntlmpacket: undefined | any;
declare ntlmpacket: undefined | any;
/**
* @private
*/
ntlmpacketBuffer: undefined | Buffer;
declare ntlmpacketBuffer: undefined | Buffer;

/**
* @private
Expand All @@ -974,54 +974,54 @@ class Connection extends EventEmitter {
/**
* @private
*/
routingData: undefined | RoutingData;
declare routingData: undefined | RoutingData;

/**
* @private
*/
messageIo!: MessageIO;
declare messageIo: MessageIO;
/**
* @private
*/
state: State;
declare state: State;
/**
* @private
*/
resetConnectionOnNextRequest: undefined | boolean;
declare resetConnectionOnNextRequest: undefined | boolean;

/**
* @private
*/
request: undefined | Request | BulkLoad;
declare request: undefined | Request | BulkLoad;
/**
* @private
*/
procReturnStatusValue: undefined | any;
declare procReturnStatusValue: undefined | any;
/**
* @private
*/
socket: undefined | net.Socket;
declare socket: undefined | net.Socket;
/**
* @private
*/
messageBuffer: Buffer;
declare messageBuffer: Buffer;

/**
* @private
*/
connectTimer: undefined | NodeJS.Timeout;
declare connectTimer: undefined | NodeJS.Timeout;
/**
* @private
*/
cancelTimer: undefined | NodeJS.Timeout;
declare cancelTimer: undefined | NodeJS.Timeout;
/**
* @private
*/
requestTimer: undefined | NodeJS.Timeout;
declare requestTimer: undefined | NodeJS.Timeout;
/**
* @private
*/
retryTimer: undefined | NodeJS.Timeout;
declare retryTimer: undefined | NodeJS.Timeout;

/**
* @private
Expand All @@ -1031,7 +1031,7 @@ class Connection extends EventEmitter {
/**
* @private
*/
databaseCollation: Collation | undefined;
declare databaseCollation: Collation | undefined;

/**
* Note: be aware of the different options field:
Expand Down

0 comments on commit 443701f

Please sign in to comment.