node-firebird 2.0.0 → 2.0.2

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.
@@ -1208,7 +1208,10 @@ class Connection {
1208
1208
 
1209
1209
  fetchAll(statement, transaction, callback) {
1210
1210
  const self = this;
1211
- const data = [];
1211
+ const custom = statement.custom || {};
1212
+ const asStream = custom.asStream && custom.on;
1213
+ const data = asStream ? null : [];
1214
+ let streamIndex = 0;
1212
1215
  const loop = (err, ret) => {
1213
1216
  if (err) {
1214
1217
  callback(err);
@@ -1224,11 +1227,8 @@ class Connection {
1224
1227
  ret.data[blob.row][blob.column] = blob.value;
1225
1228
  }
1226
1229
 
1227
- const custom = statement.custom || {};
1228
- const asStream = custom.asStream && custom.on;
1229
-
1230
- doSynchronousLoop(ret.data, (row, i, next) => {
1231
- const pos = data.push(row) - 1;
1230
+ doSynchronousLoop(ret.data, (row, _i, next) => {
1231
+ const pos = asStream ? streamIndex++ : (data.push(row) - 1);
1232
1232
  if (asStream) {
1233
1233
  executeStreamRow(custom, row, pos, statement.output, next);
1234
1234
  } else {
@@ -1241,7 +1241,7 @@ class Connection {
1241
1241
  }
1242
1242
 
1243
1243
  if (ret.fetched) {
1244
- callback(undefined, data);
1244
+ callback(undefined, data || []);
1245
1245
  } else {
1246
1246
  self.fetch(statement, transaction, Const.DEFAULT_FETCHSIZE, loop);
1247
1247
  }
@@ -1251,7 +1251,7 @@ class Connection {
1251
1251
  }
1252
1252
 
1253
1253
  if (ret && ret.fetched) {
1254
- callback(undefined, data);
1254
+ callback(undefined, data || []);
1255
1255
  } else {
1256
1256
  self.fetch(statement, transaction, Const.DEFAULT_FETCHSIZE, loop);
1257
1257
  }
@@ -280,7 +280,12 @@ class Database extends Events.EventEmitter {
280
280
  return;
281
281
  }
282
282
 
283
- const eventConnection = new EventConnection(socket_info.host, socket_info.port, function (err) {
283
+ const host = (socket_info.host === '0.0.0.0' || socket_info.host === '::')
284
+ ? self.connection.options.host
285
+ : socket_info.host;
286
+
287
+ const eventConnection = new EventConnection(
288
+ host, socket_info.port, function(err) {
284
289
  if (err) {
285
290
  doError(err, callback);
286
291
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-firebird",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Pure JavaScript and Asynchronous Firebird client for Node.js.",
5
5
  "keywords": [
6
6
  "firebird",
package/srp.js DELETED
@@ -1,94 +0,0 @@
1
- const BigInteger = require('big-integer');
2
- const crypto = require('crypto');
3
-
4
- console.log('Preparing benchmark...');
5
-
6
- // Constants from lib/srp.js
7
- const HEX_N = 'E67D2E994B2F900C3F41F08F5BB2627ED0D49EE1FE767A52EFCD565CD6E768812C3E1E9CE8F0A8BEA6CB13CD29DDEBF7A96D4A93B55D488DF099A15C89DCB0640738EB2CBDD9A8F7BAB561AB1B0DC1C6CDABF303264A08D1BCA932D1F1EE428B619D970F342ABA9A65793B8B2F041AE5364350C16F735F56ECBCA87BD57B29E7';
8
- const DEC_K = '1277432915985975349439481660349303019122249719989';
9
-
10
- // --- Library Setup ---
11
- const lib_N = BigInteger(HEX_N, 16);
12
- const lib_g = BigInteger(2);
13
- const lib_k = BigInteger(DEC_K);
14
-
15
- // --- Native Setup ---
16
- const native_N = BigInt('0x' + HEX_N);
17
- const native_g = 2n;
18
- const native_k = BigInt(DEC_K);
19
-
20
- /**
21
- * Native BigInt Modular Exponentiation
22
- * Calculates (base ^ exp) % mod
23
- */
24
- function nativeModPow(base, exp, mod) {
25
- let result = 1n;
26
- base = base % mod;
27
- while (exp > 0n) {
28
- if (exp & 1n) result = (result * base) % mod;
29
- base = (base * base) % mod;
30
- exp >>= 1n;
31
- }
32
- return result;
33
- }
34
-
35
- // --- Test Data Generation ---
36
- const ITERATIONS = 2000;
37
- const inputs = [];
38
-
39
- for (let i = 0; i < ITERATIONS; i++) {
40
- // Generate random 32-byte private key (similar to SRP_KEY_SIZE)
41
- const hex = crypto.randomBytes(32).toString('hex');
42
- inputs.push({
43
- lib: BigInteger(hex, 16),
44
- native: BigInt('0x' + hex)
45
- });
46
- }
47
-
48
- // --- Verification ---
49
- console.log('Verifying implementations match...');
50
- const vLib = lib_g.modPow(inputs[0].lib, lib_N);
51
- const vNative = nativeModPow(native_g, inputs[0].native, native_N);
52
-
53
- if (vLib.toString(16) !== vNative.toString(16)) {
54
- console.error('MISMATCH!');
55
- console.error('Lib:', vLib.toString(16));
56
- console.error('Nat:', vNative.toString(16));
57
- process.exit(1);
58
- }
59
- console.log('Verification passed.');
60
-
61
- // --- Benchmark ---
62
- console.log(`\nStarting benchmark (${ITERATIONS} iterations)...`);
63
-
64
- // 1. Library Benchmark
65
- const startLib = process.hrtime.bigint();
66
- for (let i = 0; i < ITERATIONS; i++) {
67
- // Simulate: A = g^a % N
68
- const A = lib_g.modPow(inputs[i].lib, lib_N);
69
-
70
- // Simulate part of server calc: B = (k*v + g^b) % N
71
- // We'll just do (k * A) % N + A to simulate the mix of mult/add/mod
72
- const term = lib_k.multiply(A).mod(lib_N).add(A).mod(lib_N);
73
- }
74
- const endLib = process.hrtime.bigint();
75
-
76
- // 2. Native Benchmark
77
- const startNative = process.hrtime.bigint();
78
- for (let i = 0; i < ITERATIONS; i++) {
79
- // Simulate: A = g^a % N
80
- const A = nativeModPow(native_g, inputs[i].native, native_N);
81
-
82
- // Simulate part of server calc: B = (k*v + g^b) % N
83
- const term = ((native_k * A) % native_N + A) % native_N;
84
- }
85
- const endNative = process.hrtime.bigint();
86
-
87
- // --- Results ---
88
- const timeLib = Number(endLib - startLib) / 1e6; // ms
89
- const timeNative = Number(endNative - startNative) / 1e6; // ms
90
-
91
- console.log('\nResults:');
92
- console.log(`big-integer (Lib): ${timeLib.toFixed(2)} ms`);
93
- console.log(`Native BigInt: ${timeNative.toFixed(2)} ms`);
94
- console.log(`\nSpeedup: ${(timeLib / timeNative).toFixed(2)}x faster`);