node-firebird 2.3.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +544 -6
  2. package/lib/callback.d.ts +20 -0
  3. package/lib/callback.js +6 -16
  4. package/lib/firebird.msg.json +1370 -1370
  5. package/lib/gdscodes.d.ts +1519 -1520
  6. package/lib/gdscodes.js +5 -5
  7. package/lib/ieee754-decimal.d.ts +38 -0
  8. package/lib/ieee754-decimal.js +71 -118
  9. package/lib/index.d.ts +37 -338
  10. package/lib/index.js +97 -86
  11. package/lib/messages.d.ts +6 -0
  12. package/lib/messages.js +135 -162
  13. package/lib/pool.d.ts +23 -0
  14. package/lib/pool.js +34 -47
  15. package/lib/srp.d.ts +51 -0
  16. package/lib/srp.js +62 -72
  17. package/lib/types.d.ts +375 -0
  18. package/lib/types.js +22 -0
  19. package/lib/unix-crypt.d.ts +1 -0
  20. package/lib/unix-crypt.js +126 -152
  21. package/lib/utils.d.ts +16 -0
  22. package/lib/utils.js +24 -48
  23. package/lib/wire/connection.d.ts +100 -0
  24. package/lib/wire/connection.js +1029 -1009
  25. package/lib/wire/const.d.ts +567 -0
  26. package/lib/wire/const.js +620 -599
  27. package/lib/wire/database.d.ts +57 -0
  28. package/lib/wire/database.js +111 -108
  29. package/lib/wire/eventConnection.d.ts +16 -0
  30. package/lib/wire/eventConnection.js +29 -31
  31. package/lib/wire/fbEventManager.d.ts +45 -0
  32. package/lib/wire/fbEventManager.js +38 -57
  33. package/lib/wire/serialize.d.ts +97 -0
  34. package/lib/wire/serialize.js +42 -141
  35. package/lib/wire/service.d.ts +66 -0
  36. package/lib/wire/service.js +374 -401
  37. package/lib/wire/socket.d.ts +59 -0
  38. package/lib/wire/socket.js +79 -40
  39. package/lib/wire/statement.d.ts +25 -0
  40. package/lib/wire/statement.js +13 -9
  41. package/lib/wire/transaction.d.ts +21 -0
  42. package/lib/wire/transaction.js +33 -61
  43. package/lib/wire/xsqlvar.d.ts +175 -0
  44. package/lib/wire/xsqlvar.js +169 -269
  45. package/package.json +12 -4
  46. package/src/callback.ts +55 -0
  47. package/{poc/node_modules/node-firebird/lib/gdscodes.js → src/gdscodes.ts} +3 -3
  48. package/{poc/node_modules/node-firebird/lib/ieee754-decimal.js → src/ieee754-decimal.ts} +7 -14
  49. package/src/index.ts +157 -0
  50. package/{poc/node_modules/node-firebird/lib/messages.js → src/messages.ts} +163 -162
  51. package/src/pool.ts +209 -0
  52. package/{poc/node_modules/node-firebird/lib/srp.js → src/srp.ts} +74 -33
  53. package/src/types.ts +419 -0
  54. package/{poc/node_modules/node-firebird/lib/unix-crypt.js → src/unix-crypt.ts} +6 -12
  55. package/{poc/node_modules/node-firebird/lib/utils.js → src/utils.ts} +11 -20
  56. package/{poc/node_modules/node-firebird/lib/wire/connection.js → src/wire/connection.ts} +611 -129
  57. package/{poc/node_modules/node-firebird/lib/wire/const.js → src/wire/const.ts} +96 -9
  58. package/{poc/node_modules/node-firebird/lib/wire/database.js → src/wire/database.ts} +110 -44
  59. package/{poc/node_modules/node-firebird/lib/wire/eventConnection.js → src/wire/eventConnection.ts} +29 -14
  60. package/{poc/node_modules/node-firebird/lib/wire/fbEventManager.js → src/wire/fbEventManager.ts} +39 -30
  61. package/{poc/node_modules/node-firebird/lib/wire/serialize.js → src/wire/serialize.ts} +78 -59
  62. package/{poc/node_modules/node-firebird/lib/wire/service.js → src/wire/service.ts} +90 -88
  63. package/src/wire/socket.ts +262 -0
  64. package/src/wire/statement.ts +71 -0
  65. package/{poc/node_modules/node-firebird/lib/wire/transaction.js → src/wire/transaction.ts} +25 -19
  66. package/{poc/node_modules/node-firebird/lib/wire/xsqlvar.js → src/wire/xsqlvar.ts} +244 -143
  67. package/.eslintrc.json +0 -12
  68. package/.github/workflows/codeql.yml +0 -76
  69. package/.github/workflows/node.js.yml +0 -95
  70. package/BIGINT_MIGRATION.md +0 -374
  71. package/CI_DEBUGGING_GUIDE.md +0 -148
  72. package/ENCRYPTION_CALLBACK.md +0 -152
  73. package/FIREBIRD_LOG_FEATURE.md +0 -145
  74. package/MINIMAL_CHANGES_SUMMARY.md +0 -136
  75. package/PR_SUMMARY.md +0 -96
  76. package/ROADMAP.md +0 -223
  77. package/SRP_PROTOCOL.md +0 -482
  78. package/poc/README.md +0 -160
  79. package/poc/helpers.js +0 -59
  80. package/poc/node_modules/.package-lock.json +0 -14
  81. package/poc/node_modules/node-firebird/.eslintrc.json +0 -12
  82. package/poc/node_modules/node-firebird/.github/workflows/codeql.yml +0 -76
  83. package/poc/node_modules/node-firebird/.github/workflows/node.js.yml +0 -95
  84. package/poc/node_modules/node-firebird/BIGINT_MIGRATION.md +0 -374
  85. package/poc/node_modules/node-firebird/CI_DEBUGGING_GUIDE.md +0 -148
  86. package/poc/node_modules/node-firebird/ENCRYPTION_CALLBACK.md +0 -152
  87. package/poc/node_modules/node-firebird/FIREBIRD_LOG_FEATURE.md +0 -145
  88. package/poc/node_modules/node-firebird/LICENSE +0 -373
  89. package/poc/node_modules/node-firebird/MINIMAL_CHANGES_SUMMARY.md +0 -136
  90. package/poc/node_modules/node-firebird/PR_SUMMARY.md +0 -96
  91. package/poc/node_modules/node-firebird/README.md +0 -794
  92. package/poc/node_modules/node-firebird/ROADMAP.md +0 -223
  93. package/poc/node_modules/node-firebird/SRP_PROTOCOL.md +0 -482
  94. package/poc/node_modules/node-firebird/lib/callback.js +0 -38
  95. package/poc/node_modules/node-firebird/lib/gdscodes.d.ts +0 -1524
  96. package/poc/node_modules/node-firebird/lib/index.d.ts +0 -316
  97. package/poc/node_modules/node-firebird/lib/index.js +0 -128
  98. package/poc/node_modules/node-firebird/lib/pool.js +0 -108
  99. package/poc/node_modules/node-firebird/lib/wire/socket.js +0 -175
  100. package/poc/node_modules/node-firebird/lib/wire/statement.js +0 -48
  101. package/poc/node_modules/node-firebird/package.json +0 -38
  102. package/poc/node_modules/node-firebird/vitest.config.js +0 -24
  103. package/poc/package-lock.json +0 -21
  104. package/poc/package.json +0 -12
  105. package/poc/reproduce-fixed.js +0 -150
  106. package/poc/reproduce.js +0 -133
  107. package/vitest.config.js +0 -27
  108. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg +0 -0
  109. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg.json +0 -0
