Skip to content

Commit

Permalink
Merge pull request #933 from dhensby/pulls/push-for-stable
Browse files Browse the repository at this point in the history
Upgrade dependencies and fix linting rules
  • Loading branch information
dhensby authored Nov 5, 2019
2 parents b63c771 + a53fbf8 commit 624219a
Show file tree
Hide file tree
Showing 17 changed files with 989 additions and 1,013 deletions.
45 changes: 23 additions & 22 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ISOLATION_LEVEL = require('./isolationlevel')
const Table = require('./table')
const ConnectionString = require('./connectionstring')
const IDS = require('./utils').IDS
const objectHasProperty = require('./utils').objectHasProperty

let globalConnection = null
let PromiseLibrary = Promise
Expand All @@ -27,7 +28,7 @@ const driver = {}

map.register = function (jstype, sqltype) {
for (let index = 0; index < this.length; index++) {
let item = this[index]
const item = this[index]
if (item.js === jstype) {
this.splice(index, 1)
break
Expand All @@ -53,7 +54,7 @@ map.register(Table, TYPES.TVP)
* @ignore
*/

let getTypeByValue = function (value) {
const getTypeByValue = function (value) {
if ((value === null) || (value === undefined)) { return TYPES.NVarChar }

switch (typeof value) {
Expand Down Expand Up @@ -548,7 +549,7 @@ class PreparedStatement extends EventEmitter {
type = type()
}

if (this.parameters.hasOwnProperty(name)) {
if (objectHasProperty(this.parameters, name)) {
throw new PreparedStatementError(`The parameter name ${name} has already been declared. Parameter names must be unique`, 'EDUPEPARAM')
}

Expand Down Expand Up @@ -599,7 +600,7 @@ class PreparedStatement extends EventEmitter {

if (type instanceof Function) type = type()

if (this.parameters.hasOwnProperty(name)) {
if (objectHasProperty(this.parameters, name)) {
throw new PreparedStatementError(`The parameter name ${name} has already been declared. Parameter names must be unique`, 'EDUPEPARAM')
}

Expand Down Expand Up @@ -681,12 +682,12 @@ class PreparedStatement extends EventEmitter {
req.stream = false
req.output('handle', TYPES.Int)
req.input('params', TYPES.NVarChar, ((() => {
let result = []
for (let name in this.parameters) {
if (!this.parameters.hasOwnProperty(name)) {
const result = []
for (const name in this.parameters) {
if (!objectHasProperty(this.parameters, name)) {
continue
}
let param = this.parameters[name]
const param = this.parameters[name]
result.push(`@${name} ${declare(param.type, param)}${param.io === 2 ? ' output' : ''}`)
}
return result
Expand Down Expand Up @@ -744,11 +745,11 @@ class PreparedStatement extends EventEmitter {
req.input('handle', TYPES.Int, this._handle)

// copy parameters with new values
for (let name in this.parameters) {
if (!this.parameters.hasOwnProperty(name)) {
for (const name in this.parameters) {
if (!objectHasProperty(this.parameters, name)) {
continue
}
let param = this.parameters[name]
const param = this.parameters[name]
req.parameters[name] = {
name,
type: param.type,
Expand Down Expand Up @@ -1112,10 +1113,10 @@ class Request extends EventEmitter {
*/

_template (strings, values, method) {
let command = [strings[0]]
const command = [strings[0]]

for (let index = 0; index < values.length; index++) {
let value = values[index]
const value = values[index]
// if value is an array, prepare each items as it's own comma separated parameter
if (Array.isArray(value)) {
for (let parameterIndex = 0; parameterIndex < value.length; parameterIndex++) {
Expand Down Expand Up @@ -1168,7 +1169,7 @@ class Request extends EventEmitter {
if (typeof value === 'number' && isNaN(value)) value = null // NaN to null
if (type instanceof Function) type = type()

if (this.parameters.hasOwnProperty(name)) {
if (objectHasProperty(this.parameters, name)) {
throw new RequestError(`The parameter name ${name} has already been declared. Parameter names must be unique`, 'EDUPEPARAM')
}

Expand Down Expand Up @@ -1228,7 +1229,7 @@ class Request extends EventEmitter {
if (typeof value === 'number' && isNaN(value)) value = null // NaN to null
if (type instanceof Function) type = type()

if (this.parameters.hasOwnProperty(name)) {
if (objectHasProperty(this.parameters, name)) {
throw new RequestError(`The parameter name ${name} has already been declared. Parameter names must be unique`, 'EDUPEPARAM')
}

Expand Down Expand Up @@ -1814,8 +1815,8 @@ Object.defineProperty(module.exports, 'Promise', {

// append datatypes to this modules export

for (let key in TYPES) {
let value = TYPES[key]
for (const key in TYPES) {
const value = TYPES[key]
module.exports.exports[key] = value
module.exports.exports[key.toUpperCase()] = value
}
Expand All @@ -1834,7 +1835,7 @@ module.exports.exports.connect = function connect (config, callback) {
}
globalConnection = new driver.ConnectionPool(config)

for (let event in globalConnectionHandlers) {
for (const event in globalConnectionHandlers) {
for (let i = 0, l = globalConnectionHandlers[event].length; i < l; i++) {
globalConnection.on(event, globalConnectionHandlers[event][i])
}
Expand All @@ -1844,17 +1845,17 @@ module.exports.exports.connect = function connect (config, callback) {

function globalClose (callback) {
// remove event handlers from the global connection
for (let event in globalConnectionHandlers) {
for (const event in globalConnectionHandlers) {
for (let i = 0, l = globalConnectionHandlers[event].length; i < l; i++) {
this.removeListener(event, globalConnectionHandlers[event][i])
}
}

// attach error handler to prevent process crash in case of error
this.on('error', err => {
if (globalConnectionHandlers['error']) {
for (let i = 0, l = globalConnectionHandlers['error'].length; i < l; i++) {
globalConnectionHandlers['error'][i].call(this, err)
if (globalConnectionHandlers.error) {
for (let i = 0, l = globalConnectionHandlers.error.length; i < l; i++) {
globalConnectionHandlers.error[i].call(this, err)
}
}
})
Expand Down
31 changes: 13 additions & 18 deletions lib/connectionstring.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const url = require('url')
const qs = require('querystring')
const URL = require('url').URL

const IGNORE_KEYS = ['stream']
const oror = function () {
Expand All @@ -13,7 +12,7 @@ const oror = function () {
}

const parseConnectionURI = function (uri) {
const parsed = url.parse(uri)
const parsed = new URL(uri)
let instance
let user
let password
Expand All @@ -23,10 +22,10 @@ const parseConnectionURI = function (uri) {
instance = path.shift()
}

if (parsed.auth) {
parsed.auth = parsed.auth.split(':')
user = parsed.auth.shift()
password = parsed.auth.join(':')
if (parsed.username) {
const auth = [parsed.username, parsed.password]
user = auth.shift()
password = decodeURIComponent(auth.join(':'))
}

const port = parsed.port ? `,${parsed.port}` : (instance ? `\\${instance}` : '')
Expand All @@ -37,18 +36,14 @@ const parseConnectionURI = function (uri) {
database: path[0]
}

if (parsed.query) {
const query = qs.parse(parsed.query)
for (const key in query) {
if (Object.prototype.hasOwnProperty.call(query, key)) {
const value = query[key]
if (key === 'domain') {
object.uid = `${value}\\${object.uid}`
} else {
object[key] = value
}
if (parsed.searchParams) {
parsed.searchParams.forEach((value, key) => {
if (key === 'domain') {
object.uid = `${value}\\${object.uid}`
} else {
object[key] = value
}
}
})
}

Object.defineProperty(object, 'toString', {
Expand Down
3 changes: 2 additions & 1 deletion lib/datatypes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
const objectHasProperty = require('./utils').objectHasProperty

const TYPES = {
VarChar (length) {
Expand Down Expand Up @@ -118,7 +119,7 @@ const zero = function (value, length) {
}

for (const key in TYPES) {
if (Object.prototype.hasOwnProperty.call(TYPES, key)) {
if (objectHasProperty(TYPES, key)) {
const value = TYPES[key]
value.declaration = key.toLowerCase()
module.exports.DECLARATIONS[value.declaration] = value;
Expand Down
Loading

0 comments on commit 624219a

Please sign in to comment.