chore: Point mysql2 dependency to fork

I'd like some control over incoming changes to fit our use-case, and patch-package doesn't quite fulfil our needs.
This commit is contained in:
Linden committed 2021-10-16 10:20:35 +11:00
1 parent 29d28197bb
commit bacd9c171d
3 files changed
+11 -465

No files matched your search

+2 -2
View File
@@ -15,8 +15,8 @@
"@citizenfx/server": "^2.0.4780-1",
"connection-string-parser": "^1.0.4",
"github-version-checker": "^2.2.0",
"mysql2": "^2.3.0",
"postinstall-postinstall": "^2.1.0"
"mysql2": "https://github.com/overextended/node-mysql2.git",
"postinstall-postinstall": "^2.1.0"
},
"devDependencies": {
"copy-webpack-plugin": "^9.0.1",
-453
View File
@@ -1,453 +0,0 @@
diff --git a/node_modules/mysql2/lib/commands/execute.js b/node_modules/mysql2/lib/commands/execute.js
index d5c2d8a..8ab7304 100644
--- a/node_modules/mysql2/lib/commands/execute.js
+++ b/node_modules/mysql2/lib/commands/execute.js
@@ -85,10 +85,10 @@ class Execute extends Command {
if (!packet.isEOF()) {
return connection.protocolError('Expected EOF packet');
}
- this._rowParser = this.buildParserFromFields(
+ this._rowParser = new (this.buildParserFromFields(
this._fields[this._resultIndex],
connection
- );
+ ))();
return Execute.prototype.row;
}
}
diff --git a/node_modules/mysql2/lib/commands/query.js b/node_modules/mysql2/lib/commands/query.js
index 344b4ab..91424ee 100644
--- a/node_modules/mysql2/lib/commands/query.js
+++ b/node_modules/mysql2/lib/commands/query.js
@@ -9,7 +9,6 @@ const Command = require('./command.js');
const Packets = require('../packets/index.js');
const getTextParser = require('../parsers/text_parser.js');
const ServerStatus = require('../constants/server_status.js');
-const CharsetToEncoding = require('../constants/charset_encodings.js');
const EmptyPacket = new Packets.Packet(0, Buffer.allocUnsafe(4), 0, 4);
@@ -44,7 +43,8 @@ class Query extends Command {
throw new Error(err);
}
- start(packet, connection) {
+ /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
+ start(_packet, connection) {
if (connection.config.debug) {
// eslint-disable-next-line
console.log(' Sending query command: %s', this.sql);
@@ -212,7 +212,7 @@ class Query extends Command {
if (this._receivedFieldsCount === this._fieldCount) {
const fields = this._fields[this._resultIndex];
this.emit('fields', fields);
- this._rowParser = getTextParser(fields, this.options, connection.config);
+ this._rowParser = new (getTextParser(fields, this.options, connection.config))();
return Query.prototype.fieldsEOF;
}
return Query.prototype.readField;
@@ -226,7 +226,8 @@ class Query extends Command {
return this.row;
}
- row(packet) {
+ /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
+ row(packet, _connection) {
if (packet.isEOF()) {
const status = packet.eofStatusFlags();
const moreResults = status & ServerStatus.SERVER_MORE_RESULTS_EXISTS;
@@ -238,11 +239,10 @@ class Query extends Command {
}
let row;
try {
- row = new this._rowParser(
+ row = this._rowParser.next(
packet,
this._fields[this._resultIndex],
- this.options,
- CharsetToEncoding
+ this.options
);
} catch (err) {
this._localStreamError = err;
diff --git a/node_modules/mysql2/lib/connection.js b/node_modules/mysql2/lib/connection.js
index 47970e9..f802e2e 100644
--- a/node_modules/mysql2/lib/connection.js
+++ b/node_modules/mysql2/lib/connection.js
@@ -540,7 +540,6 @@ class Connection extends EventEmitter {
} else {
cmdQuery = Connection.createQuery(sql, values, cb, this.config);
}
- this._resolveNamedPlaceholders(cmdQuery);
const rawSql = this.format(cmdQuery.sql, cmdQuery.values !== undefined ? cmdQuery.values : []);
cmdQuery.sql = rawSql;
return this.addCommand(cmdQuery);
diff --git a/node_modules/mysql2/lib/packets/column_definition.js b/node_modules/mysql2/lib/packets/column_definition.js
index b17782b..cfaa43a 100644
--- a/node_modules/mysql2/lib/packets/column_definition.js
+++ b/node_modules/mysql2/lib/packets/column_definition.js
@@ -45,8 +45,10 @@ class ColumnDefinition {
this.characterSet = packet.readInt16();
this.encoding = CharsetToEncoding[this.characterSet];
this.name = StringParser.decode(
- this._buf.slice(_nameStart, _nameStart + _nameLength),
- this.encoding === 'binary' ? this._clientEncoding : this.encoding
+ this._buf,
+ this.encoding === 'binary' ? this._clientEncoding : this.encoding,
+ _nameStart,
+ _nameStart + _nameLength
);
this.columnLength = packet.readInt32();
this.columnType = packet.readInt8();
@@ -112,10 +114,20 @@ const addString = function(name) {
get: function() {
const start = this[`_${name}Start`];
const end = start + this[`_${name}Length`];
- return StringParser.decode(
- this._buf.slice(start, end),
- this.encoding === 'binary' ? this._clientEncoding : this.encoding
+ const val = StringParser.decode(
+ this._buf,
+ this.encoding === 'binary' ? this._clientEncoding : this.encoding,
+ start,
+ end
);
+ Object.defineProperty(this, name, {
+ value: val,
+ writable: false,
+ configurable: false,
+ enumerable: false
+ });
+
+ return val;
}
});
};
diff --git a/node_modules/mysql2/lib/packets/packet.js b/node_modules/mysql2/lib/packets/packet.js
index 90233c9..811b251 100644
--- a/node_modules/mysql2/lib/packets/packet.js
+++ b/node_modules/mysql2/lib/packets/packet.js
@@ -385,8 +385,10 @@ class Packet {
// TODO: Use characterSetCode to get proper encoding
// https://github.com/sidorares/node-mysql2/pull/374
return StringParser.decode(
- this.buffer.slice(this.offset - len, this.offset),
- encoding
+ this.buffer,
+ encoding,
+ this.offset - len,
+ this.offset
);
}
@@ -405,7 +407,7 @@ class Packet {
end = end + 1; // TODO: handle OOB check
}
this.offset = end + 1;
- return StringParser.decode(this.buffer.slice(start, end), encoding);
+ return StringParser.decode(this.buffer, encoding, start, end);
}
// TODO reuse?
@@ -419,8 +421,10 @@ class Packet {
}
this.offset += len;
return StringParser.decode(
- this.buffer.slice(this.offset - len, this.offset),
- encoding
+ this.buffer,
+ encoding,
+ this.offset - len,
+ this.offset
);
}
diff --git a/node_modules/mysql2/lib/parsers/binary_parser.js b/node_modules/mysql2/lib/parsers/binary_parser.js
index d20c87c..bbd2959 100644
--- a/node_modules/mysql2/lib/parsers/binary_parser.js
+++ b/node_modules/mysql2/lib/parsers/binary_parser.js
@@ -74,7 +74,7 @@ function readCodeFor(field, config, options, fieldNum) {
if (field.characterSet === Charsets.BINARY) {
return 'packet.readLengthCodedBuffer();';
}
- return `packet.readLengthCodedString(CharsetToEncoding[fields[${fieldNum}].characterSet])`;
+ return `packet.readLengthCodedString(fields[${fieldNum}].encoding)`;
}
}
@@ -87,12 +87,16 @@ function compile(fields, options, config) {
/* eslint-disable no-spaced-func */
/* eslint-disable no-unexpected-multiline */
- parserFn('(function(){')(
- 'return function BinaryRow(packet, fields, options, CharsetToEncoding) {'
- );
+ parserFn('(function(){');
+ parserFn('return class BinaryRow {');
+ parserFn('constructor() {');
+ parserFn('}');
+ parserFn('next(packet, fields, options) {');
if (options.rowsAsArray) {
parserFn(`const result = new Array(${fields.length});`);
+ } else {
+ parserFn("const result = {};");
}
const resultTables = {};
@@ -104,7 +108,7 @@ function compile(fields, options, config) {
}
resultTablesArray = Object.keys(resultTables);
for (i = 0; i < resultTablesArray.length; i++) {
- parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
+ parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
}
}
@@ -125,16 +129,16 @@ function compile(fields, options, config) {
if (typeof options.nestTables === 'string') {
tableName = helpers.srcEscape(fields[i].table);
- lvalue = `this[${helpers.srcEscape(
+ lvalue = `result[${helpers.srcEscape(
fields[i].table + options.nestTables + fields[i].name
)}]`;
} else if (options.nestTables === true) {
tableName = helpers.srcEscape(fields[i].table);
- lvalue = `this[${tableName}][${fieldName}]`;
+ lvalue = `result[${tableName}][${fieldName}]`;
} else if (options.rowsAsArray) {
lvalue = `result[${i.toString(10)}]`;
} else {
- lvalue = `this[${helpers.srcEscape(fields[i].name)}]`;
+ lvalue = `result[${helpers.srcEscape(fields[i].name)}]`;
}
// TODO: this used to be an optimisation ( if column marked as NOT_NULL don't include code to check null
@@ -158,10 +162,8 @@ function compile(fields, options, config) {
}
}
- if (options.rowsAsArray) {
- parserFn('return result;');
- }
-
+ parserFn('return result;');
+ parserFn('}');
parserFn('};')('})()');
/* eslint-enable no-trailing-spaces */
diff --git a/node_modules/mysql2/lib/parsers/parser_cache.js b/node_modules/mysql2/lib/parsers/parser_cache.js
index 2fa8cf0..509b5c6 100644
--- a/node_modules/mysql2/lib/parsers/parser_cache.js
+++ b/node_modules/mysql2/lib/parsers/parser_cache.js
@@ -20,13 +20,7 @@ function keyFromFields(type, fields, options, config) {
`/${options.dateStrings}`;
for (let i = 0; i < fields.length; ++i) {
const field = fields[i];
- res += `/${field.name}:${field.columnType}:${field.flags}:${
- field.characterSet
- }`;
-
- if (options.nestTables) {
- res += `:${field.table}`
- }
+ res += `/${field.name}:${field.columnType}:${field.length}:${field.schema}:${field.table}:${field.flags}:${field.characterSet}`;
}
return res;
}
diff --git a/node_modules/mysql2/lib/parsers/string.js b/node_modules/mysql2/lib/parsers/string.js
index 0739f17..5523fb2 100644
--- a/node_modules/mysql2/lib/parsers/string.js
+++ b/node_modules/mysql2/lib/parsers/string.js
@@ -2,14 +2,14 @@
const Iconv = require('iconv-lite');
-exports.decode = function(buffer, encoding, options) {
+exports.decode = function(buffer, encoding, start, end, options) {
if (Buffer.isEncoding(encoding)) {
- return buffer.toString(encoding);
+ return buffer.toString(encoding, start, end);
}
const decoder = Iconv.getDecoder(encoding, options || {});
- const res = decoder.write(buffer);
+ const res = decoder.write(buffer.slice(start, end));
const trail = decoder.end();
return trail ? res + trail : res;
diff --git a/node_modules/mysql2/lib/parsers/text_parser.js b/node_modules/mysql2/lib/parsers/text_parser.js
index eb777d8..8bde10b 100644
--- a/node_modules/mysql2/lib/parsers/text_parser.js
+++ b/node_modules/mysql2/lib/parsers/text_parser.js
@@ -70,27 +70,6 @@ function readCodeFor(type, charset, encodingExpr, config, options) {
}
function compile(fields, options, config) {
- // node-mysql typeCast compatibility wrapper
- // see https://github.com/mysqljs/mysql/blob/96fdd0566b654436624e2375c7b6604b1f50f825/lib/protocol/packets/Field.js
- function wrap(field, type, packet, encoding) {
- return {
- type: type,
- length: field.columnLength,
- db: field.schema,
- table: field.table,
- name: field.name,
- string: function() {
- return packet.readLengthCodedString(encoding);
- },
- buffer: function() {
- return packet.readLengthCodedBuffer();
- },
- geometry: function() {
- return packet.parseGeometryValue();
- }
- };
- }
-
// use global typeCast if current query doesn't specify one
if (
typeof config.typeCast === 'function' &&
@@ -100,77 +79,110 @@ function compile(fields, options, config) {
}
const parserFn = genFunc();
- let i = 0;
/* eslint-disable no-trailing-spaces */
/* eslint-disable no-spaced-func */
/* eslint-disable no-unexpected-multiline */
parserFn('(function () {')(
- 'return function TextRow(packet, fields, options, CharsetToEncoding) {'
+ 'return class TextRow {'
);
- if (options.rowsAsArray) {
- parserFn(`const result = new Array(${fields.length})`);
+ // constructor method
+ parserFn('constructor() {');
+ // node-mysql typeCast compatibility wrapper
+ // see https://github.com/mysqljs/mysql/blob/96fdd0566b654436624e2375c7b6604b1f50f825/lib/protocol/packets/Field.js
+ if (typeof options.typeCast === 'function') {
+ parserFn('const _this = this;');
+ for(let i=0; i<fields.length; ++i) {
+ const field = fields[i];
+ const encodingExpr = helpers.srcEscape(field.encoding);
+ const readCode = readCodeFor(
+ fields[i].columnType,
+ fields[i].characterSet,
+ encodingExpr,
+ config,
+ options
+ );
+ parserFn(`this.wrap${i} = {
+ type: ${helpers.srcEscape(typeNames[field.columnType])},
+ length: ${helpers.srcEscape(field.columnLength)},
+ db: ${helpers.srcEscape(field.schema)},
+ table: ${helpers.srcEscape(field.table)},
+ name: ${helpers.srcEscape(field.name)},
+ string: function() {
+ return _this.packet.readLengthCodedString(${encodingExpr});
+ },
+ buffer: function() {
+ return _this.packet.readLengthCodedBuffer();
+ },
+ geometry: function() {
+ return _this.packet.parseGeometryValue();
+ },
+ readNext: function() {
+ return _this.${readCode};
+ }
+ };`);
+ }
}
+ parserFn('}');
- if (typeof options.typeCast === 'function') {
- parserFn(`const wrap = ${wrap.toString()}`);
+ // next method
+ parserFn('next(packet, fields, options) {');
+ parserFn("this.packet = packet;");
+ if (options.rowsAsArray) {
+ parserFn(`const result = new Array(${fields.length});`);
+ } else {
+ parserFn("const result = {};");
}
const resultTables = {};
let resultTablesArray = [];
if (options.nestTables === true) {
- for (i = 0; i < fields.length; i++) {
+ for (let i = 0; i < fields.length; i++) {
resultTables[fields[i].table] = 1;
}
resultTablesArray = Object.keys(resultTables);
- for (i = 0; i < resultTablesArray.length; i++) {
- parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
+ for (let i = 0; i < resultTablesArray.length; i++) {
+ parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
}
}
let lvalue = '';
let fieldName = '';
- for (i = 0; i < fields.length; i++) {
+ for (let i = 0; i < fields.length; i++) {
fieldName = helpers.srcEscape(fields[i].name);
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`);
if (typeof options.nestTables === 'string') {
- lvalue = `this[${helpers.srcEscape(
+ lvalue = `result[${helpers.srcEscape(
fields[i].table + options.nestTables + fields[i].name
)}]`;
} else if (options.nestTables === true) {
- lvalue = `this[${helpers.srcEscape(fields[i].table)}][${fieldName}]`;
+ lvalue = `result[${helpers.srcEscape(fields[i].table)}][${fieldName}]`;
} else if (options.rowsAsArray) {
lvalue = `result[${i.toString(10)}]`;
} else {
- lvalue = `this[${fieldName}]`;
+ lvalue = `result[${fieldName}]`;
}
- const encodingExpr = `CharsetToEncoding[fields[${i}].characterSet]`;
- const readCode = readCodeFor(
- fields[i].columnType,
- fields[i].characterSet,
- encodingExpr,
- config,
- options
- );
if (typeof options.typeCast === 'function') {
- parserFn(
- `${lvalue} = options.typeCast(wrap(fields[${i}], ${helpers.srcEscape(
- typeNames[fields[i].columnType]
- )}, packet, ${encodingExpr}), function() { return ${readCode};})`
- );
+ parserFn(`${lvalue} = options.typeCast(this.wrap${i}, this.wrap${i}.readNext);`);
} else if (options.typeCast === false) {
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
} else {
+ const encodingExpr = `fields[${i}].encoding`;
+ const readCode = readCodeFor(
+ fields[i].columnType,
+ fields[i].characterSet,
+ encodingExpr,
+ config,
+ options
+ );
parserFn(`${lvalue} = ${readCode};`);
}
}
- if (options.rowsAsArray) {
- parserFn('return result;');
- }
-
+ parserFn('return result;');
+ parserFn('}');
parserFn('};')('})()');
/* eslint-enable no-trailing-spaces */
+9 -10
View File
@@ -395,10 +395,10 @@ cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"
denque@^1.4.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/denque/-/denque-1.5.1.tgz#07f670e29c9a78f8faecb2566a1e2c11929c5cbf"
integrity sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==
denque@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/denque/-/denque-2.0.1.tgz#bcef4c1b80dc32efe97515744f21a4229ab8934a"
integrity sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==
dir-glob@^3.0.1:
version "3.0.1"
@@ -654,7 +654,7 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
iconv-lite@^0.6.2:
iconv-lite@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==
@@ -879,14 +879,13 @@ minimist@^1.2.0:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
mysql2@^2.3.0:
"mysql2@https://github.com/overextended/node-mysql2.git":
version "2.3.0"
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-2.3.0.tgz#600f5cc27e397dfb77b59eac93666434f88e8079"
integrity sha512-0t5Ivps5Tdy5YHk5NdKwQhe/4Qyn2pload+S+UooDBvsqngtzujG1BaTWBihQLfeKO3t3122/GtusBtmHEHqww==
resolved "https://github.com/overextended/node-mysql2.git#694e1003732f048c91a2ab99f7a7667d88a02549"
dependencies:
denque "^1.4.1"
denque "^2.0.1"
generate-function "^2.3.1"
iconv-lite "^0.6.2"
iconv-lite "^0.6.3"
long "^4.0.0"
lru-cache "^6.0.0"
named-placeholders "^1.1.2"