Skip to content

Commit 667e528

Browse files
authored
Merge pull request #308 from TimelordUK/elec27
Elec27
2 parents 586744d + 81671e5 commit 667e528

35 files changed

+519
-1913
lines changed

.eslintrc

-24
This file was deleted.

.eslintrc.cjs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
extends: [
3+
"eslint:recommended",
4+
"plugin:@typescript-eslint/eslint-recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"standard-with-typescript"
7+
],
8+
parser: '@typescript-eslint/parser',
9+
"plugins": [
10+
"@typescript-eslint"
11+
],
12+
root: true,
13+
rules: {
14+
"@typescript-eslint/no-explicit-any":"off",
15+
"@typescript-eslint/return-await": "off",
16+
"@typescript-eslint/no-this-alias": "off",
17+
"@typescript-eslint/no-var-requires": "off",
18+
"@typescript-eslint/no-unused-vars": "off",
19+
"@typescript-eslint/restrict-template-expressions": "off",
20+
"@typescript-eslint/no-misused-promises": "off",
21+
"@typescript-eslint/strict-boolean-expressions": "off",
22+
"@typescript-eslint/consistent-type-assertions": "off",
23+
"@typescript-eslint/no-extraneous-class": "off",
24+
"@typescript-eslint/no-dynamic-delete": "off",
25+
"no-this-assignment": "off",
26+
"no-async-promise-executor": "off",
27+
"valid-typeof": "off",
28+
"@typescript-eslint/consistent-type-imports":"off",
29+
"@typescript-eslint/ban-types":"off",
30+
"@typescript-eslint/prefer-ts-expect-error":"off",
31+
"@typescript-eslint/explicit-function-return-type":"off"
32+
},
33+
};

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1. *new* Ubuntu, Debian Node v18, v20 - install openssl 3.2 see WIKI
1010
1. docker images see WIKI
1111
1. *new* support always on encryption via tables and procedures.
12-
1. *new* support Node v20
13-
1. *new* support electron v24
12+
1. *new* support Node v20, v21
13+
1. *new* support electron v24, v25, v26
1414
1. *new* read numerics as strings - see WIKI
1515
1. Sybase Adaptive Server Enterprise support - see WIKI
1616
1. thread worker support - see WIKI

lib/base-promises.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
'use strict'
22

