node-firebird 2.9.0 → 2.10.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.
- package/README.md +166 -6
- package/lib/index.d.ts +5 -0
- package/lib/index.js +32 -1
- package/lib/pool.js +1 -1
- package/lib/srp.d.ts +3 -3
- package/lib/types.d.ts +143 -5
- package/lib/uri.js +2 -2
- package/lib/wire/connection.d.ts +92 -59
- package/lib/wire/connection.js +267 -53
- package/lib/wire/const.d.ts +9 -1
- package/lib/wire/const.js +21 -9
- package/lib/wire/database.d.ts +51 -26
- package/lib/wire/database.js +26 -8
- package/lib/wire/eventConnection.js +5 -3
- package/lib/wire/query-stream.d.ts +18 -0
- package/lib/wire/query-stream.js +73 -0
- package/lib/wire/serialize.d.ts +18 -2
- package/lib/wire/serialize.js +7 -0
- package/lib/wire/service.d.ts +42 -0
- package/lib/wire/service.js +145 -0
- package/lib/wire/socket.d.ts +3 -1
- package/lib/wire/socket.js +5 -2
- package/lib/wire/statement.d.ts +31 -19
- package/lib/wire/statement.js +1 -5
- package/lib/wire/transaction.d.ts +30 -18
- package/lib/wire/transaction.js +23 -4
- package/lib/wire/wire-types.d.ts +116 -0
- package/lib/wire/wire-types.js +10 -0
- package/lib/wire/xsqlvar.d.ts +18 -18
- package/package.json +1 -1
- package/src/index.ts +36 -4
- package/src/messages.ts +1 -1
- package/src/pool.ts +1 -1
- package/src/srp.ts +6 -6
- package/src/types.ts +140 -5
- package/src/unix-crypt.ts +9 -9
- package/src/uri.ts +2 -2
- package/src/wire/connection.ts +464 -232
- package/src/wire/const.ts +21 -9
- package/src/wire/database.ts +75 -43
- package/src/wire/eventConnection.ts +8 -5
- package/src/wire/query-stream.ts +80 -0
- package/src/wire/serialize.ts +29 -0
- package/src/wire/service.ts +188 -6
- package/src/wire/socket.ts +17 -8
- package/src/wire/statement.ts +37 -29
- package/src/wire/transaction.ts +57 -32
- package/src/wire/wire-types.ts +127 -0
- package/src/wire/xsqlvar.ts +9 -7
package/lib/wire/statement.d.ts
CHANGED
|
@@ -3,13 +3,21 @@
|
|
|
3
3
|
* Statement
|
|
4
4
|
*
|
|
5
5
|
***************************************/
|
|
6
|
+
import { type Callback, type SimpleCallback } from '../callback';
|
|
7
|
+
import type Connection from './connection';
|
|
8
|
+
import type Transaction from './transaction';
|
|
9
|
+
import type { SQLVarBase } from './xsqlvar';
|
|
10
|
+
import type { QueryOptions, QueryParams } from '../types';
|
|
6
11
|
declare class Statement {
|
|
7
|
-
connection:
|
|
12
|
+
connection: Connection;
|
|
8
13
|
query: string;
|
|
9
14
|
type: number;
|
|
10
|
-
output:
|
|
11
|
-
input:
|
|
12
|
-
options
|
|
15
|
+
output: SQLVarBase[];
|
|
16
|
+
input: SQLVarBase[];
|
|
17
|
+
/** per-execute query options (asObject/asStream/timeout/...) */
|
|
18
|
+
options: (QueryOptions & {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}) | undefined;
|
|
13
21
|
handle: number;
|
|
14
22
|
plan: string;
|
|
15
23
|
/**
|
|
@@ -18,27 +26,31 @@ declare class Statement {
|
|
|
18
26
|
* null/undefined otherwise. Set by Transaction.newStatement.
|
|
19
27
|
*/
|
|
20
28
|
namedParams?: string[] | null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
/** set when an execute/fetch on this statement errored — the statement
|
|
30
|
+
* is dropped on release instead of going back into the cache */
|
|
31
|
+
_failed?: boolean;
|
|
32
|
+
/** rows fetched so far by the current cursor (decodeResponse) */
|
|
33
|
+
nbrowsfetched?: number;
|
|
34
|
+
constructor(connection: Connection);
|
|
35
|
+
close(callback?: SimpleCallback): void;
|
|
36
|
+
drop(callback?: SimpleCallback): void;
|
|
37
|
+
release(callback?: SimpleCallback): void;
|
|
38
|
+
execute(transaction: Transaction, params?: any, callback?: any, options?: any): void;
|
|
39
|
+
fetch(transaction: Transaction, count: number | string, callback: Callback): void;
|
|
40
|
+
fetchScroll(transaction: Transaction, direction: string | number, offset?: any, count?: any, callback?: any): void;
|
|
41
|
+
fetchAll(transaction: Transaction, callback: Callback): void;
|
|
30
42
|
/**
|
|
31
43
|
* Execute this statement once per row via the Firebird 4 batch API
|
|
32
44
|
* (protocol 16+). `rows` is an array of parameter arrays — or, when the
|
|
33
45
|
* statement was prepared with named placeholders, of values-by-name
|
|
34
46
|
* objects (the two forms can be mixed).
|
|
35
47
|
*/
|
|
36
|
-
executeBatch(transaction:
|
|
37
|
-
executeAsync(transaction:
|
|
38
|
-
executeBatchAsync(transaction:
|
|
39
|
-
fetchAsync(transaction:
|
|
40
|
-
fetchScrollAsync(transaction:
|
|
41
|
-
fetchAllAsync(transaction:
|
|
48
|
+
executeBatch(transaction: Transaction, rows: QueryParams[], callback?: any, options?: any): void;
|
|
49
|
+
executeAsync(transaction: Transaction, params?: any, options?: any): Promise<any>;
|
|
50
|
+
executeBatchAsync(transaction: Transaction, rows: QueryParams[], options?: any): Promise<any>;
|
|
51
|
+
fetchAsync(transaction: Transaction, count: number | string): Promise<any>;
|
|
52
|
+
fetchScrollAsync(transaction: Transaction, direction: string | number, offset?: any, count?: any): Promise<any>;
|
|
53
|
+
fetchAllAsync(transaction: Transaction): Promise<any>;
|
|
42
54
|
closeAsync(): Promise<void>;
|
|
43
55
|
dropAsync(): Promise<void>;
|
|
44
56
|
releaseAsync(): Promise<void>;
|
package/lib/wire/statement.js
CHANGED
|
@@ -17,11 +17,7 @@ class Statement {
|
|
|
17
17
|
this.connection.dropStatement(this, callback);
|
|
18
18
|
}
|
|
19
19
|
release(callback) {
|
|
20
|
-
|
|
21
|
-
if (cache_query)
|
|
22
|
-
this.connection.closeStatement(this, callback);
|
|
23
|
-
else
|
|
24
|
-
this.connection.dropStatement(this, callback);
|
|
20
|
+
this.connection.releaseStatement(this, callback);
|
|
25
21
|
}
|
|
26
22
|
execute(transaction, params, callback, options) {
|
|
27
23
|
if (params instanceof Function) {
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import { type Callback, type SimpleCallback } from '../callback';
|
|
2
|
+
import type Connection from './connection';
|
|
3
|
+
import type Database from './database';
|
|
4
|
+
import type Statement from './statement';
|
|
5
|
+
import type { BatchCb, StatementCb, InternalQueryOptions } from './wire-types';
|
|
6
|
+
import type { BatchOptions, BatchResult, QueryOptions, QueryParams, QueryStreamOptions, SequentialCallback } from '../types';
|
|
1
7
|
declare class Transaction {
|
|
2
|
-
connection:
|
|
3
|
-
db:
|
|
8
|
+
connection: Connection;
|
|
9
|
+
db: Database;
|
|
4
10
|
handle: number;
|
|
5
|
-
|
|
6
|
-
constructor(connection: any);
|
|
11
|
+
constructor(connection: Connection);
|
|
7
12
|
/** Per-call options.namedPlaceholders overrides the connection option. */
|
|
8
13
|
private namedPlaceholdersEnabled;
|
|
9
|
-
newStatement(query: string, callback:
|
|
10
|
-
execute(query: string, params?:
|
|
11
|
-
sequentially(query: string, params?: any, on?: any, callback?: any, options?:
|
|
12
|
-
|
|
14
|
+
newStatement(query: string, callback: StatementCb, options?: InternalQueryOptions): void;
|
|
15
|
+
execute(query: string, params?: QueryParams | Callback, callback?: any, options?: InternalQueryOptions): void;
|
|
16
|
+
sequentially(query: string, params?: any, on?: any, callback?: any, options?: InternalQueryOptions | boolean): this;
|
|
17
|
+
/**
|
|
18
|
+
* Run `query` inside this transaction and return an object-mode
|
|
19
|
+
* Readable emitting one row per chunk, with real backpressure (see
|
|
20
|
+
* Database.queryStream). The transaction is NOT committed when the
|
|
21
|
+
* stream ends — commit or roll back yourself.
|
|
22
|
+
*/
|
|
23
|
+
queryStream(query: string, params?: QueryParams, options?: QueryStreamOptions): import("node:stream").Readable;
|
|
24
|
+
query(query: string, params?: QueryParams | Callback, callback?: any, options?: InternalQueryOptions): void;
|
|
13
25
|
/**
|
|
14
26
|
* Execute `query` once per row in `rows` using the Firebird 4 batch API
|
|
15
27
|
* (protocol 16+, single network flush). The callback receives a
|
|
@@ -19,16 +31,16 @@ declare class Transaction {
|
|
|
19
31
|
* commit or roll back yourself (or use db.executeBatch for
|
|
20
32
|
* all-or-nothing semantics).
|
|
21
33
|
*/
|
|
22
|
-
executeBatch(query: string, rows:
|
|
23
|
-
executeBatchAsync(query: string, rows:
|
|
24
|
-
commit(callback?:
|
|
25
|
-
rollback(callback?:
|
|
26
|
-
commitRetaining(callback?:
|
|
27
|
-
rollbackRetaining(callback?:
|
|
28
|
-
queryAsync(query: string, params?:
|
|
29
|
-
executeAsync(query: string, params?:
|
|
30
|
-
sequentiallyAsync(query: string, params?: any, on?:
|
|
31
|
-
newStatementAsync(query: string): Promise<
|
|
34
|
+
executeBatch(query: string, rows: QueryParams[], callback?: BatchCb, options?: BatchOptions & QueryOptions): void;
|
|
35
|
+
executeBatchAsync(query: string, rows: QueryParams[], options?: BatchOptions & QueryOptions): Promise<BatchResult>;
|
|
36
|
+
commit(callback?: SimpleCallback): void;
|
|
37
|
+
rollback(callback?: SimpleCallback): void;
|
|
38
|
+
commitRetaining(callback?: SimpleCallback): void;
|
|
39
|
+
rollbackRetaining(callback?: SimpleCallback): void;
|
|
40
|
+
queryAsync(query: string, params?: QueryParams, options?: InternalQueryOptions): Promise<any[]>;
|
|
41
|
+
executeAsync(query: string, params?: QueryParams, options?: InternalQueryOptions): Promise<any[]>;
|
|
42
|
+
sequentiallyAsync(query: string, params?: any, on?: SequentialCallback, options?: InternalQueryOptions | boolean): Promise<void>;
|
|
43
|
+
newStatementAsync(query: string): Promise<Statement>;
|
|
32
44
|
commitAsync(): Promise<void>;
|
|
33
45
|
rollbackAsync(): Promise<void>;
|
|
34
46
|
commitRetainingAsync(): Promise<void>;
|
package/lib/wire/transaction.js
CHANGED
|
@@ -6,6 +6,7 @@ const callback_1 = require("../callback");
|
|
|
6
6
|
const named_params_1 = require("../named-params");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const const_1 = __importDefault(require("./const"));
|
|
9
|
+
const query_stream_1 = __importDefault(require("./query-stream"));
|
|
9
10
|
/***************************************
|
|
10
11
|
*
|
|
11
12
|
* Transaction
|
|
@@ -55,6 +56,9 @@ class Transaction {
|
|
|
55
56
|
newStatement(query, callback, options) {
|
|
56
57
|
var cnx = this.connection;
|
|
57
58
|
var self = this;
|
|
59
|
+
// the public strict callback shape and the internal optional-args
|
|
60
|
+
// shape only differ in optionality; treat it as the internal one
|
|
61
|
+
var cb = callback;
|
|
58
62
|
// With namedPlaceholders on, prepare the positional rewrite and
|
|
59
63
|
// remember the name order on the statement so statement.execute can
|
|
60
64
|
// accept a values-by-name object. The rewritten SQL is the cache key.
|
|
@@ -69,9 +73,9 @@ class Transaction {
|
|
|
69
73
|
var deliver = function (err, statement) {
|
|
70
74
|
if (statement)
|
|
71
75
|
statement.namedParams = names;
|
|
72
|
-
|
|
76
|
+
cb(err, statement);
|
|
73
77
|
};
|
|
74
|
-
var query_cache = cnx.
|
|
78
|
+
var query_cache = cnx.takeCachedStatement(query);
|
|
75
79
|
if (query_cache) {
|
|
76
80
|
deliver(null, query_cache);
|
|
77
81
|
}
|
|
@@ -95,11 +99,15 @@ class Transaction {
|
|
|
95
99
|
}
|
|
96
100
|
var self = this;
|
|
97
101
|
this.newStatement(query, function (err, statement) {
|
|
98
|
-
if (err) {
|
|
102
|
+
if (err || !statement) {
|
|
99
103
|
(0, callback_1.doError)(err, callback);
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
102
106
|
function dropError(err) {
|
|
107
|
+
// do not put a statement that just failed back into the cache
|
|
108
|
+
// (statement is guaranteed by the guard above; hoisting keeps
|
|
109
|
+
// the narrowing from reaching this function declaration)
|
|
110
|
+
statement._failed = true;
|
|
103
111
|
statement.release();
|
|
104
112
|
(0, callback_1.doCallback)(err, callback);
|
|
105
113
|
}
|
|
@@ -209,6 +217,15 @@ class Transaction {
|
|
|
209
217
|
self.execute(query, params, callback, options);
|
|
210
218
|
return self;
|
|
211
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Run `query` inside this transaction and return an object-mode
|
|
222
|
+
* Readable emitting one row per chunk, with real backpressure (see
|
|
223
|
+
* Database.queryStream). The transaction is NOT committed when the
|
|
224
|
+
* stream ends — commit or roll back yourself.
|
|
225
|
+
*/
|
|
226
|
+
queryStream(query, params, options) {
|
|
227
|
+
return (0, query_stream_1.default)(this, query, params, options);
|
|
228
|
+
}
|
|
212
229
|
query(query, params, callback, options = {}) {
|
|
213
230
|
if (params instanceof Function) {
|
|
214
231
|
callback = params;
|
|
@@ -235,11 +252,13 @@ class Transaction {
|
|
|
235
252
|
executeBatch(query, rows, callback, options) {
|
|
236
253
|
var self = this;
|
|
237
254
|
this.newStatement(query, function (err, statement) {
|
|
238
|
-
if (err) {
|
|
255
|
+
if (err || !statement) {
|
|
239
256
|
(0, callback_1.doError)(err, callback);
|
|
240
257
|
return;
|
|
241
258
|
}
|
|
242
259
|
statement.executeBatch(self, rows, function (err, result) {
|
|
260
|
+
if (err)
|
|
261
|
+
statement._failed = true;
|
|
243
262
|
statement.release();
|
|
244
263
|
if (callback)
|
|
245
264
|
callback(err, result);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/***************************************
|
|
2
|
+
*
|
|
3
|
+
* Internal wire-protocol types (type-only module)
|
|
4
|
+
*
|
|
5
|
+
* Shared vocabulary for the wire core (connection/statement/transaction/
|
|
6
|
+
* database). Nothing here exists at runtime.
|
|
7
|
+
*
|
|
8
|
+
***************************************/
|
|
9
|
+
import type { Callback, FbStatusItem } from '../callback';
|
|
10
|
+
import type Statement from './statement';
|
|
11
|
+
import type { BatchResult, Options, QueryOptions, Statement as PublicStatement } from '../types';
|
|
12
|
+
/**
|
|
13
|
+
* One entry of the connection's response queue (`connection._queue`).
|
|
14
|
+
* The function itself is the user/driver callback; the extra properties
|
|
15
|
+
* steer decodeResponse:
|
|
16
|
+
*
|
|
17
|
+
* - `response` — pre-allocated object the op_response decode fills in
|
|
18
|
+
* (a Statement, Transaction, or plain response object).
|
|
19
|
+
* - `statement` — statement whose `output` describes the rows of an
|
|
20
|
+
* op_fetch_response / op_sql_response.
|
|
21
|
+
* - `lazy_count`— number of chained lazy op_responses this entry consumes
|
|
22
|
+
* (ptype_lazy_send batches e.g. allocate+prepare).
|
|
23
|
+
*
|
|
24
|
+
* Deferred ops (op_free_statement, op_close_blob, ...) push `undefined`
|
|
25
|
+
* placeholders so every server response still pairs with one entry.
|
|
26
|
+
*/
|
|
27
|
+
export interface QueueCallback {
|
|
28
|
+
(err?: any, obj?: any): void;
|
|
29
|
+
response?: any;
|
|
30
|
+
statement?: Statement;
|
|
31
|
+
lazy_count?: number;
|
|
32
|
+
}
|
|
33
|
+
/** A queue entry: a callback, or a placeholder for a deferred op. */
|
|
34
|
+
export type QueueEntry = QueueCallback | undefined;
|
|
35
|
+
/** XDR quad — 64-bit value as two 32-bit halves (blob ids, object ids). */
|
|
36
|
+
export interface Quad {
|
|
37
|
+
high: number;
|
|
38
|
+
low: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decoded op_response packet (see parseOpResponse): object handle, object
|
|
42
|
+
* id, optional info buffer and, on failure, the status vector. Statement /
|
|
43
|
+
* Transaction responses are these fields merged onto the pre-allocated
|
|
44
|
+
* object from QueueCallback.response.
|
|
45
|
+
*/
|
|
46
|
+
export interface WireResponse {
|
|
47
|
+
handle?: number;
|
|
48
|
+
oid?: Quad;
|
|
49
|
+
buffer?: Buffer;
|
|
50
|
+
status?: FbStatusItem[];
|
|
51
|
+
/** isc_arg_warning entries — attached to a SUCCESSFUL response */
|
|
52
|
+
warnings?: FbStatusItem[];
|
|
53
|
+
sqlcode?: number;
|
|
54
|
+
message?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Result of decoding op_fetch_response / op_sql_response row data. */
|
|
57
|
+
export interface FetchResult {
|
|
58
|
+
data: any[];
|
|
59
|
+
/** true when the cursor is exhausted (fetch status 100 / singleton). */
|
|
60
|
+
fetched: boolean;
|
|
61
|
+
/** pending blobAsText fetches to resolve before delivering rows. */
|
|
62
|
+
arrBlob?: any[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Protocol negotiation result decoded from op_accept / op_cond_accept /
|
|
66
|
+
* op_accept_data, plus the auth/crypt state accumulated during the
|
|
67
|
+
* handshake (op_cont_auth rounds, wire-crypt keys).
|
|
68
|
+
*/
|
|
69
|
+
export interface AcceptPacket {
|
|
70
|
+
protocolVersion: number;
|
|
71
|
+
protocolArchitecture: number;
|
|
72
|
+
protocolMinimumType: number;
|
|
73
|
+
compress: boolean;
|
|
74
|
+
pluginName: string;
|
|
75
|
+
authData: any;
|
|
76
|
+
sessionKey?: any;
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Query options as the wire core sees them: the public QueryOptions plus
|
|
81
|
+
* the internal row-delivery flags set by the Database/Transaction helpers
|
|
82
|
+
* (query / sequentially / queryStream).
|
|
83
|
+
*/
|
|
84
|
+
export type InternalQueryOptions = QueryOptions & {
|
|
85
|
+
/** deliver rows as objects keyed by column alias */
|
|
86
|
+
asObject?: boolean;
|
|
87
|
+
/** deliver rows one by one (row events / `on` delegate) instead of accumulating */
|
|
88
|
+
asStream?: boolean;
|
|
89
|
+
/** per-row delegate installed by sequentially() */
|
|
90
|
+
on?: (row: any, index: number, meta: any[], next: (err?: any) => void) => void;
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* newStatement callback: the internal optional-args shape, or the public
|
|
95
|
+
* strict shape (non-optional statement) declared in types.ts.
|
|
96
|
+
*/
|
|
97
|
+
export type StatementCb = Callback<Statement> | ((err: Error | null, statement: PublicStatement) => void);
|
|
98
|
+
/**
|
|
99
|
+
* executeBatch callback: the internal optional-args shape, or the public
|
|
100
|
+
* strict shape (non-optional result) declared in types.ts.
|
|
101
|
+
*/
|
|
102
|
+
export type BatchCb = Callback<BatchResult> | ((err: any, result: BatchResult) => void);
|
|
103
|
+
/**
|
|
104
|
+
* Connection options as the wire core sees them: the public Options plus
|
|
105
|
+
* internal flags set by the driver itself.
|
|
106
|
+
*/
|
|
107
|
+
export type InternalOptions = Options & {
|
|
108
|
+
/** set by the pool so detach() returns the connection instead */
|
|
109
|
+
isPool?: boolean;
|
|
110
|
+
/** override path of the firebird.msg error-message file */
|
|
111
|
+
messageFile?: string;
|
|
112
|
+
/** legacy statement-cache flags (mapped onto statementCacheSize) */
|
|
113
|
+
cacheQuery?: boolean;
|
|
114
|
+
maxCachedQuery?: number;
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/***************************************
|
|
3
|
+
*
|
|
4
|
+
* Internal wire-protocol types (type-only module)
|
|
5
|
+
*
|
|
6
|
+
* Shared vocabulary for the wire core (connection/statement/transaction/
|
|
7
|
+
* database). Nothing here exists at runtime.
|
|
8
|
+
*
|
|
9
|
+
***************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/wire/xsqlvar.d.ts
CHANGED
|
@@ -22,20 +22,20 @@ export declare abstract class SQLVarBase {
|
|
|
22
22
|
abstract calcBlr(blr: BlrWriter): void;
|
|
23
23
|
}
|
|
24
24
|
export declare class SQLVarText extends SQLVarBase {
|
|
25
|
-
decode(data: XdrReader, lowerV13: boolean, options?: any):
|
|
25
|
+
decode(data: XdrReader, lowerV13: boolean, options?: any): string | Buffer<ArrayBufferLike> | null | undefined;
|
|
26
26
|
calcBlr(blr: BlrWriter): void;
|
|
27
27
|
}
|
|
28
28
|
export declare class SQLVarNull extends SQLVarText {
|
|
29
29
|
}
|
|
30
30
|
export declare class SQLVarString extends SQLVarBase {
|
|
31
|
-
decode(data: XdrReader, lowerV13: boolean, options?: any):
|
|
31
|
+
decode(data: XdrReader, lowerV13: boolean, options?: any): string | Buffer<ArrayBufferLike> | null | undefined;
|
|
32
32
|
calcBlr(blr: BlrWriter): void;
|
|
33
33
|
}
|
|
34
34
|
export declare class SQLVarQuad extends SQLVarBase {
|
|
35
35
|
decode(data: XdrReader, lowerV13: boolean): {
|
|
36
36
|
low: number;
|
|
37
37
|
high: number;
|
|
38
|
-
};
|
|
38
|
+
} | null;
|
|
39
39
|
calcBlr(blr: BlrWriter): void;
|
|
40
40
|
}
|
|
41
41
|
export declare class SQLVarBlob extends SQLVarQuad {
|
|
@@ -45,66 +45,66 @@ export declare class SQLVarArray extends SQLVarQuad {
|
|
|
45
45
|
calcBlr(blr: BlrWriter): void;
|
|
46
46
|
}
|
|
47
47
|
export declare class SQLVarInt extends SQLVarBase {
|
|
48
|
-
decode(data: XdrReader, lowerV13: boolean): number;
|
|
48
|
+
decode(data: XdrReader, lowerV13: boolean): number | null;
|
|
49
49
|
calcBlr(blr: BlrWriter): void;
|
|
50
50
|
}
|
|
51
51
|
export declare class SQLVarShort extends SQLVarInt {
|
|
52
52
|
calcBlr(blr: BlrWriter): void;
|
|
53
53
|
}
|
|
54
54
|
export declare class SQLVarInt64 extends SQLVarBase {
|
|
55
|
-
decode(data: XdrReader, lowerV13: boolean): number;
|
|
55
|
+
decode(data: XdrReader, lowerV13: boolean): number | null;
|
|
56
56
|
calcBlr(blr: BlrWriter): void;
|
|
57
57
|
}
|
|
58
58
|
export declare class SQLVarInt128 extends SQLVarBase {
|
|
59
|
-
decode(data: XdrReader, lowerV13: boolean): string | number;
|
|
59
|
+
decode(data: XdrReader, lowerV13: boolean): string | number | null;
|
|
60
60
|
calcBlr(blr: BlrWriter): void;
|
|
61
61
|
}
|
|
62
62
|
export declare class SQLVarDecFloat16 extends SQLVarBase {
|
|
63
|
-
decode(data: XdrReader, lowerV13: boolean): string | number;
|
|
63
|
+
decode(data: XdrReader, lowerV13: boolean): string | number | null;
|
|
64
64
|
calcBlr(blr: BlrWriter): void;
|
|
65
65
|
}
|
|
66
66
|
export declare class SQLVarDecFloat34 extends SQLVarBase {
|
|
67
|
-
decode(data: XdrReader, lowerV13: boolean): string | number;
|
|
67
|
+
decode(data: XdrReader, lowerV13: boolean): string | number | null;
|
|
68
68
|
calcBlr(blr: BlrWriter): void;
|
|
69
69
|
}
|
|
70
70
|
export declare class SQLVarFloat extends SQLVarBase {
|
|
71
|
-
decode(data: XdrReader, lowerV13: boolean): number;
|
|
71
|
+
decode(data: XdrReader, lowerV13: boolean): number | null;
|
|
72
72
|
calcBlr(blr: BlrWriter): void;
|
|
73
73
|
}
|
|
74
74
|
export declare class SQLVarDouble extends SQLVarBase {
|
|
75
|
-
decode(data: XdrReader, lowerV13: boolean): number;
|
|
75
|
+
decode(data: XdrReader, lowerV13: boolean): number | null;
|
|
76
76
|
calcBlr(blr: BlrWriter): void;
|
|
77
77
|
}
|
|
78
78
|
export declare class SQLVarDate extends SQLVarBase {
|
|
79
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
79
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
80
80
|
calcBlr(blr: BlrWriter): void;
|
|
81
81
|
}
|
|
82
82
|
export declare class SQLVarTime extends SQLVarBase {
|
|
83
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
83
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
84
84
|
calcBlr(blr: BlrWriter): void;
|
|
85
85
|
}
|
|
86
86
|
export declare class SQLVarTimeStamp extends SQLVarBase {
|
|
87
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
87
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
88
88
|
calcBlr(blr: BlrWriter): void;
|
|
89
89
|
}
|
|
90
90
|
export declare class SQLVarTimeTz extends SQLVarBase {
|
|
91
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
91
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
92
92
|
calcBlr(blr: BlrWriter): void;
|
|
93
93
|
}
|
|
94
94
|
export declare class SQLVarTimeTzEx extends SQLVarTimeTz {
|
|
95
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
95
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
96
96
|
calcBlr(blr: BlrWriter): void;
|
|
97
97
|
}
|
|
98
98
|
export declare class SQLVarTimeStampTz extends SQLVarBase {
|
|
99
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
99
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
100
100
|
calcBlr(blr: BlrWriter): void;
|
|
101
101
|
}
|
|
102
102
|
export declare class SQLVarTimeStampTzEx extends SQLVarTimeStampTz {
|
|
103
|
-
decode(data: XdrReader, lowerV13: boolean): Date;
|
|
103
|
+
decode(data: XdrReader, lowerV13: boolean): Date | null;
|
|
104
104
|
calcBlr(blr: BlrWriter): void;
|
|
105
105
|
}
|
|
106
106
|
export declare class SQLVarBoolean extends SQLVarBase {
|
|
107
|
-
decode(data: XdrReader, lowerV13: boolean): boolean;
|
|
107
|
+
decode(data: XdrReader, lowerV13: boolean): boolean | null;
|
|
108
108
|
calcBlr(blr: BlrWriter): void;
|
|
109
109
|
}
|
|
110
110
|
export declare class SQLParamInt {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Const from './wire/const';
|
|
2
|
-
import { doError, doCallback, fromCallback } from './callback';
|
|
2
|
+
import { doError, doCallback, fromCallback, type Callback } from './callback';
|
|
3
3
|
import Connection from './wire/connection';
|
|
4
4
|
import Pool from './pool';
|
|
5
5
|
import { escape as escapeValue } from './utils';
|
|
@@ -48,6 +48,36 @@ export const ISOLATION_READ_COMMITTED_READ_ONLY: number[] = Const.ISOLATION_READ
|
|
|
48
48
|
|
|
49
49
|
export const escape = escapeValue;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Firebird SQL type codes, as seen in `column.type` inside a `typeCast`
|
|
53
|
+
* hook (each code also has a friendly `column.typeName`).
|
|
54
|
+
*/
|
|
55
|
+
export const SQL_TYPES: Readonly<Record<string, number>> = Object.freeze({
|
|
56
|
+
SQL_TEXT: Const.SQL_TEXT,
|
|
57
|
+
SQL_VARYING: Const.SQL_VARYING,
|
|
58
|
+
SQL_SHORT: Const.SQL_SHORT,
|
|
59
|
+
SQL_LONG: Const.SQL_LONG,
|
|
60
|
+
SQL_FLOAT: Const.SQL_FLOAT,
|
|
61
|
+
SQL_DOUBLE: Const.SQL_DOUBLE,
|
|
62
|
+
SQL_D_FLOAT: Const.SQL_D_FLOAT,
|
|
63
|
+
SQL_TIMESTAMP: Const.SQL_TIMESTAMP,
|
|
64
|
+
SQL_BLOB: Const.SQL_BLOB,
|
|
65
|
+
SQL_ARRAY: Const.SQL_ARRAY,
|
|
66
|
+
SQL_QUAD: Const.SQL_QUAD,
|
|
67
|
+
SQL_TYPE_TIME: Const.SQL_TYPE_TIME,
|
|
68
|
+
SQL_TYPE_DATE: Const.SQL_TYPE_DATE,
|
|
69
|
+
SQL_INT64: Const.SQL_INT64,
|
|
70
|
+
SQL_INT128: Const.SQL_INT128,
|
|
71
|
+
SQL_TIMESTAMP_TZ: Const.SQL_TIMESTAMP_TZ,
|
|
72
|
+
SQL_TIMESTAMP_TZ_EX: Const.SQL_TIMESTAMP_TZ_EX,
|
|
73
|
+
SQL_TIME_TZ: Const.SQL_TIME_TZ,
|
|
74
|
+
SQL_TIME_TZ_EX: Const.SQL_TIME_TZ_EX,
|
|
75
|
+
SQL_DEC16: Const.SQL_DEC16,
|
|
76
|
+
SQL_DEC34: Const.SQL_DEC34,
|
|
77
|
+
SQL_BOOLEAN: Const.SQL_BOOLEAN,
|
|
78
|
+
SQL_NULL: Const.SQL_NULL,
|
|
79
|
+
});
|
|
80
|
+
|
|
51
81
|
/**
|
|
52
82
|
* The most recent Connection created by attach()/create()/attachOrCreate().
|
|
53
83
|
* Kept for backwards compatibility with the previous CommonJS module where
|
|
@@ -114,7 +144,7 @@ export function create(options: Options | string, callback: DatabaseCallback): v
|
|
|
114
144
|
return;
|
|
115
145
|
}
|
|
116
146
|
|
|
117
|
-
cnx.createDatabase(options, callback);
|
|
147
|
+
cnx.createDatabase(options, callback as any);
|
|
118
148
|
});
|
|
119
149
|
}, options);
|
|
120
150
|
}
|
|
@@ -146,11 +176,13 @@ export function attachOrCreate(options: Options | string, callback: DatabaseCall
|
|
|
146
176
|
if (!err) {
|
|
147
177
|
if (self.db)
|
|
148
178
|
self.db.emit('connect', ret);
|
|
149
|
-
|
|
179
|
+
// DatabaseCallback stays permissive (db non-optional) for
|
|
180
|
+
// API users; internally the error path passes no db
|
|
181
|
+
doCallback(ret, callback as Callback<Database>);
|
|
150
182
|
return;
|
|
151
183
|
}
|
|
152
184
|
|
|
153
|
-
cnx.createDatabase(options, callback);
|
|
185
|
+
cnx.createDatabase(options, callback as any);
|
|
154
186
|
});
|
|
155
187
|
});
|
|
156
188
|
|
package/src/messages.ts
CHANGED
|
@@ -138,7 +138,7 @@ export const lookupMessages = function(status: FbStatusItem[], messageFile: stri
|
|
|
138
138
|
buffer = Buffer.alloc(bucket_size);
|
|
139
139
|
|
|
140
140
|
var i = 0;
|
|
141
|
-
var text;
|
|
141
|
+
var text: string | undefined;
|
|
142
142
|
|
|
143
143
|
function loop() {
|
|
144
144
|
lookup(status[i], function(line) {
|
package/src/pool.ts
CHANGED
package/src/srp.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function clientSeed(a: bigint = toBigInt(crypto.randomBytes(SRP_KEY_SIZE)
|
|
|
67
67
|
* @param b BigInt Server private key.
|
|
68
68
|
* @returns {{private: BigInt, public: BigInt}}
|
|
69
69
|
*/
|
|
70
|
-
export function serverSeed(user: string, password: string, salt: Buffer, b?: bigint | string, hashAlgo: string = 'sha1'): KeyPair {
|
|
70
|
+
export function serverSeed(user: string, password: string, salt: Buffer | string, b?: bigint | string, hashAlgo: string = 'sha1'): KeyPair {
|
|
71
71
|
if (typeof b === 'string') {
|
|
72
72
|
hashAlgo = b;
|
|
73
73
|
b = undefined;
|
|
@@ -104,7 +104,7 @@ export function serverSeed(user: string, password: string, salt: Buffer, b?: big
|
|
|
104
104
|
* @param b BigInt Server private key.
|
|
105
105
|
* @returns {BigInt}
|
|
106
106
|
*/
|
|
107
|
-
export function serverSession(user: string, password: string, salt: Buffer, A: bigint, B: bigint, b: bigint, hashAlgo: string = 'sha1'): bigint {
|
|
107
|
+
export function serverSession(user: string, password: string, salt: Buffer | string, A: bigint, B: bigint, b: bigint, hashAlgo: string = 'sha1'): bigint {
|
|
108
108
|
var u = getScramble(A, B, 'sha1');
|
|
109
109
|
var v = getVerifier(user, password, salt, 'sha1');
|
|
110
110
|
var vu = modPow(v, u, PRIME.N);
|
|
@@ -121,7 +121,7 @@ export function serverSession(user: string, password: string, salt: Buffer, A: b
|
|
|
121
121
|
/**
|
|
122
122
|
* M = H(H(N) xor H(g), H(I), s, A, B, K)
|
|
123
123
|
*/
|
|
124
|
-
export function clientProof(user: string, password: string, salt: Buffer, A: bigint, B: bigint, a: bigint, hashAlgo: string = 'sha1'): ClientProof {
|
|
124
|
+
export function clientProof(user: string, password: string, salt: Buffer | string, A: bigint, B: bigint, a: bigint, hashAlgo: string = 'sha1'): ClientProof {
|
|
125
125
|
var K = clientSession(user, password, salt, A, B, a, 'sha1');
|
|
126
126
|
var n1, n2;
|
|
127
127
|
|
|
@@ -222,7 +222,7 @@ function getScramble(A: bigint, B: bigint, hashAlgo: string = 'sha1'): bigint {
|
|
|
222
222
|
* @returns Buffer The raw session-key digest (fixed length, may start
|
|
223
223
|
* with a zero byte — significant for the proof).
|
|
224
224
|
*/
|
|
225
|
-
function clientSession(user: string, password: string, salt: Buffer, A: bigint, B: bigint, a: bigint, hashAlgo: string = 'sha1'): Buffer {
|
|
225
|
+
function clientSession(user: string, password: string, salt: Buffer | string, A: bigint, B: bigint, a: bigint, hashAlgo: string = 'sha1'): Buffer {
|
|
226
226
|
var u = getScramble(A, B, 'sha1');
|
|
227
227
|
var x = getUserHash(user, salt, password, 'sha1');
|
|
228
228
|
var gx = modPow(PRIME.g, x, PRIME.N);
|
|
@@ -264,7 +264,7 @@ function clientSession(user: string, password: string, salt: Buffer, A: bigint,
|
|
|
264
264
|
* @param password string Connection password.
|
|
265
265
|
* @returns {BigInt}
|
|
266
266
|
*/
|
|
267
|
-
function getUserHash(user: string, salt: Buffer, password: string, hashAlgo: string = 'sha1'): bigint {
|
|
267
|
+
function getUserHash(user: string, salt: Buffer | string, password: string, hashAlgo: string = 'sha1'): bigint {
|
|
268
268
|
var hash1 = getHash(hashAlgo, user.toUpperCase(), ':', password);
|
|
269
269
|
var hash2 = getHash(hashAlgo, salt, toBuffer(hash1));
|
|
270
270
|
|
|
@@ -279,7 +279,7 @@ function getUserHash(user: string, salt: Buffer, password: string, hashAlgo: str
|
|
|
279
279
|
* @param salt BigInt Connection salt.
|
|
280
280
|
* @returns {BigInt}
|
|
281
281
|
*/
|
|
282
|
-
function getVerifier(user: string, password: string, salt: Buffer, hashAlgo: string = 'sha1'): bigint {
|
|
282
|
+
function getVerifier(user: string, password: string, salt: Buffer | string, hashAlgo: string = 'sha1'): bigint {
|
|
283
283
|
return modPow(PRIME.g, getUserHash(user, salt, password, hashAlgo), PRIME.N);
|
|
284
284
|
}
|
|
285
285
|
|