node-firebird 2.3.4 → 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,18 +1,17 @@
1
- const Const= require('./const');
2
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SQLParamBool = exports.SQLParamDate = exports.SQLParamQuad = exports.SQLParamBuffer = exports.SQLParamString = exports.SQLParamDouble = exports.SQLParamDecFloat34 = exports.SQLParamDecFloat16 = exports.SQLParamInt128 = exports.SQLParamInt64 = exports.SQLParamInt = exports.SQLVarBoolean = exports.SQLVarTimeStampTzEx = exports.SQLVarTimeStampTz = exports.SQLVarTimeTzEx = exports.SQLVarTimeTz = exports.SQLVarTimeStamp = exports.SQLVarTime = exports.SQLVarDate = exports.SQLVarDouble = exports.SQLVarFloat = exports.SQLVarDecFloat34 = exports.SQLVarDecFloat16 = exports.SQLVarInt128 = exports.SQLVarInt64 = exports.SQLVarShort = exports.SQLVarInt = exports.SQLVarArray = exports.SQLVarBlob = exports.SQLVarQuad = exports.SQLVarString = exports.SQLVarNull = exports.SQLVarText = exports.SQLVarBase = void 0;
7
+ const const_1 = __importDefault(require("./const"));
3
8
  /***************************************
4
9
  *
5
10
  * SQLVar
6
11
  *
7
12
  ***************************************/
8
-
9
- const
10
- ScaleDivisor = [1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000, 100000000000,1000000000000,10000000000000,100000000000000,1000000000000000];
11
- const
12
- DateOffset = 40587,
13
- TimeCoeff = 86400000,
14
- MsPerMinute = 60000;
15
-
13
+ const ScaleDivisor = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000];
14
+ const DateOffset = 40587, TimeCoeff = 86400000, MsPerMinute = 60000;
16
15
  /**
17
16
  * Maps Firebird character-set names (upper-case) to the Node.js Buffer
18
17
  * encoding string used by Buffer.toString() / Buffer.from().
@@ -26,28 +25,26 @@ const
26
25
  * connection-level DEFAULT_ENCODING (typically 'utf8').
27
26
  */
28
27
  const FirebirdToNodeEncoding = Object.freeze({
29
- UTF8: 'utf8',
28
+ UTF8: 'utf8',
30
29
  UNICODE_FSS: 'utf8',
31
- WIN1252: 'latin1',
32
- ISO8859_1: 'latin1',
33
- LATIN1: 'latin1',
34
- ASCII: 'ascii',
35
- NONE: 'latin1', // unspecified charset – treat as binary-safe latin1
30
+ WIN1252: 'latin1',
31
+ ISO8859_1: 'latin1',
32
+ LATIN1: 'latin1',
33
+ ASCII: 'ascii',
34
+ NONE: 'latin1', // unspecified charset – treat as binary-safe latin1
36
35
  });
37
-
38
36
  const FirebirdCharsetWidths = {
39
37
  'UTF8': 4,
40
38
  'UNICODE_FSS': 3,
41
39
  'SJIS': 2,
42
40
  'EUCJ': 2
43
41
  };
44
-
45
42
  function getFirebirdCharsetWidth(charset) {
46
- if (!charset) return 4;
43
+ if (!charset)
44
+ return 4;
47
45
  const upper = charset.toUpperCase();
48
46
  return FirebirdCharsetWidths[upper] || 1;
49
47
  }
50
-
51
48
  /**
52
49
  * Resolve the Node.js Buffer encoding to use when decoding text from a
53
50
  * Firebird response buffer.
@@ -58,13 +55,20 @@ function getFirebirdCharsetWidth(charset) {
58
55
  function resolveTextEncoding(options) {
59
56
  const encoding = (options && options.encoding)
60
57
  ? options.encoding.toUpperCase()
61
- : Const.DEFAULT_ENCODING;
62
- return FirebirdToNodeEncoding[encoding] || Const.DEFAULT_ENCODING.toLowerCase();
58
+ : const_1.default.DEFAULT_ENCODING;
59
+ return (FirebirdToNodeEncoding[encoding] || const_1.default.DEFAULT_ENCODING.toLowerCase());
60
+ }
61
+ //------------------------------------------------------
62
+ /**
63
+ * Common shape of all SQLVar descriptor objects. The metadata properties
64
+ * are populated externally (in connection.ts) from the op_prepare_statement
65
+ * describe response before decode()/calcBlr() are called.
66
+ */
67
+ class SQLVarBase {
63
68
  }
