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
@@ -64,16 +64,26 @@
64
64
  // ───────────────────────────────────────────────────────────────
65
65
  // Server → Client : op_event (fired by Firebird POST_EVENT trigger)
66
66
 
67
- const Events = require('events');
68
- const { doError } = require('../callback');
67
+ import Events from 'events';
68
+ import { doError } from '../callback';
69
69
 
70
70
  class FbEventManager extends Events.EventEmitter {
71
- constructor(db, eventconnection, eventid, callback) {
71
+ db: any;
72
+ eventconnection: any;
73
+ events: Record<string, number>;
74
+ eventid: number;
75
+ _subscriptionVersion: number;
76
+ _hasActiveSubscription: boolean;
77
+
78
+ constructor(db: any, eventconnection: any, eventid: number, callback: (err: any, ret?: any) => void) {
72
79
  super();
73
80
  this.db = db;
74
81
  this.eventconnection = eventconnection;
75
82
  this.events = {};
76
83
  this.eventid = eventid;
84
+ // Guards _hasActiveSubscription against late callbacks from an older
85
+ // register/unregister cycle after a newer subscription change started.
86
+ this._subscriptionVersion = 0;
77
87
  // True when an op_que_events subscription is currently active on the
78
88
  // main connection (so close() and _changeEvent know whether to send
79
89
  // op_cancel_events before tearing down or re-subscribing).
@@ -102,7 +112,7 @@ class FbEventManager extends Events.EventEmitter {
102
112
  * isDatabaseConnectionClosed: boolean
103
113
  * }}
104
114
  */
105
- getState() {
115
+ getState(): { state: string; hasActiveSubscription: boolean; registeredEvents: Record<string, number>; eventId: number; isEventConnectionOpen: boolean; isDatabaseConnectionClosed: boolean } {
106
116
  const evtConnOpen = this.eventconnection
107
117
  ? !this.eventconnection._isClosed
108
118
  : false;
@@ -114,7 +124,7 @@ class FbEventManager extends Events.EventEmitter {
114
124
  // Transitional states (SUBSCRIBING / CANCELLING / CLOSING) are not
115
125
  // individually flagged; callers that need finer granularity can
116
126
  // inspect hasActiveSubscription and isEventConnectionOpen together.
117
- let state;
127
+ let state: string;
118
128
  if (dbConnClosed || !evtConnOpen) {
119
129
  state = 'CLOSED';
120
130
  } else if (this._hasActiveSubscription) {
@@ -133,7 +143,7 @@ class FbEventManager extends Events.EventEmitter {
133
143
  };
134
144
  }
135
145
 
136
- _createEventLoop(callback) {
146
+ _createEventLoop(callback: (err: any, ret?: any) => void): void {
137
147
  var self = this;
138
148
  var cnx = this.db.connection;
139
149
  this.eventconnection.emgr = this;
@@ -154,7 +164,7 @@ class FbEventManager extends Events.EventEmitter {
154
164
  if (!self._hasActiveSubscription || Object.keys(self.events).length === 0) {
155
165
  return;
156
166
  }
157
- cnx.queEvents(self.events, self.eventid, function (err) {
167
+ cnx.queEvents(self.events, self.eventid, function (err: any) {
158
168
  if (err) {
159
169
  doError(err, callback);
160
170
  return;
@@ -163,13 +173,13 @@ class FbEventManager extends Events.EventEmitter {
163
173
  });
164
174
  }
165
175
 
166
- this.eventconnection.eventcallback = function (err, ret) {
176
+ this.eventconnection.eventcallback = function (err: any, ret?: any) {
167
177
  if (err || (self.eventid !== ret.eventid)) {
168
178
  doError(err || new Error('Bad eventid'), callback);
169
179
  return;
170
180
  }
171
181
 
172
- ret.events.forEach(function (event) {
182
+ ret.events.forEach(function (event: { name: string; count: number }) {
173
183
  self.emit('post_event', event.name, event.count);
174
184
  });
175
185
 
@@ -183,14 +193,9 @@ class FbEventManager extends Events.EventEmitter {
183
193
  process.nextTick(function() { callback(null); });
184
194
  }
185
195
 
186
- _changeEvent(callback) {
196
+ _changeEvent(callback: (err: any, ret?: any) => void): void {
187
197
  var self = this;
188
-
189
- // Temporarily suppress the event loop to prevent stale op_event
190
- // notifications from pushing spurious queEvents onto the main
191
- // connection queue while we're reconfiguring the subscription.
192
- var savedCallback = self.eventconnection.eventcallback;
193
- self.eventconnection.eventcallback = null;
198
+ const changeVersion = ++self._subscriptionVersion;
194
199
 
195
200
  function subscribe() {
196
201
  // If no events remain, mark subscription as inactive and return.
@@ -199,27 +204,31 @@ class FbEventManager extends Events.EventEmitter {
199
204
  // permanently block the main connection queue.
200
205
  if (Object.keys(self.events).length === 0) {
201
206
  self._hasActiveSubscription = false;
202
- self.eventconnection.eventcallback = savedCallback;
203
207
  callback(null);
204
208
  return;
205
209
  }
206
210
 
207
- self.db.connection.queEvents(self.events, self.eventid, function (err, ret) {
208
- self.eventconnection.eventcallback = savedCallback;
211
+ // Firebird can deliver the initial op_event baseline before the
212
+ // matching op_response reaches the main connection. Mark the
213
+ // subscription active before sending queEvents so that this early
214
+ // op_event can re-queue the next one-shot request.
215
+ self._hasActiveSubscription = true;
216
+ self.db.connection.queEvents(self.events, self.eventid, function (err: any, ret?: any) {
209
217
  if (err) {
218
+ if (self._subscriptionVersion === changeVersion) {
219
+ self._hasActiveSubscription = false;
220
+ }
210
221
  doError(err, callback);
211
222
  return;
212
223
  }
213
- self._hasActiveSubscription = true;
214
224
  callback(null, ret);
215
225
  });
216
226
  }
217
227
 
218
228
  if (self._hasActiveSubscription) {
219
229
  // Cancel the current subscription before setting up a new one.
220
- self.db.connection.closeEvents(this.eventid, function (err) {
230
+ self.db.connection.closeEvents(this.eventid, function (err: any) {
221
231
  if (err) {
222
- self.eventconnection.eventcallback = savedCallback;
223
232
  doError(err, callback);
224
233
  return;
225
234
  }
@@ -233,7 +242,7 @@ class FbEventManager extends Events.EventEmitter {
233
242
  }
234
243
  }
235
244
 
236
- registerEvent(events, callback) {
245
+ registerEvent(events: string[], callback: (err: any, ret?: any) => void): any {
237
246
  var self = this;
238
247
 
239
248
  if (self.db.connection._isClosed || self.eventconnection._isClosed)
@@ -243,7 +252,7 @@ class FbEventManager extends Events.EventEmitter {
243
252
  self._changeEvent(callback);
244
253
  }
245
254
 
246
- unregisterEvent(events, callback) {
255
+ unregisterEvent(events: string[], callback: (err: any, ret?: any) => void): any {
247
256
  var self = this;
248
257
 
249
258
  if (self.db.connection._isClosed || self.eventconnection._isClosed)
@@ -253,7 +262,7 @@ class FbEventManager extends Events.EventEmitter {
253
262
  self._changeEvent(callback);
254
263
  }
255
264
 
256
- close(callback) {
265
+ close(callback?: (err?: any) => void): void {
257
266
  var self = this;
258
267
 
259
268
  if (process.env.FIREBIRD_DEBUG) {
@@ -273,7 +282,7 @@ class FbEventManager extends Events.EventEmitter {
273
282
  // queEvents calls – the server internally fails on the RST error and does not
274
283
  // clean up its event state in time for the next subscription request.
275
284
  // A 200 ms safety timer fires as a fallback if Firebird never sends its FIN.
276
- function endAndWaitForClose(cb) {
285
+ function endAndWaitForClose(cb?: (err?: any) => void) {
277
286
  var sock = self.eventconnection && self.eventconnection._socket;
278
287
  if (!sock || sock.destroyed) {
279
288
  if (process.env.FIREBIRD_DEBUG) {
@@ -283,8 +292,8 @@ class FbEventManager extends Events.EventEmitter {
283
292
  return;
284
293
  }
285
294
  var fired = false;
286
- var timer;
287
- function done(source) {
295
+ var timer: NodeJS.Timeout;
296
+ function done(source: string) {
288
297
  if (!fired) {
289
298
  fired = true;
290
299
  clearTimeout(timer);
@@ -311,7 +320,7 @@ class FbEventManager extends Events.EventEmitter {
311
320
  return;
312
321
  }
313
322
 
314
- self.db.connection.closeEvents(this.eventid, function (err) {
323
+ self.db.connection.closeEvents(this.eventid, function (err: any) {
315
324
  if (err) {
316
325
  doError(err, callback);
317
326
  return;
@@ -323,4 +332,4 @@ class FbEventManager extends Events.EventEmitter {
323
332
  }
324
333
  }
325
334
 
326
- module.exports = FbEventManager;
335
+ export = FbEventManager;
@@ -1,7 +1,7 @@
1
1
 
2
- const { encodeDecimal64, decodeDecimal64, encodeDecimal128, decodeDecimal128 } = require('../ieee754-decimal');
2
+ import { encodeDecimal64, decodeDecimal64, encodeDecimal128, decodeDecimal128 } from '../ieee754-decimal';
3
3
 
4
- function align(n) {
4
+ function align(n: number): number {
5
5
  return (n + 3) & ~3;
6
6
  }
7
7
 
@@ -14,13 +14,16 @@ function align(n) {
14
14
  const
15
15
  MAX_STRING_SIZE = 255;
16
16
 
17
- class BlrWriter {
18
- constructor(size) {
17
+ export class BlrWriter {
18
+ buffer: Buffer;
19
+ pos: number;
20
+
21
+ constructor(size?: number) {
19
22
  this.buffer = Buffer.alloc(size || 32);
20
23
  this.pos = 0;
21
24
  }
22
25
 
23
- ensure(len) {
26
+ ensure(len: number): void {
24
27
  var newlen = this.buffer.length;
25
28
 
26
29
  while (newlen < this.pos + len)
@@ -31,48 +34,47 @@ class BlrWriter {
31
34
 
32
35
  var b = Buffer.alloc(newlen);
33
36
  this.buffer.copy(b);
34
- delete(this.buffer);
35
37
  this.buffer = b;
36
38
  }
37
39
 
38
- addByte(b) {
40
+ addByte(b: number): void {
39
41
  this.ensure(1);
40
42
  this.buffer.writeUInt8(b, this.pos);
41
43
  this.pos++;
42
44
  }
43
45
 
44
- addShort(b) {
46
+ addShort(b: number): void {
45
47
  this.ensure(1);
46
48
  this.buffer.writeInt8(b, this.pos);
47
49
  this.pos++;
48
50
  }
49
51
 
50
- addSmall(b) {
52
+ addSmall(b: number): void {
51
53
  this.ensure(2);
52
54
  this.buffer.writeInt16LE(b, this.pos);
53
55
  this.pos += 2;
54
56
  }
55
57
 
56
- addWord(b) {
58
+ addWord(b: number): void {
57
59
  this.ensure(2);
58
60
  this.buffer.writeUInt16LE(b, this.pos);
59
61
  this.pos += 2;
60
62
  }
61
63
 
62
- addInt32(b) {
64
+ addInt32(b: number): void {
63
65
  this.ensure(4);
64
66
  this.buffer.writeUInt32LE(b, this.pos);
65
67
  this.pos += 4;
66
68
  }
67
69
 
68
- addByteInt32(c, b) {
70
+ addByteInt32(c: number, b: number): void {
69
71
  this.addByte(c);
70
72
  this.ensure(4);
71
73
  this.buffer.writeUInt32LE(b, this.pos);
72
74
  this.pos += 4;
73
75
  }
74
76
 
75
- addNumeric(c, v) {
77
+ addNumeric(c: number, v: number): void {
76
78
  if (v < 256){
77
79
  this.ensure(3);
78
80
  this.buffer.writeUInt8(c, this.pos);
@@ -93,7 +95,7 @@ class BlrWriter {
93
95
  this.pos += 4;
94
96
  }
95
97
 
96
- addBytes(b) {
98
+ addBytes(b: number[] | Buffer): void {
97
99
  this.ensure(b.length);
98
100
  for (var i = 0, length = b.length; i < length; i++) {
99
101
  this.buffer.writeUInt8(b[i], this.pos);
@@ -101,7 +103,7 @@ class BlrWriter {
101
103
  }
102
104
  }
103
105
 
104
- addString(c, s, encoding) {
106
+ addString(c: number, s: string, encoding: BufferEncoding): void {
105
107
  this.addByte(c);
106
108
 
107
109
  var len = Buffer.byteLength(s, encoding);
@@ -115,14 +117,14 @@ class BlrWriter {
115
117
  this.pos += len;
116
118
  }
117
119
 
118
- addBuffer(b) {
120
+ addBuffer(b: Buffer): void {
119
121
  this.addWord(b.length);
120
122
  this.ensure(b.length);
121
123
  b.copy(this.buffer, this.pos);
122
124
  this.pos += b.length;
123
125
  }
124
126
 
125
- addString2(c, s, encoding) {
127
+ addString2(c: number, s: string, encoding: BufferEncoding): void {
126
128
  this.addByte(c);
127
129
 
128
130
  var len = Buffer.byteLength(s, encoding);
@@ -136,7 +138,7 @@ class BlrWriter {
136
138
  this.pos += len;
137
139
  }
138
140
 
139
- addMultiblockPart(c, s, encoding) {
141
+ addMultiblockPart(c: number, s: string, encoding: BufferEncoding): void {
140
142
  var buff = Buffer.from(s, encoding);
141
143
  var remaining = buff.length;
142
144
  var step = 0;
@@ -164,8 +166,11 @@ class BlrWriter {
164
166
  *
165
167
  ***************************************/
166
168
 
167
- class BlrReader {
168
- constructor(buffer) {
169
+ export class BlrReader {
170
+ buffer: Buffer;
171
+ pos: number;
172
+
173
+ constructor(buffer: Buffer) {
169
174
  this.buffer = buffer;
170
175
  this.pos = 0;
171
176
  }
@@ -198,7 +203,7 @@ class BlrReader {
198
203
  return value;
199
204
  }
200
205
 
201
- readString(encoding) {
206
+ readString(encoding?: BufferEncoding): string {
202
207
  var len = this.buffer.readUInt16LE(this.pos);
203
208
  var str;
204
209
 
@@ -211,8 +216,8 @@ class BlrReader {
211
216
  return str;
212
217
  }
213
218
 
214
- readSegment() {
215
- var ret, tmp;
219
+ readSegment(): Buffer {
220
+ var ret: Buffer | undefined, tmp: Buffer;
216
221
  var len = this.buffer.readUInt16LE(this.pos);
217
222
 
218
223
  this.pos += 2;
@@ -248,13 +253,16 @@ class BlrReader {
248
253
  *
249
254
  ***************************************/
250
255
 
251
- class XdrWriter {
252
- constructor(size) {
256
+ export class XdrWriter {
257
+ buffer: Buffer;
258
+ pos: number;
259
+
260
+ constructor(size?: number) {
253
261
  this.buffer = Buffer.alloc(size || 32);
254
262
  this.pos = 0;
255
263
  }
256
264
 
257
- ensure(len) {
265
+ ensure(len: number): void {
258
266
  var newlen = this.buffer.length;
259
267
 
260
268
  while (newlen < this.pos + len)
@@ -265,17 +273,16 @@ class XdrWriter {
265
273
 
266
274
  var b = Buffer.alloc(newlen);
267
275
  this.buffer.copy(b);
268
- delete(this.buffer);
269
276
  this.buffer = b;
270
277
  }
271
278
 
272
- addInt(value) {
279
+ addInt(value: number): void {
273
280
  this.ensure(4);
274
281
  this.buffer.writeInt32BE(value, this.pos);
275
282
  this.pos += 4;
276
283
  }
277
284
 
278
- addInt64(value) {
285
+ addInt64(value: number): void {
279
286
  this.ensure(8);
280
287
  // Note: precision is limited to Number.MAX_SAFE_INTEGER (±2^53-1).
281
288
  // Values outside this range lose precision, which matches the previous
@@ -284,7 +291,7 @@ class XdrWriter {
284
291
  this.pos += 8;
285
292
  }
286
293
 
287
- addInt128(value) {
294
+ addInt128(value: number | bigint | string): void {
288
295
  this.ensure(16);
289
296
 
290
297
  const bigValue = BigInt(value);
@@ -298,7 +305,7 @@ class XdrWriter {
298
305
  this.pos += 8;
299
306
  }
300
307
 
301
- addDecFloat16(value) {
308
+ addDecFloat16(value: number | string | bigint): void {
302
309
  // DECFLOAT(16) - IEEE 754 Decimal64 - 8 bytes
303
310
  // Full IEEE 754-2008 Decimal64 implementation
304
311
  this.ensure(8);
@@ -308,7 +315,7 @@ class XdrWriter {
308
315
  this.pos += 8;
309
316
  }
310
317
 
311
- addDecFloat34(value) {
318
+ addDecFloat34(value: number | string | bigint): void {
312
319
  // DECFLOAT(34) - IEEE 754 Decimal128 - 16 bytes
313
320
  // Full IEEE 754-2008 Decimal128 implementation
314
321
  this.ensure(16);
@@ -318,50 +325,63 @@ class XdrWriter {
318
325
  this.pos += 16;
319
326
  }
320
327
 
321
- addUInt(value) {
328
+ addUInt(value: number): void {
322
329
  this.ensure(4);
323
330
  this.buffer.writeUInt32BE(value, this.pos);
324
331
  this.pos += 4;
325
332
  }
326
333
 
327
- addString(s, encoding) {
334
+ addString(s: string, encoding: BufferEncoding): void {
328
335
  var len = Buffer.byteLength(s, encoding);
329
336
  var alen = align(len);
330
337
  this.ensure(alen + 4);
331
338
  this.buffer.writeInt32BE(len, this.pos);
332
339
  this.pos += 4;
333
340
  this.buffer.write(s, this.pos, len, encoding);
341
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
334
342
  this.pos += alen;
335
343
  }
336
344
 
337
- addText(s, encoding) {
345
+ addText(s: string, encoding: BufferEncoding): void {
338
346
  var len = Buffer.byteLength(s, encoding);
339
347
  var alen = align(len);
340
348
  this.ensure(alen);
341
349
  this.buffer.write(s, this.pos, len, encoding);
350
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
342
351
  this.pos += alen;
343
352
  }
344
353
 
345
- addBlr(blr) {
354
+ addParamBuffer(b: Buffer): void {
355
+ var len = b.length;
356
+ var alen = align(len);
357
+ this.ensure(alen);
358
+ b.copy(this.buffer, this.pos);
359
+ this.buffer.fill(0, this.pos + len, this.pos + alen);
360
+ this.pos += alen;
361
+ }
362
+
363
+
364
+ addBlr(blr: BlrWriter): void {
346
365
  var alen = align(blr.pos);
347
366
  this.ensure(alen + 4);
348
367
  this.buffer.writeInt32BE(blr.pos, this.pos);
349
368
  this.pos += 4;
350
- blr.buffer.copy(this.buffer, this.pos);
369
+ blr.buffer.copy(this.buffer, this.pos, 0, blr.pos);
370
+ this.buffer.fill(0, this.pos + blr.pos, this.pos + alen);
351
371
  this.pos += alen;
352
372
  }
353
373
 
354
- getData() {
374
+ getData(): Buffer {
355
375
  return this.buffer.slice(0, this.pos);
356
376
  }
357
377
 
358
- addDouble(value) {
378
+ addDouble(value: number): void {
359
379
  this.ensure(8);
360
380
  this.buffer.writeDoubleBE(value, this.pos);
361
381
  this.pos += 8;
362
382
  }
363
383
 
364
- addQuad(quad) {
384
+ addQuad(quad: { low: number; high: number }): void {
365
385
  this.ensure(8);
366
386
  var b = this.buffer;
367
387
  b.writeInt32BE(quad.high, this.pos);
@@ -370,13 +390,13 @@ class XdrWriter {
370
390
  this.pos += 4;
371
391
  }
372
392
 
373
- addBuffer(buffer) {
393
+ addBuffer(buffer: Buffer): void {
374
394
  this.ensure(buffer.length);
375
395
  buffer.copy(this.buffer, this.pos, 0, buffer.length);
376
396
  this.pos += buffer.length;
377
397
  }
378
398
 
379
- addAlignment(len) {
399
+ addAlignment(len: number): void {
380
400
  var alen = (4 - len) & 3;
381
401
 
382
402
  this.ensure(alen);
@@ -391,8 +411,11 @@ class XdrWriter {
391
411
  *
392
412
  ***************************************/
393
413
 
394
- class XdrReader {
395
- constructor(buffer) {
414
+ export class XdrReader {
415
+ buffer: Buffer;
416
+ pos: number;
417
+
418
+ constructor(buffer: Buffer) {
396
419
  this.buffer = buffer;
397
420
  this.pos = 0;
398
421
  }
@@ -482,7 +505,7 @@ class XdrReader {
482
505
  return r;
483
506
  }
484
507
 
485
- readBuffer(len, toAlign = true) {
508
+ readBuffer(len?: number, toAlign = true): Buffer | undefined {
486
509
  if (!arguments.length) {
487
510
  len = this.readInt();
488
511
  }
@@ -499,12 +522,12 @@ class XdrReader {
499
522
  }
500
523
  }
501
524
 
502
- readString(encoding) {
525
+ readString(encoding: BufferEncoding): string {
503
526
  var len = this.readInt();
504
527
  return this.readText(len, encoding);
505
528
  }
506
529
 
507
- readText(len, encoding) {
530
+ readText(len: number, encoding: BufferEncoding): string {
508
531
  if (len <= 0)
509
532
  return '';
510
533
 
@@ -524,8 +547,10 @@ var BUFFER_BITS = 8;
524
547
  var BIT_ON = 1;
525
548
  var BIT_OFF = 0;
526
549
 
527
- class BitSet {
528
- constructor(buffer) {
550
+ export class BitSet {
551
+ data: number[];
552
+
553
+ constructor(buffer?: Buffer) {
529
554
  this.data = [];
530
555
 
531
556
  if (buffer) {
@@ -542,7 +567,7 @@ class BitSet {
542
567
  }
543
568
  }
544
569
 
545
- scale(index) {
570
+ scale(index: number): void {
546
571
  var l = index >>> WORD_LOG;
547
572
 
548
573
  for (var i = this.data.length; l >= i; l--) {
@@ -550,7 +575,7 @@ class BitSet {
550
575
  }
551
576
  }
552
577
 
553
- set(index, value) {
578
+ set(index: number, value?: boolean | number): void {
554
579
  let pos = index >>> 3;
555
580
 
556
581
  for (let i = this.data.length; pos >= i; pos--) {
@@ -566,7 +591,7 @@ class BitSet {
566
591
  }
567
592
  }
568
593
 
569
- get(index) {
594
+ get(index: number): number {
570
595
  var n = index >>> WORD_LOG;
571
596
 
572
597
  if (n >= this.data.length) {
@@ -576,13 +601,7 @@ class BitSet {
576
601
  return (this.data[n] >>> index) & BIT_ON;
577
602
  }
578
603
 
579
- toBuffer() {
604
+ toBuffer(): Buffer {
580
605
  return Buffer.from(this.data);
581
606
  }
582
607
  }
583
-
584
- exports.BlrWriter = BlrWriter;
585
- exports.BlrReader = BlrReader;
586
- exports.XdrWriter = XdrWriter;
587
- exports.XdrReader = XdrReader;
588
- exports.BitSet = BitSet;