node-firebird 2.3.3 → 2.4.0

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.
Files changed (109) hide show
  1. package/README.md +544 -6
  2. package/lib/callback.d.ts +20 -0
  3. package/lib/callback.js +6 -16
  4. package/lib/firebird.msg.json +1370 -1370
  5. package/lib/gdscodes.d.ts +1519 -1520
  6. package/lib/gdscodes.js +5 -5
  7. package/lib/ieee754-decimal.d.ts +38 -0
  8. package/lib/ieee754-decimal.js +71 -118
  9. package/lib/index.d.ts +37 -338
  10. package/lib/index.js +97 -86
  11. package/lib/messages.d.ts +6 -0
  12. package/lib/messages.js +135 -162
  13. package/lib/pool.d.ts +23 -0
  14. package/lib/pool.js +34 -47
  15. package/lib/srp.d.ts +51 -0
  16. package/lib/srp.js +62 -72
  17. package/lib/types.d.ts +375 -0
  18. package/lib/types.js +22 -0
  19. package/lib/unix-crypt.d.ts +1 -0
  20. package/lib/unix-crypt.js +126 -152
  21. package/lib/utils.d.ts +16 -0
  22. package/lib/utils.js +24 -48
  23. package/lib/wire/connection.d.ts +100 -0
  24. package/lib/wire/connection.js +1029 -1009
  25. package/lib/wire/const.d.ts +567 -0
  26. package/lib/wire/const.js +620 -599
  27. package/lib/wire/database.d.ts +57 -0
  28. package/lib/wire/database.js +111 -108
  29. package/lib/wire/eventConnection.d.ts +16 -0
  30. package/lib/wire/eventConnection.js +29 -31
  31. package/lib/wire/fbEventManager.d.ts +45 -0
  32. package/lib/wire/fbEventManager.js +38 -57
  33. package/lib/wire/serialize.d.ts +97 -0
  34. package/lib/wire/serialize.js +42 -141
  35. package/lib/wire/service.d.ts +66 -0
  36. package/lib/wire/service.js +374 -401
  37. package/lib/wire/socket.d.ts +59 -0
  38. package/lib/wire/socket.js +79 -40
  39. package/lib/wire/statement.d.ts +25 -0
  40. package/lib/wire/statement.js +13 -9
  41. package/lib/wire/transaction.d.ts +21 -0
  42. package/lib/wire/transaction.js +33 -61
  43. package/lib/wire/xsqlvar.d.ts +175 -0
  44. package/lib/wire/xsqlvar.js +169 -269
  45. package/package.json +12 -4
  46. package/src/callback.ts +55 -0
  47. package/{poc/node_modules/node-firebird/lib/gdscodes.js → src/gdscodes.ts} +3 -3
  48. package/{poc/node_modules/node-firebird/lib/ieee754-decimal.js → src/ieee754-decimal.ts} +7 -14
  49. package/src/index.ts +157 -0
  50. package/{poc/node_modules/node-firebird/lib/messages.js → src/messages.ts} +163 -162
  51. package/src/pool.ts +209 -0
  52. package/{poc/node_modules/node-firebird/lib/srp.js → src/srp.ts} +74 -33
  53. package/src/types.ts +419 -0
  54. package/{poc/node_modules/node-firebird/lib/unix-crypt.js → src/unix-crypt.ts} +6 -12
  55. package/{poc/node_modules/node-firebird/lib/utils.js → src/utils.ts} +11 -20
  56. package/{poc/node_modules/node-firebird/lib/wire/connection.js → src/wire/connection.ts} +611 -129
  57. package/{poc/node_modules/node-firebird/lib/wire/const.js → src/wire/const.ts} +96 -9
  58. package/{poc/node_modules/node-firebird/lib/wire/database.js → src/wire/database.ts} +110 -44
  59. package/{poc/node_modules/node-firebird/lib/wire/eventConnection.js → src/wire/eventConnection.ts} +29 -14
  60. package/{poc/node_modules/node-firebird/lib/wire/fbEventManager.js → src/wire/fbEventManager.ts} +39 -30
  61. package/{poc/node_modules/node-firebird/lib/wire/serialize.js → src/wire/serialize.ts} +78 -59
  62. package/{poc/node_modules/node-firebird/lib/wire/service.js → src/wire/service.ts} +90 -88
  63. package/src/wire/socket.ts +262 -0
  64. package/src/wire/statement.ts +71 -0
  65. package/{poc/node_modules/node-firebird/lib/wire/transaction.js → src/wire/transaction.ts} +25 -19
  66. package/{poc/node_modules/node-firebird/lib/wire/xsqlvar.js → src/wire/xsqlvar.ts} +244 -143
  67. package/.eslintrc.json +0 -12
  68. package/.github/workflows/codeql.yml +0 -76
  69. package/.github/workflows/node.js.yml +0 -95
  70. package/BIGINT_MIGRATION.md +0 -374
  71. package/CI_DEBUGGING_GUIDE.md +0 -148
  72. package/ENCRYPTION_CALLBACK.md +0 -152
  73. package/FIREBIRD_LOG_FEATURE.md +0 -145
  74. package/MINIMAL_CHANGES_SUMMARY.md +0 -136
  75. package/PR_SUMMARY.md +0 -96
  76. package/ROADMAP.md +0 -223
  77. package/SRP_PROTOCOL.md +0 -482
  78. package/poc/README.md +0 -160
  79. package/poc/helpers.js +0 -59
  80. package/poc/node_modules/.package-lock.json +0 -14
  81. package/poc/node_modules/node-firebird/.eslintrc.json +0 -12
  82. package/poc/node_modules/node-firebird/.github/workflows/codeql.yml +0 -76
  83. package/poc/node_modules/node-firebird/.github/workflows/node.js.yml +0 -95
  84. package/poc/node_modules/node-firebird/BIGINT_MIGRATION.md +0 -374
  85. package/poc/node_modules/node-firebird/CI_DEBUGGING_GUIDE.md +0 -148
  86. package/poc/node_modules/node-firebird/ENCRYPTION_CALLBACK.md +0 -152
  87. package/poc/node_modules/node-firebird/FIREBIRD_LOG_FEATURE.md +0 -145
  88. package/poc/node_modules/node-firebird/LICENSE +0 -373
  89. package/poc/node_modules/node-firebird/MINIMAL_CHANGES_SUMMARY.md +0 -136
  90. package/poc/node_modules/node-firebird/PR_SUMMARY.md +0 -96
  91. package/poc/node_modules/node-firebird/README.md +0 -794
  92. package/poc/node_modules/node-firebird/ROADMAP.md +0 -223
  93. package/poc/node_modules/node-firebird/SRP_PROTOCOL.md +0 -482
  94. package/poc/node_modules/node-firebird/lib/callback.js +0 -38
  95. package/poc/node_modules/node-firebird/lib/gdscodes.d.ts +0 -1524
  96. package/poc/node_modules/node-firebird/lib/index.d.ts +0 -316
  97. package/poc/node_modules/node-firebird/lib/index.js +0 -128
  98. package/poc/node_modules/node-firebird/lib/pool.js +0 -108
  99. package/poc/node_modules/node-firebird/lib/wire/socket.js +0 -175
  100. package/poc/node_modules/node-firebird/lib/wire/statement.js +0 -48
  101. package/poc/node_modules/node-firebird/package.json +0 -38
  102. package/poc/node_modules/node-firebird/vitest.config.js +0 -24
  103. package/poc/package-lock.json +0 -21
  104. package/poc/package.json +0 -12
  105. package/poc/reproduce-fixed.js +0 -150
  106. package/poc/reproduce.js +0 -133
  107. package/vitest.config.js +0 -27
  108. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg +0 -0
  109. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg.json +0 -0