33
class BasePromises {
4-
op (f) {
4+
async op (f) {
55
return new Promise((resolve, reject) => {
66
setImmediate(() => {
77
try {
88
f((err, v) => {
99
if (err) {
10-
setImmediate(() => reject(err))
10+
setImmediate(() => { reject(err) })
1111
} else {
12-
setImmediate(() => resolve(v))
12+
setImmediate(() => { resolve(v) })
1313
}
1414
})
1515
} catch (e) {
16-
setImmediate(() => reject(e))
16+
setImmediate(() => { reject(e) })
1717
}
1818
})
1919
})

lib/connection.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PrivateConnection {
5555
open () {
5656
this.nf.validateParameters(this.validationParams(), this.parentFn)
5757
this.callback2 = this.callback2 || this.defaultCallback
58-
this.native.open(this.connectObj, (e, c) => this.queueCb(e, c))
58+
this.native.open(this.connectObj, (e, c) => { this.queueCb(e, c) })
5959
}
6060

6161
decodeSqlServerVersion (connectionString) {
@@ -75,47 +75,47 @@ class ConnectionWrapperPromises extends BasePromises {
7575
this.aggregator = new utilModule.QueryAggregator(connection)
7676
}
7777

78-
callProc (name, params, options) {
78+
async callProc (name, params, options) {
7979
return this.aggregator.callProc(name, params, options)
8080
}
8181

82-
query (sql, params, options) {
82+
async query (sql, params, options) {
8383
return this.aggregator.query(sql, params, options)
8484
}
8585

86-
getTable (name) {
86+
async getTable (name) {
8787
return this.op(cb => this.tm.getTable(name, cb))
8888
}
8989

90-
getProc (name) {
90+
async getProc (name) {
9191
return this.op(cb => this.pm.getProc(name, cb))
9292
}
9393

94-
getUserTypeTable (type) {
94+
async getUserTypeTable (type) {
9595
return this.op(cb => this.connection.getUserTypeTable(type, cb))
9696
}
9797

98-
cancel (q) {
98+
async cancel (q) {
9999
return this.op(cb => this.connection.cancel(q, cb))
100100
}
101101

102-
close () {
102+
async close () {
103103
return this.op(cb => this.connection.close(cb))
104104
}
105105

106-
prepare (sqlQuery) {
106+
async prepare (sqlQuery) {
107107
return this.op(cb => this.connection.prepare(sqlQuery, cb))
108108
}
109109

110-
beginTransaction () {
110+
async beginTransaction () {
111111
return this.op(cb => this.connection.beginTransaction(cb))
112112
}
113113

114-
commit () {
114+
async commit () {
115115
return this.op(cb => this.connection.commit(cb))
116116
}
117117

118-
rollback () {
118+
async rollback () {
119119
return this.op(cb => this.connection.rollback(cb))
120120
}
121121
}
@@ -146,7 +146,7 @@ class ConnectionWrapper {
146146
}
147147

148148
getUserTypeTable (name, callback) {
149-
return this.tables.getUserTypeTable(name, callback)
149+
this.tables.getUserTypeTable(name, callback)
150150
}
151151

152152
tableMgr () {
@@ -242,7 +242,7 @@ class ConnectionWrapper {
242242
}
243243

244244
if (chunky.callback) {
245-
return this.queryRawNotify(notify, queryOrObj, this.notifier.getChunkyArgs(chunky.params, (err, results, more) => {
245+
this.queryRawNotify(notify, queryOrObj, this.notifier.getChunkyArgs(chunky.params, (err, results, more) => {
246246
setImmediate(() => {
247247
onQueryRaw(err, results, more)
248248
})
@@ -371,11 +371,11 @@ class ConnectionWrapper {
371371
}
372372

373373
getTable (name, cb) {
374-
return this.tables.getTable(name, cb)
374+
this.tables.getTable(name, cb)
375375
}
376376

377377
// returns a promise of aggregated results not a query
378-
callprocAggregator (name, params, options) {
378+
async callprocAggregator (name, params, options) {
379379
return this.promises.callProc(name, params, options)
380380
}
381381
}

lib/driver.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const driverModule = ((() => {
177177
if (queryId >= 0) {
178178
this.workQueue.enqueue(driverCommandEnum.FREE_STATEMENT, () => {
179179
this.cppDriver.freeStatement(queryId,
180-
() => this.raiseFree(queryId, notify, callback))
180+
() => { this.raiseFree(queryId, notify, callback) })
181181
}, [])
182182
} else {
183183
this.raiseFree(queryId, notify, callback)
@@ -213,19 +213,19 @@ const driverModule = ((() => {
213213

214214
beginTransaction (callback) {
215215
this.workQueue.enqueue(driverCommandEnum.BEGIN_TRANSACTION, () => {
216-
this.cppDriver.beginTransaction(err => this.next(callback, err))
216+
this.cppDriver.beginTransaction(err => { this.next(callback, err) })
217217
}, [])
218218
}
219219

220220
rollback (callback) {
221221
this.workQueue.enqueue(driverCommandEnum.ROLLBACK, () => {
222-
this.cppDriver.rollback(err => this.next(callback, err))
222+
this.cppDriver.rollback(err => { this.next(callback, err) })
223223
}, [])
224224
}
225225

226226
commit (callback) {
227227
this.workQueue.enqueue(driverCommandEnum.COMMIT, () => {
228-
this.cppDriver.commit(err => this.next(callback, err))
228+
this.cppDriver.commit(err => { this.next(callback, err) })
229229
}, [])
230230
}
231231

@@ -266,7 +266,7 @@ const driverModule = ((() => {
266266

267267
headPaused (notify, queryObj, params, cb) {
268268
const peek = this.workQueue.peek()
269-
const paused = peek && peek.paused
269+
const paused = peek?.paused
270270
if (paused) {
271271
const pausedNotify = peek.args[0]
272272
this.freeStatement(pausedNotify, () => {

lib/meta.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const metaModule = (() => {
1010
this.file = file
1111
}
1212

13-
readFile (f) {
13+
async readFile (f) {
1414
return new Promise((resolve, reject) => {
1515
fs.readFile(f, 'utf8', (err, contents) => {
1616
if (err) {
@@ -22,7 +22,7 @@ const metaModule = (() => {
2222
})
2323
}
2424

25-
resolve () {
25+
async resolve () {
2626
return new Promise((resolve, reject) => {
2727
if (!this.resolvedSql) {
2828
const p = path.join(__dirname, 'queries', this.file)
@@ -38,7 +38,7 @@ const metaModule = (() => {
3838
})
3939
}
4040

41-
query (conn, mapFn) {
41+
async query (conn, mapFn) {
4242
const inst = this
4343
return new Promise((resolve, reject) => {
4444
inst.resolve().then(sql => {
@@ -66,7 +66,7 @@ const metaModule = (() => {
6666
this.describeTable2014 = new FileReader('table_describe.2014.sql')
6767
}
6868

69-
getUserType (conn, userTypeName, mapFn) {
69+
async getUserType (conn, userTypeName, mapFn) {
7070
return new Promise((resolve, reject) => {
7171
this.describeTableType.query(conn, mapFn).then(typeResults => {
7272
typeResults.forEach(col => {
@@ -82,15 +82,15 @@ const metaModule = (() => {
8282
})
8383
}
8484

85-
getProcedureDefinition (conn, procedureName, mapFn) {
85+
async getProcedureDefinition (conn, procedureName, mapFn) {
8686
return this.describeProc.query(conn, mapFn)
8787
}
8888

89-
getServerVersionRes (conn) {
89+
async getServerVersionRes (conn) {
9090
return this.describeServerVersion.query(conn)
9191
}
9292

93-
getTableDefinition (conn, majorVersion, mapFn) {
93+
async getTableDefinition (conn, majorVersion, mapFn) {
9494
const target = majorVersion <= 2014 ? this.describeTable2014 : this.describeTable
9595
return target.query(conn, mapFn)
9696
}

lib/notifier.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const notifyModule = ((() => {
3535
this.se = se
3636
}
3737

38-
cancel (timeout) {
38+
async cancel (timeout) {
3939
timeout = timeout || 5000
4040
const q = this.se
4141
let err
@@ -163,7 +163,7 @@ const notifyModule = ((() => {
163163

164164
getChunkyArgs (paramsOrCallback, callback) {
165165
if ((typeof paramsOrCallback === 'object' &&
166-
Array.isArray(paramsOrCallback) === true) &&
166+
Array.isArray(paramsOrCallback)) &&
167167
typeof callback === 'function') {
168168
return new ChunkyArgs(paramsOrCallback, callback)
169169
}
@@ -177,7 +177,7 @@ const notifyModule = ((() => {
177177
}
178178

179179
if ((typeof paramsOrCallback === 'object' &&
180-
Array.isArray(paramsOrCallback) === true) &&
180+
Array.isArray(paramsOrCallback)) &&
181181
callback === undefined) {
182182
return new ChunkyArgs(paramsOrCallback, null)
183183
}

lib/pool.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ const poolModule = (() => {
361361
pause.unshift(add.pop())
362362
}
363363
if (start !== pause.length) {
364-
setImmediate(() => crank())
364+
setImmediate(() => { crank() })
365365
}
366366
}
367367

@@ -413,7 +413,7 @@ const poolModule = (() => {
413413
return new PoolWorkItem(commandId++, sql, paramsOrCallback, callback, notifier, workType, chunk(paramsOrCallback, callback, workType))
414414
}
415415

416-
function checkClosedPromise () {
416+
async function checkClosedPromise () {
417417
return new Promise((resolve, reject) => {
418418
if (closed) {
419419
reject(closedError)
@@ -456,26 +456,26 @@ const poolModule = (() => {
456456
return submit(sql, paramsOrCallback, callback, workTypeEnum.PROC)
457457
}
458458

459-
function getUserTypeTable (name) {
459+
async function getUserTypeTable (name) {
460460
// the table mgr will submit query into pool as if it's a connection
461-
return checkClosedPromise().then(() => tableMgr.promises.getUserTypeTable(name))
461+
return checkClosedPromise().then(async () => tableMgr.promises.getUserTypeTable(name))
462462
}
463463

464-
function getTable (name) {
465-
return checkClosedPromise().then(() => tableMgr.promises.getTable(name))
464+
async function getTable (name) {
465+
return checkClosedPromise().then(async () => tableMgr.promises.getTable(name))
466466
}
467467

468-
function getProc (name) {
469-
return checkClosedPromise().then(() => procedureManager.promises.getProc(name))
468+
async function getProc (name) {
469+
return checkClosedPromise().then(async () => procedureManager.promises.getProc(name))
470470
}
471471

472472
// returns a promise of aggregated results not a query
473-
function callprocAggregator (name, params, options) {
474-
return checkClosedPromise().then(() => aggregator.callProc(name, params, options))
473+
async function callprocAggregator (name, params, options) {
474+
return checkClosedPromise().then(async () => aggregator.callProc(name, params, options))
475475
}
476476

477-
function queryAggregator (sql, params, options) {
478-
return checkClosedPromise().then(() => aggregator.query(sql, params, options))
477+
async function queryAggregator (sql, params, options) {
478+
return checkClosedPromise().then(async () => aggregator.query(sql, params, options))
479479
}
480480

481481
function enqueue (item) {
@@ -566,7 +566,7 @@ const poolModule = (() => {
566566
connectionOptions(c)
567567
checkin('grow', getDescription(c))
568568
},
569-
e => {
569+
async e => {
570570
--pendingCreates
571571
return Promise.reject(e)
572572
}

lib/prepared-statement.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const { utilModule } = require('./util')
22
const { BasePromises } = require('./base-promises')
33

44
class PreparedStatementPromises extends BasePromises {
5-
query (params, options) {
5+
async query (params, options) {
66
const q = this.prepared.preparedQuery(params)
77
return this.aggregator.queryPrepared(q, options)
88
}
99

10-
free () {
10+
async free () {
1111
return this.op(cb => this.prepared.free(cb))
1212
}
1313

0 commit comments

Comments
 (0)