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.
Files changed (49) hide show
  1. package/README.md +166 -6
  2. package/lib/index.d.ts +5 -0
  3. package/lib/index.js +32 -1
  4. package/lib/pool.js +1 -1
  5. package/lib/srp.d.ts +3 -3
  6. package/lib/types.d.ts +143 -5
  7. package/lib/uri.js +2 -2
  8. package/lib/wire/connection.d.ts +92 -59
  9. package/lib/wire/connection.js +267 -53
  10. package/lib/wire/const.d.ts +9 -1
  11. package/lib/wire/const.js +21 -9
  12. package/lib/wire/database.d.ts +51 -26
  13. package/lib/wire/database.js +26 -8
  14. package/lib/wire/eventConnection.js +5 -3
  15. package/lib/wire/query-stream.d.ts +18 -0
  16. package/lib/wire/query-stream.js +73 -0
  17. package/lib/wire/serialize.d.ts +18 -2
  18. package/lib/wire/serialize.js +7 -0
  19. package/lib/wire/service.d.ts +42 -0
  20. package/lib/wire/service.js +145 -0
  21. package/lib/wire/socket.d.ts +3 -1
  22. package/lib/wire/socket.js +5 -2
  23. package/lib/wire/statement.d.ts +31 -19
  24. package/lib/wire/statement.js +1 -5
  25. package/lib/wire/transaction.d.ts +30 -18
  26. package/lib/wire/transaction.js +23 -4
  27. package/lib/wire/wire-types.d.ts +116 -0
  28. package/lib/wire/wire-types.js +10 -0
  29. package/lib/wire/xsqlvar.d.ts +18 -18
  30. package/package.json +1 -1
  31. package/src/index.ts +36 -4
  32. package/src/messages.ts +1 -1
  33. package/src/pool.ts +1 -1
  34. package/src/srp.ts +6 -6
  35. package/src/types.ts +140 -5
  36. package/src/unix-crypt.ts +9 -9
  37. package/src/uri.ts +2 -2
  38. package/src/wire/connection.ts +464 -232
  39. package/src/wire/const.ts +21 -9
  40. package/src/wire/database.ts +75 -43
  41. package/src/wire/eventConnection.ts +8 -5
  42. package/src/wire/query-stream.ts +80 -0
  43. package/src/wire/serialize.ts +29 -0
  44. package/src/wire/service.ts +188 -6
  45. package/src/wire/socket.ts +17 -8
  46. package/src/wire/statement.ts +37 -29
  47. package/src/wire/transaction.ts +57 -32
  48. package/src/wire/wire-types.ts +127 -0
  49. package/src/wire/xsqlvar.ts +9 -7
@@ -1,5 +1,14 @@
1
- import { XdrWriter, BlrWriter } from './serialize';
1
+ import { XdrWriter, BlrWriter, XdrReader } from './serialize';
2
+ import { type Callback, type SimpleCallback } from '../callback';
2
3
  import * as srp from '../srp';
4
+ import * as Xsql from './xsqlvar';
5
+ import ServiceManager from './service';
6
+ import Database from './database';
7
+ import Statement from './statement';
8
+ import Transaction from './transaction';
9
+ import Socket from './socket';
10
+ import type { QueueCallback, QueueEntry, WireResponse, InternalOptions, InternalQueryOptions, BatchCb, Quad, AcceptPacket } from './wire-types';
11
+ import type { BatchOptions, QueryParams } from '../types';
3
12
  declare function parseValueIfJson(value: any, options: any): any;
4
13
  /***************************************
5
14
  *
@@ -12,10 +21,12 @@ declare class Connection {
12
21
  static fetch_blob_async: typeof fetch_blob_async;
13
22
  static parseValueIfJson: typeof parseValueIfJson;
14
23
  static describe: typeof describe;
15
- db: any;
16
- svc: any;
17
- options: any;
18
- accept: any;
24
+ db: Database;
25
+ svc: ServiceManager | undefined;
26
+ options: InternalOptions;
27
+ /** protocol negotiation result (op_accept / op_cond_accept / op_accept_data);
28
+ * populated during the connect/attach handshake */
29
+ accept: AcceptPacket;
19
30
  error: any;
