node-firebird 2.3.4 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +574 -20
  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
@@ -0,0 +1,57 @@
1
+ import Events from 'events';
2
+ declare class Database extends Events.EventEmitter {
3
+ connection: any;
4
+ eventid: number;
5
+ constructor(connection: any);
6
+ escape(value: any): string;
7
+ detach(callback?: (err?: any, obj?: any) => void, force?: boolean): this;
8
+ transaction(options: any, callback?: (err: any, transaction?: any) => void): this;
9
+ startTransaction(options: any, callback?: (err: any, transaction?: any) => void): this;
10
+ newStatement(query: string, callback: (err: any, statement?: any) => void): this;
11
+ execute(query: string, params?: any, callback?: any, options?: any): this;
12
+ sequentially(query: string, params?: any, on?: any, callback?: any, options?: any): this;
13
+ query(query: string, params?: any, callback?: any, options?: any): this;
14
+ drop(callback?: (err?: any) => void): void;
15
+ attachEvent(callback: (err: any, evt?: any) => void): this;
16
+ /**
17
+ * Create a physical tablespace.
18
+ * Supported in Firebird 6.0+ (Protocol 20+).
19
+ *
20
+ * @param {string} name - The name of the tablespace.
21
+ * @param {string} filePath - The physical file path for the tablespace.
22
+ * @param {function} [callback] - Asynchronous completion callback.
23
+ * @returns {Database}
24
+ */
25
+ createTablespace(name: string, filePath: string, callback?: any): this;
26
+ /**
27
+ * Alter an existing tablespace physical location.
28
+ * Supported in Firebird 6.0+ (Protocol 20+).
29
+ *
30
+ * @param {string} name - The name of the tablespace.
31
+ * @param {string} filePath - The new physical file path.
32
+ * @param {function} [callback] - Asynchronous completion callback.
33
+ * @returns {Database}
34
+ */
35
+ alterTablespace(name: string, filePath: string, callback?: any): this;
36
+ /**
37
+ * Drop a tablespace.
38
+ * Supported in Firebird 6.0+ (Protocol 20+).
39
+ *
40
+ * @param {string} name - The name of the tablespace.
41
+ * @param {function} [callback] - Asynchronous completion callback.
42
+ * @returns {Database}
43
+ */
44
+ dropTablespace(name: string, callback?: any): this;
45
+ /**
46
+ * Create a schema/namespace. Can optionally partition/map the namespace
47
+ * to a physical tablespace.
48
+ * Supported in Firebird 6.0+ (Protocol 20+).
49
+ *
50
+ * @param {string} schemaName - The name of the schema.
51
+ * @param {string} [tablespaceName] - Optional tablespace name to bind this schema namespace.
52
+ * @param {function} [callback] - Asynchronous completion callback.
53
+ * @returns {Database}
54
+ */
55
+ createSchema(schemaName: string, tablespaceName?: string | ((err?: any) => void), callback?: any): this;
56
+ }
57
+ export = Database;
@@ -1,10 +1,13 @@
1
- const Events = require('events');
2
- const { doError } = require('../callback');
3
- const { escape } = require('../utils');
4
- const Const = require('./const');
5
- const EventConnection = require('./eventConnection');
6
- const FbEventManager = require('./fbEventManager');
7
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const events_1 = __importDefault(require("events"));
6
+ const callback_1 = require("../callback");
7
+ const utils_1 = require("../utils");
8
+ const const_1 = __importDefault(require("./const"));
9
+ const eventConnection_1 = __importDefault(require("./eventConnection"));
10
+ const fbEventManager_1 = __importDefault(require("./fbEventManager"));
8
11
  /***************************************
9
12
  *
10
13
  * Database
@@ -39,72 +42,58 @@ const FbEventManager = require('./fbEventManager');
39
42
  * 5. Call evtmgr.close(callback) when done to release the aux connection.
40
43
  *
41
44
  ***************************************/
