node-firebird 1.1.10 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -7,7 +7,7 @@ declare module 'node-firebird' {
7
7
  type TransactionCallback = (err: any, transaction: Transaction) => void;
8
8
  type QueryCallback = (err: any, result: any[]) => void;
9
9
  type SimpleCallback = (err: any) => void;
10
- type SequentialCallback = (row: any, index: number) => void;
10
+ type SequentialCallback = (row: any, index: number, next?: (err?: any) => void) => void | Promise<void>;
11
11
 
12
12
  export const AUTH_PLUGIN_LEGACY: string;
13
13
  export const AUTH_PLUGIN_SRP: string;
@@ -110,6 +110,10 @@ declare module 'node-firebird' {
110
110
  retryConnectionInterval?: number;
111
111
  encoding?: SupportedCharacterSet;
112
112
  blobAsText?: boolean; // only affects for blob subtype 1
113
+ wireCrypt?: number; // WIRE_CRYPT_DISABLE or WIRE_CRYPT_ENABLE
114
+ wireCompression?: boolean;
115
+ pluginName?: string;
116
+ dbCryptConfig?: string; // Database encryption key callback config (base64: prefix for base64, or plain string)
113
117
  }
114
118
 
115
119
  export interface SvcMgrOptions extends Options {
package/lib/index.js CHANGED
@@ -12,7 +12,7 @@ if (typeof(setImmediate) === 'undefined') {
12
12
 
13
13
  exports.AUTH_PLUGIN_LEGACY = Const.AUTH_PLUGIN_LEGACY;
14
14
  exports.AUTH_PLUGIN_SRP = Const.AUTH_PLUGIN_SRP;
15
- // exports.AUTH_PLUGIN_SRP256 = Const.AUTH_PLUGIN_SRP256;
15
+ exports.AUTH_PLUGIN_SRP256 = Const.AUTH_PLUGIN_SRP256;
16
16
 
17
17
  exports.WIRE_CRYPT_DISABLE = Const.WIRE_CRYPT_DISABLE;
18
18
  exports.WIRE_CRYPT_ENABLE = Const.WIRE_CRYPT_ENABLE;
package/lib/pool.js CHANGED
@@ -4,104 +4,105 @@
4
4
  *
5
5
  ***************************************/
6
6
 
7
- function Pool(attach, max, options) {
8
- this.attach = attach;
9
- this.internaldb = []; // connection created by the pool (for destroy)
10
- this.pooldb = []; // available connection in the pool
11
- this.dbinuse = 0; // connection currently in use into the pool
12
- this.max = max || 4;
13
- this.pending = [];
14
- this.options = options;
15
- }
16
-
17
- Pool.prototype.get = function(callback) {
18
- var self = this;
19
- self.pending.push(callback);
20
- self.check();
21
- return self;
22
- };
23
-
24
- Pool.prototype.check = function() {
7
+ class Pool {
8
+ constructor(attach, max, options) {
9
+ this.attach = attach;
10
+ this.internaldb = []; // connection created by the pool (for destroy)
11
+ this.pooldb = []; // available connection in the pool
12
+ this.dbinuse = 0; // connection currently in use into the pool
13
+ this._creating = 0; // connections currently being created
14
+ this.max = max || 4;
15
+ this.pending = [];
16
+ this.options = options;
17
+ }
25
18
 
26
- var self = this;
27
- if (self.dbinuse >= self.max)
19
+ get(callback) {
20
+ var self = this;
21
+ self.pending.push(callback);
22
+ self.check();
28
23
  return self;
24
+ }
29
25
 
30
- var cb = self.pending.shift();
31
- if (!cb)
32
- return self;
33
- self.dbinuse++;
34
- if (self.pooldb.length) {
35
- cb(null, self.pooldb.shift());
36
- } else {
37
- this.attach(self.options, function (err, db) {
38
- if (!err) {
39
- self.internaldb.push(db);
40
- db.on('detach', function () {
41
- // also in pool (could be a twice call to detach)
42
- if (self.pooldb.indexOf(db) !== -1 || self.internaldb.indexOf(db) === -1)
43
- return;
44
- // if not usable don't put in again in the pool and remove reference on it
45
- if (db.connection._isClosed || db.connection._isDetach || db.connection._pooled === false)
46
- self.internaldb.splice(self.internaldb.indexOf(db), 1);
47
- else
48
- self.pooldb.push(db);
26
+ check() {
27
+ var self = this;
28
+ if ((self.dbinuse + self._creating) >= self.max)
29
+ return self;
30
+
31
+ var cb = self.pending.shift();
32
+ if (!cb)
33
+ return self;
34
+ if (self.pooldb.length) {
35
+ self.dbinuse++;
36
+ cb(null, self.pooldb.shift());
37
+ } else {
38
+ self._creating++;
39
+ this.attach(self.options, function (err, db) {
40
+ self._creating--;
41
+ if (!err) {
42
+ self.dbinuse++;
43
+ self.internaldb.push(db);
44
+ db.on('detach', function () {
45
+ // also in pool (could be a twice call to detach)
46
+ if (self.pooldb.indexOf(db) !== -1 || self.internaldb.indexOf(db) === -1)
47
+ return;
48
+ // if not usable don't put in again in the pool and remove reference on it
49
+ if (db.connection._isClosed || db.connection._isDetach || db.connection._pooled === false)
50
+ self.internaldb.splice(self.internaldb.indexOf(db), 1);
51
+ else
52
+ self.pooldb.push(db);
49
53
 
50
- if (db.connection._pooled)
51
54
  self.dbinuse--;
52
- self.check();
53
- });
54
- } else {
55
- // attach fail so not in the pool
56
- self.dbinuse--;
57
- }
55
+ self.check();
56
+ });
57
+ }
58
58
 
59
- cb(err, db);
59
+ cb(err, db);
60
+ });
61
+ }
62
+ setImmediate(function() {
63
+ self.check();
60
64
  });
65
+
66
+ return self;
61
67
  }
62
- setImmediate(function() {
63
- self.check();
64
- });
65
68
 
66
- return self;
67
- };
69
+ destroy(callback) {
70
+ var self = this;
68
71
 
69
- Pool.prototype.destroy = function(callback) {
70
- var self = this;
72
+ var connectionCount = this.internaldb.length;
71
73
 
72
- var connectionCount = this.internaldb.length;
74
+ if (connectionCount === 0 && callback) {
75
+ callback();
76
+ }
73
77
 
74
- if (connectionCount === 0 && callback) {
75
- callback();
76
- }
78
+ function detachCallback(err) {
79
+ if (err) {
80
+ if (callback) {
81
+ callback(err);
82
+ }
83
+ return;
84
+ }
77
85
 
78
- function detachCallback(err) {
79
- if (err) {
80
- if (callback) {
81
- callback(err);
86
+ connectionCount--;
87
+ if (connectionCount === 0 && callback) {
88
+ callback();
82
89
  }
83
- return;
84
90
  }
85
91
 
86
- connectionCount--;
87
- if (connectionCount === 0 && callback) {
88
- callback();
89
- }
92
+ this.internaldb.forEach(function(db) {
93
+ if (db.connection._pooled === false) {
94
+ detachCallback();
95
+ return;
96
+ }
97
+ // check if the db is not free into the pool otherwise user should manual detach it
98
+ var _db_in_pool = self.pooldb.indexOf(db);
99
+ if (_db_in_pool !== -1) {
100
+ self.pooldb.splice(_db_in_pool, 1);
101
+ db.connection._pooled = false;
102
+ db.detach(detachCallback);
103
+ }
104
+ });
90
105
  }
91
-
92
- this.internaldb.forEach(function(db) {
93
- if (db.connection._pooled === false) {
94
- detachCallback();
95
- return;
96
- }
97
- // check if the db is not free into the pool otherwise user should manual detach it
98
- var _db_in_pool = self.pooldb.indexOf(db);
99
- if (_db_in_pool !== -1) {
100
- self.pooldb.splice(_db_in_pool, 1);
101
- db.connection._pooled = false;
102
- db.detach(detachCallback);
103
- }
104
- });
105
- };
106
+ }
106
107
 
107
108
  module.exports = Pool;
package/lib/srp.js CHANGED
@@ -181,6 +181,9 @@ function clientSession(user, password, salt, A, B, a) {
181
181
  diff = diff.add(PRIME.N);
182
182
  }
183
183
 
184
+ // Note: While the SRP specification says exponents should not be reduced mod N,
185
+ // the Firebird engine implementation does reduce these exponents mod N.
186
+ // We must match the server's behavior for authentication to succeed.
184
187
  var ux = u.multiply(x).mod(PRIME.N);
185
188
  var aux = a.add(ux).mod(PRIME.N);
186
189
  var sessionSecret = diff.modPow(aux, PRIME.N);