@tachybase/module-multi-app 1.6.0 → 1.6.2

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 (105) hide show
  1. package/README.md +34 -34
  2. package/README.zh-CN.md +34 -34
  3. package/client.d.ts +1 -1
  4. package/client.js +1 -1
  5. package/dist/externalVersion.js +5 -5
  6. package/dist/locale/en-US.json +48 -48
  7. package/dist/locale/es-ES.json +9 -9
  8. package/dist/locale/ko_KR.json +11 -11
  9. package/dist/locale/pt-BR.json +9 -9
  10. package/dist/locale/zh-CN.json +58 -58
  11. package/dist/node_modules/mariadb/callback.js +43 -8
  12. package/dist/node_modules/mariadb/check-node.js +30 -0
  13. package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
  14. package/dist/node_modules/mariadb/lib/cluster.js +446 -0
  15. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
  16. package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
  17. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
  18. package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
  19. package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
  20. package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
  21. package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
  22. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
  23. package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
  24. package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
  25. package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
  26. package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
  27. package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
  28. package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
  29. package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
  30. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
  31. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
  32. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
  33. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
  34. package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
  35. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
  43. package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
  44. package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
  45. package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
  46. package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
  47. package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
  48. package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
  49. package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
  50. package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
  51. package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
  52. package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
  53. package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
  54. package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
  55. package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
  56. package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
  57. package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
  58. package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
  59. package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
  60. package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
  61. package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
  62. package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
  63. package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
  64. package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
  65. package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
  66. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
  67. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
  68. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
  69. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
  70. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
  71. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
  72. package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
  73. package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
  74. package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
  75. package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
  76. package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
  77. package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
  78. package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
  79. package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
  80. package/dist/node_modules/mariadb/lib/pool.js +951 -0
  81. package/dist/node_modules/mariadb/package.json +1 -1
  82. package/dist/node_modules/mariadb/promise.js +1 -34
  83. package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
  84. package/dist/node_modules/mariadb/types/index.d.ts +94 -674
  85. package/dist/node_modules/mariadb/types/share.d.ts +804 -0
  86. package/dist/node_modules/qs/package.json +1 -1
  87. package/dist/server/actions/apps.js +2 -2
  88. package/dist/server/app-lifecycle.d.ts +1 -1
  89. package/dist/server/app-lifecycle.js +4 -4
  90. package/dist/server/models/application.d.ts +1 -1
  91. package/package.json +7 -7
  92. package/server.d.ts +2 -2
  93. package/server.js +1 -1
  94. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
  95. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
  96. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
  97. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
  98. package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
  99. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
  100. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
  101. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
  102. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
  103. package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
  104. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
  105. package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
