@tachybase/module-multi-app 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/externalVersion.js +5 -5
  2. package/dist/node_modules/mariadb/callback.js +43 -8
  3. package/dist/node_modules/mariadb/check-node.js +30 -0
  4. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  5. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  6. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  7. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  8. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  9. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  10. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  11. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  12. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  13. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  14. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  15. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  16. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  17. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  18. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  19. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  20. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  21. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  22. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  23. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  24. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  25. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  26. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  27. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  28. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  29. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  34. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  35. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  36. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  37. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  38. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  39. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  40. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  41. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  42. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  43. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  44. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  45. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  46. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  47. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  48. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  49. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  50. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  51. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  52. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  53. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  54. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  55. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  56. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  57. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  58. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  59. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  60. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  61. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  62. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  63. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  64. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  65. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  66. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  67. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  68. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  69. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  70. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  71. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  72. package/dist/node_modules/mariadb/package.json +1 -1
  73. package/dist/node_modules/mariadb/promise.js +1 -34
  74. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  75. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  76. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  77. package/dist/node_modules/qs/package.json +1 -1
  78. package/dist/server/actions/apps.js +2 -2
  79. package/dist/server/app-lifecycle.d.ts +1 -1
  80. package/dist/server/app-lifecycle.js +4 -4
  81. package/dist/server/models/application.d.ts +1 -1
  82. package/package.json +7 -7
  83. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  84. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  85. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  86. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  87. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  88. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  89. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  90. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  91. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  92. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  93. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  94. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -1,160 +1,532 @@
1
+ // SPDX-License-Identifier: LGPL-2.1-or-later
2
+ // Copyright (c) 2015-2025 MariaDB Corporation Ab
3
+
1
4
  'use strict';
2
5
 
3
- const Connection = require('./connection');
4
- const util = require('util');
5
6
  const Errors = require('./misc/errors');
6
7
  const { Status } = require('./const/connection_status');
8
+ const Query = require('./cmd/query');
7
9
 