42
-
43
45
  function readblob(blob, callback) {
44
46
  if (blob === undefined || blob === null) {
45
47
  callback(null, blob);
46
48
  return;
47
49
  }
48
-
49
50
  if (typeof blob !== 'function') {
50
51
  callback(null, blob);
51
52
  return;
52
53
  }
53
-
54
- blob(function(err, name, e) {
54
+ blob(function (err, name, e) {
55
55
  if (err) {
56
56
  callback(err);
57
57
  return;
58
58
  }
59
-
60
59
  if (!e) {
61
60
  callback(null, null);
62
61
  return;
63
62
  }
64
-
65
63
  const chunks = [];
66
64
  let chunksLength = 0;
67
-
68
- e.on('data', function(chunk) {
65
+ e.on('data', function (chunk) {
69
66
  chunksLength += chunk.length;
70
67
  chunks.push(chunk);
71
68
  });
72
-
73
- e.on('end', function() {
69
+ e.on('end', function () {
74
70
  callback(null, Buffer.concat(chunks, chunksLength));
75
71
  });
76
-
77
- e.on('error', function(streamErr) {
72
+ e.on('error', function (streamErr) {
78
73
  callback(streamErr);
79
74
  });
80
75
  });
81
76
  }
82
-
83
77
  function fetchBlobSyncRow(row, meta, callback) {
84
78
  if (!row || !meta || !meta.length) {
85
79
  callback(null, row);
86
80
  return;
87
81
  }
88
-
89
82
  const rowKeys = Object.keys(row);
90
83
  const blobColumns = [];
91
-
92
84
  for (let i = 0; i < meta.length; i++) {
93
- if (meta[i] && meta[i].type === Const.SQL_BLOB && rowKeys[i] !== undefined) {
85
+ if (meta[i] && meta[i].type === const_1.default.SQL_BLOB && rowKeys[i] !== undefined) {
94
86
  blobColumns.push(rowKeys[i]);
95
87
  }
96
88
  }
97
-
98
89
  if (!blobColumns.length) {
99
90
  callback(null, row);
100
91
  return;
101
92
  }
102
-
103
93
  let pending = blobColumns.length;
104
94
  let blobErr;
105
-
106
- blobColumns.forEach(function(columnName) {
107
- readblob(row[columnName], function(err, data) {
95
+ blobColumns.forEach(function (columnName) {
96
+ readblob(row[columnName], function (err, data) {
108
97
  if (err && !blobErr) {
109
98
  blobErr = err;
110
99
  }
@@ -116,116 +105,90 @@ function fetchBlobSyncRow(row, meta, callback) {
116
105
  });
117
106
  });
118
107
  }
119
-
120
- class Database extends Events.EventEmitter {
108
+ class Database extends events_1.default.EventEmitter {
121
109
  constructor(connection) {
122
110
  super();
123
111
  this.connection = connection;
124
112
  connection.db = this;
125
113
  this.eventid = 1;
126
114
  }
127
-
128
115
  escape(value) {
129
- return escape(value, this.connection.accept.protocolVersion);
116
+ return (0, utils_1.escape)(value, this.connection.accept.protocolVersion);
130
117
  }
131
-
132
118
  detach(callback, force) {
133
119
  var self = this;
134
-
135
120
  if (!force && self.connection._pending.length > 0) {
136
121
  self.connection._detachAuto = true;
137
122
  self.connection._detachCallback = callback;
138
123
  return self;
139
124
  }
140
-
141
125
  if (self.connection._pooled === false) {
142
126
  self.connection.detach(function (err, obj) {
143
-
144
127
  self.connection.disconnect();
145
128
  self.emit('detach', false);
146
-
147
129
  if (callback)
148
130
  callback(err, obj);
149
-
150
131
  }, force);
151
- } else {
132
+ }
133
+ else {
152
134
  self.emit('detach', false);
153
135
  if (callback)
154
136
  callback();
155
137
  }
156
-
157
138
  return self;
158
139
  }
159
-
160
140
  transaction(options, callback) {
161
141
  return this.startTransaction(options, callback);
162
142
  }
163
-
164
143
  startTransaction(options, callback) {
165
144
  this.connection.startTransaction(options, callback);
166
145
  return this;
167
146
  }
168
-
169
147
  newStatement(query, callback) {
170
- this.startTransaction(function(err, transaction) {
171
-
148
+ this.startTransaction(function (err, transaction) {
172
149
  if (err) {
173
150
  callback(err);
174
151
  return;
175
152
  }
176
-
177
- transaction.newStatement(query, function(err, statement) {
178
-
153
+ transaction.newStatement(query, function (err, statement) {
179
154
  if (err) {
180
155
  callback(err);
181
156
  return;
182
157
  }
183
-
184
- transaction.commit(function(err) {
158
+ transaction.commit(function (err) {
185
159
  callback(err, statement);
186
160
  });
187
161
  });
188
162
  });
189
-
190
163
  return this;
191
164
  }
192
-
193
165
  execute(query, params, callback, options) {
194
166
  if (params instanceof Function) {
195
167
  options = callback;
196
168
  callback = params;
197
169
  params = undefined;
198
170
  }
199
-
200
171
  var self = this;
201
-
202
- self.connection.startTransaction(function(err, transaction) {
203
-
172
+ self.connection.startTransaction(function (err, transaction) {
204
173
  if (err) {
205
- doError(err, callback);
174
+ (0, callback_1.doError)(err, callback);
206
175
  return;
207
176
  }
208
-
209
- transaction.execute(query, params, function(err, result, meta, isSelect) {
210
-
177
+ transaction.execute(query, params, function (err, result, meta, isSelect) {
211
178
  if (err) {
212
- transaction.rollback(function() {
213
- doError(err, callback);
179
+ transaction.rollback(function () {
180
+ (0, callback_1.doError)(err, callback);
214
181
  });
215
182
  return;
216
183
  }
217
-
218
- transaction.commit(function(err) {
184
+ transaction.commit(function (err) {
219
185
  if (callback)
220
186
  callback(err, result, meta, isSelect);
221
187
  });
222
-
223
188
  }, options);
224
189
  });
225
-
226
190
  return self;
227
191
  }
228
-
229
192
  sequentially(query, params, on, callback, options = {}) {
230
193
  if (params instanceof Function) {
231
194
  options = callback;
@@ -233,58 +196,55 @@ class Database extends Events.EventEmitter {
233
196
  on = params;
234
197
  params = undefined;
235
198
  }
236
-
237
- if (on === undefined){
199
+ if (on === undefined) {
238
200
  throw new Error('Expected "on" delegate.');
239
201
  }
240
-
241
202
  if (callback instanceof Boolean) {
242
203
  options = callback;
243
204
  callback = undefined;
244
205
  }
245
-
246
206
  var self = this;
247
- var _on = function(row, i, meta, next) {
207
+ var _on = function (row, i, meta, next) {
248
208
  var done = false;
249
- var finish = function(err) {
209
+ var finish = function (err) {
250
210
  if (done) {
251
211
  return;
252
212
  }
253
213
  done = true;
254
214
  next(err);
255
215
  };
256
-
257
- fetchBlobSyncRow(row, meta, function(blobErr) {
216
+ fetchBlobSyncRow(row, meta, function (blobErr) {
258
217
  if (blobErr) {
259
218
  finish(blobErr);
260
219
  return;
261
220
  }
262
-
263
221
  try {
264
222
  var ret;
265
223
  if (on.length >= 3) {
266
224
  ret = on(row, i, finish);
267
- } else {
225
+ }
226
+ else {
268
227
  ret = on(row, i);
269
228
  }
270
-
271
229
  if (ret && typeof ret.then === 'function') {
272
- ret.then(function() {
230
+ ret.then(function () {
273
231
  finish();
274
232
  }).catch(finish);
275
- } else if (on.length < 3) {
233
+ }
234
+ else if (on.length < 3) {
276
235
  finish();
277
236
  }
278
- } catch (err) {
237
+ }
238
+ catch (err) {
279
239
  finish(err);
280
240
  }
281
241
  });
282
242
  };
283
-
284
243
  // back compatibility - options parameter is a boolean
285
244
  if (typeof options === 'boolean') {
286
245
  options = { asObject: !options, asStream: true, on: _on };
287
- } else {
246
+ }
247
+ else {
288
248
  options = {
289
249
  asObject: true,
290
250
  asStream: true,
@@ -292,87 +252,130 @@ class Database extends Events.EventEmitter {
292
252
  ...options,
293
253
  };
294
254
  }
295
-
296
255
  self.execute(query, params, callback, options);
297
256
  return self;
298
257
  }
299
-
300
258
  query(query, params, callback, options = {}) {
301
259
  if (params instanceof Function) {
302
260
  options = callback || {};
303
261
  callback = params;
304
262
  params = undefined;
305
263
  }
306
-
307
264
  options = {
308
265
  asObject: true,
309
266
  asStream: callback === undefined || callback === null,
310
267
  ...options
311
268
  };
312
-
313
269
  var self = this;
314
270
  self.execute(query, params, callback, options);
315
271
  return self;
316
272
  }
317
-
318
273
  drop(callback) {
319
274
  return this.connection.dropDatabase(callback);
320
275
  }
321
-
322
276
  attachEvent(callback) {
323
277
  var self = this;
278
+ const eventid = self.eventid++;
324
279
  if (process.env.FIREBIRD_DEBUG) {
325
- console.log('[fb-debug] Database.attachEvent: calling auxConnection, eventid=%d queue=%d', self.eventid, self.connection._queue.length);
280
+ console.log('[fb-debug] Database.attachEvent: calling auxConnection, eventid=%d queue=%d', eventid, self.connection._queue.length);
326
281
  }
327
- this.connection.auxConnection(function (err, socket_info) {
328
-
282
+ this.connection.auxConnection(eventid, function (err, socket_info) {
329
283
  if (err) {
330
284
  if (process.env.FIREBIRD_DEBUG) {
331
285
  console.log('[fb-debug] Database.attachEvent: auxConnection error:', err.message);
332
286
  }
333
- doError(err, callback);
287
+ (0, callback_1.doError)(err, callback);
334
288
  return;
335
289
  }
336
-
337
290
  if (process.env.FIREBIRD_DEBUG) {
338
291
  console.log('[fb-debug] Database.attachEvent: auxConnection ok, connecting to aux port %s:%d', socket_info.host, socket_info.port);
339
292
  }
340
-
341
293
  const host = (socket_info.host === '0.0.0.0' || socket_info.host === '::')
342
294
  ? self.connection.options.host
343
295
  : socket_info.host;
344
-
345
- const eventConnection = new EventConnection(
346
- host, socket_info.port, function(err) {
296
+ const eventConnection = new eventConnection_1.default(host, socket_info.port, function (err) {
347
297
  if (err) {
348
298
  if (process.env.FIREBIRD_DEBUG) {
349
299
  console.log('[fb-debug] Database.attachEvent: EventConnection error:', err.message);
350
300
  }
351
- doError(err, callback);
301
+ (0, callback_1.doError)(err, callback);
352
302
  return;
353
303
  }
354
-
355
304
  if (process.env.FIREBIRD_DEBUG) {
356
- console.log('[fb-debug] Database.attachEvent: EventConnection connected, creating FbEventManager eventid=%d', self.eventid);
305
+ console.log('[fb-debug] Database.attachEvent: EventConnection connected, creating FbEventManager eventid=%d', eventid);
357
306
  }
358
-
359
- const evt = new FbEventManager(self, eventConnection, self.eventid++, function (err) {
307
+ const evt = new fbEventManager_1.default(self, eventConnection, eventid, function (err) {
360
308
  if (err) {
361
- doError(err, callback);
309
+ (0, callback_1.doError)(err, callback);
362
310
  return;
363
311
  }
364
-
365
312
  if (process.env.FIREBIRD_DEBUG) {
366
313
  console.log('[fb-debug] Database.attachEvent: FbEventManager ready, eventid=%d', evt.eventid);
367
314
  }
368
-
369
315
  callback(err, evt);
370
316
  });
371
317
  }, self);
372
318
  });
373
-
374
319
  return this;
375
320
  }
321
+ /**
322
+ * Create a physical tablespace.
323
+ * Supported in Firebird 6.0+ (Protocol 20+).
324
+ *
325
+ * @param {string} name - The name of the tablespace.
326
+ * @param {string} filePath - The physical file path for the tablespace.
327
+ * @param {function} [callback] - Asynchronous completion callback.
328
+ * @returns {Database}
329
+ */
330
+ createTablespace(name, filePath, callback) {
331
+ const sql = `CREATE TABLESPACE ${name} FILE '${filePath}'`;
332
+ return this.execute(sql, [], callback);
333
+ }
334
+ /**
335
+ * Alter an existing tablespace physical location.
336
+ * Supported in Firebird 6.0+ (Protocol 20+).
337
+ *
338
+ * @param {string} name - The name of the tablespace.
339
+ * @param {string} filePath - The new physical file path.
340
+ * @param {function} [callback] - Asynchronous completion callback.
341
+ * @returns {Database}
342
+ */
343
+ alterTablespace(name, filePath, callback) {
344
+ const sql = `ALTER TABLESPACE ${name} SET FILE TO '${filePath}'`;
345
+ return this.execute(sql, [], callback);
346
+ }
347
+ /**
348
+ * Drop a tablespace.
349
+ * Supported in Firebird 6.0+ (Protocol 20+).
350
+ *
351
+ * @param {string} name - The name of the tablespace.
352
+ * @param {function} [callback] - Asynchronous completion callback.
353
+ * @returns {Database}
354
+ */
355
+ dropTablespace(name, callback) {
356
+ const sql = `DROP TABLESPACE ${name}`;
357
+ return this.execute(sql, [], callback);
358
+ }
359
+ /**
360
+ * Create a schema/namespace. Can optionally partition/map the namespace
361
+ * to a physical tablespace.
362
+ * Supported in Firebird 6.0+ (Protocol 20+).
363
+ *
364
+ * @param {string} schemaName - The name of the schema.
365
+ * @param {string} [tablespaceName] - Optional tablespace name to bind this schema namespace.
366
+ * @param {function} [callback] - Asynchronous completion callback.
367
+ * @returns {Database}
368
+ */
369
+ createSchema(schemaName, tablespaceName, callback) {
370
+ if (typeof tablespaceName === 'function') {
371
+ callback = tablespaceName;
372
+ tablespaceName = undefined;
373
+ }
374
+ let sql = `CREATE SCHEMA ${schemaName}`;
375
+ if (tablespaceName) {
376
+ sql += ` TABLESPACE ${tablespaceName}`;
377
+ }
378
+ return this.execute(sql, [], callback);
379
+ }
376
380
  }
377
-
378
381
  module.exports = Database;
@@ -0,0 +1,16 @@
1
+ import net from 'net';
2
+ import { XdrReader } from './serialize';
3
+ declare class EventConnection {
4
+ db: any;
5
+ emgr: any;
6
+ _isClosed: boolean;
7
+ _isOpened: boolean;
8
+ _socket: net.Socket;
9
+ _xdr?: XdrReader;
10
+ error: any;
11
+ eventcallback: ((err: any, ret?: any) => void) | null;
12
+ constructor(host: string, port: number, callback: (() => void) | undefined, db: any);
13
+ _bind_events(host: string, port: number, callback?: () => void): void;
14
+ throwClosed(callback?: (err: any) => void): this;
15
+ }
16
+ export = EventConnection;
@@ -1,8 +1,11 @@
1
- const net = require('net');
2
- const { XdrReader } = require('./serialize');
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const net_1 = __importDefault(require("net"));
6
+ const serialize_1 = require("./serialize");
7
+ const const_1 = __importDefault(require("./const"));
3
8
  const DEFAULT_ENCODING = 'utf8';
4
- const Const = require('./const');
5
-
6
9
  class EventConnection {
7
10
  constructor(host, port, callback, db) {
8
11
  var self = this;
@@ -10,59 +13,49 @@ class EventConnection {
10
13
  this.emgr = null;
11
14
  this._isClosed = false;
12
15
  this._isOpened = false;
13
- this._socket = net.createConnection(port, host);
16
+ this._socket = net_1.default.createConnection(port, host);
14
17
  this._bind_events(host, port, callback);
15
18
  this.error;
16
19
  this.eventcallback;
17
20
  }
18
-
19
21
  _bind_events(host, port, callback) {
20
22
  var self = this;
21
-
22
23
  self._socket.on('close', function () {
23
-
24
24
  self._isClosed = true;
25
- })
26
-
25
+ });
27
26
  self._socket.on('error', function (e) {
28
-
29
27
  self.error = e;
30
- })
31
-
28
+ });
32
29
  self._socket.on('connect', function () {
33
30
  self._isClosed = false;
34
31
  self._isOpened = true;
35
32
  if (callback)
36
33
  callback();
37
34
  });
38
-
39
35
  self._socket.on('data', function (data) {
40
36
  var xdr, buf;
41
-
42
37
  if (!self._xdr) {
43
- xdr = new XdrReader(data);
44
- } else {
38
+ xdr = new serialize_1.XdrReader(data);
39
+ }
40
+ else {
45
41
  xdr = self._xdr;
46
42
  delete (self._xdr);
47
- buf = Buffer.from(data.length + xdr.buffer.length);
43
+ buf = Buffer.alloc(data.length + xdr.buffer.length);
48
44
  xdr.buffer.copy(buf);
49
45
  data.copy(buf, xdr.buffer.length);
50
46
  xdr.buffer = buf;
51
47
  }
52
-
53
48
  try {
54
- var item, op;
55
49
  var op_pos = xdr.pos;
56
50
  var tmp_event;
57
51
  while (xdr.pos < xdr.buffer.length) {
58
52
  do {
59
53
  var r = xdr.readInt();
60
- } while (r === Const.op_dummy);
61
-
54
+ } while (r === const_1.default.op_dummy);
62
55
  switch (r) {
63
- case Const.op_event:
56
+ case const_1.default.op_event:
64
57
  xdr.readInt(); // db handle
65
- var buf = xdr.readArray();
58
+ buf = xdr.readArray();
66
59
  // first byte is always set to 1
67
60
  tmp_event = {};
68
61
  var lst_event = [];
@@ -83,8 +76,13 @@ class EventConnection {
83
76
  xdr.readInt64(); // ignore AST INFO
84
77
  var event_id = xdr.readInt();
85
78
  // set the new count in global event hash
79
+ // Only update events that are still registered; do not
80
+ // re-add events that unregisterEvent() has deleted, since
81
+ // that would cause subscribe() to re-subscribe for them.
86
82
  for (var evt in tmp_event) {
87
- self.emgr.events[evt] = tmp_event[evt];
83
+ if (Object.prototype.hasOwnProperty.call(self.emgr.events, evt)) {
84
+ self.emgr.events[evt] = tmp_event[evt];
85
+ }
88
86
  }
89
87
  if (self.eventcallback)
90
88
  self.eventcallback(null, { eventid: event_id, events: lst_event });
@@ -94,18 +92,19 @@ class EventConnection {
94
92
  return;
95
93
  }
96
94
  }
97
- } catch (err) {
95
+ }
96
+ catch (err) {
98
97
  if (err instanceof RangeError) { // incomplete packet case
99
98
  xdr.buffer = xdr.buffer = xdr.buffer.slice(op_pos);
100
99
  xdr.pos = 0;
101
100
  self._xdr = xdr;
102
- } else {
101
+ }
102
+ else {
103
103
  throw err;
104
104
  }
105
105
  }
106
- })
106
+ });
107
107
  }
108
-
109
108
  throwClosed(callback) {
110
109
  var err = new Error('Event Connection is closed.');
111
110
  this.db.emit('error', err);
@@ -114,5 +113,4 @@ class EventConnection {
114
113
  return this;
115
114
  }
116
115
  }
117
-
118
- module.exports = EventConnection;
116
+ module.exports = EventConnection;