mysql2 3.23.2 → 3.23.3-canary.361d232

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.
@@ -104,7 +104,8 @@ class BaseConnection extends EventEmitter {
104
104
  this.handlePacket(p);
105
105
  });
106
106
  this.stream.on('data', (data) => {
107
- if (this.connectTimeout) {
107
+ // Server-side connections do not run ClientHandshake.
108
+ if (this.connectTimeout && this.config.isServer) {
108
109
  Timers.clearTimeout(this.connectTimeout);
109
110
  this.connectTimeout = null;
110
111
  }
@@ -133,6 +134,10 @@ class BaseConnection extends EventEmitter {
133
134
  if (!this.config.isServer) {
134
135
  handshakeCommand = new Commands.ClientHandshake(this.config.clientFlags);
135
136
  handshakeCommand.on('end', () => {
137
+ if (this.connectTimeout) {
138
+ Timers.clearTimeout(this.connectTimeout);
139
+ this.connectTimeout = null;
140
+ }
136
141
  // this happens when handshake finishes early either because there was
137
142
  // some fatal error or the server sent an error packet instead of
138
143
  // an hello packet (for example, 'Too many connections' error)
@@ -160,7 +165,6 @@ class BaseConnection extends EventEmitter {
160
165
  connectChannel,
161
166
  () =>
162
167
  new Promise((resolve, reject) => {
163
- /* eslint-disable prefer-const */
164
168
  let onConnect, onError;
165
169
  onConnect = (param) => {
166
170
  this.removeListener('error', onError);
@@ -170,7 +174,6 @@ class BaseConnection extends EventEmitter {
170
174
  this.removeListener('connect', onConnect);
171
175
  reject(err);
172
176
  };
173
- /* eslint-enable prefer-const */
174
177
  this.once('connect', onConnect);
175
178
  this.once('error', onError);
176
179
  }),
@@ -271,13 +274,11 @@ class BaseConnection extends EventEmitter {
271
274
  // connection handshake is special because we allow it to be implicit
272
275
  // if error happened during handshake, but there are others commands in queue
273
276
  // then bubble error to other commands and not to connection
274
- } else if (
275
- !(
276
- this._command &&
277
- this._command.constructor === Commands.ClientHandshake &&
278
- this._commands.length > 0
279
- )
280
- ) {
277
+ } else if (!(
278
+ this._command &&
279
+ this._command.constructor === Commands.ClientHandshake &&
280
+ this._commands.length > 0
281
+ )) {
281
282
  bubbleErrorToConnection = true;
282
283
  }
283
284
  while ((command = this._commands.shift())) {
@@ -583,7 +584,7 @@ class BaseConnection extends EventEmitter {
583
584
  return cmd;
584
585
  }
585
586
 
586
- format(sql, values) {
587
+ format(sql, values, namedPlaceholders) {
587
588
  if (typeof this.config.queryFormat === 'function') {
588
589
  return this.config.queryFormat.call(
589
590
  this,
@@ -596,6 +597,9 @@ class BaseConnection extends EventEmitter {
596
597
  sql: sql,
597
598
  values: values,
598
599
  };
600
+ if (typeof namedPlaceholders !== 'undefined') {
601
+ opts.namedPlaceholders = namedPlaceholders;
602
+ }
599
603
  this._resolveNamedPlaceholders(opts);
600
604
  return SqlString.format(
601
605
  opts.sql,
@@ -619,7 +623,10 @@ class BaseConnection extends EventEmitter {
619
623
 
620
624
  _resolveNamedPlaceholders(options) {
621
625
  let unnamed;
622
- if (this.config.namedPlaceholders || options.namedPlaceholders) {
626
+ if (typeof options.namedPlaceholders === 'undefined') {
627
+ options.namedPlaceholders = this.config.namedPlaceholders;
628
+ }
629
+ if (options.namedPlaceholders) {
623
630
  if (Array.isArray(options.values)) {
624
631
  // if an array is provided as the values, assume the conversion is not necessary.
625
632
  // this allows the usage of unnamed placeholders even if the namedPlaceholders flag is enabled.
@@ -644,7 +651,8 @@ class BaseConnection extends EventEmitter {
644
651
  this._resolveNamedPlaceholders(cmdQuery);
645
652
  const rawSql = this.format(
646
653
  cmdQuery.sql,
647
- cmdQuery.values !== undefined ? cmdQuery.values : []
654
+ cmdQuery.values !== undefined ? cmdQuery.values : [],
655
+ cmdQuery.namedPlaceholders
648
656
  );
649
657
  cmdQuery.sql = rawSql;
650
658
 
@@ -997,7 +1005,6 @@ class BaseConnection extends EventEmitter {
997
1005
  return cb(null, this);
998
1006
  }
999
1007
 
1000
- /* eslint-disable prefer-const */
1001
1008
  let onError, onConnect;
1002
1009
 
1003
1010
  onError = (param) => {
@@ -1009,7 +1016,6 @@ class BaseConnection extends EventEmitter {
1009
1016
  this.removeListener('error', onError);
1010
1017
  cb(null, param);
1011
1018
  };
1012
- /* eslint-enable prefer-const */
1013
1019
 
1014
1020
  this.once('error', onError);
1015
1021
  this.once('connect', onConnect);
package/lib/base/pool.js CHANGED
@@ -53,6 +53,23 @@ class BasePool extends EventEmitter {
53
53
  }
54
54
  }
55
55
 
56
+ /**
57
+ * Creates a per-connection copy of the pool connection config.
58
+ *
59
+ * Commands like `changeUser` mutate `connection.config` in place. Sharing a
60
+ * single config object between every pooled connection made those mutations
61
+ * leak into connections created later. The prototype is preserved so the
62
+ * copy is still a `ConnectionConfig`.
63
+ */
64
+ _createConnectionConfig() {
65
+ const { connectionConfig } = this.config;
66
+
67
+ return Object.create(
68
+ Object.getPrototypeOf(connectionConfig),
69
+ Object.getOwnPropertyDescriptors(connectionConfig)
70
+ );
71
+ }
72
+
56
73
  getConnection(cb) {
57
74
  const _getConnection = (cb) => {
58
75
  if (this._closed) {
@@ -72,7 +89,7 @@ class BasePool extends EventEmitter {
72
89
  this._allConnections.length < this.config.connectionLimit
73
90
  ) {
74
91
  connection = new PoolConnection(this, {
75
- config: this.config.connectionConfig,
92
+ config: this._createConnectionConfig(),
76
93
  });
77
94
  this._allConnections.push(connection);
78
95
  return connection.connect((err) => {
@@ -254,7 +271,11 @@ class BasePool extends EventEmitter {
254
271
  });
255
272
  } catch (e) {
256
273
  conn.release();
257
- throw e;
274
+ if (typeof cmdQuery.onResult === 'function') {
275
+ cmdQuery.onResult(e);
276
+ } else {
277
+ cmdQuery.emit('error', e);
278
+ }
258
279
  }
259
280
  });
260
281
  return cmdQuery;
@@ -68,7 +68,8 @@ class RotateEvent {
68
68
  class FormatDescriptionEvent {
69
69
  constructor(packet) {
70
70
  this.binlogVersion = packet.readInt16();
71
- this.serverVersion = packet.readString(50).replace(/\u0000.*/, ''); // eslint-disable-line no-control-regex
71
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: the server version string is NUL-terminated
72
+ this.serverVersion = packet.readString(50).replace(/\u0000.*/, '');
72
73
  this.createTimestamp = packet.readInt32();
73
74
  this.eventHeaderLength = packet.readInt8(); // should be 19
74
75
  this.eventsLength = packet.readBuffer();
@@ -20,7 +20,12 @@ class Query extends Command {
20
20
  this.sql = options.sql;
21
21
  this.values = options.values;
22
22
  this._queryOptions = options;
23
- this.namedPlaceholders = options.namedPlaceholders || false;
23
+ this.namedPlaceholders = Object.prototype.hasOwnProperty.call(
24
+ options,
25
+ 'namedPlaceholders'
26
+ )
27
+ ? options.namedPlaceholders
28
+ : undefined;
24
29
  this.onResult = callback;
25
30
  this.timeout = options.timeout;
26
31
  this.queryTimeout = null;
@@ -44,7 +49,6 @@ class Query extends Command {
44
49
  throw new Error(err);
45
50
  }
46
51
 
47
- /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
48
52
  start(_packet, connection) {
49
53
  if (connection.config.debug) {
50
54
  console.log(' Sending query command: %s', this.sql);
@@ -33,7 +33,6 @@ class Queue {
33
33
  }
34
34
 
35
35
  function handleCompressedPacket(packet) {
36
- // eslint-disable-next-line consistent-this, no-invalid-this
37
36
  const connection = this;
38
37
  const deflatedLength = packet.readInt24();
39
38
  const body = packet.readBuffer();
@@ -71,7 +70,6 @@ function writeCompressed(buffer) {
71
70
  if (buffer.length > MAX_COMPRESSED_LENGTH) {
72
71
  for (start = 0; start < buffer.length; start += MAX_COMPRESSED_LENGTH) {
73
72
  writeCompressed.call(
74
- // eslint-disable-next-line no-invalid-this
75
73
  this,
76
74
  buffer.slice(start, start + MAX_COMPRESSED_LENGTH)
77
75
  );
@@ -79,7 +77,6 @@ function writeCompressed(buffer) {
79
77
  return;
80
78
  }
81
79
 
82
- // eslint-disable-next-line no-invalid-this, consistent-this
83
80
  const connection = this;
84
81
 
85
82
  let packetLen = buffer.length;
@@ -15,7 +15,6 @@ function toParameter(value, encoding, timezone, jsonAsString) {
15
15
  let type = Types.VAR_STRING;
16
16
  let length;
17
17
  let writer = function (value) {
18
- // eslint-disable-next-line no-invalid-this
19
18
  return Packet.prototype.writeLengthCodedString.call(this, value, encoding);
20
19
  };
21
20
  if (value !== null) {
@@ -41,7 +40,6 @@ function toParameter(value, encoding, timezone, jsonAsString) {
41
40
  type = Types.DATETIME;
42
41
  length = 12;
43
42
  writer = function (value) {
44
- // eslint-disable-next-line no-invalid-this
45
43
  return Packet.prototype.writeDate.call(this, value, timezone);
46
44
  };
47
45
  } else if (isJSON(value)) {
@@ -80,7 +80,6 @@ class ResultSetHeader {
80
80
  packet.readLengthCodedString(encoding);
81
81
  } else if (type === sessionInfoTypes.STATE_GTIDS) {
82
82
  // TODO: find if the first length coded string means anything. Usually comes as empty
83
- // eslint-disable-next-line no-unused-vars
84
83
  const _unknownString = packet.readLengthCodedString(encoding);
85
84
  const gtid = packet.readLengthCodedString(encoding);
86
85
  stateChanges.gtids = gtid.split(',');
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.23.2",
3
+ "version": "3.23.3-canary.361d232",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "typings": "typings/mysql/index",
7
7
  "type": "commonjs",
8
8
  "scripts": {
9
- "lint": "eslint . && prettier --check .",
10
- "lint:fix": "eslint . --fix && prettier --write .",
9
+ "lint": "biome lint --error-on-warnings && prettier --check .",
10
+ "lint:fix": "biome lint --write . && prettier --write .",
11
11
  "test": "poku",
12
12
  "test:bun": "bun poku",
13
13
  "test:deno": "deno run -A npm:poku",
@@ -56,7 +56,7 @@
56
56
  "aws-ssl-profiles": "^1.1.2",
57
57
  "denque": "^2.1.0",
58
58
  "generate-function": "^2.3.1",
59
- "iconv-lite": "^0.7.2",
59
+ "iconv-lite": "^0.7.3",
60
60
  "long": "^5.3.2",
61
61
  "lru.min": "^1.1.4",
62
62
  "named-placeholders": "^1.1.6",
@@ -66,30 +66,22 @@
66
66
  "@types/node": ">= 8"
67
67
  },
68
68
  "devDependencies": {
69
- "@eslint/eslintrc": "^3.3.3",
70
- "@eslint/js": "^9.39.2",
71
- "@eslint/markdown": "^8.0.1",
69
+ "@biomejs/biome": "^2.5.7",
72
70
  "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
73
- "@pokujs/multi-suite": "^1.0.0",
74
- "@rollup/plugin-commonjs": "^29.0.2",
71
+ "@pokujs/multi-suite": "^1.0.2",
72
+ "@rollup/plugin-commonjs": "^29.0.3",
75
73
  "@rollup/plugin-json": "^6.1.0",
76
74
  "@rollup/plugin-node-resolve": "^16.0.3",
77
- "@types/node": "^26.0.0",
78
- "@typescript-eslint/eslint-plugin": "^8.56.0",
79
- "@typescript-eslint/parser": "^8.56.0",
75
+ "@types/node": "^26.2.0",
80
76
  "assert-diff": "^3.0.4",
81
77
  "benchmark": "^2.1.4",
82
- "c8": "^11.0.0",
78
+ "c8": "^12.0.0",
83
79
  "error-stack-parser": "^2.1.4",
84
- "eslint-config-prettier": "^10.1.8",
85
- "eslint-plugin-async-await": "^0.0.0",
86
- "eslint-plugin-prettier": "^5.5.5",
87
- "globals": "^17.3.0",
88
- "poku": "^4.1.0",
80
+ "poku": "^4.5.0",
89
81
  "portfinder": "^1.0.38",
90
- "prettier": "^3.8.1",
91
- "rollup": "^4.59.0",
92
- "tsx": "^4.21.0",
93
- "typescript": "^5.9.3"
82
+ "prettier": "^3.9.6",
83
+ "rollup": "^4.62.4",
84
+ "tsx": "^4.23.11",
85
+ "typescript": "^7.0.2"
94
86
  }
95
87
  }
@@ -52,17 +52,13 @@ export declare function tracePromise<T extends object, R>(
52
52
  ): Promise<R>;
53
53
 
54
54
  export declare const queryChannel:
55
- | TracingChannel<QueryTraceContext>
56
- | undefined;
55
+ TracingChannel<QueryTraceContext> | undefined;
57
56
  export declare const executeChannel:
58
- | TracingChannel<ExecuteTraceContext>
59
- | undefined;
57
+ TracingChannel<ExecuteTraceContext> | undefined;
60
58
  export declare const connectChannel:
61
- | TracingChannel<ConnectTraceContext>
62
- | undefined;
59
+ TracingChannel<ConnectTraceContext> | undefined;
63
60
  export declare const poolConnectChannel:
64
- | TracingChannel<PoolConnectTraceContext>
65
- | undefined;
61
+ TracingChannel<PoolConnectTraceContext> | undefined;
66
62
 
67
63
  export declare function getServerContext(config: {
68
64
  socketPath?: string;