@depup/mysql2 3.19.0-depup.0

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 (124) hide show
  1. package/License +19 -0
  2. package/README.md +114 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +77 -0
  5. package/lib/auth_41.js +95 -0
  6. package/lib/auth_plugins/caching_sha2_password.js +114 -0
  7. package/lib/auth_plugins/caching_sha2_password.md +18 -0
  8. package/lib/auth_plugins/index.js +8 -0
  9. package/lib/auth_plugins/mysql_clear_password.js +17 -0
  10. package/lib/auth_plugins/mysql_native_password.js +34 -0
  11. package/lib/auth_plugins/sha256_password.js +68 -0
  12. package/lib/base/connection.js +988 -0
  13. package/lib/base/pool.js +282 -0
  14. package/lib/base/pool_connection.js +77 -0
  15. package/lib/commands/auth_switch.js +129 -0
  16. package/lib/commands/binlog_dump.js +109 -0
  17. package/lib/commands/change_user.js +68 -0
  18. package/lib/commands/client_handshake.js +383 -0
  19. package/lib/commands/close_statement.js +18 -0
  20. package/lib/commands/command.js +54 -0
  21. package/lib/commands/execute.js +112 -0
  22. package/lib/commands/index.js +27 -0
  23. package/lib/commands/ping.js +36 -0
  24. package/lib/commands/prepare.js +143 -0
  25. package/lib/commands/query.js +361 -0
  26. package/lib/commands/quit.js +29 -0
  27. package/lib/commands/register_slave.js +27 -0
  28. package/lib/commands/server_handshake.js +202 -0
  29. package/lib/compressed_protocol.js +153 -0
  30. package/lib/connection.js +12 -0
  31. package/lib/connection_config.js +293 -0
  32. package/lib/constants/charset_encodings.js +317 -0
  33. package/lib/constants/charsets.js +317 -0
  34. package/lib/constants/client.js +38 -0
  35. package/lib/constants/commands.js +36 -0
  36. package/lib/constants/cursor.js +8 -0
  37. package/lib/constants/encoding_charset.js +50 -0
  38. package/lib/constants/errors.js +3973 -0
  39. package/lib/constants/field_flags.js +20 -0
  40. package/lib/constants/server_status.js +44 -0
  41. package/lib/constants/session_track.js +11 -0
  42. package/lib/constants/ssl_profiles.js +11 -0
  43. package/lib/constants/types.js +64 -0
  44. package/lib/create_connection.js +10 -0
  45. package/lib/create_pool.js +10 -0
  46. package/lib/create_pool_cluster.js +9 -0
  47. package/lib/helpers.js +83 -0
  48. package/lib/packet_parser.js +195 -0
  49. package/lib/packets/auth_next_factor.js +35 -0
  50. package/lib/packets/auth_switch_request.js +38 -0
  51. package/lib/packets/auth_switch_request_more_data.js +33 -0
  52. package/lib/packets/auth_switch_response.js +30 -0
  53. package/lib/packets/binary_row.js +95 -0
  54. package/lib/packets/binlog_dump.js +33 -0
  55. package/lib/packets/binlog_query_statusvars.js +115 -0
  56. package/lib/packets/change_user.js +97 -0
  57. package/lib/packets/close_statement.js +21 -0
  58. package/lib/packets/column_definition.js +291 -0
  59. package/lib/packets/execute.js +214 -0
  60. package/lib/packets/handshake.js +112 -0
  61. package/lib/packets/handshake_response.js +173 -0
  62. package/lib/packets/index.js +152 -0
  63. package/lib/packets/packet.js +946 -0
  64. package/lib/packets/prepare_statement.js +27 -0
  65. package/lib/packets/prepared_statement_header.js +16 -0
  66. package/lib/packets/query.js +27 -0
  67. package/lib/packets/register_slave.js +46 -0
  68. package/lib/packets/resultset_header.js +124 -0
  69. package/lib/packets/ssl_request.js +25 -0
  70. package/lib/packets/text_row.js +47 -0
  71. package/lib/parsers/binary_parser.js +235 -0
  72. package/lib/parsers/parser_cache.js +68 -0
  73. package/lib/parsers/static_binary_parser.js +213 -0
  74. package/lib/parsers/static_text_parser.js +152 -0
  75. package/lib/parsers/string.js +50 -0
  76. package/lib/parsers/text_parser.js +214 -0
  77. package/lib/pool.js +12 -0
  78. package/lib/pool_cluster.js +375 -0
  79. package/lib/pool_config.js +30 -0
  80. package/lib/pool_connection.js +12 -0
  81. package/lib/promise/connection.js +228 -0
  82. package/lib/promise/inherit_events.js +27 -0
  83. package/lib/promise/make_done_cb.js +19 -0
  84. package/lib/promise/pool.js +118 -0
  85. package/lib/promise/pool_cluster.js +54 -0
  86. package/lib/promise/pool_connection.js +23 -0
  87. package/lib/promise/prepared_statement_info.js +32 -0
  88. package/lib/results_stream.js +38 -0
  89. package/lib/server.js +37 -0
  90. package/package.json +96 -0
  91. package/promise.d.ts +139 -0
  92. package/promise.js +208 -0
  93. package/typings/mysql/LICENSE.txt +15 -0
  94. package/typings/mysql/index.d.ts +84 -0
  95. package/typings/mysql/info.txt +1 -0
  96. package/typings/mysql/lib/Auth.d.ts +30 -0
  97. package/typings/mysql/lib/Connection.d.ts +442 -0
  98. package/typings/mysql/lib/Pool.d.ts +71 -0
  99. package/typings/mysql/lib/PoolCluster.d.ts +92 -0
  100. package/typings/mysql/lib/PoolConnection.d.ts +11 -0
  101. package/typings/mysql/lib/Server.d.ts +11 -0
  102. package/typings/mysql/lib/constants/CharsetToEncoding.d.ts +8 -0
  103. package/typings/mysql/lib/constants/Charsets.d.ts +326 -0
  104. package/typings/mysql/lib/constants/Types.d.ts +70 -0
  105. package/typings/mysql/lib/constants/index.d.ts +5 -0
  106. package/typings/mysql/lib/parsers/ParserCache.d.ts +4 -0
  107. package/typings/mysql/lib/parsers/index.d.ts +18 -0
  108. package/typings/mysql/lib/parsers/typeCast.d.ts +54 -0
  109. package/typings/mysql/lib/protocol/packets/Field.d.ts +10 -0
  110. package/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +27 -0
  111. package/typings/mysql/lib/protocol/packets/OkPacket.d.ts +23 -0
  112. package/typings/mysql/lib/protocol/packets/ProcedurePacket.d.ts +13 -0
  113. package/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts +18 -0
  114. package/typings/mysql/lib/protocol/packets/RowDataPacket.d.ts +9 -0
  115. package/typings/mysql/lib/protocol/packets/index.d.ts +28 -0
  116. package/typings/mysql/lib/protocol/packets/params/ErrorPacketParams.d.ts +6 -0
  117. package/typings/mysql/lib/protocol/packets/params/OkPacketParams.d.ts +9 -0
  118. package/typings/mysql/lib/protocol/sequences/ExecutableBase.d.ts +41 -0
  119. package/typings/mysql/lib/protocol/sequences/Prepare.d.ts +65 -0
  120. package/typings/mysql/lib/protocol/sequences/Query.d.ts +228 -0
  121. package/typings/mysql/lib/protocol/sequences/QueryableBase.d.ts +41 -0
  122. package/typings/mysql/lib/protocol/sequences/Sequence.d.ts +5 -0
  123. package/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts +17 -0
  124. package/typings/mysql/lib/protocol/sequences/promise/QueryableBase.d.ts +18 -0
