node-firebird-driver 3.2.2 → 3.3.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/impl/attachment.d.ts +4 -4
  3. package/dist/lib/impl/attachment.js +8 -6
  4. package/dist/lib/impl/attachment.js.map +1 -1
  5. package/dist/lib/impl/blob.js.map +1 -1
  6. package/dist/lib/impl/client.js +3 -2
  7. package/dist/lib/impl/client.js.map +1 -1
  8. package/dist/lib/impl/date-time.js +2 -1
  9. package/dist/lib/impl/date-time.js.map +1 -1
  10. package/dist/lib/impl/events.js +2 -1
  11. package/dist/lib/impl/events.js.map +1 -1
  12. package/dist/lib/impl/fb-util.d.ts +2 -1
  13. package/dist/lib/impl/fb-util.js +100 -81
  14. package/dist/lib/impl/fb-util.js.map +1 -1
  15. package/dist/lib/impl/resultset.js +11 -5
  16. package/dist/lib/impl/resultset.js.map +1 -1
  17. package/dist/lib/impl/statement.js +4 -2
  18. package/dist/lib/impl/statement.js.map +1 -1
  19. package/dist/lib/impl/time-zones.js +5 -3
  20. package/dist/lib/impl/time-zones.js.map +1 -1
  21. package/dist/lib/impl/transaction.js +2 -1
  22. package/dist/lib/impl/transaction.js.map +1 -1
  23. package/dist/lib/index.d.ts +8 -1
  24. package/dist/lib/index.js +7 -1
  25. package/dist/lib/index.js.map +1 -1
  26. package/dist/test/tests.js +176 -68
  27. package/dist/test/tests.js.map +1 -1
  28. package/package.json +6 -5
  29. package/src/lib/impl/attachment.ts +290 -253
  30. package/src/lib/impl/blob.ts +37 -35
  31. package/src/lib/impl/client.ts +60 -61
  32. package/src/lib/impl/date-time.ts +33 -33
  33. package/src/lib/impl/events.ts +17 -18
  34. package/src/lib/impl/fb-util.ts +552 -448
  35. package/src/lib/impl/resultset.ts +94 -86
  36. package/src/lib/impl/statement.ts +154 -127
  37. package/src/lib/impl/time-zones.ts +643 -641
  38. package/src/lib/impl/transaction.ts +37 -38
  39. package/src/lib/index.ts +325 -285
  40. package/src/test/tests.ts +996 -860
  41. package/tsconfig.json +7 -13
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "node-firebird-driver",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "Firebird Driver Interfaces for Node.js",
5
5
  "main": "dist/lib/index.js",
6
6
  "scripts": {
7
- "build": "yarn run clean && yarn run lint && tsc --build",
7
+ "build": "yarn run clean && yarn run lint:check && tsc --build",
8
8
  "build:w": "tsc --build -w",
9
9
  "clean": "tsc --build --clean && rimraf dist",
10
- "lint": "tslint --project .",
10
+ "lint:check": "eslint",
11
+ "lint:fix": "eslint --fix",
11
12
  "prepublishOnly": "yarn run build"
12
13
  },
13
14
  "repository": {
@@ -29,7 +30,7 @@
29
30
  "homepage": "https://github.com/asfernandes/node-firebird-drivers#readme",
30
31
  "typings": "./dist/lib/index.d.ts",
31
32
  "dependencies": {
32
- "@types/node": "^22.7.5"
33
+ "@types/node": "^22.13.10"
33
34
  },
34
- "gitHead": "20e22c67b13e0d5ddf6667aa005d65949f5961db"
35
+ "gitHead": "b5e16b7a239c6a8eee91de6576ee8edb4815ab53"
35
36
  }
@@ -6,261 +6,298 @@ import { AbstractTransaction } from './transaction';
6
6
  import { AbstractEvents } from './events';
7
7
 