package/src/types.ts ADDED
@@ -0,0 +1,419 @@
1
+ // Public API type definitions for node-firebird.
2
+ //
3
+ // These types were previously maintained by hand in lib/index.d.ts
4
+ // (originally contributed by Marco Warm <https://github.com/MarcusCalidus>).
5
+ // They now live in the TypeScript source tree and are compiled into the
6
+ // published declaration files.
7
+
8
+ export type DatabaseCallback = (err: any, db: Database) => void;
9
+ export type TransactionCallback = (err: any, transaction: Transaction) => void;
10
+ export type QueryCallback = (err: any, result: any[]) => void;
11
+ export type SimpleCallback = (err: any) => void;
12
+ export type SequentialCallback = (row: any, index: number, next?: (err?: any) => void) => void | Promise<void>;
13
+
14
+ /**
15
+ * Describes a single column in a prepared statement's result set or
16
+ * parameter list. The properties here are populated by the
17
+ * `isc_info_sql_*` response items returned by the Firebird server during
18
+ * op_prepare_statement.
19
+ *
20
+ * On Firebird 6.0+ (Protocol 20) `relationSchema` is additionally
21
+ * populated when the column comes from a table that lives in a
22
+ * named schema.
23
+ */
24
+ export interface ColumnMetadata {
25
+ /** Internal Firebird SQL type code (before nullability bit is masked). */
26
+ type: number;
27
+ /** SQL sub-type (e.g. BLOB sub-type 1 = TEXT). */
28
+ subType: number;
29
+ /** Numeric scale for fixed-point types (negative, e.g. NUMERIC(9,2) → -2). */
30
+ scale: number;
31
+ /** Maximum byte length for character / binary columns. */
32
+ length: number;
33
+ /** Whether the column accepts NULL values. */
34
+ nullable: boolean;
35
+ /** Column / parameter name as declared in the DDL. */
36
+ field?: string;
37
+ /** Source relation (table / view) name. */
38
+ relation?: string;
39
+ /**
40
+ * **Firebird 6.0+ (Protocol 20+)**
41
+ * Schema that owns the source relation. `undefined` or empty string
42
+ * for legacy (pre-6.0) servers or columns not drawn from a named
43
+ * schema (e.g. computed expressions).
44
+ */
45
+ relationSchema?: string;
46
+ /** Column alias as it appears in the SELECT list. */
47
+ alias?: string;
48
+ /** Alias of the source relation / sub-query. */
49
+ relationAlias?: string;
50
+ /** Owner (user) of the source relation. */
51
+ owner?: string;
52
+ /**
53
+ * **Firebird 6.0+ (Protocol 20+)**
54
+ *
55
+ * Character Set ID extracted from packed subType for string/character types.
56
+ */
57
+ charSetId?: number;
58
+ /**
59
+ * **Firebird 6.0+ (Protocol 20+)**
60
+ *
61
+ * Collation ID extracted from packed subType for string/character types.
62
+ */
63
+ collationId?: number;
64
+ }
65
+
66
+ export type Isolation = number[];
67
+
68
+ export type TransactionOptions = {
69
+ autoCommit?: boolean;
70
+ autoUndo?: boolean;
71
+ isolation?: Isolation;
72
+ ignoreLimbo?: boolean;
73
+ readOnly?: boolean;
74
+ wait?: boolean;
75
+ waitTimeout?: number;
76
+ };
77
+
78
+ export type QueryOptions = {
79
+ timeout?: number;
80
+ scrollable?: boolean;
81
+ }
82
+
83
+ export interface Database {
84
+ detach(callback?: SimpleCallback): Database;
85
+ transaction(options: TransactionOptions|Isolation|TransactionCallback, callback?: TransactionCallback): Database;
86
+ newStatement(query: string, callback: (err: Error | null, statement: Statement) => void): Database;
87
+ query(query: string, params: any[], callback: QueryCallback, options?: QueryOptions): Database;
88
+ execute(query: string, params: any[], callback: QueryCallback, options?: QueryOptions): Database;
89
+ sequentially(query: string, params: any[], rowCallback: SequentialCallback, callback: SimpleCallback, options?: QueryOptions | boolean): Database;
90
+ drop(callback: SimpleCallback): void;
91
+ escape(value: any): string;
92
+ attachEvent(callback: any): this;
93
+ createTablespace(name: string, filePath: string, callback?: QueryCallback): Database;
94
+ alterTablespace(name: string, filePath: string, callback?: QueryCallback): Database;
95
+ dropTablespace(name: string, callback?: QueryCallback): Database;
96
+ createSchema(schemaName: string, tablespaceName?: string | QueryCallback, callback?: QueryCallback): Database;
97
+ }
98
+
99
+ export interface Transaction {
100
+ newStatement(query: string, callback: (err: Error | null, statement: Statement) => void): void;
101
+ query(query: string, params: any[], callback: QueryCallback, options?: QueryOptions): void;
102
+ execute(query: string, params: any[], callback: QueryCallback, options?: QueryOptions): void;
103
+ sequentially(query: string, params: any[], rowCallback: SequentialCallback, callback: SimpleCallback, options?: QueryOptions | boolean): Database;
104
+ commit(callback?: SimpleCallback): void;
105
+ commitRetaining(callback?: SimpleCallback): void;
106
+ rollback(callback?: SimpleCallback): void;
107
+ rollbackRetaining(callback?: SimpleCallback): void;
108
+ }
109
+
110
+ export interface Statement {
111
+ close(callback?: SimpleCallback): void;
112
+ drop(callback?: SimpleCallback): void;
113
+ release(callback?: SimpleCallback): void;
114
+ execute(transaction: Transaction, params: any[], callback: QueryCallback, options?: QueryOptions): void;
115
+ fetch(transaction: Transaction, count: number, callback: QueryCallback): void;
116
+ fetchScroll(transaction: Transaction, direction: 'NEXT' | 'PRIOR' | 'FIRST' | 'LAST' | 'ABSOLUTE' | 'RELATIVE' | number, offset: number, count: number, callback: QueryCallback): void;
117
+ fetchAll(transaction: Transaction, callback: QueryCallback): void;
118
+ }
119
+
120
+ export type SupportedCharacterSet = |
121
+ 'NONE' |
122
+ 'CP943C' |
123
+ 'DOS737' |
124
+ 'DOS775' |
125
+ 'DOS858' |
126
+ 'DOS862' |
127
+ 'DOS864' |
128
+ 'DOS866' |
129
+ 'DOS869' |
130
+ 'GB18030' |
131
+ 'GBK' |
132
+ 'ISO8859_1' |
133
+ 'ISO8859_2' |
134
+ 'ISO8859_3' |
135
+ 'ISO8859_4' |
136
+ 'ISO8859_5' |
137
+ 'ISO8859_6' |
138
+ 'ISO8859_7' |
139
+ 'ISO8859_8' |
140
+ 'ISO8859_9' |
141
+ 'ISO8859_13' |
142
+ 'KOI8R' |
143
+ 'KOI8U' |
144
+ 'TIS620' |
145
+ 'UTF8' |
146
+ 'WIN1251' |
147
+ 'WIN1252' |
148
+ 'WIN1253' |
149
+ 'WIN1254' |
150
+ 'WIN1255' |
151
+ 'WIN1256' |
152
+ 'WIN1257' |
153
+ 'WIN1258' |
154
+ 'WIN_1258';
155
+
156
+ export interface Options {
157
+ host?: string;
158
+ port?: number;
159
+ database?: string;
160
+ user?: string;
161
+ password?: string;
162
+ lowercase_keys?: boolean;
163
+ role?: string;
164
+ pageSize?: number;
165
+ retryConnectionInterval?: number;
166
+ encoding?: SupportedCharacterSet;
167
+ blobAsText?: boolean; // only affects for blob subtype 1
168
+ /**
169
+ * Segment size in bytes used when WRITING blobs (op_batch_segments).
170
+ * Default 1024, max 65535. Use 65535 to minimize round-trips on
171
+ * remote/high-latency connections.
172
+ */
173
+ blobChunkSize?: number;
174
+ /**
175
+ * Buffer size in bytes requested per op_get_segment when READING
176
+ * blobs. Default 1024, max 65535. Use 65535 to minimize round-trips
177
+ * on remote/high-latency connections (~64x fewer round-trips).
178
+ */
179
+ blobReadChunkSize?: number;
180
+ wireCrypt?: number; // WIRE_CRYPT_DISABLE or WIRE_CRYPT_ENABLE
181
+ wireCompression?: boolean;
182
+ pluginName?: string;
183
+ parallelWorkers?: number;
184
+ maxInlineBlobSize?: number;
185
+ maxNegotiatedProtocols?: number;
186
+ dbCryptConfig?: string; // Database encryption key callback config (base64: prefix for base64, or plain string)
187
+ /**
188
+ * Timeout in milliseconds for a single pool.get() attach operation.
189
+ * If attach() does not complete within this time the slot is freed,
190
+ * the caller receives an error, and any late-arriving connection is
191
+ * safely discarded. Set to 0 or omit to disable (default: no timeout).
192
+ *
193
+ * Recommended value: 5000–10000 ms depending on network latency and
194
+ * expected Firebird server response time under load.
195
+ */
196
+ connectTimeout?: number;
197
+ /**
198
+ * **Firebird 6.0+ only (Protocol 20+)**
199
+ *
200
+ * Sets the session's current schema at connection time. Equivalent to
201
+ * executing `SET SCHEMA <name>` immediately after connecting.
202
+ *
203
+ * Unqualified object references (tables, procedures, etc.) that do not
204
+ * match any schema in the `searchPath` fall back to `PUBLIC`.
205
+ *
206
+ * Example: `defaultSchema: 'myapp'`
207
+ */
208
+ defaultSchema?: string;
209
+ /**
210
+ * **Firebird 6.0+ only (Protocol 20+)**
211
+ *
212
+ * Comma-separated (or array of) schema names used to resolve
213
+ * unqualified object references, tried in order from left to right.
214
+ * Equivalent to PostgreSQL's `search_path`.
215
+ *
216
+ * Examples:
217
+ * ```ts
218
+ * searchPath: 'myapp,PUBLIC'
219
+ * searchPath: ['myapp', 'PUBLIC']
220
+ * ```
221
+ *
222
+ * When omitted the server uses its own configured default
223
+ * (typically `PUBLIC` then `SYSTEM`).
224
+ */
225
+ searchPath?: string | string[];
226
+ /**
227
+ * **Firebird 6.0+ only (Protocol 20+)**
228
+ *
229
+ * Automatically stringifies JavaScript objects/arrays passed as query
230
+ * parameters to JSON strings, and automatically parses returned JSON
231
+ * text/BLOB columns back into JavaScript objects/arrays.
232
+ */
233
+ jsonAsObject?: boolean;
234
+ }
235
+
236
+ export interface SvcMgrOptions extends Options {
237
+ manager: true; // Attach to ServiceManager
238
+ }
239
+
240
+ export interface ConnectionPool {
241
+ get(callback: DatabaseCallback): void;
242
+ destroy(callback?: SimpleCallback): void;
243
+ }
244
+
245
+ export interface ReadableOptions {
246
+ optread?: 'byline' | 'buffer'; // default 'byline'
247
+ buffersize?: number; // default 'byline': 2048, 'buffer': 8192
248
+ timeout?: number;
249
+ }
250
+
251
+ export interface BackupOptions extends ReadableOptions {
252
+ database?: string;
253
+ files: string | { filename: string, sizefile: string }[];
254
+ factor?: number; // If backing up to a physical tape device, this switch lets you specify the tape's blocking factor
255
+ verbose?: boolean;
256
+ ignorechecksums?: boolean;
257
+ ignorelimbo?: boolean;
258
+ metadataonly?: boolean;
259
+ nogarbasecollect?: boolean;
260
+ olddescriptions?: boolean;
261
+ nontransportable?: boolean;
262
+ convert?: boolean;
263
+ expand?: boolean;
264
+ notriggers?: boolean;
265
+ }
266
+
267
+ export interface NBackupOptions extends ReadableOptions {
268
+ database?: string;
269
+ file: string;
270
+ level?: number; // nb day for incremental
271
+ notriggers?: boolean;
272
+ direct?: 'on' | 'off'; // default 'on'
273
+ }
274
+
275
+ export interface RestoreOptions extends ReadableOptions {
276
+ database?: string;
277
+ files: string | string[];
278
+ verbose?: boolean;
279
+ cachebuffers?: number; // default 2048, gbak -buffers
280
+ pagesize?: boolean; // default 4096
281
+ readonly?: boolean; // default false
282
+ deactivateindexes?: boolean; // default false
283
+ noshadow?: boolean; // default false
284
+ novalidity?: boolean; // default false
285
+ individualcommit?: boolean; // default true
286
+ replace?: boolean; // default false
287
+ create?: boolean; // default true
288
+ useallspace?: boolean; // default false
289
+ metadataonly?: boolean; // default false
290
+ fixfssdata?: string; // default null
291
+ fixfssmetadata?: string; // default null
292
+ }
293
+
294
+ export interface NRestoreOptions extends ReadableOptions {
295
+ database?: string;
296
+ files: string | string[];
297
+ }
298
+
299
+ export interface ValidateOptions extends ReadableOptions {
300
+ database?: string;
301
+ checkdb?: boolean;
302
+ ignorechecksums?: boolean;
303
+ killshadows?: boolean;
304
+ mend?: boolean;
305
+ validate?: boolean;
306
+ full?: boolean;
307
+ sweep?: boolean;
308
+ listlimbo?: boolean;
309
+ icu?: boolean;
310
+ }
311
+
312
+ export interface StatsOptions extends ReadableOptions {
313
+ database?: string;
314
+ record?: boolean;
315
+ nocreation?: boolean;
316
+ tables?: boolean;
317
+ pages?: boolean;
318
+ header?: boolean;
319
+ indexes?: boolean;
320
+ tablesystem?: boolean;
321
+ encryption?: boolean;
322
+ objects?: string; // space-separated list of object index,table,systemtable
323
+ }
324
+
325
+ export interface UserInfo {
326
+ userid: number;
327
+ groupid: number;
328
+ username: string;
329
+ firstname: string;
330
+ middlename: string;
331
+ lastname: string
332
+ admin: number;
333
+ rolename?: string;
334
+ groupname?: string;
335
+ }
336
+
337
+ export interface ServerInfo {
338
+ result: number;
339
+ dbinfo?: { database: any[], nbattachment: number, nbdatabase: number };
340
+ fbconfig?: any;
341
+ svcversion?: number;
342
+ fbversion?: string;
343
+ fbimplementation?: string;
344
+ fbcapatibilities: string[];
345
+ pathsecuritydb?: string;
346
+ fbenv?: string;
347
+ fbenvlock?: string;
348
+ fbenvmsg?: string;
349
+ limbotrans?: number[];
350
+ fbusers?: UserInfo[]
351
+ }
352
+
353
+ export interface ServerInfoReq {
354
+ dbinfo?: boolean;
355
+ fbconfig?: boolean;
356
+ svcversion?: boolean;
357
+ fbversion?: boolean;
358
+ fbimplementation?: boolean;
359
+ fbcapatibilities?: boolean;
360
+ pathsecuritydb?: boolean;
361
+ fbenv?: boolean;
362
+ fbenvlock?: boolean;
363
+ fbenvmsg?: boolean;
364
+ limbotrans?: boolean;
365
+ }
366
+
367
+ export interface TraceOptions extends ReadableOptions {
368
+ configfile?: string; // startTrace uses it
369
+ tracename?: string; // startTrace uses it
370
+ traceid?: number; // suspendTrace, stopTrace, and resumeTrace use it
371
+ }
372
+
373
+ export type ServiceManagerCallback = (err: any, svc: ServiceManager) => void;
374
+ export type ReadableCallback = (err: any, reader: NodeJS.ReadableStream) => void;
375
+ export type InfoCallback = (err: any, info: ServerInfo) => void;
376
+ export type LineCallback = (err: any, data: { result: number, line: string }) => void;
377
+
378
+ export enum ShutdownMode { NORMAL = 0, MULTI = 1, SINGLE = 2, FULL = 3 }
379
+ export enum ShutdownKind { FORCED = 0, DENY_TRANSACTION = 1, DENY_ATTACHMENT = 2 }
380
+
381
+ export interface ServiceManager {
382
+ detach(callback?: SimpleCallback, force?: boolean): void;
383
+ backup(options: BackupOptions, callback: ReadableCallback): void;
384
+ nbackup(options: BackupOptions, callback: ReadableCallback): void;
385
+ restore(options: RestoreOptions, callback: ReadableCallback): void;
386
+ nrestore(options: NRestoreOptions, callback: ReadableCallback): void;
387
+ setDialect(db: string, dialect: 1 | 3, callback: ReadableCallback): void;
388
+ setSweepinterval(db: string, interval: number, callback: Function): void; // gfix -h INTERVAL
389
+ setCachebuffer(db: string, nbpages: any, callback: ReadableCallback): void; // gfix -b NBPAGES
390
+ BringOnline(db: string, callback: ReadableCallback): void; // gfix -o
391
+ Shutdown(db: string, kind: ShutdownKind, delay: number, mode: ShutdownMode, callback: ReadableCallback): void; // server version >= 2.0
392
+ Shutdown(db: string, kind: ShutdownKind, delay: number, callback: ReadableCallback): void; // server version < 2.0
393
+ setShadow(db: string, val: boolean, callback: ReadableCallback): void;
394
+ setForcewrite(db: string, val: boolean, callback: ReadableCallback): void; // gfix -write
395
+ setReservespace(db: string, val: boolean, callback: ReadableCallback): void; // true: gfix -use reserve, false: gfix -use full
396
+ setReadonlyMode(db: string, callback: ReadableCallback): void; // gfix -mode read_only
397
+ setReadwriteMode(db: string, callback: ReadableCallback): void; // gfix -mode read_write
398
+ validate(options: ValidateOptions, callback: ReadableCallback): void; // gfix -validate
399
+ commit(db: string, transactid: number, callback: ReadableCallback): void; // gfix -commit
400
+ rollback(db: string, transactid: number, callback: ReadableCallback): void;
401
+ recover(db: string, transactid: number, callback: ReadableCallback): void;
402
+ getStats(options: StatsOptions, callback: ReadableCallback): void;
403
+ getLog(options: ReadableOptions, callback: ReadableCallback): void;
404
+ getUsers(username: string | null, callback: InfoCallback): void;
405
+ addUser(username: string, password: string, info: UserInfo, callback: ReadableCallback): void;
406
+ editUser(username: string, info: UserInfo, callback: ReadableCallback): void;
407
+ removeUser(username: string, rolename: string | null, callback: ReadableCallback): void;
408
+ getFbserverInfos(infos: ServerInfoReq, options: { buffersize?: number, timeout?: number }, callback: InfoCallback): void; // if infos is empty all options are asked to the service
409
+ startTrace(options: TraceOptions, callback: ReadableCallback): void;
410
+ suspendTrace(options: TraceOptions, callback: ReadableCallback): void;
411
+ resumeTrace(options: TraceOptions, callback: ReadableCallback): void;
412
+ stopTrace(options: TraceOptions, callback: ReadableCallback): void;
413
+ getTraceList(options: ReadableOptions, callback: ReadableCallback): void;
414
+ readline(options: ReadableOptions, callback: LineCallback): void;
415
+ readeof(options: ReadableOptions, callback: LineCallback): void;
416
+ hasRunningAction(options: ReadableOptions, callback: ReadableCallback): void;
417
+ readusers(options: ReadableOptions, callback: ReadableCallback): void;
418
+ readlimbo(options: ReadableOptions, callback: ReadableCallback): void;
419
+ }
@@ -285,26 +285,24 @@ function body(schedule, eSwap0, eSwap1) {
285
285
  return out;
286
286
  }