@@ -0,0 +1,143 @@
1
+ 'use strict';
2
+
3
+ const Packets = require('../packets/index.js');
4
+ const Command = require('./command.js');
5
+ const CloseStatement = require('./close_statement.js');
6
+ const Execute = require('./execute.js');
7
+
8
+ class PreparedStatementInfo {
9
+ constructor(query, id, columns, parameters, connection) {
10
+ this.query = query;
11
+ this.id = id;
12
+ this.columns = columns;
13
+ this.parameters = parameters;
14
+ this.rowParser = null;
15
+ this._connection = connection;
16
+ }
17
+
18
+ close() {
19
+ return this._connection.addCommand(new CloseStatement(this.id));
20
+ }
21
+
22
+ execute(parameters, callback) {
23
+ if (typeof parameters === 'function') {
24
+ callback = parameters;
25
+ parameters = [];
26
+ }
27
+ return this._connection.addCommand(
28
+ new Execute({ statement: this, values: parameters }, callback)
29
+ );
30
+ }
31
+ }
32
+
33
+ class Prepare extends Command {
34
+ constructor(options, callback) {
35
+ super();
36
+ this.query = options.sql;
37
+ this.onResult = callback;
38
+ this.id = 0;
39
+ this.fieldCount = 0;
40
+ this.parameterCount = 0;
41
+ this.fields = [];
42
+ this.parameterDefinitions = [];
43
+ this.options = options;
44
+ }
45
+
46
+ start(packet, connection) {
47
+ const Connection = connection.constructor;
48
+ this.key = Connection.statementKey(this.options);
49
+ const statement = connection._statements.get(this.key);
50
+ if (statement) {
51
+ if (this.onResult) {
52
+ this.onResult(null, statement);
53
+ }
54
+ return null;
55
+ }
56
+ const cmdPacket = new Packets.PrepareStatement(
57
+ this.query,
58
+ connection.config.charsetNumber,
59
+ this.options.values
60
+ );
61
+ connection.writePacket(cmdPacket.toPacket(1));
62
+ return Prepare.prototype.prepareHeader;
63
+ }
64
+
65
+ prepareHeader(packet, connection) {
66
+ const header = new Packets.PreparedStatementHeader(packet);
67
+ this.id = header.id;
68
+ this.fieldCount = header.fieldCount;
69
+ this.parameterCount = header.parameterCount;
70
+ if (this.parameterCount > 0) {
71
+ return Prepare.prototype.readParameter;
72
+ }
73
+ if (this.fieldCount > 0) {
74
+ return Prepare.prototype.readField;
75
+ }
76
+ return this.prepareDone(connection);
77
+ }
78
+
79
+ readParameter(packet, connection) {
80
+ // there might be scenarios when mysql server reports more parameters than
81
+ // are actually present in the array of parameter definitions.
82
+ // if EOF packet is received we switch to "read fields" state if there are
83
+ // any fields reported by the server, otherwise we finish the command.
84
+ if (packet.isEOF()) {
85
+ if (this.fieldCount > 0) {
86
+ return Prepare.prototype.readField;
87
+ }
88
+ return this.prepareDone(connection);
89
+ }
90
+ const def = new Packets.ColumnDefinition(packet, connection.clientEncoding);
91
+ this.parameterDefinitions.push(def);
92
+ if (this.parameterDefinitions.length === this.parameterCount) {
93
+ return Prepare.prototype.parametersEOF;
94
+ }
95
+ return this.readParameter;
96
+ }
97
+
98
+ readField(packet, connection) {
99
+ if (packet.isEOF()) {
100
+ return this.prepareDone(connection);
101
+ }
102
+ const def = new Packets.ColumnDefinition(packet, connection.clientEncoding);
103
+ this.fields.push(def);
104
+ if (this.fields.length === this.fieldCount) {
105
+ return Prepare.prototype.fieldsEOF;
106
+ }
107
+ return Prepare.prototype.readField;
108
+ }
109
+
110
+ parametersEOF(packet, connection) {
111
+ if (!packet.isEOF()) {
112
+ return connection.protocolError('Expected EOF packet after parameters');
113
+ }
114
+ if (this.fieldCount > 0) {
115
+ return Prepare.prototype.readField;
116
+ }
117
+ return this.prepareDone(connection);
118
+ }
119
+
120
+ fieldsEOF(packet, connection) {
121
+ if (!packet.isEOF()) {
122
+ return connection.protocolError('Expected EOF packet after fields');
123
+ }
124
+ return this.prepareDone(connection);
125
+ }
126
+
127
+ prepareDone(connection) {
128
+ const statement = new PreparedStatementInfo(
129
+ this.query,
130
+ this.id,
131
+ this.fields,
132
+ this.parameterDefinitions,
133
+ connection
134
+ );
135
+ connection._statements.set(this.key, statement);
136
+ if (this.onResult) {
137
+ this.onResult(null, statement);
138
+ }
139
+ return null;
140
+ }
141
+ }
142
+
143
+ module.exports = Prepare;
@@ -0,0 +1,361 @@
1
+ 'use strict';
2
+
3
+ const process = require('process');
4
+ const Timers = require('timers');
5
+
6
+ const Readable = require('stream').Readable;
7
+
8
+ const Command = require('./command.js');
9
+ const Packets = require('../packets/index.js');
10
+ const getTextParser = require('../parsers/text_parser.js');
11
+ const staticParser = require('../parsers/static_text_parser.js');
12
+ const ServerStatus = require('../constants/server_status.js');
13
+
14
+ const EmptyPacket = new Packets.Packet(0, Buffer.allocUnsafe(4), 0, 4);
15
+
16
+ // http://dev.mysql.com/doc/internals/en/com-query.html
17
+ class Query extends Command {
18
+ constructor(options, callback) {
19
+ super();
20
+ this.sql = options.sql;
21
+ this.values = options.values;
22
+ this._queryOptions = options;
23
+ this.namedPlaceholders = options.namedPlaceholders || false;
24
+ this.onResult = callback;
25
+ this.timeout = options.timeout;
26
+ this.queryTimeout = null;
27
+ this._fieldCount = 0;
28
+ this._rowParser = null;
29
+ this._fields = [];
30
+ this._rows = [];
31
+ this._receivedFieldsCount = 0;
32
+ this._resultIndex = 0;
33
+ this._localStream = null;
34
+ this._unpipeStream = function () {};
35
+ this._streamFactory = options.infileStreamFactory;
36
+ this._connection = null;
37
+ }
38
+
39
+ then() {
40
+ const err =
41
+ "You have tried to call .then(), .catch(), or invoked await on the result of query that is not a promise, which is a programming error. Try calling con.promise().query(), or require('mysql2/promise') instead of 'mysql2' for a promise-compatible version of the query interface. To learn how to use async/await or Promises check out documentation at https://sidorares.github.io/node-mysql2/docs#using-promise-wrapper, or the mysql2 documentation at https://sidorares.github.io/node-mysql2/docs/documentation/promise-wrapper";
42
+
43
+ console.log(err);
44
+ throw new Error(err);
45
+ }
46
+
47
+ /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
48
+ start(_packet, connection) {
49
+ if (connection.config.debug) {
50
+ console.log(' Sending query command: %s', this.sql);
51
+ }
52
+ this._connection = connection;
53
+ this.options = Object.assign({}, connection.config, this._queryOptions);
54
+ this._setTimeout();
55
+
56
+ const cmdPacket = new Packets.Query(
57
+ this.sql,
58
+ connection.config.charsetNumber
59
+ );
60
+ connection.writePacket(cmdPacket.toPacket(1));
61
+ return Query.prototype.resultsetHeader;
62
+ }
63
+
64
+ done() {
65
+ this._unpipeStream();
66
+ // if all ready timeout, return null directly
67
+ if (this.timeout && !this.queryTimeout) {
68
+ return null;
69
+ }
70
+ // else clear timer
71
+ if (this.queryTimeout) {
72
+ Timers.clearTimeout(this.queryTimeout);
73
+ this.queryTimeout = null;
74
+ }
75
+ if (this.onResult) {
76
+ let rows, fields;
77
+ if (this._resultIndex === 0) {
78
+ rows = this._rows[0];
79
+ fields = this._fields[0];
80
+ } else {
81
+ rows = this._rows;
82
+ fields = this._fields;
83
+ }
84
+ if (fields) {
85
+ process.nextTick(() => {
86
+ this.onResult(null, rows, fields);
87
+ });
88
+ } else {
89
+ process.nextTick(() => {
90
+ this.onResult(null, rows);
91
+ });
92
+ }
93
+ }
94
+ return null;
95
+ }
96
+
97
+ doneInsert(rs) {
98
+ if (this._localStreamError) {
99
+ if (this.onResult) {
100
+ this.onResult(this._localStreamError, rs);
101
+ } else {
102
+ this.emit('error', this._localStreamError);
103
+ }
104
+ return null;
105
+ }
106
+ this._rows.push(rs);
107
+ this._fields.push(void 0);
108
+ this.emit('fields', void 0);
109
+ this.emit('result', rs);
110
+ if (rs.serverStatus & ServerStatus.SERVER_MORE_RESULTS_EXISTS) {
111
+ this._resultIndex++;
112
+ return this.resultsetHeader;
113
+ }
114
+ return this.done();
115
+ }
116
+
117
+ resultsetHeader(packet, connection) {
118
+ const rs = new Packets.ResultSetHeader(packet, connection);
119
+ this._fieldCount = rs.fieldCount;
120
+ if (connection.config.debug) {
121
+ console.log(
122
+ ` Resultset header received, expecting ${rs.fieldCount} column definition packets`
123
+ );
124
+ }
125
+ if (this._fieldCount === 0) {
126
+ return this.doneInsert(rs);
127
+ }
128
+ if (this._fieldCount === null) {
129
+ return this._streamLocalInfile(connection, rs.infileName);
130
+ }
131
+ this._receivedFieldsCount = 0;
132
+ this._rows.push([]);
133
+ this._fields.push([]);
134
+ return this.readField;
135
+ }
136
+
137
+ _streamLocalInfile(connection, path) {
138
+ if (this._streamFactory) {
139
+ this._localStream = this._streamFactory(path);
140
+ } else {
141
+ this._localStreamError = new Error(
142
+ `As a result of LOCAL INFILE command server wants to read ${path} file, but as of v2.0 you must provide streamFactory option returning ReadStream.`
143
+ );
144
+ connection.writePacket(EmptyPacket);
145
+ return this.infileOk;
146
+ }
147
+
148
+ const onConnectionError = () => {
149
+ this._unpipeStream();
150
+ };
151
+ const onDrain = () => {
152
+ this._localStream.resume();
153
+ };
154
+ const onPause = () => {
155
+ this._localStream.pause();
156
+ };
157
+ const onData = function (data) {
158
+ const dataWithHeader = Buffer.allocUnsafe(data.length + 4);
159
+ data.copy(dataWithHeader, 4);
160
+ connection.writePacket(
161
+ new Packets.Packet(0, dataWithHeader, 0, dataWithHeader.length)
162
+ );
163
+ };
164
+ const onEnd = () => {
165
+ connection.removeListener('error', onConnectionError);
166
+ connection.writePacket(EmptyPacket);
167
+ };
168
+ const onError = (err) => {
169
+ this._localStreamError = err;
170
+ connection.removeListener('error', onConnectionError);
171
+ connection.writePacket(EmptyPacket);
172
+ };
173
+ this._unpipeStream = () => {
174
+ connection.stream.removeListener('pause', onPause);
175
+ connection.stream.removeListener('drain', onDrain);
176
+ this._localStream.removeListener('data', onData);
177
+ this._localStream.removeListener('end', onEnd);
178
+ this._localStream.removeListener('error', onError);
179
+ };
180
+ connection.stream.on('pause', onPause);
181
+ connection.stream.on('drain', onDrain);
182
+ this._localStream.on('data', onData);
183
+ this._localStream.on('end', onEnd);
184
+ this._localStream.on('error', onError);
185
+ connection.once('error', onConnectionError);
186
+ return this.infileOk;
187
+ }
188
+
189
+ readField(packet, connection) {
190
+ this._receivedFieldsCount++;
191
+ // Often there is much more data in the column definition than in the row itself
192
+ // If you set manually _fields[0] to array of ColumnDefinition's (from previous call)
193
+ // you can 'cache' result of parsing. Field packets still received, but ignored in that case
194
+ // this is the reason _receivedFieldsCount exist (otherwise we could just use current length of fields array)
195
+ if (this._fields[this._resultIndex].length !== this._fieldCount) {
196
+ const field = new Packets.ColumnDefinition(
197
+ packet,
198
+ connection.clientEncoding
199
+ );
200
+ this._fields[this._resultIndex].push(field);
201
+ if (connection.config.debug) {
202
+ console.log(' Column definition:');
203
+ console.log(` name: ${field.name}`);
204
+ console.log(` type: ${field.columnType}`);
205
+ console.log(` flags: ${field.flags}`);
206
+ }
207
+ }
208
+ // last field received
209
+ if (this._receivedFieldsCount === this._fieldCount) {
210
+ const fields = this._fields[this._resultIndex];
211
+ this.emit('fields', fields);
212
+ if (this.options.disableEval) {
213
+ this._rowParser = staticParser(fields, this.options, connection.config);
214
+ } else {
215
+ this._rowParser = new (getTextParser(
216
+ fields,
217
+ this.options,
218
+ connection.config
219
+ ))(fields);
220
+ }
221
+ return Query.prototype.fieldsEOF;
222
+ }
223
+ return Query.prototype.readField;
224
+ }
225
+
226
+ fieldsEOF(packet, connection) {
227
+ // check EOF
228
+ if (!packet.isEOF()) {
229
+ return connection.protocolError('Expected EOF packet');
230
+ }
231
+ return this.row;
232
+ }
233
+
234
+ row(packet, _connection) {
235
+ if (packet.isEOF()) {
236
+ const status = packet.eofStatusFlags();
237
+ const moreResults = status & ServerStatus.SERVER_MORE_RESULTS_EXISTS;
238
+ if (moreResults) {
239
+ this._resultIndex++;
240
+ return Query.prototype.resultsetHeader;
241
+ }
242
+ return this.done();
243
+ }
244
+ let row;
245
+ try {
246
+ row = this._rowParser.next(
247
+ packet,
248
+ this._fields[this._resultIndex],
249
+ this.options
250
+ );
251
+ } catch (err) {
252
+ this._localStreamError = err;
253
+ return this.doneInsert(null);
254
+ }
255
+ if (this.onResult) {
256
+ this._rows[this._resultIndex].push(row);
257
+ } else {
258
+ this.emit('result', row, this._resultIndex);
259
+ }
260
+ return Query.prototype.row;
261
+ }
262
+
263
+ infileOk(packet, connection) {
264
+ const rs = new Packets.ResultSetHeader(packet, connection);
265
+ return this.doneInsert(rs);
266
+ }
267
+
268
+ stream(options) {
269
+ options = options || Object.create(null);
270
+ options.objectMode = true;
271
+
272
+ const stream = new Readable({
273
+ ...options,
274
+ emitClose: true,
275
+ autoDestroy: true,
276
+ read: () => {
277
+ this._connection && this._connection.resume();
278
+ },
279
+ });
280
+
281
+ // Prevent a breaking change for users that rely on `end` event
282
+ stream.once('close', () => {
283
+ if (!stream.readableEnded) {
284
+ stream.emit('end');
285
+ }
286
+ });
287
+
288
+ const onResult = (row, index) => {
289
+ if (stream.destroyed) return;
290
+
291
+ if (!stream.push(row)) {
292
+ this._connection && this._connection.pause();
293
+ }
294
+
295
+ stream.emit('result', row, index); // replicate old emitter
296
+ };
297
+
298
+ const onFields = (fields) => {
299
+ if (stream.destroyed) return;
300
+
301
+ stream.emit('fields', fields); // replicate old emitter
302
+ };
303
+
304
+ const onEnd = () => {
305
+ if (stream.destroyed) return;
306
+
307
+ stream.push(null); // pushing null, indicating EOF
308
+ };
309
+
310
+ const onError = (err) => {
311
+ stream.destroy(err);
312
+ };
313
+
314
+ stream._destroy = (err, cb) => {
315
+ this._connection && this._connection.resume();
316
+
317
+ this.removeListener('result', onResult);
318
+ this.removeListener('fields', onFields);
319
+ this.removeListener('end', onEnd);
320
+ this.removeListener('error', onError);
321
+
322
+ cb(err); // Pass on any errors
323
+ };
324
+
325
+ this.on('result', onResult);
326
+ this.on('fields', onFields);
327
+ this.on('end', onEnd);
328
+ this.on('error', onError);
329
+
330
+ return stream;
331
+ }
332
+
333
+ _setTimeout() {
334
+ if (this.timeout) {
335
+ const timeoutHandler = this._handleTimeoutError.bind(this);
336
+ this.queryTimeout = Timers.setTimeout(timeoutHandler, this.timeout);
337
+ }
338
+ }
339
+
340
+ _handleTimeoutError() {
341
+ if (this.queryTimeout) {
342
+ Timers.clearTimeout(this.queryTimeout);
343
+ this.queryTimeout = null;
344
+ }
345
+
346
+ const err = new Error('Query inactivity timeout');
347
+ err.errorno = 'PROTOCOL_SEQUENCE_TIMEOUT';
348
+ err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
349
+ err.syscall = 'query';
350
+
351
+ if (this.onResult) {
352
+ this.onResult(err);
353
+ } else {
354
+ this.emit('error', err);
355
+ }
356
+ }
357
+ }
358
+
359
+ Query.prototype.catch = Query.prototype.then;
360
+
361
+ module.exports = Query;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const Command = require('./command.js');
4
+ const CommandCode = require('../constants/commands.js');
5
+ const Packet = require('../packets/packet.js');
6
+
7
+ class Quit extends Command {
8
+ constructor(callback) {
9
+ super();
10
+ this.onResult = callback;
11
+ }
12
+
13
+ start(packet, connection) {
14
+ connection._closing = true;
15
+ const quit = new Packet(
16
+ 0,
17
+ Buffer.from([1, 0, 0, 0, CommandCode.QUIT]),
18
+ 0,
19
+ 5
20
+ );
21
+ if (this.onResult) {
22
+ this.onResult();
23
+ }
24
+ connection.writePacket(quit);
25
+ return null;
26
+ }
27
+ }
28
+
29
+ module.exports = Quit;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const Command = require('./command');
4
+ const Packets = require('../packets');
5
+
6
+ class RegisterSlave extends Command {
7
+ constructor(opts, callback) {
8
+ super();
9
+ this.onResult = callback;
10
+ this.opts = opts;
11
+ }
12
+
13
+ start(packet, connection) {
14
+ const newPacket = new Packets.RegisterSlave(this.opts);
15
+ connection.writePacket(newPacket.toPacket(1));
16
+ return RegisterSlave.prototype.registerResponse;
17
+ }
18
+
19
+ registerResponse() {
20
+ if (this.onResult) {
21
+ process.nextTick(this.onResult.bind(this));
22
+ }
23
+ return null;
24
+ }
25
+ }
26
+
27
+ module.exports = RegisterSlave;