8
8
  import {
9
- Attachment,
10
- Blob,
11
- CreateBlobOptions,
12
- ExecuteOptions,
13
- ExecuteQueryOptions,
14
- Events,
15
- FetchOptions,
16
- PrepareOptions,
17
- TransactionOptions
9
+ Attachment,
10
+ Blob,
11
+ CreateBlobOptions,
12
+ ExecuteOptions,
13
+ ExecuteQueryOptions,
14
+ Events,
15
+ FetchOptions,
16
+ PrepareOptions,
17
+ TransactionOptions,
18
18
  } from '..';
19
19
 
20
-
21
20
  /** AbstractAttachment implementation. */
22
21
  export abstract class AbstractAttachment implements Attachment {
23
- events = new Set<Events>();
24
- statements = new Set<AbstractStatement>();
25
- transactions = new Set<AbstractTransaction>();
26
-
27
- /** Default transaction options. */
28
- defaultTransactionOptions: TransactionOptions;
29
-
30
- /** Default query's prepare options. */
31
- defaultPrepareOptions: PrepareOptions;
32
-
33
- /** Default query's execute options. */
34
- defaultExecuteOptions: ExecuteOptions;
35
-
36
- /** Default query's executeQuery options. */
37
- defaultExecuteQueryOptions: ExecuteQueryOptions;
38
-
39
- /** Default result set's fetch options. */
40
- defaultFetchOptions: FetchOptions;
41
-
42
- protected constructor(public client?: AbstractClient) {
43
- }
44
-
45
- /** Disconnects this attachment. */
46
- async disconnect(): Promise<void> {
47
- this.check();
48
-
49
- await this.preDispose();
50
- await this.internalDisconnect();
51
- await this.postDispose();
52
- }
53
-
54
- /** Drops the database and release this attachment. */
55
- async dropDatabase(): Promise<void> {
56
- this.check();
57
-
58
- await this.preDispose();
59
- await this.internalDropDatabase();
60
- await this.postDispose();
61
- }
62
-
63
- /** Enable/disable cancellation of operations in this attachment. */
64
- async enableCancellation(enable: boolean): Promise<void> {
65
- this.check();
66
- await this.internalEnableCancellation(enable);
67
- }
68
-
69
- /** Cancel a running operation in this attachment. */
70
- async cancelOperation(forcibleAbort?: boolean): Promise<void> {
71
- this.check();
72
- await this.internalCancelOperation(forcibleAbort ?? false);
73
- }
74
-
75
- /** Executes a statement that uses the SET TRANSACTION command. Returns the new transaction. */
76
- async executeTransaction(transaction: AbstractTransaction, sqlStmt: string,
77
- options?: {
78
- prepareOptions?: PrepareOptions
79
- }): Promise<AbstractTransaction> {
80
- this.check();
81
-
82
- const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
83
- try {
84
- const newTransaction = await statement.executeTransaction(transaction);
85
- this.transactions.add(newTransaction);
86
- return newTransaction;
87
- }
88
- finally {
89
- await statement.dispose();
90
- }
91
- }
92
-
93
- /** Executes a statement that has no result set. */
94
- async execute(transaction: AbstractTransaction, sqlStmt: string, parameters?: any[],
95
- options?: {
96
- prepareOptions?: PrepareOptions,
97
- executeOptions?: ExecuteOptions
98
- }): Promise<void> {
99
- this.check();
100
-
101
- const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
102
- try {
103
- return await statement.execute(transaction, parameters, options && options.executeOptions);
104
- }
105
- finally {
106
- await statement.dispose();
107
- }
108
- }
109
-
110
- /** Executes a statement that returns a single record. */
111
- async executeSingleton(transaction: AbstractTransaction, sqlStmt: string, parameters?: Array<any>,
112
- options?: {
113
- prepareOptions?: PrepareOptions,
114
- executeOptions?: ExecuteOptions
115
- }): Promise<Array<any>> {
116
- this.check();
117
-
118
- const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
119
- try {
120
- return await statement.executeSingleton(transaction, parameters, options && options.executeOptions);
121
- }
122
- finally {
123
- await statement.dispose();
124
- }
125
- }
126
-
127
- /** Executes a statement that returns a single record in object form. */
128
- async executeSingletonAsObject<T extends object>(transaction: AbstractTransaction, sqlStmt: string, parameters?: any[],
129
- options?: {
130
- prepareOptions?: PrepareOptions,
131
- executeOptions?: ExecuteOptions
132
- }): Promise<T> {
133
- this.check();
134
-
135
- const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
136
- try {
137
- return await statement.executeSingletonAsObject(transaction, parameters, options && options.executeOptions);
138
- }
139
- finally {
140
- await statement.dispose();
141
- }
142
- }
143
-
144
- /** Executes a statement that returns a single record. */
145
- async executeReturning(transaction: AbstractTransaction, sqlStmt: string, parameters?: Array<any>,
146
- options?: {
147
- prepareOptions?: PrepareOptions,
148
- executeOptions?: ExecuteOptions
149
- }): Promise<Array<any>> {
150
- return await this.executeSingleton(transaction, sqlStmt, parameters, options);
151
- }
152
-
153
- /** Executes a statement that returns a single record in object form. */
154
- async executeReturningAsObject<T extends object>(transaction: AbstractTransaction, sqlStmt: string, parameters?: any[],
155
- options?: {
156
- prepareOptions?: PrepareOptions,
157
- executeOptions?: ExecuteOptions
158
- }): Promise<T> {
159
- return await this.executeSingletonAsObject<T>(transaction, sqlStmt, parameters, options);
160
- }
161
-
162
- /** Executes a statement that has result set. */
163
- async executeQuery(transaction: AbstractTransaction, sqlStmt: string, parameters?: any[],
164
- options?: {
165
- prepareOptions?: PrepareOptions,
166
- executeOptions?: ExecuteQueryOptions
167
- }): Promise<AbstractResultSet> {
168
- this.check();
169
-
170
- const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
171
- try {
172
- const resultSet = await statement.executeQuery(transaction, parameters, options && options.executeOptions);
173
- resultSet.diposeStatementOnClose = true;
174
- return resultSet;
175
- }
176
- catch (e) {
177
- await statement.dispose();
178
- throw e;
179
- }
180
- }
181
-
182
- async queueEvents(names: string[], callBack: (counters: [string, number][]) => Promise<void>): Promise<Events> {
183
- this.check();
184
-
185
- const trimmedNames = names.map(name => {
186
- const trimmedName = name.trimRight();
187
-
188
- if (Buffer.from(trimmedName).byteLength > 255)
189
- throw new Error(`Invalid event name: ${name}.`);
190
-
191
- return trimmedName;
192
- });
193
-
194
- const events = await this.internalQueueEvents(trimmedNames, callBack);
195
- this.events.add(events);
196
-
197
- return events;
198
- }
199
-
200
- async createBlob(transaction: AbstractTransaction, options?: CreateBlobOptions): Promise<AbstractBlobStream> {
201
- return await this.internalCreateBlob(transaction, options);
202
- }
203
-
204
- async openBlob(transaction: AbstractTransaction, blob: Blob): Promise<AbstractBlobStream> {
205
- return await this.internalOpenBlob(transaction, blob);
206
- }
207
-
208
- /** Starts a new transaction. */
209
- async startTransaction(options?: TransactionOptions): Promise<AbstractTransaction> {
210
- this.check();
211
-
212
- const transaction = await this.internalStartTransaction(
213
- options || this.defaultTransactionOptions || this.client!.defaultTransactionOptions);
214
- this.transactions.add(transaction);
215
- return transaction;
216
- }
217
-
218
- /** Prepares a query. */
219
- async prepare(transaction: AbstractTransaction, sqlStmt: string, options?: PrepareOptions): Promise<AbstractStatement> {
220
- this.check();
221
-
222
- const statement = await this.internalPrepare(transaction, sqlStmt,
223
- options || this.defaultPrepareOptions || this.client!.defaultPrepareOptions);
224
- this.statements.add(statement);
225
- return statement;
226
- }
227
-
228
- get isValid(): boolean {
229
- return !!this.client;
230
- }
231
-
232
- private check() {
233
- if (!this.isValid)
234
- throw new Error('Attachment is already disconnected.');
235
- }
236
-
237
- private async preDispose() {
238
- try {
239
- await Promise.all(Array.from(this.events).map(events => events.cancel()));
240
- await Promise.all(Array.from(this.statements).map(statement => statement.dispose()));
241
- await Promise.all(Array.from(this.transactions).map(transaction => transaction.rollback()));
242
- }
243
- finally {
244
- this.events.clear();
245
- this.statements.clear();
246
- this.transactions.clear();
247
- }
248
- }
249
-
250
- private async postDispose() {
251
- this.client!.attachments.delete(this);
252
- this.client = undefined;
253
- }
254
-
255
- protected abstract internalDisconnect(): Promise<void>;
256
- protected abstract internalDropDatabase(): Promise<void>;
257
- protected abstract internalEnableCancellation(enable: boolean): Promise<void>;
258
- protected abstract internalCancelOperation(forcibleAbort: boolean): Promise<void>;
259
- protected abstract internalCreateBlob(transaction: AbstractTransaction, options?: CreateBlobOptions): Promise<AbstractBlobStream>;
260
- protected abstract internalOpenBlob(transaction: AbstractTransaction, blob: Blob): Promise<AbstractBlobStream>;
261
- protected abstract internalPrepare(transaction: AbstractTransaction, sqlStmt: string, options?: PrepareOptions):
262
- Promise<AbstractStatement>;
263
- protected abstract internalStartTransaction(options?: TransactionOptions): Promise<AbstractTransaction>;
264
- protected abstract internalQueueEvents(names: string[], callBack: (counters: [string, number][]) => Promise<void>):
265
- Promise<AbstractEvents>;
22
+ events = new Set<Events>();
23
+ statements = new Set<AbstractStatement>();
24
+ transactions = new Set<AbstractTransaction>();
25
+
26
+ /** Default transaction options. */
27
+ defaultTransactionOptions: TransactionOptions;
28
+
29
+ /** Default query's prepare options. */
30
+ defaultPrepareOptions: PrepareOptions;
31
+
32
+ /** Default query's execute options. */
33
+ defaultExecuteOptions: ExecuteOptions;
34
+
35
+ /** Default query's executeQuery options. */
36
+ defaultExecuteQueryOptions: ExecuteQueryOptions;
37
+
38
+ /** Default result set's fetch options. */
39
+ defaultFetchOptions: FetchOptions;
40
+
41
+ protected constructor(public client?: AbstractClient) {}
42
+
43
+ /** Disconnects this attachment. */
44
+ async disconnect(): Promise<void> {
45
+ this.check();
46
+
47
+ await this.preDispose();
48
+ await this.internalDisconnect();
49
+ await this.postDispose();
50
+ }
51
+
52
+ /** Drops the database and release this attachment. */
53
+ async dropDatabase(): Promise<void> {
54
+ this.check();
55
+
56
+ await this.preDispose();
57
+ await this.internalDropDatabase();
58
+ await this.postDispose();
59
+ }
60
+
61
+ /** Enable/disable cancellation of operations in this attachment. */
62
+ async enableCancellation(enable: boolean): Promise<void> {
63
+ this.check();
64
+ await this.internalEnableCancellation(enable);
65
+ }
66
+
67
+ /** Cancel a running operation in this attachment. */
68
+ async cancelOperation(forcibleAbort?: boolean): Promise<void> {
69
+ this.check();
70
+ await this.internalCancelOperation(forcibleAbort ?? false);
71
+ }
72
+
73
+ /** Executes a statement that uses the SET TRANSACTION command. Returns the new transaction. */
74
+ async executeTransaction(
75
+ transaction: AbstractTransaction,
76
+ sqlStmt: string,
77
+ options?: {
78
+ prepareOptions?: PrepareOptions;
79
+ },
80
+ ): Promise<AbstractTransaction> {
81
+ this.check();
82
+
83
+ const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
84
+ try {
85
+ const newTransaction = await statement.executeTransaction(transaction);
86
+ this.transactions.add(newTransaction);
87
+ return newTransaction;
88
+ } finally {
89
+ await statement.dispose();
90
+ }
91
+ }
92
+
93
+ /** Executes a statement that has no result set. */
94
+ async execute(
95
+ transaction: AbstractTransaction,
96
+ sqlStmt: string,
97
+ parameters?: any[],
98
+ options?: {
99
+ prepareOptions?: PrepareOptions;
100
+ executeOptions?: ExecuteOptions;
101
+ },
102
+ ): Promise<void> {
103
+ this.check();
104
+
105
+ const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
106
+ try {
107
+ return await statement.execute(transaction, parameters, options && options.executeOptions);
108
+ } finally {
109
+ await statement.dispose();
110
+ }
111
+ }
112
+
113
+ /** Executes a statement that returns a single record. */
114
+ async executeSingleton(
115
+ transaction: AbstractTransaction,
116
+ sqlStmt: string,
117
+ parameters?: any[],
118
+ options?: {
119
+ prepareOptions?: PrepareOptions;
120
+ executeOptions?: ExecuteOptions;
121
+ },
122
+ ): Promise<any[]> {
123
+ this.check();
124
+
125
+ const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
126
+ try {
127
+ return await statement.executeSingleton(transaction, parameters, options && options.executeOptions);
128
+ } finally {
129
+ await statement.dispose();
130
+ }
131
+ }
132
+
133
+ /** Executes a statement that returns a single record in object form. */
134
+ async executeSingletonAsObject<T extends object>(
135
+ transaction: AbstractTransaction,
136
+ sqlStmt: string,
137
+ parameters?: any[],
138
+ options?: {
139
+ prepareOptions?: PrepareOptions;
140
+ executeOptions?: ExecuteOptions;
141
+ },
142
+ ): Promise<T> {
143
+ this.check();
144
+
145
+ const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
146
+ try {
147
+ return await statement.executeSingletonAsObject(transaction, parameters, options && options.executeOptions);
148
+ } finally {
149
+ await statement.dispose();
150
+ }
151
+ }
152
+
153
+ /** Executes a statement that returns a single record. */
154
+ async executeReturning(
155
+ transaction: AbstractTransaction,
156
+ sqlStmt: string,
157
+ parameters?: any[],
158
+ options?: {
159
+ prepareOptions?: PrepareOptions;
160
+ executeOptions?: ExecuteOptions;
161
+ },
162
+ ): Promise<any[]> {
163
+ return await this.executeSingleton(transaction, sqlStmt, parameters, options);
164
+ }
165
+
166
+ /** Executes a statement that returns a single record in object form. */
167
+ async executeReturningAsObject<T extends object>(
168
+ transaction: AbstractTransaction,
169
+ sqlStmt: string,
170
+ parameters?: any[],
171
+ options?: {
172
+ prepareOptions?: PrepareOptions;
173
+ executeOptions?: ExecuteOptions;
174
+ },
175
+ ): Promise<T> {
176
+ return await this.executeSingletonAsObject<T>(transaction, sqlStmt, parameters, options);
177
+ }
178
+
179
+ /** Executes a statement that has result set. */
180
+ async executeQuery(
181
+ transaction: AbstractTransaction,
182
+ sqlStmt: string,
183
+ parameters?: any[],
184
+ options?: {
185
+ prepareOptions?: PrepareOptions;
186
+ executeOptions?: ExecuteQueryOptions;
187
+ },
188
+ ): Promise<AbstractResultSet> {
189
+ this.check();
190
+
191
+ const statement = await this.prepare(transaction, sqlStmt, options && options.prepareOptions);
192
+ try {
193
+ const resultSet = await statement.executeQuery(transaction, parameters, options && options.executeOptions);
194
+ resultSet.diposeStatementOnClose = true;
195
+ return resultSet;
196
+ } catch (e) {
197
+ await statement.dispose();
198
+ throw e;
199
+ }
200
+ }
201
+
202
+ async queueEvents(names: string[], callBack: (counters: [string, number][]) => Promise<void>): Promise<Events> {
203
+ this.check();
204
+
205
+ const trimmedNames = names.map((name) => {
206
+ const trimmedName = name.trimRight();
207
+
208
+ if (Buffer.from(trimmedName).byteLength > 255) {
209
+ throw new Error(`Invalid event name: ${name}.`);
210
+ }
211
+
212
+ return trimmedName;
213
+ });
214
+
215
+ const events = await this.internalQueueEvents(trimmedNames, callBack);
216
+ this.events.add(events);
217
+
218
+ return events;
219
+ }
220
+
221
+ async createBlob(transaction: AbstractTransaction, options?: CreateBlobOptions): Promise<AbstractBlobStream> {
222
+ return await this.internalCreateBlob(transaction, options);
223
+ }
224
+
225
+ async openBlob(transaction: AbstractTransaction, blob: Blob): Promise<AbstractBlobStream> {
226
+ return await this.internalOpenBlob(transaction, blob);
227
+ }
228
+
229
+ /** Starts a new transaction. */
230
+ async startTransaction(options?: TransactionOptions): Promise<AbstractTransaction> {
231
+ this.check();
232
+
233
+ const transaction = await this.internalStartTransaction(
234
+ options || this.defaultTransactionOptions || this.client!.defaultTransactionOptions,
235
+ );
236
+ this.transactions.add(transaction);
237
+ return transaction;
238
+ }
239
+
240
+ /** Prepares a query. */
241
+ async prepare(
242
+ transaction: AbstractTransaction,
243
+ sqlStmt: string,
244
+ options?: PrepareOptions,
245
+ ): Promise<AbstractStatement> {
246
+ this.check();
247
+
248
+ const statement = await this.internalPrepare(
249
+ transaction,
250
+ sqlStmt,
251
+ options || this.defaultPrepareOptions || this.client!.defaultPrepareOptions,
252
+ );
253
+ this.statements.add(statement);
254
+ return statement;
255
+ }
256
+
257
+ get isValid(): boolean {
258
+ return !!this.client;
259
+ }
260
+
261
+ private check() {
262
+ if (!this.isValid) {
263
+ throw new Error('Attachment is already disconnected.');
264
+ }
265
+ }
266
+
267
+ private async preDispose() {
268
+ try {
269
+ await Promise.all(Array.from(this.events).map((events) => events.cancel()));
270
+ await Promise.all(Array.from(this.statements).map((statement) => statement.dispose()));
271
+ await Promise.all(Array.from(this.transactions).map((transaction) => transaction.rollback()));
272
+ } finally {
273
+ this.events.clear();
274
+ this.statements.clear();
275
+ this.transactions.clear();
276
+ }
277
+ }
278
+
279
+ private async postDispose() {
280
+ this.client!.attachments.delete(this);
281
+ this.client = undefined;
282
+ }
283
+
284
+ protected abstract internalDisconnect(): Promise<void>;
285
+ protected abstract internalDropDatabase(): Promise<void>;
286
+ protected abstract internalEnableCancellation(enable: boolean): Promise<void>;
287
+ protected abstract internalCancelOperation(forcibleAbort: boolean): Promise<void>;
288
+ protected abstract internalCreateBlob(
289
+ transaction: AbstractTransaction,
290
+ options?: CreateBlobOptions,
291
+ ): Promise<AbstractBlobStream>;
292
+ protected abstract internalOpenBlob(transaction: AbstractTransaction, blob: Blob): Promise<AbstractBlobStream>;
293
+ protected abstract internalPrepare(
294
+ transaction: AbstractTransaction,
295
+ sqlStmt: string,
296
+ options?: PrepareOptions,
297
+ ): Promise<AbstractStatement>;
298
+ protected abstract internalStartTransaction(options?: TransactionOptions): Promise<AbstractTransaction>;
299
+ protected abstract internalQueueEvents(
300
+ names: string[],
301
+ callBack: (counters: [string, number][]) => Promise<void>,
302
+ ): Promise<AbstractEvents>;
266
303
  }