diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index b8e376ba5..6a001bbda 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -63,7 +63,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x] fail-fast: false services: diff --git a/appveyor.yml b/appveyor.yml index 20536ca83..a4da6aeee 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,6 @@ version: "{build}" environment: matrix: - - nodejs_version: "10" - nodejs_version: "12" - nodejs_version: "14" - nodejs_version: "16" diff --git a/package.json b/package.json index 8298c0545..8174290cb 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "url": "https://github.com/tediousjs/tedious.git" }, "engines": { - "node": ">= 10" + "node": ">= 12" }, "publishConfig": { "tag": "next" @@ -108,7 +108,7 @@ "@babel/preset-env", { "targets": { - "node": 10 + "node": 12 } } ], diff --git a/src/bulk-load.ts b/src/bulk-load.ts index 86f0de0b4..e36f83115 100644 --- a/src/bulk-load.ts +++ b/src/bulk-load.ts @@ -179,12 +179,10 @@ class RowTransform extends Transform { const c = this.columns[i]; let value = Array.isArray(row) ? row[i] : row[c.objName]; - if (this.bulkLoad.options.validateBulkLoadParameters) { - try { - value = c.type.validate(value); - } catch (error) { - return callback(error); - } + try { + value = c.type.validate(value); + } catch (error) { + return callback(error); } const parameter = { @@ -493,23 +491,11 @@ class BulkLoad extends EventEmitter { // write each column if (Array.isArray(row)) { this.rowToPacketTransform.write(this.columns.map((column, i) => { - let value = row[i]; - - if (this.options.validateBulkLoadParameters) { - value = column.type.validate(value); - } - - return value; + return column.type.validate(row[i]); })); } else { this.rowToPacketTransform.write(this.columns.map((column) => { - let value = row[column.objName]; - - if (this.options.validateBulkLoadParameters) { - value = column.type.validate(value); - } - - return value; + return column.type.validate(row[column.objName]); })); } } diff --git a/src/connection.ts b/src/connection.ts index f3375f610..65aa21033 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -384,7 +384,6 @@ export interface InternalConnectionOptions { trustServerCertificate: boolean; useColumnNames: boolean; useUTC: boolean; - validateBulkLoadParameters: boolean; workstationId: undefined | string; lowerCaseGuids: boolean; } @@ -824,13 +823,6 @@ export interface ConnectionOptions { */ useUTC?: boolean; - /** - * A boolean determining whether BulkLoad parameters should be validated. - * - * (default: `true`). - */ - validateBulkLoadParameters?: boolean; - /** * The workstation ID (WSID) of the client, default os.hostname(). * Used for identifying a specific client in profiling, logging or @@ -1276,7 +1268,6 @@ class Connection extends EventEmitter { trustServerCertificate: true, useColumnNames: false, useUTC: true, - validateBulkLoadParameters: true, workstationId: undefined, lowerCaseGuids: false } @@ -1677,18 +1668,6 @@ class Connection extends EventEmitter { this.config.options.useUTC = config.options.useUTC; } - if (config.options.validateBulkLoadParameters !== undefined) { - if (typeof config.options.validateBulkLoadParameters !== 'boolean') { - throw new TypeError('The "config.options.validateBulkLoadParameters" property must be of type boolean.'); - } - - if (config.options.validateBulkLoadParameters === false) { - deprecate('Setting the "config.options.validateBulkLoadParameters" to `false` is deprecated and will no longer work in the next major version of `tedious`. Set the value to `true` and update your use of BulkLoad functionality to silence this message.'); - } - - this.config.options.validateBulkLoadParameters = config.options.validateBulkLoadParameters; - } - if (config.options.workstationId !== undefined) { if (typeof config.options.workstationId !== 'string') { throw new TypeError('The "config.options.workstationId" property must be of type string.'); diff --git a/test/integration/bulk-load-test.js b/test/integration/bulk-load-test.js index 7a4d54f81..5775e643d 100644 --- a/test/integration/bulk-load-test.js +++ b/test/integration/bulk-load-test.js @@ -1690,117 +1690,86 @@ describe('BulkLoad', function() { connection.execSqlBatch(request); }); -}); - -describe('Bulk Loads when `config.options.validateBulkLoadParameters` is `true`', () => { - /** - * @type {Connection} - */ - let connection; - beforeEach(function(done) { - const config = getConfig(); - config.options = { ...config.options, validateBulkLoadParameters: true }; - connection = new Connection(config); - connection.connect(done); - - if (debugMode) { - 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) - ); - } - }); + describe('validation errors', function() { + beforeEach(function(done) { + const request = new Request('create table #stream_test ([value] date)', (err) => { + done(err); + }); - beforeEach(function(done) { - const request = new Request('create table #stream_test ([value] date)', (err) => { - done(err); + connection.execSqlBatch(request); }); - connection.execSqlBatch(request); - }); + it('should handle validation errors during streaming bulk loads', (done) => { + const bulkLoad = connection.newBulkLoad('#stream_test', completeBulkLoad); + bulkLoad.addColumn('value', TYPES.Date, { nullable: false }); - afterEach(function(done) { - if (!connection.closed) { - connection.on('end', done); - connection.close(); - } else { - done(); - } - }); + const rowStream = bulkLoad.getRowStream(); + connection.execBulkLoad(bulkLoad); - it('should handle validation errors during streaming bulk loads', (done) => { - const bulkLoad = connection.newBulkLoad('#stream_test', completeBulkLoad); - bulkLoad.addColumn('value', TYPES.Date, { nullable: false }); + const rowSource = Readable.from([ + ['invalid date'] + ]); - const rowStream = bulkLoad.getRowStream(); - connection.execBulkLoad(bulkLoad); + pipeline(rowSource, rowStream, (err) => { + assert.instanceOf(err, TypeError); + assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); + }); - const rowSource = Readable.from([ - ['invalid date'] - ]); + /** + * @param {Error | undefined | null} err + * @param {undefined | number} rowCount + */ + function completeBulkLoad(err, rowCount) { + assert.instanceOf(err, TypeError); + assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); - pipeline(rowSource, rowStream, (err) => { - assert.instanceOf(err, TypeError); - assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); + done(); + } }); - /** - * @param {Error | undefined | null} err - * @param {undefined | number} rowCount - */ - function completeBulkLoad(err, rowCount) { - assert.instanceOf(err, TypeError); - assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); - - done(); - } - }); - - it('should allow reusing the connection after validation errors during streaming bulk loads', (done) => { - const bulkLoad = connection.newBulkLoad('#stream_test', completeBulkLoad); - bulkLoad.addColumn('value', TYPES.Date, { nullable: false }); - - const rowStream = bulkLoad.getRowStream(); - connection.execBulkLoad(bulkLoad); - - const rowSource = Readable.from([ ['invalid date'] ]); + it('should allow reusing the connection after validation errors during streaming bulk loads', (done) => { + const bulkLoad = connection.newBulkLoad('#stream_test', completeBulkLoad); + bulkLoad.addColumn('value', TYPES.Date, { nullable: false }); - pipeline(rowSource, rowStream, (err) => { - assert.instanceOf(err, TypeError); - assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); - }); + const rowStream = bulkLoad.getRowStream(); + connection.execBulkLoad(bulkLoad); - /** - * @param {Error | undefined | null} err - * @param {undefined | number} rowCount - */ - function completeBulkLoad(err, rowCount) { - assert.instanceOf(err, TypeError); - assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); + const rowSource = Readable.from([ ['invalid date'] ]); - assert.strictEqual(rowCount, 0); + pipeline(rowSource, rowStream, (err) => { + assert.instanceOf(err, TypeError); + assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); + }); /** - * @type {unknown[]} + * @param {Error | undefined | null} err + * @param {undefined | number} rowCount */ - const rows = []; - const request = new Request('SELECT 1', (err) => { - assert.ifError(err); + function completeBulkLoad(err, rowCount) { + assert.instanceOf(err, TypeError); + assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.'); - assert.deepEqual([1], rows); + assert.strictEqual(rowCount, 0); - done(); - }); + /** + * @type {unknown[]} + */ + const rows = []; + const request = new Request('SELECT 1', (err) => { + assert.ifError(err); - request.on('row', (row) => { - rows.push(row[0].value); - }); + assert.deepEqual([1], rows); - connection.execSql(request); - } + done(); + }); + + request.on('row', (row) => { + rows.push(row[0].value); + }); + + connection.execSql(request); + } + }); }); }); diff --git a/test/unit/bulk-load-test.js b/test/unit/bulk-load-test.js index 47822855a..ec071f297 100644 --- a/test/unit/bulk-load-test.js +++ b/test/unit/bulk-load-test.js @@ -10,7 +10,7 @@ describe('BulkLoad', function() { }); it('throws an error when adding row with a value has the wrong data type', function() { - const request = new BulkLoad('tablename', { tdsVersion: '7_2', validateBulkLoadParameters: true }, { }); + const request = new BulkLoad('tablename', { tdsVersion: '7_2' }, { }); request.addColumn('columnName', TYPES.Date, { nullable: true }); assert.throws(() => { request.addRow({ columnName: 'Wrong Input' }); diff --git a/test/unit/connection-config-validation.js b/test/unit/connection-config-validation.js index 97b6b14fe..df94c6c0a 100644 --- a/test/unit/connection-config-validation.js +++ b/test/unit/connection-config-validation.js @@ -94,13 +94,4 @@ describe('Connection configuration validation', function() { new Connection(config); }); }); - - it('bad validateBulkLoadParameters value', () => { - const validateBulkLoadParametersVal = 'text'; - config.options.validateBulkLoadParameters = validateBulkLoadParametersVal; - config.options.tdsVersion = '7_2'; - assert.throws(() => { - new Connection(config); - }); - }); });