287
287
 
288
- function crypt(original, salt) {
289
- if (!(original instanceof Buffer)) {
290
- original = Buffer.from(original);
291
- }
288
+ export function crypt(original: string | Buffer, salt: string): string {
289
+ const orig: Buffer = original instanceof Buffer ? original : Buffer.from(original);
292
290
 
293
291
  if (!salt) {
294
292
  throw new Error("Invalid salt value: " + salt);
295
293
  }
296
294
 
297
295
  var buffer = Buffer.alloc(13);
298
- var charZero = salt[0].charCodeAt();
299
- var charOne = salt[1].charCodeAt();
296
+ var charZero = salt[0].charCodeAt(0);
297
+ var charOne = salt[1].charCodeAt(0);
300
298
  buffer[0] = charZero;
301
299
  buffer[1] = charOne;
302
300
  var eSwap0 = CON_SALT[charZero];
303
301
  var eSwap1 = CON_SALT[charOne] << 4;
304
302
 
305
303
  var key = Buffer.alloc(8);
306
- for (var i = 0; i < key.length && i < original.length; i++) {
307
- var iChar = original[i];
304
+ for (var i = 0; i < key.length && i < orig.length; i++) {
305
+ var iChar = orig[i];
308
306
  key[i] = iChar << 1;
309
307
  }
310
308
 
@@ -337,7 +335,3 @@ function crypt(original, salt) {
337
335
 
338
336
  return buffer.toString('ascii');
339
337
  }
340
-
341
- module.exports = {
342
- crypt : crypt
343
- }
@@ -1,12 +1,13 @@
1
- const MessagesError = require('./firebird.msg.json');
2
- const Const = require('./wire/const');
1
+ import messagesJson from './firebird.msg.json';
2
+ import Const from './wire/const';
3
+ import type { FbStatusItem } from './callback';
4
+
5
+ const MessagesError = messagesJson as Record<string, string>;
3
6
 
4
7
  /**
5
8
  * Parse date from string
6
- * @param {String} str
7
- * @return {Date}
8
9
  */
9
- const parseDate = (str) => {
10
+ export const parseDate = (str: string): Date => {
10
11
  const self = str.trim();
11
12
  const arr = self.indexOf(' ') === -1 ? self.split('T') : self.split(' ');
12
13
  let index = arr[0].indexOf(':');
@@ -106,10 +107,8 @@ const parseDate = (str) => {
106
107
 
107
108
  /**
108
109
  * Get Error Message per gdscode
109
- * @param {{gdscode: Number, params: Any[]}[]} status
110
- * @returns {String} - Error message
111
110
  */
112
- const lookupMessages = (status) => {
111
+ export const lookupMessages = (status: FbStatusItem[]): string => {
113
112
  const messages = status.map((item) => {
114
113
  let text = MessagesError[item.gdscode];
115
114
  if (text === undefined) {
@@ -127,11 +126,10 @@ const lookupMessages = (status) => {
127
126
 
128
127
  /**
129
128
  * Escape value
130
- * @param {Object} value
131
- * @param {Number} protocolVersion (optional, default: PROTOCOL_VERSION13)
132
- * @return {String}
129
+ * @param value value to escape
130
+ * @param protocolVersion optional, default: PROTOCOL_VERSION13
133
131
  */
134
- const escape = function(value, protocolVersion) {
132
+ export const escape = function(value: any, protocolVersion?: number): string {
135
133
 
136
134
  if (value === null || value === undefined)
137
135
  return 'NULL';
@@ -154,11 +152,4 @@ const escape = function(value, protocolVersion) {
154
152
  throw new Error('Escape supports only primitive values.');
155
153
  };
156
154
 
157
- function noop() {}
158
-
159
- module.exports = {
160
- escape,
161
- lookupMessages,
162
- noop,
163
- parseDate,
164
- };
155
+ export function noop(): void {}