20
31
  dbhandle: number | undefined;
21
32
  svchandle: number | undefined;
@@ -27,10 +38,12 @@ declare class Connection {
27
38
  } | undefined;
28
39
  _msg: XdrWriter;
29
40
  _blr: BlrWriter;
30
- _queue: any[];
41
+ /** response queue: one entry per expected server response (see wire-types) */
42
+ _queue: QueueEntry[];
31
43
  _pending: string[];
32
- _socket: any;
33
- _xdr: any;
44
+ _socket: Socket;
45
+ /** partially received packet buffered between 'data' events */
46
+ _xdr: XdrReader | undefined;
34
47
  _isOpened: boolean;
35
48
  _isClosed: boolean;
36
49
  _isDetach: boolean;
@@ -42,48 +55,64 @@ declare class Connection {
42
55
  _detachAuto: any;
43
56
  _retry_connection_id: any;
44
57
  _retry_connection_interval: number;
45
- _max_cached_query: number;
46
- _cache_query: Record<string, any> | null;
58
+ _statementCacheSize: number;
59
+ _statementCache: Map<string, Statement> | null;
47
60
  _messageFile: string;
48
61
  _authStartTime: number | undefined;
49
62
  _pendingAccept: any;
50
63
  _inlineBlobs: Map<string, Buffer> | undefined;
51
- constructor(host: string, port: number, callback: any, options: any, db?: any, svc?: any);
52
- _setcachedquery(query: any, statement: any): void;
53
- getCachedQuery(query: any): any;
64
+ constructor(host: string, port: number, callback: SimpleCallback | undefined, options: InternalOptions, db?: Database, svc?: ServiceManager);
65
+ /**
66
+ * Take an idle prepared statement for `query` out of the cache, or null.
67
+ * The statement leaves the cache while in use, so concurrent callers of
68
+ * the same query never share a server-side cursor — they simply prepare
69
+ * a fresh statement and the spare is dropped when released.
70
+ */
71
+ takeCachedStatement(query: string): Statement | null;
72
+ /**
73
+ * Return a statement after use. With the statement cache enabled the
74
+ * statement goes back into the cache as most-recently-used (closing its
75
+ * cursor but keeping the prepared handle), evicting the least-recently
76
+ * used statement over the limit. Failed statements, DDL and spares for
77
+ * an already-cached query are dropped instead.
78
+ */
79
+ releaseStatement(statement: Statement, callback?: QueueCallback): void;
54
80
  _rejectPending(err: any): void;
55
- _bind_events(host: any, port: any, callback: any): void;
81
+ _bind_events(host: string, port: number, callback: SimpleCallback | undefined): void;
56
82
  disconnect(): void;
57
- sendOpContAuth(authData: any, authDataEnc: any, pluginName: any): void;
58
- sendOpCrypt(encryptPlugin: any): void;
59
- sendOpCryptKeyCallback(pluginData: any): void;
83
+ sendOpContAuth(authData: string, authDataEnc: BufferEncoding, pluginName: string): void;
84
+ sendOpCrypt(encryptPlugin: string): void;
85
+ sendOpCryptKeyCallback(pluginData: BlrWriter): void;
60
86
  /**
61
87
  * Send an out-of-band op_cancel packet (protocol 12+ / Firebird 2.5+).
62
88
  * The server reads it asynchronously while an operation is executing and
63
89
  * makes that operation fail with isc_cancelled (GDSCode.CANCELLED); the
64
90
  * op_cancel packet itself has no response, so nothing is queued here.
65
91
  */
66
- cancelOperation(kind: any, callback: any): this;
92
+ cancelOperation(kind?: number | SimpleCallback, callback?: SimpleCallback): this | undefined;
67
93
  /** Write a prebuilt packet and queue its response callback. */
68
- _queueEventBuffer(buffer: any, callback: any): void;
69
- _queueEvent(callback: any, defer?: boolean): void;
70
- connect(options: any, callback: any): void;
71
- attach(options: any, callback?: any, db?: any): void;
72
- detach(callback: any): this;
73
- createDatabase(options: any, callback: any): void;
74
- dropDatabase(callback: any): void;
75
- throwClosed(callback: any): this;
76
- startTransaction(options: any, callback: any): this;
77
- commit(transaction: any, callback: any): this;
78
- rollback(transaction: any, callback: any): this;
79
- commitRetaining(transaction: any, callback: any): this;
80
- rollbackRetaining(transaction: any, callback: any): this;
81
- allocateStatement(callback: any): this;
82
- dropStatement(statement: any, callback: any): this;
83
- closeStatement(statement: any, callback: any): this;
84
- allocateAndPrepareStatement(transaction: any, query: any, plan: any, callback: any): void;
85
- prepare(transaction: any, query: any, plan: any, callback: any): void;
86
- prepareStatement(transaction: any, statement: any, query: any, plan: any, callback: any): this;
94
+ _queueEventBuffer(buffer: Buffer, callback: QueueCallback | undefined): void;
95
+ _queueEvent(callback: QueueCallback | undefined, defer?: boolean): void;
96
+ connect(options: InternalOptions, callback: Callback<AcceptPacket> | undefined): void;
97
+ attach(options: InternalOptions, callback?: Callback<Database>, db?: Database): void;
98
+ detach(callback: Callback | undefined): this | undefined;
99
+ createDatabase(options: InternalOptions, callback: Callback<Database> | undefined): void;
100
+ dropDatabase(callback: SimpleCallback | undefined): void;
101
+ throwClosed(callback: ((err: Error, ...args: any[]) => void) | undefined): this;
102
+ /** `options` is a resolved options object, a bare isolation array, or
103
+ * the callback itself when no options are given. */
104
+ startTransaction(options: any, callback?: any): this | undefined;
105
+ commit(transaction: Transaction, callback: QueueCallback | undefined): this | undefined;
106
+ rollback(transaction: Transaction, callback: QueueCallback | undefined): this | undefined;
107
+ commitRetaining(transaction: Transaction, callback: QueueCallback | undefined): this | undefined;
108
+ rollbackRetaining(transaction: Transaction, callback: QueueCallback | undefined): this | undefined;
109
+ allocateStatement(callback: QueueCallback): this | undefined;
110
+ dropStatement(statement: Statement, callback: QueueCallback | undefined): this | undefined;
111
+ closeStatement(statement: Statement, callback: QueueCallback | undefined): this | undefined;
112
+ allocateAndPrepareStatement(transaction: Transaction, query: string, plan: boolean, callback: Callback<Statement>): void;
113
+ prepare(transaction: Transaction, query: string, plan: boolean, callback: Callback<Statement>): void;
114
+ /** `plan` may be the callback itself when no plan flag is given. */
115
+ prepareStatement(transaction: Transaction, statement: Statement, query: string, plan: boolean | Callback<Statement>, callback?: Callback<Statement>): this | undefined;
87
116
  /**
88
117
  * Execute a statement once per row using the Firebird 4 batch API
89
118
  * (protocol 16+): op_batch_create + op_batch_msg(s) + op_batch_exec +
@@ -96,27 +125,31 @@ declare class Connection {
96
125
  * { recordCount, updateCounts, errors: [{recordNumber, error}],
97
126
  * errorRecordNumbers, success }.
98
127
  */
99
- executeBatch(transaction: any, statement: any, rows: any, callback: any, options: any): this;
100
- executeStatement(transaction: any, statement: any, params: any, callback: any, custom: any): this;
101
- sendExecute(op: number, statement: any, transaction: any, callback: any, parameters?: any[]): void;
102
- fetch(statement: any, transaction: any, count: any, callback: any): void;
103
- fetchScroll(statement: any, transaction: any, direction: any, offset: any, count: any, callback: any): void;
104
- fetchAll(statement: any, transaction: any, callback: any): void;
105
- openBlob(blob: any, transaction: any, callback: any): void;
106
- closeBlob(blob: any, callback: any, defer?: boolean): void;
107
- getSegment(blob: any, callback: any): void;
108
- createBlob2(transaction: any, callback: any): void;
109
- batchSegments(blob: any, buffer: any, callback: any): void;
110
- svcattach(options: any, callback?: any, svc?: any): void;
111
- svcstart(spbaction: any, callback: any): void;
112
- svcquery(spbquery: any, resultbuffersize: any, timeout: any, callback: any): void;
113
- svcdetach(callback: any): void;
114
- auxConnection(eventid: any, callback: any): this;
115
- queEvents(events: any, eventid: any, callback: any): this;
116
- closeEvents(eventid: any, callback: any): this;
128
+ executeBatch(transaction: Transaction, statement: Statement, rows: QueryParams[], callback: BatchCb | undefined, options?: BatchOptions): this | undefined;
129
+ /** `params` may be the callback itself when the statement has no parameters. */
130
+ executeStatement(transaction: Transaction, statement: Statement, params: any, callback?: QueueCallback, custom?: InternalQueryOptions): this | undefined;
131
+ sendExecute(op: number, statement: Statement, transaction: Transaction, callback: QueueCallback | undefined, parameters?: any[]): void;
132
+ /** `count` may be the callback itself when no fetch size is given. */
133
+ fetch(statement: Statement, transaction: Transaction, count: any, callback?: QueueCallback): void;
134
+ fetchScroll(statement: Statement, transaction: Transaction, direction: string | number, offset: any, count: any, callback?: QueueCallback): void;
135
+ fetchAll(statement: Statement, transaction: Transaction, callback: Callback<any[]>): void;
136
+ openBlob(blob: Quad, transaction: Transaction, callback: QueueCallback): void;
137
+ closeBlob(blob: any, callback?: QueueCallback, defer?: boolean): void;
138
+ getSegment(blob: any, callback: QueueCallback): void;
139
+ createBlob2(transaction: Transaction, callback: QueueCallback): void;
140
+ batchSegments(blob: any, buffer: Buffer, callback: QueueCallback): void;
141
+ svcattach(options: InternalOptions, callback?: Callback<ServiceManager>, svc?: ServiceManager): void;
142
+ svcstart(spbaction: BlrWriter, callback: QueueCallback | undefined): void;
143
+ svcquery(spbquery: number[], resultbuffersize: number, timeout: number | undefined, callback: QueueCallback | undefined): void;
144
+ svcdetach(callback: Callback | undefined): void;
145
+ auxConnection(eventid: number | Callback, callback?: Callback): this | undefined;
146
+ queEvents(events: Record<string, number>, eventid: number, callback: Callback): this | undefined;
147
+ closeEvents(eventid: number, callback: Callback): this | undefined;
117
148
  }
118
- declare function decodeResponse(data: any, callback: any, cnx: any, lowercase_keys: any, cb: (err?: any, obj?: any) => void): any;
119
- declare function describe(buff: Buffer, statement: any): void;
120
- declare function fetch_blob_async_transaction(statement: any, id: any, column: any, row: any): (transactionArg: any) => any;
121
- declare function fetch_blob_async(statement: any, id: any, name: any, row: any): (transaction: any, callback: any) => void;
149
+ declare function decodeResponse(data: XdrReader, callback: QueueCallback | undefined, cnx: Connection, lowercase_keys: boolean | undefined, cb: (err?: any, obj?: any) => void): void | WireResponse | {
150
+ error: Error;
151
+ };
152
+ declare function describe(buff: Buffer, statement: Statement): void;
153
+ declare function fetch_blob_async_transaction(statement: Statement, id: Quad, column: string | number, row: number, meta?: Xsql.SQLVarBase): (transactionArg: any) => Promise<unknown>;
154
+ declare function fetch_blob_async(statement: Statement, id: Quad, name: string | number, row: number): (transaction: Transaction, callback: any) => void;
122
155
  export = Connection;