@@ -1,427 +0,0 @@
1
- 'use strict';
2
-
3
- const ResultSet = require('./resultset');
4
- const FieldDetail = require('../const/field-detail');
5
- const FieldType = require('../const/field-type');
6
- const Long = require('long');
7
- const moment = require('moment-timezone');
8
- const QUOTE = 0x27;
9
-
10
- class CommonText extends ResultSet {
11
- constructor(resolve, reject, cmdOpts, connOpts, sql, values) {
12
- super(resolve, reject);
13
- this.configAssign(connOpts, cmdOpts);
14
- this.sql = sql;
15
- this.initialValues = values;
16
- this.getDateQuote = this.opts.tz
17
- ? this.opts.tz === 'Etc/UTC'
18
- ? CommonText.getUtcDate
19
- : CommonText.getTimezoneDate
20
- : CommonText.getLocalDate;
21
- }
22
-
23
- /**
24
- * Write (and escape) current parameter value to output writer
25
- *
26
- * @param out output writer
27
- * @param value current parameter
28
- * @param opts connection options
29
- * @param info connection information
30
- */
31
- writeParam(out, value, opts, info) {
32
- switch (typeof value) {
33
- case 'boolean':
34
- out.writeStringAscii(value ? 'true' : 'false');
35
- break;
36
- case 'bigint':
37
- case 'number':
38
- out.writeStringAscii('' + value);
39
- break;
40
- case 'object':
41
- if (value === null) {
42
- out.writeStringAscii('NULL');
43
- } else if (Object.prototype.toString.call(value) === '[object Date]') {
44
- out.writeStringAscii(this.getDateQuote(value, opts));
45
- } else if (Buffer.isBuffer(value)) {
46
- out.writeStringAscii("_BINARY '");
47
- out.writeBufferEscape(value);
48
- out.writeInt8(QUOTE);
49
- } else if (typeof value.toSqlString === 'function') {
50
- out.writeStringEscapeQuote(String(value.toSqlString()));
51
- } else if (Long.isLong(value)) {
52
- out.writeStringAscii(value.toString());
53
- } else if (Array.isArray(value)) {
54
- if (opts.arrayParenthesis) {
55
- out.writeStringAscii('(');
56
- }
57
- for (let i = 0; i < value.length; i++) {
58
- if (i !== 0) out.writeStringAscii(',');
59
- this.writeParam(out, value[i], opts, info);
60
- }
61
- if (opts.arrayParenthesis) {
62
- out.writeStringAscii(')');
63
- }
64
- } else {
65
- if (
66
- value.type != null &&
67
- [
68
- 'Point',
69
- 'LineString',
70
- 'Polygon',
71
- 'MultiPoint',
72
- 'MultiLineString',
73
- 'MultiPolygon',
74
- 'GeometryCollection'
75
- ].includes(value.type)
76
- ) {
77
- //GeoJSON format.
78
- let prefix =
79
- (info.isMariaDB() && info.hasMinVersion(10, 1, 4)) ||
80
- (!info.isMariaDB() && info.hasMinVersion(5, 7, 6))
81
- ? 'ST_'
82
- : '';
83
- switch (value.type) {
84
- case 'Point':
85
- out.writeStringAscii(
86
- prefix +
87
- "PointFromText('POINT(" +
88
- CommonText.geoPointToString(value.coordinates) +
89
- ")')"
90
- );
91
- break;
92
-
93
- case 'LineString':
94
- out.writeStringAscii(
95
- prefix +
96
- "LineFromText('LINESTRING(" +
97
- CommonText.geoArrayPointToString(value.coordinates) +
98
- ")')"
99
- );
100
- break;
101
-
102
- case 'Polygon':
103
- out.writeStringAscii(
104
- prefix +
105
- "PolygonFromText('POLYGON(" +
106
- CommonText.geoMultiArrayPointToString(value.coordinates) +
107
- ")')"
108
- );
109
- break;
110
-
111
- case 'MultiPoint':
112
- out.writeStringAscii(
113
- prefix +
114
- "MULTIPOINTFROMTEXT('MULTIPOINT(" +
115
- CommonText.geoArrayPointToString(value.coordinates) +
116
- ")')"
117
- );
118
- break;
119
-
120
- case 'MultiLineString':
121
- out.writeStringAscii(
122
- prefix +
123
- "MLineFromText('MULTILINESTRING(" +
124
- CommonText.geoMultiArrayPointToString(value.coordinates) +
125
- ")')"
126
- );
127
- break;
128
-
129
- case 'MultiPolygon':
130
- out.writeStringAscii(
131
- prefix +
132
- "MPolyFromText('MULTIPOLYGON(" +
133
- CommonText.geoMultiPolygonToString(value.coordinates) +
134
- ")')"
135
- );
136
- break;
137
-
138
- case 'GeometryCollection':
139
- out.writeStringAscii(
140
- prefix +
141
- "GeomCollFromText('GEOMETRYCOLLECTION(" +
142
- CommonText.geometricCollectionToString(value.geometries) +
143
- ")')"
144
- );
145
- break;
146
- }
147
- } else {
148
- if (opts.permitSetMultiParamEntries) {
149
- let first = true;
150
- for (let key in value) {
151
- const val = value[key];
152
- if (typeof val === 'function') continue;
153
- if (first) {
154
- first = false;
155
- } else {
156
- out.writeStringAscii(',');
157
- }
158
- out.writeString('`' + key + '`');
159
- out.writeStringAscii('=');
160
- this.writeParam(out, val, opts, info);
161
- }
162
- if (first) out.writeStringEscapeQuote(JSON.stringify(value));
163
- } else {
164
- out.writeStringEscapeQuote(JSON.stringify(value));
165
- }
166
- }
167
- }
168
- break;
169
- default:
170
- out.writeStringEscapeQuote(value);
171
- }
172
- }
173
-
174
- static geometricCollectionToString(geo) {
175
- if (!geo) return '';
176
- let st = '';
177
- for (let i = 0; i < geo.length; i++) {
178
- //GeoJSON format.
179
- st += i !== 0 ? ',' : '';
180
- switch (geo[i].type) {
181
- case 'Point':
182
- st += 'POINT(' + CommonText.geoPointToString(geo[i].coordinates) + ')';
183
- break;
184
-
185
- case 'LineString':
186
- st += 'LINESTRING(' + CommonText.geoArrayPointToString(geo[i].coordinates) + ')';
187
- break;
188
-
189
- case 'Polygon':
190
- st += 'POLYGON(' + CommonText.geoMultiArrayPointToString(geo[i].coordinates) + ')';
191
- break;
192
-
193
- case 'MultiPoint':
194
- st += 'MULTIPOINT(' + CommonText.geoArrayPointToString(geo[i].coordinates) + ')';
195
- break;
196
-
197
- case 'MultiLineString':
198
- st +=
199
- 'MULTILINESTRING(' + CommonText.geoMultiArrayPointToString(geo[i].coordinates) + ')';
200
- break;
201
-
202
- case 'MultiPolygon':
203
- st += 'MULTIPOLYGON(' + CommonText.geoMultiPolygonToString(geo[i].coordinates) + ')';
204
- break;
205
- }
206
- }
207
- return st;
208
- }
209
-
210
- static geoMultiPolygonToString(coords) {
211
- if (!coords) return '';
212
- let st = '';
213
- for (let i = 0; i < coords.length; i++) {
214
- st += (i !== 0 ? ',(' : '(') + CommonText.geoMultiArrayPointToString(coords[i]) + ')';
215
- }
216
- return st;
217
- }
218
-
219
- static geoMultiArrayPointToString(coords) {
220
- if (!coords) return '';
221
- let st = '';
222
- for (let i = 0; i < coords.length; i++) {
223
- st += (i !== 0 ? ',(' : '(') + CommonText.geoArrayPointToString(coords[i]) + ')';
224
- }
225
- return st;
226
- }
227
-
228
- static geoArrayPointToString(coords) {
229
- if (!coords) return '';
230
- let st = '';
231
- for (let i = 0; i < coords.length; i++) {
232
- st += (i !== 0 ? ',' : '') + CommonText.geoPointToString(coords[i]);
233
- }
234
- return st;
235
- }
236
-
237
- static geoPointToString(coords) {
238
- if (!coords) return '';
239
- return (isNaN(coords[0]) ? '' : coords[0]) + ' ' + (isNaN(coords[1]) ? '' : coords[1]);
240
- }
241
-
242
- parseRowAsArray(columns, packet, connOpts) {
243
- const row = new Array(this._columnCount);
244
- for (let i = 0; i < this._columnCount; i++) {
245
- row[i] = this._getValue(i, columns[i], this.opts, connOpts, packet);
246
- }
247
- return row;
248
- }
249
-
250
- parseRowNested(columns, packet, connOpts) {
251
- const row = {};
252
- for (let i = 0; i < this._columnCount; i++) {
253
- if (!row[this.tableHeader[i][0]]) row[this.tableHeader[i][0]] = {};
254
- row[this.tableHeader[i][0]][this.tableHeader[i][1]] = this._getValue(
255
- i,
256
- columns[i],
257
- this.opts,
258
- connOpts,
259
- packet
260
- );
261
- }
262
- return row;
263
- }
264
-
265
- parseRowStd(columns, packet, connOpts) {
266
- const row = {};
267
- for (let i = 0; i < this._columnCount; i++) {
268
- row[this.tableHeader[i]] = this._getValue(i, columns[i], this.opts, connOpts, packet);
269
- }
270
- return row;
271
- }
272
-
273
- castTextWrapper(column, opts, connOpts, packet) {
274
- column.string = () => packet.readStringLength();
275
- column.buffer = () => packet.readBufferLengthEncoded();
276
- column.float = () => packet.readFloatLengthCoded();
277
- column.int = () => packet.readIntLengthEncoded();
278
- column.long = () =>
279
- packet.readLongLengthEncoded(
280
- opts.supportBigInt,
281
- opts.supportBigNumbers,
282
- opts.bigNumberStrings,
283
- (column.flags & FieldDetail.UNSIGNED) > 0
284
- );
285
- column.decimal = () => packet.readDecimalLengthEncoded(opts.bigNumberStrings);
286
- column.date = () => packet.readDateTime(opts);
287
- column.geometry = () => {
288
- return column.readGeometry();
289
- };
290
- }
291
-
292
- readCastValue(index, column, opts, connOpts, packet) {
293
- this.castTextWrapper(column, opts, connOpts, packet);
294
- return opts.typeCast(
295
- column,
296
- this.readRowData.bind(this, index, column, opts, connOpts, packet)
297
- );
298
- }
299
-
300
- /**
301
- * Read row data.
302
- *
303
- * @param index current data index in row
304
- * @param column associate metadata
305
- * @param opts query options
306
- * @param connOpts connection options
307
- * @param packet row packet
308
- * @returns {*} data
309
- */
310
- readRowData(index, column, opts, connOpts, packet) {
311
- switch (column.columnType) {
312
- case FieldType.TINY:
313
- case FieldType.SHORT:
314
- case FieldType.LONG:
315
- case FieldType.INT24:
316
- case FieldType.YEAR:
317
- return packet.readIntLengthEncoded();
318
- case FieldType.FLOAT:
319
- case FieldType.DOUBLE:
320
- return packet.readFloatLengthCoded();
321
- case FieldType.LONGLONG:
322
- return packet.readLongLengthEncoded(
323
- opts.supportBigInt,
324
- opts.supportBigNumbers,
325
- opts.bigNumberStrings,
326
- (column.flags & FieldDetail.UNSIGNED) > 0
327
- );
328
- case FieldType.DECIMAL:
329
- case FieldType.NEWDECIMAL:
330
- return packet.readDecimalLengthEncoded(opts.bigNumberStrings);
331
- case FieldType.DATE:
332
- if (opts.dateStrings) {
333
- return packet.readAsciiStringLengthEncoded();
334
- }
335
- return packet.readDate();
336
- case FieldType.DATETIME:
337
- case FieldType.TIMESTAMP:
338
- if (opts.dateStrings) {
339
- return packet.readAsciiStringLengthEncoded();
340
- }
341
- return packet.readDateTime(opts);
342
- case FieldType.TIME:
343
- return packet.readAsciiStringLengthEncoded();
344
- case FieldType.GEOMETRY:
345
- return packet.readGeometry(column.dataTypeName);
346
- case FieldType.JSON:
347
- //for mysql only => parse string as JSON object
348
- return JSON.parse(packet.readStringLengthEncoded('utf8'));
349
-
350
- default:
351
- if (column.dataTypeFormat && column.dataTypeFormat === 'json' && opts.autoJsonMap) {
352
- return JSON.parse(packet.readStringLengthEncoded('utf8'));
353
- }
354
-
355
- if (column.collation.index === 63) {
356
- return packet.readBufferLengthEncoded();
357
- }
358
- const string = packet.readStringLength();
359
- if (column.flags & 2048) {
360
- //SET
361
- return string == null ? null : string === '' ? [] : string.split(',');
362
- }
363
- return string;
364
- }
365
- }
366
- }
367
-
368
- function getDatePartQuote(year, mon, day, hour, min, sec, ms) {
369
- //return 'YYYY-MM-DD HH:MM:SS' datetime format
370
- //see https://mariadb.com/kb/en/library/datetime/
371
- return (
372
- "'" +
373
- (year > 999 ? year : year > 99 ? '0' + year : year > 9 ? '00' + year : '000' + year) +
374
- '-' +
375
- (mon < 10 ? '0' : '') +
376
- mon +
377
- '-' +
378
- (day < 10 ? '0' : '') +
379
- day +
380
- ' ' +
381
- (hour < 10 ? '0' : '') +
382
- hour +
383
- ':' +
384
- (min < 10 ? '0' : '') +
385
- min +
386
- ':' +
387
- (sec < 10 ? '0' : '') +
388
- sec +
389
- '.' +
390
- (ms > 99 ? ms : ms > 9 ? '0' + ms : '00' + ms) +
391
- "'"
392
- );
393
- }
394
-
395
- function getLocalDate(date, opts) {
396
- const year = date.getFullYear();
397
- const mon = date.getMonth() + 1;
398
- const day = date.getDate();
399
- const hour = date.getHours();
400
- const min = date.getMinutes();
401
- const sec = date.getSeconds();
402
- const ms = date.getMilliseconds();
403
- return getDatePartQuote(year, mon, day, hour, min, sec, ms);
404
- }
405
-
406
- function getUtcDate(date, opts) {
407
- const year = date.getUTCFullYear();
408
- const mon = date.getUTCMonth() + 1;
409
- const day = date.getUTCDate();
410
- const hour = date.getUTCHours();
411
- const min = date.getUTCMinutes();
412
- const sec = date.getUTCSeconds();
413
- const ms = date.getUTCMilliseconds();
414
- return getDatePartQuote(year, mon, day, hour, min, sec, ms);
415
- }
416
-
417
- function getTimezoneDate(date, opts) {
418
- if (date.getMilliseconds() != 0) {
419
- return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss.SSS'");
420
- }
421
- return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss'");
422
- }
423
-
424
- module.exports = CommonText;
425
- module.exports.getTimezoneDate = getTimezoneDate;
426
- module.exports.getUtcDate = getUtcDate;
427
- module.exports.getLocalDate = getLocalDate;
@@ -1,126 +0,0 @@
1
- 'use strict';
2
-
3
- const Capabilities = require('../../const/capabilities');
4
- const Iconv = require('iconv-lite');
5
- const NativePasswordAuth = require('./auth/native-password-auth');
6
- const Ed25519PasswordAuth = require('./auth/ed25519-password-auth');
7
- const driverVersion = require('../../../package.json').version;
8
- const os = require('os');
9
-
10
- /**
11
- * Send Handshake response packet
12
- * see https://mariadb.com/kb/en/library/1-connecting-connecting/#handshake-response-packet
13
- *
14
- * @param cmd current handshake command
15
- * @param out output writer
16
- * @param opts connection options
17
- * @param pluginName plugin name
18
- * @param info connection information
19
- */
20
- module.exports.send = function send(cmd, out, opts, pluginName, info) {
21
- out.startPacket(cmd);
22
- info.defaultPluginName = pluginName;
23
- const pwd = Array.isArray(opts.password) ? opts.password[0] : opts.password;
24
- let authToken;
25
- let authPlugin;
26
- switch (pluginName) {
27
- case 'client_ed25519':
28
- authToken = Ed25519PasswordAuth.encryptPassword(pwd, info.seed);
29
- authPlugin = 'client_ed25519';
30
- break;
31
-
32
- case 'mysql_clear_password':
33
- authToken = Buffer.from(pwd);
34
- authPlugin = 'mysql_clear_password';
35
- break;
36
-
37
- default:
38
- authToken = NativePasswordAuth.encryptPassword(pwd, info.seed, 'sha1');
39
- authPlugin = 'mysql_native_password';
40
- break;
41
- }
42
- out.writeInt32(Number(info.clientCapabilities & BigInt(0xffffffff)));
43
- out.writeInt32(1024 * 1024 * 1024); // max packet size
44
- out.writeInt8(opts.collation.index);
45
- for (let i = 0; i < 19; i++) {
46
- out.writeInt8(0);
47
- }
48
-
49
- out.writeInt32(Number(info.clientCapabilities >> BigInt(32)));
50
-
51
- //null encoded user
52
- out.writeString(opts.user || '');
53
- out.writeInt8(0);
54
-
55
- if (info.serverCapabilities & Capabilities.PLUGIN_AUTH_LENENC_CLIENT_DATA) {
56
- out.writeLengthCoded(authToken.length);
57
- out.writeBuffer(authToken, 0, authToken.length);
58
- } else if (info.serverCapabilities & Capabilities.SECURE_CONNECTION) {
59
- out.writeInt8(authToken.length);
60
- out.writeBuffer(authToken, 0, authToken.length);
61
- } else {
62
- out.writeBuffer(authToken, 0, authToken.length);
63
- out.writeInt8(0);
64
- }
65
-
66
- if (info.clientCapabilities & Capabilities.CONNECT_WITH_DB) {
67
- out.writeString(opts.database);
68
- out.writeInt8(0);
69
- info.database = opts.database;
70
- }
71
-
72
- if (info.clientCapabilities & Capabilities.PLUGIN_AUTH) {
73
- out.writeString(authPlugin);
74
- out.writeInt8(0);
75
- }
76
-
77
- if (info.clientCapabilities & Capabilities.CONNECT_ATTRS) {
78
- out.writeInt8(0xfc);
79
- let initPos = out.pos; //save position, assuming connection attributes length will be less than 2 bytes length
80
- out.writeInt16(0);
81
-
82
- const encoding = opts.collation.charset;
83
-
84
- writeParam(out, '_client_name', encoding);
85
- writeParam(out, 'MariaDB connector/Node', encoding);
86
-
87
- writeParam(out, '_client_version', encoding);
88
- writeParam(out, driverVersion, encoding);
89
-
90
- const address = cmd.getSocket().address().address;
91
- if (address) {
92
- writeParam(out, '_server_host', encoding);
93
- writeParam(out, address, encoding);
94
- }
95
-
96
- writeParam(out, '_os', encoding);
97
- writeParam(out, process.platform, encoding);
98
-
99
- writeParam(out, '_client_host', encoding);
100
- writeParam(out, os.hostname(), encoding);
101
-
102
- writeParam(out, '_node_version', encoding);
103
- writeParam(out, process.versions.node, encoding);
104
-
105
- if (opts.connectAttributes !== true) {
106
- let attrNames = Object.keys(opts.connectAttributes);
107
- for (let k = 0; k < attrNames.length; ++k) {
108
- writeParam(out, attrNames[k], encoding);
109
- writeParam(out, opts.connectAttributes[attrNames[k]], encoding);
110
- }
111
- }
112
-
113
- //write end size
114
- out.writeInt16AtPos(initPos);
115
- }
116
-
117
- out.flushBuffer(true);
118
- };
119
-
120
- function writeParam(out, val, encoding) {
121
- let param = Buffer.isEncoding(encoding)
122
- ? Buffer.from(val, encoding)
123
- : Iconv.encode(val, encoding);
124
- out.writeLengthCoded(param.length);
125
- out.writeBuffer(param, 0, param.length);
126
- }