@@ -1,79 +1,64 @@
1
-
2
- const { encodeDecimal64, decodeDecimal64, encodeDecimal128, decodeDecimal128 } = require('../ieee754-decimal');
3
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitSet = exports.XdrReader = exports.XdrWriter = exports.BlrReader = exports.BlrWriter = void 0;
4
+ const ieee754_decimal_1 = require("../ieee754-decimal");
4
5
  function align(n) {
5
6
  return (n + 3) & ~3;
6
7
  }
7
-
8
8
  /***************************************
9
9
  *
10
10
  * BLR Writer
11
11
  *
12
12
  ***************************************/
13
-
14
- const
15
- MAX_STRING_SIZE = 255;
16
-
13
+ const MAX_STRING_SIZE = 255;
17
14
  class BlrWriter {
18
15
  constructor(size) {
19
16
  this.buffer = Buffer.alloc(size || 32);
20
17
  this.pos = 0;
21
18
  }
22
-
23
19
  ensure(len) {
24
20
  var newlen = this.buffer.length;
25
-
26
21
  while (newlen < this.pos + len)
27
- newlen *= 2
28
-
22
+ newlen *= 2;
29
23
  if (this.buffer.length >= newlen)
30
24
  return;
31
-
32
25
  var b = Buffer.alloc(newlen);
33
26
  this.buffer.copy(b);
34
- delete(this.buffer);
35
27
  this.buffer = b;
36
28
  }
37
-
38
29
  addByte(b) {
39
30
  this.ensure(1);
40
31
  this.buffer.writeUInt8(b, this.pos);
41
32
  this.pos++;
42
33
  }
43
-
44
34
  addShort(b) {
45
35
  this.ensure(1);
46
36
  this.buffer.writeInt8(b, this.pos);
47
37
  this.pos++;
48
38
  }
49
-
50
39
  addSmall(b) {
51
40
  this.ensure(2);
52
41
  this.buffer.writeInt16LE(b, this.pos);
53
42
  this.pos += 2;
54
43
  }
55
-
56
44
  addWord(b) {
57
45
  this.ensure(2);
58
46
  this.buffer.writeUInt16LE(b, this.pos);
59
47
  this.pos += 2;
60
48
  }
61
-
62
49
  addInt32(b) {
63
50
  this.ensure(4);
64
51
  this.buffer.writeUInt32LE(b, this.pos);
65
52
  this.pos += 4;
66
53
  }
67
-
68
54
  addByteInt32(c, b) {
69
55
  this.addByte(c);
70
56
  this.ensure(4);
71
57
  this.buffer.writeUInt32LE(b, this.pos);
72
58
  this.pos += 4;
73
59
  }
74
-
75
60
  addNumeric(c, v) {
76
- if (v < 256){
61
+ if (v < 256) {
77
62
  this.ensure(3);
78
63
  this.buffer.writeUInt8(c, this.pos);
79
64
  this.pos++;
@@ -83,7 +68,6 @@ class BlrWriter {
83
68
  this.pos++;
84
69
  return;
85
70
  }
86
-
87
71
  this.ensure(6);
88
72
  this.buffer.writeUInt8(c, this.pos);
89
73
  this.pos++;
@@ -92,7 +76,6 @@ class BlrWriter {
92
76
  this.buffer.writeInt32BE(v, this.pos);
93
77
  this.pos += 4;
94
78
  }
95
-
96
79
  addBytes(b) {
97
80
  this.ensure(b.length);
98
81
  for (var i = 0, length = b.length; i < length; i++) {
@@ -100,86 +83,70 @@ class BlrWriter {
100
83
  this.pos++;
101
84
  }
102
85
  }
103
-
104
86
  addString(c, s, encoding) {
105
87
  this.addByte(c);
106
-
107
88
  var len = Buffer.byteLength(s, encoding);
108
89
  if (len > MAX_STRING_SIZE)
109
90
  throw new Error('blr string is too big');
110
-
111
91
  this.ensure(len + 1);
112
92
  this.buffer.writeUInt8(len, this.pos);
113
93
  this.pos++;
114
94
  this.buffer.write(s, this.pos, len, encoding);
115
95
  this.pos += len;
116
96
  }
117
-
118
97
  addBuffer(b) {
119
98
  this.addWord(b.length);
120
99
  this.ensure(b.length);
121
100
  b.copy(this.buffer, this.pos);
122
101
  this.pos += b.length;
123
102
  }
124
-
125
103
  addString2(c, s, encoding) {
126
104
  this.addByte(c);
127
-
128
105
  var len = Buffer.byteLength(s, encoding);
129
- if (len > MAX_STRING_SIZE* MAX_STRING_SIZE)
106
+ if (len > MAX_STRING_SIZE * MAX_STRING_SIZE)
130
107
  throw new Error('blr string is too big');
131
-
132
108
  this.ensure(len + 2);
133
109
  this.buffer.writeUInt16LE(len, this.pos);
134
110
  this.pos += 2;
135
111
  this.buffer.write(s, this.pos, len, encoding);
136
112
  this.pos += len;
137
113
  }
138
-
139
114
  addMultiblockPart(c, s, encoding) {
140
115
  var buff = Buffer.from(s, encoding);
141
116
  var remaining = buff.length;
142
117
  var step = 0;
143
-
144
118
  while (remaining > 0) {
145
119
  var toWrite = Math.min(remaining, 254);
146
-
147
120
  this.addByte(c);
148
121
  this.addByte(toWrite + 1);
149
122
  this.addByte(step);
150
-
151
123
  this.ensure(toWrite);
152
124
  buff.copy(this.buffer, this.pos, step * 254, (step * 254) + toWrite);
153
-
154
125
  step++;
155
126
  remaining -= toWrite;
156
127
  this.pos += toWrite;
157
128
  }
158
129
  }
159
130
  }
160
-
131
+ exports.BlrWriter = BlrWriter;
161
132
  /***************************************
162
133
  *
163
134
  * BLR Reader
164
135
  *
165
136
  ***************************************/
166
-
167
137
  class BlrReader {
168
138
  constructor(buffer) {
169
139
  this.buffer = buffer;
170
140
  this.pos = 0;
171
141
  }
172
-
173
142
  readByteCode() {
174
143
  return this.buffer.readUInt8(this.pos++);
175
144
  }
176
-
177
145
  readInt32() {
178
146
  var value = this.buffer.readUInt32LE(this.pos);
179
147
  this.pos += 4;
180
148
  return value;
181
149
  }
182
-
183
150
  readInt() {
184
151
  var len = this.buffer.readUInt16LE(this.pos);
185
152
  this.pos += 2;
@@ -192,89 +159,71 @@ class BlrReader {
192
159
  value = this.buffer.readInt16LE(this.pos);
193
160
  break;
194
161
  case 4:
195
- value = this.buffer.readInt32LE(this.pos)
162
+ value = this.buffer.readInt32LE(this.pos);
196
163
  }
197
164
  this.pos += len;
198
165
  return value;
199
166
  }
200
-
201
167
  readString(encoding) {
202
168
  var len = this.buffer.readUInt16LE(this.pos);
203
169
  var str;
204
-
205
170
  this.pos += 2;
206
171
  if (len <= 0)
207
172
  return '';
208
-
209
173
  str = this.buffer.toString(encoding, this.pos, this.pos + len);
210
174
  this.pos += len;
211
175
  return str;
212
176
  }
213
-
214
177
  readSegment() {
215
178
  var ret, tmp;
216
179
  var len = this.buffer.readUInt16LE(this.pos);
217
-
218
180
  this.pos += 2;
219
-
220
181
  while (len > 0) {
221
-
222
182
  if (ret) {
223
183
  tmp = ret;
224
184
  ret = Buffer.alloc(tmp.length + len);
225
185
  tmp.copy(ret);
226
186
  this.buffer.copy(ret, tmp.length, this.pos, this.pos + len);
227
- } else {
187
+ }
188
+ else {
228
189
  ret = Buffer.alloc(len);
229
190
  this.buffer.copy(ret, 0, this.pos, this.pos + len);
230
191
  }
231
-
232
192
  this.pos += len;
233
-
234
193
  if (this.pos === this.buffer.length)
235
194
  break;
236
-
237
195
  len = this.buffer.readUInt16LE(this.pos);
238
196
  this.pos += 2;
239
197
  }
240
-
241
198
  return ret ? ret : Buffer.alloc(0);
242
199
  }
243
200
  }
244
-
201
+ exports.BlrReader = BlrReader;
245
202
  /***************************************
246
203
  *
247
204
  * XDR Writer
248
205
  *
249
206
  ***************************************/
250
-
251
207
  class XdrWriter {
252
208
  constructor(size) {
253
209
  this.buffer = Buffer.alloc(size || 32);
254
210
  this.pos = 0;
255
211
  }
256
-
257
212
  ensure(len) {
258
213
  var newlen = this.buffer.length;
259
-
260
214
  while (newlen < this.pos + len)
261
- newlen *= 2
262
-
215
+ newlen *= 2;
263
216
  if (this.buffer.length >= newlen)
264
217
  return;
265
-
266
218
  var b = Buffer.alloc(newlen);
267
219
  this.buffer.copy(b);
268
- delete(this.buffer);
269
220
  this.buffer = b;
270
221
  }
271
-
272
222
  addInt(value) {
273
223
  this.ensure(4);
274
224
  this.buffer.writeInt32BE(value, this.pos);
275
225
  this.pos += 4;
276
226
  }
277
-
278
227
  addInt64(value) {
279
228
  this.ensure(8);
280
229
  // Note: precision is limited to Number.MAX_SAFE_INTEGER (±2^53-1).
@@ -283,47 +232,37 @@ class XdrWriter {
283
232
  this.buffer.writeBigInt64BE(BigInt(Math.trunc(value)), this.pos);
284
233
  this.pos += 8;
285
234
  }
286
-
287
235
  addInt128(value) {
288
236
  this.ensure(16);
289
-
290
237
  const bigValue = BigInt(value);
291
-
292
238
  const high = bigValue >> BigInt(64);
293
239
  const low = bigValue & BigInt("0xFFFFFFFFFFFFFFFF");
294
-
295
240
  this.buffer.writeBigUInt64BE(high, this.pos);
296
241
  this.pos += 8;
297
242
  this.buffer.writeBigUInt64BE(low, this.pos);
298
243
  this.pos += 8;
299
244
  }
300
-
301
245
  addDecFloat16(value) {
302
246
  // DECFLOAT(16) - IEEE 754 Decimal64 - 8 bytes
303
247
  // Full IEEE 754-2008 Decimal64 implementation
304
248
  this.ensure(8);
305
-
306
- const encoded = encodeDecimal64(value);
249
+ const encoded = (0, ieee754_decimal_1.encodeDecimal64)(value);
307
250
  encoded.copy(this.buffer, this.pos, 0, 8);
308
251
  this.pos += 8;
309
252
  }
310
-
311
253
  addDecFloat34(value) {
312
254
  // DECFLOAT(34) - IEEE 754 Decimal128 - 16 bytes
313
255
  // Full IEEE 754-2008 Decimal128 implementation
314
256
  this.ensure(16);
315
-
316
- const encoded = encodeDecimal128(value);
257
+ const encoded = (0, ieee754_decimal_1.encodeDecimal128)(value);
317
258
  encoded.copy(this.buffer, this.pos, 0, 16);
318
259
  this.pos += 16;
319
260
  }
320
-
321
261
  addUInt(value) {
322
262
  this.ensure(4);
323
263
  this.buffer.writeUInt32BE(value, this.pos);
324
264
  this.pos += 4;
325
265
  }
326
-
327
266
  addString(s, encoding) {
328
267
  var len = Buffer.byteLength(s, encoding);
329
268
  var alen = align(len);
@@ -331,36 +270,42 @@ class XdrWriter {
331
270
  this.buffer.writeInt32BE(len, this.pos);
332
271
  this.pos += 4;
333
272
  this.buffer.write(s, this.pos, len, encoding);
273
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
334
274
  this.pos += alen;
335
275
  }
336
-
337
276
  addText(s, encoding) {
338
277
  var len = Buffer.byteLength(s, encoding);
339
278
  var alen = align(len);
340
279
  this.ensure(alen);
341
280
  this.buffer.write(s, this.pos, len, encoding);
281
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
282
+ this.pos += alen;
283
+ }
284
+ addParamBuffer(b) {
285
+ var len = b.length;
286
+ var alen = align(len);
287
+ this.ensure(alen);
288
+ b.copy(this.buffer, this.pos);
289
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
342
290
  this.pos += alen;
343
291
  }
344
-
345
292
  addBlr(blr) {
346
293
  var alen = align(blr.pos);
347
294
  this.ensure(alen + 4);
348
295
  this.buffer.writeInt32BE(blr.pos, this.pos);
349
296
  this.pos += 4;
350
- blr.buffer.copy(this.buffer, this.pos);
297
+ blr.buffer.copy(this.buffer, this.pos, 0, blr.pos);
298
+ this.buffer.fill(0, this.pos + blr.pos, this.pos + alen);
351
299
  this.pos += alen;
352
300
  }
353
-
354
301
  getData() {
355
302
  return this.buffer.slice(0, this.pos);
356
303
  }
357
-
358
304
  addDouble(value) {
359
305
  this.ensure(8);
360
306
  this.buffer.writeDoubleBE(value, this.pos);
361
307
  this.pos += 8;
362
308
  }
363
-
364
309
  addQuad(quad) {
365
310
  this.ensure(8);
366
311
  var b = this.buffer;
@@ -369,46 +314,39 @@ class XdrWriter {
369
314
  b.writeInt32BE(quad.low, this.pos);
370
315
  this.pos += 4;
371
316
  }
372
-
373
317
  addBuffer(buffer) {
374
318
  this.ensure(buffer.length);
375
319
  buffer.copy(this.buffer, this.pos, 0, buffer.length);
376
320
  this.pos += buffer.length;
377
321
  }
378
-
379
322
  addAlignment(len) {
380
323
  var alen = (4 - len) & 3;
381
-
382
324
  this.ensure(alen);
383
325
  this.buffer.write('ffffff', this.pos, alen, 'hex');
384
326
  this.pos += alen;
385
327
  }
386
328
  }
387
-
329
+ exports.XdrWriter = XdrWriter;
388
330
  /***************************************
389
331
  *
390
332
  * XDR Reader
391
333
  *
392
334
  ***************************************/
393
-
394
335
  class XdrReader {
395
336
  constructor(buffer) {
396
337
  this.buffer = buffer;
397
338
  this.pos = 0;
398
339
  }
399
-
400
340
  readInt() {
401
341
  var r = this.buffer.readInt32BE(this.pos);
402
342
  this.pos += 4;
403
343
  return r;
404
344
  }
405
-
406
345
  readUInt() {
407
346
  var r = this.buffer.readUInt32BE(this.pos);
408
347
  this.pos += 4;
409
348
  return r;
410
349
  }
411
-
412
350
  readInt64() {
413
351
  // Note: precision is limited to Number.MAX_SAFE_INTEGER (±2^53-1).
414
352
  // Values outside this range lose precision, which matches the previous
@@ -417,62 +355,50 @@ class XdrReader {
417
355
  this.pos += 8;
418
356
  return result;
419
357
  }
420
-
421
358
  readInt128() {
422
- var high = this.buffer.readBigUInt64BE(this.pos)
423
- this.pos += 8
424
-
425
- var low = this.buffer.readBigUInt64BE(this.pos)
426
- this.pos += 8
427
-
428
- return (BigInt(high) << BigInt(64)) + BigInt(low)
429
- }
430
-
359
+ var high = this.buffer.readBigUInt64BE(this.pos);
360
+ this.pos += 8;
361
+ var low = this.buffer.readBigUInt64BE(this.pos);
362
+ this.pos += 8;
363
+ return (BigInt(high) << BigInt(64)) + BigInt(low);
364
+ }
431
365
  readDecFloat16() {
432
366
  // DECFLOAT(16) - IEEE 754 Decimal64 - 8 bytes
433
367
  // Full IEEE 754-2008 Decimal64 implementation
434
368
  const buf = this.buffer.slice(this.pos, this.pos + 8);
435
369
  this.pos += 8;
436
-
437
- return decodeDecimal64(buf);
370
+ return (0, ieee754_decimal_1.decodeDecimal64)(buf);
438
371
  }
439
-
440
372
  readDecFloat34() {
441
373
  // DECFLOAT(34) - IEEE 754 Decimal128 - 16 bytes
442
374
  // Full IEEE 754-2008 Decimal128 implementation
443
375
  const buf = this.buffer.slice(this.pos, this.pos + 16);
444
376
  this.pos += 16;
445
-
446
- return decodeDecimal128(buf);
377
+ return (0, ieee754_decimal_1.decodeDecimal128)(buf);
447
378
  }
448
-
449
379
  readShort() {
450
380
  var r = this.buffer.readInt16BE(this.pos);
451
381
  this.pos += 2;
452
382
  return r;
453
383
  }
454
-
455
384
  readQuad() {
456
385
  var b = this.buffer;
457
386
  var high = b.readInt32BE(this.pos);
458
387
  this.pos += 4;
459
388
  var low = b.readInt32BE(this.pos);
460
389
  this.pos += 4;
461
- return {low: low, high: high}
390
+ return { low: low, high: high };
462
391
  }
463
-
464
392
  readFloat() {
465
393
  var r = this.buffer.readFloatBE(this.pos);
466
394
  this.pos += 4;
467
395
  return r;
468
396
  }
469
-
470
397
  readDouble() {
471
398
  var r = this.buffer.readDoubleBE(this.pos);
472
399
  this.pos += 8;
473
400
  return r;
474
401
  }
475
-
476
402
  readArray() {
477
403
  var len = this.readInt();
478
404
  if (!len)
@@ -481,39 +407,32 @@ class XdrReader {
481
407
  this.pos += align(len);
482
408
  return r;
483
409
  }
484
-
485
410
  readBuffer(len, toAlign = true) {
486
411
  if (!arguments.length) {
487
412
  len = this.readInt();
488
413
  }
489
-
490
414
  if (len !== null && len !== undefined) {
491
-
492
- if (len <= 0){
415
+ if (len <= 0) {
493
416
  return Buffer.alloc(0);
494
417
  }
495
-
496
418
  var r = this.buffer.slice(this.pos, this.pos + len);
497
419
  this.pos += toAlign ? align(len) : len;
498
420
  return r;
499
421
  }
500
422
  }
501
-
502
423
  readString(encoding) {
503
424
  var len = this.readInt();
504
425
  return this.readText(len, encoding);
505
426
  }
506
-
507
427
  readText(len, encoding) {
508
428
  if (len <= 0)
509
429
  return '';
510
-
511
430
  var r = this.buffer.toString(encoding, this.pos, this.pos + len);
512
431
  this.pos += align(len);
513
432
  return r;
514
433
  }
515
434
  }
516
-
435
+ exports.XdrReader = XdrReader;
517
436
  /***************************************
518
437
  *
519
438
  * BitSet
@@ -523,17 +442,13 @@ var WORD_LOG = 5;
523
442
  var BUFFER_BITS = 8;
524
443
  var BIT_ON = 1;
525
444
  var BIT_OFF = 0;
526
-
527
445
  class BitSet {
528
446
  constructor(buffer) {
529
447
  this.data = [];
530
-
531
448
  if (buffer) {
532
449
  this.scale(buffer.length * BUFFER_BITS);
533
-
534
450
  for (var i = 0; i < buffer.length; i++) {
535
451
  var n = buffer[i];
536
-
537
452
  for (var j = 0; j < BUFFER_BITS; j++) {
538
453
  var k = i * BUFFER_BITS + j;
539
454
  this.data[k >>> WORD_LOG] |= (n >> j & BIT_ON) << k;
@@ -541,48 +456,34 @@ class BitSet {
541
456
  }
542
457
  }
543
458
  }
544
-
545
459
  scale(index) {
546
460
  var l = index >>> WORD_LOG;
547
-
548
461
  for (var i = this.data.length; l >= i; l--) {
549
462
  this.data.push(BIT_OFF);
550
463
  }
551
464
  }
552
-
553
465
  set(index, value) {
554
466
  let pos = index >>> 3;
555
-
556
467
  for (let i = this.data.length; pos >= i; pos--) {
557
468
  this.data.push(BIT_OFF);
558
469
  }
559
-
560
470
  pos = index >>> 3;
561
-
562
471
  if (value === undefined || value) {
563
472
  this.data[pos] |= (1 << (index % BUFFER_BITS));
564
- } else {
473
+ }
474
+ else {
565
475
  this.data[pos] &= ~(1 << (index % BUFFER_BITS));
566
476
  }
567
477
  }
568
-
569
478
  get(index) {
570
479
  var n = index >>> WORD_LOG;
571
-
572
480
  if (n >= this.data.length) {
573
481
  return BIT_OFF;
574
482
  }
575
-
576
483
  return (this.data[n] >>> index) & BIT_ON;
577
484
  }
578
-
579
485
  toBuffer() {
580
486
  return Buffer.from(this.data);
581
487
  }
582
488
  }
583
-
584
- exports.BlrWriter = BlrWriter;
585
- exports.BlrReader = BlrReader;
586
- exports.XdrWriter = XdrWriter;
587
- exports.XdrReader = XdrReader;
588
489
  exports.BitSet = BitSet;
@@ -0,0 +1,66 @@
1
+ import Events from 'events';
2
+ import stream from 'stream';
3
+ import { BlrReader } from './serialize';
4
+ /***************************************
5
+ *
6
+ * Service Manager
7
+ *
8
+ ***************************************/
9
+ declare class ServiceManager extends Events.EventEmitter {
10
+ static ShutdownMode: {
11
+ NORMAL: number;
12
+ MULTI: number;
13
+ SINGLE: number;
14
+ FULL: number;
15
+ };
16
+ static ShutdownKind: {
17
+ FORCED: number;
18
+ DENY_TRANSACTION: number;
19
+ DENY_ATTACHMENT: number;
20
+ };
21
+ connection: any;
22
+ constructor(connection: any);
23
+ _createOutputStream(optread: string | null | undefined, buffersize: number | null | undefined, callback: (err: any, stream?: stream.Readable) => void): void;
24
+ _infosmapping: Record<string | number, string>;
25
+ _processcapabilities(blr: BlrReader, res: any): void;
26
+ _processdbinfo(blr: BlrReader, res: any): void;
27
+ _processquery(buffer: Buffer, callback: (err: any, res?: any) => void): void;
28
+ detach(callback?: (err?: any, obj?: any) => void, force?: boolean): this;
29
+ backup(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
30
+ nbackup(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
31
+ restore(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
32
+ nrestore(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
33
+ _fixpropertie(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
34
+ setDialect(db: string, dialect: number, callback: any): void;
35
+ setSweepinterval(db: string, sweepinterval: number, callback: any): void;
36
+ setCachebuffer(db: string, nbpages: number, callback: any): void;
37
+ BringOnline(db: string, callback: any): void;
38
+ Shutdown(db: string, kind: number, delay: number, mode?: any, callback?: any): void;
39
+ setShadow(db: string, val: boolean, callback: any): void;
40
+ setForcewrite(db: string, val: boolean, callback: any): void;
41
+ setReservespace(db: string, val: boolean, callback: any): void;
42
+ setReadonlyMode(db: string, callback: any): void;
43
+ setReadwriteMode(db: string, callback: any): void;
44
+ validate(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
45
+ commit(db: string, transactid: number, callback: any): void;
46
+ rollback(db: string, transactid: number, callback: any): void;
47
+ recover(db: string, transactid: number, callback: any): void;
48
+ getStats(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
49
+ getLog(options: any, callback: (err: any, stream?: stream.Readable) => void): void;
50
+ getUsers(username: string | null, callback: any): void;
51
+ addUser(username: string, password: string, options: any, callback: any): void;
52
+ editUser(username: string, options: any, callback: any): void;
53
+ removeUser(username: string, rolename: string | null, callback: any): void;
54
+ getFbserverInfos(infos: any, options: any, callback: any): void;
55
+ startTrace(options: any, callback: any): void;
56
+ suspendTrace(options: any, callback: any): void;
57
+ resumeTrace(options: any, callback: any): void;
58
+ stopTrace(options: any, callback: any): void;
59
+ getTraceList(options: any, callback: any): void;
60
+ readline(options: any, callback: any): void;
61
+ readeof(options: any, callback: any): void;
62
+ hasRunningAction(options: any, callback: any): void;
63
+ readusers(options: any, callback: any): void;
64
+ readlimbo(options: any, callback: any): void;
65
+ }
66
+ export = ServiceManager;