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/.github/workflows/node.js.yml +45 -12
- package/0001-fix-attachEvent-host-resolution.patch +72 -0
- package/ENCRYPTION_CALLBACK.md +152 -0
- package/PR_SUMMARY.md +139 -0
- package/README.md +59 -25
- package/Roadmap.md +13 -13
- package/diff +62 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +1 -1
- package/lib/pool.js +83 -82
- package/lib/srp.js +3 -0
- package/lib/wire/connection.js +1623 -1366
- package/lib/wire/const.js +11 -5
- package/lib/wire/database.js +229 -118
- package/lib/wire/eventConnection.js +94 -92
- package/lib/wire/fbEventManager.js +107 -72
- package/lib/wire/serialize.js +434 -408
- package/lib/wire/service.js +935 -931
- package/lib/wire/socket.js +78 -3
- package/lib/wire/statement.js +32 -31
- package/lib/wire/transaction.js +135 -107
- package/lib/wire/xsqlvar.js +339 -330
- package/package.json +4 -4
- package/vitest.config.js +13 -0
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
27
|
-
|
|
19
|
+
get(callback) {
|
|
20
|
+
var self = this;
|
|
21
|
+
self.pending.push(callback);
|
|
22
|
+
self.check();
|
|
28
23
|
return self;
|
|
24
|
+
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
cb
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// attach fail so not in the pool
|
|
56
|
-
self.dbinuse--;
|
|
57
|
-
}
|
|
55
|
+
self.check();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
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
|
-
|
|
67
|
-
|
|
69
|
+
destroy(callback) {
|
|
70
|
+
var self = this;
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
var self = this;
|
|
72
|
+
var connectionCount = this.internaldb.length;
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
if (connectionCount === 0 && callback) {
|
|
75
|
+
callback();
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
function detachCallback(err) {
|
|
79
|
+
if (err) {
|
|
80
|
+
if (callback) {
|
|
81
|
+
callback(err);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
callback(err);
|
|
86
|
+
connectionCount--;
|
|
87
|
+
if (connectionCount === 0 && callback) {
|
|
88
|
+
callback();
|
|
82
89
|
}
|
|
83
|
-
return;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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);
|