diff --git a/src/always-encrypted/aead-aes-256-cbc-hmac-algorithm.ts b/src/always-encrypted/aead-aes-256-cbc-hmac-algorithm.ts index 5df398617..3fffc5fb6 100644 --- a/src/always-encrypted/aead-aes-256-cbc-hmac-algorithm.ts +++ b/src/always-encrypted/aead-aes-256-cbc-hmac-algorithm.ts @@ -1,7 +1,7 @@ // This code is based on the `mssql-jdbc` library published under the conditions of MIT license. // Copyright (c) 2019 Microsoft Corporation -import { EncryptionAlgorithm, SQLServerEncryptionType } from './types'; +import { type EncryptionAlgorithm, SQLServerEncryptionType } from './types'; import { createHmac, randomBytes, createCipheriv, createDecipheriv } from 'crypto'; import { AeadAes256CbcHmac256EncryptionKey, keySize } from './aead-aes-256-cbc-hmac-encryption-key'; diff --git a/src/always-encrypted/cek-entry.ts b/src/always-encrypted/cek-entry.ts index 516866872..5e97c91e5 100644 --- a/src/always-encrypted/cek-entry.ts +++ b/src/always-encrypted/cek-entry.ts @@ -1,7 +1,7 @@ // This code is based on the `mssql-jdbc` library published under the conditions of MIT license. // Copyright (c) 2019 Microsoft Corporation -import { EncryptionKeyInfo } from './types'; +import { type EncryptionKeyInfo } from './types'; export class CEKEntry { columnEncryptionKeyValues: EncryptionKeyInfo[]; diff --git a/src/always-encrypted/get-parameter-encryption-metadata.ts b/src/always-encrypted/get-parameter-encryption-metadata.ts index 09b098fc7..f866db1a3 100644 --- a/src/always-encrypted/get-parameter-encryption-metadata.ts +++ b/src/always-encrypted/get-parameter-encryption-metadata.ts @@ -1,10 +1,10 @@ // This code is based on the `mssql-jdbc` library published under the conditions of MIT license. // Copyright (c) 2019 Microsoft Corporation -import { SQLServerEncryptionType, CryptoMetadata, DescribeParameterEncryptionResultSet1, DescribeParameterEncryptionResultSet2 } from './types'; +import { SQLServerEncryptionType, type CryptoMetadata, DescribeParameterEncryptionResultSet1, DescribeParameterEncryptionResultSet2 } from './types'; import { CEKEntry } from './cek-entry'; import { decryptSymmetricKey } from './key-crypto'; -import { typeByName as TYPES, Parameter } from '../data-type'; +import { typeByName as TYPES, type Parameter } from '../data-type'; import Request from '../request'; import Connection from '../connection'; import RpcRequestPayload from '../rpcrequest-payload'; diff --git a/src/always-encrypted/key-crypto.ts b/src/always-encrypted/key-crypto.ts index 5ff6641f5..9fab125e3 100644 --- a/src/always-encrypted/key-crypto.ts +++ b/src/always-encrypted/key-crypto.ts @@ -1,8 +1,8 @@ // This code is based on the `mssql-jdbc` library published under the conditions of MIT license. // Copyright (c) 2019 Microsoft Corporation -import { CryptoMetadata, EncryptionKeyInfo } from './types'; -import { InternalConnectionOptions as ConnectionOptions } from '../connection'; +import { type CryptoMetadata, type EncryptionKeyInfo } from './types'; +import { type InternalConnectionOptions as ConnectionOptions } from '../connection'; import SymmetricKey from './symmetric-key'; import { getKey } from './symmetric-key-cache'; import { AeadAes256CbcHmac256Algorithm, algorithmName } from './aead-aes-256-cbc-hmac-algorithm'; diff --git a/src/always-encrypted/keystore-provider-azure-key-vault.ts b/src/always-encrypted/keystore-provider-azure-key-vault.ts index f519439b5..4646dc09e 100644 --- a/src/always-encrypted/keystore-provider-azure-key-vault.ts +++ b/src/always-encrypted/keystore-provider-azure-key-vault.ts @@ -2,7 +2,7 @@ // Copyright (c) 2019 Microsoft Corporation import { ClientSecretCredential } from '@azure/identity'; -import { CryptographyClient, KeyWrapAlgorithm, KeyClient, KeyVaultKey } from '@azure/keyvault-keys'; +import { CryptographyClient, type KeyWrapAlgorithm, KeyClient, type KeyVaultKey } from '@azure/keyvault-keys'; import { createHash } from 'crypto'; import { parse } from 'url'; diff --git a/src/always-encrypted/symmetric-key-cache.ts b/src/always-encrypted/symmetric-key-cache.ts index c0a27782f..81d874f19 100644 --- a/src/always-encrypted/symmetric-key-cache.ts +++ b/src/always-encrypted/symmetric-key-cache.ts @@ -1,9 +1,9 @@ // This code is based on the `mssql-jdbc` library published under the conditions of MIT license. // Copyright (c) 2019 Microsoft Corporation -import { EncryptionKeyInfo } from './types'; +import { type EncryptionKeyInfo } from './types'; import SymmetricKey from './symmetric-key'; -import { InternalConnectionOptions as ConnectionOptions } from '../connection'; +import { type InternalConnectionOptions as ConnectionOptions } from '../connection'; import LRU from 'lru-cache'; const cache = new LRU(0); diff --git a/src/always-encrypted/types.ts b/src/always-encrypted/types.ts index 023577ed5..b7bd236d9 100644 --- a/src/always-encrypted/types.ts +++ b/src/always-encrypted/types.ts @@ -2,7 +2,7 @@ // Copyright (c) 2019 Microsoft Corporation import { CEKEntry } from './cek-entry'; -import { BaseMetadata } from '../metadata-parser'; +import { type BaseMetadata } from '../metadata-parser'; export interface EncryptionKeyInfo { encryptedKey: Buffer; diff --git a/src/bulk-load.ts b/src/bulk-load.ts index 0b892f5b9..6a007b235 100644 --- a/src/bulk-load.ts +++ b/src/bulk-load.ts @@ -1,12 +1,12 @@ import { EventEmitter } from 'events'; import WritableTrackingBuffer from './tracking-buffer/writable-tracking-buffer'; -import Connection, { InternalConnectionOptions } from './connection'; import { ParameterValidationError } from './errors'; +import Connection, { type InternalConnectionOptions } from './connection'; import { Transform } from 'stream'; import { TYPE as TOKEN_TYPE } from './token/token'; -import { DataType, Parameter } from './data-type'; +import { type DataType, type Parameter } from './data-type'; import { Collation } from './collation'; /** diff --git a/src/connection.ts b/src/connection.ts index dd2d746d3..a4e4f2e8a 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -5,7 +5,7 @@ import * as net from 'net'; import dns from 'dns'; import constants from 'constants'; -import { SecureContextOptions } from 'tls'; +import { type SecureContextOptions } from 'tls'; import { Readable } from 'stream'; @@ -16,7 +16,7 @@ import { UsernamePasswordCredential, } from '@azure/identity'; -import BulkLoad, { Options as BulkLoadOptions, Callback as BulkLoadCallback } from './bulk-load'; +import BulkLoad, { type Options as BulkLoadOptions, type Callback as BulkLoadCallback } from './bulk-load'; import Debug from './debug'; import { EventEmitter, once } from 'events'; import { instanceLookup } from './instance-lookup'; @@ -36,12 +36,12 @@ import { connectInParallel, connectInSequence } from './connector'; import { name as libraryName } from './library'; import { versions } from './tds-versions'; import Message from './message'; -import { Metadata } from './metadata-parser'; +import { type Metadata } from './metadata-parser'; import { createNTLMRequest } from './ntlm'; import { ColumnEncryptionAzureKeyVaultProvider } from './always-encrypted/keystore-provider-azure-key-vault'; import { AbortController, AbortSignal } from 'node-abort-controller'; -import { Parameter, TYPES } from './data-type'; +import { type Parameter, TYPES } from './data-type'; import { BulkLoadPayload } from './bulk-load-payload'; import { Collation } from './collation'; import Procedures from './special-stored-procedure'; diff --git a/src/connector.ts b/src/connector.ts index db4e1801d..fa1b9f4e3 100644 --- a/src/connector.ts +++ b/src/connector.ts @@ -1,5 +1,5 @@ import net from 'net'; -import dns, { LookupAddress } from 'dns'; +import dns, { type LookupAddress } from 'dns'; import * as punycode from 'punycode'; import { AbortSignal } from 'node-abort-controller'; diff --git a/src/data-type.ts b/src/data-type.ts index 8fc3a475f..77d81eed9 100644 --- a/src/data-type.ts +++ b/src/data-type.ts @@ -37,9 +37,9 @@ import DateTimeOffset from './data-types/datetimeoffset'; import UDT from './data-types/udt'; import TVP from './data-types/tvp'; import Variant from './data-types/sql-variant'; -import { CryptoMetadata } from './always-encrypted/types'; +import { type CryptoMetadata } from './always-encrypted/types'; -import { InternalConnectionOptions } from './connection'; +import { type InternalConnectionOptions } from './connection'; import { Collation } from './collation'; export interface Parameter { diff --git a/src/data-types/bigint.ts b/src/data-types/bigint.ts index 2ea0c74f9..db3298fc3 100644 --- a/src/data-types/bigint.ts +++ b/src/data-types/bigint.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import IntN from './intn'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; diff --git a/src/data-types/binary.ts b/src/data-types/binary.ts index 05e256631..0a298c166 100644 --- a/src/data-types/binary.ts +++ b/src/data-types/binary.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF]); diff --git a/src/data-types/bit.ts b/src/data-types/bit.ts index 0e7db512a..36bf01cfe 100644 --- a/src/data-types/bit.ts +++ b/src/data-types/bit.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import BitN from './bitn'; const DATA_LENGTH = Buffer.from([0x01]); diff --git a/src/data-types/bitn.ts b/src/data-types/bitn.ts index 2d91fa5c6..26fd9da8f 100644 --- a/src/data-types/bitn.ts +++ b/src/data-types/bitn.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const BitN: DataType = { id: 0x68, diff --git a/src/data-types/char.ts b/src/data-types/char.ts index 3ac87699a..8358dcec0 100644 --- a/src/data-types/char.ts +++ b/src/data-types/char.ts @@ -1,5 +1,5 @@ import iconv from 'iconv-lite'; -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF]); diff --git a/src/data-types/date.ts b/src/data-types/date.ts index 6cf7a547f..d5c73ab95 100644 --- a/src/data-types/date.ts +++ b/src/data-types/date.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import { ChronoUnit, LocalDate } from '@js-joda/core'; // globalDate is to be used for JavaScript's global 'Date' object to avoid name clashing with the 'Date' constant below diff --git a/src/data-types/datetime.ts b/src/data-types/datetime.ts index ee8fcd772..02f62ef15 100644 --- a/src/data-types/datetime.ts +++ b/src/data-types/datetime.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import DateTimeN from './datetimen'; import { ChronoUnit, LocalDate } from '@js-joda/core'; diff --git a/src/data-types/datetime2.ts b/src/data-types/datetime2.ts index 5f979edb8..a31151107 100644 --- a/src/data-types/datetime2.ts +++ b/src/data-types/datetime2.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import { ChronoUnit, LocalDate } from '@js-joda/core'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; diff --git a/src/data-types/datetimen.ts b/src/data-types/datetimen.ts index 20e7aaccf..59d4bdd7b 100644 --- a/src/data-types/datetimen.ts +++ b/src/data-types/datetimen.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const DateTimeN: DataType = { id: 0x6F, diff --git a/src/data-types/datetimeoffset.ts b/src/data-types/datetimeoffset.ts index 177407b68..b936fcc18 100644 --- a/src/data-types/datetimeoffset.ts +++ b/src/data-types/datetimeoffset.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import { ChronoUnit, LocalDate } from '@js-joda/core'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; diff --git a/src/data-types/decimal.ts b/src/data-types/decimal.ts index 95f159f2d..78bc04dcd 100644 --- a/src/data-types/decimal.ts +++ b/src/data-types/decimal.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import DecimalN from './decimaln'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; diff --git a/src/data-types/decimaln.ts b/src/data-types/decimaln.ts index e41139f01..e81d32ffc 100644 --- a/src/data-types/decimaln.ts +++ b/src/data-types/decimaln.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const DecimalN: DataType = { id: 0x6A, diff --git a/src/data-types/float.ts b/src/data-types/float.ts index db99d672b..73a97405f 100644 --- a/src/data-types/float.ts +++ b/src/data-types/float.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import FloatN from './floatn'; const NULL_LENGTH = Buffer.from([0x00]); diff --git a/src/data-types/floatn.ts b/src/data-types/floatn.ts index 9c217d52c..d717a3c2e 100644 --- a/src/data-types/floatn.ts +++ b/src/data-types/floatn.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const FloatN: DataType = { id: 0x6D, diff --git a/src/data-types/image.ts b/src/data-types/image.ts index 65dddad89..9c0854b46 100644 --- a/src/data-types/image.ts +++ b/src/data-types/image.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]); diff --git a/src/data-types/int.ts b/src/data-types/int.ts index 1d6aa3da1..5a51bc650 100644 --- a/src/data-types/int.ts +++ b/src/data-types/int.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import IntN from './intn'; const NULL_LENGTH = Buffer.from([0x00]); diff --git a/src/data-types/intn.ts b/src/data-types/intn.ts index 07a3f371e..8f58834a0 100644 --- a/src/data-types/intn.ts +++ b/src/data-types/intn.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const IntN: DataType = { id: 0x26, diff --git a/src/data-types/money.ts b/src/data-types/money.ts index 5aa36721c..7a614606e 100644 --- a/src/data-types/money.ts +++ b/src/data-types/money.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import MoneyN from './moneyn'; const SHIFT_LEFT_32 = (1 << 16) * (1 << 16); diff --git a/src/data-types/moneyn.ts b/src/data-types/moneyn.ts index 4cc8a7dc1..03452e17e 100644 --- a/src/data-types/moneyn.ts +++ b/src/data-types/moneyn.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const MoneyN: DataType = { id: 0x6E, diff --git a/src/data-types/nchar.ts b/src/data-types/nchar.ts index a4c7ec608..5202bb831 100644 --- a/src/data-types/nchar.ts +++ b/src/data-types/nchar.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF]); diff --git a/src/data-types/ntext.ts b/src/data-types/ntext.ts index 33dcb8b00..fd8607d3d 100644 --- a/src/data-types/ntext.ts +++ b/src/data-types/ntext.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]); diff --git a/src/data-types/null.ts b/src/data-types/null.ts index 47f0abb20..94493690e 100644 --- a/src/data-types/null.ts +++ b/src/data-types/null.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const Null: DataType = { id: 0x1F, diff --git a/src/data-types/numeric.ts b/src/data-types/numeric.ts index 243c07d9c..fea719a88 100644 --- a/src/data-types/numeric.ts +++ b/src/data-types/numeric.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import NumericN from './numericn'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; diff --git a/src/data-types/numericn.ts b/src/data-types/numericn.ts index 74e61e745..593bbb562 100644 --- a/src/data-types/numericn.ts +++ b/src/data-types/numericn.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NumericN: DataType = { id: 0x6C, diff --git a/src/data-types/nvarchar.ts b/src/data-types/nvarchar.ts index 07927a45d..1e0da9658 100644 --- a/src/data-types/nvarchar.ts +++ b/src/data-types/nvarchar.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const MAX = (1 << 16) - 1; const UNKNOWN_PLP_LEN = Buffer.from([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); diff --git a/src/data-types/real.ts b/src/data-types/real.ts index 9f9095618..415370e7f 100644 --- a/src/data-types/real.ts +++ b/src/data-types/real.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import FloatN from './floatn'; const NULL_LENGTH = Buffer.from([0x00]); diff --git a/src/data-types/smalldatetime.ts b/src/data-types/smalldatetime.ts index 4b171d9c1..b17d0d834 100644 --- a/src/data-types/smalldatetime.ts +++ b/src/data-types/smalldatetime.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import DateTimeN from './datetimen'; const EPOCH_DATE = new Date(1900, 0, 1); diff --git a/src/data-types/smallint.ts b/src/data-types/smallint.ts index 748a70b55..ab79e28fb 100644 --- a/src/data-types/smallint.ts +++ b/src/data-types/smallint.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import IntN from './intn'; const DATA_LENGTH = Buffer.from([0x02]); diff --git a/src/data-types/smallmoney.ts b/src/data-types/smallmoney.ts index edbce29f7..2398a6072 100644 --- a/src/data-types/smallmoney.ts +++ b/src/data-types/smallmoney.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import MoneyN from './moneyn'; const DATA_LENGTH = Buffer.from([0x04]); diff --git a/src/data-types/sql-variant.ts b/src/data-types/sql-variant.ts index 85cb3bb34..c09983945 100644 --- a/src/data-types/sql-variant.ts +++ b/src/data-types/sql-variant.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const Variant: DataType = { id: 0x62, diff --git a/src/data-types/text.ts b/src/data-types/text.ts index 31f0d3ac7..5773dc59e 100644 --- a/src/data-types/text.ts +++ b/src/data-types/text.ts @@ -1,6 +1,6 @@ import iconv from 'iconv-lite'; -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const NULL_LENGTH = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]); diff --git a/src/data-types/time.ts b/src/data-types/time.ts index db2e12926..d4f1be9a0 100644 --- a/src/data-types/time.ts +++ b/src/data-types/time.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; const NULL_LENGTH = Buffer.from([0x00]); diff --git a/src/data-types/tinyint.ts b/src/data-types/tinyint.ts index e4442262f..8ea47afca 100644 --- a/src/data-types/tinyint.ts +++ b/src/data-types/tinyint.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import IntN from './intn'; const DATA_LENGTH = Buffer.from([0x01]); diff --git a/src/data-types/tvp.ts b/src/data-types/tvp.ts index 4244c82c5..118157bf4 100644 --- a/src/data-types/tvp.ts +++ b/src/data-types/tvp.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import WritableTrackingBuffer from '../tracking-buffer/writable-tracking-buffer'; const TVP_ROW_TOKEN = Buffer.from([0x01]); diff --git a/src/data-types/udt.ts b/src/data-types/udt.ts index 4c2d7c9d4..7a222be97 100644 --- a/src/data-types/udt.ts +++ b/src/data-types/udt.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const UDT: DataType = { id: 0xF0, diff --git a/src/data-types/uniqueidentifier.ts b/src/data-types/uniqueidentifier.ts index 115131141..da3dd7402 100644 --- a/src/data-types/uniqueidentifier.ts +++ b/src/data-types/uniqueidentifier.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; import { guidToArray } from '../guid-parser'; const NULL_LENGTH = Buffer.from([0x00]); diff --git a/src/data-types/varbinary.ts b/src/data-types/varbinary.ts index 3c26ef0da..0f9b7f8fa 100644 --- a/src/data-types/varbinary.ts +++ b/src/data-types/varbinary.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const MAX = (1 << 16) - 1; const UNKNOWN_PLP_LEN = Buffer.from([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); diff --git a/src/data-types/varchar.ts b/src/data-types/varchar.ts index 9c6f7ed78..7ebe0d94d 100644 --- a/src/data-types/varchar.ts +++ b/src/data-types/varchar.ts @@ -1,6 +1,6 @@ import iconv from 'iconv-lite'; -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const MAX = (1 << 16) - 1; const UNKNOWN_PLP_LEN = Buffer.from([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); diff --git a/src/data-types/xml.ts b/src/data-types/xml.ts index b1b25a811..ec0fdd3c1 100644 --- a/src/data-types/xml.ts +++ b/src/data-types/xml.ts @@ -1,4 +1,4 @@ -import { DataType } from '../data-type'; +import { type DataType } from '../data-type'; const XML: DataType = { id: 0xF1, diff --git a/src/metadata-parser.ts b/src/metadata-parser.ts index 5108fd1f3..ea1ed1b43 100644 --- a/src/metadata-parser.ts +++ b/src/metadata-parser.ts @@ -1,7 +1,7 @@ import { Collation } from './collation'; -import Parser, { ParserOptions } from './token/stream-parser'; -import { TYPE, DataType } from './data-type'; -import { CryptoMetadata } from './always-encrypted/types'; +import Parser, { type ParserOptions } from './token/stream-parser'; +import { TYPE, type DataType } from './data-type'; +import { type CryptoMetadata } from './always-encrypted/types'; import { sprintf } from 'sprintf-js'; diff --git a/src/request.ts b/src/request.ts index 9baff8a61..c32937b15 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,11 +1,11 @@ import { EventEmitter } from 'events'; -import { Parameter, DataType } from './data-type'; import { ParameterValidationError } from './errors'; +import { type Parameter, type DataType } from './data-type'; import Connection from './connection'; -import { Metadata } from './metadata-parser'; +import { type Metadata } from './metadata-parser'; import { SQLServerStatementColumnEncryptionSetting } from './always-encrypted/types'; -import { ColumnMetadata } from './token/colmetadata-token-parser'; +import { type ColumnMetadata } from './token/colmetadata-token-parser'; import { Collation } from './collation'; /** diff --git a/src/rpcrequest-payload.ts b/src/rpcrequest-payload.ts index ad357169e..8c2c9567a 100644 --- a/src/rpcrequest-payload.ts +++ b/src/rpcrequest-payload.ts @@ -1,7 +1,7 @@ import WritableTrackingBuffer from './tracking-buffer/writable-tracking-buffer'; import { writeToTrackingBuffer } from './all-headers'; -import { Parameter, ParameterData } from './data-type'; -import { InternalConnectionOptions } from './connection'; +import { type Parameter, type ParameterData } from './data-type'; +import { type InternalConnectionOptions } from './connection'; import { Collation } from './collation'; // const OPTION = { diff --git a/src/tedious.ts b/src/tedious.ts index 44e97202e..8831e4524 100644 --- a/src/tedious.ts +++ b/src/tedious.ts @@ -1,5 +1,5 @@ import BulkLoad from './bulk-load'; -import Connection, { ConnectionConfiguration } from './connection'; +import Connection, { type ConnectionConfiguration } from './connection'; import Request from './request'; import { name } from './library'; diff --git a/src/token/colmetadata-token-parser.ts b/src/token/colmetadata-token-parser.ts index cab333c5a..954ec3329 100644 --- a/src/token/colmetadata-token-parser.ts +++ b/src/token/colmetadata-token-parser.ts @@ -1,6 +1,6 @@ -import metadataParse, { Metadata } from '../metadata-parser'; +import metadataParse, { type Metadata } from '../metadata-parser'; -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { ColMetadataToken } from './token'; export interface ColumnMetadata extends Metadata { diff --git a/src/token/done-token-parser.ts b/src/token/done-token-parser.ts index 8856fc53d..0db7642dd 100644 --- a/src/token/done-token-parser.ts +++ b/src/token/done-token-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { DoneToken, DoneInProcToken, DoneProcToken } from './token'; // s2.2.7.5/6/7 diff --git a/src/token/env-change-token-parser.ts b/src/token/env-change-token-parser.ts index e760fb2c6..3f20a4012 100644 --- a/src/token/env-change-token-parser.ts +++ b/src/token/env-change-token-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { Collation } from '../collation'; import { diff --git a/src/token/feature-ext-ack-parser.ts b/src/token/feature-ext-ack-parser.ts index 338e0eb5e..bb977c2b8 100644 --- a/src/token/feature-ext-ack-parser.ts +++ b/src/token/feature-ext-ack-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { FeatureExtAckToken } from './token'; diff --git a/src/token/fedauth-info-parser.ts b/src/token/fedauth-info-parser.ts index bead3cd55..e4bcd8c8e 100644 --- a/src/token/fedauth-info-parser.ts +++ b/src/token/fedauth-info-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { FedAuthInfoToken } from './token'; const FEDAUTHINFOID = { diff --git a/src/token/handler.ts b/src/token/handler.ts index 8d0088c9d..ccd1bb74e 100644 --- a/src/token/handler.ts +++ b/src/token/handler.ts @@ -1,7 +1,7 @@ import Connection from '../connection'; import Request from '../request'; import { ConnectionError, RequestError } from '../errors'; -import { ColumnMetadata } from './colmetadata-token-parser'; +import { type ColumnMetadata } from './colmetadata-token-parser'; import { BeginTransactionEnvChangeToken, CharsetEnvChangeToken, diff --git a/src/token/infoerror-token-parser.ts b/src/token/infoerror-token-parser.ts index b55acec09..1c38d427f 100644 --- a/src/token/infoerror-token-parser.ts +++ b/src/token/infoerror-token-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { InfoMessageToken, ErrorMessageToken } from './token'; diff --git a/src/token/loginack-token-parser.ts b/src/token/loginack-token-parser.ts index b28c47330..4abda8d45 100644 --- a/src/token/loginack-token-parser.ts +++ b/src/token/loginack-token-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { LoginAckToken } from './token'; diff --git a/src/token/nbcrow-token-parser.ts b/src/token/nbcrow-token-parser.ts index 67ded8634..4a7012ed7 100644 --- a/src/token/nbcrow-token-parser.ts +++ b/src/token/nbcrow-token-parser.ts @@ -1,7 +1,7 @@ // s2.2.7.13 (introduced in TDS 7.3.B) -import Parser, { ParserOptions } from './stream-parser'; -import { ColumnMetadata } from './colmetadata-token-parser'; +import Parser, { type ParserOptions } from './stream-parser'; +import { type ColumnMetadata } from './colmetadata-token-parser'; import { NBCRowToken } from './token'; diff --git a/src/token/order-token-parser.ts b/src/token/order-token-parser.ts index 3f8a5792a..bcc3498cb 100644 --- a/src/token/order-token-parser.ts +++ b/src/token/order-token-parser.ts @@ -1,5 +1,5 @@ // s2.2.7.14 -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { OrderToken } from './token'; diff --git a/src/token/returnstatus-token-parser.ts b/src/token/returnstatus-token-parser.ts index a925d3dbf..83be29b7d 100644 --- a/src/token/returnstatus-token-parser.ts +++ b/src/token/returnstatus-token-parser.ts @@ -1,5 +1,5 @@ // s2.2.7.16 -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { ReturnStatusToken } from './token'; diff --git a/src/token/returnvalue-token-parser.ts b/src/token/returnvalue-token-parser.ts index 42699497a..64b195fdc 100644 --- a/src/token/returnvalue-token-parser.ts +++ b/src/token/returnvalue-token-parser.ts @@ -1,6 +1,6 @@ // s2.2.7.16 -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { ReturnValueToken } from './token'; diff --git a/src/token/row-token-parser.ts b/src/token/row-token-parser.ts index 5069b1d6a..7960bc3b3 100644 --- a/src/token/row-token-parser.ts +++ b/src/token/row-token-parser.ts @@ -1,7 +1,7 @@ // s2.2.7.17 import Parser from './stream-parser'; -import { ColumnMetadata } from './colmetadata-token-parser'; +import { type ColumnMetadata } from './colmetadata-token-parser'; import { RowToken } from './token'; diff --git a/src/token/sspi-token-parser.ts b/src/token/sspi-token-parser.ts index acae50eac..ef91c6f57 100644 --- a/src/token/sspi-token-parser.ts +++ b/src/token/sspi-token-parser.ts @@ -1,4 +1,4 @@ -import Parser, { ParserOptions } from './stream-parser'; +import Parser, { type ParserOptions } from './stream-parser'; import { SSPIToken } from './token'; diff --git a/src/token/stream-parser.ts b/src/token/stream-parser.ts index 61ac11bb1..4b39aa23b 100644 --- a/src/token/stream-parser.ts +++ b/src/token/stream-parser.ts @@ -1,9 +1,9 @@ import Debug from '../debug'; -import { InternalConnectionOptions } from '../connection'; +import { type InternalConnectionOptions } from '../connection'; import { TYPE, Token, ColMetadataToken } from './token'; -import colMetadataParser, { ColumnMetadata } from './colmetadata-token-parser'; +import colMetadataParser, { type ColumnMetadata } from './colmetadata-token-parser'; import { doneParser, doneInProcParser, doneProcParser } from './done-token-parser'; import envChangeParser from './env-change-token-parser'; import { errorParser, infoParser } from './infoerror-token-parser'; diff --git a/src/token/token-stream-parser.ts b/src/token/token-stream-parser.ts index a95258f8d..8fc6c8017 100644 --- a/src/token/token-stream-parser.ts +++ b/src/token/token-stream-parser.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import StreamParser, { ParserOptions } from './stream-parser'; +import StreamParser, { type ParserOptions } from './stream-parser'; import Debug from '../debug'; import { Token } from './token'; import { Readable } from 'stream'; diff --git a/src/token/token.ts b/src/token/token.ts index 141856e1c..7322da7bd 100644 --- a/src/token/token.ts +++ b/src/token/token.ts @@ -1,6 +1,6 @@ import { Collation } from '../collation'; -import { Metadata } from '../metadata-parser'; -import { ColumnMetadata } from './colmetadata-token-parser'; +import { type Metadata } from '../metadata-parser'; +import { type ColumnMetadata } from './colmetadata-token-parser'; import { TokenHandler } from './handler'; export const TYPE = { diff --git a/src/value-parser.ts b/src/value-parser.ts index 2c1f303c6..a0ce96ce3 100644 --- a/src/value-parser.ts +++ b/src/value-parser.ts @@ -1,5 +1,5 @@ -import Parser, { ParserOptions } from './token/stream-parser'; -import { Metadata, readCollation } from './metadata-parser'; +import Parser, { type ParserOptions } from './token/stream-parser'; +import { type Metadata, readCollation } from './metadata-parser'; import { TYPE } from './data-type'; import iconv from 'iconv-lite'; diff --git a/test/helpers/debug-options-from-env.ts b/test/helpers/debug-options-from-env.ts new file mode 100644 index 000000000..17603dd54 --- /dev/null +++ b/test/helpers/debug-options-from-env.ts @@ -0,0 +1,24 @@ +export function debugOptionsFromEnv() { + const options = { + packet: false, + data: false, + payload: false, + token: false, + }; + + if (!process.env.TEDIOUS_DEBUG) { + return options; + } + + for (const type of process.env.TEDIOUS_DEBUG.split(',')) { + switch (type) { + case 'packet': + case 'data': + case 'payload': + case 'token': + options[type] = true; + } + } + + return options; +} diff --git a/test/integration/binary-insert-test.js b/test/integration/binary-insert-test.js index 4a942f55d..4abd4ea2a 100644 --- a/test/integration/binary-insert-test.js +++ b/test/integration/binary-insert-test.js @@ -7,19 +7,13 @@ const TYPES = require('../../src/data-type').typeByName; import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; -config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true -}; - +config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; describe('inserting binary data', function() { @@ -28,6 +22,10 @@ describe('inserting binary data', function() { beforeEach(function(done) { this.connection = new Connection(config); this.connection.connect(done); + + if (process.env.TEDIOUS_DEBUG) { + this.connection.on('debug', console.log); + } }); afterEach(function(done) { diff --git a/test/integration/bulk-load-test.js b/test/integration/bulk-load-test.js index 35d59ac1b..185a72b66 100644 --- a/test/integration/bulk-load-test.js +++ b/test/integration/bulk-load-test.js @@ -9,8 +9,7 @@ const TYPES = require('../../src/data-type').typeByName; import Connection from '../../src/connection'; import { RequestError, ParameterValidationError } from '../../src/errors'; import Request from '../../src/request'; - -const debugMode = false; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const { config } = JSON.parse( @@ -21,14 +20,7 @@ function getConfig() { config.options.cancelTimeout = 1000; - if (debugMode) { - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true - }; - } + config.options.debug = debugOptionsFromEnv(); return config; } @@ -43,14 +35,14 @@ describe('BulkLoad', function() { connection = new Connection(getConfig()); connection.connect(done); - if (debugMode) { + if (process.env.TEDIOUS_DEBUG) { connection.on('debug', (message) => console.log(message)); - connection.on('infoMessage', (info) => - console.log('Info: ' + info.number + ' - ' + info.message) - ); - connection.on('errorMessage', (error) => - console.log('Error: ' + error.number + ' - ' + error.message) - ); + connection.on('infoMessage', (info) => { + console.log('Info: ' + info.number + ' - ' + info.message); + }); + connection.on('errorMessage', (error) => { + console.log('Error: ' + error.number + ' - ' + error.message); + }); } }); diff --git a/test/integration/collation-test.ts b/test/integration/collation-test.ts index ca087d25d..4ac02c1e7 100644 --- a/test/integration/collation-test.ts +++ b/test/integration/collation-test.ts @@ -6,6 +6,7 @@ import Connection from '../../src/connection'; import Request from '../../src/request'; import { Flags } from '../../src/collation'; import { TYPES } from '../../src/data-type'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const { config } = JSON.parse( @@ -13,6 +14,7 @@ function getConfig() { ); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; + config.options.debug = debugOptionsFromEnv(); return config; } @@ -33,6 +35,11 @@ describe('Database Collation Support', function() { connection.once('databaseChange', (databaseName) => { originalDatabaseName = databaseName; }); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect(done); }); diff --git a/test/integration/connection-test.js b/test/integration/connection-test.js index 24b111a4a..17bf5ef40 100644 --- a/test/integration/connection-test.js +++ b/test/integration/connection-test.js @@ -10,19 +10,14 @@ import Connection from '../../src/connection'; import { ConnectionError, RequestError } from '../../src/errors'; import Request from '../../src/request'; import { versions } from '../../src/tds-versions'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse( fs.readFileSync(homedir + '/.tedious/test-connection.json', 'utf8') ).config; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true, - }; + config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; @@ -54,9 +49,9 @@ describe('Initiate Connect Test', function() { done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(function(err) { assert.ok(err); @@ -100,9 +95,9 @@ describe('Initiate Connect Test', function() { return assert.ok(~error.message.indexOf('failed') || ~error.message.indexOf('登录失败')); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(function(err) { assert.ok(err); @@ -139,9 +134,9 @@ describe('Initiate Connect Test', function() { // console.log("#{info.number} : #{info.message}") }); - return connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should connect by instance name', function(done) { @@ -174,9 +169,9 @@ describe('Initiate Connect Test', function() { // console.log("#{info.number} : #{info.message}") }); - return connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should connect by invalid instance name', function(done) { @@ -205,9 +200,9 @@ describe('Initiate Connect Test', function() { // console.log("#{info.number} : #{info.message}") }); - return connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should potentially throw an error on invalid crypto credential details', function(done) { @@ -230,6 +225,9 @@ describe('Initiate Connect Test', function() { const config = getConfig(); const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect((err) => { if (err) { return done(err); @@ -244,6 +242,9 @@ describe('Initiate Connect Test', function() { const config = getConfig(); const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect((err) => { if (err) { return done(err); @@ -264,6 +265,9 @@ describe('Initiate Connect Test', function() { const config = getConfig(); const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.on('connect', (err) => { if (err) { return done(err); @@ -281,6 +285,10 @@ describe('Initiate Connect Test', function() { options: { connectTimeout: 30000 }, }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.on('connect', (err) => { try { assert.instanceOf(err, ConnectionError); @@ -307,6 +315,10 @@ describe('Initiate Connect Test', function() { }, }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.on('connect', (err) => { assert.instanceOf(err, ConnectionError); assert.strictEqual(/** @type {ConnectionError} */(err).code, 'EINSTLOOKUP'); @@ -331,6 +343,11 @@ describe('Initiate Connect Test', function() { }; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect(function(err) { assert.instanceOf(err, ConnectionError); assert.strictEqual(/** @type {ConnectionError} */(err).code, 'ESOCKET'); @@ -358,6 +375,10 @@ describe('Initiate Connect Test', function() { let connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { assert.ifError(err); @@ -386,6 +407,10 @@ describe('Initiate Connect Test', function() { let connection = new Connection({ ...config, options: { ...config.options, workstationId: 'foo.bar.baz' } }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { assert.ifError(err); @@ -402,6 +427,9 @@ describe('Initiate Connect Test', function() { config.options.connectTimeout = 1; const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.on('error', (error) => { assert.ifError(error); }); connection.connect((err) => { }); @@ -424,6 +452,10 @@ describe('Initiate Connect Test', function() { } }); + if (process.env.TEDIOUS_DEBUG) { + conn.on('debug', console.log); + } + conn.connect((err) => { conn.close(); @@ -508,9 +540,9 @@ describe('Ntlm Test', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } } it('should ntlm', function(done) { @@ -532,8 +564,16 @@ describe('Encrypt Test', function() { * @param {(err: Error | null, supportsTds8?: boolean) => void} callback */ function supportsTds8(config, callback) { + if (config.options.tdsVersion < '7_2') { + return callback(null, false); + } + const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { if (err) { return callback(err); @@ -549,12 +589,12 @@ describe('Encrypt Test', function() { return callback(err); } - if (!productMajorVersion || productMajorVersion < '2022') { + if (!productMajorVersion || productMajorVersion < '16') { connection.close(); return callback(null, false); } - if (productMajorVersion > '2022') { + if (productMajorVersion > '16') { connection.close(); return callback(null, true); } @@ -606,6 +646,9 @@ describe('Encrypt Test', function() { config.options.encrypt = 'strict'; connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); }); @@ -650,6 +693,9 @@ describe('Encrypt Test', function() { const config = getConfig(); config.options.encrypt = true; connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); @@ -690,6 +736,9 @@ describe('BeginTransaction Tests', function() { beforeEach(function(done) { const config = getConfig(); connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); @@ -765,9 +814,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - return connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); describe('when `useColumnNames` is `true`', function() { @@ -776,6 +825,11 @@ describe('Insertion Tests', function() { config.options.useColumnNames = true; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { if (err) { return done(err); @@ -811,6 +865,10 @@ describe('Insertion Tests', function() { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { if (err) { return done(err); @@ -856,6 +914,11 @@ describe('Insertion Tests', function() { config.options.useColumnNames = true; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { if (err) { return done(err); @@ -938,9 +1001,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should exec sql with order', function(done) { @@ -992,9 +1055,9 @@ describe('Insertion Tests', function() { // console.log("#{error.number} : #{error.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should exec Bad Sql', function(done) { @@ -1021,9 +1084,9 @@ describe('Insertion Tests', function() { assert.ok(error); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should close connection request pending', function(done) { @@ -1056,9 +1119,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should sql with multiple result sets', function(done) { @@ -1098,9 +1161,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should row count for update', function(done) { @@ -1134,9 +1197,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should row collection on request completion', function(done) { @@ -1172,9 +1235,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should row collection on Done', function(done) { @@ -1224,9 +1287,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should exec proc as sql', function(done) { @@ -1266,9 +1329,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should reset Connection', function(done) { @@ -1353,9 +1416,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should support cancelling a request while it is processed on the server', function(done) { @@ -1426,9 +1489,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', (text) => { - // console.log(text); - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should request timeout', (done) => { @@ -1478,9 +1541,9 @@ describe('Insertion Tests', function() { // console.log("#{info.number} : #{info.message}") }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); }); @@ -1494,6 +1557,10 @@ describe('Advanced Input Test', function() { function runSqlBatch(done, config, sql, requestCallback) { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request(sql, function(err, rowCount) { requestCallback(err, rowCount); connection.close(); @@ -1552,6 +1619,10 @@ describe('Date Insert Test', function() { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request('select @@datefirst', function(err) { assert.ifError(err); connection.close(); @@ -1607,6 +1678,10 @@ describe('Language Insert Test', function() { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request('select @@language', function(err) { assert.ifError(err); connection.close(); @@ -1643,6 +1718,11 @@ describe('custom textsize value', function() { config.options.textsize = 123456; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { /** * @type {number | undefined} @@ -1701,6 +1781,11 @@ describe('custom textsize value', function() { config.options.textsize = undefined; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { /** * @type {number | undefined} @@ -1732,6 +1817,11 @@ describe('custom textsize value', function() { config.options.textsize = -1; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { /** * @type {number | undefined} @@ -1767,6 +1857,11 @@ describe('custom textsize value', function() { config.options.textsize = 0; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { /** * @type {number | undefined} @@ -1798,6 +1893,11 @@ describe('custom textsize value', function() { config.options.textsize = 1000.0123; const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { /** * @type {number | undefined} @@ -1837,6 +1937,10 @@ describe('should test date format', function() { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request( 'SELECT DATE_FORMAT FROM sys.dm_exec_sessions WHERE SESSION_ID = @@SPID ', function(err) { @@ -1883,6 +1987,10 @@ describe('Boolean Config Options Test', function() { config.options[optionName] = optionValue; const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request( `SELECT (${optionFlag} & @@OPTIONS) AS OPTION_FLAG_OR_ZERO;`, function(err, rowCount) { diff --git a/test/integration/datatypes-in-results-test.ts b/test/integration/datatypes-in-results-test.ts index fc7d4a0aa..a395bcbb7 100644 --- a/test/integration/datatypes-in-results-test.ts +++ b/test/integration/datatypes-in-results-test.ts @@ -6,26 +6,14 @@ import Request from '../../src/request'; import { typeByName as TYPES } from '../../src/data-type'; import { homedir } from 'os'; - -const debug = false; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; const config = JSON.parse( fs.readFileSync(homedir() + '/.tedious/test-connection.json', 'utf8') ).config; -config.options.textsize = 8 * 1024; - -if (debug) { - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true, - }; -} else { - config.options.debug = {}; -} +config.options.textsize = 8 * 1024; +config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; describe('Datatypes in results test', function() { @@ -38,11 +26,9 @@ describe('Datatypes in results test', function() { console.log(`${error.number} : ${error.message}`); }); - connection.on('debug', function(message) { - if (debug) { - console.log(message); - } - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); diff --git a/test/integration/errors-test.js b/test/integration/errors-test.js index c5533ee69..fedbc9c60 100644 --- a/test/integration/errors-test.js +++ b/test/integration/errors-test.js @@ -2,30 +2,19 @@ const fs = require('fs'); const assert = require('chai').assert; -const debug = false; import AggregateError from 'es-aggregate-error'; import { RequestError } from '../../src/errors'; import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; -config.options.textsize = 8 * 1024; - -if (debug) { - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true - }; -} else { - config.options.debug = {}; -} +config.options.textsize = 8 * 1024; +config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; /** @@ -53,10 +42,8 @@ function execSql(done, sql, requestCallback) { done(); }); - if (debug) { - connection.on('debug', function(message) { - console.log(message); - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); } } @@ -153,16 +140,18 @@ describe('Errors Test', function() { done(); }); - if (debug) { - connection.on('debug', function(message) { - console.log(message); - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); } }); it('should support cancelling after starting query execution', function(done) { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + const request = new Request("select 42, 'hello world'", function(err, rowCount) { if (err) { assert.equal(err.message, 'Canceled.'); @@ -187,6 +176,10 @@ describe('Errors Test', function() { it('should throw aggregate error with two error messages', function(done) { const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { if (err) { return done(err); @@ -226,6 +219,10 @@ describe('Errors Test', function() { config.options.tdsVersion = '7_4'; const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + /** @type {Error | undefined} */ let connectionError; connection.connect((err) => { diff --git a/test/integration/invalid-packet-stream-test.js b/test/integration/invalid-packet-stream-test.js index ce33b59f8..e1e28ce26 100644 --- a/test/integration/invalid-packet-stream-test.js +++ b/test/integration/invalid-packet-stream-test.js @@ -2,6 +2,7 @@ const { assert } = require('chai'); const net = require('net'); +const { debugOptionsFromEnv } = require('../helpers/debug-options-from-env'); const Connection = require('../../src/tedious').Connection; const ConnectionError = require('../../src/errors').ConnectionError; @@ -55,9 +56,14 @@ describe('Connecting to a server that sends invalid packet data', function() { server: addressInfo.address, options: { port: addressInfo.port, + debug: debugOptionsFromEnv() } }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect((err) => { assert.instanceOf(err, ConnectionError); assert.equal(/** @type {ConnectionError} */(err).message, 'Connection lost - Unable to process incoming packet'); diff --git a/test/integration/parameterised-statements-test.js b/test/integration/parameterised-statements-test.js index e66ce2ca5..3fb3188a3 100644 --- a/test/integration/parameterised-statements-test.js +++ b/test/integration/parameterised-statements-test.js @@ -7,20 +7,14 @@ const TYPES = require('../../src/data-type').typeByName; import async from 'async'; import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true, - }; - + config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; return config; @@ -101,9 +95,9 @@ function execSql(done, type, value, tdsVersion, options, expectedValue, cast, co console.log(`${error.number} : ${error.message}`); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } } /** @@ -163,9 +157,9 @@ function execSqlOutput(done, type, value, expectedValue, connectionOptions) { done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } } describe('Parameterised Statements Test', function() { @@ -989,12 +983,17 @@ describe('Parameterised Statements Test', function() { it('supports TVP values', function(done) { const config = getConfig(); - const connection = new Connection(config); if (config.options.tdsVersion < '7_3_A') { this.skip(); } + const connection = new Connection(config); + + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } + connection.connect(function(err) { if (err) { return done(err); @@ -1168,9 +1167,9 @@ describe('Parameterised Statements Test', function() { done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should call procedure with parameters', function(done) { @@ -1251,9 +1250,9 @@ end')\ done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); }); diff --git a/test/integration/pause-resume-test.js b/test/integration/pause-resume-test.js index b3475eadc..22120813d 100644 --- a/test/integration/pause-resume-test.js +++ b/test/integration/pause-resume-test.js @@ -6,10 +6,12 @@ const assert = require('chai').assert; import Connection from '../../src/connection'; import Request from '../../src/request'; import { RequestError } from '../../src/errors'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse(fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8')).config; config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; + config.options.debug = debugOptionsFromEnv(); // 250 ms timeout until the first response package is received config.options.requestTimeout = 250; return config; @@ -22,6 +24,9 @@ describe('Pause-Resume Test', function() { beforeEach(function(done) { connection = new Connection(getConfig()); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); diff --git a/test/integration/prepare-execute-statements-test.js b/test/integration/prepare-execute-statements-test.js index 56a55689b..61b448129 100644 --- a/test/integration/prepare-execute-statements-test.js +++ b/test/integration/prepare-execute-statements-test.js @@ -6,20 +6,14 @@ const assert = require('chai').assert; import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: false, - log: true, - }; - + config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; return config; @@ -58,15 +52,18 @@ describe('Prepare Execute Statement', function() { done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('does not cause unexpected `returnValue` events to be emitted', function(done) { const config = getConfig(); const connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(function(err) { if (err) { return done(err); @@ -138,7 +135,9 @@ describe('Prepare Execute Statement', function() { }); const connection = new Connection(config); - + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } request.on('prepared', function() { connection.execute(request); }); @@ -185,8 +184,8 @@ describe('Prepare Execute Statement', function() { done(); }); - connection.on('debug', function(text) { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); }); diff --git a/test/integration/rpc-test.js b/test/integration/rpc-test.js index 78f55dfdb..a58a87abb 100644 --- a/test/integration/rpc-test.js +++ b/test/integration/rpc-test.js @@ -6,19 +6,14 @@ const assert = require('chai').assert; import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true, - }; + config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; @@ -46,9 +41,9 @@ describe('RPC test', function() { console.log(`${error.number} : ${error.message}`); }); - connection.on('debug', (text) => { - // console.log(text) - }); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); afterEach(function(done) { @@ -360,11 +355,9 @@ set @paramOut = @paramIn\ assert.ok(error); }); - connection.on( - 'debug', - function(text) { } - // console.log(text) - ); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); it('should proc return value', function(done) { @@ -414,11 +407,9 @@ set @paramOut = @paramIn\ assert.ok(error); }); - connection.on( - 'debug', - function(text) { } - // console.log(text) - ); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } }); }); diff --git a/test/integration/socket-error-test.js b/test/integration/socket-error-test.js index 37a552de9..27ea2073a 100644 --- a/test/integration/socket-error-test.js +++ b/test/integration/socket-error-test.js @@ -5,19 +5,14 @@ const { assert } = require('chai'); import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: false, - log: true - }; + config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; @@ -37,6 +32,9 @@ describe('A `error` on the network socket', function() { connection = new Connection(getConfig()); connection.on('error', done); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect((err) => { connection.removeListener('error', done); done(err); diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index 6bcda5183..578b6e1f0 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -3,26 +3,14 @@ const Request = require('../../src/request'); const Transaction = require('../../src/transaction'); const fs = require('fs'); const async = require('async'); +const { debugOptionsFromEnv } = require('../helpers/debug-options-from-env'); const assert = require('chai').assert; -const debug = false; - const config = JSON.parse( fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8') ).config; -if (debug) { - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true - }; -} else { - config.options.debug = {}; -} - +config.options.debug = debugOptionsFromEnv(); config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; class Tester { @@ -52,11 +40,9 @@ class Tester { console.log(`${error.number} : ${error.message}`); }); - this.connection.on('debug', (message) => { - if (debug) { - console.log(message); - } - }); + if (process.env.TEDIOUS_DEBUG) { + this.connection.on('debug', console.log); + } } createTable(callback) { diff --git a/test/integration/tvp-test.js b/test/integration/tvp-test.js index 454e5a67c..333a3c3e8 100644 --- a/test/integration/tvp-test.js +++ b/test/integration/tvp-test.js @@ -7,6 +7,7 @@ const { assert } = require('chai'); import Connection from '../../src/connection'; import Request from '../../src/request'; +import { debugOptionsFromEnv } from '../helpers/debug-options-from-env'; function getConfig() { var config = JSON.parse( @@ -15,13 +16,7 @@ function getConfig() { config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION; - config.options.debug = { - packet: true, - data: true, - payload: true, - token: true, - log: true - }; + config.options.debug = debugOptionsFromEnv(); return config; } @@ -37,6 +32,9 @@ describe('calling a procedure that takes and returns a TVP', function() { config = getConfig(); connection = new Connection(config); + if (process.env.TEDIOUS_DEBUG) { + connection.on('debug', console.log); + } connection.connect(done); }); diff --git a/test/unit/message-io-test.ts b/test/unit/message-io-test.ts index ddd053e87..b7f94c632 100644 --- a/test/unit/message-io-test.ts +++ b/test/unit/message-io-test.ts @@ -1,4 +1,4 @@ -import { AddressInfo, createConnection, createServer, Server, Socket } from 'net'; +import { type AddressInfo, createConnection, createServer, Server, Socket } from 'net'; import { once } from 'events'; import { assert } from 'chai'; import { promisify } from 'util'; diff --git a/tsconfig.json b/tsconfig.json index 6b793d211..2b2394143 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,13 +5,13 @@ "allowJs": true, "noEmit": true, "strict": true, - "isolatedModules": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "lib": [ "esnext" ], "skipLibCheck": true, "resolveJsonModule": true, - "exactOptionalPropertyTypes": true + "exactOptionalPropertyTypes": true, + "verbatimModuleSyntax": true }, "include": [