64
-
69
+ exports.SQLVarBase = SQLVarBase;
65
70
  //------------------------------------------------------
66
-
67
- class SQLVarText {
71
+ class SQLVarText extends SQLVarBase {
68
72
  decode(data, lowerV13, options) {
69
73
  let ret;
70
74
  const textEncoding = resolveTextEncoding(options);
@@ -77,7 +81,8 @@ class SQLVarText {
77
81
  if (ret.length > charLength) {
78
82
  ret = ret.substring(0, charLength);
79
83
  }
80
- } else if (this.subType === 0) {
84
+ }
85
+ else if (this.subType === 0) {
81
86
  // without charset definition
82
87
  ret = data.readText(this.length, textEncoding);
83
88
  const encoding = options && options.encoding ? options.encoding : 'UTF8';
@@ -86,280 +91,233 @@ class SQLVarText {
86
91
  if (ret.length > charLength) {
87
92
  ret = ret.substring(0, charLength);
88
93
  }
89
- } else {
94
+ }
95
+ else {
90
96
  ret = data.readBuffer(this.length);
91
97
  }
92
-
93
98
  if (!lowerV13 || !data.readInt()) {
94
99
  return ret;
95
100
  }
96
-
97
101
  return null;
98
102
  }
99
-
100
103
  calcBlr(blr) {
101
- blr.addByte(Const.blr_text);
104
+ blr.addByte(const_1.default.blr_text);
102
105
  blr.addWord(this.length);
103
106
  }
104
107
  }
105
-
108
+ exports.SQLVarText = SQLVarText;
106
109
  //------------------------------------------------------
107
-
108
110
  class SQLVarNull extends SQLVarText {
109
111
  }
110
-
112
+ exports.SQLVarNull = SQLVarNull;
111
113
  //------------------------------------------------------
112
-
113
- class SQLVarString {
114
+ class SQLVarString extends SQLVarBase {
114
115
  decode(data, lowerV13, options) {
115
116
  let ret;
116
117
  const textEncoding = resolveTextEncoding(options);
117
118
  if (this.subType > 1) {
118
119
  // ToDo: with column charset
119
120
  ret = data.readString(textEncoding);
120
- } else if (this.subType === 0) {
121
+ }
122
+ else if (this.subType === 0) {
121
123
  // without charset definition
122
124
  ret = data.readString(textEncoding);
123
- } else {
125
+ }
126
+ else {
124
127
  ret = data.readBuffer();
125
128
  }
126
-
127
129
  if (!lowerV13 || !data.readInt()) {
128
130
  return ret;
129
131
  }
130
-
131
132
  return null;
132
133
  }
133
-
134
134
  calcBlr(blr) {
135
- blr.addByte(Const.blr_varying);
135
+ blr.addByte(const_1.default.blr_varying);
136
136
  blr.addWord(this.length);
137
137
  }
138
138
  }
139
-
139
+ exports.SQLVarString = SQLVarString;
140
140
  //------------------------------------------------------
141
-
142
- class SQLVarQuad {
141
+ class SQLVarQuad extends SQLVarBase {
143
142
  decode(data, lowerV13) {
144
143
  var ret = data.readQuad();
145
-
146
144
  if (!lowerV13 || !data.readInt()) {
147
145
  return ret;
148
146
  }
149
147
  return null;
150
148
  }
151
-
152
149
  calcBlr(blr) {
153
- blr.addByte(Const.blr_quad);
150
+ blr.addByte(const_1.default.blr_quad);
154
151
  blr.addShort(this.scale);
155
152
  }
156
153
  }
157
-
154
+ exports.SQLVarQuad = SQLVarQuad;
158
155
  //------------------------------------------------------
159
-
160
156
  class SQLVarBlob extends SQLVarQuad {
161
157
  calcBlr(blr) {
162
- blr.addByte(Const.blr_quad);
158
+ blr.addByte(const_1.default.blr_quad);
163
159
  blr.addShort(0);
164
160
  }
165
161
  }
166
-
162
+ exports.SQLVarBlob = SQLVarBlob;
167
163
  //------------------------------------------------------
168
-
169
164
  class SQLVarArray extends SQLVarQuad {
170
165
  calcBlr(blr) {
171
- blr.addByte(Const.blr_quad);
166
+ blr.addByte(const_1.default.blr_quad);
172
167
  blr.addShort(0);
173
168
  }
174
169
  }
175
-
170
+ exports.SQLVarArray = SQLVarArray;
176
171
  //------------------------------------------------------
177
-
178
- class SQLVarInt {
172
+ class SQLVarInt extends SQLVarBase {
179
173
  decode(data, lowerV13) {
180
174
  var ret = data.readInt();
181
-
182
175
  if (this.scale) {
183
176
  ret = ret / ScaleDivisor[Math.abs(this.scale)];
184
177
  }
185
-
186
178
  if (!lowerV13 || !data.readInt()) {
187
179
  return ret;
188
180
  }
189
-
190
181
  return null;
191
182
  }
192
-
193
183
  calcBlr(blr) {
194
- blr.addByte(Const.blr_long);
184
+ blr.addByte(const_1.default.blr_long);
195
185
  blr.addShort(this.scale);
196
186
  }
197
187
  }
198
-
188
+ exports.SQLVarInt = SQLVarInt;
199
189
  //------------------------------------------------------
200
-
201
190
  class SQLVarShort extends SQLVarInt {
202
191
  calcBlr(blr) {
203
- blr.addByte(Const.blr_short);
192
+ blr.addByte(const_1.default.blr_short);
204
193
  blr.addShort(this.scale);
205
194
  }
206
195
  }
207
-
196
+ exports.SQLVarShort = SQLVarShort;
208
197
  //------------------------------------------------------
209
-
210
- class SQLVarInt64 {
198
+ class SQLVarInt64 extends SQLVarBase {
211
199
  decode(data, lowerV13) {
212
200
  var ret = data.readInt64();
213
-
214
201
  if (this.scale) {
215
202
  ret = ret / ScaleDivisor[Math.abs(this.scale)];
216
203
  }
217
-
218
204
  if (!lowerV13 || !data.readInt()) {
219
205
  return ret;
220
206
  }
221
207
  return null;
222
208
  }
223
-
224
209
  calcBlr(blr) {
225
- blr.addByte(Const.blr_int64);
210
+ blr.addByte(const_1.default.blr_int64);
226
211
  blr.addShort(this.scale);
227
212
  }
228
213
  }
229
-
214
+ exports.SQLVarInt64 = SQLVarInt64;
230
215
  //------------------------------------------------------
231
-
232
- class SQLVarInt128 {
216
+ class SQLVarInt128 extends SQLVarBase {
233
217
  decode(data, lowerV13) {
234
- var retBigInt = BigInt(data.readInt128())
235
-
218
+ var retBigInt = BigInt(data.readInt128());
219
+ let ret;
236
220
  if (retBigInt > BigInt(Number.MAX_SAFE_INTEGER)) {
237
- var ret = retBigInt.toString();
238
-
239
- var integerPart = ret.slice(0, Math.abs(this.scale) * -1)
240
- var decimalPart = ret.slice(Math.abs(this.scale) * -1)
241
-
242
- if (integerPart === '') integerPart = '0'
243
-
244
- ret = `${integerPart}.${decimalPart}`
245
- } else {
246
- var ret = Number(retBigInt);
221
+ ret = retBigInt.toString();
222
+ var integerPart = ret.slice(0, Math.abs(this.scale) * -1);
223
+ var decimalPart = ret.slice(Math.abs(this.scale) * -1);
224
+ if (integerPart === '')
225
+ integerPart = '0';
226
+ ret = `${integerPart}.${decimalPart}`;
227
+ }
228
+ else {
229
+ ret = Number(retBigInt);
247
230
  ret = ret / ScaleDivisor[Math.abs(this.scale)];
248
231
  }
249
-
250
232
  if (!lowerV13 || !data.readInt()) {
251
233
  return ret;
252
234
  }
253
-
254
235
  return null;
255
236
  }
256
-
257
237
  calcBlr(blr) {
258
- blr.addByte(Const.blr_int128);
238
+ blr.addByte(const_1.default.blr_int128);
259
239
  blr.addShort(this.scale);
260
240
  }
261
241
  }
262
-
242
+ exports.SQLVarInt128 = SQLVarInt128;
263
243
  //------------------------------------------------------
264
-
265
- class SQLVarDecFloat16 {
244
+ class SQLVarDecFloat16 extends SQLVarBase {
266
245
  decode(data, lowerV13) {
267
246
  var ret = data.readDecFloat16();
268
-
269
247
  if (!lowerV13 || !data.readInt()) {
270
248
  return ret;
271
249
  }
272
-
273
250
  return null;
274
251
  }
275
-
276
252
  calcBlr(blr) {
277
- blr.addByte(Const.blr_dec64);
253
+ blr.addByte(const_1.default.blr_dec64);
278
254
  blr.addShort(0);
279
255
  }
280
256
  }
281
-
257
+ exports.SQLVarDecFloat16 = SQLVarDecFloat16;
282
258
  //------------------------------------------------------
283
-
284
- class SQLVarDecFloat34 {
259
+ class SQLVarDecFloat34 extends SQLVarBase {
285
260
  decode(data, lowerV13) {
286
261
  var ret = data.readDecFloat34();
287
-
288
262
  if (!lowerV13 || !data.readInt()) {
289
263
  return ret;
290
264
  }
291
-
292
265
  return null;
293
266
  }
294
-
295
267
  calcBlr(blr) {
296
- blr.addByte(Const.blr_dec128);
268
+ blr.addByte(const_1.default.blr_dec128);
297
269
  blr.addShort(0);
298
270
  }
299
271
  }
300
-
272
+ exports.SQLVarDecFloat34 = SQLVarDecFloat34;
301
273
  //------------------------------------------------------
302
-
303
- class SQLVarFloat {
274
+ class SQLVarFloat extends SQLVarBase {
304
275
  decode(data, lowerV13) {
305
276
  var ret = data.readFloat();
306
-
307
277
  if (!lowerV13 || !data.readInt()) {
308
278
  return ret;
309
279
  }
310
-
311
280
  return null;
312
281
  }
313
-
314
282
  calcBlr(blr) {
315
- blr.addByte(Const.blr_float);
283
+ blr.addByte(const_1.default.blr_float);
316
284
  }
317
285
  }
318
-
286
+ exports.SQLVarFloat = SQLVarFloat;
319
287
  //------------------------------------------------------
320
-
321
- class SQLVarDouble {
288
+ class SQLVarDouble extends SQLVarBase {
322
289
  decode(data, lowerV13) {
323
290
  var ret = data.readDouble();
324
-
325
291
  if (!lowerV13 || !data.readInt()) {
326
292
  return ret;
327
293
  }
328
-
329
294
  return null;
330
295
  }
331
-
332
296
  calcBlr(blr) {
333
- blr.addByte(Const.blr_double);
297
+ blr.addByte(const_1.default.blr_double);
334
298
  }
335
299
  }
336
-
300
+ exports.SQLVarDouble = SQLVarDouble;
337
301
  //------------------------------------------------------
338
-
339
- class SQLVarDate {
302
+ class SQLVarDate extends SQLVarBase {
340
303
  decode(data, lowerV13) {
341
304
  var ret = data.readInt();
342
-
343
305
  if (!lowerV13 || !data.readInt()) {
344
306
  var d = new Date(0);
345
307
  d.setMilliseconds((ret - DateOffset) * TimeCoeff + d.getTimezoneOffset() * MsPerMinute);
346
308
  return d;
347
309
  }
348
-
349
310
  return null;
350
311
  }
351
-
352
312
  calcBlr(blr) {
353
- blr.addByte(Const.blr_sql_date);
313
+ blr.addByte(const_1.default.blr_sql_date);
354
314
  }
355
315
  }
356
-
316
+ exports.SQLVarDate = SQLVarDate;
357
317
  //------------------------------------------------------
358
-
359
- class SQLVarTime {
318
+ class SQLVarTime extends SQLVarBase {
360
319
  decode(data, lowerV13) {
361
320
  var ret = data.readUInt();
362
-
363
321
  if (!lowerV13 || !data.readInt()) {
364
322
  var d = new Date(0);
365
323
  d.setMilliseconds(Math.floor(ret / 10) + d.getTimezoneOffset() * MsPerMinute);
@@ -367,40 +325,33 @@ class SQLVarTime {
367
325
  }
368
326
  return null;
369
327
  }
370
-
371
328
  calcBlr(blr) {
372
- blr.addByte(Const.blr_sql_time);
329
+ blr.addByte(const_1.default.blr_sql_time);
373
330
  }
374
331
  }
375
-
332
+ exports.SQLVarTime = SQLVarTime;
376
333
  //------------------------------------------------------
377
-
378
- class SQLVarTimeStamp {
334
+ class SQLVarTimeStamp extends SQLVarBase {
379
335
  decode(data, lowerV13) {
380
336
  var date = data.readInt();
381
337
  var time = data.readUInt();
382
-
383
338
  if (!lowerV13 || !data.readInt()) {
384
339
  var d = new Date(0);
385
340
  d.setMilliseconds((date - DateOffset) * TimeCoeff + Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute);
386
341
  return d;
387
342
  }
388
-
389
343
  return null;
390
344
  }
391
-
392
345
  calcBlr(blr) {
393
- blr.addByte(Const.blr_timestamp);
346
+ blr.addByte(const_1.default.blr_timestamp);
394
347
  }
395
348
  }
396
-
349
+ exports.SQLVarTimeStamp = SQLVarTimeStamp;
397
350
  //------------------------------------------------------
398
-
399
- class SQLVarTimeTz {
351
+ class SQLVarTimeTz extends SQLVarBase {
400
352
  decode(data, lowerV13) {
401
353
  var time = data.readUInt();
402
354
  data.readInt(); // skip timezone info
403
-
404
355
  if (!lowerV13 || !data.readInt()) {
405
356
  var d = new Date(0);
406
357
  d.setMilliseconds(Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute);
@@ -408,20 +359,17 @@ class SQLVarTimeTz {
408
359
  }
409
360
  return null;
410
361
  }
411
-
412
362
  calcBlr(blr) {
413
- blr.addByte(Const.blr_sql_time_tz);
363
+ blr.addByte(const_1.default.blr_sql_time_tz);
414
364
  }
415
365
  }
416
-
366
+ exports.SQLVarTimeTz = SQLVarTimeTz;
417
367
  //------------------------------------------------------
418
-
419
368
  class SQLVarTimeTzEx extends SQLVarTimeTz {
420
369
  decode(data, lowerV13) {
421
370
  var time = data.readUInt();
422
371
  data.readInt(); // skip timezone info
423
372
  data.readInt(); // skip ext_offset
424
-
425
373
  if (!lowerV13 || !data.readInt()) {
426
374
  var d = new Date(0);
427
375
  d.setMilliseconds(Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute);
@@ -429,338 +377,290 @@ class SQLVarTimeTzEx extends SQLVarTimeTz {
429
377
  }
430
378
  return null;
431
379
  }
432
-
433
380
  calcBlr(blr) {
434
- blr.addByte(Const.blr_ex_time_tz);
381
+ blr.addByte(const_1.default.blr_ex_time_tz);
435
382
  }
436
383
  }
437
-
384
+ exports.SQLVarTimeTzEx = SQLVarTimeTzEx;
438
385
  //------------------------------------------------------
439
-
440
- class SQLVarTimeStampTz {
386
+ class SQLVarTimeStampTz extends SQLVarBase {
441
387
  decode(data, lowerV13) {
442
388
  var date = data.readInt();
443
389
  var time = data.readUInt();
444
390
  data.readInt(); // skip timezone info
445
-
446
391
  if (!lowerV13 || !data.readInt()) {
447
392
  var d = new Date(0);
448
393
  d.setMilliseconds((date - DateOffset) * TimeCoeff + Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute);
449
394
  return d;
450
395
  }
451
-
452
396
  return null;
453
397
  }
454
-
455
398
  calcBlr(blr) {
456
- blr.addByte(Const.blr_timestamp_tz);
399
+ blr.addByte(const_1.default.blr_timestamp_tz);
457
400
  }
458
401
  }
459
-
402
+ exports.SQLVarTimeStampTz = SQLVarTimeStampTz;
460
403
  //------------------------------------------------------
461
-
462
404
  class SQLVarTimeStampTzEx extends SQLVarTimeStampTz {
463
405
  decode(data, lowerV13) {
464
406
  var date = data.readInt();
465
407
  var time = data.readUInt();
466
408
  data.readInt(); // skip timezone info
467
409
  data.readInt(); // skip ext_offset
468
-
469
410
  if (!lowerV13 || !data.readInt()) {
470
411
  var d = new Date(0);
471
412
  d.setMilliseconds((date - DateOffset) * TimeCoeff + Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute);
472
413
  return d;
473
414
  }
474
-
475
415
  return null;
476
416
  }
477
-
478
417
  calcBlr(blr) {
479
- blr.addByte(Const.blr_ex_timestamp_tz);
418
+ blr.addByte(const_1.default.blr_ex_timestamp_tz);
480
419
  }
481
420
  }
482
-
421
+ exports.SQLVarTimeStampTzEx = SQLVarTimeStampTzEx;
483
422
  //------------------------------------------------------
484
-
485
- class SQLVarBoolean {
423
+ class SQLVarBoolean extends SQLVarBase {
486
424
  decode(data, lowerV13) {
487
425
  var ret = data.readInt();
488
-
489
426
  if (!lowerV13 || !data.readInt()) {
490
427
  return Boolean(ret);
491
428
  }
492
429
  return null;
493
430
  }
494
-
495
431
  calcBlr(blr) {
496
- blr.addByte(Const.blr_bool);
432
+ blr.addByte(const_1.default.blr_bool);
497
433
  }
498
434
  }
499
-
435
+ exports.SQLVarBoolean = SQLVarBoolean;
500
436
  //------------------------------------------------------
501
-
502
437
  class SQLParamInt {
503
438
  constructor(value) {
504
439
  this.value = value;
505
440
  }
506
-
507
441
  calcBlr(blr) {
508
- blr.addByte(Const.blr_long);
442
+ blr.addByte(const_1.default.blr_long);
509
443
  blr.addShort(0);
510
444
  }
511
-
512
445
  encode(data) {
513
446
  if (this.value != null) {
514
447
  data.addInt(this.value);
515
- } else {
448
+ }
449
+ else {
516
450
  data.addInt(0);
517
451
  data.addInt(1);
518
452
  }
519
453
  }
520
454
  }
521
-
455
+ exports.SQLParamInt = SQLParamInt;
522
456
  //------------------------------------------------------
523
-
524
457
  class SQLParamInt64 {
525
458
  constructor(value) {
526
459
  this.value = value;
527
460
  }
528
-
529
461
  calcBlr(blr) {
530
- blr.addByte(Const.blr_int64);
462
+ blr.addByte(const_1.default.blr_int64);
531
463
  blr.addShort(0);
532
464
  }
533
-
534
465
  encode(data) {
535
466
  if (this.value != null) {
536
467
  data.addInt64(this.value);
537
- } else {
468
+ }
469
+ else {
538
470
  data.addInt64(0);
539
471
  data.addInt(1);
540
472
  }
541
473
  }
542
474
  }
543
-
475
+ exports.SQLParamInt64 = SQLParamInt64;
544
476
  //------------------------------------------------------
545
-
546
477
  class SQLParamInt128 {
547
478
  constructor(value) {
548
479
  this.value = value;
549
480
  }
550
-
551
481
  calcBlr(blr) {
552
- blr.addByte(Const.blr_int128);
482
+ blr.addByte(const_1.default.blr_int128);
553
483
  blr.addShort(0);
554
484
  }
555
-
556
485
  encode(data) {
557
486
  if (this.value != null) {
558
487
  data.addInt128(this.value);
559
- } else {
488
+ }
489
+ else {
560
490
  data.addInt128(0);
561
491
  data.addInt(1);
562
492
  }
563
493
  }
564
494
  }
565
-
495
+ exports.SQLParamInt128 = SQLParamInt128;
566
496
  //------------------------------------------------------
567
-
568
497
  class SQLParamDecFloat16 {
569
498
  constructor(value) {
570
499
  this.value = value;
571
500
  }
572
-
573
501
  calcBlr(blr) {
574
- blr.addByte(Const.blr_dec64);
502
+ blr.addByte(const_1.default.blr_dec64);
575
503
  blr.addShort(0);
576
504
  }
577
-
578
505
  encode(data) {
579
506
  if (this.value != null) {
580
507
  data.addDecFloat16(this.value);
581
- } else {
508
+ }
509
+ else {
582
510
  data.addDecFloat16(0);
583
511
  data.addInt(1);
584
512
  }
585
513
  }
586
514
  }
587
-
515
+ exports.SQLParamDecFloat16 = SQLParamDecFloat16;
588
516
  //------------------------------------------------------
589
-
590
517
  class SQLParamDecFloat34 {
591
518
  constructor(value) {
592
519
  this.value = value;
593
520
  }
594
-
595
521
  calcBlr(blr) {
596
- blr.addByte(Const.blr_dec128);
522
+ blr.addByte(const_1.default.blr_dec128);
597
523
  blr.addShort(0);
598
524
  }
599
-
600
525
  encode(data) {
601
526
  if (this.value != null) {
602
527
  data.addDecFloat34(this.value);
603
- } else {
528
+ }
529
+ else {
604
530
  data.addDecFloat34(0);
605
531
  data.addInt(1);
606
532
  }
607
533
  }
608
534
  }
609
-
535
+ exports.SQLParamDecFloat34 = SQLParamDecFloat34;
610
536
  //------------------------------------------------------
611
-
612
537
  class SQLParamDouble {
613
538
  constructor(value) {
614
539
  this.value = value;
615
540
  }
616
-
617
541
  encode(data) {
618
542
  if (this.value != null) {
619
543
  data.addDouble(this.value);
620
- } else {
544
+ }
545
+ else {
621
546
  data.addDouble(0);
622
547
  data.addInt(1);
623
548
  }
624
549
  }
625
-
626
550
  calcBlr(blr) {
627
- blr.addByte(Const.blr_double);
551
+ blr.addByte(const_1.default.blr_double);
628
552
  }
629
553
  }
630
-
554
+ exports.SQLParamDouble = SQLParamDouble;
631
555
  //------------------------------------------------------
632
-
633
556
  class SQLParamString {
634
557
  constructor(value) {
635
558
  this.value = value;
636
559
  }
637
-
638
560
  encode(data) {
639
561
  if (this.value != null) {
640
- data.addText(this.value, Const.DEFAULT_ENCODING);
641
- } else {
562
+ data.addText(this.value, const_1.default.DEFAULT_ENCODING);
563
+ }
564
+ else {
642
565
  data.addInt(1);
643
566
  }
644
567
  }
645
-
646
568
  calcBlr(blr) {
647
- blr.addByte(Const.blr_text);
648
- var len = this.value ? Buffer.byteLength(this.value, Const.DEFAULT_ENCODING) : 0;
569
+ blr.addByte(const_1.default.blr_text);
570
+ var len = this.value ? Buffer.byteLength(this.value, const_1.default.DEFAULT_ENCODING) : 0;
649
571
  blr.addWord(len);
650
572
  }
651
573
  }
652
-
574
+ exports.SQLParamString = SQLParamString;
575
+ //------------------------------------------------------
576
+ class SQLParamBuffer {
577
+ constructor(value) {
578
+ this.value = value;
579
+ }
580
+ encode(data) {
581
+ if (this.value != null) {
582
+ data.addParamBuffer(this.value);
583
+ }
584
+ else {
585
+ data.addInt(1);
586
+ }
587
+ }
588
+ calcBlr(blr) {
589
+ blr.addByte(const_1.default.blr_text);
590
+ var len = this.value ? this.value.length : 0;
591
+ blr.addWord(len);
592
+ }
593
+ }
594
+ exports.SQLParamBuffer = SQLParamBuffer;
653
595
  //------------------------------------------------------
654
-
655
596
  class SQLParamQuad {
656
597
  constructor(value) {
657
598
  this.value = value;
658
599
  }
659
-
660
600
  encode(data) {
661
601
  if (this.value != null) {
662
602
  data.addInt(this.value.high);
663
603
  data.addInt(this.value.low);
664
- } else {
604
+ }
605
+ else {
665
606
  data.addInt(0);
666
607
  data.addInt(0);
667
608
  data.addInt(1);
668
609
  }
669
610
  }
670
-
671
611
  calcBlr(blr) {
672
- blr.addByte(Const.blr_quad);
612
+ blr.addByte(const_1.default.blr_quad);
673
613
  blr.addShort(0);
674
614
  }
675
615
  }
676
-
616
+ exports.SQLParamQuad = SQLParamQuad;
677
617
  //------------------------------------------------------
678
-
679
618
  class SQLParamDate {
680
619
  constructor(value) {
681
620
  this.value = value;
682
621
  }
683
-
684
622
  encode(data) {
685
623
  if (this.value != null) {
686
-
687
624
  var value = this.value.getTime() - this.value.getTimezoneOffset() * MsPerMinute;
688
625
  var time = value % TimeCoeff;
689
626
  var date = (value - time) / TimeCoeff + DateOffset;
690
627
  time *= 10;
691
-
692
628
  // check overflow
693
629
  if (time < 0) {
694
630
  date--;
695
- time = TimeCoeff*10 + time;
631
+ time = TimeCoeff * 10 + time;
696
632
  }
697
-
698
633
  data.addInt(date);
699
634
  data.addUInt(time);
700
- } else {
635
+ }
636
+ else {
701
637
  data.addInt(0);
702
638
  data.addUInt(0);
703
639
  data.addInt(1);
704
640
  }
705
641
  }
706
-
707
642
  calcBlr(blr) {
708
- blr.addByte(Const.blr_timestamp);
643
+ blr.addByte(const_1.default.blr_timestamp);
709
644
  }
710
645
  }
711
-
646
+ exports.SQLParamDate = SQLParamDate;
712
647
  //------------------------------------------------------
713
-
714
648
  class SQLParamBool {
715
649
  constructor(value) {
716
650
  this.value = value;
717
651
  }
718
-
719
652
  encode(data) {
720
653
  if (this.value != null) {
721
654
  data.addInt(this.value ? 1 : 0);
722
- } else {
655
+ }
656
+ else {
723
657
  data.addInt(0);
724
658
  data.addInt(1);
725
659
  }
726
660
  }
727
-
728
661
  calcBlr(blr) {
729
- blr.addByte(Const.blr_short);
662
+ blr.addByte(const_1.default.blr_short);
730
663
  blr.addShort(0);
731
664
  }
732
665
  }
733
-
734
- module.exports = {
735
- SQLVarArray,
736
- SQLVarDate,
737
- SQLVarBlob,
738
- SQLVarBoolean,
739
- SQLVarDouble,
740
- SQLVarInt,
741
- SQLVarInt64,
742
- SQLVarInt128,
743
- SQLVarDecFloat16,
744
- SQLVarDecFloat34,
745
- SQLVarFloat,
746
- SQLVarNull,
747
- SQLVarShort,
748
- SQLVarString,
749
- SQLVarText,
750
- SQLVarTime,
751
- SQLVarTimeStamp,
752
- SQLVarTimeTz,
753
- SQLVarTimeTzEx,
754
- SQLVarTimeStampTz,
755
- SQLVarTimeStampTzEx,
756
- SQLParamBool,
757
- SQLParamDate,
758
- SQLParamDouble,
759
- SQLParamInt,
760
- SQLParamInt64,
761
- SQLParamInt128,
762
- SQLParamDecFloat16,
763
- SQLParamDecFloat34,
764
- SQLParamQuad,
765
- SQLParamString,
766
- };
666
+ exports.SQLParamBool = SQLParamBool;