Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46db2cd

Browse filesBrowse files
lneves12lneves
authored and
lneves
committed
This makes mysqljs easier to minify and support minifier mangle
1 parent 0e6f861 commit 46db2cd
Copy full SHA for 46db2cd
Expand file treeCollapse file tree

32 files changed

+70
-6
lines changed

‎lib/protocol/Protocol.js

Copy file name to clipboardExpand all lines: lib/protocol/Protocol.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Protocol.prototype._enqueue = function(sequence) {
157157
self._emitPacket(packet);
158158
})
159159
.on('timeout', function() {
160-
var err = new Error(sequence.constructor.name + ' inactivity timeout');
160+
var err = new Error(sequence._id + ' inactivity timeout');
161161

162162
err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
163163
err.fatal = true;
@@ -206,7 +206,7 @@ Protocol.prototype._enqueue = function(sequence) {
206206

207207
Protocol.prototype._validateEnqueue = function _validateEnqueue(sequence) {
208208
var err;
209-
var prefix = 'Cannot enqueue ' + sequence.constructor.name;
209+
var prefix = 'Cannot enqueue ' + sequence._id;
210210

211211
if (this._fatalError) {
212212
err = new Error(prefix + ' after fatal error.');
@@ -253,7 +253,7 @@ Protocol.prototype._parsePacket = function() {
253253

254254
var Packet = this._determinePacket(sequence);
255255
var packet = new Packet({protocol41: this._config.protocol41});
256-
var packetName = Packet.name;
256+
var packetName = packet._id;
257257

258258
// Special case: Faster dispatch, and parsing done inside sequence
259259
if (Packet === Packets.RowDataPacket) {
@@ -447,7 +447,7 @@ Protocol.prototype._debugPacket = function(incoming, packet) {
447447
var direction = incoming
448448
? '<--'
449449
: '-->';
450-
var packetName = packet.constructor.name;
450+
var packetName = packet._id;
451451
var threadId = connection && connection.threadId !== null
452452
? ' (' + connection.threadId + ')'
453453
: '';

‎lib/protocol/packets/AuthSwitchRequestPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/AuthSwitchRequestPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function AuthSwitchRequestPacket(options) {
77
this.authMethodData = options.authMethodData;
88
}
99

10+
AuthSwitchRequestPacket.prototype._id = 'AuthSwitchRequestPacket';
11+
1012
AuthSwitchRequestPacket.prototype.parse = function parse(parser) {
1113
this.status = parser.parseUnsignedNumber(1);
1214
this.authMethodName = parser.parseNullTerminatedString();

‎lib/protocol/packets/AuthSwitchResponsePacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/AuthSwitchResponsePacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function AuthSwitchResponsePacket(options) {
55
this.data = options.data;
66
}
77

8+
AuthSwitchResponsePacket.prototype._id = 'AuthSwitchResponsePacket';
9+
810
AuthSwitchResponsePacket.prototype.parse = function parse(parser) {
911
this.data = parser.parsePacketTerminatedBuffer();
1012
};

‎lib/protocol/packets/ClientAuthenticationPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ClientAuthenticationPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function ClientAuthenticationPacket(options) {
1414
this.protocol41 = options.protocol41;
1515
}
1616

17+
ClientAuthenticationPacket.prototype._id = 'ClientAuthenticationPacket';
18+
1719
ClientAuthenticationPacket.prototype.parse = function(parser) {
1820
if (this.protocol41) {
1921
this.clientFlags = parser.parseUnsignedNumber(4);

‎lib/protocol/packets/ComChangeUserPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ComChangeUserPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function ComChangeUserPacket(options) {
99
this.charsetNumber = options.charsetNumber;
1010
}
1111

12+
ComChangeUserPacket.prototype._id = 'ComChangeUserPacket';
13+
1214
ComChangeUserPacket.prototype.parse = function(parser) {
1315
this.command = parser.parseUnsignedNumber(1);
1416
this.user = parser.parseNullTerminatedString();

‎lib/protocol/packets/ComPingPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ComPingPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function ComPingPacket() {
33
this.command = 0x0e;
44
}
55

6+
ComPingPacket.prototype._id = 'ComPingPacket';
7+
68
ComPingPacket.prototype.write = function(writer) {
79
writer.writeUnsignedNumber(1, this.command);
810
};

‎lib/protocol/packets/ComQueryPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ComQueryPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ function ComQueryPacket(sql) {
44
this.sql = sql;
55
}
66

7+
ComQueryPacket.prototype._id = 'ComQueryPacket';
8+
79
ComQueryPacket.prototype.write = function(writer) {
810
writer.writeUnsignedNumber(1, this.command);
911
writer.writeString(this.sql);

‎lib/protocol/packets/ComQuitPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ComQuitPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function ComQuitPacket() {
33
this.command = 0x01;
44
}
55

6+
ComQuitPacket.prototype._id = 'ComQuitPacket';
7+
68
ComQuitPacket.prototype.parse = function parse(parser) {
79
this.command = parser.parseUnsignedNumber(1);
810
};

‎lib/protocol/packets/ComStatisticsPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ComStatisticsPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function ComStatisticsPacket() {
33
this.command = 0x09;
44
}
55

6+
ComStatisticsPacket.prototype._id = 'ComStatisticsPacket';
7+
68
ComStatisticsPacket.prototype.write = function(writer) {
79
writer.writeUnsignedNumber(1, this.command);
810
};

‎lib/protocol/packets/EmptyPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/EmptyPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module.exports = EmptyPacket;
22
function EmptyPacket() {
33
}
44

5+
EmptyPacket.prototype._id = 'EmptyPacket';
6+
57
EmptyPacket.prototype.parse = function parse() {
68
};
79

‎lib/protocol/packets/EofPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/EofPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function EofPacket(options) {
88
this.protocol41 = options.protocol41;
99
}
1010

11+
EofPacket.prototype._id = 'EofPacket';
12+
1113
EofPacket.prototype.parse = function(parser) {
1214
this.fieldCount = parser.parseUnsignedNumber(1);
1315
if (this.protocol41) {

‎lib/protocol/packets/ErrorPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ErrorPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function ErrorPacket(options) {
99
this.message = options.message;
1010
}
1111

12+
ErrorPacket.prototype._id = 'ErrorPacket';
13+
1214
ErrorPacket.prototype.parse = function(parser) {
1315
this.fieldCount = parser.parseUnsignedNumber(1);
1416
this.errno = parser.parseUnsignedNumber(2);

‎lib/protocol/packets/Field.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/Field.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function Field(options) {
1313
this.length = options.packet.length;
1414
}
1515

16+
Field.prototype._id = 'Field';
17+
1618
Field.prototype.string = function () {
1719
return this.parser.parseLengthCodedString();
1820
};

‎lib/protocol/packets/FieldPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/FieldPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function FieldPacket(options) {
1818
this.protocol41 = options.protocol41;
1919
}
2020

21+
FieldPacket.prototype._id = 'FieldPacket';
22+
2123
FieldPacket.prototype.parse = function(parser) {
2224
if (this.protocol41) {
2325
this.catalog = parser.parseLengthCodedString();

‎lib/protocol/packets/HandshakeInitializationPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/HandshakeInitializationPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function HandshakeInitializationPacket(options) {
2727
}
2828
}
2929

30+
HandshakeInitializationPacket.prototype._id = 'HandshakeInitializationPacket';
31+
3032
HandshakeInitializationPacket.prototype.parse = function(parser) {
3133
this.protocolVersion = parser.parseUnsignedNumber(1);
3234
this.serverVersion = parser.parseNullTerminatedString();

‎lib/protocol/packets/LocalDataFilePacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/LocalDataFilePacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ function LocalDataFilePacket(data) {
1010
this.data = data;
1111
}
1212

13+
LocalDataFilePacket.prototype._id = 'LocalDataFilePacket';
14+
1315
LocalDataFilePacket.prototype.write = function(writer) {
1416
writer.writeBuffer(this.data);
1517
};

‎lib/protocol/packets/LocalInfileRequestPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/LocalInfileRequestPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function LocalInfileRequestPacket(options) {
55
this.filename = options.filename;
66
}
77

8+
LocalInfileRequestPacket.prototype._id = 'LocalInfileRequestPacket';
9+
810
LocalInfileRequestPacket.prototype.parse = function parse(parser) {
911
if (parser.parseLengthCodedNumber() !== null) {
1012
var err = new TypeError('Received invalid field length');

‎lib/protocol/packets/OkPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/OkPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function OkPacket(options) {
1515
this.protocol41 = options.protocol41;
1616
}
1717

18+
OkPacket.prototype._id = 'OkPacket';
19+
1820
OkPacket.prototype.parse = function(parser) {
1921
this.fieldCount = parser.parseUnsignedNumber(1);
2022
this.affectedRows = parser.parseLengthCodedNumber();

‎lib/protocol/packets/OldPasswordPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/OldPasswordPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function OldPasswordPacket(options) {
55
this.scrambleBuff = options.scrambleBuff;
66
}
77

8+
OldPasswordPacket.prototype._id = 'OldPasswordPacket';
9+
810
OldPasswordPacket.prototype.parse = function(parser) {
911
this.scrambleBuff = parser.parsePacketTerminatedBuffer();
1012
};

‎lib/protocol/packets/ResultSetHeaderPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/ResultSetHeaderPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function ResultSetHeaderPacket(options) {
55
this.fieldCount = options.fieldCount;
66
}
77

8+
ResultSetHeaderPacket.prototype._id = 'ResultSetHeaderPacket';
9+
810
ResultSetHeaderPacket.prototype.parse = function(parser) {
911
this.fieldCount = parser.parseLengthCodedNumber();
1012
};

‎lib/protocol/packets/RowDataPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/RowDataPacket.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Object.defineProperty(RowDataPacket.prototype, '_typeCast', {
1919
value : typeCast
2020
});
2121

22+
Object.defineProperty(RowDataPacket.prototype, '_id', {
23+
configurable : true,
24+
enumerable : false,
25+
value : 'RowDataPacket'
26+
});
27+
2228
function parse(parser, fieldPackets, typeCast, nestTables, connection) {
2329
var self = this;
2430
var next = function () {

‎lib/protocol/packets/SSLRequestPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/SSLRequestPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function SSLRequestPacket(options) {
1212
this.charsetNumber = options.charsetNumber;
1313
}
1414

15+
SSLRequestPacket.prototype._id = 'SSLRequestPacket';
16+
1517
SSLRequestPacket.prototype.parse = function(parser) {
1618
// TODO: check SSLRequest packet v41 vs pre v41
1719
this.clientFlags = parser.parseUnsignedNumber(4);

‎lib/protocol/packets/StatisticsPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/StatisticsPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function StatisticsPacket() {
33
this.message = undefined;
44
}
55

6+
StatisticsPacket.prototype._id = 'StatisticsPacket';
7+
68
StatisticsPacket.prototype.parse = function(parser) {
79
this.message = parser.parsePacketTerminatedString();
810

‎lib/protocol/packets/UseOldPasswordPacket.js

Copy file name to clipboardExpand all lines: lib/protocol/packets/UseOldPasswordPacket.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function UseOldPasswordPacket(options) {
55
this.firstByte = options.firstByte || 0xfe;
66
}
77

8+
UseOldPasswordPacket.prototype._id = 'UseOldPasswordPacket';
9+
810
UseOldPasswordPacket.prototype.parse = function(parser) {
911
this.firstByte = parser.parseUnsignedNumber(1);
1012
};

‎lib/protocol/sequences/ChangeUser.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/ChangeUser.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ChangeUser.prototype.determinePacket = function determinePacket(firstByte) {
2323
}
2424
};
2525

26+
ChangeUser.prototype._id = 'ChangeUser';
27+
2628
ChangeUser.prototype.start = function(handshakeInitializationPacket) {
2729
var scrambleBuff = handshakeInitializationPacket.scrambleBuff();
2830
scrambleBuff = Auth.token(this._password, scrambleBuff);

‎lib/protocol/sequences/Handshake.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Handshake.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Handshake.prototype.determinePacket = function determinePacket(firstByte, parser
3333
return undefined;
3434
};
3535

36+
Handshake.prototype._id = 'Handshake';
37+
3638
Handshake.prototype['AuthSwitchRequestPacket'] = function (packet) {
3739
var name = packet.authMethodName;
3840
var data = Auth.auth(name, packet.authMethodData, {

‎lib/protocol/sequences/Ping.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Ping.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function Ping(options, callback) {
1414
Sequence.call(this, options, callback);
1515
}
1616

17+
Ping.prototype._id = 'Ping';
18+
1719
Ping.prototype.start = function() {
1820
this.emit('packet', new Packets.ComPingPacket());
1921
};

‎lib/protocol/sequences/Query.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Query.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function Query(options, callback) {
2626
this._loadError = null;
2727
}
2828

29+
Query.prototype._id = 'Query';
30+
2931
Query.prototype.start = function() {
3032
this.emit('packet', new Packets.ComQueryPacket(this.sql));
3133
};

‎lib/protocol/sequences/Quit.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Quit.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function Quit(options, callback) {
1515
this._started = false;
1616
}
1717

18+
Quit.prototype._id = 'Quit';
19+
1820
Quit.prototype.end = function end(err) {
1921
if (this._ended) {
2022
return;

‎lib/protocol/sequences/Sequence.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Sequence.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Sequence.determinePacket = function(byte) {
3838
}
3939
};
4040

41+
Sequence.prototype._id = 'Sequence';
42+
4143
Sequence.prototype.hasErrorHandler = function() {
4244
return Boolean(this._callback) || listenerCount(this, 'error') > 1;
4345
};

‎lib/protocol/sequences/Statistics.js

Copy file name to clipboardExpand all lines: lib/protocol/sequences/Statistics.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function Statistics(options, callback) {
1313
Sequence.call(this, options, callback);
1414
}
1515

16+
Statistics.prototype._id = 'Statistics';
17+
1618
Statistics.prototype.start = function() {
1719
this.emit('packet', new Packets.ComStatisticsPacket());
1820
};

‎test/FakeServer.js

Copy file name to clipboardExpand all lines: test/FakeServer.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ FakeConnection.prototype._parsePacket = function _parsePacket(packetHeader) {
332332
}
333333
break;
334334
default:
335-
if (!this.emit(packet.constructor.name, packet)) {
336-
throw new Error('Unexpected packet: ' + Packet.name);
335+
if (!this.emit(packet._id, packet)) {
336+
throw new Error('Unexpected packet: ' + packet._id);
337337
}
338338
}
339339
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.