Skip to content

Commit 3b25db2

Browse files
committed
This makes mysqljs easier to minify and support minifier mangle
1 parent 283425b commit 3b25db2

32 files changed

+66
-6
lines changed

lib/protocol/Protocol.js

+4-4
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Object.defineProperty(RowDataPacket.prototype, '_typeCast', {
1919
value : typeCast
2020
});
2121

22+
RowDataPacket.prototype.id = 'RowDataPacket';
23+
2224
function parse(parser, fieldPackets, typeCast, nestTables, connection) {
2325
var self = this;
2426
var next = function () {

lib/protocol/packets/SSLRequestPacket.js

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2
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

+2-2
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)