8
- function ConnectionCallback(options) {
9
- Connection.call(this, options);
10
+ class ConnectionCallback {
11
+ #conn;
10
12
 
11
- let connecting = 1;
12
- const connectPromise = this.connect.bind(this);
13
- const changeUserPromise = this.changeUser.bind(this);
14
- const queryPromise = this.query.bind(this);
15
- const endPromise = this.end.bind(this);
16
- const pingPromise = this.ping.bind(this);
17
- const resetPromise = this.reset.bind(this);
18
- const commitPromise = this.commit.bind(this);
19
- const rollbackPromise = this.rollback.bind(this);
13
+ constructor(conn) {
14
+ this.#conn = conn;
15
+ }
20
16
 
21
- const emptySuccess = (rows) => {};
22
- const emptyError = (err) => {};
17
+ get threadId() {
18
+ return this.#conn.info ? this.#conn.info.threadId : null;
19
+ }
23
20
 
24
- //*****************************************************************
25
- // internal equivalent with callback of promised functions
26
- //*****************************************************************
21
+ get info() {
22
+ return this.#conn.info;
23
+ }
27
24
 
28
- const _commitCallback = (callback) => {
29
- commitPromise()
30
- .then(() => {
31
- if (callback) callback(null, null, null);
32
- })
33
- .catch(callback || emptyError);
34
- };
25
+ #noop = () => {};
35
26
 
36
- const _rollbackCallback = (callback) => {
37
- rollbackPromise()
38
- .then(() => {
39
- if (callback) callback(null, null, null);
40
- })
41
- .catch(callback || emptyError);
27
+ release = (cb) => {
28
+ this.#conn.release(() => {
29
+ if (cb) cb();
30
+ });
42
31
  };
43
32
 
44
- const _pingCallback = (timeout, callback) => {
45
- let _timeout, _cb;
46
- if (typeof timeout === 'function') {
47
- _cb = timeout;
48
- _timeout = undefined;
33
+ /**
34
+ * Permit changing user during connection.
35
+ * All user variables will be reset, Prepare commands will be released.
36
+ * !!! mysql has a bug when CONNECT_ATTRS capability is set, that is default !!!!
37
+ *
38
+ * @param options connection options
39
+ * @param callback callback function
40
+ */
41
+ changeUser(options, callback) {
42
+ let _options, _cb;
43
+ if (typeof options === 'function') {
44
+ _cb = options;
45
+ _options = undefined;
49
46
  } else {
50
- _timeout = timeout;
47
+ _options = options;
51
48
  _cb = callback;
52
49
  }
53
- pingPromise(_timeout)
54
- .then(_cb || emptySuccess)
55
- .catch(_cb || emptyError);
56
- };
50
+ const cmdParam = {
51
+ opts: _options,
52
+ callback: _cb
53
+ };
54
+ if (this.#conn.opts.trace) Error.captureStackTrace(cmdParam);
57
55
 
58
- const _resetCallback = (callback) => {
59
- resetPromise()
60
- .then(callback || emptySuccess)
61
- .catch(callback || emptyError);
62
- };
63
-
64
- const _beginTransactionCallback = (callback) => {
65
- queryPromise('START TRANSACTION')
56
+ new Promise(this.#conn.changeUser.bind(this.#conn, cmdParam))
66
57
  .then(() => {
67
- if (callback) callback(null, null, null);
58
+ if (cmdParam.callback) cmdParam.callback(null, null, null);
68
59
  })
69
- .catch(callback || emptyError);
70
- };
60
+ .catch(cmdParam.callback || this.#noop);
61
+ }
71
62
 
72
- const _endCallback = (callback) => {
73
- endPromise()
74
- .then(callback || emptySuccess)
75
- .catch(callback || emptyError);
76
- };
63
+ /**
64
+ * Start transaction
65
+ *
66
+ * @param callback callback function
67
+ */
68
+ beginTransaction(callback) {
69
+ this.query('START TRANSACTION', null, callback);
70
+ }
77
71
 
78
- const _connectCallback = function (callback) {
79
- if (!callback) {
80
- throw new Errors.createError(
81
- 'missing callback parameter',
82
- null,
83
- false,
84
- this.info,
85
- 'HY000',
86
- Errors.ER_MISSING_PARAMETER
72
+ /**
73
+ * Commit a transaction.
74
+ *
75
+ * @param callback callback function
76
+ */
77
+ commit(callback) {
78
+ this.#conn.changeTransaction(
79
+ { sql: 'COMMIT' },
80
+ () => {
81
+ if (callback) callback(null, null, null);
82
+ },
83
+ callback || this.#noop
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Roll back a transaction.
89
+ *
90
+ * @param callback callback function
91
+ */
92
+ rollback(callback) {
93
+ this.#conn.changeTransaction(
94
+ { sql: 'ROLLBACK' },
95
+ () => {
96
+ if (callback) callback(null, null, null);
97
+ },
98
+ callback || this.#noop
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Execute query using text protocol with callback emit columns/data/end/error
104
+ * events to permit streaming big result-set
105
+ *
106
+ * @param sql sql parameter Object can be used to supersede default option.
107
+ * Object must then have sql property.
108
+ * @param values object / array of placeholder values (not mandatory)
109
+ * @param callback callback function
110
+ */
111
+ query(sql, values, callback) {
112
+ const cmdParam = ConnectionCallback._PARAM(this.#conn.opts, sql, values, callback);
113
+ return ConnectionCallback._QUERY_CMD(this.#conn, cmdParam);
114
+ }
115
+
116
+ /**
117
+ * Execute a query returning a Readable Object that will emit columns/data/end/error events
118
+ * to permit streaming big result-set
119
+ *
120
+ * @param sql sql parameter Object can be used to supersede the default option.
121
+ * Object must then have `sql` property.
122
+ * @param values object / array of placeholder values (not mandatory)
123
+ * @returns {Readable}
124
+ */
125
+ queryStream(sql, values) {
126
+ const cmdParam = ConnectionCallback._PARAM(this.#conn.opts, sql, values);
127
+ const cmd = ConnectionCallback._QUERY_CMD(this.#conn, cmdParam);
128
+ return cmd.stream();
129
+ }
130
+
131
+ static _QUERY_CMD(conn, cmdParam) {
132
+ let cmd;
133
+ if (cmdParam.callback) {
134
+ cmdParam.opts = cmdParam.opts ? Object.assign(cmdParam.opts, { metaAsArray: true }) : { metaAsArray: true };
135
+ cmd = new Query(
136
+ ([rows, meta]) => {
137
+ cmdParam.callback(null, rows, meta);
138
+ },
139
+ cmdParam.callback,
140
+ conn.opts,
141
+ cmdParam
142
+ );
143
+ } else {
144
+ cmd = new Query(
145
+ () => {},
146
+ () => {},
147
+ conn.opts,
148
+ cmdParam
87
149
  );
88
150
  }
89
151
 
90
- if (connecting === 1) {
91
- this.on('connect', callback);
152
+ cmd.handleNewRows = (row) => {
153
+ cmd._rows[cmd._responseIndex].push(row);
154
+ cmd.emit('data', row);
155
+ };
156
+
157
+ conn.addCommand(cmd, true);
158
+ cmd.stream = (opt) => cmd._stream(conn.socket, opt);
159
+ return cmd;
160
+ }
161
+
162
+ execute(sql, values, callback) {
163
+ const cmdParam = ConnectionCallback._PARAM(this.#conn.opts, sql, values, callback);
164
+ cmdParam.opts = cmdParam.opts ? Object.assign(cmdParam.opts, { metaAsArray: true }) : { metaAsArray: true };
165
+ this.#conn.prepareExecute(
166
+ cmdParam,
167
+ ([rows, meta]) => {
168
+ if (cmdParam.callback) {
169
+ cmdParam.callback(null, rows, meta);
170
+ }
171
+ },
172
+ (err) => {
173
+ if (cmdParam.callback) {
174
+ cmdParam.callback(err);
175
+ }
176
+ }
177
+ );
178
+ }
179
+
180
+ static _PARAM(options, sql, values, callback) {
181
+ let _cmdOpt,
182
+ _sql,
183
+ _values = values,
184
+ _cb = callback;
185
+ if (typeof values === 'function') {
186
+ _cb = values;
187
+ _values = undefined;
188
+ }
189
+ if (typeof sql === 'object') {
190
+ _cmdOpt = sql;
191
+ _sql = _cmdOpt.sql;
192
+ if (_cmdOpt.values) _values = _cmdOpt.values;
193
+ } else {
194
+ _sql = sql;
195
+ }
196
+
197
+ const cmdParam = {
198
+ sql: _sql,
199
+ values: _values,
200
+ opts: _cmdOpt,
201
+ callback: _cb
202
+ };
203
+ if (options.trace) Error.captureStackTrace(cmdParam, ConnectionCallback._PARAM);
204
+ return cmdParam;
205
+ }
206
+
207
+ static _EXECUTE_CMD(conn, cmdParam) {
208
+ new Promise(conn.prepare.bind(conn, cmdParam))
209
+ .then((prepare) => {
210
+ const opts = cmdParam.opts ? Object.assign(cmdParam.opts, { metaAsArray: true }) : { metaAsArray: true };
211
+ return prepare
212
+ .execute(cmdParam.values, opts, null, cmdParam.stack)
213
+ .then(([rows, meta]) => {
214
+ if (cmdParam.callback) {
215
+ cmdParam.callback(null, rows, meta);
216
+ }
217
+ })
218
+ .finally(() => prepare.close());
219
+ })
220
+ .catch((err) => {
221
+ if (conn.opts.logger.error) conn.opts.logger.error(err);
222
+ if (cmdParam.callback) cmdParam.callback(err);
223
+ });
224
+ }
225
+
226
+ prepare(sql, callback) {
227
+ let _cmdOpt, _sql;
228
+ if (typeof sql === 'object') {
229
+ _cmdOpt = sql;
230
+ _sql = _cmdOpt.sql;
92
231
  } else {
93
- switch (this._status()) {
94
- case Status.CLOSING:
95
- case Status.CLOSED:
96
- callback(
97
- Errors.createError(
98
- 'Connection closed',
99
- null,
100
- true,
101
- this.info,
102
- '08S01',
103
- Errors.ER_CONNECTION_ALREADY_CLOSED
104
- )
105
- );
106
- break;
107
-
108
- default:
109
- callback();
232
+ _sql = sql;
233
+ }
234
+ const cmdParam = {
235
+ sql: _sql,
236
+ opts: _cmdOpt,
237
+ callback: callback
238
+ };
239
+ if (this.#conn.opts.trace) Error.captureStackTrace(cmdParam);
240
+ return new Promise(this.#conn.prepare.bind(this.#conn, cmdParam))
241
+ .then((prepare) => {
242
+ if (callback) callback(null, prepare, null);
243
+ })
244
+ .catch(callback || this.#noop);
245
+ }
246
+
247
+ /**
248
+ * Execute a batch
249
+ * events to permit streaming big result-set
250
+ *
251
+ * @param sql sql parameter Object can be used to supersede the default options.
252
+ * Object must then have `sql` property.
253
+ * @param values object / array of placeholder values (not mandatory)
254
+ * @param callback callback
255
+ */
256
+ batch(sql, values, callback) {
257
+ const cmdParam = ConnectionCallback._PARAM(this.#conn.opts, sql, values, callback);
258
+ this.#conn.batch(
259
+ cmdParam,
260
+ (res) => {
261
+ if (cmdParam.callback) cmdParam.callback(null, res);
262
+ },
263
+ (err) => {
264
+ if (cmdParam.callback) cmdParam.callback(err);
110
265
  }
266
+ );
267
+ }
268
+
269
+ /**
270
+ * Import sql file.
271
+ *
272
+ * @param opts JSON array with 2 possible fields: file and database
273
+ * @param cb callback
274
+ */
275
+ importFile(opts, cb) {
276
+ if (!opts || !opts.file) {
277
+ if (cb)
278
+ cb(
279
+ Errors.createError(
280
+ 'SQL file parameter is mandatory',
281
+ Errors.ER_MISSING_SQL_PARAMETER,
282
+ this.#conn.info,
283
+ 'HY000',
284
+ null,
285
+ false,
286
+ null
287
+ )
288
+ );
289
+ return;
111
290
  }
112
- };
291
+ new Promise(this.#conn.importFile.bind(this.#conn, { file: opts.file, database: opts.database }))
292
+ .then(() => {
293
+ if (cb) cb();
294
+ })
295
+ .catch((err) => {
296
+ if (cb) cb(err);
297
+ });
298
+ }
113
299
 
114
- const _changeUserCallback = (options, callback) => {
115
- let _options, _cb;
116
- if (typeof options === 'function') {
117
- _cb = options;
118
- _options = undefined;
300
+ /**
301
+ * Send an empty MySQL packet to ensure connection is active, and reset @@wait_timeout
302
+ * @param timeout (optional) timeout value in ms. If reached, throw error and close connection
303
+ * @param callback callback
304
+ */
305
+ ping(timeout, callback) {
306
+ let _cmdOpt = {},
307
+ _cb;
308
+ if (typeof timeout === 'function') {
309
+ _cb = timeout;
119
310
  } else {
120
- _options = options;
311
+ _cmdOpt.timeout = timeout;
121
312
  _cb = callback;
122
313
  }
314
+ const cmdParam = {
315
+ opts: _cmdOpt,
316
+ callback: _cb
317
+ };
318
+ if (this.#conn.opts.trace) Error.captureStackTrace(cmdParam);
319
+ new Promise(this.#conn.ping.bind(this.#conn, cmdParam)).then(_cb || this.#noop).catch(_cb || this.#noop);
320
+ }
321
+
322
+ /**
323
+ * Send a reset command that will
324
+ * - rollback any open transaction
325
+ * - reset transaction isolation level
326
+ * - reset session variables
327
+ * - delete user variables
328
+ * - remove temporary tables
329
+ * - remove all PREPARE statement
330
+ *
331
+ * @param callback callback
332
+ */
333
+ reset(callback) {
334
+ const cmdParam = {};
335
+ if (this.#conn.opts.trace) Error.captureStackTrace(cmdParam);
336
+ return new Promise(this.#conn.reset.bind(this.#conn, cmdParam))
337
+ .then(callback || this.#noop)
338
+ .catch(callback || this.#noop);
339
+ }
340
+
341
+ /**
342
+ * Indicates the state of the connection as the driver knows it
343
+ * @returns {boolean}
344
+ */
345
+ isValid() {
346
+ return this.#conn.isValid();
347
+ }
123
348
 
124
- changeUserPromise(_options)
349
+ /**
350
+ * Terminate connection gracefully.
351
+ *
352
+ * @param callback callback
353
+ */
354
+ end(callback) {
355
+ const cmdParam = {};
356
+ if (this.#conn.opts.trace) Error.captureStackTrace(cmdParam);
357
+ new Promise(this.#conn.end.bind(this.#conn, cmdParam))
125
358
  .then(() => {
126
- if (_cb) _cb(null, null, null);
359
+ if (callback) callback();
127
360
  })
128
- .catch(_cb || emptyError);
129
- };
361
+ .catch(callback || this.#noop);
362
+ }
363
+
364
+ /**
365
+ * Alias for destroy.
366
+ */
367
+ close() {
368
+ this.destroy();
369
+ }
370
+
371
+ /**
372
+ * Force connection termination by closing the underlying socket and killing server process if any.
373
+ */
374
+ destroy() {
375
+ this.#conn.destroy();
376
+ }
377
+
378
+ pause() {
379
+ this.#conn.pause();
380
+ }
381
+
382
+ resume() {
383
+ this.#conn.resume();
384
+ }
385
+
386
+ format(sql, values) {
387
+ this.#conn.format(sql, values);
388
+ }
389
+
390
+ /**
391
+ * return current connected server version information.
392
+ *
393
+ * @returns {*}
394
+ */
395
+ serverVersion() {
396
+ return this.#conn.serverVersion();
397
+ }
398
+
399
+ /**
400
+ * Change option "debug" during connection.
401
+ * @param val debug value
402
+ */
403
+ debug(val) {
404
+ return this.#conn.debug(val);
405
+ }
406
+
407
+ debugCompress(val) {
408
+ return this.#conn.debugCompress(val);
409
+ }
410
+
411
+ escape(val) {
412
+ return this.#conn.escape(val);
413
+ }
414
+
415
+ escapeId(val) {
416
+ return this.#conn.escapeId(val);
417
+ }
130
418
 
131
419
  //*****************************************************************
132
- // replacing public promise function with callback equivalent
420
+ // internal public testing methods
133
421
  //*****************************************************************
134
422
 
135
- this.commit = _commitCallback;
136
- this.rollback = _rollbackCallback;
137
- this.ping = _pingCallback;
138
- this.reset = _resetCallback;
139
- this.end = _endCallback;
140
- this.connect = _connectCallback;
141
- this.changeUser = _changeUserCallback;
142
- this.query = this._queryCallback;
143
- this.batch = this._batchCallback;
144
- this.beginTransaction = _beginTransactionCallback;
145
-
146
- const self = this;
147
- connectPromise()
148
- .then(() => {
149
- connecting = 0;
150
- self.emit('connect');
151
- })
152
- .catch((err) => {
153
- connecting = 0;
154
- self.emit('connect', err);
155
- });
156
- }
423
+ get __tests() {
424
+ return this.#conn.__tests;
425
+ }
426
+
427
+ connect(callback) {
428
+ if (!callback) {
429
+ throw new Errors.createError(
430
+ 'missing mandatory callback parameter',
431
+ Errors.ER_MISSING_PARAMETER,
432
+ this.#conn.info
433
+ );
434
+ }
435
+ switch (this.#conn.status) {
436
+ case Status.NOT_CONNECTED:
437
+ case Status.CONNECTING:
438
+ case Status.AUTHENTICATING:
439
+ case Status.INIT_CMD:
440
+ this.once('connect', callback);
441
+ break;
442
+ case Status.CONNECTED:
443
+ callback.call(this);
444
+ break;
445
+ case Status.CLOSING:
446
+ case Status.CLOSED:
447
+ callback.call(
448
+ this,
449
+ Errors.createError(
450
+ 'Connection closed',
451
+ Errors.ER_CONNECTION_ALREADY_CLOSED,
452
+ this.#conn.info,
453
+ '08S01',
454
+ null,
455
+ true
456
+ )
457
+ );
458
+ break;
459
+ }
460
+ }
461
+
462
+ //*****************************************************************
463
+ // EventEmitter proxy methods
464
+ //*****************************************************************
465
+
466
+ on(eventName, listener) {
467
+ this.#conn.on.call(this.#conn, eventName, listener);
468
+ return this;
469
+ }
470
+
471
+ off(eventName, listener) {
472
+ this.#conn.off.call(this.#conn, eventName, listener);
473
+ return this;
474
+ }
157
475
 
158
- util.inherits(ConnectionCallback, Connection);
476
+ once(eventName, listener) {
477
+ this.#conn.once.call(this.#conn, eventName, listener);
478
+ return this;
479
+ }
480
+
481
+ listeners(eventName) {
482
+ return this.#conn.listeners.call(this.#conn, eventName);
483
+ }
484
+
485
+ addListener(eventName, listener) {
486
+ this.#conn.addListener.call(this.#conn, eventName, listener);
487
+ return this;
488
+ }
489
+
490
+ eventNames() {
491
+ return this.#conn.eventNames.call(this.#conn);
492
+ }
493
+
494
+ getMaxListeners() {
495
+ return this.#conn.getMaxListeners.call(this.#conn);
496
+ }
497
+
498
+ listenerCount(eventName, listener) {
499
+ return this.#conn.listenerCount.call(this.#conn, eventName, listener);
500
+ }
501
+
502
+ prependListener(eventName, listener) {
503
+ this.#conn.prependListener.call(this.#conn, eventName, listener);
504
+ return this;
505
+ }
506
+
507
+ prependOnceListener(eventName, listener) {
508
+ this.#conn.prependOnceListener.call(this.#conn, eventName, listener);
509
+ return this;
510
+ }
511
+
512
+ removeAllListeners(eventName, listener) {
513
+ this.#conn.removeAllListeners.call(this.#conn, eventName, listener);
514
+ return this;
515
+ }
516
+
517
+ removeListener(eventName, listener) {
518
+ this.#conn.removeListener.call(this.#conn, eventName, listener);
519
+ return this;
520
+ }
521
+
522
+ setMaxListeners(n) {
523
+ this.#conn.setMaxListeners.call(this.#conn, n);
524
+ return this;
525
+ }
526
+
527
+ rawListeners(eventName) {
528
+ return this.#conn.rawListeners.call(this.#conn, eventName);
529
+ }
530
+ }
159
531
 
160
532
  module.exports = ConnectionCallback;